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.167 by elmex, Mon Apr 24 08:44:23 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
517 ]; 533 ];
518 534
519 $child->check_size; 535 $child->check_size;
520} 536}
521 537
538sub children {
539 @{ $_[0]{children} }
540}
541
522sub remove { 542sub remove {
523 my ($self, $child) = @_; 543 my ($self, $child) = @_;
524 544
525 delete $child->{parent}; 545 delete $child->{parent};
526 $child->hide; 546 $child->hide;
912 $self->{children}[$y][$x] = $child; 932 $self->{children}[$y][$x] = $child;
913 933
914 $child->check_size; 934 $child->check_size;
915} 935}
916 936
937sub children {
938 grep $_, map @$_, grep $_, @{ $_[0]{children} }
939}
940
917# 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?
918sub clear { 942sub clear {
919 my ($self) = @_; 943 my ($self) = @_;
920 944
921 my $children = delete $self->{children}; 945 my @children = $self->children;
946 delete $self->{children};
922 947
923 for (grep $_, map @$_, grep $_, @$children) { 948 for (@children) {
924 delete $_->{parent}; 949 delete $_->{parent};
925 $_->hide; 950 $_->hide;
926 } 951 }
927 952
928 $self->update; 953 $self->update;
1189 s/</&lt;/g; 1214 s/</&lt;/g;
1190 1215
1191 $_[1] 1216 $_[1]
1192} 1217}
1193 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
1194sub set_text { 1232sub set_text {
1195 my ($self, $text) = @_; 1233 my ($self, $text) = @_;
1196 1234
1235 return if $self->{text} eq "T$text";
1236 $self->{text} = "T$text";
1237
1197 $self->{layout}->set_text ($text); 1238 $self->{layout}->set_text ($text);
1198 1239
1199 delete $self->{texture}; 1240 delete $self->{texture};
1241 $self->update;
1200 $self->check_size; 1242 $self->check_size;
1201 $self->update;
1202} 1243}
1203 1244
1204sub set_markup { 1245sub set_markup {
1205 my ($self, $markup) = @_; 1246 my ($self, $markup) = @_;
1206 1247
1248 return if $self->{text} eq "M$markup";
1249 $self->{text} = "M$markup";
1250
1207 $self->{layout}->set_markup ($markup); 1251 $self->{layout}->set_markup ($markup);
1208 1252
1209 delete $self->{texture}; 1253 delete $self->{texture};
1254 $self->update;
1210 $self->check_size; 1255 $self->check_size;
1211 $self->update;
1212} 1256}
1213 1257
1214sub size_request { 1258sub size_request {
1215 my ($self) = @_; 1259 my ($self) = @_;
1216 1260
1469 1513
1470 if ($sym == 13) { 1514 if ($sym == 13) {
1471 unshift @{$self->{history}}, 1515 unshift @{$self->{history}},
1472 my $txt = $self->get_text; 1516 my $txt = $self->get_text;
1473 $self->{history_pointer} = -1; 1517 $self->{history_pointer} = -1;
1518 $self->{history_saveback} = '';
1474 $self->emit (activate => $txt); 1519 $self->emit (activate => $txt);
1475 $self->update; 1520 $self->update;
1476 1521
1477 } elsif ($sym == CFClient::SDLK_UP) { 1522 } elsif ($sym == CFClient::SDLK_UP) {
1478 if ($self->{history_pointer} < 0) { 1523 if ($self->{history_pointer} < 0) {
1479 $self->{history_saveback} = $self->get_text; 1524 $self->{history_saveback} = $self->get_text;
1480 } 1525 }
1526 if (@{$self->{history} || []} > 0) {
1481 $self->{history_pointer}++; 1527 $self->{history_pointer}++;
1482 if ($self->{history_pointer} >= @{$self->{history}}) { 1528 if ($self->{history_pointer} >= @{$self->{history} || []}) {
1483 $self->{history_pointer} = @{$self->{history}} - 1; 1529 $self->{history_pointer} = @{$self->{history} || []} - 1;
1530 }
1531 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1484 } 1532 }
1485 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1486 1533
1487 } elsif ($sym == CFClient::SDLK_DOWN) { 1534 } elsif ($sym == CFClient::SDLK_DOWN) {
1488 $self->{history_pointer}--; 1535 $self->{history_pointer}--;
1489 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 1536 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1490 1537
1737} 1784}
1738 1785
1739sub set_max { 1786sub set_max {
1740 my ($self, $max) = @_; 1787 my ($self, $max) = @_;
1741 1788
1789 return if $self->{max_val} == $max;
1790
1742 $self->{max_val} = $max; 1791 $self->{max_val} = $max;
1792 $self->update;
1743} 1793}
1744 1794
1745sub set_value { 1795sub set_value {
1746 my ($self, $val, $max) = @_; 1796 my ($self, $val, $max) = @_;
1747 1797
1748 $self->set_max ($max) 1798 $self->set_max ($max)
1749 if defined $max; 1799 if defined $max;
1750 1800
1751 $max = $self->{max_val}; 1801 return if $self->{val} == $val;
1802
1752 $self->{val} = $val; 1803 $self->{val} = $val;
1753
1754 $self->update; 1804 $self->update;
1755} 1805}
1756 1806
1757sub _draw { 1807sub _draw {
1758 my ($self) = @_; 1808 my ($self) = @_;
1821 1871
1822sub new { 1872sub new {
1823 my ($class, %arg) = @_; 1873 my ($class, %arg) = @_;
1824 1874
1825 my $self = $class->SUPER::new ( 1875 my $self = $class->SUPER::new (
1826 tooltip => $arg{type}, 1876 tooltip => $arg{type},
1827 can_hover => 1, 1877 can_hover => 1,
1878 can_events => 1,
1828 %arg, 1879 %arg,
1829 ); 1880 );
1830 1881
1831 $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");
1832 $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);
1840 1891
1841 $self->{value}->set_fontsize ($fsize); 1892 $self->{value}->set_fontsize ($fsize);
1842 $self->{max} ->set_fontsize ($fsize); 1893 $self->{max} ->set_fontsize ($fsize);
1843} 1894}
1844 1895
1896sub set_max {
1897 my ($self, $max) = @_;
1898
1899 $self->{gauge}->set_max ($max);
1900 $self->{max}->set_text ($max);
1901}
1902
1845sub set_value { 1903sub set_value {
1846 my ($self, $val, $max) = @_; 1904 my ($self, $val, $max) = @_;
1847 1905
1848 $self->set_max ($max) 1906 $self->set_max ($max)
1849 if defined $max; 1907 if defined $max;
1850 1908
1851 $self->{gauge}->set_value ($val, $max); 1909 $self->{gauge}->set_value ($val, $max);
1852 $self->{value}->set_text ($val); 1910 $self->{value}->set_text ($val);
1853}
1854
1855sub set_max {
1856 my ($self, $max) = @_;
1857
1858 $self->{gauge}->set_max ($max);
1859 $self->{max}->set_text ($max);
1860} 1911}
1861 1912
1862############################################################################# 1913#############################################################################
1863 1914
1864package CFClient::UI::Slider; 1915package CFClient::UI::Slider;
2147 my ($self) = @_; 2198 my ($self) = @_;
2148 2199
2149 if ($self->{texture}) { 2200 if ($self->{texture}) {
2150 glEnable GL_TEXTURE_2D; 2201 glEnable GL_TEXTURE_2D;
2151 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;
2152 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 2204 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h});
2153 glDisable GL_TEXTURE_2D; 2205 glDisable GL_TEXTURE_2D;
2154 } 2206 }
2155 2207
2156 $self->{children}[1]->draw; 2208 $self->{children}[1]->draw;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines