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.418 by elmex, Tue Jul 24 18:39:39 2007 UTC vs.
Revision 1.432 by root, Tue Aug 21 23:42:02 2007 UTC

607sub DESTROY { 607sub DESTROY {
608 my ($self) = @_; 608 my ($self) = @_;
609 609
610 return if CFPlus::in_destruct; 610 return if CFPlus::in_destruct;
611 611
612 local $@;
612 eval { $self->destroy }; 613 eval { $self->destroy };
613 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 614 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
614 615
615 delete $WIDGET{$self+0}; 616 delete $WIDGET{$self+0};
616} 617}
624use strict; 625use strict;
625use CFPlus::OpenGL; 626use CFPlus::OpenGL;
626 627
627sub new { 628sub new {
628 my $class = shift; 629 my $class = shift;
629
630 # range [value, low, high, page]
631 630
632 $class->SUPER::new ( 631 $class->SUPER::new (
633 #bg => [0, 0, 0, 0.2], 632 #bg => [0, 0, 0, 0.2],
634 #active_bg => [1, 1, 1, 0.5], 633 #active_bg => [1, 1, 1, 0.5],
635 @_ 634 @_
647 my ($w, $h) = @$self{qw(w h)}; 646 my ($w, $h) = @$self{qw(w h)};
648 647
649 glEnable GL_BLEND; 648 glEnable GL_BLEND;
650 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 649 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
651 glColor_premultiply @$color; 650 glColor_premultiply @$color;
652
653 glBegin GL_QUADS;
654 glVertex 0 , 0;
655 glVertex 0 , $h;
656 glVertex $w, $h; 651 glRect 0, 0, $w, $h;
657 glVertex $w, 0;
658 glEnd;
659
660 glDisable GL_BLEND; 652 glDisable GL_BLEND;
661 } 653 }
662} 654}
663 655
664############################################################################# 656#############################################################################
1027 my $child = delete $arg{child}; 1019 my $child = delete $arg{child};
1028 1020
1029 my $self; 1021 my $self;
1030 1022
1031 my $hslider = new CFPlus::UI::Slider 1023 my $hslider = new CFPlus::UI::Slider
1032 col => 0, 1024 c_col => 0,
1033 row => 1, 1025 c_row => 1,
1034 vertical => 0, 1026 vertical => 0,
1035 range => [0, 0, 1, 0.01], # HACK fix 1027 range => [0, 0, 1, 0.01], # HACK fix
1036 on_changed => sub { 1028 on_changed => sub {
1037 $self->{hpos} = $_[1]; 1029 $self->{hpos} = $_[1];
1038 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1030 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1039 }, 1031 },
1040 ; 1032 ;
1041 1033
1042 my $vslider = new CFPlus::UI::Slider 1034 my $vslider = new CFPlus::UI::Slider
1043 col => 1, 1035 c_col => 1,
1044 row => 0, 1036 c_row => 0,
1045 vertical => 1, 1037 vertical => 1,
1046 range => [0, 0, 1, 0.01], # HACK fix 1038 range => [0, 0, 1, 0.01], # HACK fix
1047 on_changed => sub { 1039 on_changed => sub {
1048 $self->{vpos} = $_[1]; 1040 $self->{vpos} = $_[1];
1049 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1041 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1060 row_expand => [1, 0], 1052 row_expand => [1, 0],
1061 %arg, 1053 %arg,
1062 ); 1054 );
1063 1055
1064 $self->{vp} = new CFPlus::UI::ViewPort 1056 $self->{vp} = new CFPlus::UI::ViewPort
1065 col => 0, 1057 c_col => 0,
1066 row => 0, 1058 c_row => 0,
1067 expand => 1, 1059 expand => 1,
1068 scroll_x => $self->{scroll_x}, 1060 scroll_x => $self->{scroll_x},
1069 scroll_y => $self->{scroll_y}, 1061 scroll_y => $self->{scroll_y},
1070 on_changed => sub { 1062 on_changed => sub {
1071 my ($vp, $x, $y) = @_; 1063 my ($vp, $x, $y) = @_;
1219 my ($w, $h) = @$self{qw(w h)}; 1211 my ($w, $h) = @$self{qw(w h)};
1220 1212
1221 glEnable GL_BLEND; 1213 glEnable GL_BLEND;
1222 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 1214 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
1223 glColor_premultiply @{ $self->{bg} }; 1215 glColor_premultiply @{ $self->{bg} };
1224
1225 glBegin GL_QUADS;
1226 glVertex 0 , 0;
1227 glVertex 0 , $h;
1228 glVertex $w, $h; 1216 glRect 0, 0, $w, $h;
1229 glVertex $w, 0;
1230 glEnd;
1231
1232 glDisable GL_BLEND; 1217 glDisable GL_BLEND;
1233 } 1218 }
1234 1219
1235 $self->SUPER::_draw; 1220 $self->SUPER::_draw;
1236} 1221}
1598 1583
1599sub add { 1584sub add {
1600 my ($self, @widgets) = @_; 1585 my ($self, @widgets) = @_;
1601 1586
1602 for my $child (@widgets) { 1587 for my $child (@widgets) {
1603 $child->{rowspan} ||= 1; 1588 $child->{c_rowspan} ||= 1;
1604 $child->{colspan} ||= 1; 1589 $child->{c_colspan} ||= 1;
1605 } 1590 }
1606 1591
1607 $self->SUPER::add (@widgets); 1592 $self->SUPER::add (@widgets);
1608} 1593}
1609 1594
1613 my @widgets; 1598 my @widgets;
1614 1599
1615 while (@_) { 1600 while (@_) {
1616 my ($col, $row, $child) = splice @_, 0, 3, (); 1601 my ($col, $row, $child) = splice @_, 0, 3, ();
1617 1602
1618 $child->{row} = $row; 1603 $child->{c_row} = $row;
1619 $child->{col} = $col; 1604 $child->{c_col} = $col;
1620 1605
1621 push @widgets, $child; 1606 push @widgets, $child;
1622 } 1607 }
1623 1608
1624 $self->add (@widgets); 1609 $self->add (@widgets);
1630 my (@w, @h); 1615 my (@w, @h);
1631 1616
1632 my @children = $self->children; 1617 my @children = $self->children;
1633 1618
1634 # first pass, columns 1619 # first pass, columns
1635 for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { 1620 for my $widget (sort { $a->{c_colspan} <=> $b->{c_colspan} } @children) {
1636 my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; 1621 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)};
1637 1622
1638 my $sw = sum @w[$c .. $c + $cs - 1]; 1623 my $sw = sum @w[$c .. $c + $cs - 1];
1639 1624
1640 if ($w > $sw) { 1625 if ($w > $sw) {
1641 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; 1626 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1];
1642 } 1627 }
1643 } 1628 }
1644 1629
1645 # second pass, rows 1630 # second pass, rows
1646 for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { 1631 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) {
1647 my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; 1632 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)};
1648 1633
1649 my $sh = sum @h[$r .. $r + $rs - 1]; 1634 my $sh = sum @h[$r .. $r + $rs - 1];
1650 1635
1651 if ($h > $sh) { 1636 if ($h > $sh) {
1652 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; 1637 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1];
1694 1679
1695 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } 1680 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] }
1696 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } 1681 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] }
1697 1682
1698 for my $widget ($self->children) { 1683 for my $widget ($self->children) {
1699 my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; 1684 my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(c_row c_col req_w req_h c_rowspan c_colspan)};
1700 1685
1701 $widget->configure ( 1686 $widget->configure (
1702 $x[$c], $y[$r], 1687 $x[$c], $y[$r],
1703 $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], 1688 $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r],
1704 ); 1689 );
1923 1908
1924 delete $self->{ox}; 1909 delete $self->{ox};
1925 $self->SUPER::realloc; 1910 $self->SUPER::realloc;
1926} 1911}
1927 1912
1913sub clear {
1914 my ($self) = @_;
1915
1916 $self->set_text ("");
1917}
1918
1928sub set_text { 1919sub set_text {
1929 my ($self, $text) = @_; 1920 my ($self, $text) = @_;
1930 1921
1931 return if $self->{text} eq "T$text"; 1922 return if $self->{text} eq "T$text";
1932 $self->{text} = "T$text"; 1923 $self->{text} = "T$text";
2038 : ($self->{w} - $size->[0]) * 0.5); 2029 : ($self->{w} - $size->[0]) * 0.5);
2039 2030
2040 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 2031 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2041 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} 2032 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2042 : ($self->{h} - $size->[1]) * 0.5); 2033 : ($self->{h} - $size->[1]) * 0.5);
2034
2035 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2043 }; 2036 };
2044 2037
2045# unless ($self->{list}) { 2038# unless ($self->{list}) {
2046# $self->{list} = CFPlus::OpenGL::glGenList; 2039# $self->{list} = CFPlus::OpenGL::glGenList;
2047# CFPlus::OpenGL::glNewList $self->{list}; 2040# CFPlus::OpenGL::glNewList $self->{list};
2049# CFPlus::OpenGL::glEndList; 2042# CFPlus::OpenGL::glEndList;
2050# } 2043# }
2051# 2044#
2052# CFPlus::OpenGL::glCallList $self->{list}; 2045# CFPlus::OpenGL::glCallList $self->{list};
2053 2046
2054 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2047 $self->{layout}->draw;
2055} 2048}
2056 2049
2057#sub destroy { 2050#sub destroy {
2058# my ($self) = @_; 2051# my ($self) = @_;
2059# 2052#
2074 my $class = shift; 2067 my $class = shift;
2075 2068
2076 $class->SUPER::new ( 2069 $class->SUPER::new (
2077 fg => [1, 1, 1], 2070 fg => [1, 1, 1],
2078 bg => [0, 0, 0, 0.2], 2071 bg => [0, 0, 0, 0.2],
2072 outline => [0.6, 0.3, 0.1],
2079 active_bg => [0, 0, 1, .2], 2073 active_bg => [0, 0, 1, .2],
2080 active_fg => [1, 1, 1], 2074 active_fg => [1, 1, 1],
2081 active_outline => [1, 1, 0], 2075 active_outline => [1, 1, 0],
2082 can_hover => 1, 2076 can_hover => 1,
2083 can_focus => 1, 2077 can_focus => 1,
2226 glColor_premultiply @{$self->{bg}}; 2220 glColor_premultiply @{$self->{bg}};
2227 } 2221 }
2228 2222
2229 glEnable GL_BLEND; 2223 glEnable GL_BLEND;
2230 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2224 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2231 glBegin GL_QUADS;
2232 glVertex 0 , 0;
2233 glVertex 0 , $self->{h};
2234 glVertex $self->{w}, $self->{h}; 2225 glRect 0, 0, $self->{w}, $self->{h};
2235 glVertex $self->{w}, 0;
2236 glEnd;
2237 glDisable GL_BLEND; 2226 glDisable GL_BLEND;
2238 2227
2239 $self->SUPER::_draw; 2228 $self->SUPER::_draw;
2240 2229
2241 #TODO: force update every cursor change :( 2230 #TODO: force update every cursor change :(
2254 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; 2243 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
2255 glEnd; 2244 glEnd;
2256 2245
2257 glLineWidth 3; 2246 glLineWidth 3;
2258 glColor @{$self->{active_outline}}; 2247 glColor @{$self->{active_outline}};
2248 glRect_lineloop 0, 0, $self->{w} - 1, $self->{h} - 1;
2249 glLineWidth 1;
2250
2251 } else {
2252 glColor @{$self->{outline}};
2259 glTranslate -.375, -.375; 2253 glTranslate .375, .375;
2260 glBegin GL_LINE_LOOP; 2254 glBegin GL_LINE_STRIP;
2261 glVertex 0, 0; 2255 glVertex 0, $self->{h} * .5;
2262 glVertex $self->{w}, 0;
2263 glVertex $self->{w}, $self->{h};
2264 glVertex 0, $self->{h}; 2256 glVertex 0, $self->{h} - 3;
2257 glVertex $self->{w} - 1, $self->{h} - 3;
2258 glVertex $self->{w} - 1, $self->{h} * .5;
2265 glEnd; 2259 glEnd;
2266 glLineWidth 1;
2267 } 2260 }
2268} 2261}
2269 2262
2270############################################################################# 2263#############################################################################
2271 2264
2633 align => 0, 2626 align => 0,
2634 valign => 0, 2627 valign => 0,
2635 can_events => 1, 2628 can_events => 1,
2636 @_ 2629 @_
2637 ); 2630 );
2631}
2632
2633sub invoke_button_down {
2634 my ($self, $ev, $x, $y) = @_;
2635
2636 1
2638} 2637}
2639 2638
2640sub invoke_button_up { 2639sub invoke_button_up {
2641 my ($self, $ev, $x, $y) = @_; 2640 my ($self, $ev, $x, $y) = @_;
2642 2641
2782 glDisable GL_TEXTURE_2D; 2781 glDisable GL_TEXTURE_2D;
2783} 2782}
2784 2783
2785############################################################################# 2784#############################################################################
2786 2785
2786package CFPlus::UI::Progress;
2787
2788our @ISA = CFPlus::UI::Label::;
2789
2790use CFPlus::OpenGL;
2791
2792sub new {
2793 my ($class, %arg) = @_;
2794
2795 my $self = $class->SUPER::new (
2796 fg => [1, 1, 1],
2797 bg => [0, 0, 1, 0.2],
2798 bar => [0.7, 0.5, 0.1, 0.8],
2799 outline => [0.4, 0.3, 0],
2800 fontsize => 0.9,
2801 valign => 0,
2802 align => 0,
2803 can_events => 1,
2804 ellipsise => 1,
2805 %arg,
2806 );
2807
2808 $self->set_value ($arg{value} || -1);
2809
2810 $self
2811}
2812
2813sub set_value {
2814 my ($self, $value) = @_;
2815
2816 if ($self->{value} != $value) {
2817 $self->{value} = $value;
2818
2819 if ($value < 0) {
2820 $self->set_text ("-");
2821 } else {
2822 $self->set_text (sprintf "%d%%", $value * 100);
2823 }
2824 $self->update;
2825 }
2826}
2827
2828sub _draw {
2829 my ($self) = @_;
2830
2831 glEnable GL_BLEND;
2832 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2833
2834 if ($self->{value} >= 0) {
2835 my $s = 3 + ($self->{w} - 6) * $self->{value};
2836
2837 glColor_premultiply @{$self->{bar}};
2838 glRect 2, 2, $s, $self->{h} - 2;
2839 glColor_premultiply @{$self->{bg}};
2840 glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2;
2841 }
2842
2843 glColor_premultiply @{$self->{outline}};
2844 glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2;
2845
2846 glDisable GL_BLEND;
2847
2848 {
2849 local $self->{bg}; # do not draw background
2850 $self->SUPER::_draw;
2851 }
2852}
2853
2854#############################################################################
2855
2856package CFPlus::UI::ExperienceProgress;
2857
2858our @ISA = CFPlus::UI::Progress::;
2859
2860sub new {
2861 my ($class, %arg) = @_;
2862
2863 my $self = $class->SUPER::new (
2864 %arg
2865 );
2866
2867 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2868 if $::CONN;
2869
2870 $self
2871}
2872
2873sub DESTROY {
2874 my ($self) = @_;
2875
2876 delete $::CONN->{on_exp_update}{$self+0}
2877 if $::CONN;
2878
2879 $self->SUPER::DESTROY;
2880}
2881
2882sub set_value {
2883 my ($self, $lvl, $exp) = @_;
2884
2885 my $v = -1;
2886
2887 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2888 my $l0 = $table->[$lvl - 1];
2889 my $l1 = $table->[$lvl];
2890
2891 $v = ($exp - $l0) / ($l1 - $l0);
2892 }
2893
2894 $self->SUPER::set_value ($v);
2895}
2896
2897#############################################################################
2898
2787package CFPlus::UI::Gauge; 2899package CFPlus::UI::Gauge;
2788 2900
2789our @ISA = CFPlus::UI::VBox::; 2901our @ISA = CFPlus::UI::VBox::;
2790 2902
2791sub new { 2903sub new {
3288 3400
3289 if ($y0 < $y + $h && $y < $y1) { 3401 if ($y0 < $y + $h && $y < $y1) {
3290 my $layout = $self->get_layout ($para); 3402 my $layout = $self->get_layout ($para);
3291 3403
3292 $layout->render ($para->{indent}, $y - $y0); 3404 $layout->render ($para->{indent}, $y - $y0);
3405 $layout->draw;
3293 3406
3294 if (my @w = @{ $para->{widget} }) { 3407 if (my @w = @{ $para->{widget} }) {
3295 my @s = $layout->get_shapes; 3408 my @s = $layout->get_shapes;
3296 3409
3297 for (@w) { 3410 for (@w) {
3488 glTranslate 0.375, 0.375; 3601 glTranslate 0.375, 0.375;
3489 3602
3490 my ($w, $h) = @$self{qw(w h)}; 3603 my ($w, $h) = @$self{qw(w h)};
3491 3604
3492 glColor 1, 0.8, 0.4; 3605 glColor 1, 0.8, 0.4;
3493 glBegin GL_QUADS; 3606 glRect 0, 0, $w, $h;
3494 glVertex 0 , 0;
3495 glVertex 0 , $h;
3496 glVertex $w, $h;
3497 glVertex $w, 0;
3498 glEnd;
3499 3607
3500 glColor 0, 0, 0; 3608 glColor 0, 0, 0;
3501 glBegin GL_LINE_LOOP; 3609 glRect_lineloop 0, 0, $w, $h;
3502 glVertex 0 , 0;
3503 glVertex 0 , $h;
3504 glVertex $w, $h;
3505 glVertex $w, 0;
3506 glEnd;
3507 3610
3508 glTranslate 2 - 0.375, 2 - 0.375; 3611 glTranslate 2 - 0.375, 2 - 0.375;
3509 3612
3510 $self->SUPER::_draw; 3613 $self->SUPER::_draw;
3511} 3614}
3535 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3638 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3536 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; 3639 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed};
3537 $self->{timer} = Event->timer ( 3640 $self->{timer} = Event->timer (
3538 parked => 1, 3641 parked => 1,
3539 cb => sub { 3642 cb => sub {
3540 return unless $::CONN && $widget; 3643 return unless $::CONN;
3541 3644
3645 my $w = $widget
3646 or return;
3647
3542 ++$widget->{frame}; 3648 ++$w->{frame};
3543 $widget->update_face; 3649 $w->update_face;
3650
3651 # somehow, $widget can go away
3544 $widget->update; 3652 $w->update;
3545
3546 $widget->update_timer; 3653 $w->update_timer;
3547 }, 3654 },
3548 ); 3655 );
3549 3656
3550 $self->update_face; 3657 $self->update_face;
3551 $self->update_timer; 3658 $self->update_timer;
3572} 3679}
3573 3680
3574sub update_face { 3681sub update_face {
3575 my ($self) = @_; 3682 my ($self) = @_;
3576 3683
3577 return unless $::CONN; 3684 if ($::CONN) {
3578
3579 if (my $anim = $::CONN->{anim}[$self->{anim}]) { 3685 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3580 if ($anim && @$anim) { 3686 if ($anim && @$anim) {
3581 delete $self->{wait_face};
3582 $self->{face} = $anim->[ $self->{frame} % @$anim ]; 3687 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3688 delete $self->{face_change_cb};
3689
3583 $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ]; 3690 if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) {
3691 unless ($tex->{name} || $tex->{loading}) {
3692 $tex->upload (sub { $self->reconfigure });
3693 }
3694 }
3695 }
3584 } 3696 }
3585 } 3697 }
3586} 3698}
3587 3699
3588sub size_request { 3700sub size_request {
3589 my ($self) = @_; 3701 my ($self) = @_;
3590 3702
3591 if ($::CONN) { 3703 if ($::CONN) {
3592 if (my $faceid = $::CONN->{faceid}[$self->{face}]) { 3704 if (my $faceid = $::CONN->{face}[$self->{face}]{id}) {
3593 if (my $tex = $::CONN->{texture}[$faceid]) { 3705 if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) {
3594 $self->{tex} = $tex; 3706 if ($tex->{name}) {
3595 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); 3707 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3596 } else { 3708 } elsif (!$tex->{loading}) {
3597 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { 3709 $tex->upload (sub { $self->reconfigure });
3598 $self->realloc;
3599 }); 3710 }
3600 } 3711 }
3712
3713 $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure });
3601 } 3714 }
3602 } 3715 }
3603 3716
3604 ($self->{size_w} || 8, $self->{size_h} || 8) 3717 ($self->{size_w} || 8, $self->{size_h} || 8)
3605} 3718}
3820 3933
3821############################################################################# 3934#############################################################################
3822 3935
3823package CFPlus::UI::Notebook; 3936package CFPlus::UI::Notebook;
3824 3937
3938use CFPlus::OpenGL;
3939
3825our @ISA = CFPlus::UI::VBox::; 3940our @ISA = CFPlus::UI::VBox::;
3826 3941
3827sub new { 3942sub new {
3828 my $class = shift; 3943 my $class = shift;
3829 3944
3830 my $self = $class->SUPER::new ( 3945 my $self = $class->SUPER::new (
3831 buttonbar => (new CFPlus::UI::Buttonbar), 3946 buttonbar => (new CFPlus::UI::Buttonbar),
3832 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3947 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3948 active_outline => [1, 1, 0],
3833 # filter => # will be put between multiplexer and $self 3949 # filter => # will be put between multiplexer and $self
3834 @_, 3950 @_,
3835 ); 3951 );
3836 3952
3837 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3953 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3909sub set_current_page { 4025sub set_current_page {
3910 my ($self, $page) = @_; 4026 my ($self, $page) = @_;
3911 4027
3912 $self->{multiplexer}->set_current_page ($page); 4028 $self->{multiplexer}->set_current_page ($page);
3913 $self->emit (page_changed => $self->{multiplexer}{current}); 4029 $self->emit (page_changed => $self->{multiplexer}{current});
4030}
4031
4032sub _draw {
4033 my ($self) = @_;
4034
4035 $self->SUPER::_draw ();
4036
4037 if (my $cur = $self->{multiplexer}{current}) {
4038 if ($cur = $cur->{c_tab_}) {
4039 glTranslate $cur->{x}, $cur->{y};
4040 glLineWidth 3;
4041 glColor @{$self->{active_outline}};
4042 glRect_lineloop 1, 1, $cur->{w} - 2, $cur->{h} - 2;
4043 glLineWidth 1;
4044 }
4045 }
3914} 4046}
3915 4047
3916############################################################################# 4048#############################################################################
3917 4049
3918package CFPlus::UI::Selector; 4050package CFPlus::UI::Selector;
4188} 4320}
4189 4321
4190sub update { 4322sub update {
4191 my ($self) = @_; 4323 my ($self) = @_;
4192 4324
4193 $::WANT_REFRESH++; 4325 $::WANT_REFRESH->start;
4194} 4326}
4195 4327
4196sub add { 4328sub add {
4197 my ($self, @children) = @_; 4329 my ($self, @children) = @_;
4198 4330

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines