… | |
… | |
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_(.*)$/) { |
… | |
… | |
134 | $self->{z} = $z if defined $z; |
168 | $self->{z} = $z if defined $z; |
135 | |
169 | |
136 | $self->update; |
170 | $self->update; |
137 | } |
171 | } |
138 | |
172 | |
139 | sub needs_redraw { |
173 | sub set_size { |
140 | 0 |
174 | my ($self, $w, $h) = @_; |
|
|
175 | |
|
|
176 | $self->{user_w} = $w; |
|
|
177 | $self->{user_h} = $h; |
|
|
178 | |
|
|
179 | $self->check_size; |
141 | } |
180 | } |
142 | |
181 | |
143 | sub size_request { |
182 | sub size_request { |
144 | require Carp; |
183 | require Carp; |
145 | Carp::confess "size_request is abtract"; |
184 | Carp::confess "size_request is abstract"; |
146 | } |
185 | } |
147 | |
186 | |
148 | sub configure { |
187 | sub configure { |
149 | my ($self, $x, $y, $w, $h) = @_; |
188 | my ($self, $x, $y, $w, $h) = @_; |
150 | |
189 | |
151 | $self->{x} = $x; |
|
|
152 | $self->{y} = $y; |
|
|
153 | |
|
|
154 | if ($self->{aspect}) { |
190 | if ($self->{aspect}) { |
155 | $w = List::Util::min $w, int $h * $self->{aspect}; |
191 | my $w2 = List::Util::min $w, int $h * $self->{aspect}; |
156 | $h = List::Util::min $h, int $w / $self->{aspect}; |
192 | my $h2 = List::Util::min $h, int $w / $self->{aspect}; |
157 | } |
|
|
158 | |
193 | |
|
|
194 | # use alignment to adjust x, y |
|
|
195 | |
|
|
196 | $x += int +($w - $w2) * 0.5; |
|
|
197 | $y += int +($h - $h2) * 0.5; |
|
|
198 | |
|
|
199 | ($w, $h) = ($w2, $h2); |
|
|
200 | } |
|
|
201 | |
|
|
202 | if ($self->{x} != $x || $self->{y} != $y) { |
|
|
203 | $self->{x} = $x; |
|
|
204 | $self->{y} = $y; |
|
|
205 | $self->update; |
|
|
206 | } |
|
|
207 | |
159 | return unless $self->{w} != $w || $self->{h} != $h; |
208 | if ($self->{w} != $w || $self->{h} != $h) { |
160 | |
|
|
161 | $self->{w} = $w; |
209 | $self->{w} = $w; |
162 | $self->{h} = $h; |
210 | $self->{h} = $h; |
163 | |
211 | |
164 | $self->size_allocate ($w, $h); |
212 | $self->size_allocate ($w, $h); |
165 | $self->update; |
213 | $self->update; |
|
|
214 | } |
166 | } |
215 | } |
167 | |
216 | |
168 | sub size_allocate { |
217 | sub size_allocate { |
169 | # nothing to be done |
218 | # nothing to be done |
|
|
219 | } |
|
|
220 | |
|
|
221 | sub set_max_size { |
|
|
222 | my ($self, $w, $h) = @_; |
|
|
223 | |
|
|
224 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
|
|
225 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
170 | } |
226 | } |
171 | |
227 | |
172 | # return top left coordinates |
228 | # return top left coordinates |
173 | sub _topleft { |
229 | sub _topleft { |
174 | my ($self, $x, $y) = @_; |
230 | my ($self, $x, $y) = @_; |
… | |
… | |
268 | } |
324 | } |
269 | |
325 | |
270 | sub find_widget { |
326 | sub find_widget { |
271 | my ($self, $x, $y) = @_; |
327 | my ($self, $x, $y) = @_; |
272 | |
328 | |
|
|
329 | return () unless $self->{can_events}; |
|
|
330 | |
273 | return $self |
331 | return $self |
274 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
332 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
275 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
333 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
276 | |
334 | |
277 | () |
335 | () |
… | |
… | |
284 | } |
342 | } |
285 | |
343 | |
286 | sub check_size { |
344 | sub check_size { |
287 | my ($self) = @_; |
345 | my ($self) = @_; |
288 | |
346 | |
289 | my ($w, $h) = $self->size_request; |
347 | $self->{parent} |
|
|
348 | or return 1; |
290 | |
349 | |
|
|
350 | my ($w, $h) = $self->{user_w} && $self->{user_h} |
|
|
351 | ? @$self{qw(user_w user_h)} |
|
|
352 | : $self->size_request; |
|
|
353 | |
291 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
354 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
292 | $self->{req_w} = $w; |
355 | $self->{req_w} = $w; |
293 | $self->{req_h} = $h; |
356 | $self->{req_h} = $h; |
294 | |
357 | |
295 | $self->{parent}->check_size |
358 | $self->{parent}->check_size |
296 | if $self->{parent}; |
359 | or $self->size_allocate ( |
|
|
360 | (List::Util::max $self->{w}, $w), |
|
|
361 | (List::Util::max $self->{h}, $h), |
|
|
362 | ); |
|
|
363 | |
|
|
364 | 1 |
|
|
365 | } else { |
|
|
366 | 0 |
297 | } |
367 | } |
298 | } |
368 | } |
299 | |
369 | |
300 | sub update { |
370 | sub update { |
301 | my ($self) = @_; |
371 | my ($self) = @_; |
… | |
… | |
368 | |
438 | |
369 | package CFClient::UI::Empty; |
439 | package CFClient::UI::Empty; |
370 | |
440 | |
371 | our @ISA = CFClient::UI::Base::; |
441 | our @ISA = CFClient::UI::Base::; |
372 | |
442 | |
|
|
443 | sub new { |
|
|
444 | my ($class, %arg) = @_; |
|
|
445 | $class->SUPER::new (can_events => 0, %arg); |
|
|
446 | } |
|
|
447 | |
373 | sub size_request { |
448 | sub size_request { |
374 | (0, 0) |
449 | (0, 0) |
375 | } |
450 | } |
376 | |
451 | |
377 | sub draw { } |
452 | sub draw { } |
… | |
… | |
385 | sub new { |
460 | sub new { |
386 | my ($class, %arg) = @_; |
461 | my ($class, %arg) = @_; |
387 | |
462 | |
388 | my $children = delete $arg{children} || []; |
463 | my $children = delete $arg{children} || []; |
389 | |
464 | |
390 | my $self = $class->SUPER::new (children => [], %arg); |
465 | my $self = $class->SUPER::new (children => [], can_events => 0, %arg); |
391 | $self->add ($_) for @$children; |
466 | $self->add ($_) for @$children; |
392 | |
467 | |
393 | $self |
468 | $self |
394 | } |
469 | } |
395 | |
470 | |
… | |
… | |
414 | delete $child->{parent}; |
489 | delete $child->{parent}; |
415 | |
490 | |
416 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
491 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
417 | |
492 | |
418 | $self->check_size; |
493 | $self->check_size; |
|
|
494 | $self->update; |
419 | } |
495 | } |
420 | |
496 | |
421 | sub find_widget { |
497 | sub find_widget { |
422 | my ($self, $x, $y) = @_; |
498 | my ($self, $x, $y) = @_; |
423 | |
499 | |
… | |
… | |
551 | sub new { die } |
627 | sub new { die } |
552 | |
628 | |
553 | sub size_request { |
629 | sub size_request { |
554 | my ($self) = @_; |
630 | my ($self) = @_; |
555 | |
631 | |
556 | @$self{qw(child_w child_h)} = $self->child->size_request; |
632 | @$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)}); |
633 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
558 | |
634 | |
559 | @$self{qw(child_w child_h)} |
635 | @$self{qw(child_w child_h)} |
560 | } |
636 | } |
561 | |
637 | |
… | |
… | |
571 | package CFClient::UI::Frame; |
647 | package CFClient::UI::Frame; |
572 | |
648 | |
573 | our @ISA = CFClient::UI::Bin::; |
649 | our @ISA = CFClient::UI::Bin::; |
574 | |
650 | |
575 | use CFClient::OpenGL; |
651 | 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 | |
652 | |
623 | sub new { |
653 | sub new { |
624 | my $class = shift; |
654 | my $class = shift; |
625 | |
655 | |
626 | # TODO: user_x, user_y, overwrite moveto? |
|
|
627 | |
|
|
628 | $class->SUPER::new ( |
656 | my $self = $class->SUPER::new ( |
629 | bg => [1, 1, 1, 1], |
657 | bg => [1, 1, 1, 1], |
630 | border_bg => [1, 1, 1, 1], |
658 | border_bg => [1, 1, 1, 1], |
631 | border => 0.8, |
659 | border => 0.8, |
632 | @_ |
660 | @_ |
633 | ) |
661 | ); |
|
|
662 | |
|
|
663 | $self |
|
|
664 | } |
|
|
665 | |
|
|
666 | sub _draw { |
|
|
667 | my ($self) = @_; |
|
|
668 | |
|
|
669 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
670 | |
|
|
671 | glEnable GL_BLEND; |
|
|
672 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
673 | glEnable GL_TEXTURE_2D; |
|
|
674 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
675 | |
|
|
676 | # glBegin GL_QUADS; |
|
|
677 | # glColor 0, 0, 0, 0; |
|
|
678 | # glVertex 0 , 0; |
|
|
679 | # glVertex 0 , $h; |
|
|
680 | # glVertex $w, $h; |
|
|
681 | # glVertex $w, 0; |
|
|
682 | # glEnd; |
|
|
683 | |
|
|
684 | |
|
|
685 | $self->child->draw; |
|
|
686 | glDisable GL_BLEND; |
|
|
687 | glDisable GL_TEXTURE_2D; |
|
|
688 | } |
|
|
689 | |
|
|
690 | ############################################################################# |
|
|
691 | |
|
|
692 | package CFClient::UI::FancyFrame; |
|
|
693 | |
|
|
694 | our @ISA = CFClient::UI::Bin::; |
|
|
695 | |
|
|
696 | use CFClient::OpenGL; |
|
|
697 | |
|
|
698 | my @tex = |
|
|
699 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
700 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
701 | |
|
|
702 | sub new { |
|
|
703 | my $class = shift; |
|
|
704 | |
|
|
705 | # TODO: user_x, user_y, overwrite moveto? |
|
|
706 | |
|
|
707 | my $self = $class->SUPER::new ( |
|
|
708 | bg => [1, 1, 1, 1], |
|
|
709 | border_bg => [1, 1, 1, 1], |
|
|
710 | border => 0.8, |
|
|
711 | can_events => 1, |
|
|
712 | @_ |
|
|
713 | ); |
|
|
714 | |
|
|
715 | $self->{title} &&= new CFClient::UI::Label |
|
|
716 | align => 0, |
|
|
717 | valign => 1, |
|
|
718 | text => $self->{title}, |
|
|
719 | fontsize => 1; |
|
|
720 | |
|
|
721 | $self |
634 | } |
722 | } |
635 | |
723 | |
636 | sub border { |
724 | sub border { |
637 | int $_[0]{border} * $::FONTSIZE |
725 | int $_[0]{border} * $::FONTSIZE |
638 | } |
726 | } |
639 | |
727 | |
640 | sub size_request { |
728 | sub size_request { |
641 | my ($self) = @_; |
729 | my ($self) = @_; |
642 | |
|
|
643 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
|
|
644 | |
730 | |
645 | my ($w, $h) = $self->SUPER::size_request; |
731 | my ($w, $h) = $self->SUPER::size_request; |
646 | |
732 | |
647 | ( |
733 | ( |
648 | $w + $self->border * 2, |
734 | $w + $self->border * 2, |
… | |
… | |
653 | sub size_allocate { |
739 | sub size_allocate { |
654 | my ($self, $w, $h) = @_; |
740 | my ($self, $w, $h) = @_; |
655 | |
741 | |
656 | $h -= List::Util::max 0, $self->border * 2; |
742 | $h -= List::Util::max 0, $self->border * 2; |
657 | $w -= List::Util::max 0, $self->border * 2; |
743 | $w -= List::Util::max 0, $self->border * 2; |
|
|
744 | |
|
|
745 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
|
|
746 | if $self->{title}; |
658 | |
747 | |
659 | $self->child->configure ($self->border, $self->border, $w, $h); |
748 | $self->child->configure ($self->border, $self->border, $w, $h); |
660 | } |
749 | } |
661 | |
750 | |
662 | sub button_down { |
751 | sub button_down { |
… | |
… | |
742 | $bg->draw_quad ($border, $border, $cw, $ch); |
831 | $bg->draw_quad ($border, $border, $cw, $ch); |
743 | |
832 | |
744 | glDisable GL_TEXTURE_2D; |
833 | glDisable GL_TEXTURE_2D; |
745 | glDisable GL_BLEND; |
834 | glDisable GL_BLEND; |
746 | |
835 | |
|
|
836 | $self->{title}->draw if $self->{title}; |
747 | $self->child->draw; |
837 | $self->child->draw; |
748 | } |
838 | } |
749 | |
839 | |
750 | ############################################################################# |
840 | ############################################################################# |
751 | |
841 | |
… | |
… | |
793 | or next; |
883 | or next; |
794 | |
884 | |
795 | for my $x (0 .. $#$row) { |
885 | for my $x (0 .. $#$row) { |
796 | my $widget = $row->[$x] |
886 | my $widget = $row->[$x] |
797 | or next; |
887 | or next; |
798 | my ($w, $h) = $widget->size_request; |
888 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
799 | |
889 | |
800 | $w[$x] = max $w[$x], $w; |
890 | $w[$x] = max $w[$x], $w; |
801 | $h[$y] = max $h[$y], $h; |
891 | $h[$y] = max $h[$y], $h; |
802 | } |
892 | } |
803 | } |
893 | } |
… | |
… | |
908 | |
998 | |
909 | ($h, $w) = ($w, $h); |
999 | ($h, $w) = ($w, $h); |
910 | |
1000 | |
911 | my $children = $self->{children}; |
1001 | my $children = $self->{children}; |
912 | |
1002 | |
913 | my @h = map +($_->size_request)[0], @$children; |
1003 | my @h = map $_->{req_w}, @$children; |
914 | |
1004 | |
915 | my $req_h = List::Util::sum @h; |
1005 | my $req_h = List::Util::sum @h; |
916 | |
1006 | |
917 | if ($req_h > $h) { |
1007 | if ($req_h > $h) { |
918 | # ah well, not enough space |
1008 | # ah well, not enough space |
… | |
… | |
966 | sub size_allocate { |
1056 | sub size_allocate { |
967 | my ($self, $w, $h) = @_; |
1057 | my ($self, $w, $h) = @_; |
968 | |
1058 | |
969 | my $children = $self->{children}; |
1059 | my $children = $self->{children}; |
970 | |
1060 | |
971 | my @h = map +($_->size_request)[1], @$children; |
1061 | my @h = map $_->{req_h}, @$children; |
972 | |
1062 | |
973 | my $req_h = List::Util::sum @h; |
1063 | my $req_h = List::Util::sum @h; |
974 | |
1064 | |
975 | if ($req_h > $h) { |
1065 | if ($req_h > $h) { |
976 | # ah well, not enough space |
1066 | # ah well, not enough space |
… | |
… | |
1011 | sub new { |
1101 | sub new { |
1012 | my ($class, %arg) = @_; |
1102 | my ($class, %arg) = @_; |
1013 | |
1103 | |
1014 | my $self = $class->SUPER::new ( |
1104 | my $self = $class->SUPER::new ( |
1015 | fg => [1, 1, 1], |
1105 | fg => [1, 1, 1], |
|
|
1106 | #font => default_font |
1016 | fontsize => 1, |
1107 | fontsize => 1, |
1017 | text => "", |
1108 | text => "", |
1018 | align => -1, |
1109 | align => -1, |
1019 | valign => -1, |
1110 | valign => -1, |
1020 | padding => 2, |
1111 | padding => 2, |
1021 | layout => new CFClient::Layout, |
1112 | layout => new CFClient::Layout, |
|
|
1113 | can_events => 0, |
1022 | %arg |
1114 | %arg |
1023 | ); |
1115 | ); |
1024 | |
1116 | |
1025 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
1117 | if (exists $self->{template}) { |
|
|
1118 | my $layout = new CFClient::Layout; |
|
|
1119 | $layout->set_text (delete $self->{template}); |
|
|
1120 | $self->{template} = $layout; |
|
|
1121 | } |
1026 | |
1122 | |
1027 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1123 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1028 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1124 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1029 | |
1125 | |
1030 | $self |
1126 | $self |
… | |
… | |
1044 | my ($self, $text) = @_; |
1140 | my ($self, $text) = @_; |
1045 | |
1141 | |
1046 | $self->{layout}->set_text ($text); |
1142 | $self->{layout}->set_text ($text); |
1047 | |
1143 | |
1048 | delete $self->{texture}; |
1144 | delete $self->{texture}; |
|
|
1145 | $self->check_size; |
1049 | $self->update; |
1146 | $self->update; |
1050 | } |
1147 | } |
1051 | |
1148 | |
1052 | sub set_markup { |
1149 | sub set_markup { |
1053 | my ($self, $markup) = @_; |
1150 | my ($self, $markup) = @_; |
1054 | |
1151 | |
1055 | $self->{layout}->set_markup ($markup); |
1152 | $self->{layout}->set_markup ($markup); |
1056 | |
1153 | |
1057 | delete $self->{texture}; |
1154 | delete $self->{texture}; |
|
|
1155 | $self->check_size; |
1058 | $self->update; |
1156 | $self->update; |
1059 | } |
1157 | } |
1060 | |
1158 | |
1061 | sub size_request { |
1159 | sub size_request { |
1062 | my ($self) = @_; |
1160 | my ($self) = @_; |
1063 | |
1161 | |
1064 | $self->{layout}->set_width; |
1162 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
|
|
1163 | $self->{layout}->set_width ($self->{max_w} || -1); |
1065 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1164 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1066 | |
1165 | |
1067 | my ($w, $h) = $self->{layout}->size; |
1166 | my ($w, $h) = $self->{layout}->size; |
|
|
1167 | |
|
|
1168 | if (exists $self->{template}) { |
|
|
1169 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
|
|
1170 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
1171 | |
|
|
1172 | my ($w2, $h2) = $self->{template}->size; |
|
|
1173 | |
|
|
1174 | $w = List::Util::max $w, $w2; |
|
|
1175 | $h = List::Util::max $h, $h2; |
|
|
1176 | } |
1068 | |
1177 | |
1069 | ( |
1178 | ( |
1070 | $w + $self->{padding} * 2, |
1179 | $w + $self->{padding} * 2, |
1071 | $h + $self->{padding} * 2, |
1180 | $h + $self->{padding} * 2, |
1072 | ) |
1181 | ) |
… | |
… | |
1076 | my ($self, $w, $h) = @_; |
1185 | my ($self, $w, $h) = @_; |
1077 | |
1186 | |
1078 | delete $self->{texture}; |
1187 | delete $self->{texture}; |
1079 | } |
1188 | } |
1080 | |
1189 | |
|
|
1190 | sub set_fontsize { |
|
|
1191 | my ($self, $fontsize) = @_; |
|
|
1192 | |
|
|
1193 | $self->{fontsize} = $fontsize; |
|
|
1194 | delete $self->{texture}; |
|
|
1195 | $self->check_size; |
|
|
1196 | $self->update; |
|
|
1197 | } |
|
|
1198 | |
1081 | sub _draw { |
1199 | sub _draw { |
1082 | my ($self) = @_; |
1200 | my ($self) = @_; |
1083 | |
1201 | |
1084 | my $tex = $self->{texture} ||= do { |
1202 | my $tex = $self->{texture} ||= do { |
|
|
1203 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1085 | $self->{layout}->set_width ($self->{w}); |
1204 | $self->{layout}->set_width ($self->{w}); |
1086 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1205 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1087 | new_from_layout CFClient::Texture $self->{layout} |
1206 | new_from_layout CFClient::Texture $self->{layout} |
1088 | }; |
1207 | }; |
1089 | |
1208 | |
… | |
… | |
1129 | active_bg => [1, 1, 1, 0.5], |
1248 | active_bg => [1, 1, 1, 0.5], |
1130 | active_fg => [0, 0, 0], |
1249 | active_fg => [0, 0, 0], |
1131 | can_hover => 1, |
1250 | can_hover => 1, |
1132 | can_focus => 1, |
1251 | can_focus => 1, |
1133 | valign => 0, |
1252 | valign => 0, |
|
|
1253 | can_events => 1, |
1134 | @_ |
1254 | @_ |
1135 | ) |
1255 | ) |
1136 | } |
1256 | } |
1137 | |
1257 | |
1138 | sub _set_text { |
1258 | sub _set_text { |
… | |
… | |
1166 | } |
1286 | } |
1167 | |
1287 | |
1168 | sub size_allocate { |
1288 | sub size_allocate { |
1169 | my ($self, $w, $h) = @_; |
1289 | my ($self, $w, $h) = @_; |
1170 | |
1290 | |
1171 | $self->_set_text ($self->{text}); |
1291 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1172 | } |
1292 | } |
1173 | |
1293 | |
1174 | sub set_text { |
1294 | sub set_text { |
1175 | my ($self, $text) = @_; |
1295 | my ($self, $text) = @_; |
1176 | |
1296 | |
… | |
… | |
1309 | our @ISA = CFClient::UI::Label::; |
1429 | our @ISA = CFClient::UI::Label::; |
1310 | |
1430 | |
1311 | use CFClient::OpenGL; |
1431 | use CFClient::OpenGL; |
1312 | |
1432 | |
1313 | my @tex = |
1433 | my @tex = |
1314 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1434 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1315 | qw(b1_button_active.png); |
1435 | qw(b1_button_active.png); |
1316 | |
1436 | |
1317 | sub new { |
1437 | sub new { |
1318 | my $class = shift; |
1438 | my $class = shift; |
1319 | |
1439 | |
… | |
… | |
1323 | bg => [1, 1, 1, 0.2], |
1443 | bg => [1, 1, 1, 0.2], |
1324 | active_fg => [0, 0, 1], |
1444 | active_fg => [0, 0, 1], |
1325 | can_hover => 1, |
1445 | can_hover => 1, |
1326 | align => 0, |
1446 | align => 0, |
1327 | valign => 0, |
1447 | valign => 0, |
|
|
1448 | can_events => 1, |
1328 | @_ |
1449 | @_ |
1329 | ) |
1450 | ) |
1330 | } |
1451 | } |
1331 | |
1452 | |
1332 | sub button_up { |
1453 | sub button_up { |
… | |
… | |
1366 | package CFClient::UI::CheckBox; |
1487 | package CFClient::UI::CheckBox; |
1367 | |
1488 | |
1368 | our @ISA = CFClient::UI::DrawBG::; |
1489 | our @ISA = CFClient::UI::DrawBG::; |
1369 | |
1490 | |
1370 | my @tex = |
1491 | my @tex = |
1371 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1492 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1372 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1493 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1373 | |
1494 | |
1374 | use CFClient::OpenGL; |
1495 | use CFClient::OpenGL; |
1375 | |
1496 | |
1376 | sub new { |
1497 | sub new { |
… | |
… | |
1425 | glDisable GL_BLEND; |
1546 | glDisable GL_BLEND; |
1426 | } |
1547 | } |
1427 | |
1548 | |
1428 | ############################################################################# |
1549 | ############################################################################# |
1429 | |
1550 | |
1430 | package CFClient::UI::VGauge; |
1551 | package CFClient::UI::Image; |
1431 | |
1552 | |
1432 | our @ISA = CFClient::UI::Base::; |
1553 | our @ISA = CFClient::UI::Base::; |
1433 | |
1554 | |
1434 | use CFClient::OpenGL; |
1555 | use CFClient::OpenGL; |
|
|
1556 | use Carp qw/confess/; |
1435 | |
1557 | |
1436 | my %tex = ( |
1558 | 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 | |
1559 | |
1455 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1456 | sub new { |
1560 | sub new { |
1457 | my $class = shift; |
1561 | my $class = shift; |
1458 | |
1562 | |
1459 | my $self = $class->SUPER::new ( |
1563 | my $self = $class->SUPER::new (can_events => 0, @_); |
1460 | gauge => 'food', |
|
|
1461 | @_ |
|
|
1462 | ); |
|
|
1463 | |
1564 | |
1464 | $self->{aspect} = $tex{$self->{gauge}}[0]{w} / $tex{$self->{gauge}}[0]{h}; |
1565 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
|
|
1566 | |
|
|
1567 | $loaded_images{$self->{image}} ||= |
|
|
1568 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
|
|
1569 | |
|
|
1570 | my $tex = $self->{tex} = $loaded_images{$self->{image}}; |
|
|
1571 | |
|
|
1572 | Scalar::Util::weaken $loaded_images{$self->{image}}; |
|
|
1573 | |
|
|
1574 | $self->{aspect} = $tex->{w} / $tex->{h}; |
1465 | |
1575 | |
1466 | $self |
1576 | $self |
1467 | } |
1577 | } |
1468 | |
1578 | |
1469 | sub size_request { |
1579 | sub size_request { |
1470 | my ($self) = @_; |
1580 | my ($self) = @_; |
1471 | |
1581 | |
1472 | my $tex = $tex{$self->{gauge}}[0]; |
1582 | ($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 | } |
1583 | } |
1494 | |
1584 | |
1495 | sub _draw { |
1585 | sub _draw { |
1496 | my ($self) = @_; |
1586 | my ($self) = @_; |
1497 | |
1587 | |
1498 | my $tex = $tex{$self->{gauge}}; |
1588 | my $tex = $self->{tex}; |
1499 | |
1589 | |
1500 | my ($w, $h) = ($self->{w}, $self->{h}); |
1590 | my ($w, $h) = ($self->{w}, $self->{h}); |
1501 | |
1591 | |
1502 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1592 | if ($self->{rot90}) { |
1503 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1593 | glRotate 90, 0, 0, 1; |
|
|
1594 | glTranslate 0, -$self->{w}, 0; |
1504 | |
1595 | |
1505 | my $t1 = $tex->[0]; |
1596 | ($w, $h) = ($h, $w); |
1506 | my $t2 = $tex->[1]; |
1597 | } |
1507 | |
1598 | |
1508 | glEnable GL_BLEND; |
1599 | glEnable GL_BLEND; |
1509 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1600 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1510 | glEnable GL_TEXTURE_2D; |
1601 | glEnable GL_TEXTURE_2D; |
1511 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1602 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1512 | |
1603 | |
|
|
1604 | $tex->draw_quad (0, 0, $w, $h); |
|
|
1605 | |
|
|
1606 | glDisable GL_BLEND; |
|
|
1607 | glDisable GL_TEXTURE_2D; |
|
|
1608 | } |
|
|
1609 | |
|
|
1610 | ############################################################################# |
|
|
1611 | |
|
|
1612 | package CFClient::UI::VGauge; |
|
|
1613 | |
|
|
1614 | our @ISA = CFClient::UI::Base::; |
|
|
1615 | |
|
|
1616 | use List::Util qw(min max); |
|
|
1617 | |
|
|
1618 | use CFClient::OpenGL; |
|
|
1619 | |
|
|
1620 | my %tex = ( |
|
|
1621 | food => [ |
|
|
1622 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1623 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1624 | ], |
|
|
1625 | grace => [ |
|
|
1626 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1627 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
|
|
1628 | ], |
|
|
1629 | hp => [ |
|
|
1630 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1631 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1632 | ], |
|
|
1633 | mana => [ |
|
|
1634 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1635 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
|
|
1636 | ], |
|
|
1637 | ); |
|
|
1638 | |
|
|
1639 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1640 | sub new { |
|
|
1641 | my $class = shift; |
|
|
1642 | |
|
|
1643 | my $self = $class->SUPER::new ( |
|
|
1644 | type => 'food', |
|
|
1645 | @_ |
|
|
1646 | ); |
|
|
1647 | |
|
|
1648 | $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h}; |
|
|
1649 | |
|
|
1650 | $self |
|
|
1651 | } |
|
|
1652 | |
|
|
1653 | sub size_request { |
|
|
1654 | my ($self) = @_; |
|
|
1655 | |
|
|
1656 | #my $tex = $tex{$self->{type}}[0]; |
|
|
1657 | #@$tex{qw(w h)} |
|
|
1658 | (0, 0) |
|
|
1659 | } |
|
|
1660 | |
|
|
1661 | sub set_max { |
|
|
1662 | my ($self, $max) = @_; |
|
|
1663 | |
|
|
1664 | $self->{max_val} = $max; |
|
|
1665 | } |
|
|
1666 | |
|
|
1667 | sub set_value { |
|
|
1668 | my ($self, $val, $max) = @_; |
|
|
1669 | |
|
|
1670 | $self->set_max ($max) |
|
|
1671 | if defined $max; |
|
|
1672 | |
|
|
1673 | $max = $self->{max_val}; |
|
|
1674 | $self->{val} = $val; |
|
|
1675 | |
|
|
1676 | $self->update; |
|
|
1677 | } |
|
|
1678 | |
|
|
1679 | sub _draw { |
|
|
1680 | my ($self) = @_; |
|
|
1681 | |
|
|
1682 | my $tex = $tex{$self->{type}}; |
|
|
1683 | my ($t1, $t2, $t3) = @$tex; |
|
|
1684 | |
|
|
1685 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1686 | |
|
|
1687 | if ($self->{vertical}) { |
|
|
1688 | glRotate 90, 0, 0, 1; |
|
|
1689 | glTranslate 0, -$self->{w}, 0; |
|
|
1690 | |
|
|
1691 | ($w, $h) = ($h, $w); |
|
|
1692 | } |
|
|
1693 | |
|
|
1694 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1695 | |
|
|
1696 | my $ycut1 = max 0, min 1, $ycut; |
|
|
1697 | my $ycut2 = max 0, min 1, $ycut - 1; |
|
|
1698 | |
1513 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1699 | my $h1 = $self->{h} * (1 - $ycut1); |
1514 | my $h2 = $ycut * $self->{h}; |
1700 | my $h2 = $self->{h} * (1 - $ycut2); |
1515 | |
1701 | |
1516 | my $yp = 0; |
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; |
1517 | |
1706 | |
1518 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1707 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1519 | glBegin GL_QUADS; |
1708 | glBegin GL_QUADS; |
1520 | glTexCoord 0 , 0; glVertex 0 , $yp; |
1709 | glTexCoord 0 , 0; glVertex 0 , 0; |
1521 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
1710 | glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1; |
1522 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
1711 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1; |
1523 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
1712 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1524 | glEnd; |
1713 | glEnd; |
1525 | |
1714 | |
1526 | $yp += $h1; |
1715 | my $ycut1 = List::Util::min 1, $ycut; |
1527 | |
|
|
1528 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1716 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1529 | glBegin GL_QUADS; |
1717 | glBegin GL_QUADS; |
1530 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
1718 | glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1; |
1531 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
1719 | glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2; |
1532 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
|
|
1533 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
1720 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2; |
|
|
1721 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1; |
1534 | glEnd; |
1722 | glEnd; |
|
|
1723 | |
|
|
1724 | if ($t3) { |
|
|
1725 | glBindTexture GL_TEXTURE_2D, $t3->{name}; |
|
|
1726 | glBegin GL_QUADS; |
|
|
1727 | glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2; |
|
|
1728 | glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h}; |
|
|
1729 | glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h}; |
|
|
1730 | glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2; |
|
|
1731 | glEnd; |
|
|
1732 | } |
1535 | |
1733 | |
1536 | glDisable GL_BLEND; |
1734 | glDisable GL_BLEND; |
1537 | glDisable GL_TEXTURE_2D; |
1735 | glDisable GL_TEXTURE_2D; |
|
|
1736 | } |
|
|
1737 | |
|
|
1738 | ############################################################################# |
|
|
1739 | |
|
|
1740 | package CFClient::UI::Gauge; |
|
|
1741 | |
|
|
1742 | our @ISA = CFClient::UI::VBox::; |
|
|
1743 | |
|
|
1744 | sub new { |
|
|
1745 | my ($class, %arg) = @_; |
|
|
1746 | |
|
|
1747 | my $self = $class->SUPER::new ( |
|
|
1748 | tooltip => $arg{type}, |
|
|
1749 | %arg, |
|
|
1750 | ); |
|
|
1751 | |
|
|
1752 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1); |
|
|
1753 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1); |
|
|
1754 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1); |
|
|
1755 | |
|
|
1756 | $self |
|
|
1757 | } |
|
|
1758 | |
|
|
1759 | sub set_fontsize { |
|
|
1760 | my ($self, $fsize) = @_; |
|
|
1761 | |
|
|
1762 | $self->{value}->set_fontsize ($fsize); |
|
|
1763 | $self->{max} ->set_fontsize ($fsize); |
|
|
1764 | } |
|
|
1765 | |
|
|
1766 | sub set_value { |
|
|
1767 | my ($self, $val, $max) = @_; |
|
|
1768 | |
|
|
1769 | $self->set_max ($max) |
|
|
1770 | if defined $max; |
|
|
1771 | |
|
|
1772 | $self->{gauge}->set_value ($val, $max); |
|
|
1773 | $self->{value}->set_text ($val); |
|
|
1774 | } |
|
|
1775 | |
|
|
1776 | sub set_max { |
|
|
1777 | my ($self, $max) = @_; |
|
|
1778 | |
|
|
1779 | $self->{gauge}->set_max ($max); |
|
|
1780 | $self->{max}->set_text ($max); |
1538 | } |
1781 | } |
1539 | |
1782 | |
1540 | ############################################################################# |
1783 | ############################################################################# |
1541 | |
1784 | |
1542 | package CFClient::UI::Slider; |
1785 | package CFClient::UI::Slider; |
… | |
… | |
1683 | sub new { |
1926 | sub new { |
1684 | my $class = shift; |
1927 | my $class = shift; |
1685 | |
1928 | |
1686 | my $self = $class->SUPER::new ( |
1929 | my $self = $class->SUPER::new ( |
1687 | fontsize => 1, |
1930 | fontsize => 1, |
|
|
1931 | #font => default_font |
1688 | @_, |
1932 | @_, |
1689 | |
1933 | |
1690 | layout => (new CFClient::Layout), |
1934 | layout => (new CFClient::Layout), |
1691 | par => [], |
1935 | par => [], |
1692 | height => 0, |
1936 | height => 0, |
… | |
… | |
1732 | sub size_allocate { |
1976 | sub size_allocate { |
1733 | my ($self, $w, $h) = @_; |
1977 | my ($self, $w, $h) = @_; |
1734 | |
1978 | |
1735 | $self->SUPER::size_allocate ($w, $h); |
1979 | $self->SUPER::size_allocate ($w, $h); |
1736 | |
1980 | |
|
|
1981 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1737 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1982 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1738 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1983 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1739 | |
1984 | |
1740 | $self->reflow; |
1985 | $self->reflow; |
1741 | } |
1986 | } |
… | |
… | |
1793 | my $y1 = $top + $self->{h}; |
2038 | my $y1 = $top + $self->{h}; |
1794 | |
2039 | |
1795 | my $y = 0; |
2040 | my $y = 0; |
1796 | |
2041 | |
1797 | my $layout = $self->{layout}; |
2042 | my $layout = $self->{layout}; |
|
|
2043 | |
|
|
2044 | $layout->set_font ($self->{font}) if $self->{font}; |
1798 | |
2045 | |
1799 | for my $par (@{$self->{par}}) { |
2046 | for my $par (@{$self->{par}}) { |
1800 | my $h = $par->[0]; |
2047 | my $h = $par->[0]; |
1801 | |
2048 | |
1802 | if ($y0 < $y + $h && $y < $y1) { |
2049 | if ($y0 < $y + $h && $y < $y1) { |
… | |
… | |
1882 | my $class = shift; |
2129 | my $class = shift; |
1883 | |
2130 | |
1884 | my $self = $class->SUPER::new ( |
2131 | my $self = $class->SUPER::new ( |
1885 | state => 0, |
2132 | state => 0, |
1886 | connect_activate => \&toggle_flopper, |
2133 | connect_activate => \&toggle_flopper, |
|
|
2134 | can_events => 1, |
1887 | @_ |
2135 | @_ |
1888 | ); |
2136 | ); |
1889 | |
2137 | |
1890 | if ($self->{state}) { |
2138 | if ($self->{state}) { |
1891 | $self->{state} = 0; |
2139 | $self->{state} = 0; |
… | |
… | |
1911 | $self->emit (changed => $self->{state}); |
2159 | $self->emit (changed => $self->{state}); |
1912 | } |
2160 | } |
1913 | |
2161 | |
1914 | ############################################################################# |
2162 | ############################################################################# |
1915 | |
2163 | |
|
|
2164 | package CFClient::UI::Tooltip; |
|
|
2165 | |
|
|
2166 | our @ISA = CFClient::UI::Bin::; |
|
|
2167 | |
|
|
2168 | use CFClient::OpenGL; |
|
|
2169 | |
|
|
2170 | sub new { |
|
|
2171 | my $class = shift; |
|
|
2172 | |
|
|
2173 | $class->SUPER::new ( |
|
|
2174 | @_, |
|
|
2175 | can_events => 0, |
|
|
2176 | ) |
|
|
2177 | } |
|
|
2178 | |
|
|
2179 | sub set_text { |
|
|
2180 | my ($self, $text) = @_; |
|
|
2181 | |
|
|
2182 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
|
|
2183 | $self->{label}->set_text ($text); |
|
|
2184 | $self->add ($self->{label}); |
|
|
2185 | } |
|
|
2186 | |
|
|
2187 | sub size_request { |
|
|
2188 | my ($self) = @_; |
|
|
2189 | |
|
|
2190 | $self->child->set_max_size ($::WIDTH * 0.2); |
|
|
2191 | |
|
|
2192 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
|
|
2193 | |
|
|
2194 | ($w + 4, $h + 4) |
|
|
2195 | } |
|
|
2196 | |
|
|
2197 | sub _draw { |
|
|
2198 | my ($self) = @_; |
|
|
2199 | |
|
|
2200 | glPushMatrix; |
|
|
2201 | glTranslate 0.375, 0.375; |
|
|
2202 | |
|
|
2203 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2204 | |
|
|
2205 | glColor 1, 0.8, 0.4; |
|
|
2206 | glBegin GL_QUADS; |
|
|
2207 | glVertex 0 , 0; |
|
|
2208 | glVertex 0 , $h; |
|
|
2209 | glVertex $w, $h; |
|
|
2210 | glVertex $w, 0; |
|
|
2211 | glEnd; |
|
|
2212 | |
|
|
2213 | glColor 0, 0, 0; |
|
|
2214 | glBegin GL_LINE_LOOP; |
|
|
2215 | glVertex 0 , 0; |
|
|
2216 | glVertex 0 , $h; |
|
|
2217 | glVertex $w, $h; |
|
|
2218 | glVertex $w, 0; |
|
|
2219 | glEnd; |
|
|
2220 | |
|
|
2221 | glPopMatrix; |
|
|
2222 | |
|
|
2223 | glTranslate 2, 2; |
|
|
2224 | $self->SUPER::_draw; |
|
|
2225 | } |
|
|
2226 | |
|
|
2227 | ############################################################################# |
|
|
2228 | |
1916 | package CFClient::UI::Root; |
2229 | package CFClient::UI::Root; |
1917 | |
2230 | |
1918 | our @ISA = CFClient::UI::Container::; |
2231 | our @ISA = CFClient::UI::Container::; |
1919 | |
2232 | |
1920 | use CFClient::OpenGL; |
2233 | use CFClient::OpenGL; |
1921 | |
2234 | |
1922 | sub check_size { |
2235 | sub check_size { |
1923 | my ($self) = @_; |
2236 | my ($self) = @_; |
1924 | |
2237 | |
1925 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2238 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
1926 | } |
2239 | } |
1927 | |
2240 | |
1928 | sub size_request { |
2241 | sub size_request { |
1929 | ($::WIDTH, $::HEIGHT) |
2242 | ($::WIDTH, $::HEIGHT) |
1930 | } |
2243 | } |
… | |
… | |
1932 | sub configure { |
2245 | sub configure { |
1933 | my ($self, $x, $y, $w, $h) = @_; |
2246 | my ($self, $x, $y, $w, $h) = @_; |
1934 | |
2247 | |
1935 | $self->SUPER::configure ($x, $y, $w, $h); |
2248 | $self->SUPER::configure ($x, $y, $w, $h); |
1936 | |
2249 | |
1937 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
|
|
1938 | for @{$self->{children}}; |
2250 | for my $child (@{$self->{children}}) { |
|
|
2251 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
|
|
2252 | |
|
|
2253 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
|
|
2254 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
|
|
2255 | $child->configure ($X, $Y, $W,$H); |
|
|
2256 | } |
1939 | } |
2257 | } |
1940 | |
2258 | |
1941 | sub _topleft { |
2259 | sub _topleft { |
1942 | my ($self, $x, $y) = @_; |
2260 | my ($self, $x, $y) = @_; |
1943 | |
2261 | |
… | |
… | |
1951 | ::refresh (); |
2269 | ::refresh (); |
1952 | } |
2270 | } |
1953 | |
2271 | |
1954 | sub add { |
2272 | sub add { |
1955 | my ($self, $child) = @_; |
2273 | my ($self, $child) = @_; |
|
|
2274 | |
|
|
2275 | # integerize window positions |
|
|
2276 | $child->{x} = int $child->{x}; |
|
|
2277 | $child->{y} = int $child->{y}; |
1956 | |
2278 | |
1957 | $self->SUPER::add ($child); |
2279 | $self->SUPER::add ($child); |
1958 | } |
2280 | } |
1959 | |
2281 | |
1960 | sub on_refresh { |
2282 | sub on_refresh { |
… | |
… | |
1986 | ############################################################################# |
2308 | ############################################################################# |
1987 | |
2309 | |
1988 | package CFClient::UI; |
2310 | package CFClient::UI; |
1989 | |
2311 | |
1990 | $ROOT = new CFClient::UI::Root; |
2312 | $ROOT = new CFClient::UI::Root; |
|
|
2313 | $TOOLTIP = new CFClient::UI::Tooltip; |
1991 | |
2314 | |
1992 | 1 |
2315 | 1 |
1993 | |
2316 | |