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.199 by root, Fri May 12 15:45:42 2006 UTC vs.
Revision 1.203 by root, Sun May 14 21:13:11 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) = @_;
242 266
243sub size_allocate { 267sub size_allocate {
244 # nothing to be done 268 # nothing to be done
245} 269}
246 270
247sub children {
248}
249
250# call when resolution changes etc.
251sub reconfigure { 271sub reconfigure {
252 my ($self) = @_; 272 my ($self) = @_;
253
254 $_->reconfigure
255 for $self->children;
256 273
257 $self->check_size (1); 274 $self->check_size (1);
258 $self->update; 275 $self->update;
276}
277
278sub children {
259} 279}
260 280
261sub set_max_size { 281sub set_max_size {
262 my ($self, $w, $h) = @_; 282 my ($self, $w, $h) = @_;
263 283
417} 437}
418 438
419sub DESTROY { 439sub DESTROY {
420 my ($self) = @_; 440 my ($self) = @_;
421 441
442 delete $WIDGET{$self+0};
422 #$self->deactivate; 443 #$self->deactivate;
423} 444}
424 445
425############################################################################# 446#############################################################################
426 447
840 861
841 my $self = $class->SUPER::new ( 862 my $self = $class->SUPER::new (
842 bg => [1, 1, 1, 1], 863 bg => [1, 1, 1, 1],
843 border_bg => [1, 1, 1, 1], 864 border_bg => [1, 1, 1, 1],
844 border => 0.6, 865 border => 0.6,
866 toplevel => 1,
845 can_events => 1, 867 can_events => 1,
846 @_ 868 @_
847 ); 869 );
848 870
849 $self->{title} &&= new CFClient::UI::Label 871 $self->{title} &&= new CFClient::UI::Label
1480 my $sym = $ev->{sym}; 1502 my $sym = $ev->{sym};
1481 my $uni = $ev->{unicode}; 1503 my $uni = $ev->{unicode};
1482 1504
1483 my $text = $self->get_text; 1505 my $text = $self->get_text;
1484 1506
1485 if ($sym == 8) { 1507 if ($uni == 8) {
1486 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1508 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1487 } elsif ($sym == 127) { 1509 } elsif ($uni == 127) {
1488 substr $text, $self->{cursor}, 1, ""; 1510 substr $text, $self->{cursor}, 1, "";
1489 } elsif ($sym == CFClient::SDLK_LEFT) { 1511 } elsif ($sym == CFClient::SDLK_LEFT) {
1490 --$self->{cursor} if $self->{cursor}; 1512 --$self->{cursor} if $self->{cursor};
1491 } elsif ($sym == CFClient::SDLK_RIGHT) { 1513 } elsif ($sym == CFClient::SDLK_RIGHT) {
1492 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1514 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1493 } elsif ($sym == CFClient::SDLK_HOME) { 1515 } elsif ($sym == CFClient::SDLK_HOME) {
1494 $self->{cursor} = 0; 1516 $self->{cursor} = 0;
1495 } elsif ($sym == CFClient::SDLK_END) { 1517 } elsif ($sym == CFClient::SDLK_END) {
1496 $self->{cursor} = length $text; 1518 $self->{cursor} = length $text;
1497 } elsif ($sym == 27) { 1519 } elsif ($uni == 27) {
1498 $self->emit ('escape'); 1520 $self->emit ('escape');
1499 } elsif ($uni) { 1521 } elsif ($uni) {
1500 substr $text, $self->{cursor}++, 0, chr $uni; 1522 substr $text, $self->{cursor}++, 0, chr $uni;
1501 } 1523 }
1502 1524
2538 my ($self, $items) = @_; 2560 my ($self, $items) = @_;
2539 2561
2540 $self->{scrolled}->clear; 2562 $self->{scrolled}->clear;
2541 return unless $items; 2563 return unless $items;
2542 2564
2543 my @items = sort { $a->{type} <=> $b->{type} } @$items; 2565 my @items = sort {
2566 ($a->{type} <=> $b->{type})
2567 or ($a->{name} cmp $b->{name})
2568 } @$items;
2544 2569
2545 $self->{real_items} = \@items; 2570 $self->{real_items} = \@items;
2546 2571
2547 for my $item (@items) { 2572 for my $item (@items) {
2548 my $desc = $item->{nrof} < 2 2573 my $desc = $item->{nrof} < 2
2549 ? $item->{name} 2574 ? $item->{name}
2550 : "$item->{nrof} $item->{name_pl}"; 2575 : "$item->{nrof} $item->{name_pl}";
2551 2576
2552 $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item); 2577 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2553 } 2578 }
2579
2580 $self->{scrolled}->add (@items);
2554 2581
2555# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2582# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2556} 2583}
2557 2584
2558sub size_request { 2585sub size_request {
2760} 2787}
2761 2788
2762sub size_allocate { 2789sub size_allocate {
2763 my ($self, $w, $h) = @_; 2790 my ($self, $w, $h) = @_;
2764 2791
2765 my $old_w = $self->{old_w}; 2792 my $old_w = $self->{old_w}; $self->{old_w} = $w;
2766 my $old_h = $self->{old_h}; 2793 my $old_h = $self->{old_h}; $self->{old_h} = $h;
2767 2794
2768 if ($old_w && $old_h) { 2795 CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h
2769 for my $child ($self->children) { 2796 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 2797
2781 for my $child ($self->children) { 2798 for my $child ($self->children) {
2782 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 2799 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2783 2800
2784 $X = List::Util::max 0, List::Util::min $w - $W, $X; 2801 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2785 $Y = List::Util::max 0, List::Util::min $h - $H, $Y; 2802 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2786 $child->configure ($X, $Y, $W, $H); 2803 $child->configure ($X, $Y, $W, $H);
2787 } 2804 }
2788
2789 $self->{old_w} = $w;
2790 $self->{old_h} = $h;
2791} 2805}
2792 2806
2793sub coord2local { 2807sub coord2local {
2794 my ($self, $x, $y) = @_; 2808 my ($self, $x, $y) = @_;
2795 2809
2808 $self->check_size; 2822 $self->check_size;
2809 $::WANT_REFRESH++; 2823 $::WANT_REFRESH++;
2810} 2824}
2811 2825
2812sub add { 2826sub add {
2813 my ($self, $child) = @_; 2827 my ($self, @children) = @_;
2814 2828
2829 for my $child (@children) {
2830 $child->{toplevel} = 1;
2831
2815 # integerise window positions 2832 # integerise window positions
2816 $child->{x} = int $child->{x}; 2833 $child->{x} = int $child->{x};
2817 $child->{y} = int $child->{y}; 2834 $child->{y} = int $child->{y};
2835 }
2818 2836
2819 $self->SUPER::add ($child); 2837 $self->SUPER::add (@children);
2820} 2838}
2821 2839
2822sub on_refresh { 2840sub on_refresh {
2823 my ($self, $id, $cb) = @_; 2841 my ($self, $id, $cb) = @_;
2824 2842

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines