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.169 by elmex, Mon Apr 24 10:43:39 2006 UTC vs.
Revision 1.174 by root, Tue Apr 25 11:18:49 2006 UTC

24 my $tip = $widget->{tooltip}; 24 my $tip = $widget->{tooltip};
25 25
26 $tip = $tip->($widget) if CODE:: eq ref $tip; 26 $tip = $tip->($widget) if CODE:: eq ref $tip;
27 27
28 $TOOLTIP->set_markup ($widget->{tooltip}); 28 $TOOLTIP->set_markup ($widget->{tooltip});
29 $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); 29
30 $TOOLTIP->show; 30 $TOOLTIP->show;
31
32 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
33
34 if ($x + $TOOLTIP->{w} > $::WIDTH) {
35 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0);
36 }
37
38 $TOOLTIP->move ($x, $y);
31 } 39 }
32 40
33 return; 41 return;
34 } 42 }
35 } 43 }
236 244
237sub size_allocate { 245sub size_allocate {
238 # nothing to be done 246 # nothing to be done
239} 247}
240 248
249sub children {
250}
251
252# call when resoltuion changes etc.
253sub reconfigure {
254 my ($self) = @_;
255
256 $_->reconfigure
257 for $self->children;
258
259 $_->check_size;
260}
261
241sub set_max_size { 262sub set_max_size {
242 my ($self, $w, $h) = @_; 263 my ($self, $w, $h) = @_;
243 264
244 delete $self->{max_w}; $self->{max_w} = $w if $w; 265 delete $self->{max_w}; $self->{max_w} = $w if $w;
245 delete $self->{max_h}; $self->{max_h} = $h if $h; 266 delete $self->{max_h}; $self->{max_h} = $h if $h;
246} 267}
247 268
248# return top left coordinates 269# return top left coordinates
249sub _topleft { 270sub _topleft {
250 my ($self, $x, $y) = @_; 271 my ($self, $x, $y) = @_;
272
273 $self->{parent}
274 or Carp::confess "no parent widget in _topleft\n";#d#
251 275
252 $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); 276 $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y});
253} 277}
254 278
255# translate global coordinates to local coordinate system 279# translate global coordinates to local coordinate system
517 ]; 541 ];
518 542
519 $child->check_size; 543 $child->check_size;
520} 544}
521 545
546sub children {
547 @{ $_[0]{children} }
548}
549
522sub remove { 550sub remove {
523 my ($self, $child) = @_; 551 my ($self, $child) = @_;
524 552
525 delete $child->{parent}; 553 delete $child->{parent};
526 $child->hide; 554 $child->hide;
623} 651}
624 652
625sub update { 653sub update {
626 my ($self) = @_; 654 my ($self) = @_;
627 655
628 # we want to do this delayed... 656 $ROOT->on_refresh ($self => sub { $self->render_child });
629 $self->render_chld;
630 $self->SUPER::update; 657 $self->SUPER::update;
631} 658}
632 659
660sub size_allocate {
661 my ($self, $w, $h) = @_;
662
663 $self->SUPER::size_allocate ($w, $h);
664 $self->update;
665}
666
633sub render_chld { 667sub render_child {
634 my ($self) = @_; 668 my ($self) = @_;
635 669
636 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 670 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
637 glClearColor 0, 0, 0, 1; 671 glClearColor 0, 0, 0, 0;
638 glClear GL_COLOR_BUFFER_BIT; 672 glClear GL_COLOR_BUFFER_BIT;
639 $self->child->draw; 673 $self->child->draw;
640 }; 674 };
641} 675}
642 676
643sub size_allocate {
644 my ($self, $w, $h) = @_;
645
646 $self->child->configure (0, 0, $w, $h);
647
648 $self->render_chld;
649}
650
651sub _draw { 677sub _draw {
652 my ($self) = @_; 678 my ($self) = @_;
653 679
654 my ($w, $h) = ($self->w, $self->h); 680 my ($w, $h) = ($self->w, $self->h);
655 681
656 my $tex = $self->{texture} 682 my $tex = $self->{texture}
657 or return; 683 or return;
658 684
659 glEnable GL_BLEND; 685 glEnable GL_BLEND;
660 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 686 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
661 glEnable GL_TEXTURE_2D; 687 glEnable GL_TEXTURE_2D;
662 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 688 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
689 glColor 0, 0, 0, 1;
663 690
664 $tex->draw_quad (0, 0, $w, $h); 691 $tex->draw_quad (0, 0, $w, $h);
665 692
666 glDisable GL_BLEND; 693 glDisable GL_BLEND;
667 glDisable GL_TEXTURE_2D; 694 glDisable GL_TEXTURE_2D;
912 $self->{children}[$y][$x] = $child; 939 $self->{children}[$y][$x] = $child;
913 940
914 $child->check_size; 941 $child->check_size;
915} 942}
916 943
944sub children {
945 grep $_, map @$_, grep $_, @{ $_[0]{children} }
946}
947
917# TODO: move to container class maybe? send childs a signal on removal? 948# TODO: move to container class maybe? send childs a signal on removal?
918sub clear { 949sub clear {
919 my ($self) = @_; 950 my ($self) = @_;
920 951
921 my $children = delete $self->{children}; 952 my @children = $self->children;
953 delete $self->{children};
922 954
923 for (grep $_, map @$_, grep $_, @$children) { 955 for (@children) {
924 delete $_->{parent}; 956 delete $_->{parent};
925 $_->hide; 957 $_->hide;
926 } 958 }
927 959
928 $self->update; 960 $self->update;
1189 s/</&lt;/g; 1221 s/</&lt;/g;
1190 1222
1191 $_[1] 1223 $_[1]
1192} 1224}
1193 1225
1226sub update {
1227 my ($self) = @_;
1228
1229 delete $self->{texture};
1230 $self->SUPER::update;
1231}
1232
1233sub reconfigure {
1234 my ($self) = @_;
1235
1236 delete $self->{texture};
1237}
1238
1194sub set_text { 1239sub set_text {
1195 my ($self, $text) = @_; 1240 my ($self, $text) = @_;
1196 1241
1242 return if $self->{text} eq "T$text";
1243 $self->{text} = "T$text";
1244
1197 $self->{layout}->set_text ($text); 1245 $self->{layout}->set_text ($text);
1198 1246
1199 delete $self->{texture}; 1247 delete $self->{texture};
1248 $self->update;
1200 $self->check_size; 1249 $self->check_size;
1201 $self->update;
1202} 1250}
1203 1251
1204sub set_markup { 1252sub set_markup {
1205 my ($self, $markup) = @_; 1253 my ($self, $markup) = @_;
1206 1254
1255 return if $self->{text} eq "M$markup";
1256 $self->{text} = "M$markup";
1257
1207 $self->{layout}->set_markup ($markup); 1258 $self->{layout}->set_markup ($markup);
1208 1259
1209 delete $self->{texture}; 1260 delete $self->{texture};
1261 $self->update;
1210 $self->check_size; 1262 $self->check_size;
1211 $self->update;
1212} 1263}
1213 1264
1214sub size_request { 1265sub size_request {
1215 my ($self) = @_; 1266 my ($self) = @_;
1216 1267
1740} 1791}
1741 1792
1742sub set_max { 1793sub set_max {
1743 my ($self, $max) = @_; 1794 my ($self, $max) = @_;
1744 1795
1796 return if $self->{max_val} == $max;
1797
1745 $self->{max_val} = $max; 1798 $self->{max_val} = $max;
1799 $self->update;
1746} 1800}
1747 1801
1748sub set_value { 1802sub set_value {
1749 my ($self, $val, $max) = @_; 1803 my ($self, $val, $max) = @_;
1750 1804
1751 $self->set_max ($max) 1805 $self->set_max ($max)
1752 if defined $max; 1806 if defined $max;
1753 1807
1754 $max = $self->{max_val}; 1808 return if $self->{val} == $val;
1809
1755 $self->{val} = $val; 1810 $self->{val} = $val;
1756
1757 $self->update; 1811 $self->update;
1758} 1812}
1759 1813
1760sub _draw { 1814sub _draw {
1761 my ($self) = @_; 1815 my ($self) = @_;
1824 1878
1825sub new { 1879sub new {
1826 my ($class, %arg) = @_; 1880 my ($class, %arg) = @_;
1827 1881
1828 my $self = $class->SUPER::new ( 1882 my $self = $class->SUPER::new (
1829 tooltip => $arg{type}, 1883 tooltip => $arg{type},
1830 can_hover => 1, 1884 can_hover => 1,
1885 can_events => 1,
1831 %arg, 1886 %arg,
1832 ); 1887 );
1833 1888
1834 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); 1889 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1835 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 1890 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1843 1898
1844 $self->{value}->set_fontsize ($fsize); 1899 $self->{value}->set_fontsize ($fsize);
1845 $self->{max} ->set_fontsize ($fsize); 1900 $self->{max} ->set_fontsize ($fsize);
1846} 1901}
1847 1902
1903sub set_max {
1904 my ($self, $max) = @_;
1905
1906 $self->{gauge}->set_max ($max);
1907 $self->{max}->set_text ($max);
1908}
1909
1848sub set_value { 1910sub set_value {
1849 my ($self, $val, $max) = @_; 1911 my ($self, $val, $max) = @_;
1850 1912
1851 $self->set_max ($max) 1913 $self->set_max ($max)
1852 if defined $max; 1914 if defined $max;
1853 1915
1854 $self->{gauge}->set_value ($val, $max); 1916 $self->{gauge}->set_value ($val, $max);
1855 $self->{value}->set_text ($val); 1917 $self->{value}->set_text ($val);
1856}
1857
1858sub set_max {
1859 my ($self, $max) = @_;
1860
1861 $self->{gauge}->set_max ($max);
1862 $self->{max}->set_text ($max);
1863} 1918}
1864 1919
1865############################################################################# 1920#############################################################################
1866 1921
1867package CFClient::UI::Slider; 1922package CFClient::UI::Slider;
2150 my ($self) = @_; 2205 my ($self) = @_;
2151 2206
2152 if ($self->{texture}) { 2207 if ($self->{texture}) {
2153 glEnable GL_TEXTURE_2D; 2208 glEnable GL_TEXTURE_2D;
2154 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2209 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2210 glColor 1, 1, 1, 1;
2155 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 2211 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h});
2156 glDisable GL_TEXTURE_2D; 2212 glDisable GL_TEXTURE_2D;
2157 } 2213 }
2158 2214
2159 $self->{children}[1]->draw; 2215 $self->{children}[1]->draw;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines