… | |
… | |
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) = @_; |
… | |
… | |
260 | my ($self, $parent) = @_; |
291 | my ($self, $parent) = @_; |
261 | |
292 | |
262 | Scalar::Util::weaken ($self->{parent} = $parent); |
293 | Scalar::Util::weaken ($self->{parent} = $parent); |
263 | } |
294 | } |
264 | |
295 | |
|
|
296 | sub check_size { |
|
|
297 | my ($self) = @_; |
|
|
298 | |
|
|
299 | my ($w, $h) = $self->size_request; |
|
|
300 | |
|
|
301 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
|
|
302 | $self->{req_w} = $w; |
|
|
303 | $self->{req_h} = $h; |
|
|
304 | |
|
|
305 | $self->{parent}->check_size |
|
|
306 | if $self->{parent}; |
|
|
307 | } |
|
|
308 | } |
|
|
309 | |
265 | sub update { |
310 | sub update { |
266 | my ($self) = @_; |
311 | my ($self) = @_; |
267 | |
312 | |
268 | $self->{parent}->update |
313 | $self->{parent}->update |
269 | if $self->{parent}; |
314 | if $self->{parent}; |
270 | } |
315 | } |
271 | |
316 | |
272 | sub connect { |
317 | sub connect { |
273 | my ($self, $signal, $cb) = @_; |
318 | my ($self, $signal, $cb) = @_; |
274 | |
319 | |
275 | push @{ $self->{cb}{$signal} }, $cb; |
320 | push @{ $self->{signal_cb}{$signal} }, $cb; |
276 | } |
321 | } |
277 | |
322 | |
278 | sub emit { |
323 | sub emit { |
279 | my ($self, $signal, @args) = @_; |
324 | my ($self, $signal, @args) = @_; |
280 | |
325 | |
|
|
326 | for my $cb (@{$self->{signal_cb}{$signal} || []}) { |
281 | $_->($self, @args) |
327 | $cb->($self, @args); |
282 | for @{$self->{cb}{$signal} || []}; |
328 | } |
283 | } |
329 | } |
284 | |
330 | |
285 | sub DESTROY { |
331 | sub DESTROY { |
286 | my ($self) = @_; |
332 | my ($self) = @_; |
287 | |
333 | |
… | |
… | |
293 | package CFClient::UI::DrawBG; |
339 | package CFClient::UI::DrawBG; |
294 | |
340 | |
295 | our @ISA = CFClient::UI::Base::; |
341 | our @ISA = CFClient::UI::Base::; |
296 | |
342 | |
297 | use strict; |
343 | use strict; |
298 | use SDL::OpenGL; |
344 | use CFClient::OpenGL; |
299 | |
345 | |
300 | sub new { |
346 | sub new { |
301 | my $class = shift; |
347 | my $class = shift; |
302 | |
348 | |
303 | # range [value, low, high, page] |
349 | # range [value, low, high, page] |
… | |
… | |
367 | $self->{children} = [ |
413 | $self->{children} = [ |
368 | sort { $a->{z} <=> $b->{z} } |
414 | sort { $a->{z} <=> $b->{z} } |
369 | @{$self->{children}}, $child |
415 | @{$self->{children}}, $child |
370 | ]; |
416 | ]; |
371 | |
417 | |
372 | $self->{w} = $self->{h} = -1; |
418 | $child->check_size; |
373 | $self->update; |
|
|
374 | } |
419 | } |
375 | |
420 | |
376 | sub remove { |
421 | sub remove { |
377 | my ($self, $widget) = @_; |
422 | my ($self, $child) = @_; |
378 | |
423 | |
|
|
424 | delete $child->{parent}; |
|
|
425 | |
379 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
426 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
380 | |
427 | |
381 | $self->size_allocate (0, 0, $self->{w}, $self->{h}); |
428 | $self->check_size; |
382 | } |
429 | } |
383 | |
430 | |
384 | sub find_widget { |
431 | sub find_widget { |
385 | my ($self, $x, $y) = @_; |
432 | my ($self, $x, $y) = @_; |
386 | |
433 | |
… | |
… | |
416 | |
463 | |
417 | $class->SUPER::new (children => [$child], %arg) |
464 | $class->SUPER::new (children => [$child], %arg) |
418 | } |
465 | } |
419 | |
466 | |
420 | sub add { |
467 | sub add { |
421 | my ($self, $widget) = @_; |
468 | my ($self, $child) = @_; |
422 | |
469 | |
423 | $self->{children} = []; |
470 | $self->{children} = []; |
424 | |
471 | |
425 | $self->SUPER::add ($widget); |
472 | $self->SUPER::add ($child); |
426 | } |
473 | } |
427 | |
474 | |
428 | sub remove { |
475 | sub remove { |
429 | my ($self, $widget) = @_; |
476 | my ($self, $widget) = @_; |
430 | |
477 | |
… | |
… | |
439 | sub size_request { |
486 | sub size_request { |
440 | $_[0]{children}[0]->size_request |
487 | $_[0]{children}[0]->size_request |
441 | } |
488 | } |
442 | |
489 | |
443 | sub size_allocate { |
490 | sub size_allocate { |
444 | my ($self, $x, $y, $w, $h) = @_; |
491 | my ($self, $w, $h) = @_; |
445 | |
492 | |
446 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
447 | |
|
|
448 | $self->{children}[0]->size_allocate (0, 0, $w, $h); |
493 | $self->{children}[0]->configure (0, 0, $w, $h); |
449 | } |
494 | } |
450 | |
495 | |
451 | ############################################################################# |
496 | ############################################################################# |
452 | |
497 | |
453 | package CFClient::UI::Window; |
498 | package CFClient::UI::Window; |
454 | |
499 | |
455 | our @ISA = CFClient::UI::Bin::; |
500 | our @ISA = CFClient::UI::Bin::; |
456 | |
501 | |
457 | use SDL::OpenGL; |
502 | use CFClient::OpenGL; |
458 | |
503 | |
459 | sub new { |
504 | sub new { |
460 | my ($class, %arg) = @_; |
505 | my ($class, %arg) = @_; |
461 | |
506 | |
462 | my $self = $class->SUPER::new (%arg); |
507 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
479 | $self->child->draw; |
524 | $self->child->draw; |
480 | }; |
525 | }; |
481 | } |
526 | } |
482 | |
527 | |
483 | sub size_allocate { |
528 | sub size_allocate { |
484 | my ($self, $x, $y, $w, $h) = @_; |
529 | my ($self, $w, $h) = @_; |
485 | |
530 | |
486 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
487 | |
|
|
488 | $self->child->size_allocate (0, 0, $w, $h); |
531 | $self->child->configure (0, 0, $w, $h); |
489 | |
532 | |
490 | $self->render_chld; |
533 | $self->render_chld; |
491 | } |
534 | } |
492 | |
535 | |
493 | sub _draw { |
536 | sub _draw { |
… | |
… | |
509 | glDisable GL_TEXTURE_2D; |
552 | glDisable GL_TEXTURE_2D; |
510 | } |
553 | } |
511 | |
554 | |
512 | ############################################################################# |
555 | ############################################################################# |
513 | |
556 | |
|
|
557 | package CFClient::UI::ViewPort; |
|
|
558 | |
|
|
559 | our @ISA = CFClient::UI::Window::; |
|
|
560 | |
|
|
561 | sub new { die } |
|
|
562 | |
|
|
563 | sub size_request { |
|
|
564 | my ($self) = @_; |
|
|
565 | |
|
|
566 | @$self{qw(child_w child_h)} = $self->child->size_request; |
|
|
567 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
|
|
568 | |
|
|
569 | @$self{qw(child_w child_h)} |
|
|
570 | } |
|
|
571 | |
|
|
572 | sub _draw { |
|
|
573 | my ($self) = @_; |
|
|
574 | |
|
|
575 | $self->{children}[1]->draw; |
|
|
576 | } |
|
|
577 | |
|
|
578 | |
|
|
579 | ############################################################################# |
|
|
580 | |
514 | package CFClient::UI::Frame; |
581 | package CFClient::UI::Frame; |
515 | |
582 | |
516 | our @ISA = CFClient::UI::Bin::; |
583 | our @ISA = CFClient::UI::Bin::; |
517 | |
584 | |
518 | use SDL::OpenGL; |
585 | use CFClient::OpenGL; |
519 | |
586 | |
520 | sub size_request { |
587 | sub size_request { |
521 | my ($self) = @_; |
588 | my ($self) = @_; |
522 | my $chld = $self->child |
589 | my $chld = $self->child |
523 | or return (0, 0); |
590 | or return (0, 0); |
… | |
… | |
528 | } |
595 | } |
529 | |
596 | |
530 | sub size_allocate { |
597 | sub size_allocate { |
531 | my ($self, $x, $y, $w, $h) = @_; |
598 | my ($self, $x, $y, $w, $h) = @_; |
532 | |
599 | |
533 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
534 | |
|
|
535 | $self->child->size_allocate (2, 2, $w - 4, $h - 4); |
600 | $self->child->configure (2, 2, $w - 4, $h - 4); |
536 | } |
601 | } |
537 | |
602 | |
538 | sub _draw { |
603 | sub _draw { |
539 | my ($self) = @_; |
604 | my ($self) = @_; |
540 | |
605 | |
… | |
… | |
557 | |
622 | |
558 | package CFClient::UI::FancyFrame; |
623 | package CFClient::UI::FancyFrame; |
559 | |
624 | |
560 | our @ISA = CFClient::UI::Bin::; |
625 | our @ISA = CFClient::UI::Bin::; |
561 | |
626 | |
562 | use SDL::OpenGL; |
627 | use CFClient::OpenGL; |
563 | |
628 | |
564 | my @tex = |
629 | my @tex = |
565 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
630 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
566 | 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); |
567 | |
632 | |
568 | sub new { |
633 | sub new { |
569 | my $class = shift; |
634 | my $class = shift; |
570 | |
635 | |
571 | # TODO: user_x, user_y, overwrite moveto? |
636 | # TODO: user_x, user_y, overwrite moveto? |
572 | |
637 | |
573 | $class->SUPER::new ( |
638 | my $self = $class->SUPER::new ( |
574 | bg => [1, 1, 1, 1], |
639 | bg => [1, 1, 1, 1], |
575 | border_bg => [1, 1, 1, 1], |
640 | border_bg => [1, 1, 1, 1], |
576 | border => int $::FONTSIZE * 0.8, |
641 | border => 0.8, |
577 | @_ |
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, |
578 | ) |
668 | ) |
579 | } |
669 | } |
580 | |
670 | |
581 | sub size_request { |
|
|
582 | my ($self) = @_; |
|
|
583 | |
|
|
584 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
|
|
585 | |
|
|
586 | my ($w, $h) = $self->SUPER::size_request; |
|
|
587 | |
|
|
588 | ( |
|
|
589 | $w + $self->{border} * 2, |
|
|
590 | $h + $self->{border} * 2, |
|
|
591 | ) |
|
|
592 | } |
|
|
593 | |
|
|
594 | sub size_allocate { |
671 | sub size_allocate { |
595 | my ($self, $x, $y, $w, $h) = @_; |
672 | my ($self, $w, $h) = @_; |
596 | |
673 | |
597 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
598 | |
|
|
599 | $h -= List::Util::max 0, $self->{border} * 2; |
674 | $h -= List::Util::max 0, $self->border * 2; |
600 | $w -= List::Util::max 0, $self->{border} * 2; |
675 | $w -= List::Util::max 0, $self->border * 2; |
601 | |
676 | |
|
|
677 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
|
|
678 | if $self->{title}; |
|
|
679 | |
602 | $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); |
680 | $self->child->configure ($self->border, $self->border, $w, $h); |
603 | } |
681 | } |
604 | |
682 | |
605 | sub button_down { |
683 | sub button_down { |
606 | my ($self, $ev, $x, $y) = @_; |
684 | my ($self, $ev, $x, $y) = @_; |
607 | |
685 | |
|
|
686 | my $border = $self->border; |
|
|
687 | |
608 | if ($x < $self->{w} && $x >= $self->{w} - $self->{border} |
688 | if ($x < $self->{w} && $x >= $self->{w} - $border |
609 | && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { |
689 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
610 | |
690 | |
611 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
691 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
612 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
692 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
613 | |
693 | |
614 | $self->{motion} = sub { |
694 | $self->{motion} = sub { |
615 | my ($ev, $x, $y) = @_; |
695 | my ($ev, $x, $y) = @_; |
616 | |
696 | |
617 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
697 | ($x, $y) = ($ev->{x}, $ev->{y}); |
618 | |
698 | |
619 | $self->{user_w} = $bw + $x - $ox; |
699 | $self->{user_w} = $bw + $x - $ox; |
620 | $self->{user_h} = $bh + $y - $oy; |
700 | $self->{user_h} = $bh + $y - $oy; |
621 | $self->update; |
701 | $self->check_size; |
622 | }; |
702 | }; |
623 | |
703 | |
624 | } elsif ($x >= 0 && $x < $self->{w} |
704 | } elsif ($x >= 0 && $x < $self->{w} |
625 | && $y >= 0 && $y < $self->{border}) { |
705 | && $y >= 0 && $y < $border) { |
626 | |
706 | |
627 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
707 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
628 | my ($bx, $by) = ($self->{x}, $self->{y}); |
708 | my ($bx, $by) = ($self->{x}, $self->{y}); |
629 | |
709 | |
630 | $self->{motion} = sub { |
710 | $self->{motion} = sub { |
631 | my ($ev, $x, $y) = @_; |
711 | my ($ev, $x, $y) = @_; |
632 | |
712 | |
633 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
713 | ($x, $y) = ($ev->{x}, $ev->{y}); |
634 | |
714 | |
635 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
715 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
636 | $self->update; |
716 | $self->update; |
637 | }; |
717 | }; |
638 | } |
718 | } |
… | |
… | |
659 | glEnable GL_BLEND; |
739 | glEnable GL_BLEND; |
660 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
740 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
661 | glEnable GL_TEXTURE_2D; |
741 | glEnable GL_TEXTURE_2D; |
662 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
742 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
663 | |
743 | |
|
|
744 | my $border = $self->border; |
|
|
745 | |
664 | glColor @{ $self->{border_bg} }; |
746 | glColor @{ $self->{border_bg} }; |
665 | $tex[1]->draw_quad (0, 0, $w, $self->{border}); |
747 | $tex[1]->draw_quad (0, 0, $w, $border); |
666 | $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); |
748 | $tex[3]->draw_quad (0, $border, $border, $ch); |
667 | $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); |
749 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
668 | $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); |
750 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
669 | |
751 | |
670 | my $bg = $tex[0]; |
752 | my $bg = $tex[0]; |
671 | |
753 | |
672 | # TODO: repeat texture not scale |
754 | # TODO: repeat texture not scale |
673 | my $rep_x = $cw / $bg->{w}; |
755 | my $rep_x = $cw / $bg->{w}; |
… | |
… | |
676 | glColor @{ $self->{bg} }; |
758 | glColor @{ $self->{bg} }; |
677 | |
759 | |
678 | $bg->{s} = $rep_x; |
760 | $bg->{s} = $rep_x; |
679 | $bg->{t} = $rep_y; |
761 | $bg->{t} = $rep_y; |
680 | $bg->{wrap_mode} = 1; |
762 | $bg->{wrap_mode} = 1; |
681 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
763 | $bg->draw_quad ($border, $border, $cw, $ch); |
682 | |
764 | |
683 | glDisable GL_TEXTURE_2D; |
765 | glDisable GL_TEXTURE_2D; |
684 | glDisable GL_BLEND; |
766 | glDisable GL_BLEND; |
685 | |
767 | |
|
|
768 | $self->{title}->draw if $self->{title}; |
686 | $self->child->draw; |
769 | $self->child->draw; |
687 | } |
770 | } |
688 | |
771 | |
689 | ############################################################################# |
772 | ############################################################################# |
690 | |
773 | |
… | |
… | |
692 | |
775 | |
693 | our @ISA = CFClient::UI::Base::; |
776 | our @ISA = CFClient::UI::Base::; |
694 | |
777 | |
695 | use List::Util qw(max sum); |
778 | use List::Util qw(max sum); |
696 | |
779 | |
697 | use SDL::OpenGL; |
780 | use CFClient::OpenGL; |
698 | |
781 | |
699 | sub new { |
782 | sub new { |
700 | my $class = shift; |
783 | my $class = shift; |
701 | |
784 | |
702 | $class->SUPER::new ( |
785 | $class->SUPER::new ( |
… | |
… | |
709 | my ($self, $x, $y, $child) = @_; |
792 | my ($self, $x, $y, $child) = @_; |
710 | |
793 | |
711 | $child->set_parent ($self); |
794 | $child->set_parent ($self); |
712 | $self->{children}[$y][$x] = $child; |
795 | $self->{children}[$y][$x] = $child; |
713 | |
796 | |
714 | $self->{w} = $self->{h} = -1; |
797 | $child->check_size; |
715 | $self->update; |
|
|
716 | } |
798 | } |
717 | |
799 | |
718 | # 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? |
719 | sub clear { |
801 | sub clear { |
720 | my ($self) = @_; |
802 | my ($self) = @_; |
… | |
… | |
755 | (sum @$hs), |
837 | (sum @$hs), |
756 | ) |
838 | ) |
757 | } |
839 | } |
758 | |
840 | |
759 | sub size_allocate { |
841 | sub size_allocate { |
760 | my ($self, $x, $y, $w, $h) = @_; |
842 | my ($self, $w, $h) = @_; |
761 | |
|
|
762 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
763 | |
843 | |
764 | my ($ws, $hs) = $self->get_wh; |
844 | my ($ws, $hs) = $self->get_wh; |
765 | |
845 | |
766 | my $req_w = sum @$ws; |
846 | my $req_w = sum @$ws; |
767 | my $req_h = sum @$hs; |
847 | my $req_h = sum @$hs; |
… | |
… | |
789 | |
869 | |
790 | for my $c (0 .. $#$row) { |
870 | for my $c (0 .. $#$row) { |
791 | my $col_w = $ws->[$c]; |
871 | my $col_w = $ws->[$c]; |
792 | |
872 | |
793 | if (my $widget = $row->[$c]) { |
873 | if (my $widget = $row->[$c]) { |
794 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
874 | $widget->configure ($x, $y, $col_w, $row_h); |
795 | } |
875 | } |
796 | |
876 | |
797 | $x += $col_w; |
877 | $x += $col_w; |
798 | } |
878 | } |
799 | |
879 | |
… | |
… | |
844 | (List::Util::max map $_->[1], @alloc), |
924 | (List::Util::max map $_->[1], @alloc), |
845 | ) |
925 | ) |
846 | } |
926 | } |
847 | |
927 | |
848 | sub size_allocate { |
928 | sub size_allocate { |
849 | my ($self, $x, $y, $w, $h) = @_; |
929 | my ($self, $w, $h) = @_; |
850 | |
|
|
851 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
852 | |
930 | |
853 | ($h, $w) = ($w, $h); |
931 | ($h, $w) = ($w, $h); |
854 | |
932 | |
855 | my $children = $self->{children}; |
933 | my $children = $self->{children}; |
856 | |
934 | |
… | |
… | |
878 | |
956 | |
879 | my $y = 0; |
957 | my $y = 0; |
880 | for (0 .. $#$children) { |
958 | for (0 .. $#$children) { |
881 | my $child = $children->[$_]; |
959 | my $child = $children->[$_]; |
882 | my $h = $h[$_]; |
960 | my $h = $h[$_]; |
883 | $child->size_allocate ($y, 0, $h, $w); |
961 | $child->configure ($y, 0, $h, $w); |
884 | |
962 | |
885 | $y += $h; |
963 | $y += $h; |
886 | } |
964 | } |
|
|
965 | |
|
|
966 | 1 |
887 | } |
967 | } |
888 | |
968 | |
889 | ############################################################################# |
969 | ############################################################################# |
890 | |
970 | |
891 | package CFClient::UI::VBox; |
971 | package CFClient::UI::VBox; |
… | |
… | |
904 | (List::Util::sum map $_->[1], @alloc), |
984 | (List::Util::sum map $_->[1], @alloc), |
905 | ) |
985 | ) |
906 | } |
986 | } |
907 | |
987 | |
908 | sub size_allocate { |
988 | sub size_allocate { |
909 | my ($self, $x, $y, $w, $h) = @_; |
989 | my ($self, $w, $h) = @_; |
910 | |
|
|
911 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
912 | |
990 | |
913 | my $children = $self->{children}; |
991 | my $children = $self->{children}; |
914 | |
992 | |
915 | my @h = map +($_->size_request)[1], @$children; |
993 | my @h = map +($_->size_request)[1], @$children; |
916 | |
994 | |
… | |
… | |
934 | |
1012 | |
935 | my $y = 0; |
1013 | my $y = 0; |
936 | for (0 .. $#$children) { |
1014 | for (0 .. $#$children) { |
937 | my $child = $children->[$_]; |
1015 | my $child = $children->[$_]; |
938 | my $h = $h[$_]; |
1016 | my $h = $h[$_]; |
939 | $child->size_allocate (0, $y, $w, $h); |
1017 | $child->configure (0, $y, $w, $h); |
940 | |
1018 | |
941 | $y += $h; |
1019 | $y += $h; |
942 | } |
1020 | } |
|
|
1021 | |
|
|
1022 | 1 |
943 | } |
1023 | } |
944 | |
1024 | |
945 | ############################################################################# |
1025 | ############################################################################# |
946 | |
1026 | |
947 | package CFClient::UI::Label; |
1027 | package CFClient::UI::Label; |
948 | |
1028 | |
949 | our @ISA = CFClient::UI::Base::; |
1029 | our @ISA = CFClient::UI::Base::; |
950 | |
1030 | |
951 | use SDL::OpenGL; |
1031 | use CFClient::OpenGL; |
952 | |
1032 | |
953 | sub new { |
1033 | sub new { |
954 | my ($class, %arg) = @_; |
1034 | my ($class, %arg) = @_; |
955 | |
1035 | |
956 | my $self = $class->SUPER::new ( |
1036 | my $self = $class->SUPER::new ( |
957 | fg => [1, 1, 1], |
1037 | fg => [1, 1, 1], |
958 | fontsize => $::FONTSIZE, |
1038 | fontsize => 1, |
959 | text => "", |
1039 | text => "", |
960 | align => -1, |
1040 | align => -1, |
961 | valign => -1, |
1041 | valign => -1, |
962 | padding => 2, |
1042 | padding => 2, |
963 | layout => new CFClient::Layout, |
1043 | layout => new CFClient::Layout, |
964 | %arg |
1044 | %arg |
965 | ); |
1045 | ); |
966 | |
1046 | |
967 | $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 | } |
968 | |
1052 | |
969 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1053 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
970 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1054 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
971 | |
1055 | |
972 | $self |
1056 | $self |
… | |
… | |
1002 | |
1086 | |
1003 | sub size_request { |
1087 | sub size_request { |
1004 | my ($self) = @_; |
1088 | my ($self) = @_; |
1005 | |
1089 | |
1006 | $self->{layout}->set_width; |
1090 | $self->{layout}->set_width; |
1007 | $self->{layout}->set_height ($self->{fontsize}); |
1091 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1008 | |
1092 | |
1009 | 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 | } |
1010 | |
1103 | |
1011 | ( |
1104 | ( |
1012 | $w + $self->{padding} * 2, |
1105 | $w + $self->{padding} * 2, |
1013 | $h + $self->{padding} * 2, |
1106 | $h + $self->{padding} * 2, |
1014 | ) |
1107 | ) |
1015 | } |
1108 | } |
1016 | |
1109 | |
1017 | sub size_allocate { |
1110 | sub size_allocate { |
1018 | my ($self, $x, $y, $w, $h) = @_; |
1111 | my ($self, $w, $h) = @_; |
1019 | |
|
|
1020 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
1021 | |
1112 | |
1022 | delete $self->{texture}; |
1113 | delete $self->{texture}; |
1023 | } |
1114 | } |
1024 | |
1115 | |
1025 | sub update { |
1116 | sub set_fontsize { |
1026 | my ($self) = @_; |
1117 | my ($self, $fontsize) = @_; |
1027 | |
1118 | |
1028 | delete $self->{texture}; |
1119 | $self->{fontsize} = $fontsize; |
1029 | $self->SUPER::update; |
1120 | $self->check_size; |
1030 | } |
1121 | } |
1031 | |
1122 | |
1032 | sub _draw { |
1123 | sub _draw { |
1033 | my ($self) = @_; |
1124 | my ($self) = @_; |
1034 | |
1125 | |
1035 | my $tex = $self->{texture} ||= do { |
1126 | my $tex = $self->{texture} ||= do { |
1036 | $self->{layout}->set_width ($self->{w}); |
1127 | $self->{layout}->set_width ($self->{w}); |
1037 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); |
1128 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1038 | new_from_layout CFClient::Texture $self->{layout} |
1129 | new_from_layout CFClient::Texture $self->{layout} |
1039 | }; |
1130 | }; |
1040 | |
1131 | |
1041 | glEnable GL_BLEND; |
1132 | glEnable GL_BLEND; |
1042 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1133 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
… | |
… | |
1067 | |
1158 | |
1068 | package CFClient::UI::EntryBase; |
1159 | package CFClient::UI::EntryBase; |
1069 | |
1160 | |
1070 | our @ISA = CFClient::UI::Label::; |
1161 | our @ISA = CFClient::UI::Label::; |
1071 | |
1162 | |
1072 | use SDL; |
1163 | use CFClient::OpenGL; |
1073 | use SDL::OpenGL; |
|
|
1074 | |
1164 | |
1075 | sub new { |
1165 | sub new { |
1076 | my $class = shift; |
1166 | my $class = shift; |
1077 | |
1167 | |
1078 | $class->SUPER::new ( |
1168 | $class->SUPER::new ( |
… | |
… | |
1092 | |
1182 | |
1093 | delete $self->{cur_h}; |
1183 | delete $self->{cur_h}; |
1094 | |
1184 | |
1095 | return if $self->{text} eq $text; |
1185 | return if $self->{text} eq $text; |
1096 | |
1186 | |
|
|
1187 | delete $self->{texture}; |
|
|
1188 | |
1097 | $self->{last_activity} = $::NOW; |
1189 | $self->{last_activity} = $::NOW; |
1098 | $self->{text} = $text; |
1190 | $self->{text} = $text; |
1099 | |
1191 | |
1100 | $text =~ s/./*/g if $self->{hidden}; |
1192 | $text =~ s/./*/g if $self->{hidden}; |
1101 | $self->{layout}->set_text ("$text "); |
1193 | $self->{layout}->set_text ("$text "); |
… | |
… | |
1114 | |
1206 | |
1115 | ($w + 1, $h) # add 1 for cursor |
1207 | ($w + 1, $h) # add 1 for cursor |
1116 | } |
1208 | } |
1117 | |
1209 | |
1118 | sub size_allocate { |
1210 | sub size_allocate { |
1119 | my ($self, $x, $y, $w, $h) = @_; |
1211 | my ($self, $w, $h) = @_; |
1120 | |
|
|
1121 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
|
|
1122 | |
1212 | |
1123 | $self->_set_text ($self->{text}); |
1213 | $self->_set_text ($self->{text}); |
1124 | } |
1214 | } |
1125 | |
1215 | |
1126 | sub set_text { |
1216 | sub set_text { |
… | |
… | |
1132 | } |
1222 | } |
1133 | |
1223 | |
1134 | sub key_down { |
1224 | sub key_down { |
1135 | my ($self, $ev) = @_; |
1225 | my ($self, $ev) = @_; |
1136 | |
1226 | |
1137 | my $mod = $ev->key_mod; |
1227 | my $mod = $ev->{mod}; |
1138 | my $sym = $ev->key_sym; |
1228 | my $sym = $ev->{sym}; |
1139 | |
|
|
1140 | my $uni = $ev->key_unicode; |
1229 | my $uni = $ev->{unicode}; |
1141 | |
1230 | |
1142 | my $text = $self->get_text; |
1231 | my $text = $self->get_text; |
1143 | |
1232 | |
1144 | if ($sym == SDLK_BACKSPACE) { |
1233 | if ($sym == 8) { |
1145 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1234 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1146 | } elsif ($sym == SDLK_DELETE) { |
1235 | } elsif ($sym == 127) { |
1147 | substr $text, $self->{cursor}, 1, ""; |
1236 | substr $text, $self->{cursor}, 1, ""; |
1148 | } elsif ($sym == SDLK_LEFT) { |
1237 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1149 | --$self->{cursor} if $self->{cursor}; |
1238 | --$self->{cursor} if $self->{cursor}; |
1150 | } elsif ($sym == SDLK_RIGHT) { |
1239 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1151 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1240 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1152 | } elsif ($sym == SDLK_HOME) { |
1241 | } elsif ($sym == CFClient::SDLK_HOME) { |
1153 | $self->{cursor} = 0; |
1242 | $self->{cursor} = 0; |
1154 | } elsif ($sym == SDLK_END) { |
1243 | } elsif ($sym == CFClient::SDLK_END) { |
1155 | $self->{cursor} = length $text; |
1244 | $self->{cursor} = length $text; |
1156 | } elsif ($sym == SDLK_ESCAPE) { |
1245 | } elsif ($sym == 27) { |
1157 | $self->emit ('escape'); |
1246 | $self->emit ('escape'); |
1158 | } elsif ($uni) { |
1247 | } elsif ($uni) { |
1159 | substr $text, $self->{cursor}++, 0, chr $uni; |
1248 | substr $text, $self->{cursor}++, 0, chr $uni; |
1160 | } |
1249 | } |
1161 | |
1250 | |
… | |
… | |
1236 | |
1325 | |
1237 | package CFClient::UI::Entry; |
1326 | package CFClient::UI::Entry; |
1238 | |
1327 | |
1239 | our @ISA = CFClient::UI::EntryBase::; |
1328 | our @ISA = CFClient::UI::EntryBase::; |
1240 | |
1329 | |
1241 | use SDL; |
1330 | use CFClient::OpenGL; |
1242 | use SDL::OpenGL; |
|
|
1243 | |
1331 | |
1244 | sub key_down { |
1332 | sub key_down { |
1245 | my ($self, $ev) = @_; |
1333 | my ($self, $ev) = @_; |
1246 | |
1334 | |
1247 | my $sym = $ev->key_sym; |
1335 | my $sym = $ev->{sym}; |
1248 | |
1336 | |
1249 | if ($sym == SDLK_RETURN) { |
1337 | if ($sym == 13) { |
1250 | $self->emit (activate => $self->get_text); |
1338 | $self->emit (activate => $self->get_text); |
1251 | $self->update; |
1339 | $self->update; |
1252 | |
1340 | |
1253 | } else { |
1341 | } else { |
1254 | $self->SUPER::key_down ($ev); |
1342 | $self->SUPER::key_down ($ev); |
… | |
… | |
1260 | |
1348 | |
1261 | package CFClient::UI::Button; |
1349 | package CFClient::UI::Button; |
1262 | |
1350 | |
1263 | our @ISA = CFClient::UI::Label::; |
1351 | our @ISA = CFClient::UI::Label::; |
1264 | |
1352 | |
1265 | use SDL; |
1353 | use CFClient::OpenGL; |
1266 | use SDL::OpenGL; |
|
|
1267 | |
1354 | |
1268 | my @tex = |
1355 | my @tex = |
1269 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1356 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1270 | qw(b1_button_active.png); |
1357 | qw(b1_button_active.png); |
1271 | |
1358 | |
1272 | sub new { |
1359 | sub new { |
1273 | my $class = shift; |
1360 | my $class = shift; |
1274 | |
1361 | |
… | |
… | |
1276 | padding => 4, |
1363 | padding => 4, |
1277 | fg => [1, 1, 1], |
1364 | fg => [1, 1, 1], |
1278 | bg => [1, 1, 1, 0.2], |
1365 | bg => [1, 1, 1, 0.2], |
1279 | active_fg => [0, 0, 1], |
1366 | active_fg => [0, 0, 1], |
1280 | can_hover => 1, |
1367 | can_hover => 1, |
|
|
1368 | align => 0, |
|
|
1369 | valign => 0, |
1281 | @_ |
1370 | @_ |
1282 | ) |
1371 | ) |
1283 | } |
1372 | } |
1284 | |
1373 | |
1285 | sub button_up { |
1374 | sub button_up { |
… | |
… | |
1319 | package CFClient::UI::CheckBox; |
1408 | package CFClient::UI::CheckBox; |
1320 | |
1409 | |
1321 | our @ISA = CFClient::UI::DrawBG::; |
1410 | our @ISA = CFClient::UI::DrawBG::; |
1322 | |
1411 | |
1323 | my @tex = |
1412 | my @tex = |
1324 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1413 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1325 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1414 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1326 | |
1415 | |
1327 | use SDL; |
1416 | use CFClient::OpenGL; |
1328 | use SDL::OpenGL; |
|
|
1329 | |
1417 | |
1330 | sub new { |
1418 | sub new { |
1331 | my $class = shift; |
1419 | my $class = shift; |
1332 | |
1420 | |
1333 | $class->SUPER::new ( |
1421 | $class->SUPER::new ( |
… | |
… | |
1344 | my ($self) = @_; |
1432 | my ($self) = @_; |
1345 | |
1433 | |
1346 | ($self->{padding} * 2 + 6) x 2 |
1434 | ($self->{padding} * 2 + 6) x 2 |
1347 | } |
1435 | } |
1348 | |
1436 | |
1349 | sub size_allocate { |
|
|
1350 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1351 | |
|
|
1352 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
1353 | } |
|
|
1354 | |
|
|
1355 | sub button_down { |
1437 | sub button_down { |
1356 | my ($self, $ev, $x, $y) = @_; |
1438 | my ($self, $ev, $x, $y) = @_; |
1357 | |
1439 | |
1358 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1440 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1359 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1441 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
… | |
… | |
1385 | glDisable GL_BLEND; |
1467 | glDisable GL_BLEND; |
1386 | } |
1468 | } |
1387 | |
1469 | |
1388 | ############################################################################# |
1470 | ############################################################################# |
1389 | |
1471 | |
1390 | package CFClient::UI::VGauge; |
1472 | package CFClient::UI::Image; |
1391 | |
1473 | |
1392 | our @ISA = CFClient::UI::Base::; |
1474 | our @ISA = CFClient::UI::Base::; |
1393 | |
1475 | |
1394 | use SDL::OpenGL; |
1476 | use CFClient::OpenGL; |
|
|
1477 | use Carp qw/confess/; |
1395 | |
1478 | |
1396 | my %tex = ( |
1479 | our %loaded_images; |
1397 | food => [ |
|
|
1398 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1399 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1400 | ], |
|
|
1401 | grace => [ |
|
|
1402 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1403 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1404 | ], |
|
|
1405 | hp => [ |
|
|
1406 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1407 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1408 | ], |
|
|
1409 | mana => [ |
|
|
1410 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1411 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1412 | ], |
|
|
1413 | ); |
|
|
1414 | |
1480 | |
1415 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1416 | sub new { |
1481 | sub new { |
1417 | my $class = shift; |
1482 | my $class = shift; |
1418 | |
1483 | |
1419 | 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}; |
1420 | |
1496 | |
1421 | $self |
1497 | $self |
1422 | } |
1498 | } |
1423 | |
1499 | |
1424 | sub size_request { |
1500 | sub size_request { |
1425 | my ($self) = @_; |
1501 | my ($self) = @_; |
1426 | |
1502 | |
1427 | ($self->{w}, $self->{h}) |
1503 | ($self->{tex}->{w}, $self->{tex}->{h}) |
1428 | } |
|
|
1429 | |
|
|
1430 | sub set_max { |
|
|
1431 | my ($self, $max) = @_; |
|
|
1432 | $self->{max_val} = $max; |
|
|
1433 | } |
|
|
1434 | |
|
|
1435 | sub set_value { |
|
|
1436 | my ($self, $val, $max) = @_; |
|
|
1437 | |
|
|
1438 | $self->set_max ($max) |
|
|
1439 | if defined $max; |
|
|
1440 | |
|
|
1441 | $max = $self->{max_val}; |
|
|
1442 | $self->{val} = $val; |
|
|
1443 | |
|
|
1444 | $self->update; |
|
|
1445 | } |
1504 | } |
1446 | |
1505 | |
1447 | sub _draw { |
1506 | sub _draw { |
1448 | my ($self) = @_; |
1507 | my ($self) = @_; |
1449 | |
1508 | |
1450 | my $tex = $tex{$self->{gauge}}; |
1509 | my $tex = $self->{tex}; |
1451 | |
1510 | |
1452 | my ($w, $h) = ($self->{w}, $self->{h}); |
1511 | my ($w, $h) = ($self->{w}, $self->{h}); |
1453 | |
1512 | |
1454 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1513 | if ($self->{rot90}) { |
1455 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1514 | glRotate 90, 0, 0, 1; |
|
|
1515 | glTranslate 0, -$self->{w}, 0; |
1456 | |
1516 | |
1457 | my $t1 = $tex->[0]; |
1517 | ($w, $h) = ($h, $w); |
1458 | my $t2 = $tex->[1]; |
1518 | } |
1459 | |
1519 | |
1460 | glEnable GL_BLEND; |
1520 | glEnable GL_BLEND; |
1461 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1521 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1462 | glEnable GL_TEXTURE_2D; |
1522 | glEnable GL_TEXTURE_2D; |
1463 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1523 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1464 | |
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 | |
1465 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1623 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1466 | my $h2 = $ycut * $self->{h}; |
1624 | my $h2 = $ycut * $self->{h}; |
1467 | |
1625 | |
1468 | my $yp = 0; |
|
|
1469 | |
|
|
1470 | glBindTexture (GL_TEXTURE_2D, $t1->{name}); |
1626 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1471 | glBegin (GL_QUADS); |
1627 | glBegin GL_QUADS; |
1472 | glTexCoord (0, 0); glVertex (0 , $yp); |
1628 | glTexCoord 0 , 0; glVertex 0 , 0; |
1473 | glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1); |
1629 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1474 | glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1); |
1630 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1475 | glTexCoord (1, 0); glVertex (0 + $w, $yp); |
1631 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1476 | glEnd (); |
1632 | glEnd; |
1477 | |
1633 | |
1478 | $yp += $h1; |
|
|
1479 | |
|
|
1480 | glBindTexture (GL_TEXTURE_2D, $t2->{name}); |
1634 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1481 | glBegin (GL_QUADS); |
1635 | glBegin GL_QUADS; |
1482 | glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp); |
1636 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1483 | glTexCoord (0, 1); glVertex (0 , $yp + $h2); |
1637 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1484 | glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2); |
1638 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1485 | glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp); |
1639 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1486 | glEnd (); |
1640 | glEnd; |
1487 | |
1641 | |
1488 | glDisable GL_BLEND; |
1642 | glDisable GL_BLEND; |
1489 | glDisable GL_TEXTURE_2D; |
1643 | glDisable GL_TEXTURE_2D; |
1490 | } |
1644 | } |
1491 | |
1645 | |
1492 | ############################################################################# |
1646 | ############################################################################# |
1493 | |
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 | |
1494 | package CFClient::UI::Slider; |
1692 | package CFClient::UI::Slider; |
1495 | |
1693 | |
1496 | use strict; |
1694 | use strict; |
1497 | |
1695 | |
1498 | use SDL::OpenGL; |
1696 | use CFClient::OpenGL; |
1499 | |
1697 | |
1500 | our @ISA = CFClient::UI::DrawBG::; |
1698 | our @ISA = CFClient::UI::DrawBG::; |
1501 | |
1699 | |
1502 | my @tex = |
1700 | my @tex = |
1503 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1701 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1513 | # TODO: calculations are off |
1711 | # TODO: calculations are off |
1514 | my $self = $class->SUPER::new ( |
1712 | my $self = $class->SUPER::new ( |
1515 | fg => [1, 1, 1], |
1713 | fg => [1, 1, 1], |
1516 | active_fg => [0, 0, 0], |
1714 | active_fg => [0, 0, 0], |
1517 | range => [0, 0, 100, 10], |
1715 | range => [0, 0, 100, 10], |
1518 | req_w => 40, |
1716 | req_w => 20, |
1519 | req_h => 13, |
1717 | req_h => 20, |
1520 | vertical => 0, |
1718 | vertical => 0, |
1521 | can_hover => 1, |
1719 | can_hover => 1, |
1522 | inner_pad => 5, |
1720 | inner_pad => 5, |
1523 | @_ |
1721 | @_ |
1524 | ); |
1722 | ); |
… | |
… | |
1628 | |
1826 | |
1629 | package CFClient::UI::TextView; |
1827 | package CFClient::UI::TextView; |
1630 | |
1828 | |
1631 | our @ISA = CFClient::UI::HBox::; |
1829 | our @ISA = CFClient::UI::HBox::; |
1632 | |
1830 | |
1633 | use SDL::OpenGL; |
1831 | use CFClient::OpenGL; |
1634 | |
1832 | |
1635 | sub new { |
1833 | sub new { |
1636 | my $class = shift; |
1834 | my $class = shift; |
1637 | |
1835 | |
1638 | my $self = $class->SUPER::new ( |
1836 | my $self = $class->SUPER::new ( |
1639 | req_w => $::WIDTH / 6, |
|
|
1640 | req_h => $::HEIGHT / 6, |
|
|
1641 | fontsize => $::FONTSIZE, |
1837 | fontsize => 1, |
1642 | @_, |
1838 | @_, |
1643 | |
1839 | |
1644 | layout => (new CFClient::Layout), |
1840 | layout => (new CFClient::Layout), |
1645 | par => [], |
1841 | par => [], |
1646 | height => 0, |
1842 | height => 0, |
… | |
… | |
1667 | sub text_height { |
1863 | sub text_height { |
1668 | my ($self, $text) = @_; |
1864 | my ($self, $text) = @_; |
1669 | |
1865 | |
1670 | my $layout = $self->{layout}; |
1866 | my $layout = $self->{layout}; |
1671 | |
1867 | |
1672 | $layout->set_height ($self->{fontsize}); |
1868 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
1673 | $layout->set_width ($self->{w}); |
1869 | $layout->set_width ($self->{w}); |
1674 | $layout->set_text ($text); |
1870 | $layout->set_text ($text); |
1675 | |
1871 | |
1676 | ($layout->size)[1] |
1872 | ($layout->size)[1] |
1677 | } |
1873 | } |
… | |
… | |
1681 | |
1877 | |
1682 | $self->{need_reflow}++; |
1878 | $self->{need_reflow}++; |
1683 | $self->update; |
1879 | $self->update; |
1684 | } |
1880 | } |
1685 | |
1881 | |
1686 | sub size_request { |
|
|
1687 | my ($self) = @_; |
|
|
1688 | |
|
|
1689 | ($self->{req_w}, $self->{req_h}) |
|
|
1690 | } |
|
|
1691 | |
|
|
1692 | sub size_allocate { |
1882 | sub size_allocate { |
1693 | my ($self, $x, $y, $w, $h) = @_; |
1883 | my ($self, $w, $h) = @_; |
1694 | |
1884 | |
1695 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
1885 | $self->SUPER::size_allocate ($w, $h); |
1696 | |
1886 | |
1697 | $self->{layout}->set_height ($self->{fontsize}); |
1887 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1698 | $self->{layout}->set_width ($self->{w}); |
1888 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1699 | |
1889 | |
1700 | $self->reflow; |
1890 | $self->reflow; |
1701 | } |
1891 | } |
1702 | |
1892 | |
1703 | sub add_paragraph { |
1893 | sub add_paragraph { |
… | |
… | |
1790 | |
1980 | |
1791 | } |
1981 | } |
1792 | |
1982 | |
1793 | ############################################################################# |
1983 | ############################################################################# |
1794 | |
1984 | |
1795 | package CFClient::UI::MapWidget; |
|
|
1796 | |
|
|
1797 | use strict; |
|
|
1798 | |
|
|
1799 | use List::Util qw(min max); |
|
|
1800 | |
|
|
1801 | use SDL; |
|
|
1802 | use SDL::OpenGL; |
|
|
1803 | |
|
|
1804 | our @ISA = CFClient::UI::Base::; |
|
|
1805 | |
|
|
1806 | sub new { |
|
|
1807 | my $class = shift; |
|
|
1808 | |
|
|
1809 | $class->SUPER::new ( |
|
|
1810 | z => -1, |
|
|
1811 | can_focus => 1, |
|
|
1812 | list => (glGenLists 1), |
|
|
1813 | @_ |
|
|
1814 | ) |
|
|
1815 | } |
|
|
1816 | |
|
|
1817 | sub key_down { |
|
|
1818 | print "MAPKEYDOWN\n"; |
|
|
1819 | } |
|
|
1820 | |
|
|
1821 | sub key_up { |
|
|
1822 | } |
|
|
1823 | |
|
|
1824 | sub button_down { |
|
|
1825 | my ($self, $ev, $x, $y) = @_; |
|
|
1826 | |
|
|
1827 | $self->focus_in; |
|
|
1828 | |
|
|
1829 | if ($ev->button == 2) { |
|
|
1830 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
1831 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
|
|
1832 | |
|
|
1833 | $self->{motion} = sub { |
|
|
1834 | my ($ev, $x, $y) = @_; |
|
|
1835 | |
|
|
1836 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
1837 | |
|
|
1838 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
|
|
1839 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
|
|
1840 | |
|
|
1841 | $self->update; |
|
|
1842 | }; |
|
|
1843 | } |
|
|
1844 | } |
|
|
1845 | |
|
|
1846 | sub button_up { |
|
|
1847 | my ($self, $ev, $x, $y) = @_; |
|
|
1848 | |
|
|
1849 | delete $self->{motion}; |
|
|
1850 | } |
|
|
1851 | |
|
|
1852 | sub mouse_motion { |
|
|
1853 | my ($self, $ev, $x, $y) = @_; |
|
|
1854 | |
|
|
1855 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1856 | } |
|
|
1857 | |
|
|
1858 | sub size_request { |
|
|
1859 | ( |
|
|
1860 | 1 + 32 * int $::WIDTH / 32, |
|
|
1861 | 1 + 32 * int $::HEIGHT / 32, |
|
|
1862 | ) |
|
|
1863 | } |
|
|
1864 | |
|
|
1865 | sub update { |
|
|
1866 | my ($self) = @_; |
|
|
1867 | |
|
|
1868 | $self->{need_update} = 1; |
|
|
1869 | $self->SUPER::update; |
|
|
1870 | } |
|
|
1871 | |
|
|
1872 | sub draw { |
|
|
1873 | my ($self) = @_; |
|
|
1874 | |
|
|
1875 | if (delete $self->{need_update}) { |
|
|
1876 | glNewList $self->{list}, GL_COMPILE; |
|
|
1877 | |
|
|
1878 | if ($::MAP) { |
|
|
1879 | my $sw = int $::WIDTH / 32; |
|
|
1880 | my $sh = int $::HEIGHT / 32; |
|
|
1881 | |
|
|
1882 | my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
1883 | my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
1884 | |
|
|
1885 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
|
|
1886 | |
|
|
1887 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
|
|
1888 | |
|
|
1889 | if ($::CFG->{fow_enable}) { |
|
|
1890 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1891 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
|
|
1892 | glConvolutionFilter2D |
|
|
1893 | GL_CONVOLUTION_2D, |
|
|
1894 | GL_ALPHA, |
|
|
1895 | 3, 3, |
|
|
1896 | GL_ALPHA, GL_FLOAT, |
|
|
1897 | pack "f*", |
|
|
1898 | 0.1, 0.1, 0.1, |
|
|
1899 | 0.1, 0.2, 0.1, |
|
|
1900 | 0.1, 0.1, 0.1, |
|
|
1901 | ; |
|
|
1902 | glEnable GL_CONVOLUTION_2D; |
|
|
1903 | } |
|
|
1904 | |
|
|
1905 | $self->{fow_texture} = new CFClient::Texture |
|
|
1906 | w => $w, |
|
|
1907 | h => $h, |
|
|
1908 | data => $data, |
|
|
1909 | internalformat => GL_ALPHA, |
|
|
1910 | format => GL_ALPHA; |
|
|
1911 | |
|
|
1912 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
1913 | |
|
|
1914 | glEnable GL_BLEND; |
|
|
1915 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1916 | glEnable GL_TEXTURE_2D; |
|
|
1917 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1918 | |
|
|
1919 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1920 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1921 | |
|
|
1922 | glDisable GL_TEXTURE_2D; |
|
|
1923 | glDisable GL_BLEND; |
|
|
1924 | } |
|
|
1925 | |
|
|
1926 | # HACK BEGIN |
|
|
1927 | { |
|
|
1928 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
1929 | my ($w, $h) = (250, 250); |
|
|
1930 | |
|
|
1931 | glEnable GL_BLEND; |
|
|
1932 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1933 | glEnable GL_TEXTURE_2D; |
|
|
1934 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1935 | |
|
|
1936 | $self->{mapmap_texture} = |
|
|
1937 | new CFClient::Texture |
|
|
1938 | w => $w, |
|
|
1939 | h => $h, |
|
|
1940 | data => $::MAP->mapmap ($w, $h), |
|
|
1941 | type => GL_UNSIGNED_INT_8_8_8_8_REV; |
|
|
1942 | |
|
|
1943 | $self->{mapmap_texture}->draw_quad (100, 100); |
|
|
1944 | |
|
|
1945 | glDisable GL_TEXTURE_2D; |
|
|
1946 | glDisable GL_BLEND; |
|
|
1947 | } |
|
|
1948 | # HACK END |
|
|
1949 | } |
|
|
1950 | |
|
|
1951 | glEndList; |
|
|
1952 | } |
|
|
1953 | |
|
|
1954 | glPushMatrix; |
|
|
1955 | glCallList $self->{list}; |
|
|
1956 | glPopMatrix; |
|
|
1957 | |
|
|
1958 | if ($FOCUS != $self) { |
|
|
1959 | glColor 64/255, 64/255, 64/255; |
|
|
1960 | glLogicOp GL_AND; |
|
|
1961 | glEnable GL_COLOR_LOGIC_OP; |
|
|
1962 | glBegin GL_QUADS; |
|
|
1963 | glVertex 0, 0; |
|
|
1964 | glVertex 0, $::HEIGHT; |
|
|
1965 | glVertex $::WIDTH, $::HEIGHT; |
|
|
1966 | glVertex $::WIDTH, 0; |
|
|
1967 | glEnd; |
|
|
1968 | glDisable GL_COLOR_LOGIC_OP; |
|
|
1969 | } |
|
|
1970 | } |
|
|
1971 | |
|
|
1972 | my %DIR = ( |
|
|
1973 | SDLK_KP8, [1, "north"], |
|
|
1974 | SDLK_KP9, [2, "northeast"], |
|
|
1975 | SDLK_KP6, [3, "east"], |
|
|
1976 | SDLK_KP3, [4, "southeast"], |
|
|
1977 | SDLK_KP2, [5, "south"], |
|
|
1978 | SDLK_KP1, [6, "southwest"], |
|
|
1979 | SDLK_KP4, [7, "west"], |
|
|
1980 | SDLK_KP7, [8, "northwest"], |
|
|
1981 | |
|
|
1982 | SDLK_UP, [1, "north"], |
|
|
1983 | SDLK_RIGHT, [3, "east"], |
|
|
1984 | SDLK_DOWN, [5, "south"], |
|
|
1985 | SDLK_LEFT, [7, "west"], |
|
|
1986 | ); |
|
|
1987 | |
|
|
1988 | sub key_down { |
|
|
1989 | my ($self, $ev) = @_; |
|
|
1990 | |
|
|
1991 | my $mod = $ev->key_mod; |
|
|
1992 | my $sym = $ev->key_sym; |
|
|
1993 | |
|
|
1994 | if ($sym == SDLK_KP5) { |
|
|
1995 | $::CONN->user_send ("stay fire"); |
|
|
1996 | } elsif ($sym == SDLK_a) { |
|
|
1997 | $::CONN->user_send ("apply"); |
|
|
1998 | } elsif ($sym == SDLK_QUOTE) { |
|
|
1999 | $self->emit ('activate_console'); |
|
|
2000 | } elsif ($sym == SDLK_SLASH) { |
|
|
2001 | $self->emit ('activate_console' => '/'); |
|
|
2002 | } elsif (exists $DIR{$sym}) { |
|
|
2003 | if ($mod & KMOD_SHIFT) { |
|
|
2004 | $self->{shft}++; |
|
|
2005 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
2006 | } elsif ($mod & KMOD_CTRL) { |
|
|
2007 | $self->{ctrl}++; |
|
|
2008 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
|
|
2009 | } else { |
|
|
2010 | $::CONN->user_send ("$DIR{$sym}[1]"); |
|
|
2011 | } |
|
|
2012 | } |
|
|
2013 | } |
|
|
2014 | |
|
|
2015 | sub key_up { |
|
|
2016 | my ($self, $ev) = @_; |
|
|
2017 | |
|
|
2018 | my $mod = $ev->key_mod; |
|
|
2019 | my $sym = $ev->key_sym; |
|
|
2020 | |
|
|
2021 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
|
|
2022 | $::CONN->user_send ("fire_stop"); |
|
|
2023 | } |
|
|
2024 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
2025 | $::CONN->user_send ("run_stop"); |
|
|
2026 | } |
|
|
2027 | } |
|
|
2028 | |
|
|
2029 | ############################################################################# |
|
|
2030 | |
|
|
2031 | package CFClient::UI::Animator; |
1985 | package CFClient::UI::Animator; |
2032 | |
1986 | |
2033 | use SDL::OpenGL; |
1987 | use CFClient::OpenGL; |
2034 | |
1988 | |
2035 | our @ISA = CFClient::UI::Bin::; |
1989 | our @ISA = CFClient::UI::Bin::; |
2036 | |
1990 | |
2037 | sub moveto { |
1991 | sub moveto { |
2038 | my ($self, $x, $y) = @_; |
1992 | my ($self, $x, $y) = @_; |
… | |
… | |
2111 | |
2065 | |
2112 | package CFClient::UI::Root; |
2066 | package CFClient::UI::Root; |
2113 | |
2067 | |
2114 | our @ISA = CFClient::UI::Container::; |
2068 | our @ISA = CFClient::UI::Container::; |
2115 | |
2069 | |
2116 | use SDL::OpenGL; |
2070 | use CFClient::OpenGL; |
|
|
2071 | |
|
|
2072 | sub check_size { |
|
|
2073 | my ($self) = @_; |
|
|
2074 | |
|
|
2075 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
|
|
2076 | } |
2117 | |
2077 | |
2118 | sub size_request { |
2078 | sub size_request { |
2119 | ($::WIDTH, $::HEIGHT) |
2079 | ($::WIDTH, $::HEIGHT) |
2120 | } |
2080 | } |
2121 | |
2081 | |
2122 | sub size_allocate { |
2082 | sub configure { |
2123 | my ($self, $x, $y, $w, $h) = @_; |
2083 | my ($self, $x, $y, $w, $h) = @_; |
2124 | |
2084 | |
2125 | $self->_size_allocate ($x, $y, $w, $h); |
2085 | $self->SUPER::configure ($x, $y, $w, $h); |
2126 | |
2086 | |
2127 | $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) |
2087 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
2128 | for @{$self->{children}}; |
2088 | for @{$self->{children}}; |
2129 | } |
2089 | } |
2130 | |
2090 | |
2131 | sub _topleft { |
2091 | sub _topleft { |
2132 | my ($self, $x, $y) = @_; |
2092 | my ($self, $x, $y) = @_; |
… | |
… | |
2135 | } |
2095 | } |
2136 | |
2096 | |
2137 | sub update { |
2097 | sub update { |
2138 | my ($self) = @_; |
2098 | my ($self) = @_; |
2139 | |
2099 | |
2140 | $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); |
2100 | $self->check_size; |
2141 | ::refresh (); |
2101 | ::refresh (); |
2142 | } |
2102 | } |
2143 | |
2103 | |
2144 | sub add { |
2104 | sub add { |
2145 | my ($self, $widget) = @_; |
2105 | my ($self, $child) = @_; |
2146 | |
2106 | |
|
|
2107 | # integerize window positions |
|
|
2108 | $child->{x} = int $child->{x}; |
|
|
2109 | $child->{y} = int $child->{y}; |
|
|
2110 | |
2147 | $self->SUPER::add ($widget); |
2111 | $self->SUPER::add ($child); |
2148 | |
|
|
2149 | $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request); |
|
|
2150 | } |
2112 | } |
2151 | |
2113 | |
2152 | sub on_refresh { |
2114 | sub on_refresh { |
2153 | my ($self, $id, $cb) = @_; |
2115 | my ($self, $id, $cb) = @_; |
2154 | |
2116 | |