… | |
… | |
30 | $TOOLTIP->{owner} = $widget; |
30 | $TOOLTIP->{owner} = $widget; |
31 | $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner}; |
31 | $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner}; |
32 | |
32 | |
33 | return if $ENV{CFPLUS_DEBUG} & 8; |
33 | return if $ENV{CFPLUS_DEBUG} & 8; |
34 | |
34 | |
35 | my $tip = $widget->{tooltip}; |
|
|
36 | |
|
|
37 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
|
|
38 | |
|
|
39 | $TOOLTIP->set_tooltip_from ($widget); |
35 | $TOOLTIP->set_tooltip_from ($widget); |
40 | $TOOLTIP->show; |
36 | $TOOLTIP->show; |
41 | } |
37 | } |
42 | |
38 | |
43 | return; |
39 | return; |
… | |
… | |
273 | $self->emit ("destroy"); |
269 | $self->emit ("destroy"); |
274 | %$self = (); |
270 | %$self = (); |
275 | } |
271 | } |
276 | |
272 | |
277 | sub TO_JSON { |
273 | sub TO_JSON { |
278 | { __w_ => $_[0]{s_id} } |
274 | { "\fw" => $_[0]{s_id} } |
279 | } |
275 | } |
280 | |
276 | |
281 | sub show { |
277 | sub show { |
282 | my ($self) = @_; |
278 | my ($self) = @_; |
283 | |
279 | |
… | |
… | |
2237 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
2233 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
2238 | } |
2234 | } |
2239 | |
2235 | |
2240 | glColor_premultiply @{$self->{active_fg}}; |
2236 | glColor_premultiply @{$self->{active_fg}}; |
2241 | glBegin GL_LINES; |
2237 | glBegin GL_LINES; |
2242 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2238 | glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy}; |
2243 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2239 | glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2244 | glEnd; |
2240 | glEnd; |
2245 | |
2241 | |
2246 | glLineWidth 3; |
2242 | glLineWidth 3; |
2247 | glColor @{$self->{active_outline}}; |
2243 | glColor @{$self->{active_outline}}; |
2248 | glRect_lineloop 0, 0, $self->{w} - 1, $self->{h} - 1; |
2244 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
2249 | glLineWidth 1; |
2245 | glLineWidth 1; |
2250 | |
2246 | |
2251 | } else { |
2247 | } else { |
2252 | glColor @{$self->{outline}}; |
2248 | glColor @{$self->{outline}}; |
2253 | glTranslate .375, .375; |
|
|
2254 | glBegin GL_LINE_STRIP; |
2249 | glBegin GL_LINE_STRIP; |
2255 | glVertex 0, $self->{h} * .5; |
2250 | glVertex .5, $self->{h} * .5; |
2256 | glVertex 0, $self->{h} - 3; |
2251 | glVertex .5, $self->{h} - 2.5; |
2257 | glVertex $self->{w} - 1, $self->{h} - 3; |
2252 | glVertex $self->{w} - .5, $self->{h} - 2.5; |
2258 | glVertex $self->{w} - 1, $self->{h} * .5; |
2253 | glVertex $self->{w} - .5, $self->{h} * .5; |
2259 | glEnd; |
2254 | glEnd; |
2260 | } |
2255 | } |
2261 | } |
2256 | } |
2262 | |
2257 | |
2263 | ############################################################################# |
2258 | ############################################################################# |
… | |
… | |
2512 | sub _draw { |
2507 | sub _draw { |
2513 | my ($self) = @_; |
2508 | my ($self) = @_; |
2514 | |
2509 | |
2515 | $self->SUPER::_draw; |
2510 | $self->SUPER::_draw; |
2516 | |
2511 | |
2517 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
2512 | glTranslate $self->{padding_x}, $self->{padding_y}, 0; |
2518 | |
2513 | |
2519 | my ($w, $h) = @$self{qw(w h)}; |
2514 | my ($w, $h) = @$self{qw(w h)}; |
2520 | |
2515 | |
2521 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
2516 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
2522 | |
2517 | |
… | |
… | |
2800 | fontsize => 0.9, |
2795 | fontsize => 0.9, |
2801 | valign => 0, |
2796 | valign => 0, |
2802 | align => 0, |
2797 | align => 0, |
2803 | can_events => 1, |
2798 | can_events => 1, |
2804 | ellipsise => 1, |
2799 | ellipsise => 1, |
|
|
2800 | label => "%d%%", |
2805 | %arg, |
2801 | %arg, |
2806 | text => "-", |
|
|
2807 | value => -1, |
|
|
2808 | ); |
2802 | ); |
2809 | |
2803 | |
2810 | $self->set_value ($arg{value}) if exists $arg{value}; |
2804 | $self->set_value ($arg{value} || -1); |
2811 | |
2805 | |
2812 | $self |
2806 | $self |
|
|
2807 | } |
|
|
2808 | |
|
|
2809 | sub set_label { |
|
|
2810 | my ($self, $label) = @_; |
|
|
2811 | |
|
|
2812 | return if $self->{label} eq $label; |
|
|
2813 | $self->{label} = $label; |
|
|
2814 | |
|
|
2815 | $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value}); |
2813 | } |
2816 | } |
2814 | |
2817 | |
2815 | sub set_value { |
2818 | sub set_value { |
2816 | my ($self, $value) = @_; |
2819 | my ($self, $value) = @_; |
2817 | |
2820 | |
2818 | if ($self->{value} != $value) { |
2821 | if ($self->{value} ne $value) { |
2819 | $self->{value} = $value; |
2822 | $self->{value} = $value; |
|
|
2823 | |
|
|
2824 | if ($value < 0) { |
|
|
2825 | $self->set_text ("-"); |
|
|
2826 | } else { |
2820 | $self->set_text (sprintf "%d%%", $value * 100); |
2827 | $self->set_text (sprintf $self->{label}, $value * 100); |
|
|
2828 | } |
|
|
2829 | |
2821 | $self->update; |
2830 | $self->update; |
2822 | } |
2831 | } |
2823 | } |
2832 | } |
2824 | |
2833 | |
2825 | sub _draw { |
2834 | sub _draw { |
… | |
… | |
2827 | |
2836 | |
2828 | glEnable GL_BLEND; |
2837 | glEnable GL_BLEND; |
2829 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2838 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2830 | |
2839 | |
2831 | if ($self->{value} >= 0) { |
2840 | if ($self->{value} >= 0) { |
2832 | my $s = 3 + ($self->{w} - 6) * $self->{value}; |
2841 | my $s = int 2 + ($self->{w} - 4) * $self->{value}; |
2833 | |
2842 | |
2834 | glColor_premultiply @{$self->{bar}}; |
2843 | glColor_premultiply @{$self->{bar}}; |
2835 | glRect 2, 2, $s, $self->{h} - 2; |
2844 | glRect 2, 2, $s, $self->{h} - 2; |
2836 | glColor_premultiply @{$self->{bg}}; |
2845 | glColor_premultiply @{$self->{bg}}; |
2837 | glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2; |
2846 | glRect $s, 2, $self->{w} - 2, $self->{h} - 2; |
2838 | } |
2847 | } |
2839 | |
2848 | |
2840 | glColor_premultiply @{$self->{outline}}; |
2849 | glColor_premultiply @{$self->{outline}}; |
2841 | glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2; |
2850 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
2842 | |
2851 | |
2843 | glDisable GL_BLEND; |
2852 | glDisable GL_BLEND; |
2844 | |
2853 | |
2845 | { |
2854 | { |
2846 | local $self->{bg}; # do not draw background |
2855 | local $self->{bg}; # do not draw background |
… | |
… | |
2856 | |
2865 | |
2857 | sub new { |
2866 | sub new { |
2858 | my ($class, %arg) = @_; |
2867 | my ($class, %arg) = @_; |
2859 | |
2868 | |
2860 | my $self = $class->SUPER::new ( |
2869 | my $self = $class->SUPER::new ( |
|
|
2870 | tooltip => sub { |
|
|
2871 | my ($self) = @_; |
|
|
2872 | |
|
|
2873 | sprintf "level %d\n%s points\n%s next level\n%s to go", |
|
|
2874 | $self->{lvl}, |
|
|
2875 | ::formsep ($self->{exp}), |
|
|
2876 | ::formsep ($self->{nxt}), |
|
|
2877 | ::formsep ($self->{nxt} - $self->{exp}), |
|
|
2878 | }, |
2861 | %arg |
2879 | %arg |
2862 | ); |
2880 | ); |
2863 | |
2881 | |
2864 | $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } |
2882 | $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } |
2865 | if $::CONN; |
2883 | if $::CONN; |
… | |
… | |
2877 | } |
2895 | } |
2878 | |
2896 | |
2879 | sub set_value { |
2897 | sub set_value { |
2880 | my ($self, $lvl, $exp) = @_; |
2898 | my ($self, $lvl, $exp) = @_; |
2881 | |
2899 | |
|
|
2900 | $self->{lvl} = $lvl; |
|
|
2901 | $self->{exp} = $exp; |
|
|
2902 | |
2882 | my $v = 0; |
2903 | my $v = -1; |
2883 | |
2904 | |
2884 | if ($::CONN && (my $table = $::CONN->{exp_table})) { |
2905 | if ($::CONN && (my $table = $::CONN->{exp_table})) { |
2885 | my $l0 = $table->[$lvl - 1]; |
2906 | my $l0 = $table->[$lvl - 1]; |
2886 | my $l1 = $table->[$lvl]; |
2907 | my $l1 = $table->[$lvl]; |
|
|
2908 | |
|
|
2909 | $self->{nxt} = $l1; |
2887 | |
2910 | |
2888 | $v = ($exp - $l0) / ($l1 - $l0); |
2911 | $v = ($exp - $l0) / ($l1 - $l0); |
2889 | } |
2912 | } |
2890 | |
2913 | |
2891 | $self->SUPER::set_value ($v); |
2914 | $self->SUPER::set_value ($v); |
… | |
… | |
3529 | } |
3552 | } |
3530 | |
3553 | |
3531 | sub set_tooltip_from { |
3554 | sub set_tooltip_from { |
3532 | my ($self, $widget) = @_; |
3555 | my ($self, $widget) = @_; |
3533 | |
3556 | |
3534 | $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1 |
|
|
3535 | if $widget->{tooltip} =~ /^#(.*)$/; |
|
|
3536 | |
|
|
3537 | my $tooltip = $widget->{tooltip}; |
3557 | my $tip = $widget->{tooltip}; |
|
|
3558 | $tip = $tip->($widget) if "CODE" eq ref $tip; |
|
|
3559 | |
|
|
3560 | $tip = CFPlus::Pod::section_label tooltip => $1 |
|
|
3561 | if $tip =~ /^#(.*)$/; |
3538 | |
3562 | |
3539 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3563 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3540 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
3564 | $tip .= "\n\n" . (ref $widget) . "\n" |
3541 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3565 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3542 | . "req $widget->{req_w} $widget->{req_h}\n" |
3566 | . "req $widget->{req_w} $widget->{req_h}\n" |
3543 | . "visible $widget->{visible}"; |
3567 | . "visible $widget->{visible}"; |
3544 | } |
3568 | } |
3545 | |
3569 | |
3546 | $tooltip =~ s/^\n+//; |
3570 | $tip =~ s/^\n+//; |
3547 | $tooltip =~ s/\n+$//; |
3571 | $tip =~ s/\n+$//; |
3548 | |
3572 | |
3549 | $self->add (new CFPlus::UI::Label |
3573 | $self->add (new CFPlus::UI::Label |
3550 | markup => $tooltip, |
3574 | markup => $tip, |
3551 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3575 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3552 | fontsize => 0.8, |
3576 | fontsize => 0.8, |
3553 | style => 1, # FLAG_INVERSE |
3577 | style => 1, # FLAG_INVERSE |
3554 | ellipsise => 0, |
3578 | ellipsise => 0, |
3555 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3579 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
… | |
… | |
3593 | } |
3617 | } |
3594 | |
3618 | |
3595 | sub _draw { |
3619 | sub _draw { |
3596 | my ($self) = @_; |
3620 | my ($self) = @_; |
3597 | |
3621 | |
3598 | glTranslate 0.375, 0.375; |
|
|
3599 | |
|
|
3600 | my ($w, $h) = @$self{qw(w h)}; |
3622 | my ($w, $h) = @$self{qw(w h)}; |
3601 | |
3623 | |
3602 | glColor 1, 0.8, 0.4; |
3624 | glColor 1, 0.8, 0.4; |
3603 | glRect 0, 0, $w, $h; |
3625 | glRect 0, 0, $w, $h; |
3604 | |
3626 | |
3605 | glColor 0, 0, 0; |
3627 | glColor 0, 0, 0; |
3606 | glRect_lineloop 0, 0, $w, $h; |
3628 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3607 | |
3629 | |
3608 | glTranslate 2 - 0.375, 2 - 0.375; |
3630 | glTranslate 2, 2; |
3609 | |
3631 | |
3610 | $self->SUPER::_draw; |
3632 | $self->SUPER::_draw; |
3611 | } |
3633 | } |
3612 | |
3634 | |
3613 | ############################################################################# |
3635 | ############################################################################# |
… | |
… | |
3930 | |
3952 | |
3931 | ############################################################################# |
3953 | ############################################################################# |
3932 | |
3954 | |
3933 | package CFPlus::UI::Notebook; |
3955 | package CFPlus::UI::Notebook; |
3934 | |
3956 | |
|
|
3957 | use CFPlus::OpenGL; |
|
|
3958 | |
3935 | our @ISA = CFPlus::UI::VBox::; |
3959 | our @ISA = CFPlus::UI::VBox::; |
3936 | |
3960 | |
3937 | sub new { |
3961 | sub new { |
3938 | my $class = shift; |
3962 | my $class = shift; |
3939 | |
3963 | |
3940 | my $self = $class->SUPER::new ( |
3964 | my $self = $class->SUPER::new ( |
3941 | buttonbar => (new CFPlus::UI::Buttonbar), |
3965 | buttonbar => (new CFPlus::UI::Buttonbar), |
3942 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3966 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
|
|
3967 | active_outline => [.7, .7, 0.2], |
3943 | # filter => # will be put between multiplexer and $self |
3968 | # filter => # will be put between multiplexer and $self |
3944 | @_, |
3969 | @_, |
3945 | ); |
3970 | ); |
3946 | |
3971 | |
3947 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3972 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
… | |
… | |
4019 | sub set_current_page { |
4044 | sub set_current_page { |
4020 | my ($self, $page) = @_; |
4045 | my ($self, $page) = @_; |
4021 | |
4046 | |
4022 | $self->{multiplexer}->set_current_page ($page); |
4047 | $self->{multiplexer}->set_current_page ($page); |
4023 | $self->emit (page_changed => $self->{multiplexer}{current}); |
4048 | $self->emit (page_changed => $self->{multiplexer}{current}); |
|
|
4049 | } |
|
|
4050 | |
|
|
4051 | sub _draw { |
|
|
4052 | my ($self) = @_; |
|
|
4053 | |
|
|
4054 | $self->SUPER::_draw (); |
|
|
4055 | |
|
|
4056 | if (my $cur = $self->{multiplexer}{current}) { |
|
|
4057 | if ($cur = $cur->{c_tab_}) { |
|
|
4058 | glTranslate $self->{buttonbar}{x} + $cur->{x}, |
|
|
4059 | $self->{buttonbar}{y} + $cur->{y}; |
|
|
4060 | glLineWidth 3; |
|
|
4061 | #glEnable GL_BLEND; |
|
|
4062 | #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
4063 | glColor @{$self->{active_outline}}; |
|
|
4064 | glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5; |
|
|
4065 | glLineWidth 1; |
|
|
4066 | #glDisable GL_BLEND; |
|
|
4067 | } |
|
|
4068 | } |
4024 | } |
4069 | } |
4025 | |
4070 | |
4026 | ############################################################################# |
4071 | ############################################################################# |
4027 | |
4072 | |
4028 | package CFPlus::UI::Selector; |
4073 | package CFPlus::UI::Selector; |