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.426 by root, Sat Aug 11 12:07:54 2007 UTC vs.
Revision 1.433 by root, Wed Aug 22 21:27:13 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#############################################################################
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;
2651 align => 0, 2626 align => 0,
2652 valign => 0, 2627 valign => 0,
2653 can_events => 1, 2628 can_events => 1,
2654 @_ 2629 @_
2655 ); 2630 );
2631}
2632
2633sub invoke_button_down {
2634 my ($self, $ev, $x, $y) = @_;
2635
2636 1
2656} 2637}
2657 2638
2658sub invoke_button_up { 2639sub invoke_button_up {
2659 my ($self, $ev, $x, $y) = @_; 2640 my ($self, $ev, $x, $y) = @_;
2660 2641
2800 glDisable GL_TEXTURE_2D; 2781 glDisable GL_TEXTURE_2D;
2801} 2782}
2802 2783
2803############################################################################# 2784#############################################################################
2804 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 label => "%d%%",
2806 %arg,
2807 );
2808
2809 $self->set_value ($arg{value} || -1);
2810
2811 $self
2812}
2813
2814sub set_label {
2815 my ($self, $label) = @_;
2816
2817 return if $self->{label} eq $label;
2818 $self->{label} = $label;
2819
2820 $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value});
2821}
2822
2823sub set_value {
2824 my ($self, $value) = @_;
2825
2826 if ($self->{value} ne $value) {
2827 $self->{value} = $value;
2828
2829 if ($value < 0) {
2830 $self->set_text ("-");
2831 } else {
2832 $self->set_text (sprintf $self->{label}, $value * 100);
2833 }
2834
2835 $self->update;
2836 }
2837}
2838
2839sub _draw {
2840 my ($self) = @_;
2841
2842 glEnable GL_BLEND;
2843 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2844
2845 if ($self->{value} >= 0) {
2846 my $s = 3 + ($self->{w} - 6) * $self->{value};
2847
2848 glColor_premultiply @{$self->{bar}};
2849 glRect 2, 2, $s, $self->{h} - 2;
2850 glColor_premultiply @{$self->{bg}};
2851 glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2;
2852 }
2853
2854 glColor_premultiply @{$self->{outline}};
2855 glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2;
2856
2857 glDisable GL_BLEND;
2858
2859 {
2860 local $self->{bg}; # do not draw background
2861 $self->SUPER::_draw;
2862 }
2863}
2864
2865#############################################################################
2866
2867package CFPlus::UI::ExperienceProgress;
2868
2869our @ISA = CFPlus::UI::Progress::;
2870
2871sub new {
2872 my ($class, %arg) = @_;
2873
2874 my $self = $class->SUPER::new (
2875 %arg
2876 );
2877
2878 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2879 if $::CONN;
2880
2881 $self
2882}
2883
2884sub DESTROY {
2885 my ($self) = @_;
2886
2887 delete $::CONN->{on_exp_update}{$self+0}
2888 if $::CONN;
2889
2890 $self->SUPER::DESTROY;
2891}
2892
2893sub set_value {
2894 my ($self, $lvl, $exp) = @_;
2895
2896 my $v = -1;
2897
2898 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2899 my $l0 = $table->[$lvl - 1];
2900 my $l1 = $table->[$lvl];
2901
2902 $v = ($exp - $l0) / ($l1 - $l0);
2903 }
2904
2905 $self->SUPER::set_value ($v);
2906}
2907
2908#############################################################################
2909
2805package CFPlus::UI::Gauge; 2910package CFPlus::UI::Gauge;
2806 2911
2807our @ISA = CFPlus::UI::VBox::; 2912our @ISA = CFPlus::UI::VBox::;
2808 2913
2809sub new { 2914sub new {
3510 3615
3511 glColor 1, 0.8, 0.4; 3616 glColor 1, 0.8, 0.4;
3512 glRect 0, 0, $w, $h; 3617 glRect 0, 0, $w, $h;
3513 3618
3514 glColor 0, 0, 0; 3619 glColor 0, 0, 0;
3515 glBegin GL_LINE_LOOP; 3620 glRect_lineloop 0, 0, $w, $h;
3516 glVertex 0 , 0;
3517 glVertex 0 , $h;
3518 glVertex $w, $h;
3519 glVertex $w, 0;
3520 glEnd;
3521 3621
3522 glTranslate 2 - 0.375, 2 - 0.375; 3622 glTranslate 2 - 0.375, 2 - 0.375;
3523 3623
3524 $self->SUPER::_draw; 3624 $self->SUPER::_draw;
3525} 3625}
3549 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3649 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3550 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; 3650 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed};
3551 $self->{timer} = Event->timer ( 3651 $self->{timer} = Event->timer (
3552 parked => 1, 3652 parked => 1,
3553 cb => sub { 3653 cb => sub {
3554 return unless $::CONN && $widget; 3654 return unless $::CONN;
3555 3655
3656 my $w = $widget
3657 or return;
3658
3556 ++$widget->{frame}; 3659 ++$w->{frame};
3557 $widget->update_face; 3660 $w->update_face;
3661
3662 # somehow, $widget can go away
3558 $widget->update; 3663 $w->update;
3559
3560 $widget->update_timer; 3664 $w->update_timer;
3561 }, 3665 },
3562 ); 3666 );
3563 3667
3564 $self->update_face; 3668 $self->update_face;
3565 $self->update_timer; 3669 $self->update_timer;
3586} 3690}
3587 3691
3588sub update_face { 3692sub update_face {
3589 my ($self) = @_; 3693 my ($self) = @_;
3590 3694
3591 return unless $::CONN; 3695 if ($::CONN) {
3592
3593 if (my $anim = $::CONN->{anim}[$self->{anim}]) { 3696 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3594 if ($anim && @$anim) { 3697 if ($anim && @$anim) {
3595 delete $self->{wait_face};
3596 $self->{face} = $anim->[ $self->{frame} % @$anim ]; 3698 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3699 delete $self->{face_change_cb};
3700
3597 if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ]) { 3701 if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) {
3598 unless ($tex->{name} || $tex->{loading}) { 3702 unless ($tex->{name} || $tex->{loading}) {
3599 $tex->upload (sub { $self->reconfigure }); 3703 $tex->upload (sub { $self->reconfigure });
3704 }
3600 } 3705 }
3601 } 3706 }
3602 } 3707 }
3603 } 3708 }
3604} 3709}
3605 3710
3606sub size_request { 3711sub size_request {
3607 my ($self) = @_; 3712 my ($self) = @_;
3608 3713
3609 if ($::CONN) { 3714 if ($::CONN) {
3610 if (my $faceid = $::CONN->{faceid}[$self->{face}]) { 3715 if (my $faceid = $::CONN->{face}[$self->{face}]{id}) {
3611 if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) { 3716 if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) {
3612 if ($tex->{name}) { 3717 if ($tex->{name}) {
3613 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); 3718 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3614 } elsif (!$tex->{loading}) { 3719 } elsif (!$tex->{loading}) {
3615 $tex->upload (sub { $self->reconfigure }); 3720 $tex->upload (sub { $self->reconfigure });
3616 } 3721 }
3617 } else {
3618 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub {
3619 $self->reconfigure;
3620 });
3621 } 3722 }
3723
3724 $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure });
3622 } 3725 }
3623 } 3726 }
3624 3727
3625 ($self->{size_w} || 8, $self->{size_h} || 8) 3728 ($self->{size_w} || 8, $self->{size_h} || 8)
3626} 3729}
3841 3944
3842############################################################################# 3945#############################################################################
3843 3946
3844package CFPlus::UI::Notebook; 3947package CFPlus::UI::Notebook;
3845 3948
3949use CFPlus::OpenGL;
3950
3846our @ISA = CFPlus::UI::VBox::; 3951our @ISA = CFPlus::UI::VBox::;
3847 3952
3848sub new { 3953sub new {
3849 my $class = shift; 3954 my $class = shift;
3850 3955
3851 my $self = $class->SUPER::new ( 3956 my $self = $class->SUPER::new (
3852 buttonbar => (new CFPlus::UI::Buttonbar), 3957 buttonbar => (new CFPlus::UI::Buttonbar),
3853 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3958 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3959 active_outline => [1, 1, 0],
3854 # filter => # will be put between multiplexer and $self 3960 # filter => # will be put between multiplexer and $self
3855 @_, 3961 @_,
3856 ); 3962 );
3857 3963
3858 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3964 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3930sub set_current_page { 4036sub set_current_page {
3931 my ($self, $page) = @_; 4037 my ($self, $page) = @_;
3932 4038
3933 $self->{multiplexer}->set_current_page ($page); 4039 $self->{multiplexer}->set_current_page ($page);
3934 $self->emit (page_changed => $self->{multiplexer}{current}); 4040 $self->emit (page_changed => $self->{multiplexer}{current});
4041}
4042
4043sub _draw {
4044 my ($self) = @_;
4045
4046 $self->SUPER::_draw ();
4047
4048 if (my $cur = $self->{multiplexer}{current}) {
4049 if ($cur = $cur->{c_tab_}) {
4050 glTranslate $cur->{x}, $cur->{y};
4051 glLineWidth 3;
4052 glColor @{$self->{active_outline}};
4053 glRect_lineloop 1, 1, $cur->{w} - 2, $cur->{h} - 2;
4054 glLineWidth 1;
4055 }
4056 }
3935} 4057}
3936 4058
3937############################################################################# 4059#############################################################################
3938 4060
3939package CFPlus::UI::Selector; 4061package CFPlus::UI::Selector;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines