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.166 by root, Mon Apr 24 08:38:36 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 }
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;
912 $self->{children}[$y][$x] = $child; 946 $self->{children}[$y][$x] = $child;
913 947
914 $child->check_size; 948 $child->check_size;
915} 949}
916 950
951sub children {
952 grep $_, map @$_, grep $_, @{ $_[0]{children} }
953}
954
917# 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?
918sub clear { 956sub clear {
919 my ($self) = @_; 957 my ($self) = @_;
920 958
921 my $children = delete $self->{children}; 959 my @children = $self->children;
960 delete $self->{children};
922 961
923 for (grep $_, map @$_, grep $_, @$children) { 962 for (@children) {
924 delete $_->{parent}; 963 delete $_->{parent};
925 $_->hide; 964 $_->hide;
926 } 965 }
927 966
928 $self->update; 967 $self->update;
1189 s/</&lt;/g; 1228 s/</&lt;/g;
1190 1229
1191 $_[1] 1230 $_[1]
1192} 1231}
1193 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
1194sub set_text { 1246sub set_text {
1195 my ($self, $text) = @_; 1247 my ($self, $text) = @_;
1196 1248
1249 return if $self->{text} eq "T$text";
1250 $self->{text} = "T$text";
1251
1197 $self->{layout}->set_text ($text); 1252 $self->{layout}->set_text ($text);
1198 1253
1199 delete $self->{texture}; 1254 delete $self->{texture};
1255 $self->update;
1200 $self->check_size; 1256 $self->check_size;
1201 $self->update;
1202} 1257}
1203 1258
1204sub set_markup { 1259sub set_markup {
1205 my ($self, $markup) = @_; 1260 my ($self, $markup) = @_;
1206 1261
1262 return if $self->{text} eq "M$markup";
1263 $self->{text} = "M$markup";
1264
1207 $self->{layout}->set_markup ($markup); 1265 $self->{layout}->set_markup ($markup);
1208 1266
1209 delete $self->{texture}; 1267 delete $self->{texture};
1268 $self->update;
1210 $self->check_size; 1269 $self->check_size;
1211 $self->update;
1212} 1270}
1213 1271
1214sub size_request { 1272sub size_request {
1215 my ($self) = @_; 1273 my ($self) = @_;
1216 1274
1466 my ($self, $ev) = @_; 1524 my ($self, $ev) = @_;
1467 1525
1468 my $sym = $ev->{sym}; 1526 my $sym = $ev->{sym};
1469 1527
1470 if ($sym == 13) { 1528 if ($sym == 13) {
1529 unshift @{$self->{history}},
1530 my $txt = $self->get_text;
1531 $self->{history_pointer} = -1;
1532 $self->{history_saveback} = '';
1471 $self->emit (activate => $self->get_text); 1533 $self->emit (activate => $txt);
1472 $self->update; 1534 $self->update;
1535
1536 } elsif ($sym == CFClient::SDLK_UP) {
1537 if ($self->{history_pointer} < 0) {
1538 $self->{history_saveback} = $self->get_text;
1539 }
1540 if (@{$self->{history} || []} > 0) {
1541 $self->{history_pointer}++;
1542 if ($self->{history_pointer} >= @{$self->{history} || []}) {
1543 $self->{history_pointer} = @{$self->{history} || []} - 1;
1544 }
1545 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1546 }
1547
1548 } elsif ($sym == CFClient::SDLK_DOWN) {
1549 $self->{history_pointer}--;
1550 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1551
1552 if ($self->{history_pointer} >= 0) {
1553 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1554 } else {
1555 $self->set_text ($self->{history_saveback});
1556 }
1473 1557
1474 } else { 1558 } else {
1475 $self->SUPER::key_down ($ev); 1559 $self->SUPER::key_down ($ev);
1476 } 1560 }
1477 1561
1714} 1798}
1715 1799
1716sub set_max { 1800sub set_max {
1717 my ($self, $max) = @_; 1801 my ($self, $max) = @_;
1718 1802
1803 return if $self->{max_val} == $max;
1804
1719 $self->{max_val} = $max; 1805 $self->{max_val} = $max;
1806 $self->update;
1720} 1807}
1721 1808
1722sub set_value { 1809sub set_value {
1723 my ($self, $val, $max) = @_; 1810 my ($self, $val, $max) = @_;
1724 1811
1725 $self->set_max ($max) 1812 $self->set_max ($max)
1726 if defined $max; 1813 if defined $max;
1727 1814
1728 $max = $self->{max_val}; 1815 return if $self->{val} == $val;
1816
1729 $self->{val} = $val; 1817 $self->{val} = $val;
1730
1731 $self->update; 1818 $self->update;
1732} 1819}
1733 1820
1734sub _draw { 1821sub _draw {
1735 my ($self) = @_; 1822 my ($self) = @_;
1798 1885
1799sub new { 1886sub new {
1800 my ($class, %arg) = @_; 1887 my ($class, %arg) = @_;
1801 1888
1802 my $self = $class->SUPER::new ( 1889 my $self = $class->SUPER::new (
1803 tooltip => $arg{type}, 1890 tooltip => $arg{type},
1804 can_hover => 1, 1891 can_hover => 1,
1892 can_events => 1,
1805 %arg, 1893 %arg,
1806 ); 1894 );
1807 1895
1808 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); 1896 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1809 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 1897 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1817 1905
1818 $self->{value}->set_fontsize ($fsize); 1906 $self->{value}->set_fontsize ($fsize);
1819 $self->{max} ->set_fontsize ($fsize); 1907 $self->{max} ->set_fontsize ($fsize);
1820} 1908}
1821 1909
1910sub set_max {
1911 my ($self, $max) = @_;
1912
1913 $self->{gauge}->set_max ($max);
1914 $self->{max}->set_text ($max);
1915}
1916
1822sub set_value { 1917sub set_value {
1823 my ($self, $val, $max) = @_; 1918 my ($self, $val, $max) = @_;
1824 1919
1825 $self->set_max ($max) 1920 $self->set_max ($max)
1826 if defined $max; 1921 if defined $max;
1827 1922
1828 $self->{gauge}->set_value ($val, $max); 1923 $self->{gauge}->set_value ($val, $max);
1829 $self->{value}->set_text ($val); 1924 $self->{value}->set_text ($val);
1830}
1831
1832sub set_max {
1833 my ($self, $max) = @_;
1834
1835 $self->{gauge}->set_max ($max);
1836 $self->{max}->set_text ($max);
1837} 1925}
1838 1926
1839############################################################################# 1927#############################################################################
1840 1928
1841package CFClient::UI::Slider; 1929package CFClient::UI::Slider;
2079 2167
2080 delete $self->{texture}; 2168 delete $self->{texture};
2081 } 2169 }
2082 2170
2083 $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 {
2084 glClearColor 0, 0, 0, 1; 2172 glClearColor 0, 0, 0, 0;
2085 glClear GL_COLOR_BUFFER_BIT; 2173 glClear GL_COLOR_BUFFER_BIT;
2086 2174
2087 glEnable GL_BLEND; 2175 glEnable GL_BLEND;
2088 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2176 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2089 glEnable GL_TEXTURE_2D; 2177 glEnable GL_TEXTURE_2D;
2122 2210
2123sub _draw { 2211sub _draw {
2124 my ($self) = @_; 2212 my ($self) = @_;
2125 2213
2126 if ($self->{texture}) { 2214 if ($self->{texture}) {
2215 glEnable GL_BLEND;
2216 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2127 glEnable GL_TEXTURE_2D; 2217 glEnable GL_TEXTURE_2D;
2128 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;
2129 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 2220 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h});
2130 glDisable GL_TEXTURE_2D; 2221 glDisable GL_TEXTURE_2D;
2222 glDisable GL_BLEND;
2131 } 2223 }
2132 2224
2133 $self->{children}[1]->draw; 2225 $self->{children}[1]->draw;
2134 2226
2135} 2227}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines