… | |
… | |
24 | my $tip = $widget->{tooltip}; |
24 | my $tip = $widget->{tooltip}; |
25 | |
25 | |
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
27 | |
27 | |
28 | $TOOLTIP->set_markup ($widget->{tooltip}); |
28 | $TOOLTIP->set_markup ($widget->{tooltip}); |
29 | $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); |
29 | |
30 | $TOOLTIP->show; |
30 | $TOOLTIP->show; |
|
|
31 | |
|
|
32 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
|
|
33 | |
|
|
34 | if ($x + $TOOLTIP->{w} > $::WIDTH) { |
|
|
35 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); |
|
|
36 | } |
|
|
37 | |
|
|
38 | $TOOLTIP->move ($x, $y); |
31 | } |
39 | } |
32 | |
40 | |
33 | return; |
41 | return; |
34 | } |
42 | } |
35 | } |
43 | } |
… | |
… | |
229 | $self->{w} = $w; |
237 | $self->{w} = $w; |
230 | $self->{h} = $h; |
238 | $self->{h} = $h; |
231 | |
239 | |
232 | $self->size_allocate ($w, $h); |
240 | $self->size_allocate ($w, $h); |
233 | $self->update; |
241 | $self->update; |
|
|
242 | $self->emit (size_allocate => $w, $h); |
234 | } |
243 | } |
235 | } |
244 | } |
236 | |
245 | |
237 | sub size_allocate { |
246 | sub size_allocate { |
238 | # nothing to be done |
247 | # nothing to be done |
|
|
248 | } |
|
|
249 | |
|
|
250 | sub children { |
|
|
251 | } |
|
|
252 | |
|
|
253 | # call when resolution changes etc. |
|
|
254 | sub reconfigure { |
|
|
255 | my ($self) = @_; |
|
|
256 | |
|
|
257 | $_->reconfigure |
|
|
258 | for $self->children; |
|
|
259 | |
|
|
260 | $self->check_size; |
|
|
261 | $self->size_allocate ($self->{w}, $self->{h}); |
|
|
262 | $self->update; |
239 | } |
263 | } |
240 | |
264 | |
241 | sub set_max_size { |
265 | sub set_max_size { |
242 | my ($self, $w, $h) = @_; |
266 | my ($self, $w, $h) = @_; |
243 | |
267 | |
… | |
… | |
246 | } |
270 | } |
247 | |
271 | |
248 | # return top left coordinates |
272 | # return top left coordinates |
249 | sub _topleft { |
273 | sub _topleft { |
250 | my ($self, $x, $y) = @_; |
274 | my ($self, $x, $y) = @_; |
|
|
275 | |
|
|
276 | $self->{parent} |
|
|
277 | or Carp::confess "no parent widget in _topleft\n";#d# |
251 | |
278 | |
252 | $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); |
279 | $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); |
253 | } |
280 | } |
254 | |
281 | |
255 | # translate global coordinates to local coordinate system |
282 | # translate global coordinates to local coordinate system |
… | |
… | |
376 | } |
403 | } |
377 | |
404 | |
378 | sub check_size { |
405 | sub check_size { |
379 | my ($self) = @_; |
406 | my ($self) = @_; |
380 | |
407 | |
|
|
408 | $self->_check_size; |
|
|
409 | return; |
|
|
410 | #TODO: but needs a vastly more difficult algorithm |
|
|
411 | my $check_size = $CFClient::UI::ROOT->{_check_size} ||= {}; |
|
|
412 | |
|
|
413 | $check_size->{$self} = $self; |
|
|
414 | |
|
|
415 | $CFClient::UI::ROOT->on_refresh (_check_size => sub { |
|
|
416 | while (%$check_size) { |
|
|
417 | my @widgets = values %$check_size; |
|
|
418 | $_->_check_size |
|
|
419 | for @widgets; |
|
|
420 | } |
|
|
421 | }); |
|
|
422 | } |
|
|
423 | |
|
|
424 | sub _check_size { |
|
|
425 | my ($self) = @_; |
|
|
426 | |
|
|
427 | delete $CFClient::UI::ROOT->{_check_size}{$self}; |
|
|
428 | |
381 | $self->{parent} |
429 | $self->{parent} |
382 | or return 1; |
430 | or return 1; |
383 | |
431 | |
384 | my ($w, $h) = $self->{user_w} && $self->{user_h} |
432 | my ($w, $h) = $self->{user_w} && $self->{user_h} |
385 | ? @$self{qw(user_w user_h)} |
433 | ? @$self{qw(user_w user_h)} |
… | |
… | |
387 | |
435 | |
388 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
436 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
389 | $self->{req_w} = $w; |
437 | $self->{req_w} = $w; |
390 | $self->{req_h} = $h; |
438 | $self->{req_h} = $h; |
391 | |
439 | |
392 | $self->{parent}->check_size |
440 | $self->{parent}->_check_size |
393 | or $self->size_allocate ( |
441 | or $self->size_allocate ( |
394 | (List::Util::max $self->{w}, $w), |
442 | (List::Util::max $self->{w}, $w), |
395 | (List::Util::max $self->{h}, $h), |
443 | (List::Util::max $self->{h}, $h), |
396 | ); |
444 | ); |
397 | |
445 | |
… | |
… | |
402 | } |
450 | } |
403 | |
451 | |
404 | sub update { |
452 | sub update { |
405 | my ($self) = @_; |
453 | my ($self) = @_; |
406 | |
454 | |
407 | $self->{parent}->update |
455 | my $update = $CFClient::UI::ROOT->{_update} ||= {}; |
408 | if $self->{parent}; |
456 | |
|
|
457 | $update->{$self} = $self; |
|
|
458 | |
|
|
459 | $CFClient::UI::ROOT->on_refresh (_update => sub { |
|
|
460 | while (%$update) { |
|
|
461 | my @widgets = values %$update; |
|
|
462 | %$update = (); |
|
|
463 | |
|
|
464 | $_->{parent} && $_->{parent}->update |
|
|
465 | for @widgets; |
|
|
466 | } |
|
|
467 | }); |
409 | } |
468 | } |
410 | |
469 | |
411 | sub connect { |
470 | sub connect { |
412 | my ($self, $signal, $cb) = @_; |
471 | my ($self, $signal, $cb) = @_; |
413 | |
472 | |
… | |
… | |
503 | |
562 | |
504 | $self |
563 | $self |
505 | } |
564 | } |
506 | |
565 | |
507 | sub add { |
566 | sub add { |
508 | my ($self, $child) = @_; |
567 | my ($self, @widgets) = @_; |
509 | |
568 | |
510 | $child->set_parent ($self); |
569 | $_->set_parent ($self) |
|
|
570 | for @widgets; |
511 | |
571 | |
512 | use sort 'stable'; |
572 | use sort 'stable'; |
513 | |
573 | |
514 | $self->{children} = [ |
574 | $self->{children} = [ |
515 | sort { $a->{z} <=> $b->{z} } |
575 | sort { $a->{z} <=> $b->{z} } |
516 | @{$self->{children}}, $child |
576 | @{$self->{children}}, @widgets |
517 | ]; |
577 | ]; |
518 | |
578 | |
519 | $child->check_size; |
579 | $_->check_size |
|
|
580 | for @widgets; |
|
|
581 | |
|
|
582 | $self->update; |
|
|
583 | } |
|
|
584 | |
|
|
585 | sub children { |
|
|
586 | @{ $_[0]{children} } |
520 | } |
587 | } |
521 | |
588 | |
522 | sub remove { |
589 | sub remove { |
523 | my ($self, $child) = @_; |
590 | my ($self, $child) = @_; |
524 | |
591 | |
… | |
… | |
539 | |
606 | |
540 | for (@$children) { |
607 | for (@$children) { |
541 | delete $_->{parent}; |
608 | delete $_->{parent}; |
542 | $_->hide; |
609 | $_->hide; |
543 | } |
610 | } |
|
|
611 | |
|
|
612 | $self->check_size; |
|
|
613 | $self->update; |
544 | } |
614 | } |
545 | |
615 | |
546 | sub find_widget { |
616 | sub find_widget { |
547 | my ($self, $x, $y) = @_; |
617 | my ($self, $x, $y) = @_; |
548 | |
618 | |
… | |
… | |
623 | } |
693 | } |
624 | |
694 | |
625 | sub update { |
695 | sub update { |
626 | my ($self) = @_; |
696 | my ($self) = @_; |
627 | |
697 | |
628 | # we want to do this delayed... |
698 | $ROOT->on_refresh ($self => sub { $self->render_child }); |
629 | $self->render_chld; |
|
|
630 | $self->SUPER::update; |
699 | $self->SUPER::update; |
631 | } |
|
|
632 | |
|
|
633 | sub render_chld { |
|
|
634 | my ($self) = @_; |
|
|
635 | |
|
|
636 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
|
|
637 | glClearColor 0, 0, 0, 1; |
|
|
638 | glClear GL_COLOR_BUFFER_BIT; |
|
|
639 | $self->child->draw; |
|
|
640 | }; |
|
|
641 | } |
700 | } |
642 | |
701 | |
643 | sub size_allocate { |
702 | sub size_allocate { |
644 | my ($self, $w, $h) = @_; |
703 | my ($self, $w, $h) = @_; |
645 | |
704 | |
646 | $self->child->configure (0, 0, $w, $h); |
705 | $self->SUPER::size_allocate ($w, $h); |
|
|
706 | $self->update; |
|
|
707 | } |
647 | |
708 | |
|
|
709 | sub _render { |
|
|
710 | $_[0]{children}[0]->draw; |
|
|
711 | } |
|
|
712 | |
|
|
713 | sub render_child { |
|
|
714 | my ($self) = @_; |
|
|
715 | |
|
|
716 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
|
|
717 | glClearColor 0, 0, 0, 0; |
|
|
718 | glClear GL_COLOR_BUFFER_BIT; |
|
|
719 | |
648 | $self->render_chld; |
720 | $self->_render; |
|
|
721 | # glColorMask 1, 1, 1, 0; |
|
|
722 | # glEnable GL_BLEND; |
|
|
723 | # glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
|
|
724 | # glRasterPos 0, 0; |
|
|
725 | # glCopyPixels 0, 0, $self->{w}, $self->{h}; |
|
|
726 | # glDisable GL_BLEND; |
|
|
727 | # glColorMask 1, 1, 1, 1; |
|
|
728 | }; |
649 | } |
729 | } |
650 | |
730 | |
651 | sub _draw { |
731 | sub _draw { |
652 | my ($self) = @_; |
732 | my ($self) = @_; |
653 | |
733 | |
… | |
… | |
655 | |
735 | |
656 | my $tex = $self->{texture} |
736 | my $tex = $self->{texture} |
657 | or return; |
737 | or return; |
658 | |
738 | |
659 | glEnable GL_BLEND; |
739 | glEnable GL_BLEND; |
660 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
740 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
661 | glEnable GL_TEXTURE_2D; |
741 | glEnable GL_TEXTURE_2D; |
662 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
742 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
743 | glColor 0, 0, 0, 1; |
663 | |
744 | |
664 | $tex->draw_quad (0, 0, $w, $h); |
745 | $tex->draw_quad (0, 0, $w, $h); |
665 | |
746 | |
666 | glDisable GL_BLEND; |
747 | glDisable GL_BLEND; |
667 | glDisable GL_TEXTURE_2D; |
748 | glDisable GL_TEXTURE_2D; |
… | |
… | |
671 | |
752 | |
672 | package CFClient::UI::ViewPort; |
753 | package CFClient::UI::ViewPort; |
673 | |
754 | |
674 | our @ISA = CFClient::UI::Window::; |
755 | our @ISA = CFClient::UI::Window::; |
675 | |
756 | |
676 | sub new { die } |
|
|
677 | |
|
|
678 | sub size_request { |
757 | sub size_request { |
679 | my ($self) = @_; |
758 | my ($self) = @_; |
680 | |
759 | |
681 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
760 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
682 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
761 | $self->child->configure (0, 0, @$self{qw(child_w child_h)}); |
683 | |
762 | |
684 | @$self{qw(child_w child_h)} |
763 | @$self{qw(child_w child_h)} |
685 | } |
764 | } |
686 | |
765 | |
687 | sub _draw { |
766 | sub size_allocate { |
688 | my ($self) = @_; |
767 | my ($self, $w, $h) = @_; |
689 | |
768 | |
690 | $self->{children}[1]->draw; |
769 | $self->update; |
691 | } |
770 | } |
692 | |
771 | |
|
|
772 | sub set_offset { |
|
|
773 | my ($self, $x, $y) = @_; |
|
|
774 | |
|
|
775 | $self->{view_x} = int $x; |
|
|
776 | $self->{view_y} = int $y; |
|
|
777 | |
|
|
778 | $self->update; |
|
|
779 | } |
|
|
780 | |
|
|
781 | # hmm, this does not work for topleft of $self... but we should not aks for that |
|
|
782 | sub _topleft { |
|
|
783 | my ($self, $x, $y) = @_; |
|
|
784 | |
|
|
785 | $self->SUPER::_topleft ($x - $self->{view_x}, $y - $self->{view_y}) |
|
|
786 | } |
|
|
787 | |
|
|
788 | sub find_widget { |
|
|
789 | my ($self, $x, $y) = @_; |
|
|
790 | |
|
|
791 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
792 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
|
|
793 | ) { |
|
|
794 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
|
|
795 | } else { |
|
|
796 | $self->CFClient::UI::Base::find_widget ($x, $y) |
|
|
797 | } |
|
|
798 | } |
|
|
799 | |
|
|
800 | sub _render { |
|
|
801 | my ($self) = @_; |
|
|
802 | |
|
|
803 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
|
|
804 | |
|
|
805 | $self->SUPER::_render; |
|
|
806 | } |
|
|
807 | |
|
|
808 | ############################################################################# |
|
|
809 | |
|
|
810 | package CFClient::UI::ScrolledWindow; |
|
|
811 | |
|
|
812 | our @ISA = CFClient::UI::HBox::; |
|
|
813 | |
|
|
814 | sub new { |
|
|
815 | my $class = shift; |
|
|
816 | |
|
|
817 | my $self; |
|
|
818 | |
|
|
819 | my $slider = new CFClient::UI::Slider |
|
|
820 | vertical => 1, |
|
|
821 | range => [0, 0, 1, 0.01], # HACK fix |
|
|
822 | connect_changed => sub { |
|
|
823 | $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); |
|
|
824 | }, |
|
|
825 | ; |
|
|
826 | |
|
|
827 | $self = $class->SUPER::new ( |
|
|
828 | vp => (new CFClient::UI::ViewPort), |
|
|
829 | slider => $slider, |
|
|
830 | @_, |
|
|
831 | ); |
|
|
832 | |
|
|
833 | $self->{vp}->add ($self->{scrolled}); |
|
|
834 | $self->add ($self->{vp}); |
|
|
835 | $self->add ($self->{slider}); |
|
|
836 | |
|
|
837 | $self |
|
|
838 | } |
|
|
839 | |
|
|
840 | #TODO# update range on size_allocate depeneing on child |
|
|
841 | # update viewport offset on scroll |
693 | |
842 | |
694 | ############################################################################# |
843 | ############################################################################# |
695 | |
844 | |
696 | package CFClient::UI::Frame; |
845 | package CFClient::UI::Frame; |
697 | |
846 | |
… | |
… | |
754 | # TODO: user_x, user_y, overwrite moveto? |
903 | # TODO: user_x, user_y, overwrite moveto? |
755 | |
904 | |
756 | my $self = $class->SUPER::new ( |
905 | my $self = $class->SUPER::new ( |
757 | bg => [1, 1, 1, 1], |
906 | bg => [1, 1, 1, 1], |
758 | border_bg => [1, 1, 1, 1], |
907 | border_bg => [1, 1, 1, 1], |
759 | border => 0.8, |
908 | border => 0.6, |
760 | can_events => 1, |
909 | can_events => 1, |
761 | @_ |
910 | @_ |
762 | ); |
911 | ); |
763 | |
912 | |
764 | $self->{title} &&= new CFClient::UI::Label |
913 | $self->{title} &&= new CFClient::UI::Label |
765 | align => 0, |
914 | align => 0, |
766 | valign => 1, |
915 | valign => 1, |
767 | text => $self->{title}, |
916 | text => $self->{title}, |
768 | fontsize => 1; |
917 | fontsize => $self->{border}; |
769 | |
918 | |
770 | $self |
919 | $self |
771 | } |
920 | } |
772 | |
921 | |
773 | sub border { |
922 | sub border { |
… | |
… | |
798 | } |
947 | } |
799 | |
948 | |
800 | sub button_down { |
949 | sub button_down { |
801 | my ($self, $ev, $x, $y) = @_; |
950 | my ($self, $ev, $x, $y) = @_; |
802 | |
951 | |
|
|
952 | my ($w, $h) = @$self{qw(w h)}; |
803 | my $border = $self->border; |
953 | my $border = $self->border; |
804 | |
954 | |
805 | if ($x < $self->{w} && $x >= $self->{w} - $border |
955 | my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w); |
806 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
956 | my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h); |
807 | |
957 | |
|
|
958 | if ($lr & $td) { |
|
|
959 | my ($wx, $wy) = ($self->{x}, $self->{y}); |
808 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
960 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
809 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
961 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
810 | |
962 | |
|
|
963 | my $mx = $x < $border; |
|
|
964 | my $my = $y < $border; |
|
|
965 | |
811 | $self->{motion} = sub { |
966 | $self->{motion} = sub { |
812 | my ($ev, $x, $y) = @_; |
967 | my ($ev, $x, $y) = @_; |
813 | |
968 | |
814 | ($x, $y) = ($ev->{x}, $ev->{y}); |
969 | my $dx = $ev->{x} - $ox; |
|
|
970 | my $dy = $ev->{y} - $oy; |
815 | |
971 | |
816 | $self->{user_w} = $bw + $x - $ox; |
972 | $self->{user_w} = $bw + $dx * ($mx ? -1 : 1); |
817 | $self->{user_h} = $bh + $y - $oy; |
973 | $self->{user_h} = $bh + $dy * ($my ? -1 : 1); |
|
|
974 | $self->move ($wx + $dx * $mx, $wy + $dy * $my); |
818 | $self->check_size; |
975 | $self->check_size; |
819 | }; |
976 | }; |
820 | |
977 | |
821 | } elsif ($x >= 0 && $x < $self->{w} |
978 | } elsif ($lr ^ $td) { |
822 | && $y >= 0 && $y < $border) { |
|
|
823 | |
|
|
824 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
979 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
825 | my ($bx, $by) = ($self->{x}, $self->{y}); |
980 | my ($bx, $by) = ($self->{x}, $self->{y}); |
826 | |
981 | |
827 | $self->{motion} = sub { |
982 | $self->{motion} = sub { |
828 | my ($ev, $x, $y) = @_; |
983 | my ($ev, $x, $y) = @_; |
… | |
… | |
864 | $tex[1]->draw_quad (0, 0, $w, $border); |
1019 | $tex[1]->draw_quad (0, 0, $w, $border); |
865 | $tex[3]->draw_quad (0, $border, $border, $ch); |
1020 | $tex[3]->draw_quad (0, $border, $border, $ch); |
866 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
1021 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
867 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
1022 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
868 | |
1023 | |
|
|
1024 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
869 | my $bg = $tex[0]; |
1025 | my $bg = $tex[0]; |
870 | |
1026 | |
871 | # TODO: repeat texture not scale |
1027 | # TODO: repeat texture not scale |
872 | my $rep_x = $cw / $bg->{w}; |
1028 | my $rep_x = $cw / $bg->{w}; |
873 | my $rep_y = $ch / $bg->{h}; |
1029 | my $rep_y = $ch / $bg->{h}; |
874 | |
1030 | |
875 | glColor @{ $self->{bg} }; |
1031 | glColor @{ $self->{bg} }; |
876 | |
1032 | |
877 | $bg->{s} = $rep_x; |
1033 | $bg->{s} = $rep_x; |
878 | $bg->{t} = $rep_y; |
1034 | $bg->{t} = $rep_y; |
879 | $bg->{wrap_mode} = 1; |
1035 | $bg->{wrap_mode} = 1; |
880 | $bg->draw_quad ($border, $border, $cw, $ch); |
1036 | $bg->draw_quad ($border, $border, $cw, $ch); |
881 | |
1037 | |
882 | glDisable GL_TEXTURE_2D; |
1038 | glDisable GL_TEXTURE_2D; |
883 | glDisable GL_BLEND; |
1039 | glDisable GL_BLEND; |
|
|
1040 | } |
884 | |
1041 | |
885 | $self->{title}->draw if $self->{title}; |
1042 | $self->{title}->draw if $self->{title}; |
|
|
1043 | |
886 | $self->child->draw; |
1044 | $self->child->draw; |
887 | } |
1045 | } |
888 | |
1046 | |
889 | ############################################################################# |
1047 | ############################################################################# |
890 | |
1048 | |
… | |
… | |
912 | $self->{children}[$y][$x] = $child; |
1070 | $self->{children}[$y][$x] = $child; |
913 | |
1071 | |
914 | $child->check_size; |
1072 | $child->check_size; |
915 | } |
1073 | } |
916 | |
1074 | |
|
|
1075 | sub children { |
|
|
1076 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1077 | } |
|
|
1078 | |
917 | # TODO: move to container class maybe? send childs a signal on removal? |
1079 | # TODO: move to container class maybe? send childs a signal on removal? |
918 | sub clear { |
1080 | sub clear { |
919 | my ($self) = @_; |
1081 | my ($self) = @_; |
920 | |
1082 | |
921 | my $children = delete $self->{children}; |
1083 | my @children = $self->children; |
|
|
1084 | delete $self->{children}; |
922 | |
1085 | |
923 | for (grep $_, map @$_, grep $_, @$children) { |
1086 | for (@children) { |
924 | delete $_->{parent}; |
1087 | delete $_->{parent}; |
925 | $_->hide; |
1088 | $_->hide; |
926 | } |
1089 | } |
927 | |
1090 | |
928 | $self->update; |
1091 | $self->update; |
… | |
… | |
1189 | s/</</g; |
1352 | s/</</g; |
1190 | |
1353 | |
1191 | $_[1] |
1354 | $_[1] |
1192 | } |
1355 | } |
1193 | |
1356 | |
|
|
1357 | sub update { |
|
|
1358 | my ($self) = @_; |
|
|
1359 | |
|
|
1360 | delete $self->{texture}; |
|
|
1361 | $self->SUPER::update; |
|
|
1362 | } |
|
|
1363 | |
1194 | sub set_text { |
1364 | sub set_text { |
1195 | my ($self, $text) = @_; |
1365 | my ($self, $text) = @_; |
1196 | |
1366 | |
|
|
1367 | return if $self->{text} eq "T$text"; |
|
|
1368 | $self->{text} = "T$text"; |
|
|
1369 | |
1197 | $self->{layout}->set_text ($text); |
1370 | $self->{layout}->set_text ($text); |
1198 | |
1371 | |
1199 | delete $self->{texture}; |
1372 | delete $self->{texture}; |
|
|
1373 | $self->update; |
1200 | $self->check_size; |
1374 | $self->check_size; |
1201 | $self->update; |
|
|
1202 | } |
1375 | } |
1203 | |
1376 | |
1204 | sub set_markup { |
1377 | sub set_markup { |
1205 | my ($self, $markup) = @_; |
1378 | my ($self, $markup) = @_; |
1206 | |
1379 | |
|
|
1380 | return if $self->{text} eq "M$markup"; |
|
|
1381 | $self->{text} = "M$markup"; |
|
|
1382 | |
1207 | $self->{layout}->set_markup ($markup); |
1383 | $self->{layout}->set_markup ($markup); |
1208 | |
1384 | |
1209 | delete $self->{texture}; |
1385 | delete $self->{texture}; |
|
|
1386 | $self->update; |
1210 | $self->check_size; |
1387 | $self->check_size; |
1211 | $self->update; |
|
|
1212 | } |
1388 | } |
1213 | |
1389 | |
1214 | sub size_request { |
1390 | sub size_request { |
1215 | my ($self) = @_; |
1391 | my ($self) = @_; |
1216 | |
1392 | |
… | |
… | |
1245 | sub set_fontsize { |
1421 | sub set_fontsize { |
1246 | my ($self, $fontsize) = @_; |
1422 | my ($self, $fontsize) = @_; |
1247 | |
1423 | |
1248 | $self->{fontsize} = $fontsize; |
1424 | $self->{fontsize} = $fontsize; |
1249 | delete $self->{texture}; |
1425 | delete $self->{texture}; |
|
|
1426 | |
|
|
1427 | $self->update; |
1250 | $self->check_size; |
1428 | $self->check_size; |
1251 | $self->update; |
|
|
1252 | } |
1429 | } |
1253 | |
1430 | |
1254 | sub _draw { |
1431 | sub _draw { |
1255 | my ($self) = @_; |
1432 | my ($self) = @_; |
1256 | |
1433 | |
… | |
… | |
1469 | |
1646 | |
1470 | if ($sym == 13) { |
1647 | if ($sym == 13) { |
1471 | unshift @{$self->{history}}, |
1648 | unshift @{$self->{history}}, |
1472 | my $txt = $self->get_text; |
1649 | my $txt = $self->get_text; |
1473 | $self->{history_pointer} = -1; |
1650 | $self->{history_pointer} = -1; |
|
|
1651 | $self->{history_saveback} = ''; |
1474 | $self->emit (activate => $txt); |
1652 | $self->emit (activate => $txt); |
1475 | $self->update; |
1653 | $self->update; |
1476 | |
1654 | |
1477 | } elsif ($sym == CFClient::SDLK_UP) { |
1655 | } elsif ($sym == CFClient::SDLK_UP) { |
1478 | if ($self->{history_pointer} < 0) { |
1656 | if ($self->{history_pointer} < 0) { |
1479 | $self->{history_saveback} = $self->get_text; |
1657 | $self->{history_saveback} = $self->get_text; |
1480 | } |
1658 | } |
|
|
1659 | if (@{$self->{history} || []} > 0) { |
1481 | $self->{history_pointer}++; |
1660 | $self->{history_pointer}++; |
1482 | if ($self->{history_pointer} >= @{$self->{history}}) { |
1661 | if ($self->{history_pointer} >= @{$self->{history} || []}) { |
1483 | $self->{history_pointer} = @{$self->{history}} - 1; |
1662 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
|
|
1663 | } |
|
|
1664 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
1484 | } |
1665 | } |
1485 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
|
|
1486 | |
1666 | |
1487 | } elsif ($sym == CFClient::SDLK_DOWN) { |
1667 | } elsif ($sym == CFClient::SDLK_DOWN) { |
1488 | $self->{history_pointer}--; |
1668 | $self->{history_pointer}--; |
1489 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
1669 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
1490 | |
1670 | |
… | |
… | |
1737 | } |
1917 | } |
1738 | |
1918 | |
1739 | sub set_max { |
1919 | sub set_max { |
1740 | my ($self, $max) = @_; |
1920 | my ($self, $max) = @_; |
1741 | |
1921 | |
|
|
1922 | return if $self->{max_val} == $max; |
|
|
1923 | |
1742 | $self->{max_val} = $max; |
1924 | $self->{max_val} = $max; |
|
|
1925 | $self->update; |
1743 | } |
1926 | } |
1744 | |
1927 | |
1745 | sub set_value { |
1928 | sub set_value { |
1746 | my ($self, $val, $max) = @_; |
1929 | my ($self, $val, $max) = @_; |
1747 | |
1930 | |
1748 | $self->set_max ($max) |
1931 | $self->set_max ($max) |
1749 | if defined $max; |
1932 | if defined $max; |
1750 | |
1933 | |
1751 | $max = $self->{max_val}; |
1934 | return if $self->{val} == $val; |
|
|
1935 | |
1752 | $self->{val} = $val; |
1936 | $self->{val} = $val; |
1753 | |
|
|
1754 | $self->update; |
1937 | $self->update; |
1755 | } |
1938 | } |
1756 | |
1939 | |
1757 | sub _draw { |
1940 | sub _draw { |
1758 | my ($self) = @_; |
1941 | my ($self) = @_; |
… | |
… | |
1821 | |
2004 | |
1822 | sub new { |
2005 | sub new { |
1823 | my ($class, %arg) = @_; |
2006 | my ($class, %arg) = @_; |
1824 | |
2007 | |
1825 | my $self = $class->SUPER::new ( |
2008 | my $self = $class->SUPER::new ( |
1826 | tooltip => $arg{type}, |
2009 | tooltip => $arg{type}, |
1827 | can_hover => 1, |
2010 | can_hover => 1, |
|
|
2011 | can_events => 1, |
1828 | %arg, |
2012 | %arg, |
1829 | ); |
2013 | ); |
1830 | |
2014 | |
1831 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
2015 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1832 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
2016 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
… | |
… | |
1840 | |
2024 | |
1841 | $self->{value}->set_fontsize ($fsize); |
2025 | $self->{value}->set_fontsize ($fsize); |
1842 | $self->{max} ->set_fontsize ($fsize); |
2026 | $self->{max} ->set_fontsize ($fsize); |
1843 | } |
2027 | } |
1844 | |
2028 | |
|
|
2029 | sub set_max { |
|
|
2030 | my ($self, $max) = @_; |
|
|
2031 | |
|
|
2032 | $self->{gauge}->set_max ($max); |
|
|
2033 | $self->{max}->set_text ($max); |
|
|
2034 | } |
|
|
2035 | |
1845 | sub set_value { |
2036 | sub set_value { |
1846 | my ($self, $val, $max) = @_; |
2037 | my ($self, $val, $max) = @_; |
1847 | |
2038 | |
1848 | $self->set_max ($max) |
2039 | $self->set_max ($max) |
1849 | if defined $max; |
2040 | if defined $max; |
1850 | |
2041 | |
1851 | $self->{gauge}->set_value ($val, $max); |
2042 | $self->{gauge}->set_value ($val, $max); |
1852 | $self->{value}->set_text ($val); |
2043 | $self->{value}->set_text ($val); |
1853 | } |
|
|
1854 | |
|
|
1855 | sub set_max { |
|
|
1856 | my ($self, $max) = @_; |
|
|
1857 | |
|
|
1858 | $self->{gauge}->set_max ($max); |
|
|
1859 | $self->{max}->set_text ($max); |
|
|
1860 | } |
2044 | } |
1861 | |
2045 | |
1862 | ############################################################################# |
2046 | ############################################################################# |
1863 | |
2047 | |
1864 | package CFClient::UI::Slider; |
2048 | package CFClient::UI::Slider; |
… | |
… | |
1883 | # TODO: calculations are off |
2067 | # TODO: calculations are off |
1884 | my $self = $class->SUPER::new ( |
2068 | my $self = $class->SUPER::new ( |
1885 | fg => [1, 1, 1], |
2069 | fg => [1, 1, 1], |
1886 | active_fg => [0, 0, 0], |
2070 | active_fg => [0, 0, 0], |
1887 | range => [0, 0, 100, 10], |
2071 | range => [0, 0, 100, 10], |
1888 | req_w => 20, |
2072 | req_w => $::WIDTH / 80, |
1889 | req_h => 20, |
2073 | req_h => $::WIDTH / 80, |
1890 | vertical => 0, |
2074 | vertical => 0, |
1891 | can_hover => 1, |
2075 | can_hover => 1, |
1892 | inner_pad => 5, |
2076 | inner_pad => 5, |
1893 | @_ |
2077 | @_ |
1894 | ); |
2078 | ); |
… | |
… | |
2018 | (new CFClient::UI::Empty expand => 1), |
2202 | (new CFClient::UI::Empty expand => 1), |
2019 | (new CFClient::UI::Slider vertical => 1), |
2203 | (new CFClient::UI::Slider vertical => 1), |
2020 | ], |
2204 | ], |
2021 | ); |
2205 | ); |
2022 | |
2206 | |
2023 | $self->{children}[1]->connect (changed => sub { |
2207 | $self->{children}[1]->connect (changed => sub { $self->update }); |
2024 | $self->update; |
|
|
2025 | }); |
|
|
2026 | |
2208 | |
2027 | $self |
2209 | $self |
2028 | } |
2210 | } |
2029 | |
2211 | |
2030 | sub set_fontsize { |
2212 | sub set_fontsize { |
… | |
… | |
2038 | my ($self, $text) = @_; |
2220 | my ($self, $text) = @_; |
2039 | |
2221 | |
2040 | my $layout = $self->{layout}; |
2222 | my $layout = $self->{layout}; |
2041 | |
2223 | |
2042 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2224 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2043 | $layout->set_width ($self->{w}); |
2225 | $layout->set_width ($self->{children}[0]{w}); |
2044 | $layout->set_text ($text); |
2226 | $layout->set_text ($text); |
2045 | |
2227 | |
2046 | ($layout->size)[1] |
2228 | ($layout->size)[1] |
2047 | } |
2229 | } |
2048 | |
2230 | |
… | |
… | |
2101 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
2283 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
2102 | |
2284 | |
2103 | delete $self->{texture}; |
2285 | delete $self->{texture}; |
2104 | } |
2286 | } |
2105 | |
2287 | |
2106 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
2288 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2107 | glClearColor 0, 0, 0, 1; |
2289 | glClearColor 0, 0, 0, 0; |
2108 | glClear GL_COLOR_BUFFER_BIT; |
2290 | glClear GL_COLOR_BUFFER_BIT; |
2109 | |
2291 | |
2110 | glEnable GL_BLEND; |
2292 | glEnable GL_BLEND; |
2111 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2293 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2112 | glEnable GL_TEXTURE_2D; |
2294 | glEnable GL_TEXTURE_2D; |
… | |
… | |
2144 | } |
2326 | } |
2145 | |
2327 | |
2146 | sub _draw { |
2328 | sub _draw { |
2147 | my ($self) = @_; |
2329 | my ($self) = @_; |
2148 | |
2330 | |
2149 | if ($self->{texture}) { |
2331 | glEnable GL_BLEND; |
|
|
2332 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2150 | glEnable GL_TEXTURE_2D; |
2333 | glEnable GL_TEXTURE_2D; |
2151 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2334 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2335 | glColor 1, 1, 1, 1; |
2152 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
2336 | $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2153 | glDisable GL_TEXTURE_2D; |
2337 | glDisable GL_TEXTURE_2D; |
2154 | } |
2338 | glDisable GL_BLEND; |
2155 | |
2339 | |
2156 | $self->{children}[1]->draw; |
2340 | $self->{children}[1]->draw; |
2157 | |
2341 | |
2158 | } |
2342 | } |
2159 | |
2343 | |
… | |
… | |
2328 | |
2512 | |
2329 | sub size_request { |
2513 | sub size_request { |
2330 | (32, 8) |
2514 | (32, 8) |
2331 | } |
2515 | } |
2332 | |
2516 | |
2333 | sub draw { |
2517 | sub _draw { |
2334 | my ($self) = @_; |
2518 | my ($self) = @_; |
2335 | |
2519 | |
|
|
2520 | return unless $::CONN;#d# manage and cache textures differently |
2336 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2521 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2337 | |
2522 | |
|
|
2523 | # TODO animation |
2338 | if ($tex) { |
2524 | if ($tex) { |
2339 | glEnable GL_BLEND; |
2525 | glEnable GL_BLEND; |
2340 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2526 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2341 | glEnable GL_TEXTURE_2D; |
2527 | glEnable GL_TEXTURE_2D; |
2342 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2528 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
… | |
… | |
2347 | } |
2533 | } |
2348 | } |
2534 | } |
2349 | |
2535 | |
2350 | ############################################################################# |
2536 | ############################################################################# |
2351 | |
2537 | |
|
|
2538 | package CFClient::UI::InventoryItem; |
|
|
2539 | |
|
|
2540 | our @ISA = CFClient::UI::HBox::; |
|
|
2541 | |
|
|
2542 | sub new { |
|
|
2543 | my $class = shift; |
|
|
2544 | |
|
|
2545 | my %args = @_; |
|
|
2546 | |
|
|
2547 | my $item = $args{item}; |
|
|
2548 | |
|
|
2549 | my $desc = $item->{nrof} < 2 |
|
|
2550 | ? $item->{name} |
|
|
2551 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2552 | |
|
|
2553 | |
|
|
2554 | my $self = $class->SUPER::new ( |
|
|
2555 | can_hover => 1, |
|
|
2556 | can_events => 1, |
|
|
2557 | tooltip => (CFClient::UI::Label->escape ($desc) |
|
|
2558 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
2559 | connect_button_down => sub { |
|
|
2560 | my ($self, $ev, $x, $y) = @_; |
|
|
2561 | |
|
|
2562 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
2563 | if ($ev->{button} == 1) { |
|
|
2564 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
|
|
2565 | } elsif ($ev->{button} == 2) { |
|
|
2566 | $::CONN->send ("apply $item->{tag}"); |
|
|
2567 | } elsif ($ev->{button} == 3) { |
|
|
2568 | CFClient::UI::Menu->new ( |
|
|
2569 | items => [ |
|
|
2570 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
|
|
2571 | [ |
|
|
2572 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
|
|
2573 | sub { $::CONN->send ("lock $item->{tag}") }, |
|
|
2574 | ], |
|
|
2575 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
|
|
2576 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2577 | ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }], |
|
|
2578 | ], |
|
|
2579 | )->popup ($ev); |
|
|
2580 | } |
|
|
2581 | |
|
|
2582 | 1 |
|
|
2583 | }, |
|
|
2584 | %args |
|
|
2585 | ); |
|
|
2586 | $self->add(new CFClient::UI::Face |
|
|
2587 | can_events => 0, |
|
|
2588 | face => $item->{face}, |
|
|
2589 | anim => $item->{anim}, |
|
|
2590 | animspeed => $item->{animspeed}); |
|
|
2591 | $self->add(new CFClient::UI::Label |
|
|
2592 | can_events => 0, |
|
|
2593 | text => $desc); |
|
|
2594 | |
|
|
2595 | $self |
|
|
2596 | } |
|
|
2597 | |
|
|
2598 | ############################################################################# |
|
|
2599 | |
|
|
2600 | package CFClient::UI::Inventory; |
|
|
2601 | |
|
|
2602 | our @ISA = CFClient::UI::ScrolledWindow::; |
|
|
2603 | |
|
|
2604 | sub new { |
|
|
2605 | my $class = shift; |
|
|
2606 | |
|
|
2607 | my $self = $class->SUPER::new ( |
|
|
2608 | scrolled => (new CFClient::UI::VBox), |
|
|
2609 | @_, |
|
|
2610 | ); |
|
|
2611 | |
|
|
2612 | $self |
|
|
2613 | } |
|
|
2614 | |
|
|
2615 | sub set_items { |
|
|
2616 | my ($self, $items) = @_; |
|
|
2617 | |
|
|
2618 | $self->{scrolled}->clear; |
|
|
2619 | return unless $items; |
|
|
2620 | |
|
|
2621 | my @items = sort { $a->{type} <=> $b->{type} } @$items; |
|
|
2622 | |
|
|
2623 | $self->{real_items} = \@items; |
|
|
2624 | |
|
|
2625 | for my $item (@items) { |
|
|
2626 | my $desc = $item->{nrof} < 2 |
|
|
2627 | ? $item->{name} |
|
|
2628 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2629 | |
|
|
2630 | $self->{scrolled}->add (new CFClient::UI::InventoryItem item => $item); |
|
|
2631 | } |
|
|
2632 | |
|
|
2633 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
|
|
2634 | } |
|
|
2635 | |
|
|
2636 | sub size_request { |
|
|
2637 | my ($self) = @_; |
|
|
2638 | ($self->{req_w}, $self->{req_h}); |
|
|
2639 | } |
|
|
2640 | |
|
|
2641 | ############################################################################# |
|
|
2642 | |
|
|
2643 | package CFClient::UI::Menu; |
|
|
2644 | |
|
|
2645 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
2646 | |
|
|
2647 | use CFClient::OpenGL; |
|
|
2648 | |
|
|
2649 | sub new { |
|
|
2650 | my $class = shift; |
|
|
2651 | |
|
|
2652 | my $self = $class->SUPER::new ( |
|
|
2653 | items => [], |
|
|
2654 | z => 100, |
|
|
2655 | @_, |
|
|
2656 | ); |
|
|
2657 | |
|
|
2658 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
|
|
2659 | |
|
|
2660 | for my $item (@{ $self->{items} }) { |
|
|
2661 | my ($widget, $cb) = @$item; |
|
|
2662 | |
|
|
2663 | # handle various types of items, only text for now |
|
|
2664 | if (!ref $widget) { |
|
|
2665 | $widget = new CFClient::UI::Label |
|
|
2666 | can_hover => 1, |
|
|
2667 | can_events => 1, |
|
|
2668 | text => $widget; |
|
|
2669 | } |
|
|
2670 | |
|
|
2671 | $self->{item}{$widget} = $item; |
|
|
2672 | |
|
|
2673 | $self->{vbox}->add ($widget); |
|
|
2674 | } |
|
|
2675 | |
|
|
2676 | $self |
|
|
2677 | } |
|
|
2678 | |
|
|
2679 | # popup given the event (must be a mouse button down event currently) |
|
|
2680 | sub popup { |
|
|
2681 | my ($self, $ev) = @_; |
|
|
2682 | |
|
|
2683 | $self->emit ("popdown"); |
|
|
2684 | |
|
|
2685 | # maybe save $GRAB? must be careful about events... |
|
|
2686 | $GRAB = $self; |
|
|
2687 | $self->{button} = $ev->{button}; |
|
|
2688 | |
|
|
2689 | $self->show; |
|
|
2690 | $self->move ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); |
|
|
2691 | } |
|
|
2692 | |
|
|
2693 | sub mouse_motion { |
|
|
2694 | my ($self, $ev, $x, $y) = @_; |
|
|
2695 | |
|
|
2696 | # TODO: should use vbox->find_widget or so |
|
|
2697 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
|
|
2698 | $self->{hover} = $self->{item}{$HOVER}; |
|
|
2699 | } |
|
|
2700 | |
|
|
2701 | sub button_up { |
|
|
2702 | my ($self, $ev, $x, $y) = @_; |
|
|
2703 | |
|
|
2704 | if ($ev->{button} == $self->{button}) { |
|
|
2705 | undef $GRAB; |
|
|
2706 | $self->hide; |
|
|
2707 | |
|
|
2708 | $self->emit ("popdown"); |
|
|
2709 | $self->{hover}[1]->() if $self->{hover}; |
|
|
2710 | } |
|
|
2711 | } |
|
|
2712 | |
|
|
2713 | ############################################################################# |
|
|
2714 | |
2352 | package CFClient::UI::Root; |
2715 | package CFClient::UI::Root; |
2353 | |
2716 | |
2354 | our @ISA = CFClient::UI::Container::; |
2717 | our @ISA = CFClient::UI::Container::; |
2355 | |
2718 | |
2356 | use CFClient::OpenGL; |
2719 | use CFClient::OpenGL; |
2357 | |
2720 | |
2358 | sub check_size { |
2721 | sub check_size { |
2359 | my ($self) = @_; |
2722 | my ($self) = @_; |
2360 | |
2723 | |
2361 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
2724 | $self->configure (0, 0, $self->{w}, $self->{h}); |
2362 | } |
2725 | } |
2363 | |
2726 | |
2364 | sub size_request { |
2727 | sub size_request { |
2365 | ($::WIDTH, $::HEIGHT) |
2728 | my ($self) = @_; |
|
|
2729 | |
|
|
2730 | ($self->{w}, $self->{h}) |
|
|
2731 | } |
|
|
2732 | |
|
|
2733 | sub size_allocate { |
|
|
2734 | my ($self, $w, $h) = @_; |
|
|
2735 | |
|
|
2736 | my $old_w = $self->{old_w}; |
|
|
2737 | my $old_h = $self->{old_h}; |
|
|
2738 | |
|
|
2739 | if ($old_w && $old_h) { |
|
|
2740 | for my $child ($self->children) { |
|
|
2741 | $child->{x} = int 0.5 + $child->{x} * $w / $old_w; |
|
|
2742 | $child->{w} = int 0.5 + $child->{w} * $w / $old_w; |
|
|
2743 | $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w}; |
|
|
2744 | $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w}; |
|
|
2745 | $child->{y} = int 0.5 + $child->{y} * $h / $old_h; |
|
|
2746 | $child->{h} = int 0.5 + $child->{h} * $h / $old_h; |
|
|
2747 | $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; |
|
|
2748 | $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h}; |
|
|
2749 | } |
|
|
2750 | } |
|
|
2751 | |
|
|
2752 | $self->{old_w} = $w; |
|
|
2753 | $self->{old_h} = $h; |
2366 | } |
2754 | } |
2367 | |
2755 | |
2368 | sub configure { |
2756 | sub configure { |
2369 | my ($self, $x, $y, $w, $h) = @_; |
2757 | my ($self, $x, $y, $w, $h) = @_; |
2370 | |
2758 | |
2371 | $self->SUPER::configure ($x, $y, $w, $h); |
2759 | $self->SUPER::configure ($x, $y, $w, $h); |
2372 | |
2760 | |
2373 | for my $child (@{$self->{children}}) { |
2761 | for my $child ($self->children) { |
2374 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2762 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2375 | |
2763 | |
2376 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2764 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2377 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2765 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2378 | $child->configure ($X, $Y, $W,$H); |
2766 | $child->configure ($X, $Y, $W, $H); |
2379 | } |
2767 | } |
2380 | } |
2768 | } |
2381 | |
2769 | |
2382 | sub _topleft { |
2770 | sub _topleft { |
2383 | my ($self, $x, $y) = @_; |
2771 | my ($self, $x, $y) = @_; |