… | |
… | |
8 | use CFClient; |
8 | use CFClient; |
9 | |
9 | |
10 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
10 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
11 | |
11 | |
12 | our $ROOT; |
12 | our $ROOT; |
|
|
13 | our $TOOLTIP; |
13 | our $BUTTON_STATE; |
14 | our $BUTTON_STATE; |
|
|
15 | |
|
|
16 | sub check_tooltip { |
|
|
17 | if (!$GRAB) { |
|
|
18 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
|
|
19 | if (exists $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 |
16 | sub feed_sdl_key_down_event { |
43 | sub 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 | |
57 | sub feed_sdl_motion_event { |
88 | sub 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 | |
… | |
… | |
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_(.*)$/) { |
… | |
… | |
140 | 0 |
174 | 0 |
141 | } |
175 | } |
142 | |
176 | |
143 | sub size_request { |
177 | sub size_request { |
144 | require Carp; |
178 | require Carp; |
145 | Carp::confess "size_request is abtract"; |
179 | Carp::confess "size_request is abstract"; |
146 | } |
180 | } |
147 | |
181 | |
148 | sub configure { |
182 | sub configure { |
149 | my ($self, $x, $y, $w, $h) = @_; |
183 | my ($self, $x, $y, $w, $h) = @_; |
150 | |
184 | |
151 | $self->{x} = $x; |
|
|
152 | $self->{y} = $y; |
|
|
153 | |
|
|
154 | if ($self->{aspect}) { |
185 | if ($self->{aspect}) { |
155 | $w = List::Util::min $w, int $h * $self->{aspect}; |
186 | my $w2 = List::Util::min $w, int $h * $self->{aspect}; |
156 | $h = List::Util::min $h, int $w / $self->{aspect}; |
187 | my $h2 = List::Util::min $h, int $w / $self->{aspect}; |
157 | } |
|
|
158 | |
188 | |
|
|
189 | # use alignment to adjust x, y |
|
|
190 | |
|
|
191 | $x += int +($w - $w2) * 0.5; |
|
|
192 | $y += int +($h - $h2) * 0.5; |
|
|
193 | |
|
|
194 | ($w, $h) = ($w2, $h2); |
|
|
195 | } |
|
|
196 | |
|
|
197 | if ($self->{x} != $x || $self->{y} != $y) { |
|
|
198 | $self->{x} = $x; |
|
|
199 | $self->{y} = $y; |
|
|
200 | $self->update; |
|
|
201 | } |
|
|
202 | |
159 | return unless $self->{w} != $w || $self->{h} != $h; |
203 | if ($self->{w} != $w || $self->{h} != $h) { |
160 | |
|
|
161 | $self->{w} = $w; |
204 | $self->{w} = $w; |
162 | $self->{h} = $h; |
205 | $self->{h} = $h; |
163 | |
206 | |
164 | $self->size_allocate ($w, $h); |
207 | $self->size_allocate ($w, $h); |
165 | $self->update; |
208 | $self->update; |
|
|
209 | } |
166 | } |
210 | } |
167 | |
211 | |
168 | sub size_allocate { |
212 | sub size_allocate { |
169 | # nothing to be done |
213 | # nothing to be done |
|
|
214 | } |
|
|
215 | |
|
|
216 | sub set_max_size { |
|
|
217 | my ($self, $w, $h) = @_; |
|
|
218 | |
|
|
219 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
|
|
220 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
170 | } |
221 | } |
171 | |
222 | |
172 | # return top left coordinates |
223 | # return top left coordinates |
173 | sub _topleft { |
224 | sub _topleft { |
174 | my ($self, $x, $y) = @_; |
225 | my ($self, $x, $y) = @_; |
… | |
… | |
268 | } |
319 | } |
269 | |
320 | |
270 | sub find_widget { |
321 | sub find_widget { |
271 | my ($self, $x, $y) = @_; |
322 | my ($self, $x, $y) = @_; |
272 | |
323 | |
|
|
324 | return () unless $self->{can_events}; |
|
|
325 | |
273 | return $self |
326 | return $self |
274 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
327 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
275 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
328 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
276 | |
329 | |
277 | () |
330 | () |
… | |
… | |
284 | } |
337 | } |
285 | |
338 | |
286 | sub check_size { |
339 | sub check_size { |
287 | my ($self) = @_; |
340 | my ($self) = @_; |
288 | |
341 | |
|
|
342 | return unless $self->{parent}; |
|
|
343 | |
289 | my ($w, $h) = $self->size_request; |
344 | my ($w, $h) = $self->size_request; |
290 | |
345 | |
291 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
346 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
292 | $self->{req_w} = $w; |
347 | $self->{req_w} = $w; |
293 | $self->{req_h} = $h; |
348 | $self->{req_h} = $h; |
294 | |
349 | |
295 | $self->{parent}->check_size |
350 | $self->{parent}->check_size; |
296 | if $self->{parent}; |
|
|
297 | } |
351 | } |
298 | } |
352 | } |
299 | |
353 | |
300 | sub update { |
354 | sub update { |
301 | my ($self) = @_; |
355 | my ($self) = @_; |
… | |
… | |
368 | |
422 | |
369 | package CFClient::UI::Empty; |
423 | package CFClient::UI::Empty; |
370 | |
424 | |
371 | our @ISA = CFClient::UI::Base::; |
425 | our @ISA = CFClient::UI::Base::; |
372 | |
426 | |
|
|
427 | sub new { |
|
|
428 | my ($class, %arg) = @_; |
|
|
429 | $class->SUPER::new (can_events => 0, %arg); |
|
|
430 | } |
|
|
431 | |
373 | sub size_request { |
432 | sub size_request { |
374 | (0, 0) |
433 | (0, 0) |
375 | } |
434 | } |
376 | |
435 | |
377 | sub draw { } |
436 | sub draw { } |
… | |
… | |
385 | sub new { |
444 | sub new { |
386 | my ($class, %arg) = @_; |
445 | my ($class, %arg) = @_; |
387 | |
446 | |
388 | my $children = delete $arg{children} || []; |
447 | my $children = delete $arg{children} || []; |
389 | |
448 | |
390 | my $self = $class->SUPER::new (children => [], %arg); |
449 | my $self = $class->SUPER::new (children => [], can_events => 0, %arg); |
391 | $self->add ($_) for @$children; |
450 | $self->add ($_) for @$children; |
392 | |
451 | |
393 | $self |
452 | $self |
394 | } |
453 | } |
395 | |
454 | |
… | |
… | |
414 | delete $child->{parent}; |
473 | delete $child->{parent}; |
415 | |
474 | |
416 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
475 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
417 | |
476 | |
418 | $self->check_size; |
477 | $self->check_size; |
|
|
478 | $self->update; |
419 | } |
479 | } |
420 | |
480 | |
421 | sub find_widget { |
481 | sub find_widget { |
422 | my ($self, $x, $y) = @_; |
482 | my ($self, $x, $y) = @_; |
423 | |
483 | |
… | |
… | |
551 | sub new { die } |
611 | sub new { die } |
552 | |
612 | |
553 | sub size_request { |
613 | sub size_request { |
554 | my ($self) = @_; |
614 | my ($self) = @_; |
555 | |
615 | |
556 | @$self{qw(child_w child_h)} = $self->child->size_request; |
616 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
557 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
617 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
558 | |
618 | |
559 | @$self{qw(child_w child_h)} |
619 | @$self{qw(child_w child_h)} |
560 | } |
620 | } |
561 | |
621 | |
… | |
… | |
571 | package CFClient::UI::Frame; |
631 | package CFClient::UI::Frame; |
572 | |
632 | |
573 | our @ISA = CFClient::UI::Bin::; |
633 | our @ISA = CFClient::UI::Bin::; |
574 | |
634 | |
575 | use CFClient::OpenGL; |
635 | use CFClient::OpenGL; |
576 | |
|
|
577 | sub size_request { |
|
|
578 | my ($self) = @_; |
|
|
579 | my $chld = $self->child |
|
|
580 | or return (0, 0); |
|
|
581 | |
|
|
582 | $chld->move (2, 2); |
|
|
583 | |
|
|
584 | map { $_ + 4 } $chld->size_request; |
|
|
585 | } |
|
|
586 | |
|
|
587 | sub size_allocate { |
|
|
588 | my ($self, $x, $y, $w, $h) = @_; |
|
|
589 | |
|
|
590 | $self->child->configure (2, 2, $w - 4, $h - 4); |
|
|
591 | } |
|
|
592 | |
|
|
593 | sub _draw { |
|
|
594 | my ($self) = @_; |
|
|
595 | |
|
|
596 | my $chld = $self->child; |
|
|
597 | |
|
|
598 | my ($w, $h) = $chld->size_request; |
|
|
599 | |
|
|
600 | glBegin GL_QUADS; |
|
|
601 | glColor 0, 0, 0; |
|
|
602 | glVertex 0 , 0; |
|
|
603 | glVertex 0 , $h + 4; |
|
|
604 | glVertex $w + 4 , $h + 4; |
|
|
605 | glVertex $w + 4 , 0; |
|
|
606 | glEnd; |
|
|
607 | |
|
|
608 | $chld->draw; |
|
|
609 | } |
|
|
610 | |
|
|
611 | ############################################################################# |
|
|
612 | |
|
|
613 | package CFClient::UI::FancyFrame; |
|
|
614 | |
|
|
615 | our @ISA = CFClient::UI::Bin::; |
|
|
616 | |
|
|
617 | use CFClient::OpenGL; |
|
|
618 | |
|
|
619 | my @tex = |
|
|
620 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
621 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
622 | |
636 | |
623 | sub new { |
637 | sub new { |
624 | my $class = shift; |
638 | my $class = shift; |
625 | |
639 | |
626 | # TODO: user_x, user_y, overwrite moveto? |
|
|
627 | |
|
|
628 | $class->SUPER::new ( |
640 | my $self = $class->SUPER::new ( |
629 | bg => [1, 1, 1, 1], |
641 | bg => [1, 1, 1, 1], |
630 | border_bg => [1, 1, 1, 1], |
642 | border_bg => [1, 1, 1, 1], |
631 | border => 0.8, |
643 | border => 0.8, |
632 | @_ |
644 | @_ |
633 | ) |
645 | ); |
|
|
646 | |
|
|
647 | $self |
|
|
648 | } |
|
|
649 | |
|
|
650 | sub set_size { |
|
|
651 | my ($self, $w, $h) = @_; |
|
|
652 | $self->{req_w} = $w; |
|
|
653 | $self->{req_h} = $h; |
|
|
654 | $self->check_size; |
|
|
655 | } |
|
|
656 | |
|
|
657 | sub size_request { |
|
|
658 | my ($self) = @_; |
|
|
659 | ($self->{req_w}, $self->{req_h}) |
|
|
660 | } |
|
|
661 | |
|
|
662 | sub size_allocate { |
|
|
663 | my ($self, $w, $h) = @_; |
|
|
664 | $self->{w} = $w; |
|
|
665 | $self->{h} = $h; |
|
|
666 | $self->child->configure (0, 0, $w, $h); |
|
|
667 | } |
|
|
668 | |
|
|
669 | sub _draw { |
|
|
670 | my ($self) = @_; |
|
|
671 | |
|
|
672 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
673 | |
|
|
674 | glEnable GL_BLEND; |
|
|
675 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
676 | glEnable GL_TEXTURE_2D; |
|
|
677 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
678 | |
|
|
679 | # glBegin GL_QUADS; |
|
|
680 | # glColor 0, 0, 0, 0; |
|
|
681 | # glVertex 0 , 0; |
|
|
682 | # glVertex 0 , $h; |
|
|
683 | # glVertex $w, $h; |
|
|
684 | # glVertex $w, 0; |
|
|
685 | # glEnd; |
|
|
686 | |
|
|
687 | |
|
|
688 | $self->child->draw; |
|
|
689 | glDisable GL_BLEND; |
|
|
690 | glDisable GL_TEXTURE_2D; |
|
|
691 | } |
|
|
692 | |
|
|
693 | ############################################################################# |
|
|
694 | |
|
|
695 | package CFClient::UI::FancyFrame; |
|
|
696 | |
|
|
697 | our @ISA = CFClient::UI::Bin::; |
|
|
698 | |
|
|
699 | use CFClient::OpenGL; |
|
|
700 | |
|
|
701 | my @tex = |
|
|
702 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
703 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
704 | |
|
|
705 | sub new { |
|
|
706 | my $class = shift; |
|
|
707 | |
|
|
708 | # TODO: user_x, user_y, overwrite moveto? |
|
|
709 | |
|
|
710 | my $self = $class->SUPER::new ( |
|
|
711 | bg => [1, 1, 1, 1], |
|
|
712 | border_bg => [1, 1, 1, 1], |
|
|
713 | border => 0.8, |
|
|
714 | can_events => 1, |
|
|
715 | @_ |
|
|
716 | ); |
|
|
717 | |
|
|
718 | $self->{title} &&= new CFClient::UI::Label |
|
|
719 | align => 0, |
|
|
720 | valign => 1, |
|
|
721 | text => $self->{title}, |
|
|
722 | fontsize => 1; |
|
|
723 | |
|
|
724 | $self |
634 | } |
725 | } |
635 | |
726 | |
636 | sub border { |
727 | sub border { |
637 | int $_[0]{border} * $::FONTSIZE |
728 | int $_[0]{border} * $::FONTSIZE |
638 | } |
729 | } |
… | |
… | |
653 | sub size_allocate { |
744 | sub size_allocate { |
654 | my ($self, $w, $h) = @_; |
745 | my ($self, $w, $h) = @_; |
655 | |
746 | |
656 | $h -= List::Util::max 0, $self->border * 2; |
747 | $h -= List::Util::max 0, $self->border * 2; |
657 | $w -= List::Util::max 0, $self->border * 2; |
748 | $w -= List::Util::max 0, $self->border * 2; |
|
|
749 | |
|
|
750 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
|
|
751 | if $self->{title}; |
658 | |
752 | |
659 | $self->child->configure ($self->border, $self->border, $w, $h); |
753 | $self->child->configure ($self->border, $self->border, $w, $h); |
660 | } |
754 | } |
661 | |
755 | |
662 | sub button_down { |
756 | sub button_down { |
… | |
… | |
742 | $bg->draw_quad ($border, $border, $cw, $ch); |
836 | $bg->draw_quad ($border, $border, $cw, $ch); |
743 | |
837 | |
744 | glDisable GL_TEXTURE_2D; |
838 | glDisable GL_TEXTURE_2D; |
745 | glDisable GL_BLEND; |
839 | glDisable GL_BLEND; |
746 | |
840 | |
|
|
841 | $self->{title}->draw if $self->{title}; |
747 | $self->child->draw; |
842 | $self->child->draw; |
748 | } |
843 | } |
749 | |
844 | |
750 | ############################################################################# |
845 | ############################################################################# |
751 | |
846 | |
… | |
… | |
793 | or next; |
888 | or next; |
794 | |
889 | |
795 | for my $x (0 .. $#$row) { |
890 | for my $x (0 .. $#$row) { |
796 | my $widget = $row->[$x] |
891 | my $widget = $row->[$x] |
797 | or next; |
892 | or next; |
798 | my ($w, $h) = $widget->size_request; |
893 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
799 | |
894 | |
800 | $w[$x] = max $w[$x], $w; |
895 | $w[$x] = max $w[$x], $w; |
801 | $h[$y] = max $h[$y], $h; |
896 | $h[$y] = max $h[$y], $h; |
802 | } |
897 | } |
803 | } |
898 | } |
… | |
… | |
908 | |
1003 | |
909 | ($h, $w) = ($w, $h); |
1004 | ($h, $w) = ($w, $h); |
910 | |
1005 | |
911 | my $children = $self->{children}; |
1006 | my $children = $self->{children}; |
912 | |
1007 | |
913 | my @h = map +($_->size_request)[0], @$children; |
1008 | my @h = map $_->{req_w}, @$children; |
914 | |
1009 | |
915 | my $req_h = List::Util::sum @h; |
1010 | my $req_h = List::Util::sum @h; |
916 | |
1011 | |
917 | if ($req_h > $h) { |
1012 | if ($req_h > $h) { |
918 | # ah well, not enough space |
1013 | # ah well, not enough space |
… | |
… | |
966 | sub size_allocate { |
1061 | sub size_allocate { |
967 | my ($self, $w, $h) = @_; |
1062 | my ($self, $w, $h) = @_; |
968 | |
1063 | |
969 | my $children = $self->{children}; |
1064 | my $children = $self->{children}; |
970 | |
1065 | |
971 | my @h = map +($_->size_request)[1], @$children; |
1066 | my @h = map $_->{req_h}, @$children; |
972 | |
1067 | |
973 | my $req_h = List::Util::sum @h; |
1068 | my $req_h = List::Util::sum @h; |
974 | |
1069 | |
975 | if ($req_h > $h) { |
1070 | if ($req_h > $h) { |
976 | # ah well, not enough space |
1071 | # ah well, not enough space |
… | |
… | |
1011 | sub new { |
1106 | sub new { |
1012 | my ($class, %arg) = @_; |
1107 | my ($class, %arg) = @_; |
1013 | |
1108 | |
1014 | my $self = $class->SUPER::new ( |
1109 | my $self = $class->SUPER::new ( |
1015 | fg => [1, 1, 1], |
1110 | fg => [1, 1, 1], |
|
|
1111 | #font => default_font |
1016 | fontsize => 1, |
1112 | fontsize => 1, |
1017 | text => "", |
1113 | text => "", |
1018 | align => -1, |
1114 | align => -1, |
1019 | valign => -1, |
1115 | valign => -1, |
1020 | padding => 2, |
1116 | padding => 2, |
1021 | layout => new CFClient::Layout, |
1117 | layout => new CFClient::Layout, |
|
|
1118 | can_events => 0, |
1022 | %arg |
1119 | %arg |
1023 | ); |
1120 | ); |
1024 | |
1121 | |
1025 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
1122 | if (exists $self->{template}) { |
|
|
1123 | my $layout = new CFClient::Layout; |
|
|
1124 | $layout->set_text (delete $self->{template}); |
|
|
1125 | $self->{template} = $layout; |
|
|
1126 | } |
1026 | |
1127 | |
1027 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1128 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1028 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1129 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1029 | |
1130 | |
1030 | $self |
1131 | $self |
… | |
… | |
1044 | my ($self, $text) = @_; |
1145 | my ($self, $text) = @_; |
1045 | |
1146 | |
1046 | $self->{layout}->set_text ($text); |
1147 | $self->{layout}->set_text ($text); |
1047 | |
1148 | |
1048 | delete $self->{texture}; |
1149 | delete $self->{texture}; |
|
|
1150 | $self->check_size; |
1049 | $self->update; |
1151 | $self->update; |
1050 | } |
1152 | } |
1051 | |
1153 | |
1052 | sub set_markup { |
1154 | sub set_markup { |
1053 | my ($self, $markup) = @_; |
1155 | my ($self, $markup) = @_; |
1054 | |
1156 | |
1055 | $self->{layout}->set_markup ($markup); |
1157 | $self->{layout}->set_markup ($markup); |
1056 | |
1158 | |
1057 | delete $self->{texture}; |
1159 | delete $self->{texture}; |
|
|
1160 | $self->check_size; |
1058 | $self->update; |
1161 | $self->update; |
1059 | } |
1162 | } |
1060 | |
1163 | |
1061 | sub size_request { |
1164 | sub size_request { |
1062 | my ($self) = @_; |
1165 | my ($self) = @_; |
1063 | |
1166 | |
1064 | $self->{layout}->set_width; |
1167 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
|
|
1168 | $self->{layout}->set_width ($self->{max_w} || -1); |
1065 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1169 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1066 | |
1170 | |
1067 | my ($w, $h) = $self->{layout}->size; |
1171 | my ($w, $h) = $self->{layout}->size; |
|
|
1172 | |
|
|
1173 | if (exists $self->{template}) { |
|
|
1174 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
|
|
1175 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
1176 | |
|
|
1177 | my ($w2, $h2) = $self->{template}->size; |
|
|
1178 | |
|
|
1179 | $w = List::Util::max $w, $w2; |
|
|
1180 | $h = List::Util::max $h, $h2; |
|
|
1181 | } |
1068 | |
1182 | |
1069 | ( |
1183 | ( |
1070 | $w + $self->{padding} * 2, |
1184 | $w + $self->{padding} * 2, |
1071 | $h + $self->{padding} * 2, |
1185 | $h + $self->{padding} * 2, |
1072 | ) |
1186 | ) |
… | |
… | |
1076 | my ($self, $w, $h) = @_; |
1190 | my ($self, $w, $h) = @_; |
1077 | |
1191 | |
1078 | delete $self->{texture}; |
1192 | delete $self->{texture}; |
1079 | } |
1193 | } |
1080 | |
1194 | |
|
|
1195 | sub set_fontsize { |
|
|
1196 | my ($self, $fontsize) = @_; |
|
|
1197 | |
|
|
1198 | $self->{fontsize} = $fontsize; |
|
|
1199 | delete $self->{texture}; |
|
|
1200 | $self->check_size; |
|
|
1201 | $self->update; |
|
|
1202 | } |
|
|
1203 | |
1081 | sub _draw { |
1204 | sub _draw { |
1082 | my ($self) = @_; |
1205 | my ($self) = @_; |
1083 | |
1206 | |
1084 | my $tex = $self->{texture} ||= do { |
1207 | my $tex = $self->{texture} ||= do { |
|
|
1208 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1085 | $self->{layout}->set_width ($self->{w}); |
1209 | $self->{layout}->set_width ($self->{w}); |
1086 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1210 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1087 | new_from_layout CFClient::Texture $self->{layout} |
1211 | new_from_layout CFClient::Texture $self->{layout} |
1088 | }; |
1212 | }; |
1089 | |
1213 | |
… | |
… | |
1129 | active_bg => [1, 1, 1, 0.5], |
1253 | active_bg => [1, 1, 1, 0.5], |
1130 | active_fg => [0, 0, 0], |
1254 | active_fg => [0, 0, 0], |
1131 | can_hover => 1, |
1255 | can_hover => 1, |
1132 | can_focus => 1, |
1256 | can_focus => 1, |
1133 | valign => 0, |
1257 | valign => 0, |
|
|
1258 | can_events => 1, |
1134 | @_ |
1259 | @_ |
1135 | ) |
1260 | ) |
1136 | } |
1261 | } |
1137 | |
1262 | |
1138 | sub _set_text { |
1263 | sub _set_text { |
… | |
… | |
1166 | } |
1291 | } |
1167 | |
1292 | |
1168 | sub size_allocate { |
1293 | sub size_allocate { |
1169 | my ($self, $w, $h) = @_; |
1294 | my ($self, $w, $h) = @_; |
1170 | |
1295 | |
1171 | $self->_set_text ($self->{text}); |
1296 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1172 | } |
1297 | } |
1173 | |
1298 | |
1174 | sub set_text { |
1299 | sub set_text { |
1175 | my ($self, $text) = @_; |
1300 | my ($self, $text) = @_; |
1176 | |
1301 | |
… | |
… | |
1309 | our @ISA = CFClient::UI::Label::; |
1434 | our @ISA = CFClient::UI::Label::; |
1310 | |
1435 | |
1311 | use CFClient::OpenGL; |
1436 | use CFClient::OpenGL; |
1312 | |
1437 | |
1313 | my @tex = |
1438 | my @tex = |
1314 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1439 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1315 | qw(b1_button_active.png); |
1440 | qw(b1_button_active.png); |
1316 | |
1441 | |
1317 | sub new { |
1442 | sub new { |
1318 | my $class = shift; |
1443 | my $class = shift; |
1319 | |
1444 | |
… | |
… | |
1323 | bg => [1, 1, 1, 0.2], |
1448 | bg => [1, 1, 1, 0.2], |
1324 | active_fg => [0, 0, 1], |
1449 | active_fg => [0, 0, 1], |
1325 | can_hover => 1, |
1450 | can_hover => 1, |
1326 | align => 0, |
1451 | align => 0, |
1327 | valign => 0, |
1452 | valign => 0, |
|
|
1453 | can_events => 1, |
1328 | @_ |
1454 | @_ |
1329 | ) |
1455 | ) |
1330 | } |
1456 | } |
1331 | |
1457 | |
1332 | sub button_up { |
1458 | sub button_up { |
… | |
… | |
1366 | package CFClient::UI::CheckBox; |
1492 | package CFClient::UI::CheckBox; |
1367 | |
1493 | |
1368 | our @ISA = CFClient::UI::DrawBG::; |
1494 | our @ISA = CFClient::UI::DrawBG::; |
1369 | |
1495 | |
1370 | my @tex = |
1496 | my @tex = |
1371 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1497 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1372 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1498 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1373 | |
1499 | |
1374 | use CFClient::OpenGL; |
1500 | use CFClient::OpenGL; |
1375 | |
1501 | |
1376 | sub new { |
1502 | sub new { |
… | |
… | |
1425 | glDisable GL_BLEND; |
1551 | glDisable GL_BLEND; |
1426 | } |
1552 | } |
1427 | |
1553 | |
1428 | ############################################################################# |
1554 | ############################################################################# |
1429 | |
1555 | |
1430 | package CFClient::UI::VGauge; |
1556 | package CFClient::UI::Image; |
1431 | |
1557 | |
1432 | our @ISA = CFClient::UI::Base::; |
1558 | our @ISA = CFClient::UI::Base::; |
1433 | |
1559 | |
1434 | use CFClient::OpenGL; |
1560 | use CFClient::OpenGL; |
|
|
1561 | use Carp qw/confess/; |
1435 | |
1562 | |
1436 | my %tex = ( |
1563 | our %loaded_images; |
1437 | food => [ |
|
|
1438 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1439 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1440 | ], |
|
|
1441 | grace => [ |
|
|
1442 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1443 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1444 | ], |
|
|
1445 | hp => [ |
|
|
1446 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1447 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1448 | ], |
|
|
1449 | mana => [ |
|
|
1450 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1451 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1452 | ], |
|
|
1453 | ); |
|
|
1454 | |
1564 | |
1455 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1456 | sub new { |
1565 | sub new { |
1457 | my $class = shift; |
1566 | my $class = shift; |
1458 | |
1567 | |
1459 | my $self = $class->SUPER::new ( |
1568 | my $self = $class->SUPER::new (can_events => 0, @_); |
1460 | gauge => 'food', |
|
|
1461 | @_ |
|
|
1462 | ); |
|
|
1463 | |
1569 | |
1464 | $self->{aspect} = $tex{$self->{gauge}}[0]{w} / $tex{$self->{gauge}}[0]{h}; |
1570 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
|
|
1571 | |
|
|
1572 | $loaded_images{$self->{image}} ||= |
|
|
1573 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
|
|
1574 | |
|
|
1575 | my $tex = $self->{tex} = $loaded_images{$self->{image}}; |
|
|
1576 | |
|
|
1577 | Scalar::Util::weaken $loaded_images{$self->{image}}; |
|
|
1578 | |
|
|
1579 | $self->{aspect} = $tex->{w} / $tex->{h}; |
1465 | |
1580 | |
1466 | $self |
1581 | $self |
1467 | } |
1582 | } |
1468 | |
1583 | |
1469 | sub size_request { |
1584 | sub size_request { |
1470 | my ($self) = @_; |
1585 | my ($self) = @_; |
1471 | |
1586 | |
1472 | my $tex = $tex{$self->{gauge}}[0]; |
1587 | ($self->{tex}->{w}, $self->{tex}->{h}) |
1473 | |
|
|
1474 | @$tex{qw(w h)} |
|
|
1475 | } |
|
|
1476 | |
|
|
1477 | sub set_max { |
|
|
1478 | my ($self, $max) = @_; |
|
|
1479 | |
|
|
1480 | $self->{max_val} = $max; |
|
|
1481 | } |
|
|
1482 | |
|
|
1483 | sub set_value { |
|
|
1484 | my ($self, $val, $max) = @_; |
|
|
1485 | |
|
|
1486 | $self->set_max ($max) |
|
|
1487 | if defined $max; |
|
|
1488 | |
|
|
1489 | $max = $self->{max_val}; |
|
|
1490 | $self->{val} = $val; |
|
|
1491 | |
|
|
1492 | $self->update; |
|
|
1493 | } |
1588 | } |
1494 | |
1589 | |
1495 | sub _draw { |
1590 | sub _draw { |
1496 | my ($self) = @_; |
1591 | my ($self) = @_; |
1497 | |
1592 | |
1498 | my $tex = $tex{$self->{gauge}}; |
1593 | my $tex = $self->{tex}; |
1499 | |
1594 | |
1500 | my ($w, $h) = ($self->{w}, $self->{h}); |
1595 | my ($w, $h) = ($self->{w}, $self->{h}); |
1501 | |
1596 | |
1502 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1597 | if ($self->{rot90}) { |
1503 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1598 | glRotate 90, 0, 0, 1; |
|
|
1599 | glTranslate 0, -$self->{w}, 0; |
1504 | |
1600 | |
1505 | my $t1 = $tex->[0]; |
1601 | ($w, $h) = ($h, $w); |
1506 | my $t2 = $tex->[1]; |
1602 | } |
1507 | |
1603 | |
1508 | glEnable GL_BLEND; |
1604 | glEnable GL_BLEND; |
1509 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1605 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1510 | glEnable GL_TEXTURE_2D; |
1606 | glEnable GL_TEXTURE_2D; |
1511 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1607 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1512 | |
1608 | |
|
|
1609 | $tex->draw_quad (0, 0, $w, $h); |
|
|
1610 | |
|
|
1611 | glDisable GL_BLEND; |
|
|
1612 | glDisable GL_TEXTURE_2D; |
|
|
1613 | } |
|
|
1614 | |
|
|
1615 | ############################################################################# |
|
|
1616 | |
|
|
1617 | package CFClient::UI::VGauge; |
|
|
1618 | |
|
|
1619 | our @ISA = CFClient::UI::Base::; |
|
|
1620 | |
|
|
1621 | use CFClient::OpenGL; |
|
|
1622 | |
|
|
1623 | my %tex = ( |
|
|
1624 | food => [ |
|
|
1625 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1626 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1627 | ], |
|
|
1628 | grace => [ |
|
|
1629 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1630 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1631 | ], |
|
|
1632 | hp => [ |
|
|
1633 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1634 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1635 | ], |
|
|
1636 | mana => [ |
|
|
1637 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1638 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1639 | ], |
|
|
1640 | ); |
|
|
1641 | |
|
|
1642 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1643 | sub new { |
|
|
1644 | my $class = shift; |
|
|
1645 | |
|
|
1646 | my $self = $class->SUPER::new ( |
|
|
1647 | type => 'food', |
|
|
1648 | @_ |
|
|
1649 | ); |
|
|
1650 | |
|
|
1651 | $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h}; |
|
|
1652 | |
|
|
1653 | $self |
|
|
1654 | } |
|
|
1655 | |
|
|
1656 | sub size_request { |
|
|
1657 | my ($self) = @_; |
|
|
1658 | |
|
|
1659 | #my $tex = $tex{$self->{type}}[0]; |
|
|
1660 | #@$tex{qw(w h)} |
|
|
1661 | (0, 0) |
|
|
1662 | } |
|
|
1663 | |
|
|
1664 | sub set_max { |
|
|
1665 | my ($self, $max) = @_; |
|
|
1666 | |
|
|
1667 | $self->{max_val} = $max; |
|
|
1668 | } |
|
|
1669 | |
|
|
1670 | sub set_value { |
|
|
1671 | my ($self, $val, $max) = @_; |
|
|
1672 | |
|
|
1673 | $self->set_max ($max) |
|
|
1674 | if defined $max; |
|
|
1675 | |
|
|
1676 | $max = $self->{max_val}; |
|
|
1677 | $self->{val} = $val; |
|
|
1678 | |
|
|
1679 | $self->update; |
|
|
1680 | } |
|
|
1681 | |
|
|
1682 | sub _draw { |
|
|
1683 | my ($self) = @_; |
|
|
1684 | |
|
|
1685 | my $tex = $tex{$self->{type}}; |
|
|
1686 | |
|
|
1687 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1688 | |
|
|
1689 | if ($self->{vertical}) { |
|
|
1690 | glRotate 90, 0, 0, 1; |
|
|
1691 | glTranslate 0, -$self->{w}, 0; |
|
|
1692 | |
|
|
1693 | ($w, $h) = ($h, $w); |
|
|
1694 | } |
|
|
1695 | |
|
|
1696 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1697 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1698 | |
|
|
1699 | my $t1 = $tex->[0]; |
|
|
1700 | my $t2 = $tex->[1]; |
|
|
1701 | |
|
|
1702 | glEnable GL_BLEND; |
|
|
1703 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1704 | glEnable GL_TEXTURE_2D; |
|
|
1705 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1706 | |
1513 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1707 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1514 | my $h2 = $ycut * $self->{h}; |
1708 | my $h2 = $ycut * $self->{h}; |
1515 | |
1709 | |
1516 | my $yp = 0; |
|
|
1517 | |
|
|
1518 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1710 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1519 | glBegin GL_QUADS; |
1711 | glBegin GL_QUADS; |
1520 | glTexCoord 0 , 0; glVertex 0 , $yp; |
1712 | glTexCoord 0 , 0; glVertex 0 , 0; |
1521 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
1713 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1522 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
1714 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1523 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
1715 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1524 | glEnd; |
1716 | glEnd; |
1525 | |
|
|
1526 | $yp += $h1; |
|
|
1527 | |
1717 | |
1528 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1718 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1529 | glBegin GL_QUADS; |
1719 | glBegin GL_QUADS; |
1530 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
1720 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1531 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
1721 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1532 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
1722 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1533 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
1723 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1534 | glEnd; |
1724 | glEnd; |
1535 | |
1725 | |
1536 | glDisable GL_BLEND; |
1726 | glDisable GL_BLEND; |
1537 | glDisable GL_TEXTURE_2D; |
1727 | glDisable GL_TEXTURE_2D; |
|
|
1728 | } |
|
|
1729 | |
|
|
1730 | ############################################################################# |
|
|
1731 | |
|
|
1732 | package CFClient::UI::Gauge; |
|
|
1733 | |
|
|
1734 | our @ISA = CFClient::UI::VBox::; |
|
|
1735 | |
|
|
1736 | sub new { |
|
|
1737 | my ($class, %arg) = @_; |
|
|
1738 | |
|
|
1739 | my $self = $class->SUPER::new ( |
|
|
1740 | tooltip => $arg{type}, |
|
|
1741 | %arg, |
|
|
1742 | ); |
|
|
1743 | |
|
|
1744 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1); |
|
|
1745 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1); |
|
|
1746 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1); |
|
|
1747 | |
|
|
1748 | $self |
|
|
1749 | } |
|
|
1750 | |
|
|
1751 | sub set_fontsize { |
|
|
1752 | my ($self, $fsize) = @_; |
|
|
1753 | |
|
|
1754 | $self->{value}->set_fontsize ($fsize); |
|
|
1755 | $self->{max} ->set_fontsize ($fsize); |
|
|
1756 | } |
|
|
1757 | |
|
|
1758 | sub set_value { |
|
|
1759 | my ($self, $val, $max) = @_; |
|
|
1760 | |
|
|
1761 | $self->set_max ($max) |
|
|
1762 | if defined $max; |
|
|
1763 | |
|
|
1764 | $self->{gauge}->set_value ($val, $max); |
|
|
1765 | $self->{value}->set_text ($val); |
|
|
1766 | } |
|
|
1767 | |
|
|
1768 | sub set_max { |
|
|
1769 | my ($self, $max) = @_; |
|
|
1770 | |
|
|
1771 | $self->{gauge}->set_max ($max); |
|
|
1772 | $self->{max}->set_text ($max); |
1538 | } |
1773 | } |
1539 | |
1774 | |
1540 | ############################################################################# |
1775 | ############################################################################# |
1541 | |
1776 | |
1542 | package CFClient::UI::Slider; |
1777 | package CFClient::UI::Slider; |
… | |
… | |
1683 | sub new { |
1918 | sub new { |
1684 | my $class = shift; |
1919 | my $class = shift; |
1685 | |
1920 | |
1686 | my $self = $class->SUPER::new ( |
1921 | my $self = $class->SUPER::new ( |
1687 | fontsize => 1, |
1922 | fontsize => 1, |
|
|
1923 | #font => default_font |
1688 | @_, |
1924 | @_, |
1689 | |
1925 | |
1690 | layout => (new CFClient::Layout), |
1926 | layout => (new CFClient::Layout), |
1691 | par => [], |
1927 | par => [], |
1692 | height => 0, |
1928 | height => 0, |
… | |
… | |
1732 | sub size_allocate { |
1968 | sub size_allocate { |
1733 | my ($self, $w, $h) = @_; |
1969 | my ($self, $w, $h) = @_; |
1734 | |
1970 | |
1735 | $self->SUPER::size_allocate ($w, $h); |
1971 | $self->SUPER::size_allocate ($w, $h); |
1736 | |
1972 | |
|
|
1973 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1737 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1974 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1738 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1975 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1739 | |
1976 | |
1740 | $self->reflow; |
1977 | $self->reflow; |
1741 | } |
1978 | } |
… | |
… | |
1793 | my $y1 = $top + $self->{h}; |
2030 | my $y1 = $top + $self->{h}; |
1794 | |
2031 | |
1795 | my $y = 0; |
2032 | my $y = 0; |
1796 | |
2033 | |
1797 | my $layout = $self->{layout}; |
2034 | my $layout = $self->{layout}; |
|
|
2035 | |
|
|
2036 | $layout->set_font ($self->{font}) if $self->{font}; |
1798 | |
2037 | |
1799 | for my $par (@{$self->{par}}) { |
2038 | for my $par (@{$self->{par}}) { |
1800 | my $h = $par->[0]; |
2039 | my $h = $par->[0]; |
1801 | |
2040 | |
1802 | if ($y0 < $y + $h && $y < $y1) { |
2041 | if ($y0 < $y + $h && $y < $y1) { |
… | |
… | |
1882 | my $class = shift; |
2121 | my $class = shift; |
1883 | |
2122 | |
1884 | my $self = $class->SUPER::new ( |
2123 | my $self = $class->SUPER::new ( |
1885 | state => 0, |
2124 | state => 0, |
1886 | connect_activate => \&toggle_flopper, |
2125 | connect_activate => \&toggle_flopper, |
|
|
2126 | can_events => 1, |
1887 | @_ |
2127 | @_ |
1888 | ); |
2128 | ); |
1889 | |
2129 | |
1890 | if ($self->{state}) { |
2130 | if ($self->{state}) { |
1891 | $self->{state} = 0; |
2131 | $self->{state} = 0; |
… | |
… | |
1911 | $self->emit (changed => $self->{state}); |
2151 | $self->emit (changed => $self->{state}); |
1912 | } |
2152 | } |
1913 | |
2153 | |
1914 | ############################################################################# |
2154 | ############################################################################# |
1915 | |
2155 | |
|
|
2156 | package CFClient::UI::Tooltip; |
|
|
2157 | |
|
|
2158 | our @ISA = CFClient::UI::Bin::; |
|
|
2159 | |
|
|
2160 | use CFClient::OpenGL; |
|
|
2161 | |
|
|
2162 | sub new { |
|
|
2163 | my $class = shift; |
|
|
2164 | |
|
|
2165 | $class->SUPER::new ( |
|
|
2166 | @_, |
|
|
2167 | can_events => 0, |
|
|
2168 | ) |
|
|
2169 | } |
|
|
2170 | |
|
|
2171 | sub set_text { |
|
|
2172 | my ($self, $text) = @_; |
|
|
2173 | |
|
|
2174 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
|
|
2175 | $self->{label}->set_text ($text); |
|
|
2176 | $self->add ($self->{label}); |
|
|
2177 | } |
|
|
2178 | |
|
|
2179 | sub size_request { |
|
|
2180 | my ($self) = @_; |
|
|
2181 | |
|
|
2182 | $self->child->set_max_size ($::WIDTH * 0.2); |
|
|
2183 | |
|
|
2184 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
|
|
2185 | |
|
|
2186 | ($w + 4, $h + 4) |
|
|
2187 | } |
|
|
2188 | |
|
|
2189 | sub _draw { |
|
|
2190 | my ($self) = @_; |
|
|
2191 | |
|
|
2192 | glPushMatrix; |
|
|
2193 | glTranslate 0.375, 0.375; |
|
|
2194 | |
|
|
2195 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2196 | |
|
|
2197 | glColor 1, 0.8, 0.4; |
|
|
2198 | glBegin GL_QUADS; |
|
|
2199 | glVertex 0 , 0; |
|
|
2200 | glVertex 0 , $h; |
|
|
2201 | glVertex $w, $h; |
|
|
2202 | glVertex $w, 0; |
|
|
2203 | glEnd; |
|
|
2204 | |
|
|
2205 | glColor 0, 0, 0; |
|
|
2206 | glBegin GL_LINE_LOOP; |
|
|
2207 | glVertex 0 , 0; |
|
|
2208 | glVertex 0 , $h; |
|
|
2209 | glVertex $w, $h; |
|
|
2210 | glVertex $w, 0; |
|
|
2211 | glEnd; |
|
|
2212 | |
|
|
2213 | glPopMatrix; |
|
|
2214 | |
|
|
2215 | glTranslate 2, 2; |
|
|
2216 | $self->SUPER::_draw; |
|
|
2217 | } |
|
|
2218 | |
|
|
2219 | ############################################################################# |
|
|
2220 | |
1916 | package CFClient::UI::Root; |
2221 | package CFClient::UI::Root; |
1917 | |
2222 | |
1918 | our @ISA = CFClient::UI::Container::; |
2223 | our @ISA = CFClient::UI::Container::; |
1919 | |
2224 | |
1920 | use CFClient::OpenGL; |
2225 | use CFClient::OpenGL; |
1921 | |
2226 | |
1922 | sub check_size { |
2227 | sub check_size { |
1923 | my ($self) = @_; |
2228 | my ($self) = @_; |
1924 | |
2229 | |
1925 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2230 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
1926 | } |
2231 | } |
1927 | |
2232 | |
1928 | sub size_request { |
2233 | sub size_request { |
1929 | ($::WIDTH, $::HEIGHT) |
2234 | ($::WIDTH, $::HEIGHT) |
1930 | } |
2235 | } |
… | |
… | |
1932 | sub configure { |
2237 | sub configure { |
1933 | my ($self, $x, $y, $w, $h) = @_; |
2238 | my ($self, $x, $y, $w, $h) = @_; |
1934 | |
2239 | |
1935 | $self->SUPER::configure ($x, $y, $w, $h); |
2240 | $self->SUPER::configure ($x, $y, $w, $h); |
1936 | |
2241 | |
1937 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
|
|
1938 | for @{$self->{children}}; |
2242 | for my $child (@{$self->{children}}) { |
|
|
2243 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
|
|
2244 | |
|
|
2245 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
|
|
2246 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
|
|
2247 | $child->configure ($X, $Y, $W,$H); |
|
|
2248 | } |
1939 | } |
2249 | } |
1940 | |
2250 | |
1941 | sub _topleft { |
2251 | sub _topleft { |
1942 | my ($self, $x, $y) = @_; |
2252 | my ($self, $x, $y) = @_; |
1943 | |
2253 | |
… | |
… | |
1951 | ::refresh (); |
2261 | ::refresh (); |
1952 | } |
2262 | } |
1953 | |
2263 | |
1954 | sub add { |
2264 | sub add { |
1955 | my ($self, $child) = @_; |
2265 | my ($self, $child) = @_; |
|
|
2266 | |
|
|
2267 | # integerize window positions |
|
|
2268 | $child->{x} = int $child->{x}; |
|
|
2269 | $child->{y} = int $child->{y}; |
1956 | |
2270 | |
1957 | $self->SUPER::add ($child); |
2271 | $self->SUPER::add ($child); |
1958 | } |
2272 | } |
1959 | |
2273 | |
1960 | sub on_refresh { |
2274 | sub on_refresh { |
… | |
… | |
1986 | ############################################################################# |
2300 | ############################################################################# |
1987 | |
2301 | |
1988 | package CFClient::UI; |
2302 | package CFClient::UI; |
1989 | |
2303 | |
1990 | $ROOT = new CFClient::UI::Root; |
2304 | $ROOT = new CFClient::UI::Root; |
|
|
2305 | $TOOLTIP = new CFClient::UI::Tooltip; |
1991 | |
2306 | |
1992 | 1 |
2307 | 1 |
1993 | |
2308 | |