… | |
… | |
3 | use utf8; |
3 | use utf8; |
4 | use strict; |
4 | use strict; |
5 | |
5 | |
6 | use Scalar::Util (); |
6 | use Scalar::Util (); |
7 | use List::Util (); |
7 | use List::Util (); |
|
|
8 | use Event; |
8 | |
9 | |
9 | use CFClient; |
10 | use CFClient; |
10 | use CFClient::Texture; |
11 | use CFClient::Texture; |
11 | |
12 | |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
13 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
… | |
… | |
15 | our $ROOT; |
16 | our $ROOT; |
16 | our $TOOLTIP; |
17 | our $TOOLTIP; |
17 | our $BUTTON_STATE; |
18 | our $BUTTON_STATE; |
18 | |
19 | |
19 | our %WIDGET; # all widgets, weak-referenced |
20 | our %WIDGET; # all widgets, weak-referenced |
|
|
21 | |
|
|
22 | our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { |
|
|
23 | if (!$GRAB) { |
|
|
24 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
|
|
25 | if (length $widget->{tooltip}) { |
|
|
26 | if ($TOOLTIP->{owner} != $widget) { |
|
|
27 | $TOOLTIP->hide; |
|
|
28 | |
|
|
29 | $TOOLTIP->{owner} = $widget; |
|
|
30 | |
|
|
31 | return if $ENV{CFPLUS_DEBUG} & 8; |
|
|
32 | |
|
|
33 | my $tip = $widget->{tooltip}; |
|
|
34 | |
|
|
35 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
|
|
36 | |
|
|
37 | $TOOLTIP->set_tooltip_from ($widget); |
|
|
38 | $TOOLTIP->show; |
|
|
39 | } |
|
|
40 | |
|
|
41 | return; |
|
|
42 | } |
|
|
43 | } |
|
|
44 | } |
|
|
45 | |
|
|
46 | $TOOLTIP->hide; |
|
|
47 | delete $TOOLTIP->{owner}; |
|
|
48 | }); |
20 | |
49 | |
21 | sub get_layout { |
50 | sub get_layout { |
22 | my $layout; |
51 | my $layout; |
23 | |
52 | |
24 | for (grep { $_->{name} } values %WIDGET) { |
53 | for (grep { $_->{name} } values %WIDGET) { |
… | |
… | |
39 | my ($layout) = @_; |
68 | my ($layout) = @_; |
40 | |
69 | |
41 | $LAYOUT = $layout; |
70 | $LAYOUT = $layout; |
42 | } |
71 | } |
43 | |
72 | |
44 | sub check_tooltip { |
|
|
45 | return if $ENV{CFPLUS_DEBUG} & 8; |
|
|
46 | |
|
|
47 | if (!$GRAB) { |
|
|
48 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
|
|
49 | if (length $widget->{tooltip}) { |
|
|
50 | if ($TOOLTIP->{owner} != $widget) { |
|
|
51 | $TOOLTIP->hide; |
|
|
52 | |
|
|
53 | $TOOLTIP->{owner} = $widget; |
|
|
54 | |
|
|
55 | my $tip = $widget->{tooltip}; |
|
|
56 | |
|
|
57 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
|
|
58 | |
|
|
59 | $TOOLTIP->set_tooltip_from ($widget); |
|
|
60 | $TOOLTIP->show; |
|
|
61 | } |
|
|
62 | |
|
|
63 | return; |
|
|
64 | } |
|
|
65 | } |
|
|
66 | } |
|
|
67 | |
|
|
68 | $TOOLTIP->hide; |
|
|
69 | delete $TOOLTIP->{owner}; |
|
|
70 | } |
|
|
71 | |
|
|
72 | # class methods for events |
73 | # class methods for events |
73 | sub feed_sdl_key_down_event { |
74 | sub feed_sdl_key_down_event { |
74 | $FOCUS->emit (key_down => $_[0]) |
75 | $FOCUS->emit (key_down => $_[0]) |
75 | if $FOCUS; |
76 | if $FOCUS; |
76 | } |
77 | } |
… | |
… | |
88 | my $widget = $ROOT->find_widget ($x, $y); |
89 | my $widget = $ROOT->find_widget ($x, $y); |
89 | |
90 | |
90 | $GRAB = $widget; |
91 | $GRAB = $widget; |
91 | $GRAB->update if $GRAB; |
92 | $GRAB->update if $GRAB; |
92 | |
93 | |
93 | check_tooltip; |
94 | $TOOLTIP_WATCHER->cb->(); |
94 | } |
95 | } |
95 | |
96 | |
96 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
97 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
97 | |
98 | |
98 | $GRAB->emit (button_down => $ev, $GRAB->coord2local ($x, $y)) |
99 | $GRAB->emit (button_down => $ev, $GRAB->coord2local ($x, $y)) |
… | |
… | |
113 | if (!$BUTTON_STATE) { |
114 | if (!$BUTTON_STATE) { |
114 | my $grab = $GRAB; undef $GRAB; |
115 | my $grab = $GRAB; undef $GRAB; |
115 | $grab->update if $grab; |
116 | $grab->update if $grab; |
116 | $GRAB->update if $GRAB; |
117 | $GRAB->update if $GRAB; |
117 | |
118 | |
118 | check_tooltip; |
119 | $TOOLTIP_WATCHER->cb->(); |
119 | } |
120 | } |
120 | } |
121 | } |
121 | |
122 | |
122 | sub feed_sdl_motion_event { |
123 | sub feed_sdl_motion_event { |
123 | my ($ev) = @_; |
124 | my ($ev) = @_; |
… | |
… | |
129 | my $hover = $HOVER; $HOVER = $widget; |
130 | my $hover = $HOVER; $HOVER = $widget; |
130 | |
131 | |
131 | $hover->update if $hover && $hover->{can_hover}; |
132 | $hover->update if $hover && $hover->{can_hover}; |
132 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
133 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
133 | |
134 | |
134 | check_tooltip; |
135 | $TOOLTIP_WATCHER->start; |
135 | } |
136 | } |
136 | |
137 | |
137 | $HOVER->emit (mouse_motion => $ev, $HOVER->coord2local ($x, $y)) |
138 | $HOVER->emit (mouse_motion => $ev, $HOVER->coord2local ($x, $y)) |
138 | if $HOVER; |
139 | if $HOVER; |
139 | } |
140 | } |
… | |
… | |
277 | delete $self->{visible}; |
278 | delete $self->{visible}; |
278 | |
279 | |
279 | undef $GRAB if $GRAB == $self; |
280 | undef $GRAB if $GRAB == $self; |
280 | undef $HOVER if $HOVER == $self; |
281 | undef $HOVER if $HOVER == $self; |
281 | |
282 | |
282 | CFClient::UI::check_tooltip |
283 | $CFClient::UI::TOOLTIP_WATCHER->cb->() |
283 | if $TOOLTIP->{owner} == $self; |
284 | if $TOOLTIP->{owner} == $self; |
284 | |
285 | |
285 | $self->focus_out; |
286 | $self->focus_out; |
286 | |
287 | |
287 | $self->emit (visibility_change => 0); |
288 | $self->emit (visibility_change => 0); |
… | |
… | |
371 | sub size_allocate { |
372 | sub size_allocate { |
372 | # nothing to be done |
373 | # nothing to be done |
373 | } |
374 | } |
374 | |
375 | |
375 | sub children { |
376 | sub children { |
|
|
377 | # nop |
|
|
378 | } |
|
|
379 | |
|
|
380 | sub visible_children { |
|
|
381 | $_[0]->children |
376 | } |
382 | } |
377 | |
383 | |
378 | sub set_max_size { |
384 | sub set_max_size { |
379 | my ($self, $w, $h) = @_; |
385 | my ($self, $w, $h) = @_; |
380 | |
386 | |
381 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
387 | $self->{max_w} = int $w if defined $w; |
382 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
388 | $self->{max_h} = int $h if defined $h; |
|
|
389 | |
|
|
390 | $self->realloc; |
383 | } |
391 | } |
384 | |
392 | |
385 | sub set_tooltip { |
393 | sub set_tooltip { |
386 | my ($self, $tooltip) = @_; |
394 | my ($self, $tooltip) = @_; |
387 | |
395 | |
… | |
… | |
392 | |
400 | |
393 | $self->{tooltip} = $tooltip; |
401 | $self->{tooltip} = $tooltip; |
394 | |
402 | |
395 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
403 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
396 | delete $CFClient::UI::TOOLTIP->{owner}; |
404 | delete $CFClient::UI::TOOLTIP->{owner}; |
397 | CFClient::UI::check_tooltip; |
405 | $CFClient::UI::TOOLTIP_WATCHER->cb->(); |
398 | } |
406 | } |
399 | } |
407 | } |
400 | |
408 | |
401 | # translate global coordinates to local coordinate system |
409 | # translate global coordinates to local coordinate system |
402 | sub coord2local { |
410 | sub coord2local { |
… | |
… | |
439 | |
447 | |
440 | $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus |
448 | $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus |
441 | unless $FOCUS; |
449 | unless $FOCUS; |
442 | } |
450 | } |
443 | |
451 | |
444 | sub mouse_motion { } |
452 | sub mouse_motion { 0 } |
445 | sub button_up { } |
453 | sub button_up { 0 } |
446 | sub key_down { } |
454 | sub key_down { 0 } |
447 | sub key_up { } |
455 | sub key_up { 0 } |
448 | |
456 | |
449 | sub button_down { |
457 | sub button_down { |
450 | my ($self, $ev, $x, $y) = @_; |
458 | my ($self, $ev, $x, $y) = @_; |
451 | |
459 | |
452 | $self->focus_in; |
460 | $self->focus_in; |
|
|
461 | |
|
|
462 | 0 |
453 | } |
463 | } |
454 | |
464 | |
455 | sub find_widget { |
465 | sub find_widget { |
456 | my ($self, $x, $y) = @_; |
466 | my ($self, $x, $y) = @_; |
457 | |
467 | |
… | |
… | |
516 | } |
526 | } |
517 | |
527 | |
518 | sub reconfigure { |
528 | sub reconfigure { |
519 | my ($self) = @_; |
529 | my ($self) = @_; |
520 | |
530 | |
|
|
531 | # some widgets cache req_w and req_h |
|
|
532 | delete $self->{req_w}; |
|
|
533 | delete $self->{req_h}; |
|
|
534 | |
521 | $self->realloc; |
535 | $self->realloc; |
522 | $self->update; |
536 | $self->update; |
523 | } |
537 | } |
524 | |
538 | |
525 | # using global variables seems a bit hacky, but passing through all drawing |
539 | # using global variables seems a bit hacky, but passing through all drawing |
… | |
… | |
541 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
555 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
542 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
556 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
543 | |
557 | |
544 | glPushMatrix; |
558 | glPushMatrix; |
545 | glTranslate $self->{x}, $self->{y}, 0; |
559 | glTranslate $self->{x}, $self->{y}, 0; |
546 | $self->_draw; |
|
|
547 | glPopMatrix; |
|
|
548 | |
560 | |
549 | if ($self == $HOVER && $self->{can_hover}) { |
561 | if ($self == $HOVER && $self->{can_hover}) { |
550 | my ($x, $y) = @$self{qw(x y)}; |
|
|
551 | |
|
|
552 | glColor 1, 0.8, 0.5, 0.2; |
562 | glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2; |
553 | glEnable GL_BLEND; |
563 | glEnable GL_BLEND; |
554 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
564 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
555 | glBegin GL_QUADS; |
565 | glBegin GL_QUADS; |
556 | glVertex $x , $y; |
566 | glVertex 0 , 0; |
557 | glVertex $x + $self->{w}, $y; |
567 | glVertex $self->{w}, 0; |
558 | glVertex $x + $self->{w}, $y + $self->{h}; |
568 | glVertex $self->{w}, $self->{h}; |
559 | glVertex $x , $y + $self->{h}; |
569 | glVertex 0 , $self->{h}; |
560 | glEnd; |
570 | glEnd; |
561 | glDisable GL_BLEND; |
571 | glDisable GL_BLEND; |
562 | } |
572 | } |
563 | |
573 | |
564 | if ($ENV{CFPLUS_DEBUG} & 1) { |
574 | if ($ENV{CFPLUS_DEBUG} & 1) { |
565 | glPushMatrix; |
575 | glPushMatrix; |
566 | glColor 1, 1, 0, 1; |
576 | glColor 1, 1, 0, 1; |
567 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
577 | glTranslate 0.375, 0.375; |
568 | glBegin GL_LINE_LOOP; |
578 | glBegin GL_LINE_LOOP; |
569 | glVertex 0 , 0; |
579 | glVertex 0 , 0; |
570 | glVertex $self->{w} - 1, 0; |
580 | glVertex $self->{w} - 1, 0; |
571 | glVertex $self->{w} - 1, $self->{h} - 1; |
581 | glVertex $self->{w} - 1, $self->{h} - 1; |
572 | glVertex 0 , $self->{h} - 1; |
582 | glVertex 0 , $self->{h} - 1; |
573 | glEnd; |
583 | glEnd; |
574 | glPopMatrix; |
584 | glPopMatrix; |
575 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
585 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
576 | } |
586 | } |
|
|
587 | |
|
|
588 | $self->_draw; |
|
|
589 | glPopMatrix; |
577 | } |
590 | } |
578 | |
591 | |
579 | sub _draw { |
592 | sub _draw { |
580 | my ($self) = @_; |
593 | my ($self) = @_; |
581 | |
594 | |
… | |
… | |
619 | |
632 | |
620 | if ($color && (@$color < 4 || $color->[3])) { |
633 | if ($color && (@$color < 4 || $color->[3])) { |
621 | my ($w, $h) = @$self{qw(w h)}; |
634 | my ($w, $h) = @$self{qw(w h)}; |
622 | |
635 | |
623 | glEnable GL_BLEND; |
636 | glEnable GL_BLEND; |
624 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
637 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
625 | glColor @$color; |
638 | glColor_premultiply @$color; |
626 | |
639 | |
627 | glBegin GL_QUADS; |
640 | glBegin GL_QUADS; |
628 | glVertex 0 , 0; |
641 | glVertex 0 , 0; |
629 | glVertex 0 , $h; |
642 | glVertex 0 , $h; |
630 | glVertex $w, $h; |
643 | glVertex $w, $h; |
… | |
… | |
661 | our @ISA = CFClient::UI::Base::; |
674 | our @ISA = CFClient::UI::Base::; |
662 | |
675 | |
663 | sub new { |
676 | sub new { |
664 | my ($class, %arg) = @_; |
677 | my ($class, %arg) = @_; |
665 | |
678 | |
666 | my $children = delete $arg{children} || []; |
679 | my $children = delete $arg{children}; |
667 | |
680 | |
668 | my $self = $class->SUPER::new ( |
681 | my $self = $class->SUPER::new ( |
669 | children => [], |
682 | children => [], |
670 | can_events => 0, |
683 | can_events => 0, |
671 | %arg, |
684 | %arg, |
672 | ); |
685 | ); |
|
|
686 | |
673 | $self->add ($_) for @$children; |
687 | $self->add (@$children) |
|
|
688 | if $children; |
674 | |
689 | |
675 | $self |
690 | $self |
676 | } |
691 | } |
677 | |
692 | |
678 | sub add { |
693 | sub add { |
… | |
… | |
726 | $x -= $self->{x}; |
741 | $x -= $self->{x}; |
727 | $y -= $self->{y}; |
742 | $y -= $self->{y}; |
728 | |
743 | |
729 | my $res; |
744 | my $res; |
730 | |
745 | |
731 | for (reverse @{ $self->{children} }) { |
746 | for (reverse $self->visible_children) { |
732 | $res = $_->find_widget ($x, $y) |
747 | $res = $_->find_widget ($x, $y) |
733 | and return $res; |
748 | and return $res; |
734 | } |
749 | } |
735 | |
750 | |
736 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
751 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
… | |
… | |
785 | $self->{children}[0]->configure (0, 0, $w, $h); |
800 | $self->{children}[0]->configure (0, 0, $w, $h); |
786 | } |
801 | } |
787 | |
802 | |
788 | ############################################################################# |
803 | ############################################################################# |
789 | |
804 | |
|
|
805 | # back-buffered drawing area |
|
|
806 | |
790 | package CFClient::UI::Window; |
807 | package CFClient::UI::Window; |
791 | |
808 | |
792 | our @ISA = CFClient::UI::Bin::; |
809 | our @ISA = CFClient::UI::Bin::; |
793 | |
810 | |
794 | use CFClient::OpenGL; |
811 | use CFClient::OpenGL; |
… | |
… | |
845 | my $tex = $self->{texture} |
862 | my $tex = $self->{texture} |
846 | or return; |
863 | or return; |
847 | |
864 | |
848 | glEnable GL_TEXTURE_2D; |
865 | glEnable GL_TEXTURE_2D; |
849 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
866 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
850 | glColor 1, 1, 1, 1; |
867 | glColor 0, 0, 0, 1; |
851 | |
868 | |
852 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
869 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
853 | |
870 | |
854 | glDisable GL_TEXTURE_2D; |
871 | glDisable GL_TEXTURE_2D; |
855 | } |
872 | } |
… | |
… | |
946 | package CFClient::UI::ScrolledWindow; |
963 | package CFClient::UI::ScrolledWindow; |
947 | |
964 | |
948 | our @ISA = CFClient::UI::HBox::; |
965 | our @ISA = CFClient::UI::HBox::; |
949 | |
966 | |
950 | sub new { |
967 | sub new { |
951 | my $class = shift; |
968 | my ($class, %arg) = @_; |
|
|
969 | |
|
|
970 | my $child = delete $arg{child}; |
952 | |
971 | |
953 | my $self; |
972 | my $self; |
954 | |
973 | |
955 | my $slider = new CFClient::UI::Slider |
974 | my $slider = new CFClient::UI::Slider |
956 | vertical => 1, |
975 | vertical => 1, |
… | |
… | |
961 | ; |
980 | ; |
962 | |
981 | |
963 | $self = $class->SUPER::new ( |
982 | $self = $class->SUPER::new ( |
964 | vp => (new CFClient::UI::ViewPort expand => 1), |
983 | vp => (new CFClient::UI::ViewPort expand => 1), |
965 | slider => $slider, |
984 | slider => $slider, |
966 | @_, |
985 | %arg, |
967 | ); |
986 | ); |
968 | |
987 | |
969 | $self->{vp}->add ($self->{scrolled}); |
|
|
970 | $self->add ($self->{vp}); |
|
|
971 | $self->add ($self->{slider}); |
988 | $self->SUPER::add ($self->{vp}, $self->{slider}); |
|
|
989 | $self->add ($child) if $child; |
972 | |
990 | |
973 | $self |
991 | $self |
|
|
992 | } |
|
|
993 | |
|
|
994 | sub add { |
|
|
995 | my ($self, $widget) = @_; |
|
|
996 | |
|
|
997 | $self->{vp}->add ($self->{child} = $widget); |
974 | } |
998 | } |
975 | |
999 | |
976 | sub update { |
1000 | sub update { |
977 | my ($self) = @_; |
1001 | my ($self) = @_; |
978 | |
1002 | |
… | |
… | |
1017 | |
1041 | |
1018 | if ($self->{bg}) { |
1042 | if ($self->{bg}) { |
1019 | my ($w, $h) = @$self{qw(w h)}; |
1043 | my ($w, $h) = @$self{qw(w h)}; |
1020 | |
1044 | |
1021 | glEnable GL_BLEND; |
1045 | glEnable GL_BLEND; |
1022 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1046 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1023 | glColor @{ $self->{bg} }; |
1047 | glColor_premultiply @{ $self->{bg} }; |
1024 | |
1048 | |
1025 | glBegin GL_QUADS; |
1049 | glBegin GL_QUADS; |
1026 | glVertex 0 , 0; |
1050 | glVertex 0 , 0; |
1027 | glVertex 0 , $h; |
1051 | glVertex 0 , $h; |
1028 | glVertex $w, $h; |
1052 | glVertex $w, $h; |
… | |
… | |
1050 | my @border = |
1074 | my @border = |
1051 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1075 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1052 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1076 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1053 | |
1077 | |
1054 | sub new { |
1078 | sub new { |
1055 | my $class = shift; |
1079 | my ($class, %arg) = @_; |
|
|
1080 | |
|
|
1081 | my $title = delete $arg{title}; |
1056 | |
1082 | |
1057 | my $self = $class->SUPER::new ( |
1083 | my $self = $class->SUPER::new ( |
1058 | bg => [1, 1, 1, 1], |
1084 | bg => [1, 1, 1, 1], |
1059 | border_bg => [1, 1, 1, 1], |
1085 | border_bg => [1, 1, 1, 1], |
1060 | border => 0.6, |
1086 | border => 0.6, |
1061 | can_events => 1, |
1087 | can_events => 1, |
1062 | min_w => 16, |
1088 | min_w => 16, |
1063 | min_h => 16, |
1089 | min_h => 16, |
1064 | @_ |
1090 | %arg, |
1065 | ); |
1091 | ); |
1066 | |
1092 | |
1067 | $self->{title} &&= new CFClient::UI::Label |
1093 | $self->{title} = new CFClient::UI::Label |
1068 | align => 0, |
1094 | align => 0, |
1069 | valign => 1, |
1095 | valign => 1, |
1070 | text => $self->{title}, |
1096 | text => $title, |
1071 | fontsize => $self->{border}; |
1097 | fontsize => $self->{border} |
|
|
1098 | if defined $title; |
1072 | |
1099 | |
1073 | $self |
1100 | $self |
|
|
1101 | } |
|
|
1102 | |
|
|
1103 | sub add { |
|
|
1104 | my ($self, @widgets) = @_; |
|
|
1105 | |
|
|
1106 | $self->SUPER::add (@widgets); |
|
|
1107 | $self->CFClient::UI::Container::add ($self->{title}) if $self->{title}; |
1074 | } |
1108 | } |
1075 | |
1109 | |
1076 | sub border { |
1110 | sub border { |
1077 | int $_[0]{border} * $::FONTSIZE |
1111 | int $_[0]{border} * $::FONTSIZE |
1078 | } |
1112 | } |
1079 | |
1113 | |
1080 | sub size_request { |
1114 | sub size_request { |
1081 | my ($self) = @_; |
1115 | my ($self) = @_; |
|
|
1116 | |
|
|
1117 | $self->{title}->size_request |
|
|
1118 | if $self->{title}; |
1082 | |
1119 | |
1083 | my ($w, $h) = $self->SUPER::size_request; |
1120 | my ($w, $h) = $self->SUPER::size_request; |
1084 | |
1121 | |
1085 | ( |
1122 | ( |
1086 | $w + $self->border * 2, |
1123 | $w + $self->border * 2, |
… | |
… | |
1089 | } |
1126 | } |
1090 | |
1127 | |
1091 | sub size_allocate { |
1128 | sub size_allocate { |
1092 | my ($self, $w, $h) = @_; |
1129 | my ($self, $w, $h) = @_; |
1093 | |
1130 | |
|
|
1131 | if ($self->{title}) { |
|
|
1132 | $self->{title}{w} = $w; |
|
|
1133 | $self->{title}{h} = $h; |
|
|
1134 | $self->{title}->size_allocate ($w, $h); |
|
|
1135 | } |
|
|
1136 | |
|
|
1137 | my $border = $self->border; |
|
|
1138 | |
1094 | $h -= List::Util::max 0, $self->border * 2; |
1139 | $h -= List::Util::max 0, $border * 2; |
1095 | $w -= List::Util::max 0, $self->border * 2; |
1140 | $w -= List::Util::max 0, $border * 2; |
1096 | |
1141 | |
1097 | $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) |
|
|
1098 | if $self->{title}; |
|
|
1099 | |
|
|
1100 | $self->child->configure ($self->border, $self->border, $w, $h); |
1142 | $self->child->configure ($border, $border, $w, $h); |
1101 | } |
1143 | } |
1102 | |
1144 | |
1103 | sub button_down { |
1145 | sub button_down { |
1104 | my ($self, $ev, $x, $y) = @_; |
1146 | my ($self, $ev, $x, $y) = @_; |
1105 | |
1147 | |
… | |
… | |
1124 | my $dy = $ev->{y} - $oy; |
1166 | my $dy = $ev->{y} - $oy; |
1125 | |
1167 | |
1126 | $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); |
1168 | $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); |
1127 | $self->{force_h} = $bh + $dy * ($my ? -1 : 1); |
1169 | $self->{force_h} = $bh + $dy * ($my ? -1 : 1); |
1128 | |
1170 | |
|
|
1171 | $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my); |
1129 | $self->realloc; |
1172 | $self->realloc; |
1130 | $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my); |
|
|
1131 | }; |
1173 | }; |
1132 | |
1174 | |
1133 | } elsif ($lr ^ $td) { |
1175 | } elsif ($lr ^ $td) { |
1134 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1176 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1135 | my ($bx, $by) = ($self->{x}, $self->{y}); |
1177 | my ($bx, $by) = ($self->{x}, $self->{y}); |
… | |
… | |
1138 | my ($ev, $x, $y) = @_; |
1180 | my ($ev, $x, $y) = @_; |
1139 | |
1181 | |
1140 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1182 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1141 | |
1183 | |
1142 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1184 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
|
|
1185 | # HACK: the next line is required to enforce placement |
|
|
1186 | $self->{parent}->size_allocate ($self->{parent}{w}, $self->{parent}{h}); |
1143 | }; |
1187 | }; |
|
|
1188 | } else { |
|
|
1189 | return 0; |
|
|
1190 | } |
|
|
1191 | |
1144 | } |
1192 | 1 |
1145 | } |
1193 | } |
1146 | |
1194 | |
1147 | sub button_up { |
1195 | sub button_up { |
1148 | my ($self, $ev, $x, $y) = @_; |
1196 | my ($self, $ev, $x, $y) = @_; |
1149 | |
1197 | |
1150 | delete $self->{motion}; |
1198 | !!delete $self->{motion} |
1151 | } |
1199 | } |
1152 | |
1200 | |
1153 | sub mouse_motion { |
1201 | sub mouse_motion { |
1154 | my ($self, $ev, $x, $y) = @_; |
1202 | my ($self, $ev, $x, $y) = @_; |
1155 | |
1203 | |
1156 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
1204 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1205 | |
|
|
1206 | !!$self->{motion} |
1157 | } |
1207 | } |
1158 | |
1208 | |
1159 | sub _draw { |
1209 | sub _draw { |
1160 | my ($self) = @_; |
1210 | my ($self) = @_; |
1161 | |
1211 | |
|
|
1212 | my $child = $self->{children}[0]; |
|
|
1213 | |
1162 | my ($w, $h ) = ($self->{w}, $self->{h}); |
1214 | my ($w, $h ) = ($self->{w}, $self->{h}); |
1163 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
1215 | my ($cw, $ch) = ($child->{w}, $child->{h}); |
1164 | |
1216 | |
1165 | glEnable GL_TEXTURE_2D; |
1217 | glEnable GL_TEXTURE_2D; |
1166 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1218 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1167 | |
1219 | |
1168 | my $border = $self->border; |
1220 | my $border = $self->border; |
… | |
… | |
1183 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
1235 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
1184 | } |
1236 | } |
1185 | |
1237 | |
1186 | glDisable GL_TEXTURE_2D; |
1238 | glDisable GL_TEXTURE_2D; |
1187 | |
1239 | |
1188 | $self->{title}->draw if $self->{title}; |
|
|
1189 | |
|
|
1190 | $self->child->draw; |
1240 | $child->draw; |
|
|
1241 | |
|
|
1242 | if ($self->{title}) { |
|
|
1243 | glTranslate 0, $border - $self->{h}; |
|
|
1244 | $self->{title}->_draw; |
|
|
1245 | } |
1191 | } |
1246 | } |
1192 | |
1247 | |
1193 | ############################################################################# |
1248 | ############################################################################# |
1194 | |
1249 | |
1195 | package CFClient::UI::Table; |
1250 | package CFClient::UI::Table; |
… | |
… | |
1488 | |
1543 | |
1489 | delete $self->{texture}; |
1544 | delete $self->{texture}; |
1490 | $self->SUPER::update; |
1545 | $self->SUPER::update; |
1491 | } |
1546 | } |
1492 | |
1547 | |
|
|
1548 | sub realloc { |
|
|
1549 | my ($self) = @_; |
|
|
1550 | |
|
|
1551 | delete $self->{ox}; |
|
|
1552 | $self->SUPER::realloc; |
|
|
1553 | } |
|
|
1554 | |
1493 | sub set_text { |
1555 | sub set_text { |
1494 | my ($self, $text) = @_; |
1556 | my ($self, $text) = @_; |
1495 | |
1557 | |
1496 | return if $self->{text} eq "T$text"; |
1558 | return if $self->{text} eq "T$text"; |
1497 | $self->{text} = "T$text"; |
1559 | $self->{text} = "T$text"; |
1498 | |
1560 | |
1499 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1561 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1500 | $self->{layout}->set_text ($text); |
1562 | $self->{layout}->set_text ($text); |
1501 | |
1563 | |
|
|
1564 | delete $self->{req_h}; |
1502 | $self->realloc; |
1565 | $self->realloc; |
1503 | $self->update; |
1566 | $self->update; |
1504 | } |
1567 | } |
1505 | |
1568 | |
1506 | sub set_markup { |
1569 | sub set_markup { |
… | |
… | |
1512 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1575 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1513 | |
1576 | |
1514 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1577 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1515 | $self->{layout}->set_markup ($markup); |
1578 | $self->{layout}->set_markup ($markup); |
1516 | |
1579 | |
|
|
1580 | delete $self->{req_h}; |
1517 | $self->realloc; |
1581 | $self->realloc; |
1518 | $self->update; |
1582 | $self->update; |
1519 | } |
1583 | } |
1520 | |
1584 | |
1521 | sub size_request { |
1585 | sub size_request { |
1522 | my ($self) = @_; |
1586 | my ($self) = @_; |
1523 | |
1587 | |
|
|
1588 | if (exists $self->{req_h}) { |
|
|
1589 | @$self{qw(req_w req_h)} |
|
|
1590 | } else { |
1524 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1591 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1525 | $self->{layout}->set_width ($self->{max_w} || -1); |
1592 | $self->{layout}->set_width ($self->{max_w} || -1); |
1526 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1593 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1527 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1594 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1528 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1595 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1529 | |
1596 | |
1530 | my ($w, $h) = $self->{layout}->size; |
1597 | my ($w, $h) = $self->{layout}->size; |
1531 | |
1598 | |
1532 | if (exists $self->{template}) { |
1599 | if (exists $self->{template}) { |
1533 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1600 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1534 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1601 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1535 | |
1602 | |
1536 | my ($w2, $h2) = $self->{template}->size; |
1603 | my ($w2, $h2) = $self->{template}->size; |
1537 | |
1604 | |
1538 | $w = List::Util::max $w, $w2; |
1605 | $w = List::Util::max $w, $w2; |
1539 | $h = List::Util::max $h, $h2; |
1606 | $h = List::Util::max $h, $h2; |
1540 | } |
1607 | } |
1541 | |
1608 | |
1542 | ($w, $h) |
1609 | ($w, $h) |
|
|
1610 | } |
1543 | } |
1611 | } |
1544 | |
1612 | |
1545 | sub size_allocate { |
1613 | sub size_allocate { |
1546 | my ($self, $w, $h) = @_; |
1614 | my ($self, $w, $h) = @_; |
|
|
1615 | |
|
|
1616 | delete $self->{ox}; |
1547 | |
1617 | |
1548 | delete $self->{texture} |
1618 | delete $self->{texture} |
1549 | unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; |
1619 | unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; |
1550 | } |
1620 | } |
1551 | |
1621 | |
… | |
… | |
1569 | $self->{layout}->set_width ($self->{w}); |
1639 | $self->{layout}->set_width ($self->{w}); |
1570 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1640 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1571 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1641 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1572 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1642 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1573 | |
1643 | |
1574 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1644 | new_from_layout CFClient::Texture $self->{layout} |
|
|
1645 | }; |
1575 | |
1646 | |
|
|
1647 | unless (exists $self->{ox}) { |
1576 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1648 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1577 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} |
1649 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} |
1578 | : ($self->{w} - $tex->{w}) * 0.5); |
1650 | : ($self->{w} - $tex->{w}) * 0.5); |
1579 | |
1651 | |
1580 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
1652 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
1581 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} |
1653 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} |
1582 | : ($self->{h} - $tex->{h}) * 0.5); |
1654 | : ($self->{h} - $tex->{h}) * 0.5); |
1583 | |
|
|
1584 | $tex |
|
|
1585 | }; |
1655 | }; |
1586 | |
1656 | |
1587 | glEnable GL_TEXTURE_2D; |
1657 | glEnable GL_TEXTURE_2D; |
1588 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1589 | |
1658 | |
1590 | if ($tex->{format} == GL_ALPHA) { |
1659 | if ($tex->{format} == GL_ALPHA) { |
|
|
1660 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1591 | glColor @{$self->{fg}}; |
1661 | glColor @{$self->{fg}}; |
1592 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
1662 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
1593 | } else { |
1663 | } else { |
|
|
1664 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1594 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1665 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1595 | } |
1666 | } |
1596 | |
1667 | |
1597 | glDisable GL_TEXTURE_2D; |
1668 | glDisable GL_TEXTURE_2D; |
1598 | } |
1669 | } |
… | |
… | |
1627 | |
1698 | |
1628 | delete $self->{cur_h}; |
1699 | delete $self->{cur_h}; |
1629 | |
1700 | |
1630 | return if $self->{text} eq $text; |
1701 | return if $self->{text} eq $text; |
1631 | |
1702 | |
1632 | delete $self->{texture}; |
|
|
1633 | |
|
|
1634 | $self->{last_activity} = $::NOW; |
1703 | $self->{last_activity} = $::NOW; |
1635 | $self->{text} = $text; |
1704 | $self->{text} = $text; |
1636 | |
1705 | |
1637 | $text =~ s/./*/g if $self->{hidden}; |
1706 | $text =~ s/./*/g if $self->{hidden}; |
1638 | $self->{layout}->set_text ("$text "); |
1707 | $self->{layout}->set_text ("$text "); |
|
|
1708 | delete $self->{req_h}; |
1639 | |
1709 | |
1640 | $self->_emit (changed => $self->{text}); |
1710 | $self->_emit (changed => $self->{text}); |
|
|
1711 | |
|
|
1712 | $self->realloc; |
|
|
1713 | $self->update; |
1641 | } |
1714 | } |
1642 | |
1715 | |
1643 | sub set_text { |
1716 | sub set_text { |
1644 | my ($self, $text) = @_; |
1717 | my ($self, $text) = @_; |
1645 | |
1718 | |
1646 | $self->{cursor} = length $text; |
1719 | $self->{cursor} = length $text; |
1647 | $self->_set_text ($text); |
1720 | $self->_set_text ($text); |
1648 | |
|
|
1649 | $self->realloc; |
|
|
1650 | } |
1721 | } |
1651 | |
1722 | |
1652 | sub get_text { |
1723 | sub get_text { |
1653 | $_[0]{text} |
1724 | $_[0]{text} |
1654 | } |
1725 | } |
… | |
… | |
1684 | $self->{cursor} = length $text; |
1755 | $self->{cursor} = length $text; |
1685 | } elsif ($uni == 27) { |
1756 | } elsif ($uni == 27) { |
1686 | $self->_emit ('escape'); |
1757 | $self->_emit ('escape'); |
1687 | } elsif ($uni) { |
1758 | } elsif ($uni) { |
1688 | substr $text, $self->{cursor}++, 0, chr $uni; |
1759 | substr $text, $self->{cursor}++, 0, chr $uni; |
|
|
1760 | } else { |
|
|
1761 | return 0; |
1689 | } |
1762 | } |
1690 | |
1763 | |
1691 | $self->_set_text ($text); |
1764 | $self->_set_text ($text); |
1692 | |
1765 | |
1693 | $self->realloc; |
1766 | $self->realloc; |
|
|
1767 | |
|
|
1768 | 1 |
1694 | } |
1769 | } |
1695 | |
1770 | |
1696 | sub focus_in { |
1771 | sub focus_in { |
1697 | my ($self) = @_; |
1772 | my ($self) = @_; |
1698 | |
1773 | |
… | |
… | |
1713 | utf8::encode $text; |
1788 | utf8::encode $text; |
1714 | $self->{cursor} = length substr $text, 0, $idx; |
1789 | $self->{cursor} = length substr $text, 0, $idx; |
1715 | |
1790 | |
1716 | $self->_set_text ($self->{text}); |
1791 | $self->_set_text ($self->{text}); |
1717 | $self->update; |
1792 | $self->update; |
|
|
1793 | |
|
|
1794 | 1 |
1718 | } |
1795 | } |
1719 | |
1796 | |
1720 | sub mouse_motion { |
1797 | sub mouse_motion { |
1721 | my ($self, $ev, $x, $y) = @_; |
1798 | my ($self, $ev, $x, $y) = @_; |
1722 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
1799 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
|
|
1800 | |
|
|
1801 | 0 |
1723 | } |
1802 | } |
1724 | |
1803 | |
1725 | sub _draw { |
1804 | sub _draw { |
1726 | my ($self) = @_; |
1805 | my ($self) = @_; |
1727 | |
1806 | |
1728 | local $self->{fg} = $self->{fg}; |
1807 | local $self->{fg} = $self->{fg}; |
1729 | |
1808 | |
1730 | if ($FOCUS == $self) { |
1809 | if ($FOCUS == $self) { |
1731 | glColor @{$self->{active_bg}}; |
1810 | glColor_premultiply @{$self->{active_bg}}; |
1732 | $self->{fg} = $self->{active_fg}; |
1811 | $self->{fg} = $self->{active_fg}; |
1733 | } else { |
1812 | } else { |
1734 | glColor @{$self->{bg}}; |
1813 | glColor_premultiply @{$self->{bg}}; |
1735 | } |
1814 | } |
1736 | |
1815 | |
1737 | glEnable GL_BLEND; |
1816 | glEnable GL_BLEND; |
1738 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1817 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1739 | glBegin GL_QUADS; |
1818 | glBegin GL_QUADS; |
1740 | glVertex 0 , 0; |
1819 | glVertex 0 , 0; |
1741 | glVertex 0 , $self->{h}; |
1820 | glVertex 0 , $self->{h}; |
1742 | glVertex $self->{w}, $self->{h}; |
1821 | glVertex $self->{w}, $self->{h}; |
1743 | glVertex $self->{w}, 0; |
1822 | glVertex $self->{w}, 0; |
… | |
… | |
1804 | } else { |
1883 | } else { |
1805 | $self->set_text ($self->{history_saveback}); |
1884 | $self->set_text ($self->{history_saveback}); |
1806 | } |
1885 | } |
1807 | |
1886 | |
1808 | } else { |
1887 | } else { |
1809 | $self->SUPER::key_down ($ev); |
1888 | return $self->SUPER::key_down ($ev) |
|
|
1889 | } |
|
|
1890 | |
1810 | } |
1891 | 1 |
1811 | |
|
|
1812 | } |
1892 | } |
1813 | |
1893 | |
1814 | ############################################################################# |
1894 | ############################################################################# |
1815 | |
1895 | |
1816 | package CFClient::UI::Button; |
1896 | package CFClient::UI::Button; |
… | |
… | |
1845 | my ($self, $ev, $x, $y) = @_; |
1925 | my ($self, $ev, $x, $y) = @_; |
1846 | |
1926 | |
1847 | $self->emit ("activate") |
1927 | $self->emit ("activate") |
1848 | if $x >= 0 && $x < $self->{w} |
1928 | if $x >= 0 && $x < $self->{w} |
1849 | && $y >= 0 && $y < $self->{h}; |
1929 | && $y >= 0 && $y < $self->{h}; |
|
|
1930 | |
|
|
1931 | 1 |
1850 | } |
1932 | } |
1851 | |
1933 | |
1852 | sub _draw { |
1934 | sub _draw { |
1853 | my ($self) = @_; |
1935 | my ($self) = @_; |
1854 | |
1936 | |
1855 | local $self->{fg} = $self->{fg}; |
1937 | local $self->{fg} = $GRAB == $self ? $self->{active_fg} : $self->{fg}; |
1856 | |
|
|
1857 | if ($GRAB == $self) { |
|
|
1858 | $self->{fg} = $self->{active_fg}; |
|
|
1859 | } |
|
|
1860 | |
1938 | |
1861 | glEnable GL_TEXTURE_2D; |
1939 | glEnable GL_TEXTURE_2D; |
1862 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1940 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1863 | glColor 0, 0, 0, 1; |
1941 | glColor 0, 0, 0, 1; |
1864 | |
1942 | |
… | |
… | |
1908 | |
1986 | |
1909 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1987 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1910 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1988 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1911 | $self->{state} = !$self->{state}; |
1989 | $self->{state} = !$self->{state}; |
1912 | $self->_emit (changed => $self->{state}); |
1990 | $self->_emit (changed => $self->{state}); |
|
|
1991 | } else { |
|
|
1992 | return 0 |
|
|
1993 | } |
|
|
1994 | |
1913 | } |
1995 | 1 |
1914 | } |
1996 | } |
1915 | |
1997 | |
1916 | sub _draw { |
1998 | sub _draw { |
1917 | my ($self) = @_; |
1999 | my ($self) = @_; |
1918 | |
2000 | |
… | |
… | |
2085 | |
2167 | |
2086 | my $h1 = $self->{h} * (1 - $ycut1); |
2168 | my $h1 = $self->{h} * (1 - $ycut1); |
2087 | my $h2 = $self->{h} * (1 - $ycut2); |
2169 | my $h2 = $self->{h} * (1 - $ycut2); |
2088 | |
2170 | |
2089 | glEnable GL_BLEND; |
2171 | glEnable GL_BLEND; |
2090 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2172 | glBlendFuncSeparate GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
|
|
2173 | GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2091 | glEnable GL_TEXTURE_2D; |
2174 | glEnable GL_TEXTURE_2D; |
2092 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2175 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2093 | |
2176 | |
2094 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
2177 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
2095 | glBegin GL_QUADS; |
2178 | glBegin GL_QUADS; |
… | |
… | |
2256 | |
2339 | |
2257 | $self->SUPER::button_down ($ev, $x, $y); |
2340 | $self->SUPER::button_down ($ev, $x, $y); |
2258 | |
2341 | |
2259 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2342 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2260 | |
2343 | |
2261 | $self->mouse_motion ($ev, $x, $y); |
2344 | $self->mouse_motion ($ev, $x, $y) |
2262 | } |
2345 | } |
2263 | |
2346 | |
2264 | sub mouse_motion { |
2347 | sub mouse_motion { |
2265 | my ($self, $ev, $x, $y) = @_; |
2348 | my ($self, $ev, $x, $y) = @_; |
2266 | |
2349 | |
… | |
… | |
2270 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2353 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2271 | |
2354 | |
2272 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2355 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2273 | |
2356 | |
2274 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
2357 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
|
|
2358 | } else { |
|
|
2359 | return 0; |
|
|
2360 | } |
|
|
2361 | |
2275 | } |
2362 | 1 |
2276 | } |
2363 | } |
2277 | |
2364 | |
2278 | sub update { |
2365 | sub update { |
2279 | my ($self) = @_; |
2366 | my ($self) = @_; |
2280 | |
2367 | |
2281 | $CFClient::UI::ROOT->on_post_alloc ($self => sub { |
2368 | delete $self->{knob_w}; |
|
|
2369 | $self->SUPER::update; |
|
|
2370 | } |
|
|
2371 | |
|
|
2372 | sub _draw { |
|
|
2373 | my ($self) = @_; |
|
|
2374 | |
|
|
2375 | unless ($self->{knob_w}) { |
2282 | $self->set_value ($self->{range}[0]); |
2376 | $self->set_value ($self->{range}[0]); |
2283 | |
2377 | |
2284 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2378 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2285 | my $range = ($hi - $page - $lo) || 1e-100; |
2379 | my $range = ($hi - $page - $lo) || 1e-100; |
2286 | |
2380 | |
… | |
… | |
2292 | $value = ($value - $lo) / $range; |
2386 | $value = ($value - $lo) / $range; |
2293 | $value = $value * $self->{scale} + $self->{offset}; |
2387 | $value = $value * $self->{scale} + $self->{offset}; |
2294 | |
2388 | |
2295 | $self->{knob_x} = $value - $knob_w * 0.5; |
2389 | $self->{knob_x} = $value - $knob_w * 0.5; |
2296 | $self->{knob_w} = $knob_w; |
2390 | $self->{knob_w} = $knob_w; |
2297 | }); |
2391 | } |
2298 | |
|
|
2299 | $self->SUPER::update; |
|
|
2300 | } |
|
|
2301 | |
|
|
2302 | sub _draw { |
|
|
2303 | my ($self) = @_; |
|
|
2304 | |
2392 | |
2305 | $self->SUPER::_draw (); |
2393 | $self->SUPER::_draw (); |
2306 | |
2394 | |
2307 | glScale $self->{w}, $self->{h}; |
2395 | glScale $self->{w}, $self->{h}; |
2308 | |
2396 | |
… | |
… | |
2502 | |
2590 | |
2503 | delete $self->{texture}; |
2591 | delete $self->{texture}; |
2504 | } |
2592 | } |
2505 | |
2593 | |
2506 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2594 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2507 | glClearColor 0.5, 0.5, 0.5, 0; |
2595 | glClearColor 0, 0, 0, 0; |
2508 | glClear GL_COLOR_BUFFER_BIT; |
2596 | glClear GL_COLOR_BUFFER_BIT; |
2509 | |
2597 | |
2510 | my $top = int $self->{children}[1]{range}[0]; |
2598 | my $top = int $self->{children}[1]{range}[0]; |
2511 | |
2599 | |
2512 | my $y0 = $top; |
2600 | my $y0 = $top; |
… | |
… | |
2547 | sub _draw { |
2635 | sub _draw { |
2548 | my ($self) = @_; |
2636 | my ($self) = @_; |
2549 | |
2637 | |
2550 | glEnable GL_TEXTURE_2D; |
2638 | glEnable GL_TEXTURE_2D; |
2551 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2639 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2552 | glColor 1, 1, 1, 1; |
2640 | glColor 0, 0, 0, 1; |
2553 | $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2641 | $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2554 | glDisable GL_TEXTURE_2D; |
2642 | glDisable GL_TEXTURE_2D; |
2555 | |
2643 | |
2556 | $self->{children}[1]->draw; |
2644 | $self->{children}[1]->draw; |
2557 | |
2645 | |
2558 | } |
2646 | } |
… | |
… | |
2785 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2873 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2786 | |
2874 | |
2787 | if ($tex) { |
2875 | if ($tex) { |
2788 | glEnable GL_TEXTURE_2D; |
2876 | glEnable GL_TEXTURE_2D; |
2789 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2877 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2790 | glColor 1, 1, 1, 1; |
2878 | glColor 0, 0, 0, 1; |
2791 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2879 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2792 | glDisable GL_TEXTURE_2D; |
2880 | glDisable GL_TEXTURE_2D; |
2793 | } |
2881 | } |
2794 | } |
2882 | } |
2795 | |
2883 | |
… | |
… | |
2799 | $self->{timer}->cancel |
2887 | $self->{timer}->cancel |
2800 | if $self->{timer}; |
2888 | if $self->{timer}; |
2801 | |
2889 | |
2802 | $self->SUPER::DESTROY; |
2890 | $self->SUPER::DESTROY; |
2803 | } |
2891 | } |
|
|
2892 | |
|
|
2893 | ############################################################################# |
|
|
2894 | |
|
|
2895 | package CFClient::UI::Buttonbar; |
|
|
2896 | |
|
|
2897 | our @ISA = CFClient::UI::HBox::; |
|
|
2898 | |
|
|
2899 | # TODO: should actualyl wrap buttons and other goodies. |
2804 | |
2900 | |
2805 | ############################################################################# |
2901 | ############################################################################# |
2806 | |
2902 | |
2807 | package CFClient::UI::Menu; |
2903 | package CFClient::UI::Menu; |
2808 | |
2904 | |
… | |
… | |
2858 | my ($self, $ev, $x, $y) = @_; |
2954 | my ($self, $ev, $x, $y) = @_; |
2859 | |
2955 | |
2860 | # TODO: should use vbox->find_widget or so |
2956 | # TODO: should use vbox->find_widget or so |
2861 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2957 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2862 | $self->{hover} = $self->{item}{$HOVER}; |
2958 | $self->{hover} = $self->{item}{$HOVER}; |
|
|
2959 | |
|
|
2960 | 0 |
2863 | } |
2961 | } |
2864 | |
2962 | |
2865 | sub button_up { |
2963 | sub button_up { |
2866 | my ($self, $ev, $x, $y) = @_; |
2964 | my ($self, $ev, $x, $y) = @_; |
2867 | |
2965 | |
… | |
… | |
2869 | undef $GRAB; |
2967 | undef $GRAB; |
2870 | $self->hide; |
2968 | $self->hide; |
2871 | |
2969 | |
2872 | $self->_emit ("popdown"); |
2970 | $self->_emit ("popdown"); |
2873 | $self->{hover}[1]->() if $self->{hover}; |
2971 | $self->{hover}[1]->() if $self->{hover}; |
|
|
2972 | } else { |
|
|
2973 | return 0 |
|
|
2974 | } |
|
|
2975 | |
2874 | } |
2976 | 1 |
2875 | } |
2977 | } |
2876 | |
2978 | |
2877 | ############################################################################# |
2979 | ############################################################################# |
2878 | |
2980 | |
2879 | package CFClient::UI::Statusbox; |
2981 | package CFClient::UI::Multiplexer; |
2880 | |
2982 | |
2881 | our @ISA = CFClient::UI::VBox::; |
2983 | our @ISA = CFClient::UI::Container::; |
2882 | |
2984 | |
2883 | sub new { |
2985 | sub new { |
2884 | my $class = shift; |
2986 | my $class = shift; |
2885 | |
2987 | |
2886 | $class->SUPER::new ( |
2988 | my $self = $class->SUPER::new ( |
|
|
2989 | @_, |
|
|
2990 | ); |
|
|
2991 | |
|
|
2992 | $self->{current} = $self->{children}[0] |
|
|
2993 | if @{ $self->{children} }; |
|
|
2994 | |
|
|
2995 | $self |
|
|
2996 | } |
|
|
2997 | |
|
|
2998 | sub add { |
|
|
2999 | my ($self, @widgets) = @_; |
|
|
3000 | |
|
|
3001 | $self->SUPER::add (@widgets); |
|
|
3002 | |
|
|
3003 | $self->{current} = $self->{children}[0] |
|
|
3004 | if @{ $self->{children} }; |
|
|
3005 | } |
|
|
3006 | |
|
|
3007 | sub set_current_page { |
|
|
3008 | my ($self, $page_or_widget) = @_; |
|
|
3009 | |
|
|
3010 | my $widget = ref $page_or_widget |
|
|
3011 | ? $page_or_widget |
|
|
3012 | : $self->{children}[$page_or_widget]; |
|
|
3013 | |
|
|
3014 | $self->{current} = $widget; |
|
|
3015 | $self->{current}->configure (0, 0, $self->{w}, $self->{h}); |
|
|
3016 | |
|
|
3017 | $self->_emit (page_changed => $self->{current}); |
|
|
3018 | |
|
|
3019 | $self->realloc; |
|
|
3020 | } |
|
|
3021 | |
|
|
3022 | sub visible_children { |
|
|
3023 | $_[0]{current} |
|
|
3024 | } |
|
|
3025 | |
|
|
3026 | sub size_request { |
|
|
3027 | my ($self) = @_; |
|
|
3028 | |
|
|
3029 | $self->{current}->size_request |
|
|
3030 | } |
|
|
3031 | |
|
|
3032 | sub size_allocate { |
|
|
3033 | my ($self, $w, $h) = @_; |
|
|
3034 | |
|
|
3035 | $self->{current}->configure (0, 0, $w, $h); |
|
|
3036 | } |
|
|
3037 | |
|
|
3038 | sub _draw { |
|
|
3039 | my ($self) = @_; |
|
|
3040 | |
|
|
3041 | $self->{current}->draw; |
|
|
3042 | } |
|
|
3043 | |
|
|
3044 | ############################################################################# |
|
|
3045 | |
|
|
3046 | package CFClient::UI::Notebook; |
|
|
3047 | |
|
|
3048 | our @ISA = CFClient::UI::VBox::; |
|
|
3049 | |
|
|
3050 | sub new { |
|
|
3051 | my $class = shift; |
|
|
3052 | |
|
|
3053 | my $self = $class->SUPER::new ( |
|
|
3054 | buttonbar => (new CFClient::UI::Buttonbar), |
|
|
3055 | multiplexer => (new CFClient::UI::Multiplexer expand => 1), |
|
|
3056 | # filter => # will be put between multiplexer and $self |
|
|
3057 | @_, |
|
|
3058 | ); |
|
|
3059 | |
|
|
3060 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
|
|
3061 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
|
|
3062 | |
|
|
3063 | $self |
|
|
3064 | } |
|
|
3065 | |
|
|
3066 | sub add { |
|
|
3067 | my ($self, $title, $widget, $tooltip) = @_; |
|
|
3068 | |
|
|
3069 | Scalar::Util::weaken $self; |
|
|
3070 | |
|
|
3071 | $self->{buttonbar}->add (new CFClient::UI::Button |
|
|
3072 | markup => $title, |
|
|
3073 | tooltip => $tooltip, |
|
|
3074 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3075 | ); |
|
|
3076 | |
|
|
3077 | $self->{multiplexer}->add ($widget); |
|
|
3078 | } |
|
|
3079 | |
|
|
3080 | sub set_current_page { |
|
|
3081 | my ($self, $page) = @_; |
|
|
3082 | |
|
|
3083 | $self->{multiplexer}->set_current_page ($page); |
|
|
3084 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
|
|
3085 | } |
|
|
3086 | |
|
|
3087 | ############################################################################# |
|
|
3088 | |
|
|
3089 | package CFClient::UI::Statusbox; |
|
|
3090 | |
|
|
3091 | our @ISA = CFClient::UI::VBox::; |
|
|
3092 | |
|
|
3093 | sub new { |
|
|
3094 | my $class = shift; |
|
|
3095 | |
|
|
3096 | my $self = $class->SUPER::new ( |
2887 | fontsize => 0.8, |
3097 | fontsize => 0.8, |
2888 | @_, |
3098 | @_, |
2889 | ) |
3099 | ); |
|
|
3100 | |
|
|
3101 | Scalar::Util::weaken (my $this = $self); |
|
|
3102 | |
|
|
3103 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
|
|
3104 | |
|
|
3105 | $self |
2890 | } |
3106 | } |
2891 | |
3107 | |
2892 | sub reorder { |
3108 | sub reorder { |
2893 | my ($self) = @_; |
3109 | my ($self) = @_; |
2894 | my $NOW = time; |
3110 | my $NOW = Time::HiRes::time; |
|
|
3111 | |
|
|
3112 | # freeze display when hovering over any label |
|
|
3113 | return if $CFClient::UI::TOOLTIP->{owner} |
|
|
3114 | && grep $CFClient::UI::TOOLTIP->{owner} == $_->{label}, |
|
|
3115 | values %{ $self->{item} }; |
2895 | |
3116 | |
2896 | while (my ($k, $v) = each %{ $self->{item} }) { |
3117 | while (my ($k, $v) = each %{ $self->{item} }) { |
2897 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
3118 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
2898 | } |
3119 | } |
2899 | |
3120 | |
… | |
… | |
2902 | my @items = sort { |
3123 | my @items = sort { |
2903 | $a->{pri} <=> $b->{pri} |
3124 | $a->{pri} <=> $b->{pri} |
2904 | or $b->{id} <=> $a->{id} |
3125 | or $b->{id} <=> $a->{id} |
2905 | } values %{ $self->{item} }; |
3126 | } values %{ $self->{item} }; |
2906 | |
3127 | |
|
|
3128 | $self->{timer}->interval (1); |
|
|
3129 | |
2907 | my $count = 10 + 1; |
3130 | my $count = 10 + 1; |
2908 | for my $item (@items) { |
3131 | for my $item (@items) { |
2909 | last unless --$count; |
3132 | last unless --$count; |
2910 | |
3133 | |
2911 | push @widgets, $item->{label} ||= do { |
3134 | my $label = $item->{label} ||= do { |
2912 | # TODO: doesn't handle markup well (read as: at all) |
3135 | # TODO: doesn't handle markup well (read as: at all) |
2913 | my $short = $item->{count} > 1 |
3136 | my $short = $item->{count} > 1 |
2914 | ? "<b>$item->{count} ×</b> $item->{text}" |
3137 | ? "<b>$item->{count} ×</b> $item->{text}" |
2915 | : $item->{text}; |
3138 | : $item->{text}; |
2916 | |
3139 | |
… | |
… | |
2924 | tooltip => $item->{tooltip}, |
3147 | tooltip => $item->{tooltip}, |
2925 | tooltip_font => $::FONT_PROP, |
3148 | tooltip_font => $::FONT_PROP, |
2926 | tooltip_width => 0.67, |
3149 | tooltip_width => 0.67, |
2927 | fontsize => $item->{fontsize} || $self->{fontsize}, |
3150 | fontsize => $item->{fontsize} || $self->{fontsize}, |
2928 | max_w => $::WIDTH * 0.44, |
3151 | max_w => $::WIDTH * 0.44, |
2929 | fg => $item->{fg}, |
3152 | fg => [@{ $item->{fg} }], |
2930 | can_events => 1, |
3153 | can_events => 1, |
2931 | can_hover => 1 |
3154 | can_hover => 1 |
2932 | }; |
3155 | }; |
|
|
3156 | |
|
|
3157 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
|
|
3158 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
|
|
3159 | $label->update; |
|
|
3160 | $label->set_max_size (undef, $label->{req_h} * $diff) |
|
|
3161 | if $diff < 1; |
|
|
3162 | $self->{timer}->interval (1/30); |
|
|
3163 | } else { |
|
|
3164 | $label->{fg}[3] = $item->{fg}[3] || 1; |
|
|
3165 | } |
|
|
3166 | |
|
|
3167 | push @widgets, $label; |
2933 | } |
3168 | } |
2934 | |
3169 | |
2935 | $self->clear; |
3170 | $self->clear; |
2936 | $self->SUPER::add (reverse @widgets); |
3171 | $self->SUPER::add (reverse @widgets); |
2937 | } |
3172 | } |
… | |
… | |
2942 | $text =~ s/^\s+//; |
3177 | $text =~ s/^\s+//; |
2943 | $text =~ s/\s+$//; |
3178 | $text =~ s/\s+$//; |
2944 | |
3179 | |
2945 | return unless $text; |
3180 | return unless $text; |
2946 | |
3181 | |
2947 | my $timeout = time + ((delete $arg{timeout}) || 60); |
3182 | my $timeout = (int time) + ((delete $arg{timeout}) || 60); |
2948 | |
3183 | |
2949 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
3184 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
2950 | |
3185 | |
2951 | if (my $item = $self->{item}{$group}) { |
3186 | if (my $item = $self->{item}{$group}) { |
2952 | if ($item->{text} eq $text) { |
3187 | if ($item->{text} eq $text) { |
… | |
… | |
2982 | |
3217 | |
2983 | $self->reorder; |
3218 | $self->reorder; |
2984 | $self->SUPER::reconfigure; |
3219 | $self->SUPER::reconfigure; |
2985 | } |
3220 | } |
2986 | |
3221 | |
|
|
3222 | sub DESTROY { |
|
|
3223 | my ($self) = @_; |
|
|
3224 | |
|
|
3225 | $self->{timer}->cancel; |
|
|
3226 | |
|
|
3227 | $self->SUPER::DESTROY; |
|
|
3228 | } |
|
|
3229 | |
2987 | ############################################################################# |
3230 | ############################################################################# |
2988 | |
3231 | |
2989 | package CFClient::UI::Inventory; |
3232 | package CFClient::UI::Inventory; |
2990 | |
3233 | |
2991 | our @ISA = CFClient::UI::ScrolledWindow::; |
3234 | our @ISA = CFClient::UI::ScrolledWindow::; |
2992 | |
3235 | |
2993 | sub new { |
3236 | sub new { |
2994 | my $class = shift; |
3237 | my $class = shift; |
2995 | |
3238 | |
2996 | my $self = $class->SUPER::new ( |
3239 | my $self = $class->SUPER::new ( |
2997 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
3240 | child => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
2998 | @_, |
3241 | @_, |
2999 | ); |
3242 | ); |
3000 | |
3243 | |
3001 | $self |
3244 | $self |
3002 | } |
3245 | } |
3003 | |
3246 | |
3004 | sub set_items { |
3247 | sub set_items { |
3005 | my ($self, $items) = @_; |
3248 | my ($self, $items) = @_; |
3006 | |
3249 | |
3007 | $self->{scrolled}->clear; |
3250 | $self->{child}->clear; |
3008 | return unless $items; |
3251 | return unless $items; |
3009 | |
3252 | |
3010 | my @items = sort { |
3253 | my @items = sort { |
3011 | ($a->{type} <=> $b->{type}) |
3254 | ($a->{type} <=> $b->{type}) |
3012 | or ($a->{name} cmp $b->{name}) |
3255 | or ($a->{name} cmp $b->{name}) |
… | |
… | |
3016 | |
3259 | |
3017 | my $row = 0; |
3260 | my $row = 0; |
3018 | for my $item (@items) { |
3261 | for my $item (@items) { |
3019 | CFClient::Item::update_widgets $item; |
3262 | CFClient::Item::update_widgets $item; |
3020 | |
3263 | |
3021 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
3264 | $self->{child}->add (0, $row, $item->{face_widget}); |
3022 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
3265 | $self->{child}->add (1, $row, $item->{desc_widget}); |
3023 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
3266 | $self->{child}->add (2, $row, $item->{weight_widget}); |
3024 | |
3267 | |
3025 | $row++; |
3268 | $row++; |
3026 | } |
3269 | } |
3027 | } |
3270 | } |
3028 | |
3271 | |
… | |
… | |
3126 | $rec = $::CONN->stop_record if $::CONN; |
3369 | $rec = $::CONN->stop_record if $::CONN; |
3127 | return unless ref $rec eq 'ARRAY'; |
3370 | return unless ref $rec eq 'ARRAY'; |
3128 | $self->set_command_list ($rec); |
3371 | $self->set_command_list ($rec); |
3129 | } |
3372 | } |
3130 | |
3373 | |
3131 | # if $commit is true, the binding will be set after the user entered a key combo |
3374 | |
|
|
3375 | sub ask_for_bind_and_commit { |
|
|
3376 | my ($self) = @_; |
|
|
3377 | $self->ask_for_bind (1); |
|
|
3378 | } |
|
|
3379 | |
3132 | sub ask_for_bind { |
3380 | sub ask_for_bind { |
3133 | my ($self, $commit) = @_; |
3381 | my ($self, $commit) = @_; |
3134 | |
3382 | |
3135 | CFClient::Binder::open_binding_dialog (sub { |
3383 | CFClient::Binder::open_binding_dialog (sub { |
3136 | my ($mod, $sym) = @_; |
3384 | my ($mod, $sym) = @_; |
… | |
… | |
3220 | |
3468 | |
3221 | ############################################################################# |
3469 | ############################################################################# |
3222 | |
3470 | |
3223 | package CFClient::UI::SpellList; |
3471 | package CFClient::UI::SpellList; |
3224 | |
3472 | |
3225 | our @ISA = CFClient::UI::FancyFrame::; |
3473 | our @ISA = CFClient::UI::Table::; |
3226 | |
3474 | |
3227 | sub new { |
3475 | sub new { |
3228 | my $class = shift; |
3476 | my $class = shift; |
3229 | |
3477 | |
3230 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
3478 | my $self = $class->SUPER::new ( |
3231 | |
3479 | binding => [], |
3232 | $self->add (new CFClient::UI::ScrolledWindow |
3480 | commands => [], |
3233 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
3481 | @_, |
3234 | |
3482 | ) |
3235 | $self; |
|
|
3236 | } |
3483 | } |
3237 | |
3484 | |
3238 | # XXX: Do sorting? Argl... |
3485 | # XXX: Do sorting? Argl... |
3239 | sub add_spell { |
3486 | sub add_spell { |
3240 | my ($self, $spell) = @_; |
3487 | my ($self, $spell) = @_; |
3241 | $self->{spells}->{$spell->{name}} = $spell; |
3488 | $self->{spells}->{$spell->{name}} = $spell; |
3242 | |
3489 | |
3243 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3490 | $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3244 | face => $spell->{face}, |
3491 | face => $spell->{face}, |
3245 | can_hover => 1, |
3492 | can_hover => 1, |
3246 | can_events => 1, |
3493 | can_events => 1, |
3247 | tooltip => $spell->{message}); |
3494 | tooltip => $spell->{message}); |
3248 | |
3495 | |
3249 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3496 | $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3250 | text => $spell->{name}, |
3497 | text => $spell->{name}, |
3251 | can_hover => 1, |
3498 | can_hover => 1, |
3252 | can_events => 1, |
3499 | can_events => 1, |
3253 | tooltip => $spell->{message}, |
3500 | tooltip => $spell->{message}, |
3254 | expand => 1); |
3501 | expand => 1); |
3255 | |
3502 | |
3256 | $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3503 | $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3257 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3504 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3258 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3505 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3259 | expand => 1); |
3506 | expand => 1); |
3260 | |
3507 | |
3261 | $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3508 | $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3262 | text => "bind to key", |
3509 | text => "bind to key", |
3263 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3510 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3264 | } |
3511 | } |
3265 | |
3512 | |
3266 | sub rebuild_spell_list { |
3513 | sub rebuild_spell_list { |
… | |
… | |
3278 | ############################################################################# |
3525 | ############################################################################# |
3279 | |
3526 | |
3280 | package CFClient::UI::Root; |
3527 | package CFClient::UI::Root; |
3281 | |
3528 | |
3282 | our @ISA = CFClient::UI::Container::; |
3529 | our @ISA = CFClient::UI::Container::; |
|
|
3530 | |
|
|
3531 | use List::Util qw(min max); |
3283 | |
3532 | |
3284 | use CFClient::OpenGL; |
3533 | use CFClient::OpenGL; |
3285 | |
3534 | |
3286 | sub new { |
3535 | sub new { |
3287 | my $class = shift; |
3536 | my $class = shift; |
… | |
… | |
3422 | |
3671 | |
3423 | delete $queue{$widget+0}; |
3672 | delete $queue{$widget+0}; |
3424 | |
3673 | |
3425 | my ($w, $h) = $widget->size_request; |
3674 | my ($w, $h) = $widget->size_request; |
3426 | |
3675 | |
3427 | $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
3676 | $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
3428 | $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
3677 | $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
|
|
3678 | |
|
|
3679 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
|
|
3680 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
3429 | |
3681 | |
3430 | $w = $widget->{force_w} if exists $widget->{force_w}; |
3682 | $w = $widget->{force_w} if exists $widget->{force_w}; |
3431 | $h = $widget->{force_h} if exists $widget->{force_h}; |
3683 | $h = $widget->{force_h} if exists $widget->{force_h}; |
3432 | |
3684 | |
3433 | if ($widget->{req_w} != $w || $widget->{req_h} != $h |
3685 | if ($widget->{req_w} != $w || $widget->{req_h} != $h |