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.235 by root, Thu May 25 16:35:42 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
458sub set_parent { 486sub set_parent {
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
491 $self->{root} = $parent->{root};
492 $self->{visible} = $parent->{visible} + 1;
493
463 # TODO: req_w _does_change after ->reconfigure 494 # TODO: req_w _does_change after ->reconfigure
464 $self->check_size 495 $self->check_size
465 unless exists $self->{req_w}; 496 unless exists $self->{req_w};
466 497
467 $self->show; 498 $self->show;
618 delete $child->{parent}; 649 delete $child->{parent};
619 $child->hide; 650 $child->hide;
620 651
621 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 652 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
622 653
623 $self->check_size; 654 $self->check_size (1);
624 $self->update; 655 $self->update;
625} 656}
626 657
627sub clear { 658sub clear {
628 my ($self) = @_; 659 my ($self) = @_;
871 $self->{vp}->add ($self->{scrolled}); 902 $self->{vp}->add ($self->{scrolled});
872 $self->add ($self->{vp}); 903 $self->add ($self->{vp});
873 $self->add ($self->{slider}); 904 $self->add ($self->{slider});
874 905
875 $self 906 $self
907}
908
909sub update {
910 my ($self) = @_;
911
912 $self->SUPER::update;
913
914 # todo: overwrite size_allocate of child
915 my $child = $self->{vp}->child;
916 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
876} 917}
877 918
878sub size_allocate { 919sub size_allocate {
879 my ($self, $w, $h) = @_; 920 my ($self, $w, $h) = @_;
880 921
1101 col_expand => [], 1142 col_expand => [],
1102 @_, 1143 @_,
1103 ) 1144 )
1104} 1145}
1105 1146
1147sub children {
1148 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1149}
1150
1106sub add { 1151sub add {
1107 my ($self, $x, $y, $child) = @_; 1152 my ($self, $x, $y, $child) = @_;
1108 1153
1109 $child->set_parent ($self); 1154 $child->set_parent ($self);
1110 $self->{children}[$y][$x] = $child; 1155 $self->{children}[$y][$x] = $child;
1111 1156
1112 $child->check_size; 1157 $self->check_size (1);
1113} 1158}
1114 1159
1115sub children {
1116 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1117}
1118
1119# TODO: move to container class maybe? send childs a signal on removal? 1160# TODO: move to container class maybe? send children a signal on removal?
1120sub clear { 1161sub clear {
1121 my ($self) = @_; 1162 my ($self) = @_;
1122 1163
1123 my @children = $self->children; 1164 my @children = $self->children;
1124 delete $self->{children}; 1165 delete $self->{children};
1126 for (@children) { 1167 for (@children) {
1127 delete $_->{parent}; 1168 delete $_->{parent};
1128 $_->hide; 1169 $_->hide;
1129 } 1170 }
1130 1171
1172 $self->check_size (1);
1131 $self->update; 1173 $self->update;
1132} 1174}
1133 1175
1134sub get_wh { 1176sub get_wh {
1135 my ($self) = @_; 1177 my ($self) = @_;
1167sub size_allocate { 1209sub size_allocate {
1168 my ($self, $w, $h) = @_; 1210 my ($self, $w, $h) = @_;
1169 1211
1170 my ($ws, $hs) = $self->get_wh; 1212 my ($ws, $hs) = $self->get_wh;
1171 1213
1172 my $req_w = sum @$ws; 1214 my $req_w = (sum @$ws) || 1;
1173 my $req_h = sum @$hs; 1215 my $req_h = (sum @$hs) || 1;
1174 1216
1175 # TODO: nicer code && do row_expand 1217 # TODO: nicer code && do row_expand
1176 my @col_expand = @{$self->{col_expand}}; 1218 my @col_expand = @{$self->{col_expand}};
1177 @col_expand = (1) x @$ws unless @col_expand; 1219 @col_expand = (1) x @$ws unless @col_expand;
1178 my $col_expand = (sum @col_expand) || 1; 1220 my $col_expand = (sum @col_expand) || 1;
2132} 2174}
2133 2175
2134sub set_range { 2176sub set_range {
2135 my ($self, $range) = @_; 2177 my ($self, $range) = @_;
2136 2178
2137 $self->{range} = $range; 2179 ($range, $self->{range}) = ($self->{range}, $range);
2138 2180
2139 $self->update; 2181 $self->update
2182 if "@$range" ne "@{$self->{range}}";
2140} 2183}
2141 2184
2142sub set_value { 2185sub set_value {
2143 my ($self, $value) = @_; 2186 my ($self, $value) = @_;
2144 2187
2747 $self->{scrolled}->add (1, $row, $item->{desc_widget}); 2790 $self->{scrolled}->add (1, $row, $item->{desc_widget});
2748 $self->{scrolled}->add (2, $row, $item->{weight_widget}); 2791 $self->{scrolled}->add (2, $row, $item->{weight_widget});
2749 2792
2750 $row++; 2793 $row++;
2751 } 2794 }
2752
2753# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2754} 2795}
2755 2796
2756sub size_request { 2797sub size_request {
2757 my ($self) = @_; 2798 my ($self) = @_;
2758 ($self->{req_w}, $self->{req_h}); 2799 ($self->{req_w}, $self->{req_h});
2950 2991
2951sub new { 2992sub new {
2952 my $class = shift; 2993 my $class = shift;
2953 2994
2954 $class->SUPER::new ( 2995 $class->SUPER::new (
2996 visible => 1,
2955 @_, 2997 @_,
2956 ) 2998 )
2957} 2999}
2958 3000
2959sub configure { 3001sub configure {
3017sub add { 3059sub add {
3018 my ($self, @children) = @_; 3060 my ($self, @children) = @_;
3019 3061
3020 for (my @widgets = @children; my $w = pop @widgets; ) { 3062 for (my @widgets = @children; my $w = pop @widgets; ) {
3021 push @widgets, $w->children; 3063 push @widgets, $w->children;
3022 $w->{root} = $self; 3064 $w->{root} = $self;
3023 $w->{visible} = 1; 3065 $w->{visible} = $self->{visible} + 1;
3024 } 3066 }
3025 3067
3026 for my $child (@children) { 3068 for my $child (@children) {
3027 $child->{is_toplevel} = 1; 3069 $child->{is_toplevel} = 1;
3028 3070

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines