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.283 by root, Mon Jun 5 02:28:30 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 $self->SUPER::realloc;
1548}
1549
1543sub set_text { 1550sub set_text {
1544 my ($self, $text) = @_; 1551 my ($self, $text) = @_;
1545 1552
1546 return if $self->{text} eq "T$text"; 1553 return if $self->{text} eq "T$text";
1547 $self->{text} = "T$text"; 1554 $self->{text} = "T$text";
1548 1555
1549 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; 1556 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
1550 $self->{layout}->set_text ($text); 1557 $self->{layout}->set_text ($text);
1558 delete $self->{req_h};
1551 1559
1552 $self->realloc; 1560 $self->realloc;
1553 $self->update; 1561 $self->update;
1554} 1562}
1555 1563
1561 1569
1562 my $rgba = $markup =~ /span.*(?:foreground|background)/; 1570 my $rgba = $markup =~ /span.*(?:foreground|background)/;
1563 1571
1564 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; 1572 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1565 $self->{layout}->set_markup ($markup); 1573 $self->{layout}->set_markup ($markup);
1574 delete $self->{req_h};
1566 1575
1567 $self->realloc; 1576 $self->realloc;
1568 $self->update; 1577 $self->update;
1569} 1578}
1570 1579
1571sub size_request { 1580sub size_request {
1572 my ($self) = @_; 1581 my ($self) = @_;
1573 1582
1583 if (exists $self->{req_h}) {
1584 @$self{qw(req_w req_h)}
1585 } else {
1574 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1586 $self->{layout}->set_font ($self->{font}) if $self->{font};
1575 $self->{layout}->set_width ($self->{max_w} || -1); 1587 $self->{layout}->set_width ($self->{max_w} || -1);
1576 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1588 $self->{layout}->set_ellipsise ($self->{ellipsise});
1577 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1589 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1578 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1590 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1579 1591
1580 my ($w, $h) = $self->{layout}->size; 1592 my ($w, $h) = $self->{layout}->size;
1581 1593
1582 if (exists $self->{template}) { 1594 if (exists $self->{template}) {
1583 $self->{template}->set_font ($self->{font}) if $self->{font}; 1595 $self->{template}->set_font ($self->{font}) if $self->{font};
1584 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1596 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1585 1597
1586 my ($w2, $h2) = $self->{template}->size; 1598 my ($w2, $h2) = $self->{template}->size;
1587 1599
1588 $w = List::Util::max $w, $w2; 1600 $w = List::Util::max $w, $w2;
1589 $h = List::Util::max $h, $h2; 1601 $h = List::Util::max $h, $h2;
1590 } 1602 }
1591 1603
1592 ($w, $h) 1604 ($w, $h)
1605 }
1593} 1606}
1594 1607
1595sub size_allocate { 1608sub size_allocate {
1596 my ($self, $w, $h) = @_; 1609 my ($self, $w, $h) = @_;
1597 1610
1682 $self->{last_activity} = $::NOW; 1695 $self->{last_activity} = $::NOW;
1683 $self->{text} = $text; 1696 $self->{text} = $text;
1684 1697
1685 $text =~ s/./*/g if $self->{hidden}; 1698 $text =~ s/./*/g if $self->{hidden};
1686 $self->{layout}->set_text ("$text "); 1699 $self->{layout}->set_text ("$text ");
1700 delete $self->{req_h};
1687 1701
1688 $self->_emit (changed => $self->{text}); 1702 $self->_emit (changed => $self->{text});
1703
1704 $self->realloc;
1689 $self->update; 1705 $self->update;
1690} 1706}
1691 1707
1692sub set_text { 1708sub set_text {
1693 my ($self, $text) = @_; 1709 my ($self, $text) = @_;
1694 1710
1695 $self->{cursor} = length $text; 1711 $self->{cursor} = length $text;
1696 $self->_set_text ($text); 1712 $self->_set_text ($text);
1697
1698 $self->realloc;
1699} 1713}
1700 1714
1701sub get_text { 1715sub get_text {
1702 $_[0]{text} 1716 $_[0]{text}
1703} 1717}
3076 @_, 3090 @_,
3077 ); 3091 );
3078 3092
3079 Scalar::Util::weaken (my $this = $self); 3093 Scalar::Util::weaken (my $this = $self);
3080 3094
3081 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { 3095 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder });
3082 $this->reorder;
3083 $this->update;
3084 });
3085 3096
3086 $self 3097 $self
3087} 3098}
3088 3099
3089sub reorder { 3100sub reorder {
3090 my ($self) = @_; 3101 my ($self) = @_;
3091 my $NOW = Time::HiRes::time; 3102 my $NOW = Time::HiRes::time;
3103
3104 # freeze display when hovering over any label
3105 return if $CFClient::UI::TOOLTIP->{owner}
3106 && grep $CFClient::UI::TOOLTIP->{owner} == $_->{label},
3107 values %{ $self->{item} };
3092 3108
3093 while (my ($k, $v) = each %{ $self->{item} }) { 3109 while (my ($k, $v) = each %{ $self->{item} }) {
3094 delete $self->{item}{$k} if $v->{timeout} < $NOW; 3110 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3095 } 3111 }
3096 3112
3105 3121
3106 my $count = 10 + 1; 3122 my $count = 10 + 1;
3107 for my $item (@items) { 3123 for my $item (@items) {
3108 last unless --$count; 3124 last unless --$count;
3109 3125
3110 push @widgets, $item->{label} ||= do { 3126 my $label = $item->{label} ||= do {
3111 # TODO: doesn't handle markup well (read as: at all) 3127 # TODO: doesn't handle markup well (read as: at all)
3112 my $short = $item->{count} > 1 3128 my $short = $item->{count} > 1
3113 ? "<b>$item->{count} ×</b> $item->{text}" 3129 ? "<b>$item->{count} ×</b> $item->{text}"
3114 : $item->{text}; 3130 : $item->{text};
3115 3131
3123 tooltip => $item->{tooltip}, 3139 tooltip => $item->{tooltip},
3124 tooltip_font => $::FONT_PROP, 3140 tooltip_font => $::FONT_PROP,
3125 tooltip_width => 0.67, 3141 tooltip_width => 0.67,
3126 fontsize => $item->{fontsize} || $self->{fontsize}, 3142 fontsize => $item->{fontsize} || $self->{fontsize},
3127 max_w => $::WIDTH * 0.44, 3143 max_w => $::WIDTH * 0.44,
3128 fg => $item->{fg}, 3144 fg => [@{ $item->{fg} }],
3129 orig_alpha => $item->{fg}[3] || 1,
3130 can_events => 1, 3145 can_events => 1,
3131 can_hover => 1 3146 can_hover => 1
3132 }; 3147 };
3133 3148
3134 if ((my $diff = $item->{timeout} - $NOW) < 2) { 3149 if ((my $diff = $item->{timeout} - $NOW) < 2) {
3135 $item->{label}{fg}[3] = $item->{label}{orig_alpha} * $diff / 2; 3150 $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; 3151 $label->update;
3152 $label->set_max_size (undef, $label->{req_h} * $diff)
3153 if $diff < 1;
3141 $self->{timer}->interval (1/30); 3154 $self->{timer}->interval (1/30);
3155 } else {
3156 $label->{fg}[3] = $item->{fg}[3] || 1;
3142 } 3157 }
3158
3159 push @widgets, $label;
3143 } 3160 }
3144 3161
3145 $self->clear; 3162 $self->clear;
3146 $self->SUPER::add (reverse @widgets); 3163 $self->SUPER::add (reverse @widgets);
3147} 3164}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines