… | |
… | |
50 | delete $TOOLTIP->{owner}; |
50 | delete $TOOLTIP->{owner}; |
51 | } |
51 | } |
52 | |
52 | |
53 | # class methods for events |
53 | # class methods for events |
54 | sub feed_sdl_key_down_event { |
54 | sub feed_sdl_key_down_event { |
55 | $FOCUS->emit (key_down => $_[0]) || $FOCUS->key_down ($_[0]) |
55 | $FOCUS->emit (key_down => $_[0]) |
56 | if $FOCUS; |
56 | if $FOCUS; |
57 | } |
57 | } |
58 | |
58 | |
59 | sub feed_sdl_key_up_event { |
59 | sub feed_sdl_key_up_event { |
60 | $FOCUS->emit (key_up => $_[0]) || $FOCUS->key_up ($_[0]) |
60 | $FOCUS->emit (key_up => $_[0]) |
61 | if $FOCUS; |
61 | if $FOCUS; |
62 | } |
62 | } |
63 | |
63 | |
64 | sub feed_sdl_button_down_event { |
64 | sub feed_sdl_button_down_event { |
65 | my ($ev) = @_; |
65 | my ($ev) = @_; |
… | |
… | |
74 | check_tooltip; |
74 | check_tooltip; |
75 | } |
75 | } |
76 | |
76 | |
77 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
77 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
78 | |
78 | |
79 | if ($GRAB) { |
79 | $GRAB->emit (button_down => $ev, $GRAB->coord2local ($x, $y)) |
80 | ($x, $y) = $GRAB->coord2local ($x, $y); |
80 | if $GRAB; |
81 | $GRAB->emit (button_down => $ev, $x, $y) || $GRAB->button_down ($ev, $x, $y); |
|
|
82 | } |
|
|
83 | } |
81 | } |
84 | |
82 | |
85 | sub feed_sdl_button_up_event { |
83 | sub feed_sdl_button_up_event { |
86 | my ($ev) = @_; |
84 | my ($ev) = @_; |
87 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
85 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
88 | |
86 | |
89 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
87 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
90 | |
88 | |
91 | $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); |
89 | $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); |
92 | |
90 | |
93 | if ($GRAB) { |
91 | $GRAB->emit (button_up => $ev, $GRAB->coord2local ($x, $y)) |
94 | ($x, $y) = $GRAB->coord2local ($x, $y); |
92 | if $GRAB; |
95 | $GRAB->emit (button_up => $ev, $x, $y) || $GRAB->button_up ($ev, $x, $y); |
|
|
96 | } |
|
|
97 | |
93 | |
98 | if (!$BUTTON_STATE) { |
94 | if (!$BUTTON_STATE) { |
99 | my $grab = $GRAB; undef $GRAB; |
95 | my $grab = $GRAB; undef $GRAB; |
100 | $grab->update if $grab; |
96 | $grab->update if $grab; |
101 | $GRAB->update if $GRAB; |
97 | $GRAB->update if $GRAB; |
… | |
… | |
117 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
113 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
118 | |
114 | |
119 | check_tooltip; |
115 | check_tooltip; |
120 | } |
116 | } |
121 | |
117 | |
122 | if ($HOVER) { |
|
|
123 | ($x, $y) = $HOVER->coord2local ($x, $y); |
|
|
124 | $HOVER->emit (mouse_motion => $ev, $x, $y) || $HOVER->mouse_motion ($ev, $x, $y); |
118 | $HOVER->emit (mouse_motion => $ev, $HOVER->coord2local ($x, $y)) |
125 | } |
119 | if $HOVER; |
126 | } |
120 | } |
127 | |
121 | |
128 | # convert position array to integers |
122 | # convert position array to integers |
129 | sub harmonize { |
123 | sub harmonize { |
130 | my ($vals) = @_; |
124 | my ($vals) = @_; |
… | |
… | |
136 | $rem += $_ - $i; |
130 | $rem += $_ - $i; |
137 | $_ = $i; |
131 | $_ = $i; |
138 | } |
132 | } |
139 | } |
133 | } |
140 | |
134 | |
|
|
135 | sub full_refresh { |
|
|
136 | # make a copy, otherwise for complains about freed values. |
|
|
137 | my @widgets = values %WIDGET; |
|
|
138 | |
|
|
139 | $_->update |
|
|
140 | for @widgets; |
|
|
141 | } |
|
|
142 | |
|
|
143 | sub reconfigure_widgets { |
|
|
144 | # make a copy, otherwise C<for> complains about freed values. |
|
|
145 | my @widgets = values %WIDGET; |
|
|
146 | |
|
|
147 | $_->reconfigure |
|
|
148 | for @widgets; |
|
|
149 | } |
|
|
150 | |
141 | # call when resolution changes etc. |
151 | # call when resolution changes etc. |
142 | sub rescale_widgets { |
152 | sub rescale_widgets { |
143 | my ($sx, $sy) = @_; |
153 | my ($sx, $sy) = @_; |
144 | |
154 | |
145 | # make a copy, otherwise for complains about freed values. |
|
|
146 | my @widgets = values %WIDGET; |
155 | for my $widget (values %WIDGET) { |
147 | |
|
|
148 | for my $widget (@widgets) { |
|
|
149 | if ($widget->{toplevel}) { |
156 | if ($widget->{is_toplevel}) { |
150 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
157 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
151 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
158 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
152 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
159 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
153 | $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; |
160 | $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; |
154 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
161 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
155 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
162 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
156 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
163 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
157 | $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; |
164 | $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; |
158 | } |
165 | } |
159 | |
|
|
160 | $widget->reconfigure; |
|
|
161 | } |
166 | } |
|
|
167 | |
|
|
168 | reconfigure_widgets; |
162 | } |
169 | } |
163 | |
170 | |
164 | ############################################################################# |
171 | ############################################################################# |
165 | |
172 | |
166 | package CFClient::UI::Base; |
173 | package CFClient::UI::Base; |
… | |
… | |
198 | %$self = (); |
205 | %$self = (); |
199 | } |
206 | } |
200 | |
207 | |
201 | sub show { |
208 | sub show { |
202 | my ($self) = @_; |
209 | my ($self) = @_; |
203 | |
|
|
204 | return if $self->{parent}; |
210 | return if $self->{parent}; |
205 | |
211 | |
206 | $CFClient::UI::ROOT->add ($self); |
212 | $CFClient::UI::ROOT->add ($self); |
207 | } |
213 | } |
208 | |
214 | |
209 | sub hide { |
215 | sub show_centered { |
210 | my ($self) = @_; |
216 | my ($self) = @_; |
|
|
217 | return if $self->{parent}; |
|
|
218 | |
|
|
219 | $self->show; |
|
|
220 | |
|
|
221 | $CFClient::UI::ROOT->on_post_alloc ( |
|
|
222 | "centered $self" => sub { |
|
|
223 | $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); |
|
|
224 | }, |
|
|
225 | ); |
|
|
226 | } |
|
|
227 | |
|
|
228 | sub set_invisible { |
|
|
229 | my ($self) = @_; |
|
|
230 | |
|
|
231 | # broken show/hide model |
|
|
232 | |
|
|
233 | delete $self->{visible}; |
211 | |
234 | |
212 | undef $GRAB if $GRAB == $self; |
235 | undef $GRAB if $GRAB == $self; |
213 | undef $HOVER if $HOVER == $self; |
236 | undef $HOVER if $HOVER == $self; |
|
|
237 | |
|
|
238 | CFClient::UI::check_tooltip |
|
|
239 | if $CFClient::UI::TOOLTIP->{owner} == $self; |
|
|
240 | |
|
|
241 | $self->focus_out; |
|
|
242 | } |
|
|
243 | |
|
|
244 | sub hide { |
|
|
245 | my ($self) = @_; |
|
|
246 | |
|
|
247 | $self->set_invisible; |
214 | |
248 | |
215 | $self->{parent}->remove ($self) |
249 | $self->{parent}->remove ($self) |
216 | if $self->{parent}; |
250 | if $self->{parent}; |
217 | } |
251 | } |
218 | |
252 | |
… | |
… | |
288 | } |
322 | } |
289 | |
323 | |
290 | sub set_tooltip { |
324 | sub set_tooltip { |
291 | my ($self, $tooltip) = @_; |
325 | my ($self, $tooltip) = @_; |
292 | |
326 | |
|
|
327 | $tooltip =~ s/^\s+//; |
|
|
328 | $tooltip =~ s/\s+$//; |
|
|
329 | |
|
|
330 | return if $self->{tooltip} eq $tooltip; |
|
|
331 | |
293 | $self->{tooltip} = $tooltip; |
332 | $self->{tooltip} = $tooltip; |
294 | |
333 | |
295 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
334 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
296 | delete $CFClient::UI::TOOLTIP->{owner}; |
335 | delete $CFClient::UI::TOOLTIP->{owner}; |
297 | CFClient::UI::check_tooltip; |
336 | CFClient::UI::check_tooltip; |
… | |
… | |
318 | return if $FOCUS == $self; |
357 | return if $FOCUS == $self; |
319 | return unless $self->{can_focus}; |
358 | return unless $self->{can_focus}; |
320 | |
359 | |
321 | my $focus = $FOCUS; $FOCUS = $self; |
360 | my $focus = $FOCUS; $FOCUS = $self; |
322 | |
361 | |
323 | $self->emit (focus_in => $focus); |
362 | $self->_emit (focus_in => $focus); |
324 | |
363 | |
325 | $focus->update if $focus; |
364 | $focus->update if $focus; |
326 | $FOCUS->update; |
365 | $FOCUS->update; |
327 | } |
366 | } |
328 | |
367 | |
… | |
… | |
331 | |
370 | |
332 | return unless $FOCUS == $self; |
371 | return unless $FOCUS == $self; |
333 | |
372 | |
334 | my $focus = $FOCUS; undef $FOCUS; |
373 | my $focus = $FOCUS; undef $FOCUS; |
335 | |
374 | |
336 | $self->emit (focus_out => $focus); |
375 | $self->_emit (focus_out => $focus); |
337 | |
376 | |
338 | $focus->update if $focus; #? |
377 | $focus->update if $focus; #? |
|
|
378 | |
|
|
379 | $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus |
|
|
380 | unless $FOCUS; |
339 | } |
381 | } |
340 | |
382 | |
341 | sub mouse_motion { } |
383 | sub mouse_motion { } |
342 | sub button_up { } |
384 | sub button_up { } |
343 | sub key_down { } |
385 | sub key_down { } |
344 | sub key_up { } |
386 | sub key_up { } |
345 | |
387 | |
346 | sub button_down { |
388 | sub button_down { |
347 | my ($self, $ev, $x, $y) = @_; |
389 | my ($self, $ev, $x, $y) = @_; |
348 | |
390 | |
349 | $self->focus_in; |
391 | $self->focus_in; |
… | |
… | |
383 | if ($ENV{PCLIENT_DEBUG}) { |
425 | if ($ENV{PCLIENT_DEBUG}) { |
384 | glPushMatrix; |
426 | glPushMatrix; |
385 | glColor 1, 1, 0, 1; |
427 | glColor 1, 1, 0, 1; |
386 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
428 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
387 | glBegin GL_LINE_LOOP; |
429 | glBegin GL_LINE_LOOP; |
388 | glVertex 0 , 0; |
430 | glVertex 0 , 0; |
389 | glVertex $self->{w}, 0; |
431 | glVertex $self->{w} - 1, 0; |
390 | glVertex $self->{w}, $self->{h}; |
432 | glVertex $self->{w} - 1, $self->{h} - 1; |
391 | glVertex 0 , $self->{h}; |
433 | glVertex 0 , $self->{h} - 1; |
392 | glEnd; |
434 | glEnd; |
393 | glPopMatrix; |
435 | glPopMatrix; |
394 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
436 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
395 | } |
437 | } |
396 | } |
438 | } |
… | |
… | |
419 | Scalar::Util::weaken ($self->{parent} = $parent); |
461 | Scalar::Util::weaken ($self->{parent} = $parent); |
420 | |
462 | |
421 | # TODO: req_w _does_change after ->reconfigure |
463 | # TODO: req_w _does_change after ->reconfigure |
422 | $self->check_size |
464 | $self->check_size |
423 | unless exists $self->{req_w}; |
465 | unless exists $self->{req_w}; |
|
|
466 | |
|
|
467 | $self->show; |
424 | } |
468 | } |
425 | |
469 | |
426 | sub check_size { |
470 | sub check_size { |
427 | my ($self, $forced) = @_; |
471 | my ($self, $forced) = @_; |
428 | |
472 | |
… | |
… | |
441 | my ($self, $signal, $cb) = @_; |
485 | my ($self, $signal, $cb) = @_; |
442 | |
486 | |
443 | push @{ $self->{signal_cb}{$signal} }, $cb; |
487 | push @{ $self->{signal_cb}{$signal} }, $cb; |
444 | } |
488 | } |
445 | |
489 | |
|
|
490 | sub _emit { |
|
|
491 | my ($self, $signal, @args) = @_; |
|
|
492 | |
|
|
493 | List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} |
|
|
494 | } |
|
|
495 | |
446 | sub emit { |
496 | sub emit { |
447 | my ($self, $signal, @args) = @_; |
497 | my ($self, $signal, @args) = @_; |
448 | |
498 | |
449 | List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} |
499 | $self->_emit ($signal, @args) |
|
|
500 | || $self->$signal (@args); |
450 | } |
501 | } |
451 | |
502 | |
452 | sub DESTROY { |
503 | sub DESTROY { |
453 | my ($self) = @_; |
504 | my ($self) = @_; |
454 | |
505 | |
… | |
… | |
691 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
742 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
692 | glClearColor 0, 0, 0, 0; |
743 | glClearColor 0, 0, 0, 0; |
693 | glClear GL_COLOR_BUFFER_BIT; |
744 | glClear GL_COLOR_BUFFER_BIT; |
694 | |
745 | |
695 | $self->_render; |
746 | $self->_render; |
696 | # glColorMask 1, 1, 1, 0; |
|
|
697 | # glEnable GL_BLEND; |
|
|
698 | # glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
|
|
699 | # glRasterPos 0, 0; |
|
|
700 | # glCopyPixels 0, 0, $self->{w}, $self->{h}; |
|
|
701 | # glDisable GL_BLEND; |
|
|
702 | # glColorMask 1, 1, 1, 1; |
|
|
703 | }; |
747 | }; |
704 | } |
748 | } |
705 | |
749 | |
706 | sub _draw { |
750 | sub _draw { |
707 | my ($self) = @_; |
751 | my ($self) = @_; |
… | |
… | |
711 | my $tex = $self->{texture} |
755 | my $tex = $self->{texture} |
712 | or return; |
756 | or return; |
713 | |
757 | |
714 | glEnable GL_TEXTURE_2D; |
758 | glEnable GL_TEXTURE_2D; |
715 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
759 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
716 | glColor 0, 0, 0, 1; |
760 | glColor 1, 1, 1, 1; |
717 | |
761 | |
718 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
762 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
719 | |
763 | |
720 | glDisable GL_TEXTURE_2D; |
764 | glDisable GL_TEXTURE_2D; |
721 | } |
765 | } |
… | |
… | |
724 | |
768 | |
725 | package CFClient::UI::ViewPort; |
769 | package CFClient::UI::ViewPort; |
726 | |
770 | |
727 | our @ISA = CFClient::UI::Window::; |
771 | our @ISA = CFClient::UI::Window::; |
728 | |
772 | |
|
|
773 | sub new { |
|
|
774 | my $class = shift; |
|
|
775 | |
|
|
776 | $class->SUPER::new ( |
|
|
777 | scroll_x => 0, |
|
|
778 | scroll_y => 1, |
|
|
779 | @_, |
|
|
780 | ) |
|
|
781 | } |
|
|
782 | |
729 | sub size_request { |
783 | sub size_request { |
730 | my ($self) = @_; |
784 | my ($self) = @_; |
731 | |
785 | |
732 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
786 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
733 | $self->child->configure (0, 0, @$self{qw(child_w child_h)}); |
|
|
734 | |
787 | |
735 | @$self{qw(child_w child_h)} |
788 | @$self{qw(child_w child_h)} |
736 | } |
789 | } |
737 | |
790 | |
738 | sub size_allocate { |
791 | sub size_allocate { |
739 | my ($self, $w, $h) = @_; |
792 | my ($self, $w, $h) = @_; |
740 | |
793 | |
|
|
794 | $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; |
|
|
795 | $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; |
|
|
796 | |
|
|
797 | $self->child->configure (0, 0, $w, $h); |
741 | $self->update; |
798 | $self->update; |
742 | } |
799 | } |
743 | |
800 | |
744 | sub set_offset { |
801 | sub set_offset { |
745 | my ($self, $x, $y) = @_; |
802 | my ($self, $x, $y) = @_; |
… | |
… | |
799 | |
856 | |
800 | my $slider = new CFClient::UI::Slider |
857 | my $slider = new CFClient::UI::Slider |
801 | vertical => 1, |
858 | vertical => 1, |
802 | range => [0, 0, 1, 0.01], # HACK fix |
859 | range => [0, 0, 1, 0.01], # HACK fix |
803 | connect_changed => sub { |
860 | connect_changed => sub { |
804 | $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); |
861 | $self->{vp}->set_offset (0, $_[1]); |
805 | }, |
862 | }, |
806 | ; |
863 | ; |
807 | |
864 | |
808 | $self = $class->SUPER::new ( |
865 | $self = $class->SUPER::new ( |
809 | vp => (new CFClient::UI::ViewPort), |
866 | vp => (new CFClient::UI::ViewPort expand => 1), |
810 | slider => $slider, |
867 | slider => $slider, |
811 | @_, |
868 | @_, |
812 | ); |
869 | ); |
813 | |
870 | |
814 | $self->{vp}->add ($self->{scrolled}); |
871 | $self->{vp}->add ($self->{scrolled}); |
815 | $self->add ($self->{vp}); |
872 | $self->add ($self->{vp}); |
816 | $self->add ($self->{slider}); |
873 | $self->add ($self->{slider}); |
817 | |
874 | |
818 | $self |
875 | $self |
|
|
876 | } |
|
|
877 | |
|
|
878 | sub size_allocate { |
|
|
879 | my ($self, $w, $h) = @_; |
|
|
880 | |
|
|
881 | $self->SUPER::size_allocate ($w, $h); |
|
|
882 | |
|
|
883 | my $child = $self->{vp}->child; |
|
|
884 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
819 | } |
885 | } |
820 | |
886 | |
821 | #TODO# update range on size_allocate depending on child |
887 | #TODO# update range on size_allocate depending on child |
822 | # update viewport offset on scroll |
888 | # update viewport offset on scroll |
823 | |
889 | |
… | |
… | |
877 | my $class = shift; |
943 | my $class = shift; |
878 | |
944 | |
879 | # TODO: user_x, user_y, overwrite moveto? |
945 | # TODO: user_x, user_y, overwrite moveto? |
880 | |
946 | |
881 | my $self = $class->SUPER::new ( |
947 | my $self = $class->SUPER::new ( |
882 | bg => [1, 1, 1, 1], |
948 | bg => [1, 1, 1, 1], |
883 | border_bg => [1, 1, 1, 1], |
949 | border_bg => [1, 1, 1, 1], |
884 | border => 0.6, |
950 | border => 0.6, |
885 | toplevel => 1, |
951 | is_toplevel => 1, |
886 | can_events => 1, |
952 | can_events => 1, |
887 | @_ |
953 | @_ |
888 | ); |
954 | ); |
889 | |
955 | |
890 | $self->{title} &&= new CFClient::UI::Label |
956 | $self->{title} &&= new CFClient::UI::Label |
891 | align => 0, |
957 | align => 0, |
… | |
… | |
1031 | sub new { |
1097 | sub new { |
1032 | my $class = shift; |
1098 | my $class = shift; |
1033 | |
1099 | |
1034 | $class->SUPER::new ( |
1100 | $class->SUPER::new ( |
1035 | col_expand => [], |
1101 | col_expand => [], |
1036 | @_ |
1102 | @_, |
1037 | ) |
1103 | ) |
1038 | } |
1104 | } |
1039 | |
1105 | |
1040 | sub add { |
1106 | sub add { |
1041 | my ($self, $x, $y, $child) = @_; |
1107 | my ($self, $x, $y, $child) = @_; |
… | |
… | |
1473 | active_fg => [0, 0, 0], |
1539 | active_fg => [0, 0, 0], |
1474 | can_hover => 1, |
1540 | can_hover => 1, |
1475 | can_focus => 1, |
1541 | can_focus => 1, |
1476 | valign => 0, |
1542 | valign => 0, |
1477 | can_events => 1, |
1543 | can_events => 1, |
|
|
1544 | #text => ... |
1478 | @_ |
1545 | @_ |
1479 | ) |
1546 | ) |
1480 | } |
1547 | } |
1481 | |
1548 | |
1482 | sub _set_text { |
1549 | sub _set_text { |
… | |
… | |
1492 | $self->{text} = $text; |
1559 | $self->{text} = $text; |
1493 | |
1560 | |
1494 | $text =~ s/./*/g if $self->{hidden}; |
1561 | $text =~ s/./*/g if $self->{hidden}; |
1495 | $self->{layout}->set_text ("$text "); |
1562 | $self->{layout}->set_text ("$text "); |
1496 | |
1563 | |
1497 | $self->emit (changed => $self->{text}); |
1564 | $self->_emit (changed => $self->{text}); |
1498 | } |
1565 | } |
1499 | |
1566 | |
1500 | sub set_text { |
1567 | sub set_text { |
1501 | my ($self, $text) = @_; |
1568 | my ($self, $text) = @_; |
1502 | |
1569 | |
… | |
… | |
1514 | my ($self) = @_; |
1581 | my ($self) = @_; |
1515 | |
1582 | |
1516 | my ($w, $h) = $self->SUPER::size_request; |
1583 | my ($w, $h) = $self->SUPER::size_request; |
1517 | |
1584 | |
1518 | ($w + 1, $h) # add 1 for cursor |
1585 | ($w + 1, $h) # add 1 for cursor |
1519 | } |
|
|
1520 | |
|
|
1521 | sub size_allocate { |
|
|
1522 | my ($self, $w, $h) = @_; |
|
|
1523 | |
|
|
1524 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
|
|
1525 | } |
1586 | } |
1526 | |
1587 | |
1527 | sub key_down { |
1588 | sub key_down { |
1528 | my ($self, $ev) = @_; |
1589 | my ($self, $ev) = @_; |
1529 | |
1590 | |
… | |
… | |
1544 | } elsif ($sym == CFClient::SDLK_HOME) { |
1605 | } elsif ($sym == CFClient::SDLK_HOME) { |
1545 | $self->{cursor} = 0; |
1606 | $self->{cursor} = 0; |
1546 | } elsif ($sym == CFClient::SDLK_END) { |
1607 | } elsif ($sym == CFClient::SDLK_END) { |
1547 | $self->{cursor} = length $text; |
1608 | $self->{cursor} = length $text; |
1548 | } elsif ($uni == 27) { |
1609 | } elsif ($uni == 27) { |
1549 | $self->emit ('escape'); |
1610 | $self->_emit ('escape'); |
1550 | } elsif ($uni) { |
1611 | } elsif ($uni) { |
1551 | substr $text, $self->{cursor}++, 0, chr $uni; |
1612 | substr $text, $self->{cursor}++, 0, chr $uni; |
1552 | } |
1613 | } |
1553 | |
1614 | |
1554 | $self->_set_text ($text); |
1615 | $self->_set_text ($text); |
… | |
… | |
1641 | if ($sym == 13) { |
1702 | if ($sym == 13) { |
1642 | unshift @{$self->{history}}, |
1703 | unshift @{$self->{history}}, |
1643 | my $txt = $self->get_text; |
1704 | my $txt = $self->get_text; |
1644 | $self->{history_pointer} = -1; |
1705 | $self->{history_pointer} = -1; |
1645 | $self->{history_saveback} = ''; |
1706 | $self->{history_saveback} = ''; |
1646 | $self->emit (activate => $txt); |
1707 | $self->_emit (activate => $txt); |
1647 | $self->update; |
1708 | $self->update; |
1648 | |
1709 | |
1649 | } elsif ($sym == CFClient::SDLK_UP) { |
1710 | } elsif ($sym == CFClient::SDLK_UP) { |
1650 | if ($self->{history_pointer} < 0) { |
1711 | if ($self->{history_pointer} < 0) { |
1651 | $self->{history_saveback} = $self->get_text; |
1712 | $self->{history_saveback} = $self->get_text; |
… | |
… | |
1699 | can_events => 1, |
1760 | can_events => 1, |
1700 | @_ |
1761 | @_ |
1701 | ) |
1762 | ) |
1702 | } |
1763 | } |
1703 | |
1764 | |
|
|
1765 | sub activate { } |
|
|
1766 | |
1704 | sub button_up { |
1767 | sub button_up { |
1705 | my ($self, $ev, $x, $y) = @_; |
1768 | my ($self, $ev, $x, $y) = @_; |
1706 | |
1769 | |
|
|
1770 | $self->emit ("activate") |
1707 | if ($x >= 0 && $x < $self->{w} |
1771 | if $x >= 0 && $x < $self->{w} |
1708 | && $y >= 0 && $y < $self->{h}) { |
1772 | && $y >= 0 && $y < $self->{h}; |
1709 | $self->emit ("activate"); |
|
|
1710 | } |
|
|
1711 | } |
1773 | } |
1712 | |
1774 | |
1713 | sub _draw { |
1775 | sub _draw { |
1714 | my ($self) = @_; |
1776 | my ($self) = @_; |
1715 | |
1777 | |
… | |
… | |
1767 | my ($self, $ev, $x, $y) = @_; |
1829 | my ($self, $ev, $x, $y) = @_; |
1768 | |
1830 | |
1769 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1831 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1770 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1832 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1771 | $self->{state} = !$self->{state}; |
1833 | $self->{state} = !$self->{state}; |
1772 | $self->emit (changed => $self->{state}); |
1834 | $self->_emit (changed => $self->{state}); |
1773 | } |
1835 | } |
1774 | } |
1836 | } |
1775 | |
1837 | |
1776 | sub _draw { |
1838 | sub _draw { |
1777 | my ($self) = @_; |
1839 | my ($self) = @_; |
… | |
… | |
2052 | my $self = $class->SUPER::new ( |
2114 | my $self = $class->SUPER::new ( |
2053 | fg => [1, 1, 1], |
2115 | fg => [1, 1, 1], |
2054 | active_fg => [0, 0, 0], |
2116 | active_fg => [0, 0, 0], |
2055 | bg => [0, 0, 0, 0.2], |
2117 | bg => [0, 0, 0, 0.2], |
2056 | active_bg => [1, 1, 1, 0.5], |
2118 | active_bg => [1, 1, 1, 0.5], |
2057 | range => [0, 0, 100, 10], |
2119 | range => [0, 0, 100, 10, 0], |
2058 | req_w => $::WIDTH / 80, |
2120 | req_w => $::WIDTH / 80, |
2059 | req_h => $::WIDTH / 80, |
2121 | req_h => $::WIDTH / 80, |
2060 | vertical => 0, |
2122 | vertical => 0, |
2061 | can_hover => 1, |
2123 | can_hover => 1, |
2062 | inner_pad => .05, |
2124 | inner_pad => 0.02, |
2063 | @_ |
2125 | @_ |
2064 | ); |
2126 | ); |
2065 | |
2127 | |
2066 | $self->set_value ($self->{range}[0]); |
2128 | $self->set_value ($self->{range}[0]); |
2067 | $self->update; |
2129 | $self->update; |
2068 | |
2130 | |
2069 | $self |
2131 | $self |
2070 | } |
2132 | } |
2071 | |
2133 | |
|
|
2134 | sub set_range { |
|
|
2135 | my ($self, $range) = @_; |
|
|
2136 | |
|
|
2137 | $self->{range} = $range; |
|
|
2138 | |
|
|
2139 | $self->update; |
|
|
2140 | } |
|
|
2141 | |
2072 | sub set_value { |
2142 | sub set_value { |
2073 | my ($self, $value) = @_; |
2143 | my ($self, $value) = @_; |
2074 | |
2144 | |
2075 | my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; |
2145 | my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; |
2076 | |
2146 | |
2077 | $hi = $lo + 1 if $hi <= $lo; |
2147 | $hi = $lo + 1 if $hi <= $lo; |
2078 | |
2148 | |
|
|
2149 | $page = $hi - $lo if $page > $hi - $lo; |
|
|
2150 | |
2079 | $value = $lo if $value < $lo; |
2151 | $value = $lo if $value < $lo; |
2080 | $value = $hi if $value > $hi; |
2152 | $value = $hi - $page if $value > $hi - $page; |
2081 | |
2153 | |
2082 | $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit |
2154 | $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit |
2083 | if $unit; |
2155 | if $unit; |
2084 | |
2156 | |
2085 | $page = $hi - $lo if $page > $hi - $lo; |
|
|
2086 | |
|
|
2087 | @{$self->{range}} = ($value, $lo, $hi, $page, $unit); |
2157 | @{$self->{range}} = ($value, $lo, $hi, $page, $unit); |
2088 | |
2158 | |
2089 | if ($value != $old_value) { |
2159 | if ($value != $old_value) { |
2090 | $self->emit (changed => $value); |
2160 | $self->_emit (changed => $value); |
2091 | $self->update; |
2161 | $self->update; |
2092 | } |
2162 | } |
2093 | } |
2163 | } |
2094 | |
2164 | |
2095 | sub size_request { |
2165 | sub size_request { |
… | |
… | |
2103 | |
2173 | |
2104 | sub button_down { |
2174 | sub button_down { |
2105 | my ($self, $ev, $x, $y) = @_; |
2175 | my ($self, $ev, $x, $y) = @_; |
2106 | |
2176 | |
2107 | $self->SUPER::button_down ($ev, $x, $y); |
2177 | $self->SUPER::button_down ($ev, $x, $y); |
|
|
2178 | |
|
|
2179 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
|
|
2180 | |
2108 | $self->mouse_motion ($ev, $x, $y); |
2181 | $self->mouse_motion ($ev, $x, $y); |
2109 | } |
2182 | } |
2110 | |
2183 | |
2111 | sub mouse_motion { |
2184 | sub mouse_motion { |
2112 | my ($self, $ev, $x, $y) = @_; |
2185 | my ($self, $ev, $x, $y) = @_; |
… | |
… | |
2114 | if ($GRAB == $self) { |
2187 | if ($GRAB == $self) { |
2115 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
2188 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
2116 | |
2189 | |
2117 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2190 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
2118 | |
2191 | |
2119 | $x = $x / ($w * (1 - 2 * $self->{inner_pad})) - $self->{inner_pad}; |
2192 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
2120 | |
2193 | |
2121 | $self->set_value ($x * ($hi - $lo) + $lo); |
2194 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
2122 | } |
2195 | } |
2123 | } |
2196 | } |
2124 | |
2197 | |
2125 | sub update { |
2198 | sub update { |
2126 | my ($self) = @_; |
2199 | my ($self) = @_; |
2127 | |
2200 | |
2128 | $CFClient::UI::ROOT->on_post_alloc ($self => sub { |
2201 | $CFClient::UI::ROOT->on_post_alloc ($self => sub { |
2129 | $self->set_value ($self->{range}[0]); |
2202 | $self->set_value ($self->{range}[0]); |
2130 | |
2203 | |
2131 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2204 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
|
|
2205 | my $range = ($hi - $page - $lo) || 1e-100; |
2132 | |
2206 | |
2133 | my $inner_w = 1 - 2 * $self->{inner_pad}; |
2207 | my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1; |
2134 | |
2208 | |
2135 | $self->{scale} = ($inner_w / ($hi - $lo)) || 1; |
2209 | $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; |
|
|
2210 | $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; |
2136 | |
2211 | |
2137 | $page = $self->{scale} * $page || 10 / ($self->{w} || 1); |
2212 | $value = ($value - $lo) / $range; |
2138 | $value = $self->{scale} * ($value - $lo); |
2213 | $value = $value * $self->{scale} + $self->{offset}; |
2139 | |
2214 | |
2140 | $value = $self->{inner_pad} + ($value - $page * 0.5); |
|
|
2141 | |
|
|
2142 | $value = 0 if $value < 0; |
|
|
2143 | $page = 1 - $value if $value + $page > 1; |
|
|
2144 | |
|
|
2145 | $self->{knob_x} = $value; |
2215 | $self->{knob_x} = $value - $knob_w * 0.5; |
2146 | $self->{knob_w} = $page; |
2216 | $self->{knob_w} = $knob_w; |
2147 | }); |
2217 | }); |
2148 | |
2218 | |
2149 | $self->SUPER::update; |
2219 | $self->SUPER::update; |
2150 | } |
2220 | } |
2151 | |
2221 | |
… | |
… | |
2157 | glScale $self->{w}, $self->{h}; |
2227 | glScale $self->{w}, $self->{h}; |
2158 | |
2228 | |
2159 | if ($self->{vertical}) { |
2229 | if ($self->{vertical}) { |
2160 | # draw a vertical slider like a rotated horizontal slider |
2230 | # draw a vertical slider like a rotated horizontal slider |
2161 | |
2231 | |
|
|
2232 | glTranslate 1, 0, 0; |
2162 | glRotate 90, 0, 0, 1; |
2233 | glRotate 90, 0, 0, 1; |
2163 | glTranslate 0, 1, 0; |
|
|
2164 | } |
2234 | } |
2165 | |
2235 | |
2166 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2236 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2167 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2237 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2168 | |
2238 | |
… | |
… | |
2175 | # draw handle |
2245 | # draw handle |
2176 | $tex[0]->draw_quad_alpha ($self->{knob_x}, 0, $self->{knob_w}, 1); |
2246 | $tex[0]->draw_quad_alpha ($self->{knob_x}, 0, $self->{knob_w}, 1); |
2177 | |
2247 | |
2178 | glDisable GL_TEXTURE_2D; |
2248 | glDisable GL_TEXTURE_2D; |
2179 | } |
2249 | } |
|
|
2250 | |
|
|
2251 | ############################################################################# |
|
|
2252 | |
|
|
2253 | package CFClient::UI::ValSlider; |
|
|
2254 | |
|
|
2255 | our @ISA = CFClient::UI::HBox::; |
|
|
2256 | |
|
|
2257 | sub new { |
|
|
2258 | my ($class, %arg) = @_; |
|
|
2259 | |
|
|
2260 | my $range = delete $arg{range}; |
|
|
2261 | |
|
|
2262 | my $self = $class->SUPER::new ( |
|
|
2263 | slider => (new CFClient::UI::Slider expand => 1, range => $range), |
|
|
2264 | entry => (new CFClient::UI::Label text => "", template => delete $arg{template}), |
|
|
2265 | to_value => sub { shift }, |
|
|
2266 | from_value => sub { shift }, |
|
|
2267 | %arg, |
|
|
2268 | ); |
|
|
2269 | |
|
|
2270 | $self->{slider}->connect (changed => sub { |
|
|
2271 | my ($self, $value) = @_; |
|
|
2272 | $self->{parent}{entry}->set_text ($self->{parent}{to_value}->($value)); |
|
|
2273 | $self->{parent}->emit (changed => $value); |
|
|
2274 | }); |
|
|
2275 | |
|
|
2276 | # $self->{entry}->connect (changed => sub { |
|
|
2277 | # my ($self, $value) = @_; |
|
|
2278 | # $self->{parent}{slider}->set_value ($self->{parent}{from_value}->($value)); |
|
|
2279 | # $self->{parent}->emit (changed => $value); |
|
|
2280 | # }); |
|
|
2281 | |
|
|
2282 | $self->add ($self->{slider}, $self->{entry}); |
|
|
2283 | |
|
|
2284 | $self->{slider}->emit (changed => $self->{slider}{range}[0]); |
|
|
2285 | |
|
|
2286 | $self |
|
|
2287 | } |
|
|
2288 | |
|
|
2289 | sub set_range { shift->{slider}->set_range (@_) } |
|
|
2290 | sub set_value { shift->{slider}->set_value (@_) } |
2180 | |
2291 | |
2181 | ############################################################################# |
2292 | ############################################################################# |
2182 | |
2293 | |
2183 | package CFClient::UI::TextView; |
2294 | package CFClient::UI::TextView; |
2184 | |
2295 | |
… | |
… | |
2214 | |
2325 | |
2215 | $self->{fontsize} = $fontsize; |
2326 | $self->{fontsize} = $fontsize; |
2216 | $self->reflow; |
2327 | $self->reflow; |
2217 | } |
2328 | } |
2218 | |
2329 | |
2219 | sub text_height { |
|
|
2220 | my ($self, $text) = @_; |
|
|
2221 | |
|
|
2222 | my $layout = $self->{layout}; |
|
|
2223 | |
|
|
2224 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
2225 | $layout->set_width ($self->{children}[0]{w}); |
|
|
2226 | $layout->set_markup ($text); |
|
|
2227 | |
|
|
2228 | ($layout->size)[1] |
|
|
2229 | } |
|
|
2230 | |
|
|
2231 | sub reflow { |
|
|
2232 | my ($self) = @_; |
|
|
2233 | |
|
|
2234 | $self->{need_reflow}++; |
|
|
2235 | $self->update; |
|
|
2236 | } |
|
|
2237 | |
|
|
2238 | sub size_allocate { |
2330 | sub size_allocate { |
2239 | my ($self, $w, $h) = @_; |
2331 | my ($self, $w, $h) = @_; |
2240 | |
2332 | |
2241 | $self->SUPER::size_allocate ($w, $h); |
2333 | $self->SUPER::size_allocate ($w, $h); |
2242 | |
2334 | |
… | |
… | |
2245 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2337 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2246 | |
2338 | |
2247 | $self->reflow; |
2339 | $self->reflow; |
2248 | } |
2340 | } |
2249 | |
2341 | |
|
|
2342 | sub text_size { |
|
|
2343 | my ($self, $text, $indent) = @_; |
|
|
2344 | |
|
|
2345 | my $layout = $self->{layout}; |
|
|
2346 | |
|
|
2347 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
2348 | $layout->set_width ($self->{children}[0]{w} - $indent); |
|
|
2349 | $layout->set_markup ($text); |
|
|
2350 | |
|
|
2351 | $layout->size |
|
|
2352 | } |
|
|
2353 | |
|
|
2354 | sub reflow { |
|
|
2355 | my ($self) = @_; |
|
|
2356 | |
|
|
2357 | $self->{need_reflow}++; |
|
|
2358 | $self->update; |
|
|
2359 | } |
|
|
2360 | |
|
|
2361 | sub set_offset { |
|
|
2362 | my ($self, $offset) = @_; |
|
|
2363 | |
|
|
2364 | # todo: base offset on lines or so, not on pixels |
|
|
2365 | $self->{children}[1]->set_value ($offset); |
|
|
2366 | } |
|
|
2367 | |
|
|
2368 | sub clear { |
|
|
2369 | my ($self) = @_; |
|
|
2370 | |
|
|
2371 | $self->{par} = []; |
|
|
2372 | $self->{height} = 0; |
|
|
2373 | $self->{children}[1]->set_range ([0, 0, 0, 1, 1]); |
|
|
2374 | } |
|
|
2375 | |
2250 | sub add_paragraph { |
2376 | sub add_paragraph { |
2251 | my ($self, $color, $text) = @_; |
2377 | my ($self, $color, $text, $indent) = @_; |
2252 | |
2378 | |
2253 | #TODO: intelligently "reformat" paragraph |
2379 | for my $line (split /\n/, $text) { |
2254 | |
2380 | my ($w, $h) = $self->text_size ($line); |
2255 | my $height = $self->text_height ($text); |
|
|
2256 | |
|
|
2257 | $self->{height} += $height; |
2381 | $self->{height} += $h; |
|
|
2382 | push @{$self->{par}}, [$w + $indent, $h, $color, $indent, $line]; |
|
|
2383 | } |
2258 | |
2384 | |
2259 | push @{$self->{par}}, [$height, $color, $text]; |
|
|
2260 | |
|
|
2261 | $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; |
2385 | $self->{children}[1]->set_range ([$self->{height}, 0, $self->{height}, $self->{h}, 1]); |
2262 | $self->{children}[1]->update; |
|
|
2263 | } |
2386 | } |
2264 | |
2387 | |
2265 | sub update { |
2388 | sub update { |
2266 | my ($self) = @_; |
2389 | my ($self) = @_; |
2267 | |
2390 | |
… | |
… | |
2270 | return unless $self->{h} > 0; |
2393 | return unless $self->{h} > 0; |
2271 | |
2394 | |
2272 | delete $self->{texture}; |
2395 | delete $self->{texture}; |
2273 | |
2396 | |
2274 | $ROOT->on_post_alloc ($self, sub { |
2397 | $ROOT->on_post_alloc ($self, sub { |
|
|
2398 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
|
|
2399 | |
2275 | if (delete $self->{need_reflow}) { |
2400 | if (delete $self->{need_reflow}) { |
2276 | my $height = 0; |
2401 | my $height = 0; |
2277 | |
2402 | |
2278 | $height += $_->[0] = $self->text_height ($_->[2]) |
2403 | my $layout = $self->{layout}; |
|
|
2404 | |
|
|
2405 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
2406 | |
2279 | for @{$self->{par}}; |
2407 | for (@{$self->{par}}) { |
|
|
2408 | if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support |
|
|
2409 | $layout->set_width ($W - $_->[3]); |
|
|
2410 | $layout->set_markup ($_->[4]); |
|
|
2411 | my ($w, $h) = $layout->size; |
|
|
2412 | $_->[0] = $w + $_->[3]; |
|
|
2413 | $_->[1] = $h; |
|
|
2414 | } |
|
|
2415 | |
|
|
2416 | $height += $_->[1]; |
|
|
2417 | } |
2280 | |
2418 | |
2281 | $self->{height} = $height; |
2419 | $self->{height} = $height; |
2282 | |
2420 | |
2283 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
2421 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2284 | |
2422 | |
2285 | delete $self->{texture}; |
2423 | delete $self->{texture}; |
2286 | } |
2424 | } |
2287 | |
2425 | |
2288 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2426 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2289 | glClearColor 0, 0, 0, 0; |
2427 | glClearColor 0.5, 0.5, 0.5, 0; |
2290 | glClear GL_COLOR_BUFFER_BIT; |
2428 | glClear GL_COLOR_BUFFER_BIT; |
2291 | |
2429 | |
2292 | glEnable GL_TEXTURE_2D; |
|
|
2293 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2294 | |
|
|
2295 | my $top = int $self->{children}[1]{range}[0]; |
2430 | my $top = int $self->{children}[1]{range}[0]; |
2296 | |
2431 | |
2297 | my $y0 = $top; |
2432 | my $y0 = $top; |
2298 | my $y1 = $top + $self->{h}; |
2433 | my $y1 = $top + $H; |
2299 | |
2434 | |
2300 | my $y = 0; |
2435 | my $y = 0; |
2301 | |
2436 | |
2302 | my $layout = $self->{layout}; |
2437 | my $layout = $self->{layout}; |
2303 | |
2438 | |
2304 | $layout->set_font ($self->{font}) if $self->{font}; |
2439 | $layout->set_font ($self->{font}) if $self->{font}; |
2305 | |
2440 | |
|
|
2441 | glEnable GL_BLEND; |
|
|
2442 | #TODO# not correct in windows where rgba is forced off |
|
|
2443 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2444 | |
2306 | for my $par (@{$self->{par}}) { |
2445 | for my $par (@{$self->{par}}) { |
2307 | my $h = $par->[0]; |
2446 | my $h = $par->[1]; |
2308 | |
2447 | |
2309 | if ($y0 < $y + $h && $y < $y1) { |
2448 | if ($y0 < $y + $h && $y < $y1) { |
2310 | $layout->set_foreground (@{ $par->[1] }); |
2449 | $layout->set_foreground (@{ $par->[2] }); |
|
|
2450 | $layout->set_width ($W - $par->[3]); |
2311 | $layout->set_markup ($par->[2]); |
2451 | $layout->set_markup ($par->[4]); |
2312 | |
2452 | |
2313 | my ($W, $H) = $layout->size; |
2453 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
2314 | CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); |
2454 | |
|
|
2455 | glRasterPos $par->[3], $y - $y0; |
|
|
2456 | glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data; |
2315 | } |
2457 | } |
2316 | |
2458 | |
2317 | $y += $h; |
2459 | $y += $h; |
2318 | } |
2460 | } |
2319 | |
2461 | |
2320 | glDisable GL_TEXTURE_2D; |
2462 | glDisable GL_BLEND; |
2321 | }; |
2463 | }; |
2322 | }); |
2464 | }); |
2323 | } |
2465 | } |
2324 | |
2466 | |
2325 | sub _draw { |
2467 | sub _draw { |
2326 | my ($self) = @_; |
2468 | my ($self) = @_; |
2327 | |
2469 | |
2328 | glEnable GL_TEXTURE_2D; |
2470 | glEnable GL_TEXTURE_2D; |
2329 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2471 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2330 | glColor 1, 1, 1, 1; |
2472 | glColor 1, 1, 1, 1; |
2331 | $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2473 | $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2332 | glDisable GL_TEXTURE_2D; |
2474 | glDisable GL_TEXTURE_2D; |
2333 | |
2475 | |
2334 | $self->{children}[1]->draw; |
2476 | $self->{children}[1]->draw; |
2335 | |
2477 | |
2336 | } |
2478 | } |
… | |
… | |
2405 | |
2547 | |
2406 | # TODO: use animation |
2548 | # TODO: use animation |
2407 | if ($self->{state} = !$self->{state}) { |
2549 | if ($self->{state} = !$self->{state}) { |
2408 | $CFClient::UI::ROOT->add ($self->{other}); |
2550 | $CFClient::UI::ROOT->add ($self->{other}); |
2409 | $self->{other}->move ($self->coord2global (0, $self->{h})); |
2551 | $self->{other}->move ($self->coord2global (0, $self->{h})); |
2410 | $self->emit ("open"); |
2552 | $self->_emit ("open"); |
2411 | } else { |
2553 | } else { |
2412 | $CFClient::UI::ROOT->remove ($self->{other}); |
2554 | $CFClient::UI::ROOT->remove ($self->{other}); |
2413 | $self->emit ("close"); |
2555 | $self->_emit ("close"); |
2414 | } |
2556 | } |
2415 | |
2557 | |
2416 | $self->emit (changed => $self->{state}); |
2558 | $self->_emit (changed => $self->{state}); |
2417 | } |
2559 | } |
2418 | |
2560 | |
2419 | ############################################################################# |
2561 | ############################################################################# |
2420 | |
2562 | |
2421 | package CFClient::UI::Tooltip; |
2563 | package CFClient::UI::Tooltip; |
… | |
… | |
2496 | use CFClient::OpenGL; |
2638 | use CFClient::OpenGL; |
2497 | |
2639 | |
2498 | sub new { |
2640 | sub new { |
2499 | my $class = shift; |
2641 | my $class = shift; |
2500 | |
2642 | |
2501 | $class->SUPER::new ( |
2643 | my $self = $class->SUPER::new ( |
2502 | aspect => 1, |
2644 | aspect => 1, |
|
|
2645 | can_events => 0, |
2503 | @_, |
2646 | @_, |
2504 | ) |
2647 | ); |
|
|
2648 | |
|
|
2649 | if ($self->{anim} && $self->{animspeed}) { |
|
|
2650 | Scalar::Util::weaken (my $widget = $self); |
|
|
2651 | |
|
|
2652 | $self->{timer} = Event->timer ( |
|
|
2653 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
|
|
2654 | hard => 1, |
|
|
2655 | interval => $self->{animspeed}, |
|
|
2656 | cb => sub { |
|
|
2657 | ++$widget->{frame}; |
|
|
2658 | $widget->update; |
|
|
2659 | }, |
|
|
2660 | ); |
|
|
2661 | } |
|
|
2662 | |
|
|
2663 | $self |
2505 | } |
2664 | } |
2506 | |
2665 | |
2507 | sub size_request { |
2666 | sub size_request { |
2508 | (32, 8) |
2667 | (32, 8) |
2509 | } |
2668 | } |
2510 | |
2669 | |
|
|
2670 | sub update { |
|
|
2671 | my ($self) = @_; |
|
|
2672 | |
|
|
2673 | return unless $self->{visible}; |
|
|
2674 | |
|
|
2675 | $self->SUPER::update; |
|
|
2676 | } |
|
|
2677 | |
2511 | sub _draw { |
2678 | sub _draw { |
2512 | my ($self) = @_; |
2679 | my ($self) = @_; |
2513 | |
2680 | |
2514 | return unless $::CONN;#d# manage and cache textures differently |
2681 | return unless $::CONN; |
|
|
2682 | |
|
|
2683 | my $face; |
|
|
2684 | |
|
|
2685 | if ($self->{frame}) { |
|
|
2686 | my $anim = $::CONN->{anim}[$self->{anim}]; |
|
|
2687 | |
|
|
2688 | $face = $anim->[ $self->{frame} % @$anim ] |
|
|
2689 | if $anim && @$anim; |
|
|
2690 | } |
|
|
2691 | |
2515 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2692 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2516 | |
2693 | |
2517 | # TODO animation |
|
|
2518 | if ($tex) { |
2694 | if ($tex) { |
2519 | glEnable GL_TEXTURE_2D; |
2695 | glEnable GL_TEXTURE_2D; |
2520 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2696 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2521 | glColor 1, 1, 1, 1; |
2697 | glColor 1, 1, 1, 1; |
2522 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2698 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2523 | glDisable GL_TEXTURE_2D; |
2699 | glDisable GL_TEXTURE_2D; |
2524 | } |
2700 | } |
2525 | } |
2701 | } |
2526 | |
2702 | |
|
|
2703 | sub DESTROY { |
|
|
2704 | my ($self) = @_; |
|
|
2705 | |
|
|
2706 | $self->{timer}->cancel |
|
|
2707 | if $self->{timer}; |
|
|
2708 | |
|
|
2709 | $self->SUPER::DESTROY; |
|
|
2710 | } |
|
|
2711 | |
2527 | ############################################################################# |
2712 | ############################################################################# |
2528 | |
2713 | |
2529 | package CFClient::UI::InventoryItem; |
2714 | package CFClient::UI::InventoryItem; |
2530 | |
2715 | |
2531 | our @ISA = CFClient::UI::HBox::; |
2716 | our @ISA = CFClient::UI::HBox::; |
2532 | |
|
|
2533 | sub _item_to_desc { |
|
|
2534 | my ($item) = @_; |
|
|
2535 | |
|
|
2536 | my $desc = |
|
|
2537 | $item->{nrof} < 2 |
|
|
2538 | ? $item->{name} |
|
|
2539 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2540 | |
|
|
2541 | $item->{flags} & Crossfire::Protocol::F_OPEN |
|
|
2542 | and $desc .= " (open)"; |
|
|
2543 | $item->{flags} & Crossfire::Protocol::F_APPLIED |
|
|
2544 | and $desc .= " (applied)"; |
|
|
2545 | $item->{flags} & Crossfire::Protocol::F_UNPAID |
|
|
2546 | and $desc .= " (unpaid)"; |
|
|
2547 | $item->{flags} & Crossfire::Protocol::F_MAGIC |
|
|
2548 | and $desc .= " (magic)"; |
|
|
2549 | $item->{flags} & Crossfire::Protocol::F_CURSED |
|
|
2550 | and $desc .= " (cursed)"; |
|
|
2551 | $item->{flags} & Crossfire::Protocol::F_DAMNED |
|
|
2552 | and $desc .= " (damned)"; |
|
|
2553 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2554 | and $desc .= " *"; |
|
|
2555 | |
|
|
2556 | $desc |
|
|
2557 | } |
|
|
2558 | |
2717 | |
2559 | sub new { |
2718 | sub new { |
2560 | my $class = shift; |
2719 | my $class = shift; |
2561 | |
2720 | |
2562 | my %args = @_; |
2721 | my %args = @_; |
2563 | |
2722 | |
2564 | my $item = delete $args{item}; |
2723 | my $item = delete $args{item}; |
2565 | |
2724 | |
2566 | my $desc = _item_to_desc ($item); |
2725 | my $desc = CFClient::Item::desc_string $item; |
2567 | |
2726 | |
2568 | my $self = $class->SUPER::new ( |
2727 | my $self = $class->SUPER::new ( |
2569 | can_hover => 1, |
2728 | can_hover => 1, |
2570 | can_events => 1, |
2729 | can_events => 1, |
2571 | tooltip => ((CFClient::UI::Label::escape $desc) |
2730 | tooltip => ((CFClient::UI::Label::escape $desc) |
2572 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2731 | . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"), |
2573 | connect_button_down => sub { |
2732 | connect_button_down => sub { |
2574 | my ($self, $ev, $x, $y) = @_; |
2733 | my ($self, $ev, $x, $y) = @_; |
2575 | |
2734 | |
2576 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2735 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2577 | if ($ev->{button} == 1) { |
2736 | if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { |
2578 | my $targ = $::CONN->{player}{tag}; |
2737 | my $targ = $::CONN->{player}{tag}; |
2579 | |
2738 | |
2580 | if ($item->{container} == $::CONN->{player}{tag}) { |
2739 | if ($item->{container} == $::CONN->{player}{tag}) { |
2581 | $targ = $main::OPENCONT; |
2740 | $targ = $main::OPENCONT; |
2582 | } |
2741 | } |
2583 | |
2742 | |
2584 | $::CONN->send ("move $targ $item->{tag} 0"); |
2743 | $::CONN->send ("move $targ $item->{tag} 0"); |
|
|
2744 | } elsif ($ev->{button} == 1) { |
|
|
2745 | $::CONN->send ("examine $item->{tag}"); |
2585 | } elsif ($ev->{button} == 2) { |
2746 | } elsif ($ev->{button} == 2) { |
2586 | $::CONN->send ("apply $item->{tag}"); |
2747 | $::CONN->send ("apply $item->{tag}"); |
2587 | } elsif ($ev->{button} == 3) { |
2748 | } elsif ($ev->{button} == 3) { |
2588 | my @menu_items = ( |
2749 | my @menu_items = ( |
2589 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2750 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2590 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
2751 | ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }], |
2591 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
2752 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2753 | ( |
|
|
2754 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2755 | ? ( |
|
|
2756 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }], |
|
|
2757 | ) |
|
|
2758 | : ( |
|
|
2759 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }], |
2592 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
2760 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
2593 | [ |
2761 | ) |
2594 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
|
|
2595 | sub { $::CONN->send ("lock $item->{tag}") }, |
|
|
2596 | ], |
2762 | ), |
2597 | ); |
2763 | ); |
2598 | |
2764 | |
2599 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2765 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2600 | } |
2766 | } |
2601 | |
2767 | |
… | |
… | |
2622 | } |
2788 | } |
2623 | |
2789 | |
2624 | sub update_item { |
2790 | sub update_item { |
2625 | my ($self) = @_; |
2791 | my ($self) = @_; |
2626 | |
2792 | |
2627 | my $desc = _item_to_desc ($self->{item}); |
2793 | my $desc = CFClient::Item::desc_string ($self->{item}); |
2628 | |
2794 | |
2629 | $self->{name_lbl}->set_text ($desc); |
2795 | $self->{name_lbl}->set_text ($desc); |
2630 | } |
2796 | } |
2631 | |
2797 | |
2632 | ############################################################################# |
2798 | ############################################################################# |
… | |
… | |
2637 | |
2803 | |
2638 | sub new { |
2804 | sub new { |
2639 | my $class = shift; |
2805 | my $class = shift; |
2640 | |
2806 | |
2641 | my $self = $class->SUPER::new ( |
2807 | my $self = $class->SUPER::new ( |
2642 | scrolled => (new CFClient::UI::VBox), |
2808 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
2643 | @_, |
2809 | @_, |
2644 | ); |
2810 | ); |
2645 | |
2811 | |
2646 | $self |
2812 | $self |
2647 | } |
2813 | } |
… | |
… | |
2657 | or ($a->{name} cmp $b->{name}) |
2823 | or ($a->{name} cmp $b->{name}) |
2658 | } @$items; |
2824 | } @$items; |
2659 | |
2825 | |
2660 | $self->{real_items} = \@items; |
2826 | $self->{real_items} = \@items; |
2661 | |
2827 | |
|
|
2828 | my $row = 0; |
2662 | for my $item (@items) { |
2829 | for my $item (@items) { |
2663 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
2830 | CFClient::Item::update_widgets $item; |
2664 | $item->update_item (); |
|
|
2665 | } |
|
|
2666 | |
2831 | |
2667 | $self->{scrolled}->add (@items); |
2832 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
|
|
2833 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
|
|
2834 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
|
|
2835 | |
|
|
2836 | $row++; |
|
|
2837 | } |
2668 | |
2838 | |
2669 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2839 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2670 | } |
2840 | } |
2671 | |
2841 | |
2672 | sub size_request { |
2842 | sub size_request { |
… | |
… | |
2714 | |
2884 | |
2715 | # popup given the event (must be a mouse button down event currently) |
2885 | # popup given the event (must be a mouse button down event currently) |
2716 | sub popup { |
2886 | sub popup { |
2717 | my ($self, $ev) = @_; |
2887 | my ($self, $ev) = @_; |
2718 | |
2888 | |
2719 | $self->emit ("popdown"); |
2889 | $self->_emit ("popdown"); |
2720 | |
2890 | |
2721 | # maybe save $GRAB? must be careful about events... |
2891 | # maybe save $GRAB? must be careful about events... |
2722 | $GRAB = $self; |
2892 | $GRAB = $self; |
2723 | $self->{button} = $ev->{button}; |
2893 | $self->{button} = $ev->{button}; |
2724 | |
2894 | |
… | |
… | |
2739 | |
2909 | |
2740 | if ($ev->{button} == $self->{button}) { |
2910 | if ($ev->{button} == $self->{button}) { |
2741 | undef $GRAB; |
2911 | undef $GRAB; |
2742 | $self->hide; |
2912 | $self->hide; |
2743 | |
2913 | |
2744 | $self->emit ("popdown"); |
2914 | $self->_emit ("popdown"); |
2745 | $self->{hover}[1]->() if $self->{hover}; |
2915 | $self->{hover}[1]->() if $self->{hover}; |
2746 | } |
2916 | } |
2747 | } |
2917 | } |
2748 | |
2918 | |
2749 | ############################################################################# |
2919 | ############################################################################# |
… | |
… | |
2811 | sub add { |
2981 | sub add { |
2812 | my ($self, $text, %arg) = @_; |
2982 | my ($self, $text, %arg) = @_; |
2813 | |
2983 | |
2814 | $text =~ s/^\s+//; |
2984 | $text =~ s/^\s+//; |
2815 | $text =~ s/\s+$//; |
2985 | $text =~ s/\s+$//; |
|
|
2986 | |
|
|
2987 | return unless $text; |
2816 | |
2988 | |
2817 | my $timeout = time + ((delete $arg{timeout}) || 60); |
2989 | my $timeout = time + ((delete $arg{timeout}) || 60); |
2818 | |
2990 | |
2819 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
2991 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
2820 | |
2992 | |
… | |
… | |
2891 | } |
3063 | } |
2892 | |
3064 | |
2893 | sub size_allocate { |
3065 | sub size_allocate { |
2894 | my ($self, $w, $h) = @_; |
3066 | my ($self, $w, $h) = @_; |
2895 | |
3067 | |
2896 | my $old_w = $self->{old_w}; $self->{old_w} = $w; |
|
|
2897 | my $old_h = $self->{old_h}; $self->{old_h} = $h; |
|
|
2898 | |
|
|
2899 | CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h |
|
|
2900 | if $old_w && $old_h && ($old_w != $w || $old_h != $h); |
|
|
2901 | |
|
|
2902 | for my $child ($self->children) { |
3068 | for my $child ($self->children) { |
2903 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
3069 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2904 | |
3070 | |
2905 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
3071 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
2906 | if exists $child->{req_x}; |
3072 | if exists $child->{req_x}; |
… | |
… | |
2935 | } |
3101 | } |
2936 | |
3102 | |
2937 | sub add { |
3103 | sub add { |
2938 | my ($self, @children) = @_; |
3104 | my ($self, @children) = @_; |
2939 | |
3105 | |
|
|
3106 | for (my @widgets = @children; my $w = pop @widgets; ) { |
|
|
3107 | push @widgets, $w->children; |
|
|
3108 | $w->{root} = $self; |
|
|
3109 | $w->{visible} = 1; |
|
|
3110 | } |
|
|
3111 | |
2940 | for my $child (@children) { |
3112 | for my $child (@children) { |
2941 | $child->{toplevel} = 1; |
3113 | $child->{is_toplevel} = 1; |
2942 | |
3114 | |
2943 | # integerise window positions |
3115 | # integerise window positions |
2944 | $child->{x} = int $child->{x}; |
3116 | $child->{x} = int $child->{x}; |
2945 | $child->{y} = int $child->{y}; |
3117 | $child->{y} = int $child->{y}; |
2946 | } |
3118 | } |
2947 | |
3119 | |
2948 | $self->SUPER::add (@children); |
3120 | $self->SUPER::add (@children); |
|
|
3121 | } |
|
|
3122 | |
|
|
3123 | sub remove { |
|
|
3124 | my ($self, @children) = @_; |
|
|
3125 | |
|
|
3126 | $self->SUPER::remove (@children); |
|
|
3127 | |
|
|
3128 | while (@children) { |
|
|
3129 | my $w = pop @children; |
|
|
3130 | push @children, $w->children; |
|
|
3131 | $w->set_invisible; |
|
|
3132 | } |
2949 | } |
3133 | } |
2950 | |
3134 | |
2951 | sub on_refresh { |
3135 | sub on_refresh { |
2952 | my ($self, $id, $cb) = @_; |
3136 | my ($self, $id, $cb) = @_; |
2953 | |
3137 | |
… | |
… | |
3006 | $w = 0 if $w < 0; |
3190 | $w = 0 if $w < 0; |
3007 | $h = 0 if $h < 0; |
3191 | $h = 0 if $h < 0; |
3008 | |
3192 | |
3009 | $widget->{w} = $w; |
3193 | $widget->{w} = $w; |
3010 | $widget->{h} = $h; |
3194 | $widget->{h} = $h; |
3011 | $widget->size_allocate ($w, $h); |
|
|
3012 | $widget->emit (size_allocate => $w, $h); |
3195 | $widget->emit (size_allocate => $w, $h); |
3013 | } |
3196 | } |
3014 | } |
3197 | } |
3015 | |
3198 | |
3016 | while ($self->{post_alloc_hook}) { |
3199 | while ($self->{post_alloc_hook}) { |
… | |
… | |
3022 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
3205 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
3023 | glClear GL_COLOR_BUFFER_BIT; |
3206 | glClear GL_COLOR_BUFFER_BIT; |
3024 | |
3207 | |
3025 | glMatrixMode GL_PROJECTION; |
3208 | glMatrixMode GL_PROJECTION; |
3026 | glLoadIdentity; |
3209 | glLoadIdentity; |
3027 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; |
3210 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
3028 | glMatrixMode GL_MODELVIEW; |
3211 | glMatrixMode GL_MODELVIEW; |
3029 | glLoadIdentity; |
3212 | glLoadIdentity; |
3030 | |
3213 | |
3031 | $self->_draw; |
3214 | $self->_draw; |
3032 | } |
3215 | } |