… | |
… | |
74 | sub harmonize { |
74 | sub harmonize { |
75 | my ($vals) = @_; |
75 | my ($vals) = @_; |
76 | |
76 | |
77 | my $rem = 0; |
77 | my $rem = 0; |
78 | |
78 | |
79 | for ($vals) { |
79 | for (@$vals) { |
80 | my $i = int $_ + $rem; |
80 | my $i = int $_ + $rem; |
81 | $rem += $_ - $i; |
81 | $rem += $_ - $i; |
82 | $_ = $i; |
82 | $_ = $i; |
83 | } |
83 | } |
84 | } |
84 | } |
… | |
… | |
96 | |
96 | |
97 | my $self = bless { |
97 | my $self = bless { |
98 | x => 0, |
98 | x => 0, |
99 | y => 0, |
99 | y => 0, |
100 | z => 0, |
100 | z => 0, |
101 | w => -1, |
|
|
102 | h => -1, |
|
|
103 | @_ |
101 | @_ |
104 | }, $class; |
102 | }, $class; |
105 | |
103 | |
106 | for (keys %$self) { |
104 | for (keys %$self) { |
107 | if (/^connect_(.*)$/) { |
105 | if (/^connect_(.*)$/) { |
… | |
… | |
110 | } |
108 | } |
111 | |
109 | |
112 | $self |
110 | $self |
113 | } |
111 | } |
114 | |
112 | |
|
|
113 | sub show { |
|
|
114 | my ($self) = @_; |
|
|
115 | |
|
|
116 | return if $self->{parent}; |
|
|
117 | |
|
|
118 | $CFClient::UI::ROOT->add ($self); |
|
|
119 | } |
|
|
120 | |
|
|
121 | sub hide { |
|
|
122 | my ($self) = @_; |
|
|
123 | |
|
|
124 | return unless $self->{parent}; |
|
|
125 | |
|
|
126 | $self->{parent}->remove ($self); |
|
|
127 | } |
|
|
128 | |
115 | sub move { |
129 | sub move { |
116 | my ($self, $x, $y, $z) = @_; |
130 | my ($self, $x, $y, $z) = @_; |
|
|
131 | |
117 | $self->{x} = $x; |
132 | $self->{x} = int $x; |
118 | $self->{y} = $y; |
133 | $self->{y} = int $y; |
119 | $self->{z} = $z if defined $z; |
134 | $self->{z} = $z if defined $z; |
|
|
135 | |
|
|
136 | $self->update; |
120 | } |
137 | } |
121 | |
138 | |
122 | sub needs_redraw { |
139 | sub needs_redraw { |
123 | 0 |
140 | 0 |
124 | } |
141 | } |
… | |
… | |
126 | sub size_request { |
143 | sub size_request { |
127 | require Carp; |
144 | require Carp; |
128 | Carp::confess "size_request is abtract"; |
145 | Carp::confess "size_request is abtract"; |
129 | } |
146 | } |
130 | |
147 | |
131 | sub _size_allocate { |
148 | sub configure { |
132 | my ($self, $x, $y, $w, $h) = @_; |
149 | my ($self, $x, $y, $w, $h) = @_; |
133 | |
150 | |
134 | $self->{x} = $x; |
151 | $self->{x} = $x; |
135 | $self->{y} = $y; |
152 | $self->{y} = $y; |
136 | |
153 | |
137 | return unless $self->{w} != $w || $self->{h} != $h; |
154 | return unless $self->{w} != $w || $self->{h} != $h; |
138 | |
155 | |
139 | $self->{w} = $w; |
156 | $self->{w} = $w; |
140 | $self->{h} = $h; |
157 | $self->{h} = $h; |
141 | |
158 | |
142 | 1 |
159 | $self->size_allocate ($w, $h); |
|
|
160 | $self->update; |
143 | } |
161 | } |
144 | |
162 | |
145 | sub size_allocate { |
163 | sub size_allocate { |
146 | my ($self, $x, $y, $w, $h) = @_; |
164 | # nothing to be done |
147 | |
|
|
148 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
149 | } |
165 | } |
150 | |
166 | |
151 | # return top left coordinates |
167 | # return top left coordinates |
152 | sub _topleft { |
168 | sub _topleft { |
153 | my ($self, $x, $y) = @_; |
169 | my ($self, $x, $y) = @_; |
… | |
… | |
176 | |
192 | |
177 | return if $FOCUS == $self; |
193 | return if $FOCUS == $self; |
178 | return unless $self->{can_focus}; |
194 | return unless $self->{can_focus}; |
179 | |
195 | |
180 | my $focus = $FOCUS; $FOCUS = $self; |
196 | my $focus = $FOCUS; $FOCUS = $self; |
|
|
197 | |
|
|
198 | $self->emit (focus_in => $focus); |
|
|
199 | |
181 | $focus->update if $focus; |
200 | $focus->update if $focus; |
182 | $FOCUS->update; |
201 | $FOCUS->update; |
183 | } |
202 | } |
184 | |
203 | |
185 | sub focus_out { |
204 | sub focus_out { |
186 | my ($self) = @_; |
205 | my ($self) = @_; |
187 | |
206 | |
188 | return unless $FOCUS == $self; |
207 | return unless $FOCUS == $self; |
189 | |
208 | |
190 | my $focus = $FOCUS; undef $FOCUS; |
209 | my $focus = $FOCUS; undef $FOCUS; |
|
|
210 | |
|
|
211 | $self->emit (focus_out => $focus); |
|
|
212 | |
191 | $focus->update if $focus; #? |
213 | $focus->update if $focus; #? |
192 | } |
214 | } |
193 | |
215 | |
194 | sub mouse_motion { } |
216 | sub mouse_motion { } |
195 | sub button_up { } |
217 | sub button_up { } |
… | |
… | |
219 | glPopMatrix; |
241 | glPopMatrix; |
220 | |
242 | |
221 | if ($self == $HOVER && $self->{can_hover}) { |
243 | if ($self == $HOVER && $self->{can_hover}) { |
222 | my ($x, $y) = @$self{qw(x y)}; |
244 | my ($x, $y) = @$self{qw(x y)}; |
223 | |
245 | |
224 | glColor 0, 0, 1, 0.2; |
246 | glColor 1, 0.8, 0.5, 0.2; |
225 | glEnable GL_BLEND; |
247 | glEnable GL_BLEND; |
226 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
248 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
227 | glBegin GL_QUADS; |
249 | glBegin GL_QUADS; |
228 | glVertex $x , $y; |
250 | glVertex $x , $y; |
229 | glVertex $x + $self->{w}, $y; |
251 | glVertex $x + $self->{w}, $y; |
… | |
… | |
254 | my ($self, $parent) = @_; |
276 | my ($self, $parent) = @_; |
255 | |
277 | |
256 | Scalar::Util::weaken ($self->{parent} = $parent); |
278 | Scalar::Util::weaken ($self->{parent} = $parent); |
257 | } |
279 | } |
258 | |
280 | |
|
|
281 | sub check_size { |
|
|
282 | my ($self) = @_; |
|
|
283 | |
|
|
284 | my ($w, $h) = $self->size_request; |
|
|
285 | |
|
|
286 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
|
|
287 | $self->{req_w} = $w; |
|
|
288 | $self->{req_h} = $h; |
|
|
289 | |
|
|
290 | $self->{parent}->check_size |
|
|
291 | if $self->{parent}; |
|
|
292 | } |
|
|
293 | } |
|
|
294 | |
259 | sub update { |
295 | sub update { |
260 | my ($self) = @_; |
296 | my ($self) = @_; |
261 | |
297 | |
262 | $self->{parent}->update |
298 | $self->{parent}->update |
263 | if $self->{parent}; |
299 | if $self->{parent}; |
264 | } |
300 | } |
265 | |
301 | |
266 | sub connect { |
302 | sub connect { |
267 | my ($self, $signal, $cb) = @_; |
303 | my ($self, $signal, $cb) = @_; |
268 | |
304 | |
269 | push @{ $self->{cb}{$signal} }, $cb; |
305 | push @{ $self->{signal_cb}{$signal} }, $cb; |
270 | } |
306 | } |
271 | |
307 | |
272 | sub emit { |
308 | sub emit { |
273 | my ($self, $signal, @args) = @_; |
309 | my ($self, $signal, @args) = @_; |
274 | |
310 | |
|
|
311 | for my $cb (@{$self->{signal_cb}{$signal} || []}) { |
275 | $_->($self, @args) |
312 | $cb->($self, @args); |
276 | for @{$self->{cb}{$signal} || []}; |
313 | } |
277 | } |
314 | } |
278 | |
315 | |
279 | sub DESTROY { |
316 | sub DESTROY { |
280 | my ($self) = @_; |
317 | my ($self) = @_; |
281 | |
318 | |
… | |
… | |
361 | $self->{children} = [ |
398 | $self->{children} = [ |
362 | sort { $a->{z} <=> $b->{z} } |
399 | sort { $a->{z} <=> $b->{z} } |
363 | @{$self->{children}}, $child |
400 | @{$self->{children}}, $child |
364 | ]; |
401 | ]; |
365 | |
402 | |
366 | $self->{w} = $self->{h} = -1; |
403 | $child->check_size; |
367 | $self->update; |
|
|
368 | } |
404 | } |
369 | |
405 | |
370 | sub remove { |
406 | sub remove { |
371 | my ($self, $widget) = @_; |
407 | my ($self, $child) = @_; |
372 | |
408 | |
|
|
409 | delete $child->{parent}; |
|
|
410 | |
373 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
411 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
374 | |
412 | |
375 | $self->size_allocate (0, 0, $self->{w}, $self->{h}); |
413 | $self->check_size; |
376 | } |
414 | } |
377 | |
415 | |
378 | sub find_widget { |
416 | sub find_widget { |
379 | my ($self, $x, $y) = @_; |
417 | my ($self, $x, $y) = @_; |
380 | |
418 | |
… | |
… | |
410 | |
448 | |
411 | $class->SUPER::new (children => [$child], %arg) |
449 | $class->SUPER::new (children => [$child], %arg) |
412 | } |
450 | } |
413 | |
451 | |
414 | sub add { |
452 | sub add { |
415 | my ($self, $widget) = @_; |
453 | my ($self, $child) = @_; |
416 | |
454 | |
417 | $self->{children} = []; |
455 | $self->{children} = []; |
418 | |
456 | |
419 | $self->SUPER::add ($widget); |
457 | $self->SUPER::add ($child); |
420 | } |
458 | } |
421 | |
459 | |
422 | sub remove { |
460 | sub remove { |
423 | my ($self, $widget) = @_; |
461 | my ($self, $widget) = @_; |
424 | |
462 | |
… | |
… | |
433 | sub size_request { |
471 | sub size_request { |
434 | $_[0]{children}[0]->size_request |
472 | $_[0]{children}[0]->size_request |
435 | } |
473 | } |
436 | |
474 | |
437 | sub size_allocate { |
475 | sub size_allocate { |
438 | my ($self, $x, $y, $w, $h) = @_; |
476 | my ($self, $w, $h) = @_; |
439 | |
477 | |
440 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
441 | |
|
|
442 | $self->{children}[0]->size_allocate (0, 0, $w, $h); |
478 | $self->{children}[0]->configure (0, 0, $w, $h); |
443 | } |
479 | } |
444 | |
480 | |
445 | ############################################################################# |
481 | ############################################################################# |
446 | |
482 | |
447 | package CFClient::UI::Window; |
483 | package CFClient::UI::Window; |
… | |
… | |
473 | $self->child->draw; |
509 | $self->child->draw; |
474 | }; |
510 | }; |
475 | } |
511 | } |
476 | |
512 | |
477 | sub size_allocate { |
513 | sub size_allocate { |
478 | my ($self, $x, $y, $w, $h) = @_; |
514 | my ($self, $w, $h) = @_; |
479 | |
515 | |
480 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
481 | |
|
|
482 | $self->child->size_allocate (0, 0, $w, $h); |
516 | $self->child->configure (0, 0, $w, $h); |
483 | |
517 | |
484 | $self->render_chld; |
518 | $self->render_chld; |
485 | } |
519 | } |
486 | |
520 | |
487 | sub _draw { |
521 | sub _draw { |
… | |
… | |
503 | glDisable GL_TEXTURE_2D; |
537 | glDisable GL_TEXTURE_2D; |
504 | } |
538 | } |
505 | |
539 | |
506 | ############################################################################# |
540 | ############################################################################# |
507 | |
541 | |
|
|
542 | package CFClient::UI::ViewPort; |
|
|
543 | |
|
|
544 | our @ISA = CFClient::UI::Window::; |
|
|
545 | |
|
|
546 | sub new { die } |
|
|
547 | |
|
|
548 | sub size_request { |
|
|
549 | my ($self) = @_; |
|
|
550 | |
|
|
551 | @$self{qw(child_w child_h)} = $self->child->size_request; |
|
|
552 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
|
|
553 | |
|
|
554 | @$self{qw(child_w child_h)} |
|
|
555 | } |
|
|
556 | |
|
|
557 | sub _draw { |
|
|
558 | my ($self) = @_; |
|
|
559 | |
|
|
560 | $self->{children}[1]->draw; |
|
|
561 | } |
|
|
562 | |
|
|
563 | |
|
|
564 | ############################################################################# |
|
|
565 | |
508 | package CFClient::UI::Frame; |
566 | package CFClient::UI::Frame; |
509 | |
567 | |
510 | our @ISA = CFClient::UI::Bin::; |
568 | our @ISA = CFClient::UI::Bin::; |
511 | |
569 | |
512 | use SDL::OpenGL; |
570 | use SDL::OpenGL; |
… | |
… | |
522 | } |
580 | } |
523 | |
581 | |
524 | sub size_allocate { |
582 | sub size_allocate { |
525 | my ($self, $x, $y, $w, $h) = @_; |
583 | my ($self, $x, $y, $w, $h) = @_; |
526 | |
584 | |
527 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
528 | |
|
|
529 | $self->child->size_allocate (2, 2, $w - 4, $h - 4); |
585 | $self->child->configure (2, 2, $w - 4, $h - 4); |
530 | } |
586 | } |
531 | |
587 | |
532 | sub _draw { |
588 | sub _draw { |
533 | my ($self) = @_; |
589 | my ($self) = @_; |
534 | |
590 | |
… | |
… | |
565 | # TODO: user_x, user_y, overwrite moveto? |
621 | # TODO: user_x, user_y, overwrite moveto? |
566 | |
622 | |
567 | $class->SUPER::new ( |
623 | $class->SUPER::new ( |
568 | bg => [1, 1, 1, 1], |
624 | bg => [1, 1, 1, 1], |
569 | border_bg => [1, 1, 1, 1], |
625 | border_bg => [1, 1, 1, 1], |
570 | border => $::FONTSIZE * 0.8, |
626 | border => 0.8, |
571 | @_ |
627 | @_ |
572 | ) |
628 | ) |
573 | } |
629 | } |
574 | |
630 | |
|
|
631 | sub border { |
|
|
632 | int $_[0]{border} * $::FONTSIZE |
|
|
633 | } |
|
|
634 | |
575 | sub size_request { |
635 | sub size_request { |
576 | my ($self) = @_; |
636 | my ($self) = @_; |
577 | |
637 | |
578 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
638 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
579 | |
639 | |
580 | my ($w, $h) = $self->SUPER::size_request; |
640 | my ($w, $h) = $self->SUPER::size_request; |
581 | |
641 | |
582 | ( |
642 | ( |
583 | $w + $self->{border} * 2, |
643 | $w + $self->border * 2, |
584 | $h + $self->{border} * 2, |
644 | $h + $self->border * 2, |
585 | ) |
645 | ) |
586 | } |
646 | } |
587 | |
647 | |
588 | sub size_allocate { |
648 | sub size_allocate { |
589 | my ($self, $x, $y, $w, $h) = @_; |
649 | my ($self, $w, $h) = @_; |
590 | |
650 | |
591 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
592 | |
|
|
593 | $h -= List::Util::max 0, $self->{border} * 2; |
651 | $h -= List::Util::max 0, $self->border * 2; |
594 | $w -= List::Util::max 0, $self->{border} * 2; |
652 | $w -= List::Util::max 0, $self->border * 2; |
595 | |
653 | |
596 | $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); |
654 | $self->child->configure ($self->border, $self->border, $w, $h); |
597 | } |
655 | } |
598 | |
656 | |
599 | sub button_down { |
657 | sub button_down { |
600 | my ($self, $ev, $x, $y) = @_; |
658 | my ($self, $ev, $x, $y) = @_; |
601 | |
659 | |
|
|
660 | my $border = $self->border; |
|
|
661 | |
602 | if ($x < $self->{w} && $x >= $self->{w} - $self->{border} |
662 | if ($x < $self->{w} && $x >= $self->{w} - $border |
603 | && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { |
663 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
604 | |
664 | |
605 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
665 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
606 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
666 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
607 | |
667 | |
608 | $self->{motion} = sub { |
668 | $self->{motion} = sub { |
… | |
… | |
610 | |
670 | |
611 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
671 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
612 | |
672 | |
613 | $self->{user_w} = $bw + $x - $ox; |
673 | $self->{user_w} = $bw + $x - $ox; |
614 | $self->{user_h} = $bh + $y - $oy; |
674 | $self->{user_h} = $bh + $y - $oy; |
615 | $self->update; |
675 | $self->check_size; |
616 | }; |
676 | }; |
617 | |
677 | |
618 | } elsif ($x >= 0 && $x < $self->{w} |
678 | } elsif ($x >= 0 && $x < $self->{w} |
619 | && $y >= 0 && $y < $self->{border}) { |
679 | && $y >= 0 && $y < $border) { |
620 | |
680 | |
621 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
681 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
622 | my ($bx, $by) = ($self->{x}, $self->{y}); |
682 | my ($bx, $by) = ($self->{x}, $self->{y}); |
623 | |
683 | |
624 | $self->{motion} = sub { |
684 | $self->{motion} = sub { |
… | |
… | |
653 | glEnable GL_BLEND; |
713 | glEnable GL_BLEND; |
654 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
714 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
655 | glEnable GL_TEXTURE_2D; |
715 | glEnable GL_TEXTURE_2D; |
656 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
716 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
657 | |
717 | |
|
|
718 | my $border = $self->border; |
|
|
719 | |
658 | glColor @{ $self->{border_bg} }; |
720 | glColor @{ $self->{border_bg} }; |
659 | $tex[1]->draw_quad (0, 0, $w, $self->{border}); |
721 | $tex[1]->draw_quad (0, 0, $w, $border); |
660 | $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); |
722 | $tex[3]->draw_quad (0, $border, $border, $ch); |
661 | $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); |
723 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
662 | $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); |
724 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
663 | |
725 | |
664 | my $bg = $tex[0]; |
726 | my $bg = $tex[0]; |
665 | |
727 | |
666 | # TODO: repeat texture not scale |
728 | # TODO: repeat texture not scale |
667 | my $rep_x = $cw / $bg->{w}; |
729 | my $rep_x = $cw / $bg->{w}; |
… | |
… | |
670 | glColor @{ $self->{bg} }; |
732 | glColor @{ $self->{bg} }; |
671 | |
733 | |
672 | $bg->{s} = $rep_x; |
734 | $bg->{s} = $rep_x; |
673 | $bg->{t} = $rep_y; |
735 | $bg->{t} = $rep_y; |
674 | $bg->{wrap_mode} = 1; |
736 | $bg->{wrap_mode} = 1; |
675 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
737 | $bg->draw_quad ($border, $border, $cw, $ch); |
676 | |
738 | |
677 | glDisable GL_TEXTURE_2D; |
739 | glDisable GL_TEXTURE_2D; |
678 | glDisable GL_BLEND; |
740 | glDisable GL_BLEND; |
679 | |
741 | |
680 | $self->child->draw; |
742 | $self->child->draw; |
… | |
… | |
703 | my ($self, $x, $y, $child) = @_; |
765 | my ($self, $x, $y, $child) = @_; |
704 | |
766 | |
705 | $child->set_parent ($self); |
767 | $child->set_parent ($self); |
706 | $self->{children}[$y][$x] = $child; |
768 | $self->{children}[$y][$x] = $child; |
707 | |
769 | |
708 | $self->{w} = $self->{h} = -1; |
770 | $child->check_size; |
709 | $self->update; |
|
|
710 | } |
771 | } |
711 | |
772 | |
712 | # TODO: move to container class maybe? send childs a signal on removal? |
773 | # TODO: move to container class maybe? send childs a signal on removal? |
713 | sub clear { |
774 | sub clear { |
714 | my ($self) = @_; |
775 | my ($self) = @_; |
… | |
… | |
749 | (sum @$hs), |
810 | (sum @$hs), |
750 | ) |
811 | ) |
751 | } |
812 | } |
752 | |
813 | |
753 | sub size_allocate { |
814 | sub size_allocate { |
754 | my ($self, $x, $y, $w, $h) = @_; |
815 | my ($self, $w, $h) = @_; |
755 | |
|
|
756 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
757 | |
816 | |
758 | my ($ws, $hs) = $self->get_wh; |
817 | my ($ws, $hs) = $self->get_wh; |
759 | |
818 | |
760 | my $req_w = sum @$ws; |
819 | my $req_w = sum @$ws; |
761 | my $req_h = sum @$hs; |
820 | my $req_h = sum @$hs; |
… | |
… | |
783 | |
842 | |
784 | for my $c (0 .. $#$row) { |
843 | for my $c (0 .. $#$row) { |
785 | my $col_w = $ws->[$c]; |
844 | my $col_w = $ws->[$c]; |
786 | |
845 | |
787 | if (my $widget = $row->[$c]) { |
846 | if (my $widget = $row->[$c]) { |
788 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
847 | $widget->configure ($x, $y, $col_w, $row_h); |
789 | } |
848 | } |
790 | |
849 | |
791 | $x += $col_w; |
850 | $x += $col_w; |
792 | } |
851 | } |
793 | |
852 | |
… | |
… | |
838 | (List::Util::max map $_->[1], @alloc), |
897 | (List::Util::max map $_->[1], @alloc), |
839 | ) |
898 | ) |
840 | } |
899 | } |
841 | |
900 | |
842 | sub size_allocate { |
901 | sub size_allocate { |
843 | my ($self, $x, $y, $w, $h) = @_; |
902 | my ($self, $w, $h) = @_; |
844 | |
|
|
845 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
846 | |
903 | |
847 | ($h, $w) = ($w, $h); |
904 | ($h, $w) = ($w, $h); |
848 | |
905 | |
849 | my $children = $self->{children}; |
906 | my $children = $self->{children}; |
850 | |
907 | |
… | |
… | |
872 | |
929 | |
873 | my $y = 0; |
930 | my $y = 0; |
874 | for (0 .. $#$children) { |
931 | for (0 .. $#$children) { |
875 | my $child = $children->[$_]; |
932 | my $child = $children->[$_]; |
876 | my $h = $h[$_]; |
933 | my $h = $h[$_]; |
877 | $child->size_allocate ($y, 0, $h, $w); |
934 | $child->configure ($y, 0, $h, $w); |
878 | |
935 | |
879 | $y += $h; |
936 | $y += $h; |
880 | } |
937 | } |
|
|
938 | |
|
|
939 | 1 |
881 | } |
940 | } |
882 | |
941 | |
883 | ############################################################################# |
942 | ############################################################################# |
884 | |
943 | |
885 | package CFClient::UI::VBox; |
944 | package CFClient::UI::VBox; |
… | |
… | |
898 | (List::Util::sum map $_->[1], @alloc), |
957 | (List::Util::sum map $_->[1], @alloc), |
899 | ) |
958 | ) |
900 | } |
959 | } |
901 | |
960 | |
902 | sub size_allocate { |
961 | sub size_allocate { |
903 | my ($self, $x, $y, $w, $h) = @_; |
962 | my ($self, $w, $h) = @_; |
904 | |
|
|
905 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
906 | |
963 | |
907 | my $children = $self->{children}; |
964 | my $children = $self->{children}; |
908 | |
965 | |
909 | my @h = map +($_->size_request)[1], @$children; |
966 | my @h = map +($_->size_request)[1], @$children; |
910 | |
967 | |
… | |
… | |
928 | |
985 | |
929 | my $y = 0; |
986 | my $y = 0; |
930 | for (0 .. $#$children) { |
987 | for (0 .. $#$children) { |
931 | my $child = $children->[$_]; |
988 | my $child = $children->[$_]; |
932 | my $h = $h[$_]; |
989 | my $h = $h[$_]; |
933 | $child->size_allocate (0, $y, $w, $h); |
990 | $child->configure (0, $y, $w, $h); |
934 | |
991 | |
935 | $y += $h; |
992 | $y += $h; |
936 | } |
993 | } |
|
|
994 | |
|
|
995 | 1 |
937 | } |
996 | } |
938 | |
997 | |
939 | ############################################################################# |
998 | ############################################################################# |
940 | |
999 | |
941 | package CFClient::UI::Label; |
1000 | package CFClient::UI::Label; |
… | |
… | |
947 | sub new { |
1006 | sub new { |
948 | my ($class, %arg) = @_; |
1007 | my ($class, %arg) = @_; |
949 | |
1008 | |
950 | my $self = $class->SUPER::new ( |
1009 | my $self = $class->SUPER::new ( |
951 | fg => [1, 1, 1], |
1010 | fg => [1, 1, 1], |
952 | fontsize => $::FONTSIZE, |
1011 | fontsize => 1, |
953 | text => "", |
1012 | text => "", |
954 | align => -1, |
1013 | align => -1, |
|
|
1014 | valign => -1, |
955 | padding => 2, |
1015 | padding => 2, |
956 | layout => new CFClient::Layout, |
1016 | layout => new CFClient::Layout, |
957 | %arg |
1017 | %arg |
958 | ); |
1018 | ); |
959 | |
1019 | |
960 | $self->set_text ($self->{text}); |
1020 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
|
|
1021 | |
|
|
1022 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
|
|
1023 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
961 | |
1024 | |
962 | $self |
1025 | $self |
963 | } |
1026 | } |
964 | |
1027 | |
965 | sub escape_text { |
1028 | sub escape_text { |
… | |
… | |
973 | } |
1036 | } |
974 | |
1037 | |
975 | sub set_text { |
1038 | sub set_text { |
976 | my ($self, $text) = @_; |
1039 | my ($self, $text) = @_; |
977 | |
1040 | |
978 | $self->{text} = $text; |
|
|
979 | $self->{layout}->set_markup ($text); |
1041 | $self->{layout}->set_text ($text); |
980 | |
1042 | |
981 | delete $self->{texture}; |
1043 | delete $self->{texture}; |
982 | # $self->{w} = $self->{h} = -1; |
|
|
983 | $self->update; |
1044 | $self->update; |
984 | } |
1045 | } |
985 | |
1046 | |
986 | sub get_text { |
1047 | sub set_markup { |
987 | my ($self, $text) = @_; |
1048 | my ($self, $markup) = @_; |
988 | |
1049 | |
989 | $self->{text} |
1050 | $self->{layout}->set_markup ($markup); |
|
|
1051 | |
|
|
1052 | delete $self->{texture}; |
|
|
1053 | $self->update; |
990 | } |
1054 | } |
991 | |
1055 | |
992 | sub size_request { |
1056 | sub size_request { |
993 | my ($self) = @_; |
1057 | my ($self) = @_; |
994 | |
1058 | |
995 | $self->{layout}->set_width; |
1059 | $self->{layout}->set_width; |
996 | $self->{layout}->set_height ($self->{fontsize}); |
1060 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
1061 | |
997 | my ($w, $h) = $self->{layout}->size; |
1062 | my ($w, $h) = $self->{layout}->size; |
998 | |
1063 | |
999 | ( |
1064 | ( |
1000 | $w + $self->{padding} * 2, |
1065 | $w + $self->{padding} * 2, |
1001 | $h + $self->{padding} * 2, |
1066 | $h + $self->{padding} * 2, |
1002 | ) |
1067 | ) |
1003 | } |
1068 | } |
1004 | |
1069 | |
1005 | sub size_allocate { |
1070 | sub size_allocate { |
1006 | my ($self, $x, $y, $w, $h) = @_; |
1071 | my ($self, $w, $h) = @_; |
1007 | |
|
|
1008 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
1009 | |
1072 | |
1010 | delete $self->{texture}; |
1073 | delete $self->{texture}; |
1011 | } |
|
|
1012 | |
|
|
1013 | sub update { |
|
|
1014 | my ($self) = @_; |
|
|
1015 | |
|
|
1016 | delete $self->{texture}; |
|
|
1017 | $self->SUPER::update; |
|
|
1018 | } |
1074 | } |
1019 | |
1075 | |
1020 | sub _draw { |
1076 | sub _draw { |
1021 | my ($self) = @_; |
1077 | my ($self) = @_; |
1022 | |
1078 | |
1023 | my $tex = $self->{texture} ||= do { |
1079 | my $tex = $self->{texture} ||= do { |
1024 | $self->{layout}->set_width ($self->{w}); |
1080 | $self->{layout}->set_width ($self->{w}); |
1025 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
1081 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1026 | new_from_layout CFClient::Texture $self->{layout} |
1082 | new_from_layout CFClient::Texture $self->{layout} |
1027 | }; |
1083 | }; |
1028 | |
1084 | |
1029 | glEnable GL_BLEND; |
1085 | glEnable GL_BLEND; |
1030 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1086 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1031 | glEnable GL_TEXTURE_2D; |
1087 | glEnable GL_TEXTURE_2D; |
1032 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1088 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1033 | |
1089 | |
1034 | glColor @{$self->{fg}}; |
1090 | glColor @{$self->{fg}}; |
1035 | |
1091 | |
1036 | my $x = |
1092 | $self->{ox} = int ( |
1037 | $self->{align} < 0 ? $self->{padding} |
1093 | $self->{align} < 0 ? $self->{padding} |
1038 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1094 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1039 | : ($self->{w} - $tex->{w}) * 0.5; |
1095 | : ($self->{w} - $tex->{w}) * 0.5 |
|
|
1096 | ); |
1040 | |
1097 | |
1041 | $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5); |
1098 | $self->{oy} = int ( |
|
|
1099 | $self->{valign} < 0 ? $self->{padding} |
|
|
1100 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
|
|
1101 | : ($self->{h} - $tex->{h}) * 0.5 |
|
|
1102 | ); |
|
|
1103 | |
|
|
1104 | $tex->draw_quad ($self->{ox}, $self->{oy}); |
1042 | |
1105 | |
1043 | glDisable GL_TEXTURE_2D; |
1106 | glDisable GL_TEXTURE_2D; |
1044 | glDisable GL_BLEND; |
1107 | glDisable GL_BLEND; |
1045 | } |
1108 | } |
1046 | |
1109 | |
1047 | ############################################################################# |
1110 | ############################################################################# |
1048 | |
1111 | |
1049 | package CFClient::UI::Entry; |
1112 | package CFClient::UI::EntryBase; |
1050 | |
1113 | |
1051 | our @ISA = CFClient::UI::Label::; |
1114 | our @ISA = CFClient::UI::Label::; |
1052 | |
1115 | |
1053 | use SDL; |
|
|
1054 | use SDL::OpenGL; |
1116 | use SDL::OpenGL; |
1055 | |
1117 | |
1056 | sub new { |
1118 | sub new { |
1057 | my $class = shift; |
1119 | my $class = shift; |
1058 | |
1120 | |
… | |
… | |
1061 | bg => [0, 0, 0, 0.2], |
1123 | bg => [0, 0, 0, 0.2], |
1062 | active_bg => [1, 1, 1, 0.5], |
1124 | active_bg => [1, 1, 1, 0.5], |
1063 | active_fg => [0, 0, 0], |
1125 | active_fg => [0, 0, 0], |
1064 | can_hover => 1, |
1126 | can_hover => 1, |
1065 | can_focus => 1, |
1127 | can_focus => 1, |
|
|
1128 | valign => 0, |
1066 | @_ |
1129 | @_ |
1067 | ) |
1130 | ) |
1068 | } |
1131 | } |
1069 | |
1132 | |
1070 | sub _set_text { |
1133 | sub _set_text { |
1071 | my ($self, $text) = @_; |
1134 | my ($self, $text) = @_; |
1072 | |
1135 | |
1073 | my $old_text = $self->{text}; |
1136 | delete $self->{cur_h}; |
|
|
1137 | |
|
|
1138 | return if $self->{text} eq $text; |
|
|
1139 | |
|
|
1140 | delete $self->{texture}; |
1074 | |
1141 | |
1075 | $self->{last_activity} = $::NOW; |
1142 | $self->{last_activity} = $::NOW; |
1076 | |
|
|
1077 | $self->{text} = $text; |
1143 | $self->{text} = $text; |
1078 | $self->{layout}->set_width ($self->{w}); |
|
|
1079 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
|
|
1080 | |
1144 | |
1081 | $text =~ s/./*/g if $self->{hidden}; |
1145 | $text =~ s/./*/g if $self->{hidden}; |
|
|
1146 | $self->{layout}->set_text ("$text "); |
1082 | |
1147 | |
1083 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1148 | $self->emit (changed => $self->{text}); |
|
|
1149 | } |
1084 | |
1150 | |
1085 | $text = substr $text, 0, $self->{cursor}; |
1151 | sub get_text { |
1086 | utf8::encode $text; |
1152 | $_[0]{text} |
1087 | |
|
|
1088 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
|
|
1089 | |
|
|
1090 | $self->emit (changed => $self->{text}) # XXX: is this the right place to do this? |
|
|
1091 | if $old_text ne $self->{text}; |
|
|
1092 | } |
1153 | } |
1093 | |
1154 | |
1094 | sub size_request { |
1155 | sub size_request { |
1095 | my ($self) = @_; |
1156 | my ($self) = @_; |
1096 | |
1157 | |
… | |
… | |
1098 | |
1159 | |
1099 | ($w + 1, $h) # add 1 for cursor |
1160 | ($w + 1, $h) # add 1 for cursor |
1100 | } |
1161 | } |
1101 | |
1162 | |
1102 | sub size_allocate { |
1163 | sub size_allocate { |
1103 | my ($self, $x, $y, $w, $h) = @_; |
1164 | my ($self, $w, $h) = @_; |
1104 | |
|
|
1105 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
|
|
1106 | |
1165 | |
1107 | $self->_set_text ($self->{text}); |
1166 | $self->_set_text ($self->{text}); |
1108 | } |
1167 | } |
1109 | |
1168 | |
1110 | sub set_text { |
1169 | sub set_text { |
… | |
… | |
1123 | |
1182 | |
1124 | my $uni = $ev->key_unicode; |
1183 | my $uni = $ev->key_unicode; |
1125 | |
1184 | |
1126 | my $text = $self->get_text; |
1185 | my $text = $self->get_text; |
1127 | |
1186 | |
1128 | if ($sym == SDLK_BACKSPACE) { |
1187 | if ($sym == 8) { |
1129 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1188 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1130 | } elsif ($sym == SDLK_DELETE) { |
1189 | } elsif ($sym == 127) { |
1131 | substr $text, $self->{cursor}, 1, ""; |
1190 | substr $text, $self->{cursor}, 1, ""; |
1132 | } elsif ($sym == SDLK_LEFT) { |
1191 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1133 | --$self->{cursor} if $self->{cursor}; |
1192 | --$self->{cursor} if $self->{cursor}; |
1134 | } elsif ($sym == SDLK_RIGHT) { |
1193 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1135 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1194 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1136 | } elsif ($sym == SDLK_HOME) { |
1195 | } elsif ($sym == CFClient::SDLK_HOME) { |
1137 | $self->{cursor} = 0; |
1196 | $self->{cursor} = 0; |
1138 | } elsif ($sym == SDLK_END) { |
1197 | } elsif ($sym == CFClient::SDLK_END) { |
1139 | $self->{cursor} = length $text; |
1198 | $self->{cursor} = length $text; |
1140 | } elsif ($sym == SDLK_ESCAPE) { |
1199 | } elsif ($sym == 27) { |
1141 | $self->emit ('escape'); |
1200 | $self->emit ('escape'); |
1142 | } elsif ($uni) { |
1201 | } elsif ($uni) { |
1143 | substr $text, $self->{cursor}++, 0, chr $uni; |
1202 | substr $text, $self->{cursor}++, 0, chr $uni; |
1144 | } |
1203 | } |
1145 | |
1204 | |
… | |
… | |
1200 | |
1259 | |
1201 | $self->SUPER::_draw; |
1260 | $self->SUPER::_draw; |
1202 | |
1261 | |
1203 | #TODO: force update every cursor change :( |
1262 | #TODO: force update every cursor change :( |
1204 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
1263 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
|
|
1264 | |
|
|
1265 | unless (exists $self->{cur_h}) { |
|
|
1266 | my $text = substr $self->{text}, 0, $self->{cursor}; |
|
|
1267 | utf8::encode $text; |
|
|
1268 | |
|
|
1269 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
|
|
1270 | } |
|
|
1271 | |
1205 | glColor @{$self->{fg}}; |
1272 | glColor @{$self->{fg}}; |
1206 | glBegin GL_LINES; |
1273 | glBegin GL_LINES; |
1207 | glVertex $self->{cur_x}, $self->{cur_y}; |
|
|
1208 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1274 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
|
|
1275 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
1209 | glEnd; |
1276 | glEnd; |
1210 | } |
1277 | } |
1211 | } |
1278 | } |
1212 | |
1279 | |
1213 | package CFClient::UI::LineEntry; |
1280 | package CFClient::UI::Entry; |
1214 | |
1281 | |
1215 | our @ISA = CFClient::UI::Entry::; |
1282 | our @ISA = CFClient::UI::EntryBase::; |
1216 | |
1283 | |
1217 | use SDL; |
|
|
1218 | use SDL::OpenGL; |
1284 | use SDL::OpenGL; |
1219 | |
1285 | |
1220 | sub key_down { |
1286 | sub key_down { |
1221 | my ($self, $ev) = @_; |
1287 | my ($self, $ev) = @_; |
1222 | |
1288 | |
1223 | my $sym = $ev->key_sym; |
1289 | my $sym = $ev->key_sym; |
1224 | |
1290 | |
1225 | if ($sym == SDLK_RETURN) { |
1291 | if ($sym == 13) { |
1226 | $self->emit (activate => $self->get_text); |
1292 | $self->emit (activate => $self->get_text); |
1227 | $self->update; |
1293 | $self->update; |
1228 | |
1294 | |
1229 | } else { |
1295 | } else { |
1230 | $self->SUPER::key_down ($ev); |
1296 | $self->SUPER::key_down ($ev); |
… | |
… | |
1236 | |
1302 | |
1237 | package CFClient::UI::Button; |
1303 | package CFClient::UI::Button; |
1238 | |
1304 | |
1239 | our @ISA = CFClient::UI::Label::; |
1305 | our @ISA = CFClient::UI::Label::; |
1240 | |
1306 | |
1241 | use SDL; |
|
|
1242 | use SDL::OpenGL; |
1307 | use SDL::OpenGL; |
1243 | |
1308 | |
1244 | my @tex = |
1309 | my @tex = |
1245 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1310 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1246 | qw(b1_button_active.png); |
1311 | qw(b1_button_active.png); |
… | |
… | |
1250 | |
1315 | |
1251 | $class->SUPER::new ( |
1316 | $class->SUPER::new ( |
1252 | padding => 4, |
1317 | padding => 4, |
1253 | fg => [1, 1, 1], |
1318 | fg => [1, 1, 1], |
1254 | bg => [1, 1, 1, 0.2], |
1319 | bg => [1, 1, 1, 0.2], |
1255 | active_fg => [1, 1, 0], |
1320 | active_fg => [0, 0, 1], |
1256 | can_hover => 1, |
1321 | can_hover => 1, |
|
|
1322 | align => 0, |
|
|
1323 | valign => 0, |
1257 | @_ |
1324 | @_ |
1258 | ) |
1325 | ) |
1259 | } |
1326 | } |
1260 | |
1327 | |
1261 | sub button_up { |
1328 | sub button_up { |
… | |
… | |
1269 | |
1336 | |
1270 | sub _draw { |
1337 | sub _draw { |
1271 | my ($self) = @_; |
1338 | my ($self) = @_; |
1272 | |
1339 | |
1273 | local $self->{fg} = $self->{fg}; |
1340 | local $self->{fg} = $self->{fg}; |
1274 | my $tex = $tex[0]; |
|
|
1275 | |
|
|
1276 | glEnable GL_BLEND; |
|
|
1277 | glEnable GL_TEXTURE_2D; |
|
|
1278 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1279 | |
1341 | |
1280 | if ($GRAB == $self) { |
1342 | if ($GRAB == $self) { |
1281 | $self->{fg} = $self->{active_fg}; |
1343 | $self->{fg} = $self->{active_fg}; |
1282 | } |
1344 | } |
1283 | |
1345 | |
1284 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
1346 | glEnable GL_BLEND; |
|
|
1347 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1348 | glEnable GL_TEXTURE_2D; |
1285 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1349 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1350 | glColor 0, 0, 0, 1; |
1286 | |
1351 | |
1287 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
1352 | $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); |
1288 | |
1353 | |
1289 | glDisable GL_TEXTURE_2D; |
1354 | glDisable GL_TEXTURE_2D; |
1290 | glDisable GL_BLEND; |
1355 | glDisable GL_BLEND; |
1291 | |
1356 | |
1292 | $self->SUPER::_draw; |
1357 | $self->SUPER::_draw; |
… | |
… | |
1300 | |
1365 | |
1301 | my @tex = |
1366 | my @tex = |
1302 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1367 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1303 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1368 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1304 | |
1369 | |
1305 | use SDL; |
|
|
1306 | use SDL::OpenGL; |
1370 | use SDL::OpenGL; |
1307 | |
1371 | |
1308 | sub new { |
1372 | sub new { |
1309 | my $class = shift; |
1373 | my $class = shift; |
1310 | |
1374 | |
… | |
… | |
1322 | my ($self) = @_; |
1386 | my ($self) = @_; |
1323 | |
1387 | |
1324 | ($self->{padding} * 2 + 6) x 2 |
1388 | ($self->{padding} * 2 + 6) x 2 |
1325 | } |
1389 | } |
1326 | |
1390 | |
1327 | sub size_allocate { |
|
|
1328 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1329 | |
|
|
1330 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
1331 | } |
|
|
1332 | |
|
|
1333 | sub button_down { |
1391 | sub button_down { |
1334 | my ($self, $ev, $x, $y) = @_; |
1392 | my ($self, $ev, $x, $y) = @_; |
1335 | |
1393 | |
1336 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1394 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1337 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1395 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
… | |
… | |
1359 | |
1417 | |
1360 | $tex->draw_quad (0, 0, $s, $s); |
1418 | $tex->draw_quad (0, 0, $s, $s); |
1361 | |
1419 | |
1362 | glDisable GL_TEXTURE_2D; |
1420 | glDisable GL_TEXTURE_2D; |
1363 | glDisable GL_BLEND; |
1421 | glDisable GL_BLEND; |
|
|
1422 | } |
|
|
1423 | |
|
|
1424 | ############################################################################# |
|
|
1425 | |
|
|
1426 | package CFClient::UI::VGauge; |
|
|
1427 | |
|
|
1428 | our @ISA = CFClient::UI::Base::; |
|
|
1429 | |
|
|
1430 | use SDL::OpenGL; |
|
|
1431 | |
|
|
1432 | my %tex = ( |
|
|
1433 | food => [ |
|
|
1434 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1435 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1436 | ], |
|
|
1437 | grace => [ |
|
|
1438 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1439 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1440 | ], |
|
|
1441 | hp => [ |
|
|
1442 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1443 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1444 | ], |
|
|
1445 | mana => [ |
|
|
1446 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1447 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1448 | ], |
|
|
1449 | ); |
|
|
1450 | |
|
|
1451 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1452 | sub new { |
|
|
1453 | my $class = shift; |
|
|
1454 | |
|
|
1455 | my $self = $class->SUPER::new (gauge => 'food', @_); |
|
|
1456 | |
|
|
1457 | $self |
|
|
1458 | } |
|
|
1459 | |
|
|
1460 | sub size_request { |
|
|
1461 | my ($self) = @_; |
|
|
1462 | |
|
|
1463 | my $tex = $tex{$self->{gauge}}[0]; |
|
|
1464 | |
|
|
1465 | @$tex{qw(w h)} |
|
|
1466 | } |
|
|
1467 | |
|
|
1468 | sub set_max { |
|
|
1469 | my ($self, $max) = @_; |
|
|
1470 | |
|
|
1471 | $self->{max_val} = $max; |
|
|
1472 | } |
|
|
1473 | |
|
|
1474 | sub set_value { |
|
|
1475 | my ($self, $val, $max) = @_; |
|
|
1476 | |
|
|
1477 | $self->set_max ($max) |
|
|
1478 | if defined $max; |
|
|
1479 | |
|
|
1480 | $max = $self->{max_val}; |
|
|
1481 | $self->{val} = $val; |
|
|
1482 | |
|
|
1483 | $self->update; |
|
|
1484 | } |
|
|
1485 | |
|
|
1486 | sub _draw { |
|
|
1487 | my ($self) = @_; |
|
|
1488 | |
|
|
1489 | my $tex = $tex{$self->{gauge}}; |
|
|
1490 | |
|
|
1491 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1492 | |
|
|
1493 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1494 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1495 | |
|
|
1496 | my $t1 = $tex->[0]; |
|
|
1497 | my $t2 = $tex->[1]; |
|
|
1498 | |
|
|
1499 | glEnable GL_BLEND; |
|
|
1500 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1501 | glEnable GL_TEXTURE_2D; |
|
|
1502 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1503 | |
|
|
1504 | my $h1 = $self->{h} - $ycut * $self->{h}; |
|
|
1505 | my $h2 = $ycut * $self->{h}; |
|
|
1506 | |
|
|
1507 | my $yp = 0; |
|
|
1508 | |
|
|
1509 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
|
|
1510 | glBegin GL_QUADS; |
|
|
1511 | glTexCoord 0 , 0; glVertex 0 , $yp; |
|
|
1512 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
|
|
1513 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
|
|
1514 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
|
|
1515 | glEnd; |
|
|
1516 | |
|
|
1517 | $yp += $h1; |
|
|
1518 | |
|
|
1519 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
|
|
1520 | glBegin GL_QUADS; |
|
|
1521 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
|
|
1522 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
|
|
1523 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
|
|
1524 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
|
|
1525 | glEnd; |
|
|
1526 | |
|
|
1527 | glDisable GL_BLEND; |
|
|
1528 | glDisable GL_TEXTURE_2D; |
1364 | } |
1529 | } |
1365 | |
1530 | |
1366 | ############################################################################# |
1531 | ############################################################################# |
1367 | |
1532 | |
1368 | package CFClient::UI::Slider; |
1533 | package CFClient::UI::Slider; |
… | |
… | |
1387 | # TODO: calculations are off |
1552 | # TODO: calculations are off |
1388 | my $self = $class->SUPER::new ( |
1553 | my $self = $class->SUPER::new ( |
1389 | fg => [1, 1, 1], |
1554 | fg => [1, 1, 1], |
1390 | active_fg => [0, 0, 0], |
1555 | active_fg => [0, 0, 0], |
1391 | range => [0, 0, 100, 10], |
1556 | range => [0, 0, 100, 10], |
1392 | req_w => 40, |
1557 | req_w => 20, |
1393 | req_h => 13, |
1558 | req_h => 20, |
1394 | vertical => 0, |
1559 | vertical => 0, |
1395 | can_hover => 1, |
1560 | can_hover => 1, |
1396 | inner_pad => 5, |
1561 | inner_pad => 5, |
1397 | @_ |
1562 | @_ |
1398 | ); |
1563 | ); |
… | |
… | |
1508 | |
1673 | |
1509 | sub new { |
1674 | sub new { |
1510 | my $class = shift; |
1675 | my $class = shift; |
1511 | |
1676 | |
1512 | my $self = $class->SUPER::new ( |
1677 | my $self = $class->SUPER::new ( |
1513 | req_w => $::WIDTH / 6, |
|
|
1514 | req_h => $::HEIGHT / 6, |
|
|
1515 | fontsize => $::FONTSIZE, |
1678 | fontsize => 1, |
1516 | @_, |
1679 | @_, |
1517 | |
1680 | |
1518 | layout => (new CFClient::Layout), |
1681 | layout => (new CFClient::Layout), |
1519 | par => [], |
1682 | par => [], |
1520 | height => 0, |
1683 | height => 0, |
… | |
… | |
1541 | sub text_height { |
1704 | sub text_height { |
1542 | my ($self, $text) = @_; |
1705 | my ($self, $text) = @_; |
1543 | |
1706 | |
1544 | my $layout = $self->{layout}; |
1707 | my $layout = $self->{layout}; |
1545 | |
1708 | |
1546 | $layout->set_height ($self->{fontsize}); |
1709 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
1547 | $layout->set_width ($self->{w}); |
1710 | $layout->set_width ($self->{w}); |
1548 | $layout->set_text ($text); |
1711 | $layout->set_text ($text); |
1549 | |
1712 | |
1550 | ($layout->size)[1] |
1713 | ($layout->size)[1] |
1551 | } |
1714 | } |
… | |
… | |
1555 | |
1718 | |
1556 | $self->{need_reflow}++; |
1719 | $self->{need_reflow}++; |
1557 | $self->update; |
1720 | $self->update; |
1558 | } |
1721 | } |
1559 | |
1722 | |
1560 | sub size_request { |
|
|
1561 | my ($self) = @_; |
|
|
1562 | |
|
|
1563 | ($self->{req_w}, $self->{req_h}) |
|
|
1564 | } |
|
|
1565 | |
|
|
1566 | sub size_allocate { |
1723 | sub size_allocate { |
1567 | my ($self, $x, $y, $w, $h) = @_; |
1724 | my ($self, $w, $h) = @_; |
1568 | |
1725 | |
1569 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
1726 | $self->SUPER::size_allocate ($w, $h); |
1570 | |
1727 | |
1571 | $self->{layout}->set_height ($self->{fontsize}); |
1728 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1572 | $self->{layout}->set_width ($self->{w}); |
1729 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1573 | |
1730 | |
1574 | $self->reflow; |
1731 | $self->reflow; |
1575 | } |
1732 | } |
1576 | |
1733 | |
1577 | sub add_paragraph { |
1734 | sub add_paragraph { |
… | |
… | |
1660 | glDisable GL_TEXTURE_2D; |
1817 | glDisable GL_TEXTURE_2D; |
1661 | } |
1818 | } |
1662 | |
1819 | |
1663 | $self->{children}[1]->draw; |
1820 | $self->{children}[1]->draw; |
1664 | |
1821 | |
1665 | } |
|
|
1666 | |
|
|
1667 | ############################################################################# |
|
|
1668 | |
|
|
1669 | package CFClient::UI::MapWidget; |
|
|
1670 | |
|
|
1671 | use strict; |
|
|
1672 | |
|
|
1673 | use List::Util qw(min max); |
|
|
1674 | |
|
|
1675 | use SDL; |
|
|
1676 | use SDL::OpenGL; |
|
|
1677 | |
|
|
1678 | our @ISA = CFClient::UI::Base::; |
|
|
1679 | |
|
|
1680 | sub new { |
|
|
1681 | my $class = shift; |
|
|
1682 | |
|
|
1683 | $class->SUPER::new ( |
|
|
1684 | z => -1, |
|
|
1685 | can_focus => 1, |
|
|
1686 | list => (glGenLists 1), |
|
|
1687 | @_ |
|
|
1688 | ) |
|
|
1689 | } |
|
|
1690 | |
|
|
1691 | sub key_down { |
|
|
1692 | print "MAPKEYDOWN\n"; |
|
|
1693 | } |
|
|
1694 | |
|
|
1695 | sub key_up { |
|
|
1696 | } |
|
|
1697 | |
|
|
1698 | sub button_down { |
|
|
1699 | my ($self, $ev, $x, $y) = @_; |
|
|
1700 | |
|
|
1701 | $self->focus_in; |
|
|
1702 | |
|
|
1703 | if ($ev->button == 2) { |
|
|
1704 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
1705 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
|
|
1706 | |
|
|
1707 | $self->{motion} = sub { |
|
|
1708 | my ($ev, $x, $y) = @_; |
|
|
1709 | |
|
|
1710 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
1711 | |
|
|
1712 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
|
|
1713 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
|
|
1714 | |
|
|
1715 | $self->update; |
|
|
1716 | }; |
|
|
1717 | } |
|
|
1718 | } |
|
|
1719 | |
|
|
1720 | sub button_up { |
|
|
1721 | my ($self, $ev, $x, $y) = @_; |
|
|
1722 | |
|
|
1723 | delete $self->{motion}; |
|
|
1724 | } |
|
|
1725 | |
|
|
1726 | sub mouse_motion { |
|
|
1727 | my ($self, $ev, $x, $y) = @_; |
|
|
1728 | |
|
|
1729 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1730 | } |
|
|
1731 | |
|
|
1732 | sub size_request { |
|
|
1733 | ( |
|
|
1734 | 1 + 32 * int $::WIDTH / 32, |
|
|
1735 | 1 + 32 * int $::HEIGHT / 32, |
|
|
1736 | ) |
|
|
1737 | } |
|
|
1738 | |
|
|
1739 | sub update { |
|
|
1740 | my ($self) = @_; |
|
|
1741 | |
|
|
1742 | $self->{need_update} = 1; |
|
|
1743 | $self->SUPER::update; |
|
|
1744 | } |
|
|
1745 | |
|
|
1746 | sub draw { |
|
|
1747 | my ($self) = @_; |
|
|
1748 | |
|
|
1749 | if (delete $self->{need_update}) { |
|
|
1750 | glNewList $self->{list}, GL_COMPILE; |
|
|
1751 | |
|
|
1752 | if ($::MAP) { |
|
|
1753 | my $sw = int $::WIDTH / 32; |
|
|
1754 | my $sh = int $::HEIGHT / 32; |
|
|
1755 | |
|
|
1756 | my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
1757 | my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
1758 | |
|
|
1759 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
|
|
1760 | |
|
|
1761 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
|
|
1762 | |
|
|
1763 | if ($::CFG->{fow_enable}) { |
|
|
1764 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1765 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
|
|
1766 | glConvolutionFilter2D |
|
|
1767 | GL_CONVOLUTION_2D, |
|
|
1768 | GL_ALPHA, |
|
|
1769 | 3, 3, |
|
|
1770 | GL_ALPHA, GL_FLOAT, |
|
|
1771 | pack "f*", |
|
|
1772 | 0.1, 0.1, 0.1, |
|
|
1773 | 0.1, 0.2, 0.1, |
|
|
1774 | 0.1, 0.1, 0.1, |
|
|
1775 | ; |
|
|
1776 | glEnable GL_CONVOLUTION_2D; |
|
|
1777 | } |
|
|
1778 | |
|
|
1779 | my $tex = new CFClient::Texture |
|
|
1780 | w => $w, |
|
|
1781 | h => $h, |
|
|
1782 | data => $data, |
|
|
1783 | internalformat => GL_ALPHA, |
|
|
1784 | format => GL_ALPHA; |
|
|
1785 | |
|
|
1786 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
1787 | |
|
|
1788 | glEnable GL_BLEND; |
|
|
1789 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1790 | glEnable GL_TEXTURE_2D; |
|
|
1791 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1792 | |
|
|
1793 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1794 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1795 | |
|
|
1796 | glDisable GL_TEXTURE_2D; |
|
|
1797 | glDisable GL_BLEND; |
|
|
1798 | } |
|
|
1799 | |
|
|
1800 | # HACK BEGIN |
|
|
1801 | { |
|
|
1802 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
1803 | my ($w, $h) = (250, 250); |
|
|
1804 | |
|
|
1805 | glEnable GL_BLEND; |
|
|
1806 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1807 | glEnable GL_TEXTURE_2D; |
|
|
1808 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1809 | |
|
|
1810 | CFClient::Texture->new ( |
|
|
1811 | w => $w, |
|
|
1812 | h => $h, |
|
|
1813 | data => $::MAP->mapmap ($w, $h), |
|
|
1814 | type => GL_UNSIGNED_INT_8_8_8_8_REV |
|
|
1815 | )->draw_quad (100, 100); |
|
|
1816 | |
|
|
1817 | glDisable GL_TEXTURE_2D; |
|
|
1818 | glDisable GL_BLEND; |
|
|
1819 | } |
|
|
1820 | # HACK END |
|
|
1821 | } |
|
|
1822 | |
|
|
1823 | glEndList; |
|
|
1824 | } |
|
|
1825 | |
|
|
1826 | glPushMatrix; |
|
|
1827 | glCallList $self->{list}; |
|
|
1828 | glPopMatrix; |
|
|
1829 | |
|
|
1830 | if ($FOCUS != $self) { |
|
|
1831 | glColor 64/255, 64/255, 64/255; |
|
|
1832 | glLogicOp GL_AND; |
|
|
1833 | glEnable GL_COLOR_LOGIC_OP; |
|
|
1834 | glBegin GL_QUADS; |
|
|
1835 | glVertex 0, 0; |
|
|
1836 | glVertex 0, $::HEIGHT; |
|
|
1837 | glVertex $::WIDTH, $::HEIGHT; |
|
|
1838 | glVertex $::WIDTH, 0; |
|
|
1839 | glEnd; |
|
|
1840 | glDisable GL_COLOR_LOGIC_OP; |
|
|
1841 | } |
|
|
1842 | } |
|
|
1843 | |
|
|
1844 | my %DIR = ( |
|
|
1845 | SDLK_KP8, [1, "north"], |
|
|
1846 | SDLK_KP9, [2, "northeast"], |
|
|
1847 | SDLK_KP6, [3, "east"], |
|
|
1848 | SDLK_KP3, [4, "southeast"], |
|
|
1849 | SDLK_KP2, [5, "south"], |
|
|
1850 | SDLK_KP1, [6, "southwest"], |
|
|
1851 | SDLK_KP4, [7, "west"], |
|
|
1852 | SDLK_KP7, [8, "northwest"], |
|
|
1853 | |
|
|
1854 | SDLK_UP, [1, "north"], |
|
|
1855 | SDLK_RIGHT, [3, "east"], |
|
|
1856 | SDLK_DOWN, [5, "south"], |
|
|
1857 | SDLK_LEFT, [7, "west"], |
|
|
1858 | ); |
|
|
1859 | |
|
|
1860 | sub key_down { |
|
|
1861 | my ($self, $ev) = @_; |
|
|
1862 | |
|
|
1863 | my $mod = $ev->key_mod; |
|
|
1864 | my $sym = $ev->key_sym; |
|
|
1865 | |
|
|
1866 | if ($sym == SDLK_KP5) { |
|
|
1867 | $::CONN->user_send ("command stay fire"); |
|
|
1868 | } elsif ($sym == SDLK_a) { |
|
|
1869 | $::CONN->user_send ("command apply"); |
|
|
1870 | } elsif ($sym == SDLK_QUOTE) { |
|
|
1871 | $self->emit ('activate_console'); |
|
|
1872 | } elsif ($sym == SDLK_SLASH) { |
|
|
1873 | $self->emit ('activate_console' => '/'); |
|
|
1874 | } elsif (exists $DIR{$sym}) { |
|
|
1875 | if ($mod & KMOD_SHIFT) { |
|
|
1876 | $self->{shft}++; |
|
|
1877 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
|
|
1878 | } elsif ($mod & KMOD_CTRL) { |
|
|
1879 | $self->{ctrl}++; |
|
|
1880 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
|
|
1881 | } else { |
|
|
1882 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
|
|
1883 | } |
|
|
1884 | } |
|
|
1885 | } |
|
|
1886 | |
|
|
1887 | sub key_up { |
|
|
1888 | my ($self, $ev) = @_; |
|
|
1889 | |
|
|
1890 | my $mod = $ev->key_mod; |
|
|
1891 | my $sym = $ev->key_sym; |
|
|
1892 | |
|
|
1893 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
|
|
1894 | $::CONN->user_send ("command fire_stop"); |
|
|
1895 | } |
|
|
1896 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
1897 | $::CONN->user_send ("command run_stop"); |
|
|
1898 | } |
|
|
1899 | } |
1822 | } |
1900 | |
1823 | |
1901 | ############################################################################# |
1824 | ############################################################################# |
1902 | |
1825 | |
1903 | package CFClient::UI::Animator; |
1826 | package CFClient::UI::Animator; |
… | |
… | |
1985 | |
1908 | |
1986 | our @ISA = CFClient::UI::Container::; |
1909 | our @ISA = CFClient::UI::Container::; |
1987 | |
1910 | |
1988 | use SDL::OpenGL; |
1911 | use SDL::OpenGL; |
1989 | |
1912 | |
|
|
1913 | sub check_size { |
|
|
1914 | my ($self) = @_; |
|
|
1915 | |
|
|
1916 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
|
|
1917 | } |
|
|
1918 | |
1990 | sub size_request { |
1919 | sub size_request { |
1991 | ($::WIDTH, $::HEIGHT) |
1920 | ($::WIDTH, $::HEIGHT) |
1992 | } |
1921 | } |
1993 | |
1922 | |
1994 | sub size_allocate { |
1923 | sub configure { |
1995 | my ($self, $x, $y, $w, $h) = @_; |
1924 | my ($self, $x, $y, $w, $h) = @_; |
1996 | |
1925 | |
1997 | $self->_size_allocate ($x, $y, $w, $h); |
1926 | $self->SUPER::configure ($x, $y, $w, $h); |
1998 | |
1927 | |
1999 | $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) |
1928 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
2000 | for @{$self->{children}}; |
1929 | for @{$self->{children}}; |
2001 | } |
1930 | } |
2002 | |
1931 | |
2003 | sub _topleft { |
1932 | sub _topleft { |
2004 | my ($self, $x, $y) = @_; |
1933 | my ($self, $x, $y) = @_; |
… | |
… | |
2007 | } |
1936 | } |
2008 | |
1937 | |
2009 | sub update { |
1938 | sub update { |
2010 | my ($self) = @_; |
1939 | my ($self) = @_; |
2011 | |
1940 | |
2012 | $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); |
1941 | $self->check_size; |
2013 | ::refresh (); |
1942 | ::refresh (); |
2014 | } |
1943 | } |
2015 | |
1944 | |
2016 | sub add { |
1945 | sub add { |
2017 | my ($self, $widget) = @_; |
1946 | my ($self, $child) = @_; |
2018 | |
1947 | |
2019 | $self->SUPER::add ($widget); |
1948 | $self->SUPER::add ($child); |
2020 | |
|
|
2021 | $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); |
|
|
2022 | } |
1949 | } |
2023 | |
1950 | |
2024 | sub on_refresh { |
1951 | sub on_refresh { |
2025 | my ($self, $id, $cb) = @_; |
1952 | my ($self, $id, $cb) = @_; |
2026 | |
1953 | |