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.281 by root, Mon Jun 5 01:59:59 2006 UTC

381} 381}
382 382
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 $self->{max_w} = int $w if defined $w;
387 delete $self->{max_h}; $self->{max_h} = $h if $h; 387 $self->{max_h} = int $h if defined $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 { $this->reorder });
3082
3083 $self
3076} 3084}
3077 3085
3078sub reorder { 3086sub reorder {
3079 my ($self) = @_; 3087 my ($self) = @_;
3080 my $NOW = time; 3088 my $NOW = Time::HiRes::time;
3089
3090 # freeze display when hovering over any label
3091 return if $CFClient::UI::TOOLTIP->{owner}
3092 && grep $CFClient::UI::TOOLTIP->{owner} == $_->{label},
3093 values %{ $self->{item} };
3081 3094
3082 while (my ($k, $v) = each %{ $self->{item} }) { 3095 while (my ($k, $v) = each %{ $self->{item} }) {
3083 delete $self->{item}{$k} if $v->{timeout} < $NOW; 3096 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3084 } 3097 }
3085 3098
3088 my @items = sort { 3101 my @items = sort {
3089 $a->{pri} <=> $b->{pri} 3102 $a->{pri} <=> $b->{pri}
3090 or $b->{id} <=> $a->{id} 3103 or $b->{id} <=> $a->{id}
3091 } values %{ $self->{item} }; 3104 } values %{ $self->{item} };
3092 3105
3106 $self->{timer}->interval (1);
3107
3093 my $count = 10 + 1; 3108 my $count = 10 + 1;
3094 for my $item (@items) { 3109 for my $item (@items) {
3095 last unless --$count; 3110 last unless --$count;
3096 3111
3097 push @widgets, $item->{label} ||= do { 3112 my $label = $item->{label} ||= do {
3098 # TODO: doesn't handle markup well (read as: at all) 3113 # TODO: doesn't handle markup well (read as: at all)
3099 my $short = $item->{count} > 1 3114 my $short = $item->{count} > 1
3100 ? "<b>$item->{count} ×</b> $item->{text}" 3115 ? "<b>$item->{count} ×</b> $item->{text}"
3101 : $item->{text}; 3116 : $item->{text};
3102 3117
3110 tooltip => $item->{tooltip}, 3125 tooltip => $item->{tooltip},
3111 tooltip_font => $::FONT_PROP, 3126 tooltip_font => $::FONT_PROP,
3112 tooltip_width => 0.67, 3127 tooltip_width => 0.67,
3113 fontsize => $item->{fontsize} || $self->{fontsize}, 3128 fontsize => $item->{fontsize} || $self->{fontsize},
3114 max_w => $::WIDTH * 0.44, 3129 max_w => $::WIDTH * 0.44,
3115 fg => $item->{fg}, 3130 fg => [@{ $item->{fg} }],
3116 can_events => 1, 3131 can_events => 1,
3117 can_hover => 1 3132 can_hover => 1
3118 }; 3133 };
3134
3135 if ((my $diff = $item->{timeout} - $NOW) < 2) {
3136 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2;
3137 $label->update;
3138 $label->set_max_size (undef, $label->{req_h} * $diff)
3139 if $diff < 1;
3140 $self->{timer}->interval (1/30);
3141 } else {
3142 $label->{fg}[3] = $item->{fg}[3] || 1;
3143 }
3144
3145 push @widgets, $label;
3119 } 3146 }
3120 3147
3121 $self->clear; 3148 $self->clear;
3122 $self->SUPER::add (reverse @widgets); 3149 $self->SUPER::add (reverse @widgets);
3123} 3150}
3128 $text =~ s/^\s+//; 3155 $text =~ s/^\s+//;
3129 $text =~ s/\s+$//; 3156 $text =~ s/\s+$//;
3130 3157
3131 return unless $text; 3158 return unless $text;
3132 3159
3133 my $timeout = time + ((delete $arg{timeout}) || 60); 3160 my $timeout = (int time) + ((delete $arg{timeout}) || 60);
3134 3161
3135 my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; 3162 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
3136 3163
3137 if (my $item = $self->{item}{$group}) { 3164 if (my $item = $self->{item}{$group}) {
3138 if ($item->{text} eq $text) { 3165 if ($item->{text} eq $text) {
3168 3195
3169 $self->reorder; 3196 $self->reorder;
3170 $self->SUPER::reconfigure; 3197 $self->SUPER::reconfigure;
3171} 3198}
3172 3199
3200sub DESTROY {
3201 my ($self) = @_;
3202
3203 $self->{timer}->cancel;
3204
3205 $self->SUPER::DESTROY;
3206}
3207
3173############################################################################# 3208#############################################################################
3174 3209
3175package CFClient::UI::Inventory; 3210package CFClient::UI::Inventory;
3176 3211
3177our @ISA = CFClient::UI::ScrolledWindow::; 3212our @ISA = CFClient::UI::ScrolledWindow::;
3469 3504
3470package CFClient::UI::Root; 3505package CFClient::UI::Root;
3471 3506
3472our @ISA = CFClient::UI::Container::; 3507our @ISA = CFClient::UI::Container::;
3473 3508
3509use List::Util qw(min max);
3510
3474use CFClient::OpenGL; 3511use CFClient::OpenGL;
3475 3512
3476sub new { 3513sub new {
3477 my $class = shift; 3514 my $class = shift;
3478 3515
3612 3649
3613 delete $queue{$widget+0}; 3650 delete $queue{$widget+0};
3614 3651
3615 my ($w, $h) = $widget->size_request; 3652 my ($w, $h) = $widget->size_request;
3616 3653
3617 $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; 3654 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2;
3618 $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; 3655 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2;
3656
3657 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
3658 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
3619 3659
3620 $w = $widget->{force_w} if exists $widget->{force_w}; 3660 $w = $widget->{force_w} if exists $widget->{force_w};
3621 $h = $widget->{force_h} if exists $widget->{force_h}; 3661 $h = $widget->{force_h} if exists $widget->{force_h};
3622 3662
3623 if ($widget->{req_w} != $w || $widget->{req_h} != $h 3663 if ($widget->{req_w} != $w || $widget->{req_h} != $h

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines