… | |
… | |
273 | $self->emit ("destroy"); |
273 | $self->emit ("destroy"); |
274 | %$self = (); |
274 | %$self = (); |
275 | } |
275 | } |
276 | |
276 | |
277 | sub TO_JSON { |
277 | sub TO_JSON { |
278 | { __widget_ref__ => $_[0]{s_id} } |
278 | { __w_ => $_[0]{s_id} } |
279 | } |
279 | } |
280 | |
280 | |
281 | sub show { |
281 | sub show { |
282 | my ($self) = @_; |
282 | my ($self) = @_; |
283 | |
283 | |
… | |
… | |
607 | sub DESTROY { |
607 | sub 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 | } |
… | |
… | |
624 | use strict; |
625 | use strict; |
625 | use CFPlus::OpenGL; |
626 | use CFPlus::OpenGL; |
626 | |
627 | |
627 | sub new { |
628 | sub 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 | |
1599 | sub add { |
1584 | sub 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 | |
|
|
1913 | sub clear { |
|
|
1914 | my ($self) = @_; |
|
|
1915 | |
|
|
1916 | $self->set_text (""); |
|
|
1917 | } |
|
|
1918 | |
1928 | sub set_text { |
1919 | sub 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 | |
|
|
2355 | package CFPlus::UI::ButtonBin; |
|
|
2356 | |
|
|
2357 | our @ISA = CFPlus::UI::Bin::; |
|
|
2358 | |
|
|
2359 | use CFPlus::OpenGL; |
|
|
2360 | |
|
|
2361 | my @tex = |
|
|
2362 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
|
|
2363 | qw(b1_button_inactive.png b1_button_active.png); |
|
|
2364 | |
|
|
2365 | sub 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 | |
|
|
2377 | sub 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 | |
|
|
2387 | sub _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 | |
2349 | package CFPlus::UI::Button; |
2404 | package CFPlus::UI::Button; |
2350 | |
2405 | |
2351 | our @ISA = CFPlus::UI::Label::; |
2406 | our @ISA = CFPlus::UI::Label::; |
2352 | |
2407 | |
2353 | use CFPlus::OpenGL; |
2408 | use CFPlus::OpenGL; |
… | |
… | |
2487 | sub new { |
2542 | sub 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 | |
2523 | sub size_request { |
2579 | sub 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 | |
2529 | sub _draw { |
2585 | sub _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 | |
|
|
2633 | sub invoke_button_down { |
|
|
2634 | my ($self, $ev, $x, $y) = @_; |
|
|
2635 | |
|
|
2636 | 1 |
2575 | } |
2637 | } |
2576 | |
2638 | |
2577 | sub invoke_button_up { |
2639 | sub 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 | |
|
|
2786 | package CFPlus::UI::Progress; |
|
|
2787 | |
|
|
2788 | our @ISA = CFPlus::UI::Label::; |
|
|
2789 | |
|
|
2790 | use CFPlus::OpenGL; |
|
|
2791 | |
|
|
2792 | sub 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 | |
|
|
2813 | sub 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 | |
|
|
2828 | sub _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 | |
|
|
2856 | package CFPlus::UI::ExperienceProgress; |
|
|
2857 | |
|
|
2858 | our @ISA = CFPlus::UI::Progress::; |
|
|
2859 | |
|
|
2860 | sub 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 | |
|
|
2873 | sub DESTROY { |
|
|
2874 | my ($self) = @_; |
|
|
2875 | |
|
|
2876 | delete $::CONN->{on_exp_update}{$self+0} |
|
|
2877 | if $::CONN; |
|
|
2878 | |
|
|
2879 | $self->SUPER::DESTROY; |
|
|
2880 | } |
|
|
2881 | |
|
|
2882 | sub 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 | |
2724 | package CFPlus::UI::Gauge; |
2899 | package CFPlus::UI::Gauge; |
2725 | |
2900 | |
2726 | our @ISA = CFPlus::UI::VBox::; |
2901 | our @ISA = CFPlus::UI::VBox::; |
2727 | |
2902 | |
2728 | sub new { |
2903 | sub new { |
… | |
… | |
3225 | |
3400 | |
3226 | if ($y0 < $y + $h && $y < $y1) { |
3401 | if ($y0 < $y + $h && $y < $y1) { |
3227 | my $layout = $self->get_layout ($para); |
3402 | my $layout = $self->get_layout ($para); |
3228 | |
3403 | |
3229 | $layout->render ($para->{indent}, $y - $y0); |
3404 | $layout->render ($para->{indent}, $y - $y0); |
|
|
3405 | $layout->draw; |
3230 | |
3406 | |
3231 | if (my @w = @{ $para->{widget} }) { |
3407 | if (my @w = @{ $para->{widget} }) { |
3232 | my @s = $layout->get_shapes; |
3408 | my @s = $layout->get_shapes; |
3233 | |
3409 | |
3234 | for (@w) { |
3410 | for (@w) { |
… | |
… | |
3425 | glTranslate 0.375, 0.375; |
3601 | glTranslate 0.375, 0.375; |
3426 | |
3602 | |
3427 | my ($w, $h) = @$self{qw(w h)}; |
3603 | my ($w, $h) = @$self{qw(w h)}; |
3428 | |
3604 | |
3429 | glColor 1, 0.8, 0.4; |
3605 | glColor 1, 0.8, 0.4; |
3430 | glBegin GL_QUADS; |
3606 | glRect 0, 0, $w, $h; |
3431 | glVertex 0 , 0; |
|
|
3432 | glVertex 0 , $h; |
|
|
3433 | glVertex $w, $h; |
|
|
3434 | glVertex $w, 0; |
|
|
3435 | glEnd; |
|
|
3436 | |
3607 | |
3437 | glColor 0, 0, 0; |
3608 | glColor 0, 0, 0; |
3438 | glBegin GL_LINE_LOOP; |
3609 | 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 | |
3610 | |
3445 | glTranslate 2 - 0.375, 2 - 0.375; |
3611 | glTranslate 2 - 0.375, 2 - 0.375; |
3446 | |
3612 | |
3447 | $self->SUPER::_draw; |
3613 | $self->SUPER::_draw; |
3448 | } |
3614 | } |
… | |
… | |
3472 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3638 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3473 | $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; |
3639 | $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; |
3474 | $self->{timer} = Event->timer ( |
3640 | $self->{timer} = Event->timer ( |
3475 | parked => 1, |
3641 | parked => 1, |
3476 | cb => sub { |
3642 | cb => sub { |
3477 | return unless $::CONN && $widget; |
3643 | return unless $::CONN; |
3478 | |
3644 | |
|
|
3645 | my $w = $widget |
|
|
3646 | or return; |
|
|
3647 | |
3479 | ++$widget->{frame}; |
3648 | ++$w->{frame}; |
3480 | $widget->update_face; |
3649 | $w->update_face; |
|
|
3650 | |
|
|
3651 | # somehow, $widget can go away |
3481 | $widget->update; |
3652 | $w->update; |
3482 | |
|
|
3483 | $widget->update_timer; |
3653 | $w->update_timer; |
3484 | }, |
3654 | }, |
3485 | ); |
3655 | ); |
3486 | |
3656 | |
3487 | $self->update_face; |
3657 | $self->update_face; |
3488 | $self->update_timer; |
3658 | $self->update_timer; |
… | |
… | |
3509 | } |
3679 | } |
3510 | |
3680 | |
3511 | sub update_face { |
3681 | sub update_face { |
3512 | my ($self) = @_; |
3682 | my ($self) = @_; |
3513 | |
3683 | |
3514 | return unless $::CONN; |
3684 | if ($::CONN) { |
3515 | |
|
|
3516 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3685 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3517 | if ($anim && @$anim) { |
3686 | if ($anim && @$anim) { |
3518 | delete $self->{wait_face}; |
|
|
3519 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
3687 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
|
|
3688 | delete $self->{face_change_cb}; |
|
|
3689 | |
3520 | $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 | } |
3521 | } |
3696 | } |
3522 | } |
3697 | } |
3523 | } |
3698 | } |
3524 | |
3699 | |
3525 | sub size_request { |
3700 | sub size_request { |
3526 | my ($self) = @_; |
3701 | my ($self) = @_; |
3527 | |
3702 | |
3528 | if ($::CONN) { |
3703 | if ($::CONN) { |
3529 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3704 | if (my $faceid = $::CONN->{face}[$self->{face}]{id}) { |
3530 | if (my $tex = $::CONN->{texture}[$faceid]) { |
3705 | if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) { |
3531 | $self->{tex} = $tex; |
3706 | if ($tex->{name}) { |
3532 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3707 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3533 | } else { |
3708 | } elsif (!$tex->{loading}) { |
3534 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3709 | $tex->upload (sub { $self->reconfigure }); |
3535 | $self->realloc; |
|
|
3536 | }); |
3710 | } |
3537 | } |
3711 | } |
|
|
3712 | |
|
|
3713 | $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure }); |
3538 | } |
3714 | } |
3539 | } |
3715 | } |
3540 | |
3716 | |
3541 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3717 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3542 | } |
3718 | } |
… | |
… | |
3622 | children => [ |
3798 | children => [ |
3623 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3799 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3624 | (new CFPlus::UI::Label markup => $right, align => +1), |
3800 | (new CFPlus::UI::Label markup => $right, align => +1), |
3625 | ], |
3801 | ], |
3626 | ; |
3802 | ; |
3627 | |
3803 | |
3628 | } else { |
3804 | } else { |
3629 | $widget = new CFPlus::UI::Label |
3805 | $widget = new CFPlus::UI::Label |
3630 | can_hover => 1, |
3806 | can_hover => 1, |
3631 | can_events => 1, |
3807 | can_events => 1, |
3632 | markup => $widget, |
3808 | markup => $widget, |
… | |
… | |
3757 | |
3933 | |
3758 | ############################################################################# |
3934 | ############################################################################# |
3759 | |
3935 | |
3760 | package CFPlus::UI::Notebook; |
3936 | package CFPlus::UI::Notebook; |
3761 | |
3937 | |
|
|
3938 | use CFPlus::OpenGL; |
|
|
3939 | |
3762 | our @ISA = CFPlus::UI::VBox::; |
3940 | our @ISA = CFPlus::UI::VBox::; |
3763 | |
3941 | |
3764 | sub new { |
3942 | sub new { |
3765 | my $class = shift; |
3943 | my $class = shift; |
3766 | |
3944 | |
3767 | my $self = $class->SUPER::new ( |
3945 | my $self = $class->SUPER::new ( |
3768 | buttonbar => (new CFPlus::UI::Buttonbar), |
3946 | buttonbar => (new CFPlus::UI::Buttonbar), |
3769 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3947 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
|
|
3948 | active_outline => [1, 1, 0], |
3770 | # filter => # will be put between multiplexer and $self |
3949 | # filter => # will be put between multiplexer and $self |
3771 | @_, |
3950 | @_, |
3772 | ); |
3951 | ); |
3773 | |
3952 | |
3774 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3953 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
… | |
… | |
3846 | sub set_current_page { |
4025 | sub set_current_page { |
3847 | my ($self, $page) = @_; |
4026 | my ($self, $page) = @_; |
3848 | |
4027 | |
3849 | $self->{multiplexer}->set_current_page ($page); |
4028 | $self->{multiplexer}->set_current_page ($page); |
3850 | $self->emit (page_changed => $self->{multiplexer}{current}); |
4029 | $self->emit (page_changed => $self->{multiplexer}{current}); |
|
|
4030 | } |
|
|
4031 | |
|
|
4032 | sub _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 | } |
3851 | } |
4046 | } |
3852 | |
4047 | |
3853 | ############################################################################# |
4048 | ############################################################################# |
3854 | |
4049 | |
3855 | package CFPlus::UI::Selector; |
4050 | package CFPlus::UI::Selector; |
… | |
… | |
4125 | } |
4320 | } |
4126 | |
4321 | |
4127 | sub update { |
4322 | sub update { |
4128 | my ($self) = @_; |
4323 | my ($self) = @_; |
4129 | |
4324 | |
4130 | $::WANT_REFRESH++; |
4325 | $::WANT_REFRESH->start; |
4131 | } |
4326 | } |
4132 | |
4327 | |
4133 | sub add { |
4328 | sub add { |
4134 | my ($self, @children) = @_; |
4329 | my ($self, @children) = @_; |
4135 | |
4330 | |