… | |
… | |
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 | ############################################################################# |
… | |
… | |
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 | } |
… | |
… | |
2235 | glColor_premultiply @{$self->{bg}}; |
2220 | glColor_premultiply @{$self->{bg}}; |
2236 | } |
2221 | } |
2237 | |
2222 | |
2238 | glEnable GL_BLEND; |
2223 | glEnable GL_BLEND; |
2239 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2224 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2240 | glBegin GL_QUADS; |
|
|
2241 | glVertex 0 , 0; |
|
|
2242 | glVertex 0 , $self->{h}; |
|
|
2243 | glVertex $self->{w}, $self->{h}; |
2225 | glRect 0, 0, $self->{w}, $self->{h}; |
2244 | glVertex $self->{w}, 0; |
|
|
2245 | glEnd; |
|
|
2246 | glDisable GL_BLEND; |
2226 | glDisable GL_BLEND; |
2247 | |
2227 | |
2248 | $self->SUPER::_draw; |
2228 | $self->SUPER::_draw; |
2249 | |
2229 | |
2250 | #TODO: force update every cursor change :( |
2230 | #TODO: force update every cursor change :( |
… | |
… | |
2263 | 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}; |
2264 | glEnd; |
2244 | glEnd; |
2265 | |
2245 | |
2266 | glLineWidth 3; |
2246 | glLineWidth 3; |
2267 | glColor @{$self->{active_outline}}; |
2247 | glColor @{$self->{active_outline}}; |
2268 | glBegin GL_LINE_LOOP; |
|
|
2269 | glVertex 0, 0; |
|
|
2270 | glVertex $self->{w} - 1, 0; |
|
|
2271 | glVertex $self->{w} - 1, $self->{h} - 1; |
2248 | glRect_lineloop 0, 0, $self->{w} - 1, $self->{h} - 1; |
2272 | glVertex 0, $self->{h} - 1; |
|
|
2273 | glEnd; |
|
|
2274 | glLineWidth 1; |
2249 | glLineWidth 1; |
2275 | |
2250 | |
2276 | } else { |
2251 | } else { |
2277 | glColor @{$self->{outline}}; |
2252 | glColor @{$self->{outline}}; |
2278 | glTranslate .375, .375; |
2253 | glTranslate .375, .375; |
… | |
… | |
2806 | glDisable GL_TEXTURE_2D; |
2781 | glDisable GL_TEXTURE_2D; |
2807 | } |
2782 | } |
2808 | |
2783 | |
2809 | ############################################################################# |
2784 | ############################################################################# |
2810 | |
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 | text => "-", |
|
|
2807 | value => -1, |
|
|
2808 | ); |
|
|
2809 | |
|
|
2810 | $self->set_value ($arg{value}) if exists $arg{value}; |
|
|
2811 | |
|
|
2812 | $self |
|
|
2813 | } |
|
|
2814 | |
|
|
2815 | sub 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 | |
|
|
2825 | sub _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 | |
|
|
2853 | package CFPlus::UI::ExperienceProgress; |
|
|
2854 | |
|
|
2855 | our @ISA = CFPlus::UI::Progress::; |
|
|
2856 | |
|
|
2857 | sub 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 | |
|
|
2870 | sub DESTROY { |
|
|
2871 | my ($self) = @_; |
|
|
2872 | |
|
|
2873 | delete $::CONN->{on_exp_update}{$self+0} |
|
|
2874 | if $::CONN; |
|
|
2875 | |
|
|
2876 | $self->SUPER::DESTROY; |
|
|
2877 | } |
|
|
2878 | |
|
|
2879 | sub 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 | |
2811 | package CFPlus::UI::Gauge; |
2896 | package CFPlus::UI::Gauge; |
2812 | |
2897 | |
2813 | our @ISA = CFPlus::UI::VBox::; |
2898 | our @ISA = CFPlus::UI::VBox::; |
2814 | |
2899 | |
2815 | sub new { |
2900 | sub new { |
… | |
… | |
3516 | |
3601 | |
3517 | glColor 1, 0.8, 0.4; |
3602 | glColor 1, 0.8, 0.4; |
3518 | glRect 0, 0, $w, $h; |
3603 | glRect 0, 0, $w, $h; |
3519 | |
3604 | |
3520 | glColor 0, 0, 0; |
3605 | glColor 0, 0, 0; |
3521 | glBegin GL_LINE_LOOP; |
3606 | glRect_lineloop 0, 0, $w, $h; |
3522 | glVertex 0 , 0; |
|
|
3523 | glVertex 0 , $h; |
|
|
3524 | glVertex $w, $h; |
|
|
3525 | glVertex $w, 0; |
|
|
3526 | glEnd; |
|
|
3527 | |
3607 | |
3528 | glTranslate 2 - 0.375, 2 - 0.375; |
3608 | glTranslate 2 - 0.375, 2 - 0.375; |
3529 | |
3609 | |
3530 | $self->SUPER::_draw; |
3610 | $self->SUPER::_draw; |
3531 | } |
3611 | } |