… | |
… | |
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; |
… | |
… | |
439 | |
439 | |
440 | $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus |
440 | $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus |
441 | unless $FOCUS; |
441 | unless $FOCUS; |
442 | } |
442 | } |
443 | |
443 | |
444 | sub mouse_motion { } |
444 | sub mouse_motion { 0 } |
445 | sub button_up { } |
445 | sub button_up { 0 } |
446 | sub key_down { } |
446 | sub key_down { 0 } |
447 | sub key_up { } |
447 | sub key_up { 0 } |
448 | |
448 | |
449 | sub button_down { |
449 | sub button_down { |
450 | my ($self, $ev, $x, $y) = @_; |
450 | my ($self, $ev, $x, $y) = @_; |
451 | |
451 | |
452 | $self->focus_in; |
452 | $self->focus_in; |
453 | } |
|
|
454 | |
453 | |
455 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
454 | 0 |
456 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
455 | } |
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 | |
456 | |
461 | sub find_widget { |
457 | sub find_widget { |
462 | my ($self, $x, $y) = @_; |
458 | my ($self, $x, $y) = @_; |
463 | |
459 | |
464 | return () unless $self->{can_events}; |
460 | return () unless $self->{can_events}; |
… | |
… | |
526 | |
522 | |
527 | $self->realloc; |
523 | $self->realloc; |
528 | $self->update; |
524 | $self->update; |
529 | } |
525 | } |
530 | |
526 | |
|
|
527 | # using global variables seems a bit hacky, but passing through all drawing |
|
|
528 | # functions seems pointless. |
|
|
529 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
|
|
530 | |
531 | sub draw { |
531 | sub draw { |
532 | my ($self) = @_; |
532 | my ($self) = @_; |
533 | |
533 | |
534 | return unless $self->{h} && $self->{w}; |
534 | return unless $self->{h} && $self->{w}; |
|
|
535 | |
|
|
536 | # update screen rectangle |
|
|
537 | local $draw_x = $draw_x + $self->{x}; |
|
|
538 | local $draw_y = $draw_y + $self->{y}; |
|
|
539 | local $draw_w = $draw_x + $self->{w}; |
|
|
540 | local $draw_h = $draw_y + $self->{h}; |
|
|
541 | |
|
|
542 | # skip widgets that are entirely outside the drawing area |
|
|
543 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
|
|
544 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
535 | |
545 | |
536 | glPushMatrix; |
546 | glPushMatrix; |
537 | glTranslate $self->{x}, $self->{y}, 0; |
547 | glTranslate $self->{x}, $self->{y}, 0; |
538 | $self->_draw; |
548 | $self->_draw; |
539 | glPopMatrix; |
549 | glPopMatrix; |
… | |
… | |
804 | $self->SUPER::size_allocate ($w, $h); |
814 | $self->SUPER::size_allocate ($w, $h); |
805 | $self->update; |
815 | $self->update; |
806 | } |
816 | } |
807 | |
817 | |
808 | sub _render { |
818 | sub _render { |
|
|
819 | my ($self) = @_; |
|
|
820 | |
809 | $_[0]{children}[0]->draw; |
821 | $self->{children}[0]->draw; |
810 | } |
822 | } |
811 | |
823 | |
812 | sub render_child { |
824 | sub render_child { |
813 | my ($self) = @_; |
825 | my ($self) = @_; |
814 | |
826 | |
815 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
827 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
816 | glClearColor 0, 0, 0, 0; |
828 | glClearColor 0, 0, 0, 0; |
817 | glClear GL_COLOR_BUFFER_BIT; |
829 | glClear GL_COLOR_BUFFER_BIT; |
818 | |
830 | |
|
|
831 | { |
|
|
832 | package CFClient::UI::Base; |
|
|
833 | |
|
|
834 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
|
|
835 | (0, 0, $self->{w}, $self->{h}); |
|
|
836 | } |
|
|
837 | |
819 | $self->_render; |
838 | $self->_render; |
820 | }; |
839 | }; |
821 | } |
840 | } |
822 | |
841 | |
823 | sub _draw { |
842 | sub _draw { |
824 | my ($self) = @_; |
843 | my ($self) = @_; |
825 | |
844 | |
826 | my ($w, $h) = ($self->w, $self->h); |
845 | my ($w, $h) = @$self{qw(w h)}; |
827 | |
846 | |
828 | my $tex = $self->{texture} |
847 | my $tex = $self->{texture} |
829 | or return; |
848 | or return; |
830 | |
849 | |
831 | glEnable GL_TEXTURE_2D; |
850 | glEnable GL_TEXTURE_2D; |
… | |
… | |
913 | } |
932 | } |
914 | } |
933 | } |
915 | |
934 | |
916 | sub _render { |
935 | sub _render { |
917 | my ($self) = @_; |
936 | my ($self) = @_; |
|
|
937 | |
|
|
938 | local $CFClient::UI::Base::draw_x = $CFClient::UI::Base::draw_x - $self->{view_x}; |
|
|
939 | local $CFClient::UI::Base::draw_y = $CFClient::UI::Base::draw_y - $self->{view_y}; |
918 | |
940 | |
919 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
941 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
920 | |
942 | |
921 | $self->SUPER::_render; |
943 | $self->SUPER::_render; |
922 | } |
944 | } |
… | |
… | |
1030 | my @border = |
1052 | my @border = |
1031 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1053 | 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); |
1054 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1033 | |
1055 | |
1034 | sub new { |
1056 | sub new { |
1035 | my $class = shift; |
1057 | my ($class, %arg) = @_; |
|
|
1058 | |
|
|
1059 | my $title = delete $arg{title}; |
1036 | |
1060 | |
1037 | my $self = $class->SUPER::new ( |
1061 | my $self = $class->SUPER::new ( |
1038 | bg => [1, 1, 1, 1], |
1062 | bg => [1, 1, 1, 1], |
1039 | border_bg => [1, 1, 1, 1], |
1063 | border_bg => [1, 1, 1, 1], |
1040 | border => 0.6, |
1064 | border => 0.6, |
1041 | can_events => 1, |
1065 | can_events => 1, |
1042 | min_w => 16, |
1066 | min_w => 16, |
1043 | min_h => 16, |
1067 | min_h => 16, |
1044 | @_ |
1068 | %arg, |
1045 | ); |
1069 | ); |
1046 | |
1070 | |
1047 | $self->{title} &&= new CFClient::UI::Label |
1071 | $self->{title} = new CFClient::UI::Label |
1048 | align => 0, |
1072 | align => 0, |
1049 | valign => 1, |
1073 | valign => 1, |
1050 | text => $self->{title}, |
1074 | text => $title, |
1051 | fontsize => $self->{border}; |
1075 | fontsize => $self->{border} |
|
|
1076 | if defined $title; |
1052 | |
1077 | |
1053 | $self |
1078 | $self |
|
|
1079 | } |
|
|
1080 | |
|
|
1081 | sub add { |
|
|
1082 | my ($self, @widgets) = @_; |
|
|
1083 | |
|
|
1084 | $self->SUPER::add (@widgets); |
|
|
1085 | $self->CFClient::UI::Container::add ($self->{title}) if $self->{title}; |
1054 | } |
1086 | } |
1055 | |
1087 | |
1056 | sub border { |
1088 | sub border { |
1057 | int $_[0]{border} * $::FONTSIZE |
1089 | int $_[0]{border} * $::FONTSIZE |
1058 | } |
1090 | } |
1059 | |
1091 | |
1060 | sub size_request { |
1092 | sub size_request { |
1061 | my ($self) = @_; |
1093 | my ($self) = @_; |
|
|
1094 | |
|
|
1095 | $self->{title}->size_request |
|
|
1096 | if $self->{title}; |
1062 | |
1097 | |
1063 | my ($w, $h) = $self->SUPER::size_request; |
1098 | my ($w, $h) = $self->SUPER::size_request; |
1064 | |
1099 | |
1065 | ( |
1100 | ( |
1066 | $w + $self->border * 2, |
1101 | $w + $self->border * 2, |
… | |
… | |
1069 | } |
1104 | } |
1070 | |
1105 | |
1071 | sub size_allocate { |
1106 | sub size_allocate { |
1072 | my ($self, $w, $h) = @_; |
1107 | my ($self, $w, $h) = @_; |
1073 | |
1108 | |
|
|
1109 | if ($self->{title}) { |
|
|
1110 | $self->{title}{w} = $w; |
|
|
1111 | $self->{title}{h} = $h; |
|
|
1112 | $self->{title}->size_allocate ($w, $h); |
|
|
1113 | } |
|
|
1114 | |
|
|
1115 | my $border = $self->border; |
|
|
1116 | |
1074 | $h -= List::Util::max 0, $self->border * 2; |
1117 | $h -= List::Util::max 0, $border * 2; |
1075 | $w -= List::Util::max 0, $self->border * 2; |
1118 | $w -= List::Util::max 0, $border * 2; |
1076 | |
1119 | |
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); |
1120 | $self->child->configure ($border, $border, $w, $h); |
1081 | } |
1121 | } |
1082 | |
1122 | |
1083 | sub button_down { |
1123 | sub button_down { |
1084 | my ($self, $ev, $x, $y) = @_; |
1124 | my ($self, $ev, $x, $y) = @_; |
1085 | |
1125 | |
… | |
… | |
1119 | |
1159 | |
1120 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1160 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1121 | |
1161 | |
1122 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1162 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1123 | }; |
1163 | }; |
|
|
1164 | } else { |
|
|
1165 | return 0; |
|
|
1166 | } |
|
|
1167 | |
1124 | } |
1168 | 1 |
1125 | } |
1169 | } |
1126 | |
1170 | |
1127 | sub button_up { |
1171 | sub button_up { |
1128 | my ($self, $ev, $x, $y) = @_; |
1172 | my ($self, $ev, $x, $y) = @_; |
1129 | |
1173 | |
1130 | delete $self->{motion}; |
1174 | !!delete $self->{motion} |
1131 | } |
1175 | } |
1132 | |
1176 | |
1133 | sub mouse_motion { |
1177 | sub mouse_motion { |
1134 | my ($self, $ev, $x, $y) = @_; |
1178 | my ($self, $ev, $x, $y) = @_; |
1135 | |
1179 | |
1136 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
1180 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1181 | |
|
|
1182 | !!$self->{motion} |
1137 | } |
1183 | } |
1138 | |
1184 | |
1139 | sub _draw { |
1185 | sub _draw { |
1140 | my ($self) = @_; |
1186 | my ($self) = @_; |
1141 | |
1187 | |
|
|
1188 | my $child = $self->{children}[0]; |
|
|
1189 | |
1142 | my ($w, $h ) = ($self->{w}, $self->{h}); |
1190 | my ($w, $h ) = ($self->{w}, $self->{h}); |
1143 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
1191 | my ($cw, $ch) = ($child->{w}, $child->{h}); |
1144 | |
1192 | |
1145 | glEnable GL_TEXTURE_2D; |
1193 | glEnable GL_TEXTURE_2D; |
1146 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1194 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1147 | |
1195 | |
1148 | my $border = $self->border; |
1196 | my $border = $self->border; |
… | |
… | |
1163 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
1211 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
1164 | } |
1212 | } |
1165 | |
1213 | |
1166 | glDisable GL_TEXTURE_2D; |
1214 | glDisable GL_TEXTURE_2D; |
1167 | |
1215 | |
1168 | $self->{title}->draw if $self->{title}; |
|
|
1169 | |
|
|
1170 | $self->child->draw; |
1216 | $child->draw; |
|
|
1217 | |
|
|
1218 | if ($self->{title}) { |
|
|
1219 | glTranslate 0, $border - $self->{h}; |
|
|
1220 | $self->{title}->_draw; |
|
|
1221 | } |
1171 | } |
1222 | } |
1172 | |
1223 | |
1173 | ############################################################################# |
1224 | ############################################################################# |
1174 | |
1225 | |
1175 | package CFClient::UI::Table; |
1226 | package CFClient::UI::Table; |
… | |
… | |
1523 | } |
1574 | } |
1524 | |
1575 | |
1525 | sub size_allocate { |
1576 | sub size_allocate { |
1526 | my ($self, $w, $h) = @_; |
1577 | my ($self, $w, $h) = @_; |
1527 | |
1578 | |
|
|
1579 | delete $self->{ox}; |
|
|
1580 | |
1528 | delete $self->{texture} |
1581 | delete $self->{texture} |
1529 | unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; |
1582 | unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; |
1530 | } |
1583 | } |
1531 | |
1584 | |
1532 | sub set_fontsize { |
1585 | sub set_fontsize { |
… | |
… | |
1549 | $self->{layout}->set_width ($self->{w}); |
1602 | $self->{layout}->set_width ($self->{w}); |
1550 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1603 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1551 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1604 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1552 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1605 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1553 | |
1606 | |
1554 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1607 | new_from_layout CFClient::Texture $self->{layout} |
|
|
1608 | }; |
1555 | |
1609 | |
|
|
1610 | unless (exists $self->{ox}) { |
1556 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1611 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1557 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} |
1612 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} |
1558 | : ($self->{w} - $tex->{w}) * 0.5); |
1613 | : ($self->{w} - $tex->{w}) * 0.5); |
1559 | |
1614 | |
1560 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
1615 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
1561 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} |
1616 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} |
1562 | : ($self->{h} - $tex->{h}) * 0.5); |
1617 | : ($self->{h} - $tex->{h}) * 0.5); |
1563 | |
|
|
1564 | $tex |
|
|
1565 | }; |
1618 | }; |
1566 | |
1619 | |
1567 | glEnable GL_TEXTURE_2D; |
1620 | glEnable GL_TEXTURE_2D; |
1568 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1621 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1569 | |
1622 | |
… | |
… | |
1664 | $self->{cursor} = length $text; |
1717 | $self->{cursor} = length $text; |
1665 | } elsif ($uni == 27) { |
1718 | } elsif ($uni == 27) { |
1666 | $self->_emit ('escape'); |
1719 | $self->_emit ('escape'); |
1667 | } elsif ($uni) { |
1720 | } elsif ($uni) { |
1668 | substr $text, $self->{cursor}++, 0, chr $uni; |
1721 | substr $text, $self->{cursor}++, 0, chr $uni; |
|
|
1722 | } else { |
|
|
1723 | return 0; |
1669 | } |
1724 | } |
1670 | |
1725 | |
1671 | $self->_set_text ($text); |
1726 | $self->_set_text ($text); |
1672 | |
1727 | |
1673 | $self->realloc; |
1728 | $self->realloc; |
|
|
1729 | |
|
|
1730 | 1 |
1674 | } |
1731 | } |
1675 | |
1732 | |
1676 | sub focus_in { |
1733 | sub focus_in { |
1677 | my ($self) = @_; |
1734 | my ($self) = @_; |
1678 | |
1735 | |
… | |
… | |
1693 | utf8::encode $text; |
1750 | utf8::encode $text; |
1694 | $self->{cursor} = length substr $text, 0, $idx; |
1751 | $self->{cursor} = length substr $text, 0, $idx; |
1695 | |
1752 | |
1696 | $self->_set_text ($self->{text}); |
1753 | $self->_set_text ($self->{text}); |
1697 | $self->update; |
1754 | $self->update; |
|
|
1755 | |
|
|
1756 | 1 |
1698 | } |
1757 | } |
1699 | |
1758 | |
1700 | sub mouse_motion { |
1759 | sub mouse_motion { |
1701 | my ($self, $ev, $x, $y) = @_; |
1760 | my ($self, $ev, $x, $y) = @_; |
1702 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
1761 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
|
|
1762 | |
|
|
1763 | 0 |
1703 | } |
1764 | } |
1704 | |
1765 | |
1705 | sub _draw { |
1766 | sub _draw { |
1706 | my ($self) = @_; |
1767 | my ($self) = @_; |
1707 | |
1768 | |
… | |
… | |
1784 | } else { |
1845 | } else { |
1785 | $self->set_text ($self->{history_saveback}); |
1846 | $self->set_text ($self->{history_saveback}); |
1786 | } |
1847 | } |
1787 | |
1848 | |
1788 | } else { |
1849 | } else { |
1789 | $self->SUPER::key_down ($ev); |
1850 | return $self->SUPER::key_down ($ev) |
|
|
1851 | } |
|
|
1852 | |
1790 | } |
1853 | 1 |
1791 | |
|
|
1792 | } |
1854 | } |
1793 | |
1855 | |
1794 | ############################################################################# |
1856 | ############################################################################# |
1795 | |
1857 | |
1796 | package CFClient::UI::Button; |
1858 | package CFClient::UI::Button; |
… | |
… | |
1825 | my ($self, $ev, $x, $y) = @_; |
1887 | my ($self, $ev, $x, $y) = @_; |
1826 | |
1888 | |
1827 | $self->emit ("activate") |
1889 | $self->emit ("activate") |
1828 | if $x >= 0 && $x < $self->{w} |
1890 | if $x >= 0 && $x < $self->{w} |
1829 | && $y >= 0 && $y < $self->{h}; |
1891 | && $y >= 0 && $y < $self->{h}; |
|
|
1892 | |
|
|
1893 | 1 |
1830 | } |
1894 | } |
1831 | |
1895 | |
1832 | sub _draw { |
1896 | sub _draw { |
1833 | my ($self) = @_; |
1897 | my ($self) = @_; |
1834 | |
1898 | |
… | |
… | |
1888 | |
1952 | |
1889 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1953 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1890 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1954 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1891 | $self->{state} = !$self->{state}; |
1955 | $self->{state} = !$self->{state}; |
1892 | $self->_emit (changed => $self->{state}); |
1956 | $self->_emit (changed => $self->{state}); |
|
|
1957 | } else { |
|
|
1958 | return 0 |
|
|
1959 | } |
|
|
1960 | |
1893 | } |
1961 | 1 |
1894 | } |
1962 | } |
1895 | |
1963 | |
1896 | sub _draw { |
1964 | sub _draw { |
1897 | my ($self) = @_; |
1965 | my ($self) = @_; |
1898 | |
1966 | |
… | |
… | |
2236 | |
2304 | |
2237 | $self->SUPER::button_down ($ev, $x, $y); |
2305 | $self->SUPER::button_down ($ev, $x, $y); |
2238 | |
2306 | |
2239 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2307 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2240 | |
2308 | |
2241 | $self->mouse_motion ($ev, $x, $y); |
2309 | $self->mouse_motion ($ev, $x, $y) |
2242 | } |
2310 | } |
2243 | |
2311 | |
2244 | sub mouse_motion { |
2312 | sub mouse_motion { |
2245 | my ($self, $ev, $x, $y) = @_; |
2313 | my ($self, $ev, $x, $y) = @_; |
2246 | |
2314 | |
… | |
… | |
2250 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2318 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2251 | |
2319 | |
2252 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2320 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2253 | |
2321 | |
2254 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
2322 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
|
|
2323 | } else { |
|
|
2324 | return 0; |
|
|
2325 | } |
|
|
2326 | |
2255 | } |
2327 | 1 |
2256 | } |
2328 | } |
2257 | |
2329 | |
2258 | sub update { |
2330 | sub update { |
2259 | my ($self) = @_; |
2331 | my ($self) = @_; |
2260 | |
2332 | |
… | |
… | |
2838 | my ($self, $ev, $x, $y) = @_; |
2910 | my ($self, $ev, $x, $y) = @_; |
2839 | |
2911 | |
2840 | # TODO: should use vbox->find_widget or so |
2912 | # TODO: should use vbox->find_widget or so |
2841 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2913 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2842 | $self->{hover} = $self->{item}{$HOVER}; |
2914 | $self->{hover} = $self->{item}{$HOVER}; |
|
|
2915 | |
|
|
2916 | 0 |
2843 | } |
2917 | } |
2844 | |
2918 | |
2845 | sub button_up { |
2919 | sub button_up { |
2846 | my ($self, $ev, $x, $y) = @_; |
2920 | my ($self, $ev, $x, $y) = @_; |
2847 | |
2921 | |
… | |
… | |
2849 | undef $GRAB; |
2923 | undef $GRAB; |
2850 | $self->hide; |
2924 | $self->hide; |
2851 | |
2925 | |
2852 | $self->_emit ("popdown"); |
2926 | $self->_emit ("popdown"); |
2853 | $self->{hover}[1]->() if $self->{hover}; |
2927 | $self->{hover}[1]->() if $self->{hover}; |
|
|
2928 | } else { |
|
|
2929 | return 0 |
|
|
2930 | } |
|
|
2931 | |
2854 | } |
2932 | 1 |
2855 | } |
2933 | } |
2856 | |
2934 | |
2857 | ############################################################################# |
2935 | ############################################################################# |
2858 | |
2936 | |
2859 | package CFClient::UI::Statusbox; |
2937 | package CFClient::UI::Statusbox; |
… | |
… | |
3106 | $rec = $::CONN->stop_record if $::CONN; |
3184 | $rec = $::CONN->stop_record if $::CONN; |
3107 | return unless ref $rec eq 'ARRAY'; |
3185 | return unless ref $rec eq 'ARRAY'; |
3108 | $self->set_command_list ($rec); |
3186 | $self->set_command_list ($rec); |
3109 | } |
3187 | } |
3110 | |
3188 | |
3111 | # if $commit is true, the binding will be set after the user entered a key combo |
3189 | |
|
|
3190 | sub ask_for_bind_and_commit { |
|
|
3191 | my ($self) = @_; |
|
|
3192 | $self->ask_for_bind (1); |
|
|
3193 | } |
|
|
3194 | |
3112 | sub ask_for_bind { |
3195 | sub ask_for_bind { |
3113 | my ($self, $commit) = @_; |
3196 | my ($self, $commit) = @_; |
3114 | |
3197 | |
3115 | CFClient::Binder::open_binding_dialog (sub { |
3198 | CFClient::Binder::open_binding_dialog (sub { |
3116 | my ($mod, $sym) = @_; |
3199 | my ($mod, $sym) = @_; |
… | |
… | |
3471 | glLoadIdentity; |
3554 | glLoadIdentity; |
3472 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
3555 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
3473 | glMatrixMode GL_MODELVIEW; |
3556 | glMatrixMode GL_MODELVIEW; |
3474 | glLoadIdentity; |
3557 | glLoadIdentity; |
3475 | |
3558 | |
|
|
3559 | { |
|
|
3560 | package CFClient::UI::Base; |
|
|
3561 | |
|
|
3562 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
|
|
3563 | (0, 0, $self->{w}, $self->{h}); |
|
|
3564 | } |
|
|
3565 | |
3476 | $self->_draw; |
3566 | $self->_draw; |
3477 | } |
3567 | } |
3478 | |
3568 | |
3479 | ############################################################################# |
3569 | ############################################################################# |
3480 | |
3570 | |