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.200 by root, Sat May 13 00:27:09 2006 UTC vs.
Revision 1.202 by root, Sun May 14 20:51:19 2006 UTC

11our ($FOCUS, $HOVER, $GRAB); # various widgets 11our ($FOCUS, $HOVER, $GRAB); # various widgets
12 12
13our $ROOT; 13our $ROOT;
14our $TOOLTIP; 14our $TOOLTIP;
15our $BUTTON_STATE; 15our $BUTTON_STATE;
16
17our %WIDGET; # all widgets, weak-referenced
16 18
17sub check_tooltip { 19sub check_tooltip {
18 if (!$GRAB) { 20 if (!$GRAB) {
19 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 21 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
20 if (length $widget->{tooltip}) { 22 if (length $widget->{tooltip}) {
132 134
133 for (@$vals) { 135 for (@$vals) {
134 my $i = int $_ + $rem; 136 my $i = int $_ + $rem;
135 $rem += $_ - $i; 137 $rem += $_ - $i;
136 $_ = $i; 138 $_ = $i;
139 }
140}
141
142# call when resolution changes etc.
143sub rescale_widgets {
144 my ($sx, $sy) = @_;
145
146 for my $widget (values %WIDGET) {
147 if ($widget->{toplevel}) {
148 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x};
149 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
150 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w};
151 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w};
152 $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y};
153 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h};
154 $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h};
155 $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h};
156 }
157
158 $widget->reconfigure;
137 } 159 }
138} 160}
139 161
140############################################################################# 162#############################################################################
141 163
160 if (/^connect_(.*)$/) { 182 if (/^connect_(.*)$/) {
161 $self->connect ($1 => delete $self->{$_}); 183 $self->connect ($1 => delete $self->{$_});
162 } 184 }
163 } 185 }
164 186
187 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self);
188
165 $self 189 $self
166} 190}
167 191
168sub destroy { 192sub destroy {
169 my ($self) = @_; 193 my ($self) = @_;
175sub show { 199sub show {
176 my ($self) = @_; 200 my ($self) = @_;
177 201
178 return if $self->{parent}; 202 return if $self->{parent};
179 203
204 $self->{toplevel} = 1;
180 $CFClient::UI::ROOT->add ($self); 205 $CFClient::UI::ROOT->add ($self);
181} 206}
182 207
183sub hide { 208sub hide {
184 my ($self) = @_; 209 my ($self) = @_;
242 267
243sub size_allocate { 268sub size_allocate {
244 # nothing to be done 269 # nothing to be done
245} 270}
246 271
247sub children {
248}
249
250# call when resolution changes etc.
251sub reconfigure { 272sub reconfigure {
252 my ($self) = @_; 273 my ($self) = @_;
253
254 $_->reconfigure
255 for $self->children;
256 274
257 $self->check_size (1); 275 $self->check_size (1);
258 $self->update; 276 $self->update;
277}
278
279sub children {
259} 280}
260 281
261sub set_max_size { 282sub set_max_size {
262 my ($self, $w, $h) = @_; 283 my ($self, $w, $h) = @_;
263 284
417} 438}
418 439
419sub DESTROY { 440sub DESTROY {
420 my ($self) = @_; 441 my ($self) = @_;
421 442
443 delete $WIDGET{$self+0};
422 #$self->deactivate; 444 #$self->deactivate;
423} 445}
424 446
425############################################################################# 447#############################################################################
426 448
840 862
841 my $self = $class->SUPER::new ( 863 my $self = $class->SUPER::new (
842 bg => [1, 1, 1, 1], 864 bg => [1, 1, 1, 1],
843 border_bg => [1, 1, 1, 1], 865 border_bg => [1, 1, 1, 1],
844 border => 0.6, 866 border => 0.6,
867 toplevel => 1,
845 can_events => 1, 868 can_events => 1,
846 @_ 869 @_
847 ); 870 );
848 871
849 $self->{title} &&= new CFClient::UI::Label 872 $self->{title} &&= new CFClient::UI::Label
2538 my ($self, $items) = @_; 2561 my ($self, $items) = @_;
2539 2562
2540 $self->{scrolled}->clear; 2563 $self->{scrolled}->clear;
2541 return unless $items; 2564 return unless $items;
2542 2565
2543 my @items = sort { $a->{type} <=> $b->{type} } @$items; 2566 my @items = sort {
2567 ($a->{type} <=> $b->{type})
2568 or ($a->{name} cmp $b->{name})
2569 } @$items;
2544 2570
2545 $self->{real_items} = \@items; 2571 $self->{real_items} = \@items;
2546 2572
2547 for my $item (@items) { 2573 for my $item (@items) {
2548 my $desc = $item->{nrof} < 2 2574 my $desc = $item->{nrof} < 2
2549 ? $item->{name} 2575 ? $item->{name}
2550 : "$item->{nrof} $item->{name_pl}"; 2576 : "$item->{nrof} $item->{name_pl}";
2551 2577
2552 $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item); 2578 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2553 } 2579 }
2580
2581 $self->{scrolled}->add (@items);
2554 2582
2555# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2583# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2556} 2584}
2557 2585
2558sub size_request { 2586sub size_request {
2760} 2788}
2761 2789
2762sub size_allocate { 2790sub size_allocate {
2763 my ($self, $w, $h) = @_; 2791 my ($self, $w, $h) = @_;
2764 2792
2765 my $old_w = $self->{old_w}; 2793 my $old_w = $self->{old_w}; $self->{old_w} = $w;
2766 my $old_h = $self->{old_h}; 2794 my $old_h = $self->{old_h}; $self->{old_h} = $h;
2767 2795
2768 if ($old_w && $old_h) { 2796 CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h
2769 for my $child ($self->children) { 2797 if $old_w && $old_h && ($old_w != $w || $old_h != $h);
2770 $child->{x} = int 0.5 + $child->{x} * $w / $old_w;
2771 $child->{w} = int 0.5 + $child->{w} * $w / $old_w;
2772 $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w};
2773 $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w};
2774 $child->{y} = int 0.5 + $child->{y} * $h / $old_h;
2775 $child->{h} = int 0.5 + $child->{h} * $h / $old_h;
2776 $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h};
2777 $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h};
2778 }
2779 }
2780 2798
2781 for my $child ($self->children) { 2799 for my $child ($self->children) {
2782 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 2800 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2783 2801
2784 $X = List::Util::max 0, List::Util::min $w - $W, $X; 2802 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2785 $Y = List::Util::max 0, List::Util::min $h - $H, $Y; 2803 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2786 $child->configure ($X, $Y, $W, $H); 2804 $child->configure ($X, $Y, $W, $H);
2787 } 2805 }
2788
2789 $self->{old_w} = $w;
2790 $self->{old_h} = $h;
2791} 2806}
2792 2807
2793sub coord2local { 2808sub coord2local {
2794 my ($self, $x, $y) = @_; 2809 my ($self, $x, $y) = @_;
2795 2810

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines