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.165 by root, Mon Apr 24 08:22:22 2006 UTC vs.
Revision 1.174 by root, Tue Apr 25 11:18:49 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
492sub new { 516sub new {
493 my ($class, %arg) = @_; 517 my ($class, %arg) = @_;
494 518
495 my $children = delete $arg{children} || []; 519 my $children = delete $arg{children} || [];
496 520
497 my $self = $class->SUPER::new (children => [], can_events => 0, %arg); 521 my $self = $class->SUPER::new (
522 children => [],
523 can_events => 0,
524 %arg,
525 );
498 $self->add ($_) for @$children; 526 $self->add ($_) for @$children;
499 527
500 $self 528 $self
501} 529}
502 530
513 ]; 541 ];
514 542
515 $child->check_size; 543 $child->check_size;
516} 544}
517 545
546sub children {
547 @{ $_[0]{children} }
548}
549
518sub remove { 550sub remove {
519 my ($self, $child) = @_; 551 my ($self, $child) = @_;
520 552
521 delete $child->{parent}; 553 delete $child->{parent};
522 $child->hide; 554 $child->hide;
619} 651}
620 652
621sub update { 653sub update {
622 my ($self) = @_; 654 my ($self) = @_;
623 655
624 # we want to do this delayed... 656 $ROOT->on_refresh ($self => sub { $self->render_child });
625 $self->render_chld;
626 $self->SUPER::update; 657 $self->SUPER::update;
627} 658}
628 659
660sub size_allocate {
661 my ($self, $w, $h) = @_;
662
663 $self->SUPER::size_allocate ($w, $h);
664 $self->update;
665}
666
629sub render_chld { 667sub render_child {
630 my ($self) = @_; 668 my ($self) = @_;
631 669
632 $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 {
633 glClearColor 0, 0, 0, 1; 671 glClearColor 0, 0, 0, 0;
634 glClear GL_COLOR_BUFFER_BIT; 672 glClear GL_COLOR_BUFFER_BIT;
635 $self->child->draw; 673 $self->child->draw;
636 }; 674 };
637} 675}
638 676
639sub size_allocate {
640 my ($self, $w, $h) = @_;
641
642 $self->child->configure (0, 0, $w, $h);
643
644 $self->render_chld;
645}
646
647sub _draw { 677sub _draw {
648 my ($self) = @_; 678 my ($self) = @_;
649 679
650 my ($w, $h) = ($self->w, $self->h); 680 my ($w, $h) = ($self->w, $self->h);
651 681
652 my $tex = $self->{texture} 682 my $tex = $self->{texture}
653 or return; 683 or return;
654 684
655 glEnable GL_BLEND; 685 glEnable GL_BLEND;
656 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 686 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
657 glEnable GL_TEXTURE_2D; 687 glEnable GL_TEXTURE_2D;
658 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 688 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
689 glColor 0, 0, 0, 1;
659 690
660 $tex->draw_quad (0, 0, $w, $h); 691 $tex->draw_quad (0, 0, $w, $h);
661 692
662 glDisable GL_BLEND; 693 glDisable GL_BLEND;
663 glDisable GL_TEXTURE_2D; 694 glDisable GL_TEXTURE_2D;
751 782
752 my $self = $class->SUPER::new ( 783 my $self = $class->SUPER::new (
753 bg => [1, 1, 1, 1], 784 bg => [1, 1, 1, 1],
754 border_bg => [1, 1, 1, 1], 785 border_bg => [1, 1, 1, 1],
755 border => 0.8, 786 border => 0.8,
787 can_events => 1,
756 @_ 788 @_
757 ); 789 );
758 790
759 $self->{title} &&= new CFClient::UI::Label 791 $self->{title} &&= new CFClient::UI::Label
760 align => 0, 792 align => 0,
907 $self->{children}[$y][$x] = $child; 939 $self->{children}[$y][$x] = $child;
908 940
909 $child->check_size; 941 $child->check_size;
910} 942}
911 943
944sub children {
945 grep $_, map @$_, grep $_, @{ $_[0]{children} }
946}
947
912# TODO: move to container class maybe? send childs a signal on removal? 948# TODO: move to container class maybe? send childs a signal on removal?
913sub clear { 949sub clear {
914 my ($self) = @_; 950 my ($self) = @_;
915 951
916 my $children = delete $self->{children}; 952 my @children = $self->children;
953 delete $self->{children};
917 954
918 for (grep $_, map @$_, grep $_, @$children) { 955 for (@children) {
919 delete $_->{parent}; 956 delete $_->{parent};
920 $_->hide; 957 $_->hide;
921 } 958 }
922 959
923 $self->update; 960 $self->update;
1184 s/</&lt;/g; 1221 s/</&lt;/g;
1185 1222
1186 $_[1] 1223 $_[1]
1187} 1224}
1188 1225
1226sub update {
1227 my ($self) = @_;
1228
1229 delete $self->{texture};
1230 $self->SUPER::update;
1231}
1232
1233sub reconfigure {
1234 my ($self) = @_;
1235
1236 delete $self->{texture};
1237}
1238
1189sub set_text { 1239sub set_text {
1190 my ($self, $text) = @_; 1240 my ($self, $text) = @_;
1191 1241
1242 return if $self->{text} eq "T$text";
1243 $self->{text} = "T$text";
1244
1192 $self->{layout}->set_text ($text); 1245 $self->{layout}->set_text ($text);
1193 1246
1194 delete $self->{texture}; 1247 delete $self->{texture};
1248 $self->update;
1195 $self->check_size; 1249 $self->check_size;
1196 $self->update;
1197} 1250}
1198 1251
1199sub set_markup { 1252sub set_markup {
1200 my ($self, $markup) = @_; 1253 my ($self, $markup) = @_;
1201 1254
1255 return if $self->{text} eq "M$markup";
1256 $self->{text} = "M$markup";
1257
1202 $self->{layout}->set_markup ($markup); 1258 $self->{layout}->set_markup ($markup);
1203 1259
1204 delete $self->{texture}; 1260 delete $self->{texture};
1261 $self->update;
1205 $self->check_size; 1262 $self->check_size;
1206 $self->update;
1207} 1263}
1208 1264
1209sub size_request { 1265sub size_request {
1210 my ($self) = @_; 1266 my ($self) = @_;
1211 1267
1461 my ($self, $ev) = @_; 1517 my ($self, $ev) = @_;
1462 1518
1463 my $sym = $ev->{sym}; 1519 my $sym = $ev->{sym};
1464 1520
1465 if ($sym == 13) { 1521 if ($sym == 13) {
1522 unshift @{$self->{history}},
1523 my $txt = $self->get_text;
1524 $self->{history_pointer} = -1;
1525 $self->{history_saveback} = '';
1466 $self->emit (activate => $self->get_text); 1526 $self->emit (activate => $txt);
1467 $self->update; 1527 $self->update;
1528
1529 } elsif ($sym == CFClient::SDLK_UP) {
1530 if ($self->{history_pointer} < 0) {
1531 $self->{history_saveback} = $self->get_text;
1532 }
1533 if (@{$self->{history} || []} > 0) {
1534 $self->{history_pointer}++;
1535 if ($self->{history_pointer} >= @{$self->{history} || []}) {
1536 $self->{history_pointer} = @{$self->{history} || []} - 1;
1537 }
1538 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1539 }
1540
1541 } elsif ($sym == CFClient::SDLK_DOWN) {
1542 $self->{history_pointer}--;
1543 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1544
1545 if ($self->{history_pointer} >= 0) {
1546 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1547 } else {
1548 $self->set_text ($self->{history_saveback});
1549 }
1468 1550
1469 } else { 1551 } else {
1470 $self->SUPER::key_down ($ev); 1552 $self->SUPER::key_down ($ev);
1471 } 1553 }
1472 1554
1709} 1791}
1710 1792
1711sub set_max { 1793sub set_max {
1712 my ($self, $max) = @_; 1794 my ($self, $max) = @_;
1713 1795
1796 return if $self->{max_val} == $max;
1797
1714 $self->{max_val} = $max; 1798 $self->{max_val} = $max;
1799 $self->update;
1715} 1800}
1716 1801
1717sub set_value { 1802sub set_value {
1718 my ($self, $val, $max) = @_; 1803 my ($self, $val, $max) = @_;
1719 1804
1720 $self->set_max ($max) 1805 $self->set_max ($max)
1721 if defined $max; 1806 if defined $max;
1722 1807
1723 $max = $self->{max_val}; 1808 return if $self->{val} == $val;
1809
1724 $self->{val} = $val; 1810 $self->{val} = $val;
1725
1726 $self->update; 1811 $self->update;
1727} 1812}
1728 1813
1729sub _draw { 1814sub _draw {
1730 my ($self) = @_; 1815 my ($self) = @_;
1793 1878
1794sub new { 1879sub new {
1795 my ($class, %arg) = @_; 1880 my ($class, %arg) = @_;
1796 1881
1797 my $self = $class->SUPER::new ( 1882 my $self = $class->SUPER::new (
1798 tooltip => $arg{type}, 1883 tooltip => $arg{type},
1799 can_hover => 1, 1884 can_hover => 1,
1885 can_events => 1,
1800 %arg, 1886 %arg,
1801 ); 1887 );
1802 1888
1803 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); 1889 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1804 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 1890 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1812 1898
1813 $self->{value}->set_fontsize ($fsize); 1899 $self->{value}->set_fontsize ($fsize);
1814 $self->{max} ->set_fontsize ($fsize); 1900 $self->{max} ->set_fontsize ($fsize);
1815} 1901}
1816 1902
1903sub set_max {
1904 my ($self, $max) = @_;
1905
1906 $self->{gauge}->set_max ($max);
1907 $self->{max}->set_text ($max);
1908}
1909
1817sub set_value { 1910sub set_value {
1818 my ($self, $val, $max) = @_; 1911 my ($self, $val, $max) = @_;
1819 1912
1820 $self->set_max ($max) 1913 $self->set_max ($max)
1821 if defined $max; 1914 if defined $max;
1822 1915
1823 $self->{gauge}->set_value ($val, $max); 1916 $self->{gauge}->set_value ($val, $max);
1824 $self->{value}->set_text ($val); 1917 $self->{value}->set_text ($val);
1825}
1826
1827sub set_max {
1828 my ($self, $max) = @_;
1829
1830 $self->{gauge}->set_max ($max);
1831 $self->{max}->set_text ($max);
1832} 1918}
1833 1919
1834############################################################################# 1920#############################################################################
1835 1921
1836package CFClient::UI::Slider; 1922package CFClient::UI::Slider;
2119 my ($self) = @_; 2205 my ($self) = @_;
2120 2206
2121 if ($self->{texture}) { 2207 if ($self->{texture}) {
2122 glEnable GL_TEXTURE_2D; 2208 glEnable GL_TEXTURE_2D;
2123 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2209 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2210 glColor 1, 1, 1, 1;
2124 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 2211 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h});
2125 glDisable GL_TEXTURE_2D; 2212 glDisable GL_TEXTURE_2D;
2126 } 2213 }
2127 2214
2128 $self->{children}[1]->draw; 2215 $self->{children}[1]->draw;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines