ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.57 by root, Mon Apr 10 22:53:49 2006 UTC vs.
Revision 1.59 by root, Tue Apr 11 13:05:12 2006 UTC

34 $GRAB->update if $GRAB; 34 $GRAB->update if $GRAB;
35 } 35 }
36 36
37 $BUTTON_STATE |= 1 << ($ev->button - 1); 37 $BUTTON_STATE |= 1 << ($ev->button - 1);
38 38
39 $GRAB->button_down ($ev) if $GRAB; 39 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB;
40} 40}
41 41
42sub feed_sdl_button_up_event { 42sub feed_sdl_button_up_event {
43 my ($ev) = @_; 43 my ($ev) = @_;
44 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 44 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
45 45
46 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 46 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
47 47
48 $BUTTON_STATE &= ~(1 << ($ev->button - 1)); 48 $BUTTON_STATE &= ~(1 << ($ev->button - 1));
49
50 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB;
49 51
50 if (!$BUTTON_STATE) { 52 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 53 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 54 $grab->update if $grab;
53 $GRAB->update if $GRAB; 55 $GRAB->update if $GRAB;
65 67
66 $hover->update if $hover; 68 $hover->update if $hover;
67 $HOVER->update if $HOVER; 69 $HOVER->update if $HOVER;
68 } 70 }
69 71
70 $HOVER->mouse_motion ($ev) if $HOVER; 72 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER;
71} 73}
72 74
73sub new { 75sub new {
74 my $class = shift; 76 my $class = shift;
75 77
95sub size_allocate { 97sub size_allocate {
96 my ($self, $w, $h) = @_; 98 my ($self, $w, $h) = @_;
97 99
98 $self->{w} = $w; 100 $self->{w} = $w;
99 $self->{h} = $h; 101 $self->{h} = $h;
102}
103
104# translate global koordinates to local coordinate system
105sub translate {
106 my ($self, $x, $y) = @_;
107
108 $self->{parent}->translate ($x - $self->{x}, $y - $self->{y});
100} 109}
101 110
102sub focus_in { 111sub focus_in {
103 my ($self) = @_; 112 my ($self) = @_;
104 113
629 my ($class, $x, $y, $z, $height, $text) = @_; 638 my ($class, $x, $y, $z, $height, $text) = @_;
630 639
631 $height ||= $::FONTSIZE; 640 $height ||= $::FONTSIZE;
632 641
633 # TODO: color, and make height, xyz etc. optional 642 # TODO: color, and make height, xyz etc. optional
634 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); 643 my $self = $class->SUPER::new (
644 x => $x,
645 y => $y,
646 z => $z,
647 height => $height,
648 layout => new Crossfire::Client::Layout,
649 );
635 650
636 $self->set_text ($text); 651 $self->set_text ($text);
637 652
638 $self 653 $self
639} 654}
640 655
641sub set_text { 656sub set_text {
642 my ($self, $text) = @_; 657 my ($self, $text) = @_;
643 658
644 $self->{text} = $text; 659 $self->{text} = $text;
645 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; 660 $self->{layout}->set_markup ($text);
646 661
647 $self->update; 662 delete $self->{texture};
648} 663}
649 664
650sub get_text { 665sub get_text {
651 my ($self, $text) = @_; 666 my ($self, $text) = @_;
652 667
654} 669}
655 670
656sub size_request { 671sub size_request {
657 my ($self) = @_; 672 my ($self) = @_;
658 673
674 $self->{layout}->set_width;
675 $self->{layout}->size
659 if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack 676# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack
660 ( 677# (
661 $self->{texture}{width}, 678# $self->{texture}{width},
662 $self->{texture}{height}, 679# $self->{texture}{height},
663 ) 680# )
664 } else { 681# } else {
665 my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; 682# my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height};
666 683#
667 ($w, $h) 684# ($w, $h)
668 } 685# }
686}
669 687
688sub size_allocate {
689 my ($self, $w, $h) = @_;
690
691 $self->SUPER::size_allocate ($w, $h);
692 delete $self->{texture};
670} 693}
671 694
672sub _draw { 695sub _draw {
673 my ($self) = @_; 696 my ($self) = @_;
674 697
675 my $tex = $self->{texture}; 698 my $tex = $self->{texture} ||= do {
699 $self->{layout}->set_width ($self->{w});
700 new_from_layout Crossfire::Client::Texture $self->{layout};
701 };
676 702
677 glEnable GL_BLEND; 703 glEnable GL_BLEND;
678 glEnable GL_TEXTURE_2D; 704 glEnable GL_TEXTURE_2D;
679 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 705 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
680 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 706 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
708 734
709 if ($sym == SDLK_BACKSPACE) { 735 if ($sym == SDLK_BACKSPACE) {
710 substr $text, -1, 1, ''; 736 substr $text, -1, 1, '';
711 } elsif ($uni) { 737 } elsif ($uni) {
712 $text .= chr $uni; 738 $text .= chr $uni;
713 print "$uni <$text>\n";#d#
714 } 739 }
715 740
716 $self->set_text ($text); 741 $self->set_text ($text);
717} 742}
718 743
719sub button_down { 744sub button_down {
720 my ($self, $ev) = @_; 745 my ($self, $ev) = @_;
721 746
722 $self->focus_in; 747 $self->focus_in;
748}
749
750sub mouse_motion {
751 my ($self, $ev, $x, $y) = @_;
752 printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
723} 753}
724 754
725sub _draw { 755sub _draw {
726 my ($self) = @_; 756 my ($self) = @_;
727 757
923} 953}
924 954
925sub animate { 955sub animate {
926 my ($self, $interval) = @_; 956 my ($self, $interval) = @_;
927 957
928 printf "%5.2f\n", 1 / $interval if $interval;#d#
929
930 $self->{time} -= $interval * $self->{speed}; 958 $self->{time} -= $interval * $self->{speed};
931 if ($self->{time} <= 0) { 959 if ($self->{time} <= 0) {
932 $self->{time} = 0; 960 $self->{time} = 0;
933 ::animation_stop $self; 961 ::animation_stop $self;
934 } 962 }
965 993
966 $_->size_allocate ($_->size_request) 994 $_->size_allocate ($_->size_request)
967 for @{$self->{children}}; 995 for @{$self->{children}};
968} 996}
969 997
998sub translate {
999 my ($self, $x, $y) = @_;
1000
1001 ($x, $y)
1002}
1003
970sub update { 1004sub update {
971 my ($self) = @_; 1005 my ($self) = @_;
972 1006
973 $self->size_allocate ($self->size_request); 1007 $self->size_allocate ($self->size_request);
974 ::refresh (); 1008 ::refresh ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines