1 | package CFPlus::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 CFPlus; |
9 | use CFPlus; |
|
|
10 | use CFPlus::Pod; |
11 | use CFPlus::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; |
… | |
… | |
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; |
… | |
… | |
110 | } |
113 | } |
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; |
|
|
116 | $ev->{dy} = $ev->{button} * 2 - 9; |
118 | my $delta = $ev->{button} * 2 - 9; |
|
|
119 | my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT; |
|
|
120 | |
|
|
121 | $ev->{dx} = $shift ? $delta : 0; |
|
|
122 | $ev->{dy} = $shift ? 0 : $delta; |
|
|
123 | |
117 | $GRAB->emit (mouse_wheel => $ev); |
124 | $GRAB->emit (mouse_wheel => $ev); |
118 | } else { |
125 | } else { |
119 | $GRAB->emit (button_down => $ev) |
126 | $GRAB->emit (button_down => $ev) |
120 | } |
127 | } |
121 | } |
128 | } |
… | |
… | |
234 | h => undef, |
241 | h => undef, |
235 | can_events => 1, |
242 | can_events => 1, |
236 | @_ |
243 | @_ |
237 | }, $class; |
244 | }, $class; |
238 | |
245 | |
239 | Scalar::Util::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); |
246 | CFPlus::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); |
240 | |
247 | |
241 | for (keys %$self) { |
248 | for (keys %$self) { |
242 | if (/^on_(.*)$/) { |
249 | if (/^on_(.*)$/) { |
243 | $self->connect ($1 => delete $self->{$_}); |
250 | $self->connect ($1 => delete $self->{$_}); |
244 | } |
251 | } |
… | |
… | |
261 | |
268 | |
262 | sub destroy { |
269 | sub destroy { |
263 | my ($self) = @_; |
270 | my ($self) = @_; |
264 | |
271 | |
265 | $self->hide; |
272 | $self->hide; |
|
|
273 | $self->emit ("destroy"); |
266 | %$self = (); |
274 | %$self = (); |
|
|
275 | } |
|
|
276 | |
|
|
277 | sub TO_JSON { |
|
|
278 | { __widget_ref__ => $_[0]{s_id} } |
267 | } |
279 | } |
268 | |
280 | |
269 | sub show { |
281 | sub show { |
270 | my ($self) = @_; |
282 | my ($self) = @_; |
271 | |
283 | |
… | |
… | |
312 | sub set_visibility { |
324 | sub set_visibility { |
313 | my ($self, $visible) = @_; |
325 | my ($self, $visible) = @_; |
314 | |
326 | |
315 | return if $self->{visible} == $visible; |
327 | return if $self->{visible} == $visible; |
316 | |
328 | |
317 | $visible ? $self->hide |
329 | $visible ? $self->show |
318 | : $self->show; |
330 | : $self->hide; |
319 | } |
331 | } |
320 | |
332 | |
321 | sub toggle_visibility { |
333 | sub toggle_visibility { |
322 | my ($self) = @_; |
334 | my ($self) = @_; |
323 | |
335 | |
… | |
… | |
501 | |
513 | |
502 | defined wantarray and CFPlus::guard { |
514 | defined wantarray and CFPlus::guard { |
503 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
515 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
504 | @{ $self->{signal_cb}{$signal} }; |
516 | @{ $self->{signal_cb}{$signal} }; |
505 | } |
517 | } |
|
|
518 | } |
|
|
519 | |
|
|
520 | sub disconnect_all { |
|
|
521 | my ($self, $signal) = @_; |
|
|
522 | |
|
|
523 | delete $self->{signal_cb}{$signal}; |
506 | } |
524 | } |
507 | |
525 | |
508 | my %has_coords = ( |
526 | my %has_coords = ( |
509 | button_down => 1, |
527 | button_down => 1, |
510 | button_up => 1, |
528 | button_up => 1, |
… | |
… | |
513 | ); |
531 | ); |
514 | |
532 | |
515 | sub emit { |
533 | sub emit { |
516 | my ($self, $signal, @args) = @_; |
534 | my ($self, $signal, @args) = @_; |
517 | |
535 | |
518 | # I do not really like this solution, but I dislike duplication |
536 | # I do not really like this solution, but I do not like duplication |
519 | # and needlessly verbose code, too. |
537 | # and needlessly verbose code, either. |
520 | my @append |
538 | my @append |
521 | = $has_coords{$signal} |
539 | = $has_coords{$signal} |
522 | ? $args[0]->xy ($self) |
540 | ? $args[0]->xy ($self) |
523 | : (); |
541 | : (); |
524 | |
542 | |
525 | #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# |
543 | #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# |
526 | |
544 | |
527 | #d##TODO# stop propagating at first true, do not use sum |
545 | for my $cb ( |
528 | (List::Util::sum map $_->($self, @args, @append), @{$self->{signal_cb}{$signal} || []}) # before |
546 | @{$self->{signal_cb}{$signal} || []}, # before |
529 | || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args, @append) # closure |
547 | ($self->can ("invoke_$signal") || sub { 1 }), # closure |
|
|
548 | ) { |
|
|
549 | return $cb->($self, @args, @append) || next; |
|
|
550 | } |
|
|
551 | |
|
|
552 | # parent |
530 | || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent |
553 | $self->{parent} && $self->{parent}->emit ($signal, @args) |
531 | } |
554 | } |
532 | |
555 | |
533 | sub find_widget { |
556 | #sub find_widget { |
534 | my ($self, $x, $y) = @_; |
557 | # in .xs |
535 | |
|
|
536 | return () unless $self->{can_events}; |
|
|
537 | |
|
|
538 | return $self |
|
|
539 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
540 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
|
|
541 | |
|
|
542 | () |
|
|
543 | } |
|
|
544 | |
558 | |
545 | sub set_parent { |
559 | sub set_parent { |
546 | my ($self, $parent) = @_; |
560 | my ($self, $parent) = @_; |
547 | |
561 | |
548 | Scalar::Util::weaken ($self->{parent} = $parent); |
562 | CFPlus::weaken ($self->{parent} = $parent); |
549 | $self->set_visible if $parent->{visible}; |
563 | $self->set_visible if $parent->{visible}; |
550 | } |
564 | } |
551 | |
565 | |
552 | sub realloc { |
566 | sub realloc { |
553 | my ($self) = @_; |
567 | my ($self) = @_; |
… | |
… | |
632 | my ($self) = @_; |
646 | my ($self) = @_; |
633 | |
647 | |
634 | warn "no draw defined for $self\n"; |
648 | warn "no draw defined for $self\n"; |
635 | } |
649 | } |
636 | |
650 | |
|
|
651 | my $cntx;#d# |
637 | sub DESTROY { |
652 | sub DESTROY { |
638 | my ($self) = @_; |
653 | my ($self) = @_; |
639 | |
654 | |
640 | return if CFPlus::in_destruct; |
655 | return if CFPlus::in_destruct; |
641 | |
|
|
642 | delete $WIDGET{$self+0}; |
|
|
643 | |
656 | |
644 | eval { $self->destroy }; |
657 | eval { $self->destroy }; |
645 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
658 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
|
|
659 | |
|
|
660 | delete $WIDGET{$self+0}; |
646 | } |
661 | } |
647 | |
662 | |
648 | ############################################################################# |
663 | ############################################################################# |
649 | |
664 | |
650 | package CFPlus::UI::DrawBG; |
665 | package CFPlus::UI::DrawBG; |
… | |
… | |
726 | can_events => 0, |
741 | can_events => 0, |
727 | %arg, |
742 | %arg, |
728 | ); |
743 | ); |
729 | |
744 | |
730 | $self->add (@$children) |
745 | $self->add (@$children) |
731 | if $children; |
746 | if $children && @$children; |
732 | |
747 | |
733 | $self |
748 | $self |
734 | } |
749 | } |
735 | |
750 | |
736 | sub realloc { |
751 | sub realloc { |
… | |
… | |
745 | my ($self, @widgets) = @_; |
760 | my ($self, @widgets) = @_; |
746 | |
761 | |
747 | $_->set_parent ($self) |
762 | $_->set_parent ($self) |
748 | for @widgets; |
763 | for @widgets; |
749 | |
764 | |
|
|
765 | # TODO: only do this in widgets that need it, e.g. root, fixed |
750 | use sort 'stable'; |
766 | use sort 'stable'; |
751 | |
767 | |
752 | $self->{children} = [ |
768 | $self->{children} = [ |
753 | sort { $a->{z} <=> $b->{z} } |
769 | sort { $a->{z} <=> $b->{z} } |
754 | @{$self->{children}}, @widgets |
770 | @{$self->{children}}, @widgets |
… | |
… | |
773 | } |
789 | } |
774 | |
790 | |
775 | sub clear { |
791 | sub clear { |
776 | my ($self) = @_; |
792 | my ($self) = @_; |
777 | |
793 | |
778 | my $children = delete $self->{children}; |
794 | my $children = $self->{children}; |
779 | $self->{children} = []; |
795 | $self->{children} = []; |
780 | |
796 | |
781 | for (@$children) { |
797 | for (@$children) { |
782 | delete $_->{parent}; |
798 | delete $_->{parent}; |
783 | $_->hide; |
799 | $_->hide; |
… | |
… | |
897 | glClear GL_COLOR_BUFFER_BIT; |
913 | glClear GL_COLOR_BUFFER_BIT; |
898 | |
914 | |
899 | { |
915 | { |
900 | package CFPlus::UI::Base; |
916 | package CFPlus::UI::Base; |
901 | |
917 | |
902 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
918 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
903 | (0, 0, $self->{w}, $self->{h}); |
919 | (0, 0, $self->{w}, $self->{h}); |
|
|
920 | |
|
|
921 | $self->_render; |
904 | } |
922 | } |
905 | |
|
|
906 | $self->_render; |
|
|
907 | }; |
923 | }; |
908 | } |
924 | } |
909 | |
925 | |
910 | sub _draw { |
926 | sub _draw { |
911 | my ($self) = @_; |
927 | my ($self) = @_; |
912 | |
|
|
913 | my ($w, $h) = @$self{qw(w h)}; |
|
|
914 | |
928 | |
915 | my $tex = $self->{texture} |
929 | my $tex = $self->{texture} |
916 | or return; |
930 | or return; |
917 | |
931 | |
918 | glEnable GL_TEXTURE_2D; |
932 | glEnable GL_TEXTURE_2D; |
919 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
933 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
920 | glColor 0, 0, 0, 1; |
934 | glColor 0, 0, 0, 1; |
921 | |
935 | |
922 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
936 | $tex->draw_quad_alpha_premultiplied (0, 0); |
923 | |
937 | |
924 | glDisable GL_TEXTURE_2D; |
938 | glDisable GL_TEXTURE_2D; |
925 | } |
939 | } |
926 | |
940 | |
927 | ############################################################################# |
941 | ############################################################################# |
928 | |
942 | |
929 | package CFPlus::UI::ViewPort; |
943 | package CFPlus::UI::ViewPort; |
|
|
944 | |
|
|
945 | use List::Util qw(min max); |
930 | |
946 | |
931 | our @ISA = CFPlus::UI::Window::; |
947 | our @ISA = CFPlus::UI::Window::; |
932 | |
948 | |
933 | sub new { |
949 | sub new { |
934 | my $class = shift; |
950 | my $class = shift; |
… | |
… | |
943 | sub size_request { |
959 | sub size_request { |
944 | my ($self) = @_; |
960 | my ($self) = @_; |
945 | |
961 | |
946 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
962 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
947 | |
963 | |
948 | $w = 10 if $self->{scroll_x}; |
964 | $w = 1 if $self->{scroll_x}; |
949 | $h = 10 if $self->{scroll_y}; |
965 | $h = 1 if $self->{scroll_y}; |
950 | |
966 | |
951 | ($w, $h) |
967 | ($w, $h) |
952 | } |
968 | } |
953 | |
969 | |
954 | sub invoke_size_allocate { |
970 | sub invoke_size_allocate { |
… | |
… | |
966 | } |
982 | } |
967 | |
983 | |
968 | sub set_offset { |
984 | sub set_offset { |
969 | my ($self, $x, $y) = @_; |
985 | my ($self, $x, $y) = @_; |
970 | |
986 | |
|
|
987 | my $x = max 0, min $self->child->{w} - $self->{w}, int $x; |
|
|
988 | my $y = max 0, min $self->child->{h} - $self->{h}, int $y; |
|
|
989 | |
|
|
990 | if ($x != $self->{view_x} or $y != $self->{view_y}) { |
971 | $self->{view_x} = int $x; |
991 | $self->{view_x} = $x; |
972 | $self->{view_y} = int $y; |
992 | $self->{view_y} = $y; |
973 | |
993 | |
|
|
994 | $self->emit (changed => $x, $y); |
974 | $self->update; |
995 | $self->update; |
|
|
996 | } |
975 | } |
997 | } |
976 | |
998 | |
977 | # hmm, this does not work for topleft of $self... but we should not ask for that |
999 | # hmm, this does not work for topleft of $self... but we should not ask for that |
978 | sub coord2local { |
1000 | sub coord2local { |
979 | my ($self, $x, $y) = @_; |
1001 | my ($self, $x, $y) = @_; |
… | |
… | |
994 | my ($self, $x, $y) = @_; |
1016 | my ($self, $x, $y) = @_; |
995 | |
1017 | |
996 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
1018 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
997 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
1019 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
998 | ) { |
1020 | ) { |
999 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
1021 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
1000 | } else { |
1022 | } else { |
1001 | $self->CFPlus::UI::Base::find_widget ($x, $y) |
1023 | $self->CFPlus::UI::Base::find_widget ($x, $y) |
1002 | } |
1024 | } |
1003 | } |
1025 | } |
1004 | |
1026 | |
… | |
… | |
1015 | |
1037 | |
1016 | ############################################################################# |
1038 | ############################################################################# |
1017 | |
1039 | |
1018 | package CFPlus::UI::ScrolledWindow; |
1040 | package CFPlus::UI::ScrolledWindow; |
1019 | |
1041 | |
1020 | our @ISA = CFPlus::UI::HBox::; |
1042 | our @ISA = CFPlus::UI::Table::; |
1021 | |
1043 | |
1022 | sub new { |
1044 | sub new { |
1023 | my ($class, %arg) = @_; |
1045 | my ($class, %arg) = @_; |
1024 | |
1046 | |
1025 | my $child = delete $arg{child}; |
1047 | my $child = delete $arg{child}; |
1026 | |
1048 | |
1027 | my $self; |
1049 | my $self; |
1028 | |
1050 | |
1029 | my $slider = new CFPlus::UI::Slider |
1051 | my $hslider = new CFPlus::UI::Slider |
|
|
1052 | col => 0, |
|
|
1053 | row => 1, |
|
|
1054 | vertical => 0, |
|
|
1055 | range => [0, 0, 1, 0.01], # HACK fix |
|
|
1056 | on_changed => sub { |
|
|
1057 | $self->{hpos} = $_[1]; |
|
|
1058 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
|
|
1059 | }, |
|
|
1060 | ; |
|
|
1061 | |
|
|
1062 | my $vslider = new CFPlus::UI::Slider |
|
|
1063 | col => 1, |
|
|
1064 | row => 0, |
1030 | vertical => 1, |
1065 | vertical => 1, |
1031 | range => [0, 0, 1, 0.01], # HACK fix |
1066 | range => [0, 0, 1, 0.01], # HACK fix |
1032 | on_changed => sub { |
1067 | on_changed => sub { |
1033 | $self->{vp}->set_offset (0, $_[1]); |
1068 | $self->{vpos} = $_[1]; |
|
|
1069 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1034 | }, |
1070 | }, |
1035 | ; |
1071 | ; |
1036 | |
1072 | |
1037 | $self = $class->SUPER::new ( |
1073 | $self = $class->SUPER::new ( |
1038 | vp => (new CFPlus::UI::ViewPort expand => 1), |
1074 | scroll_x => 0, |
|
|
1075 | scroll_y => 1, |
1039 | can_events => 1, |
1076 | can_events => 1, |
1040 | slider => $slider, |
1077 | hslider => $hslider, |
|
|
1078 | vslider => $vslider, |
|
|
1079 | col_expand => [1, 0], |
|
|
1080 | row_expand => [1, 0], |
1041 | %arg, |
1081 | %arg, |
1042 | ); |
1082 | ); |
1043 | |
1083 | |
|
|
1084 | $self->{vp} = new CFPlus::UI::ViewPort |
|
|
1085 | col => 0, |
|
|
1086 | row => 0, |
|
|
1087 | expand => 1, |
|
|
1088 | scroll_x => $self->{scroll_x}, |
|
|
1089 | scroll_y => $self->{scroll_y}, |
|
|
1090 | on_changed => sub { |
|
|
1091 | my ($vp, $x, $y) = @_; |
|
|
1092 | |
|
|
1093 | $vp->{parent}{hslider}->set_value ($x); |
|
|
1094 | $vp->{parent}{vslider}->set_value ($y); |
|
|
1095 | |
|
|
1096 | 0 |
|
|
1097 | }, |
|
|
1098 | ; |
|
|
1099 | |
1044 | $self->SUPER::add ($self->{vp}, $self->{slider}); |
1100 | $self->SUPER::add ($self->{vp}); |
|
|
1101 | |
1045 | $self->add ($child) if $child; |
1102 | $self->add ($child) if $child; |
1046 | |
1103 | |
1047 | $self |
1104 | $self |
1048 | } |
1105 | } |
1049 | |
|
|
1050 | #TODO# update range on size_allocate depending on child |
|
|
1051 | |
1106 | |
1052 | sub add { |
1107 | sub add { |
1053 | my ($self, $widget) = @_; |
1108 | my ($self, $widget) = @_; |
1054 | |
1109 | |
1055 | $self->{vp}->add ($self->{child} = $widget); |
1110 | $self->{vp}->add ($self->{child} = $widget); |
1056 | } |
1111 | } |
1057 | |
1112 | |
|
|
1113 | sub update_slider { |
|
|
1114 | my ($self) = @_; |
|
|
1115 | |
|
|
1116 | my $child = ($self->{vp} or return)->child; |
|
|
1117 | |
|
|
1118 | my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); |
|
|
1119 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
|
|
1120 | |
|
|
1121 | my $visible = $w1 > $w2; |
|
|
1122 | if ($visible != $self->{hslider_visible}) { |
|
|
1123 | $self->{hslider_visible} = $visible; |
|
|
1124 | $visible ? $self->SUPER::add ($self->{hslider}) |
|
|
1125 | : $self->SUPER::remove ($self->{hslider}); |
|
|
1126 | } |
|
|
1127 | |
|
|
1128 | my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); |
|
|
1129 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
|
|
1130 | |
|
|
1131 | my $visible = $h1 > $h2; |
|
|
1132 | if ($visible != $self->{vslider_visible}) { |
|
|
1133 | $self->{vslider_visible} = $visible; |
|
|
1134 | $visible ? $self->SUPER::add ($self->{vslider}) |
|
|
1135 | : $self->SUPER::remove ($self->{vslider}); |
|
|
1136 | } |
|
|
1137 | } |
|
|
1138 | |
1058 | sub invoke_mouse_wheel { |
1139 | sub invoke_mouse_wheel { |
1059 | my ($self, $ev) = @_; |
1140 | my ($self, $ev) = @_; |
1060 | |
1141 | |
1061 | return 0 unless $ev->{dy}; # only vertical movements |
|
|
1062 | |
|
|
1063 | $self->{slider}->emit (mouse_wheel => $ev); |
1142 | $self->{vslider}->emit (mouse_wheel => $ev) |
|
|
1143 | if $ev->{dy}; |
|
|
1144 | |
|
|
1145 | $self->{hslider}->emit (mouse_wheel => $ev) |
|
|
1146 | if $ev->{dx}; |
1064 | |
1147 | |
1065 | 1 |
1148 | 1 |
1066 | } |
1149 | } |
1067 | |
1150 | |
1068 | sub update_slider { |
1151 | sub invoke_button_down { |
1069 | my ($self) = @_; |
1152 | my ($self, $ev, $x, $y) = @_; |
1070 | |
1153 | |
1071 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); |
1154 | if ($ev->{button} == 2) { |
1072 | } |
1155 | $self->grab_focus; |
1073 | |
1156 | |
1074 | sub update { |
1157 | my $ox = $self->{vp}{view_x} + $ev->{x}; |
1075 | my ($self) = @_; |
1158 | my $oy = $self->{vp}{view_y} + $ev->{y}; |
|
|
1159 | |
|
|
1160 | $self->{motion} = sub { |
|
|
1161 | my ($ev, $x, $y) = @_; |
1076 | |
1162 | |
1077 | $self->SUPER::update; |
1163 | $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y}); |
|
|
1164 | $self->update; |
|
|
1165 | }; |
1078 | |
1166 | |
1079 | $self->update_slider; |
1167 | return 1; |
|
|
1168 | } |
|
|
1169 | |
|
|
1170 | 0 |
|
|
1171 | } |
|
|
1172 | |
|
|
1173 | sub invoke_button_up { |
|
|
1174 | my ($self, $ev, $x, $y) = @_; |
|
|
1175 | |
|
|
1176 | if (delete $self->{motion}) { |
|
|
1177 | return 1; |
|
|
1178 | } |
|
|
1179 | |
|
|
1180 | 0 |
|
|
1181 | } |
|
|
1182 | |
|
|
1183 | sub invoke_mouse_motion { |
|
|
1184 | my ($self, $ev, $x, $y) = @_; |
|
|
1185 | |
|
|
1186 | if ($self->{motion}) { |
|
|
1187 | $self->{motion}->($ev, $x, $y); |
|
|
1188 | return 1; |
|
|
1189 | } |
|
|
1190 | |
|
|
1191 | 0 |
1080 | } |
1192 | } |
1081 | |
1193 | |
1082 | sub invoke_size_allocate { |
1194 | sub invoke_size_allocate { |
1083 | my ($self, $w, $h) = @_; |
1195 | my ($self, $w, $h) = @_; |
1084 | |
1196 | |
1085 | $self->update_slider; |
1197 | $self->update_slider; |
1086 | |
|
|
1087 | $self->SUPER::invoke_size_allocate ($w, $h) |
1198 | $self->SUPER::invoke_size_allocate ($w, $h) |
1088 | } |
1199 | } |
1089 | |
1200 | |
1090 | ############################################################################# |
1201 | ############################################################################# |
1091 | |
1202 | |
… | |
… | |
1133 | |
1244 | |
1134 | our @ISA = CFPlus::UI::Bin::; |
1245 | our @ISA = CFPlus::UI::Bin::; |
1135 | |
1246 | |
1136 | use CFPlus::OpenGL; |
1247 | use CFPlus::OpenGL; |
1137 | |
1248 | |
|
|
1249 | sub new { |
|
|
1250 | my ($class, %arg) = @_; |
|
|
1251 | |
|
|
1252 | if ((exists $arg{label}) && !ref $arg{label}) { |
|
|
1253 | $arg{label} = new CFPlus::UI::Label |
|
|
1254 | align => 1, |
|
|
1255 | valign => 0, |
|
|
1256 | text => $arg{label}, |
|
|
1257 | fontsize => ($arg{border} || 0.8) * 0.75; |
|
|
1258 | } |
|
|
1259 | |
|
|
1260 | my $self = $class->SUPER::new ( |
|
|
1261 | # label => "", |
|
|
1262 | fg => [0.6, 0.3, 0.1], |
|
|
1263 | border => 0.8, |
|
|
1264 | style => 'single', |
|
|
1265 | %arg, |
|
|
1266 | ); |
|
|
1267 | |
|
|
1268 | $self |
|
|
1269 | } |
|
|
1270 | |
|
|
1271 | sub add { |
|
|
1272 | my ($self, @widgets) = @_; |
|
|
1273 | |
|
|
1274 | $self->SUPER::add (@widgets); |
|
|
1275 | $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label}; |
|
|
1276 | } |
|
|
1277 | |
|
|
1278 | sub border { |
|
|
1279 | int $_[0]{border} * $::FONTSIZE |
|
|
1280 | } |
|
|
1281 | |
|
|
1282 | sub size_request { |
|
|
1283 | my ($self) = @_; |
|
|
1284 | |
|
|
1285 | ($self->{label_w}, undef) = $self->{label}->size_request |
|
|
1286 | if $self->{label}; |
|
|
1287 | |
|
|
1288 | my ($w, $h) = $self->SUPER::size_request; |
|
|
1289 | |
|
|
1290 | ( |
|
|
1291 | $w + $self->border * 2, |
|
|
1292 | $h + $self->border * 2, |
|
|
1293 | ) |
|
|
1294 | } |
|
|
1295 | |
|
|
1296 | sub invoke_size_allocate { |
|
|
1297 | my ($self, $w, $h) = @_; |
|
|
1298 | |
|
|
1299 | my $border = $self->border; |
|
|
1300 | |
|
|
1301 | $w -= List::Util::max 0, $border * 2; |
|
|
1302 | $h -= List::Util::max 0, $border * 2; |
|
|
1303 | |
|
|
1304 | if (my $label = $self->{label}) { |
|
|
1305 | $label->{w} = List::Util::max 0, List::Util::min $self->{label_w}, $w - $border * 2; |
|
|
1306 | $label->{h} = List::Util::min $h, $border; |
|
|
1307 | $label->invoke_size_allocate ($label->{w}, $label->{h}); |
|
|
1308 | } |
|
|
1309 | |
|
|
1310 | $self->child->configure ($border, $border, $w, $h); |
|
|
1311 | |
|
|
1312 | 1 |
|
|
1313 | } |
|
|
1314 | |
|
|
1315 | sub _draw { |
|
|
1316 | my ($self) = @_; |
|
|
1317 | |
|
|
1318 | my $child = $self->{children}[0]; |
|
|
1319 | |
|
|
1320 | my $border = $self->border; |
|
|
1321 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1322 | |
|
|
1323 | $child->draw; |
|
|
1324 | |
|
|
1325 | glColor @{$self->{fg}}; |
|
|
1326 | glBegin GL_LINE_STRIP; |
|
|
1327 | glVertex $border * 1.5 , $border * 0.5 + 0.5; |
|
|
1328 | glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; |
|
|
1329 | glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
|
|
1330 | glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
|
|
1331 | glVertex $w - $border * 0.5 + 0.5, $border * 0.5 + 0.5; |
|
|
1332 | glVertex $self->{label} ? $border * 2 + $self->{label}{w} : $border * 1.5, $border * 0.5 + 0.5; |
|
|
1333 | glEnd; |
|
|
1334 | |
|
|
1335 | if ($self->{label}) { |
|
|
1336 | glTranslate $border * 2, 0; |
|
|
1337 | $self->{label}->_draw; |
|
|
1338 | } |
|
|
1339 | } |
|
|
1340 | |
|
|
1341 | ############################################################################# |
|
|
1342 | |
|
|
1343 | package CFPlus::UI::Toplevel; |
|
|
1344 | |
|
|
1345 | our @ISA = CFPlus::UI::Bin::; |
|
|
1346 | |
|
|
1347 | use CFPlus::OpenGL; |
|
|
1348 | |
1138 | my $bg = |
1349 | my $bg = |
1139 | new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", |
1350 | new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", |
1140 | mipmap => 1, wrap => 1; |
1351 | mipmap => 1, wrap => 1; |
1141 | |
1352 | |
1142 | my @border = |
1353 | my @border = |
1143 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1354 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1144 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1355 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
1356 | |
|
|
1357 | my @icon = |
|
|
1358 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
|
|
1359 | qw(x1_move.png x1_resize.png); |
1145 | |
1360 | |
1146 | sub new { |
1361 | sub new { |
1147 | my ($class, %arg) = @_; |
1362 | my ($class, %arg) = @_; |
1148 | |
1363 | |
1149 | my $self = $class->SUPER::new ( |
1364 | my $self = $class->SUPER::new ( |
… | |
… | |
1318 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1533 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1319 | |
1534 | |
1320 | my $border = $self->border; |
1535 | my $border = $self->border; |
1321 | |
1536 | |
1322 | glColor @{ $self->{border_bg} }; |
1537 | glColor @{ $self->{border_bg} }; |
1323 | $border[0]->draw_quad_alpha (0, 0, $w, $border); |
1538 | $border[0]->draw_quad_alpha ( 0, 0, $w, $border); |
1324 | $border[1]->draw_quad_alpha (0, $border, $border, $ch); |
1539 | $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); |
1325 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1540 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1326 | $border[3]->draw_quad_alpha (0, $h - $border, $w, $border); |
1541 | $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); |
|
|
1542 | |
|
|
1543 | # move |
|
|
1544 | my $w2 = ($w - $border) * .5; |
|
|
1545 | my $h2 = ($h - $border) * .5; |
|
|
1546 | $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); |
|
|
1547 | $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); |
|
|
1548 | $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); |
|
|
1549 | |
|
|
1550 | # resize |
|
|
1551 | $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); |
|
|
1552 | $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) |
|
|
1553 | unless $self->{has_close_button}; |
|
|
1554 | $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); |
|
|
1555 | $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); |
1327 | |
1556 | |
1328 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1557 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1329 | glColor @{ $self->{bg} }; |
1558 | glColor @{ $self->{bg} }; |
1330 | |
1559 | |
1331 | # TODO: repeat texture not scale |
1560 | # TODO: repeat texture not scale |
… | |
… | |
1352 | |
1581 | |
1353 | ############################################################################# |
1582 | ############################################################################# |
1354 | |
1583 | |
1355 | package CFPlus::UI::Table; |
1584 | package CFPlus::UI::Table; |
1356 | |
1585 | |
1357 | our @ISA = CFPlus::UI::Base::; |
1586 | our @ISA = CFPlus::UI::Container::; |
1358 | |
1587 | |
1359 | use List::Util qw(max sum); |
1588 | use List::Util qw(max sum); |
1360 | |
1589 | |
1361 | use CFPlus::OpenGL; |
1590 | use CFPlus::OpenGL; |
1362 | |
1591 | |
1363 | sub new { |
1592 | sub new { |
1364 | my $class = shift; |
1593 | my $class = shift; |
1365 | |
1594 | |
1366 | $class->SUPER::new ( |
1595 | $class->SUPER::new ( |
1367 | col_expand => [], |
1596 | col_expand => [], |
|
|
1597 | row_expand => [], |
1368 | @_, |
1598 | @_, |
1369 | ) |
1599 | ) |
1370 | } |
1600 | } |
1371 | |
1601 | |
1372 | sub children { |
|
|
1373 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1374 | } |
|
|
1375 | |
|
|
1376 | sub add { |
1602 | sub add { |
|
|
1603 | my ($self, @widgets) = @_; |
|
|
1604 | |
|
|
1605 | for my $child (@widgets) { |
|
|
1606 | $child->{rowspan} ||= 1; |
|
|
1607 | $child->{colspan} ||= 1; |
|
|
1608 | } |
|
|
1609 | |
|
|
1610 | $self->SUPER::add (@widgets); |
|
|
1611 | } |
|
|
1612 | |
|
|
1613 | sub add_at { |
1377 | my ($self) = shift; |
1614 | my $self = shift; |
|
|
1615 | |
|
|
1616 | my @widgets; |
1378 | |
1617 | |
1379 | while (@_) { |
1618 | while (@_) { |
1380 | my ($x, $y, $child) = splice @_, 0, 3, (); |
1619 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1381 | $child->set_parent ($self); |
|
|
1382 | $self->{children}[$y][$x] = $child; |
|
|
1383 | } |
|
|
1384 | |
1620 | |
1385 | $self->{force_realloc} = 1; |
1621 | $child->{row} = $row; |
1386 | $self->{force_size_alloc} = 1; |
1622 | $child->{col} = $col; |
1387 | $self->realloc; |
|
|
1388 | } |
|
|
1389 | |
1623 | |
1390 | sub remove { |
1624 | push @widgets, $child; |
|
|
1625 | } |
|
|
1626 | |
|
|
1627 | $self->add (@widgets); |
|
|
1628 | } |
|
|
1629 | |
|
|
1630 | sub get_wh { |
1391 | my ($self, $child) = @_; |
1631 | my ($self) = @_; |
1392 | |
1632 | |
1393 | # TODO: not yet implemented |
1633 | my (@w, @h); |
1394 | } |
|
|
1395 | |
|
|
1396 | # TODO: move to container class maybe? send children a signal on removal? |
|
|
1397 | sub clear { |
|
|
1398 | my ($self) = @_; |
|
|
1399 | |
1634 | |
1400 | my @children = $self->children; |
1635 | my @children = $self->children; |
1401 | delete $self->{children}; |
1636 | |
|
|
1637 | # first pass, columns |
|
|
1638 | for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { |
|
|
1639 | my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; |
|
|
1640 | |
|
|
1641 | my $sw = sum @w[$c .. $c + $cs - 1]; |
|
|
1642 | |
|
|
1643 | if ($w > $sw) { |
|
|
1644 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
|
|
1645 | } |
1402 | |
1646 | } |
1403 | for (@children) { |
|
|
1404 | delete $_->{parent}; |
|
|
1405 | $_->hide; |
|
|
1406 | } |
|
|
1407 | |
1647 | |
1408 | $self->realloc; |
1648 | # second pass, rows |
1409 | } |
1649 | for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { |
1410 | |
|
|
1411 | sub get_wh { |
|
|
1412 | my ($self) = @_; |
|
|
1413 | |
|
|
1414 | my (@w, @h); |
|
|
1415 | |
|
|
1416 | for my $y (0 .. $#{$self->{children}}) { |
|
|
1417 | my $row = $self->{children}[$y] |
|
|
1418 | or next; |
|
|
1419 | |
|
|
1420 | for my $x (0 .. $#$row) { |
|
|
1421 | my $widget = $row->[$x] |
|
|
1422 | or next; |
|
|
1423 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
1650 | my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; |
1424 | |
1651 | |
1425 | $w[$x] = max $w[$x], $w; |
1652 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1426 | $h[$y] = max $h[$y], $h; |
1653 | |
|
|
1654 | if ($h > $sh) { |
|
|
1655 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1427 | } |
1656 | } |
1428 | } |
1657 | } |
1429 | |
1658 | |
1430 | (\@w, \@h) |
1659 | (\@w, \@h) |
1431 | } |
1660 | } |
… | |
… | |
1447 | my ($ws, $hs) = $self->get_wh; |
1676 | my ($ws, $hs) = $self->get_wh; |
1448 | |
1677 | |
1449 | my $req_w = (sum @$ws) || 1; |
1678 | my $req_w = (sum @$ws) || 1; |
1450 | my $req_h = (sum @$hs) || 1; |
1679 | my $req_h = (sum @$hs) || 1; |
1451 | |
1680 | |
1452 | # TODO: nicer code && do row_expand |
1681 | # now linearly scale the rows/columns to the allocated size |
1453 | my @col_expand = @{$self->{col_expand}}; |
1682 | my @col_expand = @{$self->{col_expand}}; |
1454 | @col_expand = (1) x @$ws unless @col_expand; |
1683 | @col_expand = (1) x @$ws unless @col_expand; |
1455 | my $col_expand = (sum @col_expand) || 1; |
1684 | my $col_expand = (sum @col_expand) || 1; |
1456 | |
1685 | |
1457 | # linearly scale sizes |
|
|
1458 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1686 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1459 | $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; |
|
|
1460 | |
1687 | |
1461 | CFPlus::UI::harmonize $ws; |
1688 | CFPlus::UI::harmonize $ws; |
|
|
1689 | |
|
|
1690 | my @row_expand = @{$self->{row_expand}}; |
|
|
1691 | @row_expand = (1) x @$ws unless @row_expand; |
|
|
1692 | my $row_expand = (sum @row_expand) || 1; |
|
|
1693 | |
|
|
1694 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
|
|
1695 | |
1462 | CFPlus::UI::harmonize $hs; |
1696 | CFPlus::UI::harmonize $hs; |
1463 | |
1697 | |
1464 | my $y; |
1698 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
|
|
1699 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1465 | |
1700 | |
1466 | for my $r (0 .. $#{$self->{children}}) { |
1701 | for my $widget ($self->children) { |
1467 | my $row = $self->{children}[$r] |
1702 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; |
1468 | or next; |
|
|
1469 | |
1703 | |
1470 | my $x = 0; |
1704 | $widget->configure ( |
1471 | my $row_h = $hs->[$r]; |
1705 | $x[$c], $y[$r], |
|
|
1706 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1472 | |
1707 | ); |
1473 | for my $c (0 .. $#$row) { |
1708 | } |
1474 | my $col_w = $ws->[$c]; |
|
|
1475 | |
1709 | |
1476 | if (my $widget = $row->[$c]) { |
1710 | 1 |
1477 | $widget->configure ($x, $y, $col_w, $row_h); |
1711 | } |
1478 | } |
|
|
1479 | |
1712 | |
1480 | $x += $col_w; |
1713 | ############################################################################# |
|
|
1714 | |
|
|
1715 | package CFPlus::UI::Fixed; |
|
|
1716 | |
|
|
1717 | use List::Util qw(min max); |
|
|
1718 | |
|
|
1719 | our @ISA = CFPlus::UI::Container::; |
|
|
1720 | |
|
|
1721 | sub add { |
|
|
1722 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
|
|
1723 | |
|
|
1724 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
|
|
1725 | $self->SUPER::add ($child); |
|
|
1726 | } |
|
|
1727 | |
|
|
1728 | sub _scale($$$) { |
|
|
1729 | my ($mode, $val, $max) = @_; |
|
|
1730 | |
|
|
1731 | $mode eq "abs" ? $val |
|
|
1732 | : $mode eq "rel" ? $val * $max |
|
|
1733 | : 0 |
|
|
1734 | } |
|
|
1735 | |
|
|
1736 | sub size_request { |
|
|
1737 | my ($self) = @_; |
|
|
1738 | |
|
|
1739 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
|
|
1740 | |
|
|
1741 | # determine overall size by querying abs widgets |
|
|
1742 | for my $child ($self->visible_children) { |
|
|
1743 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
|
|
1744 | |
|
|
1745 | if ($pos eq "abs") { |
|
|
1746 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1747 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1748 | |
|
|
1749 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
|
|
1750 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1481 | } |
1751 | } |
|
|
1752 | } |
1482 | |
1753 | |
1483 | $y += $row_h; |
1754 | my $W = $x2 - $x1; |
|
|
1755 | my $H = $y2 - $y1; |
|
|
1756 | |
|
|
1757 | # now layout remaining widgets |
|
|
1758 | for my $child ($self->visible_children) { |
|
|
1759 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
|
|
1760 | |
|
|
1761 | if ($pos ne "abs") { |
|
|
1762 | $x = _scale $pos, $x, $W; |
|
|
1763 | $y = _scale $pos, $x, $H; |
|
|
1764 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1765 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1766 | |
|
|
1767 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
|
|
1768 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
|
|
1769 | } |
|
|
1770 | } |
|
|
1771 | |
|
|
1772 | my $W = $x2 - $x1; |
|
|
1773 | my $H = $y2 - $y1; |
|
|
1774 | |
|
|
1775 | ($W, $H) |
|
|
1776 | } |
|
|
1777 | |
|
|
1778 | sub invoke_size_allocate { |
|
|
1779 | my ($self, $W, $H) = @_; |
|
|
1780 | |
|
|
1781 | for my $child ($self->visible_children) { |
|
|
1782 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
|
|
1783 | |
|
|
1784 | $x = _scale $pos, $x, $W; |
|
|
1785 | $y = _scale $pos, $x, $H; |
|
|
1786 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1787 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1788 | |
|
|
1789 | $child->configure ($x, $y, $w, $h); |
1484 | } |
1790 | } |
1485 | |
1791 | |
1486 | 1 |
1792 | 1 |
1487 | } |
|
|
1488 | |
|
|
1489 | sub find_widget { |
|
|
1490 | my ($self, $x, $y) = @_; |
|
|
1491 | |
|
|
1492 | $x -= $self->{x}; |
|
|
1493 | $y -= $self->{y}; |
|
|
1494 | |
|
|
1495 | my $res; |
|
|
1496 | |
|
|
1497 | for (grep $_, map @$_, grep $_, @{ $self->{children} }) { |
|
|
1498 | $res = $_->find_widget ($x, $y) |
|
|
1499 | and return $res; |
|
|
1500 | } |
|
|
1501 | |
|
|
1502 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
|
|
1503 | } |
|
|
1504 | |
|
|
1505 | sub _draw { |
|
|
1506 | my ($self) = @_; |
|
|
1507 | |
|
|
1508 | for (grep $_, @{$self->{children}}) { |
|
|
1509 | $_->draw for grep $_, @$_; |
|
|
1510 | } |
|
|
1511 | } |
1793 | } |
1512 | |
1794 | |
1513 | ############################################################################# |
1795 | ############################################################################# |
1514 | |
1796 | |
1515 | package CFPlus::UI::Box; |
1797 | package CFPlus::UI::Box; |
… | |
… | |
1617 | #active_bg => none |
1899 | #active_bg => none |
1618 | #font => default_font |
1900 | #font => default_font |
1619 | #text => initial text |
1901 | #text => initial text |
1620 | #markup => initial narkup |
1902 | #markup => initial narkup |
1621 | #max_w => maximum pixel width |
1903 | #max_w => maximum pixel width |
|
|
1904 | #style => 0, # render flags |
1622 | ellipsise => 3, # end |
1905 | ellipsise => 3, # end |
1623 | layout => (new CFPlus::Layout), |
1906 | layout => (new CFPlus::Layout), |
1624 | fontsize => 1, |
1907 | fontsize => 1, |
1625 | align => -1, |
1908 | align => -1, |
1626 | valign => -1, |
1909 | valign => -1, |
… | |
… | |
1777 | }; |
2060 | }; |
1778 | |
2061 | |
1779 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
2062 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
1780 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
2063 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
1781 | |
2064 | |
1782 | $self->{layout}->render ($self->{ox}, $self->{oy}); |
2065 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
1783 | } |
2066 | } |
1784 | |
2067 | |
1785 | ############################################################################# |
2068 | ############################################################################# |
1786 | |
2069 | |
1787 | package CFPlus::UI::EntryBase; |
2070 | package CFPlus::UI::EntryBase; |
… | |
… | |
1800 | active_fg => [0, 0, 0], |
2083 | active_fg => [0, 0, 0], |
1801 | can_hover => 1, |
2084 | can_hover => 1, |
1802 | can_focus => 1, |
2085 | can_focus => 1, |
1803 | valign => 0, |
2086 | valign => 0, |
1804 | can_events => 1, |
2087 | can_events => 1, |
|
|
2088 | ellipsise => 0, |
1805 | #text => ... |
2089 | #text => ... |
1806 | #hidden => "*", |
2090 | #hidden => "*", |
1807 | @_ |
2091 | @_ |
1808 | ) |
2092 | ) |
1809 | } |
2093 | } |
… | |
… | |
1853 | my $mod = $ev->{mod}; |
2137 | my $mod = $ev->{mod}; |
1854 | my $sym = $ev->{sym}; |
2138 | my $sym = $ev->{sym}; |
1855 | my $uni = $ev->{unicode}; |
2139 | my $uni = $ev->{unicode}; |
1856 | |
2140 | |
1857 | my $text = $self->get_text; |
2141 | my $text = $self->get_text; |
|
|
2142 | |
|
|
2143 | $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; |
1858 | |
2144 | |
1859 | if ($uni == 8) { |
2145 | if ($uni == 8) { |
1860 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
2146 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1861 | } elsif ($uni == 127) { |
2147 | } elsif ($uni == 127) { |
1862 | substr $text, $self->{cursor}, 1, ""; |
2148 | substr $text, $self->{cursor}, 1, ""; |
1863 | } elsif ($sym == CFPlus::SDLK_LEFT) { |
2149 | } elsif ($sym == CFPlus::SDLK_LEFT) { |
1864 | --$self->{cursor} if $self->{cursor}; |
2150 | --$self->{cursor} if $self->{cursor}; |
1865 | } elsif ($sym == CFPlus::SDLK_RIGHT) { |
2151 | } elsif ($sym == CFPlus::SDLK_RIGHT) { |
1866 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
2152 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1867 | } elsif ($sym == CFPlus::SDLK_HOME) { |
2153 | } elsif ($sym == CFPlus::SDLK_HOME) { |
|
|
2154 | # what a hack |
|
|
2155 | $self->{cursor} = |
|
|
2156 | (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ |
|
|
2157 | ? length $1 |
|
|
2158 | : 0; |
|
|
2159 | } elsif ($sym == CFPlus::SDLK_END) { |
|
|
2160 | # uh, again |
|
|
2161 | $self->{cursor} = |
|
|
2162 | (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ |
|
|
2163 | ? $self->{cursor} + length $1 |
|
|
2164 | : length $self->{text}; |
|
|
2165 | } elsif ($uni == 21) { # ctrl-u |
|
|
2166 | $text = ""; |
1868 | $self->{cursor} = 0; |
2167 | $self->{cursor} = 0; |
1869 | } elsif ($sym == CFPlus::SDLK_END) { |
|
|
1870 | $self->{cursor} = length $text; |
|
|
1871 | } elsif ($uni == 27) { |
2168 | } elsif ($uni == 27) { |
1872 | $self->emit ('escape'); |
2169 | $self->emit ('escape'); |
1873 | } elsif ($uni) { |
2170 | } elsif ($uni == 0x0d) { |
|
|
2171 | substr $text, $self->{cursor}++, 0, "\012"; |
|
|
2172 | } elsif ($uni >= 0x20) { |
1874 | substr $text, $self->{cursor}++, 0, chr $uni; |
2173 | substr $text, $self->{cursor}++, 0, chr $uni; |
1875 | } else { |
2174 | } else { |
1876 | return 0; |
2175 | return 0; |
1877 | } |
2176 | } |
1878 | |
2177 | |
1879 | $self->_set_text ($text); |
2178 | $self->_set_text ($text); |
1880 | |
2179 | |
1881 | $self->realloc; |
2180 | $self->realloc; |
|
|
2181 | $self->update; |
1882 | |
2182 | |
1883 | 1 |
2183 | 1 |
1884 | } |
2184 | } |
1885 | |
2185 | |
1886 | sub invoke_focus_in { |
2186 | sub invoke_focus_in { |
… | |
… | |
1948 | utf8::encode $text; |
2248 | utf8::encode $text; |
1949 | |
2249 | |
1950 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
2250 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
1951 | } |
2251 | } |
1952 | |
2252 | |
1953 | glColor @{$self->{fg}}; |
|
|
1954 | glBegin GL_LINES; |
2253 | glBegin GL_LINES; |
1955 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2254 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
1956 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2255 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
1957 | glEnd; |
2256 | glEnd; |
1958 | } |
2257 | } |
1959 | } |
2258 | } |
|
|
2259 | |
|
|
2260 | ############################################################################# |
1960 | |
2261 | |
1961 | package CFPlus::UI::Entry; |
2262 | package CFPlus::UI::Entry; |
1962 | |
2263 | |
1963 | our @ISA = CFPlus::UI::EntryBase::; |
2264 | our @ISA = CFPlus::UI::EntryBase::; |
1964 | |
2265 | |
… | |
… | |
1967 | sub invoke_key_down { |
2268 | sub invoke_key_down { |
1968 | my ($self, $ev) = @_; |
2269 | my ($self, $ev) = @_; |
1969 | |
2270 | |
1970 | my $sym = $ev->{sym}; |
2271 | my $sym = $ev->{sym}; |
1971 | |
2272 | |
1972 | if ($sym == 13) { |
2273 | if ($ev->{uni} == 0x0d || $sym == 13) { |
1973 | unshift @{$self->{history}}, |
2274 | unshift @{$self->{history}}, |
1974 | my $txt = $self->get_text; |
2275 | my $txt = $self->get_text; |
1975 | |
2276 | |
1976 | $self->{history_pointer} = -1; |
2277 | $self->{history_pointer} = -1; |
1977 | $self->{history_saveback} = ''; |
2278 | $self->{history_saveback} = ''; |
… | |
… | |
2007 | 1 |
2308 | 1 |
2008 | } |
2309 | } |
2009 | |
2310 | |
2010 | ############################################################################# |
2311 | ############################################################################# |
2011 | |
2312 | |
|
|
2313 | package CFPlus::UI::TextEdit; |
|
|
2314 | |
|
|
2315 | our @ISA = CFPlus::UI::EntryBase::; |
|
|
2316 | |
|
|
2317 | use CFPlus::OpenGL; |
|
|
2318 | |
|
|
2319 | sub move_cursor_ver { |
|
|
2320 | my ($self, $dy) = @_; |
|
|
2321 | |
|
|
2322 | my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); |
|
|
2323 | |
|
|
2324 | $y += $dy; |
|
|
2325 | |
|
|
2326 | if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { |
|
|
2327 | $self->{cursor} = $index; |
|
|
2328 | delete $self->{cur_h}; |
|
|
2329 | $self->update; |
|
|
2330 | return; |
|
|
2331 | } |
|
|
2332 | } |
|
|
2333 | |
|
|
2334 | sub invoke_key_down { |
|
|
2335 | my ($self, $ev) = @_; |
|
|
2336 | |
|
|
2337 | my $sym = $ev->{sym}; |
|
|
2338 | |
|
|
2339 | if ($sym == CFPlus::SDLK_UP) { |
|
|
2340 | $self->move_cursor_ver (-1); |
|
|
2341 | } elsif ($sym == CFPlus::SDLK_DOWN) { |
|
|
2342 | $self->move_cursor_ver (+1); |
|
|
2343 | } else { |
|
|
2344 | return $self->SUPER::invoke_key_down ($ev) |
|
|
2345 | } |
|
|
2346 | |
|
|
2347 | 1 |
|
|
2348 | } |
|
|
2349 | |
|
|
2350 | ############################################################################# |
|
|
2351 | |
2012 | package CFPlus::UI::Button; |
2352 | package CFPlus::UI::Button; |
2013 | |
2353 | |
2014 | our @ISA = CFPlus::UI::Label::; |
2354 | our @ISA = CFPlus::UI::Label::; |
2015 | |
2355 | |
2016 | use CFPlus::OpenGL; |
2356 | use CFPlus::OpenGL; |
2017 | |
2357 | |
2018 | my @tex = |
2358 | my @tex = |
2019 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2359 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2020 | qw(b1_button_active.png); |
2360 | qw(b1_button_inactive.png b1_button_active.png); |
2021 | |
2361 | |
2022 | sub new { |
2362 | sub new { |
2023 | my $class = shift; |
2363 | my $class = shift; |
2024 | |
2364 | |
2025 | $class->SUPER::new ( |
2365 | $class->SUPER::new ( |
2026 | padding_x => 4, |
2366 | padding_x => 4, |
2027 | padding_y => 4, |
2367 | padding_y => 4, |
2028 | fg => [1, 1, 1], |
2368 | fg => [1.0, 1.0, 1.0], |
2029 | active_fg => [0, 0, 1], |
2369 | active_fg => [0.8, 0.8, 0.8], |
2030 | can_hover => 1, |
2370 | can_hover => 1, |
2031 | align => 0, |
2371 | align => 0, |
2032 | valign => 0, |
2372 | valign => 0, |
2033 | can_events => 1, |
2373 | can_events => 1, |
2034 | @_ |
2374 | @_ |
… | |
… | |
2052 | |
2392 | |
2053 | glEnable GL_TEXTURE_2D; |
2393 | glEnable GL_TEXTURE_2D; |
2054 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2394 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2055 | glColor 0, 0, 0, 1; |
2395 | glColor 0, 0, 0, 1; |
2056 | |
2396 | |
|
|
2397 | my $tex = $tex[$GRAB == $self]; |
2057 | $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2398 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2058 | |
2399 | |
2059 | glDisable GL_TEXTURE_2D; |
2400 | glDisable GL_TEXTURE_2D; |
2060 | |
2401 | |
2061 | $self->SUPER::_draw; |
2402 | $self->SUPER::_draw; |
2062 | } |
2403 | } |
… | |
… | |
2158 | or Carp::croak "'path' or 'tex' attributes required"; |
2499 | or Carp::croak "'path' or 'tex' attributes required"; |
2159 | |
2500 | |
2160 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
2501 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
2161 | new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; |
2502 | new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; |
2162 | |
2503 | |
2163 | Scalar::Util::weaken $texture_cache{$self->{path}}; |
2504 | CFPlus::weaken $texture_cache{$self->{path}}; |
2164 | |
2505 | |
2165 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2506 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2166 | |
2507 | |
2167 | $self |
2508 | $self |
2168 | } |
2509 | } |
… | |
… | |
2541 | sub invoke_mouse_wheel { |
2882 | sub invoke_mouse_wheel { |
2542 | my ($self, $ev) = @_; |
2883 | my ($self, $ev) = @_; |
2543 | |
2884 | |
2544 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
2885 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
2545 | |
2886 | |
|
|
2887 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
|
|
2888 | |
2546 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.2); |
2889 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2547 | |
2890 | |
2548 | ! ! $delta |
2891 | ! ! $delta |
2549 | } |
2892 | } |
2550 | |
2893 | |
2551 | sub update { |
2894 | sub update { |
… | |
… | |
2661 | #font => default_font |
3004 | #font => default_font |
2662 | @_, |
3005 | @_, |
2663 | |
3006 | |
2664 | layout => (new CFPlus::Layout), |
3007 | layout => (new CFPlus::Layout), |
2665 | par => [], |
3008 | par => [], |
|
|
3009 | max_par => 0, |
2666 | height => 0, |
3010 | height => 0, |
2667 | children => [ |
3011 | children => [ |
2668 | (new CFPlus::UI::Empty expand => 1), |
3012 | (new CFPlus::UI::Empty expand => 1), |
2669 | (new CFPlus::UI::Slider vertical => 1), |
3013 | (new CFPlus::UI::Slider vertical => 1), |
2670 | ], |
3014 | ], |
… | |
… | |
2749 | sub set_offset { |
3093 | sub set_offset { |
2750 | my ($self, $offset) = @_; |
3094 | my ($self, $offset) = @_; |
2751 | |
3095 | |
2752 | # todo: base offset on lines or so, not on pixels |
3096 | # todo: base offset on lines or so, not on pixels |
2753 | $self->{children}[1]->set_value ($offset); |
3097 | $self->{children}[1]->set_value ($offset); |
|
|
3098 | } |
|
|
3099 | |
|
|
3100 | sub current_paragraph { |
|
|
3101 | my ($self) = @_; |
|
|
3102 | |
|
|
3103 | $self->{top_paragraph} - 1 |
|
|
3104 | } |
|
|
3105 | |
|
|
3106 | sub scroll_to { |
|
|
3107 | my ($self, $para) = @_; |
|
|
3108 | |
|
|
3109 | $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para; |
|
|
3110 | |
|
|
3111 | $self->{scroll_to} = $para; |
|
|
3112 | $self->update; |
2754 | } |
3113 | } |
2755 | |
3114 | |
2756 | sub clear { |
3115 | sub clear { |
2757 | my ($self) = @_; |
3116 | my ($self) = @_; |
2758 | |
3117 | |
… | |
… | |
2780 | |
3139 | |
2781 | $self->add (@{ $para->{widget} }) if @{ $para->{widget} }; |
3140 | $self->add (@{ $para->{widget} }) if @{ $para->{widget} }; |
2782 | push @{$self->{par}}, $para; |
3141 | push @{$self->{par}}, $para; |
2783 | } |
3142 | } |
2784 | |
3143 | |
|
|
3144 | if (my $max = $self->{max_par}) { |
|
|
3145 | shift @{$self->{par}} while @{$self->{par}} > $max; |
|
|
3146 | } |
|
|
3147 | |
2785 | $self->{need_reflow}++; |
3148 | $self->{need_reflow}++; |
2786 | $self->update; |
3149 | $self->update; |
2787 | } |
3150 | } |
2788 | |
3151 | |
2789 | sub scroll_to_bottom { |
3152 | sub scroll_to_bottom { |
2790 | my ($self) = @_; |
3153 | my ($self) = @_; |
2791 | |
3154 | |
2792 | $self->{scroll_to_bottom} = 1; |
3155 | $self->{scroll_to} = $#{$self->{par}}; |
2793 | $self->update; |
3156 | $self->update; |
2794 | } |
3157 | } |
2795 | |
3158 | |
|
|
3159 | sub force_uptodate { |
|
|
3160 | my ($self) = @_; |
|
|
3161 | |
|
|
3162 | if (delete $self->{need_reflow}) { |
|
|
3163 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
|
|
3164 | |
|
|
3165 | my $height = 0; |
|
|
3166 | |
|
|
3167 | for my $para (@{$self->{par}}) { |
|
|
3168 | if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { |
|
|
3169 | my $layout = $self->get_layout ($para); |
|
|
3170 | my ($w, $h) = $layout->size; |
|
|
3171 | |
|
|
3172 | $para->{w} = $w + $para->{indent}; |
|
|
3173 | $para->{h} = $h; |
|
|
3174 | $para->{wrapped} = $layout->has_wrapped; |
|
|
3175 | } |
|
|
3176 | |
|
|
3177 | $para->{y} = $height; |
|
|
3178 | $height += $para->{h}; |
|
|
3179 | } |
|
|
3180 | |
|
|
3181 | $self->{height} = $height; |
|
|
3182 | $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); |
|
|
3183 | |
|
|
3184 | delete $self->{texture}; |
|
|
3185 | } |
|
|
3186 | |
|
|
3187 | if (my $paridx = delete $self->{scroll_to}) { |
|
|
3188 | $self->{children}[1]->set_value ($self->{par}[$paridx]{y}); |
|
|
3189 | } |
|
|
3190 | } |
|
|
3191 | |
2796 | sub update { |
3192 | sub update { |
2797 | my ($self) = @_; |
3193 | my ($self) = @_; |
2798 | |
3194 | |
2799 | $self->SUPER::update; |
3195 | $self->SUPER::update; |
2800 | |
3196 | |
2801 | return unless $self->{h} > 0; |
3197 | return unless $self->{h} > 0; |
2802 | |
3198 | |
2803 | delete $self->{texture}; |
3199 | delete $self->{texture}; |
2804 | |
3200 | |
2805 | $ROOT->on_post_alloc ($self => sub { |
3201 | $ROOT->on_post_alloc ($self => sub { |
|
|
3202 | $self->force_uptodate; |
|
|
3203 | |
2806 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
3204 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2807 | |
|
|
2808 | if (delete $self->{need_reflow}) { |
|
|
2809 | my $height = 0; |
|
|
2810 | |
|
|
2811 | for my $para (@{$self->{par}}) { |
|
|
2812 | if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { |
|
|
2813 | my $layout = $self->get_layout ($para); |
|
|
2814 | my ($w, $h) = $layout->size; |
|
|
2815 | |
|
|
2816 | $para->{w} = $w + $para->{indent}; |
|
|
2817 | $para->{h} = $h; |
|
|
2818 | $para->{wrapped} = $layout->has_wrapped; |
|
|
2819 | } |
|
|
2820 | |
|
|
2821 | $height += $para->{h}; |
|
|
2822 | } |
|
|
2823 | |
|
|
2824 | $self->{height} = $height; |
|
|
2825 | |
|
|
2826 | $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); |
|
|
2827 | |
|
|
2828 | delete $self->{texture}; |
|
|
2829 | } |
|
|
2830 | |
|
|
2831 | if (delete $self->{scroll_to_bottom}) { |
|
|
2832 | $self->{children}[1]->set_value (1e10); |
|
|
2833 | } |
|
|
2834 | |
3205 | |
2835 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
3206 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
2836 | glClearColor 0, 0, 0, 0; |
3207 | glClearColor 0, 0, 0, 0; |
2837 | glClear GL_COLOR_BUFFER_BIT; |
3208 | glClear GL_COLOR_BUFFER_BIT; |
2838 | |
3209 | |
|
|
3210 | package CFPlus::UI::Base; |
|
|
3211 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
|
|
3212 | (0, 0, $self->{w}, $self->{h}); |
|
|
3213 | |
|
|
3214 | my $top = int $self->{children}[1]{range}[0]; |
|
|
3215 | |
|
|
3216 | my $paridx = 0; |
|
|
3217 | my $top_paragraph; |
2839 | my $top = int $self->{children}[1]{range}[0]; |
3218 | my $top = int $self->{children}[1]{range}[0]; |
2840 | |
3219 | |
2841 | my $y0 = $top; |
3220 | my $y0 = $top; |
2842 | my $y1 = $top + $H; |
3221 | my $y1 = $top + $H; |
2843 | |
3222 | |
2844 | my $y = 0; |
|
|
2845 | |
|
|
2846 | for my $para (@{$self->{par}}) { |
3223 | for my $para (@{$self->{par}}) { |
2847 | my $h = $para->{h}; |
3224 | my $h = $para->{h}; |
|
|
3225 | my $y = $para->{y}; |
2848 | |
3226 | |
2849 | if ($y0 < $y + $h && $y < $y1) { |
3227 | if ($y0 < $y + $h && $y < $y1) { |
2850 | |
|
|
2851 | my $layout = $self->get_layout ($para); |
3228 | my $layout = $self->get_layout ($para); |
2852 | |
3229 | |
2853 | $layout->render ($para->{indent}, $y - $y0); |
3230 | $layout->render ($para->{indent}, $y - $y0); |
2854 | |
3231 | |
2855 | if (my @w = @{ $para->{widget} }) { |
3232 | if (my @w = @{ $para->{widget} }) { |
… | |
… | |
2864 | $_->draw; |
3241 | $_->draw; |
2865 | } |
3242 | } |
2866 | } |
3243 | } |
2867 | } |
3244 | } |
2868 | |
3245 | |
2869 | $y += $h; |
3246 | $paridx++; |
|
|
3247 | $top_paragraph ||= $paridx if $y >= $top; |
2870 | } |
3248 | } |
|
|
3249 | |
|
|
3250 | $self->{top_paragraph} = $top_paragraph; |
2871 | }; |
3251 | }; |
2872 | }); |
3252 | }); |
2873 | } |
3253 | } |
2874 | |
3254 | |
2875 | sub reconfigure { |
3255 | sub reconfigure { |
… | |
… | |
2977 | } |
3357 | } |
2978 | |
3358 | |
2979 | sub set_tooltip_from { |
3359 | sub set_tooltip_from { |
2980 | my ($self, $widget) = @_; |
3360 | my ($self, $widget) = @_; |
2981 | |
3361 | |
|
|
3362 | $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1 |
|
|
3363 | if $widget->{tooltip} =~ /^#(.*)$/; |
|
|
3364 | |
2982 | my $tooltip = $widget->{tooltip}; |
3365 | my $tooltip = $widget->{tooltip}; |
2983 | |
3366 | |
2984 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3367 | if ($ENV{CFPLUS_DEBUG} & 2) { |
2985 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
3368 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2986 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3369 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
… | |
… | |
2993 | |
3376 | |
2994 | $self->add (new CFPlus::UI::Label |
3377 | $self->add (new CFPlus::UI::Label |
2995 | markup => $tooltip, |
3378 | markup => $tooltip, |
2996 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3379 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2997 | fontsize => 0.8, |
3380 | fontsize => 0.8, |
2998 | fg => [0, 0, 0, 1], |
3381 | style => 1, # FLAG_INVERSE |
2999 | ellipsise => 0, |
3382 | ellipsise => 0, |
3000 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3383 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3001 | ); |
3384 | ); |
3002 | } |
3385 | } |
3003 | |
3386 | |
… | |
… | |
3075 | |
3458 | |
3076 | sub new { |
3459 | sub new { |
3077 | my $class = shift; |
3460 | my $class = shift; |
3078 | |
3461 | |
3079 | my $self = $class->SUPER::new ( |
3462 | my $self = $class->SUPER::new ( |
|
|
3463 | size_w => 32, |
|
|
3464 | size_h => 8, |
3080 | aspect => 1, |
3465 | aspect => 1, |
3081 | can_events => 0, |
3466 | can_events => 0, |
3082 | @_, |
3467 | @_, |
3083 | ); |
3468 | ); |
3084 | |
3469 | |
3085 | if ($self->{anim} && $self->{animspeed}) { |
3470 | if ($self->{anim} && $self->{animspeed}) { |
3086 | Scalar::Util::weaken (my $widget = $self); |
3471 | CFPlus::weaken (my $widget = $self); |
3087 | |
3472 | |
|
|
3473 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
|
|
3474 | $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; |
3088 | $self->{timer} = Event->timer ( |
3475 | $self->{timer} = Event->timer ( |
3089 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
|
|
3090 | hard => 1, |
3476 | parked => 1, |
3091 | interval => $self->{animspeed}, |
|
|
3092 | cb => sub { |
3477 | cb => sub { |
|
|
3478 | return unless $::CONN && $widget; |
|
|
3479 | |
3093 | ++$widget->{frame}; |
3480 | ++$widget->{frame}; |
|
|
3481 | $widget->update_face; |
3094 | $widget->update; |
3482 | $widget->update; |
|
|
3483 | |
|
|
3484 | $widget->update_timer; |
3095 | }, |
3485 | }, |
3096 | ); |
3486 | ); |
|
|
3487 | |
|
|
3488 | $self->update_face; |
|
|
3489 | $self->update_timer; |
3097 | } |
3490 | } |
3098 | |
3491 | |
3099 | $self |
3492 | $self |
3100 | } |
3493 | } |
3101 | |
3494 | |
|
|
3495 | sub update_timer { |
|
|
3496 | my ($self) = @_; |
|
|
3497 | |
|
|
3498 | return unless $self->{timer}; |
|
|
3499 | |
|
|
3500 | if ($self->{visible}) { |
|
|
3501 | $self->{timer}->at ( |
|
|
3502 | $self->{anim_start} |
|
|
3503 | + $self->{animspeed} |
|
|
3504 | * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed} |
|
|
3505 | ); |
|
|
3506 | $self->{timer}->start; |
|
|
3507 | } else { |
|
|
3508 | $self->{timer}->stop; |
|
|
3509 | } |
|
|
3510 | } |
|
|
3511 | |
|
|
3512 | sub update_face { |
|
|
3513 | my ($self) = @_; |
|
|
3514 | |
|
|
3515 | return unless $::CONN; |
|
|
3516 | |
|
|
3517 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
|
|
3518 | if ($anim && @$anim) { |
|
|
3519 | delete $self->{wait_face}; |
|
|
3520 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
|
|
3521 | } |
|
|
3522 | } |
|
|
3523 | } |
|
|
3524 | |
3102 | sub size_request { |
3525 | sub size_request { |
3103 | (32, 8) |
3526 | my ($self) = @_; |
|
|
3527 | |
|
|
3528 | if ($::CONN) { |
|
|
3529 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
|
|
3530 | if (my $tex = $::CONN->{texture}[$faceid]) { |
|
|
3531 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
|
|
3532 | } else { |
|
|
3533 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
|
|
3534 | $self->realloc; |
|
|
3535 | }); |
|
|
3536 | } |
|
|
3537 | } |
|
|
3538 | } |
|
|
3539 | |
|
|
3540 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3104 | } |
3541 | } |
3105 | |
3542 | |
3106 | sub update { |
3543 | sub update { |
3107 | my ($self) = @_; |
3544 | my ($self) = @_; |
3108 | |
3545 | |
3109 | return unless $self->{visible}; |
3546 | return unless $self->{visible}; |
3110 | |
3547 | |
3111 | $self->SUPER::update; |
3548 | $self->SUPER::update; |
3112 | } |
3549 | } |
3113 | |
3550 | |
|
|
3551 | sub invoke_visibility_change { |
|
|
3552 | my ($self) = @_; |
|
|
3553 | |
|
|
3554 | $self->update_timer; |
|
|
3555 | |
|
|
3556 | 0 |
|
|
3557 | } |
|
|
3558 | |
3114 | sub _draw { |
3559 | sub _draw { |
3115 | my ($self) = @_; |
3560 | my ($self) = @_; |
3116 | |
3561 | |
3117 | return unless $::CONN; |
3562 | return unless $::CONN; |
3118 | |
3563 | |
3119 | $self->SUPER::_draw; |
3564 | $self->SUPER::_draw; |
3120 | |
3565 | |
3121 | my $face; |
|
|
3122 | |
|
|
3123 | if ($self->{frame}) { |
|
|
3124 | my $anim = $::CONN->{anim}[$self->{anim}]; |
3566 | my $faceid = $::CONN->{faceid}[$self->{face}] |
3125 | |
3567 | or return; |
3126 | $face = $anim->[ $self->{frame} % @$anim ] |
|
|
3127 | if $anim && @$anim; |
|
|
3128 | } |
|
|
3129 | |
3568 | |
3130 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
3569 | my $tex = $::CONN->{texture}[$faceid]; |
3131 | |
3570 | |
3132 | if ($tex) { |
3571 | if ($tex) { |
3133 | glEnable GL_TEXTURE_2D; |
3572 | glEnable GL_TEXTURE_2D; |
3134 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3573 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3135 | glColor 0, 0, 0, 1; |
3574 | glColor 0, 0, 0, 1; |
… | |
… | |
3139 | } |
3578 | } |
3140 | |
3579 | |
3141 | sub destroy { |
3580 | sub destroy { |
3142 | my ($self) = @_; |
3581 | my ($self) = @_; |
3143 | |
3582 | |
3144 | $self->{timer}->cancel |
3583 | (delete $self->{timer})->cancel |
3145 | if $self->{timer}; |
3584 | if $self->{timer}; |
3146 | |
3585 | |
3147 | $self->SUPER::destroy; |
3586 | $self->SUPER::destroy; |
3148 | } |
3587 | } |
3149 | |
3588 | |
… | |
… | |
3151 | |
3590 | |
3152 | package CFPlus::UI::Buttonbar; |
3591 | package CFPlus::UI::Buttonbar; |
3153 | |
3592 | |
3154 | our @ISA = CFPlus::UI::HBox::; |
3593 | our @ISA = CFPlus::UI::HBox::; |
3155 | |
3594 | |
3156 | # TODO: should actualyl wrap buttons and other goodies. |
3595 | # TODO: should actually wrap buttons and other goodies. |
3157 | |
3596 | |
3158 | ############################################################################# |
3597 | ############################################################################# |
3159 | |
3598 | |
3160 | package CFPlus::UI::Menu; |
3599 | package CFPlus::UI::Menu; |
3161 | |
3600 | |
3162 | our @ISA = CFPlus::UI::FancyFrame::; |
3601 | our @ISA = CFPlus::UI::Toplevel::; |
3163 | |
3602 | |
3164 | use CFPlus::OpenGL; |
3603 | use CFPlus::OpenGL; |
3165 | |
3604 | |
3166 | sub new { |
3605 | sub new { |
3167 | my $class = shift; |
3606 | my $class = shift; |
… | |
… | |
3345 | } |
3784 | } |
3346 | |
3785 | |
3347 | sub add { |
3786 | sub add { |
3348 | my ($self, $title, $widget, $tooltip) = @_; |
3787 | my ($self, $title, $widget, $tooltip) = @_; |
3349 | |
3788 | |
3350 | Scalar::Util::weaken $self; |
3789 | CFPlus::weaken $self; |
3351 | |
3790 | |
3352 | $self->{buttonbar}->add (new CFPlus::UI::Button |
3791 | $self->{buttonbar}->add (new CFPlus::UI::Button |
3353 | markup => $title, |
3792 | markup => $title, |
3354 | tooltip => $tooltip, |
3793 | tooltip => $tooltip, |
3355 | on_activate => sub { $self->set_current_page ($widget) }, |
3794 | on_activate => sub { $self->set_current_page ($widget) }, |
… | |
… | |
3439 | my $self = $class->SUPER::new ( |
3878 | my $self = $class->SUPER::new ( |
3440 | fontsize => 0.8, |
3879 | fontsize => 0.8, |
3441 | @_, |
3880 | @_, |
3442 | ); |
3881 | ); |
3443 | |
3882 | |
3444 | Scalar::Util::weaken (my $this = $self); |
3883 | CFPlus::weaken (my $this = $self); |
3445 | |
3884 | |
3446 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
3885 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
3447 | |
3886 | |
3448 | $self |
3887 | $self |
3449 | } |
3888 | } |
… | |
… | |
3572 | $self->SUPER::destroy; |
4011 | $self->SUPER::destroy; |
3573 | } |
4012 | } |
3574 | |
4013 | |
3575 | ############################################################################# |
4014 | ############################################################################# |
3576 | |
4015 | |
3577 | package CFPlus::UI::Inventory; |
|
|
3578 | |
|
|
3579 | our @ISA = CFPlus::UI::Table::; |
|
|
3580 | |
|
|
3581 | sub new { |
|
|
3582 | my $class = shift; |
|
|
3583 | |
|
|
3584 | my $self = $class->SUPER::new ( |
|
|
3585 | col_expand => [0, 1, 0], |
|
|
3586 | items => [], |
|
|
3587 | @_, |
|
|
3588 | ); |
|
|
3589 | |
|
|
3590 | $self->set_sort_order (undef); |
|
|
3591 | |
|
|
3592 | $self |
|
|
3593 | } |
|
|
3594 | |
|
|
3595 | sub update_items { |
|
|
3596 | my ($self) = @_; |
|
|
3597 | |
|
|
3598 | $self->clear; |
|
|
3599 | |
|
|
3600 | my @item = $self->{sort}->(@{ $self->{items} }); |
|
|
3601 | |
|
|
3602 | my @adds; |
|
|
3603 | my $row = 0; |
|
|
3604 | for my $item ($self->{sort}->(@{ $self->{items} })) { |
|
|
3605 | CFPlus::Item::update_widgets $item; |
|
|
3606 | |
|
|
3607 | push @adds, 0, $row, $item->{face_widget}; |
|
|
3608 | push @adds, 1, $row, $item->{desc_widget}; |
|
|
3609 | push @adds, 2, $row, $item->{weight_widget}; |
|
|
3610 | |
|
|
3611 | $row++; |
|
|
3612 | } |
|
|
3613 | |
|
|
3614 | $self->add (@adds); |
|
|
3615 | } |
|
|
3616 | |
|
|
3617 | sub set_sort_order { |
|
|
3618 | my ($self, $order) = @_; |
|
|
3619 | |
|
|
3620 | $self->{sort} = $order ||= sub { |
|
|
3621 | sort { |
|
|
3622 | $a->{type} <=> $b->{type} |
|
|
3623 | or $a->{name} cmp $b->{name} |
|
|
3624 | } @_ |
|
|
3625 | }; |
|
|
3626 | |
|
|
3627 | $self->update_items; |
|
|
3628 | } |
|
|
3629 | |
|
|
3630 | sub set_items { |
|
|
3631 | my ($self, $items) = @_; |
|
|
3632 | |
|
|
3633 | $self->{items} = [$items ? values %$items : ()]; |
|
|
3634 | $self->update_items; |
|
|
3635 | } |
|
|
3636 | |
|
|
3637 | ############################################################################# |
|
|
3638 | |
|
|
3639 | package CFPlus::UI::SpellList; |
|
|
3640 | |
|
|
3641 | our @ISA = CFPlus::UI::Table::; |
|
|
3642 | |
|
|
3643 | sub new { |
|
|
3644 | my $class = shift; |
|
|
3645 | |
|
|
3646 | my $self = $class->SUPER::new ( |
|
|
3647 | binding => [], |
|
|
3648 | commands => [], |
|
|
3649 | @_, |
|
|
3650 | ) |
|
|
3651 | } |
|
|
3652 | |
|
|
3653 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>"; |
|
|
3654 | |
|
|
3655 | my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3656 | "<b>Name</b>. The name of the spell.$TOOLTIP_ALL"); |
|
|
3657 | my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3658 | "<b>Skill</b>. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL"); |
|
|
3659 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3660 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL"); |
|
|
3661 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3662 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL"); |
|
|
3663 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3664 | "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL"); |
|
|
3665 | |
|
|
3666 | sub rebuild_spell_list { |
|
|
3667 | my ($self) = @_; |
|
|
3668 | |
|
|
3669 | $CFPlus::UI::ROOT->on_refresh ($self => sub { |
|
|
3670 | $self->clear; |
|
|
3671 | |
|
|
3672 | return unless $::CONN; |
|
|
3673 | |
|
|
3674 | $self->add (1, 0, new CFPlus::UI::Label text => "Spell Name", @TOOLTIP_NAME); |
|
|
3675 | $self->add (2, 0, new CFPlus::UI::Label text => "Skill", @TOOLTIP_SKILL); |
|
|
3676 | $self->add (3, 0, new CFPlus::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
|
|
3677 | $self->add (4, 0, new CFPlus::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
|
|
3678 | $self->add (5, 0, new CFPlus::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
|
|
3679 | |
|
|
3680 | my $row = 0; |
|
|
3681 | |
|
|
3682 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
|
|
3683 | my $spell = $self->{spell}{$_}; |
|
|
3684 | |
|
|
3685 | $row++; |
|
|
3686 | |
|
|
3687 | my $spell_cb = sub { |
|
|
3688 | my ($widget, $ev) = @_; |
|
|
3689 | |
|
|
3690 | if ($ev->{button} == 1) { |
|
|
3691 | $::CONN->user_send ("cast $spell->{name}"); |
|
|
3692 | } elsif ($ev->{button} == 2) { |
|
|
3693 | $::CONN->user_send ("invoke $spell->{name}"); |
|
|
3694 | } elsif ($ev->{button} == 3) { |
|
|
3695 | (new CFPlus::UI::Menu |
|
|
3696 | items => [ |
|
|
3697 | ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
|
|
3698 | ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
|
|
3699 | ], |
|
|
3700 | )->popup ($ev); |
|
|
3701 | } else { |
|
|
3702 | return 0; |
|
|
3703 | } |
|
|
3704 | |
|
|
3705 | 1 |
|
|
3706 | }; |
|
|
3707 | |
|
|
3708 | my $tooltip = "$spell->{message}$TOOLTIP_ALL"; |
|
|
3709 | |
|
|
3710 | #TODO: add path info to tooltip |
|
|
3711 | #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path}); |
|
|
3712 | |
|
|
3713 | $self->add (0, $row, new CFPlus::UI::Face |
|
|
3714 | face => $spell->{face}, |
|
|
3715 | can_hover => 1, |
|
|
3716 | can_events => 1, |
|
|
3717 | tooltip => $tooltip, |
|
|
3718 | on_button_down => $spell_cb, |
|
|
3719 | ); |
|
|
3720 | |
|
|
3721 | $self->add (1, $row, new CFPlus::UI::Label |
|
|
3722 | expand => 1, |
|
|
3723 | text => $spell->{name}, |
|
|
3724 | can_hover => 1, |
|
|
3725 | can_events => 1, |
|
|
3726 | tooltip => $tooltip, |
|
|
3727 | on_button_down => $spell_cb, |
|
|
3728 | ); |
|
|
3729 | |
|
|
3730 | $self->add (2, $row, new CFPlus::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL); |
|
|
3731 | $self->add (3, $row, new CFPlus::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
|
|
3732 | $self->add (4, $row, new CFPlus::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
|
|
3733 | $self->add (5, $row, new CFPlus::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
|
|
3734 | } |
|
|
3735 | }); |
|
|
3736 | } |
|
|
3737 | |
|
|
3738 | sub add_spell { |
|
|
3739 | my ($self, $spell) = @_; |
|
|
3740 | |
|
|
3741 | $self->{spell}->{$spell->{name}} = $spell; |
|
|
3742 | $self->rebuild_spell_list; |
|
|
3743 | } |
|
|
3744 | |
|
|
3745 | sub remove_spell { |
|
|
3746 | my ($self, $spell) = @_; |
|
|
3747 | |
|
|
3748 | delete $self->{spell}->{$spell->{name}}; |
|
|
3749 | $self->rebuild_spell_list; |
|
|
3750 | } |
|
|
3751 | |
|
|
3752 | sub clear_spells { |
|
|
3753 | my ($self) = @_; |
|
|
3754 | |
|
|
3755 | $self->{spell} = {}; |
|
|
3756 | $self->rebuild_spell_list; |
|
|
3757 | } |
|
|
3758 | |
|
|
3759 | ############################################################################# |
|
|
3760 | |
|
|
3761 | package CFPlus::UI::Root; |
4016 | package CFPlus::UI::Root; |
3762 | |
4017 | |
3763 | our @ISA = CFPlus::UI::Container::; |
4018 | our @ISA = CFPlus::UI::Container::; |
3764 | |
4019 | |
3765 | use List::Util qw(min max); |
4020 | use List::Util qw(min max); |
… | |
… | |
3772 | my $self = $class->SUPER::new ( |
4027 | my $self = $class->SUPER::new ( |
3773 | visible => 1, |
4028 | visible => 1, |
3774 | @_, |
4029 | @_, |
3775 | ); |
4030 | ); |
3776 | |
4031 | |
3777 | Scalar::Util::weaken ($self->{root} = $self); |
4032 | CFPlus::weaken ($self->{root} = $self); |
3778 | |
4033 | |
3779 | $self |
4034 | $self |
3780 | } |
4035 | } |
3781 | |
4036 | |
3782 | sub size_request { |
4037 | sub size_request { |
… | |
… | |
3977 | while ($self->{post_alloc_hook}) { |
4232 | while ($self->{post_alloc_hook}) { |
3978 | $_->() |
4233 | $_->() |
3979 | for values %{delete $self->{post_alloc_hook}}; |
4234 | for values %{delete $self->{post_alloc_hook}}; |
3980 | } |
4235 | } |
3981 | |
4236 | |
3982 | |
|
|
3983 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
4237 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
3984 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
4238 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
3985 | glClear GL_COLOR_BUFFER_BIT; |
4239 | glClear GL_COLOR_BUFFER_BIT; |
3986 | |
4240 | |
3987 | glMatrixMode GL_PROJECTION; |
4241 | glMatrixMode GL_PROJECTION; |
… | |
… | |
3991 | glLoadIdentity; |
4245 | glLoadIdentity; |
3992 | |
4246 | |
3993 | { |
4247 | { |
3994 | package CFPlus::UI::Base; |
4248 | package CFPlus::UI::Base; |
3995 | |
4249 | |
3996 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
4250 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
3997 | (0, 0, $self->{w}, $self->{h}); |
4251 | (0, 0, $self->{w}, $self->{h}); |
3998 | } |
|
|
3999 | |
4252 | |
4000 | $self->_draw; |
4253 | $self->_draw; |
|
|
4254 | } |
4001 | } |
4255 | } |
4002 | |
4256 | |
4003 | ############################################################################# |
4257 | ############################################################################# |
4004 | |
4258 | |
4005 | package CFPlus::UI; |
4259 | package CFPlus::UI; |