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.270 by elmex, Fri Jun 2 09:02:49 2006 UTC vs.
Revision 1.279 by root, Mon Jun 5 00:17:47 2006 UTC

371sub size_allocate { 371sub size_allocate {
372 # nothing to be done 372 # nothing to be done
373} 373}
374 374
375sub children { 375sub children {
376 # nop
377}
378
379sub visible_children {
380 $_[0]->children
376} 381}
377 382
378sub set_max_size { 383sub set_max_size {
379 my ($self, $w, $h) = @_; 384 my ($self, $w, $h) = @_;
380 385
439 444
440 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus 445 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus
441 unless $FOCUS; 446 unless $FOCUS;
442} 447}
443 448
444sub mouse_motion { } 449sub mouse_motion { 0 }
445sub button_up { } 450sub button_up { 0 }
446sub key_down { } 451sub key_down { 0 }
447sub key_up { } 452sub key_up { 0 }
448 453
449sub button_down { 454sub button_down {
450 my ($self, $ev, $x, $y) = @_; 455 my ($self, $ev, $x, $y) = @_;
451 456
452 $self->focus_in; 457 $self->focus_in;
458
459 0
453} 460}
454 461
455sub find_widget { 462sub find_widget {
456 my ($self, $x, $y) = @_; 463 my ($self, $x, $y) = @_;
457 464
541 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) 548 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w)
542 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); 549 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h);
543 550
544 glPushMatrix; 551 glPushMatrix;
545 glTranslate $self->{x}, $self->{y}, 0; 552 glTranslate $self->{x}, $self->{y}, 0;
546 $self->_draw;
547 glPopMatrix;
548 553
549 if ($self == $HOVER && $self->{can_hover}) { 554 if ($self == $HOVER && $self->{can_hover}) {
550 my ($x, $y) = @$self{qw(x y)};
551
552 glColor 1, 0.8, 0.5, 0.2; 555 glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2;
553 glEnable GL_BLEND; 556 glEnable GL_BLEND;
554 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 557 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
555 glBegin GL_QUADS; 558 glBegin GL_QUADS;
556 glVertex $x , $y; 559 glVertex 0 , 0;
557 glVertex $x + $self->{w}, $y; 560 glVertex $self->{w}, 0;
558 glVertex $x + $self->{w}, $y + $self->{h}; 561 glVertex $self->{w}, $self->{h};
559 glVertex $x , $y + $self->{h}; 562 glVertex 0 , $self->{h};
560 glEnd; 563 glEnd;
561 glDisable GL_BLEND; 564 glDisable GL_BLEND;
562 } 565 }
563 566
564 if ($ENV{CFPLUS_DEBUG} & 1) { 567 if ($ENV{CFPLUS_DEBUG} & 1) {
565 glPushMatrix; 568 glPushMatrix;
566 glColor 1, 1, 0, 1; 569 glColor 1, 1, 0, 1;
567 glTranslate $self->{x} + 0.375, $self->{y} + 0.375; 570 glTranslate 0.375, 0.375;
568 glBegin GL_LINE_LOOP; 571 glBegin GL_LINE_LOOP;
569 glVertex 0 , 0; 572 glVertex 0 , 0;
570 glVertex $self->{w} - 1, 0; 573 glVertex $self->{w} - 1, 0;
571 glVertex $self->{w} - 1, $self->{h} - 1; 574 glVertex $self->{w} - 1, $self->{h} - 1;
572 glVertex 0 , $self->{h} - 1; 575 glVertex 0 , $self->{h} - 1;
573 glEnd; 576 glEnd;
574 glPopMatrix; 577 glPopMatrix;
575 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; 578 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
576 } 579 }
580
581 $self->_draw;
582 glPopMatrix;
577} 583}
578 584
579sub _draw { 585sub _draw {
580 my ($self) = @_; 586 my ($self) = @_;
581 587
619 625
620 if ($color && (@$color < 4 || $color->[3])) { 626 if ($color && (@$color < 4 || $color->[3])) {
621 my ($w, $h) = @$self{qw(w h)}; 627 my ($w, $h) = @$self{qw(w h)};
622 628
623 glEnable GL_BLEND; 629 glEnable GL_BLEND;
624 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 630 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
625 glColor @$color; 631 glColor_premultiply @$color;
626 632
627 glBegin GL_QUADS; 633 glBegin GL_QUADS;
628 glVertex 0 , 0; 634 glVertex 0 , 0;
629 glVertex 0 , $h; 635 glVertex 0 , $h;
630 glVertex $w, $h; 636 glVertex $w, $h;
661our @ISA = CFClient::UI::Base::; 667our @ISA = CFClient::UI::Base::;
662 668
663sub new { 669sub new {
664 my ($class, %arg) = @_; 670 my ($class, %arg) = @_;
665 671
666 my $children = delete $arg{children} || []; 672 my $children = delete $arg{children};
667 673
668 my $self = $class->SUPER::new ( 674 my $self = $class->SUPER::new (
669 children => [], 675 children => [],
670 can_events => 0, 676 can_events => 0,
671 %arg, 677 %arg,
672 ); 678 );
679
673 $self->add ($_) for @$children; 680 $self->add (@$children)
681 if $children;
674 682
675 $self 683 $self
676} 684}
677 685
678sub add { 686sub add {
726 $x -= $self->{x}; 734 $x -= $self->{x};
727 $y -= $self->{y}; 735 $y -= $self->{y};
728 736
729 my $res; 737 my $res;
730 738
731 for (reverse @{ $self->{children} }) { 739 for (reverse $self->visible_children) {
732 $res = $_->find_widget ($x, $y) 740 $res = $_->find_widget ($x, $y)
733 and return $res; 741 and return $res;
734 } 742 }
735 743
736 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) 744 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
785 $self->{children}[0]->configure (0, 0, $w, $h); 793 $self->{children}[0]->configure (0, 0, $w, $h);
786} 794}
787 795
788############################################################################# 796#############################################################################
789 797
798# back-buffered drawing area
799
790package CFClient::UI::Window; 800package CFClient::UI::Window;
791 801
792our @ISA = CFClient::UI::Bin::; 802our @ISA = CFClient::UI::Bin::;
793 803
794use CFClient::OpenGL; 804use CFClient::OpenGL;
845 my $tex = $self->{texture} 855 my $tex = $self->{texture}
846 or return; 856 or return;
847 857
848 glEnable GL_TEXTURE_2D; 858 glEnable GL_TEXTURE_2D;
849 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 859 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
850 glColor 1, 1, 1, 1; 860 glColor 0, 0, 0, 1;
851 861
852 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 862 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
853 863
854 glDisable GL_TEXTURE_2D; 864 glDisable GL_TEXTURE_2D;
855} 865}
946package CFClient::UI::ScrolledWindow; 956package CFClient::UI::ScrolledWindow;
947 957
948our @ISA = CFClient::UI::HBox::; 958our @ISA = CFClient::UI::HBox::;
949 959
950sub new { 960sub new {
951 my $class = shift; 961 my ($class, %arg) = @_;
962
963 my $child = delete $arg{child};
952 964
953 my $self; 965 my $self;
954 966
955 my $slider = new CFClient::UI::Slider 967 my $slider = new CFClient::UI::Slider
956 vertical => 1, 968 vertical => 1,
961 ; 973 ;
962 974
963 $self = $class->SUPER::new ( 975 $self = $class->SUPER::new (
964 vp => (new CFClient::UI::ViewPort expand => 1), 976 vp => (new CFClient::UI::ViewPort expand => 1),
965 slider => $slider, 977 slider => $slider,
966 @_, 978 %arg,
967 ); 979 );
968 980
969 $self->{vp}->add ($self->{scrolled});
970 $self->add ($self->{vp});
971 $self->add ($self->{slider}); 981 $self->SUPER::add ($self->{vp}, $self->{slider});
982 $self->add ($child) if $child;
972 983
973 $self 984 $self
985}
986
987sub add {
988 my ($self, $widget) = @_;
989
990 $self->{vp}->add ($self->{child} = $widget);
974} 991}
975 992
976sub update { 993sub update {
977 my ($self) = @_; 994 my ($self) = @_;
978 995
1017 1034
1018 if ($self->{bg}) { 1035 if ($self->{bg}) {
1019 my ($w, $h) = @$self{qw(w h)}; 1036 my ($w, $h) = @$self{qw(w h)};
1020 1037
1021 glEnable GL_BLEND; 1038 glEnable GL_BLEND;
1022 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1039 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
1023 glColor @{ $self->{bg} }; 1040 glColor_premultiply @{ $self->{bg} };
1024 1041
1025 glBegin GL_QUADS; 1042 glBegin GL_QUADS;
1026 glVertex 0 , 0; 1043 glVertex 0 , 0;
1027 glVertex 0 , $h; 1044 glVertex 0 , $h;
1028 glVertex $w, $h; 1045 glVertex $w, $h;
1142 my $dy = $ev->{y} - $oy; 1159 my $dy = $ev->{y} - $oy;
1143 1160
1144 $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); 1161 $self->{force_w} = $bw + $dx * ($mx ? -1 : 1);
1145 $self->{force_h} = $bh + $dy * ($my ? -1 : 1); 1162 $self->{force_h} = $bh + $dy * ($my ? -1 : 1);
1146 1163
1164 $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my);
1147 $self->realloc; 1165 $self->realloc;
1148 $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my);
1149 }; 1166 };
1150 1167
1151 } elsif ($lr ^ $td) { 1168 } elsif ($lr ^ $td) {
1152 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 1169 my ($ox, $oy) = ($ev->{x}, $ev->{y});
1153 my ($bx, $by) = ($self->{x}, $self->{y}); 1170 my ($bx, $by) = ($self->{x}, $self->{y});
1156 my ($ev, $x, $y) = @_; 1173 my ($ev, $x, $y) = @_;
1157 1174
1158 ($x, $y) = ($ev->{x}, $ev->{y}); 1175 ($x, $y) = ($ev->{x}, $ev->{y});
1159 1176
1160 $self->move_abs ($bx + $x - $ox, $by + $y - $oy); 1177 $self->move_abs ($bx + $x - $ox, $by + $y - $oy);
1178 # HACK: the next line is required to enforce placement
1179 $self->{parent}->size_allocate ($self->{parent}{w}, $self->{parent}{h});
1161 }; 1180 };
1181 } else {
1182 return 0;
1183 }
1184
1162 } 1185 1
1163} 1186}
1164 1187
1165sub button_up { 1188sub button_up {
1166 my ($self, $ev, $x, $y) = @_; 1189 my ($self, $ev, $x, $y) = @_;
1167 1190
1168 delete $self->{motion}; 1191 !!delete $self->{motion}
1169} 1192}
1170 1193
1171sub mouse_motion { 1194sub mouse_motion {
1172 my ($self, $ev, $x, $y) = @_; 1195 my ($self, $ev, $x, $y) = @_;
1173 1196
1174 $self->{motion}->($ev, $x, $y) if $self->{motion}; 1197 $self->{motion}->($ev, $x, $y) if $self->{motion};
1198
1199 !!$self->{motion}
1175} 1200}
1176 1201
1177sub _draw { 1202sub _draw {
1178 my ($self) = @_; 1203 my ($self) = @_;
1179 1204
1610 }; 1635 };
1611 1636
1612 glEnable GL_TEXTURE_2D; 1637 glEnable GL_TEXTURE_2D;
1613 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1638 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1614 1639
1640 glColor_premultiply @{$self->{fg}}
1615 if ($tex->{format} == GL_ALPHA) { 1641 if $tex->{format} == GL_ALPHA;
1616 glColor @{$self->{fg}}; 1642
1617 $tex->draw_quad_alpha ($self->{ox}, $self->{oy});
1618 } else {
1619 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); 1643 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy});
1620 }
1621 1644
1622 glDisable GL_TEXTURE_2D; 1645 glDisable GL_TEXTURE_2D;
1623} 1646}
1624 1647
1625############################################################################# 1648#############################################################################
1652 1675
1653 delete $self->{cur_h}; 1676 delete $self->{cur_h};
1654 1677
1655 return if $self->{text} eq $text; 1678 return if $self->{text} eq $text;
1656 1679
1657 delete $self->{texture};
1658
1659 $self->{last_activity} = $::NOW; 1680 $self->{last_activity} = $::NOW;
1660 $self->{text} = $text; 1681 $self->{text} = $text;
1661 1682
1662 $text =~ s/./*/g if $self->{hidden}; 1683 $text =~ s/./*/g if $self->{hidden};
1663 $self->{layout}->set_text ("$text "); 1684 $self->{layout}->set_text ("$text ");
1664 1685
1665 $self->_emit (changed => $self->{text}); 1686 $self->_emit (changed => $self->{text});
1687 $self->update;
1666} 1688}
1667 1689
1668sub set_text { 1690sub set_text {
1669 my ($self, $text) = @_; 1691 my ($self, $text) = @_;
1670 1692
1709 $self->{cursor} = length $text; 1731 $self->{cursor} = length $text;
1710 } elsif ($uni == 27) { 1732 } elsif ($uni == 27) {
1711 $self->_emit ('escape'); 1733 $self->_emit ('escape');
1712 } elsif ($uni) { 1734 } elsif ($uni) {
1713 substr $text, $self->{cursor}++, 0, chr $uni; 1735 substr $text, $self->{cursor}++, 0, chr $uni;
1736 } else {
1737 return 0;
1714 } 1738 }
1715 1739
1716 $self->_set_text ($text); 1740 $self->_set_text ($text);
1717 1741
1718 $self->realloc; 1742 $self->realloc;
1743
1744 1
1719} 1745}
1720 1746
1721sub focus_in { 1747sub focus_in {
1722 my ($self) = @_; 1748 my ($self) = @_;
1723 1749
1738 utf8::encode $text; 1764 utf8::encode $text;
1739 $self->{cursor} = length substr $text, 0, $idx; 1765 $self->{cursor} = length substr $text, 0, $idx;
1740 1766
1741 $self->_set_text ($self->{text}); 1767 $self->_set_text ($self->{text});
1742 $self->update; 1768 $self->update;
1769
1770 1
1743} 1771}
1744 1772
1745sub mouse_motion { 1773sub mouse_motion {
1746 my ($self, $ev, $x, $y) = @_; 1774 my ($self, $ev, $x, $y) = @_;
1747# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# 1775# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
1776
1777 0
1748} 1778}
1749 1779
1750sub _draw { 1780sub _draw {
1751 my ($self) = @_; 1781 my ($self) = @_;
1752 1782
1753 local $self->{fg} = $self->{fg}; 1783 local $self->{fg} = $self->{fg};
1754 1784
1755 if ($FOCUS == $self) { 1785 if ($FOCUS == $self) {
1756 glColor @{$self->{active_bg}}; 1786 glColor_premultiply @{$self->{active_bg}};
1757 $self->{fg} = $self->{active_fg}; 1787 $self->{fg} = $self->{active_fg};
1758 } else { 1788 } else {
1759 glColor @{$self->{bg}}; 1789 glColor_premultiply @{$self->{bg}};
1760 } 1790 }
1761 1791
1762 glEnable GL_BLEND; 1792 glEnable GL_BLEND;
1763 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1793 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
1764 glBegin GL_QUADS; 1794 glBegin GL_QUADS;
1765 glVertex 0 , 0; 1795 glVertex 0 , 0;
1766 glVertex 0 , $self->{h}; 1796 glVertex 0 , $self->{h};
1767 glVertex $self->{w}, $self->{h}; 1797 glVertex $self->{w}, $self->{h};
1768 glVertex $self->{w}, 0; 1798 glVertex $self->{w}, 0;
1829 } else { 1859 } else {
1830 $self->set_text ($self->{history_saveback}); 1860 $self->set_text ($self->{history_saveback});
1831 } 1861 }
1832 1862
1833 } else { 1863 } else {
1834 $self->SUPER::key_down ($ev); 1864 return $self->SUPER::key_down ($ev)
1865 }
1866
1835 } 1867 1
1836
1837} 1868}
1838 1869
1839############################################################################# 1870#############################################################################
1840 1871
1841package CFClient::UI::Button; 1872package CFClient::UI::Button;
1870 my ($self, $ev, $x, $y) = @_; 1901 my ($self, $ev, $x, $y) = @_;
1871 1902
1872 $self->emit ("activate") 1903 $self->emit ("activate")
1873 if $x >= 0 && $x < $self->{w} 1904 if $x >= 0 && $x < $self->{w}
1874 && $y >= 0 && $y < $self->{h}; 1905 && $y >= 0 && $y < $self->{h};
1906
1907 1
1875} 1908}
1876 1909
1877sub _draw { 1910sub _draw {
1878 my ($self) = @_; 1911 my ($self) = @_;
1879 1912
1880 local $self->{fg} = $self->{fg}; 1913 local $self->{fg} = $GRAB == $self ? $self->{active_fg} : $self->{fg};
1881
1882 if ($GRAB == $self) {
1883 $self->{fg} = $self->{active_fg};
1884 }
1885 1914
1886 glEnable GL_TEXTURE_2D; 1915 glEnable GL_TEXTURE_2D;
1887 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1916 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1888 glColor 0, 0, 0, 1; 1917 glColor 0, 0, 0, 1;
1889 1918
1933 1962
1934 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} 1963 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
1935 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { 1964 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
1936 $self->{state} = !$self->{state}; 1965 $self->{state} = !$self->{state};
1937 $self->_emit (changed => $self->{state}); 1966 $self->_emit (changed => $self->{state});
1967 } else {
1968 return 0
1969 }
1970
1938 } 1971 1
1939} 1972}
1940 1973
1941sub _draw { 1974sub _draw {
1942 my ($self) = @_; 1975 my ($self) = @_;
1943 1976
2110 2143
2111 my $h1 = $self->{h} * (1 - $ycut1); 2144 my $h1 = $self->{h} * (1 - $ycut1);
2112 my $h2 = $self->{h} * (1 - $ycut2); 2145 my $h2 = $self->{h} * (1 - $ycut2);
2113 2146
2114 glEnable GL_BLEND; 2147 glEnable GL_BLEND;
2115 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2148 glBlendFuncSeparate GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
2149 GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2116 glEnable GL_TEXTURE_2D; 2150 glEnable GL_TEXTURE_2D;
2117 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2151 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2118 2152
2119 glBindTexture GL_TEXTURE_2D, $t1->{name}; 2153 glBindTexture GL_TEXTURE_2D, $t1->{name};
2120 glBegin GL_QUADS; 2154 glBegin GL_QUADS;
2281 2315
2282 $self->SUPER::button_down ($ev, $x, $y); 2316 $self->SUPER::button_down ($ev, $x, $y);
2283 2317
2284 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 2318 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2285 2319
2286 $self->mouse_motion ($ev, $x, $y); 2320 $self->mouse_motion ($ev, $x, $y)
2287} 2321}
2288 2322
2289sub mouse_motion { 2323sub mouse_motion {
2290 my ($self, $ev, $x, $y) = @_; 2324 my ($self, $ev, $x, $y) = @_;
2291 2325
2295 my (undef, $lo, $hi, $page) = @{$self->{range}}; 2329 my (undef, $lo, $hi, $page) = @{$self->{range}};
2296 2330
2297 $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); 2331 $x = ($x - $self->{click}[1]) / ($w * $self->{scale});
2298 2332
2299 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); 2333 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo));
2334 } else {
2335 return 0;
2336 }
2337
2300 } 2338 1
2301} 2339}
2302 2340
2303sub update { 2341sub update {
2304 my ($self) = @_; 2342 my ($self) = @_;
2305 2343
2306 $CFClient::UI::ROOT->on_post_alloc ($self => sub { 2344 delete $self->{knob_w};
2345 $self->SUPER::update;
2346}
2347
2348sub _draw {
2349 my ($self) = @_;
2350
2351 unless ($self->{knob_w}) {
2307 $self->set_value ($self->{range}[0]); 2352 $self->set_value ($self->{range}[0]);
2308 2353
2309 my ($value, $lo, $hi, $page) = @{$self->{range}}; 2354 my ($value, $lo, $hi, $page) = @{$self->{range}};
2310 my $range = ($hi - $page - $lo) || 1e-100; 2355 my $range = ($hi - $page - $lo) || 1e-100;
2311 2356
2317 $value = ($value - $lo) / $range; 2362 $value = ($value - $lo) / $range;
2318 $value = $value * $self->{scale} + $self->{offset}; 2363 $value = $value * $self->{scale} + $self->{offset};
2319 2364
2320 $self->{knob_x} = $value - $knob_w * 0.5; 2365 $self->{knob_x} = $value - $knob_w * 0.5;
2321 $self->{knob_w} = $knob_w; 2366 $self->{knob_w} = $knob_w;
2322 }); 2367 }
2323
2324 $self->SUPER::update;
2325}
2326
2327sub _draw {
2328 my ($self) = @_;
2329 2368
2330 $self->SUPER::_draw (); 2369 $self->SUPER::_draw ();
2331 2370
2332 glScale $self->{w}, $self->{h}; 2371 glScale $self->{w}, $self->{h};
2333 2372
2527 2566
2528 delete $self->{texture}; 2567 delete $self->{texture};
2529 } 2568 }
2530 2569
2531 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { 2570 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub {
2532 glClearColor 0.5, 0.5, 0.5, 0; 2571 glClearColor 0, 0, 0, 0;
2533 glClear GL_COLOR_BUFFER_BIT; 2572 glClear GL_COLOR_BUFFER_BIT;
2534 2573
2535 my $top = int $self->{children}[1]{range}[0]; 2574 my $top = int $self->{children}[1]{range}[0];
2536 2575
2537 my $y0 = $top; 2576 my $y0 = $top;
2572sub _draw { 2611sub _draw {
2573 my ($self) = @_; 2612 my ($self) = @_;
2574 2613
2575 glEnable GL_TEXTURE_2D; 2614 glEnable GL_TEXTURE_2D;
2576 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2615 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2577 glColor 1, 1, 1, 1; 2616 glColor 0, 0, 0, 1;
2578 $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2617 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2579 glDisable GL_TEXTURE_2D; 2618 glDisable GL_TEXTURE_2D;
2580 2619
2581 $self->{children}[1]->draw; 2620 $self->{children}[1]->draw;
2582 2621
2583} 2622}
2810 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; 2849 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]];
2811 2850
2812 if ($tex) { 2851 if ($tex) {
2813 glEnable GL_TEXTURE_2D; 2852 glEnable GL_TEXTURE_2D;
2814 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2853 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2815 glColor 1, 1, 1, 1; 2854 glColor 0, 0, 0, 1;
2816 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2855 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2817 glDisable GL_TEXTURE_2D; 2856 glDisable GL_TEXTURE_2D;
2818 } 2857 }
2819} 2858}
2820 2859
2824 $self->{timer}->cancel 2863 $self->{timer}->cancel
2825 if $self->{timer}; 2864 if $self->{timer};
2826 2865
2827 $self->SUPER::DESTROY; 2866 $self->SUPER::DESTROY;
2828} 2867}
2868
2869#############################################################################
2870
2871package CFClient::UI::Buttonbar;
2872
2873our @ISA = CFClient::UI::HBox::;
2874
2875# TODO: should actualyl wrap buttons and other goodies.
2829 2876
2830############################################################################# 2877#############################################################################
2831 2878
2832package CFClient::UI::Menu; 2879package CFClient::UI::Menu;
2833 2880
2883 my ($self, $ev, $x, $y) = @_; 2930 my ($self, $ev, $x, $y) = @_;
2884 2931
2885 # TODO: should use vbox->find_widget or so 2932 # TODO: should use vbox->find_widget or so
2886 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); 2933 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2887 $self->{hover} = $self->{item}{$HOVER}; 2934 $self->{hover} = $self->{item}{$HOVER};
2935
2936 0
2888} 2937}
2889 2938
2890sub button_up { 2939sub button_up {
2891 my ($self, $ev, $x, $y) = @_; 2940 my ($self, $ev, $x, $y) = @_;
2892 2941
2894 undef $GRAB; 2943 undef $GRAB;
2895 $self->hide; 2944 $self->hide;
2896 2945
2897 $self->_emit ("popdown"); 2946 $self->_emit ("popdown");
2898 $self->{hover}[1]->() if $self->{hover}; 2947 $self->{hover}[1]->() if $self->{hover};
2948 } else {
2949 return 0
2950 }
2951
2952 1
2953}
2954
2955#############################################################################
2956
2957package CFClient::UI::Multiplexer;
2958
2959our @ISA = CFClient::UI::Container::;
2960
2961sub new {
2962 my $class = shift;
2963
2964 my $self = $class->SUPER::new (
2965 @_,
2966 );
2967
2968 $self->{current} = $self->{children}[0]
2969 if @{ $self->{children} };
2970
2971 $self
2972}
2973
2974sub add {
2975 my ($self, @widgets) = @_;
2976
2977 $self->SUPER::add (@widgets);
2978
2979 $self->{current} = $self->{children}[0]
2980 if @{ $self->{children} };
2981}
2982
2983sub set_current_page {
2984 my ($self, $page_or_widget) = @_;
2985
2986 my $widget = ref $page_or_widget
2987 ? $page_or_widget
2988 : $self->{children}[$page_or_widget];
2989
2990 $self->{current} = $widget;
2991 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
2992
2993 $self->_emit (page_changed => $self->{current});
2994
2995 $self->realloc;
2996}
2997
2998sub visible_children {
2999 $_[0]{current}
3000}
3001
3002sub size_request {
3003 my ($self) = @_;
3004
3005 $self->{current}->size_request
3006}
3007
3008sub size_allocate {
3009 my ($self, $w, $h) = @_;
3010
3011 $self->{current}->configure (0, 0, $w, $h);
3012}
3013
3014sub _draw {
3015 my ($self) = @_;
3016
3017 $self->{current}->draw;
3018}
3019
3020#############################################################################
3021
3022package CFClient::UI::Notebook;
3023
3024our @ISA = CFClient::UI::VBox::;
3025
3026sub new {
3027 my $class = shift;
3028
3029 my $self = $class->SUPER::new (
3030 buttonbar => (new CFClient::UI::Buttonbar),
3031 multiplexer => (new CFClient::UI::Multiplexer expand => 1),
3032 # filter => # will be put between multiplexer and $self
3033 @_,
3034 );
2899 } 3035
3036 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3037 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3038
3039 $self
3040}
3041
3042sub add {
3043 my ($self, $title, $widget, $tooltip) = @_;
3044
3045 Scalar::Util::weaken $self;
3046
3047 $self->{buttonbar}->add (new CFClient::UI::Button
3048 markup => $title,
3049 tooltip => $tooltip,
3050 on_activate => sub { $self->set_current_page ($widget) },
3051 );
3052
3053 $self->{multiplexer}->add ($widget);
3054}
3055
3056sub set_current_page {
3057 my ($self, $page) = @_;
3058
3059 $self->{multiplexer}->set_current_page ($page);
3060 $self->_emit (page_changed => $self->{multiplexer}{current});
2900} 3061}
2901 3062
2902############################################################################# 3063#############################################################################
2903 3064
2904package CFClient::UI::Statusbox; 3065package CFClient::UI::Statusbox;
3017 3178
3018sub new { 3179sub new {
3019 my $class = shift; 3180 my $class = shift;
3020 3181
3021 my $self = $class->SUPER::new ( 3182 my $self = $class->SUPER::new (
3022 scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), 3183 child => (new CFClient::UI::Table col_expand => [0, 1, 0]),
3023 @_, 3184 @_,
3024 ); 3185 );
3025 3186
3026 $self 3187 $self
3027} 3188}
3028 3189
3029sub set_items { 3190sub set_items {
3030 my ($self, $items) = @_; 3191 my ($self, $items) = @_;
3031 3192
3032 $self->{scrolled}->clear; 3193 $self->{child}->clear;
3033 return unless $items; 3194 return unless $items;
3034 3195
3035 my @items = sort { 3196 my @items = sort {
3036 ($a->{type} <=> $b->{type}) 3197 ($a->{type} <=> $b->{type})
3037 or ($a->{name} cmp $b->{name}) 3198 or ($a->{name} cmp $b->{name})
3041 3202
3042 my $row = 0; 3203 my $row = 0;
3043 for my $item (@items) { 3204 for my $item (@items) {
3044 CFClient::Item::update_widgets $item; 3205 CFClient::Item::update_widgets $item;
3045 3206
3046 $self->{scrolled}->add (0, $row, $item->{face_widget}); 3207 $self->{child}->add (0, $row, $item->{face_widget});
3047 $self->{scrolled}->add (1, $row, $item->{desc_widget}); 3208 $self->{child}->add (1, $row, $item->{desc_widget});
3048 $self->{scrolled}->add (2, $row, $item->{weight_widget}); 3209 $self->{child}->add (2, $row, $item->{weight_widget});
3049 3210
3050 $row++; 3211 $row++;
3051 } 3212 }
3052} 3213}
3053 3214
3250 3411
3251############################################################################# 3412#############################################################################
3252 3413
3253package CFClient::UI::SpellList; 3414package CFClient::UI::SpellList;
3254 3415
3255our @ISA = CFClient::UI::FancyFrame::; 3416our @ISA = CFClient::UI::Table::;
3256 3417
3257sub new { 3418sub new {
3258 my $class = shift; 3419 my $class = shift;
3259 3420
3260 my $self = $class->SUPER::new (binding => [], commands => [], @_); 3421 my $self = $class->SUPER::new (
3261 3422 binding => [],
3262 $self->add (new CFClient::UI::ScrolledWindow 3423 commands => [],
3263 scrolled => $self->{spellbox} = new CFClient::UI::Table); 3424 @_,
3264 3425 )
3265 $self;
3266} 3426}
3267 3427
3268# XXX: Do sorting? Argl... 3428# XXX: Do sorting? Argl...
3269sub add_spell { 3429sub add_spell {
3270 my ($self, $spell) = @_; 3430 my ($self, $spell) = @_;
3271 $self->{spells}->{$spell->{name}} = $spell; 3431 $self->{spells}->{$spell->{name}} = $spell;
3272 3432
3273 $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face 3433 $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face
3274 face => $spell->{face}, 3434 face => $spell->{face},
3275 can_hover => 1, 3435 can_hover => 1,
3276 can_events => 1, 3436 can_events => 1,
3277 tooltip => $spell->{message}); 3437 tooltip => $spell->{message});
3278 3438
3279 $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label 3439 $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label
3280 text => $spell->{name}, 3440 text => $spell->{name},
3281 can_hover => 1, 3441 can_hover => 1,
3282 can_events => 1, 3442 can_events => 1,
3283 tooltip => $spell->{message}, 3443 tooltip => $spell->{message},
3284 expand => 1); 3444 expand => 1);
3285 3445
3286 $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label 3446 $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label
3287 text => (sprintf "lvl: %2d sp: %2d dmg: %2d", 3447 text => (sprintf "lvl: %2d sp: %2d dmg: %2d",
3288 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), 3448 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}),
3289 expand => 1); 3449 expand => 1);
3290 3450
3291 $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button 3451 $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button
3292 text => "bind to key", 3452 text => "bind to key",
3293 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); 3453 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) });
3294} 3454}
3295 3455
3296sub rebuild_spell_list { 3456sub rebuild_spell_list {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines