… | |
… | |
381 | } |
381 | } |
382 | |
382 | |
383 | sub set_max_size { |
383 | sub 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 | |
390 | sub set_tooltip { |
392 | sub set_tooltip { |
391 | my ($self, $tooltip) = @_; |
393 | my ($self, $tooltip) = @_; |
392 | |
394 | |
… | |
… | |
855 | my $tex = $self->{texture} |
857 | my $tex = $self->{texture} |
856 | or return; |
858 | or return; |
857 | |
859 | |
858 | glEnable GL_TEXTURE_2D; |
860 | glEnable GL_TEXTURE_2D; |
859 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
861 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
860 | glEnable GL_BLEND; |
|
|
861 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
862 | glColor 0, 0, 0, 1; |
862 | glColor 0, 0, 0, 1; |
863 | |
863 | |
864 | $tex->draw_quad (0, 0, $w, $h); |
864 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
865 | |
865 | |
866 | glDisable GL_BLEND; |
|
|
867 | glDisable GL_TEXTURE_2D; |
866 | glDisable GL_TEXTURE_2D; |
868 | } |
867 | } |
869 | |
868 | |
870 | ############################################################################# |
869 | ############################################################################# |
871 | |
870 | |
… | |
… | |
1539 | |
1538 | |
1540 | delete $self->{texture}; |
1539 | delete $self->{texture}; |
1541 | $self->SUPER::update; |
1540 | $self->SUPER::update; |
1542 | } |
1541 | } |
1543 | |
1542 | |
|
|
1543 | sub realloc { |
|
|
1544 | my ($self) = @_; |
|
|
1545 | |
|
|
1546 | delete $self->{ox}; |
|
|
1547 | $self->SUPER::realloc; |
|
|
1548 | } |
|
|
1549 | |
1544 | sub set_text { |
1550 | sub set_text { |
1545 | my ($self, $text) = @_; |
1551 | my ($self, $text) = @_; |
1546 | |
1552 | |
1547 | return if $self->{text} eq "T$text"; |
1553 | return if $self->{text} eq "T$text"; |
1548 | $self->{text} = "T$text"; |
1554 | $self->{text} = "T$text"; |
1549 | |
1555 | |
1550 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1556 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1551 | $self->{layout}->set_text ($text); |
1557 | $self->{layout}->set_text ($text); |
|
|
1558 | delete $self->{req_h}; |
1552 | |
1559 | |
1553 | $self->realloc; |
1560 | $self->realloc; |
1554 | $self->update; |
1561 | $self->update; |
1555 | } |
1562 | } |
1556 | |
1563 | |
… | |
… | |
1562 | |
1569 | |
1563 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1570 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1564 | |
1571 | |
1565 | $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; |
1566 | $self->{layout}->set_markup ($markup); |
1573 | $self->{layout}->set_markup ($markup); |
|
|
1574 | delete $self->{req_h}; |
1567 | |
1575 | |
1568 | $self->realloc; |
1576 | $self->realloc; |
1569 | $self->update; |
1577 | $self->update; |
1570 | } |
1578 | } |
1571 | |
1579 | |
1572 | sub size_request { |
1580 | sub size_request { |
1573 | my ($self) = @_; |
1581 | my ($self) = @_; |
1574 | |
1582 | |
|
|
1583 | if (exists $self->{req_h}) { |
|
|
1584 | @$self{qw(req_w req_h)} |
|
|
1585 | } else { |
1575 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1586 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1576 | $self->{layout}->set_width ($self->{max_w} || -1); |
1587 | $self->{layout}->set_width ($self->{max_w} || -1); |
1577 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1588 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1578 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1589 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1579 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1590 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1580 | |
1591 | |
1581 | my ($w, $h) = $self->{layout}->size; |
1592 | my ($w, $h) = $self->{layout}->size; |
1582 | |
1593 | |
1583 | if (exists $self->{template}) { |
1594 | if (exists $self->{template}) { |
1584 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1595 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1585 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1596 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1586 | |
1597 | |
1587 | my ($w2, $h2) = $self->{template}->size; |
1598 | my ($w2, $h2) = $self->{template}->size; |
1588 | |
1599 | |
1589 | $w = List::Util::max $w, $w2; |
1600 | $w = List::Util::max $w, $w2; |
1590 | $h = List::Util::max $h, $h2; |
1601 | $h = List::Util::max $h, $h2; |
1591 | } |
1602 | } |
1592 | |
1603 | |
1593 | ($w, $h) |
1604 | ($w, $h) |
|
|
1605 | } |
1594 | } |
1606 | } |
1595 | |
1607 | |
1596 | sub size_allocate { |
1608 | sub size_allocate { |
1597 | my ($self, $w, $h) = @_; |
1609 | my ($self, $w, $h) = @_; |
1598 | |
1610 | |
… | |
… | |
1638 | }; |
1650 | }; |
1639 | |
1651 | |
1640 | glEnable GL_TEXTURE_2D; |
1652 | glEnable GL_TEXTURE_2D; |
1641 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1653 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1642 | |
1654 | |
|
|
1655 | glColor_premultiply @{$self->{fg}} |
1643 | if ($tex->{format} == GL_ALPHA) { |
1656 | if $tex->{format} == GL_ALPHA; |
1644 | glColor @{$self->{fg}}; |
1657 | |
1645 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
|
|
1646 | } else { |
|
|
1647 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1658 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1648 | } |
|
|
1649 | |
1659 | |
1650 | glDisable GL_TEXTURE_2D; |
1660 | glDisable GL_TEXTURE_2D; |
1651 | } |
1661 | } |
1652 | |
1662 | |
1653 | ############################################################################# |
1663 | ############################################################################# |
… | |
… | |
1685 | $self->{last_activity} = $::NOW; |
1695 | $self->{last_activity} = $::NOW; |
1686 | $self->{text} = $text; |
1696 | $self->{text} = $text; |
1687 | |
1697 | |
1688 | $text =~ s/./*/g if $self->{hidden}; |
1698 | $text =~ s/./*/g if $self->{hidden}; |
1689 | $self->{layout}->set_text ("$text "); |
1699 | $self->{layout}->set_text ("$text "); |
|
|
1700 | delete $self->{req_h}; |
1690 | |
1701 | |
1691 | $self->_emit (changed => $self->{text}); |
1702 | $self->_emit (changed => $self->{text}); |
|
|
1703 | |
|
|
1704 | $self->realloc; |
1692 | $self->update; |
1705 | $self->update; |
1693 | } |
1706 | } |
1694 | |
1707 | |
1695 | sub set_text { |
1708 | sub set_text { |
1696 | my ($self, $text) = @_; |
1709 | my ($self, $text) = @_; |
1697 | |
1710 | |
1698 | $self->{cursor} = length $text; |
1711 | $self->{cursor} = length $text; |
1699 | $self->_set_text ($text); |
1712 | $self->_set_text ($text); |
1700 | |
|
|
1701 | $self->realloc; |
|
|
1702 | } |
1713 | } |
1703 | |
1714 | |
1704 | sub get_text { |
1715 | sub get_text { |
1705 | $_[0]{text} |
1716 | $_[0]{text} |
1706 | } |
1717 | } |
… | |
… | |
1913 | } |
1924 | } |
1914 | |
1925 | |
1915 | sub _draw { |
1926 | sub _draw { |
1916 | my ($self) = @_; |
1927 | my ($self) = @_; |
1917 | |
1928 | |
1918 | local $self->{fg} = $self->{fg}; |
1929 | local $self->{fg} = $GRAB == $self ? $self->{active_fg} : $self->{fg}; |
1919 | |
|
|
1920 | if ($GRAB == $self) { |
|
|
1921 | $self->{fg} = $self->{active_fg}; |
|
|
1922 | } |
|
|
1923 | |
1930 | |
1924 | glEnable GL_TEXTURE_2D; |
1931 | glEnable GL_TEXTURE_2D; |
1925 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1932 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1926 | glColor 0, 0, 0, 1; |
1933 | glColor 0, 0, 0, 1; |
1927 | |
1934 | |
… | |
… | |
2575 | |
2582 | |
2576 | delete $self->{texture}; |
2583 | delete $self->{texture}; |
2577 | } |
2584 | } |
2578 | |
2585 | |
2579 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2586 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2580 | glClearColor 0.5, 0.5, 0.5, 0; |
2587 | glClearColor 0, 0, 0, 0; |
2581 | glClear GL_COLOR_BUFFER_BIT; |
2588 | glClear GL_COLOR_BUFFER_BIT; |
2582 | |
2589 | |
2583 | my $top = int $self->{children}[1]{range}[0]; |
2590 | my $top = int $self->{children}[1]{range}[0]; |
2584 | |
2591 | |
2585 | my $y0 = $top; |
2592 | my $y0 = $top; |
… | |
… | |
2620 | sub _draw { |
2627 | sub _draw { |
2621 | my ($self) = @_; |
2628 | my ($self) = @_; |
2622 | |
2629 | |
2623 | glEnable GL_TEXTURE_2D; |
2630 | glEnable GL_TEXTURE_2D; |
2624 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2631 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2625 | glColor 1, 1, 1, 1; |
2632 | glColor 0, 0, 0, 1; |
2626 | $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2633 | $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2627 | glDisable GL_TEXTURE_2D; |
2634 | glDisable GL_TEXTURE_2D; |
2628 | |
2635 | |
2629 | $self->{children}[1]->draw; |
2636 | $self->{children}[1]->draw; |
2630 | |
2637 | |
2631 | } |
2638 | } |
… | |
… | |
2858 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2865 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2859 | |
2866 | |
2860 | if ($tex) { |
2867 | if ($tex) { |
2861 | glEnable GL_TEXTURE_2D; |
2868 | glEnable GL_TEXTURE_2D; |
2862 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2869 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2863 | glColor 1, 1, 1, 1; |
2870 | glColor 0, 0, 0, 1; |
2864 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2871 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2865 | glDisable GL_TEXTURE_2D; |
2872 | glDisable GL_TEXTURE_2D; |
2866 | } |
2873 | } |
2867 | } |
2874 | } |
2868 | |
2875 | |
… | |
… | |
3076 | our @ISA = CFClient::UI::VBox::; |
3083 | our @ISA = CFClient::UI::VBox::; |
3077 | |
3084 | |
3078 | sub new { |
3085 | sub new { |
3079 | my $class = shift; |
3086 | my $class = shift; |
3080 | |
3087 | |
3081 | $class->SUPER::new ( |
3088 | my $self = $class->SUPER::new ( |
3082 | fontsize => 0.8, |
3089 | fontsize => 0.8, |
3083 | @_, |
3090 | @_, |
3084 | ) |
3091 | ); |
|
|
3092 | |
|
|
3093 | Scalar::Util::weaken (my $this = $self); |
|
|
3094 | |
|
|
3095 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
|
|
3096 | |
|
|
3097 | $self |
3085 | } |
3098 | } |
3086 | |
3099 | |
3087 | sub reorder { |
3100 | sub reorder { |
3088 | my ($self) = @_; |
3101 | my ($self) = @_; |
3089 | my $NOW = 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} }; |
3090 | |
3108 | |
3091 | while (my ($k, $v) = each %{ $self->{item} }) { |
3109 | while (my ($k, $v) = each %{ $self->{item} }) { |
3092 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
3110 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
3093 | } |
3111 | } |
3094 | |
3112 | |
… | |
… | |
3097 | my @items = sort { |
3115 | my @items = sort { |
3098 | $a->{pri} <=> $b->{pri} |
3116 | $a->{pri} <=> $b->{pri} |
3099 | or $b->{id} <=> $a->{id} |
3117 | or $b->{id} <=> $a->{id} |
3100 | } values %{ $self->{item} }; |
3118 | } values %{ $self->{item} }; |
3101 | |
3119 | |
|
|
3120 | $self->{timer}->interval (1); |
|
|
3121 | |
3102 | my $count = 10 + 1; |
3122 | my $count = 10 + 1; |
3103 | for my $item (@items) { |
3123 | for my $item (@items) { |
3104 | last unless --$count; |
3124 | last unless --$count; |
3105 | |
3125 | |
3106 | push @widgets, $item->{label} ||= do { |
3126 | my $label = $item->{label} ||= do { |
3107 | # TODO: doesn't handle markup well (read as: at all) |
3127 | # TODO: doesn't handle markup well (read as: at all) |
3108 | my $short = $item->{count} > 1 |
3128 | my $short = $item->{count} > 1 |
3109 | ? "<b>$item->{count} ×</b> $item->{text}" |
3129 | ? "<b>$item->{count} ×</b> $item->{text}" |
3110 | : $item->{text}; |
3130 | : $item->{text}; |
3111 | |
3131 | |
… | |
… | |
3119 | tooltip => $item->{tooltip}, |
3139 | tooltip => $item->{tooltip}, |
3120 | tooltip_font => $::FONT_PROP, |
3140 | tooltip_font => $::FONT_PROP, |
3121 | tooltip_width => 0.67, |
3141 | tooltip_width => 0.67, |
3122 | fontsize => $item->{fontsize} || $self->{fontsize}, |
3142 | fontsize => $item->{fontsize} || $self->{fontsize}, |
3123 | max_w => $::WIDTH * 0.44, |
3143 | max_w => $::WIDTH * 0.44, |
3124 | fg => $item->{fg}, |
3144 | fg => [@{ $item->{fg} }], |
3125 | can_events => 1, |
3145 | can_events => 1, |
3126 | can_hover => 1 |
3146 | can_hover => 1 |
3127 | }; |
3147 | }; |
|
|
3148 | |
|
|
3149 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
|
|
3150 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
|
|
3151 | $label->update; |
|
|
3152 | $label->set_max_size (undef, $label->{req_h} * $diff) |
|
|
3153 | if $diff < 1; |
|
|
3154 | $self->{timer}->interval (1/30); |
|
|
3155 | } else { |
|
|
3156 | $label->{fg}[3] = $item->{fg}[3] || 1; |
|
|
3157 | } |
|
|
3158 | |
|
|
3159 | push @widgets, $label; |
3128 | } |
3160 | } |
3129 | |
3161 | |
3130 | $self->clear; |
3162 | $self->clear; |
3131 | $self->SUPER::add (reverse @widgets); |
3163 | $self->SUPER::add (reverse @widgets); |
3132 | } |
3164 | } |
… | |
… | |
3137 | $text =~ s/^\s+//; |
3169 | $text =~ s/^\s+//; |
3138 | $text =~ s/\s+$//; |
3170 | $text =~ s/\s+$//; |
3139 | |
3171 | |
3140 | return unless $text; |
3172 | return unless $text; |
3141 | |
3173 | |
3142 | my $timeout = time + ((delete $arg{timeout}) || 60); |
3174 | my $timeout = (int time) + ((delete $arg{timeout}) || 60); |
3143 | |
3175 | |
3144 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
3176 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
3145 | |
3177 | |
3146 | if (my $item = $self->{item}{$group}) { |
3178 | if (my $item = $self->{item}{$group}) { |
3147 | if ($item->{text} eq $text) { |
3179 | if ($item->{text} eq $text) { |
… | |
… | |
3177 | |
3209 | |
3178 | $self->reorder; |
3210 | $self->reorder; |
3179 | $self->SUPER::reconfigure; |
3211 | $self->SUPER::reconfigure; |
3180 | } |
3212 | } |
3181 | |
3213 | |
|
|
3214 | sub DESTROY { |
|
|
3215 | my ($self) = @_; |
|
|
3216 | |
|
|
3217 | $self->{timer}->cancel; |
|
|
3218 | |
|
|
3219 | $self->SUPER::DESTROY; |
|
|
3220 | } |
|
|
3221 | |
3182 | ############################################################################# |
3222 | ############################################################################# |
3183 | |
3223 | |
3184 | package CFClient::UI::Inventory; |
3224 | package CFClient::UI::Inventory; |
3185 | |
3225 | |
3186 | our @ISA = CFClient::UI::ScrolledWindow::; |
3226 | our @ISA = CFClient::UI::ScrolledWindow::; |
… | |
… | |
3478 | |
3518 | |
3479 | package CFClient::UI::Root; |
3519 | package CFClient::UI::Root; |
3480 | |
3520 | |
3481 | our @ISA = CFClient::UI::Container::; |
3521 | our @ISA = CFClient::UI::Container::; |
3482 | |
3522 | |
|
|
3523 | use List::Util qw(min max); |
|
|
3524 | |
3483 | use CFClient::OpenGL; |
3525 | use CFClient::OpenGL; |
3484 | |
3526 | |
3485 | sub new { |
3527 | sub new { |
3486 | my $class = shift; |
3528 | my $class = shift; |
3487 | |
3529 | |
… | |
… | |
3621 | |
3663 | |
3622 | delete $queue{$widget+0}; |
3664 | delete $queue{$widget+0}; |
3623 | |
3665 | |
3624 | my ($w, $h) = $widget->size_request; |
3666 | my ($w, $h) = $widget->size_request; |
3625 | |
3667 | |
3626 | $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
3668 | $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
3627 | $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
3669 | $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
|
|
3670 | |
|
|
3671 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
|
|
3672 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
3628 | |
3673 | |
3629 | $w = $widget->{force_w} if exists $widget->{force_w}; |
3674 | $w = $widget->{force_w} if exists $widget->{force_w}; |
3630 | $h = $widget->{force_h} if exists $widget->{force_h}; |
3675 | $h = $widget->{force_h} if exists $widget->{force_h}; |
3631 | |
3676 | |
3632 | if ($widget->{req_w} != $w || $widget->{req_h} != $h |
3677 | if ($widget->{req_w} != $w || $widget->{req_h} != $h |