… | |
… | |
171 | sub rescale_widgets { |
171 | sub rescale_widgets { |
172 | my ($sx, $sy) = @_; |
172 | my ($sx, $sy) = @_; |
173 | |
173 | |
174 | for my $widget (values %WIDGET) { |
174 | for my $widget (values %WIDGET) { |
175 | if ($widget->{is_toplevel}) { |
175 | if ($widget->{is_toplevel}) { |
176 | $widget->{x} += $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
176 | $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
177 | $widget->{y} += $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
177 | $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
178 | |
178 | |
179 | $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; |
179 | $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; |
180 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
180 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
181 | $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w}; |
181 | $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w}; |
182 | $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/; |
182 | $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/; |
183 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
183 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
184 | $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h}; |
184 | $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h}; |
185 | |
185 | |
186 | $widget->{x} -= $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
186 | $widget->{x} -= int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
187 | $widget->{y} -= $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
187 | $widget->{y} -= int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
188 | |
188 | |
189 | } |
189 | } |
190 | } |
190 | } |
191 | |
191 | |
192 | reconfigure_widgets; |
192 | reconfigure_widgets; |
… | |
… | |
450 | my ($self, $ev, $x, $y) = @_; |
450 | my ($self, $ev, $x, $y) = @_; |
451 | |
451 | |
452 | $self->focus_in; |
452 | $self->focus_in; |
453 | } |
453 | } |
454 | |
454 | |
455 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
|
|
456 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
|
|
457 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
|
|
458 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
|
|
459 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
|
|
460 | |
|
|
461 | sub find_widget { |
455 | sub find_widget { |
462 | my ($self, $x, $y) = @_; |
456 | my ($self, $x, $y) = @_; |
463 | |
457 | |
464 | return () unless $self->{can_events}; |
458 | return () unless $self->{can_events}; |
465 | |
459 | |
… | |
… | |
526 | |
520 | |
527 | $self->realloc; |
521 | $self->realloc; |
528 | $self->update; |
522 | $self->update; |
529 | } |
523 | } |
530 | |
524 | |
|
|
525 | # using global variables seems a bit hacky, but passing through all drawing |
|
|
526 | # functions seems pointless. |
|
|
527 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
|
|
528 | |
531 | sub draw { |
529 | sub draw { |
532 | my ($self) = @_; |
530 | my ($self) = @_; |
533 | |
531 | |
534 | return unless $self->{h} && $self->{w}; |
532 | return unless $self->{h} && $self->{w}; |
|
|
533 | |
|
|
534 | # update screen rectangle |
|
|
535 | local $draw_x = $draw_x + $self->{x}; |
|
|
536 | local $draw_y = $draw_y + $self->{y}; |
|
|
537 | local $draw_w = $draw_x + $self->{w}; |
|
|
538 | local $draw_h = $draw_y + $self->{h}; |
|
|
539 | |
|
|
540 | # skip widgets that are entirely outside the drawing area |
|
|
541 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
|
|
542 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
535 | |
543 | |
536 | glPushMatrix; |
544 | glPushMatrix; |
537 | glTranslate $self->{x}, $self->{y}, 0; |
545 | glTranslate $self->{x}, $self->{y}, 0; |
538 | $self->_draw; |
546 | $self->_draw; |
539 | glPopMatrix; |
547 | glPopMatrix; |
… | |
… | |
804 | $self->SUPER::size_allocate ($w, $h); |
812 | $self->SUPER::size_allocate ($w, $h); |
805 | $self->update; |
813 | $self->update; |
806 | } |
814 | } |
807 | |
815 | |
808 | sub _render { |
816 | sub _render { |
|
|
817 | my ($self) = @_; |
|
|
818 | |
809 | $_[0]{children}[0]->draw; |
819 | $self->{children}[0]->draw; |
810 | } |
820 | } |
811 | |
821 | |
812 | sub render_child { |
822 | sub render_child { |
813 | my ($self) = @_; |
823 | my ($self) = @_; |
814 | |
824 | |
815 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
825 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
816 | glClearColor 0, 0, 0, 0; |
826 | glClearColor 0, 0, 0, 0; |
817 | glClear GL_COLOR_BUFFER_BIT; |
827 | glClear GL_COLOR_BUFFER_BIT; |
818 | |
828 | |
|
|
829 | { |
|
|
830 | package CFClient::UI::Base; |
|
|
831 | |
|
|
832 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
|
|
833 | (0, 0, $self->{w}, $self->{h}); |
|
|
834 | } |
|
|
835 | |
819 | $self->_render; |
836 | $self->_render; |
820 | }; |
837 | }; |
821 | } |
838 | } |
822 | |
839 | |
823 | sub _draw { |
840 | sub _draw { |
824 | my ($self) = @_; |
841 | my ($self) = @_; |
825 | |
842 | |
826 | my ($w, $h) = ($self->w, $self->h); |
843 | my ($w, $h) = @$self{qw(w h)}; |
827 | |
844 | |
828 | my $tex = $self->{texture} |
845 | my $tex = $self->{texture} |
829 | or return; |
846 | or return; |
830 | |
847 | |
831 | glEnable GL_TEXTURE_2D; |
848 | glEnable GL_TEXTURE_2D; |
… | |
… | |
913 | } |
930 | } |
914 | } |
931 | } |
915 | |
932 | |
916 | sub _render { |
933 | sub _render { |
917 | my ($self) = @_; |
934 | my ($self) = @_; |
|
|
935 | |
|
|
936 | local $CFClient::UI::Base::draw_x = $CFClient::UI::Base::draw_x - $self->{view_x}; |
|
|
937 | local $CFClient::UI::Base::draw_y = $CFClient::UI::Base::draw_y - $self->{view_y}; |
918 | |
938 | |
919 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
939 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
920 | |
940 | |
921 | $self->SUPER::_render; |
941 | $self->SUPER::_render; |
922 | } |
942 | } |
… | |
… | |
1030 | my @border = |
1050 | my @border = |
1031 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1051 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1032 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1052 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1033 | |
1053 | |
1034 | sub new { |
1054 | sub new { |
1035 | my $class = shift; |
1055 | my ($class, %arg) = @_; |
|
|
1056 | |
|
|
1057 | my $title = delete $arg{title}; |
1036 | |
1058 | |
1037 | my $self = $class->SUPER::new ( |
1059 | my $self = $class->SUPER::new ( |
1038 | bg => [1, 1, 1, 1], |
1060 | bg => [1, 1, 1, 1], |
1039 | border_bg => [1, 1, 1, 1], |
1061 | border_bg => [1, 1, 1, 1], |
1040 | border => 0.6, |
1062 | border => 0.6, |
1041 | can_events => 1, |
1063 | can_events => 1, |
1042 | min_w => 16, |
1064 | min_w => 16, |
1043 | min_h => 16, |
1065 | min_h => 16, |
1044 | @_ |
1066 | %arg, |
1045 | ); |
1067 | ); |
1046 | |
1068 | |
1047 | $self->{title} &&= new CFClient::UI::Label |
1069 | $self->{title} = new CFClient::UI::Label |
1048 | align => 0, |
1070 | align => 0, |
1049 | valign => 1, |
1071 | valign => 1, |
1050 | text => $self->{title}, |
1072 | text => $title, |
1051 | fontsize => $self->{border}; |
1073 | fontsize => $self->{border} |
|
|
1074 | if defined $title; |
1052 | |
1075 | |
1053 | $self |
1076 | $self |
|
|
1077 | } |
|
|
1078 | |
|
|
1079 | sub add { |
|
|
1080 | my ($self, @widgets) = @_; |
|
|
1081 | |
|
|
1082 | $self->SUPER::add (@widgets); |
|
|
1083 | $self->CFClient::UI::Container::add ($self->{title}) if $self->{title}; |
1054 | } |
1084 | } |
1055 | |
1085 | |
1056 | sub border { |
1086 | sub border { |
1057 | int $_[0]{border} * $::FONTSIZE |
1087 | int $_[0]{border} * $::FONTSIZE |
1058 | } |
1088 | } |
1059 | |
1089 | |
1060 | sub size_request { |
1090 | sub size_request { |
1061 | my ($self) = @_; |
1091 | my ($self) = @_; |
|
|
1092 | |
|
|
1093 | $self->{title}->size_request |
|
|
1094 | if $self->{title}; |
1062 | |
1095 | |
1063 | my ($w, $h) = $self->SUPER::size_request; |
1096 | my ($w, $h) = $self->SUPER::size_request; |
1064 | |
1097 | |
1065 | ( |
1098 | ( |
1066 | $w + $self->border * 2, |
1099 | $w + $self->border * 2, |
… | |
… | |
1069 | } |
1102 | } |
1070 | |
1103 | |
1071 | sub size_allocate { |
1104 | sub size_allocate { |
1072 | my ($self, $w, $h) = @_; |
1105 | my ($self, $w, $h) = @_; |
1073 | |
1106 | |
|
|
1107 | if ($self->{title}) { |
|
|
1108 | $self->{title}{w} = $w; |
|
|
1109 | $self->{title}{h} = $h; |
|
|
1110 | $self->{title}->size_allocate ($w, $h); |
|
|
1111 | } |
|
|
1112 | |
|
|
1113 | my $border = $self->border; |
|
|
1114 | |
1074 | $h -= List::Util::max 0, $self->border * 2; |
1115 | $h -= List::Util::max 0, $border * 2; |
1075 | $w -= List::Util::max 0, $self->border * 2; |
1116 | $w -= List::Util::max 0, $border * 2; |
1076 | |
1117 | |
1077 | $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) |
|
|
1078 | if $self->{title}; |
|
|
1079 | |
|
|
1080 | $self->child->configure ($self->border, $self->border, $w, $h); |
1118 | $self->child->configure ($border, $border, $w, $h); |
1081 | } |
1119 | } |
1082 | |
1120 | |
1083 | sub button_down { |
1121 | sub button_down { |
1084 | my ($self, $ev, $x, $y) = @_; |
1122 | my ($self, $ev, $x, $y) = @_; |
1085 | |
1123 | |
… | |
… | |
1137 | } |
1175 | } |
1138 | |
1176 | |
1139 | sub _draw { |
1177 | sub _draw { |
1140 | my ($self) = @_; |
1178 | my ($self) = @_; |
1141 | |
1179 | |
|
|
1180 | my $child = $self->{children}[0]; |
|
|
1181 | |
1142 | my ($w, $h ) = ($self->{w}, $self->{h}); |
1182 | my ($w, $h ) = ($self->{w}, $self->{h}); |
1143 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
1183 | my ($cw, $ch) = ($child->{w}, $child->{h}); |
1144 | |
1184 | |
1145 | glEnable GL_TEXTURE_2D; |
1185 | glEnable GL_TEXTURE_2D; |
1146 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1186 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1147 | |
1187 | |
1148 | my $border = $self->border; |
1188 | my $border = $self->border; |
… | |
… | |
1163 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
1203 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
1164 | } |
1204 | } |
1165 | |
1205 | |
1166 | glDisable GL_TEXTURE_2D; |
1206 | glDisable GL_TEXTURE_2D; |
1167 | |
1207 | |
1168 | $self->{title}->draw if $self->{title}; |
|
|
1169 | |
|
|
1170 | $self->child->draw; |
1208 | $child->draw; |
|
|
1209 | |
|
|
1210 | if ($self->{title}) { |
|
|
1211 | glTranslate 0, $border - $self->{h}; |
|
|
1212 | $self->{title}->_draw; |
|
|
1213 | } |
1171 | } |
1214 | } |
1172 | |
1215 | |
1173 | ############################################################################# |
1216 | ############################################################################# |
1174 | |
1217 | |
1175 | package CFClient::UI::Table; |
1218 | package CFClient::UI::Table; |
… | |
… | |
1523 | } |
1566 | } |
1524 | |
1567 | |
1525 | sub size_allocate { |
1568 | sub size_allocate { |
1526 | my ($self, $w, $h) = @_; |
1569 | my ($self, $w, $h) = @_; |
1527 | |
1570 | |
|
|
1571 | delete $self->{ox}; |
|
|
1572 | |
1528 | delete $self->{texture} |
1573 | delete $self->{texture} |
1529 | unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; |
1574 | unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; |
1530 | } |
1575 | } |
1531 | |
1576 | |
1532 | sub set_fontsize { |
1577 | sub set_fontsize { |
… | |
… | |
1549 | $self->{layout}->set_width ($self->{w}); |
1594 | $self->{layout}->set_width ($self->{w}); |
1550 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1595 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1551 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1596 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1552 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1597 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1553 | |
1598 | |
1554 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1599 | new_from_layout CFClient::Texture $self->{layout} |
|
|
1600 | }; |
1555 | |
1601 | |
|
|
1602 | unless (exists $self->{ox}) { |
1556 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1603 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1557 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} |
1604 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} |
1558 | : ($self->{w} - $tex->{w}) * 0.5); |
1605 | : ($self->{w} - $tex->{w}) * 0.5); |
1559 | |
1606 | |
1560 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
1607 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
1561 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} |
1608 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} |
1562 | : ($self->{h} - $tex->{h}) * 0.5); |
1609 | : ($self->{h} - $tex->{h}) * 0.5); |
1563 | |
|
|
1564 | $tex |
|
|
1565 | }; |
1610 | }; |
1566 | |
1611 | |
1567 | glEnable GL_TEXTURE_2D; |
1612 | glEnable GL_TEXTURE_2D; |
1568 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1613 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1569 | |
1614 | |
… | |
… | |
3471 | glLoadIdentity; |
3516 | glLoadIdentity; |
3472 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
3517 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
3473 | glMatrixMode GL_MODELVIEW; |
3518 | glMatrixMode GL_MODELVIEW; |
3474 | glLoadIdentity; |
3519 | glLoadIdentity; |
3475 | |
3520 | |
|
|
3521 | { |
|
|
3522 | package CFClient::UI::Base; |
|
|
3523 | |
|
|
3524 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
|
|
3525 | (0, 0, $self->{w}, $self->{h}); |
|
|
3526 | } |
|
|
3527 | |
3476 | $self->_draw; |
3528 | $self->_draw; |
3477 | } |
3529 | } |
3478 | |
3530 | |
3479 | ############################################################################# |
3531 | ############################################################################# |
3480 | |
3532 | |