… | |
… | |
21 | $FOCUS->key_up ($_[0]) if $FOCUS; |
21 | $FOCUS->key_up ($_[0]) if $FOCUS; |
22 | } |
22 | } |
23 | |
23 | |
24 | sub feed_sdl_button_down_event { |
24 | sub feed_sdl_button_down_event { |
25 | my ($ev) = @_; |
25 | my ($ev) = @_; |
26 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
26 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
27 | |
27 | |
28 | if (!$BUTTON_STATE) { |
28 | if (!$BUTTON_STATE) { |
29 | my $widget = $ROOT->find_widget ($x, $y); |
29 | my $widget = $ROOT->find_widget ($x, $y); |
30 | |
30 | |
31 | $GRAB = $widget; |
31 | $GRAB = $widget; |
32 | $GRAB->update if $GRAB; |
32 | $GRAB->update if $GRAB; |
33 | } |
33 | } |
34 | |
34 | |
35 | $BUTTON_STATE |= 1 << ($ev->button - 1); |
35 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
36 | |
36 | |
37 | $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
37 | $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
38 | } |
38 | } |
39 | |
39 | |
40 | sub feed_sdl_button_up_event { |
40 | sub feed_sdl_button_up_event { |
41 | my ($ev) = @_; |
41 | my ($ev) = @_; |
42 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
42 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
43 | |
43 | |
44 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
44 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
45 | |
45 | |
46 | $BUTTON_STATE &= ~(1 << ($ev->button - 1)); |
46 | $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); |
47 | |
47 | |
48 | $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
48 | $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
49 | |
49 | |
50 | if (!$BUTTON_STATE) { |
50 | if (!$BUTTON_STATE) { |
51 | my $grab = $GRAB; undef $GRAB; |
51 | my $grab = $GRAB; undef $GRAB; |
… | |
… | |
54 | } |
54 | } |
55 | } |
55 | } |
56 | |
56 | |
57 | sub feed_sdl_motion_event { |
57 | sub feed_sdl_motion_event { |
58 | my ($ev) = @_; |
58 | my ($ev) = @_; |
59 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
59 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
60 | |
60 | |
61 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
61 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
62 | |
62 | |
63 | if ($widget != $HOVER) { |
63 | if ($widget != $HOVER) { |
64 | my $hover = $HOVER; $HOVER = $widget; |
64 | my $hover = $HOVER; $HOVER = $widget; |
… | |
… | |
87 | |
87 | |
88 | package CFClient::UI::Base; |
88 | package CFClient::UI::Base; |
89 | |
89 | |
90 | use strict; |
90 | use strict; |
91 | |
91 | |
92 | use SDL::OpenGL; |
92 | use CFClient::OpenGL; |
93 | |
93 | |
94 | sub new { |
94 | sub new { |
95 | my $class = shift; |
95 | my $class = shift; |
96 | |
96 | |
97 | my $self = bless { |
97 | my $self = bless { |
98 | x => 0, |
98 | x => 0, |
99 | y => 0, |
99 | y => 0, |
100 | z => 0, |
100 | z => 0, |
101 | w => -1, |
|
|
102 | h => -1, |
|
|
103 | @_ |
101 | @_ |
104 | }, $class; |
102 | }, $class; |
105 | |
103 | |
106 | for (keys %$self) { |
104 | for (keys %$self) { |
107 | if (/^connect_(.*)$/) { |
105 | if (/^connect_(.*)$/) { |
… | |
… | |
110 | } |
108 | } |
111 | |
109 | |
112 | $self |
110 | $self |
113 | } |
111 | } |
114 | |
112 | |
|
|
113 | sub show { |
|
|
114 | my ($self) = @_; |
|
|
115 | |
|
|
116 | return if $self->{parent}; |
|
|
117 | |
|
|
118 | $CFClient::UI::ROOT->add ($self); |
|
|
119 | } |
|
|
120 | |
|
|
121 | sub hide { |
|
|
122 | my ($self) = @_; |
|
|
123 | |
|
|
124 | return unless $self->{parent}; |
|
|
125 | |
|
|
126 | $self->{parent}->remove ($self); |
|
|
127 | } |
|
|
128 | |
115 | sub move { |
129 | sub move { |
116 | my ($self, $x, $y, $z) = @_; |
130 | my ($self, $x, $y, $z) = @_; |
|
|
131 | |
117 | $self->{x} = int $x; |
132 | $self->{x} = int $x; |
118 | $self->{y} = int $y; |
133 | $self->{y} = int $y; |
119 | $self->{z} = $z if defined $z; |
134 | $self->{z} = $z if defined $z; |
|
|
135 | |
|
|
136 | $self->update; |
120 | } |
137 | } |
121 | |
138 | |
122 | sub needs_redraw { |
139 | sub needs_redraw { |
123 | 0 |
140 | 0 |
124 | } |
141 | } |
125 | |
142 | |
126 | sub size_request { |
143 | sub size_request { |
127 | require Carp; |
144 | require Carp; |
128 | Carp::confess "size_request is abtract"; |
145 | Carp::confess "size_request is abstract"; |
129 | } |
146 | } |
130 | |
147 | |
131 | sub _size_allocate { |
148 | sub configure { |
132 | my ($self, $x, $y, $w, $h) = @_; |
149 | my ($self, $x, $y, $w, $h) = @_; |
133 | |
150 | |
|
|
151 | if ($self->{aspect}) { |
|
|
152 | my $w2 = List::Util::min $w, int $h * $self->{aspect}; |
|
|
153 | my $h2 = List::Util::min $h, int $w / $self->{aspect}; |
|
|
154 | |
|
|
155 | # use alignment to adjust x, y |
|
|
156 | |
|
|
157 | $x += int +($w - $w2) * 0.5; |
|
|
158 | $y += int +($h - $h2) * 0.5; |
|
|
159 | |
|
|
160 | ($w, $h) = ($w2, $h2); |
|
|
161 | } |
|
|
162 | |
|
|
163 | if ($self->{x} != $x || $self->{y} != $y) { |
134 | $self->{x} = $x; |
164 | $self->{x} = $x; |
135 | $self->{y} = $y; |
165 | $self->{y} = $y; |
|
|
166 | $self->update; |
|
|
167 | } |
136 | |
168 | |
137 | return unless $self->{w} != $w || $self->{h} != $h; |
169 | if ($self->{w} != $w || $self->{h} != $h) { |
138 | |
|
|
139 | $self->{w} = $w; |
170 | $self->{w} = $w; |
140 | $self->{h} = $h; |
171 | $self->{h} = $h; |
141 | |
172 | |
|
|
173 | $self->size_allocate ($w, $h); |
|
|
174 | $self->update; |
142 | 1 |
175 | } |
143 | } |
176 | } |
144 | |
177 | |
145 | sub size_allocate { |
178 | sub size_allocate { |
146 | my ($self, $x, $y, $w, $h) = @_; |
179 | # nothing to be done |
147 | |
|
|
148 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
149 | } |
180 | } |
150 | |
181 | |
151 | # return top left coordinates |
182 | # return top left coordinates |
152 | sub _topleft { |
183 | sub _topleft { |
153 | my ($self, $x, $y) = @_; |
184 | my ($self, $x, $y) = @_; |
… | |
… | |
284 | } |
315 | } |
285 | |
316 | |
286 | sub connect { |
317 | sub connect { |
287 | my ($self, $signal, $cb) = @_; |
318 | my ($self, $signal, $cb) = @_; |
288 | |
319 | |
289 | push @{ $self->{cb}{$signal} }, $cb; |
320 | push @{ $self->{signal_cb}{$signal} }, $cb; |
290 | } |
321 | } |
291 | |
322 | |
292 | sub emit { |
323 | sub emit { |
293 | my ($self, $signal, @args) = @_; |
324 | my ($self, $signal, @args) = @_; |
294 | |
325 | |
|
|
326 | for my $cb (@{$self->{signal_cb}{$signal} || []}) { |
295 | $_->($self, @args) |
327 | $cb->($self, @args); |
296 | for @{$self->{cb}{$signal} || []}; |
328 | } |
297 | } |
329 | } |
298 | |
330 | |
299 | sub DESTROY { |
331 | sub DESTROY { |
300 | my ($self) = @_; |
332 | my ($self) = @_; |
301 | |
333 | |
… | |
… | |
307 | package CFClient::UI::DrawBG; |
339 | package CFClient::UI::DrawBG; |
308 | |
340 | |
309 | our @ISA = CFClient::UI::Base::; |
341 | our @ISA = CFClient::UI::Base::; |
310 | |
342 | |
311 | use strict; |
343 | use strict; |
312 | use SDL::OpenGL; |
344 | use CFClient::OpenGL; |
313 | |
345 | |
314 | sub new { |
346 | sub new { |
315 | my $class = shift; |
347 | my $class = shift; |
316 | |
348 | |
317 | # range [value, low, high, page] |
349 | # range [value, low, high, page] |
… | |
… | |
381 | $self->{children} = [ |
413 | $self->{children} = [ |
382 | sort { $a->{z} <=> $b->{z} } |
414 | sort { $a->{z} <=> $b->{z} } |
383 | @{$self->{children}}, $child |
415 | @{$self->{children}}, $child |
384 | ]; |
416 | ]; |
385 | |
417 | |
386 | $self->{w} = $self->{h} = -1; |
418 | $child->check_size; |
387 | $self->update; |
|
|
388 | } |
419 | } |
389 | |
420 | |
390 | sub remove { |
421 | sub remove { |
391 | my ($self, $widget) = @_; |
422 | my ($self, $child) = @_; |
392 | |
423 | |
|
|
424 | delete $child->{parent}; |
|
|
425 | |
393 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
426 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
394 | |
427 | |
395 | $self->check_size; |
428 | $self->check_size; |
396 | } |
429 | } |
397 | |
430 | |
398 | sub find_widget { |
431 | sub find_widget { |
… | |
… | |
430 | |
463 | |
431 | $class->SUPER::new (children => [$child], %arg) |
464 | $class->SUPER::new (children => [$child], %arg) |
432 | } |
465 | } |
433 | |
466 | |
434 | sub add { |
467 | sub add { |
435 | my ($self, $widget) = @_; |
468 | my ($self, $child) = @_; |
436 | |
469 | |
437 | $self->{children} = []; |
470 | $self->{children} = []; |
438 | |
471 | |
439 | $self->SUPER::add ($widget); |
472 | $self->SUPER::add ($child); |
440 | } |
473 | } |
441 | |
474 | |
442 | sub remove { |
475 | sub remove { |
443 | my ($self, $widget) = @_; |
476 | my ($self, $widget) = @_; |
444 | |
477 | |
… | |
… | |
453 | sub size_request { |
486 | sub size_request { |
454 | $_[0]{children}[0]->size_request |
487 | $_[0]{children}[0]->size_request |
455 | } |
488 | } |
456 | |
489 | |
457 | sub size_allocate { |
490 | sub size_allocate { |
458 | my ($self, $x, $y, $w, $h) = @_; |
491 | my ($self, $w, $h) = @_; |
459 | |
492 | |
460 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
461 | |
|
|
462 | $self->{children}[0]->size_allocate (0, 0, $w, $h); |
493 | $self->{children}[0]->configure (0, 0, $w, $h); |
463 | } |
494 | } |
464 | |
495 | |
465 | ############################################################################# |
496 | ############################################################################# |
466 | |
497 | |
467 | package CFClient::UI::Window; |
498 | package CFClient::UI::Window; |
468 | |
499 | |
469 | our @ISA = CFClient::UI::Bin::; |
500 | our @ISA = CFClient::UI::Bin::; |
470 | |
501 | |
471 | use SDL::OpenGL; |
502 | use CFClient::OpenGL; |
472 | |
503 | |
473 | sub new { |
504 | sub new { |
474 | my ($class, %arg) = @_; |
505 | my ($class, %arg) = @_; |
475 | |
506 | |
476 | my $self = $class->SUPER::new (%arg); |
507 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
493 | $self->child->draw; |
524 | $self->child->draw; |
494 | }; |
525 | }; |
495 | } |
526 | } |
496 | |
527 | |
497 | sub size_allocate { |
528 | sub size_allocate { |
498 | my ($self, $x, $y, $w, $h) = @_; |
529 | my ($self, $w, $h) = @_; |
499 | |
530 | |
500 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
501 | |
|
|
502 | $self->child->size_allocate (0, 0, $w, $h); |
531 | $self->child->configure (0, 0, $w, $h); |
503 | |
532 | |
504 | $self->render_chld; |
533 | $self->render_chld; |
505 | } |
534 | } |
506 | |
535 | |
507 | sub _draw { |
536 | sub _draw { |
… | |
… | |
538 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
567 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
539 | |
568 | |
540 | @$self{qw(child_w child_h)} |
569 | @$self{qw(child_w child_h)} |
541 | } |
570 | } |
542 | |
571 | |
543 | sub size_allocate { |
|
|
544 | my ($self, $x, $y, $w, $h) = @_; |
|
|
545 | |
|
|
546 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
547 | } |
|
|
548 | |
|
|
549 | sub _draw { |
572 | sub _draw { |
550 | my ($self) = @_; |
573 | my ($self) = @_; |
551 | |
574 | |
552 | $self->{children}[1]->draw; |
575 | $self->{children}[1]->draw; |
553 | } |
576 | } |
… | |
… | |
557 | |
580 | |
558 | package CFClient::UI::Frame; |
581 | package CFClient::UI::Frame; |
559 | |
582 | |
560 | our @ISA = CFClient::UI::Bin::; |
583 | our @ISA = CFClient::UI::Bin::; |
561 | |
584 | |
562 | use SDL::OpenGL; |
585 | use CFClient::OpenGL; |
563 | |
586 | |
564 | sub size_request { |
587 | sub size_request { |
565 | my ($self) = @_; |
588 | my ($self) = @_; |
566 | my $chld = $self->child |
589 | my $chld = $self->child |
567 | or return (0, 0); |
590 | or return (0, 0); |
… | |
… | |
572 | } |
595 | } |
573 | |
596 | |
574 | sub size_allocate { |
597 | sub size_allocate { |
575 | my ($self, $x, $y, $w, $h) = @_; |
598 | my ($self, $x, $y, $w, $h) = @_; |
576 | |
599 | |
577 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
578 | |
|
|
579 | $self->child->size_allocate (2, 2, $w - 4, $h - 4); |
600 | $self->child->configure (2, 2, $w - 4, $h - 4); |
580 | } |
601 | } |
581 | |
602 | |
582 | sub _draw { |
603 | sub _draw { |
583 | my ($self) = @_; |
604 | my ($self) = @_; |
584 | |
605 | |
… | |
… | |
601 | |
622 | |
602 | package CFClient::UI::FancyFrame; |
623 | package CFClient::UI::FancyFrame; |
603 | |
624 | |
604 | our @ISA = CFClient::UI::Bin::; |
625 | our @ISA = CFClient::UI::Bin::; |
605 | |
626 | |
606 | use SDL::OpenGL; |
627 | use CFClient::OpenGL; |
607 | |
628 | |
608 | my @tex = |
629 | my @tex = |
609 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
630 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
610 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
631 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
611 | |
632 | |
612 | sub new { |
633 | sub new { |
613 | my $class = shift; |
634 | my $class = shift; |
614 | |
635 | |
615 | # TODO: user_x, user_y, overwrite moveto? |
636 | # TODO: user_x, user_y, overwrite moveto? |
616 | |
637 | |
617 | $class->SUPER::new ( |
638 | my $self = $class->SUPER::new ( |
618 | bg => [1, 1, 1, 1], |
639 | bg => [1, 1, 1, 1], |
619 | border_bg => [1, 1, 1, 1], |
640 | border_bg => [1, 1, 1, 1], |
620 | border => int $::FONTSIZE * 0.8, |
641 | border => 0.8, |
621 | @_ |
642 | @_ |
|
|
643 | ); |
|
|
644 | |
|
|
645 | $self->{title} &&= new CFClient::UI::Label |
|
|
646 | align => 0, |
|
|
647 | valign => 1, |
|
|
648 | text => $self->{title}, |
|
|
649 | fontsize => 1; |
|
|
650 | |
|
|
651 | $self |
|
|
652 | } |
|
|
653 | |
|
|
654 | sub border { |
|
|
655 | int $_[0]{border} * $::FONTSIZE |
|
|
656 | } |
|
|
657 | |
|
|
658 | sub size_request { |
|
|
659 | my ($self) = @_; |
|
|
660 | |
|
|
661 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
|
|
662 | |
|
|
663 | my ($w, $h) = $self->SUPER::size_request; |
|
|
664 | |
|
|
665 | ( |
|
|
666 | $w + $self->border * 2, |
|
|
667 | $h + $self->border * 2, |
622 | ) |
668 | ) |
623 | } |
669 | } |
624 | |
670 | |
625 | sub size_request { |
|
|
626 | my ($self) = @_; |
|
|
627 | |
|
|
628 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
|
|
629 | |
|
|
630 | my ($w, $h) = $self->SUPER::size_request; |
|
|
631 | |
|
|
632 | ( |
|
|
633 | $w + $self->{border} * 2, |
|
|
634 | $h + $self->{border} * 2, |
|
|
635 | ) |
|
|
636 | } |
|
|
637 | |
|
|
638 | sub size_allocate { |
671 | sub size_allocate { |
639 | my ($self, $x, $y, $w, $h) = @_; |
672 | my ($self, $w, $h) = @_; |
640 | |
673 | |
641 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
642 | |
|
|
643 | $h -= List::Util::max 0, $self->{border} * 2; |
674 | $h -= List::Util::max 0, $self->border * 2; |
644 | $w -= List::Util::max 0, $self->{border} * 2; |
675 | $w -= List::Util::max 0, $self->border * 2; |
645 | |
676 | |
|
|
677 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
|
|
678 | if $self->{title}; |
|
|
679 | |
646 | $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); |
680 | $self->child->configure ($self->border, $self->border, $w, $h); |
647 | } |
681 | } |
648 | |
682 | |
649 | sub button_down { |
683 | sub button_down { |
650 | my ($self, $ev, $x, $y) = @_; |
684 | my ($self, $ev, $x, $y) = @_; |
651 | |
685 | |
|
|
686 | my $border = $self->border; |
|
|
687 | |
652 | if ($x < $self->{w} && $x >= $self->{w} - $self->{border} |
688 | if ($x < $self->{w} && $x >= $self->{w} - $border |
653 | && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { |
689 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
654 | |
690 | |
655 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
691 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
656 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
692 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
657 | |
693 | |
658 | $self->{motion} = sub { |
694 | $self->{motion} = sub { |
659 | my ($ev, $x, $y) = @_; |
695 | my ($ev, $x, $y) = @_; |
660 | |
696 | |
661 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
697 | ($x, $y) = ($ev->{x}, $ev->{y}); |
662 | |
698 | |
663 | $self->{user_w} = $bw + $x - $ox; |
699 | $self->{user_w} = $bw + $x - $ox; |
664 | $self->{user_h} = $bh + $y - $oy; |
700 | $self->{user_h} = $bh + $y - $oy; |
665 | $self->update; |
701 | $self->check_size; |
666 | }; |
702 | }; |
667 | |
703 | |
668 | } elsif ($x >= 0 && $x < $self->{w} |
704 | } elsif ($x >= 0 && $x < $self->{w} |
669 | && $y >= 0 && $y < $self->{border}) { |
705 | && $y >= 0 && $y < $border) { |
670 | |
706 | |
671 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
707 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
672 | my ($bx, $by) = ($self->{x}, $self->{y}); |
708 | my ($bx, $by) = ($self->{x}, $self->{y}); |
673 | |
709 | |
674 | $self->{motion} = sub { |
710 | $self->{motion} = sub { |
675 | my ($ev, $x, $y) = @_; |
711 | my ($ev, $x, $y) = @_; |
676 | |
712 | |
677 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
713 | ($x, $y) = ($ev->{x}, $ev->{y}); |
678 | |
714 | |
679 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
715 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
680 | $self->update; |
716 | $self->update; |
681 | }; |
717 | }; |
682 | } |
718 | } |
… | |
… | |
703 | glEnable GL_BLEND; |
739 | glEnable GL_BLEND; |
704 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
740 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
705 | glEnable GL_TEXTURE_2D; |
741 | glEnable GL_TEXTURE_2D; |
706 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
742 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
707 | |
743 | |
|
|
744 | my $border = $self->border; |
|
|
745 | |
708 | glColor @{ $self->{border_bg} }; |
746 | glColor @{ $self->{border_bg} }; |
709 | $tex[1]->draw_quad (0, 0, $w, $self->{border}); |
747 | $tex[1]->draw_quad (0, 0, $w, $border); |
710 | $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); |
748 | $tex[3]->draw_quad (0, $border, $border, $ch); |
711 | $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); |
749 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
712 | $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); |
750 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
713 | |
751 | |
714 | my $bg = $tex[0]; |
752 | my $bg = $tex[0]; |
715 | |
753 | |
716 | # TODO: repeat texture not scale |
754 | # TODO: repeat texture not scale |
717 | my $rep_x = $cw / $bg->{w}; |
755 | my $rep_x = $cw / $bg->{w}; |
… | |
… | |
720 | glColor @{ $self->{bg} }; |
758 | glColor @{ $self->{bg} }; |
721 | |
759 | |
722 | $bg->{s} = $rep_x; |
760 | $bg->{s} = $rep_x; |
723 | $bg->{t} = $rep_y; |
761 | $bg->{t} = $rep_y; |
724 | $bg->{wrap_mode} = 1; |
762 | $bg->{wrap_mode} = 1; |
725 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
763 | $bg->draw_quad ($border, $border, $cw, $ch); |
726 | |
764 | |
727 | glDisable GL_TEXTURE_2D; |
765 | glDisable GL_TEXTURE_2D; |
728 | glDisable GL_BLEND; |
766 | glDisable GL_BLEND; |
729 | |
767 | |
|
|
768 | $self->{title}->draw if $self->{title}; |
730 | $self->child->draw; |
769 | $self->child->draw; |
731 | } |
770 | } |
732 | |
771 | |
733 | ############################################################################# |
772 | ############################################################################# |
734 | |
773 | |
… | |
… | |
736 | |
775 | |
737 | our @ISA = CFClient::UI::Base::; |
776 | our @ISA = CFClient::UI::Base::; |
738 | |
777 | |
739 | use List::Util qw(max sum); |
778 | use List::Util qw(max sum); |
740 | |
779 | |
741 | use SDL::OpenGL; |
780 | use CFClient::OpenGL; |
742 | |
781 | |
743 | sub new { |
782 | sub new { |
744 | my $class = shift; |
783 | my $class = shift; |
745 | |
784 | |
746 | $class->SUPER::new ( |
785 | $class->SUPER::new ( |
… | |
… | |
753 | my ($self, $x, $y, $child) = @_; |
792 | my ($self, $x, $y, $child) = @_; |
754 | |
793 | |
755 | $child->set_parent ($self); |
794 | $child->set_parent ($self); |
756 | $self->{children}[$y][$x] = $child; |
795 | $self->{children}[$y][$x] = $child; |
757 | |
796 | |
758 | $self->{w} = $self->{h} = -1; |
797 | $child->check_size; |
759 | $self->update; |
|
|
760 | } |
798 | } |
761 | |
799 | |
762 | # TODO: move to container class maybe? send childs a signal on removal? |
800 | # TODO: move to container class maybe? send childs a signal on removal? |
763 | sub clear { |
801 | sub clear { |
764 | my ($self) = @_; |
802 | my ($self) = @_; |
… | |
… | |
799 | (sum @$hs), |
837 | (sum @$hs), |
800 | ) |
838 | ) |
801 | } |
839 | } |
802 | |
840 | |
803 | sub size_allocate { |
841 | sub size_allocate { |
804 | my ($self, $x, $y, $w, $h) = @_; |
842 | my ($self, $w, $h) = @_; |
805 | |
|
|
806 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
807 | |
843 | |
808 | my ($ws, $hs) = $self->get_wh; |
844 | my ($ws, $hs) = $self->get_wh; |
809 | |
845 | |
810 | my $req_w = sum @$ws; |
846 | my $req_w = sum @$ws; |
811 | my $req_h = sum @$hs; |
847 | my $req_h = sum @$hs; |
… | |
… | |
833 | |
869 | |
834 | for my $c (0 .. $#$row) { |
870 | for my $c (0 .. $#$row) { |
835 | my $col_w = $ws->[$c]; |
871 | my $col_w = $ws->[$c]; |
836 | |
872 | |
837 | if (my $widget = $row->[$c]) { |
873 | if (my $widget = $row->[$c]) { |
838 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
874 | $widget->configure ($x, $y, $col_w, $row_h); |
839 | } |
875 | } |
840 | |
876 | |
841 | $x += $col_w; |
877 | $x += $col_w; |
842 | } |
878 | } |
843 | |
879 | |
… | |
… | |
888 | (List::Util::max map $_->[1], @alloc), |
924 | (List::Util::max map $_->[1], @alloc), |
889 | ) |
925 | ) |
890 | } |
926 | } |
891 | |
927 | |
892 | sub size_allocate { |
928 | sub size_allocate { |
893 | my ($self, $x, $y, $w, $h) = @_; |
929 | my ($self, $w, $h) = @_; |
894 | |
|
|
895 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
896 | |
930 | |
897 | ($h, $w) = ($w, $h); |
931 | ($h, $w) = ($w, $h); |
898 | |
932 | |
899 | my $children = $self->{children}; |
933 | my $children = $self->{children}; |
900 | |
934 | |
… | |
… | |
922 | |
956 | |
923 | my $y = 0; |
957 | my $y = 0; |
924 | for (0 .. $#$children) { |
958 | for (0 .. $#$children) { |
925 | my $child = $children->[$_]; |
959 | my $child = $children->[$_]; |
926 | my $h = $h[$_]; |
960 | my $h = $h[$_]; |
927 | $child->size_allocate ($y, 0, $h, $w); |
961 | $child->configure ($y, 0, $h, $w); |
928 | |
962 | |
929 | $y += $h; |
963 | $y += $h; |
930 | } |
964 | } |
931 | |
965 | |
932 | 1 |
966 | 1 |
… | |
… | |
950 | (List::Util::sum map $_->[1], @alloc), |
984 | (List::Util::sum map $_->[1], @alloc), |
951 | ) |
985 | ) |
952 | } |
986 | } |
953 | |
987 | |
954 | sub size_allocate { |
988 | sub size_allocate { |
955 | my ($self, $x, $y, $w, $h) = @_; |
989 | my ($self, $w, $h) = @_; |
956 | |
|
|
957 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
958 | |
990 | |
959 | my $children = $self->{children}; |
991 | my $children = $self->{children}; |
960 | |
992 | |
961 | my @h = map +($_->size_request)[1], @$children; |
993 | my @h = map +($_->size_request)[1], @$children; |
962 | |
994 | |
… | |
… | |
980 | |
1012 | |
981 | my $y = 0; |
1013 | my $y = 0; |
982 | for (0 .. $#$children) { |
1014 | for (0 .. $#$children) { |
983 | my $child = $children->[$_]; |
1015 | my $child = $children->[$_]; |
984 | my $h = $h[$_]; |
1016 | my $h = $h[$_]; |
985 | $child->size_allocate (0, $y, $w, $h); |
1017 | $child->configure (0, $y, $w, $h); |
986 | |
1018 | |
987 | $y += $h; |
1019 | $y += $h; |
988 | } |
1020 | } |
989 | |
1021 | |
990 | 1 |
1022 | 1 |
… | |
… | |
994 | |
1026 | |
995 | package CFClient::UI::Label; |
1027 | package CFClient::UI::Label; |
996 | |
1028 | |
997 | our @ISA = CFClient::UI::Base::; |
1029 | our @ISA = CFClient::UI::Base::; |
998 | |
1030 | |
999 | use SDL::OpenGL; |
1031 | use CFClient::OpenGL; |
1000 | |
1032 | |
1001 | sub new { |
1033 | sub new { |
1002 | my ($class, %arg) = @_; |
1034 | my ($class, %arg) = @_; |
1003 | |
1035 | |
1004 | my $self = $class->SUPER::new ( |
1036 | my $self = $class->SUPER::new ( |
1005 | fg => [1, 1, 1], |
1037 | fg => [1, 1, 1], |
1006 | fontsize => $::FONTSIZE, |
1038 | fontsize => 1, |
1007 | text => "", |
1039 | text => "", |
1008 | align => -1, |
1040 | align => -1, |
1009 | valign => -1, |
1041 | valign => -1, |
1010 | padding => 2, |
1042 | padding => 2, |
1011 | layout => new CFClient::Layout, |
1043 | layout => new CFClient::Layout, |
1012 | %arg |
1044 | %arg |
1013 | ); |
1045 | ); |
1014 | |
1046 | |
1015 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
1047 | if (exists $self->{template}) { |
|
|
1048 | my $layout = new CFClient::Layout; |
|
|
1049 | $layout->set_text (delete $self->{template}); |
|
|
1050 | $self->{template} = $layout; |
|
|
1051 | } |
1016 | |
1052 | |
1017 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1053 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1018 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1054 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1019 | |
1055 | |
1020 | $self |
1056 | $self |
… | |
… | |
1050 | |
1086 | |
1051 | sub size_request { |
1087 | sub size_request { |
1052 | my ($self) = @_; |
1088 | my ($self) = @_; |
1053 | |
1089 | |
1054 | $self->{layout}->set_width; |
1090 | $self->{layout}->set_width; |
1055 | $self->{layout}->set_height ($self->{fontsize}); |
1091 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1056 | |
1092 | |
1057 | my ($w, $h) = $self->{layout}->size; |
1093 | my ($w, $h) = $self->{layout}->size; |
|
|
1094 | |
|
|
1095 | if (exists $self->{template}) { |
|
|
1096 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
1097 | |
|
|
1098 | my ($w2, $h2) = $self->{template}->size; |
|
|
1099 | |
|
|
1100 | $w = List::Util::max $w, $w2; |
|
|
1101 | $h = List::Util::max $h, $h2; |
|
|
1102 | } |
1058 | |
1103 | |
1059 | ( |
1104 | ( |
1060 | $w + $self->{padding} * 2, |
1105 | $w + $self->{padding} * 2, |
1061 | $h + $self->{padding} * 2, |
1106 | $h + $self->{padding} * 2, |
1062 | ) |
1107 | ) |
1063 | } |
1108 | } |
1064 | |
1109 | |
1065 | sub size_allocate { |
1110 | sub size_allocate { |
1066 | my ($self, $x, $y, $w, $h) = @_; |
1111 | my ($self, $w, $h) = @_; |
1067 | |
|
|
1068 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
1069 | |
1112 | |
1070 | delete $self->{texture}; |
1113 | delete $self->{texture}; |
1071 | } |
1114 | } |
1072 | |
1115 | |
1073 | sub update { |
1116 | sub set_fontsize { |
1074 | my ($self) = @_; |
1117 | my ($self, $fontsize) = @_; |
1075 | |
1118 | |
1076 | delete $self->{texture}; |
1119 | $self->{fontsize} = $fontsize; |
1077 | $self->SUPER::update; |
1120 | $self->check_size; |
1078 | } |
1121 | } |
1079 | |
1122 | |
1080 | sub _draw { |
1123 | sub _draw { |
1081 | my ($self) = @_; |
1124 | my ($self) = @_; |
1082 | |
1125 | |
1083 | my $tex = $self->{texture} ||= do { |
1126 | my $tex = $self->{texture} ||= do { |
1084 | $self->{layout}->set_width ($self->{w}); |
1127 | $self->{layout}->set_width ($self->{w}); |
1085 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); |
1128 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1086 | new_from_layout CFClient::Texture $self->{layout} |
1129 | new_from_layout CFClient::Texture $self->{layout} |
1087 | }; |
1130 | }; |
1088 | |
1131 | |
1089 | glEnable GL_BLEND; |
1132 | glEnable GL_BLEND; |
1090 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1133 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
… | |
… | |
1115 | |
1158 | |
1116 | package CFClient::UI::EntryBase; |
1159 | package CFClient::UI::EntryBase; |
1117 | |
1160 | |
1118 | our @ISA = CFClient::UI::Label::; |
1161 | our @ISA = CFClient::UI::Label::; |
1119 | |
1162 | |
1120 | use SDL; |
1163 | use CFClient::OpenGL; |
1121 | use SDL::OpenGL; |
|
|
1122 | |
1164 | |
1123 | sub new { |
1165 | sub new { |
1124 | my $class = shift; |
1166 | my $class = shift; |
1125 | |
1167 | |
1126 | $class->SUPER::new ( |
1168 | $class->SUPER::new ( |
… | |
… | |
1140 | |
1182 | |
1141 | delete $self->{cur_h}; |
1183 | delete $self->{cur_h}; |
1142 | |
1184 | |
1143 | return if $self->{text} eq $text; |
1185 | return if $self->{text} eq $text; |
1144 | |
1186 | |
|
|
1187 | delete $self->{texture}; |
|
|
1188 | |
1145 | $self->{last_activity} = $::NOW; |
1189 | $self->{last_activity} = $::NOW; |
1146 | $self->{text} = $text; |
1190 | $self->{text} = $text; |
1147 | |
1191 | |
1148 | $text =~ s/./*/g if $self->{hidden}; |
1192 | $text =~ s/./*/g if $self->{hidden}; |
1149 | $self->{layout}->set_text ("$text "); |
1193 | $self->{layout}->set_text ("$text "); |
… | |
… | |
1162 | |
1206 | |
1163 | ($w + 1, $h) # add 1 for cursor |
1207 | ($w + 1, $h) # add 1 for cursor |
1164 | } |
1208 | } |
1165 | |
1209 | |
1166 | sub size_allocate { |
1210 | sub size_allocate { |
1167 | my ($self, $x, $y, $w, $h) = @_; |
1211 | my ($self, $w, $h) = @_; |
1168 | |
|
|
1169 | $self->SUPER::size_allocate ($x, $y, $w, $h) or return; |
|
|
1170 | |
1212 | |
1171 | $self->_set_text ($self->{text}); |
1213 | $self->_set_text ($self->{text}); |
1172 | } |
1214 | } |
1173 | |
1215 | |
1174 | sub set_text { |
1216 | sub set_text { |
… | |
… | |
1180 | } |
1222 | } |
1181 | |
1223 | |
1182 | sub key_down { |
1224 | sub key_down { |
1183 | my ($self, $ev) = @_; |
1225 | my ($self, $ev) = @_; |
1184 | |
1226 | |
1185 | my $mod = $ev->key_mod; |
1227 | my $mod = $ev->{mod}; |
1186 | my $sym = $ev->key_sym; |
1228 | my $sym = $ev->{sym}; |
1187 | |
|
|
1188 | my $uni = $ev->key_unicode; |
1229 | my $uni = $ev->{unicode}; |
1189 | |
1230 | |
1190 | my $text = $self->get_text; |
1231 | my $text = $self->get_text; |
1191 | |
1232 | |
1192 | if ($sym == SDLK_BACKSPACE) { |
1233 | if ($sym == 8) { |
1193 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1234 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1194 | } elsif ($sym == SDLK_DELETE) { |
1235 | } elsif ($sym == 127) { |
1195 | substr $text, $self->{cursor}, 1, ""; |
1236 | substr $text, $self->{cursor}, 1, ""; |
1196 | } elsif ($sym == SDLK_LEFT) { |
1237 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1197 | --$self->{cursor} if $self->{cursor}; |
1238 | --$self->{cursor} if $self->{cursor}; |
1198 | } elsif ($sym == SDLK_RIGHT) { |
1239 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1199 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1240 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1200 | } elsif ($sym == SDLK_HOME) { |
1241 | } elsif ($sym == CFClient::SDLK_HOME) { |
1201 | $self->{cursor} = 0; |
1242 | $self->{cursor} = 0; |
1202 | } elsif ($sym == SDLK_END) { |
1243 | } elsif ($sym == CFClient::SDLK_END) { |
1203 | $self->{cursor} = length $text; |
1244 | $self->{cursor} = length $text; |
1204 | } elsif ($sym == SDLK_ESCAPE) { |
1245 | } elsif ($sym == 27) { |
1205 | $self->emit ('escape'); |
1246 | $self->emit ('escape'); |
1206 | } elsif ($uni) { |
1247 | } elsif ($uni) { |
1207 | substr $text, $self->{cursor}++, 0, chr $uni; |
1248 | substr $text, $self->{cursor}++, 0, chr $uni; |
1208 | } |
1249 | } |
1209 | |
1250 | |
… | |
… | |
1284 | |
1325 | |
1285 | package CFClient::UI::Entry; |
1326 | package CFClient::UI::Entry; |
1286 | |
1327 | |
1287 | our @ISA = CFClient::UI::EntryBase::; |
1328 | our @ISA = CFClient::UI::EntryBase::; |
1288 | |
1329 | |
1289 | use SDL; |
1330 | use CFClient::OpenGL; |
1290 | use SDL::OpenGL; |
|
|
1291 | |
1331 | |
1292 | sub key_down { |
1332 | sub key_down { |
1293 | my ($self, $ev) = @_; |
1333 | my ($self, $ev) = @_; |
1294 | |
1334 | |
1295 | my $sym = $ev->key_sym; |
1335 | my $sym = $ev->{sym}; |
1296 | |
1336 | |
1297 | if ($sym == SDLK_RETURN) { |
1337 | if ($sym == 13) { |
1298 | $self->emit (activate => $self->get_text); |
1338 | $self->emit (activate => $self->get_text); |
1299 | $self->update; |
1339 | $self->update; |
1300 | |
1340 | |
1301 | } else { |
1341 | } else { |
1302 | $self->SUPER::key_down ($ev); |
1342 | $self->SUPER::key_down ($ev); |
… | |
… | |
1308 | |
1348 | |
1309 | package CFClient::UI::Button; |
1349 | package CFClient::UI::Button; |
1310 | |
1350 | |
1311 | our @ISA = CFClient::UI::Label::; |
1351 | our @ISA = CFClient::UI::Label::; |
1312 | |
1352 | |
1313 | use SDL; |
1353 | use CFClient::OpenGL; |
1314 | use SDL::OpenGL; |
|
|
1315 | |
1354 | |
1316 | my @tex = |
1355 | my @tex = |
1317 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1356 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1318 | qw(b1_button_active.png); |
1357 | qw(b1_button_active.png); |
1319 | |
1358 | |
1320 | sub new { |
1359 | sub new { |
1321 | my $class = shift; |
1360 | my $class = shift; |
1322 | |
1361 | |
… | |
… | |
1324 | padding => 4, |
1363 | padding => 4, |
1325 | fg => [1, 1, 1], |
1364 | fg => [1, 1, 1], |
1326 | bg => [1, 1, 1, 0.2], |
1365 | bg => [1, 1, 1, 0.2], |
1327 | active_fg => [0, 0, 1], |
1366 | active_fg => [0, 0, 1], |
1328 | can_hover => 1, |
1367 | can_hover => 1, |
|
|
1368 | align => 0, |
|
|
1369 | valign => 0, |
1329 | @_ |
1370 | @_ |
1330 | ) |
1371 | ) |
1331 | } |
1372 | } |
1332 | |
1373 | |
1333 | sub button_up { |
1374 | sub button_up { |
… | |
… | |
1367 | package CFClient::UI::CheckBox; |
1408 | package CFClient::UI::CheckBox; |
1368 | |
1409 | |
1369 | our @ISA = CFClient::UI::DrawBG::; |
1410 | our @ISA = CFClient::UI::DrawBG::; |
1370 | |
1411 | |
1371 | my @tex = |
1412 | my @tex = |
1372 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1413 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1373 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1414 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1374 | |
1415 | |
1375 | use SDL; |
1416 | use CFClient::OpenGL; |
1376 | use SDL::OpenGL; |
|
|
1377 | |
1417 | |
1378 | sub new { |
1418 | sub new { |
1379 | my $class = shift; |
1419 | my $class = shift; |
1380 | |
1420 | |
1381 | $class->SUPER::new ( |
1421 | $class->SUPER::new ( |
… | |
… | |
1392 | my ($self) = @_; |
1432 | my ($self) = @_; |
1393 | |
1433 | |
1394 | ($self->{padding} * 2 + 6) x 2 |
1434 | ($self->{padding} * 2 + 6) x 2 |
1395 | } |
1435 | } |
1396 | |
1436 | |
1397 | sub size_allocate { |
|
|
1398 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1399 | |
|
|
1400 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
1401 | } |
|
|
1402 | |
|
|
1403 | sub button_down { |
1437 | sub button_down { |
1404 | my ($self, $ev, $x, $y) = @_; |
1438 | my ($self, $ev, $x, $y) = @_; |
1405 | |
1439 | |
1406 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1440 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1407 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1441 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
… | |
… | |
1433 | glDisable GL_BLEND; |
1467 | glDisable GL_BLEND; |
1434 | } |
1468 | } |
1435 | |
1469 | |
1436 | ############################################################################# |
1470 | ############################################################################# |
1437 | |
1471 | |
1438 | package CFClient::UI::VGauge; |
1472 | package CFClient::UI::Image; |
1439 | |
1473 | |
1440 | our @ISA = CFClient::UI::Base::; |
1474 | our @ISA = CFClient::UI::Base::; |
1441 | |
1475 | |
1442 | use SDL::OpenGL; |
1476 | use CFClient::OpenGL; |
|
|
1477 | use Carp qw/confess/; |
1443 | |
1478 | |
1444 | my %tex = ( |
1479 | our %loaded_images; |
1445 | food => [ |
|
|
1446 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1447 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1448 | ], |
|
|
1449 | grace => [ |
|
|
1450 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1451 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1452 | ], |
|
|
1453 | hp => [ |
|
|
1454 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1455 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1456 | ], |
|
|
1457 | mana => [ |
|
|
1458 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1459 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1460 | ], |
|
|
1461 | ); |
|
|
1462 | |
1480 | |
1463 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1464 | sub new { |
1481 | sub new { |
1465 | my $class = shift; |
1482 | my $class = shift; |
1466 | |
1483 | |
1467 | my $self = $class->SUPER::new (gauge => 'food', @_); |
1484 | my $self = $class->SUPER::new (@_); |
|
|
1485 | |
|
|
1486 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
|
|
1487 | |
|
|
1488 | $loaded_images{$self->{image}} ||= |
|
|
1489 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
|
|
1490 | |
|
|
1491 | my $tex = $self->{tex} = $loaded_images{$self->{image}}; |
|
|
1492 | |
|
|
1493 | Scalar::Util::weaken $loaded_images{$self->{image}}; |
|
|
1494 | |
|
|
1495 | $self->{aspect} = $tex->{w} / $tex->{h}; |
1468 | |
1496 | |
1469 | $self |
1497 | $self |
1470 | } |
1498 | } |
1471 | |
1499 | |
1472 | sub size_request { |
1500 | sub size_request { |
1473 | my ($self) = @_; |
1501 | my ($self) = @_; |
1474 | |
1502 | |
1475 | ($self->{w}, $self->{h}) |
1503 | ($self->{tex}->{w}, $self->{tex}->{h}) |
1476 | } |
|
|
1477 | |
|
|
1478 | sub set_max { |
|
|
1479 | my ($self, $max) = @_; |
|
|
1480 | $self->{max_val} = $max; |
|
|
1481 | } |
|
|
1482 | |
|
|
1483 | sub set_value { |
|
|
1484 | my ($self, $val, $max) = @_; |
|
|
1485 | |
|
|
1486 | $self->set_max ($max) |
|
|
1487 | if defined $max; |
|
|
1488 | |
|
|
1489 | $max = $self->{max_val}; |
|
|
1490 | $self->{val} = $val; |
|
|
1491 | |
|
|
1492 | $self->update; |
|
|
1493 | } |
1504 | } |
1494 | |
1505 | |
1495 | sub _draw { |
1506 | sub _draw { |
1496 | my ($self) = @_; |
1507 | my ($self) = @_; |
1497 | |
1508 | |
1498 | my $tex = $tex{$self->{gauge}}; |
1509 | my $tex = $self->{tex}; |
1499 | |
1510 | |
1500 | my ($w, $h) = ($self->{w}, $self->{h}); |
1511 | my ($w, $h) = ($self->{w}, $self->{h}); |
1501 | |
1512 | |
1502 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1513 | if ($self->{rot90}) { |
1503 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1514 | glRotate 90, 0, 0, 1; |
|
|
1515 | glTranslate 0, -$self->{w}, 0; |
1504 | |
1516 | |
1505 | my $t1 = $tex->[0]; |
1517 | ($w, $h) = ($h, $w); |
1506 | my $t2 = $tex->[1]; |
1518 | } |
1507 | |
1519 | |
1508 | glEnable GL_BLEND; |
1520 | glEnable GL_BLEND; |
1509 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1521 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1510 | glEnable GL_TEXTURE_2D; |
1522 | glEnable GL_TEXTURE_2D; |
1511 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1523 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1512 | |
1524 | |
|
|
1525 | $tex->draw_quad (0, 0, $w, $h); |
|
|
1526 | |
|
|
1527 | glDisable GL_BLEND; |
|
|
1528 | glDisable GL_TEXTURE_2D; |
|
|
1529 | } |
|
|
1530 | |
|
|
1531 | ############################################################################# |
|
|
1532 | |
|
|
1533 | package CFClient::UI::VGauge; |
|
|
1534 | |
|
|
1535 | our @ISA = CFClient::UI::Base::; |
|
|
1536 | |
|
|
1537 | use CFClient::OpenGL; |
|
|
1538 | |
|
|
1539 | my %tex = ( |
|
|
1540 | food => [ |
|
|
1541 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1542 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1543 | ], |
|
|
1544 | grace => [ |
|
|
1545 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1546 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1547 | ], |
|
|
1548 | hp => [ |
|
|
1549 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1550 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1551 | ], |
|
|
1552 | mana => [ |
|
|
1553 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1554 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1555 | ], |
|
|
1556 | ); |
|
|
1557 | |
|
|
1558 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1559 | sub new { |
|
|
1560 | my $class = shift; |
|
|
1561 | |
|
|
1562 | my $self = $class->SUPER::new ( |
|
|
1563 | type => 'food', |
|
|
1564 | @_ |
|
|
1565 | ); |
|
|
1566 | |
|
|
1567 | $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h}; |
|
|
1568 | |
|
|
1569 | $self |
|
|
1570 | } |
|
|
1571 | |
|
|
1572 | sub size_request { |
|
|
1573 | my ($self) = @_; |
|
|
1574 | |
|
|
1575 | #my $tex = $tex{$self->{type}}[0]; |
|
|
1576 | #@$tex{qw(w h)} |
|
|
1577 | (0, 0) |
|
|
1578 | } |
|
|
1579 | |
|
|
1580 | sub set_max { |
|
|
1581 | my ($self, $max) = @_; |
|
|
1582 | |
|
|
1583 | $self->{max_val} = $max; |
|
|
1584 | } |
|
|
1585 | |
|
|
1586 | sub set_value { |
|
|
1587 | my ($self, $val, $max) = @_; |
|
|
1588 | |
|
|
1589 | $self->set_max ($max) |
|
|
1590 | if defined $max; |
|
|
1591 | |
|
|
1592 | $max = $self->{max_val}; |
|
|
1593 | $self->{val} = $val; |
|
|
1594 | |
|
|
1595 | $self->update; |
|
|
1596 | } |
|
|
1597 | |
|
|
1598 | sub _draw { |
|
|
1599 | my ($self) = @_; |
|
|
1600 | |
|
|
1601 | my $tex = $tex{$self->{type}}; |
|
|
1602 | |
|
|
1603 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1604 | |
|
|
1605 | if ($self->{vertical}) { |
|
|
1606 | glRotate 90, 0, 0, 1; |
|
|
1607 | glTranslate 0, -$self->{w}, 0; |
|
|
1608 | |
|
|
1609 | ($w, $h) = ($h, $w); |
|
|
1610 | } |
|
|
1611 | |
|
|
1612 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1613 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1614 | |
|
|
1615 | my $t1 = $tex->[0]; |
|
|
1616 | my $t2 = $tex->[1]; |
|
|
1617 | |
|
|
1618 | glEnable GL_BLEND; |
|
|
1619 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1620 | glEnable GL_TEXTURE_2D; |
|
|
1621 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1622 | |
1513 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1623 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1514 | my $h2 = $ycut * $self->{h}; |
1624 | my $h2 = $ycut * $self->{h}; |
1515 | |
1625 | |
1516 | my $yp = 0; |
|
|
1517 | |
|
|
1518 | glBindTexture (GL_TEXTURE_2D, $t1->{name}); |
1626 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1519 | glBegin (GL_QUADS); |
1627 | glBegin GL_QUADS; |
1520 | glTexCoord (0, 0); glVertex (0 , $yp); |
1628 | glTexCoord 0 , 0; glVertex 0 , 0; |
1521 | glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1); |
1629 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1522 | glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1); |
1630 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1523 | glTexCoord (1, 0); glVertex (0 + $w, $yp); |
1631 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1524 | glEnd (); |
1632 | glEnd; |
1525 | |
1633 | |
1526 | $yp += $h1; |
|
|
1527 | |
|
|
1528 | glBindTexture (GL_TEXTURE_2D, $t2->{name}); |
1634 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1529 | glBegin (GL_QUADS); |
1635 | glBegin GL_QUADS; |
1530 | glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp); |
1636 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1531 | glTexCoord (0, 1); glVertex (0 , $yp + $h2); |
1637 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1532 | glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2); |
1638 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1533 | glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp); |
1639 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1534 | glEnd (); |
1640 | glEnd; |
1535 | |
1641 | |
1536 | glDisable GL_BLEND; |
1642 | glDisable GL_BLEND; |
1537 | glDisable GL_TEXTURE_2D; |
1643 | glDisable GL_TEXTURE_2D; |
1538 | } |
1644 | } |
1539 | |
1645 | |
1540 | ############################################################################# |
1646 | ############################################################################# |
1541 | |
1647 | |
|
|
1648 | package CFClient::UI::Gauge; |
|
|
1649 | |
|
|
1650 | our @ISA = CFClient::UI::VBox::; |
|
|
1651 | |
|
|
1652 | sub new { |
|
|
1653 | my ($class, %arg) = shift; |
|
|
1654 | |
|
|
1655 | my $self = $class->SUPER::new ( |
|
|
1656 | @_, |
|
|
1657 | ); |
|
|
1658 | |
|
|
1659 | $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
|
|
1660 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
|
|
1661 | $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
|
|
1662 | |
|
|
1663 | $self |
|
|
1664 | } |
|
|
1665 | |
|
|
1666 | sub set_fontsize { |
|
|
1667 | my ($self, $fsize) = @_; |
|
|
1668 | |
|
|
1669 | $self->{value}->set_fontsize ($fsize); |
|
|
1670 | $self->{max} ->set_fontsize ($fsize); |
|
|
1671 | } |
|
|
1672 | |
|
|
1673 | sub set_value { |
|
|
1674 | my ($self, $val, $max) = @_; |
|
|
1675 | |
|
|
1676 | $self->set_max ($max) |
|
|
1677 | if defined $max; |
|
|
1678 | |
|
|
1679 | $self->{gauge}->set_value ($val, $max); |
|
|
1680 | $self->{value}->set_text ($val); |
|
|
1681 | } |
|
|
1682 | |
|
|
1683 | sub set_max { |
|
|
1684 | my ($self, $max) = @_; |
|
|
1685 | |
|
|
1686 | $self->{gauge}->set_max ($max); |
|
|
1687 | $self->{max}->set_text ($max); |
|
|
1688 | } |
|
|
1689 | |
|
|
1690 | ############################################################################# |
|
|
1691 | |
1542 | package CFClient::UI::Slider; |
1692 | package CFClient::UI::Slider; |
1543 | |
1693 | |
1544 | use strict; |
1694 | use strict; |
1545 | |
1695 | |
1546 | use SDL::OpenGL; |
1696 | use CFClient::OpenGL; |
1547 | |
1697 | |
1548 | our @ISA = CFClient::UI::DrawBG::; |
1698 | our @ISA = CFClient::UI::DrawBG::; |
1549 | |
1699 | |
1550 | my @tex = |
1700 | my @tex = |
1551 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1701 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1561 | # TODO: calculations are off |
1711 | # TODO: calculations are off |
1562 | my $self = $class->SUPER::new ( |
1712 | my $self = $class->SUPER::new ( |
1563 | fg => [1, 1, 1], |
1713 | fg => [1, 1, 1], |
1564 | active_fg => [0, 0, 0], |
1714 | active_fg => [0, 0, 0], |
1565 | range => [0, 0, 100, 10], |
1715 | range => [0, 0, 100, 10], |
1566 | req_w => 40, |
1716 | req_w => 20, |
1567 | req_h => 13, |
1717 | req_h => 20, |
1568 | vertical => 0, |
1718 | vertical => 0, |
1569 | can_hover => 1, |
1719 | can_hover => 1, |
1570 | inner_pad => 5, |
1720 | inner_pad => 5, |
1571 | @_ |
1721 | @_ |
1572 | ); |
1722 | ); |
… | |
… | |
1676 | |
1826 | |
1677 | package CFClient::UI::TextView; |
1827 | package CFClient::UI::TextView; |
1678 | |
1828 | |
1679 | our @ISA = CFClient::UI::HBox::; |
1829 | our @ISA = CFClient::UI::HBox::; |
1680 | |
1830 | |
1681 | use SDL::OpenGL; |
1831 | use CFClient::OpenGL; |
1682 | |
1832 | |
1683 | sub new { |
1833 | sub new { |
1684 | my $class = shift; |
1834 | my $class = shift; |
1685 | |
1835 | |
1686 | my $self = $class->SUPER::new ( |
1836 | my $self = $class->SUPER::new ( |
1687 | req_w => $::WIDTH / 6, |
|
|
1688 | req_h => $::HEIGHT / 6, |
|
|
1689 | fontsize => $::FONTSIZE, |
1837 | fontsize => 1, |
1690 | @_, |
1838 | @_, |
1691 | |
1839 | |
1692 | layout => (new CFClient::Layout), |
1840 | layout => (new CFClient::Layout), |
1693 | par => [], |
1841 | par => [], |
1694 | height => 0, |
1842 | height => 0, |
… | |
… | |
1715 | sub text_height { |
1863 | sub text_height { |
1716 | my ($self, $text) = @_; |
1864 | my ($self, $text) = @_; |
1717 | |
1865 | |
1718 | my $layout = $self->{layout}; |
1866 | my $layout = $self->{layout}; |
1719 | |
1867 | |
1720 | $layout->set_height ($self->{fontsize}); |
1868 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
1721 | $layout->set_width ($self->{w}); |
1869 | $layout->set_width ($self->{w}); |
1722 | $layout->set_text ($text); |
1870 | $layout->set_text ($text); |
1723 | |
1871 | |
1724 | ($layout->size)[1] |
1872 | ($layout->size)[1] |
1725 | } |
1873 | } |
… | |
… | |
1729 | |
1877 | |
1730 | $self->{need_reflow}++; |
1878 | $self->{need_reflow}++; |
1731 | $self->update; |
1879 | $self->update; |
1732 | } |
1880 | } |
1733 | |
1881 | |
1734 | sub size_request { |
|
|
1735 | my ($self) = @_; |
|
|
1736 | |
|
|
1737 | ($self->{req_w}, $self->{req_h}) |
|
|
1738 | } |
|
|
1739 | |
|
|
1740 | sub size_allocate { |
1882 | sub size_allocate { |
1741 | my ($self, $x, $y, $w, $h) = @_; |
1883 | my ($self, $w, $h) = @_; |
1742 | |
1884 | |
1743 | $self->SUPER::size_allocate ($x, $y, $w, $h) or return; |
1885 | $self->SUPER::size_allocate ($w, $h); |
1744 | |
1886 | |
1745 | $self->{layout}->set_height ($self->{fontsize}); |
1887 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1746 | $self->{layout}->set_width ($self->{w}); |
1888 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1747 | |
1889 | |
1748 | $self->reflow; |
1890 | $self->reflow; |
1749 | $self->update; |
|
|
1750 | } |
1891 | } |
1751 | |
1892 | |
1752 | sub add_paragraph { |
1893 | sub add_paragraph { |
1753 | my ($self, $color, $text) = @_; |
1894 | my ($self, $color, $text) = @_; |
1754 | |
1895 | |
… | |
… | |
1839 | |
1980 | |
1840 | } |
1981 | } |
1841 | |
1982 | |
1842 | ############################################################################# |
1983 | ############################################################################# |
1843 | |
1984 | |
1844 | package CFClient::UI::MapWidget; |
|
|
1845 | |
|
|
1846 | use strict; |
|
|
1847 | |
|
|
1848 | use List::Util qw(min max); |
|
|
1849 | |
|
|
1850 | use SDL; |
|
|
1851 | use SDL::OpenGL; |
|
|
1852 | |
|
|
1853 | our @ISA = CFClient::UI::Base::; |
|
|
1854 | |
|
|
1855 | sub new { |
|
|
1856 | my $class = shift; |
|
|
1857 | |
|
|
1858 | $class->SUPER::new ( |
|
|
1859 | z => -1, |
|
|
1860 | can_focus => 1, |
|
|
1861 | list => (glGenLists 1), |
|
|
1862 | @_ |
|
|
1863 | ) |
|
|
1864 | } |
|
|
1865 | |
|
|
1866 | sub key_down { |
|
|
1867 | print "MAPKEYDOWN\n"; |
|
|
1868 | } |
|
|
1869 | |
|
|
1870 | sub key_up { |
|
|
1871 | } |
|
|
1872 | |
|
|
1873 | sub button_down { |
|
|
1874 | my ($self, $ev, $x, $y) = @_; |
|
|
1875 | |
|
|
1876 | $self->focus_in; |
|
|
1877 | |
|
|
1878 | if ($ev->button == 2) { |
|
|
1879 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
1880 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
|
|
1881 | |
|
|
1882 | $self->{motion} = sub { |
|
|
1883 | my ($ev, $x, $y) = @_; |
|
|
1884 | |
|
|
1885 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
1886 | |
|
|
1887 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
|
|
1888 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
|
|
1889 | |
|
|
1890 | $self->update; |
|
|
1891 | }; |
|
|
1892 | } |
|
|
1893 | } |
|
|
1894 | |
|
|
1895 | sub button_up { |
|
|
1896 | my ($self, $ev, $x, $y) = @_; |
|
|
1897 | |
|
|
1898 | delete $self->{motion}; |
|
|
1899 | } |
|
|
1900 | |
|
|
1901 | sub mouse_motion { |
|
|
1902 | my ($self, $ev, $x, $y) = @_; |
|
|
1903 | |
|
|
1904 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1905 | } |
|
|
1906 | |
|
|
1907 | sub size_request { |
|
|
1908 | ( |
|
|
1909 | 1 + 32 * int $::WIDTH / 32, |
|
|
1910 | 1 + 32 * int $::HEIGHT / 32, |
|
|
1911 | ) |
|
|
1912 | } |
|
|
1913 | |
|
|
1914 | sub update { |
|
|
1915 | my ($self) = @_; |
|
|
1916 | |
|
|
1917 | $self->{need_update} = 1; |
|
|
1918 | $self->SUPER::update; |
|
|
1919 | } |
|
|
1920 | |
|
|
1921 | sub draw { |
|
|
1922 | my ($self) = @_; |
|
|
1923 | |
|
|
1924 | if (delete $self->{need_update}) { |
|
|
1925 | glNewList $self->{list}, GL_COMPILE; |
|
|
1926 | |
|
|
1927 | if ($::MAP) { |
|
|
1928 | my $sw = int $::WIDTH / 32; |
|
|
1929 | my $sh = int $::HEIGHT / 32; |
|
|
1930 | |
|
|
1931 | my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
1932 | my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
1933 | |
|
|
1934 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
|
|
1935 | |
|
|
1936 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
|
|
1937 | |
|
|
1938 | if ($::CFG->{fow_enable}) { |
|
|
1939 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1940 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
|
|
1941 | glConvolutionFilter2D |
|
|
1942 | GL_CONVOLUTION_2D, |
|
|
1943 | GL_ALPHA, |
|
|
1944 | 3, 3, |
|
|
1945 | GL_ALPHA, GL_FLOAT, |
|
|
1946 | pack "f*", |
|
|
1947 | 0.1, 0.1, 0.1, |
|
|
1948 | 0.1, 0.2, 0.1, |
|
|
1949 | 0.1, 0.1, 0.1, |
|
|
1950 | ; |
|
|
1951 | glEnable GL_CONVOLUTION_2D; |
|
|
1952 | } |
|
|
1953 | |
|
|
1954 | $self->{fow_texture} = new CFClient::Texture |
|
|
1955 | w => $w, |
|
|
1956 | h => $h, |
|
|
1957 | data => $data, |
|
|
1958 | internalformat => GL_ALPHA, |
|
|
1959 | format => GL_ALPHA; |
|
|
1960 | |
|
|
1961 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
1962 | |
|
|
1963 | glEnable GL_BLEND; |
|
|
1964 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1965 | glEnable GL_TEXTURE_2D; |
|
|
1966 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1967 | |
|
|
1968 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1969 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1970 | |
|
|
1971 | glDisable GL_TEXTURE_2D; |
|
|
1972 | glDisable GL_BLEND; |
|
|
1973 | } |
|
|
1974 | |
|
|
1975 | # HACK BEGIN |
|
|
1976 | { |
|
|
1977 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
1978 | my ($w, $h) = (250, 250); |
|
|
1979 | |
|
|
1980 | glEnable GL_BLEND; |
|
|
1981 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1982 | glEnable GL_TEXTURE_2D; |
|
|
1983 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1984 | |
|
|
1985 | $self->{mapmap_texture} = |
|
|
1986 | new CFClient::Texture |
|
|
1987 | w => $w, |
|
|
1988 | h => $h, |
|
|
1989 | data => $::MAP->mapmap ($w, $h), |
|
|
1990 | type => GL_UNSIGNED_INT_8_8_8_8_REV; |
|
|
1991 | |
|
|
1992 | $self->{mapmap_texture}->draw_quad (100, 100); |
|
|
1993 | |
|
|
1994 | glDisable GL_TEXTURE_2D; |
|
|
1995 | glDisable GL_BLEND; |
|
|
1996 | } |
|
|
1997 | # HACK END |
|
|
1998 | } |
|
|
1999 | |
|
|
2000 | glEndList; |
|
|
2001 | } |
|
|
2002 | |
|
|
2003 | glPushMatrix; |
|
|
2004 | glCallList $self->{list}; |
|
|
2005 | glPopMatrix; |
|
|
2006 | |
|
|
2007 | if ($FOCUS != $self) { |
|
|
2008 | glColor 64/255, 64/255, 64/255; |
|
|
2009 | glLogicOp GL_AND; |
|
|
2010 | glEnable GL_COLOR_LOGIC_OP; |
|
|
2011 | glBegin GL_QUADS; |
|
|
2012 | glVertex 0, 0; |
|
|
2013 | glVertex 0, $::HEIGHT; |
|
|
2014 | glVertex $::WIDTH, $::HEIGHT; |
|
|
2015 | glVertex $::WIDTH, 0; |
|
|
2016 | glEnd; |
|
|
2017 | glDisable GL_COLOR_LOGIC_OP; |
|
|
2018 | } |
|
|
2019 | } |
|
|
2020 | |
|
|
2021 | my %DIR = ( |
|
|
2022 | SDLK_KP8, [1, "north"], |
|
|
2023 | SDLK_KP9, [2, "northeast"], |
|
|
2024 | SDLK_KP6, [3, "east"], |
|
|
2025 | SDLK_KP3, [4, "southeast"], |
|
|
2026 | SDLK_KP2, [5, "south"], |
|
|
2027 | SDLK_KP1, [6, "southwest"], |
|
|
2028 | SDLK_KP4, [7, "west"], |
|
|
2029 | SDLK_KP7, [8, "northwest"], |
|
|
2030 | |
|
|
2031 | SDLK_UP, [1, "north"], |
|
|
2032 | SDLK_RIGHT, [3, "east"], |
|
|
2033 | SDLK_DOWN, [5, "south"], |
|
|
2034 | SDLK_LEFT, [7, "west"], |
|
|
2035 | ); |
|
|
2036 | |
|
|
2037 | sub key_down { |
|
|
2038 | my ($self, $ev) = @_; |
|
|
2039 | |
|
|
2040 | my $mod = $ev->key_mod; |
|
|
2041 | my $sym = $ev->key_sym; |
|
|
2042 | |
|
|
2043 | if ($sym == SDLK_KP5) { |
|
|
2044 | $::CONN->user_send ("stay fire"); |
|
|
2045 | } elsif ($sym == SDLK_a) { |
|
|
2046 | $::CONN->user_send ("apply"); |
|
|
2047 | } elsif ($sym == SDLK_QUOTE) { |
|
|
2048 | $self->emit ('activate_console'); |
|
|
2049 | } elsif ($sym == SDLK_SLASH) { |
|
|
2050 | $self->emit ('activate_console' => '/'); |
|
|
2051 | } elsif (exists $DIR{$sym}) { |
|
|
2052 | if ($mod & KMOD_SHIFT) { |
|
|
2053 | $self->{shft}++; |
|
|
2054 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
2055 | } elsif ($mod & KMOD_CTRL) { |
|
|
2056 | $self->{ctrl}++; |
|
|
2057 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
|
|
2058 | } else { |
|
|
2059 | $::CONN->user_send ("$DIR{$sym}[1]"); |
|
|
2060 | } |
|
|
2061 | } |
|
|
2062 | } |
|
|
2063 | |
|
|
2064 | sub key_up { |
|
|
2065 | my ($self, $ev) = @_; |
|
|
2066 | |
|
|
2067 | my $mod = $ev->key_mod; |
|
|
2068 | my $sym = $ev->key_sym; |
|
|
2069 | |
|
|
2070 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
|
|
2071 | $::CONN->user_send ("fire_stop"); |
|
|
2072 | } |
|
|
2073 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
2074 | $::CONN->user_send ("run_stop"); |
|
|
2075 | } |
|
|
2076 | } |
|
|
2077 | |
|
|
2078 | ############################################################################# |
|
|
2079 | |
|
|
2080 | package CFClient::UI::Animator; |
1985 | package CFClient::UI::Animator; |
2081 | |
1986 | |
2082 | use SDL::OpenGL; |
1987 | use CFClient::OpenGL; |
2083 | |
1988 | |
2084 | our @ISA = CFClient::UI::Bin::; |
1989 | our @ISA = CFClient::UI::Bin::; |
2085 | |
1990 | |
2086 | sub moveto { |
1991 | sub moveto { |
2087 | my ($self, $x, $y) = @_; |
1992 | my ($self, $x, $y) = @_; |
… | |
… | |
2160 | |
2065 | |
2161 | package CFClient::UI::Root; |
2066 | package CFClient::UI::Root; |
2162 | |
2067 | |
2163 | our @ISA = CFClient::UI::Container::; |
2068 | our @ISA = CFClient::UI::Container::; |
2164 | |
2069 | |
2165 | use SDL::OpenGL; |
2070 | use CFClient::OpenGL; |
2166 | |
2071 | |
2167 | sub check_size { |
2072 | sub check_size { |
2168 | my ($self) = @_; |
2073 | my ($self) = @_; |
2169 | |
2074 | |
2170 | $self->size_allocate (0, 0, $::WITH, $::HEIGHT); |
2075 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2171 | } |
2076 | } |
2172 | |
2077 | |
2173 | sub size_request { |
2078 | sub size_request { |
2174 | ($::WIDTH, $::HEIGHT) |
2079 | ($::WIDTH, $::HEIGHT) |
2175 | } |
2080 | } |
2176 | |
2081 | |
2177 | sub size_allocate { |
2082 | sub configure { |
2178 | my ($self, $x, $y, $w, $h) = @_; |
2083 | my ($self, $x, $y, $w, $h) = @_; |
2179 | |
2084 | |
2180 | $self->_size_allocate ($x, $y, $w, $h); |
2085 | $self->SUPER::configure ($x, $y, $w, $h); |
2181 | |
2086 | |
2182 | $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) |
2087 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
2183 | for @{$self->{children}}; |
2088 | for @{$self->{children}}; |
2184 | } |
2089 | } |
2185 | |
2090 | |
2186 | sub _topleft { |
2091 | sub _topleft { |
2187 | my ($self, $x, $y) = @_; |
2092 | my ($self, $x, $y) = @_; |
… | |
… | |
2195 | $self->check_size; |
2100 | $self->check_size; |
2196 | ::refresh (); |
2101 | ::refresh (); |
2197 | } |
2102 | } |
2198 | |
2103 | |
2199 | sub add { |
2104 | sub add { |
2200 | my ($self, $widget) = @_; |
2105 | my ($self, $child) = @_; |
2201 | |
2106 | |
|
|
2107 | # integerize window positions |
|
|
2108 | $child->{x} = int $child->{x}; |
|
|
2109 | $child->{y} = int $child->{y}; |
|
|
2110 | |
2202 | $self->SUPER::add ($widget); |
2111 | $self->SUPER::add ($child); |
2203 | |
|
|
2204 | $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request); |
|
|
2205 | } |
2112 | } |
2206 | |
2113 | |
2207 | sub on_refresh { |
2114 | sub on_refresh { |
2208 | my ($self, $id, $cb) = @_; |
2115 | my ($self, $id, $cb) = @_; |
2209 | |
2116 | |