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.171 by root, Mon Apr 24 11:54:26 2006 UTC vs.
Revision 1.175 by root, Tue Apr 25 11:48:31 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 }
234 } 242 }
235} 243}
236 244
237sub size_allocate { 245sub size_allocate {
238 # nothing to be done 246 # nothing to be done
247}
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;
239} 260}
240 261
241sub set_max_size { 262sub set_max_size {
242 my ($self, $w, $h) = @_; 263 my ($self, $w, $h) = @_;
243 264
520 ]; 541 ];
521 542
522 $child->check_size; 543 $child->check_size;
523} 544}
524 545
546sub children {
547 @{ $_[0]{children} }
548}
549
525sub remove { 550sub remove {
526 my ($self, $child) = @_; 551 my ($self, $child) = @_;
527 552
528 delete $child->{parent}; 553 delete $child->{parent};
529 $child->hide; 554 $child->hide;
626} 651}
627 652
628sub update { 653sub update {
629 my ($self) = @_; 654 my ($self) = @_;
630 655
631 # we want to do this delayed... 656 $ROOT->on_refresh ($self => sub { $self->render_child });
632 $self->render_chld;
633 $self->SUPER::update; 657 $self->SUPER::update;
634} 658}
635 659
660sub size_allocate {
661 my ($self, $w, $h) = @_;
662
663 $self->SUPER::size_allocate ($w, $h);
664 $self->update;
665}
666
636sub render_chld { 667sub render_child {
637 my ($self) = @_; 668 my ($self) = @_;
638 669
639 $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 {
640 glClearColor 0, 0, 0, 1; 671 glClearColor 0, 0, 0, 0;
641 glClear GL_COLOR_BUFFER_BIT; 672 glClear GL_COLOR_BUFFER_BIT;
642 $self->child->draw; 673 $self->child->draw;
674# glColorMask 1, 1, 1, 0;
675# glEnable GL_BLEND;
676# glBlendFunc GL_SRC_ALPHA, GL_ZERO;
677# glRasterPos 0, 0;
678# glCopyPixels 0, 0, $self->{w}, $self->{h};
679# glDisable GL_BLEND;
680# glColorMask 1, 1, 1, 1;
643 }; 681 };
644}
645
646sub size_allocate {
647 my ($self, $w, $h) = @_;
648
649 $self->child->configure (0, 0, $w, $h);
650
651 $self->render_chld;
652} 682}
653 683
654sub _draw { 684sub _draw {
655 my ($self) = @_; 685 my ($self) = @_;
656 686
658 688
659 my $tex = $self->{texture} 689 my $tex = $self->{texture}
660 or return; 690 or return;
661 691
662 glEnable GL_BLEND; 692 glEnable GL_BLEND;
663 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 693 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
664 glEnable GL_TEXTURE_2D; 694 glEnable GL_TEXTURE_2D;
665 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 695 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
696 glColor 0, 0, 0, 1;
666 697
667 $tex->draw_quad (0, 0, $w, $h); 698 $tex->draw_quad (0, 0, $w, $h);
668 699
669 glDisable GL_BLEND; 700 glDisable GL_BLEND;
670 glDisable GL_TEXTURE_2D; 701 glDisable GL_TEXTURE_2D;
915 $self->{children}[$y][$x] = $child; 946 $self->{children}[$y][$x] = $child;
916 947
917 $child->check_size; 948 $child->check_size;
918} 949}
919 950
951sub children {
952 grep $_, map @$_, grep $_, @{ $_[0]{children} }
953}
954
920# TODO: move to container class maybe? send childs a signal on removal? 955# TODO: move to container class maybe? send childs a signal on removal?
921sub clear { 956sub clear {
922 my ($self) = @_; 957 my ($self) = @_;
923 958
924 my $children = delete $self->{children}; 959 my @children = $self->children;
960 delete $self->{children};
925 961
926 for (grep $_, map @$_, grep $_, @$children) { 962 for (@children) {
927 delete $_->{parent}; 963 delete $_->{parent};
928 $_->hide; 964 $_->hide;
929 } 965 }
930 966
931 $self->update; 967 $self->update;
1192 s/</&lt;/g; 1228 s/</&lt;/g;
1193 1229
1194 $_[1] 1230 $_[1]
1195} 1231}
1196 1232
1233sub update {
1234 my ($self) = @_;
1235
1236 delete $self->{texture};
1237 $self->SUPER::update;
1238}
1239
1240sub reconfigure {
1241 my ($self) = @_;
1242
1243 delete $self->{texture};
1244}
1245
1197sub set_text { 1246sub set_text {
1198 my ($self, $text) = @_; 1247 my ($self, $text) = @_;
1199 1248
1249 return if $self->{text} eq "T$text";
1250 $self->{text} = "T$text";
1251
1200 $self->{layout}->set_text ($text); 1252 $self->{layout}->set_text ($text);
1201 1253
1202 delete $self->{texture}; 1254 delete $self->{texture};
1255 $self->update;
1203 $self->check_size; 1256 $self->check_size;
1204 $self->update;
1205} 1257}
1206 1258
1207sub set_markup { 1259sub set_markup {
1208 my ($self, $markup) = @_; 1260 my ($self, $markup) = @_;
1209 1261
1262 return if $self->{text} eq "M$markup";
1263 $self->{text} = "M$markup";
1264
1210 $self->{layout}->set_markup ($markup); 1265 $self->{layout}->set_markup ($markup);
1211 1266
1212 delete $self->{texture}; 1267 delete $self->{texture};
1268 $self->update;
1213 $self->check_size; 1269 $self->check_size;
1214 $self->update;
1215} 1270}
1216 1271
1217sub size_request { 1272sub size_request {
1218 my ($self) = @_; 1273 my ($self) = @_;
1219 1274
1743} 1798}
1744 1799
1745sub set_max { 1800sub set_max {
1746 my ($self, $max) = @_; 1801 my ($self, $max) = @_;
1747 1802
1803 return if $self->{max_val} == $max;
1804
1748 $self->{max_val} = $max; 1805 $self->{max_val} = $max;
1806 $self->update;
1749} 1807}
1750 1808
1751sub set_value { 1809sub set_value {
1752 my ($self, $val, $max) = @_; 1810 my ($self, $val, $max) = @_;
1753 1811
1754 $self->set_max ($max) 1812 $self->set_max ($max)
1755 if defined $max; 1813 if defined $max;
1756 1814
1757 $max = $self->{max_val}; 1815 return if $self->{val} == $val;
1816
1758 $self->{val} = $val; 1817 $self->{val} = $val;
1759
1760 $self->update; 1818 $self->update;
1761} 1819}
1762 1820
1763sub _draw { 1821sub _draw {
1764 my ($self) = @_; 1822 my ($self) = @_;
1847 1905
1848 $self->{value}->set_fontsize ($fsize); 1906 $self->{value}->set_fontsize ($fsize);
1849 $self->{max} ->set_fontsize ($fsize); 1907 $self->{max} ->set_fontsize ($fsize);
1850} 1908}
1851 1909
1910sub set_max {
1911 my ($self, $max) = @_;
1912
1913 $self->{gauge}->set_max ($max);
1914 $self->{max}->set_text ($max);
1915}
1916
1852sub set_value { 1917sub set_value {
1853 my ($self, $val, $max) = @_; 1918 my ($self, $val, $max) = @_;
1854 1919
1855 $self->set_max ($max) 1920 $self->set_max ($max)
1856 if defined $max; 1921 if defined $max;
1857 1922
1858 $self->{gauge}->set_value ($val, $max); 1923 $self->{gauge}->set_value ($val, $max);
1859 $self->{value}->set_text ($val); 1924 $self->{value}->set_text ($val);
1860}
1861
1862sub set_max {
1863 my ($self, $max) = @_;
1864
1865 $self->{gauge}->set_max ($max);
1866 $self->{max}->set_text ($max);
1867} 1925}
1868 1926
1869############################################################################# 1927#############################################################################
1870 1928
1871package CFClient::UI::Slider; 1929package CFClient::UI::Slider;
2109 2167
2110 delete $self->{texture}; 2168 delete $self->{texture};
2111 } 2169 }
2112 2170
2113 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 2171 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
2114 glClearColor 0, 0, 0, 1; 2172 glClearColor 0, 0, 0, 0;
2115 glClear GL_COLOR_BUFFER_BIT; 2173 glClear GL_COLOR_BUFFER_BIT;
2116 2174
2117 glEnable GL_BLEND; 2175 glEnable GL_BLEND;
2118 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2176 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2119 glEnable GL_TEXTURE_2D; 2177 glEnable GL_TEXTURE_2D;
2152 2210
2153sub _draw { 2211sub _draw {
2154 my ($self) = @_; 2212 my ($self) = @_;
2155 2213
2156 if ($self->{texture}) { 2214 if ($self->{texture}) {
2215 glEnable GL_BLEND;
2216 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2157 glEnable GL_TEXTURE_2D; 2217 glEnable GL_TEXTURE_2D;
2158 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2218 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2219 glColor 1, 1, 1, 1;
2159 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 2220 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h});
2160 glDisable GL_TEXTURE_2D; 2221 glDisable GL_TEXTURE_2D;
2222 glDisable GL_BLEND;
2161 } 2223 }
2162 2224
2163 $self->{children}[1]->draw; 2225 $self->{children}[1]->draw;
2164 2226
2165} 2227}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines