… | |
… | |
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 (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_markup ($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_(.*)$/) { |
… | |
… | |
108 | } |
142 | } |
109 | |
143 | |
110 | $self |
144 | $self |
111 | } |
145 | } |
112 | |
146 | |
|
|
147 | sub destroy { |
|
|
148 | my ($self) = @_; |
|
|
149 | |
|
|
150 | $self->hide; |
|
|
151 | %$self = (); |
|
|
152 | } |
|
|
153 | |
113 | sub show { |
154 | sub 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 | |
139 | sub needs_redraw { |
180 | sub 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 | |
143 | sub size_request { |
189 | sub 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 | |
148 | sub configure { |
194 | sub configure { |
149 | my ($self, $x, $y, $w, $h) = @_; |
195 | my ($self, $x, $y, $w, $h) = @_; |
150 | |
196 | |
… | |
… | |
152 | my $w2 = List::Util::min $w, int $h * $self->{aspect}; |
198 | my $w2 = List::Util::min $w, int $h * $self->{aspect}; |
153 | my $h2 = List::Util::min $h, int $w / $self->{aspect}; |
199 | my $h2 = List::Util::min $h, int $w / $self->{aspect}; |
154 | |
200 | |
155 | # use alignment to adjust x, y |
201 | # use alignment to adjust x, y |
156 | |
202 | |
157 | $x += ($w - $w2) * 0.5; |
203 | $x += int +($w - $w2) * 0.5; |
158 | $y += ($h - $h2) * 0.5; |
204 | $y += int +($h - $h2) * 0.5; |
159 | |
205 | |
160 | ($w, $h) = ($w2, $h2); |
206 | ($w, $h) = ($w2, $h2); |
161 | } |
207 | } |
162 | |
208 | |
163 | if ($self->{x} != $x || $self->{y} != $y) { |
209 | if ($self->{x} != $x || $self->{y} != $y) { |
… | |
… | |
175 | } |
221 | } |
176 | } |
222 | } |
177 | |
223 | |
178 | sub size_allocate { |
224 | sub size_allocate { |
179 | # nothing to be done |
225 | # nothing to be done |
|
|
226 | } |
|
|
227 | |
|
|
228 | sub 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; |
180 | } |
233 | } |
181 | |
234 | |
182 | # return top left coordinates |
235 | # return top left coordinates |
183 | sub _topleft { |
236 | sub _topleft { |
184 | my ($self, $x, $y) = @_; |
237 | my ($self, $x, $y) = @_; |
… | |
… | |
267 | glVertex $x + $self->{w}, $y + $self->{h}; |
320 | glVertex $x + $self->{w}, $y + $self->{h}; |
268 | glVertex $x , $y + $self->{h}; |
321 | glVertex $x , $y + $self->{h}; |
269 | glEnd; |
322 | glEnd; |
270 | glDisable GL_BLEND; |
323 | glDisable GL_BLEND; |
271 | } |
324 | } |
|
|
325 | |
|
|
326 | if ($ENV{PCLIENT_DEBUG}) { |
|
|
327 | glPushMatrix; |
|
|
328 | glColor 1, 1, 0, 1; |
|
|
329 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
|
|
330 | glBegin GL_LINE_LOOP; |
|
|
331 | glVertex 0 , 0; |
|
|
332 | glVertex $self->{w}, 0; |
|
|
333 | glVertex $self->{w}, $self->{h}; |
|
|
334 | glVertex 0 , $self->{h}; |
|
|
335 | glEnd; |
|
|
336 | glPopMatrix; |
|
|
337 | CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
338 | } |
272 | } |
339 | } |
273 | |
340 | |
274 | sub _draw { |
341 | sub _draw { |
275 | my ($self) = @_; |
342 | my ($self) = @_; |
276 | |
343 | |
277 | warn "no draw defined for $self\n"; |
344 | warn "no draw defined for $self\n"; |
278 | } |
345 | } |
279 | |
346 | |
280 | sub find_widget { |
347 | sub find_widget { |
281 | my ($self, $x, $y) = @_; |
348 | my ($self, $x, $y) = @_; |
|
|
349 | |
|
|
350 | return () unless $self->{can_events}; |
282 | |
351 | |
283 | return $self |
352 | return $self |
284 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
353 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
285 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
354 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
286 | |
355 | |
… | |
… | |
294 | } |
363 | } |
295 | |
364 | |
296 | sub check_size { |
365 | sub check_size { |
297 | my ($self) = @_; |
366 | my ($self) = @_; |
298 | |
367 | |
299 | my ($w, $h) = $self->size_request; |
368 | $self->{parent} |
|
|
369 | or return 1; |
300 | |
370 | |
|
|
371 | my ($w, $h) = $self->{user_w} && $self->{user_h} |
|
|
372 | ? @$self{qw(user_w user_h)} |
|
|
373 | : $self->size_request; |
|
|
374 | |
301 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
375 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
302 | $self->{req_w} = $w; |
376 | $self->{req_w} = $w; |
303 | $self->{req_h} = $h; |
377 | $self->{req_h} = $h; |
304 | |
378 | |
305 | $self->{parent}->check_size |
379 | $self->{parent}->check_size |
306 | if $self->{parent}; |
380 | or $self->size_allocate ( |
|
|
381 | (List::Util::max $self->{w}, $w), |
|
|
382 | (List::Util::max $self->{h}, $h), |
|
|
383 | ); |
|
|
384 | |
|
|
385 | 1 |
|
|
386 | } else { |
|
|
387 | 0 |
307 | } |
388 | } |
308 | } |
389 | } |
309 | |
390 | |
310 | sub update { |
391 | sub update { |
311 | my ($self) = @_; |
392 | my ($self) = @_; |
… | |
… | |
378 | |
459 | |
379 | package CFClient::UI::Empty; |
460 | package CFClient::UI::Empty; |
380 | |
461 | |
381 | our @ISA = CFClient::UI::Base::; |
462 | our @ISA = CFClient::UI::Base::; |
382 | |
463 | |
|
|
464 | sub new { |
|
|
465 | my ($class, %arg) = @_; |
|
|
466 | $class->SUPER::new (can_events => 0, %arg); |
|
|
467 | } |
|
|
468 | |
383 | sub size_request { |
469 | sub size_request { |
384 | (0, 0) |
470 | (0, 0) |
385 | } |
471 | } |
386 | |
472 | |
387 | sub draw { } |
473 | sub draw { } |
… | |
… | |
395 | sub new { |
481 | sub new { |
396 | my ($class, %arg) = @_; |
482 | my ($class, %arg) = @_; |
397 | |
483 | |
398 | my $children = delete $arg{children} || []; |
484 | my $children = delete $arg{children} || []; |
399 | |
485 | |
400 | my $self = $class->SUPER::new (children => [], %arg); |
486 | my $self = $class->SUPER::new (children => [], can_events => 0, %arg); |
401 | $self->add ($_) for @$children; |
487 | $self->add ($_) for @$children; |
402 | |
488 | |
403 | $self |
489 | $self |
404 | } |
490 | } |
405 | |
491 | |
… | |
… | |
424 | delete $child->{parent}; |
510 | delete $child->{parent}; |
425 | |
511 | |
426 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
512 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
427 | |
513 | |
428 | $self->check_size; |
514 | $self->check_size; |
|
|
515 | $self->update; |
|
|
516 | } |
|
|
517 | |
|
|
518 | sub clear { |
|
|
519 | my ($self) = @_; |
|
|
520 | |
|
|
521 | delete $_->{parent} |
|
|
522 | for @{ delete $self->{children} }; |
|
|
523 | |
|
|
524 | $self->{children} = []; |
429 | } |
525 | } |
430 | |
526 | |
431 | sub find_widget { |
527 | sub find_widget { |
432 | my ($self, $x, $y) = @_; |
528 | my ($self, $x, $y) = @_; |
433 | |
529 | |
… | |
… | |
561 | sub new { die } |
657 | sub new { die } |
562 | |
658 | |
563 | sub size_request { |
659 | sub size_request { |
564 | my ($self) = @_; |
660 | my ($self) = @_; |
565 | |
661 | |
566 | @$self{qw(child_w child_h)} = $self->child->size_request; |
662 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
567 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
663 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
568 | |
664 | |
569 | @$self{qw(child_w child_h)} |
665 | @$self{qw(child_w child_h)} |
570 | } |
666 | } |
571 | |
667 | |
… | |
… | |
581 | package CFClient::UI::Frame; |
677 | package CFClient::UI::Frame; |
582 | |
678 | |
583 | our @ISA = CFClient::UI::Bin::; |
679 | our @ISA = CFClient::UI::Bin::; |
584 | |
680 | |
585 | use CFClient::OpenGL; |
681 | use CFClient::OpenGL; |
586 | |
|
|
587 | sub size_request { |
|
|
588 | my ($self) = @_; |
|
|
589 | my $chld = $self->child |
|
|
590 | or return (0, 0); |
|
|
591 | |
|
|
592 | $chld->move (2, 2); |
|
|
593 | |
|
|
594 | map { $_ + 4 } $chld->size_request; |
|
|
595 | } |
|
|
596 | |
|
|
597 | sub size_allocate { |
|
|
598 | my ($self, $x, $y, $w, $h) = @_; |
|
|
599 | |
|
|
600 | $self->child->configure (2, 2, $w - 4, $h - 4); |
|
|
601 | } |
|
|
602 | |
|
|
603 | sub _draw { |
|
|
604 | my ($self) = @_; |
|
|
605 | |
|
|
606 | my $chld = $self->child; |
|
|
607 | |
|
|
608 | my ($w, $h) = $chld->size_request; |
|
|
609 | |
|
|
610 | glBegin GL_QUADS; |
|
|
611 | glColor 0, 0, 0; |
|
|
612 | glVertex 0 , 0; |
|
|
613 | glVertex 0 , $h + 4; |
|
|
614 | glVertex $w + 4 , $h + 4; |
|
|
615 | glVertex $w + 4 , 0; |
|
|
616 | glEnd; |
|
|
617 | |
|
|
618 | $chld->draw; |
|
|
619 | } |
|
|
620 | |
|
|
621 | ############################################################################# |
|
|
622 | |
|
|
623 | package CFClient::UI::FancyFrame; |
|
|
624 | |
|
|
625 | our @ISA = CFClient::UI::Bin::; |
|
|
626 | |
|
|
627 | use CFClient::OpenGL; |
|
|
628 | |
|
|
629 | my @tex = |
|
|
630 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
631 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
632 | |
682 | |
633 | sub new { |
683 | sub new { |
634 | my $class = shift; |
684 | my $class = shift; |
635 | |
|
|
636 | # TODO: user_x, user_y, overwrite moveto? |
|
|
637 | |
685 | |
638 | my $self = $class->SUPER::new ( |
686 | my $self = $class->SUPER::new ( |
639 | bg => [1, 1, 1, 1], |
687 | bg => [1, 1, 1, 1], |
640 | border_bg => [1, 1, 1, 1], |
688 | border_bg => [1, 1, 1, 1], |
641 | border => 0.8, |
689 | border => 0.8, |
642 | @_ |
690 | @_ |
643 | ); |
691 | ); |
644 | |
692 | |
|
|
693 | $self |
|
|
694 | } |
|
|
695 | |
|
|
696 | sub _draw { |
|
|
697 | my ($self) = @_; |
|
|
698 | |
|
|
699 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
700 | |
|
|
701 | glEnable GL_BLEND; |
|
|
702 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
703 | glEnable GL_TEXTURE_2D; |
|
|
704 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
705 | |
|
|
706 | # glBegin GL_QUADS; |
|
|
707 | # glColor 0, 0, 0, 0; |
|
|
708 | # glVertex 0 , 0; |
|
|
709 | # glVertex 0 , $h; |
|
|
710 | # glVertex $w, $h; |
|
|
711 | # glVertex $w, 0; |
|
|
712 | # glEnd; |
|
|
713 | |
|
|
714 | |
|
|
715 | $self->child->draw; |
|
|
716 | glDisable GL_BLEND; |
|
|
717 | glDisable GL_TEXTURE_2D; |
|
|
718 | } |
|
|
719 | |
|
|
720 | ############################################################################# |
|
|
721 | |
|
|
722 | package CFClient::UI::FancyFrame; |
|
|
723 | |
|
|
724 | our @ISA = CFClient::UI::Bin::; |
|
|
725 | |
|
|
726 | use CFClient::OpenGL; |
|
|
727 | |
|
|
728 | my @tex = |
|
|
729 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
730 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
731 | |
|
|
732 | sub new { |
|
|
733 | my $class = shift; |
|
|
734 | |
|
|
735 | # TODO: user_x, user_y, overwrite moveto? |
|
|
736 | |
|
|
737 | my $self = $class->SUPER::new ( |
|
|
738 | bg => [1, 1, 1, 1], |
|
|
739 | border_bg => [1, 1, 1, 1], |
|
|
740 | border => 0.8, |
|
|
741 | can_events => 1, |
|
|
742 | @_ |
|
|
743 | ); |
|
|
744 | |
645 | $self->{title} &&= new CFClient::UI::Label |
745 | $self->{title} &&= new CFClient::UI::Label |
646 | align => 0, |
746 | align => 0, |
647 | valign => 1, |
747 | valign => 1, |
648 | text => $self->{title}, |
748 | text => $self->{title}, |
649 | fontsize => 1; |
749 | fontsize => 1; |
… | |
… | |
656 | } |
756 | } |
657 | |
757 | |
658 | sub size_request { |
758 | sub size_request { |
659 | my ($self) = @_; |
759 | my ($self) = @_; |
660 | |
760 | |
661 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
|
|
662 | |
|
|
663 | my ($w, $h) = $self->SUPER::size_request; |
761 | my ($w, $h) = $self->SUPER::size_request; |
664 | |
762 | |
665 | ( |
763 | ( |
666 | $w + $self->border * 2, |
764 | $w + $self->border * 2, |
667 | $h + $self->border * 2, |
765 | $h + $self->border * 2, |
… | |
… | |
815 | or next; |
913 | or next; |
816 | |
914 | |
817 | for my $x (0 .. $#$row) { |
915 | for my $x (0 .. $#$row) { |
818 | my $widget = $row->[$x] |
916 | my $widget = $row->[$x] |
819 | or next; |
917 | or next; |
820 | my ($w, $h) = $widget->size_request; |
918 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
821 | |
919 | |
822 | $w[$x] = max $w[$x], $w; |
920 | $w[$x] = max $w[$x], $w; |
823 | $h[$y] = max $h[$y], $h; |
921 | $h[$y] = max $h[$y], $h; |
824 | } |
922 | } |
825 | } |
923 | } |
… | |
… | |
930 | |
1028 | |
931 | ($h, $w) = ($w, $h); |
1029 | ($h, $w) = ($w, $h); |
932 | |
1030 | |
933 | my $children = $self->{children}; |
1031 | my $children = $self->{children}; |
934 | |
1032 | |
935 | my @h = map +($_->size_request)[0], @$children; |
1033 | my @h = map $_->{req_w}, @$children; |
936 | |
1034 | |
937 | my $req_h = List::Util::sum @h; |
1035 | my $req_h = List::Util::sum @h; |
938 | |
1036 | |
939 | if ($req_h > $h) { |
1037 | if ($req_h > $h) { |
940 | # ah well, not enough space |
1038 | # ah well, not enough space |
… | |
… | |
988 | sub size_allocate { |
1086 | sub size_allocate { |
989 | my ($self, $w, $h) = @_; |
1087 | my ($self, $w, $h) = @_; |
990 | |
1088 | |
991 | my $children = $self->{children}; |
1089 | my $children = $self->{children}; |
992 | |
1090 | |
993 | my @h = map +($_->size_request)[1], @$children; |
1091 | my @h = map $_->{req_h}, @$children; |
994 | |
1092 | |
995 | my $req_h = List::Util::sum @h; |
1093 | my $req_h = List::Util::sum @h; |
996 | |
1094 | |
997 | if ($req_h > $h) { |
1095 | if ($req_h > $h) { |
998 | # ah well, not enough space |
1096 | # ah well, not enough space |
… | |
… | |
1033 | sub new { |
1131 | sub new { |
1034 | my ($class, %arg) = @_; |
1132 | my ($class, %arg) = @_; |
1035 | |
1133 | |
1036 | my $self = $class->SUPER::new ( |
1134 | my $self = $class->SUPER::new ( |
1037 | fg => [1, 1, 1], |
1135 | fg => [1, 1, 1], |
|
|
1136 | #font => default_font |
1038 | fontsize => 1, |
1137 | fontsize => 1, |
1039 | text => "", |
1138 | text => "", |
1040 | align => -1, |
1139 | align => -1, |
1041 | valign => -1, |
1140 | valign => -1, |
1042 | padding => 2, |
1141 | padding => 2, |
1043 | layout => new CFClient::Layout, |
1142 | layout => new CFClient::Layout, |
|
|
1143 | can_events => 0, |
1044 | %arg |
1144 | %arg |
1045 | ); |
1145 | ); |
1046 | |
1146 | |
1047 | if (exists $self->{template}) { |
1147 | if (exists $self->{template}) { |
1048 | my $layout = new CFClient::Layout; |
1148 | my $layout = new CFClient::Layout; |
… | |
… | |
1054 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1154 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1055 | |
1155 | |
1056 | $self |
1156 | $self |
1057 | } |
1157 | } |
1058 | |
1158 | |
1059 | sub escape_text { |
1159 | sub escape { |
1060 | local $_ = $_[1]; |
1160 | local $_ = $_[1]; |
1061 | |
1161 | |
1062 | s/&/&/g; |
1162 | s/&/&/g; |
1063 | s/>/>/g; |
1163 | s/>/>/g; |
1064 | s/</</g; |
1164 | s/</</g; |
… | |
… | |
1070 | my ($self, $text) = @_; |
1170 | my ($self, $text) = @_; |
1071 | |
1171 | |
1072 | $self->{layout}->set_text ($text); |
1172 | $self->{layout}->set_text ($text); |
1073 | |
1173 | |
1074 | delete $self->{texture}; |
1174 | delete $self->{texture}; |
|
|
1175 | $self->check_size; |
1075 | $self->update; |
1176 | $self->update; |
1076 | } |
1177 | } |
1077 | |
1178 | |
1078 | sub set_markup { |
1179 | sub set_markup { |
1079 | my ($self, $markup) = @_; |
1180 | my ($self, $markup) = @_; |
1080 | |
1181 | |
1081 | $self->{layout}->set_markup ($markup); |
1182 | $self->{layout}->set_markup ($markup); |
1082 | |
1183 | |
1083 | delete $self->{texture}; |
1184 | delete $self->{texture}; |
|
|
1185 | $self->check_size; |
1084 | $self->update; |
1186 | $self->update; |
1085 | } |
1187 | } |
1086 | |
1188 | |
1087 | sub size_request { |
1189 | sub size_request { |
1088 | my ($self) = @_; |
1190 | my ($self) = @_; |
1089 | |
1191 | |
1090 | $self->{layout}->set_width; |
1192 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
|
|
1193 | $self->{layout}->set_width ($self->{max_w} || -1); |
1091 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1194 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1092 | |
1195 | |
1093 | my ($w, $h) = $self->{layout}->size; |
1196 | my ($w, $h) = $self->{layout}->size; |
1094 | |
1197 | |
1095 | if (exists $self->{template}) { |
1198 | if (exists $self->{template}) { |
|
|
1199 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1096 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1200 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1097 | |
1201 | |
1098 | my ($w2, $h2) = $self->{template}->size; |
1202 | my ($w2, $h2) = $self->{template}->size; |
1099 | |
1203 | |
1100 | $w = List::Util::max $w, $w2; |
1204 | $w = List::Util::max $w, $w2; |
… | |
… | |
1111 | my ($self, $w, $h) = @_; |
1215 | my ($self, $w, $h) = @_; |
1112 | |
1216 | |
1113 | delete $self->{texture}; |
1217 | delete $self->{texture}; |
1114 | } |
1218 | } |
1115 | |
1219 | |
|
|
1220 | sub set_fontsize { |
|
|
1221 | my ($self, $fontsize) = @_; |
|
|
1222 | |
|
|
1223 | $self->{fontsize} = $fontsize; |
|
|
1224 | delete $self->{texture}; |
|
|
1225 | $self->check_size; |
|
|
1226 | $self->update; |
|
|
1227 | } |
|
|
1228 | |
1116 | sub _draw { |
1229 | sub _draw { |
1117 | my ($self) = @_; |
1230 | my ($self) = @_; |
1118 | |
1231 | |
1119 | my $tex = $self->{texture} ||= do { |
1232 | my $tex = $self->{texture} ||= do { |
|
|
1233 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1120 | $self->{layout}->set_width ($self->{w}); |
1234 | $self->{layout}->set_width ($self->{w}); |
1121 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1235 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1122 | new_from_layout CFClient::Texture $self->{layout} |
1236 | new_from_layout CFClient::Texture $self->{layout} |
1123 | }; |
1237 | }; |
1124 | |
1238 | |
… | |
… | |
1164 | active_bg => [1, 1, 1, 0.5], |
1278 | active_bg => [1, 1, 1, 0.5], |
1165 | active_fg => [0, 0, 0], |
1279 | active_fg => [0, 0, 0], |
1166 | can_hover => 1, |
1280 | can_hover => 1, |
1167 | can_focus => 1, |
1281 | can_focus => 1, |
1168 | valign => 0, |
1282 | valign => 0, |
|
|
1283 | can_events => 1, |
1169 | @_ |
1284 | @_ |
1170 | ) |
1285 | ) |
1171 | } |
1286 | } |
1172 | |
1287 | |
1173 | sub _set_text { |
1288 | sub _set_text { |
… | |
… | |
1201 | } |
1316 | } |
1202 | |
1317 | |
1203 | sub size_allocate { |
1318 | sub size_allocate { |
1204 | my ($self, $w, $h) = @_; |
1319 | my ($self, $w, $h) = @_; |
1205 | |
1320 | |
1206 | $self->_set_text ($self->{text}); |
1321 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1207 | } |
1322 | } |
1208 | |
1323 | |
1209 | sub set_text { |
1324 | sub set_text { |
1210 | my ($self, $text) = @_; |
1325 | my ($self, $text) = @_; |
1211 | |
1326 | |
… | |
… | |
1344 | our @ISA = CFClient::UI::Label::; |
1459 | our @ISA = CFClient::UI::Label::; |
1345 | |
1460 | |
1346 | use CFClient::OpenGL; |
1461 | use CFClient::OpenGL; |
1347 | |
1462 | |
1348 | my @tex = |
1463 | my @tex = |
1349 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1464 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1350 | qw(b1_button_active.png); |
1465 | qw(b1_button_active.png); |
1351 | |
1466 | |
1352 | sub new { |
1467 | sub new { |
1353 | my $class = shift; |
1468 | my $class = shift; |
1354 | |
1469 | |
… | |
… | |
1358 | bg => [1, 1, 1, 0.2], |
1473 | bg => [1, 1, 1, 0.2], |
1359 | active_fg => [0, 0, 1], |
1474 | active_fg => [0, 0, 1], |
1360 | can_hover => 1, |
1475 | can_hover => 1, |
1361 | align => 0, |
1476 | align => 0, |
1362 | valign => 0, |
1477 | valign => 0, |
|
|
1478 | can_events => 1, |
1363 | @_ |
1479 | @_ |
1364 | ) |
1480 | ) |
1365 | } |
1481 | } |
1366 | |
1482 | |
1367 | sub button_up { |
1483 | sub button_up { |
… | |
… | |
1401 | package CFClient::UI::CheckBox; |
1517 | package CFClient::UI::CheckBox; |
1402 | |
1518 | |
1403 | our @ISA = CFClient::UI::DrawBG::; |
1519 | our @ISA = CFClient::UI::DrawBG::; |
1404 | |
1520 | |
1405 | my @tex = |
1521 | my @tex = |
1406 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1522 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1407 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1523 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1408 | |
1524 | |
1409 | use CFClient::OpenGL; |
1525 | use CFClient::OpenGL; |
1410 | |
1526 | |
1411 | sub new { |
1527 | sub new { |
… | |
… | |
1460 | glDisable GL_BLEND; |
1576 | glDisable GL_BLEND; |
1461 | } |
1577 | } |
1462 | |
1578 | |
1463 | ############################################################################# |
1579 | ############################################################################# |
1464 | |
1580 | |
|
|
1581 | package CFClient::UI::Image; |
|
|
1582 | |
|
|
1583 | our @ISA = CFClient::UI::Base::; |
|
|
1584 | |
|
|
1585 | use CFClient::OpenGL; |
|
|
1586 | use Carp qw/confess/; |
|
|
1587 | |
|
|
1588 | our %loaded_images; |
|
|
1589 | |
|
|
1590 | sub new { |
|
|
1591 | my $class = shift; |
|
|
1592 | |
|
|
1593 | my $self = $class->SUPER::new (can_events => 0, @_); |
|
|
1594 | |
|
|
1595 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
|
|
1596 | |
|
|
1597 | $loaded_images{$self->{image}} ||= |
|
|
1598 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
|
|
1599 | |
|
|
1600 | my $tex = $self->{tex} = $loaded_images{$self->{image}}; |
|
|
1601 | |
|
|
1602 | Scalar::Util::weaken $loaded_images{$self->{image}}; |
|
|
1603 | |
|
|
1604 | $self->{aspect} = $tex->{w} / $tex->{h}; |
|
|
1605 | |
|
|
1606 | $self |
|
|
1607 | } |
|
|
1608 | |
|
|
1609 | sub size_request { |
|
|
1610 | my ($self) = @_; |
|
|
1611 | |
|
|
1612 | ($self->{tex}->{w}, $self->{tex}->{h}) |
|
|
1613 | } |
|
|
1614 | |
|
|
1615 | sub _draw { |
|
|
1616 | my ($self) = @_; |
|
|
1617 | |
|
|
1618 | my $tex = $self->{tex}; |
|
|
1619 | |
|
|
1620 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1621 | |
|
|
1622 | if ($self->{rot90}) { |
|
|
1623 | glRotate 90, 0, 0, 1; |
|
|
1624 | glTranslate 0, -$self->{w}, 0; |
|
|
1625 | |
|
|
1626 | ($w, $h) = ($h, $w); |
|
|
1627 | } |
|
|
1628 | |
|
|
1629 | glEnable GL_BLEND; |
|
|
1630 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1631 | glEnable GL_TEXTURE_2D; |
|
|
1632 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1633 | |
|
|
1634 | $tex->draw_quad (0, 0, $w, $h); |
|
|
1635 | |
|
|
1636 | glDisable GL_BLEND; |
|
|
1637 | glDisable GL_TEXTURE_2D; |
|
|
1638 | } |
|
|
1639 | |
|
|
1640 | ############################################################################# |
|
|
1641 | |
1465 | package CFClient::UI::VGauge; |
1642 | package CFClient::UI::VGauge; |
1466 | |
1643 | |
1467 | our @ISA = CFClient::UI::Base::; |
1644 | our @ISA = CFClient::UI::Base::; |
|
|
1645 | |
|
|
1646 | use List::Util qw(min max); |
1468 | |
1647 | |
1469 | use CFClient::OpenGL; |
1648 | use CFClient::OpenGL; |
1470 | |
1649 | |
1471 | my %tex = ( |
1650 | my %tex = ( |
1472 | food => [ |
1651 | food => [ |
1473 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1652 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1474 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
1653 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
1475 | ], |
1654 | ], |
1476 | grace => [ |
1655 | grace => [ |
1477 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1656 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1478 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
1657 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
1479 | ], |
1658 | ], |
1480 | hp => [ |
1659 | hp => [ |
1481 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1660 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1482 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
1661 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
1483 | ], |
1662 | ], |
1484 | mana => [ |
1663 | mana => [ |
1485 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1664 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1486 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
1665 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
1487 | ], |
1666 | ], |
1488 | ); |
1667 | ); |
1489 | |
1668 | |
1490 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
1669 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
1491 | sub new { |
1670 | sub new { |
… | |
… | |
1529 | |
1708 | |
1530 | sub _draw { |
1709 | sub _draw { |
1531 | my ($self) = @_; |
1710 | my ($self) = @_; |
1532 | |
1711 | |
1533 | my $tex = $tex{$self->{type}}; |
1712 | my $tex = $tex{$self->{type}}; |
|
|
1713 | my ($t1, $t2, $t3) = @$tex; |
1534 | |
1714 | |
1535 | my ($w, $h) = ($self->{w}, $self->{h}); |
1715 | my ($w, $h) = ($self->{w}, $self->{h}); |
1536 | |
1716 | |
1537 | if ($self->{vertical}) { |
1717 | if ($self->{vertical}) { |
1538 | glRotate 90, 0, 0, 1; |
1718 | glRotate 90, 0, 0, 1; |
… | |
… | |
1540 | |
1720 | |
1541 | ($w, $h) = ($h, $w); |
1721 | ($w, $h) = ($h, $w); |
1542 | } |
1722 | } |
1543 | |
1723 | |
1544 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1724 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1545 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1546 | |
1725 | |
1547 | my $t1 = $tex->[0]; |
1726 | my $ycut1 = max 0, min 1, $ycut; |
1548 | my $t2 = $tex->[1]; |
1727 | my $ycut2 = max 0, min 1, $ycut - 1; |
|
|
1728 | |
|
|
1729 | my $h1 = $self->{h} * (1 - $ycut1); |
|
|
1730 | my $h2 = $self->{h} * (1 - $ycut2); |
1549 | |
1731 | |
1550 | glEnable GL_BLEND; |
1732 | glEnable GL_BLEND; |
1551 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1733 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1552 | glEnable GL_TEXTURE_2D; |
1734 | glEnable GL_TEXTURE_2D; |
1553 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1735 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1554 | |
1736 | |
1555 | my $h1 = $self->{h} - $ycut * $self->{h}; |
|
|
1556 | my $h2 = $ycut * $self->{h}; |
|
|
1557 | |
|
|
1558 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1737 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1559 | glBegin GL_QUADS; |
1738 | glBegin GL_QUADS; |
1560 | glTexCoord 0 , 0; glVertex 0 , 0; |
1739 | glTexCoord 0 , 0; glVertex 0 , 0; |
1561 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1740 | glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1; |
1562 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1741 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1; |
1563 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1742 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1564 | glEnd; |
1743 | glEnd; |
1565 | |
1744 | |
|
|
1745 | my $ycut1 = List::Util::min 1, $ycut; |
1566 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1746 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1567 | glBegin GL_QUADS; |
1747 | glBegin GL_QUADS; |
1568 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1748 | glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1; |
1569 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1749 | glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2; |
1570 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1750 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2; |
1571 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1751 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1; |
1572 | glEnd; |
1752 | glEnd; |
|
|
1753 | |
|
|
1754 | if ($t3) { |
|
|
1755 | glBindTexture GL_TEXTURE_2D, $t3->{name}; |
|
|
1756 | glBegin GL_QUADS; |
|
|
1757 | glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2; |
|
|
1758 | glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h}; |
|
|
1759 | glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h}; |
|
|
1760 | glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2; |
|
|
1761 | glEnd; |
|
|
1762 | } |
1573 | |
1763 | |
1574 | glDisable GL_BLEND; |
1764 | glDisable GL_BLEND; |
1575 | glDisable GL_TEXTURE_2D; |
1765 | glDisable GL_TEXTURE_2D; |
1576 | } |
1766 | } |
1577 | |
1767 | |
… | |
… | |
1580 | package CFClient::UI::Gauge; |
1770 | package CFClient::UI::Gauge; |
1581 | |
1771 | |
1582 | our @ISA = CFClient::UI::VBox::; |
1772 | our @ISA = CFClient::UI::VBox::; |
1583 | |
1773 | |
1584 | sub new { |
1774 | sub new { |
1585 | my ($class, %arg) = shift; |
1775 | my ($class, %arg) = @_; |
1586 | |
1776 | |
1587 | my $self = $class->SUPER::new ( |
1777 | my $self = $class->SUPER::new ( |
1588 | @_, |
1778 | tooltip => $arg{type}, |
|
|
1779 | can_events => 1, |
|
|
1780 | can_hover => 1, |
|
|
1781 | %arg, |
1589 | ); |
1782 | ); |
1590 | |
1783 | |
1591 | $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
1784 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1592 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
1785 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
1593 | $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
1786 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); |
1594 | |
1787 | |
1595 | $self |
1788 | $self |
|
|
1789 | } |
|
|
1790 | |
|
|
1791 | sub set_fontsize { |
|
|
1792 | my ($self, $fsize) = @_; |
|
|
1793 | |
|
|
1794 | $self->{value}->set_fontsize ($fsize); |
|
|
1795 | $self->{max} ->set_fontsize ($fsize); |
1596 | } |
1796 | } |
1597 | |
1797 | |
1598 | sub set_value { |
1798 | sub set_value { |
1599 | my ($self, $val, $max) = @_; |
1799 | my ($self, $val, $max) = @_; |
1600 | |
1800 | |
… | |
… | |
1758 | sub new { |
1958 | sub new { |
1759 | my $class = shift; |
1959 | my $class = shift; |
1760 | |
1960 | |
1761 | my $self = $class->SUPER::new ( |
1961 | my $self = $class->SUPER::new ( |
1762 | fontsize => 1, |
1962 | fontsize => 1, |
|
|
1963 | #font => default_font |
1763 | @_, |
1964 | @_, |
1764 | |
1965 | |
1765 | layout => (new CFClient::Layout), |
1966 | layout => (new CFClient::Layout), |
1766 | par => [], |
1967 | par => [], |
1767 | height => 0, |
1968 | height => 0, |
… | |
… | |
1807 | sub size_allocate { |
2008 | sub size_allocate { |
1808 | my ($self, $w, $h) = @_; |
2009 | my ($self, $w, $h) = @_; |
1809 | |
2010 | |
1810 | $self->SUPER::size_allocate ($w, $h); |
2011 | $self->SUPER::size_allocate ($w, $h); |
1811 | |
2012 | |
|
|
2013 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1812 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2014 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1813 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2015 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1814 | |
2016 | |
1815 | $self->reflow; |
2017 | $self->reflow; |
1816 | } |
2018 | } |
… | |
… | |
1868 | my $y1 = $top + $self->{h}; |
2070 | my $y1 = $top + $self->{h}; |
1869 | |
2071 | |
1870 | my $y = 0; |
2072 | my $y = 0; |
1871 | |
2073 | |
1872 | my $layout = $self->{layout}; |
2074 | my $layout = $self->{layout}; |
|
|
2075 | |
|
|
2076 | $layout->set_font ($self->{font}) if $self->{font}; |
1873 | |
2077 | |
1874 | for my $par (@{$self->{par}}) { |
2078 | for my $par (@{$self->{par}}) { |
1875 | my $h = $par->[0]; |
2079 | my $h = $par->[0]; |
1876 | |
2080 | |
1877 | if ($y0 < $y + $h && $y < $y1) { |
2081 | if ($y0 < $y + $h && $y < $y1) { |
… | |
… | |
1957 | my $class = shift; |
2161 | my $class = shift; |
1958 | |
2162 | |
1959 | my $self = $class->SUPER::new ( |
2163 | my $self = $class->SUPER::new ( |
1960 | state => 0, |
2164 | state => 0, |
1961 | connect_activate => \&toggle_flopper, |
2165 | connect_activate => \&toggle_flopper, |
|
|
2166 | can_events => 1, |
1962 | @_ |
2167 | @_ |
1963 | ); |
2168 | ); |
1964 | |
2169 | |
1965 | if ($self->{state}) { |
2170 | if ($self->{state}) { |
1966 | $self->{state} = 0; |
2171 | $self->{state} = 0; |
… | |
… | |
1986 | $self->emit (changed => $self->{state}); |
2191 | $self->emit (changed => $self->{state}); |
1987 | } |
2192 | } |
1988 | |
2193 | |
1989 | ############################################################################# |
2194 | ############################################################################# |
1990 | |
2195 | |
|
|
2196 | package CFClient::UI::Tooltip; |
|
|
2197 | |
|
|
2198 | our @ISA = CFClient::UI::Bin::; |
|
|
2199 | |
|
|
2200 | use CFClient::OpenGL; |
|
|
2201 | |
|
|
2202 | sub new { |
|
|
2203 | my $class = shift; |
|
|
2204 | |
|
|
2205 | $class->SUPER::new ( |
|
|
2206 | @_, |
|
|
2207 | can_events => 0, |
|
|
2208 | ) |
|
|
2209 | } |
|
|
2210 | |
|
|
2211 | sub set_markup { |
|
|
2212 | my ($self, $text) = @_; |
|
|
2213 | |
|
|
2214 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
|
|
2215 | $self->{label}->set_markup ($text); |
|
|
2216 | $self->add ($self->{label}); |
|
|
2217 | } |
|
|
2218 | |
|
|
2219 | sub size_request { |
|
|
2220 | my ($self) = @_; |
|
|
2221 | |
|
|
2222 | $self->child->set_max_size ($::WIDTH * 0.3); |
|
|
2223 | |
|
|
2224 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
|
|
2225 | |
|
|
2226 | ($w + 4, $h + 4) |
|
|
2227 | } |
|
|
2228 | |
|
|
2229 | sub size_allocate { |
|
|
2230 | my ($self, $w, $h) = @_; |
|
|
2231 | |
|
|
2232 | $self->SUPER::size_allocate ($w - 4, $h - 4); |
|
|
2233 | } |
|
|
2234 | |
|
|
2235 | sub _draw { |
|
|
2236 | my ($self) = @_; |
|
|
2237 | |
|
|
2238 | glPushMatrix; |
|
|
2239 | glTranslate 0.375, 0.375; |
|
|
2240 | |
|
|
2241 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2242 | |
|
|
2243 | glColor 1, 0.8, 0.4; |
|
|
2244 | glBegin GL_QUADS; |
|
|
2245 | glVertex 0 , 0; |
|
|
2246 | glVertex 0 , $h; |
|
|
2247 | glVertex $w, $h; |
|
|
2248 | glVertex $w, 0; |
|
|
2249 | glEnd; |
|
|
2250 | |
|
|
2251 | glColor 0, 0, 0; |
|
|
2252 | glBegin GL_LINE_LOOP; |
|
|
2253 | glVertex 0 , 0; |
|
|
2254 | glVertex 0 , $h; |
|
|
2255 | glVertex $w, $h; |
|
|
2256 | glVertex $w, 0; |
|
|
2257 | glEnd; |
|
|
2258 | |
|
|
2259 | glPopMatrix; |
|
|
2260 | |
|
|
2261 | glTranslate 2, 2; |
|
|
2262 | $self->SUPER::_draw; |
|
|
2263 | } |
|
|
2264 | |
|
|
2265 | ############################################################################# |
|
|
2266 | |
|
|
2267 | package CFClient::UI::Face; |
|
|
2268 | |
|
|
2269 | our @ISA = CFClient::UI::Base::; |
|
|
2270 | |
|
|
2271 | use CFClient::OpenGL; |
|
|
2272 | |
|
|
2273 | sub new { |
|
|
2274 | my $class = shift; |
|
|
2275 | |
|
|
2276 | $class->SUPER::new ( |
|
|
2277 | aspect => 1, |
|
|
2278 | @_, |
|
|
2279 | ) |
|
|
2280 | } |
|
|
2281 | |
|
|
2282 | sub size_request { |
|
|
2283 | (32, 8) |
|
|
2284 | } |
|
|
2285 | |
|
|
2286 | sub draw { |
|
|
2287 | my ($self) = @_; |
|
|
2288 | |
|
|
2289 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
|
|
2290 | |
|
|
2291 | if ($tex) { |
|
|
2292 | glEnable GL_BLEND; |
|
|
2293 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2294 | glEnable GL_TEXTURE_2D; |
|
|
2295 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2296 | glColor 1, 1, 1, 1; |
|
|
2297 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
|
|
2298 | glDisable GL_TEXTURE_2D; |
|
|
2299 | glDisable GL_BLEND; |
|
|
2300 | } |
|
|
2301 | } |
|
|
2302 | |
|
|
2303 | ############################################################################# |
|
|
2304 | |
1991 | package CFClient::UI::Root; |
2305 | package CFClient::UI::Root; |
1992 | |
2306 | |
1993 | our @ISA = CFClient::UI::Container::; |
2307 | our @ISA = CFClient::UI::Container::; |
1994 | |
2308 | |
1995 | use CFClient::OpenGL; |
2309 | use CFClient::OpenGL; |
1996 | |
2310 | |
1997 | sub check_size { |
2311 | sub check_size { |
1998 | my ($self) = @_; |
2312 | my ($self) = @_; |
1999 | |
2313 | |
2000 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2314 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
2001 | } |
2315 | } |
2002 | |
2316 | |
2003 | sub size_request { |
2317 | sub size_request { |
2004 | ($::WIDTH, $::HEIGHT) |
2318 | ($::WIDTH, $::HEIGHT) |
2005 | } |
2319 | } |
… | |
… | |
2007 | sub configure { |
2321 | sub configure { |
2008 | my ($self, $x, $y, $w, $h) = @_; |
2322 | my ($self, $x, $y, $w, $h) = @_; |
2009 | |
2323 | |
2010 | $self->SUPER::configure ($x, $y, $w, $h); |
2324 | $self->SUPER::configure ($x, $y, $w, $h); |
2011 | |
2325 | |
2012 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
|
|
2013 | for @{$self->{children}}; |
2326 | for my $child (@{$self->{children}}) { |
|
|
2327 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
|
|
2328 | |
|
|
2329 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
|
|
2330 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
|
|
2331 | $child->configure ($X, $Y, $W,$H); |
|
|
2332 | } |
2014 | } |
2333 | } |
2015 | |
2334 | |
2016 | sub _topleft { |
2335 | sub _topleft { |
2017 | my ($self, $x, $y) = @_; |
2336 | my ($self, $x, $y) = @_; |
2018 | |
2337 | |
… | |
… | |
2026 | ::refresh (); |
2345 | ::refresh (); |
2027 | } |
2346 | } |
2028 | |
2347 | |
2029 | sub add { |
2348 | sub add { |
2030 | my ($self, $child) = @_; |
2349 | my ($self, $child) = @_; |
|
|
2350 | |
|
|
2351 | # integerize window positions |
|
|
2352 | $child->{x} = int $child->{x}; |
|
|
2353 | $child->{y} = int $child->{y}; |
2031 | |
2354 | |
2032 | $self->SUPER::add ($child); |
2355 | $self->SUPER::add ($child); |
2033 | } |
2356 | } |
2034 | |
2357 | |
2035 | sub on_refresh { |
2358 | sub on_refresh { |
… | |
… | |
2061 | ############################################################################# |
2384 | ############################################################################# |
2062 | |
2385 | |
2063 | package CFClient::UI; |
2386 | package CFClient::UI; |
2064 | |
2387 | |
2065 | $ROOT = new CFClient::UI::Root; |
2388 | $ROOT = new CFClient::UI::Root; |
|
|
2389 | $TOOLTIP = new CFClient::UI::Tooltip; |
2066 | |
2390 | |
2067 | 1 |
2391 | 1 |
2068 | |
2392 | |