… | |
… | |
17 | our $BUTTON_STATE; |
17 | our $BUTTON_STATE; |
18 | |
18 | |
19 | our %WIDGET; # all widgets, weak-referenced |
19 | our %WIDGET; # all widgets, weak-referenced |
20 | |
20 | |
21 | sub get_layout { |
21 | sub get_layout { |
|
|
22 | my $layout; |
|
|
23 | |
22 | for (grep { $_->{name} } values %WIDGET) { |
24 | for (grep { $_->{name} } values %WIDGET) { |
23 | $LAYOUT->{$_->{name}} = { |
25 | my $win = $layout->{$_->{name}} = { }; |
24 | x => $_->{x} / $::WIDTH, |
|
|
25 | y => $_->{y} / $::HEIGHT, |
|
|
26 | w => $_->{w} / $::WIDTH, |
|
|
27 | h => $_->{h} / $::HEIGHT |
|
|
28 | }; |
26 | |
|
|
27 | $win->{x} = ($_->{x} + $_->{w} * 0.5) / $::WIDTH if $_->{x} =~ /^[0-9.]+$/; |
|
|
28 | $win->{y} = ($_->{y} + $_->{h} * 0.5) / $::HEIGHT if $_->{y} =~ /^[0-9.]+$/; |
|
|
29 | $win->{w} = $_->{w} / $::WIDTH if defined $_->{w}; |
|
|
30 | $win->{h} = $_->{h} / $::HEIGHT if defined $_->{h}; |
29 | } |
31 | } |
30 | |
32 | |
31 | return $LAYOUT; |
33 | $layout |
32 | } |
34 | } |
33 | |
35 | |
34 | sub set_layout { |
36 | sub set_layout { |
35 | my ($layout) = @_; |
37 | my ($layout) = @_; |
36 | $LAYOUT = $layout; |
38 | $LAYOUT = $layout; |
… | |
… | |
40 | if (!$GRAB) { |
42 | if (!$GRAB) { |
41 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
43 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
42 | if (length $widget->{tooltip}) { |
44 | if (length $widget->{tooltip}) { |
43 | |
45 | |
44 | if ($TOOLTIP->{owner} != $widget) { |
46 | if ($TOOLTIP->{owner} != $widget) { |
|
|
47 | $TOOLTIP->hide; |
|
|
48 | |
45 | $TOOLTIP->{owner} = $widget; |
49 | $TOOLTIP->{owner} = $widget; |
46 | |
50 | |
47 | my $tip = $widget->{tooltip}; |
51 | my $tip = $widget->{tooltip}; |
48 | |
52 | |
49 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
53 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
50 | |
54 | |
51 | $TOOLTIP->set_tooltip_from ($widget); |
55 | $TOOLTIP->set_tooltip_from ($widget); |
52 | $TOOLTIP->show; |
56 | $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 | } |
57 | } |
62 | |
58 | |
63 | return; |
59 | return; |
64 | } |
60 | } |
65 | } |
61 | } |
… | |
… | |
171 | sub rescale_widgets { |
167 | sub rescale_widgets { |
172 | my ($sx, $sy) = @_; |
168 | my ($sx, $sy) = @_; |
173 | |
169 | |
174 | for my $widget (values %WIDGET) { |
170 | for my $widget (values %WIDGET) { |
175 | if ($widget->{is_toplevel}) { |
171 | if ($widget->{is_toplevel}) { |
|
|
172 | $widget->{x} += $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
|
|
173 | $widget->{y} += $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
|
|
174 | |
176 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
175 | $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; |
177 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
176 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
178 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
177 | $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w}; |
179 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
178 | $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/; |
180 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
179 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
181 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
180 | $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h}; |
|
|
181 | |
|
|
182 | $widget->{x} -= $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
|
|
183 | $widget->{y} -= $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
|
|
184 | |
182 | } |
185 | } |
183 | } |
186 | } |
184 | |
187 | |
185 | reconfigure_widgets; |
188 | reconfigure_widgets; |
186 | } |
189 | } |
… | |
… | |
195 | |
198 | |
196 | sub new { |
199 | sub new { |
197 | my $class = shift; |
200 | my $class = shift; |
198 | |
201 | |
199 | my $self = bless { |
202 | my $self = bless { |
200 | x => 0, |
203 | x => "center", |
201 | y => 0, |
204 | y => "center", |
202 | z => 0, |
205 | z => 0, |
|
|
206 | w => undef, |
|
|
207 | h => undef, |
203 | can_events => 1, |
208 | can_events => 1, |
204 | @_ |
209 | @_ |
205 | }, $class; |
210 | }, $class; |
|
|
211 | |
|
|
212 | if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { |
|
|
213 | $self->{x} = $layout->{x} * $CFClient::UI::ROOT->{w} if exists $layout->{x}; |
|
|
214 | $self->{y} = $layout->{y} * $CFClient::UI::ROOT->{h} if exists $layout->{y}; |
|
|
215 | $self->{force_w} = $layout->{w} * $CFClient::UI::ROOT->{w} if exists $layout->{w}; |
|
|
216 | $self->{force_h} = $layout->{h} * $CFClient::UI::ROOT->{h} if exists $layout->{h}; |
|
|
217 | |
|
|
218 | $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; |
|
|
219 | $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; |
|
|
220 | } |
|
|
221 | |
|
|
222 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
206 | |
223 | |
207 | for (keys %$self) { |
224 | for (keys %$self) { |
208 | if (/^on_(.*)$/) { |
225 | if (/^on_(.*)$/) { |
209 | $self->connect ($1 => delete $self->{$_}); |
226 | $self->connect ($1 => delete $self->{$_}); |
210 | } |
227 | } |
211 | } |
228 | } |
212 | |
229 | |
213 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
|
|
214 | |
|
|
215 | if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { |
|
|
216 | $self->{req_x} = $layout->{x} * $::WIDTH; |
|
|
217 | $self->{req_y} = $layout->{y} * $::HEIGHT; |
|
|
218 | $self->{def_w} = ($layout->{w} != 0 ? $layout->{w} : 1) * $::WIDTH; |
|
|
219 | $self->{def_h} = ($layout->{h} != 0 ? $layout->{h} : 1) * $::HEIGHT; |
|
|
220 | } |
|
|
221 | |
|
|
222 | $self |
230 | $self |
223 | } |
231 | } |
224 | |
232 | |
225 | sub destroy { |
233 | sub destroy { |
226 | my ($self) = @_; |
234 | my ($self) = @_; |
… | |
… | |
235 | return if $self->{parent}; |
243 | return if $self->{parent}; |
236 | |
244 | |
237 | $CFClient::UI::ROOT->add ($self); |
245 | $CFClient::UI::ROOT->add ($self); |
238 | } |
246 | } |
239 | |
247 | |
240 | sub center { |
|
|
241 | my ($self) = @_; |
|
|
242 | |
|
|
243 | $CFClient::UI::ROOT->on_post_alloc ( |
|
|
244 | "center_$self" => sub { |
|
|
245 | $self->move (($self->{parent}{w} - $self->{w}) * 0.5, ($self->{parent}{h} - $self->{h}) * 0.5); |
|
|
246 | }, |
|
|
247 | ); |
|
|
248 | |
|
|
249 | $self->update; |
|
|
250 | } |
|
|
251 | |
|
|
252 | sub set_visible { |
248 | sub set_visible { |
253 | my ($self) = @_; |
249 | my ($self) = @_; |
254 | |
250 | |
255 | return if $self->{visible}; |
251 | return if $self->{visible}; |
256 | |
252 | |
257 | $self->{root} = $self->{parent}{root}; |
253 | $self->{root} = $self->{parent}{root}; |
258 | $self->{visible} = $self->{parent}{visible} + 1; |
254 | $self->{visible} = $self->{parent}{visible} + 1; |
259 | |
255 | |
260 | $self->emit (visibility_change => 1); |
256 | $self->emit (visibility_change => 1); |
261 | |
257 | |
262 | $self->realloc unless exists $self->{req_w}; |
258 | $self->realloc if !exists $self->{req_w}; |
263 | |
259 | |
264 | $_->set_visible for $self->children; |
260 | $_->set_visible for $self->children; |
265 | } |
261 | } |
266 | |
262 | |
267 | sub set_invisible { |
263 | sub set_invisible { |
… | |
… | |
309 | |
305 | |
310 | $self->{parent}->remove ($self) |
306 | $self->{parent}->remove ($self) |
311 | if $self->{parent}; |
307 | if $self->{parent}; |
312 | } |
308 | } |
313 | |
309 | |
314 | sub move { |
310 | sub move_abs { |
315 | my ($self, $x, $y, $z) = @_; |
311 | my ($self, $x, $y, $z) = @_; |
316 | |
312 | |
317 | $self->{x} = int $x; |
313 | $self->{x} = List::Util::max 0, int $x; |
318 | $self->{y} = int $y; |
314 | $self->{y} = List::Util::max 0, int $y; |
319 | $self->{z} = $z if defined $z; |
315 | $self->{z} = $z if defined $z; |
320 | |
316 | |
321 | $self->update; |
317 | $self->update; |
322 | } |
318 | } |
323 | |
319 | |
324 | sub set_size { |
320 | sub set_size { |
325 | my ($self, $w, $h) = @_; |
321 | my ($self, $w, $h) = @_; |
326 | |
322 | |
327 | $self->{def_w} = $w; |
323 | $self->{force_w} = $w; |
328 | $self->{def_h} = $h; |
324 | $self->{force_h} = $h; |
329 | |
325 | |
330 | $self->realloc; |
326 | $self->realloc; |
331 | } |
327 | } |
332 | |
328 | |
333 | sub size_request { |
329 | sub size_request { |
… | |
… | |
337 | |
333 | |
338 | sub configure { |
334 | sub configure { |
339 | my ($self, $x, $y, $w, $h) = @_; |
335 | my ($self, $x, $y, $w, $h) = @_; |
340 | |
336 | |
341 | if ($self->{aspect}) { |
337 | if ($self->{aspect}) { |
|
|
338 | my ($ow, $oh) = ($w, $h); |
|
|
339 | |
342 | my $w2 = List::Util::min $w, int $h * $self->{aspect}; |
340 | $w = List::Util::min $w, int $h * $self->{aspect}; |
343 | my $h2 = List::Util::min $h, int $w / $self->{aspect}; |
341 | $h = List::Util::min $h, int $w / $self->{aspect}; |
344 | |
342 | |
345 | # use alignment to adjust x, y |
343 | # use alignment to adjust x, y |
346 | |
344 | |
347 | $x += int +($w - $w2) * 0.5; |
345 | $x += int 0.5 * ($ow - $w); |
348 | $y += int +($h - $h2) * 0.5; |
346 | $y += int 0.5 * ($oh - $h); |
349 | |
|
|
350 | ($w, $h) = ($w2, $h2); |
|
|
351 | } |
347 | } |
352 | |
348 | |
353 | if ($self->{x} != $x || $self->{y} != $y) { |
349 | if ($self->{x} ne $x || $self->{y} ne $y) { |
354 | $self->{x} = $x; |
350 | $self->{x} = $x; |
355 | $self->{y} = $y; |
351 | $self->{y} = $y; |
356 | $self->update; |
352 | $self->update; |
357 | } |
353 | } |
358 | |
354 | |
… | |
… | |
469 | my ($self, $parent) = @_; |
465 | my ($self, $parent) = @_; |
470 | |
466 | |
471 | Scalar::Util::weaken ($self->{parent} = $parent); |
467 | Scalar::Util::weaken ($self->{parent} = $parent); |
472 | |
468 | |
473 | $self->set_visible if $parent->{visible}; |
469 | $self->set_visible if $parent->{visible}; |
474 | |
|
|
475 | $self->realloc; |
|
|
476 | } |
470 | } |
477 | |
471 | |
478 | sub connect { |
472 | sub connect { |
479 | my ($self, $signal, $cb) = @_; |
473 | my ($self, $signal, $cb) = @_; |
480 | |
474 | |
… | |
… | |
499 | } |
493 | } |
500 | |
494 | |
501 | sub realloc { |
495 | sub realloc { |
502 | my ($self) = @_; |
496 | my ($self) = @_; |
503 | |
497 | |
504 | return unless $self->{visible}; |
498 | if ($self->{visible}) { |
505 | |
|
|
506 | return if $self->{root}{realloc}{$self}; |
499 | return if $self->{root}{realloc}{$self}; |
507 | |
500 | |
508 | $self->{root}{realloc}{$self} = $self; |
501 | $self->{root}{realloc}{$self} = $self; |
509 | $self->{root}->update; |
502 | $self->{root}->update; |
|
|
503 | } else { |
|
|
504 | delete $self->{req_w}; |
|
|
505 | } |
510 | } |
506 | } |
511 | |
507 | |
512 | sub update { |
508 | sub update { |
513 | my ($self) = @_; |
509 | my ($self) = @_; |
514 | |
510 | |
515 | $self->{parent}->update |
511 | $self->{parent}->update |
516 | if $self->{parent}; |
512 | if $self->{parent}; |
|
|
513 | } |
|
|
514 | |
|
|
515 | sub reconfigure { |
|
|
516 | my ($self) = @_; |
|
|
517 | |
|
|
518 | $self->realloc; |
|
|
519 | $self->update; |
517 | } |
520 | } |
518 | |
521 | |
519 | sub draw { |
522 | sub draw { |
520 | my ($self) = @_; |
523 | my ($self) = @_; |
521 | |
524 | |
… | |
… | |
539 | glVertex $x , $y + $self->{h}; |
542 | glVertex $x , $y + $self->{h}; |
540 | glEnd; |
543 | glEnd; |
541 | glDisable GL_BLEND; |
544 | glDisable GL_BLEND; |
542 | } |
545 | } |
543 | |
546 | |
544 | if ($ENV{PCLIENT_DEBUG}) { |
547 | if ($ENV{CFPLUS_DEBUG}) { |
545 | glPushMatrix; |
548 | glPushMatrix; |
546 | glColor 1, 1, 0, 1; |
549 | glColor 1, 1, 0, 1; |
547 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
550 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
548 | glBegin GL_LINE_LOOP; |
551 | glBegin GL_LINE_LOOP; |
549 | glVertex 0 , 0; |
552 | glVertex 0 , 0; |
… | |
… | |
625 | my ($class, %arg) = @_; |
628 | my ($class, %arg) = @_; |
626 | $class->SUPER::new (can_events => 0, %arg); |
629 | $class->SUPER::new (can_events => 0, %arg); |
627 | } |
630 | } |
628 | |
631 | |
629 | sub size_request { |
632 | sub size_request { |
630 | (0, 0) |
633 | my ($self) = @_; |
|
|
634 | |
|
|
635 | ($self->{w} + 0, $self->{h} + 0) |
631 | } |
636 | } |
632 | |
637 | |
633 | sub draw { } |
638 | sub draw { } |
634 | |
639 | |
635 | ############################################################################# |
640 | ############################################################################# |
… | |
… | |
1006 | |
1011 | |
1007 | our @ISA = CFClient::UI::Bin::; |
1012 | our @ISA = CFClient::UI::Bin::; |
1008 | |
1013 | |
1009 | use CFClient::OpenGL; |
1014 | use CFClient::OpenGL; |
1010 | |
1015 | |
1011 | my @tex = |
1016 | my $bg = |
|
|
1017 | new_from_file CFClient::Texture CFClient::find_rcfile "d1_bg.png", |
|
|
1018 | mipmap => 1, wrap => 1; |
|
|
1019 | |
|
|
1020 | my @border = |
1012 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1021 | 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); |
1022 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1014 | |
1023 | |
1015 | sub new { |
1024 | sub new { |
1016 | my $class = shift; |
1025 | my $class = shift; |
1017 | |
1026 | |
1018 | my $self = $class->SUPER::new ( |
1027 | my $self = $class->SUPER::new ( |
1019 | bg => [1, 1, 1, 1], |
1028 | bg => [1, 1, 1, 1], |
1020 | border_bg => [1, 1, 1, 1], |
1029 | border_bg => [1, 1, 1, 1], |
1021 | border => 0.6, |
1030 | border => 0.6, |
1022 | is_toplevel => 1, |
|
|
1023 | can_events => 1, |
1031 | can_events => 1, |
1024 | @_ |
1032 | @_ |
1025 | ); |
1033 | ); |
1026 | |
1034 | |
1027 | $self->{title} &&= new CFClient::UI::Label |
1035 | $self->{title} &&= new CFClient::UI::Label |
… | |
… | |
1083 | my ($ev, $x, $y) = @_; |
1091 | my ($ev, $x, $y) = @_; |
1084 | |
1092 | |
1085 | my $dx = $ev->{x} - $ox; |
1093 | my $dx = $ev->{x} - $ox; |
1086 | my $dy = $ev->{y} - $oy; |
1094 | my $dy = $ev->{y} - $oy; |
1087 | |
1095 | |
1088 | $self->{user_x} = $wx + $dx * $mx; |
|
|
1089 | $self->{user_y} = $wy + $dy * $my; |
|
|
1090 | $self->{def_w} = $bw + $dx * ($mx ? -1 : 1); |
1096 | $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); |
1091 | $self->{def_h} = $bh + $dy * ($my ? -1 : 1); |
1097 | $self->{force_h} = $bh + $dy * ($my ? -1 : 1); |
1092 | $self->move ($self->{user_x}, $self->{user_y}); |
1098 | |
1093 | $self->realloc; |
1099 | $self->realloc; |
|
|
1100 | $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my); |
1094 | }; |
1101 | }; |
1095 | |
1102 | |
1096 | } elsif ($lr ^ $td) { |
1103 | } elsif ($lr ^ $td) { |
1097 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1104 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1098 | my ($bx, $by) = ($self->{x}, $self->{y}); |
1105 | my ($bx, $by) = ($self->{x}, $self->{y}); |
… | |
… | |
1100 | $self->{motion} = sub { |
1107 | $self->{motion} = sub { |
1101 | my ($ev, $x, $y) = @_; |
1108 | my ($ev, $x, $y) = @_; |
1102 | |
1109 | |
1103 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1110 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1104 | |
1111 | |
1105 | $self->{user_x} = $bx + $x - $ox; |
1112 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1106 | $self->{user_y} = $by + $y - $oy; |
|
|
1107 | |
|
|
1108 | $self->move ($self->{user_x}, $self->{user_y}); |
|
|
1109 | $self->realloc; |
|
|
1110 | }; |
1113 | }; |
1111 | } |
1114 | } |
1112 | } |
1115 | } |
1113 | |
1116 | |
1114 | sub button_up { |
1117 | sub button_up { |
… | |
… | |
1133 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1136 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1134 | |
1137 | |
1135 | my $border = $self->border; |
1138 | my $border = $self->border; |
1136 | |
1139 | |
1137 | glColor @{ $self->{border_bg} }; |
1140 | glColor @{ $self->{border_bg} }; |
1138 | $tex[1]->draw_quad_alpha (0, 0, $w, $border); |
1141 | $border[0]->draw_quad_alpha (0, 0, $w, $border); |
1139 | $tex[3]->draw_quad_alpha (0, $border, $border, $ch); |
1142 | $border[1]->draw_quad_alpha (0, $border, $border, $ch); |
1140 | $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1143 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1141 | $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border); |
1144 | $border[3]->draw_quad_alpha (0, $h - $border, $w, $border); |
1142 | |
1145 | |
1143 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1146 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1144 | my $bg = $tex[0]; |
1147 | glColor @{ $self->{bg} }; |
1145 | |
1148 | |
1146 | # TODO: repeat texture not scale |
1149 | # TODO: repeat texture not scale |
|
|
1150 | # solve this better(?) |
1147 | my $rep_x = $cw / $bg->{w}; |
1151 | $bg->{s} = $cw / $bg->{w}; |
1148 | my $rep_y = $ch / $bg->{h}; |
1152 | $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); |
1153 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
1156 | } |
1154 | } |
1157 | |
1155 | |
1158 | glDisable GL_TEXTURE_2D; |
1156 | glDisable GL_TEXTURE_2D; |
1159 | |
1157 | |
… | |
… | |
1469 | |
1467 | |
1470 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1468 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1471 | $self->{layout}->set_text ($text); |
1469 | $self->{layout}->set_text ($text); |
1472 | |
1470 | |
1473 | $self->realloc; |
1471 | $self->realloc; |
|
|
1472 | $self->update; |
1474 | } |
1473 | } |
1475 | |
1474 | |
1476 | sub set_markup { |
1475 | sub set_markup { |
1477 | my ($self, $markup) = @_; |
1476 | my ($self, $markup) = @_; |
1478 | |
1477 | |
… | |
… | |
1483 | |
1482 | |
1484 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1483 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1485 | $self->{layout}->set_markup ($markup); |
1484 | $self->{layout}->set_markup ($markup); |
1486 | |
1485 | |
1487 | $self->realloc; |
1486 | $self->realloc; |
|
|
1487 | $self->update; |
1488 | } |
1488 | } |
1489 | |
1489 | |
1490 | sub size_request { |
1490 | sub size_request { |
1491 | my ($self) = @_; |
1491 | my ($self) = @_; |
1492 | |
1492 | |
… | |
… | |
2163 | fg => [1, 1, 1], |
2163 | fg => [1, 1, 1], |
2164 | active_fg => [0, 0, 0], |
2164 | active_fg => [0, 0, 0], |
2165 | bg => [0, 0, 0, 0.2], |
2165 | bg => [0, 0, 0, 0.2], |
2166 | active_bg => [1, 1, 1, 0.5], |
2166 | active_bg => [1, 1, 1, 0.5], |
2167 | range => [0, 0, 100, 10, 0], |
2167 | range => [0, 0, 100, 10, 0], |
2168 | req_w => $::WIDTH / 80, |
2168 | min_w => $::WIDTH / 80, |
2169 | req_h => $::WIDTH / 80, |
2169 | min_h => $::WIDTH / 80, |
2170 | vertical => 0, |
2170 | vertical => 0, |
2171 | can_hover => 1, |
2171 | can_hover => 1, |
2172 | inner_pad => 0.02, |
2172 | inner_pad => 0.02, |
2173 | @_ |
2173 | @_ |
2174 | ); |
2174 | ); |
… | |
… | |
2214 | } |
2214 | } |
2215 | |
2215 | |
2216 | sub size_request { |
2216 | sub size_request { |
2217 | my ($self) = @_; |
2217 | my ($self) = @_; |
2218 | |
2218 | |
2219 | my $w = $self->{req_w}; |
2219 | ($self->{req_w}, $self->{req_h}) |
2220 | my $h = $self->{req_h}; |
|
|
2221 | |
|
|
2222 | $self->{vertical} ? ($h, $w) : ($w, $h) |
|
|
2223 | } |
2220 | } |
2224 | |
2221 | |
2225 | sub button_down { |
2222 | sub button_down { |
2226 | my ($self, $ev, $x, $y) = @_; |
2223 | my ($self, $ev, $x, $y) = @_; |
2227 | |
2224 | |
… | |
… | |
2638 | my ($self, $w, $h, $changed) = @_; |
2635 | my ($self, $w, $h, $changed) = @_; |
2639 | |
2636 | |
2640 | return unless $changed; |
2637 | return unless $changed; |
2641 | |
2638 | |
2642 | $self->SUPER::size_allocate ($w - 4, $h - 4, $changed); |
2639 | $self->SUPER::size_allocate ($w - 4, $h - 4, $changed); |
|
|
2640 | } |
|
|
2641 | |
|
|
2642 | sub visibility_change { |
|
|
2643 | my ($self, $visible) = @_; |
|
|
2644 | |
|
|
2645 | return unless $visible; |
|
|
2646 | |
|
|
2647 | $self->{root}->on_post_alloc ("move_$self" => sub { |
|
|
2648 | my $widget = $self->{owner} |
|
|
2649 | or return; |
|
|
2650 | |
|
|
2651 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
|
|
2652 | |
|
|
2653 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
|
|
2654 | if $x + $self->{w} > $::WIDTH; |
|
|
2655 | |
|
|
2656 | $self->move_abs ($x, $y); |
|
|
2657 | }); |
2643 | } |
2658 | } |
2644 | |
2659 | |
2645 | sub _draw { |
2660 | sub _draw { |
2646 | my ($self) = @_; |
2661 | my ($self) = @_; |
2647 | |
2662 | |
… | |
… | |
2664 | glVertex $w, $h; |
2679 | glVertex $w, $h; |
2665 | glVertex $w, 0; |
2680 | glVertex $w, 0; |
2666 | glEnd; |
2681 | glEnd; |
2667 | |
2682 | |
2668 | glTranslate 2 - 0.375, 2 - 0.375; |
2683 | glTranslate 2 - 0.375, 2 - 0.375; |
|
|
2684 | |
2669 | $self->SUPER::_draw; |
2685 | $self->SUPER::_draw; |
2670 | } |
2686 | } |
2671 | |
2687 | |
2672 | ############################################################################# |
2688 | ############################################################################# |
2673 | |
2689 | |
… | |
… | |
3014 | my ($self) = @_; |
3030 | my ($self) = @_; |
3015 | |
3031 | |
3016 | ($self->{w}, $self->{h}) |
3032 | ($self->{w}, $self->{h}) |
3017 | } |
3033 | } |
3018 | |
3034 | |
|
|
3035 | sub _to_pixel { |
|
|
3036 | my ($coord, $size, $max) = @_; |
|
|
3037 | |
|
|
3038 | $coord = |
|
|
3039 | $coord eq "center" ? ($max - $size) * 0.5 |
|
|
3040 | : $coord eq "max" ? $max |
|
|
3041 | : $coord; |
|
|
3042 | |
|
|
3043 | $coord = 0 if $coord < 0; |
|
|
3044 | $coord = $max - $size if $coord > $max - $size; |
|
|
3045 | |
|
|
3046 | int $coord + 0.5 |
|
|
3047 | } |
|
|
3048 | |
3019 | sub size_allocate { |
3049 | sub size_allocate { |
3020 | my ($self, $w, $h, $changed) = @_; |
3050 | my ($self, $w, $h, $changed) = @_; |
3021 | |
3051 | |
3022 | for my $child ($self->children) { |
3052 | for my $child ($self->children) { |
3023 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
3053 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
3024 | |
3054 | |
3025 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
3055 | $X = $child->{force_x} if exists $child->{force_x}; |
3026 | if exists $child->{req_x}; |
3056 | $Y = $child->{force_y} if exists $child->{force_y}; |
3027 | |
3057 | |
3028 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
3058 | $X = _to_pixel $X, $W, $self->{w}; |
3029 | if exists $child->{req_y}; |
3059 | $Y = _to_pixel $Y, $H, $self->{h}; |
3030 | |
|
|
3031 | #delete @$child{qw(req_x req_y)};#d# def_x, def_y |
|
|
3032 | |
|
|
3033 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
|
|
3034 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
|
|
3035 | |
3060 | |
3036 | $child->configure ($X, $Y, $W, $H); |
3061 | $child->configure ($X, $Y, $W, $H); |
3037 | } |
3062 | } |
3038 | } |
3063 | } |
3039 | |
3064 | |
… | |
… | |
3056 | } |
3081 | } |
3057 | |
3082 | |
3058 | sub add { |
3083 | sub add { |
3059 | my ($self, @children) = @_; |
3084 | my ($self, @children) = @_; |
3060 | |
3085 | |
3061 | for my $child (@children) { |
|
|
3062 | $child->{is_toplevel} = 1; |
3086 | $_->{is_toplevel} = 1 |
3063 | |
3087 | for @children; |
3064 | # integerise window positions |
|
|
3065 | $child->{x} = int $child->{x}; |
|
|
3066 | $child->{y} = int $child->{y}; |
|
|
3067 | } |
|
|
3068 | |
3088 | |
3069 | $self->SUPER::add (@children); |
3089 | $self->SUPER::add (@children); |
3070 | } |
3090 | } |
3071 | |
3091 | |
3072 | sub remove { |
3092 | sub remove { |
3073 | my ($self, @children) = @_; |
3093 | my ($self, @children) = @_; |
3074 | |
3094 | |
3075 | $self->SUPER::remove (@children); |
3095 | $self->SUPER::remove (@children); |
|
|
3096 | |
|
|
3097 | delete $self->{is_toplevel} |
|
|
3098 | for @children; |
3076 | |
3099 | |
3077 | while (@children) { |
3100 | while (@children) { |
3078 | my $w = pop @children; |
3101 | my $w = pop @children; |
3079 | push @children, $w->children; |
3102 | push @children, $w->children; |
3080 | $w->set_invisible; |
3103 | $w->set_invisible; |
… | |
… | |
3114 | |
3137 | |
3115 | my $widget = pop @queue || last; |
3138 | my $widget = pop @queue || last; |
3116 | |
3139 | |
3117 | $widget->{visible} or last; # do not resize invisible widgets |
3140 | $widget->{visible} or last; # do not resize invisible widgets |
3118 | |
3141 | |
3119 | my ($w, $h) = $widget->{def_w} && $widget->{def_h} |
|
|
3120 | ? @$widget{qw(def_w def_h)} |
|
|
3121 | : $widget->size_request; |
3142 | my ($w, $h) = $widget->size_request; |
3122 | |
3143 | |
3123 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
3144 | my $min_size = $widget->{is_toplevel} ? 16 : 0; |
3124 | |
3145 | |
|
|
3146 | $w = List::Util::max $widget->{min_w} || $widget->{is_toplevel} * 16, $w; |
|
|
3147 | $h = List::Util::max $widget->{min_h} || $widget->{is_toplevel} * 16, $h; |
|
|
3148 | |
|
|
3149 | $w = $widget->{force_w} if exists $widget->{force_w}; |
|
|
3150 | $h = $widget->{force_h} if exists $widget->{force_h}; |
|
|
3151 | |
3125 | $widget->{req_w} = $w; |
3152 | $widget->{req_w} = $w; |
3126 | $widget->{req_h} = $h; |
3153 | $widget->{req_h} = $h; |
3127 | |
3154 | |
3128 | $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; |
3155 | $self->{size_alloc}{$widget} = [$widget, undef, undef]; |
3129 | |
3156 | |
3130 | push @queue, $widget->{parent} |
3157 | push @queue, $widget->{parent} |
3131 | if $widget->{parent}; |
3158 | if ($self->{w} != $w || $self->{h} != $h) && $widget->{parent}; |
3132 | } |
3159 | } |
3133 | } |
3160 | } |
3134 | |
3161 | |
3135 | while (my $size_alloc = delete $self->{size_alloc}) { |
3162 | while (my $size_alloc = delete $self->{size_alloc}) { |
3136 | my @queue = sort $b->[0]{visible} <=> $a->[0]{visible}, |
3163 | my @queue = sort $b->[0]{visible} <=> $a->[0]{visible}, |
3137 | values %$size_alloc; |
3164 | values %$size_alloc; |
3138 | |
3165 | |
3139 | while () { |
3166 | while () { |
3140 | my ($widget, $w, $h) = @{ pop @queue or last }; |
3167 | my ($widget, $w, $h) = @{ pop @queue or last }; |
3141 | |
3168 | |
|
|
3169 | $w = $widget->{w} || $widget->{req_w} unless defined $w; |
|
|
3170 | $h = $widget->{h} || $widget->{req_h} unless defined $h; |
|
|
3171 | |
3142 | $w = 0 if $w < 0; |
3172 | $w = 0 if $w < 0; |
3143 | $h = 0 if $h < 0; |
3173 | $h = 0 if $h < 0; |
3144 | |
3174 | |
|
|
3175 | $w = int $w + 0.5; |
|
|
3176 | $h = int $h + 0.5; |
|
|
3177 | |
|
|
3178 | my $changed = $widget->{w} != $w || $widget->{h} != $h; |
|
|
3179 | |
3145 | $widget->{w} = $w; |
3180 | $widget->{w} = $w; |
3146 | $widget->{h} = $h; |
3181 | $widget->{h} = $h; |
|
|
3182 | |
3147 | $widget->emit (size_allocate => $w, $h, 1); |
3183 | $widget->emit (size_allocate => $w, $h, $changed); |
3148 | } |
3184 | } |
3149 | } |
3185 | } |
3150 | |
3186 | |
3151 | while ($self->{post_alloc_hook}) { |
3187 | while ($self->{post_alloc_hook}) { |
3152 | $_->() |
3188 | $_->() |