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.279 by root, Mon Jun 5 00:17:47 2006 UTC vs.
Revision 1.280 by root, Mon Jun 5 01:22:08 2006 UTC

383sub set_max_size { 383sub set_max_size {
384 my ($self, $w, $h) = @_; 384 my ($self, $w, $h) = @_;
385 385
386 delete $self->{max_w}; $self->{max_w} = $w if $w; 386 delete $self->{max_w}; $self->{max_w} = $w if $w;
387 delete $self->{max_h}; $self->{max_h} = $h if $h; 387 delete $self->{max_h}; $self->{max_h} = $h if $h;
388
389 $self->realloc;
388} 390}
389 391
390sub set_tooltip { 392sub set_tooltip {
391 my ($self, $tooltip) = @_; 393 my ($self, $tooltip) = @_;
392 394
3067our @ISA = CFClient::UI::VBox::; 3069our @ISA = CFClient::UI::VBox::;
3068 3070
3069sub new { 3071sub new {
3070 my $class = shift; 3072 my $class = shift;
3071 3073
3072 $class->SUPER::new ( 3074 my $self = $class->SUPER::new (
3073 fontsize => 0.8, 3075 fontsize => 0.8,
3074 @_, 3076 @_,
3075 ) 3077 );
3078
3079 Scalar::Util::weaken (my $this = $self);
3080
3081 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub {
3082 $this->reorder;
3083 $this->update;
3084 });
3085
3086 $self
3076} 3087}
3077 3088
3078sub reorder { 3089sub reorder {
3079 my ($self) = @_; 3090 my ($self) = @_;
3080 my $NOW = time; 3091 my $NOW = Time::HiRes::time;
3081 3092
3082 while (my ($k, $v) = each %{ $self->{item} }) { 3093 while (my ($k, $v) = each %{ $self->{item} }) {
3083 delete $self->{item}{$k} if $v->{timeout} < $NOW; 3094 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3084 } 3095 }
3085 3096
3087 3098
3088 my @items = sort { 3099 my @items = sort {
3089 $a->{pri} <=> $b->{pri} 3100 $a->{pri} <=> $b->{pri}
3090 or $b->{id} <=> $a->{id} 3101 or $b->{id} <=> $a->{id}
3091 } values %{ $self->{item} }; 3102 } values %{ $self->{item} };
3103
3104 $self->{timer}->interval (1);
3092 3105
3093 my $count = 10 + 1; 3106 my $count = 10 + 1;
3094 for my $item (@items) { 3107 for my $item (@items) {
3095 last unless --$count; 3108 last unless --$count;
3096 3109
3111 tooltip_font => $::FONT_PROP, 3124 tooltip_font => $::FONT_PROP,
3112 tooltip_width => 0.67, 3125 tooltip_width => 0.67,
3113 fontsize => $item->{fontsize} || $self->{fontsize}, 3126 fontsize => $item->{fontsize} || $self->{fontsize},
3114 max_w => $::WIDTH * 0.44, 3127 max_w => $::WIDTH * 0.44,
3115 fg => $item->{fg}, 3128 fg => $item->{fg},
3129 orig_alpha => $item->{fg}[3] || 1,
3116 can_events => 1, 3130 can_events => 1,
3117 can_hover => 1 3131 can_hover => 1
3118 }; 3132 };
3133
3134 if ((my $diff = $item->{timeout} - $NOW) < 2) {
3135 $item->{label}{fg}[3] = $item->{label}{orig_alpha} * $diff / 2;
3136 if ($diff < 1) {
3137 $item->{label}{max_h} = $item->{label}{req_h} * $diff;
3138 $item->{label}->realloc;
3139 }
3140 $item->{label}->update;
3141 $self->{timer}->interval (1/30);
3142 }
3119 } 3143 }
3120 3144
3121 $self->clear; 3145 $self->clear;
3122 $self->SUPER::add (reverse @widgets); 3146 $self->SUPER::add (reverse @widgets);
3123} 3147}
3128 $text =~ s/^\s+//; 3152 $text =~ s/^\s+//;
3129 $text =~ s/\s+$//; 3153 $text =~ s/\s+$//;
3130 3154
3131 return unless $text; 3155 return unless $text;
3132 3156
3133 my $timeout = time + ((delete $arg{timeout}) || 60); 3157 my $timeout = (int time) + ((delete $arg{timeout}) || 60);
3134 3158
3135 my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; 3159 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
3136 3160
3137 if (my $item = $self->{item}{$group}) { 3161 if (my $item = $self->{item}{$group}) {
3138 if ($item->{text} eq $text) { 3162 if ($item->{text} eq $text) {
3168 3192
3169 $self->reorder; 3193 $self->reorder;
3170 $self->SUPER::reconfigure; 3194 $self->SUPER::reconfigure;
3171} 3195}
3172 3196
3197sub DESTROY {
3198 my ($self) = @_;
3199
3200 $self->{timer}->cancel;
3201
3202 $self->SUPER::DESTROY;
3203}
3204
3173############################################################################# 3205#############################################################################
3174 3206
3175package CFClient::UI::Inventory; 3207package CFClient::UI::Inventory;
3176 3208
3177our @ISA = CFClient::UI::ScrolledWindow::; 3209our @ISA = CFClient::UI::ScrolledWindow::;
3469 3501
3470package CFClient::UI::Root; 3502package CFClient::UI::Root;
3471 3503
3472our @ISA = CFClient::UI::Container::; 3504our @ISA = CFClient::UI::Container::;
3473 3505
3506use List::Util qw(min max);
3507
3474use CFClient::OpenGL; 3508use CFClient::OpenGL;
3475 3509
3476sub new { 3510sub new {
3477 my $class = shift; 3511 my $class = shift;
3478 3512
3612 3646
3613 delete $queue{$widget+0}; 3647 delete $queue{$widget+0};
3614 3648
3615 my ($w, $h) = $widget->size_request; 3649 my ($w, $h) = $widget->size_request;
3616 3650
3617 $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; 3651 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2;
3618 $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; 3652 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2;
3653
3654 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
3655 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
3619 3656
3620 $w = $widget->{force_w} if exists $widget->{force_w}; 3657 $w = $widget->{force_w} if exists $widget->{force_w};
3621 $h = $widget->{force_h} if exists $widget->{force_h}; 3658 $h = $widget->{force_h} if exists $widget->{force_h};
3622 3659
3623 if ($widget->{req_w} != $w || $widget->{req_h} != $h 3660 if ($widget->{req_w} != $w || $widget->{req_h} != $h

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines