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.271 by root, Fri Jun 2 22:13:47 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
543 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) 548 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w)
544 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); 549 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h);
545 550
546 glPushMatrix; 551 glPushMatrix;
547 glTranslate $self->{x}, $self->{y}, 0; 552 glTranslate $self->{x}, $self->{y}, 0;
548 $self->_draw;
549 glPopMatrix;
550 553
551 if ($self == $HOVER && $self->{can_hover}) { 554 if ($self == $HOVER && $self->{can_hover}) {
552 my ($x, $y) = @$self{qw(x y)};
553
554 glColor 1, 0.8, 0.5, 0.2; 555 glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2;
555 glEnable GL_BLEND; 556 glEnable GL_BLEND;
556 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 557 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
557 glBegin GL_QUADS; 558 glBegin GL_QUADS;
558 glVertex $x , $y; 559 glVertex 0 , 0;
559 glVertex $x + $self->{w}, $y; 560 glVertex $self->{w}, 0;
560 glVertex $x + $self->{w}, $y + $self->{h}; 561 glVertex $self->{w}, $self->{h};
561 glVertex $x , $y + $self->{h}; 562 glVertex 0 , $self->{h};
562 glEnd; 563 glEnd;
563 glDisable GL_BLEND; 564 glDisable GL_BLEND;
564 } 565 }
565 566
566 if ($ENV{CFPLUS_DEBUG} & 1) { 567 if ($ENV{CFPLUS_DEBUG} & 1) {
567 glPushMatrix; 568 glPushMatrix;
568 glColor 1, 1, 0, 1; 569 glColor 1, 1, 0, 1;
569 glTranslate $self->{x} + 0.375, $self->{y} + 0.375; 570 glTranslate 0.375, 0.375;
570 glBegin GL_LINE_LOOP; 571 glBegin GL_LINE_LOOP;
571 glVertex 0 , 0; 572 glVertex 0 , 0;
572 glVertex $self->{w} - 1, 0; 573 glVertex $self->{w} - 1, 0;
573 glVertex $self->{w} - 1, $self->{h} - 1; 574 glVertex $self->{w} - 1, $self->{h} - 1;
574 glVertex 0 , $self->{h} - 1; 575 glVertex 0 , $self->{h} - 1;
575 glEnd; 576 glEnd;
576 glPopMatrix; 577 glPopMatrix;
577 #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;
578 } 579 }
580
581 $self->_draw;
582 glPopMatrix;
579} 583}
580 584
581sub _draw { 585sub _draw {
582 my ($self) = @_; 586 my ($self) = @_;
583 587
621 625
622 if ($color && (@$color < 4 || $color->[3])) { 626 if ($color && (@$color < 4 || $color->[3])) {
623 my ($w, $h) = @$self{qw(w h)}; 627 my ($w, $h) = @$self{qw(w h)};
624 628
625 glEnable GL_BLEND; 629 glEnable GL_BLEND;
626 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 630 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
627 glColor @$color; 631 glColor_premultiply @$color;
628 632
629 glBegin GL_QUADS; 633 glBegin GL_QUADS;
630 glVertex 0 , 0; 634 glVertex 0 , 0;
631 glVertex 0 , $h; 635 glVertex 0 , $h;
632 glVertex $w, $h; 636 glVertex $w, $h;
663our @ISA = CFClient::UI::Base::; 667our @ISA = CFClient::UI::Base::;
664 668
665sub new { 669sub new {
666 my ($class, %arg) = @_; 670 my ($class, %arg) = @_;
667 671
668 my $children = delete $arg{children} || []; 672 my $children = delete $arg{children};
669 673
670 my $self = $class->SUPER::new ( 674 my $self = $class->SUPER::new (
671 children => [], 675 children => [],
672 can_events => 0, 676 can_events => 0,
673 %arg, 677 %arg,
674 ); 678 );
679
675 $self->add ($_) for @$children; 680 $self->add (@$children)
681 if $children;
676 682
677 $self 683 $self
678} 684}
679 685
680sub add { 686sub add {
728 $x -= $self->{x}; 734 $x -= $self->{x};
729 $y -= $self->{y}; 735 $y -= $self->{y};
730 736
731 my $res; 737 my $res;
732 738
733 for (reverse @{ $self->{children} }) { 739 for (reverse $self->visible_children) {
734 $res = $_->find_widget ($x, $y) 740 $res = $_->find_widget ($x, $y)
735 and return $res; 741 and return $res;
736 } 742 }
737 743
738 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) 744 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
787 $self->{children}[0]->configure (0, 0, $w, $h); 793 $self->{children}[0]->configure (0, 0, $w, $h);
788} 794}
789 795
790############################################################################# 796#############################################################################
791 797
798# back-buffered drawing area
799
792package CFClient::UI::Window; 800package CFClient::UI::Window;
793 801
794our @ISA = CFClient::UI::Bin::; 802our @ISA = CFClient::UI::Bin::;
795 803
796use CFClient::OpenGL; 804use CFClient::OpenGL;
847 my $tex = $self->{texture} 855 my $tex = $self->{texture}
848 or return; 856 or return;
849 857
850 glEnable GL_TEXTURE_2D; 858 glEnable GL_TEXTURE_2D;
851 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 859 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
852 glColor 1, 1, 1, 1; 860 glColor 0, 0, 0, 1;
853 861
854 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 862 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
855 863
856 glDisable GL_TEXTURE_2D; 864 glDisable GL_TEXTURE_2D;
857} 865}
948package CFClient::UI::ScrolledWindow; 956package CFClient::UI::ScrolledWindow;
949 957
950our @ISA = CFClient::UI::HBox::; 958our @ISA = CFClient::UI::HBox::;
951 959
952sub new { 960sub new {
953 my $class = shift; 961 my ($class, %arg) = @_;
962
963 my $child = delete $arg{child};
954 964
955 my $self; 965 my $self;
956 966
957 my $slider = new CFClient::UI::Slider 967 my $slider = new CFClient::UI::Slider
958 vertical => 1, 968 vertical => 1,
963 ; 973 ;
964 974
965 $self = $class->SUPER::new ( 975 $self = $class->SUPER::new (
966 vp => (new CFClient::UI::ViewPort expand => 1), 976 vp => (new CFClient::UI::ViewPort expand => 1),
967 slider => $slider, 977 slider => $slider,
968 @_, 978 %arg,
969 ); 979 );
970 980
971 $self->{vp}->add ($self->{scrolled});
972 $self->add ($self->{vp});
973 $self->add ($self->{slider}); 981 $self->SUPER::add ($self->{vp}, $self->{slider});
982 $self->add ($child) if $child;
974 983
975 $self 984 $self
985}
986
987sub add {
988 my ($self, $widget) = @_;
989
990 $self->{vp}->add ($self->{child} = $widget);
976} 991}
977 992
978sub update { 993sub update {
979 my ($self) = @_; 994 my ($self) = @_;
980 995
1019 1034
1020 if ($self->{bg}) { 1035 if ($self->{bg}) {
1021 my ($w, $h) = @$self{qw(w h)}; 1036 my ($w, $h) = @$self{qw(w h)};
1022 1037
1023 glEnable GL_BLEND; 1038 glEnable GL_BLEND;
1024 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1039 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
1025 glColor @{ $self->{bg} }; 1040 glColor_premultiply @{ $self->{bg} };
1026 1041
1027 glBegin GL_QUADS; 1042 glBegin GL_QUADS;
1028 glVertex 0 , 0; 1043 glVertex 0 , 0;
1029 glVertex 0 , $h; 1044 glVertex 0 , $h;
1030 glVertex $w, $h; 1045 glVertex $w, $h;
1144 my $dy = $ev->{y} - $oy; 1159 my $dy = $ev->{y} - $oy;
1145 1160
1146 $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); 1161 $self->{force_w} = $bw + $dx * ($mx ? -1 : 1);
1147 $self->{force_h} = $bh + $dy * ($my ? -1 : 1); 1162 $self->{force_h} = $bh + $dy * ($my ? -1 : 1);
1148 1163
1164 $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my);
1149 $self->realloc; 1165 $self->realloc;
1150 $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my);
1151 }; 1166 };
1152 1167
1153 } elsif ($lr ^ $td) { 1168 } elsif ($lr ^ $td) {
1154 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 1169 my ($ox, $oy) = ($ev->{x}, $ev->{y});
1155 my ($bx, $by) = ($self->{x}, $self->{y}); 1170 my ($bx, $by) = ($self->{x}, $self->{y});
1158 my ($ev, $x, $y) = @_; 1173 my ($ev, $x, $y) = @_;
1159 1174
1160 ($x, $y) = ($ev->{x}, $ev->{y}); 1175 ($x, $y) = ($ev->{x}, $ev->{y});
1161 1176
1162 $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});
1163 }; 1180 };
1164 } else { 1181 } else {
1165 return 0; 1182 return 0;
1166 } 1183 }
1167 1184
1618 }; 1635 };
1619 1636
1620 glEnable GL_TEXTURE_2D; 1637 glEnable GL_TEXTURE_2D;
1621 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1638 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1622 1639
1640 glColor_premultiply @{$self->{fg}}
1623 if ($tex->{format} == GL_ALPHA) { 1641 if $tex->{format} == GL_ALPHA;
1624 glColor @{$self->{fg}}; 1642
1625 $tex->draw_quad_alpha ($self->{ox}, $self->{oy});
1626 } else {
1627 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); 1643 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy});
1628 }
1629 1644
1630 glDisable GL_TEXTURE_2D; 1645 glDisable GL_TEXTURE_2D;
1631} 1646}
1632 1647
1633############################################################################# 1648#############################################################################
1660 1675
1661 delete $self->{cur_h}; 1676 delete $self->{cur_h};
1662 1677
1663 return if $self->{text} eq $text; 1678 return if $self->{text} eq $text;
1664 1679
1665 delete $self->{texture};
1666
1667 $self->{last_activity} = $::NOW; 1680 $self->{last_activity} = $::NOW;
1668 $self->{text} = $text; 1681 $self->{text} = $text;
1669 1682
1670 $text =~ s/./*/g if $self->{hidden}; 1683 $text =~ s/./*/g if $self->{hidden};
1671 $self->{layout}->set_text ("$text "); 1684 $self->{layout}->set_text ("$text ");
1672 1685
1673 $self->_emit (changed => $self->{text}); 1686 $self->_emit (changed => $self->{text});
1687 $self->update;
1674} 1688}
1675 1689
1676sub set_text { 1690sub set_text {
1677 my ($self, $text) = @_; 1691 my ($self, $text) = @_;
1678 1692
1767 my ($self) = @_; 1781 my ($self) = @_;
1768 1782
1769 local $self->{fg} = $self->{fg}; 1783 local $self->{fg} = $self->{fg};
1770 1784
1771 if ($FOCUS == $self) { 1785 if ($FOCUS == $self) {
1772 glColor @{$self->{active_bg}}; 1786 glColor_premultiply @{$self->{active_bg}};
1773 $self->{fg} = $self->{active_fg}; 1787 $self->{fg} = $self->{active_fg};
1774 } else { 1788 } else {
1775 glColor @{$self->{bg}}; 1789 glColor_premultiply @{$self->{bg}};
1776 } 1790 }
1777 1791
1778 glEnable GL_BLEND; 1792 glEnable GL_BLEND;
1779 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1793 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
1780 glBegin GL_QUADS; 1794 glBegin GL_QUADS;
1781 glVertex 0 , 0; 1795 glVertex 0 , 0;
1782 glVertex 0 , $self->{h}; 1796 glVertex 0 , $self->{h};
1783 glVertex $self->{w}, $self->{h}; 1797 glVertex $self->{w}, $self->{h};
1784 glVertex $self->{w}, 0; 1798 glVertex $self->{w}, 0;
1894} 1908}
1895 1909
1896sub _draw { 1910sub _draw {
1897 my ($self) = @_; 1911 my ($self) = @_;
1898 1912
1899 local $self->{fg} = $self->{fg}; 1913 local $self->{fg} = $GRAB == $self ? $self->{active_fg} : $self->{fg};
1900
1901 if ($GRAB == $self) {
1902 $self->{fg} = $self->{active_fg};
1903 }
1904 1914
1905 glEnable GL_TEXTURE_2D; 1915 glEnable GL_TEXTURE_2D;
1906 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1916 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1907 glColor 0, 0, 0, 1; 1917 glColor 0, 0, 0, 1;
1908 1918
2133 2143
2134 my $h1 = $self->{h} * (1 - $ycut1); 2144 my $h1 = $self->{h} * (1 - $ycut1);
2135 my $h2 = $self->{h} * (1 - $ycut2); 2145 my $h2 = $self->{h} * (1 - $ycut2);
2136 2146
2137 glEnable GL_BLEND; 2147 glEnable GL_BLEND;
2138 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;
2139 glEnable GL_TEXTURE_2D; 2150 glEnable GL_TEXTURE_2D;
2140 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2151 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2141 2152
2142 glBindTexture GL_TEXTURE_2D, $t1->{name}; 2153 glBindTexture GL_TEXTURE_2D, $t1->{name};
2143 glBegin GL_QUADS; 2154 glBegin GL_QUADS;
2328} 2339}
2329 2340
2330sub update { 2341sub update {
2331 my ($self) = @_; 2342 my ($self) = @_;
2332 2343
2333 $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}) {
2334 $self->set_value ($self->{range}[0]); 2352 $self->set_value ($self->{range}[0]);
2335 2353
2336 my ($value, $lo, $hi, $page) = @{$self->{range}}; 2354 my ($value, $lo, $hi, $page) = @{$self->{range}};
2337 my $range = ($hi - $page - $lo) || 1e-100; 2355 my $range = ($hi - $page - $lo) || 1e-100;
2338 2356
2344 $value = ($value - $lo) / $range; 2362 $value = ($value - $lo) / $range;
2345 $value = $value * $self->{scale} + $self->{offset}; 2363 $value = $value * $self->{scale} + $self->{offset};
2346 2364
2347 $self->{knob_x} = $value - $knob_w * 0.5; 2365 $self->{knob_x} = $value - $knob_w * 0.5;
2348 $self->{knob_w} = $knob_w; 2366 $self->{knob_w} = $knob_w;
2349 }); 2367 }
2350
2351 $self->SUPER::update;
2352}
2353
2354sub _draw {
2355 my ($self) = @_;
2356 2368
2357 $self->SUPER::_draw (); 2369 $self->SUPER::_draw ();
2358 2370
2359 glScale $self->{w}, $self->{h}; 2371 glScale $self->{w}, $self->{h};
2360 2372
2554 2566
2555 delete $self->{texture}; 2567 delete $self->{texture};
2556 } 2568 }
2557 2569
2558 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { 2570 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub {
2559 glClearColor 0.5, 0.5, 0.5, 0; 2571 glClearColor 0, 0, 0, 0;
2560 glClear GL_COLOR_BUFFER_BIT; 2572 glClear GL_COLOR_BUFFER_BIT;
2561 2573
2562 my $top = int $self->{children}[1]{range}[0]; 2574 my $top = int $self->{children}[1]{range}[0];
2563 2575
2564 my $y0 = $top; 2576 my $y0 = $top;
2599sub _draw { 2611sub _draw {
2600 my ($self) = @_; 2612 my ($self) = @_;
2601 2613
2602 glEnable GL_TEXTURE_2D; 2614 glEnable GL_TEXTURE_2D;
2603 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2615 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2604 glColor 1, 1, 1, 1; 2616 glColor 0, 0, 0, 1;
2605 $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});
2606 glDisable GL_TEXTURE_2D; 2618 glDisable GL_TEXTURE_2D;
2607 2619
2608 $self->{children}[1]->draw; 2620 $self->{children}[1]->draw;
2609 2621
2610} 2622}
2837 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; 2849 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]];
2838 2850
2839 if ($tex) { 2851 if ($tex) {
2840 glEnable GL_TEXTURE_2D; 2852 glEnable GL_TEXTURE_2D;
2841 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2853 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2842 glColor 1, 1, 1, 1; 2854 glColor 0, 0, 0, 1;
2843 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2855 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2844 glDisable GL_TEXTURE_2D; 2856 glDisable GL_TEXTURE_2D;
2845 } 2857 }
2846} 2858}
2847 2859
2851 $self->{timer}->cancel 2863 $self->{timer}->cancel
2852 if $self->{timer}; 2864 if $self->{timer};
2853 2865
2854 $self->SUPER::DESTROY; 2866 $self->SUPER::DESTROY;
2855} 2867}
2868
2869#############################################################################
2870
2871package CFClient::UI::Buttonbar;
2872
2873our @ISA = CFClient::UI::HBox::;
2874
2875# TODO: should actualyl wrap buttons and other goodies.
2856 2876
2857############################################################################# 2877#############################################################################
2858 2878
2859package CFClient::UI::Menu; 2879package CFClient::UI::Menu;
2860 2880
2928 } else { 2948 } else {
2929 return 0 2949 return 0
2930 } 2950 }
2931 2951
2932 1 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 );
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});
2933} 3061}
2934 3062
2935############################################################################# 3063#############################################################################
2936 3064
2937package CFClient::UI::Statusbox; 3065package CFClient::UI::Statusbox;
3050 3178
3051sub new { 3179sub new {
3052 my $class = shift; 3180 my $class = shift;
3053 3181
3054 my $self = $class->SUPER::new ( 3182 my $self = $class->SUPER::new (
3055 scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), 3183 child => (new CFClient::UI::Table col_expand => [0, 1, 0]),
3056 @_, 3184 @_,
3057 ); 3185 );
3058 3186
3059 $self 3187 $self
3060} 3188}
3061 3189
3062sub set_items { 3190sub set_items {
3063 my ($self, $items) = @_; 3191 my ($self, $items) = @_;
3064 3192
3065 $self->{scrolled}->clear; 3193 $self->{child}->clear;
3066 return unless $items; 3194 return unless $items;
3067 3195
3068 my @items = sort { 3196 my @items = sort {
3069 ($a->{type} <=> $b->{type}) 3197 ($a->{type} <=> $b->{type})
3070 or ($a->{name} cmp $b->{name}) 3198 or ($a->{name} cmp $b->{name})
3074 3202
3075 my $row = 0; 3203 my $row = 0;
3076 for my $item (@items) { 3204 for my $item (@items) {
3077 CFClient::Item::update_widgets $item; 3205 CFClient::Item::update_widgets $item;
3078 3206
3079 $self->{scrolled}->add (0, $row, $item->{face_widget}); 3207 $self->{child}->add (0, $row, $item->{face_widget});
3080 $self->{scrolled}->add (1, $row, $item->{desc_widget}); 3208 $self->{child}->add (1, $row, $item->{desc_widget});
3081 $self->{scrolled}->add (2, $row, $item->{weight_widget}); 3209 $self->{child}->add (2, $row, $item->{weight_widget});
3082 3210
3083 $row++; 3211 $row++;
3084 } 3212 }
3085} 3213}
3086 3214
3283 3411
3284############################################################################# 3412#############################################################################
3285 3413
3286package CFClient::UI::SpellList; 3414package CFClient::UI::SpellList;
3287 3415
3288our @ISA = CFClient::UI::FancyFrame::; 3416our @ISA = CFClient::UI::Table::;
3289 3417
3290sub new { 3418sub new {
3291 my $class = shift; 3419 my $class = shift;
3292 3420
3293 my $self = $class->SUPER::new (binding => [], commands => [], @_); 3421 my $self = $class->SUPER::new (
3294 3422 binding => [],
3295 $self->add (new CFClient::UI::ScrolledWindow 3423 commands => [],
3296 scrolled => $self->{spellbox} = new CFClient::UI::Table); 3424 @_,
3297 3425 )
3298 $self;
3299} 3426}
3300 3427
3301# XXX: Do sorting? Argl... 3428# XXX: Do sorting? Argl...
3302sub add_spell { 3429sub add_spell {
3303 my ($self, $spell) = @_; 3430 my ($self, $spell) = @_;
3304 $self->{spells}->{$spell->{name}} = $spell; 3431 $self->{spells}->{$spell->{name}} = $spell;
3305 3432
3306 $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face 3433 $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face
3307 face => $spell->{face}, 3434 face => $spell->{face},
3308 can_hover => 1, 3435 can_hover => 1,
3309 can_events => 1, 3436 can_events => 1,
3310 tooltip => $spell->{message}); 3437 tooltip => $spell->{message});
3311 3438
3312 $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label 3439 $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label
3313 text => $spell->{name}, 3440 text => $spell->{name},
3314 can_hover => 1, 3441 can_hover => 1,
3315 can_events => 1, 3442 can_events => 1,
3316 tooltip => $spell->{message}, 3443 tooltip => $spell->{message},
3317 expand => 1); 3444 expand => 1);
3318 3445
3319 $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label 3446 $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label
3320 text => (sprintf "lvl: %2d sp: %2d dmg: %2d", 3447 text => (sprintf "lvl: %2d sp: %2d dmg: %2d",
3321 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), 3448 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}),
3322 expand => 1); 3449 expand => 1);
3323 3450
3324 $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button 3451 $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button
3325 text => "bind to key", 3452 text => "bind to key",
3326 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); 3453 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) });
3327} 3454}
3328 3455
3329sub rebuild_spell_list { 3456sub rebuild_spell_list {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines