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.177 by root, Tue Apr 25 13:08:17 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) = @_;
874 $tex[1]->draw_quad (0, 0, $w, $border); 904 $tex[1]->draw_quad (0, 0, $w, $border);
875 $tex[3]->draw_quad (0, $border, $border, $ch); 905 $tex[3]->draw_quad (0, $border, $border, $ch);
876 $tex[2]->draw_quad ($w - $border, $border, $border, $ch); 906 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
877 $tex[4]->draw_quad (0, $h - $border, $w, $border); 907 $tex[4]->draw_quad (0, $h - $border, $w, $border);
878 908
909 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
879 my $bg = $tex[0]; 910 my $bg = $tex[0];
880 911
881 # TODO: repeat texture not scale 912 # TODO: repeat texture not scale
882 my $rep_x = $cw / $bg->{w}; 913 my $rep_x = $cw / $bg->{w};
883 my $rep_y = $ch / $bg->{h}; 914 my $rep_y = $ch / $bg->{h};
884 915
885 glColor @{ $self->{bg} }; 916 glColor @{ $self->{bg} };
886 917
887 $bg->{s} = $rep_x; 918 $bg->{s} = $rep_x;
888 $bg->{t} = $rep_y; 919 $bg->{t} = $rep_y;
889 $bg->{wrap_mode} = 1; 920 $bg->{wrap_mode} = 1;
890 $bg->draw_quad ($border, $border, $cw, $ch); 921 $bg->draw_quad ($border, $border, $cw, $ch);
891 922
892 glDisable GL_TEXTURE_2D; 923 glDisable GL_TEXTURE_2D;
893 glDisable GL_BLEND; 924 glDisable GL_BLEND;
925 }
894 926
895 $self->{title}->draw if $self->{title}; 927 $self->{title}->draw if $self->{title};
928
896 $self->child->draw; 929 $self->child->draw;
897} 930}
898 931
899############################################################################# 932#############################################################################
900 933
1204 s/</&lt;/g; 1237 s/</&lt;/g;
1205 1238
1206 $_[1] 1239 $_[1]
1207} 1240}
1208 1241
1242sub update {
1243 my ($self) = @_;
1244
1245 delete $self->{texture};
1246 $self->SUPER::update;
1247}
1248
1249sub reconfigure {
1250 my ($self) = @_;
1251
1252 delete $self->{texture};
1253}
1254
1209sub set_text { 1255sub set_text {
1210 my ($self, $text) = @_; 1256 my ($self, $text) = @_;
1211 1257
1258 return if $self->{text} eq "T$text";
1259 $self->{text} = "T$text";
1260
1212 $self->{layout}->set_text ($text); 1261 $self->{layout}->set_text ($text);
1213 1262
1214 delete $self->{texture}; 1263 delete $self->{texture};
1264 $self->update;
1215 $self->check_size; 1265 $self->check_size;
1216 $self->update;
1217} 1266}
1218 1267
1219sub set_markup { 1268sub set_markup {
1220 my ($self, $markup) = @_; 1269 my ($self, $markup) = @_;
1221 1270
1271 return if $self->{text} eq "M$markup";
1272 $self->{text} = "M$markup";
1273
1222 $self->{layout}->set_markup ($markup); 1274 $self->{layout}->set_markup ($markup);
1223 1275
1224 delete $self->{texture}; 1276 delete $self->{texture};
1277 $self->update;
1225 $self->check_size; 1278 $self->check_size;
1226 $self->update;
1227} 1279}
1228 1280
1229sub size_request { 1281sub size_request {
1230 my ($self) = @_; 1282 my ($self) = @_;
1231 1283
1755} 1807}
1756 1808
1757sub set_max { 1809sub set_max {
1758 my ($self, $max) = @_; 1810 my ($self, $max) = @_;
1759 1811
1812 return if $self->{max_val} == $max;
1813
1760 $self->{max_val} = $max; 1814 $self->{max_val} = $max;
1815 $self->update;
1761} 1816}
1762 1817
1763sub set_value { 1818sub set_value {
1764 my ($self, $val, $max) = @_; 1819 my ($self, $val, $max) = @_;
1765 1820
1766 $self->set_max ($max) 1821 $self->set_max ($max)
1767 if defined $max; 1822 if defined $max;
1768 1823
1769 $max = $self->{max_val}; 1824 return if $self->{val} == $val;
1825
1770 $self->{val} = $val; 1826 $self->{val} = $val;
1771
1772 $self->update; 1827 $self->update;
1773} 1828}
1774 1829
1775sub _draw { 1830sub _draw {
1776 my ($self) = @_; 1831 my ($self) = @_;
1859 1914
1860 $self->{value}->set_fontsize ($fsize); 1915 $self->{value}->set_fontsize ($fsize);
1861 $self->{max} ->set_fontsize ($fsize); 1916 $self->{max} ->set_fontsize ($fsize);
1862} 1917}
1863 1918
1919sub set_max {
1920 my ($self, $max) = @_;
1921
1922 $self->{gauge}->set_max ($max);
1923 $self->{max}->set_text ($max);
1924}
1925
1864sub set_value { 1926sub set_value {
1865 my ($self, $val, $max) = @_; 1927 my ($self, $val, $max) = @_;
1866 1928
1867 $self->set_max ($max) 1929 $self->set_max ($max)
1868 if defined $max; 1930 if defined $max;
1869 1931
1870 $self->{gauge}->set_value ($val, $max); 1932 $self->{gauge}->set_value ($val, $max);
1871 $self->{value}->set_text ($val); 1933 $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} 1934}
1880 1935
1881############################################################################# 1936#############################################################################
1882 1937
1883package CFClient::UI::Slider; 1938package CFClient::UI::Slider;
2037 (new CFClient::UI::Empty expand => 1), 2092 (new CFClient::UI::Empty expand => 1),
2038 (new CFClient::UI::Slider vertical => 1), 2093 (new CFClient::UI::Slider vertical => 1),
2039 ], 2094 ],
2040 ); 2095 );
2041 2096
2042 $self->{children}[1]->connect (changed => sub { 2097 $self->{children}[1]->connect (changed => sub { $self->update });
2043 $self->update;
2044 });
2045 2098
2046 $self 2099 $self
2047} 2100}
2048 2101
2049sub set_fontsize { 2102sub set_fontsize {
2057 my ($self, $text) = @_; 2110 my ($self, $text) = @_;
2058 2111
2059 my $layout = $self->{layout}; 2112 my $layout = $self->{layout};
2060 2113
2061 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2114 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2062 $layout->set_width ($self->{w}); 2115 $layout->set_width ($self->{children}[0]{w});
2063 $layout->set_text ($text); 2116 $layout->set_text ($text);
2064 2117
2065 ($layout->size)[1] 2118 ($layout->size)[1]
2066} 2119}
2067 2120
2120 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2173 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2121 2174
2122 delete $self->{texture}; 2175 delete $self->{texture};
2123 } 2176 }
2124 2177
2125 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 2178 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2126 glClearColor 0, 0, 0, 1; 2179 glClearColor 0, 0, 0, 0;
2127 glClear GL_COLOR_BUFFER_BIT; 2180 glClear GL_COLOR_BUFFER_BIT;
2128 2181
2129 glEnable GL_BLEND; 2182 glEnable GL_BLEND;
2130 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2183 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2131 glEnable GL_TEXTURE_2D; 2184 glEnable GL_TEXTURE_2D;
2163} 2216}
2164 2217
2165sub _draw { 2218sub _draw {
2166 my ($self) = @_; 2219 my ($self) = @_;
2167 2220
2168 if ($self->{texture}) { 2221 glEnable GL_BLEND;
2222 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2169 glEnable GL_TEXTURE_2D; 2223 glEnable GL_TEXTURE_2D;
2170 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2224 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2171 glColor 1, 1, 1, 1; 2225 glColor 1, 1, 1, 1;
2172 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 2226 $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2173 glDisable GL_TEXTURE_2D; 2227 glDisable GL_TEXTURE_2D;
2174 } 2228 glDisable GL_BLEND;
2175 2229
2176 $self->{children}[1]->draw; 2230 $self->{children}[1]->draw;
2177 2231
2178} 2232}
2179 2233

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines