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.251 by root, Sun May 28 22:24:24 2006 UTC vs.
Revision 1.255 by root, Mon May 29 02:01:56 2006 UTC

40 if (!$GRAB) { 40 if (!$GRAB) {
41 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 41 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
42 if (length $widget->{tooltip}) { 42 if (length $widget->{tooltip}) {
43 43
44 if ($TOOLTIP->{owner} != $widget) { 44 if ($TOOLTIP->{owner} != $widget) {
45 $TOOLTIP->hide;
46
45 $TOOLTIP->{owner} = $widget; 47 $TOOLTIP->{owner} = $widget;
46 48
47 my $tip = $widget->{tooltip}; 49 my $tip = $widget->{tooltip};
48 50
49 $tip = $tip->($widget) if CODE:: eq ref $tip; 51 $tip = $tip->($widget) if CODE:: eq ref $tip;
50 52
51 $TOOLTIP->set_tooltip_from ($widget); 53 $TOOLTIP->set_tooltip_from ($widget);
52 $TOOLTIP->show; 54 $TOOLTIP->show;
53
54 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
55
56 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0)
57 if $x + $TOOLTIP->{w} > $::WIDTH;
58
59 $TOOLTIP->move ($x, $y);
60 $TOOLTIP->realloc;
61 } 55 }
62 56
63 return; 57 return;
64 } 58 }
65 } 59 }
257 $self->{root} = $self->{parent}{root}; 251 $self->{root} = $self->{parent}{root};
258 $self->{visible} = $self->{parent}{visible} + 1; 252 $self->{visible} = $self->{parent}{visible} + 1;
259 253
260 $self->emit (visibility_change => 1); 254 $self->emit (visibility_change => 1);
261 255
262 $self->realloc unless exists $self->{req_w}; 256 $self->realloc if !exists $self->{req_w};
263 257
264 $_->set_visible for $self->children; 258 $_->set_visible for $self->children;
265} 259}
266 260
267sub set_invisible { 261sub set_invisible {
469 my ($self, $parent) = @_; 463 my ($self, $parent) = @_;
470 464
471 Scalar::Util::weaken ($self->{parent} = $parent); 465 Scalar::Util::weaken ($self->{parent} = $parent);
472 466
473 $self->set_visible if $parent->{visible}; 467 $self->set_visible if $parent->{visible};
474
475 $self->realloc;
476} 468}
477 469
478sub connect { 470sub connect {
479 my ($self, $signal, $cb) = @_; 471 my ($self, $signal, $cb) = @_;
480 472
499} 491}
500 492
501sub realloc { 493sub realloc {
502 my ($self) = @_; 494 my ($self) = @_;
503 495
504 return unless $self->{visible}; 496 if ($self->{visible}) {
505
506 return if $self->{root}{realloc}{$self}; 497 return if $self->{root}{realloc}{$self};
507 498
508 $self->{root}{realloc}{$self} = $self; 499 $self->{root}{realloc}{$self} = $self;
509 $self->{root}->update; 500 $self->{root}->update;
501 } else {
502 delete $self->{req_w};
503 }
510} 504}
511 505
512sub update { 506sub update {
513 my ($self) = @_; 507 my ($self) = @_;
514 508
1006 1000
1007our @ISA = CFClient::UI::Bin::; 1001our @ISA = CFClient::UI::Bin::;
1008 1002
1009use CFClient::OpenGL; 1003use CFClient::OpenGL;
1010 1004
1011my @tex = 1005my $bg =
1006 new_from_file CFClient::Texture CFClient::find_rcfile "d1_bg.png",
1007 mipmap => 1, wrap => 1;
1008
1009my @border =
1012 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1010 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1013 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1011 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1014 1012
1015sub new { 1013sub new {
1016 my $class = shift; 1014 my $class = shift;
1017 1015
1018 my $self = $class->SUPER::new ( 1016 my $self = $class->SUPER::new (
1133 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1131 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1134 1132
1135 my $border = $self->border; 1133 my $border = $self->border;
1136 1134
1137 glColor @{ $self->{border_bg} }; 1135 glColor @{ $self->{border_bg} };
1138 $tex[1]->draw_quad_alpha (0, 0, $w, $border); 1136 $border[0]->draw_quad_alpha (0, 0, $w, $border);
1139 $tex[3]->draw_quad_alpha (0, $border, $border, $ch); 1137 $border[1]->draw_quad_alpha (0, $border, $border, $ch);
1140 $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); 1138 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
1141 $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border); 1139 $border[3]->draw_quad_alpha (0, $h - $border, $w, $border);
1142 1140
1143 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 1141 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
1144 my $bg = $tex[0]; 1142 glColor @{ $self->{bg} };
1145 1143
1146 # TODO: repeat texture not scale 1144 # TODO: repeat texture not scale
1145 # solve this better(?)
1147 my $rep_x = $cw / $bg->{w}; 1146 $bg->{s} = $cw / $bg->{w};
1148 my $rep_y = $ch / $bg->{h}; 1147 $bg->{t} = $ch / $bg->{h};
1149
1150 glColor @{ $self->{bg} };
1151
1152 $bg->{s} = $rep_x;
1153 $bg->{t} = $rep_y;
1154 $bg->{wrap_mode} = 1;
1155 $bg->draw_quad_alpha ($border, $border, $cw, $ch); 1148 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
1156 } 1149 }
1157 1150
1158 glDisable GL_TEXTURE_2D; 1151 glDisable GL_TEXTURE_2D;
1159 1152
1469 1462
1470 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; 1463 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
1471 $self->{layout}->set_text ($text); 1464 $self->{layout}->set_text ($text);
1472 1465
1473 $self->realloc; 1466 $self->realloc;
1467 $self->update;
1474} 1468}
1475 1469
1476sub set_markup { 1470sub set_markup {
1477 my ($self, $markup) = @_; 1471 my ($self, $markup) = @_;
1478 1472
1483 1477
1484 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; 1478 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1485 $self->{layout}->set_markup ($markup); 1479 $self->{layout}->set_markup ($markup);
1486 1480
1487 $self->realloc; 1481 $self->realloc;
1482 $self->update;
1488} 1483}
1489 1484
1490sub size_request { 1485sub size_request {
1491 my ($self) = @_; 1486 my ($self) = @_;
1492 1487
2640 return unless $changed; 2635 return unless $changed;
2641 2636
2642 $self->SUPER::size_allocate ($w - 4, $h - 4, $changed); 2637 $self->SUPER::size_allocate ($w - 4, $h - 4, $changed);
2643} 2638}
2644 2639
2640sub visibility_change {
2641 my ($self, $visible) = @_;
2642
2643 return unless $visible;
2644
2645 $self->{root}->on_post_alloc ("move_$self" => sub {
2646 my $widget = $self->{owner}
2647 or return;
2648
2649 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2650
2651 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2652 if $x + $self->{w} > $::WIDTH;
2653
2654 $self->move ($x, $y);
2655 });
2656}
2657
2645sub _draw { 2658sub _draw {
2646 my ($self) = @_; 2659 my ($self) = @_;
2647 2660
2648 glTranslate 0.375, 0.375; 2661 glTranslate 0.375, 0.375;
2649 2662
2664 glVertex $w, $h; 2677 glVertex $w, $h;
2665 glVertex $w, 0; 2678 glVertex $w, 0;
2666 glEnd; 2679 glEnd;
2667 2680
2668 glTranslate 2 - 0.375, 2 - 0.375; 2681 glTranslate 2 - 0.375, 2 - 0.375;
2682
2669 $self->SUPER::_draw; 2683 $self->SUPER::_draw;
2670} 2684}
2671 2685
2672############################################################################# 2686#############################################################################
2673 2687
3123 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# 3137 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
3124 3138
3125 $widget->{req_w} = $w; 3139 $widget->{req_w} = $w;
3126 $widget->{req_h} = $h; 3140 $widget->{req_h} = $h;
3127 3141
3128 $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; 3142 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h];
3129 3143
3130 push @queue, $widget->{parent} 3144 push @queue, $widget->{parent}
3131 if $widget->{parent}; 3145 if $widget->{parent};
3132 } 3146 }
3133 } 3147 }
3140 my ($widget, $w, $h) = @{ pop @queue or last }; 3154 my ($widget, $w, $h) = @{ pop @queue or last };
3141 3155
3142 $w = 0 if $w < 0; 3156 $w = 0 if $w < 0;
3143 $h = 0 if $h < 0; 3157 $h = 0 if $h < 0;
3144 3158
3159 my $changed = $widget->{w} != $w || $widget->{h} != $h;
3160
3145 $widget->{w} = $w; 3161 $widget->{w} = $w;
3146 $widget->{h} = $h; 3162 $widget->{h} = $h;
3163
3147 $widget->emit (size_allocate => $w, $h, 1); 3164 $widget->emit (size_allocate => $w, $h, $changed);
3148 } 3165 }
3149 } 3166 }
3150 3167
3151 while ($self->{post_alloc_hook}) { 3168 while ($self->{post_alloc_hook}) {
3152 $_->() 3169 $_->()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines