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.280 by root, Mon Jun 5 01:22:08 2006 UTC vs.
Revision 1.282 by root, Mon Jun 5 02:25:10 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 388
389 $self->realloc; 389 $self->realloc;
390} 390}
391 391
392sub set_tooltip { 392sub set_tooltip {
1538 1538
1539 delete $self->{texture}; 1539 delete $self->{texture};
1540 $self->SUPER::update; 1540 $self->SUPER::update;
1541} 1541}
1542 1542
1543sub realloc {
1544 my ($self) = @_;
1545
1546 delete $self->{ox};
1547 delete $self->{req_h};
1548 $self->SUPER::realloc;
1549}
1550
1543sub set_text { 1551sub set_text {
1544 my ($self, $text) = @_; 1552 my ($self, $text) = @_;
1545 1553
1546 return if $self->{text} eq "T$text"; 1554 return if $self->{text} eq "T$text";
1547 $self->{text} = "T$text"; 1555 $self->{text} = "T$text";
1569} 1577}
1570 1578
1571sub size_request { 1579sub size_request {
1572 my ($self) = @_; 1580 my ($self) = @_;
1573 1581
1582 if (exists $self->{req_h}) {
1583 @$self{qw(req_w req_h)}
1584 } else {
1574 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1585 $self->{layout}->set_font ($self->{font}) if $self->{font};
1575 $self->{layout}->set_width ($self->{max_w} || -1); 1586 $self->{layout}->set_width ($self->{max_w} || -1);
1576 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1587 $self->{layout}->set_ellipsise ($self->{ellipsise});
1577 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1588 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1578 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1589 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1579 1590
1580 my ($w, $h) = $self->{layout}->size; 1591 my ($w, $h) = $self->{layout}->size;
1581 1592
1582 if (exists $self->{template}) { 1593 if (exists $self->{template}) {
1583 $self->{template}->set_font ($self->{font}) if $self->{font}; 1594 $self->{template}->set_font ($self->{font}) if $self->{font};
1584 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1595 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1585 1596
1586 my ($w2, $h2) = $self->{template}->size; 1597 my ($w2, $h2) = $self->{template}->size;
1587 1598
1588 $w = List::Util::max $w, $w2; 1599 $w = List::Util::max $w, $w2;
1589 $h = List::Util::max $h, $h2; 1600 $h = List::Util::max $h, $h2;
1590 } 1601 }
1591 1602
1592 ($w, $h) 1603 ($w, $h)
1604 }
1593} 1605}
1594 1606
1595sub size_allocate { 1607sub size_allocate {
1596 my ($self, $w, $h) = @_; 1608 my ($self, $w, $h) = @_;
1597 1609
3076 @_, 3088 @_,
3077 ); 3089 );
3078 3090
3079 Scalar::Util::weaken (my $this = $self); 3091 Scalar::Util::weaken (my $this = $self);
3080 3092
3081 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { 3093 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder });
3082 $this->reorder;
3083 $this->update;
3084 });
3085 3094
3086 $self 3095 $self
3087} 3096}
3088 3097
3089sub reorder { 3098sub reorder {
3090 my ($self) = @_; 3099 my ($self) = @_;
3091 my $NOW = Time::HiRes::time; 3100 my $NOW = Time::HiRes::time;
3101
3102 # freeze display when hovering over any label
3103 return if $CFClient::UI::TOOLTIP->{owner}
3104 && grep $CFClient::UI::TOOLTIP->{owner} == $_->{label},
3105 values %{ $self->{item} };
3092 3106
3093 while (my ($k, $v) = each %{ $self->{item} }) { 3107 while (my ($k, $v) = each %{ $self->{item} }) {
3094 delete $self->{item}{$k} if $v->{timeout} < $NOW; 3108 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3095 } 3109 }
3096 3110
3105 3119
3106 my $count = 10 + 1; 3120 my $count = 10 + 1;
3107 for my $item (@items) { 3121 for my $item (@items) {
3108 last unless --$count; 3122 last unless --$count;
3109 3123
3110 push @widgets, $item->{label} ||= do { 3124 my $label = $item->{label} ||= do {
3111 # TODO: doesn't handle markup well (read as: at all) 3125 # TODO: doesn't handle markup well (read as: at all)
3112 my $short = $item->{count} > 1 3126 my $short = $item->{count} > 1
3113 ? "<b>$item->{count} ×</b> $item->{text}" 3127 ? "<b>$item->{count} ×</b> $item->{text}"
3114 : $item->{text}; 3128 : $item->{text};
3115 3129
3123 tooltip => $item->{tooltip}, 3137 tooltip => $item->{tooltip},
3124 tooltip_font => $::FONT_PROP, 3138 tooltip_font => $::FONT_PROP,
3125 tooltip_width => 0.67, 3139 tooltip_width => 0.67,
3126 fontsize => $item->{fontsize} || $self->{fontsize}, 3140 fontsize => $item->{fontsize} || $self->{fontsize},
3127 max_w => $::WIDTH * 0.44, 3141 max_w => $::WIDTH * 0.44,
3128 fg => $item->{fg}, 3142 fg => [@{ $item->{fg} }],
3129 orig_alpha => $item->{fg}[3] || 1,
3130 can_events => 1, 3143 can_events => 1,
3131 can_hover => 1 3144 can_hover => 1
3132 }; 3145 };
3133 3146
3134 if ((my $diff = $item->{timeout} - $NOW) < 2) { 3147 if ((my $diff = $item->{timeout} - $NOW) < 2) {
3135 $item->{label}{fg}[3] = $item->{label}{orig_alpha} * $diff / 2; 3148 $label->{fg}[3] = ($item->{fg}[3] || 1) * $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; 3149 $label->update;
3150 $label->set_max_size (undef, $label->{req_h} * $diff)
3151 if $diff < 1;
3141 $self->{timer}->interval (1/30); 3152 $self->{timer}->interval (1/30);
3153 } else {
3154 $label->{fg}[3] = $item->{fg}[3] || 1;
3142 } 3155 }
3156
3157 push @widgets, $label;
3143 } 3158 }
3144 3159
3145 $self->clear; 3160 $self->clear;
3146 $self->SUPER::add (reverse @widgets); 3161 $self->SUPER::add (reverse @widgets);
3147} 3162}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines