… | |
… | |
137 | |
137 | |
138 | sub new { |
138 | sub new { |
139 | my $class = shift; |
139 | my $class = shift; |
140 | |
140 | |
141 | my $self = bless { |
141 | my $self = bless { |
142 | x => 0, |
142 | x => 0, |
143 | y => 0, |
143 | y => 0, |
144 | z => 0, |
144 | z => 0, |
145 | can_events => 1, |
145 | can_events => 1, |
146 | @_ |
146 | @_ |
147 | }, $class; |
147 | }, $class; |
148 | |
148 | |
149 | for (keys %$self) { |
149 | for (keys %$self) { |
… | |
… | |
236 | |
236 | |
237 | sub size_allocate { |
237 | sub size_allocate { |
238 | # nothing to be done |
238 | # nothing to be done |
239 | } |
239 | } |
240 | |
240 | |
|
|
241 | sub children { |
|
|
242 | } |
|
|
243 | |
241 | sub set_max_size { |
244 | sub set_max_size { |
242 | my ($self, $w, $h) = @_; |
245 | my ($self, $w, $h) = @_; |
243 | |
246 | |
244 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
247 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
245 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
248 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
246 | } |
249 | } |
247 | |
250 | |
248 | # return top left coordinates |
251 | # return top left coordinates |
249 | sub _topleft { |
252 | sub _topleft { |
250 | my ($self, $x, $y) = @_; |
253 | my ($self, $x, $y) = @_; |
|
|
254 | |
|
|
255 | $self->{parent} |
|
|
256 | or Carp::confess "no parent widget in _topleft\n";#d# |
251 | |
257 | |
252 | $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); |
258 | $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); |
253 | } |
259 | } |
254 | |
260 | |
255 | # translate global coordinates to local coordinate system |
261 | # translate global coordinates to local coordinate system |
… | |
… | |
492 | sub new { |
498 | sub new { |
493 | my ($class, %arg) = @_; |
499 | my ($class, %arg) = @_; |
494 | |
500 | |
495 | my $children = delete $arg{children} || []; |
501 | my $children = delete $arg{children} || []; |
496 | |
502 | |
497 | my $self = $class->SUPER::new (children => [], can_events => 0, %arg); |
503 | my $self = $class->SUPER::new ( |
|
|
504 | children => [], |
|
|
505 | can_events => 0, |
|
|
506 | %arg, |
|
|
507 | ); |
498 | $self->add ($_) for @$children; |
508 | $self->add ($_) for @$children; |
499 | |
509 | |
500 | $self |
510 | $self |
501 | } |
511 | } |
502 | |
512 | |
… | |
… | |
511 | sort { $a->{z} <=> $b->{z} } |
521 | sort { $a->{z} <=> $b->{z} } |
512 | @{$self->{children}}, $child |
522 | @{$self->{children}}, $child |
513 | ]; |
523 | ]; |
514 | |
524 | |
515 | $child->check_size; |
525 | $child->check_size; |
|
|
526 | } |
|
|
527 | |
|
|
528 | sub children { |
|
|
529 | @{ $_[0]{children} } |
516 | } |
530 | } |
517 | |
531 | |
518 | sub remove { |
532 | sub remove { |
519 | my ($self, $child) = @_; |
533 | my ($self, $child) = @_; |
520 | |
534 | |
… | |
… | |
748 | my $class = shift; |
762 | my $class = shift; |
749 | |
763 | |
750 | # TODO: user_x, user_y, overwrite moveto? |
764 | # TODO: user_x, user_y, overwrite moveto? |
751 | |
765 | |
752 | my $self = $class->SUPER::new ( |
766 | my $self = $class->SUPER::new ( |
753 | bg => [1, 1, 1, 1], |
767 | bg => [1, 1, 1, 1], |
754 | border_bg => [1, 1, 1, 1], |
768 | border_bg => [1, 1, 1, 1], |
755 | border => 0.8, |
769 | border => 0.8, |
756 | can_events => 1, |
770 | can_events => 1, |
757 | @_ |
771 | @_ |
758 | ); |
772 | ); |
759 | |
773 | |
760 | $self->{title} &&= new CFClient::UI::Label |
774 | $self->{title} &&= new CFClient::UI::Label |
… | |
… | |
908 | $self->{children}[$y][$x] = $child; |
922 | $self->{children}[$y][$x] = $child; |
909 | |
923 | |
910 | $child->check_size; |
924 | $child->check_size; |
911 | } |
925 | } |
912 | |
926 | |
|
|
927 | sub children { |
|
|
928 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
929 | } |
|
|
930 | |
913 | # TODO: move to container class maybe? send childs a signal on removal? |
931 | # TODO: move to container class maybe? send childs a signal on removal? |
914 | sub clear { |
932 | sub clear { |
915 | my ($self) = @_; |
933 | my ($self) = @_; |
916 | |
934 | |
917 | my $children = delete $self->{children}; |
935 | my @children = $self->children; |
|
|
936 | delete $self->{children}; |
918 | |
937 | |
919 | for (grep $_, map @$_, grep $_, @$children) { |
938 | for (@children) { |
920 | delete $_->{parent}; |
939 | delete $_->{parent}; |
921 | $_->hide; |
940 | $_->hide; |
922 | } |
941 | } |
923 | |
942 | |
924 | $self->update; |
943 | $self->update; |
… | |
… | |
1151 | |
1170 | |
1152 | sub new { |
1171 | sub new { |
1153 | my ($class, %arg) = @_; |
1172 | my ($class, %arg) = @_; |
1154 | |
1173 | |
1155 | my $self = $class->SUPER::new ( |
1174 | my $self = $class->SUPER::new ( |
1156 | fg => [1, 1, 1], |
1175 | fg => [1, 1, 1], |
1157 | #font => default_font |
1176 | #font => default_font |
1158 | fontsize => 1, |
1177 | fontsize => 1, |
1159 | text => "", |
1178 | text => "", |
1160 | align => -1, |
1179 | align => -1, |
1161 | valign => -1, |
1180 | valign => -1, |
1162 | padding => 2, |
1181 | padding => 2, |
1163 | layout => new CFClient::Layout, |
1182 | layout => new CFClient::Layout, |
1164 | can_events => 0, |
1183 | can_events => 0, |
1165 | %arg |
1184 | %arg |
1166 | ); |
1185 | ); |
1167 | |
1186 | |
1168 | if (exists $self->{template}) { |
1187 | if (exists $self->{template}) { |
… | |
… | |
1292 | |
1311 | |
1293 | sub new { |
1312 | sub new { |
1294 | my $class = shift; |
1313 | my $class = shift; |
1295 | |
1314 | |
1296 | $class->SUPER::new ( |
1315 | $class->SUPER::new ( |
1297 | fg => [1, 1, 1], |
1316 | fg => [1, 1, 1], |
1298 | bg => [0, 0, 0, 0.2], |
1317 | bg => [0, 0, 0, 0.2], |
1299 | active_bg => [1, 1, 1, 0.5], |
1318 | active_bg => [1, 1, 1, 0.5], |
1300 | active_fg => [0, 0, 0], |
1319 | active_fg => [0, 0, 0], |
1301 | can_hover => 1, |
1320 | can_hover => 1, |
1302 | can_focus => 1, |
1321 | can_focus => 1, |
1303 | valign => 0, |
1322 | valign => 0, |
1304 | can_events => 1, |
1323 | can_events => 1, |
1305 | @_ |
1324 | @_ |
1306 | ) |
1325 | ) |
1307 | } |
1326 | } |
1308 | |
1327 | |
… | |
… | |
1462 | my ($self, $ev) = @_; |
1481 | my ($self, $ev) = @_; |
1463 | |
1482 | |
1464 | my $sym = $ev->{sym}; |
1483 | my $sym = $ev->{sym}; |
1465 | |
1484 | |
1466 | if ($sym == 13) { |
1485 | if ($sym == 13) { |
|
|
1486 | unshift @{$self->{history}}, |
|
|
1487 | my $txt = $self->get_text; |
|
|
1488 | $self->{history_pointer} = -1; |
|
|
1489 | $self->{history_saveback} = ''; |
1467 | $self->emit (activate => $self->get_text); |
1490 | $self->emit (activate => $txt); |
1468 | $self->update; |
1491 | $self->update; |
|
|
1492 | |
|
|
1493 | } elsif ($sym == CFClient::SDLK_UP) { |
|
|
1494 | if ($self->{history_pointer} < 0) { |
|
|
1495 | $self->{history_saveback} = $self->get_text; |
|
|
1496 | } |
|
|
1497 | if (@{$self->{history} || []} > 0) { |
|
|
1498 | $self->{history_pointer}++; |
|
|
1499 | if ($self->{history_pointer} >= @{$self->{history} || []}) { |
|
|
1500 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
|
|
1501 | } |
|
|
1502 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
|
|
1503 | } |
|
|
1504 | |
|
|
1505 | } elsif ($sym == CFClient::SDLK_DOWN) { |
|
|
1506 | $self->{history_pointer}--; |
|
|
1507 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
|
|
1508 | |
|
|
1509 | if ($self->{history_pointer} >= 0) { |
|
|
1510 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
|
|
1511 | } else { |
|
|
1512 | $self->set_text ($self->{history_saveback}); |
|
|
1513 | } |
1469 | |
1514 | |
1470 | } else { |
1515 | } else { |
1471 | $self->SUPER::key_down ($ev); |
1516 | $self->SUPER::key_down ($ev); |
1472 | } |
1517 | } |
1473 | |
1518 | |
… | |
… | |
1487 | |
1532 | |
1488 | sub new { |
1533 | sub new { |
1489 | my $class = shift; |
1534 | my $class = shift; |
1490 | |
1535 | |
1491 | $class->SUPER::new ( |
1536 | $class->SUPER::new ( |
1492 | padding => 4, |
1537 | padding => 4, |
1493 | fg => [1, 1, 1], |
1538 | fg => [1, 1, 1], |
1494 | bg => [1, 1, 1, 0.2], |
1539 | bg => [1, 1, 1, 0.2], |
1495 | active_fg => [0, 0, 1], |
1540 | active_fg => [0, 0, 1], |
1496 | can_hover => 1, |
1541 | can_hover => 1, |
1497 | align => 0, |
1542 | align => 0, |
1498 | valign => 0, |
1543 | valign => 0, |
1499 | can_events => 1, |
1544 | can_events => 1, |
1500 | @_ |
1545 | @_ |
1501 | ) |
1546 | ) |
1502 | } |
1547 | } |
1503 | |
1548 | |
… | |
… | |
1794 | |
1839 | |
1795 | sub new { |
1840 | sub new { |
1796 | my ($class, %arg) = @_; |
1841 | my ($class, %arg) = @_; |
1797 | |
1842 | |
1798 | my $self = $class->SUPER::new ( |
1843 | my $self = $class->SUPER::new ( |
1799 | tooltip => $arg{type}, |
1844 | tooltip => $arg{type}, |
|
|
1845 | can_hover => 1, |
1800 | can_events => 1, |
1846 | can_events => 1, |
1801 | can_hover => 1, |
|
|
1802 | %arg, |
1847 | %arg, |
1803 | ); |
1848 | ); |
1804 | |
1849 | |
1805 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1850 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1806 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
1851 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
… | |
… | |
1978 | |
2023 | |
1979 | sub new { |
2024 | sub new { |
1980 | my $class = shift; |
2025 | my $class = shift; |
1981 | |
2026 | |
1982 | my $self = $class->SUPER::new ( |
2027 | my $self = $class->SUPER::new ( |
1983 | fontsize => 1, |
2028 | fontsize => 1, |
|
|
2029 | can_events => 0, |
1984 | #font => default_font |
2030 | #font => default_font |
1985 | @_, |
2031 | @_, |
1986 | |
2032 | |
1987 | layout => (new CFClient::Layout), |
2033 | layout => (new CFClient::Layout), |
1988 | par => [], |
2034 | par => [], |
1989 | height => 0, |
2035 | height => 0, |
1990 | children => [ |
2036 | children => [ |
1991 | (new CFClient::UI::Empty expand => 1), |
2037 | (new CFClient::UI::Empty expand => 1), |
1992 | (new CFClient::UI::Slider vertical => 1), |
2038 | (new CFClient::UI::Slider vertical => 1), |
1993 | ], |
2039 | ], |
1994 | ); |
2040 | ); |
1995 | |
2041 | |
… | |
… | |
2120 | my ($self) = @_; |
2166 | my ($self) = @_; |
2121 | |
2167 | |
2122 | if ($self->{texture}) { |
2168 | if ($self->{texture}) { |
2123 | glEnable GL_TEXTURE_2D; |
2169 | glEnable GL_TEXTURE_2D; |
2124 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2170 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2171 | glColor 1, 1, 1, 1; |
2125 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
2172 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
2126 | glDisable GL_TEXTURE_2D; |
2173 | glDisable GL_TEXTURE_2D; |
2127 | } |
2174 | } |
2128 | |
2175 | |
2129 | $self->{children}[1]->draw; |
2176 | $self->{children}[1]->draw; |
… | |
… | |
2180 | |
2227 | |
2181 | sub new { |
2228 | sub new { |
2182 | my $class = shift; |
2229 | my $class = shift; |
2183 | |
2230 | |
2184 | my $self = $class->SUPER::new ( |
2231 | my $self = $class->SUPER::new ( |
2185 | state => 0, |
2232 | state => 0, |
2186 | connect_activate => \&toggle_flopper, |
2233 | connect_activate => \&toggle_flopper, |
2187 | can_events => 1, |
|
|
2188 | @_ |
2234 | @_ |
2189 | ); |
2235 | ); |
2190 | |
2236 | |
2191 | if ($self->{state}) { |
2237 | if ($self->{state}) { |
2192 | $self->{state} = 0; |
2238 | $self->{state} = 0; |