… | |
… | |
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 | |
|
|
244 | # call when resoltuion changes etc. |
|
|
245 | sub reconfigure { |
|
|
246 | my ($self) = @_; |
|
|
247 | |
|
|
248 | $_->reconfigure |
|
|
249 | for $self->children; |
|
|
250 | |
|
|
251 | $_->check_size; |
|
|
252 | } |
|
|
253 | |
241 | sub set_max_size { |
254 | sub set_max_size { |
242 | my ($self, $w, $h) = @_; |
255 | my ($self, $w, $h) = @_; |
243 | |
256 | |
244 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
257 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
245 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
258 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
246 | } |
259 | } |
247 | |
260 | |
248 | # return top left coordinates |
261 | # return top left coordinates |
249 | sub _topleft { |
262 | sub _topleft { |
250 | my ($self, $x, $y) = @_; |
263 | my ($self, $x, $y) = @_; |
|
|
264 | |
|
|
265 | $self->{parent} |
|
|
266 | or Carp::confess "no parent widget in _topleft\n";#d# |
251 | |
267 | |
252 | $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); |
268 | $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); |
253 | } |
269 | } |
254 | |
270 | |
255 | # translate global coordinates to local coordinate system |
271 | # translate global coordinates to local coordinate system |
… | |
… | |
492 | sub new { |
508 | sub new { |
493 | my ($class, %arg) = @_; |
509 | my ($class, %arg) = @_; |
494 | |
510 | |
495 | my $children = delete $arg{children} || []; |
511 | my $children = delete $arg{children} || []; |
496 | |
512 | |
497 | my $self = $class->SUPER::new (children => [], can_events => 0, %arg); |
513 | my $self = $class->SUPER::new ( |
|
|
514 | children => [], |
|
|
515 | can_events => 0, |
|
|
516 | %arg, |
|
|
517 | ); |
498 | $self->add ($_) for @$children; |
518 | $self->add ($_) for @$children; |
499 | |
519 | |
500 | $self |
520 | $self |
501 | } |
521 | } |
502 | |
522 | |
… | |
… | |
511 | sort { $a->{z} <=> $b->{z} } |
531 | sort { $a->{z} <=> $b->{z} } |
512 | @{$self->{children}}, $child |
532 | @{$self->{children}}, $child |
513 | ]; |
533 | ]; |
514 | |
534 | |
515 | $child->check_size; |
535 | $child->check_size; |
|
|
536 | } |
|
|
537 | |
|
|
538 | sub children { |
|
|
539 | @{ $_[0]{children} } |
516 | } |
540 | } |
517 | |
541 | |
518 | sub remove { |
542 | sub remove { |
519 | my ($self, $child) = @_; |
543 | my ($self, $child) = @_; |
520 | |
544 | |
… | |
… | |
751 | |
775 | |
752 | my $self = $class->SUPER::new ( |
776 | my $self = $class->SUPER::new ( |
753 | bg => [1, 1, 1, 1], |
777 | bg => [1, 1, 1, 1], |
754 | border_bg => [1, 1, 1, 1], |
778 | border_bg => [1, 1, 1, 1], |
755 | border => 0.8, |
779 | border => 0.8, |
756 | can_events => 0, |
780 | can_events => 1, |
757 | @_ |
781 | @_ |
758 | ); |
782 | ); |
759 | |
783 | |
760 | $self->{title} &&= new CFClient::UI::Label |
784 | $self->{title} &&= new CFClient::UI::Label |
761 | align => 0, |
785 | align => 0, |
… | |
… | |
908 | $self->{children}[$y][$x] = $child; |
932 | $self->{children}[$y][$x] = $child; |
909 | |
933 | |
910 | $child->check_size; |
934 | $child->check_size; |
911 | } |
935 | } |
912 | |
936 | |
|
|
937 | sub children { |
|
|
938 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
939 | } |
|
|
940 | |
913 | # TODO: move to container class maybe? send childs a signal on removal? |
941 | # TODO: move to container class maybe? send childs a signal on removal? |
914 | sub clear { |
942 | sub clear { |
915 | my ($self) = @_; |
943 | my ($self) = @_; |
916 | |
944 | |
917 | my $children = delete $self->{children}; |
945 | my @children = $self->children; |
|
|
946 | delete $self->{children}; |
918 | |
947 | |
919 | for (grep $_, map @$_, grep $_, @$children) { |
948 | for (@children) { |
920 | delete $_->{parent}; |
949 | delete $_->{parent}; |
921 | $_->hide; |
950 | $_->hide; |
922 | } |
951 | } |
923 | |
952 | |
924 | $self->update; |
953 | $self->update; |
… | |
… | |
1185 | s/</</g; |
1214 | s/</</g; |
1186 | |
1215 | |
1187 | $_[1] |
1216 | $_[1] |
1188 | } |
1217 | } |
1189 | |
1218 | |
|
|
1219 | sub update { |
|
|
1220 | my ($self) = @_; |
|
|
1221 | |
|
|
1222 | delete $self->{texture}; |
|
|
1223 | $self->SUPER::update; |
|
|
1224 | } |
|
|
1225 | |
|
|
1226 | sub reconfigure { |
|
|
1227 | my ($self) = @_; |
|
|
1228 | |
|
|
1229 | delete $self->{texture}; |
|
|
1230 | } |
|
|
1231 | |
1190 | sub set_text { |
1232 | sub set_text { |
1191 | my ($self, $text) = @_; |
1233 | my ($self, $text) = @_; |
1192 | |
1234 | |
|
|
1235 | return if $self->{text} eq "T$text"; |
|
|
1236 | $self->{text} = "T$text"; |
|
|
1237 | |
1193 | $self->{layout}->set_text ($text); |
1238 | $self->{layout}->set_text ($text); |
1194 | |
1239 | |
1195 | delete $self->{texture}; |
1240 | delete $self->{texture}; |
|
|
1241 | $self->update; |
1196 | $self->check_size; |
1242 | $self->check_size; |
1197 | $self->update; |
|
|
1198 | } |
1243 | } |
1199 | |
1244 | |
1200 | sub set_markup { |
1245 | sub set_markup { |
1201 | my ($self, $markup) = @_; |
1246 | my ($self, $markup) = @_; |
1202 | |
1247 | |
|
|
1248 | return if $self->{text} eq "M$markup"; |
|
|
1249 | $self->{text} = "M$markup"; |
|
|
1250 | |
1203 | $self->{layout}->set_markup ($markup); |
1251 | $self->{layout}->set_markup ($markup); |
1204 | |
1252 | |
1205 | delete $self->{texture}; |
1253 | delete $self->{texture}; |
|
|
1254 | $self->update; |
1206 | $self->check_size; |
1255 | $self->check_size; |
1207 | $self->update; |
|
|
1208 | } |
1256 | } |
1209 | |
1257 | |
1210 | sub size_request { |
1258 | sub size_request { |
1211 | my ($self) = @_; |
1259 | my ($self) = @_; |
1212 | |
1260 | |
… | |
… | |
1462 | my ($self, $ev) = @_; |
1510 | my ($self, $ev) = @_; |
1463 | |
1511 | |
1464 | my $sym = $ev->{sym}; |
1512 | my $sym = $ev->{sym}; |
1465 | |
1513 | |
1466 | if ($sym == 13) { |
1514 | if ($sym == 13) { |
|
|
1515 | unshift @{$self->{history}}, |
|
|
1516 | my $txt = $self->get_text; |
|
|
1517 | $self->{history_pointer} = -1; |
|
|
1518 | $self->{history_saveback} = ''; |
1467 | $self->emit (activate => $self->get_text); |
1519 | $self->emit (activate => $txt); |
1468 | $self->update; |
1520 | $self->update; |
|
|
1521 | |
|
|
1522 | } elsif ($sym == CFClient::SDLK_UP) { |
|
|
1523 | if ($self->{history_pointer} < 0) { |
|
|
1524 | $self->{history_saveback} = $self->get_text; |
|
|
1525 | } |
|
|
1526 | if (@{$self->{history} || []} > 0) { |
|
|
1527 | $self->{history_pointer}++; |
|
|
1528 | if ($self->{history_pointer} >= @{$self->{history} || []}) { |
|
|
1529 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
|
|
1530 | } |
|
|
1531 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
|
|
1532 | } |
|
|
1533 | |
|
|
1534 | } elsif ($sym == CFClient::SDLK_DOWN) { |
|
|
1535 | $self->{history_pointer}--; |
|
|
1536 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
|
|
1537 | |
|
|
1538 | if ($self->{history_pointer} >= 0) { |
|
|
1539 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
|
|
1540 | } else { |
|
|
1541 | $self->set_text ($self->{history_saveback}); |
|
|
1542 | } |
1469 | |
1543 | |
1470 | } else { |
1544 | } else { |
1471 | $self->SUPER::key_down ($ev); |
1545 | $self->SUPER::key_down ($ev); |
1472 | } |
1546 | } |
1473 | |
1547 | |
… | |
… | |
1710 | } |
1784 | } |
1711 | |
1785 | |
1712 | sub set_max { |
1786 | sub set_max { |
1713 | my ($self, $max) = @_; |
1787 | my ($self, $max) = @_; |
1714 | |
1788 | |
|
|
1789 | return if $self->{max_val} == $max; |
|
|
1790 | |
1715 | $self->{max_val} = $max; |
1791 | $self->{max_val} = $max; |
|
|
1792 | $self->update; |
1716 | } |
1793 | } |
1717 | |
1794 | |
1718 | sub set_value { |
1795 | sub set_value { |
1719 | my ($self, $val, $max) = @_; |
1796 | my ($self, $val, $max) = @_; |
1720 | |
1797 | |
1721 | $self->set_max ($max) |
1798 | $self->set_max ($max) |
1722 | if defined $max; |
1799 | if defined $max; |
1723 | |
1800 | |
1724 | $max = $self->{max_val}; |
1801 | return if $self->{val} == $val; |
|
|
1802 | |
1725 | $self->{val} = $val; |
1803 | $self->{val} = $val; |
1726 | |
|
|
1727 | $self->update; |
1804 | $self->update; |
1728 | } |
1805 | } |
1729 | |
1806 | |
1730 | sub _draw { |
1807 | sub _draw { |
1731 | my ($self) = @_; |
1808 | my ($self) = @_; |
… | |
… | |
1794 | |
1871 | |
1795 | sub new { |
1872 | sub new { |
1796 | my ($class, %arg) = @_; |
1873 | my ($class, %arg) = @_; |
1797 | |
1874 | |
1798 | my $self = $class->SUPER::new ( |
1875 | my $self = $class->SUPER::new ( |
1799 | tooltip => $arg{type}, |
1876 | tooltip => $arg{type}, |
1800 | can_hover => 1, |
1877 | can_hover => 1, |
|
|
1878 | can_events => 1, |
1801 | %arg, |
1879 | %arg, |
1802 | ); |
1880 | ); |
1803 | |
1881 | |
1804 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1882 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1805 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
1883 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
… | |
… | |
1813 | |
1891 | |
1814 | $self->{value}->set_fontsize ($fsize); |
1892 | $self->{value}->set_fontsize ($fsize); |
1815 | $self->{max} ->set_fontsize ($fsize); |
1893 | $self->{max} ->set_fontsize ($fsize); |
1816 | } |
1894 | } |
1817 | |
1895 | |
|
|
1896 | sub set_max { |
|
|
1897 | my ($self, $max) = @_; |
|
|
1898 | |
|
|
1899 | $self->{gauge}->set_max ($max); |
|
|
1900 | $self->{max}->set_text ($max); |
|
|
1901 | } |
|
|
1902 | |
1818 | sub set_value { |
1903 | sub set_value { |
1819 | my ($self, $val, $max) = @_; |
1904 | my ($self, $val, $max) = @_; |
1820 | |
1905 | |
1821 | $self->set_max ($max) |
1906 | $self->set_max ($max) |
1822 | if defined $max; |
1907 | if defined $max; |
1823 | |
1908 | |
1824 | $self->{gauge}->set_value ($val, $max); |
1909 | $self->{gauge}->set_value ($val, $max); |
1825 | $self->{value}->set_text ($val); |
1910 | $self->{value}->set_text ($val); |
1826 | } |
|
|
1827 | |
|
|
1828 | sub set_max { |
|
|
1829 | my ($self, $max) = @_; |
|
|
1830 | |
|
|
1831 | $self->{gauge}->set_max ($max); |
|
|
1832 | $self->{max}->set_text ($max); |
|
|
1833 | } |
1911 | } |
1834 | |
1912 | |
1835 | ############################################################################# |
1913 | ############################################################################# |
1836 | |
1914 | |
1837 | package CFClient::UI::Slider; |
1915 | package CFClient::UI::Slider; |
… | |
… | |
2120 | my ($self) = @_; |
2198 | my ($self) = @_; |
2121 | |
2199 | |
2122 | if ($self->{texture}) { |
2200 | if ($self->{texture}) { |
2123 | glEnable GL_TEXTURE_2D; |
2201 | glEnable GL_TEXTURE_2D; |
2124 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2202 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2203 | glColor 1, 1, 1, 1; |
2125 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
2204 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
2126 | glDisable GL_TEXTURE_2D; |
2205 | glDisable GL_TEXTURE_2D; |
2127 | } |
2206 | } |
2128 | |
2207 | |
2129 | $self->{children}[1]->draw; |
2208 | $self->{children}[1]->draw; |