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.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 }
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;
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;
640 }; 681 };
641}
642
643sub size_allocate {
644 my ($self, $w, $h) = @_;
645
646 $self->child->configure (0, 0, $w, $h);
647
648 $self->render_chld;
649} 682}
650 683
651sub _draw { 684sub _draw {
652 my ($self) = @_; 685 my ($self) = @_;
653 686
655 688
656 my $tex = $self->{texture} 689 my $tex = $self->{texture}
657 or return; 690 or return;
658 691
659 glEnable GL_BLEND; 692 glEnable GL_BLEND;
660 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 693 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
661 glEnable GL_TEXTURE_2D; 694 glEnable GL_TEXTURE_2D;
662 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;
663 697
664 $tex->draw_quad (0, 0, $w, $h); 698 $tex->draw_quad (0, 0, $w, $h);
665 699
666 glDisable GL_BLEND; 700 glDisable GL_BLEND;
667 glDisable GL_TEXTURE_2D; 701 glDisable GL_TEXTURE_2D;
754 # TODO: user_x, user_y, overwrite moveto? 788 # TODO: user_x, user_y, overwrite moveto?
755 789
756 my $self = $class->SUPER::new ( 790 my $self = $class->SUPER::new (
757 bg => [1, 1, 1, 1], 791 bg => [1, 1, 1, 1],
758 border_bg => [1, 1, 1, 1], 792 border_bg => [1, 1, 1, 1],
759 border => 0.8, 793 border => 0.6,
760 can_events => 1, 794 can_events => 1,
761 @_ 795 @_
762 ); 796 );
763 797
764 $self->{title} &&= new CFClient::UI::Label 798 $self->{title} &&= new CFClient::UI::Label
765 align => 0, 799 align => 0,
766 valign => 1, 800 valign => 1,
767 text => $self->{title}, 801 text => $self->{title},
768 fontsize => 1; 802 fontsize => $self->{border};
769 803
770 $self 804 $self
771} 805}
772 806
773sub border { 807sub border {
798} 832}
799 833
800sub button_down { 834sub button_down {
801 my ($self, $ev, $x, $y) = @_; 835 my ($self, $ev, $x, $y) = @_;
802 836
837 my ($w, $h) = @$self{qw(w h)};
803 my $border = $self->border; 838 my $border = $self->border;
804 839
805 if ($x < $self->{w} && $x >= $self->{w} - $border 840 my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w);
806 && $y < $self->{h} && $y >= $self->{h} - $border) { 841 my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h);
807 842
843 if ($lr & $td) {
844 my ($wx, $wy) = ($self->{x}, $self->{y});
808 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 845 my ($ox, $oy) = ($ev->{x}, $ev->{y});
809 my ($bw, $bh) = ($self->{w}, $self->{h}); 846 my ($bw, $bh) = ($self->{w}, $self->{h});
810 847
848 my $mx = $x < $border;
849 my $my = $y < $border;
850
811 $self->{motion} = sub { 851 $self->{motion} = sub {
812 my ($ev, $x, $y) = @_; 852 my ($ev, $x, $y) = @_;
813 853
814 ($x, $y) = ($ev->{x}, $ev->{y}); 854 my $dx = $ev->{x} - $ox;
855 my $dy = $ev->{y} - $oy;
815 856
816 $self->{user_w} = $bw + $x - $ox; 857 $self->{user_w} = $bw + $dx * ($mx ? -1 : 1);
817 $self->{user_h} = $bh + $y - $oy; 858 $self->{user_h} = $bh + $dy * ($my ? -1 : 1);
859 $self->move ($wx + $dx * $mx, $wy + $dy * $my);
818 $self->check_size; 860 $self->check_size;
819 }; 861 };
820 862
821 } elsif ($x >= 0 && $x < $self->{w} 863 } elsif ($lr ^ $td) {
822 && $y >= 0 && $y < $border) {
823
824 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 864 my ($ox, $oy) = ($ev->{x}, $ev->{y});
825 my ($bx, $by) = ($self->{x}, $self->{y}); 865 my ($bx, $by) = ($self->{x}, $self->{y});
826 866
827 $self->{motion} = sub { 867 $self->{motion} = sub {
828 my ($ev, $x, $y) = @_; 868 my ($ev, $x, $y) = @_;
912 $self->{children}[$y][$x] = $child; 952 $self->{children}[$y][$x] = $child;
913 953
914 $child->check_size; 954 $child->check_size;
915} 955}
916 956
957sub children {
958 grep $_, map @$_, grep $_, @{ $_[0]{children} }
959}
960
917# TODO: move to container class maybe? send childs a signal on removal? 961# TODO: move to container class maybe? send childs a signal on removal?
918sub clear { 962sub clear {
919 my ($self) = @_; 963 my ($self) = @_;
920 964
921 my $children = delete $self->{children}; 965 my @children = $self->children;
966 delete $self->{children};
922 967
923 for (grep $_, map @$_, grep $_, @$children) { 968 for (@children) {
924 delete $_->{parent}; 969 delete $_->{parent};
925 $_->hide; 970 $_->hide;
926 } 971 }
927 972
928 $self->update; 973 $self->update;
1189 s/</&lt;/g; 1234 s/</&lt;/g;
1190 1235
1191 $_[1] 1236 $_[1]
1192} 1237}
1193 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
1194sub set_text { 1252sub set_text {
1195 my ($self, $text) = @_; 1253 my ($self, $text) = @_;
1196 1254
1255 return if $self->{text} eq "T$text";
1256 $self->{text} = "T$text";
1257
1197 $self->{layout}->set_text ($text); 1258 $self->{layout}->set_text ($text);
1198 1259
1199 delete $self->{texture}; 1260 delete $self->{texture};
1261 $self->update;
1200 $self->check_size; 1262 $self->check_size;
1201 $self->update;
1202} 1263}
1203 1264
1204sub set_markup { 1265sub set_markup {
1205 my ($self, $markup) = @_; 1266 my ($self, $markup) = @_;
1206 1267
1268 return if $self->{text} eq "M$markup";
1269 $self->{text} = "M$markup";
1270
1207 $self->{layout}->set_markup ($markup); 1271 $self->{layout}->set_markup ($markup);
1208 1272
1209 delete $self->{texture}; 1273 delete $self->{texture};
1274 $self->update;
1210 $self->check_size; 1275 $self->check_size;
1211 $self->update;
1212} 1276}
1213 1277
1214sub size_request { 1278sub size_request {
1215 my ($self) = @_; 1279 my ($self) = @_;
1216 1280
1740} 1804}
1741 1805
1742sub set_max { 1806sub set_max {
1743 my ($self, $max) = @_; 1807 my ($self, $max) = @_;
1744 1808
1809 return if $self->{max_val} == $max;
1810
1745 $self->{max_val} = $max; 1811 $self->{max_val} = $max;
1812 $self->update;
1746} 1813}
1747 1814
1748sub set_value { 1815sub set_value {
1749 my ($self, $val, $max) = @_; 1816 my ($self, $val, $max) = @_;
1750 1817
1751 $self->set_max ($max) 1818 $self->set_max ($max)
1752 if defined $max; 1819 if defined $max;
1753 1820
1754 $max = $self->{max_val}; 1821 return if $self->{val} == $val;
1822
1755 $self->{val} = $val; 1823 $self->{val} = $val;
1756
1757 $self->update; 1824 $self->update;
1758} 1825}
1759 1826
1760sub _draw { 1827sub _draw {
1761 my ($self) = @_; 1828 my ($self) = @_;
1824 1891
1825sub new { 1892sub new {
1826 my ($class, %arg) = @_; 1893 my ($class, %arg) = @_;
1827 1894
1828 my $self = $class->SUPER::new ( 1895 my $self = $class->SUPER::new (
1829 tooltip => $arg{type}, 1896 tooltip => $arg{type},
1830 can_hover => 1, 1897 can_hover => 1,
1898 can_events => 1,
1831 %arg, 1899 %arg,
1832 ); 1900 );
1833 1901
1834 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); 1902 $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); 1903 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1843 1911
1844 $self->{value}->set_fontsize ($fsize); 1912 $self->{value}->set_fontsize ($fsize);
1845 $self->{max} ->set_fontsize ($fsize); 1913 $self->{max} ->set_fontsize ($fsize);
1846} 1914}
1847 1915
1916sub set_max {
1917 my ($self, $max) = @_;
1918
1919 $self->{gauge}->set_max ($max);
1920 $self->{max}->set_text ($max);
1921}
1922
1848sub set_value { 1923sub set_value {
1849 my ($self, $val, $max) = @_; 1924 my ($self, $val, $max) = @_;
1850 1925
1851 $self->set_max ($max) 1926 $self->set_max ($max)
1852 if defined $max; 1927 if defined $max;
1853 1928
1854 $self->{gauge}->set_value ($val, $max); 1929 $self->{gauge}->set_value ($val, $max);
1855 $self->{value}->set_text ($val); 1930 $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} 1931}
1864 1932
1865############################################################################# 1933#############################################################################
1866 1934
1867package CFClient::UI::Slider; 1935package CFClient::UI::Slider;
2021 (new CFClient::UI::Empty expand => 1), 2089 (new CFClient::UI::Empty expand => 1),
2022 (new CFClient::UI::Slider vertical => 1), 2090 (new CFClient::UI::Slider vertical => 1),
2023 ], 2091 ],
2024 ); 2092 );
2025 2093
2026 $self->{children}[1]->connect (changed => sub { 2094 $self->{children}[1]->connect (changed => sub { $self->update });
2027 $self->update;
2028 });
2029 2095
2030 $self 2096 $self
2031} 2097}
2032 2098
2033sub set_fontsize { 2099sub set_fontsize {
2041 my ($self, $text) = @_; 2107 my ($self, $text) = @_;
2042 2108
2043 my $layout = $self->{layout}; 2109 my $layout = $self->{layout};
2044 2110
2045 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2111 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2046 $layout->set_width ($self->{w}); 2112 $layout->set_width ($self->{children}[0]{w});
2047 $layout->set_text ($text); 2113 $layout->set_text ($text);
2048 2114
2049 ($layout->size)[1] 2115 ($layout->size)[1]
2050} 2116}
2051 2117
2104 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2170 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2105 2171
2106 delete $self->{texture}; 2172 delete $self->{texture};
2107 } 2173 }
2108 2174
2109 $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 {
2110 glClearColor 0, 0, 0, 1; 2176 glClearColor 0, 0, 0, 0;
2111 glClear GL_COLOR_BUFFER_BIT; 2177 glClear GL_COLOR_BUFFER_BIT;
2112 2178
2113 glEnable GL_BLEND; 2179 glEnable GL_BLEND;
2114 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2180 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2115 glEnable GL_TEXTURE_2D; 2181 glEnable GL_TEXTURE_2D;
2147} 2213}
2148 2214
2149sub _draw { 2215sub _draw {
2150 my ($self) = @_; 2216 my ($self) = @_;
2151 2217
2152 if ($self->{texture}) { 2218 glEnable GL_BLEND;
2219 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2153 glEnable GL_TEXTURE_2D; 2220 glEnable GL_TEXTURE_2D;
2154 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2221 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2222 glColor 1, 1, 1, 1;
2155 $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});
2156 glDisable GL_TEXTURE_2D; 2224 glDisable GL_TEXTURE_2D;
2157 } 2225 glDisable GL_BLEND;
2158 2226
2159 $self->{children}[1]->draw; 2227 $self->{children}[1]->draw;
2160 2228
2161} 2229}
2162 2230

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines