… | |
… | |
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_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 | } |
… | |
… | |
21 | $FOCUS->key_up ($_[0]) if $FOCUS; |
48 | $FOCUS->key_up ($_[0]) if $FOCUS; |
22 | } |
49 | } |
23 | |
50 | |
24 | sub feed_sdl_button_down_event { |
51 | sub feed_sdl_button_down_event { |
25 | my ($ev) = @_; |
52 | my ($ev) = @_; |
26 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
53 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
27 | |
54 | |
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; |
33 | } |
|
|
34 | |
60 | |
|
|
61 | check_tooltip; |
|
|
62 | } |
|
|
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; |
38 | } |
67 | } |
39 | |
68 | |
40 | sub feed_sdl_button_up_event { |
69 | sub feed_sdl_button_up_event { |
41 | my ($ev) = @_; |
70 | my ($ev) = @_; |
42 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
71 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
43 | |
72 | |
44 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
73 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
45 | |
74 | |
46 | $BUTTON_STATE &= ~(1 << ($ev->button - 1)); |
75 | $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); |
47 | |
76 | |
48 | $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
77 | $GRAB->button_up ($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) = @_; |
59 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
90 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
60 | |
91 | |
61 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
92 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
62 | |
93 | |
63 | if ($widget != $HOVER) { |
94 | if ($widget != $HOVER) { |
64 | my $hover = $HOVER; $HOVER = $widget; |
95 | my $hover = $HOVER; $HOVER = $widget; |
65 | |
96 | |
66 | $hover->update if $hover && $hover->{can_hover}; |
97 | $hover->update if $hover && $hover->{can_hover}; |
67 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
98 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
|
|
99 | |
|
|
100 | check_tooltip; |
68 | } |
101 | } |
69 | |
102 | |
70 | $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; |
103 | $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; |
71 | } |
104 | } |
72 | |
105 | |
… | |
… | |
87 | |
120 | |
88 | package CFClient::UI::Base; |
121 | package CFClient::UI::Base; |
89 | |
122 | |
90 | use strict; |
123 | use strict; |
91 | |
124 | |
92 | use SDL::OpenGL; |
125 | use CFClient::OpenGL; |
93 | |
126 | |
94 | sub new { |
127 | sub new { |
95 | my $class = shift; |
128 | my $class = shift; |
96 | |
129 | |
97 | my $self = bless { |
130 | my $self = bless { |
98 | x => 0, |
131 | x => 0, |
99 | y => 0, |
132 | y => 0, |
100 | z => 0, |
133 | z => 0, |
|
|
134 | can_events => 1, |
101 | @_ |
135 | @_ |
102 | }, $class; |
136 | }, $class; |
103 | |
137 | |
104 | for (keys %$self) { |
138 | for (keys %$self) { |
105 | if (/^connect_(.*)$/) { |
139 | if (/^connect_(.*)$/) { |
… | |
… | |
108 | } |
142 | } |
109 | |
143 | |
110 | $self |
144 | $self |
111 | } |
145 | } |
112 | |
146 | |
|
|
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 | |
|
|
197 | if ($self->{aspect}) { |
|
|
198 | my $w2 = List::Util::min $w, int $h * $self->{aspect}; |
|
|
199 | my $h2 = List::Util::min $h, int $w / $self->{aspect}; |
|
|
200 | |
|
|
201 | # use alignment to adjust x, y |
|
|
202 | |
|
|
203 | $x += int +($w - $w2) * 0.5; |
|
|
204 | $y += int +($h - $h2) * 0.5; |
|
|
205 | |
|
|
206 | ($w, $h) = ($w2, $h2); |
|
|
207 | } |
|
|
208 | |
|
|
209 | if ($self->{x} != $x || $self->{y} != $y) { |
151 | $self->{x} = $x; |
210 | $self->{x} = $x; |
152 | $self->{y} = $y; |
211 | $self->{y} = $y; |
|
|
212 | $self->update; |
|
|
213 | } |
153 | |
214 | |
154 | return unless $self->{w} != $w || $self->{h} != $h; |
215 | if ($self->{w} != $w || $self->{h} != $h) { |
155 | |
|
|
156 | $self->{w} = $w; |
216 | $self->{w} = $w; |
157 | $self->{h} = $h; |
217 | $self->{h} = $h; |
158 | |
218 | |
159 | $self->size_allocate ($w, $h); |
219 | $self->size_allocate ($w, $h); |
160 | $self->update; |
220 | $self->update; |
|
|
221 | } |
161 | } |
222 | } |
162 | |
223 | |
163 | sub size_allocate { |
224 | sub size_allocate { |
164 | # 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; |
165 | } |
233 | } |
166 | |
234 | |
167 | # return top left coordinates |
235 | # return top left coordinates |
168 | sub _topleft { |
236 | sub _topleft { |
169 | my ($self, $x, $y) = @_; |
237 | my ($self, $x, $y) = @_; |
… | |
… | |
263 | } |
331 | } |
264 | |
332 | |
265 | sub find_widget { |
333 | sub find_widget { |
266 | my ($self, $x, $y) = @_; |
334 | my ($self, $x, $y) = @_; |
267 | |
335 | |
|
|
336 | return () unless $self->{can_events}; |
|
|
337 | |
268 | return $self |
338 | return $self |
269 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
339 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
270 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
340 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
271 | |
341 | |
272 | () |
342 | () |
… | |
… | |
279 | } |
349 | } |
280 | |
350 | |
281 | sub check_size { |
351 | sub check_size { |
282 | my ($self) = @_; |
352 | my ($self) = @_; |
283 | |
353 | |
284 | my ($w, $h) = $self->size_request; |
354 | $self->{parent} |
|
|
355 | or return 1; |
285 | |
356 | |
|
|
357 | my ($w, $h) = $self->{user_w} && $self->{user_h} |
|
|
358 | ? @$self{qw(user_w user_h)} |
|
|
359 | : $self->size_request; |
|
|
360 | |
286 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
361 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
287 | $self->{req_w} = $w; |
362 | $self->{req_w} = $w; |
288 | $self->{req_h} = $h; |
363 | $self->{req_h} = $h; |
289 | |
364 | |
290 | $self->{parent}->check_size |
365 | $self->{parent}->check_size |
291 | if $self->{parent}; |
366 | or $self->size_allocate ( |
|
|
367 | (List::Util::max $self->{w}, $w), |
|
|
368 | (List::Util::max $self->{h}, $h), |
|
|
369 | ); |
|
|
370 | |
|
|
371 | 1 |
|
|
372 | } else { |
|
|
373 | 0 |
292 | } |
374 | } |
293 | } |
375 | } |
294 | |
376 | |
295 | sub update { |
377 | sub update { |
296 | my ($self) = @_; |
378 | my ($self) = @_; |
… | |
… | |
324 | package CFClient::UI::DrawBG; |
406 | package CFClient::UI::DrawBG; |
325 | |
407 | |
326 | our @ISA = CFClient::UI::Base::; |
408 | our @ISA = CFClient::UI::Base::; |
327 | |
409 | |
328 | use strict; |
410 | use strict; |
329 | use SDL::OpenGL; |
411 | use CFClient::OpenGL; |
330 | |
412 | |
331 | sub new { |
413 | sub new { |
332 | my $class = shift; |
414 | my $class = shift; |
333 | |
415 | |
334 | # range [value, low, high, page] |
416 | # range [value, low, high, page] |
… | |
… | |
363 | |
445 | |
364 | package CFClient::UI::Empty; |
446 | package CFClient::UI::Empty; |
365 | |
447 | |
366 | our @ISA = CFClient::UI::Base::; |
448 | our @ISA = CFClient::UI::Base::; |
367 | |
449 | |
|
|
450 | sub new { |
|
|
451 | my ($class, %arg) = @_; |
|
|
452 | $class->SUPER::new (can_events => 0, %arg); |
|
|
453 | } |
|
|
454 | |
368 | sub size_request { |
455 | sub size_request { |
369 | (0, 0) |
456 | (0, 0) |
370 | } |
457 | } |
371 | |
458 | |
372 | sub draw { } |
459 | sub draw { } |
… | |
… | |
380 | sub new { |
467 | sub new { |
381 | my ($class, %arg) = @_; |
468 | my ($class, %arg) = @_; |
382 | |
469 | |
383 | my $children = delete $arg{children} || []; |
470 | my $children = delete $arg{children} || []; |
384 | |
471 | |
385 | my $self = $class->SUPER::new (children => [], %arg); |
472 | my $self = $class->SUPER::new (children => [], can_events => 0, %arg); |
386 | $self->add ($_) for @$children; |
473 | $self->add ($_) for @$children; |
387 | |
474 | |
388 | $self |
475 | $self |
389 | } |
476 | } |
390 | |
477 | |
… | |
… | |
409 | delete $child->{parent}; |
496 | delete $child->{parent}; |
410 | |
497 | |
411 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
498 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
412 | |
499 | |
413 | $self->check_size; |
500 | $self->check_size; |
|
|
501 | $self->update; |
414 | } |
502 | } |
415 | |
503 | |
416 | sub find_widget { |
504 | sub find_widget { |
417 | my ($self, $x, $y) = @_; |
505 | my ($self, $x, $y) = @_; |
418 | |
506 | |
… | |
… | |
482 | |
570 | |
483 | package CFClient::UI::Window; |
571 | package CFClient::UI::Window; |
484 | |
572 | |
485 | our @ISA = CFClient::UI::Bin::; |
573 | our @ISA = CFClient::UI::Bin::; |
486 | |
574 | |
487 | use SDL::OpenGL; |
575 | use CFClient::OpenGL; |
488 | |
576 | |
489 | sub new { |
577 | sub new { |
490 | my ($class, %arg) = @_; |
578 | my ($class, %arg) = @_; |
491 | |
579 | |
492 | my $self = $class->SUPER::new (%arg); |
580 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
546 | sub new { die } |
634 | sub new { die } |
547 | |
635 | |
548 | sub size_request { |
636 | sub size_request { |
549 | my ($self) = @_; |
637 | my ($self) = @_; |
550 | |
638 | |
551 | @$self{qw(child_w child_h)} = $self->child->size_request; |
639 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
552 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
640 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
553 | |
641 | |
554 | @$self{qw(child_w child_h)} |
642 | @$self{qw(child_w child_h)} |
555 | } |
643 | } |
556 | |
644 | |
… | |
… | |
565 | |
653 | |
566 | package CFClient::UI::Frame; |
654 | package CFClient::UI::Frame; |
567 | |
655 | |
568 | our @ISA = CFClient::UI::Bin::; |
656 | our @ISA = CFClient::UI::Bin::; |
569 | |
657 | |
570 | use SDL::OpenGL; |
658 | 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 | |
659 | |
618 | sub new { |
660 | sub new { |
619 | my $class = shift; |
661 | my $class = shift; |
620 | |
662 | |
621 | # TODO: user_x, user_y, overwrite moveto? |
|
|
622 | |
|
|
623 | $class->SUPER::new ( |
663 | my $self = $class->SUPER::new ( |
624 | bg => [1, 1, 1, 1], |
664 | bg => [1, 1, 1, 1], |
625 | border_bg => [1, 1, 1, 1], |
665 | border_bg => [1, 1, 1, 1], |
626 | border => 0.8, |
666 | border => 0.8, |
627 | @_ |
667 | @_ |
628 | ) |
668 | ); |
|
|
669 | |
|
|
670 | $self |
|
|
671 | } |
|
|
672 | |
|
|
673 | sub _draw { |
|
|
674 | my ($self) = @_; |
|
|
675 | |
|
|
676 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
677 | |
|
|
678 | glEnable GL_BLEND; |
|
|
679 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
680 | glEnable GL_TEXTURE_2D; |
|
|
681 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
682 | |
|
|
683 | # glBegin GL_QUADS; |
|
|
684 | # glColor 0, 0, 0, 0; |
|
|
685 | # glVertex 0 , 0; |
|
|
686 | # glVertex 0 , $h; |
|
|
687 | # glVertex $w, $h; |
|
|
688 | # glVertex $w, 0; |
|
|
689 | # glEnd; |
|
|
690 | |
|
|
691 | |
|
|
692 | $self->child->draw; |
|
|
693 | glDisable GL_BLEND; |
|
|
694 | glDisable GL_TEXTURE_2D; |
|
|
695 | } |
|
|
696 | |
|
|
697 | ############################################################################# |
|
|
698 | |
|
|
699 | package CFClient::UI::FancyFrame; |
|
|
700 | |
|
|
701 | our @ISA = CFClient::UI::Bin::; |
|
|
702 | |
|
|
703 | use CFClient::OpenGL; |
|
|
704 | |
|
|
705 | my @tex = |
|
|
706 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
707 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
708 | |
|
|
709 | sub new { |
|
|
710 | my $class = shift; |
|
|
711 | |
|
|
712 | # TODO: user_x, user_y, overwrite moveto? |
|
|
713 | |
|
|
714 | my $self = $class->SUPER::new ( |
|
|
715 | bg => [1, 1, 1, 1], |
|
|
716 | border_bg => [1, 1, 1, 1], |
|
|
717 | border => 0.8, |
|
|
718 | can_events => 1, |
|
|
719 | @_ |
|
|
720 | ); |
|
|
721 | |
|
|
722 | $self->{title} &&= new CFClient::UI::Label |
|
|
723 | align => 0, |
|
|
724 | valign => 1, |
|
|
725 | text => $self->{title}, |
|
|
726 | fontsize => 1; |
|
|
727 | |
|
|
728 | $self |
629 | } |
729 | } |
630 | |
730 | |
631 | sub border { |
731 | sub border { |
632 | int $_[0]{border} * $::FONTSIZE |
732 | int $_[0]{border} * $::FONTSIZE |
633 | } |
733 | } |
634 | |
734 | |
635 | sub size_request { |
735 | sub size_request { |
636 | my ($self) = @_; |
736 | my ($self) = @_; |
637 | |
|
|
638 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
|
|
639 | |
737 | |
640 | my ($w, $h) = $self->SUPER::size_request; |
738 | my ($w, $h) = $self->SUPER::size_request; |
641 | |
739 | |
642 | ( |
740 | ( |
643 | $w + $self->border * 2, |
741 | $w + $self->border * 2, |
… | |
… | |
649 | my ($self, $w, $h) = @_; |
747 | my ($self, $w, $h) = @_; |
650 | |
748 | |
651 | $h -= List::Util::max 0, $self->border * 2; |
749 | $h -= List::Util::max 0, $self->border * 2; |
652 | $w -= List::Util::max 0, $self->border * 2; |
750 | $w -= List::Util::max 0, $self->border * 2; |
653 | |
751 | |
|
|
752 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
|
|
753 | if $self->{title}; |
|
|
754 | |
654 | $self->child->configure ($self->border, $self->border, $w, $h); |
755 | $self->child->configure ($self->border, $self->border, $w, $h); |
655 | } |
756 | } |
656 | |
757 | |
657 | sub button_down { |
758 | sub button_down { |
658 | my ($self, $ev, $x, $y) = @_; |
759 | my ($self, $ev, $x, $y) = @_; |
… | |
… | |
660 | my $border = $self->border; |
761 | my $border = $self->border; |
661 | |
762 | |
662 | if ($x < $self->{w} && $x >= $self->{w} - $border |
763 | if ($x < $self->{w} && $x >= $self->{w} - $border |
663 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
764 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
664 | |
765 | |
665 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
766 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
666 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
767 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
667 | |
768 | |
668 | $self->{motion} = sub { |
769 | $self->{motion} = sub { |
669 | my ($ev, $x, $y) = @_; |
770 | my ($ev, $x, $y) = @_; |
670 | |
771 | |
671 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
772 | ($x, $y) = ($ev->{x}, $ev->{y}); |
672 | |
773 | |
673 | $self->{user_w} = $bw + $x - $ox; |
774 | $self->{user_w} = $bw + $x - $ox; |
674 | $self->{user_h} = $bh + $y - $oy; |
775 | $self->{user_h} = $bh + $y - $oy; |
675 | $self->check_size; |
776 | $self->check_size; |
676 | }; |
777 | }; |
677 | |
778 | |
678 | } elsif ($x >= 0 && $x < $self->{w} |
779 | } elsif ($x >= 0 && $x < $self->{w} |
679 | && $y >= 0 && $y < $border) { |
780 | && $y >= 0 && $y < $border) { |
680 | |
781 | |
681 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
782 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
682 | my ($bx, $by) = ($self->{x}, $self->{y}); |
783 | my ($bx, $by) = ($self->{x}, $self->{y}); |
683 | |
784 | |
684 | $self->{motion} = sub { |
785 | $self->{motion} = sub { |
685 | my ($ev, $x, $y) = @_; |
786 | my ($ev, $x, $y) = @_; |
686 | |
787 | |
687 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
788 | ($x, $y) = ($ev->{x}, $ev->{y}); |
688 | |
789 | |
689 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
790 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
690 | $self->update; |
791 | $self->update; |
691 | }; |
792 | }; |
692 | } |
793 | } |
… | |
… | |
737 | $bg->draw_quad ($border, $border, $cw, $ch); |
838 | $bg->draw_quad ($border, $border, $cw, $ch); |
738 | |
839 | |
739 | glDisable GL_TEXTURE_2D; |
840 | glDisable GL_TEXTURE_2D; |
740 | glDisable GL_BLEND; |
841 | glDisable GL_BLEND; |
741 | |
842 | |
|
|
843 | $self->{title}->draw if $self->{title}; |
742 | $self->child->draw; |
844 | $self->child->draw; |
743 | } |
845 | } |
744 | |
846 | |
745 | ############################################################################# |
847 | ############################################################################# |
746 | |
848 | |
… | |
… | |
748 | |
850 | |
749 | our @ISA = CFClient::UI::Base::; |
851 | our @ISA = CFClient::UI::Base::; |
750 | |
852 | |
751 | use List::Util qw(max sum); |
853 | use List::Util qw(max sum); |
752 | |
854 | |
753 | use SDL::OpenGL; |
855 | use CFClient::OpenGL; |
754 | |
856 | |
755 | sub new { |
857 | sub new { |
756 | my $class = shift; |
858 | my $class = shift; |
757 | |
859 | |
758 | $class->SUPER::new ( |
860 | $class->SUPER::new ( |
… | |
… | |
788 | or next; |
890 | or next; |
789 | |
891 | |
790 | for my $x (0 .. $#$row) { |
892 | for my $x (0 .. $#$row) { |
791 | my $widget = $row->[$x] |
893 | my $widget = $row->[$x] |
792 | or next; |
894 | or next; |
793 | my ($w, $h) = $widget->size_request; |
895 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
794 | |
896 | |
795 | $w[$x] = max $w[$x], $w; |
897 | $w[$x] = max $w[$x], $w; |
796 | $h[$y] = max $h[$y], $h; |
898 | $h[$y] = max $h[$y], $h; |
797 | } |
899 | } |
798 | } |
900 | } |
… | |
… | |
903 | |
1005 | |
904 | ($h, $w) = ($w, $h); |
1006 | ($h, $w) = ($w, $h); |
905 | |
1007 | |
906 | my $children = $self->{children}; |
1008 | my $children = $self->{children}; |
907 | |
1009 | |
908 | my @h = map +($_->size_request)[0], @$children; |
1010 | my @h = map $_->{req_w}, @$children; |
909 | |
1011 | |
910 | my $req_h = List::Util::sum @h; |
1012 | my $req_h = List::Util::sum @h; |
911 | |
1013 | |
912 | if ($req_h > $h) { |
1014 | if ($req_h > $h) { |
913 | # ah well, not enough space |
1015 | # ah well, not enough space |
… | |
… | |
961 | sub size_allocate { |
1063 | sub size_allocate { |
962 | my ($self, $w, $h) = @_; |
1064 | my ($self, $w, $h) = @_; |
963 | |
1065 | |
964 | my $children = $self->{children}; |
1066 | my $children = $self->{children}; |
965 | |
1067 | |
966 | my @h = map +($_->size_request)[1], @$children; |
1068 | my @h = map $_->{req_h}, @$children; |
967 | |
1069 | |
968 | my $req_h = List::Util::sum @h; |
1070 | my $req_h = List::Util::sum @h; |
969 | |
1071 | |
970 | if ($req_h > $h) { |
1072 | if ($req_h > $h) { |
971 | # ah well, not enough space |
1073 | # ah well, not enough space |
… | |
… | |
999 | |
1101 | |
1000 | package CFClient::UI::Label; |
1102 | package CFClient::UI::Label; |
1001 | |
1103 | |
1002 | our @ISA = CFClient::UI::Base::; |
1104 | our @ISA = CFClient::UI::Base::; |
1003 | |
1105 | |
1004 | use SDL::OpenGL; |
1106 | use CFClient::OpenGL; |
1005 | |
1107 | |
1006 | sub new { |
1108 | sub new { |
1007 | my ($class, %arg) = @_; |
1109 | my ($class, %arg) = @_; |
1008 | |
1110 | |
1009 | my $self = $class->SUPER::new ( |
1111 | my $self = $class->SUPER::new ( |
1010 | fg => [1, 1, 1], |
1112 | fg => [1, 1, 1], |
|
|
1113 | #font => default_font |
1011 | fontsize => 1, |
1114 | fontsize => 1, |
1012 | text => "", |
1115 | text => "", |
1013 | align => -1, |
1116 | align => -1, |
1014 | valign => -1, |
1117 | valign => -1, |
1015 | padding => 2, |
1118 | padding => 2, |
1016 | layout => new CFClient::Layout, |
1119 | layout => new CFClient::Layout, |
|
|
1120 | can_events => 0, |
1017 | %arg |
1121 | %arg |
1018 | ); |
1122 | ); |
1019 | |
1123 | |
1020 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
1124 | if (exists $self->{template}) { |
|
|
1125 | my $layout = new CFClient::Layout; |
|
|
1126 | $layout->set_text (delete $self->{template}); |
|
|
1127 | $self->{template} = $layout; |
|
|
1128 | } |
1021 | |
1129 | |
1022 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1130 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1023 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1131 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1024 | |
1132 | |
1025 | $self |
1133 | $self |
… | |
… | |
1039 | my ($self, $text) = @_; |
1147 | my ($self, $text) = @_; |
1040 | |
1148 | |
1041 | $self->{layout}->set_text ($text); |
1149 | $self->{layout}->set_text ($text); |
1042 | |
1150 | |
1043 | delete $self->{texture}; |
1151 | delete $self->{texture}; |
|
|
1152 | $self->check_size; |
1044 | $self->update; |
1153 | $self->update; |
1045 | } |
1154 | } |
1046 | |
1155 | |
1047 | sub set_markup { |
1156 | sub set_markup { |
1048 | my ($self, $markup) = @_; |
1157 | my ($self, $markup) = @_; |
1049 | |
1158 | |
1050 | $self->{layout}->set_markup ($markup); |
1159 | $self->{layout}->set_markup ($markup); |
1051 | |
1160 | |
1052 | delete $self->{texture}; |
1161 | delete $self->{texture}; |
|
|
1162 | $self->check_size; |
1053 | $self->update; |
1163 | $self->update; |
1054 | } |
1164 | } |
1055 | |
1165 | |
1056 | sub size_request { |
1166 | sub size_request { |
1057 | my ($self) = @_; |
1167 | my ($self) = @_; |
1058 | |
1168 | |
1059 | $self->{layout}->set_width; |
1169 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
|
|
1170 | $self->{layout}->set_width ($self->{max_w} || -1); |
1060 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1171 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1061 | |
1172 | |
1062 | my ($w, $h) = $self->{layout}->size; |
1173 | my ($w, $h) = $self->{layout}->size; |
|
|
1174 | |
|
|
1175 | if (exists $self->{template}) { |
|
|
1176 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
|
|
1177 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
1178 | |
|
|
1179 | my ($w2, $h2) = $self->{template}->size; |
|
|
1180 | |
|
|
1181 | $w = List::Util::max $w, $w2; |
|
|
1182 | $h = List::Util::max $h, $h2; |
|
|
1183 | } |
1063 | |
1184 | |
1064 | ( |
1185 | ( |
1065 | $w + $self->{padding} * 2, |
1186 | $w + $self->{padding} * 2, |
1066 | $h + $self->{padding} * 2, |
1187 | $h + $self->{padding} * 2, |
1067 | ) |
1188 | ) |
… | |
… | |
1071 | my ($self, $w, $h) = @_; |
1192 | my ($self, $w, $h) = @_; |
1072 | |
1193 | |
1073 | delete $self->{texture}; |
1194 | delete $self->{texture}; |
1074 | } |
1195 | } |
1075 | |
1196 | |
|
|
1197 | sub set_fontsize { |
|
|
1198 | my ($self, $fontsize) = @_; |
|
|
1199 | |
|
|
1200 | $self->{fontsize} = $fontsize; |
|
|
1201 | delete $self->{texture}; |
|
|
1202 | $self->check_size; |
|
|
1203 | $self->update; |
|
|
1204 | } |
|
|
1205 | |
1076 | sub _draw { |
1206 | sub _draw { |
1077 | my ($self) = @_; |
1207 | my ($self) = @_; |
1078 | |
1208 | |
1079 | my $tex = $self->{texture} ||= do { |
1209 | my $tex = $self->{texture} ||= do { |
|
|
1210 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1080 | $self->{layout}->set_width ($self->{w}); |
1211 | $self->{layout}->set_width ($self->{w}); |
1081 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1212 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1082 | new_from_layout CFClient::Texture $self->{layout} |
1213 | new_from_layout CFClient::Texture $self->{layout} |
1083 | }; |
1214 | }; |
1084 | |
1215 | |
… | |
… | |
1111 | |
1242 | |
1112 | package CFClient::UI::EntryBase; |
1243 | package CFClient::UI::EntryBase; |
1113 | |
1244 | |
1114 | our @ISA = CFClient::UI::Label::; |
1245 | our @ISA = CFClient::UI::Label::; |
1115 | |
1246 | |
1116 | use SDL; |
1247 | use CFClient::OpenGL; |
1117 | use SDL::OpenGL; |
|
|
1118 | |
1248 | |
1119 | sub new { |
1249 | sub new { |
1120 | my $class = shift; |
1250 | my $class = shift; |
1121 | |
1251 | |
1122 | $class->SUPER::new ( |
1252 | $class->SUPER::new ( |
… | |
… | |
1125 | active_bg => [1, 1, 1, 0.5], |
1255 | active_bg => [1, 1, 1, 0.5], |
1126 | active_fg => [0, 0, 0], |
1256 | active_fg => [0, 0, 0], |
1127 | can_hover => 1, |
1257 | can_hover => 1, |
1128 | can_focus => 1, |
1258 | can_focus => 1, |
1129 | valign => 0, |
1259 | valign => 0, |
|
|
1260 | can_events => 1, |
1130 | @_ |
1261 | @_ |
1131 | ) |
1262 | ) |
1132 | } |
1263 | } |
1133 | |
1264 | |
1134 | sub _set_text { |
1265 | sub _set_text { |
… | |
… | |
1162 | } |
1293 | } |
1163 | |
1294 | |
1164 | sub size_allocate { |
1295 | sub size_allocate { |
1165 | my ($self, $w, $h) = @_; |
1296 | my ($self, $w, $h) = @_; |
1166 | |
1297 | |
1167 | $self->_set_text ($self->{text}); |
1298 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1168 | } |
1299 | } |
1169 | |
1300 | |
1170 | sub set_text { |
1301 | sub set_text { |
1171 | my ($self, $text) = @_; |
1302 | my ($self, $text) = @_; |
1172 | |
1303 | |
… | |
… | |
1176 | } |
1307 | } |
1177 | |
1308 | |
1178 | sub key_down { |
1309 | sub key_down { |
1179 | my ($self, $ev) = @_; |
1310 | my ($self, $ev) = @_; |
1180 | |
1311 | |
1181 | my $mod = $ev->key_mod; |
1312 | my $mod = $ev->{mod}; |
1182 | my $sym = $ev->key_sym; |
1313 | my $sym = $ev->{sym}; |
1183 | |
|
|
1184 | my $uni = $ev->key_unicode; |
1314 | my $uni = $ev->{unicode}; |
1185 | |
1315 | |
1186 | my $text = $self->get_text; |
1316 | my $text = $self->get_text; |
1187 | |
1317 | |
1188 | if ($sym == SDLK_BACKSPACE) { |
1318 | if ($sym == 8) { |
1189 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1319 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1190 | } elsif ($sym == SDLK_DELETE) { |
1320 | } elsif ($sym == 127) { |
1191 | substr $text, $self->{cursor}, 1, ""; |
1321 | substr $text, $self->{cursor}, 1, ""; |
1192 | } elsif ($sym == SDLK_LEFT) { |
1322 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1193 | --$self->{cursor} if $self->{cursor}; |
1323 | --$self->{cursor} if $self->{cursor}; |
1194 | } elsif ($sym == SDLK_RIGHT) { |
1324 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1195 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1325 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1196 | } elsif ($sym == SDLK_HOME) { |
1326 | } elsif ($sym == CFClient::SDLK_HOME) { |
1197 | $self->{cursor} = 0; |
1327 | $self->{cursor} = 0; |
1198 | } elsif ($sym == SDLK_END) { |
1328 | } elsif ($sym == CFClient::SDLK_END) { |
1199 | $self->{cursor} = length $text; |
1329 | $self->{cursor} = length $text; |
1200 | } elsif ($sym == SDLK_ESCAPE) { |
1330 | } elsif ($sym == 27) { |
1201 | $self->emit ('escape'); |
1331 | $self->emit ('escape'); |
1202 | } elsif ($uni) { |
1332 | } elsif ($uni) { |
1203 | substr $text, $self->{cursor}++, 0, chr $uni; |
1333 | substr $text, $self->{cursor}++, 0, chr $uni; |
1204 | } |
1334 | } |
1205 | |
1335 | |
… | |
… | |
1280 | |
1410 | |
1281 | package CFClient::UI::Entry; |
1411 | package CFClient::UI::Entry; |
1282 | |
1412 | |
1283 | our @ISA = CFClient::UI::EntryBase::; |
1413 | our @ISA = CFClient::UI::EntryBase::; |
1284 | |
1414 | |
1285 | use SDL; |
1415 | use CFClient::OpenGL; |
1286 | use SDL::OpenGL; |
|
|
1287 | |
1416 | |
1288 | sub key_down { |
1417 | sub key_down { |
1289 | my ($self, $ev) = @_; |
1418 | my ($self, $ev) = @_; |
1290 | |
1419 | |
1291 | my $sym = $ev->key_sym; |
1420 | my $sym = $ev->{sym}; |
1292 | |
1421 | |
1293 | if ($sym == SDLK_RETURN) { |
1422 | if ($sym == 13) { |
1294 | $self->emit (activate => $self->get_text); |
1423 | $self->emit (activate => $self->get_text); |
1295 | $self->update; |
1424 | $self->update; |
1296 | |
1425 | |
1297 | } else { |
1426 | } else { |
1298 | $self->SUPER::key_down ($ev); |
1427 | $self->SUPER::key_down ($ev); |
… | |
… | |
1304 | |
1433 | |
1305 | package CFClient::UI::Button; |
1434 | package CFClient::UI::Button; |
1306 | |
1435 | |
1307 | our @ISA = CFClient::UI::Label::; |
1436 | our @ISA = CFClient::UI::Label::; |
1308 | |
1437 | |
1309 | use SDL; |
1438 | use CFClient::OpenGL; |
1310 | use SDL::OpenGL; |
|
|
1311 | |
1439 | |
1312 | my @tex = |
1440 | my @tex = |
1313 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1441 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1314 | qw(b1_button_active.png); |
1442 | qw(b1_button_active.png); |
1315 | |
1443 | |
1316 | sub new { |
1444 | sub new { |
1317 | my $class = shift; |
1445 | my $class = shift; |
1318 | |
1446 | |
… | |
… | |
1322 | bg => [1, 1, 1, 0.2], |
1450 | bg => [1, 1, 1, 0.2], |
1323 | active_fg => [0, 0, 1], |
1451 | active_fg => [0, 0, 1], |
1324 | can_hover => 1, |
1452 | can_hover => 1, |
1325 | align => 0, |
1453 | align => 0, |
1326 | valign => 0, |
1454 | valign => 0, |
|
|
1455 | can_events => 1, |
1327 | @_ |
1456 | @_ |
1328 | ) |
1457 | ) |
1329 | } |
1458 | } |
1330 | |
1459 | |
1331 | sub button_up { |
1460 | sub button_up { |
… | |
… | |
1365 | package CFClient::UI::CheckBox; |
1494 | package CFClient::UI::CheckBox; |
1366 | |
1495 | |
1367 | our @ISA = CFClient::UI::DrawBG::; |
1496 | our @ISA = CFClient::UI::DrawBG::; |
1368 | |
1497 | |
1369 | my @tex = |
1498 | my @tex = |
1370 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1499 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1371 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1500 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1372 | |
1501 | |
1373 | use SDL; |
1502 | use CFClient::OpenGL; |
1374 | use SDL::OpenGL; |
|
|
1375 | |
1503 | |
1376 | sub new { |
1504 | sub new { |
1377 | my $class = shift; |
1505 | my $class = shift; |
1378 | |
1506 | |
1379 | $class->SUPER::new ( |
1507 | $class->SUPER::new ( |
… | |
… | |
1425 | glDisable GL_BLEND; |
1553 | glDisable GL_BLEND; |
1426 | } |
1554 | } |
1427 | |
1555 | |
1428 | ############################################################################# |
1556 | ############################################################################# |
1429 | |
1557 | |
1430 | package CFClient::UI::VGauge; |
1558 | package CFClient::UI::Image; |
1431 | |
1559 | |
1432 | our @ISA = CFClient::UI::Base::; |
1560 | our @ISA = CFClient::UI::Base::; |
1433 | |
1561 | |
1434 | use SDL::OpenGL; |
1562 | use CFClient::OpenGL; |
|
|
1563 | use Carp qw/confess/; |
1435 | |
1564 | |
1436 | my %tex = ( |
1565 | 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 | |
1566 | |
1455 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1456 | sub new { |
1567 | sub new { |
1457 | my $class = shift; |
1568 | my $class = shift; |
1458 | |
1569 | |
1459 | my $self = $class->SUPER::new (gauge => 'food', @_); |
1570 | my $self = $class->SUPER::new (can_events => 0, @_); |
|
|
1571 | |
|
|
1572 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
|
|
1573 | |
|
|
1574 | $loaded_images{$self->{image}} ||= |
|
|
1575 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
|
|
1576 | |
|
|
1577 | my $tex = $self->{tex} = $loaded_images{$self->{image}}; |
|
|
1578 | |
|
|
1579 | Scalar::Util::weaken $loaded_images{$self->{image}}; |
|
|
1580 | |
|
|
1581 | $self->{aspect} = $tex->{w} / $tex->{h}; |
1460 | |
1582 | |
1461 | $self |
1583 | $self |
1462 | } |
1584 | } |
1463 | |
1585 | |
1464 | sub size_request { |
1586 | sub size_request { |
1465 | my ($self) = @_; |
1587 | my ($self) = @_; |
1466 | |
1588 | |
1467 | my $tex = $tex{$self->{gauge}}[0]; |
1589 | ($self->{tex}->{w}, $self->{tex}->{h}) |
1468 | |
|
|
1469 | @$tex{qw(w h)} |
|
|
1470 | } |
|
|
1471 | |
|
|
1472 | sub set_max { |
|
|
1473 | my ($self, $max) = @_; |
|
|
1474 | |
|
|
1475 | $self->{max_val} = $max; |
|
|
1476 | } |
|
|
1477 | |
|
|
1478 | sub set_value { |
|
|
1479 | my ($self, $val, $max) = @_; |
|
|
1480 | |
|
|
1481 | $self->set_max ($max) |
|
|
1482 | if defined $max; |
|
|
1483 | |
|
|
1484 | $max = $self->{max_val}; |
|
|
1485 | $self->{val} = $val; |
|
|
1486 | |
|
|
1487 | $self->update; |
|
|
1488 | } |
1590 | } |
1489 | |
1591 | |
1490 | sub _draw { |
1592 | sub _draw { |
1491 | my ($self) = @_; |
1593 | my ($self) = @_; |
1492 | |
1594 | |
1493 | my $tex = $tex{$self->{gauge}}; |
1595 | my $tex = $self->{tex}; |
1494 | |
1596 | |
1495 | my ($w, $h) = ($self->{w}, $self->{h}); |
1597 | my ($w, $h) = ($self->{w}, $self->{h}); |
1496 | |
1598 | |
1497 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1599 | if ($self->{rot90}) { |
1498 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1600 | glRotate 90, 0, 0, 1; |
|
|
1601 | glTranslate 0, -$self->{w}, 0; |
1499 | |
1602 | |
1500 | my $t1 = $tex->[0]; |
1603 | ($w, $h) = ($h, $w); |
1501 | my $t2 = $tex->[1]; |
1604 | } |
1502 | |
1605 | |
1503 | glEnable GL_BLEND; |
1606 | glEnable GL_BLEND; |
1504 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1607 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1505 | glEnable GL_TEXTURE_2D; |
1608 | glEnable GL_TEXTURE_2D; |
1506 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1609 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1507 | |
1610 | |
|
|
1611 | $tex->draw_quad (0, 0, $w, $h); |
|
|
1612 | |
|
|
1613 | glDisable GL_BLEND; |
|
|
1614 | glDisable GL_TEXTURE_2D; |
|
|
1615 | } |
|
|
1616 | |
|
|
1617 | ############################################################################# |
|
|
1618 | |
|
|
1619 | package CFClient::UI::VGauge; |
|
|
1620 | |
|
|
1621 | our @ISA = CFClient::UI::Base::; |
|
|
1622 | |
|
|
1623 | use List::Util qw(min max); |
|
|
1624 | |
|
|
1625 | use CFClient::OpenGL; |
|
|
1626 | |
|
|
1627 | my %tex = ( |
|
|
1628 | food => [ |
|
|
1629 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1630 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1631 | ], |
|
|
1632 | grace => [ |
|
|
1633 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1634 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
|
|
1635 | ], |
|
|
1636 | hp => [ |
|
|
1637 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1638 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1639 | ], |
|
|
1640 | mana => [ |
|
|
1641 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1642 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
|
|
1643 | ], |
|
|
1644 | ); |
|
|
1645 | |
|
|
1646 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1647 | sub new { |
|
|
1648 | my $class = shift; |
|
|
1649 | |
|
|
1650 | my $self = $class->SUPER::new ( |
|
|
1651 | type => 'food', |
|
|
1652 | @_ |
|
|
1653 | ); |
|
|
1654 | |
|
|
1655 | $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h}; |
|
|
1656 | |
|
|
1657 | $self |
|
|
1658 | } |
|
|
1659 | |
|
|
1660 | sub size_request { |
|
|
1661 | my ($self) = @_; |
|
|
1662 | |
|
|
1663 | #my $tex = $tex{$self->{type}}[0]; |
|
|
1664 | #@$tex{qw(w h)} |
|
|
1665 | (0, 0) |
|
|
1666 | } |
|
|
1667 | |
|
|
1668 | sub set_max { |
|
|
1669 | my ($self, $max) = @_; |
|
|
1670 | |
|
|
1671 | $self->{max_val} = $max; |
|
|
1672 | } |
|
|
1673 | |
|
|
1674 | sub set_value { |
|
|
1675 | my ($self, $val, $max) = @_; |
|
|
1676 | |
|
|
1677 | $self->set_max ($max) |
|
|
1678 | if defined $max; |
|
|
1679 | |
|
|
1680 | $max = $self->{max_val}; |
|
|
1681 | $self->{val} = $val; |
|
|
1682 | |
|
|
1683 | $self->update; |
|
|
1684 | } |
|
|
1685 | |
|
|
1686 | sub _draw { |
|
|
1687 | my ($self) = @_; |
|
|
1688 | |
|
|
1689 | my $tex = $tex{$self->{type}}; |
|
|
1690 | my ($t1, $t2, $t3) = @$tex; |
|
|
1691 | |
|
|
1692 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1693 | |
|
|
1694 | if ($self->{vertical}) { |
|
|
1695 | glRotate 90, 0, 0, 1; |
|
|
1696 | glTranslate 0, -$self->{w}, 0; |
|
|
1697 | |
|
|
1698 | ($w, $h) = ($h, $w); |
|
|
1699 | } |
|
|
1700 | |
|
|
1701 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1702 | |
|
|
1703 | my $ycut1 = max 0, min 1, $ycut; |
|
|
1704 | my $ycut2 = max 0, min 1, $ycut - 1; |
|
|
1705 | |
1508 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1706 | my $h1 = $self->{h} * (1 - $ycut1); |
1509 | my $h2 = $ycut * $self->{h}; |
1707 | my $h2 = $self->{h} * (1 - $ycut2); |
1510 | |
1708 | |
1511 | my $yp = 0; |
1709 | glEnable GL_BLEND; |
|
|
1710 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1711 | glEnable GL_TEXTURE_2D; |
|
|
1712 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1512 | |
1713 | |
1513 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1714 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1514 | glBegin GL_QUADS; |
1715 | glBegin GL_QUADS; |
1515 | glTexCoord 0 , 0; glVertex 0 , $yp; |
1716 | glTexCoord 0 , 0; glVertex 0 , 0; |
1516 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
1717 | glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1; |
1517 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
1718 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1; |
1518 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
1719 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1519 | glEnd; |
1720 | glEnd; |
1520 | |
1721 | |
1521 | $yp += $h1; |
1722 | my $ycut1 = List::Util::min 1, $ycut; |
1522 | |
|
|
1523 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1723 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1524 | glBegin GL_QUADS; |
1724 | glBegin GL_QUADS; |
1525 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
1725 | glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1; |
1526 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
1726 | glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2; |
1527 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
|
|
1528 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
1727 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2; |
|
|
1728 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1; |
1529 | glEnd; |
1729 | glEnd; |
|
|
1730 | |
|
|
1731 | if ($t3) { |
|
|
1732 | glBindTexture GL_TEXTURE_2D, $t3->{name}; |
|
|
1733 | glBegin GL_QUADS; |
|
|
1734 | glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2; |
|
|
1735 | glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h}; |
|
|
1736 | glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h}; |
|
|
1737 | glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2; |
|
|
1738 | glEnd; |
|
|
1739 | } |
1530 | |
1740 | |
1531 | glDisable GL_BLEND; |
1741 | glDisable GL_BLEND; |
1532 | glDisable GL_TEXTURE_2D; |
1742 | glDisable GL_TEXTURE_2D; |
1533 | } |
1743 | } |
1534 | |
1744 | |
1535 | ############################################################################# |
1745 | ############################################################################# |
1536 | |
1746 | |
|
|
1747 | package CFClient::UI::Gauge; |
|
|
1748 | |
|
|
1749 | our @ISA = CFClient::UI::VBox::; |
|
|
1750 | |
|
|
1751 | sub new { |
|
|
1752 | my ($class, %arg) = @_; |
|
|
1753 | |
|
|
1754 | my $self = $class->SUPER::new ( |
|
|
1755 | tooltip => $arg{type}, |
|
|
1756 | can_events => 1, |
|
|
1757 | can_hover => 1, |
|
|
1758 | %arg, |
|
|
1759 | ); |
|
|
1760 | |
|
|
1761 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
|
|
1762 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
|
|
1763 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); |
|
|
1764 | |
|
|
1765 | $self |
|
|
1766 | } |
|
|
1767 | |
|
|
1768 | sub set_fontsize { |
|
|
1769 | my ($self, $fsize) = @_; |
|
|
1770 | |
|
|
1771 | $self->{value}->set_fontsize ($fsize); |
|
|
1772 | $self->{max} ->set_fontsize ($fsize); |
|
|
1773 | } |
|
|
1774 | |
|
|
1775 | sub set_value { |
|
|
1776 | my ($self, $val, $max) = @_; |
|
|
1777 | |
|
|
1778 | $self->set_max ($max) |
|
|
1779 | if defined $max; |
|
|
1780 | |
|
|
1781 | $self->{gauge}->set_value ($val, $max); |
|
|
1782 | $self->{value}->set_text ($val); |
|
|
1783 | } |
|
|
1784 | |
|
|
1785 | sub set_max { |
|
|
1786 | my ($self, $max) = @_; |
|
|
1787 | |
|
|
1788 | $self->{gauge}->set_max ($max); |
|
|
1789 | $self->{max}->set_text ($max); |
|
|
1790 | } |
|
|
1791 | |
|
|
1792 | ############################################################################# |
|
|
1793 | |
1537 | package CFClient::UI::Slider; |
1794 | package CFClient::UI::Slider; |
1538 | |
1795 | |
1539 | use strict; |
1796 | use strict; |
1540 | |
1797 | |
1541 | use SDL::OpenGL; |
1798 | use CFClient::OpenGL; |
1542 | |
1799 | |
1543 | our @ISA = CFClient::UI::DrawBG::; |
1800 | our @ISA = CFClient::UI::DrawBG::; |
1544 | |
1801 | |
1545 | my @tex = |
1802 | my @tex = |
1546 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1803 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1671 | |
1928 | |
1672 | package CFClient::UI::TextView; |
1929 | package CFClient::UI::TextView; |
1673 | |
1930 | |
1674 | our @ISA = CFClient::UI::HBox::; |
1931 | our @ISA = CFClient::UI::HBox::; |
1675 | |
1932 | |
1676 | use SDL::OpenGL; |
1933 | use CFClient::OpenGL; |
1677 | |
1934 | |
1678 | sub new { |
1935 | sub new { |
1679 | my $class = shift; |
1936 | my $class = shift; |
1680 | |
1937 | |
1681 | my $self = $class->SUPER::new ( |
1938 | my $self = $class->SUPER::new ( |
1682 | fontsize => 1, |
1939 | fontsize => 1, |
|
|
1940 | #font => default_font |
1683 | @_, |
1941 | @_, |
1684 | |
1942 | |
1685 | layout => (new CFClient::Layout), |
1943 | layout => (new CFClient::Layout), |
1686 | par => [], |
1944 | par => [], |
1687 | height => 0, |
1945 | height => 0, |
… | |
… | |
1727 | sub size_allocate { |
1985 | sub size_allocate { |
1728 | my ($self, $w, $h) = @_; |
1986 | my ($self, $w, $h) = @_; |
1729 | |
1987 | |
1730 | $self->SUPER::size_allocate ($w, $h); |
1988 | $self->SUPER::size_allocate ($w, $h); |
1731 | |
1989 | |
|
|
1990 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1732 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1991 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1733 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1992 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1734 | |
1993 | |
1735 | $self->reflow; |
1994 | $self->reflow; |
1736 | } |
1995 | } |
… | |
… | |
1788 | my $y1 = $top + $self->{h}; |
2047 | my $y1 = $top + $self->{h}; |
1789 | |
2048 | |
1790 | my $y = 0; |
2049 | my $y = 0; |
1791 | |
2050 | |
1792 | my $layout = $self->{layout}; |
2051 | my $layout = $self->{layout}; |
|
|
2052 | |
|
|
2053 | $layout->set_font ($self->{font}) if $self->{font}; |
1793 | |
2054 | |
1794 | for my $par (@{$self->{par}}) { |
2055 | for my $par (@{$self->{par}}) { |
1795 | my $h = $par->[0]; |
2056 | my $h = $par->[0]; |
1796 | |
2057 | |
1797 | if ($y0 < $y + $h && $y < $y1) { |
2058 | if ($y0 < $y + $h && $y < $y1) { |
… | |
… | |
1825 | |
2086 | |
1826 | } |
2087 | } |
1827 | |
2088 | |
1828 | ############################################################################# |
2089 | ############################################################################# |
1829 | |
2090 | |
1830 | package CFClient::UI::MapWidget; |
|
|
1831 | |
|
|
1832 | use strict; |
|
|
1833 | |
|
|
1834 | use List::Util qw(min max); |
|
|
1835 | |
|
|
1836 | use SDL; |
|
|
1837 | use SDL::OpenGL; |
|
|
1838 | |
|
|
1839 | our @ISA = CFClient::UI::Base::; |
|
|
1840 | |
|
|
1841 | sub new { |
|
|
1842 | my $class = shift; |
|
|
1843 | |
|
|
1844 | $class->SUPER::new ( |
|
|
1845 | z => -1, |
|
|
1846 | can_focus => 1, |
|
|
1847 | list => (glGenLists 1), |
|
|
1848 | @_ |
|
|
1849 | ) |
|
|
1850 | } |
|
|
1851 | |
|
|
1852 | sub key_down { |
|
|
1853 | print "MAPKEYDOWN\n"; |
|
|
1854 | } |
|
|
1855 | |
|
|
1856 | sub key_up { |
|
|
1857 | } |
|
|
1858 | |
|
|
1859 | sub button_down { |
|
|
1860 | my ($self, $ev, $x, $y) = @_; |
|
|
1861 | |
|
|
1862 | $self->focus_in; |
|
|
1863 | |
|
|
1864 | if ($ev->button == 2) { |
|
|
1865 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
1866 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
|
|
1867 | |
|
|
1868 | $self->{motion} = sub { |
|
|
1869 | my ($ev, $x, $y) = @_; |
|
|
1870 | |
|
|
1871 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
1872 | |
|
|
1873 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
|
|
1874 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
|
|
1875 | |
|
|
1876 | $self->update; |
|
|
1877 | }; |
|
|
1878 | } |
|
|
1879 | } |
|
|
1880 | |
|
|
1881 | sub button_up { |
|
|
1882 | my ($self, $ev, $x, $y) = @_; |
|
|
1883 | |
|
|
1884 | delete $self->{motion}; |
|
|
1885 | } |
|
|
1886 | |
|
|
1887 | sub mouse_motion { |
|
|
1888 | my ($self, $ev, $x, $y) = @_; |
|
|
1889 | |
|
|
1890 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1891 | } |
|
|
1892 | |
|
|
1893 | sub size_request { |
|
|
1894 | ( |
|
|
1895 | 1 + 32 * int $::WIDTH / 32, |
|
|
1896 | 1 + 32 * int $::HEIGHT / 32, |
|
|
1897 | ) |
|
|
1898 | } |
|
|
1899 | |
|
|
1900 | sub update { |
|
|
1901 | my ($self) = @_; |
|
|
1902 | |
|
|
1903 | $self->{need_update} = 1; |
|
|
1904 | $self->SUPER::update; |
|
|
1905 | } |
|
|
1906 | |
|
|
1907 | sub draw { |
|
|
1908 | my ($self) = @_; |
|
|
1909 | |
|
|
1910 | if (delete $self->{need_update}) { |
|
|
1911 | glNewList $self->{list}, GL_COMPILE; |
|
|
1912 | |
|
|
1913 | if ($::MAP) { |
|
|
1914 | my $sw = int $::WIDTH / 32; |
|
|
1915 | my $sh = int $::HEIGHT / 32; |
|
|
1916 | |
|
|
1917 | my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
1918 | my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
1919 | |
|
|
1920 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
|
|
1921 | |
|
|
1922 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
|
|
1923 | |
|
|
1924 | if ($::CFG->{fow_enable}) { |
|
|
1925 | if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war |
|
|
1926 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
|
|
1927 | glConvolutionFilter2D ( |
|
|
1928 | GL_CONVOLUTION_2D, |
|
|
1929 | GL_ALPHA, |
|
|
1930 | 3, 3, |
|
|
1931 | GL_ALPHA, GL_FLOAT, |
|
|
1932 | pack "f*", |
|
|
1933 | 0.1, 0.1, 0.1, |
|
|
1934 | 0.1, 0.2, 0.1, |
|
|
1935 | 0.1, 0.1, 0.1, |
|
|
1936 | ); |
|
|
1937 | glEnable GL_CONVOLUTION_2D; |
|
|
1938 | } |
|
|
1939 | |
|
|
1940 | $self->{fow_texture} = new CFClient::Texture |
|
|
1941 | w => $w, |
|
|
1942 | h => $h, |
|
|
1943 | data => $data, |
|
|
1944 | internalformat => GL_ALPHA, |
|
|
1945 | format => GL_ALPHA; |
|
|
1946 | |
|
|
1947 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
1948 | |
|
|
1949 | glEnable GL_BLEND; |
|
|
1950 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1951 | glEnable GL_TEXTURE_2D; |
|
|
1952 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1953 | |
|
|
1954 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1955 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1956 | |
|
|
1957 | glDisable GL_TEXTURE_2D; |
|
|
1958 | glDisable GL_BLEND; |
|
|
1959 | } |
|
|
1960 | |
|
|
1961 | # HACK BEGIN |
|
|
1962 | { |
|
|
1963 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
1964 | my ($w, $h) = (250, 250); |
|
|
1965 | |
|
|
1966 | glEnable GL_BLEND; |
|
|
1967 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1968 | glEnable GL_TEXTURE_2D; |
|
|
1969 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1970 | |
|
|
1971 | $self->{mapmap_texture} = |
|
|
1972 | new CFClient::Texture |
|
|
1973 | w => $w, |
|
|
1974 | h => $h, |
|
|
1975 | data => $::MAP->mapmap ($w, $h), |
|
|
1976 | type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
|
|
1977 | |
|
|
1978 | $self->{mapmap_texture}->draw_quad (100, 100); |
|
|
1979 | |
|
|
1980 | glDisable GL_TEXTURE_2D; |
|
|
1981 | glDisable GL_BLEND; |
|
|
1982 | } |
|
|
1983 | # HACK END |
|
|
1984 | } |
|
|
1985 | |
|
|
1986 | glEndList; |
|
|
1987 | } |
|
|
1988 | |
|
|
1989 | glPushMatrix; |
|
|
1990 | glCallList $self->{list}; |
|
|
1991 | glPopMatrix; |
|
|
1992 | |
|
|
1993 | if ($FOCUS != $self) { |
|
|
1994 | glColor 64/255, 64/255, 64/255; |
|
|
1995 | glLogicOp GL_AND; |
|
|
1996 | glEnable GL_COLOR_LOGIC_OP; |
|
|
1997 | glBegin GL_QUADS; |
|
|
1998 | glVertex 0, 0; |
|
|
1999 | glVertex 0, $::HEIGHT; |
|
|
2000 | glVertex $::WIDTH, $::HEIGHT; |
|
|
2001 | glVertex $::WIDTH, 0; |
|
|
2002 | glEnd; |
|
|
2003 | glDisable GL_COLOR_LOGIC_OP; |
|
|
2004 | } |
|
|
2005 | } |
|
|
2006 | |
|
|
2007 | my %DIR = ( |
|
|
2008 | SDLK_KP8, [1, "north"], |
|
|
2009 | SDLK_KP9, [2, "northeast"], |
|
|
2010 | SDLK_KP6, [3, "east"], |
|
|
2011 | SDLK_KP3, [4, "southeast"], |
|
|
2012 | SDLK_KP2, [5, "south"], |
|
|
2013 | SDLK_KP1, [6, "southwest"], |
|
|
2014 | SDLK_KP4, [7, "west"], |
|
|
2015 | SDLK_KP7, [8, "northwest"], |
|
|
2016 | |
|
|
2017 | SDLK_UP, [1, "north"], |
|
|
2018 | SDLK_RIGHT, [3, "east"], |
|
|
2019 | SDLK_DOWN, [5, "south"], |
|
|
2020 | SDLK_LEFT, [7, "west"], |
|
|
2021 | ); |
|
|
2022 | |
|
|
2023 | sub key_down { |
|
|
2024 | my ($self, $ev) = @_; |
|
|
2025 | |
|
|
2026 | my $mod = $ev->key_mod; |
|
|
2027 | my $sym = $ev->key_sym; |
|
|
2028 | |
|
|
2029 | if ($sym == SDLK_KP5) { |
|
|
2030 | $::CONN->user_send ("stay fire"); |
|
|
2031 | } elsif ($sym == SDLK_a) { |
|
|
2032 | $::CONN->user_send ("apply"); |
|
|
2033 | } elsif ($sym == SDLK_QUOTE) { |
|
|
2034 | $self->emit ('activate_console'); |
|
|
2035 | } elsif ($sym == SDLK_SLASH) { |
|
|
2036 | $self->emit ('activate_console' => '/'); |
|
|
2037 | } elsif (exists $DIR{$sym}) { |
|
|
2038 | if ($mod & KMOD_SHIFT) { |
|
|
2039 | $self->{shft}++; |
|
|
2040 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
2041 | } elsif ($mod & KMOD_CTRL) { |
|
|
2042 | $self->{ctrl}++; |
|
|
2043 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
|
|
2044 | } else { |
|
|
2045 | $::CONN->user_send ("$DIR{$sym}[1]"); |
|
|
2046 | } |
|
|
2047 | } |
|
|
2048 | } |
|
|
2049 | |
|
|
2050 | sub key_up { |
|
|
2051 | my ($self, $ev) = @_; |
|
|
2052 | |
|
|
2053 | my $mod = $ev->key_mod; |
|
|
2054 | my $sym = $ev->key_sym; |
|
|
2055 | |
|
|
2056 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
|
|
2057 | $::CONN->user_send ("fire_stop"); |
|
|
2058 | } |
|
|
2059 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
2060 | $::CONN->user_send ("run_stop"); |
|
|
2061 | } |
|
|
2062 | } |
|
|
2063 | |
|
|
2064 | ############################################################################# |
|
|
2065 | |
|
|
2066 | package CFClient::UI::Animator; |
2091 | package CFClient::UI::Animator; |
2067 | |
2092 | |
2068 | use SDL::OpenGL; |
2093 | use CFClient::OpenGL; |
2069 | |
2094 | |
2070 | our @ISA = CFClient::UI::Bin::; |
2095 | our @ISA = CFClient::UI::Bin::; |
2071 | |
2096 | |
2072 | sub moveto { |
2097 | sub moveto { |
2073 | my ($self, $x, $y) = @_; |
2098 | my ($self, $x, $y) = @_; |
… | |
… | |
2113 | my $class = shift; |
2138 | my $class = shift; |
2114 | |
2139 | |
2115 | my $self = $class->SUPER::new ( |
2140 | my $self = $class->SUPER::new ( |
2116 | state => 0, |
2141 | state => 0, |
2117 | connect_activate => \&toggle_flopper, |
2142 | connect_activate => \&toggle_flopper, |
|
|
2143 | can_events => 1, |
2118 | @_ |
2144 | @_ |
2119 | ); |
2145 | ); |
2120 | |
2146 | |
2121 | if ($self->{state}) { |
2147 | if ($self->{state}) { |
2122 | $self->{state} = 0; |
2148 | $self->{state} = 0; |
… | |
… | |
2142 | $self->emit (changed => $self->{state}); |
2168 | $self->emit (changed => $self->{state}); |
2143 | } |
2169 | } |
2144 | |
2170 | |
2145 | ############################################################################# |
2171 | ############################################################################# |
2146 | |
2172 | |
|
|
2173 | package CFClient::UI::Tooltip; |
|
|
2174 | |
|
|
2175 | our @ISA = CFClient::UI::Bin::; |
|
|
2176 | |
|
|
2177 | use CFClient::OpenGL; |
|
|
2178 | |
|
|
2179 | sub new { |
|
|
2180 | my $class = shift; |
|
|
2181 | |
|
|
2182 | $class->SUPER::new ( |
|
|
2183 | @_, |
|
|
2184 | can_events => 0, |
|
|
2185 | ) |
|
|
2186 | } |
|
|
2187 | |
|
|
2188 | sub set_text { |
|
|
2189 | my ($self, $text) = @_; |
|
|
2190 | |
|
|
2191 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
|
|
2192 | $self->{label}->set_text ($text); |
|
|
2193 | $self->add ($self->{label}); |
|
|
2194 | } |
|
|
2195 | |
|
|
2196 | sub size_request { |
|
|
2197 | my ($self) = @_; |
|
|
2198 | |
|
|
2199 | $self->child->set_max_size ($::WIDTH * 0.3); |
|
|
2200 | |
|
|
2201 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
|
|
2202 | |
|
|
2203 | ($w + 4, $h + 4) |
|
|
2204 | } |
|
|
2205 | |
|
|
2206 | sub _draw { |
|
|
2207 | my ($self) = @_; |
|
|
2208 | |
|
|
2209 | glPushMatrix; |
|
|
2210 | glTranslate 0.375, 0.375; |
|
|
2211 | |
|
|
2212 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2213 | |
|
|
2214 | glColor 1, 0.8, 0.4; |
|
|
2215 | glBegin GL_QUADS; |
|
|
2216 | glVertex 0 , 0; |
|
|
2217 | glVertex 0 , $h; |
|
|
2218 | glVertex $w, $h; |
|
|
2219 | glVertex $w, 0; |
|
|
2220 | glEnd; |
|
|
2221 | |
|
|
2222 | glColor 0, 0, 0; |
|
|
2223 | glBegin GL_LINE_LOOP; |
|
|
2224 | glVertex 0 , 0; |
|
|
2225 | glVertex 0 , $h; |
|
|
2226 | glVertex $w, $h; |
|
|
2227 | glVertex $w, 0; |
|
|
2228 | glEnd; |
|
|
2229 | |
|
|
2230 | glPopMatrix; |
|
|
2231 | |
|
|
2232 | glTranslate 2, 2; |
|
|
2233 | $self->SUPER::_draw; |
|
|
2234 | } |
|
|
2235 | |
|
|
2236 | ############################################################################# |
|
|
2237 | |
2147 | package CFClient::UI::Root; |
2238 | package CFClient::UI::Root; |
2148 | |
2239 | |
2149 | our @ISA = CFClient::UI::Container::; |
2240 | our @ISA = CFClient::UI::Container::; |
2150 | |
2241 | |
2151 | use SDL::OpenGL; |
2242 | use CFClient::OpenGL; |
2152 | |
2243 | |
2153 | sub check_size { |
2244 | sub check_size { |
2154 | my ($self) = @_; |
2245 | my ($self) = @_; |
2155 | |
2246 | |
2156 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2247 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
2157 | } |
2248 | } |
2158 | |
2249 | |
2159 | sub size_request { |
2250 | sub size_request { |
2160 | ($::WIDTH, $::HEIGHT) |
2251 | ($::WIDTH, $::HEIGHT) |
2161 | } |
2252 | } |
… | |
… | |
2163 | sub configure { |
2254 | sub configure { |
2164 | my ($self, $x, $y, $w, $h) = @_; |
2255 | my ($self, $x, $y, $w, $h) = @_; |
2165 | |
2256 | |
2166 | $self->SUPER::configure ($x, $y, $w, $h); |
2257 | $self->SUPER::configure ($x, $y, $w, $h); |
2167 | |
2258 | |
2168 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
|
|
2169 | for @{$self->{children}}; |
2259 | for my $child (@{$self->{children}}) { |
|
|
2260 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
|
|
2261 | |
|
|
2262 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
|
|
2263 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
|
|
2264 | $child->configure ($X, $Y, $W,$H); |
|
|
2265 | } |
2170 | } |
2266 | } |
2171 | |
2267 | |
2172 | sub _topleft { |
2268 | sub _topleft { |
2173 | my ($self, $x, $y) = @_; |
2269 | my ($self, $x, $y) = @_; |
2174 | |
2270 | |
… | |
… | |
2182 | ::refresh (); |
2278 | ::refresh (); |
2183 | } |
2279 | } |
2184 | |
2280 | |
2185 | sub add { |
2281 | sub add { |
2186 | my ($self, $child) = @_; |
2282 | my ($self, $child) = @_; |
|
|
2283 | |
|
|
2284 | # integerize window positions |
|
|
2285 | $child->{x} = int $child->{x}; |
|
|
2286 | $child->{y} = int $child->{y}; |
2187 | |
2287 | |
2188 | $self->SUPER::add ($child); |
2288 | $self->SUPER::add ($child); |
2189 | } |
2289 | } |
2190 | |
2290 | |
2191 | sub on_refresh { |
2291 | sub on_refresh { |
… | |
… | |
2217 | ############################################################################# |
2317 | ############################################################################# |
2218 | |
2318 | |
2219 | package CFClient::UI; |
2319 | package CFClient::UI; |
2220 | |
2320 | |
2221 | $ROOT = new CFClient::UI::Root; |
2321 | $ROOT = new CFClient::UI::Root; |
|
|
2322 | $TOOLTIP = new CFClient::UI::Tooltip; |
2222 | |
2323 | |
2223 | 1 |
2324 | 1 |
2224 | |
2325 | |