1 | package CFClient::UI; |
1 | package CFClient::UI; |
2 | |
2 | |
|
|
3 | use utf8; |
3 | use strict; |
4 | use strict; |
4 | |
5 | |
5 | use Scalar::Util (); |
6 | use Scalar::Util (); |
6 | use List::Util (); |
7 | use List::Util (); |
7 | |
8 | |
… | |
… | |
10 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
11 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
11 | |
12 | |
12 | our $ROOT; |
13 | our $ROOT; |
13 | our $TOOLTIP; |
14 | our $TOOLTIP; |
14 | our $BUTTON_STATE; |
15 | our $BUTTON_STATE; |
|
|
16 | |
|
|
17 | our %WIDGET; # all widgets, weak-referenced |
15 | |
18 | |
16 | sub check_tooltip { |
19 | sub check_tooltip { |
17 | if (!$GRAB) { |
20 | if (!$GRAB) { |
18 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
21 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
19 | if (length $widget->{tooltip}) { |
22 | if (length $widget->{tooltip}) { |
… | |
… | |
23 | |
26 | |
24 | my $tip = $widget->{tooltip}; |
27 | my $tip = $widget->{tooltip}; |
25 | |
28 | |
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
29 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
27 | |
30 | |
28 | $TOOLTIP->set_markup ($widget->{tooltip}); |
31 | $TOOLTIP->set_tooltip_from ($widget); |
29 | |
|
|
30 | $TOOLTIP->show; |
32 | $TOOLTIP->show; |
31 | |
33 | |
32 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
34 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
33 | |
35 | |
34 | if ($x + $TOOLTIP->{w} > $::WIDTH) { |
36 | if ($x + $TOOLTIP->{w} > $::WIDTH) { |
35 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); |
37 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); |
36 | } |
38 | } |
37 | |
39 | |
38 | $TOOLTIP->move ($x, $y); |
40 | $TOOLTIP->move ($x, $y); |
|
|
41 | $TOOLTIP->check_size; |
|
|
42 | $TOOLTIP->update; |
39 | } |
43 | } |
40 | |
44 | |
41 | return; |
45 | return; |
42 | } |
46 | } |
43 | } |
47 | } |
… | |
… | |
130 | |
134 | |
131 | for (@$vals) { |
135 | for (@$vals) { |
132 | my $i = int $_ + $rem; |
136 | my $i = int $_ + $rem; |
133 | $rem += $_ - $i; |
137 | $rem += $_ - $i; |
134 | $_ = $i; |
138 | $_ = $i; |
|
|
139 | } |
|
|
140 | } |
|
|
141 | |
|
|
142 | # call when resolution changes etc. |
|
|
143 | sub rescale_widgets { |
|
|
144 | my ($sx, $sy) = @_; |
|
|
145 | |
|
|
146 | for my $widget (values %WIDGET) { |
|
|
147 | if ($widget->{toplevel}) { |
|
|
148 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
|
|
149 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
|
|
150 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
|
|
151 | $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; |
|
|
152 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
|
|
153 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
|
|
154 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
|
|
155 | $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; |
|
|
156 | } |
|
|
157 | |
|
|
158 | $widget->reconfigure; |
135 | } |
159 | } |
136 | } |
160 | } |
137 | |
161 | |
138 | ############################################################################# |
162 | ############################################################################# |
139 | |
163 | |
… | |
… | |
158 | if (/^connect_(.*)$/) { |
182 | if (/^connect_(.*)$/) { |
159 | $self->connect ($1 => delete $self->{$_}); |
183 | $self->connect ($1 => delete $self->{$_}); |
160 | } |
184 | } |
161 | } |
185 | } |
162 | |
186 | |
|
|
187 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
|
|
188 | |
163 | $self |
189 | $self |
164 | } |
190 | } |
165 | |
191 | |
166 | sub destroy { |
192 | sub destroy { |
167 | my ($self) = @_; |
193 | my ($self) = @_; |
… | |
… | |
232 | $self->{y} = $y; |
258 | $self->{y} = $y; |
233 | $self->update; |
259 | $self->update; |
234 | } |
260 | } |
235 | |
261 | |
236 | if ($self->{w} != $w || $self->{h} != $h) { |
262 | if ($self->{w} != $w || $self->{h} != $h) { |
237 | $self->{w} = $w; |
263 | $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $w, $h]; |
238 | $self->{h} = $h; |
|
|
239 | |
|
|
240 | $self->size_allocate ($w, $h); |
|
|
241 | $self->update; |
|
|
242 | $self->emit (size_allocate => $w, $h); |
|
|
243 | } |
264 | } |
244 | } |
265 | } |
245 | |
266 | |
246 | sub size_allocate { |
267 | sub size_allocate { |
247 | # nothing to be done |
268 | # nothing to be done |
248 | } |
269 | } |
249 | |
270 | |
|
|
271 | sub reconfigure { |
|
|
272 | my ($self) = @_; |
|
|
273 | |
|
|
274 | $self->check_size (1); |
|
|
275 | $self->update; |
|
|
276 | } |
|
|
277 | |
250 | sub children { |
278 | sub children { |
251 | } |
|
|
252 | |
|
|
253 | # call when resolution changes etc. |
|
|
254 | sub reconfigure { |
|
|
255 | my ($self) = @_; |
|
|
256 | |
|
|
257 | $_->reconfigure |
|
|
258 | for $self->children; |
|
|
259 | |
|
|
260 | $self->check_size; |
|
|
261 | $self->size_allocate ($self->{w}, $self->{h}); |
|
|
262 | $self->update; |
|
|
263 | } |
279 | } |
264 | |
280 | |
265 | sub set_max_size { |
281 | sub set_max_size { |
266 | my ($self, $w, $h) = @_; |
282 | my ($self, $w, $h) = @_; |
267 | |
283 | |
268 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
284 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
269 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
285 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
270 | } |
|
|
271 | |
|
|
272 | # return top left coordinates |
|
|
273 | sub _topleft { |
|
|
274 | my ($self, $x, $y) = @_; |
|
|
275 | |
|
|
276 | $self->{parent} |
|
|
277 | or Carp::confess "no parent widget in _topleft\n";#d# |
|
|
278 | |
|
|
279 | $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); |
|
|
280 | } |
286 | } |
281 | |
287 | |
282 | # translate global coordinates to local coordinate system |
288 | # translate global coordinates to local coordinate system |
283 | sub coord2local { |
289 | sub coord2local { |
284 | my ($self, $x, $y) = @_; |
290 | my ($self, $x, $y) = @_; |
285 | |
291 | |
286 | my ($X, $Y) = $self->_topleft; |
292 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
287 | ($x - $X, $y - $Y) |
|
|
288 | } |
293 | } |
289 | |
294 | |
290 | # translate local coordinates to global coordinate system |
295 | # translate local coordinates to global coordinate system |
291 | sub coord2global { |
296 | sub coord2global { |
292 | my ($self, $x, $y) = @_; |
297 | my ($self, $x, $y) = @_; |
293 | |
298 | |
294 | my ($X, $Y) = $self->_topleft; |
299 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
295 | ($x + $X, $y + $Y) |
|
|
296 | } |
300 | } |
297 | |
301 | |
298 | sub focus_in { |
302 | sub focus_in { |
299 | my ($self) = @_; |
303 | my ($self) = @_; |
300 | |
304 | |
… | |
… | |
398 | |
402 | |
399 | sub set_parent { |
403 | sub set_parent { |
400 | my ($self, $parent) = @_; |
404 | my ($self, $parent) = @_; |
401 | |
405 | |
402 | Scalar::Util::weaken ($self->{parent} = $parent); |
406 | Scalar::Util::weaken ($self->{parent} = $parent); |
|
|
407 | |
|
|
408 | # TODO: req_w _does_change after ->reconfigure |
|
|
409 | $self->check_size |
|
|
410 | unless exists $self->{req_w}; |
403 | } |
411 | } |
404 | |
412 | |
405 | sub check_size { |
413 | sub check_size { |
406 | my ($self) = @_; |
414 | my ($self, $forced) = @_; |
407 | |
415 | |
408 | $self->_check_size; |
416 | $self->{force_alloc} = 1 if $forced; |
409 | return; |
|
|
410 | my $check_size = $CFClient::UI::ROOT->{_check_size} ||= {}; |
|
|
411 | |
|
|
412 | $check_size->{$self} = $self; |
|
|
413 | |
|
|
414 | $CFClient::UI::ROOT->on_refresh (_check_size => sub { |
|
|
415 | while (%$check_size) { |
|
|
416 | my @widgets = values %$check_size; |
|
|
417 | $_->_check_size |
|
|
418 | for @widgets; |
|
|
419 | } |
|
|
420 | }); |
|
|
421 | } |
|
|
422 | |
|
|
423 | sub _check_size { |
|
|
424 | my ($self) = @_; |
|
|
425 | |
|
|
426 | delete $CFClient::UI::ROOT->{_check_size}{$self}; |
417 | $CFClient::UI::ROOT->{check_size}{$self} = $self; |
427 | |
|
|
428 | $self->{parent} |
|
|
429 | or return 1; |
|
|
430 | |
|
|
431 | my ($w, $h) = $self->{user_w} && $self->{user_h} |
|
|
432 | ? @$self{qw(user_w user_h)} |
|
|
433 | : $self->size_request; |
|
|
434 | |
|
|
435 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
|
|
436 | $self->{req_w} = $w; |
|
|
437 | $self->{req_h} = $h; |
|
|
438 | |
|
|
439 | $self->{parent}->_check_size |
|
|
440 | or $self->size_allocate ( |
|
|
441 | (List::Util::max $self->{w}, $w), |
|
|
442 | (List::Util::max $self->{h}, $h), |
|
|
443 | ); |
|
|
444 | |
|
|
445 | 1 |
|
|
446 | } else { |
|
|
447 | 0 |
|
|
448 | } |
|
|
449 | } |
418 | } |
450 | |
419 | |
451 | sub update { |
420 | sub update { |
452 | my ($self) = @_; |
421 | my ($self) = @_; |
453 | |
422 | |
454 | my $update = $CFClient::UI::ROOT->{_update} ||= {}; |
423 | $self->{parent}->update |
455 | |
424 | if $self->{parent}; |
456 | $update->{$self} = $self; |
|
|
457 | |
|
|
458 | $CFClient::UI::ROOT->on_refresh (_update => sub { |
|
|
459 | while (%$update) { |
|
|
460 | my @widgets = values %$update; |
|
|
461 | %$update = (); |
|
|
462 | |
|
|
463 | $_->{parent} && $_->{parent}->update |
|
|
464 | for @widgets; |
|
|
465 | } |
|
|
466 | }); |
|
|
467 | } |
425 | } |
468 | |
426 | |
469 | sub connect { |
427 | sub connect { |
470 | my ($self, $signal, $cb) = @_; |
428 | my ($self, $signal, $cb) = @_; |
471 | |
429 | |
… | |
… | |
479 | } |
437 | } |
480 | |
438 | |
481 | sub DESTROY { |
439 | sub DESTROY { |
482 | my ($self) = @_; |
440 | my ($self) = @_; |
483 | |
441 | |
|
|
442 | delete $WIDGET{$self+0}; |
484 | #$self->deactivate; |
443 | #$self->deactivate; |
485 | } |
444 | } |
486 | |
445 | |
487 | ############################################################################# |
446 | ############################################################################# |
488 | |
447 | |
… | |
… | |
573 | $self->{children} = [ |
532 | $self->{children} = [ |
574 | sort { $a->{z} <=> $b->{z} } |
533 | sort { $a->{z} <=> $b->{z} } |
575 | @{$self->{children}}, @widgets |
534 | @{$self->{children}}, @widgets |
576 | ]; |
535 | ]; |
577 | |
536 | |
578 | $_->check_size |
537 | $self->check_size (1); |
579 | for @widgets; |
|
|
580 | |
|
|
581 | $self->update; |
538 | $self->update; |
582 | } |
539 | } |
583 | |
540 | |
584 | sub children { |
541 | sub children { |
585 | @{ $_[0]{children} } |
542 | @{ $_[0]{children} } |
… | |
… | |
692 | } |
649 | } |
693 | |
650 | |
694 | sub update { |
651 | sub update { |
695 | my ($self) = @_; |
652 | my ($self) = @_; |
696 | |
653 | |
697 | $ROOT->on_refresh ($self => sub { $self->render_child }); |
654 | $ROOT->on_post_alloc ($self => sub { $self->render_child }); |
698 | $self->SUPER::update; |
655 | $self->SUPER::update; |
699 | } |
656 | } |
700 | |
657 | |
701 | sub size_allocate { |
658 | sub size_allocate { |
702 | my ($self, $w, $h) = @_; |
659 | my ($self, $w, $h) = @_; |
… | |
… | |
733 | my ($w, $h) = ($self->w, $self->h); |
690 | my ($w, $h) = ($self->w, $self->h); |
734 | |
691 | |
735 | my $tex = $self->{texture} |
692 | my $tex = $self->{texture} |
736 | or return; |
693 | or return; |
737 | |
694 | |
738 | glEnable GL_BLEND; |
|
|
739 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
740 | glEnable GL_TEXTURE_2D; |
695 | glEnable GL_TEXTURE_2D; |
741 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
696 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
742 | glColor 0, 0, 0, 1; |
697 | glColor 0, 0, 0, 1; |
743 | |
698 | |
744 | $tex->draw_quad (0, 0, $w, $h); |
699 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
745 | |
700 | |
746 | glDisable GL_BLEND; |
|
|
747 | glDisable GL_TEXTURE_2D; |
701 | glDisable GL_TEXTURE_2D; |
748 | } |
702 | } |
749 | |
703 | |
750 | ############################################################################# |
704 | ############################################################################# |
751 | |
705 | |
… | |
… | |
775 | $self->{view_y} = int $y; |
729 | $self->{view_y} = int $y; |
776 | |
730 | |
777 | $self->update; |
731 | $self->update; |
778 | } |
732 | } |
779 | |
733 | |
780 | # hmm, this does not work for topleft of $self... but we should not aks for that |
734 | # hmm, this does not work for topleft of $self... but we should not ask for that |
781 | sub _topleft { |
735 | sub coord2local { |
782 | my ($self, $x, $y) = @_; |
736 | my ($self, $x, $y) = @_; |
783 | |
737 | |
784 | $self->SUPER::_topleft ($x - $self->{view_x}, $y - $self->{view_y}) |
738 | $self->SUPER::coord2local ($x + $self->{view_x}, $y + $self->{view_y}) |
|
|
739 | } |
|
|
740 | |
|
|
741 | sub coord2global { |
|
|
742 | my ($self, $x, $y) = @_; |
|
|
743 | |
|
|
744 | $x = List::Util::min $self->{w}, $x - $self->{view_x}; |
|
|
745 | $y = List::Util::min $self->{h}, $y - $self->{view_y}; |
|
|
746 | |
|
|
747 | $self->SUPER::coord2global ($x, $y) |
785 | } |
748 | } |
786 | |
749 | |
787 | sub find_widget { |
750 | sub find_widget { |
788 | my ($self, $x, $y) = @_; |
751 | my ($self, $x, $y) = @_; |
789 | |
752 | |
… | |
… | |
834 | $self->add ($self->{slider}); |
797 | $self->add ($self->{slider}); |
835 | |
798 | |
836 | $self |
799 | $self |
837 | } |
800 | } |
838 | |
801 | |
839 | #TODO# update range on size_allocate depeneing on child |
802 | #TODO# update range on size_allocate depending on child |
840 | # update viewport offset on scroll |
803 | # update viewport offset on scroll |
841 | |
804 | |
842 | ############################################################################# |
805 | ############################################################################# |
843 | |
806 | |
844 | package CFClient::UI::Frame; |
807 | package CFClient::UI::Frame; |
… | |
… | |
848 | use CFClient::OpenGL; |
811 | use CFClient::OpenGL; |
849 | |
812 | |
850 | sub new { |
813 | sub new { |
851 | my $class = shift; |
814 | my $class = shift; |
852 | |
815 | |
853 | my $self = $class->SUPER::new ( |
816 | $class->SUPER::new ( |
854 | bg => [1, 1, 1, 1], |
817 | bg => undef, |
855 | border_bg => [1, 1, 1, 1], |
|
|
856 | border => 0.8, |
|
|
857 | @_ |
818 | @_, |
858 | ); |
819 | ) |
859 | |
|
|
860 | $self |
|
|
861 | } |
820 | } |
862 | |
821 | |
863 | sub _draw { |
822 | sub _draw { |
864 | my ($self) = @_; |
823 | my ($self) = @_; |
865 | |
824 | |
866 | my ($w, $h) = ($self->{w}, $self->{h}); |
825 | if ($self->{bg}) { |
|
|
826 | my ($w, $h) = @$self{qw(w h)}; |
867 | |
827 | |
868 | glEnable GL_BLEND; |
828 | glEnable GL_BLEND; |
869 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
829 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
870 | glEnable GL_TEXTURE_2D; |
830 | glColor @{ $self->{bg} }; |
871 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
872 | |
831 | |
873 | # glBegin GL_QUADS; |
832 | glBegin GL_QUADS; |
874 | # glColor 0, 0, 0, 0; |
|
|
875 | # glVertex 0 , 0; |
833 | glVertex 0 , 0; |
876 | # glVertex 0 , $h; |
834 | glVertex 0 , $h; |
877 | # glVertex $w, $h; |
835 | glVertex $w, $h; |
878 | # glVertex $w, 0; |
836 | glVertex $w, 0; |
879 | # glEnd; |
837 | glEnd; |
880 | |
838 | |
881 | |
|
|
882 | $self->child->draw; |
|
|
883 | glDisable GL_BLEND; |
839 | glDisable GL_BLEND; |
884 | glDisable GL_TEXTURE_2D; |
840 | } |
|
|
841 | |
|
|
842 | $self->SUPER::_draw; |
885 | } |
843 | } |
886 | |
844 | |
887 | ############################################################################# |
845 | ############################################################################# |
888 | |
846 | |
889 | package CFClient::UI::FancyFrame; |
847 | package CFClient::UI::FancyFrame; |
… | |
… | |
903 | |
861 | |
904 | my $self = $class->SUPER::new ( |
862 | my $self = $class->SUPER::new ( |
905 | bg => [1, 1, 1, 1], |
863 | bg => [1, 1, 1, 1], |
906 | border_bg => [1, 1, 1, 1], |
864 | border_bg => [1, 1, 1, 1], |
907 | border => 0.6, |
865 | border => 0.6, |
|
|
866 | toplevel => 1, |
908 | can_events => 1, |
867 | can_events => 1, |
909 | @_ |
868 | @_ |
910 | ); |
869 | ); |
911 | |
870 | |
912 | $self->{title} &&= new CFClient::UI::Label |
871 | $self->{title} &&= new CFClient::UI::Label |
… | |
… | |
1005 | my ($self) = @_; |
964 | my ($self) = @_; |
1006 | |
965 | |
1007 | my ($w, $h ) = ($self->{w}, $self->{h}); |
966 | my ($w, $h ) = ($self->{w}, $self->{h}); |
1008 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
967 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
1009 | |
968 | |
1010 | glEnable GL_BLEND; |
|
|
1011 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1012 | glEnable GL_TEXTURE_2D; |
969 | glEnable GL_TEXTURE_2D; |
1013 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
970 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1014 | |
971 | |
1015 | my $border = $self->border; |
972 | my $border = $self->border; |
1016 | |
973 | |
1017 | glColor @{ $self->{border_bg} }; |
974 | glColor @{ $self->{border_bg} }; |
1018 | $tex[1]->draw_quad (0, 0, $w, $border); |
975 | $tex[1]->draw_quad_alpha (0, 0, $w, $border); |
1019 | $tex[3]->draw_quad (0, $border, $border, $ch); |
976 | $tex[3]->draw_quad_alpha (0, $border, $border, $ch); |
1020 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
977 | $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1021 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
978 | $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border); |
1022 | |
979 | |
1023 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
980 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1024 | my $bg = $tex[0]; |
981 | my $bg = $tex[0]; |
1025 | |
982 | |
1026 | # TODO: repeat texture not scale |
983 | # TODO: repeat texture not scale |
… | |
… | |
1030 | glColor @{ $self->{bg} }; |
987 | glColor @{ $self->{bg} }; |
1031 | |
988 | |
1032 | $bg->{s} = $rep_x; |
989 | $bg->{s} = $rep_x; |
1033 | $bg->{t} = $rep_y; |
990 | $bg->{t} = $rep_y; |
1034 | $bg->{wrap_mode} = 1; |
991 | $bg->{wrap_mode} = 1; |
1035 | $bg->draw_quad ($border, $border, $cw, $ch); |
992 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
|
|
993 | } |
1036 | |
994 | |
1037 | glDisable GL_TEXTURE_2D; |
995 | glDisable GL_TEXTURE_2D; |
1038 | glDisable GL_BLEND; |
|
|
1039 | } |
|
|
1040 | |
996 | |
1041 | $self->{title}->draw if $self->{title}; |
997 | $self->{title}->draw if $self->{title}; |
1042 | |
998 | |
1043 | $self->child->draw; |
999 | $self->child->draw; |
1044 | } |
1000 | } |
… | |
… | |
1271 | } |
1227 | } |
1272 | |
1228 | |
1273 | sub size_allocate { |
1229 | sub size_allocate { |
1274 | my ($self, $w, $h) = @_; |
1230 | my ($self, $w, $h) = @_; |
1275 | |
1231 | |
|
|
1232 | Carp::confess "negative size" if $w < 0 || $h < 0;#d# |
|
|
1233 | |
1276 | my $children = $self->{children}; |
1234 | my $children = $self->{children}; |
1277 | |
1235 | |
1278 | my @h = map $_->{req_h}, @$children; |
1236 | my @h = map $_->{req_h}, @$children; |
1279 | |
1237 | |
1280 | my $req_h = List::Util::sum @h; |
1238 | my $req_h = List::Util::sum @h; |
… | |
… | |
1319 | my ($class, %arg) = @_; |
1277 | my ($class, %arg) = @_; |
1320 | |
1278 | |
1321 | my $self = $class->SUPER::new ( |
1279 | my $self = $class->SUPER::new ( |
1322 | fg => [1, 1, 1], |
1280 | fg => [1, 1, 1], |
1323 | #font => default_font |
1281 | #font => default_font |
|
|
1282 | #text => initial text |
|
|
1283 | #markup => initial narkup |
|
|
1284 | layout => (new CFClient::Layout), |
1324 | fontsize => 1, |
1285 | fontsize => 1, |
1325 | text => "", |
|
|
1326 | align => -1, |
1286 | align => -1, |
1327 | valign => -1, |
1287 | valign => -1, |
1328 | padding => 2, |
1288 | padding => 2, |
1329 | layout => new CFClient::Layout, |
|
|
1330 | can_events => 0, |
1289 | can_events => 0, |
1331 | %arg |
1290 | %arg |
1332 | ); |
1291 | ); |
1333 | |
1292 | |
1334 | if (exists $self->{template}) { |
1293 | if (exists $self->{template}) { |
1335 | my $layout = new CFClient::Layout; |
1294 | my $layout = new CFClient::Layout; |
1336 | $layout->set_text (delete $self->{template}); |
1295 | $layout->set_text (delete $self->{template}); |
1337 | $self->{template} = $layout; |
1296 | $self->{template} = $layout; |
1338 | } |
1297 | } |
1339 | |
1298 | |
1340 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1299 | if (exists $self->{markup}) { |
1341 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1300 | $self->set_markup (delete $self->{markup}); |
|
|
1301 | } else { |
|
|
1302 | $self->set_text (delete $self->{text}); |
|
|
1303 | } |
1342 | |
1304 | |
1343 | $self |
1305 | $self |
1344 | } |
1306 | } |
1345 | |
1307 | |
1346 | sub escape { |
1308 | sub escape { |
… | |
… | |
1364 | my ($self, $text) = @_; |
1326 | my ($self, $text) = @_; |
1365 | |
1327 | |
1366 | return if $self->{text} eq "T$text"; |
1328 | return if $self->{text} eq "T$text"; |
1367 | $self->{text} = "T$text"; |
1329 | $self->{text} = "T$text"; |
1368 | |
1330 | |
|
|
1331 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1369 | $self->{layout}->set_text ($text); |
1332 | $self->{layout}->set_text ($text); |
1370 | |
1333 | |
1371 | delete $self->{texture}; |
|
|
1372 | $self->update; |
1334 | $self->update; |
1373 | $self->check_size; |
1335 | $self->check_size; |
1374 | } |
1336 | } |
1375 | |
1337 | |
1376 | sub set_markup { |
1338 | sub set_markup { |
1377 | my ($self, $markup) = @_; |
1339 | my ($self, $markup) = @_; |
1378 | |
1340 | |
1379 | return if $self->{text} eq "M$markup"; |
1341 | return if $self->{text} eq "M$markup"; |
1380 | $self->{text} = "M$markup"; |
1342 | $self->{text} = "M$markup"; |
1381 | |
1343 | |
|
|
1344 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
|
|
1345 | |
|
|
1346 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1382 | $self->{layout}->set_markup ($markup); |
1347 | $self->{layout}->set_markup ($markup); |
1383 | |
1348 | |
1384 | delete $self->{texture}; |
|
|
1385 | $self->update; |
1349 | $self->update; |
1386 | $self->check_size; |
1350 | $self->check_size; |
1387 | } |
1351 | } |
1388 | |
1352 | |
1389 | sub size_request { |
1353 | sub size_request { |
… | |
… | |
1429 | |
1393 | |
1430 | sub _draw { |
1394 | sub _draw { |
1431 | my ($self) = @_; |
1395 | my ($self) = @_; |
1432 | |
1396 | |
1433 | my $tex = $self->{texture} ||= do { |
1397 | my $tex = $self->{texture} ||= do { |
|
|
1398 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1434 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1399 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1435 | $self->{layout}->set_width ($self->{w}); |
1400 | $self->{layout}->set_width ($self->{w}); |
1436 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1401 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
|
|
1402 | |
1437 | new_from_layout CFClient::Texture $self->{layout} |
1403 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
|
|
1404 | |
|
|
1405 | $self->{ox} = int $self->{align} < 0 ? $self->{padding} |
|
|
1406 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
|
|
1407 | : ($self->{w} - $tex->{w}) * 0.5; |
|
|
1408 | |
|
|
1409 | $self->{oy} = int $self->{valign} < 0 ? $self->{padding} |
|
|
1410 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
|
|
1411 | : ($self->{h} - $tex->{h}) * 0.5; |
|
|
1412 | |
|
|
1413 | $tex |
1438 | }; |
1414 | }; |
1439 | |
1415 | |
1440 | glEnable GL_BLEND; |
|
|
1441 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1442 | glEnable GL_TEXTURE_2D; |
1416 | glEnable GL_TEXTURE_2D; |
1443 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1417 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1444 | |
1418 | |
|
|
1419 | if ($tex->{format} == GL_ALPHA) { |
1445 | glColor @{$self->{fg}}; |
1420 | glColor @{$self->{fg}}; |
1446 | |
|
|
1447 | $self->{ox} = int ( |
|
|
1448 | $self->{align} < 0 ? $self->{padding} |
|
|
1449 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
|
|
1450 | : ($self->{w} - $tex->{w}) * 0.5 |
|
|
1451 | ); |
|
|
1452 | |
|
|
1453 | $self->{oy} = int ( |
|
|
1454 | $self->{valign} < 0 ? $self->{padding} |
|
|
1455 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
|
|
1456 | : ($self->{h} - $tex->{h}) * 0.5 |
|
|
1457 | ); |
|
|
1458 | |
|
|
1459 | $tex->draw_quad ($self->{ox}, $self->{oy}); |
1421 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
|
|
1422 | } else { |
|
|
1423 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
|
|
1424 | } |
1460 | |
1425 | |
1461 | glDisable GL_TEXTURE_2D; |
1426 | glDisable GL_TEXTURE_2D; |
1462 | glDisable GL_BLEND; |
|
|
1463 | } |
1427 | } |
1464 | |
1428 | |
1465 | ############################################################################# |
1429 | ############################################################################# |
1466 | |
1430 | |
1467 | package CFClient::UI::EntryBase; |
1431 | package CFClient::UI::EntryBase; |
… | |
… | |
1502 | $self->{layout}->set_text ("$text "); |
1466 | $self->{layout}->set_text ("$text "); |
1503 | |
1467 | |
1504 | $self->emit (changed => $self->{text}); |
1468 | $self->emit (changed => $self->{text}); |
1505 | } |
1469 | } |
1506 | |
1470 | |
|
|
1471 | sub set_text { |
|
|
1472 | my ($self, $text) = @_; |
|
|
1473 | |
|
|
1474 | $self->{cursor} = length $text; |
|
|
1475 | $self->_set_text ($text); |
|
|
1476 | $self->check_size; |
|
|
1477 | $self->update; |
|
|
1478 | } |
|
|
1479 | |
1507 | sub get_text { |
1480 | sub get_text { |
1508 | $_[0]{text} |
1481 | $_[0]{text} |
1509 | } |
1482 | } |
1510 | |
1483 | |
1511 | sub size_request { |
1484 | sub size_request { |
… | |
… | |
1518 | |
1491 | |
1519 | sub size_allocate { |
1492 | sub size_allocate { |
1520 | my ($self, $w, $h) = @_; |
1493 | my ($self, $w, $h) = @_; |
1521 | |
1494 | |
1522 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1495 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1523 | } |
|
|
1524 | |
|
|
1525 | sub set_text { |
|
|
1526 | my ($self, $text) = @_; |
|
|
1527 | |
|
|
1528 | $self->{cursor} = length $text; |
|
|
1529 | $self->_set_text ($text); |
|
|
1530 | $self->update; |
|
|
1531 | } |
1496 | } |
1532 | |
1497 | |
1533 | sub key_down { |
1498 | sub key_down { |
1534 | my ($self, $ev) = @_; |
1499 | my ($self, $ev) = @_; |
1535 | |
1500 | |
… | |
… | |
1537 | my $sym = $ev->{sym}; |
1502 | my $sym = $ev->{sym}; |
1538 | my $uni = $ev->{unicode}; |
1503 | my $uni = $ev->{unicode}; |
1539 | |
1504 | |
1540 | my $text = $self->get_text; |
1505 | my $text = $self->get_text; |
1541 | |
1506 | |
1542 | if ($sym == 8) { |
1507 | if ($uni == 8) { |
1543 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1508 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1544 | } elsif ($sym == 127) { |
1509 | } elsif ($uni == 127) { |
1545 | substr $text, $self->{cursor}, 1, ""; |
1510 | substr $text, $self->{cursor}, 1, ""; |
1546 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1511 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1547 | --$self->{cursor} if $self->{cursor}; |
1512 | --$self->{cursor} if $self->{cursor}; |
1548 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1513 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1549 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1514 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1550 | } elsif ($sym == CFClient::SDLK_HOME) { |
1515 | } elsif ($sym == CFClient::SDLK_HOME) { |
1551 | $self->{cursor} = 0; |
1516 | $self->{cursor} = 0; |
1552 | } elsif ($sym == CFClient::SDLK_END) { |
1517 | } elsif ($sym == CFClient::SDLK_END) { |
1553 | $self->{cursor} = length $text; |
1518 | $self->{cursor} = length $text; |
1554 | } elsif ($sym == 27) { |
1519 | } elsif ($uni == 27) { |
1555 | $self->emit ('escape'); |
1520 | $self->emit ('escape'); |
1556 | } elsif ($uni) { |
1521 | } elsif ($uni) { |
1557 | substr $text, $self->{cursor}++, 0, chr $uni; |
1522 | substr $text, $self->{cursor}++, 0, chr $uni; |
1558 | } |
1523 | } |
1559 | |
1524 | |
… | |
… | |
1723 | |
1688 | |
1724 | if ($GRAB == $self) { |
1689 | if ($GRAB == $self) { |
1725 | $self->{fg} = $self->{active_fg}; |
1690 | $self->{fg} = $self->{active_fg}; |
1726 | } |
1691 | } |
1727 | |
1692 | |
1728 | glEnable GL_BLEND; |
|
|
1729 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1730 | glEnable GL_TEXTURE_2D; |
1693 | glEnable GL_TEXTURE_2D; |
1731 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1694 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1732 | glColor 0, 0, 0, 1; |
1695 | glColor 0, 0, 0, 1; |
1733 | |
1696 | |
1734 | $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); |
1697 | $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
1735 | |
1698 | |
1736 | glDisable GL_TEXTURE_2D; |
1699 | glDisable GL_TEXTURE_2D; |
1737 | glDisable GL_BLEND; |
|
|
1738 | |
1700 | |
1739 | $self->SUPER::_draw; |
1701 | $self->SUPER::_draw; |
1740 | } |
1702 | } |
1741 | |
1703 | |
1742 | ############################################################################# |
1704 | ############################################################################# |
… | |
… | |
1789 | |
1751 | |
1790 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1752 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1791 | |
1753 | |
1792 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1754 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1793 | |
1755 | |
1794 | glEnable GL_BLEND; |
1756 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
1757 | |
1795 | glEnable GL_TEXTURE_2D; |
1758 | glEnable GL_TEXTURE_2D; |
1796 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1797 | |
|
|
1798 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
1799 | |
|
|
1800 | $tex->draw_quad (0, 0, $s, $s); |
1759 | $tex->draw_quad_alpha (0, 0, $s, $s); |
1801 | |
|
|
1802 | glDisable GL_TEXTURE_2D; |
1760 | glDisable GL_TEXTURE_2D; |
1803 | glDisable GL_BLEND; |
|
|
1804 | } |
1761 | } |
1805 | |
1762 | |
1806 | ############################################################################# |
1763 | ############################################################################# |
1807 | |
1764 | |
1808 | package CFClient::UI::Image; |
1765 | package CFClient::UI::Image; |
… | |
… | |
1851 | glTranslate 0, -$self->{w}, 0; |
1808 | glTranslate 0, -$self->{w}, 0; |
1852 | |
1809 | |
1853 | ($w, $h) = ($h, $w); |
1810 | ($w, $h) = ($h, $w); |
1854 | } |
1811 | } |
1855 | |
1812 | |
1856 | glEnable GL_BLEND; |
|
|
1857 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1858 | glEnable GL_TEXTURE_2D; |
1813 | glEnable GL_TEXTURE_2D; |
1859 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1814 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1860 | |
1815 | |
1861 | $tex->draw_quad (0, 0, $w, $h); |
1816 | $tex->draw_quad_alpha (0, 0, $w, $h); |
1862 | |
1817 | |
1863 | glDisable GL_BLEND; |
|
|
1864 | glDisable GL_TEXTURE_2D; |
1818 | glDisable GL_TEXTURE_2D; |
1865 | } |
1819 | } |
1866 | |
1820 | |
1867 | ############################################################################# |
1821 | ############################################################################# |
1868 | |
1822 | |
… | |
… | |
2160 | $page ||= 2; |
2114 | $page ||= 2; |
2161 | |
2115 | |
2162 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
2116 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
2163 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
2117 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
2164 | |
2118 | |
2165 | glEnable GL_BLEND; |
|
|
2166 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2167 | glEnable GL_TEXTURE_2D; |
2119 | glEnable GL_TEXTURE_2D; |
2168 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2120 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2169 | |
2121 | |
2170 | # draw background |
2122 | # draw background |
2171 | $tex[1]->draw_quad (0, 0, $w, $h); |
2123 | $tex[1]->draw_quad_alpha (0, 0, $w, $h); |
2172 | |
2124 | |
2173 | # draw handle |
2125 | # draw handle |
2174 | $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h); |
2126 | $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h); |
2175 | |
2127 | |
2176 | glDisable GL_BLEND; |
|
|
2177 | glDisable GL_TEXTURE_2D; |
2128 | glDisable GL_TEXTURE_2D; |
2178 | } |
2129 | } |
2179 | |
2130 | |
2180 | ############################################################################# |
2131 | ############################################################################# |
2181 | |
2132 | |
… | |
… | |
2192 | fontsize => 1, |
2143 | fontsize => 1, |
2193 | can_events => 0, |
2144 | can_events => 0, |
2194 | #font => default_font |
2145 | #font => default_font |
2195 | @_, |
2146 | @_, |
2196 | |
2147 | |
2197 | layout => (new CFClient::Layout), |
2148 | layout => (new CFClient::Layout 1), |
2198 | par => [], |
2149 | par => [], |
2199 | height => 0, |
2150 | height => 0, |
2200 | children => [ |
2151 | children => [ |
2201 | (new CFClient::UI::Empty expand => 1), |
2152 | (new CFClient::UI::Empty expand => 1), |
2202 | (new CFClient::UI::Slider vertical => 1), |
2153 | (new CFClient::UI::Slider vertical => 1), |
… | |
… | |
2220 | |
2171 | |
2221 | my $layout = $self->{layout}; |
2172 | my $layout = $self->{layout}; |
2222 | |
2173 | |
2223 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2174 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2224 | $layout->set_width ($self->{children}[0]{w}); |
2175 | $layout->set_width ($self->{children}[0]{w}); |
2225 | $layout->set_text ($text); |
2176 | $layout->set_markup ($text); |
2226 | |
2177 | |
2227 | ($layout->size)[1] |
2178 | ($layout->size)[1] |
2228 | } |
2179 | } |
2229 | |
2180 | |
2230 | sub reflow { |
2181 | sub reflow { |
… | |
… | |
2268 | |
2219 | |
2269 | return unless $self->{h} > 0; |
2220 | return unless $self->{h} > 0; |
2270 | |
2221 | |
2271 | delete $self->{texture}; |
2222 | delete $self->{texture}; |
2272 | |
2223 | |
2273 | $ROOT->on_refresh ($self, sub { |
2224 | $ROOT->on_post_alloc ($self, sub { |
2274 | if (delete $self->{need_reflow}) { |
2225 | if (delete $self->{need_reflow}) { |
2275 | my $height = 0; |
2226 | my $height = 0; |
2276 | |
2227 | |
2277 | $height += $_->[0] = $self->text_height ($_->[2]) |
2228 | $height += $_->[0] = $self->text_height ($_->[2]) |
2278 | for @{$self->{par}}; |
2229 | for @{$self->{par}}; |
… | |
… | |
2286 | |
2237 | |
2287 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2238 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2288 | glClearColor 0, 0, 0, 0; |
2239 | glClearColor 0, 0, 0, 0; |
2289 | glClear GL_COLOR_BUFFER_BIT; |
2240 | glClear GL_COLOR_BUFFER_BIT; |
2290 | |
2241 | |
2291 | glEnable GL_BLEND; |
|
|
2292 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2293 | glEnable GL_TEXTURE_2D; |
2242 | glEnable GL_TEXTURE_2D; |
2294 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2243 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2295 | |
2244 | |
2296 | my $top = int $self->{children}[1]{range}[0]; |
2245 | my $top = int $self->{children}[1]{range}[0]; |
2297 | |
2246 | |
… | |
… | |
2306 | |
2255 | |
2307 | for my $par (@{$self->{par}}) { |
2256 | for my $par (@{$self->{par}}) { |
2308 | my $h = $par->[0]; |
2257 | my $h = $par->[0]; |
2309 | |
2258 | |
2310 | if ($y0 < $y + $h && $y < $y1) { |
2259 | if ($y0 < $y + $h && $y < $y1) { |
|
|
2260 | $layout->set_foreground (@{ $par->[1] }); |
2311 | $layout->set_text ($par->[2]); |
2261 | $layout->set_markup ($par->[2]); |
2312 | |
2262 | |
2313 | glColor @{ $par->[1] }; |
|
|
2314 | my ($W, $H) = $layout->size; |
2263 | my ($W, $H) = $layout->size; |
2315 | CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); |
2264 | CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); |
2316 | } |
2265 | } |
2317 | |
2266 | |
2318 | $y += $h; |
2267 | $y += $h; |
2319 | } |
2268 | } |
2320 | |
2269 | |
2321 | glDisable GL_TEXTURE_2D; |
2270 | glDisable GL_TEXTURE_2D; |
2322 | glDisable GL_BLEND; |
|
|
2323 | }; |
2271 | }; |
2324 | }); |
2272 | }); |
2325 | } |
2273 | } |
2326 | |
2274 | |
2327 | sub _draw { |
2275 | sub _draw { |
2328 | my ($self) = @_; |
2276 | my ($self) = @_; |
2329 | |
2277 | |
2330 | glEnable GL_BLEND; |
|
|
2331 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2332 | glEnable GL_TEXTURE_2D; |
2278 | glEnable GL_TEXTURE_2D; |
2333 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2279 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2334 | glColor 1, 1, 1, 1; |
2280 | glColor 1, 1, 1, 1; |
2335 | $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2281 | $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2336 | glDisable GL_TEXTURE_2D; |
2282 | glDisable GL_TEXTURE_2D; |
2337 | glDisable GL_BLEND; |
|
|
2338 | |
2283 | |
2339 | $self->{children}[1]->draw; |
2284 | $self->{children}[1]->draw; |
2340 | |
2285 | |
2341 | } |
2286 | } |
2342 | |
2287 | |
… | |
… | |
2436 | @_, |
2381 | @_, |
2437 | can_events => 0, |
2382 | can_events => 0, |
2438 | ) |
2383 | ) |
2439 | } |
2384 | } |
2440 | |
2385 | |
2441 | sub set_markup { |
2386 | sub set_tooltip_from { |
2442 | my ($self, $text) = @_; |
2387 | my ($self, $widget) = @_; |
2443 | |
2388 | |
2444 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
2389 | $self->add (new CFClient::UI::Label |
2445 | $self->{label}->set_markup ($text); |
2390 | markup => $widget->{tooltip}, |
2446 | $self->add ($self->{label}); |
2391 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
|
|
2392 | fontsize => 0.8, |
|
|
2393 | fg => [0, 0, 0, 1], |
|
|
2394 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
|
|
2395 | ); |
2447 | } |
2396 | } |
2448 | |
2397 | |
2449 | sub size_request { |
2398 | sub size_request { |
2450 | my ($self) = @_; |
2399 | my ($self) = @_; |
2451 | |
|
|
2452 | $self->child->set_max_size ($::WIDTH * 0.3); |
|
|
2453 | |
2400 | |
2454 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2401 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2455 | |
2402 | |
2456 | ($w + 4, $h + 4) |
2403 | ($w + 4, $h + 4) |
2457 | } |
2404 | } |
… | |
… | |
2463 | } |
2410 | } |
2464 | |
2411 | |
2465 | sub _draw { |
2412 | sub _draw { |
2466 | my ($self) = @_; |
2413 | my ($self) = @_; |
2467 | |
2414 | |
2468 | glPushMatrix; |
|
|
2469 | glTranslate 0.375, 0.375; |
2415 | glTranslate 0.375, 0.375; |
2470 | |
2416 | |
2471 | my ($w, $h) = @$self{qw(w h)}; |
2417 | my ($w, $h) = @$self{qw(w h)}; |
2472 | |
2418 | |
2473 | glColor 1, 0.8, 0.4; |
2419 | glColor 1, 0.8, 0.4; |
… | |
… | |
2484 | glVertex 0 , $h; |
2430 | glVertex 0 , $h; |
2485 | glVertex $w, $h; |
2431 | glVertex $w, $h; |
2486 | glVertex $w, 0; |
2432 | glVertex $w, 0; |
2487 | glEnd; |
2433 | glEnd; |
2488 | |
2434 | |
2489 | glPopMatrix; |
2435 | glTranslate 2 - 0.375, 2 - 0.375; |
2490 | |
|
|
2491 | glTranslate 2, 2; |
|
|
2492 | $self->SUPER::_draw; |
2436 | $self->SUPER::_draw; |
2493 | } |
2437 | } |
2494 | |
2438 | |
2495 | ############################################################################# |
2439 | ############################################################################# |
2496 | |
2440 | |
… | |
… | |
2519 | return unless $::CONN;#d# manage and cache textures differently |
2463 | return unless $::CONN;#d# manage and cache textures differently |
2520 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2464 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2521 | |
2465 | |
2522 | # TODO animation |
2466 | # TODO animation |
2523 | if ($tex) { |
2467 | if ($tex) { |
2524 | glEnable GL_BLEND; |
|
|
2525 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2526 | glEnable GL_TEXTURE_2D; |
2468 | glEnable GL_TEXTURE_2D; |
2527 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2469 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2528 | glColor 1, 1, 1, 1; |
2470 | glColor 1, 1, 1, 1; |
2529 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
2471 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2530 | glDisable GL_TEXTURE_2D; |
2472 | glDisable GL_TEXTURE_2D; |
2531 | glDisable GL_BLEND; |
|
|
2532 | } |
2473 | } |
2533 | } |
2474 | } |
2534 | |
2475 | |
2535 | ############################################################################# |
2476 | ############################################################################# |
2536 | |
2477 | |
… | |
… | |
2541 | sub new { |
2482 | sub new { |
2542 | my $class = shift; |
2483 | my $class = shift; |
2543 | |
2484 | |
2544 | my %args = @_; |
2485 | my %args = @_; |
2545 | |
2486 | |
2546 | my $item = $args{item}; |
2487 | my $item = delete $args{item}; |
2547 | |
2488 | |
2548 | my $desc = $item->{nrof} < 2 |
2489 | my $desc = $item->{nrof} < 2 |
2549 | ? $item->{name} |
2490 | ? $item->{name} |
2550 | : "$item->{nrof} $item->{name_pl}"; |
2491 | : "$item->{nrof} $item->{name_pl}"; |
2551 | |
2492 | |
… | |
… | |
2580 | |
2521 | |
2581 | 1 |
2522 | 1 |
2582 | }, |
2523 | }, |
2583 | %args |
2524 | %args |
2584 | ); |
2525 | ); |
|
|
2526 | |
2585 | $self->add(new CFClient::UI::Face |
2527 | $self->add (new CFClient::UI::Face |
2586 | can_events => 0, |
2528 | can_events => 0, |
2587 | face => $item->{face}, |
2529 | face => $item->{face}, |
2588 | anim => $item->{anim}, |
2530 | anim => $item->{anim}, |
2589 | animspeed => $item->{animspeed}); |
2531 | animspeed => $item->{animspeed}, |
|
|
2532 | ); |
|
|
2533 | |
2590 | $self->add(new CFClient::UI::Label |
2534 | $self->add (new CFClient::UI::Label |
2591 | can_events => 0, |
2535 | can_events => 0, |
2592 | text => $desc); |
2536 | text => $desc, |
|
|
2537 | ); |
2593 | |
2538 | |
2594 | $self |
2539 | $self |
2595 | } |
2540 | } |
2596 | |
2541 | |
2597 | ############################################################################# |
2542 | ############################################################################# |
… | |
… | |
2615 | my ($self, $items) = @_; |
2560 | my ($self, $items) = @_; |
2616 | |
2561 | |
2617 | $self->{scrolled}->clear; |
2562 | $self->{scrolled}->clear; |
2618 | return unless $items; |
2563 | return unless $items; |
2619 | |
2564 | |
2620 | my @items = sort { $a->{type} <=> $b->{type} } @$items; |
2565 | my @items = sort { |
|
|
2566 | ($a->{type} <=> $b->{type}) |
|
|
2567 | or ($a->{name} cmp $b->{name}) |
|
|
2568 | } @$items; |
2621 | |
2569 | |
2622 | $self->{real_items} = \@items; |
2570 | $self->{real_items} = \@items; |
2623 | |
2571 | |
2624 | for my $item (@items) { |
2572 | for my $item (@items) { |
2625 | my $desc = $item->{nrof} < 2 |
2573 | my $desc = $item->{nrof} < 2 |
2626 | ? $item->{name} |
2574 | ? $item->{name} |
2627 | : "$item->{nrof} $item->{name_pl}"; |
2575 | : "$item->{nrof} $item->{name_pl}"; |
2628 | |
2576 | |
2629 | $self->{scrolled}->add (new CFClient::UI::InventoryItem item => $item); |
2577 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
2630 | } |
2578 | } |
|
|
2579 | |
|
|
2580 | $self->{scrolled}->add (@items); |
2631 | |
2581 | |
2632 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2582 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2633 | } |
2583 | } |
2634 | |
2584 | |
2635 | sub size_request { |
2585 | sub size_request { |
… | |
… | |
2709 | } |
2659 | } |
2710 | } |
2660 | } |
2711 | |
2661 | |
2712 | ############################################################################# |
2662 | ############################################################################# |
2713 | |
2663 | |
|
|
2664 | package CFClient::UI::Statusbox; |
|
|
2665 | |
|
|
2666 | our @ISA = CFClient::UI::VBox::; |
|
|
2667 | |
|
|
2668 | sub reorder { |
|
|
2669 | my ($self) = @_; |
|
|
2670 | my $NOW = time; |
|
|
2671 | |
|
|
2672 | while (my ($k, $v) = each %{ $self->{item} }) { |
|
|
2673 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
|
|
2674 | } |
|
|
2675 | |
|
|
2676 | my @widgets; |
|
|
2677 | |
|
|
2678 | my @items = sort { |
|
|
2679 | $a->{pri} <=> $b->{pri} |
|
|
2680 | or $b->{id} <=> $a->{id} |
|
|
2681 | } values %{ $self->{item} }; |
|
|
2682 | |
|
|
2683 | my $count = 10 + 1; |
|
|
2684 | for my $item (@items) { |
|
|
2685 | last unless --$count; |
|
|
2686 | |
|
|
2687 | push @widgets, $item->{label} ||= do { |
|
|
2688 | # TODO: doesn't handle markup well (read as: at all) |
|
|
2689 | my $short = $item->{count} > 1 |
|
|
2690 | ? "<b>$item->{count} ×</b> $item->{text}" |
|
|
2691 | : $item->{text}; |
|
|
2692 | |
|
|
2693 | for ($short) { |
|
|
2694 | s/^\s+//; |
|
|
2695 | s/\012.*/…/s; |
|
|
2696 | my $len = int 40 / $item->{fontsize}; |
|
|
2697 | substr $_, $len, length, "…" if $len < length; |
|
|
2698 | } |
|
|
2699 | |
|
|
2700 | new CFClient::UI::Label |
|
|
2701 | markup => $short, |
|
|
2702 | tooltip => $item->{tooltip}, |
|
|
2703 | tooltip_font => $::FONT_PROP, |
|
|
2704 | tooltip_width => 0.67, |
|
|
2705 | fontsize => $item->{fontsize}, |
|
|
2706 | color => $item->{color}, |
|
|
2707 | can_events => 1, |
|
|
2708 | can_hover => 1 |
|
|
2709 | }; |
|
|
2710 | } |
|
|
2711 | |
|
|
2712 | $self->clear; |
|
|
2713 | $self->SUPER::add (reverse @widgets); |
|
|
2714 | } |
|
|
2715 | |
|
|
2716 | sub add { |
|
|
2717 | my ($self, $text, %arg) = @_; |
|
|
2718 | |
|
|
2719 | $text =~ s/^\s+//; |
|
|
2720 | $text =~ s/\s+$//; |
|
|
2721 | |
|
|
2722 | my $timeout = time + ((delete $arg{timeout}) || 60); |
|
|
2723 | |
|
|
2724 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
|
|
2725 | |
|
|
2726 | if (my $item = $self->{item}{$group}) { |
|
|
2727 | if ($item->{text} eq $text) { |
|
|
2728 | $item->{count}++; |
|
|
2729 | } else { |
|
|
2730 | $item->{count} = 1; |
|
|
2731 | $item->{text} = $item->{tooltip} = $text; |
|
|
2732 | } |
|
|
2733 | $item->{id} = ++$self->{id}; |
|
|
2734 | $item->{timeout} = $timeout; |
|
|
2735 | delete $item->{label}; |
|
|
2736 | } else { |
|
|
2737 | $self->{item}{$group} = { |
|
|
2738 | id => ++$self->{id}, |
|
|
2739 | text => $text, |
|
|
2740 | timeout => $timeout, |
|
|
2741 | tooltip => $text, |
|
|
2742 | fontsize => 0.8, |
|
|
2743 | color => [0.8, 0.8, 0.8, 0.8], |
|
|
2744 | pri => 0, |
|
|
2745 | count => 1, |
|
|
2746 | %arg, |
|
|
2747 | }; |
|
|
2748 | } |
|
|
2749 | |
|
|
2750 | $self->reorder; |
|
|
2751 | } |
|
|
2752 | |
|
|
2753 | ############################################################################# |
|
|
2754 | |
2714 | package CFClient::UI::Root; |
2755 | package CFClient::UI::Root; |
2715 | |
2756 | |
2716 | our @ISA = CFClient::UI::Container::; |
2757 | our @ISA = CFClient::UI::Container::; |
2717 | |
2758 | |
2718 | use CFClient::OpenGL; |
2759 | use CFClient::OpenGL; |
2719 | |
2760 | |
|
|
2761 | sub new { |
|
|
2762 | my $class = shift; |
|
|
2763 | |
|
|
2764 | $class->SUPER::new ( |
|
|
2765 | @_, |
|
|
2766 | ) |
|
|
2767 | } |
|
|
2768 | |
|
|
2769 | sub configure { |
|
|
2770 | my ($self, $x, $y, $w, $h) = @_; |
|
|
2771 | |
|
|
2772 | $self->{w} = $w; |
|
|
2773 | $self->{h} = $h; |
|
|
2774 | } |
|
|
2775 | |
2720 | sub check_size { |
2776 | sub check_size { |
2721 | my ($self) = @_; |
2777 | my ($self) = @_; |
2722 | |
2778 | |
2723 | $self->configure (0, 0, $self->{w}, $self->{h}); |
2779 | $self->size_allocate ($self->{w}, $self->{h}) |
|
|
2780 | if $self->{w}; |
2724 | } |
2781 | } |
2725 | |
2782 | |
2726 | sub size_request { |
2783 | sub size_request { |
2727 | my ($self) = @_; |
2784 | my ($self) = @_; |
2728 | |
2785 | |
… | |
… | |
2730 | } |
2787 | } |
2731 | |
2788 | |
2732 | sub size_allocate { |
2789 | sub size_allocate { |
2733 | my ($self, $w, $h) = @_; |
2790 | my ($self, $w, $h) = @_; |
2734 | |
2791 | |
2735 | my $old_w = $self->{old_w}; |
2792 | my $old_w = $self->{old_w}; $self->{old_w} = $w; |
2736 | my $old_h = $self->{old_h}; |
2793 | my $old_h = $self->{old_h}; $self->{old_h} = $h; |
2737 | |
2794 | |
2738 | if ($old_w && $old_h) { |
2795 | CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h |
2739 | for my $child ($self->children) { |
2796 | if $old_w && $old_h && ($old_w != $w || $old_h != $h); |
2740 | $child->{x} = int 0.5 + $child->{x} * $w / $old_w; |
|
|
2741 | $child->{w} = int 0.5 + $child->{w} * $w / $old_w; |
|
|
2742 | $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w}; |
|
|
2743 | $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w}; |
|
|
2744 | $child->{y} = int 0.5 + $child->{y} * $h / $old_h; |
|
|
2745 | $child->{h} = int 0.5 + $child->{h} * $h / $old_h; |
|
|
2746 | $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; |
|
|
2747 | $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h}; |
|
|
2748 | } |
|
|
2749 | } |
|
|
2750 | |
|
|
2751 | $self->{old_w} = $w; |
|
|
2752 | $self->{old_h} = $h; |
|
|
2753 | } |
|
|
2754 | |
|
|
2755 | sub configure { |
|
|
2756 | my ($self, $x, $y, $w, $h) = @_; |
|
|
2757 | |
|
|
2758 | $self->SUPER::configure ($x, $y, $w, $h); |
|
|
2759 | |
2797 | |
2760 | for my $child ($self->children) { |
2798 | for my $child ($self->children) { |
2761 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2799 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2762 | |
2800 | |
2763 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2801 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2764 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2802 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2765 | $child->configure ($X, $Y, $W, $H); |
2803 | $child->configure ($X, $Y, $W, $H); |
2766 | } |
2804 | } |
2767 | } |
2805 | } |
2768 | |
2806 | |
2769 | sub _topleft { |
2807 | sub coord2local { |
2770 | my ($self, $x, $y) = @_; |
2808 | my ($self, $x, $y) = @_; |
2771 | |
2809 | |
2772 | ($x, $y) |
2810 | ($x, $y) |
2773 | } |
2811 | } |
2774 | |
2812 | |
|
|
2813 | sub coord2global { |
|
|
2814 | my ($self, $x, $y) = @_; |
|
|
2815 | |
|
|
2816 | ($x, $y) |
|
|
2817 | } |
|
|
2818 | |
2775 | sub update { |
2819 | sub update { |
2776 | my ($self) = @_; |
2820 | my ($self) = @_; |
2777 | |
2821 | |
2778 | $self->check_size; |
2822 | $self->check_size; |
2779 | ::refresh (); |
2823 | $::WANT_REFRESH++; |
2780 | } |
2824 | } |
2781 | |
2825 | |
2782 | sub add { |
2826 | sub add { |
2783 | my ($self, $child) = @_; |
2827 | my ($self, @children) = @_; |
2784 | |
2828 | |
|
|
2829 | for my $child (@children) { |
|
|
2830 | $child->{toplevel} = 1; |
|
|
2831 | |
2785 | # integerize window positions |
2832 | # integerise window positions |
2786 | $child->{x} = int $child->{x}; |
2833 | $child->{x} = int $child->{x}; |
2787 | $child->{y} = int $child->{y}; |
2834 | $child->{y} = int $child->{y}; |
|
|
2835 | } |
2788 | |
2836 | |
2789 | $self->SUPER::add ($child); |
2837 | $self->SUPER::add (@children); |
2790 | } |
2838 | } |
2791 | |
2839 | |
2792 | sub on_refresh { |
2840 | sub on_refresh { |
2793 | my ($self, $id, $cb) = @_; |
2841 | my ($self, $id, $cb) = @_; |
2794 | |
2842 | |
2795 | $self->{refresh_hook}{$id} = $cb; |
2843 | $self->{refresh_hook}{$id} = $cb; |
2796 | } |
2844 | } |
2797 | |
2845 | |
|
|
2846 | sub on_post_alloc { |
|
|
2847 | my ($self, $id, $cb) = @_; |
|
|
2848 | |
|
|
2849 | $self->{post_alloc_hook}{$id} = $cb; |
|
|
2850 | } |
|
|
2851 | |
2798 | sub draw { |
2852 | sub draw { |
2799 | my ($self) = @_; |
2853 | my ($self) = @_; |
2800 | |
2854 | |
2801 | while (my $rcb = delete $self->{refresh_hook}) { |
2855 | while ($self->{refresh_hook}) { |
2802 | $_->() for values %$rcb; |
2856 | $_->() |
|
|
2857 | for values %{delete $self->{refresh_hook}}; |
|
|
2858 | } |
|
|
2859 | |
|
|
2860 | if ($self->{check_size}) { |
|
|
2861 | my @queue = ([], []); |
|
|
2862 | |
|
|
2863 | for (;;) { |
|
|
2864 | if ($self->{check_size}) { |
|
|
2865 | # heuristic: check containers last |
|
|
2866 | push @{ $queue[ ! ! $_->isa ("CFClient::UI::Container") ] }, $_ |
|
|
2867 | for values %{delete $self->{check_size}} |
|
|
2868 | } |
|
|
2869 | |
|
|
2870 | my $widget = (pop @{ $queue[0] }) || (pop @{ $queue[1] }) || last; |
|
|
2871 | |
|
|
2872 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
|
|
2873 | ? @$widget{qw(user_w user_h)} |
|
|
2874 | : $widget->size_request; |
|
|
2875 | |
|
|
2876 | if (delete $widget->{force_alloc} |
|
|
2877 | or $w != $widget->{req_w} or $h != $widget->{req_h}) { |
|
|
2878 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
|
|
2879 | |
|
|
2880 | $widget->{req_w} = $w; |
|
|
2881 | $widget->{req_h} = $h; |
|
|
2882 | |
|
|
2883 | $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; |
|
|
2884 | |
|
|
2885 | $widget->{parent}->check_size |
|
|
2886 | if $widget->{parent}; |
|
|
2887 | } |
|
|
2888 | } |
|
|
2889 | } |
|
|
2890 | |
|
|
2891 | while ($self->{size_alloc}) { |
|
|
2892 | for (values %{delete $self->{size_alloc}}) { |
|
|
2893 | my ($widget, $w, $h) = @$_; |
|
|
2894 | |
|
|
2895 | $w = 0 if $w < 0; |
|
|
2896 | $h = 0 if $h < 0; |
|
|
2897 | |
|
|
2898 | $widget->{w} = $w; |
|
|
2899 | $widget->{h} = $h; |
|
|
2900 | $widget->size_allocate ($w, $h); |
|
|
2901 | $widget->emit (size_allocate => $w, $h); |
|
|
2902 | } |
|
|
2903 | } |
|
|
2904 | |
|
|
2905 | while ($self->{post_alloc_hook}) { |
|
|
2906 | $_->() |
|
|
2907 | for values %{delete $self->{post_alloc_hook}}; |
2803 | } |
2908 | } |
2804 | |
2909 | |
2805 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
2910 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
2806 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
2911 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
2807 | glClear GL_COLOR_BUFFER_BIT; |
2912 | glClear GL_COLOR_BUFFER_BIT; |