ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.164 by root, Mon Apr 24 06:57:39 2006 UTC vs.
Revision 1.173 by root, Tue Apr 25 10:30:48 2006 UTC

236 236
237sub size_allocate { 237sub size_allocate {
238 # nothing to be done 238 # nothing to be done
239} 239}
240 240
241sub children {
242}
243
244# call when resoltuion changes etc.
245sub reconfigure {
246 my ($self) = @_;
247
248 $_->reconfigure
249 for $self->children;
250
251 $_->check_size;
252}
253
241sub set_max_size { 254sub 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
249sub _topleft { 262sub _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
492sub new { 508sub 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
538sub children {
539 @{ $_[0]{children} }
516} 540}
517 541
518sub remove { 542sub 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
937sub 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?
914sub clear { 942sub 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/</&lt;/g; 1214 s/</&lt;/g;
1186 1215
1187 $_[1] 1216 $_[1]
1188} 1217}
1189 1218
1219sub update {
1220 my ($self) = @_;
1221
1222 delete $self->{texture};
1223 $self->SUPER::update;
1224}
1225
1226sub reconfigure {
1227 my ($self) = @_;
1228
1229 delete $self->{texture};
1230}
1231
1190sub set_text { 1232sub 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
1200sub set_markup { 1245sub 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
1210sub size_request { 1258sub 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
1712sub set_max { 1786sub 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
1718sub set_value { 1795sub 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
1730sub _draw { 1807sub _draw {
1731 my ($self) = @_; 1808 my ($self) = @_;
1794 1871
1795sub new { 1872sub 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
1896sub set_max {
1897 my ($self, $max) = @_;
1898
1899 $self->{gauge}->set_max ($max);
1900 $self->{max}->set_text ($max);
1901}
1902
1818sub set_value { 1903sub 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
1828sub 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
1837package CFClient::UI::Slider; 1915package 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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines