1 | package CFClient::UI; |
1 | package CFPlus::UI; |
2 | |
2 | |
3 | use utf8; |
3 | use utf8; |
4 | use strict; |
4 | use strict; |
5 | |
5 | |
6 | use Scalar::Util (); |
|
|
7 | use List::Util (); |
6 | use List::Util (); |
8 | use Event; |
7 | use Event; |
9 | |
8 | |
10 | use CFClient; |
9 | use CFPlus; |
|
|
10 | use CFPlus::Pod; |
11 | use CFClient::Texture; |
11 | use CFPlus::Texture; |
12 | |
12 | |
13 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
13 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
14 | |
14 | |
15 | our $LAYOUT; |
15 | our $LAYOUT; |
16 | our $ROOT; |
16 | our $ROOT; |
… | |
… | |
22 | our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { |
22 | our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { |
23 | if (!$GRAB) { |
23 | if (!$GRAB) { |
24 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
24 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
25 | if (length $widget->{tooltip}) { |
25 | if (length $widget->{tooltip}) { |
26 | if ($TOOLTIP->{owner} != $widget) { |
26 | if ($TOOLTIP->{owner} != $widget) { |
|
|
27 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
27 | $TOOLTIP->hide; |
28 | $TOOLTIP->hide; |
28 | |
29 | |
29 | $TOOLTIP->{owner} = $widget; |
30 | $TOOLTIP->{owner} = $widget; |
|
|
31 | $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner}; |
30 | |
32 | |
31 | return if $ENV{CFPLUS_DEBUG} & 8; |
33 | return if $ENV{CFPLUS_DEBUG} & 8; |
32 | |
34 | |
33 | my $tip = $widget->{tooltip}; |
35 | my $tip = $widget->{tooltip}; |
34 | |
36 | |
… | |
… | |
42 | } |
44 | } |
43 | } |
45 | } |
44 | } |
46 | } |
45 | |
47 | |
46 | $TOOLTIP->hide; |
48 | $TOOLTIP->hide; |
|
|
49 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
47 | delete $TOOLTIP->{owner}; |
50 | delete $TOOLTIP->{owner}; |
48 | }); |
51 | }); |
49 | |
52 | |
50 | sub get_layout { |
53 | sub get_layout { |
51 | my $layout; |
54 | my $layout; |
… | |
… | |
96 | |
99 | |
97 | sub feed_sdl_button_down_event { |
100 | sub feed_sdl_button_down_event { |
98 | my ($ev) = @_; |
101 | my ($ev) = @_; |
99 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
102 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
100 | |
103 | |
101 | unless ($BUTTON_STATE) { |
104 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
|
|
105 | |
|
|
106 | unless ($GRAB) { |
102 | my $widget = $ROOT->find_widget ($x, $y); |
107 | my $widget = $ROOT->find_widget ($x, $y); |
103 | |
108 | |
104 | $GRAB = $widget; |
109 | $GRAB = $widget; |
105 | $GRAB->update if $GRAB; |
110 | $GRAB->update if $GRAB; |
106 | |
111 | |
107 | $TOOLTIP_WATCHER->cb->(); |
112 | $TOOLTIP_WATCHER->cb->(); |
108 | } |
113 | } |
109 | |
|
|
110 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
|
|
111 | |
114 | |
112 | if ($GRAB) { |
115 | if ($GRAB) { |
113 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
116 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
114 | # mousewheel |
117 | # mousewheel |
115 | $ev->{dx} = 0; |
118 | $ev->{dx} = 0; |
… | |
… | |
207 | reconfigure_widgets; |
210 | reconfigure_widgets; |
208 | } |
211 | } |
209 | |
212 | |
210 | ############################################################################# |
213 | ############################################################################# |
211 | |
214 | |
212 | package CFClient::UI::Event; |
215 | package CFPlus::UI::Event; |
213 | |
216 | |
214 | sub xy { |
217 | sub xy { |
215 | $_[1]->coord2local ($_[0]{x}, $_[0]{y}) |
218 | $_[1]->coord2local ($_[0]{x}, $_[0]{y}) |
216 | } |
219 | } |
217 | |
220 | |
218 | ############################################################################# |
221 | ############################################################################# |
219 | |
222 | |
220 | package CFClient::UI::Base; |
223 | package CFPlus::UI::Base; |
221 | |
224 | |
222 | use strict; |
225 | use strict; |
223 | |
226 | |
224 | use CFClient::OpenGL; |
227 | use CFPlus::OpenGL; |
225 | |
228 | |
226 | sub new { |
229 | sub new { |
227 | my $class = shift; |
230 | my $class = shift; |
228 | |
231 | |
229 | my $self = bless { |
232 | my $self = bless { |
… | |
… | |
234 | h => undef, |
237 | h => undef, |
235 | can_events => 1, |
238 | can_events => 1, |
236 | @_ |
239 | @_ |
237 | }, $class; |
240 | }, $class; |
238 | |
241 | |
239 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
242 | CFPlus::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); |
240 | |
243 | |
241 | for (keys %$self) { |
244 | for (keys %$self) { |
242 | if (/^on_(.*)$/) { |
245 | if (/^on_(.*)$/) { |
243 | $self->connect ($1 => delete $self->{$_}); |
246 | $self->connect ($1 => delete $self->{$_}); |
244 | } |
247 | } |
245 | } |
248 | } |
246 | |
249 | |
247 | if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { |
250 | if (my $layout = $CFPlus::UI::LAYOUT->{$self->{name}}) { |
248 | $self->{x} = $layout->{x} * $CFClient::UI::ROOT->{alloc_w} if exists $layout->{x}; |
251 | $self->{x} = $layout->{x} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{x}; |
249 | $self->{y} = $layout->{y} * $CFClient::UI::ROOT->{alloc_h} if exists $layout->{y}; |
252 | $self->{y} = $layout->{y} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{y}; |
250 | $self->{force_w} = $layout->{w} * $CFClient::UI::ROOT->{alloc_w} if exists $layout->{w}; |
253 | $self->{force_w} = $layout->{w} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{w}; |
251 | $self->{force_h} = $layout->{h} * $CFClient::UI::ROOT->{alloc_h} if exists $layout->{h}; |
254 | $self->{force_h} = $layout->{h} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{h}; |
252 | |
255 | |
253 | $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; |
256 | $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; |
254 | $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; |
257 | $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; |
255 | |
258 | |
256 | $self->show if $layout->{show}; |
259 | $self->show if $layout->{show}; |
… | |
… | |
261 | |
264 | |
262 | sub destroy { |
265 | sub destroy { |
263 | my ($self) = @_; |
266 | my ($self) = @_; |
264 | |
267 | |
265 | $self->hide; |
268 | $self->hide; |
|
|
269 | $self->emit ("destroy"); |
266 | %$self = (); |
270 | %$self = (); |
267 | } |
271 | } |
268 | |
272 | |
269 | sub show { |
273 | sub show { |
270 | my ($self) = @_; |
274 | my ($self) = @_; |
271 | |
275 | |
272 | return if $self->{parent}; |
276 | return if $self->{parent}; |
273 | |
277 | |
274 | $CFClient::UI::ROOT->add ($self); |
278 | $CFPlus::UI::ROOT->add ($self); |
275 | } |
279 | } |
276 | |
280 | |
277 | sub set_visible { |
281 | sub set_visible { |
278 | my ($self) = @_; |
282 | my ($self) = @_; |
279 | |
283 | |
… | |
… | |
300 | delete $self->{root}; |
304 | delete $self->{root}; |
301 | |
305 | |
302 | undef $GRAB if $GRAB == $self; |
306 | undef $GRAB if $GRAB == $self; |
303 | undef $HOVER if $HOVER == $self; |
307 | undef $HOVER if $HOVER == $self; |
304 | |
308 | |
305 | $CFClient::UI::TOOLTIP_WATCHER->cb->() |
309 | $CFPlus::UI::TOOLTIP_WATCHER->cb->() |
306 | if $TOOLTIP->{owner} == $self; |
310 | if $TOOLTIP->{owner} == $self; |
307 | |
311 | |
308 | $self->emit ("focus_out"); |
312 | $self->emit ("focus_out"); |
309 | $self->emit (visibility_change => 0); |
313 | $self->emit (visibility_change => 0); |
310 | } |
314 | } |
… | |
… | |
367 | my ($self, $x, $y, $w, $h) = @_; |
371 | my ($self, $x, $y, $w, $h) = @_; |
368 | |
372 | |
369 | if ($self->{aspect}) { |
373 | if ($self->{aspect}) { |
370 | my ($ow, $oh) = ($w, $h); |
374 | my ($ow, $oh) = ($w, $h); |
371 | |
375 | |
372 | $w = List::Util::min $w, int $h * $self->{aspect}; |
376 | $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect}; |
373 | $h = List::Util::min $h, int $w / $self->{aspect}; |
377 | $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect}; |
374 | |
378 | |
375 | # use alignment to adjust x, y |
379 | # use alignment to adjust x, y |
376 | |
380 | |
377 | $x += int 0.5 * ($ow - $w); |
381 | $x += int 0.5 * ($ow - $w); |
378 | $y += int 0.5 * ($oh - $h); |
382 | $y += int 0.5 * ($oh - $h); |
… | |
… | |
419 | |
423 | |
420 | return if $self->{tooltip} eq $tooltip; |
424 | return if $self->{tooltip} eq $tooltip; |
421 | |
425 | |
422 | $self->{tooltip} = $tooltip; |
426 | $self->{tooltip} = $tooltip; |
423 | |
427 | |
424 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
428 | if ($CFPlus::UI::TOOLTIP->{owner} == $self) { |
425 | delete $CFClient::UI::TOOLTIP->{owner}; |
429 | delete $CFPlus::UI::TOOLTIP->{owner}; |
426 | $CFClient::UI::TOOLTIP_WATCHER->cb->(); |
430 | $CFPlus::UI::TOOLTIP_WATCHER->cb->(); |
427 | } |
431 | } |
428 | } |
432 | } |
429 | |
433 | |
430 | # translate global coordinates to local coordinate system |
434 | # translate global coordinates to local coordinate system |
431 | sub coord2local { |
435 | sub coord2local { |
432 | my ($self, $x, $y) = @_; |
436 | my ($self, $x, $y) = @_; |
433 | |
437 | |
|
|
438 | Carp::confess unless $self->{parent};#d# |
|
|
439 | |
434 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
440 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
435 | } |
441 | } |
436 | |
442 | |
437 | # translate local coordinates to global coordinate system |
443 | # translate local coordinates to global coordinate system |
438 | sub coord2global { |
444 | sub coord2global { |
439 | my ($self, $x, $y) = @_; |
445 | my ($self, $x, $y) = @_; |
|
|
446 | |
|
|
447 | Carp::confess unless $self->{parent};#d# |
440 | |
448 | |
441 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
449 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
442 | } |
450 | } |
443 | |
451 | |
444 | sub invoke_focus_in { |
452 | sub invoke_focus_in { |
… | |
… | |
492 | |
500 | |
493 | sub connect { |
501 | sub connect { |
494 | my ($self, $signal, $cb) = @_; |
502 | my ($self, $signal, $cb) = @_; |
495 | |
503 | |
496 | push @{ $self->{signal_cb}{$signal} }, $cb; |
504 | push @{ $self->{signal_cb}{$signal} }, $cb; |
|
|
505 | |
|
|
506 | defined wantarray and CFPlus::guard { |
|
|
507 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
|
|
508 | @{ $self->{signal_cb}{$signal} }; |
|
|
509 | } |
497 | } |
510 | } |
|
|
511 | |
|
|
512 | sub disconnect_all { |
|
|
513 | my ($self, $signal) = @_; |
|
|
514 | |
|
|
515 | delete $self->{signal_cb}{$signal}; |
|
|
516 | } |
|
|
517 | |
|
|
518 | my %has_coords = ( |
|
|
519 | button_down => 1, |
|
|
520 | button_up => 1, |
|
|
521 | mouse_motion => 1, |
|
|
522 | mouse_wheel => 1, |
|
|
523 | ); |
498 | |
524 | |
499 | sub emit { |
525 | sub emit { |
500 | my ($self, $signal, @args) = @_; |
526 | my ($self, $signal, @args) = @_; |
501 | |
527 | |
|
|
528 | # I do not really like this solution, but I do not like duplication |
|
|
529 | # and needlessly verbose code, either. |
502 | my @append |
530 | my @append |
503 | = ref $args[0] && $args[0]->isa ("CFClient::UI::Event") |
531 | = $has_coords{$signal} |
504 | ? $args[0]->xy ($self) |
532 | ? $args[0]->xy ($self) |
505 | : (); |
533 | : (); |
506 | |
534 | |
507 | #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# |
535 | #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# |
508 | |
536 | |
509 | #d##TODO# stop propagating at first true, do not use sum |
537 | for my $cb ( |
510 | (List::Util::sum map $_->($self, @args, @append), @{$self->{signal_cb}{$signal} || []}) # before |
538 | @{$self->{signal_cb}{$signal} || []}, # before |
511 | || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args, @append) # closure |
539 | ($self->can ("invoke_$signal") || sub { 1 }), # closure |
|
|
540 | ) { |
|
|
541 | return $cb->($self, @args, @append) || next; |
|
|
542 | } |
|
|
543 | |
|
|
544 | # parent |
512 | || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent |
545 | $self->{parent} && $self->{parent}->emit ($signal, @args) |
513 | } |
546 | } |
514 | |
547 | |
515 | sub find_widget { |
548 | sub find_widget { |
516 | my ($self, $x, $y) = @_; |
549 | my ($self, $x, $y) = @_; |
517 | |
550 | |
… | |
… | |
525 | } |
558 | } |
526 | |
559 | |
527 | sub set_parent { |
560 | sub set_parent { |
528 | my ($self, $parent) = @_; |
561 | my ($self, $parent) = @_; |
529 | |
562 | |
530 | Scalar::Util::weaken ($self->{parent} = $parent); |
563 | CFPlus::weaken ($self->{parent} = $parent); |
531 | $self->set_visible if $parent->{visible}; |
564 | $self->set_visible if $parent->{visible}; |
532 | } |
565 | } |
533 | |
566 | |
534 | sub realloc { |
567 | sub realloc { |
535 | my ($self) = @_; |
568 | my ($self) = @_; |
… | |
… | |
601 | glVertex $self->{w} - 1, 0; |
634 | glVertex $self->{w} - 1, 0; |
602 | glVertex $self->{w} - 1, $self->{h} - 1; |
635 | glVertex $self->{w} - 1, $self->{h} - 1; |
603 | glVertex 0 , $self->{h} - 1; |
636 | glVertex 0 , $self->{h} - 1; |
604 | glEnd; |
637 | glEnd; |
605 | glPopMatrix; |
638 | glPopMatrix; |
606 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
639 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
607 | } |
640 | } |
608 | |
641 | |
609 | $self->_draw; |
642 | $self->_draw; |
610 | glPopMatrix; |
643 | glPopMatrix; |
611 | } |
644 | } |
… | |
… | |
614 | my ($self) = @_; |
647 | my ($self) = @_; |
615 | |
648 | |
616 | warn "no draw defined for $self\n"; |
649 | warn "no draw defined for $self\n"; |
617 | } |
650 | } |
618 | |
651 | |
|
|
652 | my $cntx;#d# |
619 | sub DESTROY { |
653 | sub DESTROY { |
620 | my ($self) = @_; |
654 | my ($self) = @_; |
621 | |
655 | |
622 | return if CFClient::in_destruct; |
656 | return if CFPlus::in_destruct; |
623 | |
|
|
624 | delete $WIDGET{$self+0}; |
|
|
625 | |
657 | |
626 | eval { $self->destroy }; |
658 | eval { $self->destroy }; |
627 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
659 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
|
|
660 | |
|
|
661 | delete $WIDGET{$self+0}; |
628 | } |
662 | } |
629 | |
663 | |
630 | ############################################################################# |
664 | ############################################################################# |
631 | |
665 | |
632 | package CFClient::UI::DrawBG; |
666 | package CFPlus::UI::DrawBG; |
633 | |
667 | |
634 | our @ISA = CFClient::UI::Base::; |
668 | our @ISA = CFPlus::UI::Base::; |
635 | |
669 | |
636 | use strict; |
670 | use strict; |
637 | use CFClient::OpenGL; |
671 | use CFPlus::OpenGL; |
638 | |
672 | |
639 | sub new { |
673 | sub new { |
640 | my $class = shift; |
674 | my $class = shift; |
641 | |
675 | |
642 | # range [value, low, high, page] |
676 | # range [value, low, high, page] |
… | |
… | |
673 | } |
707 | } |
674 | } |
708 | } |
675 | |
709 | |
676 | ############################################################################# |
710 | ############################################################################# |
677 | |
711 | |
678 | package CFClient::UI::Empty; |
712 | package CFPlus::UI::Empty; |
679 | |
713 | |
680 | our @ISA = CFClient::UI::Base::; |
714 | our @ISA = CFPlus::UI::Base::; |
681 | |
715 | |
682 | sub new { |
716 | sub new { |
683 | my ($class, %arg) = @_; |
717 | my ($class, %arg) = @_; |
684 | $class->SUPER::new (can_events => 0, %arg); |
718 | $class->SUPER::new (can_events => 0, %arg); |
685 | } |
719 | } |
… | |
… | |
692 | |
726 | |
693 | sub draw { } |
727 | sub draw { } |
694 | |
728 | |
695 | ############################################################################# |
729 | ############################################################################# |
696 | |
730 | |
697 | package CFClient::UI::Container; |
731 | package CFPlus::UI::Container; |
698 | |
732 | |
699 | our @ISA = CFClient::UI::Base::; |
733 | our @ISA = CFPlus::UI::Base::; |
700 | |
734 | |
701 | sub new { |
735 | sub new { |
702 | my ($class, %arg) = @_; |
736 | my ($class, %arg) = @_; |
703 | |
737 | |
704 | my $children = delete $arg{children}; |
738 | my $children = delete $arg{children}; |
… | |
… | |
713 | if $children; |
747 | if $children; |
714 | |
748 | |
715 | $self |
749 | $self |
716 | } |
750 | } |
717 | |
751 | |
|
|
752 | sub realloc { |
|
|
753 | my ($self) = @_; |
|
|
754 | |
|
|
755 | $self->{force_realloc} = 1; |
|
|
756 | $self->{force_size_alloc} = 1; |
|
|
757 | $self->SUPER::realloc; |
|
|
758 | } |
|
|
759 | |
718 | sub add { |
760 | sub add { |
719 | my ($self, @widgets) = @_; |
761 | my ($self, @widgets) = @_; |
720 | |
762 | |
721 | $_->set_parent ($self) |
763 | $_->set_parent ($self) |
722 | for @widgets; |
764 | for @widgets; |
… | |
… | |
782 | $_->draw for @{$self->{children}}; |
824 | $_->draw for @{$self->{children}}; |
783 | } |
825 | } |
784 | |
826 | |
785 | ############################################################################# |
827 | ############################################################################# |
786 | |
828 | |
787 | package CFClient::UI::Bin; |
829 | package CFPlus::UI::Bin; |
788 | |
830 | |
789 | our @ISA = CFClient::UI::Container::; |
831 | our @ISA = CFPlus::UI::Container::; |
790 | |
832 | |
791 | sub new { |
833 | sub new { |
792 | my ($class, %arg) = @_; |
834 | my ($class, %arg) = @_; |
793 | |
835 | |
794 | my $child = (delete $arg{child}) || new CFClient::UI::Empty::; |
836 | my $child = (delete $arg{child}) || new CFPlus::UI::Empty::; |
795 | |
837 | |
796 | $class->SUPER::new (children => [$child], %arg) |
838 | $class->SUPER::new (children => [$child], %arg) |
797 | } |
839 | } |
798 | |
840 | |
799 | sub add { |
841 | sub add { |
… | |
… | |
806 | sub remove { |
848 | sub remove { |
807 | my ($self, $widget) = @_; |
849 | my ($self, $widget) = @_; |
808 | |
850 | |
809 | $self->SUPER::remove ($widget); |
851 | $self->SUPER::remove ($widget); |
810 | |
852 | |
811 | $self->{children} = [new CFClient::UI::Empty] |
853 | $self->{children} = [new CFPlus::UI::Empty] |
812 | unless @{$self->{children}}; |
854 | unless @{$self->{children}}; |
813 | } |
855 | } |
814 | |
856 | |
815 | sub child { $_[0]->{children}[0] } |
857 | sub child { $_[0]->{children}[0] } |
816 | |
858 | |
… | |
… | |
828 | |
870 | |
829 | ############################################################################# |
871 | ############################################################################# |
830 | |
872 | |
831 | # back-buffered drawing area |
873 | # back-buffered drawing area |
832 | |
874 | |
833 | package CFClient::UI::Window; |
875 | package CFPlus::UI::Window; |
834 | |
876 | |
835 | our @ISA = CFClient::UI::Bin::; |
877 | our @ISA = CFPlus::UI::Bin::; |
836 | |
878 | |
837 | use CFClient::OpenGL; |
879 | use CFPlus::OpenGL; |
838 | |
880 | |
839 | sub new { |
881 | sub new { |
840 | my ($class, %arg) = @_; |
882 | my ($class, %arg) = @_; |
841 | |
883 | |
842 | my $self = $class->SUPER::new (%arg); |
884 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
864 | } |
906 | } |
865 | |
907 | |
866 | sub render_child { |
908 | sub render_child { |
867 | my ($self) = @_; |
909 | my ($self) = @_; |
868 | |
910 | |
869 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
911 | $self->{texture} = new_from_opengl CFPlus::Texture $self->{w}, $self->{h}, sub { |
870 | glClearColor 0, 0, 0, 0; |
912 | glClearColor 0, 0, 0, 0; |
871 | glClear GL_COLOR_BUFFER_BIT; |
913 | glClear GL_COLOR_BUFFER_BIT; |
872 | |
914 | |
873 | { |
915 | { |
874 | package CFClient::UI::Base; |
916 | package CFPlus::UI::Base; |
875 | |
917 | |
876 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
918 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
877 | (0, 0, $self->{w}, $self->{h}); |
919 | (0, 0, $self->{w}, $self->{h}); |
|
|
920 | |
|
|
921 | $self->_render; |
878 | } |
922 | } |
879 | |
|
|
880 | $self->_render; |
|
|
881 | }; |
923 | }; |
882 | } |
924 | } |
883 | |
925 | |
884 | sub _draw { |
926 | sub _draw { |
885 | my ($self) = @_; |
927 | my ($self) = @_; |
886 | |
|
|
887 | my ($w, $h) = @$self{qw(w h)}; |
|
|
888 | |
928 | |
889 | my $tex = $self->{texture} |
929 | my $tex = $self->{texture} |
890 | or return; |
930 | or return; |
891 | |
931 | |
892 | glEnable GL_TEXTURE_2D; |
932 | glEnable GL_TEXTURE_2D; |
893 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
933 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
894 | glColor 0, 0, 0, 1; |
934 | glColor 0, 0, 0, 1; |
895 | |
935 | |
896 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
936 | $tex->draw_quad_alpha_premultiplied (0, 0); |
897 | |
937 | |
898 | glDisable GL_TEXTURE_2D; |
938 | glDisable GL_TEXTURE_2D; |
899 | } |
939 | } |
900 | |
940 | |
901 | ############################################################################# |
941 | ############################################################################# |
902 | |
942 | |
903 | package CFClient::UI::ViewPort; |
943 | package CFPlus::UI::ViewPort; |
904 | |
944 | |
905 | our @ISA = CFClient::UI::Window::; |
945 | our @ISA = CFPlus::UI::Window::; |
906 | |
946 | |
907 | sub new { |
947 | sub new { |
908 | my $class = shift; |
948 | my $class = shift; |
909 | |
949 | |
910 | $class->SUPER::new ( |
950 | $class->SUPER::new ( |
… | |
… | |
970 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
1010 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
971 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
1011 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
972 | ) { |
1012 | ) { |
973 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
1013 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
974 | } else { |
1014 | } else { |
975 | $self->CFClient::UI::Base::find_widget ($x, $y) |
1015 | $self->CFPlus::UI::Base::find_widget ($x, $y) |
976 | } |
1016 | } |
977 | } |
1017 | } |
978 | |
1018 | |
979 | sub _render { |
1019 | sub _render { |
980 | my ($self) = @_; |
1020 | my ($self) = @_; |
981 | |
1021 | |
982 | local $CFClient::UI::Base::draw_x = $CFClient::UI::Base::draw_x - $self->{view_x}; |
1022 | local $CFPlus::UI::Base::draw_x = $CFPlus::UI::Base::draw_x - $self->{view_x}; |
983 | local $CFClient::UI::Base::draw_y = $CFClient::UI::Base::draw_y - $self->{view_y}; |
1023 | local $CFPlus::UI::Base::draw_y = $CFPlus::UI::Base::draw_y - $self->{view_y}; |
984 | |
1024 | |
985 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
1025 | CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
986 | |
1026 | |
987 | $self->SUPER::_render; |
1027 | $self->SUPER::_render; |
988 | } |
1028 | } |
989 | |
1029 | |
990 | ############################################################################# |
1030 | ############################################################################# |
991 | |
1031 | |
992 | package CFClient::UI::ScrolledWindow; |
1032 | package CFPlus::UI::ScrolledWindow; |
993 | |
1033 | |
994 | our @ISA = CFClient::UI::HBox::; |
1034 | our @ISA = CFPlus::UI::HBox::; |
995 | |
1035 | |
996 | sub new { |
1036 | sub new { |
997 | my ($class, %arg) = @_; |
1037 | my ($class, %arg) = @_; |
998 | |
1038 | |
999 | my $child = delete $arg{child}; |
1039 | my $child = delete $arg{child}; |
1000 | |
1040 | |
1001 | my $self; |
1041 | my $self; |
1002 | |
1042 | |
1003 | my $slider = new CFClient::UI::Slider |
1043 | my $slider = new CFPlus::UI::Slider |
1004 | vertical => 1, |
1044 | vertical => 1, |
1005 | range => [0, 0, 1, 0.01], # HACK fix |
1045 | range => [0, 0, 1, 0.01], # HACK fix |
1006 | on_changed => sub { |
1046 | on_changed => sub { |
1007 | $self->{vp}->set_offset (0, $_[1]); |
1047 | $self->{vp}->set_offset (0, $_[1]); |
1008 | }, |
1048 | }, |
1009 | ; |
1049 | ; |
1010 | |
1050 | |
1011 | $self = $class->SUPER::new ( |
1051 | $self = $class->SUPER::new ( |
1012 | vp => (new CFClient::UI::ViewPort expand => 1), |
1052 | vp => (new CFPlus::UI::ViewPort expand => 1), |
1013 | can_events => 1, |
1053 | can_events => 1, |
1014 | slider => $slider, |
1054 | slider => $slider, |
1015 | %arg, |
1055 | %arg, |
1016 | ); |
1056 | ); |
1017 | |
1057 | |
… | |
… | |
1061 | $self->SUPER::invoke_size_allocate ($w, $h) |
1101 | $self->SUPER::invoke_size_allocate ($w, $h) |
1062 | } |
1102 | } |
1063 | |
1103 | |
1064 | ############################################################################# |
1104 | ############################################################################# |
1065 | |
1105 | |
1066 | package CFClient::UI::Frame; |
1106 | package CFPlus::UI::Frame; |
1067 | |
1107 | |
1068 | our @ISA = CFClient::UI::Bin::; |
1108 | our @ISA = CFPlus::UI::Bin::; |
1069 | |
1109 | |
1070 | use CFClient::OpenGL; |
1110 | use CFPlus::OpenGL; |
1071 | |
1111 | |
1072 | sub new { |
1112 | sub new { |
1073 | my $class = shift; |
1113 | my $class = shift; |
1074 | |
1114 | |
1075 | $class->SUPER::new ( |
1115 | $class->SUPER::new ( |
… | |
… | |
1101 | $self->SUPER::_draw; |
1141 | $self->SUPER::_draw; |
1102 | } |
1142 | } |
1103 | |
1143 | |
1104 | ############################################################################# |
1144 | ############################################################################# |
1105 | |
1145 | |
1106 | package CFClient::UI::FancyFrame; |
1146 | package CFPlus::UI::FancyFrame; |
1107 | |
1147 | |
1108 | our @ISA = CFClient::UI::Bin::; |
1148 | our @ISA = CFPlus::UI::Bin::; |
1109 | |
1149 | |
1110 | use CFClient::OpenGL; |
1150 | use CFPlus::OpenGL; |
|
|
1151 | |
|
|
1152 | sub new { |
|
|
1153 | my ($class, %arg) = @_; |
|
|
1154 | |
|
|
1155 | if ((exists $arg{label}) && !ref $arg{label}) { |
|
|
1156 | $arg{label} = new CFPlus::UI::Label |
|
|
1157 | align => 1, |
|
|
1158 | valign => 0, |
|
|
1159 | text => $arg{label}, |
|
|
1160 | fontsize => ($arg{border} || 0.8) * 0.75; |
|
|
1161 | } |
|
|
1162 | |
|
|
1163 | my $self = $class->SUPER::new ( |
|
|
1164 | # label => "", |
|
|
1165 | fg => [0.6, 0.3, 0.1], |
|
|
1166 | border => 0.8, |
|
|
1167 | style => 'single', |
|
|
1168 | %arg, |
|
|
1169 | ); |
|
|
1170 | |
|
|
1171 | $self |
|
|
1172 | } |
|
|
1173 | |
|
|
1174 | sub add { |
|
|
1175 | my ($self, @widgets) = @_; |
|
|
1176 | |
|
|
1177 | $self->SUPER::add (@widgets); |
|
|
1178 | $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label}; |
|
|
1179 | } |
|
|
1180 | |
|
|
1181 | sub border { |
|
|
1182 | int $_[0]{border} * $::FONTSIZE |
|
|
1183 | } |
|
|
1184 | |
|
|
1185 | sub size_request { |
|
|
1186 | my ($self) = @_; |
|
|
1187 | |
|
|
1188 | ($self->{label_w}, undef) = $self->{label}->size_request |
|
|
1189 | if $self->{label}; |
|
|
1190 | |
|
|
1191 | my ($w, $h) = $self->SUPER::size_request; |
|
|
1192 | |
|
|
1193 | ( |
|
|
1194 | $w + $self->border * 2, |
|
|
1195 | $h + $self->border * 2, |
|
|
1196 | ) |
|
|
1197 | } |
|
|
1198 | |
|
|
1199 | sub invoke_size_allocate { |
|
|
1200 | my ($self, $w, $h) = @_; |
|
|
1201 | |
|
|
1202 | my $border = $self->border; |
|
|
1203 | |
|
|
1204 | $w -= List::Util::max 0, $border * 2; |
|
|
1205 | $h -= List::Util::max 0, $border * 2; |
|
|
1206 | |
|
|
1207 | if (my $label = $self->{label}) { |
|
|
1208 | $label->{w} = List::Util::max 0, List::Util::min $self->{label_w}, $w - $border * 2; |
|
|
1209 | $label->{h} = List::Util::min $h, $border; |
|
|
1210 | $label->invoke_size_allocate ($label->{w}, $label->{h}); |
|
|
1211 | } |
|
|
1212 | |
|
|
1213 | $self->child->configure ($border, $border, $w, $h); |
|
|
1214 | |
|
|
1215 | 1 |
|
|
1216 | } |
|
|
1217 | |
|
|
1218 | sub _draw { |
|
|
1219 | my ($self) = @_; |
|
|
1220 | |
|
|
1221 | my $child = $self->{children}[0]; |
|
|
1222 | |
|
|
1223 | my $border = $self->border; |
|
|
1224 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1225 | |
|
|
1226 | $child->draw; |
|
|
1227 | |
|
|
1228 | glColor @{$self->{fg}}; |
|
|
1229 | glBegin GL_LINE_STRIP; |
|
|
1230 | glVertex $border * 1.5 , $border * 0.5 + 0.5; |
|
|
1231 | glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; |
|
|
1232 | glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
|
|
1233 | glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
|
|
1234 | glVertex $w - $border * 0.5 + 0.5, $border * 0.5 + 0.5; |
|
|
1235 | glVertex $self->{label} ? $border * 2 + $self->{label}{w} : $border * 1.5, $border * 0.5 + 0.5; |
|
|
1236 | glEnd; |
|
|
1237 | |
|
|
1238 | if ($self->{label}) { |
|
|
1239 | glTranslate $border * 2, 0; |
|
|
1240 | $self->{label}->_draw; |
|
|
1241 | } |
|
|
1242 | } |
|
|
1243 | |
|
|
1244 | ############################################################################# |
|
|
1245 | |
|
|
1246 | package CFPlus::UI::Toplevel; |
|
|
1247 | |
|
|
1248 | our @ISA = CFPlus::UI::Bin::; |
|
|
1249 | |
|
|
1250 | use CFPlus::OpenGL; |
1111 | |
1251 | |
1112 | my $bg = |
1252 | my $bg = |
1113 | new_from_file CFClient::Texture CFClient::find_rcfile "d1_bg.png", |
1253 | new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", |
1114 | mipmap => 1, wrap => 1; |
1254 | mipmap => 1, wrap => 1; |
1115 | |
1255 | |
1116 | my @border = |
1256 | my @border = |
1117 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1257 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1118 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1258 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1119 | |
1259 | |
1120 | sub new { |
1260 | sub new { |
1121 | my ($class, %arg) = @_; |
1261 | my ($class, %arg) = @_; |
1122 | |
1262 | |
… | |
… | |
1128 | min_w => 64, |
1268 | min_w => 64, |
1129 | min_h => 32, |
1269 | min_h => 32, |
1130 | %arg, |
1270 | %arg, |
1131 | ); |
1271 | ); |
1132 | |
1272 | |
1133 | $self->{title_widget} = new CFClient::UI::Label |
1273 | $self->{title_widget} = new CFPlus::UI::Label |
1134 | align => 0, |
1274 | align => 0, |
1135 | valign => 1, |
1275 | valign => 1, |
1136 | text => $self->{title}, |
1276 | text => $self->{title}, |
1137 | fontsize => $self->{border}, |
1277 | fontsize => $self->{border}, |
1138 | if exists $self->{title}; |
1278 | if exists $self->{title}; |
1139 | |
1279 | |
1140 | if ($self->{has_close_button}) { |
1280 | if ($self->{has_close_button}) { |
1141 | $self->{close_button} = |
1281 | $self->{close_button} = |
1142 | new CFClient::UI::ImageButton |
1282 | new CFPlus::UI::ImageButton |
1143 | path => 'x1_close.png', |
1283 | path => 'x1_close.png', |
1144 | on_activate => sub { $self->emit ("delete") }; |
1284 | on_activate => sub { $self->emit ("delete") }; |
1145 | |
1285 | |
1146 | $self->CFClient::UI::Container::add ($self->{close_button}); |
1286 | $self->CFPlus::UI::Container::add ($self->{close_button}); |
1147 | } |
1287 | } |
1148 | |
1288 | |
1149 | $self |
1289 | $self |
1150 | } |
1290 | } |
1151 | |
1291 | |
1152 | sub add { |
1292 | sub add { |
1153 | my ($self, @widgets) = @_; |
1293 | my ($self, @widgets) = @_; |
1154 | |
1294 | |
1155 | $self->SUPER::add (@widgets); |
1295 | $self->SUPER::add (@widgets); |
1156 | $self->CFClient::UI::Container::add ($self->{close_button}) if $self->{close_button}; |
1296 | $self->CFPlus::UI::Container::add ($self->{close_button}) if $self->{close_button}; |
1157 | $self->CFClient::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1297 | $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1158 | } |
1298 | } |
1159 | |
1299 | |
1160 | sub border { |
1300 | sub border { |
1161 | int $_[0]{border} * $::FONTSIZE |
1301 | int $_[0]{border} * $::FONTSIZE |
1162 | } |
1302 | } |
… | |
… | |
1270 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
1410 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
1271 | |
1411 | |
1272 | ! ! $self->{motion} |
1412 | ! ! $self->{motion} |
1273 | } |
1413 | } |
1274 | |
1414 | |
|
|
1415 | sub invoke_visibility_change { |
|
|
1416 | my ($self, $visible) = @_; |
|
|
1417 | |
|
|
1418 | delete $self->{motion} unless $visible; |
|
|
1419 | |
|
|
1420 | 0 |
|
|
1421 | } |
|
|
1422 | |
1275 | sub _draw { |
1423 | sub _draw { |
1276 | my ($self) = @_; |
1424 | my ($self) = @_; |
1277 | |
1425 | |
1278 | my $child = $self->{children}[0]; |
1426 | my $child = $self->{children}[0]; |
1279 | |
1427 | |
… | |
… | |
1316 | if $self->{close_button}; |
1464 | if $self->{close_button}; |
1317 | } |
1465 | } |
1318 | |
1466 | |
1319 | ############################################################################# |
1467 | ############################################################################# |
1320 | |
1468 | |
1321 | package CFClient::UI::Table; |
1469 | package CFPlus::UI::Table; |
1322 | |
1470 | |
1323 | our @ISA = CFClient::UI::Base::; |
1471 | our @ISA = CFPlus::UI::Base::; |
1324 | |
1472 | |
1325 | use List::Util qw(max sum); |
1473 | use List::Util qw(max sum); |
1326 | |
1474 | |
1327 | use CFClient::OpenGL; |
1475 | use CFPlus::OpenGL; |
1328 | |
1476 | |
1329 | sub new { |
1477 | sub new { |
1330 | my $class = shift; |
1478 | my $class = shift; |
1331 | |
1479 | |
1332 | $class->SUPER::new ( |
1480 | $class->SUPER::new ( |
… | |
… | |
1338 | sub children { |
1486 | sub children { |
1339 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
1487 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
1340 | } |
1488 | } |
1341 | |
1489 | |
1342 | sub add { |
1490 | sub add { |
1343 | my ($self, $x, $y, $child) = @_; |
1491 | my ($self) = shift; |
1344 | |
1492 | |
|
|
1493 | while (@_) { |
|
|
1494 | my ($x, $y, $child) = splice @_, 0, 3, (); |
1345 | $child->set_parent ($self); |
1495 | $child->set_parent ($self); |
1346 | $self->{children}[$y][$x] = $child; |
1496 | $self->{children}[$y][$x] = $child; |
|
|
1497 | } |
1347 | |
1498 | |
|
|
1499 | $self->{force_realloc} = 1; |
|
|
1500 | $self->{force_size_alloc} = 1; |
1348 | $self->realloc; |
1501 | $self->realloc; |
1349 | } |
1502 | } |
1350 | |
1503 | |
1351 | sub remove { |
1504 | sub remove { |
1352 | my ($self, $child) = @_; |
1505 | my ($self, $child) = @_; |
… | |
… | |
1417 | |
1570 | |
1418 | # linearly scale sizes |
1571 | # linearly scale sizes |
1419 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1572 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1420 | $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; |
1573 | $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; |
1421 | |
1574 | |
1422 | CFClient::UI::harmonize $ws; |
1575 | CFPlus::UI::harmonize $ws; |
1423 | CFClient::UI::harmonize $hs; |
1576 | CFPlus::UI::harmonize $hs; |
1424 | |
1577 | |
1425 | my $y; |
1578 | my $y; |
1426 | |
1579 | |
1427 | for my $r (0 .. $#{$self->{children}}) { |
1580 | for my $r (0 .. $#{$self->{children}}) { |
1428 | my $row = $self->{children}[$r] |
1581 | my $row = $self->{children}[$r] |
… | |
… | |
1471 | } |
1624 | } |
1472 | } |
1625 | } |
1473 | |
1626 | |
1474 | ############################################################################# |
1627 | ############################################################################# |
1475 | |
1628 | |
1476 | package CFClient::UI::Box; |
1629 | package CFPlus::UI::Box; |
1477 | |
1630 | |
1478 | our @ISA = CFClient::UI::Container::; |
1631 | our @ISA = CFPlus::UI::Container::; |
1479 | |
1632 | |
1480 | sub size_request { |
1633 | sub size_request { |
1481 | my ($self) = @_; |
1634 | my ($self) = @_; |
1482 | |
1635 | |
1483 | $self->{vertical} |
1636 | $self->{vertical} |
… | |
… | |
1516 | $req[$_] += $space * $children[$_]{expand} |
1669 | $req[$_] += $space * $children[$_]{expand} |
1517 | for 0 .. $#children; |
1670 | for 0 .. $#children; |
1518 | } |
1671 | } |
1519 | } |
1672 | } |
1520 | |
1673 | |
1521 | CFClient::UI::harmonize \@req; |
1674 | CFPlus::UI::harmonize \@req; |
1522 | |
1675 | |
1523 | my $pos = 0; |
1676 | my $pos = 0; |
1524 | for (0 .. $#children) { |
1677 | for (0 .. $#children) { |
1525 | my $alloc = $req[$_]; |
1678 | my $alloc = $req[$_]; |
1526 | $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); |
1679 | $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); |
… | |
… | |
1531 | 1 |
1684 | 1 |
1532 | } |
1685 | } |
1533 | |
1686 | |
1534 | ############################################################################# |
1687 | ############################################################################# |
1535 | |
1688 | |
1536 | package CFClient::UI::HBox; |
1689 | package CFPlus::UI::HBox; |
1537 | |
1690 | |
1538 | our @ISA = CFClient::UI::Box::; |
1691 | our @ISA = CFPlus::UI::Box::; |
1539 | |
1692 | |
1540 | sub new { |
1693 | sub new { |
1541 | my $class = shift; |
1694 | my $class = shift; |
1542 | |
1695 | |
1543 | $class->SUPER::new ( |
1696 | $class->SUPER::new ( |
… | |
… | |
1546 | ) |
1699 | ) |
1547 | } |
1700 | } |
1548 | |
1701 | |
1549 | ############################################################################# |
1702 | ############################################################################# |
1550 | |
1703 | |
1551 | package CFClient::UI::VBox; |
1704 | package CFPlus::UI::VBox; |
1552 | |
1705 | |
1553 | our @ISA = CFClient::UI::Box::; |
1706 | our @ISA = CFPlus::UI::Box::; |
1554 | |
1707 | |
1555 | sub new { |
1708 | sub new { |
1556 | my $class = shift; |
1709 | my $class = shift; |
1557 | |
1710 | |
1558 | $class->SUPER::new ( |
1711 | $class->SUPER::new ( |
… | |
… | |
1561 | ) |
1714 | ) |
1562 | } |
1715 | } |
1563 | |
1716 | |
1564 | ############################################################################# |
1717 | ############################################################################# |
1565 | |
1718 | |
1566 | package CFClient::UI::Label; |
1719 | package CFPlus::UI::Label; |
1567 | |
1720 | |
1568 | our @ISA = CFClient::UI::DrawBG::; |
1721 | our @ISA = CFPlus::UI::DrawBG::; |
1569 | |
1722 | |
1570 | use CFClient::OpenGL; |
1723 | use CFPlus::OpenGL; |
1571 | |
1724 | |
1572 | sub new { |
1725 | sub new { |
1573 | my ($class, %arg) = @_; |
1726 | my ($class, %arg) = @_; |
1574 | |
1727 | |
1575 | my $self = $class->SUPER::new ( |
1728 | my $self = $class->SUPER::new ( |
… | |
… | |
1578 | #active_bg => none |
1731 | #active_bg => none |
1579 | #font => default_font |
1732 | #font => default_font |
1580 | #text => initial text |
1733 | #text => initial text |
1581 | #markup => initial narkup |
1734 | #markup => initial narkup |
1582 | #max_w => maximum pixel width |
1735 | #max_w => maximum pixel width |
|
|
1736 | #style => 0, # render flags |
1583 | ellipsise => 3, # end |
1737 | ellipsise => 3, # end |
1584 | layout => (new CFClient::Layout), |
1738 | layout => (new CFPlus::Layout), |
1585 | fontsize => 1, |
1739 | fontsize => 1, |
1586 | align => -1, |
1740 | align => -1, |
1587 | valign => -1, |
1741 | valign => -1, |
1588 | padding_x => 2, |
1742 | padding_x => 2, |
1589 | padding_y => 2, |
1743 | padding_y => 2, |
1590 | can_events => 0, |
1744 | can_events => 0, |
1591 | %arg |
1745 | %arg |
1592 | ); |
1746 | ); |
1593 | |
1747 | |
1594 | if (exists $self->{template}) { |
1748 | if (exists $self->{template}) { |
1595 | my $layout = new CFClient::Layout; |
1749 | my $layout = new CFPlus::Layout; |
1596 | $layout->set_text (delete $self->{template}); |
1750 | $layout->set_text (delete $self->{template}); |
1597 | $self->{template} = $layout; |
1751 | $self->{template} = $layout; |
1598 | } |
1752 | } |
1599 | |
1753 | |
1600 | if (exists $self->{markup}) { |
1754 | if (exists $self->{markup}) { |
… | |
… | |
1602 | } else { |
1756 | } else { |
1603 | $self->set_text (delete $self->{text}); |
1757 | $self->set_text (delete $self->{text}); |
1604 | } |
1758 | } |
1605 | |
1759 | |
1606 | $self |
1760 | $self |
1607 | } |
|
|
1608 | |
|
|
1609 | sub escape($) { |
|
|
1610 | local $_ = $_[0]; |
|
|
1611 | |
|
|
1612 | s/&/&/g; |
|
|
1613 | s/>/>/g; |
|
|
1614 | s/</</g; |
|
|
1615 | |
|
|
1616 | $_ |
|
|
1617 | } |
1761 | } |
1618 | |
1762 | |
1619 | sub update { |
1763 | sub update { |
1620 | my ($self) = @_; |
1764 | my ($self) = @_; |
1621 | |
1765 | |
… | |
… | |
1748 | }; |
1892 | }; |
1749 | |
1893 | |
1750 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
1894 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
1751 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
1895 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
1752 | |
1896 | |
1753 | $self->{layout}->render ($self->{ox}, $self->{oy}); |
1897 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
1754 | } |
1898 | } |
1755 | |
1899 | |
1756 | ############################################################################# |
1900 | ############################################################################# |
1757 | |
1901 | |
1758 | package CFClient::UI::EntryBase; |
1902 | package CFPlus::UI::EntryBase; |
1759 | |
1903 | |
1760 | our @ISA = CFClient::UI::Label::; |
1904 | our @ISA = CFPlus::UI::Label::; |
1761 | |
1905 | |
1762 | use CFClient::OpenGL; |
1906 | use CFPlus::OpenGL; |
1763 | |
1907 | |
1764 | sub new { |
1908 | sub new { |
1765 | my $class = shift; |
1909 | my $class = shift; |
1766 | |
1910 | |
1767 | $class->SUPER::new ( |
1911 | $class->SUPER::new ( |
… | |
… | |
1771 | active_fg => [0, 0, 0], |
1915 | active_fg => [0, 0, 0], |
1772 | can_hover => 1, |
1916 | can_hover => 1, |
1773 | can_focus => 1, |
1917 | can_focus => 1, |
1774 | valign => 0, |
1918 | valign => 0, |
1775 | can_events => 1, |
1919 | can_events => 1, |
|
|
1920 | ellipsise => 0, |
1776 | #text => ... |
1921 | #text => ... |
1777 | #hidden => "*", |
1922 | #hidden => "*", |
1778 | @_ |
1923 | @_ |
1779 | ) |
1924 | ) |
1780 | } |
1925 | } |
… | |
… | |
1829 | |
1974 | |
1830 | if ($uni == 8) { |
1975 | if ($uni == 8) { |
1831 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1976 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1832 | } elsif ($uni == 127) { |
1977 | } elsif ($uni == 127) { |
1833 | substr $text, $self->{cursor}, 1, ""; |
1978 | substr $text, $self->{cursor}, 1, ""; |
1834 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1979 | } elsif ($sym == CFPlus::SDLK_LEFT) { |
1835 | --$self->{cursor} if $self->{cursor}; |
1980 | --$self->{cursor} if $self->{cursor}; |
1836 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1981 | } elsif ($sym == CFPlus::SDLK_RIGHT) { |
1837 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1982 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1838 | } elsif ($sym == CFClient::SDLK_HOME) { |
1983 | } elsif ($sym == CFPlus::SDLK_HOME) { |
|
|
1984 | # what a hack |
|
|
1985 | $self->{cursor} = |
|
|
1986 | (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ |
|
|
1987 | ? length $1 |
|
|
1988 | : 0; |
|
|
1989 | } elsif ($sym == CFPlus::SDLK_END) { |
|
|
1990 | # uh, again |
|
|
1991 | $self->{cursor} = |
|
|
1992 | (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ |
|
|
1993 | ? $self->{cursor} + length $1 |
|
|
1994 | : length $self->{text}; |
|
|
1995 | } elsif ($uni == 21) { # ctrl-u |
|
|
1996 | $text = ""; |
1839 | $self->{cursor} = 0; |
1997 | $self->{cursor} = 0; |
1840 | } elsif ($sym == CFClient::SDLK_END) { |
|
|
1841 | $self->{cursor} = length $text; |
|
|
1842 | } elsif ($uni == 27) { |
1998 | } elsif ($uni == 27) { |
1843 | $self->emit ('escape'); |
1999 | $self->emit ('escape'); |
1844 | } elsif ($uni) { |
2000 | } elsif ($uni == 0x0d) { |
|
|
2001 | substr $text, $self->{cursor}++, 0, "\012"; |
|
|
2002 | } elsif ($uni >= 0x20) { |
1845 | substr $text, $self->{cursor}++, 0, chr $uni; |
2003 | substr $text, $self->{cursor}++, 0, chr $uni; |
1846 | } else { |
2004 | } else { |
1847 | return 0; |
2005 | return 0; |
1848 | } |
2006 | } |
1849 | |
2007 | |
1850 | $self->_set_text ($text); |
2008 | $self->_set_text ($text); |
1851 | |
2009 | |
1852 | $self->realloc; |
2010 | $self->realloc; |
|
|
2011 | $self->update; |
1853 | |
2012 | |
1854 | 1 |
2013 | 1 |
1855 | } |
2014 | } |
1856 | |
2015 | |
1857 | sub invoke_focus_in { |
2016 | sub invoke_focus_in { |
… | |
… | |
1919 | utf8::encode $text; |
2078 | utf8::encode $text; |
1920 | |
2079 | |
1921 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
2080 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
1922 | } |
2081 | } |
1923 | |
2082 | |
1924 | glColor @{$self->{fg}}; |
|
|
1925 | glBegin GL_LINES; |
2083 | glBegin GL_LINES; |
1926 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2084 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
1927 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2085 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
1928 | glEnd; |
2086 | glEnd; |
1929 | } |
2087 | } |
1930 | } |
2088 | } |
1931 | |
2089 | |
|
|
2090 | ############################################################################# |
|
|
2091 | |
1932 | package CFClient::UI::Entry; |
2092 | package CFPlus::UI::Entry; |
1933 | |
2093 | |
1934 | our @ISA = CFClient::UI::EntryBase::; |
2094 | our @ISA = CFPlus::UI::EntryBase::; |
1935 | |
2095 | |
1936 | use CFClient::OpenGL; |
2096 | use CFPlus::OpenGL; |
1937 | |
2097 | |
1938 | sub invoke_key_down { |
2098 | sub invoke_key_down { |
1939 | my ($self, $ev) = @_; |
2099 | my ($self, $ev) = @_; |
1940 | |
2100 | |
1941 | my $sym = $ev->{sym}; |
2101 | my $sym = $ev->{sym}; |
1942 | |
2102 | |
1943 | if ($sym == 13) { |
2103 | if ($ev->{uni} == 0x0d || $sym == 13) { |
1944 | unshift @{$self->{history}}, |
2104 | unshift @{$self->{history}}, |
1945 | my $txt = $self->get_text; |
2105 | my $txt = $self->get_text; |
1946 | |
2106 | |
1947 | $self->{history_pointer} = -1; |
2107 | $self->{history_pointer} = -1; |
1948 | $self->{history_saveback} = ''; |
2108 | $self->{history_saveback} = ''; |
1949 | $self->emit (activate => $txt); |
2109 | $self->emit (activate => $txt); |
1950 | $self->update; |
2110 | $self->update; |
1951 | |
2111 | |
1952 | } elsif ($sym == CFClient::SDLK_UP) { |
2112 | } elsif ($sym == CFPlus::SDLK_UP) { |
1953 | if ($self->{history_pointer} < 0) { |
2113 | if ($self->{history_pointer} < 0) { |
1954 | $self->{history_saveback} = $self->get_text; |
2114 | $self->{history_saveback} = $self->get_text; |
1955 | } |
2115 | } |
1956 | if (@{$self->{history} || []} > 0) { |
2116 | if (@{$self->{history} || []} > 0) { |
1957 | $self->{history_pointer}++; |
2117 | $self->{history_pointer}++; |
… | |
… | |
1959 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
2119 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
1960 | } |
2120 | } |
1961 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2121 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
1962 | } |
2122 | } |
1963 | |
2123 | |
1964 | } elsif ($sym == CFClient::SDLK_DOWN) { |
2124 | } elsif ($sym == CFPlus::SDLK_DOWN) { |
1965 | $self->{history_pointer}--; |
2125 | $self->{history_pointer}--; |
1966 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
2126 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
1967 | |
2127 | |
1968 | if ($self->{history_pointer} >= 0) { |
2128 | if ($self->{history_pointer} >= 0) { |
1969 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2129 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
… | |
… | |
1978 | 1 |
2138 | 1 |
1979 | } |
2139 | } |
1980 | |
2140 | |
1981 | ############################################################################# |
2141 | ############################################################################# |
1982 | |
2142 | |
|
|
2143 | package CFPlus::UI::TextEdit; |
|
|
2144 | |
|
|
2145 | our @ISA = CFPlus::UI::EntryBase::; |
|
|
2146 | |
|
|
2147 | use CFPlus::OpenGL; |
|
|
2148 | |
|
|
2149 | sub move_cursor_ver { |
|
|
2150 | my ($self, $dy) = @_; |
|
|
2151 | |
|
|
2152 | my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); |
|
|
2153 | |
|
|
2154 | $y += $dy; |
|
|
2155 | |
|
|
2156 | if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { |
|
|
2157 | $self->{cursor} = $index; |
|
|
2158 | delete $self->{cur_h}; |
|
|
2159 | $self->update; |
|
|
2160 | return; |
|
|
2161 | } |
|
|
2162 | } |
|
|
2163 | |
|
|
2164 | sub invoke_key_down { |
|
|
2165 | my ($self, $ev) = @_; |
|
|
2166 | |
|
|
2167 | my $sym = $ev->{sym}; |
|
|
2168 | |
|
|
2169 | if ($sym == CFPlus::SDLK_UP) { |
|
|
2170 | $self->move_cursor_ver (-1); |
|
|
2171 | } elsif ($sym == CFPlus::SDLK_DOWN) { |
|
|
2172 | $self->move_cursor_ver (+1); |
|
|
2173 | } else { |
|
|
2174 | return $self->SUPER::invoke_key_down ($ev) |
|
|
2175 | } |
|
|
2176 | |
|
|
2177 | 1 |
|
|
2178 | } |
|
|
2179 | |
|
|
2180 | ############################################################################# |
|
|
2181 | |
1983 | package CFClient::UI::Button; |
2182 | package CFPlus::UI::Button; |
1984 | |
2183 | |
1985 | our @ISA = CFClient::UI::Label::; |
2184 | our @ISA = CFPlus::UI::Label::; |
1986 | |
2185 | |
1987 | use CFClient::OpenGL; |
2186 | use CFPlus::OpenGL; |
1988 | |
2187 | |
1989 | my @tex = |
2188 | my @tex = |
1990 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
2189 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1991 | qw(b1_button_active.png); |
2190 | qw(b1_button_active.png); |
1992 | |
2191 | |
1993 | sub new { |
2192 | sub new { |
1994 | my $class = shift; |
2193 | my $class = shift; |
1995 | |
2194 | |
… | |
… | |
2032 | $self->SUPER::_draw; |
2231 | $self->SUPER::_draw; |
2033 | } |
2232 | } |
2034 | |
2233 | |
2035 | ############################################################################# |
2234 | ############################################################################# |
2036 | |
2235 | |
|
|
2236 | package CFPlus::UI::CheckBox; |
|
|
2237 | |
|
|
2238 | our @ISA = CFPlus::UI::DrawBG::; |
|
|
2239 | |
|
|
2240 | my @tex = |
|
|
2241 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
|
|
2242 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
|
|
2243 | |
|
|
2244 | use CFPlus::OpenGL; |
|
|
2245 | |
|
|
2246 | sub new { |
|
|
2247 | my $class = shift; |
|
|
2248 | |
|
|
2249 | $class->SUPER::new ( |
|
|
2250 | padding_x => 2, |
|
|
2251 | padding_y => 2, |
|
|
2252 | fg => [1, 1, 1], |
|
|
2253 | active_fg => [1, 1, 0], |
|
|
2254 | bg => [0, 0, 0, 0.2], |
|
|
2255 | active_bg => [1, 1, 1, 0.5], |
|
|
2256 | state => 0, |
|
|
2257 | can_hover => 1, |
|
|
2258 | @_ |
|
|
2259 | ) |
|
|
2260 | } |
|
|
2261 | |
|
|
2262 | sub size_request { |
|
|
2263 | my ($self) = @_; |
|
|
2264 | |
|
|
2265 | (6) x 2 |
|
|
2266 | } |
|
|
2267 | |
|
|
2268 | sub toggle { |
|
|
2269 | my ($self) = @_; |
|
|
2270 | |
|
|
2271 | $self->{state} = !$self->{state}; |
|
|
2272 | $self->emit (changed => $self->{state}); |
|
|
2273 | $self->update; |
|
|
2274 | } |
|
|
2275 | |
|
|
2276 | sub invoke_button_down { |
|
|
2277 | my ($self, $ev, $x, $y) = @_; |
|
|
2278 | |
|
|
2279 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
|
|
2280 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
|
|
2281 | $self->toggle; |
|
|
2282 | } else { |
|
|
2283 | return 0 |
|
|
2284 | } |
|
|
2285 | |
|
|
2286 | 1 |
|
|
2287 | } |
|
|
2288 | |
|
|
2289 | sub _draw { |
|
|
2290 | my ($self) = @_; |
|
|
2291 | |
|
|
2292 | $self->SUPER::_draw; |
|
|
2293 | |
|
|
2294 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
|
|
2295 | |
|
|
2296 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2297 | |
|
|
2298 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
|
|
2299 | |
|
|
2300 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
|
|
2301 | |
|
|
2302 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
2303 | |
|
|
2304 | glEnable GL_TEXTURE_2D; |
|
|
2305 | $tex->draw_quad_alpha (0, 0, $s, $s); |
|
|
2306 | glDisable GL_TEXTURE_2D; |
|
|
2307 | } |
|
|
2308 | |
|
|
2309 | ############################################################################# |
|
|
2310 | |
|
|
2311 | package CFPlus::UI::Image; |
|
|
2312 | |
|
|
2313 | our @ISA = CFPlus::UI::Base::; |
|
|
2314 | |
|
|
2315 | use CFPlus::OpenGL; |
|
|
2316 | |
|
|
2317 | our %texture_cache; |
|
|
2318 | |
|
|
2319 | sub new { |
|
|
2320 | my $class = shift; |
|
|
2321 | |
|
|
2322 | my $self = $class->SUPER::new ( |
|
|
2323 | can_events => 0, |
|
|
2324 | @_, |
|
|
2325 | ); |
|
|
2326 | |
|
|
2327 | $self->{path} || $self->{tex} |
|
|
2328 | or Carp::croak "'path' or 'tex' attributes required"; |
|
|
2329 | |
|
|
2330 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
|
|
2331 | new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; |
|
|
2332 | |
|
|
2333 | CFPlus::weaken $texture_cache{$self->{path}}; |
|
|
2334 | |
|
|
2335 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
|
|
2336 | |
|
|
2337 | $self |
|
|
2338 | } |
|
|
2339 | |
|
|
2340 | sub STORABLE_freeze { |
|
|
2341 | my ($self, $cloning) = @_; |
|
|
2342 | |
|
|
2343 | $self->{path} |
|
|
2344 | or die "cannot serialise CFPlus::UI::Image on non-loadable images\n"; |
|
|
2345 | |
|
|
2346 | $self->{path} |
|
|
2347 | } |
|
|
2348 | |
|
|
2349 | sub STORABLE_attach { |
|
|
2350 | my ($self, $cloning, $path) = @_; |
|
|
2351 | |
|
|
2352 | $self->new (path => $path) |
|
|
2353 | } |
|
|
2354 | |
|
|
2355 | sub size_request { |
|
|
2356 | my ($self) = @_; |
|
|
2357 | |
|
|
2358 | ($self->{tex}{w}, $self->{tex}{h}) |
|
|
2359 | } |
|
|
2360 | |
|
|
2361 | sub _draw { |
|
|
2362 | my ($self) = @_; |
|
|
2363 | |
|
|
2364 | my $tex = $self->{tex}; |
|
|
2365 | |
|
|
2366 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
2367 | |
|
|
2368 | if ($self->{rot90}) { |
|
|
2369 | glRotate 90, 0, 0, 1; |
|
|
2370 | glTranslate 0, -$self->{w}, 0; |
|
|
2371 | |
|
|
2372 | ($w, $h) = ($h, $w); |
|
|
2373 | } |
|
|
2374 | |
|
|
2375 | glEnable GL_TEXTURE_2D; |
|
|
2376 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2377 | |
|
|
2378 | $tex->draw_quad (0, 0, $w, $h); |
|
|
2379 | |
|
|
2380 | glDisable GL_TEXTURE_2D; |
|
|
2381 | } |
|
|
2382 | |
|
|
2383 | ############################################################################# |
|
|
2384 | |
2037 | package CFClient::UI::ImageButton; |
2385 | package CFPlus::UI::ImageButton; |
2038 | |
2386 | |
2039 | our @ISA = CFClient::UI::Image::; |
2387 | our @ISA = CFPlus::UI::Image::; |
2040 | |
2388 | |
2041 | use CFClient::OpenGL; |
2389 | use CFPlus::OpenGL; |
2042 | |
2390 | |
2043 | my %textures; |
2391 | my %textures; |
2044 | |
2392 | |
2045 | sub new { |
2393 | sub new { |
2046 | my $class = shift; |
2394 | my $class = shift; |
… | |
… | |
2068 | 1 |
2416 | 1 |
2069 | } |
2417 | } |
2070 | |
2418 | |
2071 | ############################################################################# |
2419 | ############################################################################# |
2072 | |
2420 | |
2073 | package CFClient::UI::CheckBox; |
|
|
2074 | |
|
|
2075 | our @ISA = CFClient::UI::DrawBG::; |
|
|
2076 | |
|
|
2077 | my @tex = |
|
|
2078 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
2079 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
|
|
2080 | |
|
|
2081 | use CFClient::OpenGL; |
|
|
2082 | |
|
|
2083 | sub new { |
|
|
2084 | my $class = shift; |
|
|
2085 | |
|
|
2086 | $class->SUPER::new ( |
|
|
2087 | padding_x => 2, |
|
|
2088 | padding_y => 2, |
|
|
2089 | fg => [1, 1, 1], |
|
|
2090 | active_fg => [1, 1, 0], |
|
|
2091 | bg => [0, 0, 0, 0.2], |
|
|
2092 | active_bg => [1, 1, 1, 0.5], |
|
|
2093 | state => 0, |
|
|
2094 | can_hover => 1, |
|
|
2095 | @_ |
|
|
2096 | ) |
|
|
2097 | } |
|
|
2098 | |
|
|
2099 | sub size_request { |
|
|
2100 | my ($self) = @_; |
|
|
2101 | |
|
|
2102 | (6) x 2 |
|
|
2103 | } |
|
|
2104 | |
|
|
2105 | sub toggle { |
|
|
2106 | my ($self) = @_; |
|
|
2107 | |
|
|
2108 | $self->{state} = !$self->{state}; |
|
|
2109 | $self->emit (changed => $self->{state}); |
|
|
2110 | $self->update; |
|
|
2111 | } |
|
|
2112 | |
|
|
2113 | sub invoke_button_down { |
|
|
2114 | my ($self, $ev, $x, $y) = @_; |
|
|
2115 | |
|
|
2116 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
|
|
2117 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
|
|
2118 | $self->toggle; |
|
|
2119 | } else { |
|
|
2120 | return 0 |
|
|
2121 | } |
|
|
2122 | |
|
|
2123 | 1 |
|
|
2124 | } |
|
|
2125 | |
|
|
2126 | sub _draw { |
|
|
2127 | my ($self) = @_; |
|
|
2128 | |
|
|
2129 | $self->SUPER::_draw; |
|
|
2130 | |
|
|
2131 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
|
|
2132 | |
|
|
2133 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2134 | |
|
|
2135 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
|
|
2136 | |
|
|
2137 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
|
|
2138 | |
|
|
2139 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
2140 | |
|
|
2141 | glEnable GL_TEXTURE_2D; |
|
|
2142 | $tex->draw_quad_alpha (0, 0, $s, $s); |
|
|
2143 | glDisable GL_TEXTURE_2D; |
|
|
2144 | } |
|
|
2145 | |
|
|
2146 | ############################################################################# |
|
|
2147 | |
|
|
2148 | package CFClient::UI::Image; |
2421 | package CFPlus::UI::VGauge; |
2149 | |
2422 | |
2150 | our @ISA = CFClient::UI::Base::; |
2423 | our @ISA = CFPlus::UI::Base::; |
2151 | |
|
|
2152 | use CFClient::OpenGL; |
|
|
2153 | |
|
|
2154 | our %texture_cache; |
|
|
2155 | |
|
|
2156 | sub new { |
|
|
2157 | my $class = shift; |
|
|
2158 | |
|
|
2159 | my $self = $class->SUPER::new ( |
|
|
2160 | can_events => 0, |
|
|
2161 | @_, |
|
|
2162 | ); |
|
|
2163 | |
|
|
2164 | $self->{path} || $self->{tex} |
|
|
2165 | or Carp::croak "'path' or 'tex' attributes required"; |
|
|
2166 | |
|
|
2167 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
|
|
2168 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1; |
|
|
2169 | |
|
|
2170 | Scalar::Util::weaken $texture_cache{$self->{path}}; |
|
|
2171 | |
|
|
2172 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
|
|
2173 | |
|
|
2174 | $self |
|
|
2175 | } |
|
|
2176 | |
|
|
2177 | sub size_request { |
|
|
2178 | my ($self) = @_; |
|
|
2179 | |
|
|
2180 | ($self->{tex}{w}, $self->{tex}{h}) |
|
|
2181 | } |
|
|
2182 | |
|
|
2183 | sub _draw { |
|
|
2184 | my ($self) = @_; |
|
|
2185 | |
|
|
2186 | my $tex = $self->{tex}; |
|
|
2187 | |
|
|
2188 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
2189 | |
|
|
2190 | if ($self->{rot90}) { |
|
|
2191 | glRotate 90, 0, 0, 1; |
|
|
2192 | glTranslate 0, -$self->{w}, 0; |
|
|
2193 | |
|
|
2194 | ($w, $h) = ($h, $w); |
|
|
2195 | } |
|
|
2196 | |
|
|
2197 | glEnable GL_TEXTURE_2D; |
|
|
2198 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2199 | |
|
|
2200 | $tex->draw_quad_alpha (0, 0, $w, $h); |
|
|
2201 | |
|
|
2202 | glDisable GL_TEXTURE_2D; |
|
|
2203 | } |
|
|
2204 | |
|
|
2205 | ############################################################################# |
|
|
2206 | |
|
|
2207 | package CFClient::UI::VGauge; |
|
|
2208 | |
|
|
2209 | our @ISA = CFClient::UI::Base::; |
|
|
2210 | |
2424 | |
2211 | use List::Util qw(min max); |
2425 | use List::Util qw(min max); |
2212 | |
2426 | |
2213 | use CFClient::OpenGL; |
2427 | use CFPlus::OpenGL; |
2214 | |
2428 | |
2215 | my %tex = ( |
2429 | my %tex = ( |
2216 | food => [ |
2430 | food => [ |
2217 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
2431 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2218 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
2432 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
2219 | ], |
2433 | ], |
2220 | grace => [ |
2434 | grace => [ |
2221 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
2435 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2222 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
2436 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
2223 | ], |
2437 | ], |
2224 | hp => [ |
2438 | hp => [ |
2225 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
2439 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2226 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
2440 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
2227 | ], |
2441 | ], |
2228 | mana => [ |
2442 | mana => [ |
2229 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
2443 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2230 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
2444 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
2231 | ], |
2445 | ], |
2232 | ); |
2446 | ); |
2233 | |
2447 | |
2234 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
2448 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
… | |
… | |
2337 | glDisable GL_TEXTURE_2D; |
2551 | glDisable GL_TEXTURE_2D; |
2338 | } |
2552 | } |
2339 | |
2553 | |
2340 | ############################################################################# |
2554 | ############################################################################# |
2341 | |
2555 | |
2342 | package CFClient::UI::Gauge; |
2556 | package CFPlus::UI::Gauge; |
2343 | |
2557 | |
2344 | our @ISA = CFClient::UI::VBox::; |
2558 | our @ISA = CFPlus::UI::VBox::; |
2345 | |
2559 | |
2346 | sub new { |
2560 | sub new { |
2347 | my ($class, %arg) = @_; |
2561 | my ($class, %arg) = @_; |
2348 | |
2562 | |
2349 | my $self = $class->SUPER::new ( |
2563 | my $self = $class->SUPER::new ( |
… | |
… | |
2351 | can_hover => 1, |
2565 | can_hover => 1, |
2352 | can_events => 1, |
2566 | can_events => 1, |
2353 | %arg, |
2567 | %arg, |
2354 | ); |
2568 | ); |
2355 | |
2569 | |
2356 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
2570 | $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999"); |
2357 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
2571 | $self->add ($self->{gauge} = new CFPlus::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
2358 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); |
2572 | $self->add ($self->{max} = new CFPlus::UI::Label valign => -1, align => 0, template => "999"); |
2359 | |
2573 | |
2360 | $self |
2574 | $self |
2361 | } |
2575 | } |
2362 | |
2576 | |
2363 | sub set_fontsize { |
2577 | sub set_fontsize { |
… | |
… | |
2384 | $self->{value}->set_text ($val); |
2598 | $self->{value}->set_text ($val); |
2385 | } |
2599 | } |
2386 | |
2600 | |
2387 | ############################################################################# |
2601 | ############################################################################# |
2388 | |
2602 | |
2389 | package CFClient::UI::Slider; |
2603 | package CFPlus::UI::Slider; |
2390 | |
2604 | |
2391 | use strict; |
2605 | use strict; |
2392 | |
2606 | |
2393 | use CFClient::OpenGL; |
2607 | use CFPlus::OpenGL; |
2394 | |
2608 | |
2395 | our @ISA = CFClient::UI::DrawBG::; |
2609 | our @ISA = CFPlus::UI::DrawBG::; |
2396 | |
2610 | |
2397 | my @tex = |
2611 | my @tex = |
2398 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
2612 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ } |
2399 | qw(s1_slider.png s1_slider_bg.png); |
2613 | qw(s1_slider.png s1_slider_bg.png); |
2400 | |
2614 | |
2401 | sub new { |
2615 | sub new { |
2402 | my $class = shift; |
2616 | my $class = shift; |
2403 | |
2617 | |
… | |
… | |
2497 | sub invoke_mouse_wheel { |
2711 | sub invoke_mouse_wheel { |
2498 | my ($self, $ev) = @_; |
2712 | my ($self, $ev) = @_; |
2499 | |
2713 | |
2500 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
2714 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
2501 | |
2715 | |
|
|
2716 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
|
|
2717 | |
2502 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.1); |
2718 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2503 | |
2719 | |
2504 | ! ! $delta |
2720 | ! ! $delta |
2505 | } |
2721 | } |
2506 | |
2722 | |
2507 | sub update { |
2723 | sub update { |
… | |
… | |
2558 | glDisable GL_TEXTURE_2D; |
2774 | glDisable GL_TEXTURE_2D; |
2559 | } |
2775 | } |
2560 | |
2776 | |
2561 | ############################################################################# |
2777 | ############################################################################# |
2562 | |
2778 | |
2563 | package CFClient::UI::ValSlider; |
2779 | package CFPlus::UI::ValSlider; |
2564 | |
2780 | |
2565 | our @ISA = CFClient::UI::HBox::; |
2781 | our @ISA = CFPlus::UI::HBox::; |
2566 | |
2782 | |
2567 | sub new { |
2783 | sub new { |
2568 | my ($class, %arg) = @_; |
2784 | my ($class, %arg) = @_; |
2569 | |
2785 | |
2570 | my $range = delete $arg{range}; |
2786 | my $range = delete $arg{range}; |
2571 | |
2787 | |
2572 | my $self = $class->SUPER::new ( |
2788 | my $self = $class->SUPER::new ( |
2573 | slider => (new CFClient::UI::Slider expand => 1, range => $range), |
2789 | slider => (new CFPlus::UI::Slider expand => 1, range => $range), |
2574 | entry => (new CFClient::UI::Label text => "", template => delete $arg{template}), |
2790 | entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}), |
2575 | to_value => sub { shift }, |
2791 | to_value => sub { shift }, |
2576 | from_value => sub { shift }, |
2792 | from_value => sub { shift }, |
2577 | %arg, |
2793 | %arg, |
2578 | ); |
2794 | ); |
2579 | |
2795 | |
… | |
… | |
2599 | sub set_range { shift->{slider}->set_range (@_) } |
2815 | sub set_range { shift->{slider}->set_range (@_) } |
2600 | sub set_value { shift->{slider}->set_value (@_) } |
2816 | sub set_value { shift->{slider}->set_value (@_) } |
2601 | |
2817 | |
2602 | ############################################################################# |
2818 | ############################################################################# |
2603 | |
2819 | |
2604 | package CFClient::UI::TextScroller; |
2820 | package CFPlus::UI::TextScroller; |
2605 | |
2821 | |
2606 | our @ISA = CFClient::UI::HBox::; |
2822 | our @ISA = CFPlus::UI::HBox::; |
2607 | |
2823 | |
2608 | use CFClient::OpenGL; |
2824 | use CFPlus::OpenGL; |
2609 | |
2825 | |
2610 | sub new { |
2826 | sub new { |
2611 | my $class = shift; |
2827 | my $class = shift; |
2612 | |
2828 | |
2613 | my $self = $class->SUPER::new ( |
2829 | my $self = $class->SUPER::new ( |
… | |
… | |
2615 | can_events => 1, |
2831 | can_events => 1, |
2616 | indent => 0, |
2832 | indent => 0, |
2617 | #font => default_font |
2833 | #font => default_font |
2618 | @_, |
2834 | @_, |
2619 | |
2835 | |
2620 | layout => (new CFClient::Layout), |
2836 | layout => (new CFPlus::Layout), |
2621 | par => [], |
2837 | par => [], |
|
|
2838 | max_par => 0, |
2622 | height => 0, |
2839 | height => 0, |
2623 | children => [ |
2840 | children => [ |
2624 | (new CFClient::UI::Empty expand => 1), |
2841 | (new CFPlus::UI::Empty expand => 1), |
2625 | (new CFClient::UI::Slider vertical => 1), |
2842 | (new CFPlus::UI::Slider vertical => 1), |
2626 | ], |
2843 | ], |
2627 | ); |
2844 | ); |
2628 | |
2845 | |
2629 | $self->{children}[1]->connect (changed => sub { $self->update }); |
2846 | $self->{children}[1]->connect (changed => sub { $self->update }); |
2630 | |
2847 | |
… | |
… | |
2707 | |
2924 | |
2708 | # todo: base offset on lines or so, not on pixels |
2925 | # todo: base offset on lines or so, not on pixels |
2709 | $self->{children}[1]->set_value ($offset); |
2926 | $self->{children}[1]->set_value ($offset); |
2710 | } |
2927 | } |
2711 | |
2928 | |
|
|
2929 | sub current_paragraph { |
|
|
2930 | my ($self) = @_; |
|
|
2931 | |
|
|
2932 | $self->{top_paragraph} - 1 |
|
|
2933 | } |
|
|
2934 | |
|
|
2935 | sub scroll_to { |
|
|
2936 | my ($self, $para) = @_; |
|
|
2937 | |
|
|
2938 | $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para; |
|
|
2939 | |
|
|
2940 | $self->{scroll_to} = $para; |
|
|
2941 | $self->update; |
|
|
2942 | } |
|
|
2943 | |
2712 | sub clear { |
2944 | sub clear { |
2713 | my ($self) = @_; |
2945 | my ($self) = @_; |
2714 | |
2946 | |
2715 | my (undef, undef, @other) = @{ $self->{children} }; |
2947 | my (undef, undef, @other) = @{ $self->{children} }; |
2716 | $self->remove ($_) for @other; |
2948 | $self->remove ($_) for @other; |
… | |
… | |
2719 | $self->{height} = 0; |
2951 | $self->{height} = 0; |
2720 | $self->{children}[1]->set_range ([0, 0, 0, 1, 1]); |
2952 | $self->{children}[1]->set_range ([0, 0, 0, 1, 1]); |
2721 | } |
2953 | } |
2722 | |
2954 | |
2723 | sub add_paragraph { |
2955 | sub add_paragraph { |
2724 | my ($self, $color, $para, $indent) = @_; |
2956 | my $self = shift; |
2725 | |
2957 | |
2726 | my ($text, @w) = ref $para ? @$para : $para; |
2958 | for my $para (@_) { |
2727 | |
|
|
2728 | $para = { |
2959 | $para = { |
|
|
2960 | fg => [1, 1, 1, 1], |
|
|
2961 | indent => 0, |
|
|
2962 | markup => "", |
|
|
2963 | widget => [], |
|
|
2964 | ref $para ? %$para : (markup => $para), |
2729 | w => 1e10, |
2965 | w => 1e10, |
2730 | wrapped => 1, |
2966 | wrapped => 1, |
2731 | fg => $color, |
|
|
2732 | indent => $indent, |
|
|
2733 | markup => $text, |
|
|
2734 | widget => \@w, |
|
|
2735 | }; |
2967 | }; |
2736 | |
2968 | |
2737 | $self->add (@w) if @w; |
2969 | $self->add (@{ $para->{widget} }) if @{ $para->{widget} }; |
2738 | push @{$self->{par}}, $para; |
2970 | push @{$self->{par}}, $para; |
|
|
2971 | } |
|
|
2972 | |
|
|
2973 | if (my $max = $self->{max_par}) { |
|
|
2974 | shift @{$self->{par}} while @{$self->{par}} > $max; |
|
|
2975 | } |
2739 | |
2976 | |
2740 | $self->{need_reflow}++; |
2977 | $self->{need_reflow}++; |
2741 | $self->update; |
2978 | $self->update; |
2742 | } |
2979 | } |
2743 | |
2980 | |
2744 | sub scroll_to_bottom { |
2981 | sub scroll_to_bottom { |
2745 | my ($self) = @_; |
2982 | my ($self) = @_; |
2746 | |
2983 | |
2747 | $self->{scroll_to_bottom} = 1; |
2984 | $self->{scroll_to} = $#{$self->{par}}; |
2748 | $self->update; |
2985 | $self->update; |
2749 | } |
2986 | } |
2750 | |
2987 | |
|
|
2988 | sub force_uptodate { |
|
|
2989 | my ($self) = @_; |
|
|
2990 | |
|
|
2991 | if (delete $self->{need_reflow}) { |
|
|
2992 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
|
|
2993 | |
|
|
2994 | my $height = 0; |
|
|
2995 | |
|
|
2996 | for my $para (@{$self->{par}}) { |
|
|
2997 | if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { |
|
|
2998 | my $layout = $self->get_layout ($para); |
|
|
2999 | my ($w, $h) = $layout->size; |
|
|
3000 | |
|
|
3001 | $para->{w} = $w + $para->{indent}; |
|
|
3002 | $para->{h} = $h; |
|
|
3003 | $para->{wrapped} = $layout->has_wrapped; |
|
|
3004 | } |
|
|
3005 | |
|
|
3006 | $para->{y} = $height; |
|
|
3007 | $height += $para->{h}; |
|
|
3008 | } |
|
|
3009 | |
|
|
3010 | $self->{height} = $height; |
|
|
3011 | $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); |
|
|
3012 | |
|
|
3013 | delete $self->{texture}; |
|
|
3014 | } |
|
|
3015 | |
|
|
3016 | if (my $paridx = delete $self->{scroll_to}) { |
|
|
3017 | $self->{children}[1]->set_value ($self->{par}[$paridx]{y}); |
|
|
3018 | } |
|
|
3019 | } |
|
|
3020 | |
2751 | sub update { |
3021 | sub update { |
2752 | my ($self) = @_; |
3022 | my ($self) = @_; |
2753 | |
3023 | |
2754 | $self->SUPER::update; |
3024 | $self->SUPER::update; |
2755 | |
3025 | |
2756 | return unless $self->{h} > 0; |
3026 | return unless $self->{h} > 0; |
2757 | |
3027 | |
2758 | delete $self->{texture}; |
3028 | delete $self->{texture}; |
2759 | |
3029 | |
2760 | $ROOT->on_post_alloc ($self => sub { |
3030 | $ROOT->on_post_alloc ($self => sub { |
|
|
3031 | $self->force_uptodate; |
|
|
3032 | |
2761 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
3033 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2762 | |
3034 | |
2763 | if (delete $self->{need_reflow}) { |
|
|
2764 | my $height = 0; |
|
|
2765 | |
|
|
2766 | for my $para (@{$self->{par}}) { |
|
|
2767 | if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { |
|
|
2768 | my $layout = $self->get_layout ($para); |
|
|
2769 | my ($w, $h) = $layout->size; |
|
|
2770 | |
|
|
2771 | $para->{w} = $w + $para->{indent}; |
|
|
2772 | $para->{h} = $h; |
|
|
2773 | $para->{wrapped} = $layout->has_wrapped; |
|
|
2774 | } |
|
|
2775 | |
|
|
2776 | $height += $para->{h}; |
|
|
2777 | } |
|
|
2778 | |
|
|
2779 | $self->{height} = $height; |
|
|
2780 | |
|
|
2781 | $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); |
|
|
2782 | |
|
|
2783 | delete $self->{texture}; |
|
|
2784 | } |
|
|
2785 | |
|
|
2786 | if (delete $self->{scroll_to_bottom}) { |
|
|
2787 | $self->{children}[1]->set_value (1e10); |
|
|
2788 | } |
|
|
2789 | |
|
|
2790 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
3035 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
2791 | glClearColor 0, 0, 0, 0; |
3036 | glClearColor 0, 0, 0, 0; |
2792 | glClear GL_COLOR_BUFFER_BIT; |
3037 | glClear GL_COLOR_BUFFER_BIT; |
2793 | |
3038 | |
|
|
3039 | package CFPlus::UI::Base; |
|
|
3040 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
|
|
3041 | (0, 0, $self->{w}, $self->{h}); |
|
|
3042 | |
|
|
3043 | my $top = int $self->{children}[1]{range}[0]; |
|
|
3044 | |
|
|
3045 | my $paridx = 0; |
|
|
3046 | my $top_paragraph; |
2794 | my $top = int $self->{children}[1]{range}[0]; |
3047 | my $top = int $self->{children}[1]{range}[0]; |
2795 | |
3048 | |
2796 | my $y0 = $top; |
3049 | my $y0 = $top; |
2797 | my $y1 = $top + $H; |
3050 | my $y1 = $top + $H; |
2798 | |
3051 | |
2799 | my $y = 0; |
|
|
2800 | |
|
|
2801 | for my $para (@{$self->{par}}) { |
3052 | for my $para (@{$self->{par}}) { |
2802 | my $h = $para->{h}; |
3053 | my $h = $para->{h}; |
|
|
3054 | my $y = $para->{y}; |
2803 | |
3055 | |
2804 | if ($y0 < $y + $h && $y < $y1) { |
3056 | if ($y0 < $y + $h && $y < $y1) { |
2805 | |
|
|
2806 | my $layout = $self->get_layout ($para); |
3057 | my $layout = $self->get_layout ($para); |
2807 | |
3058 | |
2808 | $layout->render ($para->{indent}, $y - $y0); |
3059 | $layout->render ($para->{indent}, $y - $y0); |
2809 | |
3060 | |
2810 | if (my @w = @{ $para->{widget} }) { |
3061 | if (my @w = @{ $para->{widget} }) { |
… | |
… | |
2819 | $_->draw; |
3070 | $_->draw; |
2820 | } |
3071 | } |
2821 | } |
3072 | } |
2822 | } |
3073 | } |
2823 | |
3074 | |
2824 | $y += $h; |
3075 | $paridx++; |
|
|
3076 | $top_paragraph ||= $paridx if $y >= $top; |
2825 | } |
3077 | } |
|
|
3078 | |
|
|
3079 | $self->{top_paragraph} = $top_paragraph; |
2826 | }; |
3080 | }; |
2827 | }); |
3081 | }); |
2828 | } |
3082 | } |
2829 | |
3083 | |
2830 | sub reconfigure { |
3084 | sub reconfigure { |
… | |
… | |
2848 | $self->{children}[1]->draw; |
3102 | $self->{children}[1]->draw; |
2849 | } |
3103 | } |
2850 | |
3104 | |
2851 | ############################################################################# |
3105 | ############################################################################# |
2852 | |
3106 | |
2853 | package CFClient::UI::Animator; |
3107 | package CFPlus::UI::Animator; |
2854 | |
3108 | |
2855 | use CFClient::OpenGL; |
3109 | use CFPlus::OpenGL; |
2856 | |
3110 | |
2857 | our @ISA = CFClient::UI::Bin::; |
3111 | our @ISA = CFPlus::UI::Bin::; |
2858 | |
3112 | |
2859 | sub moveto { |
3113 | sub moveto { |
2860 | my ($self, $x, $y) = @_; |
3114 | my ($self, $x, $y) = @_; |
2861 | |
3115 | |
2862 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
3116 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
… | |
… | |
2890 | glPopMatrix; |
3144 | glPopMatrix; |
2891 | } |
3145 | } |
2892 | |
3146 | |
2893 | ############################################################################# |
3147 | ############################################################################# |
2894 | |
3148 | |
2895 | package CFClient::UI::Flopper; |
3149 | package CFPlus::UI::Flopper; |
2896 | |
3150 | |
2897 | our @ISA = CFClient::UI::Button::; |
3151 | our @ISA = CFPlus::UI::Button::; |
2898 | |
3152 | |
2899 | sub new { |
3153 | sub new { |
2900 | my $class = shift; |
3154 | my $class = shift; |
2901 | |
3155 | |
2902 | my $self = $class->SUPER::new ( |
3156 | my $self = $class->SUPER::new ( |
… | |
… | |
2914 | $self->{other}->toggle_visibility; |
3168 | $self->{other}->toggle_visibility; |
2915 | } |
3169 | } |
2916 | |
3170 | |
2917 | ############################################################################# |
3171 | ############################################################################# |
2918 | |
3172 | |
2919 | package CFClient::UI::Tooltip; |
3173 | package CFPlus::UI::Tooltip; |
2920 | |
3174 | |
2921 | our @ISA = CFClient::UI::Bin::; |
3175 | our @ISA = CFPlus::UI::Bin::; |
2922 | |
3176 | |
2923 | use CFClient::OpenGL; |
3177 | use CFPlus::OpenGL; |
2924 | |
3178 | |
2925 | sub new { |
3179 | sub new { |
2926 | my $class = shift; |
3180 | my $class = shift; |
2927 | |
3181 | |
2928 | $class->SUPER::new ( |
3182 | $class->SUPER::new ( |
… | |
… | |
2931 | ) |
3185 | ) |
2932 | } |
3186 | } |
2933 | |
3187 | |
2934 | sub set_tooltip_from { |
3188 | sub set_tooltip_from { |
2935 | my ($self, $widget) = @_; |
3189 | my ($self, $widget) = @_; |
|
|
3190 | |
|
|
3191 | $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1 |
|
|
3192 | if $widget->{tooltip} =~ /^#(.*)$/; |
2936 | |
3193 | |
2937 | my $tooltip = $widget->{tooltip}; |
3194 | my $tooltip = $widget->{tooltip}; |
2938 | |
3195 | |
2939 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3196 | if ($ENV{CFPLUS_DEBUG} & 2) { |
2940 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
3197 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
… | |
… | |
2944 | } |
3201 | } |
2945 | |
3202 | |
2946 | $tooltip =~ s/^\n+//; |
3203 | $tooltip =~ s/^\n+//; |
2947 | $tooltip =~ s/\n+$//; |
3204 | $tooltip =~ s/\n+$//; |
2948 | |
3205 | |
2949 | $self->add (new CFClient::UI::Label |
3206 | $self->add (new CFPlus::UI::Label |
2950 | markup => $tooltip, |
3207 | markup => $tooltip, |
2951 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3208 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2952 | fontsize => 0.8, |
3209 | fontsize => 0.8, |
2953 | fg => [0, 0, 0, 1], |
3210 | style => 1, # FLAG_INVERSE |
2954 | ellipsise => 0, |
3211 | ellipsise => 0, |
2955 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3212 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
2956 | ); |
3213 | ); |
2957 | } |
3214 | } |
2958 | |
3215 | |
… | |
… | |
2977 | |
3234 | |
2978 | $self->{root}->on_post_alloc ("move_$self" => sub { |
3235 | $self->{root}->on_post_alloc ("move_$self" => sub { |
2979 | my $widget = $self->{owner} |
3236 | my $widget = $self->{owner} |
2980 | or return; |
3237 | or return; |
2981 | |
3238 | |
|
|
3239 | if ($widget->{visible}) { |
2982 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
3240 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2983 | |
3241 | |
2984 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
3242 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2985 | if $x + $self->{w} > $self->{root}{w}; |
3243 | if $x + $self->{w} > $self->{root}{w}; |
2986 | |
3244 | |
2987 | $self->move_abs ($x, $y); |
3245 | $self->move_abs ($x, $y); |
|
|
3246 | } else { |
|
|
3247 | $self->hide; |
|
|
3248 | } |
2988 | }); |
3249 | }); |
2989 | } |
3250 | } |
2990 | |
3251 | |
2991 | sub _draw { |
3252 | sub _draw { |
2992 | my ($self) = @_; |
3253 | my ($self) = @_; |
… | |
… | |
3016 | $self->SUPER::_draw; |
3277 | $self->SUPER::_draw; |
3017 | } |
3278 | } |
3018 | |
3279 | |
3019 | ############################################################################# |
3280 | ############################################################################# |
3020 | |
3281 | |
3021 | package CFClient::UI::Face; |
3282 | package CFPlus::UI::Face; |
3022 | |
3283 | |
3023 | our @ISA = CFClient::UI::Base::; |
3284 | our @ISA = CFPlus::UI::DrawBG::; |
3024 | |
3285 | |
3025 | use CFClient::OpenGL; |
3286 | use CFPlus::OpenGL; |
3026 | |
3287 | |
3027 | sub new { |
3288 | sub new { |
3028 | my $class = shift; |
3289 | my $class = shift; |
3029 | |
3290 | |
3030 | my $self = $class->SUPER::new ( |
3291 | my $self = $class->SUPER::new ( |
… | |
… | |
3032 | can_events => 0, |
3293 | can_events => 0, |
3033 | @_, |
3294 | @_, |
3034 | ); |
3295 | ); |
3035 | |
3296 | |
3036 | if ($self->{anim} && $self->{animspeed}) { |
3297 | if ($self->{anim} && $self->{animspeed}) { |
3037 | Scalar::Util::weaken (my $widget = $self); |
3298 | CFPlus::weaken (my $widget = $self); |
3038 | |
3299 | |
3039 | $self->{timer} = Event->timer ( |
3300 | $self->{timer} = Event->timer ( |
3040 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
3301 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
3041 | hard => 1, |
3302 | hard => 1, |
3042 | interval => $self->{animspeed}, |
3303 | interval => $self->{animspeed}, |
… | |
… | |
3065 | sub _draw { |
3326 | sub _draw { |
3066 | my ($self) = @_; |
3327 | my ($self) = @_; |
3067 | |
3328 | |
3068 | return unless $::CONN; |
3329 | return unless $::CONN; |
3069 | |
3330 | |
|
|
3331 | $self->SUPER::_draw; |
|
|
3332 | |
3070 | my $face; |
3333 | my $face; |
3071 | |
3334 | |
3072 | if ($self->{frame}) { |
3335 | if ($self->{frame}) { |
3073 | my $anim = $::CONN->{anim}[$self->{anim}]; |
3336 | my $anim = $::CONN->{anim}[$self->{anim}]; |
3074 | |
3337 | |
… | |
… | |
3096 | $self->SUPER::destroy; |
3359 | $self->SUPER::destroy; |
3097 | } |
3360 | } |
3098 | |
3361 | |
3099 | ############################################################################# |
3362 | ############################################################################# |
3100 | |
3363 | |
3101 | package CFClient::UI::Buttonbar; |
3364 | package CFPlus::UI::Buttonbar; |
3102 | |
3365 | |
3103 | our @ISA = CFClient::UI::HBox::; |
3366 | our @ISA = CFPlus::UI::HBox::; |
3104 | |
3367 | |
3105 | # TODO: should actualyl wrap buttons and other goodies. |
3368 | # TODO: should actually wrap buttons and other goodies. |
3106 | |
3369 | |
3107 | ############################################################################# |
3370 | ############################################################################# |
3108 | |
3371 | |
3109 | package CFClient::UI::Menu; |
3372 | package CFPlus::UI::Menu; |
3110 | |
3373 | |
3111 | our @ISA = CFClient::UI::FancyFrame::; |
3374 | our @ISA = CFPlus::UI::Toplevel::; |
3112 | |
3375 | |
3113 | use CFClient::OpenGL; |
3376 | use CFPlus::OpenGL; |
3114 | |
3377 | |
3115 | sub new { |
3378 | sub new { |
3116 | my $class = shift; |
3379 | my $class = shift; |
3117 | |
3380 | |
3118 | my $self = $class->SUPER::new ( |
3381 | my $self = $class->SUPER::new ( |
3119 | items => [], |
3382 | items => [], |
3120 | z => 100, |
3383 | z => 100, |
3121 | @_, |
3384 | @_, |
3122 | ); |
3385 | ); |
3123 | |
3386 | |
3124 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
3387 | $self->add ($self->{vbox} = new CFPlus::UI::VBox); |
3125 | |
3388 | |
3126 | for my $item (@{ $self->{items} }) { |
3389 | for my $item (@{ $self->{items} }) { |
3127 | my ($widget, $cb, $tooltip) = @$item; |
3390 | my ($widget, $cb, $tooltip) = @$item; |
3128 | |
3391 | |
3129 | # handle various types of items, only text for now |
3392 | # handle various types of items, only text for now |
3130 | if (!ref $widget) { |
3393 | if (!ref $widget) { |
3131 | if ($widget =~ /\t/) { |
3394 | if ($widget =~ /\t/) { |
3132 | my ($left, $right) = split /\t/, $widget, 2; |
3395 | my ($left, $right) = split /\t/, $widget, 2; |
3133 | |
3396 | |
3134 | $widget = new CFClient::UI::HBox |
3397 | $widget = new CFPlus::UI::HBox |
3135 | can_hover => 1, |
3398 | can_hover => 1, |
3136 | can_events => 1, |
3399 | can_events => 1, |
3137 | tooltip => $tooltip, |
3400 | tooltip => $tooltip, |
3138 | children => [ |
3401 | children => [ |
3139 | (new CFClient::UI::Label markup => $left, expand => 1), |
3402 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3140 | (new CFClient::UI::Label markup => $right, align => +1), |
3403 | (new CFPlus::UI::Label markup => $right, align => +1), |
3141 | ], |
3404 | ], |
3142 | ; |
3405 | ; |
3143 | |
3406 | |
3144 | } else { |
3407 | } else { |
3145 | $widget = new CFClient::UI::Label |
3408 | $widget = new CFPlus::UI::Label |
3146 | can_hover => 1, |
3409 | can_hover => 1, |
3147 | can_events => 1, |
3410 | can_events => 1, |
3148 | markup => $widget, |
3411 | markup => $widget, |
3149 | tooltip => $tooltip; |
3412 | tooltip => $tooltip; |
3150 | } |
3413 | } |
… | |
… | |
3198 | 1 |
3461 | 1 |
3199 | } |
3462 | } |
3200 | |
3463 | |
3201 | ############################################################################# |
3464 | ############################################################################# |
3202 | |
3465 | |
3203 | package CFClient::UI::Multiplexer; |
3466 | package CFPlus::UI::Multiplexer; |
3204 | |
3467 | |
3205 | our @ISA = CFClient::UI::Container::; |
3468 | our @ISA = CFPlus::UI::Container::; |
3206 | |
3469 | |
3207 | sub new { |
3470 | sub new { |
3208 | my $class = shift; |
3471 | my $class = shift; |
3209 | |
3472 | |
3210 | my $self = $class->SUPER::new ( |
3473 | my $self = $class->SUPER::new ( |
… | |
… | |
3271 | $self->{current}->draw; |
3534 | $self->{current}->draw; |
3272 | } |
3535 | } |
3273 | |
3536 | |
3274 | ############################################################################# |
3537 | ############################################################################# |
3275 | |
3538 | |
3276 | package CFClient::UI::Notebook; |
3539 | package CFPlus::UI::Notebook; |
3277 | |
3540 | |
3278 | our @ISA = CFClient::UI::VBox::; |
3541 | our @ISA = CFPlus::UI::VBox::; |
3279 | |
3542 | |
3280 | sub new { |
3543 | sub new { |
3281 | my $class = shift; |
3544 | my $class = shift; |
3282 | |
3545 | |
3283 | my $self = $class->SUPER::new ( |
3546 | my $self = $class->SUPER::new ( |
3284 | buttonbar => (new CFClient::UI::Buttonbar), |
3547 | buttonbar => (new CFPlus::UI::Buttonbar), |
3285 | multiplexer => (new CFClient::UI::Multiplexer expand => 1), |
3548 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3286 | # filter => # will be put between multiplexer and $self |
3549 | # filter => # will be put between multiplexer and $self |
3287 | @_, |
3550 | @_, |
3288 | ); |
3551 | ); |
3289 | |
3552 | |
3290 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3553 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
… | |
… | |
3294 | } |
3557 | } |
3295 | |
3558 | |
3296 | sub add { |
3559 | sub add { |
3297 | my ($self, $title, $widget, $tooltip) = @_; |
3560 | my ($self, $title, $widget, $tooltip) = @_; |
3298 | |
3561 | |
3299 | Scalar::Util::weaken $self; |
3562 | CFPlus::weaken $self; |
3300 | |
3563 | |
3301 | $self->{buttonbar}->add (new CFClient::UI::Button |
3564 | $self->{buttonbar}->add (new CFPlus::UI::Button |
3302 | markup => $title, |
3565 | markup => $title, |
3303 | tooltip => $tooltip, |
3566 | tooltip => $tooltip, |
3304 | on_activate => sub { $self->set_current_page ($widget) }, |
3567 | on_activate => sub { $self->set_current_page ($widget) }, |
3305 | ); |
3568 | ); |
3306 | |
3569 | |
… | |
… | |
3320 | $self->emit (page_changed => $self->{multiplexer}{current}); |
3583 | $self->emit (page_changed => $self->{multiplexer}{current}); |
3321 | } |
3584 | } |
3322 | |
3585 | |
3323 | ############################################################################# |
3586 | ############################################################################# |
3324 | |
3587 | |
3325 | package CFClient::UI::Combobox; |
3588 | package CFPlus::UI::Selector; |
3326 | |
3589 | |
3327 | use utf8; |
3590 | use utf8; |
3328 | |
3591 | |
3329 | our @ISA = CFClient::UI::Button::; |
3592 | our @ISA = CFPlus::UI::Button::; |
3330 | |
3593 | |
3331 | sub new { |
3594 | sub new { |
3332 | my $class = shift; |
3595 | my $class = shift; |
3333 | |
3596 | |
3334 | my $self = $class->SUPER::new ( |
3597 | my $self = $class->SUPER::new ( |
… | |
… | |
3351 | my ($value, $title, $tooltip) = @$_; |
3614 | my ($value, $title, $tooltip) = @$_; |
3352 | |
3615 | |
3353 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
3616 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
3354 | } |
3617 | } |
3355 | |
3618 | |
3356 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3619 | CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3357 | } |
3620 | } |
3358 | |
3621 | |
3359 | sub _set_value { |
3622 | sub _set_value { |
3360 | my ($self, $value) = @_; |
3623 | my ($self, $value) = @_; |
3361 | |
3624 | |
… | |
… | |
3376 | $self->emit (changed => $value); |
3639 | $self->emit (changed => $value); |
3377 | } |
3640 | } |
3378 | |
3641 | |
3379 | ############################################################################# |
3642 | ############################################################################# |
3380 | |
3643 | |
3381 | package CFClient::UI::Statusbox; |
3644 | package CFPlus::UI::Statusbox; |
3382 | |
3645 | |
3383 | our @ISA = CFClient::UI::VBox::; |
3646 | our @ISA = CFPlus::UI::VBox::; |
3384 | |
3647 | |
3385 | sub new { |
3648 | sub new { |
3386 | my $class = shift; |
3649 | my $class = shift; |
3387 | |
3650 | |
3388 | my $self = $class->SUPER::new ( |
3651 | my $self = $class->SUPER::new ( |
3389 | fontsize => 0.8, |
3652 | fontsize => 0.8, |
3390 | @_, |
3653 | @_, |
3391 | ); |
3654 | ); |
3392 | |
3655 | |
3393 | Scalar::Util::weaken (my $this = $self); |
3656 | CFPlus::weaken (my $this = $self); |
3394 | |
3657 | |
3395 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
3658 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
3396 | |
3659 | |
3397 | $self |
3660 | $self |
3398 | } |
3661 | } |
… | |
… | |
3400 | sub reorder { |
3663 | sub reorder { |
3401 | my ($self) = @_; |
3664 | my ($self) = @_; |
3402 | my $NOW = Time::HiRes::time; |
3665 | my $NOW = Time::HiRes::time; |
3403 | |
3666 | |
3404 | # freeze display when hovering over any label |
3667 | # freeze display when hovering over any label |
3405 | return if $CFClient::UI::TOOLTIP->{owner} |
3668 | return if $CFPlus::UI::TOOLTIP->{owner} |
3406 | && grep $CFClient::UI::TOOLTIP->{owner} == $_->{label}, |
3669 | && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label}, |
3407 | values %{ $self->{item} }; |
3670 | values %{ $self->{item} }; |
3408 | |
3671 | |
3409 | while (my ($k, $v) = each %{ $self->{item} }) { |
3672 | while (my ($k, $v) = each %{ $self->{item} }) { |
3410 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
3673 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
3411 | } |
3674 | } |
… | |
… | |
3432 | for ($short) { |
3695 | for ($short) { |
3433 | s/^\s+//; |
3696 | s/^\s+//; |
3434 | s/\s+/ /g; |
3697 | s/\s+/ /g; |
3435 | } |
3698 | } |
3436 | |
3699 | |
3437 | new CFClient::UI::Label |
3700 | new CFPlus::UI::Label |
3438 | markup => $short, |
3701 | markup => $short, |
3439 | tooltip => $item->{tooltip}, |
3702 | tooltip => $item->{tooltip}, |
3440 | tooltip_font => $::FONT_PROP, |
3703 | tooltip_font => $::FONT_PROP, |
3441 | tooltip_width => 0.67, |
3704 | tooltip_width => 0.67, |
3442 | fontsize => $item->{fontsize} || $self->{fontsize}, |
3705 | fontsize => $item->{fontsize} || $self->{fontsize}, |
… | |
… | |
3521 | $self->SUPER::destroy; |
3784 | $self->SUPER::destroy; |
3522 | } |
3785 | } |
3523 | |
3786 | |
3524 | ############################################################################# |
3787 | ############################################################################# |
3525 | |
3788 | |
3526 | package CFClient::UI::Inventory; |
|
|
3527 | |
|
|
3528 | our @ISA = CFClient::UI::Table::; |
|
|
3529 | |
|
|
3530 | sub new { |
|
|
3531 | my $class = shift; |
|
|
3532 | |
|
|
3533 | my $self = $class->SUPER::new ( |
|
|
3534 | col_expand => [0, 1, 0], |
|
|
3535 | @_, |
|
|
3536 | ); |
|
|
3537 | |
|
|
3538 | $self |
|
|
3539 | } |
|
|
3540 | |
|
|
3541 | sub set_items { |
|
|
3542 | my ($self, $items) = @_; |
|
|
3543 | |
|
|
3544 | $self->clear; |
|
|
3545 | return unless $items; |
|
|
3546 | |
|
|
3547 | my @items = sort { |
|
|
3548 | ($a->{type} <=> $b->{type}) |
|
|
3549 | or ($a->{name} cmp $b->{name}) |
|
|
3550 | } values %$items; |
|
|
3551 | |
|
|
3552 | $self->{real_items} = \@items; |
|
|
3553 | |
|
|
3554 | my $row = 0; |
|
|
3555 | for my $item (@items) { |
|
|
3556 | CFClient::Item::update_widgets $item; |
|
|
3557 | |
|
|
3558 | $self->add (0, $row, $item->{face_widget}); |
|
|
3559 | $self->add (1, $row, $item->{desc_widget}); |
|
|
3560 | $self->add (2, $row, $item->{weight_widget}); |
|
|
3561 | |
|
|
3562 | $row++; |
|
|
3563 | } |
|
|
3564 | } |
|
|
3565 | |
|
|
3566 | ############################################################################# |
|
|
3567 | |
|
|
3568 | package CFClient::UI::SpellList; |
|
|
3569 | |
|
|
3570 | our @ISA = CFClient::UI::Table::; |
|
|
3571 | |
|
|
3572 | sub new { |
|
|
3573 | my $class = shift; |
|
|
3574 | |
|
|
3575 | my $self = $class->SUPER::new ( |
|
|
3576 | binding => [], |
|
|
3577 | commands => [], |
|
|
3578 | @_, |
|
|
3579 | ) |
|
|
3580 | } |
|
|
3581 | |
|
|
3582 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>"; |
|
|
3583 | |
|
|
3584 | my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3585 | "<b>Name</b>. The name of the spell.$TOOLTIP_ALL"); |
|
|
3586 | my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3587 | "<b>Skill</b>. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL"); |
|
|
3588 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3589 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL"); |
|
|
3590 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3591 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL"); |
|
|
3592 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3593 | "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL"); |
|
|
3594 | |
|
|
3595 | sub rebuild_spell_list { |
|
|
3596 | my ($self) = @_; |
|
|
3597 | |
|
|
3598 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
|
|
3599 | $self->clear; |
|
|
3600 | |
|
|
3601 | return unless $::CONN; |
|
|
3602 | |
|
|
3603 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name", @TOOLTIP_NAME); |
|
|
3604 | $self->add (2, 0, new CFClient::UI::Label text => "Skill", @TOOLTIP_SKILL); |
|
|
3605 | $self->add (3, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
|
|
3606 | $self->add (4, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
|
|
3607 | $self->add (5, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
|
|
3608 | |
|
|
3609 | my $row = 0; |
|
|
3610 | |
|
|
3611 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
|
|
3612 | my $spell = $self->{spell}{$_}; |
|
|
3613 | |
|
|
3614 | $row++; |
|
|
3615 | |
|
|
3616 | my $spell_cb = sub { |
|
|
3617 | my ($widget, $ev) = @_; |
|
|
3618 | |
|
|
3619 | if ($ev->{button} == 1) { |
|
|
3620 | $::CONN->user_send ("cast $spell->{name}"); |
|
|
3621 | } elsif ($ev->{button} == 2) { |
|
|
3622 | $::CONN->user_send ("invoke $spell->{name}"); |
|
|
3623 | } elsif ($ev->{button} == 3) { |
|
|
3624 | (new CFClient::UI::Menu |
|
|
3625 | items => [ |
|
|
3626 | ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
|
|
3627 | ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
|
|
3628 | ], |
|
|
3629 | )->popup ($ev); |
|
|
3630 | } else { |
|
|
3631 | return 0; |
|
|
3632 | } |
|
|
3633 | |
|
|
3634 | 1 |
|
|
3635 | }; |
|
|
3636 | |
|
|
3637 | my $tooltip = "$spell->{message}$TOOLTIP_ALL"; |
|
|
3638 | |
|
|
3639 | #TODO: add path info to tooltip |
|
|
3640 | #$self->add (6, $row, new CFClient::UI::Label text => $spell->{path}); |
|
|
3641 | |
|
|
3642 | $self->add (0, $row, new CFClient::UI::Face |
|
|
3643 | face => $spell->{face}, |
|
|
3644 | can_hover => 1, |
|
|
3645 | can_events => 1, |
|
|
3646 | tooltip => $tooltip, |
|
|
3647 | on_button_down => $spell_cb, |
|
|
3648 | ); |
|
|
3649 | |
|
|
3650 | $self->add (1, $row, new CFClient::UI::Label |
|
|
3651 | expand => 1, |
|
|
3652 | text => $spell->{name}, |
|
|
3653 | can_hover => 1, |
|
|
3654 | can_events => 1, |
|
|
3655 | tooltip => $tooltip, |
|
|
3656 | on_button_down => $spell_cb, |
|
|
3657 | ); |
|
|
3658 | |
|
|
3659 | $self->add (2, $row, new CFClient::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL); |
|
|
3660 | $self->add (3, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
|
|
3661 | $self->add (4, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
|
|
3662 | $self->add (5, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
|
|
3663 | } |
|
|
3664 | }); |
|
|
3665 | } |
|
|
3666 | |
|
|
3667 | sub add_spell { |
|
|
3668 | my ($self, $spell) = @_; |
|
|
3669 | |
|
|
3670 | $self->{spell}->{$spell->{name}} = $spell; |
|
|
3671 | $self->rebuild_spell_list; |
|
|
3672 | } |
|
|
3673 | |
|
|
3674 | sub remove_spell { |
|
|
3675 | my ($self, $spell) = @_; |
|
|
3676 | |
|
|
3677 | delete $self->{spell}->{$spell->{name}}; |
|
|
3678 | $self->rebuild_spell_list; |
|
|
3679 | } |
|
|
3680 | |
|
|
3681 | sub clear_spells { |
|
|
3682 | my ($self) = @_; |
|
|
3683 | |
|
|
3684 | $self->{spell} = {}; |
|
|
3685 | $self->rebuild_spell_list; |
|
|
3686 | } |
|
|
3687 | |
|
|
3688 | ############################################################################# |
|
|
3689 | |
|
|
3690 | package CFClient::UI::Root; |
3789 | package CFPlus::UI::Root; |
3691 | |
3790 | |
3692 | our @ISA = CFClient::UI::Container::; |
3791 | our @ISA = CFPlus::UI::Container::; |
3693 | |
3792 | |
3694 | use List::Util qw(min max); |
3793 | use List::Util qw(min max); |
3695 | |
3794 | |
3696 | use CFClient::OpenGL; |
3795 | use CFPlus::OpenGL; |
3697 | |
3796 | |
3698 | sub new { |
3797 | sub new { |
3699 | my $class = shift; |
3798 | my $class = shift; |
3700 | |
3799 | |
3701 | my $self = $class->SUPER::new ( |
3800 | my $self = $class->SUPER::new ( |
3702 | visible => 1, |
3801 | visible => 1, |
3703 | @_, |
3802 | @_, |
3704 | ); |
3803 | ); |
3705 | |
3804 | |
3706 | Scalar::Util::weaken ($self->{root} = $self); |
3805 | CFPlus::weaken ($self->{root} = $self); |
3707 | |
3806 | |
3708 | $self |
3807 | $self |
3709 | } |
3808 | } |
3710 | |
3809 | |
3711 | sub size_request { |
3810 | sub size_request { |
… | |
… | |
3880 | $h = 0 if $h < 0; |
3979 | $h = 0 if $h < 0; |
3881 | |
3980 | |
3882 | $w = max $widget->{min_w}, $w; |
3981 | $w = max $widget->{min_w}, $w; |
3883 | $h = max $widget->{min_h}, $h; |
3982 | $h = max $widget->{min_h}, $h; |
3884 | |
3983 | |
|
|
3984 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
|
|
3985 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
|
|
3986 | |
3885 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
3987 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
3886 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
3988 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
3887 | |
3989 | |
3888 | $w = int $w + 0.5; |
3990 | $w = int $w + 0.5; |
3889 | $h = int $h + 0.5; |
3991 | $h = int $h + 0.5; |
… | |
… | |
3915 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
4017 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
3916 | glMatrixMode GL_MODELVIEW; |
4018 | glMatrixMode GL_MODELVIEW; |
3917 | glLoadIdentity; |
4019 | glLoadIdentity; |
3918 | |
4020 | |
3919 | { |
4021 | { |
3920 | package CFClient::UI::Base; |
4022 | package CFPlus::UI::Base; |
3921 | |
4023 | |
3922 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
4024 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
3923 | (0, 0, $self->{w}, $self->{h}); |
4025 | (0, 0, $self->{w}, $self->{h}); |
3924 | } |
|
|
3925 | |
4026 | |
3926 | $self->_draw; |
4027 | $self->_draw; |
|
|
4028 | } |
3927 | } |
4029 | } |
3928 | |
4030 | |
3929 | ############################################################################# |
4031 | ############################################################################# |
3930 | |
4032 | |
3931 | package CFClient::UI; |
4033 | package CFPlus::UI; |
3932 | |
4034 | |
3933 | $ROOT = new CFClient::UI::Root; |
4035 | $ROOT = new CFPlus::UI::Root; |
3934 | $TOOLTIP = new CFClient::UI::Tooltip z => 900; |
4036 | $TOOLTIP = new CFPlus::UI::Tooltip z => 900; |
3935 | |
4037 | |
3936 | 1 |
4038 | 1 |
3937 | |
4039 | |