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.414 by root, Mon Jul 23 17:54:14 2007 UTC vs.
Revision 1.430 by root, Tue Aug 21 02:39:17 2007 UTC

273 $self->emit ("destroy"); 273 $self->emit ("destroy");
274 %$self = (); 274 %$self = ();
275} 275}
276 276
277sub TO_JSON { 277sub TO_JSON {
278 { __widget_ref__ => $_[0]{s_id} } 278 { __w_ => $_[0]{s_id} }
279} 279}
280 280
281sub show { 281sub show {
282 my ($self) = @_; 282 my ($self) = @_;
283 283
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 => [1, 1, 1, 0.5], 2073 active_bg => [0, 0, 1, .2],
2080 active_fg => [0, 0, 0], 2074 active_fg => [1, 1, 1],
2075 active_outline => [1, 1, 0],
2081 can_hover => 1, 2076 can_hover => 1,
2082 can_focus => 1, 2077 can_focus => 1,
2083 valign => 0, 2078 valign => 0,
2084 can_events => 1, 2079 can_events => 1,
2085 ellipsise => 0, 2080 ellipsise => 0,
2225 glColor_premultiply @{$self->{bg}}; 2220 glColor_premultiply @{$self->{bg}};
2226 } 2221 }
2227 2222
2228 glEnable GL_BLEND; 2223 glEnable GL_BLEND;
2229 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2224 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2230 glBegin GL_QUADS;
2231 glVertex 0 , 0;
2232 glVertex 0 , $self->{h};
2233 glVertex $self->{w}, $self->{h}; 2225 glRect 0, 0, $self->{w}, $self->{h};
2234 glVertex $self->{w}, 0;
2235 glEnd;
2236 glDisable GL_BLEND; 2226 glDisable GL_BLEND;
2237 2227
2238 $self->SUPER::_draw; 2228 $self->SUPER::_draw;
2239 2229
2240 #TODO: force update every cursor change :( 2230 #TODO: force update every cursor change :(
2242 2232
2243 unless (exists $self->{cur_h}) { 2233 unless (exists $self->{cur_h}) {
2244 my $text = substr $self->{text}, 0, $self->{cursor}; 2234 my $text = substr $self->{text}, 0, $self->{cursor};
2245 utf8::encode $text; 2235 utf8::encode $text;
2246 2236
2247 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) 2237 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
2248 } 2238 }
2249 2239
2240 glColor_premultiply @{$self->{active_fg}};
2250 glBegin GL_LINES; 2241 glBegin GL_LINES;
2251 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; 2242 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
2252 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};
2244 glEnd;
2245
2246 glLineWidth 3;
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}};
2253 glTranslate .375, .375;
2254 glBegin GL_LINE_STRIP;
2255 glVertex 0, $self->{h} * .5;
2256 glVertex 0, $self->{h} - 3;
2257 glVertex $self->{w} - 1, $self->{h} - 3;
2258 glVertex $self->{w} - 1, $self->{h} * .5;
2253 glEnd; 2259 glEnd;
2254 } 2260 }
2255} 2261}
2256 2262
2257############################################################################# 2263#############################################################################
2344 1 2350 1
2345} 2351}
2346 2352
2347############################################################################# 2353#############################################################################
2348 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
2349package CFPlus::UI::Button; 2404package CFPlus::UI::Button;
2350 2405
2351our @ISA = CFPlus::UI::Label::; 2406our @ISA = CFPlus::UI::Label::;
2352 2407
2353use CFPlus::OpenGL; 2408use CFPlus::OpenGL;
2487sub new { 2542sub new {
2488 my $class = shift; 2543 my $class = shift;
2489 2544
2490 my $self = $class->SUPER::new ( 2545 my $self = $class->SUPER::new (
2491 can_events => 0, 2546 can_events => 0,
2547 scale => 1,
2492 @_, 2548 @_,
2493 ); 2549 );
2494 2550
2495 $self->{path} || $self->{tex} 2551 $self->{path} || $self->{tex}
2496 or Carp::croak "'path' or 'tex' attributes required"; 2552 or Carp::croak "'path' or 'tex' attributes required";
2521} 2577}
2522 2578
2523sub size_request { 2579sub size_request {
2524 my ($self) = @_; 2580 my ($self) = @_;
2525 2581
2526 ($self->{tex}{w}, $self->{tex}{h}) 2582 (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale})
2527} 2583}
2528 2584
2529sub _draw { 2585sub _draw {
2530 my ($self) = @_; 2586 my ($self) = @_;
2531 2587
2541 } 2597 }
2542 2598
2543 glEnable GL_TEXTURE_2D; 2599 glEnable GL_TEXTURE_2D;
2544 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2600 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2545 2601
2546 $tex->draw_quad (0, 0, $w, $h); 2602 $tex->draw_quad_alpha (0, 0, $w, $h);
2547 2603
2548 glDisable GL_TEXTURE_2D; 2604 glDisable GL_TEXTURE_2D;
2549} 2605}
2550 2606
2551############################################################################# 2607#############################################################################
2570 align => 0, 2626 align => 0,
2571 valign => 0, 2627 valign => 0,
2572 can_events => 1, 2628 can_events => 1,
2573 @_ 2629 @_
2574 ); 2630 );
2631}
2632
2633sub invoke_button_down {
2634 my ($self, $ev, $x, $y) = @_;
2635
2636 1
2575} 2637}
2576 2638
2577sub invoke_button_up { 2639sub invoke_button_up {
2578 my ($self, $ev, $x, $y) = @_; 2640 my ($self, $ev, $x, $y) = @_;
2579 2641
2719 glDisable GL_TEXTURE_2D; 2781 glDisable GL_TEXTURE_2D;
2720} 2782}
2721 2783
2722############################################################################# 2784#############################################################################
2723 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 text => "-",
2807 value => -1,
2808 );
2809
2810 $self->set_value ($arg{value}) if exists $arg{value};
2811
2812 $self
2813}
2814
2815sub set_value {
2816 my ($self, $value) = @_;
2817
2818 if ($self->{value} != $value) {
2819 $self->{value} = $value;
2820 $self->set_text (sprintf "%d%%", $value * 100);
2821 $self->update;
2822 }
2823}
2824
2825sub _draw {
2826 my ($self) = @_;
2827
2828 glEnable GL_BLEND;
2829 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2830
2831 if ($self->{value} >= 0) {
2832 my $s = 3 + ($self->{w} - 6) * $self->{value};
2833
2834 glColor_premultiply @{$self->{bar}};
2835 glRect 2, 2, $s, $self->{h} - 2;
2836 glColor_premultiply @{$self->{bg}};
2837 glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2;
2838 }
2839
2840 glColor_premultiply @{$self->{outline}};
2841 glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2;
2842
2843 glDisable GL_BLEND;
2844
2845 {
2846 local $self->{bg}; # do not draw background
2847 $self->SUPER::_draw;
2848 }
2849}
2850
2851#############################################################################
2852
2853package CFPlus::UI::ExperienceProgress;
2854
2855our @ISA = CFPlus::UI::Progress::;
2856
2857sub new {
2858 my ($class, %arg) = @_;
2859
2860 my $self = $class->SUPER::new (
2861 %arg
2862 );
2863
2864 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2865 if $::CONN;
2866
2867 $self
2868}
2869
2870sub DESTROY {
2871 my ($self) = @_;
2872
2873 delete $::CONN->{on_exp_update}{$self+0}
2874 if $::CONN;
2875
2876 $self->SUPER::DESTROY;
2877}
2878
2879sub set_value {
2880 my ($self, $lvl, $exp) = @_;
2881
2882 my $v = 0;
2883
2884 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2885 my $l0 = $table->[$lvl - 1];
2886 my $l1 = $table->[$lvl];
2887
2888 $v = ($exp - $l0) / ($l1 - $l0);
2889 }
2890
2891 $self->SUPER::set_value ($v);
2892}
2893
2894#############################################################################
2895
2724package CFPlus::UI::Gauge; 2896package CFPlus::UI::Gauge;
2725 2897
2726our @ISA = CFPlus::UI::VBox::; 2898our @ISA = CFPlus::UI::VBox::;
2727 2899
2728sub new { 2900sub new {
3225 3397
3226 if ($y0 < $y + $h && $y < $y1) { 3398 if ($y0 < $y + $h && $y < $y1) {
3227 my $layout = $self->get_layout ($para); 3399 my $layout = $self->get_layout ($para);
3228 3400
3229 $layout->render ($para->{indent}, $y - $y0); 3401 $layout->render ($para->{indent}, $y - $y0);
3402 $layout->draw;
3230 3403
3231 if (my @w = @{ $para->{widget} }) { 3404 if (my @w = @{ $para->{widget} }) {
3232 my @s = $layout->get_shapes; 3405 my @s = $layout->get_shapes;
3233 3406
3234 for (@w) { 3407 for (@w) {
3425 glTranslate 0.375, 0.375; 3598 glTranslate 0.375, 0.375;
3426 3599
3427 my ($w, $h) = @$self{qw(w h)}; 3600 my ($w, $h) = @$self{qw(w h)};
3428 3601
3429 glColor 1, 0.8, 0.4; 3602 glColor 1, 0.8, 0.4;
3430 glBegin GL_QUADS; 3603 glRect 0, 0, $w, $h;
3431 glVertex 0 , 0;
3432 glVertex 0 , $h;
3433 glVertex $w, $h;
3434 glVertex $w, 0;
3435 glEnd;
3436 3604
3437 glColor 0, 0, 0; 3605 glColor 0, 0, 0;
3438 glBegin GL_LINE_LOOP; 3606 glRect_lineloop 0, 0, $w, $h;
3439 glVertex 0 , 0;
3440 glVertex 0 , $h;
3441 glVertex $w, $h;
3442 glVertex $w, 0;
3443 glEnd;
3444 3607
3445 glTranslate 2 - 0.375, 2 - 0.375; 3608 glTranslate 2 - 0.375, 2 - 0.375;
3446 3609
3447 $self->SUPER::_draw; 3610 $self->SUPER::_draw;
3448} 3611}
3472 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3635 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3473 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; 3636 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed};
3474 $self->{timer} = Event->timer ( 3637 $self->{timer} = Event->timer (
3475 parked => 1, 3638 parked => 1,
3476 cb => sub { 3639 cb => sub {
3477 return unless $::CONN && $widget; 3640 return unless $::CONN;
3478 3641
3642 my $w = $widget
3643 or return;
3644
3479 ++$widget->{frame}; 3645 ++$w->{frame};
3480 $widget->update_face; 3646 $w->update_face;
3647
3648 # somehow, $widget can go away
3481 $widget->update; 3649 $w->update;
3482
3483 $widget->update_timer; 3650 $w->update_timer;
3484 }, 3651 },
3485 ); 3652 );
3486 3653
3487 $self->update_face; 3654 $self->update_face;
3488 $self->update_timer; 3655 $self->update_timer;
3509} 3676}
3510 3677
3511sub update_face { 3678sub update_face {
3512 my ($self) = @_; 3679 my ($self) = @_;
3513 3680
3514 return unless $::CONN; 3681 if ($::CONN) {
3515
3516 if (my $anim = $::CONN->{anim}[$self->{anim}]) { 3682 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3517 if ($anim && @$anim) { 3683 if ($anim && @$anim) {
3518 delete $self->{wait_face};
3519 $self->{face} = $anim->[ $self->{frame} % @$anim ]; 3684 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3685 delete $self->{face_change_cb};
3686
3520 $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ]; 3687 if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) {
3688 unless ($tex->{name} || $tex->{loading}) {
3689 $tex->upload (sub { $self->reconfigure });
3690 }
3691 }
3692 }
3521 } 3693 }
3522 } 3694 }
3523} 3695}
3524 3696
3525sub size_request { 3697sub size_request {
3526 my ($self) = @_; 3698 my ($self) = @_;
3527 3699
3528 if ($::CONN) { 3700 if ($::CONN) {
3529 if (my $faceid = $::CONN->{faceid}[$self->{face}]) { 3701 if (my $faceid = $::CONN->{face}[$self->{face}]{id}) {
3530 if (my $tex = $::CONN->{texture}[$faceid]) { 3702 if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) {
3531 $self->{tex} = $tex; 3703 if ($tex->{name}) {
3532 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); 3704 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3533 } else { 3705 } elsif (!$tex->{loading}) {
3534 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { 3706 $tex->upload (sub { $self->reconfigure });
3535 $self->realloc;
3536 }); 3707 }
3537 } 3708 }
3709
3710 $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure });
3538 } 3711 }
3539 } 3712 }
3540 3713
3541 ($self->{size_w} || 8, $self->{size_h} || 8) 3714 ($self->{size_w} || 8, $self->{size_h} || 8)
3542} 3715}
3622 children => [ 3795 children => [
3623 (new CFPlus::UI::Label markup => $left, expand => 1), 3796 (new CFPlus::UI::Label markup => $left, expand => 1),
3624 (new CFPlus::UI::Label markup => $right, align => +1), 3797 (new CFPlus::UI::Label markup => $right, align => +1),
3625 ], 3798 ],
3626 ; 3799 ;
3627 3800
3628 } else { 3801 } else {
3629 $widget = new CFPlus::UI::Label 3802 $widget = new CFPlus::UI::Label
3630 can_hover => 1, 3803 can_hover => 1,
3631 can_events => 1, 3804 can_events => 1,
3632 markup => $widget, 3805 markup => $widget,
3768 buttonbar => (new CFPlus::UI::Buttonbar), 3941 buttonbar => (new CFPlus::UI::Buttonbar),
3769 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3942 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3770 # filter => # will be put between multiplexer and $self 3943 # filter => # will be put between multiplexer and $self
3771 @_, 3944 @_,
3772 ); 3945 );
3773 3946
3774 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3947 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3775 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); 3948 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3776 3949
3777 { 3950 {
3778 Scalar::Util::weaken (my $wself = $self); 3951 Scalar::Util::weaken (my $wself = $self);
3819 3992
3820sub remove { 3993sub remove {
3821 my ($self, @widgets) = @_; 3994 my ($self, @widgets) = @_;
3822 3995
3823 $self->{multiplexer}->remove (@widgets) 3996 $self->{multiplexer}->remove (@widgets)
3997}
3998
3999sub pages {
4000 my ($self) = @_;
4001 $self->{multiplexer}->children
3824} 4002}
3825 4003
3826sub add_tab { 4004sub add_tab {
3827 my ($self, $title, $widget, $tooltip) = @_; 4005 my ($self, $title, $widget, $tooltip) = @_;
3828 4006
4120} 4298}
4121 4299
4122sub update { 4300sub update {
4123 my ($self) = @_; 4301 my ($self) = @_;
4124 4302
4125 $::WANT_REFRESH++; 4303 $::WANT_REFRESH->start;
4126} 4304}
4127 4305
4128sub add { 4306sub add {
4129 my ($self, @children) = @_; 4307 my ($self, @children) = @_;
4130 4308

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines