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.433 by root, Wed Aug 22 21:27:13 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 label => "%d%%",
2806 %arg,
2807 );
2808
2809 $self->set_value ($arg{value} || -1);
2810
2811 $self
2812}
2813
2814sub set_label {
2815 my ($self, $label) = @_;
2816
2817 return if $self->{label} eq $label;
2818 $self->{label} = $label;
2819
2820 $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value});
2821}
2822
2823sub set_value {
2824 my ($self, $value) = @_;
2825
2826 if ($self->{value} ne $value) {
2827 $self->{value} = $value;
2828
2829 if ($value < 0) {
2830 $self->set_text ("-");
2831 } else {
2832 $self->set_text (sprintf $self->{label}, $value * 100);
2833 }
2834
2835 $self->update;
2836 }
2837}
2838
2839sub _draw {
2840 my ($self) = @_;
2841
2842 glEnable GL_BLEND;
2843 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2844
2845 if ($self->{value} >= 0) {
2846 my $s = 3 + ($self->{w} - 6) * $self->{value};
2847
2848 glColor_premultiply @{$self->{bar}};
2849 glRect 2, 2, $s, $self->{h} - 2;
2850 glColor_premultiply @{$self->{bg}};
2851 glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2;
2852 }
2853
2854 glColor_premultiply @{$self->{outline}};
2855 glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2;
2856
2857 glDisable GL_BLEND;
2858
2859 {
2860 local $self->{bg}; # do not draw background
2861 $self->SUPER::_draw;
2862 }
2863}
2864
2865#############################################################################
2866
2867package CFPlus::UI::ExperienceProgress;
2868
2869our @ISA = CFPlus::UI::Progress::;
2870
2871sub new {
2872 my ($class, %arg) = @_;
2873
2874 my $self = $class->SUPER::new (
2875 %arg
2876 );
2877
2878 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2879 if $::CONN;
2880
2881 $self
2882}
2883
2884sub DESTROY {
2885 my ($self) = @_;
2886
2887 delete $::CONN->{on_exp_update}{$self+0}
2888 if $::CONN;
2889
2890 $self->SUPER::DESTROY;
2891}
2892
2893sub set_value {
2894 my ($self, $lvl, $exp) = @_;
2895
2896 my $v = -1;
2897
2898 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2899 my $l0 = $table->[$lvl - 1];
2900 my $l1 = $table->[$lvl];
2901
2902 $v = ($exp - $l0) / ($l1 - $l0);
2903 }
2904
2905 $self->SUPER::set_value ($v);
2906}
2907
2908#############################################################################
2909
2787package CFPlus::UI::Gauge; 2910package CFPlus::UI::Gauge;
2788 2911
2789our @ISA = CFPlus::UI::VBox::; 2912our @ISA = CFPlus::UI::VBox::;
2790 2913
2791sub new { 2914sub new {
3288 3411
3289 if ($y0 < $y + $h && $y < $y1) { 3412 if ($y0 < $y + $h && $y < $y1) {
3290 my $layout = $self->get_layout ($para); 3413 my $layout = $self->get_layout ($para);
3291 3414
3292 $layout->render ($para->{indent}, $y - $y0); 3415 $layout->render ($para->{indent}, $y - $y0);
3416 $layout->draw;
3293 3417
3294 if (my @w = @{ $para->{widget} }) { 3418 if (my @w = @{ $para->{widget} }) {
3295 my @s = $layout->get_shapes; 3419 my @s = $layout->get_shapes;
3296 3420
3297 for (@w) { 3421 for (@w) {
3488 glTranslate 0.375, 0.375; 3612 glTranslate 0.375, 0.375;
3489 3613
3490 my ($w, $h) = @$self{qw(w h)}; 3614 my ($w, $h) = @$self{qw(w h)};
3491 3615
3492 glColor 1, 0.8, 0.4; 3616 glColor 1, 0.8, 0.4;
3493 glBegin GL_QUADS; 3617 glRect 0, 0, $w, $h;
3494 glVertex 0 , 0;
3495 glVertex 0 , $h;
3496 glVertex $w, $h;
3497 glVertex $w, 0;
3498 glEnd;
3499 3618
3500 glColor 0, 0, 0; 3619 glColor 0, 0, 0;
3501 glBegin GL_LINE_LOOP; 3620 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 3621
3508 glTranslate 2 - 0.375, 2 - 0.375; 3622 glTranslate 2 - 0.375, 2 - 0.375;
3509 3623
3510 $self->SUPER::_draw; 3624 $self->SUPER::_draw;
3511} 3625}
3535 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3649 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3536 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; 3650 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed};
3537 $self->{timer} = Event->timer ( 3651 $self->{timer} = Event->timer (
3538 parked => 1, 3652 parked => 1,
3539 cb => sub { 3653 cb => sub {
3540 return unless $::CONN && $widget; 3654 return unless $::CONN;
3541 3655
3656 my $w = $widget
3657 or return;
3658
3542 ++$widget->{frame}; 3659 ++$w->{frame};
3543 $widget->update_face; 3660 $w->update_face;
3661
3662 # somehow, $widget can go away
3544 $widget->update; 3663 $w->update;
3545
3546 $widget->update_timer; 3664 $w->update_timer;
3547 }, 3665 },
3548 ); 3666 );
3549 3667
3550 $self->update_face; 3668 $self->update_face;
3551 $self->update_timer; 3669 $self->update_timer;
3572} 3690}
3573 3691
3574sub update_face { 3692sub update_face {
3575 my ($self) = @_; 3693 my ($self) = @_;
3576 3694
3577 return unless $::CONN; 3695 if ($::CONN) {
3578
3579 if (my $anim = $::CONN->{anim}[$self->{anim}]) { 3696 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3580 if ($anim && @$anim) { 3697 if ($anim && @$anim) {
3581 delete $self->{wait_face};
3582 $self->{face} = $anim->[ $self->{frame} % @$anim ]; 3698 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3699 delete $self->{face_change_cb};
3700
3583 $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ]; 3701 if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) {
3702 unless ($tex->{name} || $tex->{loading}) {
3703 $tex->upload (sub { $self->reconfigure });
3704 }
3705 }
3706 }
3584 } 3707 }
3585 } 3708 }
3586} 3709}
3587 3710
3588sub size_request { 3711sub size_request {
3589 my ($self) = @_; 3712 my ($self) = @_;
3590 3713
3591 if ($::CONN) { 3714 if ($::CONN) {
3592 if (my $faceid = $::CONN->{faceid}[$self->{face}]) { 3715 if (my $faceid = $::CONN->{face}[$self->{face}]{id}) {
3593 if (my $tex = $::CONN->{texture}[$faceid]) { 3716 if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) {
3594 $self->{tex} = $tex; 3717 if ($tex->{name}) {
3595 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); 3718 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3596 } else { 3719 } elsif (!$tex->{loading}) {
3597 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { 3720 $tex->upload (sub { $self->reconfigure });
3598 $self->realloc;
3599 }); 3721 }
3600 } 3722 }
3723
3724 $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure });
3601 } 3725 }
3602 } 3726 }
3603 3727
3604 ($self->{size_w} || 8, $self->{size_h} || 8) 3728 ($self->{size_w} || 8, $self->{size_h} || 8)
3605} 3729}
3820 3944
3821############################################################################# 3945#############################################################################
3822 3946
3823package CFPlus::UI::Notebook; 3947package CFPlus::UI::Notebook;
3824 3948
3949use CFPlus::OpenGL;
3950
3825our @ISA = CFPlus::UI::VBox::; 3951our @ISA = CFPlus::UI::VBox::;
3826 3952
3827sub new { 3953sub new {
3828 my $class = shift; 3954 my $class = shift;
3829 3955
3830 my $self = $class->SUPER::new ( 3956 my $self = $class->SUPER::new (
3831 buttonbar => (new CFPlus::UI::Buttonbar), 3957 buttonbar => (new CFPlus::UI::Buttonbar),
3832 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3958 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3959 active_outline => [1, 1, 0],
3833 # filter => # will be put between multiplexer and $self 3960 # filter => # will be put between multiplexer and $self
3834 @_, 3961 @_,
3835 ); 3962 );
3836 3963
3837 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3964 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3909sub set_current_page { 4036sub set_current_page {
3910 my ($self, $page) = @_; 4037 my ($self, $page) = @_;
3911 4038
3912 $self->{multiplexer}->set_current_page ($page); 4039 $self->{multiplexer}->set_current_page ($page);
3913 $self->emit (page_changed => $self->{multiplexer}{current}); 4040 $self->emit (page_changed => $self->{multiplexer}{current});
4041}
4042
4043sub _draw {
4044 my ($self) = @_;
4045
4046 $self->SUPER::_draw ();
4047
4048 if (my $cur = $self->{multiplexer}{current}) {
4049 if ($cur = $cur->{c_tab_}) {
4050 glTranslate $cur->{x}, $cur->{y};
4051 glLineWidth 3;
4052 glColor @{$self->{active_outline}};
4053 glRect_lineloop 1, 1, $cur->{w} - 2, $cur->{h} - 2;
4054 glLineWidth 1;
4055 }
4056 }
3914} 4057}
3915 4058
3916############################################################################# 4059#############################################################################
3917 4060
3918package CFPlus::UI::Selector; 4061package CFPlus::UI::Selector;
4188} 4331}
4189 4332
4190sub update { 4333sub update {
4191 my ($self) = @_; 4334 my ($self) = @_;
4192 4335
4193 $::WANT_REFRESH++; 4336 $::WANT_REFRESH->start;
4194} 4337}
4195 4338
4196sub add { 4339sub add {
4197 my ($self, @children) = @_; 4340 my ($self, @children) = @_;
4198 4341

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines