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.278 by root, Sun Jun 4 23:05:06 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
389 $self->realloc;
388} 390}
389 391
390sub set_tooltip { 392sub 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
1543sub realloc {
1544 my ($self) = @_;
1545
1546 delete $self->{ox};
1547 delete $self->{req_h};
1548 $self->SUPER::realloc;
1549}
1550
1544sub set_text { 1551sub set_text {
1545 my ($self, $text) = @_; 1552 my ($self, $text) = @_;
1546 1553
1547 return if $self->{text} eq "T$text"; 1554 return if $self->{text} eq "T$text";
1548 $self->{text} = "T$text"; 1555 $self->{text} = "T$text";
1570} 1577}
1571 1578
1572sub size_request { 1579sub size_request {
1573 my ($self) = @_; 1580 my ($self) = @_;
1574 1581
1582 if (exists $self->{req_h}) {
1583 @$self{qw(req_w req_h)}
1584 } else {
1575 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1585 $self->{layout}->set_font ($self->{font}) if $self->{font};
1576 $self->{layout}->set_width ($self->{max_w} || -1); 1586 $self->{layout}->set_width ($self->{max_w} || -1);
1577 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1587 $self->{layout}->set_ellipsise ($self->{ellipsise});
1578 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1588 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1579 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1589 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1580 1590
1581 my ($w, $h) = $self->{layout}->size; 1591 my ($w, $h) = $self->{layout}->size;
1582 1592
1583 if (exists $self->{template}) { 1593 if (exists $self->{template}) {
1584 $self->{template}->set_font ($self->{font}) if $self->{font}; 1594 $self->{template}->set_font ($self->{font}) if $self->{font};
1585 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1595 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1586 1596
1587 my ($w2, $h2) = $self->{template}->size; 1597 my ($w2, $h2) = $self->{template}->size;
1588 1598
1589 $w = List::Util::max $w, $w2; 1599 $w = List::Util::max $w, $w2;
1590 $h = List::Util::max $h, $h2; 1600 $h = List::Util::max $h, $h2;
1591 } 1601 }
1592 1602
1593 ($w, $h) 1603 ($w, $h)
1604 }
1594} 1605}
1595 1606
1596sub size_allocate { 1607sub size_allocate {
1597 my ($self, $w, $h) = @_; 1608 my ($self, $w, $h) = @_;
1598 1609
1638 }; 1649 };
1639 1650
1640 glEnable GL_TEXTURE_2D; 1651 glEnable GL_TEXTURE_2D;
1641 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1652 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1642 1653
1654 glColor_premultiply @{$self->{fg}}
1643 if ($tex->{format} == GL_ALPHA) { 1655 if $tex->{format} == GL_ALPHA;
1644 glColor @{$self->{fg}}; 1656
1645 $tex->draw_quad_alpha ($self->{ox}, $self->{oy});
1646 } else {
1647 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); 1657 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy});
1648 }
1649 1658
1650 glDisable GL_TEXTURE_2D; 1659 glDisable GL_TEXTURE_2D;
1651} 1660}
1652 1661
1653############################################################################# 1662#############################################################################
1913} 1922}
1914 1923
1915sub _draw { 1924sub _draw {
1916 my ($self) = @_; 1925 my ($self) = @_;
1917 1926
1918 local $self->{fg} = $self->{fg}; 1927 local $self->{fg} = $GRAB == $self ? $self->{active_fg} : $self->{fg};
1919
1920 if ($GRAB == $self) {
1921 $self->{fg} = $self->{active_fg};
1922 }
1923 1928
1924 glEnable GL_TEXTURE_2D; 1929 glEnable GL_TEXTURE_2D;
1925 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1930 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1926 glColor 0, 0, 0, 1; 1931 glColor 0, 0, 0, 1;
1927 1932
2575 2580
2576 delete $self->{texture}; 2581 delete $self->{texture};
2577 } 2582 }
2578 2583
2579 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { 2584 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub {
2580 glClearColor 0.5, 0.5, 0.5, 0; 2585 glClearColor 0, 0, 0, 0;
2581 glClear GL_COLOR_BUFFER_BIT; 2586 glClear GL_COLOR_BUFFER_BIT;
2582 2587
2583 my $top = int $self->{children}[1]{range}[0]; 2588 my $top = int $self->{children}[1]{range}[0];
2584 2589
2585 my $y0 = $top; 2590 my $y0 = $top;
2620sub _draw { 2625sub _draw {
2621 my ($self) = @_; 2626 my ($self) = @_;
2622 2627
2623 glEnable GL_TEXTURE_2D; 2628 glEnable GL_TEXTURE_2D;
2624 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2629 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2625 glColor 1, 1, 1, 1; 2630 glColor 0, 0, 0, 1;
2626 $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2631 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2627 glDisable GL_TEXTURE_2D; 2632 glDisable GL_TEXTURE_2D;
2628 2633
2629 $self->{children}[1]->draw; 2634 $self->{children}[1]->draw;
2630 2635
2631} 2636}
2858 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; 2863 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]];
2859 2864
2860 if ($tex) { 2865 if ($tex) {
2861 glEnable GL_TEXTURE_2D; 2866 glEnable GL_TEXTURE_2D;
2862 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2867 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2863 glColor 1, 1, 1, 1; 2868 glColor 0, 0, 0, 1;
2864 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2869 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2865 glDisable GL_TEXTURE_2D; 2870 glDisable GL_TEXTURE_2D;
2866 } 2871 }
2867} 2872}
2868 2873
3076our @ISA = CFClient::UI::VBox::; 3081our @ISA = CFClient::UI::VBox::;
3077 3082
3078sub new { 3083sub new {
3079 my $class = shift; 3084 my $class = shift;
3080 3085
3081 $class->SUPER::new ( 3086 my $self = $class->SUPER::new (
3082 fontsize => 0.8, 3087 fontsize => 0.8,
3083 @_, 3088 @_,
3084 ) 3089 );
3090
3091 Scalar::Util::weaken (my $this = $self);
3092
3093 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder });
3094
3095 $self
3085} 3096}
3086 3097
3087sub reorder { 3098sub reorder {
3088 my ($self) = @_; 3099 my ($self) = @_;
3089 my $NOW = 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} };
3090 3106
3091 while (my ($k, $v) = each %{ $self->{item} }) { 3107 while (my ($k, $v) = each %{ $self->{item} }) {
3092 delete $self->{item}{$k} if $v->{timeout} < $NOW; 3108 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3093 } 3109 }
3094 3110
3097 my @items = sort { 3113 my @items = sort {
3098 $a->{pri} <=> $b->{pri} 3114 $a->{pri} <=> $b->{pri}
3099 or $b->{id} <=> $a->{id} 3115 or $b->{id} <=> $a->{id}
3100 } values %{ $self->{item} }; 3116 } values %{ $self->{item} };
3101 3117
3118 $self->{timer}->interval (1);
3119
3102 my $count = 10 + 1; 3120 my $count = 10 + 1;
3103 for my $item (@items) { 3121 for my $item (@items) {
3104 last unless --$count; 3122 last unless --$count;
3105 3123
3106 push @widgets, $item->{label} ||= do { 3124 my $label = $item->{label} ||= do {
3107 # TODO: doesn't handle markup well (read as: at all) 3125 # TODO: doesn't handle markup well (read as: at all)
3108 my $short = $item->{count} > 1 3126 my $short = $item->{count} > 1
3109 ? "<b>$item->{count} ×</b> $item->{text}" 3127 ? "<b>$item->{count} ×</b> $item->{text}"
3110 : $item->{text}; 3128 : $item->{text};
3111 3129
3119 tooltip => $item->{tooltip}, 3137 tooltip => $item->{tooltip},
3120 tooltip_font => $::FONT_PROP, 3138 tooltip_font => $::FONT_PROP,
3121 tooltip_width => 0.67, 3139 tooltip_width => 0.67,
3122 fontsize => $item->{fontsize} || $self->{fontsize}, 3140 fontsize => $item->{fontsize} || $self->{fontsize},
3123 max_w => $::WIDTH * 0.44, 3141 max_w => $::WIDTH * 0.44,
3124 fg => $item->{fg}, 3142 fg => [@{ $item->{fg} }],
3125 can_events => 1, 3143 can_events => 1,
3126 can_hover => 1 3144 can_hover => 1
3127 }; 3145 };
3146
3147 if ((my $diff = $item->{timeout} - $NOW) < 2) {
3148 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2;
3149 $label->update;
3150 $label->set_max_size (undef, $label->{req_h} * $diff)
3151 if $diff < 1;
3152 $self->{timer}->interval (1/30);
3153 } else {
3154 $label->{fg}[3] = $item->{fg}[3] || 1;
3155 }
3156
3157 push @widgets, $label;
3128 } 3158 }
3129 3159
3130 $self->clear; 3160 $self->clear;
3131 $self->SUPER::add (reverse @widgets); 3161 $self->SUPER::add (reverse @widgets);
3132} 3162}
3137 $text =~ s/^\s+//; 3167 $text =~ s/^\s+//;
3138 $text =~ s/\s+$//; 3168 $text =~ s/\s+$//;
3139 3169
3140 return unless $text; 3170 return unless $text;
3141 3171
3142 my $timeout = time + ((delete $arg{timeout}) || 60); 3172 my $timeout = (int time) + ((delete $arg{timeout}) || 60);
3143 3173
3144 my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; 3174 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
3145 3175
3146 if (my $item = $self->{item}{$group}) { 3176 if (my $item = $self->{item}{$group}) {
3147 if ($item->{text} eq $text) { 3177 if ($item->{text} eq $text) {
3177 3207
3178 $self->reorder; 3208 $self->reorder;
3179 $self->SUPER::reconfigure; 3209 $self->SUPER::reconfigure;
3180} 3210}
3181 3211
3212sub DESTROY {
3213 my ($self) = @_;
3214
3215 $self->{timer}->cancel;
3216
3217 $self->SUPER::DESTROY;
3218}
3219
3182############################################################################# 3220#############################################################################
3183 3221
3184package CFClient::UI::Inventory; 3222package CFClient::UI::Inventory;
3185 3223
3186our @ISA = CFClient::UI::ScrolledWindow::; 3224our @ISA = CFClient::UI::ScrolledWindow::;
3478 3516
3479package CFClient::UI::Root; 3517package CFClient::UI::Root;
3480 3518
3481our @ISA = CFClient::UI::Container::; 3519our @ISA = CFClient::UI::Container::;
3482 3520
3521use List::Util qw(min max);
3522
3483use CFClient::OpenGL; 3523use CFClient::OpenGL;
3484 3524
3485sub new { 3525sub new {
3486 my $class = shift; 3526 my $class = shift;
3487 3527
3621 3661
3622 delete $queue{$widget+0}; 3662 delete $queue{$widget+0};
3623 3663
3624 my ($w, $h) = $widget->size_request; 3664 my ($w, $h) = $widget->size_request;
3625 3665
3626 $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; 3666 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2;
3627 $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; 3667 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2;
3668
3669 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
3670 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
3628 3671
3629 $w = $widget->{force_w} if exists $widget->{force_w}; 3672 $w = $widget->{force_w} if exists $widget->{force_w};
3630 $h = $widget->{force_h} if exists $widget->{force_h}; 3673 $h = $widget->{force_h} if exists $widget->{force_h};
3631 3674
3632 if ($widget->{req_w} != $w || $widget->{req_h} != $h 3675 if ($widget->{req_w} != $w || $widget->{req_h} != $h

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines