… | |
… | |
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 | $TOOLTIP->set_text ($widget->{tooltip}); |
|
|
24 | $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); |
|
|
25 | $TOOLTIP->show; |
|
|
26 | } |
|
|
27 | |
|
|
28 | return; |
|
|
29 | } |
|
|
30 | } |
|
|
31 | } |
|
|
32 | |
|
|
33 | $TOOLTIP->hide; |
|
|
34 | delete $TOOLTIP->{owner}; |
|
|
35 | } |
14 | |
36 | |
15 | # class methods for events |
37 | # class methods for events |
16 | sub feed_sdl_key_down_event { |
38 | sub feed_sdl_key_down_event { |
17 | $FOCUS->key_down ($_[0]) if $FOCUS; |
39 | $FOCUS->key_down ($_[0]) if $FOCUS; |
18 | } |
40 | } |
… | |
… | |
28 | if (!$BUTTON_STATE) { |
50 | if (!$BUTTON_STATE) { |
29 | my $widget = $ROOT->find_widget ($x, $y); |
51 | my $widget = $ROOT->find_widget ($x, $y); |
30 | |
52 | |
31 | $GRAB = $widget; |
53 | $GRAB = $widget; |
32 | $GRAB->update if $GRAB; |
54 | $GRAB->update if $GRAB; |
|
|
55 | |
|
|
56 | check_tooltip; |
33 | } |
57 | } |
34 | |
58 | |
35 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
59 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
36 | |
60 | |
37 | $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
61 | $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
… | |
… | |
49 | |
73 | |
50 | if (!$BUTTON_STATE) { |
74 | if (!$BUTTON_STATE) { |
51 | my $grab = $GRAB; undef $GRAB; |
75 | my $grab = $GRAB; undef $GRAB; |
52 | $grab->update if $grab; |
76 | $grab->update if $grab; |
53 | $GRAB->update if $GRAB; |
77 | $GRAB->update if $GRAB; |
|
|
78 | |
|
|
79 | check_tooltip; |
54 | } |
80 | } |
55 | } |
81 | } |
56 | |
82 | |
57 | sub feed_sdl_motion_event { |
83 | sub feed_sdl_motion_event { |
58 | my ($ev) = @_; |
84 | my ($ev) = @_; |
… | |
… | |
63 | if ($widget != $HOVER) { |
89 | if ($widget != $HOVER) { |
64 | my $hover = $HOVER; $HOVER = $widget; |
90 | my $hover = $HOVER; $HOVER = $widget; |
65 | |
91 | |
66 | $hover->update if $hover && $hover->{can_hover}; |
92 | $hover->update if $hover && $hover->{can_hover}; |
67 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
93 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
|
|
94 | |
|
|
95 | check_tooltip; |
68 | } |
96 | } |
69 | |
97 | |
70 | $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; |
98 | $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; |
71 | } |
99 | } |
72 | |
100 | |
… | |
… | |
87 | |
115 | |
88 | package CFClient::UI::Base; |
116 | package CFClient::UI::Base; |
89 | |
117 | |
90 | use strict; |
118 | use strict; |
91 | |
119 | |
92 | use SDL::OpenGL; |
120 | use CFClient::OpenGL; |
93 | |
121 | |
94 | sub new { |
122 | sub new { |
95 | my $class = shift; |
123 | my $class = shift; |
96 | |
124 | |
97 | my $self = bless { |
125 | my $self = bless { |
98 | x => 0, |
126 | x => 0, |
99 | y => 0, |
127 | y => 0, |
100 | z => 0, |
128 | z => 0, |
|
|
129 | can_events => 1, |
101 | @_ |
130 | @_ |
102 | }, $class; |
131 | }, $class; |
103 | |
132 | |
104 | for (keys %$self) { |
133 | for (keys %$self) { |
105 | if (/^connect_(.*)$/) { |
134 | if (/^connect_(.*)$/) { |
… | |
… | |
140 | 0 |
169 | 0 |
141 | } |
170 | } |
142 | |
171 | |
143 | sub size_request { |
172 | sub size_request { |
144 | require Carp; |
173 | require Carp; |
145 | Carp::confess "size_request is abtract"; |
174 | Carp::confess "size_request is abstract"; |
146 | } |
175 | } |
147 | |
176 | |
148 | sub configure { |
177 | sub configure { |
149 | my ($self, $x, $y, $w, $h) = @_; |
178 | my ($self, $x, $y, $w, $h) = @_; |
150 | |
179 | |
|
|
180 | if ($self->{aspect}) { |
|
|
181 | my $w2 = List::Util::min $w, int $h * $self->{aspect}; |
|
|
182 | my $h2 = List::Util::min $h, int $w / $self->{aspect}; |
|
|
183 | |
|
|
184 | # use alignment to adjust x, y |
|
|
185 | |
|
|
186 | $x += int +($w - $w2) * 0.5; |
|
|
187 | $y += int +($h - $h2) * 0.5; |
|
|
188 | |
|
|
189 | ($w, $h) = ($w2, $h2); |
|
|
190 | } |
|
|
191 | |
|
|
192 | if ($self->{x} != $x || $self->{y} != $y) { |
151 | $self->{x} = $x; |
193 | $self->{x} = $x; |
152 | $self->{y} = $y; |
194 | $self->{y} = $y; |
|
|
195 | $self->update; |
|
|
196 | } |
153 | |
197 | |
154 | return unless $self->{w} != $w || $self->{h} != $h; |
198 | if ($self->{w} != $w || $self->{h} != $h) { |
155 | |
|
|
156 | $self->{w} = $w; |
199 | $self->{w} = $w; |
157 | $self->{h} = $h; |
200 | $self->{h} = $h; |
158 | |
201 | |
159 | $self->size_allocate ($w, $h); |
202 | $self->size_allocate ($w, $h); |
160 | $self->update; |
203 | $self->update; |
|
|
204 | } |
161 | } |
205 | } |
162 | |
206 | |
163 | sub size_allocate { |
207 | sub size_allocate { |
164 | # nothing to be done |
208 | # nothing to be done |
165 | } |
209 | } |
… | |
… | |
263 | } |
307 | } |
264 | |
308 | |
265 | sub find_widget { |
309 | sub find_widget { |
266 | my ($self, $x, $y) = @_; |
310 | my ($self, $x, $y) = @_; |
267 | |
311 | |
|
|
312 | return () unless $self->{can_events}; |
|
|
313 | |
268 | return $self |
314 | return $self |
269 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
315 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
270 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
316 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
271 | |
317 | |
272 | () |
318 | () |
… | |
… | |
279 | } |
325 | } |
280 | |
326 | |
281 | sub check_size { |
327 | sub check_size { |
282 | my ($self) = @_; |
328 | my ($self) = @_; |
283 | |
329 | |
|
|
330 | return unless $self->{parent}; |
|
|
331 | |
284 | my ($w, $h) = $self->size_request; |
332 | my ($w, $h) = $self->size_request; |
285 | |
333 | |
286 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
334 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
287 | $self->{req_w} = $w; |
335 | $self->{req_w} = $w; |
288 | $self->{req_h} = $h; |
336 | $self->{req_h} = $h; |
289 | |
337 | |
290 | $self->{parent}->check_size |
338 | $self->{parent}->check_size; |
291 | if $self->{parent}; |
|
|
292 | } |
339 | } |
293 | } |
340 | } |
294 | |
341 | |
295 | sub update { |
342 | sub update { |
296 | my ($self) = @_; |
343 | my ($self) = @_; |
… | |
… | |
324 | package CFClient::UI::DrawBG; |
371 | package CFClient::UI::DrawBG; |
325 | |
372 | |
326 | our @ISA = CFClient::UI::Base::; |
373 | our @ISA = CFClient::UI::Base::; |
327 | |
374 | |
328 | use strict; |
375 | use strict; |
329 | use SDL::OpenGL; |
376 | use CFClient::OpenGL; |
330 | |
377 | |
331 | sub new { |
378 | sub new { |
332 | my $class = shift; |
379 | my $class = shift; |
333 | |
380 | |
334 | # range [value, low, high, page] |
381 | # range [value, low, high, page] |
… | |
… | |
363 | |
410 | |
364 | package CFClient::UI::Empty; |
411 | package CFClient::UI::Empty; |
365 | |
412 | |
366 | our @ISA = CFClient::UI::Base::; |
413 | our @ISA = CFClient::UI::Base::; |
367 | |
414 | |
|
|
415 | sub new { |
|
|
416 | my ($class, %arg) = @_; |
|
|
417 | $class->SUPER::new (can_events => 0, %arg); |
|
|
418 | } |
|
|
419 | |
368 | sub size_request { |
420 | sub size_request { |
369 | (0, 0) |
421 | (0, 0) |
370 | } |
422 | } |
371 | |
423 | |
372 | sub draw { } |
424 | sub draw { } |
… | |
… | |
380 | sub new { |
432 | sub new { |
381 | my ($class, %arg) = @_; |
433 | my ($class, %arg) = @_; |
382 | |
434 | |
383 | my $children = delete $arg{children} || []; |
435 | my $children = delete $arg{children} || []; |
384 | |
436 | |
385 | my $self = $class->SUPER::new (children => [], %arg); |
437 | my $self = $class->SUPER::new (children => [], can_events => 0, %arg); |
386 | $self->add ($_) for @$children; |
438 | $self->add ($_) for @$children; |
387 | |
439 | |
388 | $self |
440 | $self |
389 | } |
441 | } |
390 | |
442 | |
… | |
… | |
409 | delete $child->{parent}; |
461 | delete $child->{parent}; |
410 | |
462 | |
411 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
463 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
412 | |
464 | |
413 | $self->check_size; |
465 | $self->check_size; |
|
|
466 | $self->update; |
414 | } |
467 | } |
415 | |
468 | |
416 | sub find_widget { |
469 | sub find_widget { |
417 | my ($self, $x, $y) = @_; |
470 | my ($self, $x, $y) = @_; |
418 | |
471 | |
… | |
… | |
482 | |
535 | |
483 | package CFClient::UI::Window; |
536 | package CFClient::UI::Window; |
484 | |
537 | |
485 | our @ISA = CFClient::UI::Bin::; |
538 | our @ISA = CFClient::UI::Bin::; |
486 | |
539 | |
487 | use SDL::OpenGL; |
540 | use CFClient::OpenGL; |
488 | |
541 | |
489 | sub new { |
542 | sub new { |
490 | my ($class, %arg) = @_; |
543 | my ($class, %arg) = @_; |
491 | |
544 | |
492 | my $self = $class->SUPER::new (%arg); |
545 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
546 | sub new { die } |
599 | sub new { die } |
547 | |
600 | |
548 | sub size_request { |
601 | sub size_request { |
549 | my ($self) = @_; |
602 | my ($self) = @_; |
550 | |
603 | |
551 | @$self{qw(child_w child_h)} = $self->child->size_request; |
604 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
552 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
605 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
553 | |
606 | |
554 | @$self{qw(child_w child_h)} |
607 | @$self{qw(child_w child_h)} |
555 | } |
608 | } |
556 | |
609 | |
… | |
… | |
565 | |
618 | |
566 | package CFClient::UI::Frame; |
619 | package CFClient::UI::Frame; |
567 | |
620 | |
568 | our @ISA = CFClient::UI::Bin::; |
621 | our @ISA = CFClient::UI::Bin::; |
569 | |
622 | |
570 | use SDL::OpenGL; |
623 | use CFClient::OpenGL; |
571 | |
|
|
572 | sub size_request { |
|
|
573 | my ($self) = @_; |
|
|
574 | my $chld = $self->child |
|
|
575 | or return (0, 0); |
|
|
576 | |
|
|
577 | $chld->move (2, 2); |
|
|
578 | |
|
|
579 | map { $_ + 4 } $chld->size_request; |
|
|
580 | } |
|
|
581 | |
|
|
582 | sub size_allocate { |
|
|
583 | my ($self, $x, $y, $w, $h) = @_; |
|
|
584 | |
|
|
585 | $self->child->configure (2, 2, $w - 4, $h - 4); |
|
|
586 | } |
|
|
587 | |
|
|
588 | sub _draw { |
|
|
589 | my ($self) = @_; |
|
|
590 | |
|
|
591 | my $chld = $self->child; |
|
|
592 | |
|
|
593 | my ($w, $h) = $chld->size_request; |
|
|
594 | |
|
|
595 | glBegin GL_QUADS; |
|
|
596 | glColor 0, 0, 0; |
|
|
597 | glVertex 0 , 0; |
|
|
598 | glVertex 0 , $h + 4; |
|
|
599 | glVertex $w + 4 , $h + 4; |
|
|
600 | glVertex $w + 4 , 0; |
|
|
601 | glEnd; |
|
|
602 | |
|
|
603 | $chld->draw; |
|
|
604 | } |
|
|
605 | |
|
|
606 | ############################################################################# |
|
|
607 | |
|
|
608 | package CFClient::UI::FancyFrame; |
|
|
609 | |
|
|
610 | our @ISA = CFClient::UI::Bin::; |
|
|
611 | |
|
|
612 | use SDL::OpenGL; |
|
|
613 | |
|
|
614 | my @tex = |
|
|
615 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
616 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
617 | |
624 | |
618 | sub new { |
625 | sub new { |
619 | my $class = shift; |
626 | my $class = shift; |
620 | |
627 | |
621 | # TODO: user_x, user_y, overwrite moveto? |
|
|
622 | |
|
|
623 | $class->SUPER::new ( |
628 | my $self = $class->SUPER::new ( |
624 | bg => [1, 1, 1, 1], |
629 | bg => [1, 1, 1, 1], |
625 | border_bg => [1, 1, 1, 1], |
630 | border_bg => [1, 1, 1, 1], |
626 | border => 0.8, |
631 | border => 0.8, |
627 | @_ |
632 | @_ |
628 | ) |
633 | ); |
|
|
634 | |
|
|
635 | $self |
|
|
636 | } |
|
|
637 | |
|
|
638 | sub set_size { |
|
|
639 | my ($self, $w, $h) = @_; |
|
|
640 | $self->{req_w} = $w; |
|
|
641 | $self->{req_h} = $h; |
|
|
642 | $self->check_size; |
|
|
643 | } |
|
|
644 | |
|
|
645 | sub size_request { |
|
|
646 | my ($self) = @_; |
|
|
647 | ($self->{req_w}, $self->{req_h}) |
|
|
648 | } |
|
|
649 | |
|
|
650 | sub size_allocate { |
|
|
651 | my ($self, $w, $h) = @_; |
|
|
652 | $self->{w} = $w; |
|
|
653 | $self->{h} = $h; |
|
|
654 | $self->child->configure (0, 0, $w, $h); |
|
|
655 | } |
|
|
656 | |
|
|
657 | sub _draw { |
|
|
658 | my ($self) = @_; |
|
|
659 | |
|
|
660 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
661 | |
|
|
662 | glEnable GL_BLEND; |
|
|
663 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
664 | glEnable GL_TEXTURE_2D; |
|
|
665 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
666 | |
|
|
667 | # glBegin GL_QUADS; |
|
|
668 | # glColor 0, 0, 0, 0; |
|
|
669 | # glVertex 0 , 0; |
|
|
670 | # glVertex 0 , $h; |
|
|
671 | # glVertex $w, $h; |
|
|
672 | # glVertex $w, 0; |
|
|
673 | # glEnd; |
|
|
674 | |
|
|
675 | |
|
|
676 | $self->child->draw; |
|
|
677 | glDisable GL_BLEND; |
|
|
678 | glDisable GL_TEXTURE_2D; |
|
|
679 | } |
|
|
680 | |
|
|
681 | ############################################################################# |
|
|
682 | |
|
|
683 | package CFClient::UI::FancyFrame; |
|
|
684 | |
|
|
685 | our @ISA = CFClient::UI::Bin::; |
|
|
686 | |
|
|
687 | use CFClient::OpenGL; |
|
|
688 | |
|
|
689 | my @tex = |
|
|
690 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
691 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
692 | |
|
|
693 | sub new { |
|
|
694 | my $class = shift; |
|
|
695 | |
|
|
696 | # TODO: user_x, user_y, overwrite moveto? |
|
|
697 | |
|
|
698 | my $self = $class->SUPER::new ( |
|
|
699 | bg => [1, 1, 1, 1], |
|
|
700 | border_bg => [1, 1, 1, 1], |
|
|
701 | border => 0.8, |
|
|
702 | can_events => 1, |
|
|
703 | @_ |
|
|
704 | ); |
|
|
705 | |
|
|
706 | $self->{title} &&= new CFClient::UI::Label |
|
|
707 | align => 0, |
|
|
708 | valign => 1, |
|
|
709 | text => $self->{title}, |
|
|
710 | fontsize => 1; |
|
|
711 | |
|
|
712 | $self |
629 | } |
713 | } |
630 | |
714 | |
631 | sub border { |
715 | sub border { |
632 | int $_[0]{border} * $::FONTSIZE |
716 | int $_[0]{border} * $::FONTSIZE |
633 | } |
717 | } |
… | |
… | |
649 | my ($self, $w, $h) = @_; |
733 | my ($self, $w, $h) = @_; |
650 | |
734 | |
651 | $h -= List::Util::max 0, $self->border * 2; |
735 | $h -= List::Util::max 0, $self->border * 2; |
652 | $w -= List::Util::max 0, $self->border * 2; |
736 | $w -= List::Util::max 0, $self->border * 2; |
653 | |
737 | |
|
|
738 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
|
|
739 | if $self->{title}; |
|
|
740 | |
654 | $self->child->configure ($self->border, $self->border, $w, $h); |
741 | $self->child->configure ($self->border, $self->border, $w, $h); |
655 | } |
742 | } |
656 | |
743 | |
657 | sub button_down { |
744 | sub button_down { |
658 | my ($self, $ev, $x, $y) = @_; |
745 | my ($self, $ev, $x, $y) = @_; |
… | |
… | |
660 | my $border = $self->border; |
747 | my $border = $self->border; |
661 | |
748 | |
662 | if ($x < $self->{w} && $x >= $self->{w} - $border |
749 | if ($x < $self->{w} && $x >= $self->{w} - $border |
663 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
750 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
664 | |
751 | |
665 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
752 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
666 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
753 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
667 | |
754 | |
668 | $self->{motion} = sub { |
755 | $self->{motion} = sub { |
669 | my ($ev, $x, $y) = @_; |
756 | my ($ev, $x, $y) = @_; |
670 | |
757 | |
671 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
758 | ($x, $y) = ($ev->{x}, $ev->{y}); |
672 | |
759 | |
673 | $self->{user_w} = $bw + $x - $ox; |
760 | $self->{user_w} = $bw + $x - $ox; |
674 | $self->{user_h} = $bh + $y - $oy; |
761 | $self->{user_h} = $bh + $y - $oy; |
675 | $self->check_size; |
762 | $self->check_size; |
676 | }; |
763 | }; |
677 | |
764 | |
678 | } elsif ($x >= 0 && $x < $self->{w} |
765 | } elsif ($x >= 0 && $x < $self->{w} |
679 | && $y >= 0 && $y < $border) { |
766 | && $y >= 0 && $y < $border) { |
680 | |
767 | |
681 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
768 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
682 | my ($bx, $by) = ($self->{x}, $self->{y}); |
769 | my ($bx, $by) = ($self->{x}, $self->{y}); |
683 | |
770 | |
684 | $self->{motion} = sub { |
771 | $self->{motion} = sub { |
685 | my ($ev, $x, $y) = @_; |
772 | my ($ev, $x, $y) = @_; |
686 | |
773 | |
687 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
774 | ($x, $y) = ($ev->{x}, $ev->{y}); |
688 | |
775 | |
689 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
776 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
690 | $self->update; |
777 | $self->update; |
691 | }; |
778 | }; |
692 | } |
779 | } |
… | |
… | |
737 | $bg->draw_quad ($border, $border, $cw, $ch); |
824 | $bg->draw_quad ($border, $border, $cw, $ch); |
738 | |
825 | |
739 | glDisable GL_TEXTURE_2D; |
826 | glDisable GL_TEXTURE_2D; |
740 | glDisable GL_BLEND; |
827 | glDisable GL_BLEND; |
741 | |
828 | |
|
|
829 | $self->{title}->draw if $self->{title}; |
742 | $self->child->draw; |
830 | $self->child->draw; |
743 | } |
831 | } |
744 | |
832 | |
745 | ############################################################################# |
833 | ############################################################################# |
746 | |
834 | |
… | |
… | |
748 | |
836 | |
749 | our @ISA = CFClient::UI::Base::; |
837 | our @ISA = CFClient::UI::Base::; |
750 | |
838 | |
751 | use List::Util qw(max sum); |
839 | use List::Util qw(max sum); |
752 | |
840 | |
753 | use SDL::OpenGL; |
841 | use CFClient::OpenGL; |
754 | |
842 | |
755 | sub new { |
843 | sub new { |
756 | my $class = shift; |
844 | my $class = shift; |
757 | |
845 | |
758 | $class->SUPER::new ( |
846 | $class->SUPER::new ( |
… | |
… | |
788 | or next; |
876 | or next; |
789 | |
877 | |
790 | for my $x (0 .. $#$row) { |
878 | for my $x (0 .. $#$row) { |
791 | my $widget = $row->[$x] |
879 | my $widget = $row->[$x] |
792 | or next; |
880 | or next; |
793 | my ($w, $h) = $widget->size_request; |
881 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
794 | |
882 | |
795 | $w[$x] = max $w[$x], $w; |
883 | $w[$x] = max $w[$x], $w; |
796 | $h[$y] = max $h[$y], $h; |
884 | $h[$y] = max $h[$y], $h; |
797 | } |
885 | } |
798 | } |
886 | } |
… | |
… | |
903 | |
991 | |
904 | ($h, $w) = ($w, $h); |
992 | ($h, $w) = ($w, $h); |
905 | |
993 | |
906 | my $children = $self->{children}; |
994 | my $children = $self->{children}; |
907 | |
995 | |
908 | my @h = map +($_->size_request)[0], @$children; |
996 | my @h = map $_->{req_w}, @$children; |
909 | |
997 | |
910 | my $req_h = List::Util::sum @h; |
998 | my $req_h = List::Util::sum @h; |
911 | |
999 | |
912 | if ($req_h > $h) { |
1000 | if ($req_h > $h) { |
913 | # ah well, not enough space |
1001 | # ah well, not enough space |
… | |
… | |
961 | sub size_allocate { |
1049 | sub size_allocate { |
962 | my ($self, $w, $h) = @_; |
1050 | my ($self, $w, $h) = @_; |
963 | |
1051 | |
964 | my $children = $self->{children}; |
1052 | my $children = $self->{children}; |
965 | |
1053 | |
966 | my @h = map +($_->size_request)[1], @$children; |
1054 | my @h = map $_->{req_h}, @$children; |
967 | |
1055 | |
968 | my $req_h = List::Util::sum @h; |
1056 | my $req_h = List::Util::sum @h; |
969 | |
1057 | |
970 | if ($req_h > $h) { |
1058 | if ($req_h > $h) { |
971 | # ah well, not enough space |
1059 | # ah well, not enough space |
… | |
… | |
999 | |
1087 | |
1000 | package CFClient::UI::Label; |
1088 | package CFClient::UI::Label; |
1001 | |
1089 | |
1002 | our @ISA = CFClient::UI::Base::; |
1090 | our @ISA = CFClient::UI::Base::; |
1003 | |
1091 | |
1004 | use SDL::OpenGL; |
1092 | use CFClient::OpenGL; |
1005 | |
1093 | |
1006 | sub new { |
1094 | sub new { |
1007 | my ($class, %arg) = @_; |
1095 | my ($class, %arg) = @_; |
1008 | |
1096 | |
1009 | my $self = $class->SUPER::new ( |
1097 | my $self = $class->SUPER::new ( |
… | |
… | |
1012 | text => "", |
1100 | text => "", |
1013 | align => -1, |
1101 | align => -1, |
1014 | valign => -1, |
1102 | valign => -1, |
1015 | padding => 2, |
1103 | padding => 2, |
1016 | layout => new CFClient::Layout, |
1104 | layout => new CFClient::Layout, |
|
|
1105 | can_events => 0, |
1017 | %arg |
1106 | %arg |
1018 | ); |
1107 | ); |
1019 | |
1108 | |
1020 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
1109 | if (exists $self->{template}) { |
|
|
1110 | my $layout = new CFClient::Layout; |
|
|
1111 | $layout->set_text (delete $self->{template}); |
|
|
1112 | $self->{template} = $layout; |
|
|
1113 | } |
1021 | |
1114 | |
1022 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1115 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1023 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1116 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1024 | |
1117 | |
1025 | $self |
1118 | $self |
… | |
… | |
1039 | my ($self, $text) = @_; |
1132 | my ($self, $text) = @_; |
1040 | |
1133 | |
1041 | $self->{layout}->set_text ($text); |
1134 | $self->{layout}->set_text ($text); |
1042 | |
1135 | |
1043 | delete $self->{texture}; |
1136 | delete $self->{texture}; |
|
|
1137 | $self->check_size; |
1044 | $self->update; |
1138 | $self->update; |
1045 | } |
1139 | } |
1046 | |
1140 | |
1047 | sub set_markup { |
1141 | sub set_markup { |
1048 | my ($self, $markup) = @_; |
1142 | my ($self, $markup) = @_; |
1049 | |
1143 | |
1050 | $self->{layout}->set_markup ($markup); |
1144 | $self->{layout}->set_markup ($markup); |
1051 | |
1145 | |
1052 | delete $self->{texture}; |
1146 | delete $self->{texture}; |
|
|
1147 | $self->check_size; |
1053 | $self->update; |
1148 | $self->update; |
1054 | } |
1149 | } |
1055 | |
1150 | |
1056 | sub size_request { |
1151 | sub size_request { |
1057 | my ($self) = @_; |
1152 | my ($self) = @_; |
1058 | |
1153 | |
1059 | $self->{layout}->set_width; |
1154 | $self->{layout}->set_width; |
1060 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1155 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1061 | |
1156 | |
1062 | my ($w, $h) = $self->{layout}->size; |
1157 | my ($w, $h) = $self->{layout}->size; |
|
|
1158 | |
|
|
1159 | if (exists $self->{template}) { |
|
|
1160 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
1161 | |
|
|
1162 | my ($w2, $h2) = $self->{template}->size; |
|
|
1163 | |
|
|
1164 | $w = List::Util::max $w, $w2; |
|
|
1165 | $h = List::Util::max $h, $h2; |
|
|
1166 | } |
1063 | |
1167 | |
1064 | ( |
1168 | ( |
1065 | $w + $self->{padding} * 2, |
1169 | $w + $self->{padding} * 2, |
1066 | $h + $self->{padding} * 2, |
1170 | $h + $self->{padding} * 2, |
1067 | ) |
1171 | ) |
… | |
… | |
1069 | |
1173 | |
1070 | sub size_allocate { |
1174 | sub size_allocate { |
1071 | my ($self, $w, $h) = @_; |
1175 | my ($self, $w, $h) = @_; |
1072 | |
1176 | |
1073 | delete $self->{texture}; |
1177 | delete $self->{texture}; |
|
|
1178 | } |
|
|
1179 | |
|
|
1180 | sub set_fontsize { |
|
|
1181 | my ($self, $fontsize) = @_; |
|
|
1182 | |
|
|
1183 | $self->{fontsize} = $fontsize; |
|
|
1184 | $self->check_size; |
1074 | } |
1185 | } |
1075 | |
1186 | |
1076 | sub _draw { |
1187 | sub _draw { |
1077 | my ($self) = @_; |
1188 | my ($self) = @_; |
1078 | |
1189 | |
… | |
… | |
1111 | |
1222 | |
1112 | package CFClient::UI::EntryBase; |
1223 | package CFClient::UI::EntryBase; |
1113 | |
1224 | |
1114 | our @ISA = CFClient::UI::Label::; |
1225 | our @ISA = CFClient::UI::Label::; |
1115 | |
1226 | |
1116 | use SDL::OpenGL; |
1227 | use CFClient::OpenGL; |
1117 | |
1228 | |
1118 | sub new { |
1229 | sub new { |
1119 | my $class = shift; |
1230 | my $class = shift; |
1120 | |
1231 | |
1121 | $class->SUPER::new ( |
1232 | $class->SUPER::new ( |
… | |
… | |
1124 | active_bg => [1, 1, 1, 0.5], |
1235 | active_bg => [1, 1, 1, 0.5], |
1125 | active_fg => [0, 0, 0], |
1236 | active_fg => [0, 0, 0], |
1126 | can_hover => 1, |
1237 | can_hover => 1, |
1127 | can_focus => 1, |
1238 | can_focus => 1, |
1128 | valign => 0, |
1239 | valign => 0, |
|
|
1240 | can_events => 1, |
1129 | @_ |
1241 | @_ |
1130 | ) |
1242 | ) |
1131 | } |
1243 | } |
1132 | |
1244 | |
1133 | sub _set_text { |
1245 | sub _set_text { |
… | |
… | |
1161 | } |
1273 | } |
1162 | |
1274 | |
1163 | sub size_allocate { |
1275 | sub size_allocate { |
1164 | my ($self, $w, $h) = @_; |
1276 | my ($self, $w, $h) = @_; |
1165 | |
1277 | |
1166 | $self->_set_text ($self->{text}); |
1278 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1167 | } |
1279 | } |
1168 | |
1280 | |
1169 | sub set_text { |
1281 | sub set_text { |
1170 | my ($self, $text) = @_; |
1282 | my ($self, $text) = @_; |
1171 | |
1283 | |
… | |
… | |
1278 | |
1390 | |
1279 | package CFClient::UI::Entry; |
1391 | package CFClient::UI::Entry; |
1280 | |
1392 | |
1281 | our @ISA = CFClient::UI::EntryBase::; |
1393 | our @ISA = CFClient::UI::EntryBase::; |
1282 | |
1394 | |
1283 | use SDL::OpenGL; |
1395 | use CFClient::OpenGL; |
1284 | |
1396 | |
1285 | sub key_down { |
1397 | sub key_down { |
1286 | my ($self, $ev) = @_; |
1398 | my ($self, $ev) = @_; |
1287 | |
1399 | |
1288 | my $sym = $ev->{sym}; |
1400 | my $sym = $ev->{sym}; |
… | |
… | |
1301 | |
1413 | |
1302 | package CFClient::UI::Button; |
1414 | package CFClient::UI::Button; |
1303 | |
1415 | |
1304 | our @ISA = CFClient::UI::Label::; |
1416 | our @ISA = CFClient::UI::Label::; |
1305 | |
1417 | |
1306 | use SDL::OpenGL; |
1418 | use CFClient::OpenGL; |
1307 | |
1419 | |
1308 | my @tex = |
1420 | my @tex = |
1309 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1421 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1310 | qw(b1_button_active.png); |
1422 | qw(b1_button_active.png); |
1311 | |
1423 | |
1312 | sub new { |
1424 | sub new { |
1313 | my $class = shift; |
1425 | my $class = shift; |
1314 | |
1426 | |
… | |
… | |
1318 | bg => [1, 1, 1, 0.2], |
1430 | bg => [1, 1, 1, 0.2], |
1319 | active_fg => [0, 0, 1], |
1431 | active_fg => [0, 0, 1], |
1320 | can_hover => 1, |
1432 | can_hover => 1, |
1321 | align => 0, |
1433 | align => 0, |
1322 | valign => 0, |
1434 | valign => 0, |
|
|
1435 | can_events => 1, |
1323 | @_ |
1436 | @_ |
1324 | ) |
1437 | ) |
1325 | } |
1438 | } |
1326 | |
1439 | |
1327 | sub button_up { |
1440 | sub button_up { |
… | |
… | |
1361 | package CFClient::UI::CheckBox; |
1474 | package CFClient::UI::CheckBox; |
1362 | |
1475 | |
1363 | our @ISA = CFClient::UI::DrawBG::; |
1476 | our @ISA = CFClient::UI::DrawBG::; |
1364 | |
1477 | |
1365 | my @tex = |
1478 | my @tex = |
1366 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1479 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1367 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1480 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1368 | |
1481 | |
1369 | use SDL::OpenGL; |
1482 | use CFClient::OpenGL; |
1370 | |
1483 | |
1371 | sub new { |
1484 | sub new { |
1372 | my $class = shift; |
1485 | my $class = shift; |
1373 | |
1486 | |
1374 | $class->SUPER::new ( |
1487 | $class->SUPER::new ( |
… | |
… | |
1420 | glDisable GL_BLEND; |
1533 | glDisable GL_BLEND; |
1421 | } |
1534 | } |
1422 | |
1535 | |
1423 | ############################################################################# |
1536 | ############################################################################# |
1424 | |
1537 | |
1425 | package CFClient::UI::VGauge; |
1538 | package CFClient::UI::Image; |
1426 | |
1539 | |
1427 | our @ISA = CFClient::UI::Base::; |
1540 | our @ISA = CFClient::UI::Base::; |
1428 | |
1541 | |
1429 | use SDL::OpenGL; |
1542 | use CFClient::OpenGL; |
|
|
1543 | use Carp qw/confess/; |
1430 | |
1544 | |
1431 | my %tex = ( |
1545 | our %loaded_images; |
1432 | food => [ |
|
|
1433 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1434 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1435 | ], |
|
|
1436 | grace => [ |
|
|
1437 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1438 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1439 | ], |
|
|
1440 | hp => [ |
|
|
1441 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1442 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1443 | ], |
|
|
1444 | mana => [ |
|
|
1445 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1446 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1447 | ], |
|
|
1448 | ); |
|
|
1449 | |
1546 | |
1450 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1451 | sub new { |
1547 | sub new { |
1452 | my $class = shift; |
1548 | my $class = shift; |
1453 | |
1549 | |
1454 | my $self = $class->SUPER::new (gauge => 'food', @_); |
1550 | my $self = $class->SUPER::new (can_events => 0, @_); |
|
|
1551 | |
|
|
1552 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
|
|
1553 | |
|
|
1554 | $loaded_images{$self->{image}} ||= |
|
|
1555 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
|
|
1556 | |
|
|
1557 | my $tex = $self->{tex} = $loaded_images{$self->{image}}; |
|
|
1558 | |
|
|
1559 | Scalar::Util::weaken $loaded_images{$self->{image}}; |
|
|
1560 | |
|
|
1561 | $self->{aspect} = $tex->{w} / $tex->{h}; |
1455 | |
1562 | |
1456 | $self |
1563 | $self |
1457 | } |
1564 | } |
1458 | |
1565 | |
1459 | sub size_request { |
1566 | sub size_request { |
1460 | my ($self) = @_; |
1567 | my ($self) = @_; |
1461 | |
1568 | |
1462 | my $tex = $tex{$self->{gauge}}[0]; |
1569 | ($self->{tex}->{w}, $self->{tex}->{h}) |
1463 | |
|
|
1464 | @$tex{qw(w h)} |
|
|
1465 | } |
|
|
1466 | |
|
|
1467 | sub set_max { |
|
|
1468 | my ($self, $max) = @_; |
|
|
1469 | |
|
|
1470 | $self->{max_val} = $max; |
|
|
1471 | } |
|
|
1472 | |
|
|
1473 | sub set_value { |
|
|
1474 | my ($self, $val, $max) = @_; |
|
|
1475 | |
|
|
1476 | $self->set_max ($max) |
|
|
1477 | if defined $max; |
|
|
1478 | |
|
|
1479 | $max = $self->{max_val}; |
|
|
1480 | $self->{val} = $val; |
|
|
1481 | |
|
|
1482 | $self->update; |
|
|
1483 | } |
1570 | } |
1484 | |
1571 | |
1485 | sub _draw { |
1572 | sub _draw { |
1486 | my ($self) = @_; |
1573 | my ($self) = @_; |
1487 | |
1574 | |
1488 | my $tex = $tex{$self->{gauge}}; |
1575 | my $tex = $self->{tex}; |
1489 | |
1576 | |
1490 | my ($w, $h) = ($self->{w}, $self->{h}); |
1577 | my ($w, $h) = ($self->{w}, $self->{h}); |
1491 | |
1578 | |
1492 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1579 | if ($self->{rot90}) { |
1493 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1580 | glRotate 90, 0, 0, 1; |
|
|
1581 | glTranslate 0, -$self->{w}, 0; |
1494 | |
1582 | |
1495 | my $t1 = $tex->[0]; |
1583 | ($w, $h) = ($h, $w); |
1496 | my $t2 = $tex->[1]; |
1584 | } |
1497 | |
1585 | |
1498 | glEnable GL_BLEND; |
1586 | glEnable GL_BLEND; |
1499 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1587 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1500 | glEnable GL_TEXTURE_2D; |
1588 | glEnable GL_TEXTURE_2D; |
1501 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1589 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1502 | |
1590 | |
|
|
1591 | $tex->draw_quad (0, 0, $w, $h); |
|
|
1592 | |
|
|
1593 | glDisable GL_BLEND; |
|
|
1594 | glDisable GL_TEXTURE_2D; |
|
|
1595 | } |
|
|
1596 | |
|
|
1597 | ############################################################################# |
|
|
1598 | |
|
|
1599 | package CFClient::UI::VGauge; |
|
|
1600 | |
|
|
1601 | our @ISA = CFClient::UI::Base::; |
|
|
1602 | |
|
|
1603 | use CFClient::OpenGL; |
|
|
1604 | |
|
|
1605 | my %tex = ( |
|
|
1606 | food => [ |
|
|
1607 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1608 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1609 | ], |
|
|
1610 | grace => [ |
|
|
1611 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1612 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1613 | ], |
|
|
1614 | hp => [ |
|
|
1615 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1616 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1617 | ], |
|
|
1618 | mana => [ |
|
|
1619 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1620 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1621 | ], |
|
|
1622 | ); |
|
|
1623 | |
|
|
1624 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1625 | sub new { |
|
|
1626 | my $class = shift; |
|
|
1627 | |
|
|
1628 | my $self = $class->SUPER::new ( |
|
|
1629 | type => 'food', |
|
|
1630 | @_ |
|
|
1631 | ); |
|
|
1632 | |
|
|
1633 | $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h}; |
|
|
1634 | |
|
|
1635 | $self |
|
|
1636 | } |
|
|
1637 | |
|
|
1638 | sub size_request { |
|
|
1639 | my ($self) = @_; |
|
|
1640 | |
|
|
1641 | #my $tex = $tex{$self->{type}}[0]; |
|
|
1642 | #@$tex{qw(w h)} |
|
|
1643 | (0, 0) |
|
|
1644 | } |
|
|
1645 | |
|
|
1646 | sub set_max { |
|
|
1647 | my ($self, $max) = @_; |
|
|
1648 | |
|
|
1649 | $self->{max_val} = $max; |
|
|
1650 | } |
|
|
1651 | |
|
|
1652 | sub set_value { |
|
|
1653 | my ($self, $val, $max) = @_; |
|
|
1654 | |
|
|
1655 | $self->set_max ($max) |
|
|
1656 | if defined $max; |
|
|
1657 | |
|
|
1658 | $max = $self->{max_val}; |
|
|
1659 | $self->{val} = $val; |
|
|
1660 | |
|
|
1661 | $self->update; |
|
|
1662 | } |
|
|
1663 | |
|
|
1664 | sub _draw { |
|
|
1665 | my ($self) = @_; |
|
|
1666 | |
|
|
1667 | my $tex = $tex{$self->{type}}; |
|
|
1668 | |
|
|
1669 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1670 | |
|
|
1671 | if ($self->{vertical}) { |
|
|
1672 | glRotate 90, 0, 0, 1; |
|
|
1673 | glTranslate 0, -$self->{w}, 0; |
|
|
1674 | |
|
|
1675 | ($w, $h) = ($h, $w); |
|
|
1676 | } |
|
|
1677 | |
|
|
1678 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1679 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1680 | |
|
|
1681 | my $t1 = $tex->[0]; |
|
|
1682 | my $t2 = $tex->[1]; |
|
|
1683 | |
|
|
1684 | glEnable GL_BLEND; |
|
|
1685 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1686 | glEnable GL_TEXTURE_2D; |
|
|
1687 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1688 | |
1503 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1689 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1504 | my $h2 = $ycut * $self->{h}; |
1690 | my $h2 = $ycut * $self->{h}; |
1505 | |
1691 | |
1506 | my $yp = 0; |
|
|
1507 | |
|
|
1508 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1692 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1509 | glBegin GL_QUADS; |
1693 | glBegin GL_QUADS; |
1510 | glTexCoord 0 , 0; glVertex 0 , $yp; |
1694 | glTexCoord 0 , 0; glVertex 0 , 0; |
1511 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
1695 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1512 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
1696 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1513 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
1697 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1514 | glEnd; |
1698 | glEnd; |
1515 | |
|
|
1516 | $yp += $h1; |
|
|
1517 | |
1699 | |
1518 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1700 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1519 | glBegin GL_QUADS; |
1701 | glBegin GL_QUADS; |
1520 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
1702 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1521 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
1703 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1522 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
1704 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1523 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
1705 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1524 | glEnd; |
1706 | glEnd; |
1525 | |
1707 | |
1526 | glDisable GL_BLEND; |
1708 | glDisable GL_BLEND; |
1527 | glDisable GL_TEXTURE_2D; |
1709 | glDisable GL_TEXTURE_2D; |
1528 | } |
1710 | } |
1529 | |
1711 | |
1530 | ############################################################################# |
1712 | ############################################################################# |
1531 | |
1713 | |
|
|
1714 | package CFClient::UI::Gauge; |
|
|
1715 | |
|
|
1716 | our @ISA = CFClient::UI::VBox::; |
|
|
1717 | |
|
|
1718 | sub new { |
|
|
1719 | my ($class, %arg) = @_; |
|
|
1720 | |
|
|
1721 | my $self = $class->SUPER::new ( |
|
|
1722 | tooltip => $arg{type}, |
|
|
1723 | %arg, |
|
|
1724 | ); |
|
|
1725 | |
|
|
1726 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
|
|
1727 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
|
|
1728 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); |
|
|
1729 | |
|
|
1730 | $self |
|
|
1731 | } |
|
|
1732 | |
|
|
1733 | sub set_fontsize { |
|
|
1734 | my ($self, $fsize) = @_; |
|
|
1735 | |
|
|
1736 | $self->{value}->set_fontsize ($fsize); |
|
|
1737 | $self->{max} ->set_fontsize ($fsize); |
|
|
1738 | } |
|
|
1739 | |
|
|
1740 | sub set_value { |
|
|
1741 | my ($self, $val, $max) = @_; |
|
|
1742 | |
|
|
1743 | $self->set_max ($max) |
|
|
1744 | if defined $max; |
|
|
1745 | |
|
|
1746 | $self->{gauge}->set_value ($val, $max); |
|
|
1747 | $self->{value}->set_text ($val); |
|
|
1748 | } |
|
|
1749 | |
|
|
1750 | sub set_max { |
|
|
1751 | my ($self, $max) = @_; |
|
|
1752 | |
|
|
1753 | $self->{gauge}->set_max ($max); |
|
|
1754 | $self->{max}->set_text ($max); |
|
|
1755 | } |
|
|
1756 | |
|
|
1757 | ############################################################################# |
|
|
1758 | |
1532 | package CFClient::UI::Slider; |
1759 | package CFClient::UI::Slider; |
1533 | |
1760 | |
1534 | use strict; |
1761 | use strict; |
1535 | |
1762 | |
1536 | use SDL::OpenGL; |
1763 | use CFClient::OpenGL; |
1537 | |
1764 | |
1538 | our @ISA = CFClient::UI::DrawBG::; |
1765 | our @ISA = CFClient::UI::DrawBG::; |
1539 | |
1766 | |
1540 | my @tex = |
1767 | my @tex = |
1541 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1768 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1666 | |
1893 | |
1667 | package CFClient::UI::TextView; |
1894 | package CFClient::UI::TextView; |
1668 | |
1895 | |
1669 | our @ISA = CFClient::UI::HBox::; |
1896 | our @ISA = CFClient::UI::HBox::; |
1670 | |
1897 | |
1671 | use SDL::OpenGL; |
1898 | use CFClient::OpenGL; |
1672 | |
1899 | |
1673 | sub new { |
1900 | sub new { |
1674 | my $class = shift; |
1901 | my $class = shift; |
1675 | |
1902 | |
1676 | my $self = $class->SUPER::new ( |
1903 | my $self = $class->SUPER::new ( |
… | |
… | |
1822 | |
2049 | |
1823 | ############################################################################# |
2050 | ############################################################################# |
1824 | |
2051 | |
1825 | package CFClient::UI::Animator; |
2052 | package CFClient::UI::Animator; |
1826 | |
2053 | |
1827 | use SDL::OpenGL; |
2054 | use CFClient::OpenGL; |
1828 | |
2055 | |
1829 | our @ISA = CFClient::UI::Bin::; |
2056 | our @ISA = CFClient::UI::Bin::; |
1830 | |
2057 | |
1831 | sub moveto { |
2058 | sub moveto { |
1832 | my ($self, $x, $y) = @_; |
2059 | my ($self, $x, $y) = @_; |
… | |
… | |
1872 | my $class = shift; |
2099 | my $class = shift; |
1873 | |
2100 | |
1874 | my $self = $class->SUPER::new ( |
2101 | my $self = $class->SUPER::new ( |
1875 | state => 0, |
2102 | state => 0, |
1876 | connect_activate => \&toggle_flopper, |
2103 | connect_activate => \&toggle_flopper, |
|
|
2104 | can_events => 1, |
1877 | @_ |
2105 | @_ |
1878 | ); |
2106 | ); |
1879 | |
2107 | |
1880 | if ($self->{state}) { |
2108 | if ($self->{state}) { |
1881 | $self->{state} = 0; |
2109 | $self->{state} = 0; |
… | |
… | |
1905 | |
2133 | |
1906 | package CFClient::UI::Root; |
2134 | package CFClient::UI::Root; |
1907 | |
2135 | |
1908 | our @ISA = CFClient::UI::Container::; |
2136 | our @ISA = CFClient::UI::Container::; |
1909 | |
2137 | |
1910 | use SDL::OpenGL; |
2138 | use CFClient::OpenGL; |
1911 | |
2139 | |
1912 | sub check_size { |
2140 | sub check_size { |
1913 | my ($self) = @_; |
2141 | my ($self) = @_; |
1914 | |
2142 | |
1915 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2143 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
1916 | } |
2144 | } |
1917 | |
2145 | |
1918 | sub size_request { |
2146 | sub size_request { |
1919 | ($::WIDTH, $::HEIGHT) |
2147 | ($::WIDTH, $::HEIGHT) |
1920 | } |
2148 | } |
… | |
… | |
1922 | sub configure { |
2150 | sub configure { |
1923 | my ($self, $x, $y, $w, $h) = @_; |
2151 | my ($self, $x, $y, $w, $h) = @_; |
1924 | |
2152 | |
1925 | $self->SUPER::configure ($x, $y, $w, $h); |
2153 | $self->SUPER::configure ($x, $y, $w, $h); |
1926 | |
2154 | |
1927 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
|
|
1928 | for @{$self->{children}}; |
2155 | for my $child (@{$self->{children}}) { |
|
|
2156 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
|
|
2157 | |
|
|
2158 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
|
|
2159 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
|
|
2160 | $child->configure ($X, $Y, $W,$H); |
|
|
2161 | } |
1929 | } |
2162 | } |
1930 | |
2163 | |
1931 | sub _topleft { |
2164 | sub _topleft { |
1932 | my ($self, $x, $y) = @_; |
2165 | my ($self, $x, $y) = @_; |
1933 | |
2166 | |
… | |
… | |
1941 | ::refresh (); |
2174 | ::refresh (); |
1942 | } |
2175 | } |
1943 | |
2176 | |
1944 | sub add { |
2177 | sub add { |
1945 | my ($self, $child) = @_; |
2178 | my ($self, $child) = @_; |
|
|
2179 | |
|
|
2180 | # integerize window positions |
|
|
2181 | $child->{x} = int $child->{x}; |
|
|
2182 | $child->{y} = int $child->{y}; |
1946 | |
2183 | |
1947 | $self->SUPER::add ($child); |
2184 | $self->SUPER::add ($child); |
1948 | } |
2185 | } |
1949 | |
2186 | |
1950 | sub on_refresh { |
2187 | sub on_refresh { |
… | |
… | |
1976 | ############################################################################# |
2213 | ############################################################################# |
1977 | |
2214 | |
1978 | package CFClient::UI; |
2215 | package CFClient::UI; |
1979 | |
2216 | |
1980 | $ROOT = new CFClient::UI::Root; |
2217 | $ROOT = new CFClient::UI::Root; |
|
|
2218 | $TOOLTIP = new CFClient::UI::Label fontsize => 0.8, can_events => 0; |
1981 | |
2219 | |
1982 | 1 |
2220 | 1 |
1983 | |
2221 | |