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.172 by root, Tue Apr 25 09:52:04 2006 UTC vs.
Revision 1.176 by root, Tue Apr 25 12:10:58 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 }
237sub size_allocate { 245sub size_allocate {
238 # nothing to be done 246 # nothing to be done
239} 247}
240 248
241sub children { 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;
242} 260}
243 261
244sub set_max_size { 262sub set_max_size {
245 my ($self, $w, $h) = @_; 263 my ($self, $w, $h) = @_;
246 264
633} 651}
634 652
635sub update { 653sub update {
636 my ($self) = @_; 654 my ($self) = @_;
637 655
638 # we want to do this delayed... 656 $ROOT->on_refresh ($self => sub { $self->render_child });
639 $self->render_chld;
640 $self->SUPER::update; 657 $self->SUPER::update;
641} 658}
642 659
660sub size_allocate {
661 my ($self, $w, $h) = @_;
662
663 $self->SUPER::size_allocate ($w, $h);
664 $self->update;
665}
666
643sub render_chld { 667sub render_child {
644 my ($self) = @_; 668 my ($self) = @_;
645 669
646 $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 {
647 glClearColor 0, 0, 0, 1; 671 glClearColor 0, 0, 0, 0;
648 glClear GL_COLOR_BUFFER_BIT; 672 glClear GL_COLOR_BUFFER_BIT;
649 $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;
650 }; 681 };
651}
652
653sub size_allocate {
654 my ($self, $w, $h) = @_;
655
656 $self->child->configure (0, 0, $w, $h);
657
658 $self->render_chld;
659} 682}
660 683
661sub _draw { 684sub _draw {
662 my ($self) = @_; 685 my ($self) = @_;
663 686
665 688
666 my $tex = $self->{texture} 689 my $tex = $self->{texture}
667 or return; 690 or return;
668 691
669 glEnable GL_BLEND; 692 glEnable GL_BLEND;
670 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 693 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
671 glEnable GL_TEXTURE_2D; 694 glEnable GL_TEXTURE_2D;
672 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;
673 697
674 $tex->draw_quad (0, 0, $w, $h); 698 $tex->draw_quad (0, 0, $w, $h);
675 699
676 glDisable GL_BLEND; 700 glDisable GL_BLEND;
677 glDisable GL_TEXTURE_2D; 701 glDisable GL_TEXTURE_2D;
764 # TODO: user_x, user_y, overwrite moveto? 788 # TODO: user_x, user_y, overwrite moveto?
765 789
766 my $self = $class->SUPER::new ( 790 my $self = $class->SUPER::new (
767 bg => [1, 1, 1, 1], 791 bg => [1, 1, 1, 1],
768 border_bg => [1, 1, 1, 1], 792 border_bg => [1, 1, 1, 1],
769 border => 0.8, 793 border => 0.6,
770 can_events => 1, 794 can_events => 1,
771 @_ 795 @_
772 ); 796 );
773 797
774 $self->{title} &&= new CFClient::UI::Label 798 $self->{title} &&= new CFClient::UI::Label
775 align => 0, 799 align => 0,
776 valign => 1, 800 valign => 1,
777 text => $self->{title}, 801 text => $self->{title},
778 fontsize => 1; 802 fontsize => $self->{border};
779 803
780 $self 804 $self
781} 805}
782 806
783sub border { 807sub border {
808} 832}
809 833
810sub button_down { 834sub button_down {
811 my ($self, $ev, $x, $y) = @_; 835 my ($self, $ev, $x, $y) = @_;
812 836
837 my ($w, $h) = @$self{qw(w h)};
813 my $border = $self->border; 838 my $border = $self->border;
814 839
815 if ($x < $self->{w} && $x >= $self->{w} - $border 840 my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w);
816 && $y < $self->{h} && $y >= $self->{h} - $border) { 841 my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h);
817 842
843 if ($lr & $td) {
844 my ($wx, $wy) = ($self->{x}, $self->{y});
818 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 845 my ($ox, $oy) = ($ev->{x}, $ev->{y});
819 my ($bw, $bh) = ($self->{w}, $self->{h}); 846 my ($bw, $bh) = ($self->{w}, $self->{h});
820 847
848 my $mx = $x < $border;
849 my $my = $y < $border;
850
821 $self->{motion} = sub { 851 $self->{motion} = sub {
822 my ($ev, $x, $y) = @_; 852 my ($ev, $x, $y) = @_;
823 853
824 ($x, $y) = ($ev->{x}, $ev->{y}); 854 my $dx = $ev->{x} - $ox;
855 my $dy = $ev->{y} - $oy;
825 856
826 $self->{user_w} = $bw + $x - $ox; 857 $self->{user_w} = $bw + $dx * ($mx ? -1 : 1);
827 $self->{user_h} = $bh + $y - $oy; 858 $self->{user_h} = $bh + $dy * ($my ? -1 : 1);
859 $self->move ($wx + $dx * $mx, $wy + $dy * $my);
828 $self->check_size; 860 $self->check_size;
829 }; 861 };
830 862
831 } elsif ($x >= 0 && $x < $self->{w} 863 } elsif ($lr ^ $td) {
832 && $y >= 0 && $y < $border) {
833
834 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 864 my ($ox, $oy) = ($ev->{x}, $ev->{y});
835 my ($bx, $by) = ($self->{x}, $self->{y}); 865 my ($bx, $by) = ($self->{x}, $self->{y});
836 866
837 $self->{motion} = sub { 867 $self->{motion} = sub {
838 my ($ev, $x, $y) = @_; 868 my ($ev, $x, $y) = @_;
1204 s/</&lt;/g; 1234 s/</&lt;/g;
1205 1235
1206 $_[1] 1236 $_[1]
1207} 1237}
1208 1238
1239sub update {
1240 my ($self) = @_;
1241
1242 delete $self->{texture};
1243 $self->SUPER::update;
1244}
1245
1246sub reconfigure {
1247 my ($self) = @_;
1248
1249 delete $self->{texture};
1250}
1251
1209sub set_text { 1252sub set_text {
1210 my ($self, $text) = @_; 1253 my ($self, $text) = @_;
1211 1254
1255 return if $self->{text} eq "T$text";
1256 $self->{text} = "T$text";
1257
1212 $self->{layout}->set_text ($text); 1258 $self->{layout}->set_text ($text);
1213 1259
1214 delete $self->{texture}; 1260 delete $self->{texture};
1261 $self->update;
1215 $self->check_size; 1262 $self->check_size;
1216 $self->update;
1217} 1263}
1218 1264
1219sub set_markup { 1265sub set_markup {
1220 my ($self, $markup) = @_; 1266 my ($self, $markup) = @_;
1221 1267
1268 return if $self->{text} eq "M$markup";
1269 $self->{text} = "M$markup";
1270
1222 $self->{layout}->set_markup ($markup); 1271 $self->{layout}->set_markup ($markup);
1223 1272
1224 delete $self->{texture}; 1273 delete $self->{texture};
1274 $self->update;
1225 $self->check_size; 1275 $self->check_size;
1226 $self->update;
1227} 1276}
1228 1277
1229sub size_request { 1278sub size_request {
1230 my ($self) = @_; 1279 my ($self) = @_;
1231 1280
1755} 1804}
1756 1805
1757sub set_max { 1806sub set_max {
1758 my ($self, $max) = @_; 1807 my ($self, $max) = @_;
1759 1808
1809 return if $self->{max_val} == $max;
1810
1760 $self->{max_val} = $max; 1811 $self->{max_val} = $max;
1812 $self->update;
1761} 1813}
1762 1814
1763sub set_value { 1815sub set_value {
1764 my ($self, $val, $max) = @_; 1816 my ($self, $val, $max) = @_;
1765 1817
1766 $self->set_max ($max) 1818 $self->set_max ($max)
1767 if defined $max; 1819 if defined $max;
1768 1820
1769 $max = $self->{max_val}; 1821 return if $self->{val} == $val;
1822
1770 $self->{val} = $val; 1823 $self->{val} = $val;
1771
1772 $self->update; 1824 $self->update;
1773} 1825}
1774 1826
1775sub _draw { 1827sub _draw {
1776 my ($self) = @_; 1828 my ($self) = @_;
1859 1911
1860 $self->{value}->set_fontsize ($fsize); 1912 $self->{value}->set_fontsize ($fsize);
1861 $self->{max} ->set_fontsize ($fsize); 1913 $self->{max} ->set_fontsize ($fsize);
1862} 1914}
1863 1915
1916sub set_max {
1917 my ($self, $max) = @_;
1918
1919 $self->{gauge}->set_max ($max);
1920 $self->{max}->set_text ($max);
1921}
1922
1864sub set_value { 1923sub set_value {
1865 my ($self, $val, $max) = @_; 1924 my ($self, $val, $max) = @_;
1866 1925
1867 $self->set_max ($max) 1926 $self->set_max ($max)
1868 if defined $max; 1927 if defined $max;
1869 1928
1870 $self->{gauge}->set_value ($val, $max); 1929 $self->{gauge}->set_value ($val, $max);
1871 $self->{value}->set_text ($val); 1930 $self->{value}->set_text ($val);
1872}
1873
1874sub set_max {
1875 my ($self, $max) = @_;
1876
1877 $self->{gauge}->set_max ($max);
1878 $self->{max}->set_text ($max);
1879} 1931}
1880 1932
1881############################################################################# 1933#############################################################################
1882 1934
1883package CFClient::UI::Slider; 1935package CFClient::UI::Slider;
2037 (new CFClient::UI::Empty expand => 1), 2089 (new CFClient::UI::Empty expand => 1),
2038 (new CFClient::UI::Slider vertical => 1), 2090 (new CFClient::UI::Slider vertical => 1),
2039 ], 2091 ],
2040 ); 2092 );
2041 2093
2042 $self->{children}[1]->connect (changed => sub { 2094 $self->{children}[1]->connect (changed => sub { $self->update });
2043 $self->update;
2044 });
2045 2095
2046 $self 2096 $self
2047} 2097}
2048 2098
2049sub set_fontsize { 2099sub set_fontsize {
2057 my ($self, $text) = @_; 2107 my ($self, $text) = @_;
2058 2108
2059 my $layout = $self->{layout}; 2109 my $layout = $self->{layout};
2060 2110
2061 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2111 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2062 $layout->set_width ($self->{w}); 2112 $layout->set_width ($self->{children}[0]{w});
2063 $layout->set_text ($text); 2113 $layout->set_text ($text);
2064 2114
2065 ($layout->size)[1] 2115 ($layout->size)[1]
2066} 2116}
2067 2117
2120 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2170 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2121 2171
2122 delete $self->{texture}; 2172 delete $self->{texture};
2123 } 2173 }
2124 2174
2125 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 2175 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2126 glClearColor 0, 0, 0, 1; 2176 glClearColor 0, 0, 0, 0;
2127 glClear GL_COLOR_BUFFER_BIT; 2177 glClear GL_COLOR_BUFFER_BIT;
2128 2178
2129 glEnable GL_BLEND; 2179 glEnable GL_BLEND;
2130 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2180 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2131 glEnable GL_TEXTURE_2D; 2181 glEnable GL_TEXTURE_2D;
2163} 2213}
2164 2214
2165sub _draw { 2215sub _draw {
2166 my ($self) = @_; 2216 my ($self) = @_;
2167 2217
2168 if ($self->{texture}) { 2218 glEnable GL_BLEND;
2219 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2169 glEnable GL_TEXTURE_2D; 2220 glEnable GL_TEXTURE_2D;
2170 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2221 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2171 glColor 1, 1, 1, 1; 2222 glColor 1, 1, 1, 1;
2172 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 2223 $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2173 glDisable GL_TEXTURE_2D; 2224 glDisable GL_TEXTURE_2D;
2174 } 2225 glDisable GL_BLEND;
2175 2226
2176 $self->{children}[1]->draw; 2227 $self->{children}[1]->draw;
2177 2228
2178} 2229}
2179 2230

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines