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.137 by root, Wed Apr 19 21:38:05 2006 UTC vs.
Revision 1.161 by root, Mon Apr 24 03:43:51 2006 UTC

8use CFClient; 8use CFClient;
9 9
10our ($FOCUS, $HOVER, $GRAB); # various widgets 10our ($FOCUS, $HOVER, $GRAB); # various widgets
11 11
12our $ROOT; 12our $ROOT;
13our $TOOLTIP;
13our $BUTTON_STATE; 14our $BUTTON_STATE;
15
16sub check_tooltip {
17 if (!$GRAB) {
18 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
19 if (length $widget->{tooltip}) {
20
21 if ($TOOLTIP->{owner} != $widget) {
22 $TOOLTIP->{owner} = $widget;
23
24 my $tip = $widget->{tooltip};
25
26 $tip = $tip->($widget) if CODE:: eq ref $tip;
27
28 $TOOLTIP->set_text ($widget->{tooltip});
29 $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0));
30 $TOOLTIP->show;
31 }
32
33 return;
34 }
35 }
36 }
37
38 $TOOLTIP->hide;
39 delete $TOOLTIP->{owner};
40}
14 41
15# class methods for events 42# class methods for events
16sub feed_sdl_key_down_event { 43sub feed_sdl_key_down_event {
17 $FOCUS->key_down ($_[0]) if $FOCUS; 44 $FOCUS->key_down ($_[0]) if $FOCUS;
18} 45}
28 if (!$BUTTON_STATE) { 55 if (!$BUTTON_STATE) {
29 my $widget = $ROOT->find_widget ($x, $y); 56 my $widget = $ROOT->find_widget ($x, $y);
30 57
31 $GRAB = $widget; 58 $GRAB = $widget;
32 $GRAB->update if $GRAB; 59 $GRAB->update if $GRAB;
60
61 check_tooltip;
33 } 62 }
34 63
35 $BUTTON_STATE |= 1 << ($ev->{button} - 1); 64 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
36 65
37 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; 66 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB;
49 78
50 if (!$BUTTON_STATE) { 79 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 80 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 81 $grab->update if $grab;
53 $GRAB->update if $GRAB; 82 $GRAB->update if $GRAB;
83
84 check_tooltip;
54 } 85 }
55} 86}
56 87
57sub feed_sdl_motion_event { 88sub feed_sdl_motion_event {
58 my ($ev) = @_; 89 my ($ev) = @_;
63 if ($widget != $HOVER) { 94 if ($widget != $HOVER) {
64 my $hover = $HOVER; $HOVER = $widget; 95 my $hover = $HOVER; $HOVER = $widget;
65 96
66 $hover->update if $hover && $hover->{can_hover}; 97 $hover->update if $hover && $hover->{can_hover};
67 $HOVER->update if $HOVER && $HOVER->{can_hover}; 98 $HOVER->update if $HOVER && $HOVER->{can_hover};
99
100 check_tooltip;
68 } 101 }
69 102
70 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; 103 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER;
71} 104}
72 105
87 120
88package CFClient::UI::Base; 121package CFClient::UI::Base;
89 122
90use strict; 123use strict;
91 124
92use SDL::OpenGL; 125use CFClient::OpenGL;
93 126
94sub new { 127sub new {
95 my $class = shift; 128 my $class = shift;
96 129
97 my $self = bless { 130 my $self = bless {
98 x => 0, 131 x => 0,
99 y => 0, 132 y => 0,
100 z => 0, 133 z => 0,
134 can_events => 1,
101 @_ 135 @_
102 }, $class; 136 }, $class;
103 137
104 for (keys %$self) { 138 for (keys %$self) {
105 if (/^connect_(.*)$/) { 139 if (/^connect_(.*)$/) {
108 } 142 }
109 143
110 $self 144 $self
111} 145}
112 146
147sub destroy {
148 my ($self) = @_;
149
150 $self->hide;
151 %$self = ();
152}
153
113sub show { 154sub show {
114 my ($self) = @_; 155 my ($self) = @_;
115 156
116 return if $self->{parent}; 157 return if $self->{parent};
117 158
134 $self->{z} = $z if defined $z; 175 $self->{z} = $z if defined $z;
135 176
136 $self->update; 177 $self->update;
137} 178}
138 179
139sub needs_redraw { 180sub set_size {
140 0 181 my ($self, $w, $h) = @_;
182
183 $self->{user_w} = $w;
184 $self->{user_h} = $h;
185
186 $self->check_size;
141} 187}
142 188
143sub size_request { 189sub size_request {
144 require Carp; 190 require Carp;
145 Carp::confess "size_request is abtract"; 191 Carp::confess "size_request is abstract";
146} 192}
147 193
148sub configure { 194sub configure {
149 my ($self, $x, $y, $w, $h) = @_; 195 my ($self, $x, $y, $w, $h) = @_;
150 196
197 if ($self->{aspect}) {
198 my $w2 = List::Util::min $w, int $h * $self->{aspect};
199 my $h2 = List::Util::min $h, int $w / $self->{aspect};
200
201 # use alignment to adjust x, y
202
203 $x += int +($w - $w2) * 0.5;
204 $y += int +($h - $h2) * 0.5;
205
206 ($w, $h) = ($w2, $h2);
207 }
208
209 if ($self->{x} != $x || $self->{y} != $y) {
151 $self->{x} = $x; 210 $self->{x} = $x;
152 $self->{y} = $y; 211 $self->{y} = $y;
212 $self->update;
213 }
153 214
154 return unless $self->{w} != $w || $self->{h} != $h; 215 if ($self->{w} != $w || $self->{h} != $h) {
155
156 $self->{w} = $w; 216 $self->{w} = $w;
157 $self->{h} = $h; 217 $self->{h} = $h;
158 218
159 $self->size_allocate ($w, $h); 219 $self->size_allocate ($w, $h);
160 $self->update; 220 $self->update;
221 }
161} 222}
162 223
163sub size_allocate { 224sub size_allocate {
164 # nothing to be done 225 # nothing to be done
226}
227
228sub set_max_size {
229 my ($self, $w, $h) = @_;
230
231 delete $self->{max_w}; $self->{max_w} = $w if $w;
232 delete $self->{max_h}; $self->{max_h} = $h if $h;
165} 233}
166 234
167# return top left coordinates 235# return top left coordinates
168sub _topleft { 236sub _topleft {
169 my ($self, $x, $y) = @_; 237 my ($self, $x, $y) = @_;
263} 331}
264 332
265sub find_widget { 333sub find_widget {
266 my ($self, $x, $y) = @_; 334 my ($self, $x, $y) = @_;
267 335
336 return () unless $self->{can_events};
337
268 return $self 338 return $self
269 if $x >= $self->{x} && $x < $self->{x} + $self->{w} 339 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
270 && $y >= $self->{y} && $y < $self->{y} + $self->{h}; 340 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
271 341
272 () 342 ()
279} 349}
280 350
281sub check_size { 351sub check_size {
282 my ($self) = @_; 352 my ($self) = @_;
283 353
284 my ($w, $h) = $self->size_request; 354 $self->{parent}
355 or return 1;
285 356
357 my ($w, $h) = $self->{user_w} && $self->{user_h}
358 ? @$self{qw(user_w user_h)}
359 : $self->size_request;
360
286 if ($w != $self->{req_w} || $h != $self->{req_h}) { 361 if ($w != $self->{req_w} || $h != $self->{req_h}) {
287 $self->{req_w} = $w; 362 $self->{req_w} = $w;
288 $self->{req_h} = $h; 363 $self->{req_h} = $h;
289 364
290 $self->{parent}->check_size 365 $self->{parent}->check_size
291 if $self->{parent}; 366 or $self->size_allocate (
367 (List::Util::max $self->{w}, $w),
368 (List::Util::max $self->{h}, $h),
369 );
370
371 1
372 } else {
373 0
292 } 374 }
293} 375}
294 376
295sub update { 377sub update {
296 my ($self) = @_; 378 my ($self) = @_;
324package CFClient::UI::DrawBG; 406package CFClient::UI::DrawBG;
325 407
326our @ISA = CFClient::UI::Base::; 408our @ISA = CFClient::UI::Base::;
327 409
328use strict; 410use strict;
329use SDL::OpenGL; 411use CFClient::OpenGL;
330 412
331sub new { 413sub new {
332 my $class = shift; 414 my $class = shift;
333 415
334 # range [value, low, high, page] 416 # range [value, low, high, page]
363 445
364package CFClient::UI::Empty; 446package CFClient::UI::Empty;
365 447
366our @ISA = CFClient::UI::Base::; 448our @ISA = CFClient::UI::Base::;
367 449
450sub new {
451 my ($class, %arg) = @_;
452 $class->SUPER::new (can_events => 0, %arg);
453}
454
368sub size_request { 455sub size_request {
369 (0, 0) 456 (0, 0)
370} 457}
371 458
372sub draw { } 459sub draw { }
380sub new { 467sub new {
381 my ($class, %arg) = @_; 468 my ($class, %arg) = @_;
382 469
383 my $children = delete $arg{children} || []; 470 my $children = delete $arg{children} || [];
384 471
385 my $self = $class->SUPER::new (children => [], %arg); 472 my $self = $class->SUPER::new (children => [], can_events => 0, %arg);
386 $self->add ($_) for @$children; 473 $self->add ($_) for @$children;
387 474
388 $self 475 $self
389} 476}
390 477
409 delete $child->{parent}; 496 delete $child->{parent};
410 497
411 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 498 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
412 499
413 $self->check_size; 500 $self->check_size;
501 $self->update;
414} 502}
415 503
416sub find_widget { 504sub find_widget {
417 my ($self, $x, $y) = @_; 505 my ($self, $x, $y) = @_;
418 506
482 570
483package CFClient::UI::Window; 571package CFClient::UI::Window;
484 572
485our @ISA = CFClient::UI::Bin::; 573our @ISA = CFClient::UI::Bin::;
486 574
487use SDL::OpenGL; 575use CFClient::OpenGL;
488 576
489sub new { 577sub new {
490 my ($class, %arg) = @_; 578 my ($class, %arg) = @_;
491 579
492 my $self = $class->SUPER::new (%arg); 580 my $self = $class->SUPER::new (%arg);
546sub new { die } 634sub new { die }
547 635
548sub size_request { 636sub size_request {
549 my ($self) = @_; 637 my ($self) = @_;
550 638
551 @$self{qw(child_w child_h)} = $self->child->size_request; 639 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
552 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); 640 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
553 641
554 @$self{qw(child_w child_h)} 642 @$self{qw(child_w child_h)}
555} 643}
556 644
565 653
566package CFClient::UI::Frame; 654package CFClient::UI::Frame;
567 655
568our @ISA = CFClient::UI::Bin::; 656our @ISA = CFClient::UI::Bin::;
569 657
570use SDL::OpenGL; 658use CFClient::OpenGL;
571
572sub size_request {
573 my ($self) = @_;
574 my $chld = $self->child
575 or return (0, 0);
576
577 $chld->move (2, 2);
578
579 map { $_ + 4 } $chld->size_request;
580}
581
582sub size_allocate {
583 my ($self, $x, $y, $w, $h) = @_;
584
585 $self->child->configure (2, 2, $w - 4, $h - 4);
586}
587
588sub _draw {
589 my ($self) = @_;
590
591 my $chld = $self->child;
592
593 my ($w, $h) = $chld->size_request;
594
595 glBegin GL_QUADS;
596 glColor 0, 0, 0;
597 glVertex 0 , 0;
598 glVertex 0 , $h + 4;
599 glVertex $w + 4 , $h + 4;
600 glVertex $w + 4 , 0;
601 glEnd;
602
603 $chld->draw;
604}
605
606#############################################################################
607
608package CFClient::UI::FancyFrame;
609
610our @ISA = CFClient::UI::Bin::;
611
612use SDL::OpenGL;
613
614my @tex =
615 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
616 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
617 659
618sub new { 660sub new {
619 my $class = shift; 661 my $class = shift;
620 662
621 # TODO: user_x, user_y, overwrite moveto?
622
623 $class->SUPER::new ( 663 my $self = $class->SUPER::new (
624 bg => [1, 1, 1, 1], 664 bg => [1, 1, 1, 1],
625 border_bg => [1, 1, 1, 1], 665 border_bg => [1, 1, 1, 1],
626 border => 0.8, 666 border => 0.8,
627 @_ 667 @_
628 ) 668 );
669
670 $self
671}
672
673sub _draw {
674 my ($self) = @_;
675
676 my ($w, $h) = ($self->{w}, $self->{h});
677
678 glEnable GL_BLEND;
679 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
680 glEnable GL_TEXTURE_2D;
681 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
682
683# glBegin GL_QUADS;
684# glColor 0, 0, 0, 0;
685# glVertex 0 , 0;
686# glVertex 0 , $h;
687# glVertex $w, $h;
688# glVertex $w, 0;
689# glEnd;
690
691
692 $self->child->draw;
693 glDisable GL_BLEND;
694 glDisable GL_TEXTURE_2D;
695}
696
697#############################################################################
698
699package CFClient::UI::FancyFrame;
700
701our @ISA = CFClient::UI::Bin::;
702
703use CFClient::OpenGL;
704
705my @tex =
706 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
707 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
708
709sub new {
710 my $class = shift;
711
712 # TODO: user_x, user_y, overwrite moveto?
713
714 my $self = $class->SUPER::new (
715 bg => [1, 1, 1, 1],
716 border_bg => [1, 1, 1, 1],
717 border => 0.8,
718 can_events => 1,
719 @_
720 );
721
722 $self->{title} &&= new CFClient::UI::Label
723 align => 0,
724 valign => 1,
725 text => $self->{title},
726 fontsize => 1;
727
728 $self
629} 729}
630 730
631sub border { 731sub border {
632 int $_[0]{border} * $::FONTSIZE 732 int $_[0]{border} * $::FONTSIZE
633} 733}
634 734
635sub size_request { 735sub size_request {
636 my ($self) = @_; 736 my ($self) = @_;
637
638 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
639 737
640 my ($w, $h) = $self->SUPER::size_request; 738 my ($w, $h) = $self->SUPER::size_request;
641 739
642 ( 740 (
643 $w + $self->border * 2, 741 $w + $self->border * 2,
649 my ($self, $w, $h) = @_; 747 my ($self, $w, $h) = @_;
650 748
651 $h -= List::Util::max 0, $self->border * 2; 749 $h -= List::Util::max 0, $self->border * 2;
652 $w -= List::Util::max 0, $self->border * 2; 750 $w -= List::Util::max 0, $self->border * 2;
653 751
752 $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2)
753 if $self->{title};
754
654 $self->child->configure ($self->border, $self->border, $w, $h); 755 $self->child->configure ($self->border, $self->border, $w, $h);
655} 756}
656 757
657sub button_down { 758sub button_down {
658 my ($self, $ev, $x, $y) = @_; 759 my ($self, $ev, $x, $y) = @_;
660 my $border = $self->border; 761 my $border = $self->border;
661 762
662 if ($x < $self->{w} && $x >= $self->{w} - $border 763 if ($x < $self->{w} && $x >= $self->{w} - $border
663 && $y < $self->{h} && $y >= $self->{h} - $border) { 764 && $y < $self->{h} && $y >= $self->{h} - $border) {
664 765
665 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 766 my ($ox, $oy) = ($ev->{x}, $ev->{y});
666 my ($bw, $bh) = ($self->{w}, $self->{h}); 767 my ($bw, $bh) = ($self->{w}, $self->{h});
667 768
668 $self->{motion} = sub { 769 $self->{motion} = sub {
669 my ($ev, $x, $y) = @_; 770 my ($ev, $x, $y) = @_;
670 771
671 ($x, $y) = ($ev->motion_x, $ev->motion_y); 772 ($x, $y) = ($ev->{x}, $ev->{y});
672 773
673 $self->{user_w} = $bw + $x - $ox; 774 $self->{user_w} = $bw + $x - $ox;
674 $self->{user_h} = $bh + $y - $oy; 775 $self->{user_h} = $bh + $y - $oy;
675 $self->check_size; 776 $self->check_size;
676 }; 777 };
677 778
678 } elsif ($x >= 0 && $x < $self->{w} 779 } elsif ($x >= 0 && $x < $self->{w}
679 && $y >= 0 && $y < $border) { 780 && $y >= 0 && $y < $border) {
680 781
681 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 782 my ($ox, $oy) = ($ev->{x}, $ev->{y});
682 my ($bx, $by) = ($self->{x}, $self->{y}); 783 my ($bx, $by) = ($self->{x}, $self->{y});
683 784
684 $self->{motion} = sub { 785 $self->{motion} = sub {
685 my ($ev, $x, $y) = @_; 786 my ($ev, $x, $y) = @_;
686 787
687 ($x, $y) = ($ev->motion_x, $ev->motion_y); 788 ($x, $y) = ($ev->{x}, $ev->{y});
688 789
689 $self->move ($bx + $x - $ox, $by + $y - $oy); 790 $self->move ($bx + $x - $ox, $by + $y - $oy);
690 $self->update; 791 $self->update;
691 }; 792 };
692 } 793 }
737 $bg->draw_quad ($border, $border, $cw, $ch); 838 $bg->draw_quad ($border, $border, $cw, $ch);
738 839
739 glDisable GL_TEXTURE_2D; 840 glDisable GL_TEXTURE_2D;
740 glDisable GL_BLEND; 841 glDisable GL_BLEND;
741 842
843 $self->{title}->draw if $self->{title};
742 $self->child->draw; 844 $self->child->draw;
743} 845}
744 846
745############################################################################# 847#############################################################################
746 848
748 850
749our @ISA = CFClient::UI::Base::; 851our @ISA = CFClient::UI::Base::;
750 852
751use List::Util qw(max sum); 853use List::Util qw(max sum);
752 854
753use SDL::OpenGL; 855use CFClient::OpenGL;
754 856
755sub new { 857sub new {
756 my $class = shift; 858 my $class = shift;
757 859
758 $class->SUPER::new ( 860 $class->SUPER::new (
788 or next; 890 or next;
789 891
790 for my $x (0 .. $#$row) { 892 for my $x (0 .. $#$row) {
791 my $widget = $row->[$x] 893 my $widget = $row->[$x]
792 or next; 894 or next;
793 my ($w, $h) = $widget->size_request; 895 my ($w, $h) = @$widget{qw(req_w req_h)};
794 896
795 $w[$x] = max $w[$x], $w; 897 $w[$x] = max $w[$x], $w;
796 $h[$y] = max $h[$y], $h; 898 $h[$y] = max $h[$y], $h;
797 } 899 }
798 } 900 }
903 1005
904 ($h, $w) = ($w, $h); 1006 ($h, $w) = ($w, $h);
905 1007
906 my $children = $self->{children}; 1008 my $children = $self->{children};
907 1009
908 my @h = map +($_->size_request)[0], @$children; 1010 my @h = map $_->{req_w}, @$children;
909 1011
910 my $req_h = List::Util::sum @h; 1012 my $req_h = List::Util::sum @h;
911 1013
912 if ($req_h > $h) { 1014 if ($req_h > $h) {
913 # ah well, not enough space 1015 # ah well, not enough space
961sub size_allocate { 1063sub size_allocate {
962 my ($self, $w, $h) = @_; 1064 my ($self, $w, $h) = @_;
963 1065
964 my $children = $self->{children}; 1066 my $children = $self->{children};
965 1067
966 my @h = map +($_->size_request)[1], @$children; 1068 my @h = map $_->{req_h}, @$children;
967 1069
968 my $req_h = List::Util::sum @h; 1070 my $req_h = List::Util::sum @h;
969 1071
970 if ($req_h > $h) { 1072 if ($req_h > $h) {
971 # ah well, not enough space 1073 # ah well, not enough space
999 1101
1000package CFClient::UI::Label; 1102package CFClient::UI::Label;
1001 1103
1002our @ISA = CFClient::UI::Base::; 1104our @ISA = CFClient::UI::Base::;
1003 1105
1004use SDL::OpenGL; 1106use CFClient::OpenGL;
1005 1107
1006sub new { 1108sub new {
1007 my ($class, %arg) = @_; 1109 my ($class, %arg) = @_;
1008 1110
1009 my $self = $class->SUPER::new ( 1111 my $self = $class->SUPER::new (
1010 fg => [1, 1, 1], 1112 fg => [1, 1, 1],
1113 #font => default_font
1011 fontsize => 1, 1114 fontsize => 1,
1012 text => "", 1115 text => "",
1013 align => -1, 1116 align => -1,
1014 valign => -1, 1117 valign => -1,
1015 padding => 2, 1118 padding => 2,
1016 layout => new CFClient::Layout, 1119 layout => new CFClient::Layout,
1120 can_events => 0,
1017 %arg 1121 %arg
1018 ); 1122 );
1019 1123
1020 $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# 1124 if (exists $self->{template}) {
1125 my $layout = new CFClient::Layout;
1126 $layout->set_text (delete $self->{template});
1127 $self->{template} = $layout;
1128 }
1021 1129
1022 $self->set_text (delete $self->{text}) if exists $self->{text}; 1130 $self->set_text (delete $self->{text}) if exists $self->{text};
1023 $self->set_markup (delete $self->{markup}) if exists $self->{markup}; 1131 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
1024 1132
1025 $self 1133 $self
1039 my ($self, $text) = @_; 1147 my ($self, $text) = @_;
1040 1148
1041 $self->{layout}->set_text ($text); 1149 $self->{layout}->set_text ($text);
1042 1150
1043 delete $self->{texture}; 1151 delete $self->{texture};
1152 $self->check_size;
1044 $self->update; 1153 $self->update;
1045} 1154}
1046 1155
1047sub set_markup { 1156sub set_markup {
1048 my ($self, $markup) = @_; 1157 my ($self, $markup) = @_;
1049 1158
1050 $self->{layout}->set_markup ($markup); 1159 $self->{layout}->set_markup ($markup);
1051 1160
1052 delete $self->{texture}; 1161 delete $self->{texture};
1162 $self->check_size;
1053 $self->update; 1163 $self->update;
1054} 1164}
1055 1165
1056sub size_request { 1166sub size_request {
1057 my ($self) = @_; 1167 my ($self) = @_;
1058 1168
1059 $self->{layout}->set_width; 1169 $self->{layout}->set_font ($self->{font}) if $self->{font};
1170 $self->{layout}->set_width ($self->{max_w} || -1);
1060 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1171 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1061 1172
1062 my ($w, $h) = $self->{layout}->size; 1173 my ($w, $h) = $self->{layout}->size;
1174
1175 if (exists $self->{template}) {
1176 $self->{template}->set_font ($self->{font}) if $self->{font};
1177 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1178
1179 my ($w2, $h2) = $self->{template}->size;
1180
1181 $w = List::Util::max $w, $w2;
1182 $h = List::Util::max $h, $h2;
1183 }
1063 1184
1064 ( 1185 (
1065 $w + $self->{padding} * 2, 1186 $w + $self->{padding} * 2,
1066 $h + $self->{padding} * 2, 1187 $h + $self->{padding} * 2,
1067 ) 1188 )
1071 my ($self, $w, $h) = @_; 1192 my ($self, $w, $h) = @_;
1072 1193
1073 delete $self->{texture}; 1194 delete $self->{texture};
1074} 1195}
1075 1196
1197sub set_fontsize {
1198 my ($self, $fontsize) = @_;
1199
1200 $self->{fontsize} = $fontsize;
1201 delete $self->{texture};
1202 $self->check_size;
1203 $self->update;
1204}
1205
1076sub _draw { 1206sub _draw {
1077 my ($self) = @_; 1207 my ($self) = @_;
1078 1208
1079 my $tex = $self->{texture} ||= do { 1209 my $tex = $self->{texture} ||= do {
1210 $self->{layout}->set_font ($self->{font}) if $self->{font};
1080 $self->{layout}->set_width ($self->{w}); 1211 $self->{layout}->set_width ($self->{w});
1081 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1212 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1082 new_from_layout CFClient::Texture $self->{layout} 1213 new_from_layout CFClient::Texture $self->{layout}
1083 }; 1214 };
1084 1215
1111 1242
1112package CFClient::UI::EntryBase; 1243package CFClient::UI::EntryBase;
1113 1244
1114our @ISA = CFClient::UI::Label::; 1245our @ISA = CFClient::UI::Label::;
1115 1246
1116use SDL::OpenGL; 1247use CFClient::OpenGL;
1117 1248
1118sub new { 1249sub new {
1119 my $class = shift; 1250 my $class = shift;
1120 1251
1121 $class->SUPER::new ( 1252 $class->SUPER::new (
1124 active_bg => [1, 1, 1, 0.5], 1255 active_bg => [1, 1, 1, 0.5],
1125 active_fg => [0, 0, 0], 1256 active_fg => [0, 0, 0],
1126 can_hover => 1, 1257 can_hover => 1,
1127 can_focus => 1, 1258 can_focus => 1,
1128 valign => 0, 1259 valign => 0,
1260 can_events => 1,
1129 @_ 1261 @_
1130 ) 1262 )
1131} 1263}
1132 1264
1133sub _set_text { 1265sub _set_text {
1161} 1293}
1162 1294
1163sub size_allocate { 1295sub size_allocate {
1164 my ($self, $w, $h) = @_; 1296 my ($self, $w, $h) = @_;
1165 1297
1166 $self->_set_text ($self->{text}); 1298 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1167} 1299}
1168 1300
1169sub set_text { 1301sub set_text {
1170 my ($self, $text) = @_; 1302 my ($self, $text) = @_;
1171 1303
1278 1410
1279package CFClient::UI::Entry; 1411package CFClient::UI::Entry;
1280 1412
1281our @ISA = CFClient::UI::EntryBase::; 1413our @ISA = CFClient::UI::EntryBase::;
1282 1414
1283use SDL::OpenGL; 1415use CFClient::OpenGL;
1284 1416
1285sub key_down { 1417sub key_down {
1286 my ($self, $ev) = @_; 1418 my ($self, $ev) = @_;
1287 1419
1288 my $sym = $ev->{sym}; 1420 my $sym = $ev->{sym};
1301 1433
1302package CFClient::UI::Button; 1434package CFClient::UI::Button;
1303 1435
1304our @ISA = CFClient::UI::Label::; 1436our @ISA = CFClient::UI::Label::;
1305 1437
1306use SDL::OpenGL; 1438use CFClient::OpenGL;
1307 1439
1308my @tex = 1440my @tex =
1309 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1441 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1310 qw(b1_button_active.png); 1442 qw(b1_button_active.png);
1311 1443
1312sub new { 1444sub new {
1313 my $class = shift; 1445 my $class = shift;
1314 1446
1318 bg => [1, 1, 1, 0.2], 1450 bg => [1, 1, 1, 0.2],
1319 active_fg => [0, 0, 1], 1451 active_fg => [0, 0, 1],
1320 can_hover => 1, 1452 can_hover => 1,
1321 align => 0, 1453 align => 0,
1322 valign => 0, 1454 valign => 0,
1455 can_events => 1,
1323 @_ 1456 @_
1324 ) 1457 )
1325} 1458}
1326 1459
1327sub button_up { 1460sub button_up {
1361package CFClient::UI::CheckBox; 1494package CFClient::UI::CheckBox;
1362 1495
1363our @ISA = CFClient::UI::DrawBG::; 1496our @ISA = CFClient::UI::DrawBG::;
1364 1497
1365my @tex = 1498my @tex =
1366 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1499 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1367 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1500 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1368 1501
1369use SDL::OpenGL; 1502use CFClient::OpenGL;
1370 1503
1371sub new { 1504sub new {
1372 my $class = shift; 1505 my $class = shift;
1373 1506
1374 $class->SUPER::new ( 1507 $class->SUPER::new (
1420 glDisable GL_BLEND; 1553 glDisable GL_BLEND;
1421} 1554}
1422 1555
1423############################################################################# 1556#############################################################################
1424 1557
1425package CFClient::UI::VGauge; 1558package CFClient::UI::Image;
1426 1559
1427our @ISA = CFClient::UI::Base::; 1560our @ISA = CFClient::UI::Base::;
1428 1561
1429use SDL::OpenGL; 1562use CFClient::OpenGL;
1563use Carp qw/confess/;
1430 1564
1431my %tex = ( 1565our %loaded_images;
1432 food => [
1433 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1434 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1435 ],
1436 grace => [
1437 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1438 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1439 ],
1440 hp => [
1441 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1442 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1443 ],
1444 mana => [
1445 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1446 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1447 ],
1448);
1449 1566
1450# eg. VGauge->new (gauge => 'food'), default gauge: food
1451sub new { 1567sub new {
1452 my $class = shift; 1568 my $class = shift;
1453 1569
1454 my $self = $class->SUPER::new (gauge => 'food', @_); 1570 my $self = $class->SUPER::new (can_events => 0, @_);
1571
1572 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1573
1574 $loaded_images{$self->{image}} ||=
1575 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1576
1577 my $tex = $self->{tex} = $loaded_images{$self->{image}};
1578
1579 Scalar::Util::weaken $loaded_images{$self->{image}};
1580
1581 $self->{aspect} = $tex->{w} / $tex->{h};
1455 1582
1456 $self 1583 $self
1457} 1584}
1458 1585
1459sub size_request { 1586sub size_request {
1460 my ($self) = @_; 1587 my ($self) = @_;
1461 1588
1462 my $tex = $tex{$self->{gauge}}[0]; 1589 ($self->{tex}->{w}, $self->{tex}->{h})
1463
1464 @$tex{qw(w h)}
1465}
1466
1467sub set_max {
1468 my ($self, $max) = @_;
1469
1470 $self->{max_val} = $max;
1471}
1472
1473sub set_value {
1474 my ($self, $val, $max) = @_;
1475
1476 $self->set_max ($max)
1477 if defined $max;
1478
1479 $max = $self->{max_val};
1480 $self->{val} = $val;
1481
1482 $self->update;
1483} 1590}
1484 1591
1485sub _draw { 1592sub _draw {
1486 my ($self) = @_; 1593 my ($self) = @_;
1487 1594
1488 my $tex = $tex{$self->{gauge}}; 1595 my $tex = $self->{tex};
1489 1596
1490 my ($w, $h) = ($self->{w}, $self->{h}); 1597 my ($w, $h) = ($self->{w}, $self->{h});
1491 1598
1492 my $ycut = $self->{val} / ($self->{max_val} || 1); 1599 if ($self->{rot90}) {
1493 $ycut = 1 if $self->{val} > $self->{max_val}; 1600 glRotate 90, 0, 0, 1;
1601 glTranslate 0, -$self->{w}, 0;
1494 1602
1495 my $t1 = $tex->[0]; 1603 ($w, $h) = ($h, $w);
1496 my $t2 = $tex->[1]; 1604 }
1497 1605
1498 glEnable GL_BLEND; 1606 glEnable GL_BLEND;
1499 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1607 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1500 glEnable GL_TEXTURE_2D; 1608 glEnable GL_TEXTURE_2D;
1501 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1609 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1502 1610
1611 $tex->draw_quad (0, 0, $w, $h);
1612
1613 glDisable GL_BLEND;
1614 glDisable GL_TEXTURE_2D;
1615}
1616
1617#############################################################################
1618
1619package CFClient::UI::VGauge;
1620
1621our @ISA = CFClient::UI::Base::;
1622
1623use List::Util qw(min max);
1624
1625use CFClient::OpenGL;
1626
1627my %tex = (
1628 food => [
1629 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1630 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1631 ],
1632 grace => [
1633 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1634 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
1635 ],
1636 hp => [
1637 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1638 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1639 ],
1640 mana => [
1641 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1642 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
1643 ],
1644);
1645
1646# eg. VGauge->new (gauge => 'food'), default gauge: food
1647sub new {
1648 my $class = shift;
1649
1650 my $self = $class->SUPER::new (
1651 type => 'food',
1652 @_
1653 );
1654
1655 $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h};
1656
1657 $self
1658}
1659
1660sub size_request {
1661 my ($self) = @_;
1662
1663 #my $tex = $tex{$self->{type}}[0];
1664 #@$tex{qw(w h)}
1665 (0, 0)
1666}
1667
1668sub set_max {
1669 my ($self, $max) = @_;
1670
1671 $self->{max_val} = $max;
1672}
1673
1674sub set_value {
1675 my ($self, $val, $max) = @_;
1676
1677 $self->set_max ($max)
1678 if defined $max;
1679
1680 $max = $self->{max_val};
1681 $self->{val} = $val;
1682
1683 $self->update;
1684}
1685
1686sub _draw {
1687 my ($self) = @_;
1688
1689 my $tex = $tex{$self->{type}};
1690 my ($t1, $t2, $t3) = @$tex;
1691
1692 my ($w, $h) = ($self->{w}, $self->{h});
1693
1694 if ($self->{vertical}) {
1695 glRotate 90, 0, 0, 1;
1696 glTranslate 0, -$self->{w}, 0;
1697
1698 ($w, $h) = ($h, $w);
1699 }
1700
1701 my $ycut = $self->{val} / ($self->{max_val} || 1);
1702
1703 my $ycut1 = max 0, min 1, $ycut;
1704 my $ycut2 = max 0, min 1, $ycut - 1;
1705
1503 my $h1 = $self->{h} - $ycut * $self->{h}; 1706 my $h1 = $self->{h} * (1 - $ycut1);
1504 my $h2 = $ycut * $self->{h}; 1707 my $h2 = $self->{h} * (1 - $ycut2);
1505 1708
1506 my $yp = 0; 1709 glEnable GL_BLEND;
1710 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1711 glEnable GL_TEXTURE_2D;
1712 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1507 1713
1508 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1714 glBindTexture GL_TEXTURE_2D, $t1->{name};
1509 glBegin GL_QUADS; 1715 glBegin GL_QUADS;
1510 glTexCoord 0 , 0; glVertex 0 , $yp; 1716 glTexCoord 0 , 0; glVertex 0 , 0;
1511 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; 1717 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1512 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; 1718 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1513 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; 1719 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1514 glEnd; 1720 glEnd;
1515 1721
1516 $yp += $h1; 1722 my $ycut1 = List::Util::min 1, $ycut;
1517
1518 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1723 glBindTexture GL_TEXTURE_2D, $t2->{name};
1519 glBegin GL_QUADS; 1724 glBegin GL_QUADS;
1520 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; 1725 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1521 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; 1726 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1522 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2;
1523 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; 1727 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1728 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1524 glEnd; 1729 glEnd;
1730
1731 if ($t3) {
1732 glBindTexture GL_TEXTURE_2D, $t3->{name};
1733 glBegin GL_QUADS;
1734 glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2;
1735 glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h};
1736 glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h};
1737 glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2;
1738 glEnd;
1739 }
1525 1740
1526 glDisable GL_BLEND; 1741 glDisable GL_BLEND;
1527 glDisable GL_TEXTURE_2D; 1742 glDisable GL_TEXTURE_2D;
1528} 1743}
1529 1744
1530############################################################################# 1745#############################################################################
1531 1746
1747package CFClient::UI::Gauge;
1748
1749our @ISA = CFClient::UI::VBox::;
1750
1751sub new {
1752 my ($class, %arg) = @_;
1753
1754 my $self = $class->SUPER::new (
1755 tooltip => $arg{type},
1756 can_events => 1,
1757 can_hover => 1,
1758 %arg,
1759 );
1760
1761 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1762 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1763 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999");
1764
1765 $self
1766}
1767
1768sub set_fontsize {
1769 my ($self, $fsize) = @_;
1770
1771 $self->{value}->set_fontsize ($fsize);
1772 $self->{max} ->set_fontsize ($fsize);
1773}
1774
1775sub set_value {
1776 my ($self, $val, $max) = @_;
1777
1778 $self->set_max ($max)
1779 if defined $max;
1780
1781 $self->{gauge}->set_value ($val, $max);
1782 $self->{value}->set_text ($val);
1783}
1784
1785sub set_max {
1786 my ($self, $max) = @_;
1787
1788 $self->{gauge}->set_max ($max);
1789 $self->{max}->set_text ($max);
1790}
1791
1792#############################################################################
1793
1532package CFClient::UI::Slider; 1794package CFClient::UI::Slider;
1533 1795
1534use strict; 1796use strict;
1535 1797
1536use SDL::OpenGL; 1798use CFClient::OpenGL;
1537 1799
1538our @ISA = CFClient::UI::DrawBG::; 1800our @ISA = CFClient::UI::DrawBG::;
1539 1801
1540my @tex = 1802my @tex =
1541 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1803 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1666 1928
1667package CFClient::UI::TextView; 1929package CFClient::UI::TextView;
1668 1930
1669our @ISA = CFClient::UI::HBox::; 1931our @ISA = CFClient::UI::HBox::;
1670 1932
1671use SDL::OpenGL; 1933use CFClient::OpenGL;
1672 1934
1673sub new { 1935sub new {
1674 my $class = shift; 1936 my $class = shift;
1675 1937
1676 my $self = $class->SUPER::new ( 1938 my $self = $class->SUPER::new (
1677 fontsize => 1, 1939 fontsize => 1,
1940 #font => default_font
1678 @_, 1941 @_,
1679 1942
1680 layout => (new CFClient::Layout), 1943 layout => (new CFClient::Layout),
1681 par => [], 1944 par => [],
1682 height => 0, 1945 height => 0,
1722sub size_allocate { 1985sub size_allocate {
1723 my ($self, $w, $h) = @_; 1986 my ($self, $w, $h) = @_;
1724 1987
1725 $self->SUPER::size_allocate ($w, $h); 1988 $self->SUPER::size_allocate ($w, $h);
1726 1989
1990 $self->{layout}->set_font ($self->{font}) if $self->{font};
1727 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1991 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1728 $self->{layout}->set_width ($self->{children}[0]{w}); 1992 $self->{layout}->set_width ($self->{children}[0]{w});
1729 1993
1730 $self->reflow; 1994 $self->reflow;
1731} 1995}
1783 my $y1 = $top + $self->{h}; 2047 my $y1 = $top + $self->{h};
1784 2048
1785 my $y = 0; 2049 my $y = 0;
1786 2050
1787 my $layout = $self->{layout}; 2051 my $layout = $self->{layout};
2052
2053 $layout->set_font ($self->{font}) if $self->{font};
1788 2054
1789 for my $par (@{$self->{par}}) { 2055 for my $par (@{$self->{par}}) {
1790 my $h = $par->[0]; 2056 my $h = $par->[0];
1791 2057
1792 if ($y0 < $y + $h && $y < $y1) { 2058 if ($y0 < $y + $h && $y < $y1) {
1822 2088
1823############################################################################# 2089#############################################################################
1824 2090
1825package CFClient::UI::Animator; 2091package CFClient::UI::Animator;
1826 2092
1827use SDL::OpenGL; 2093use CFClient::OpenGL;
1828 2094
1829our @ISA = CFClient::UI::Bin::; 2095our @ISA = CFClient::UI::Bin::;
1830 2096
1831sub moveto { 2097sub moveto {
1832 my ($self, $x, $y) = @_; 2098 my ($self, $x, $y) = @_;
1872 my $class = shift; 2138 my $class = shift;
1873 2139
1874 my $self = $class->SUPER::new ( 2140 my $self = $class->SUPER::new (
1875 state => 0, 2141 state => 0,
1876 connect_activate => \&toggle_flopper, 2142 connect_activate => \&toggle_flopper,
2143 can_events => 1,
1877 @_ 2144 @_
1878 ); 2145 );
1879 2146
1880 if ($self->{state}) { 2147 if ($self->{state}) {
1881 $self->{state} = 0; 2148 $self->{state} = 0;
1901 $self->emit (changed => $self->{state}); 2168 $self->emit (changed => $self->{state});
1902} 2169}
1903 2170
1904############################################################################# 2171#############################################################################
1905 2172
2173package CFClient::UI::Tooltip;
2174
2175our @ISA = CFClient::UI::Bin::;
2176
2177use CFClient::OpenGL;
2178
2179sub new {
2180 my $class = shift;
2181
2182 $class->SUPER::new (
2183 @_,
2184 can_events => 0,
2185 )
2186}
2187
2188sub set_text {
2189 my ($self, $text) = @_;
2190
2191 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0];
2192 $self->{label}->set_text ($text);
2193 $self->add ($self->{label});
2194}
2195
2196sub size_request {
2197 my ($self) = @_;
2198
2199 $self->child->set_max_size ($::WIDTH * 0.3);
2200
2201 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2202
2203 ($w + 4, $h + 4)
2204}
2205
2206sub _draw {
2207 my ($self) = @_;
2208
2209 glPushMatrix;
2210 glTranslate 0.375, 0.375;
2211
2212 my ($w, $h) = @$self{qw(w h)};
2213
2214 glColor 1, 0.8, 0.4;
2215 glBegin GL_QUADS;
2216 glVertex 0 , 0;
2217 glVertex 0 , $h;
2218 glVertex $w, $h;
2219 glVertex $w, 0;
2220 glEnd;
2221
2222 glColor 0, 0, 0;
2223 glBegin GL_LINE_LOOP;
2224 glVertex 0 , 0;
2225 glVertex 0 , $h;
2226 glVertex $w, $h;
2227 glVertex $w, 0;
2228 glEnd;
2229
2230 glPopMatrix;
2231
2232 glTranslate 2, 2;
2233 $self->SUPER::_draw;
2234}
2235
2236#############################################################################
2237
1906package CFClient::UI::Root; 2238package CFClient::UI::Root;
1907 2239
1908our @ISA = CFClient::UI::Container::; 2240our @ISA = CFClient::UI::Container::;
1909 2241
1910use SDL::OpenGL; 2242use CFClient::OpenGL;
1911 2243
1912sub check_size { 2244sub check_size {
1913 my ($self) = @_; 2245 my ($self) = @_;
1914 2246
1915 $self->configure (0, 0, $::WITH, $::HEIGHT); 2247 $self->configure (0, 0, $::WIDTH, $::HEIGHT);
1916} 2248}
1917 2249
1918sub size_request { 2250sub size_request {
1919 ($::WIDTH, $::HEIGHT) 2251 ($::WIDTH, $::HEIGHT)
1920} 2252}
1922sub configure { 2254sub configure {
1923 my ($self, $x, $y, $w, $h) = @_; 2255 my ($self, $x, $y, $w, $h) = @_;
1924 2256
1925 $self->SUPER::configure ($x, $y, $w, $h); 2257 $self->SUPER::configure ($x, $y, $w, $h);
1926 2258
1927 $_->configure ($_->{x}, $_->{y}, $_->size_request)
1928 for @{$self->{children}}; 2259 for my $child (@{$self->{children}}) {
2260 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2261
2262 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2263 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2264 $child->configure ($X, $Y, $W,$H);
2265 }
1929} 2266}
1930 2267
1931sub _topleft { 2268sub _topleft {
1932 my ($self, $x, $y) = @_; 2269 my ($self, $x, $y) = @_;
1933 2270
1941 ::refresh (); 2278 ::refresh ();
1942} 2279}
1943 2280
1944sub add { 2281sub add {
1945 my ($self, $child) = @_; 2282 my ($self, $child) = @_;
2283
2284 # integerize window positions
2285 $child->{x} = int $child->{x};
2286 $child->{y} = int $child->{y};
1946 2287
1947 $self->SUPER::add ($child); 2288 $self->SUPER::add ($child);
1948} 2289}
1949 2290
1950sub on_refresh { 2291sub on_refresh {
1976############################################################################# 2317#############################################################################
1977 2318
1978package CFClient::UI; 2319package CFClient::UI;
1979 2320
1980$ROOT = new CFClient::UI::Root; 2321$ROOT = new CFClient::UI::Root;
2322$TOOLTIP = new CFClient::UI::Tooltip;
1981 2323
19821 23241
1983 2325

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines