… | |
… | |
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 | |
… | |
… | |
1638 | }; |
1637 | }; |
1639 | |
1638 | |
1640 | glEnable GL_TEXTURE_2D; |
1639 | glEnable GL_TEXTURE_2D; |
1641 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1640 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1642 | |
1641 | |
|
|
1642 | glColor_premultiply @{$self->{fg}} |
1643 | if ($tex->{format} == GL_ALPHA) { |
1643 | if $tex->{format} == GL_ALPHA; |
1644 | glColor @{$self->{fg}}; |
1644 | |
1645 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
|
|
1646 | } else { |
|
|
1647 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1645 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1648 | } |
|
|
1649 | |
1646 | |
1650 | glDisable GL_TEXTURE_2D; |
1647 | glDisable GL_TEXTURE_2D; |
1651 | } |
1648 | } |
1652 | |
1649 | |
1653 | ############################################################################# |
1650 | ############################################################################# |
… | |
… | |
1913 | } |
1910 | } |
1914 | |
1911 | |
1915 | sub _draw { |
1912 | sub _draw { |
1916 | my ($self) = @_; |
1913 | my ($self) = @_; |
1917 | |
1914 | |
1918 | local $self->{fg} = $self->{fg}; |
1915 | local $self->{fg} = $GRAB == $self ? $self->{active_fg} : $self->{fg}; |
1919 | |
|
|
1920 | if ($GRAB == $self) { |
|
|
1921 | $self->{fg} = $self->{active_fg}; |
|
|
1922 | } |
|
|
1923 | |
1916 | |
1924 | glEnable GL_TEXTURE_2D; |
1917 | glEnable GL_TEXTURE_2D; |
1925 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1918 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1926 | glColor 0, 0, 0, 1; |
1919 | glColor 0, 0, 0, 1; |
1927 | |
1920 | |
… | |
… | |
2575 | |
2568 | |
2576 | delete $self->{texture}; |
2569 | delete $self->{texture}; |
2577 | } |
2570 | } |
2578 | |
2571 | |
2579 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2572 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2580 | glClearColor 0.5, 0.5, 0.5, 0; |
2573 | glClearColor 0, 0, 0, 0; |
2581 | glClear GL_COLOR_BUFFER_BIT; |
2574 | glClear GL_COLOR_BUFFER_BIT; |
2582 | |
2575 | |
2583 | my $top = int $self->{children}[1]{range}[0]; |
2576 | my $top = int $self->{children}[1]{range}[0]; |
2584 | |
2577 | |
2585 | my $y0 = $top; |
2578 | my $y0 = $top; |
… | |
… | |
2620 | sub _draw { |
2613 | sub _draw { |
2621 | my ($self) = @_; |
2614 | my ($self) = @_; |
2622 | |
2615 | |
2623 | glEnable GL_TEXTURE_2D; |
2616 | glEnable GL_TEXTURE_2D; |
2624 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2617 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2625 | glColor 1, 1, 1, 1; |
2618 | glColor 0, 0, 0, 1; |
2626 | $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2619 | $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2627 | glDisable GL_TEXTURE_2D; |
2620 | glDisable GL_TEXTURE_2D; |
2628 | |
2621 | |
2629 | $self->{children}[1]->draw; |
2622 | $self->{children}[1]->draw; |
2630 | |
2623 | |
2631 | } |
2624 | } |
… | |
… | |
2858 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2851 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2859 | |
2852 | |
2860 | if ($tex) { |
2853 | if ($tex) { |
2861 | glEnable GL_TEXTURE_2D; |
2854 | glEnable GL_TEXTURE_2D; |
2862 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2855 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2863 | glColor 1, 1, 1, 1; |
2856 | glColor 0, 0, 0, 1; |
2864 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2857 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2865 | glDisable GL_TEXTURE_2D; |
2858 | glDisable GL_TEXTURE_2D; |
2866 | } |
2859 | } |
2867 | } |
2860 | } |
2868 | |
2861 | |
… | |
… | |
3076 | our @ISA = CFClient::UI::VBox::; |
3069 | our @ISA = CFClient::UI::VBox::; |
3077 | |
3070 | |
3078 | sub new { |
3071 | sub new { |
3079 | my $class = shift; |
3072 | my $class = shift; |
3080 | |
3073 | |
3081 | $class->SUPER::new ( |
3074 | my $self = $class->SUPER::new ( |
3082 | fontsize => 0.8, |
3075 | fontsize => 0.8, |
3083 | @_, |
3076 | @_, |
3084 | ) |
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 |
3085 | } |
3084 | } |
3086 | |
3085 | |
3087 | sub reorder { |
3086 | sub reorder { |
3088 | my ($self) = @_; |
3087 | my ($self) = @_; |
3089 | 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} }; |
3090 | |
3094 | |
3091 | while (my ($k, $v) = each %{ $self->{item} }) { |
3095 | while (my ($k, $v) = each %{ $self->{item} }) { |
3092 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
3096 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
3093 | } |
3097 | } |
3094 | |
3098 | |
… | |
… | |
3097 | my @items = sort { |
3101 | my @items = sort { |
3098 | $a->{pri} <=> $b->{pri} |
3102 | $a->{pri} <=> $b->{pri} |
3099 | or $b->{id} <=> $a->{id} |
3103 | or $b->{id} <=> $a->{id} |
3100 | } values %{ $self->{item} }; |
3104 | } values %{ $self->{item} }; |
3101 | |
3105 | |
|
|
3106 | $self->{timer}->interval (1); |
|
|
3107 | |
3102 | my $count = 10 + 1; |
3108 | my $count = 10 + 1; |
3103 | for my $item (@items) { |
3109 | for my $item (@items) { |
3104 | last unless --$count; |
3110 | last unless --$count; |
3105 | |
3111 | |
3106 | push @widgets, $item->{label} ||= do { |
3112 | my $label = $item->{label} ||= do { |
3107 | # TODO: doesn't handle markup well (read as: at all) |
3113 | # TODO: doesn't handle markup well (read as: at all) |
3108 | my $short = $item->{count} > 1 |
3114 | my $short = $item->{count} > 1 |
3109 | ? "<b>$item->{count} ×</b> $item->{text}" |
3115 | ? "<b>$item->{count} ×</b> $item->{text}" |
3110 | : $item->{text}; |
3116 | : $item->{text}; |
3111 | |
3117 | |
… | |
… | |
3119 | tooltip => $item->{tooltip}, |
3125 | tooltip => $item->{tooltip}, |
3120 | tooltip_font => $::FONT_PROP, |
3126 | tooltip_font => $::FONT_PROP, |
3121 | tooltip_width => 0.67, |
3127 | tooltip_width => 0.67, |
3122 | fontsize => $item->{fontsize} || $self->{fontsize}, |
3128 | fontsize => $item->{fontsize} || $self->{fontsize}, |
3123 | max_w => $::WIDTH * 0.44, |
3129 | max_w => $::WIDTH * 0.44, |
3124 | fg => $item->{fg}, |
3130 | fg => [@{ $item->{fg} }], |
3125 | can_events => 1, |
3131 | can_events => 1, |
3126 | can_hover => 1 |
3132 | can_hover => 1 |
3127 | }; |
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; |
3128 | } |
3146 | } |
3129 | |
3147 | |
3130 | $self->clear; |
3148 | $self->clear; |
3131 | $self->SUPER::add (reverse @widgets); |
3149 | $self->SUPER::add (reverse @widgets); |
3132 | } |
3150 | } |
… | |
… | |
3137 | $text =~ s/^\s+//; |
3155 | $text =~ s/^\s+//; |
3138 | $text =~ s/\s+$//; |
3156 | $text =~ s/\s+$//; |
3139 | |
3157 | |
3140 | return unless $text; |
3158 | return unless $text; |
3141 | |
3159 | |
3142 | my $timeout = time + ((delete $arg{timeout}) || 60); |
3160 | my $timeout = (int time) + ((delete $arg{timeout}) || 60); |
3143 | |
3161 | |
3144 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
3162 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
3145 | |
3163 | |
3146 | if (my $item = $self->{item}{$group}) { |
3164 | if (my $item = $self->{item}{$group}) { |
3147 | if ($item->{text} eq $text) { |
3165 | if ($item->{text} eq $text) { |
… | |
… | |
3177 | |
3195 | |
3178 | $self->reorder; |
3196 | $self->reorder; |
3179 | $self->SUPER::reconfigure; |
3197 | $self->SUPER::reconfigure; |
3180 | } |
3198 | } |
3181 | |
3199 | |
|
|
3200 | sub DESTROY { |
|
|
3201 | my ($self) = @_; |
|
|
3202 | |
|
|
3203 | $self->{timer}->cancel; |
|
|
3204 | |
|
|
3205 | $self->SUPER::DESTROY; |
|
|
3206 | } |
|
|
3207 | |
3182 | ############################################################################# |
3208 | ############################################################################# |
3183 | |
3209 | |
3184 | package CFClient::UI::Inventory; |
3210 | package CFClient::UI::Inventory; |
3185 | |
3211 | |
3186 | our @ISA = CFClient::UI::ScrolledWindow::; |
3212 | our @ISA = CFClient::UI::ScrolledWindow::; |
… | |
… | |
3478 | |
3504 | |
3479 | package CFClient::UI::Root; |
3505 | package CFClient::UI::Root; |
3480 | |
3506 | |
3481 | our @ISA = CFClient::UI::Container::; |
3507 | our @ISA = CFClient::UI::Container::; |
3482 | |
3508 | |
|
|
3509 | use List::Util qw(min max); |
|
|
3510 | |
3483 | use CFClient::OpenGL; |
3511 | use CFClient::OpenGL; |
3484 | |
3512 | |
3485 | sub new { |
3513 | sub new { |
3486 | my $class = shift; |
3514 | my $class = shift; |
3487 | |
3515 | |
… | |
… | |
3621 | |
3649 | |
3622 | delete $queue{$widget+0}; |
3650 | delete $queue{$widget+0}; |
3623 | |
3651 | |
3624 | my ($w, $h) = $widget->size_request; |
3652 | my ($w, $h) = $widget->size_request; |
3625 | |
3653 | |
3626 | $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
3654 | $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
3627 | $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}; |
3628 | |
3659 | |
3629 | $w = $widget->{force_w} if exists $widget->{force_w}; |
3660 | $w = $widget->{force_w} if exists $widget->{force_w}; |
3630 | $h = $widget->{force_h} if exists $widget->{force_h}; |
3661 | $h = $widget->{force_h} if exists $widget->{force_h}; |
3631 | |
3662 | |
3632 | if ($widget->{req_w} != $w || $widget->{req_h} != $h |
3663 | if ($widget->{req_w} != $w || $widget->{req_h} != $h |