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.417 by root, Tue Jul 24 18:24:04 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
2357 1 2350 1
2358} 2351}
2359 2352
2360############################################################################# 2353#############################################################################
2361 2354
2355package CFPlus::UI::ButtonBin;
2356
2357our @ISA = CFPlus::UI::Bin::;
2358
2359use CFPlus::OpenGL;
2360
2361my @tex =
2362 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2363 qw(b1_button_inactive.png b1_button_active.png);
2364
2365sub new {
2366 my $class = shift;
2367
2368 $class->SUPER::new (
2369 can_hover => 1,
2370 align => 0,
2371 valign => 0,
2372 can_events => 1,
2373 @_
2374 )
2375}
2376
2377sub invoke_button_up {
2378 my ($self, $ev, $x, $y) = @_;
2379
2380 $self->emit ("activate")
2381 if $x >= 0 && $x < $self->{w}
2382 && $y >= 0 && $y < $self->{h};
2383
2384 1
2385}
2386
2387sub _draw {
2388 my ($self) = @_;
2389
2390 glEnable GL_TEXTURE_2D;
2391 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2392 glColor 0, 0, 0, 1;
2393
2394 my $tex = $tex[$GRAB == $self];
2395 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2396
2397 glDisable GL_TEXTURE_2D;
2398
2399 $self->SUPER::_draw;
2400}
2401
2402#############################################################################
2403
2362package CFPlus::UI::Button; 2404package CFPlus::UI::Button;
2363 2405
2364our @ISA = CFPlus::UI::Label::; 2406our @ISA = CFPlus::UI::Label::;
2365 2407
2366use CFPlus::OpenGL; 2408use CFPlus::OpenGL;
2500sub new { 2542sub new {
2501 my $class = shift; 2543 my $class = shift;
2502 2544
2503 my $self = $class->SUPER::new ( 2545 my $self = $class->SUPER::new (
2504 can_events => 0, 2546 can_events => 0,
2547 scale => 1,
2505 @_, 2548 @_,
2506 ); 2549 );
2507 2550
2508 $self->{path} || $self->{tex} 2551 $self->{path} || $self->{tex}
2509 or Carp::croak "'path' or 'tex' attributes required"; 2552 or Carp::croak "'path' or 'tex' attributes required";
2534} 2577}
2535 2578
2536sub size_request { 2579sub size_request {
2537 my ($self) = @_; 2580 my ($self) = @_;
2538 2581
2539 ($self->{tex}{w}, $self->{tex}{h}) 2582 (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale})
2540} 2583}
2541 2584
2542sub _draw { 2585sub _draw {
2543 my ($self) = @_; 2586 my ($self) = @_;
2544 2587
2554 } 2597 }
2555 2598
2556 glEnable GL_TEXTURE_2D; 2599 glEnable GL_TEXTURE_2D;
2557 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2600 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2558 2601
2559 $tex->draw_quad (0, 0, $w, $h); 2602 $tex->draw_quad_alpha (0, 0, $w, $h);
2560 2603
2561 glDisable GL_TEXTURE_2D; 2604 glDisable GL_TEXTURE_2D;
2562} 2605}
2563 2606
2564############################################################################# 2607#############################################################################
2583 align => 0, 2626 align => 0,
2584 valign => 0, 2627 valign => 0,
2585 can_events => 1, 2628 can_events => 1,
2586 @_ 2629 @_
2587 ); 2630 );
2631}
2632
2633sub invoke_button_down {
2634 my ($self, $ev, $x, $y) = @_;
2635
2636 1
2588} 2637}
2589 2638
2590sub invoke_button_up { 2639sub invoke_button_up {
2591 my ($self, $ev, $x, $y) = @_; 2640 my ($self, $ev, $x, $y) = @_;
2592 2641
2732 glDisable GL_TEXTURE_2D; 2781 glDisable GL_TEXTURE_2D;
2733} 2782}
2734 2783
2735############################################################################# 2784#############################################################################
2736 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
2737package CFPlus::UI::Gauge; 2899package CFPlus::UI::Gauge;
2738 2900
2739our @ISA = CFPlus::UI::VBox::; 2901our @ISA = CFPlus::UI::VBox::;
2740 2902
2741sub new { 2903sub new {
3238 3400
3239 if ($y0 < $y + $h && $y < $y1) { 3401 if ($y0 < $y + $h && $y < $y1) {
3240 my $layout = $self->get_layout ($para); 3402 my $layout = $self->get_layout ($para);
3241 3403
3242 $layout->render ($para->{indent}, $y - $y0); 3404 $layout->render ($para->{indent}, $y - $y0);
3405 $layout->draw;
3243 3406
3244 if (my @w = @{ $para->{widget} }) { 3407 if (my @w = @{ $para->{widget} }) {
3245 my @s = $layout->get_shapes; 3408 my @s = $layout->get_shapes;
3246 3409
3247 for (@w) { 3410 for (@w) {
3438 glTranslate 0.375, 0.375; 3601 glTranslate 0.375, 0.375;
3439 3602
3440 my ($w, $h) = @$self{qw(w h)}; 3603 my ($w, $h) = @$self{qw(w h)};
3441 3604
3442 glColor 1, 0.8, 0.4; 3605 glColor 1, 0.8, 0.4;
3443 glBegin GL_QUADS; 3606 glRect 0, 0, $w, $h;
3444 glVertex 0 , 0;
3445 glVertex 0 , $h;
3446 glVertex $w, $h;
3447 glVertex $w, 0;
3448 glEnd;
3449 3607
3450 glColor 0, 0, 0; 3608 glColor 0, 0, 0;
3451 glBegin GL_LINE_LOOP; 3609 glRect_lineloop 0, 0, $w, $h;
3452 glVertex 0 , 0;
3453 glVertex 0 , $h;
3454 glVertex $w, $h;
3455 glVertex $w, 0;
3456 glEnd;
3457 3610
3458 glTranslate 2 - 0.375, 2 - 0.375; 3611 glTranslate 2 - 0.375, 2 - 0.375;
3459 3612
3460 $self->SUPER::_draw; 3613 $self->SUPER::_draw;
3461} 3614}
3485 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3638 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3486 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; 3639 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed};
3487 $self->{timer} = Event->timer ( 3640 $self->{timer} = Event->timer (
3488 parked => 1, 3641 parked => 1,
3489 cb => sub { 3642 cb => sub {
3490 return unless $::CONN && $widget; 3643 return unless $::CONN;
3491 3644
3645 my $w = $widget
3646 or return;
3647
3492 ++$widget->{frame}; 3648 ++$w->{frame};
3493 $widget->update_face; 3649 $w->update_face;
3650
3651 # somehow, $widget can go away
3494 $widget->update; 3652 $w->update;
3495
3496 $widget->update_timer; 3653 $w->update_timer;
3497 }, 3654 },
3498 ); 3655 );
3499 3656
3500 $self->update_face; 3657 $self->update_face;
3501 $self->update_timer; 3658 $self->update_timer;
3522} 3679}
3523 3680
3524sub update_face { 3681sub update_face {
3525 my ($self) = @_; 3682 my ($self) = @_;
3526 3683
3527 return unless $::CONN; 3684 if ($::CONN) {
3528
3529 if (my $anim = $::CONN->{anim}[$self->{anim}]) { 3685 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3530 if ($anim && @$anim) { 3686 if ($anim && @$anim) {
3531 delete $self->{wait_face};
3532 $self->{face} = $anim->[ $self->{frame} % @$anim ]; 3687 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3688 delete $self->{face_change_cb};
3689
3533 $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 }
3534 } 3696 }
3535 } 3697 }
3536} 3698}
3537 3699
3538sub size_request { 3700sub size_request {
3539 my ($self) = @_; 3701 my ($self) = @_;
3540 3702
3541 if ($::CONN) { 3703 if ($::CONN) {
3542 if (my $faceid = $::CONN->{faceid}[$self->{face}]) { 3704 if (my $faceid = $::CONN->{face}[$self->{face}]{id}) {
3543 if (my $tex = $::CONN->{texture}[$faceid]) { 3705 if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) {
3544 $self->{tex} = $tex; 3706 if ($tex->{name}) {
3545 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); 3707 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3546 } else { 3708 } elsif (!$tex->{loading}) {
3547 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { 3709 $tex->upload (sub { $self->reconfigure });
3548 $self->realloc;
3549 }); 3710 }
3550 } 3711 }
3712
3713 $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure });
3551 } 3714 }
3552 } 3715 }
3553 3716
3554 ($self->{size_w} || 8, $self->{size_h} || 8) 3717 ($self->{size_w} || 8, $self->{size_h} || 8)
3555} 3718}
3635 children => [ 3798 children => [
3636 (new CFPlus::UI::Label markup => $left, expand => 1), 3799 (new CFPlus::UI::Label markup => $left, expand => 1),
3637 (new CFPlus::UI::Label markup => $right, align => +1), 3800 (new CFPlus::UI::Label markup => $right, align => +1),
3638 ], 3801 ],
3639 ; 3802 ;
3640 3803
3641 } else { 3804 } else {
3642 $widget = new CFPlus::UI::Label 3805 $widget = new CFPlus::UI::Label
3643 can_hover => 1, 3806 can_hover => 1,
3644 can_events => 1, 3807 can_events => 1,
3645 markup => $widget, 3808 markup => $widget,
3770 3933
3771############################################################################# 3934#############################################################################
3772 3935
3773package CFPlus::UI::Notebook; 3936package CFPlus::UI::Notebook;
3774 3937
3938use CFPlus::OpenGL;
3939
3775our @ISA = CFPlus::UI::VBox::; 3940our @ISA = CFPlus::UI::VBox::;
3776 3941
3777sub new { 3942sub new {
3778 my $class = shift; 3943 my $class = shift;
3779 3944
3780 my $self = $class->SUPER::new ( 3945 my $self = $class->SUPER::new (
3781 buttonbar => (new CFPlus::UI::Buttonbar), 3946 buttonbar => (new CFPlus::UI::Buttonbar),
3782 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3947 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3948 active_outline => [1, 1, 0],
3783 # filter => # will be put between multiplexer and $self 3949 # filter => # will be put between multiplexer and $self
3784 @_, 3950 @_,
3785 ); 3951 );
3786 3952
3787 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3953 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3859sub set_current_page { 4025sub set_current_page {
3860 my ($self, $page) = @_; 4026 my ($self, $page) = @_;
3861 4027
3862 $self->{multiplexer}->set_current_page ($page); 4028 $self->{multiplexer}->set_current_page ($page);
3863 $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 }
3864} 4046}
3865 4047
3866############################################################################# 4048#############################################################################
3867 4049
3868package CFPlus::UI::Selector; 4050package CFPlus::UI::Selector;
4138} 4320}
4139 4321
4140sub update { 4322sub update {
4141 my ($self) = @_; 4323 my ($self) = @_;
4142 4324
4143 $::WANT_REFRESH++; 4325 $::WANT_REFRESH->start;
4144} 4326}
4145 4327
4146sub add { 4328sub add {
4147 my ($self, @children) = @_; 4329 my ($self, @children) = @_;
4148 4330

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines