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.239 by root, Thu May 25 22:29:57 2006 UTC vs.
Revision 1.242 by elmex, Sat May 27 20:00:40 2006 UTC

5 5
6use Scalar::Util (); 6use Scalar::Util ();
7use List::Util (); 7use List::Util ();
8 8
9use CFClient; 9use CFClient;
10use CFClient::Texture;
10 11
11our ($FOCUS, $HOVER, $GRAB); # various widgets 12our ($FOCUS, $HOVER, $GRAB); # various widgets
12 13
14our $LAYOUT;
13our $ROOT; 15our $ROOT;
14our $TOOLTIP; 16our $TOOLTIP;
15our $BUTTON_STATE; 17our $BUTTON_STATE;
16 18
17our %WIDGET; # all widgets, weak-referenced 19our %WIDGET; # all widgets, weak-referenced
20
21sub get_layout {
22 for (grep { $_->{name} } values %WIDGET) {
23 $LAYOUT->{$_->{name}} = {
24 x => $_->{x} / $::WIDTH,
25 y => $_->{y} / $::HEIGHT,
26 w => $_->{w} / $::WIDTH,
27 h => $_->{h} / $::HEIGHT
28 };
29 }
30
31 return $LAYOUT;
32}
33
34sub set_layout {
35 my ($layout) = @_;
36 $LAYOUT = $layout;
37}
18 38
19sub check_tooltip { 39sub check_tooltip {
20 if (!$GRAB) { 40 if (!$GRAB) {
21 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 41 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
22 if (length $widget->{tooltip}) { 42 if (length $widget->{tooltip}) {
193 } 213 }
194 } 214 }
195 215
196 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); 216 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self);
197 217
218 if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) {
219 $self->{user_x} = $layout->{x} * $::WIDTH;
220 $self->{user_y} = $layout->{y} * $::HEIGHT;
221 $self->{user_w} = ($layout->{w} != 0 ? $layout->{w} : 1) * $::WIDTH;
222 $self->{user_h} = ($layout->{h} != 0 ? $layout->{h} : 1) * $::HEIGHT;
223 }
224
198 $self 225 $self
199} 226}
200 227
201sub destroy { 228sub destroy {
202 my ($self) = @_; 229 my ($self) = @_;
228sub set_invisible { 255sub set_invisible {
229 my ($self) = @_; 256 my ($self) = @_;
230 257
231 # broken show/hide model 258 # broken show/hide model
232 259
260 delete $self->{root};
233 delete $self->{visible}; 261 delete $self->{visible};
234 262
235 undef $GRAB if $GRAB == $self; 263 undef $GRAB if $GRAB == $self;
236 undef $HOVER if $HOVER == $self; 264 undef $HOVER if $HOVER == $self;
237 265
459 my ($self, $parent) = @_; 487 my ($self, $parent) = @_;
460 488
461 Scalar::Util::weaken ($self->{parent} = $parent); 489 Scalar::Util::weaken ($self->{parent} = $parent);
462 490
463 $self->{root} = $parent->{root}; 491 $self->{root} = $parent->{root};
464 $self->{visible} = $parent->{visible}; 492 $self->{visible} = $parent->{visible} + 1;
465 493
466 # TODO: req_w _does_change after ->reconfigure 494 # TODO: req_w _does_change after ->reconfigure
467 $self->check_size 495 $self->check_size
468 unless exists $self->{req_w}; 496 unless exists $self->{req_w};
469 497
2963 2991
2964sub new { 2992sub new {
2965 my $class = shift; 2993 my $class = shift;
2966 2994
2967 $class->SUPER::new ( 2995 $class->SUPER::new (
2996 visible => 1,
2968 @_, 2997 @_,
2969 ) 2998 )
2970} 2999}
2971 3000
2972sub configure { 3001sub configure {
3030sub add { 3059sub add {
3031 my ($self, @children) = @_; 3060 my ($self, @children) = @_;
3032 3061
3033 for (my @widgets = @children; my $w = pop @widgets; ) { 3062 for (my @widgets = @children; my $w = pop @widgets; ) {
3034 push @widgets, $w->children; 3063 push @widgets, $w->children;
3035 $w->{root} = $self; 3064 $w->{root} = $self;
3036 $w->{visible} = 1; 3065 $w->{visible} = $self->{visible} + 1;
3037 } 3066 }
3038 3067
3039 for my $child (@children) { 3068 for my $child (@children) {
3040 $child->{is_toplevel} = 1; 3069 $child->{is_toplevel} = 1;
3041 3070

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines