… | |
… | |
11 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
11 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
12 | |
12 | |
13 | our $ROOT; |
13 | our $ROOT; |
14 | our $TOOLTIP; |
14 | our $TOOLTIP; |
15 | our $BUTTON_STATE; |
15 | our $BUTTON_STATE; |
|
|
16 | |
|
|
17 | our %WIDGET; # all widgets, weak-referenced |
16 | |
18 | |
17 | sub check_tooltip { |
19 | sub check_tooltip { |
18 | if (!$GRAB) { |
20 | if (!$GRAB) { |
19 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
21 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
20 | if (length $widget->{tooltip}) { |
22 | if (length $widget->{tooltip}) { |
… | |
… | |
24 | |
26 | |
25 | my $tip = $widget->{tooltip}; |
27 | my $tip = $widget->{tooltip}; |
26 | |
28 | |
27 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
29 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
28 | |
30 | |
29 | $TOOLTIP->set_markup ($widget->{tooltip}, $widget->{tooltip_font}); |
31 | $TOOLTIP->set_tooltip_from ($widget); |
30 | |
|
|
31 | $TOOLTIP->show; |
32 | $TOOLTIP->show; |
32 | |
33 | |
33 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
34 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
34 | |
35 | |
35 | if ($x + $TOOLTIP->{w} > $::WIDTH) { |
|
|
36 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); |
36 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0) |
37 | } |
37 | if $x + $TOOLTIP->{w} > $::WIDTH; |
38 | |
38 | |
39 | $TOOLTIP->move ($x, $y); |
39 | $TOOLTIP->move ($x, $y); |
|
|
40 | $TOOLTIP->check_size; |
|
|
41 | $TOOLTIP->update; |
40 | } |
42 | } |
41 | |
43 | |
42 | return; |
44 | return; |
43 | } |
45 | } |
44 | } |
46 | } |
… | |
… | |
132 | for (@$vals) { |
134 | for (@$vals) { |
133 | my $i = int $_ + $rem; |
135 | my $i = int $_ + $rem; |
134 | $rem += $_ - $i; |
136 | $rem += $_ - $i; |
135 | $_ = $i; |
137 | $_ = $i; |
136 | } |
138 | } |
|
|
139 | } |
|
|
140 | |
|
|
141 | sub full_refresh { |
|
|
142 | # make a copy, otherwise for complains about freed values. |
|
|
143 | my @widgets = values %WIDGET; |
|
|
144 | |
|
|
145 | $_->update |
|
|
146 | for @widgets; |
|
|
147 | } |
|
|
148 | |
|
|
149 | sub reconfigure_widgets { |
|
|
150 | # make a copy, otherwise C<for> complains about freed values. |
|
|
151 | my @widgets = values %WIDGET; |
|
|
152 | |
|
|
153 | $_->reconfigure |
|
|
154 | for @widgets; |
|
|
155 | } |
|
|
156 | |
|
|
157 | # call when resolution changes etc. |
|
|
158 | sub rescale_widgets { |
|
|
159 | my ($sx, $sy) = @_; |
|
|
160 | |
|
|
161 | for my $widget (values %WIDGET) { |
|
|
162 | if ($widget->{is_toplevel}) { |
|
|
163 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
|
|
164 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
|
|
165 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
|
|
166 | $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; |
|
|
167 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
|
|
168 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
|
|
169 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
|
|
170 | $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; |
|
|
171 | } |
|
|
172 | } |
|
|
173 | |
|
|
174 | reconfigure_widgets; |
137 | } |
175 | } |
138 | |
176 | |
139 | ############################################################################# |
177 | ############################################################################# |
140 | |
178 | |
141 | package CFClient::UI::Base; |
179 | package CFClient::UI::Base; |
… | |
… | |
159 | if (/^connect_(.*)$/) { |
197 | if (/^connect_(.*)$/) { |
160 | $self->connect ($1 => delete $self->{$_}); |
198 | $self->connect ($1 => delete $self->{$_}); |
161 | } |
199 | } |
162 | } |
200 | } |
163 | |
201 | |
|
|
202 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
|
|
203 | |
164 | $self |
204 | $self |
165 | } |
205 | } |
166 | |
206 | |
167 | sub destroy { |
207 | sub destroy { |
168 | my ($self) = @_; |
208 | my ($self) = @_; |
… | |
… | |
171 | %$self = (); |
211 | %$self = (); |
172 | } |
212 | } |
173 | |
213 | |
174 | sub show { |
214 | sub show { |
175 | my ($self) = @_; |
215 | my ($self) = @_; |
176 | |
|
|
177 | return if $self->{parent}; |
216 | return if $self->{parent}; |
178 | |
217 | |
179 | $CFClient::UI::ROOT->add ($self); |
218 | $CFClient::UI::ROOT->add ($self); |
|
|
219 | } |
|
|
220 | |
|
|
221 | sub show_centered { |
|
|
222 | my ($self) = @_; |
|
|
223 | return if $self->{parent}; |
|
|
224 | |
|
|
225 | $self->show; |
|
|
226 | |
|
|
227 | $CFClient::UI::ROOT->on_post_alloc ( |
|
|
228 | "centered $self" => sub { |
|
|
229 | $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); |
|
|
230 | }, |
|
|
231 | ); |
180 | } |
232 | } |
181 | |
233 | |
182 | sub hide { |
234 | sub hide { |
183 | my ($self) = @_; |
235 | my ($self) = @_; |
184 | |
236 | |
… | |
… | |
241 | |
293 | |
242 | sub size_allocate { |
294 | sub size_allocate { |
243 | # nothing to be done |
295 | # nothing to be done |
244 | } |
296 | } |
245 | |
297 | |
|
|
298 | sub reconfigure { |
|
|
299 | my ($self) = @_; |
|
|
300 | |
|
|
301 | $self->check_size (1); |
|
|
302 | $self->update; |
|
|
303 | } |
|
|
304 | |
246 | sub children { |
305 | sub children { |
247 | } |
|
|
248 | |
|
|
249 | # call when resolution changes etc. |
|
|
250 | sub reconfigure { |
|
|
251 | my ($self) = @_; |
|
|
252 | |
|
|
253 | $_->reconfigure |
|
|
254 | for $self->children; |
|
|
255 | |
|
|
256 | $self->check_size; |
|
|
257 | $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $self->{w}, $self->{h}]; |
|
|
258 | $self->update; |
|
|
259 | } |
306 | } |
260 | |
307 | |
261 | sub set_max_size { |
308 | sub set_max_size { |
262 | my ($self, $w, $h) = @_; |
309 | my ($self, $w, $h) = @_; |
263 | |
310 | |
264 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
311 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
265 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
312 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
|
|
313 | } |
|
|
314 | |
|
|
315 | sub set_tooltip { |
|
|
316 | my ($self, $tooltip) = @_; |
|
|
317 | |
|
|
318 | $self->{tooltip} = $tooltip; |
|
|
319 | |
|
|
320 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
|
|
321 | delete $CFClient::UI::TOOLTIP->{owner}; |
|
|
322 | CFClient::UI::check_tooltip; |
|
|
323 | } |
266 | } |
324 | } |
267 | |
325 | |
268 | # translate global coordinates to local coordinate system |
326 | # translate global coordinates to local coordinate system |
269 | sub coord2local { |
327 | sub coord2local { |
270 | my ($self, $x, $y) = @_; |
328 | my ($self, $x, $y) = @_; |
… | |
… | |
356 | glVertex $self->{w}, 0; |
414 | glVertex $self->{w}, 0; |
357 | glVertex $self->{w}, $self->{h}; |
415 | glVertex $self->{w}, $self->{h}; |
358 | glVertex 0 , $self->{h}; |
416 | glVertex 0 , $self->{h}; |
359 | glEnd; |
417 | glEnd; |
360 | glPopMatrix; |
418 | glPopMatrix; |
361 | CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
419 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
362 | } |
420 | } |
363 | } |
421 | } |
364 | |
422 | |
365 | sub _draw { |
423 | sub _draw { |
366 | my ($self) = @_; |
424 | my ($self) = @_; |
… | |
… | |
383 | sub set_parent { |
441 | sub set_parent { |
384 | my ($self, $parent) = @_; |
442 | my ($self, $parent) = @_; |
385 | |
443 | |
386 | Scalar::Util::weaken ($self->{parent} = $parent); |
444 | Scalar::Util::weaken ($self->{parent} = $parent); |
387 | |
445 | |
|
|
446 | # TODO: req_w _does_change after ->reconfigure |
388 | $self->check_size |
447 | $self->check_size |
389 | unless exists $self->{req_w}; |
448 | unless exists $self->{req_w}; |
|
|
449 | |
|
|
450 | $self->show; |
390 | } |
451 | } |
391 | |
452 | |
392 | sub check_size { |
453 | sub check_size { |
393 | my ($self) = @_; |
454 | my ($self, $forced) = @_; |
394 | |
455 | |
|
|
456 | $self->{force_alloc} = 1 if $forced; |
395 | $CFClient::UI::ROOT->{check_size}{$self} = $self; |
457 | $CFClient::UI::ROOT->{check_size}{$self} = $self; |
396 | } |
458 | } |
397 | |
459 | |
398 | sub update { |
460 | sub update { |
399 | my ($self) = @_; |
461 | my ($self) = @_; |
… | |
… | |
415 | } |
477 | } |
416 | |
478 | |
417 | sub DESTROY { |
479 | sub DESTROY { |
418 | my ($self) = @_; |
480 | my ($self) = @_; |
419 | |
481 | |
|
|
482 | delete $WIDGET{$self+0}; |
420 | #$self->deactivate; |
483 | #$self->deactivate; |
421 | } |
484 | } |
422 | |
485 | |
423 | ############################################################################# |
486 | ############################################################################# |
424 | |
487 | |
… | |
… | |
433 | my $class = shift; |
496 | my $class = shift; |
434 | |
497 | |
435 | # range [value, low, high, page] |
498 | # range [value, low, high, page] |
436 | |
499 | |
437 | $class->SUPER::new ( |
500 | $class->SUPER::new ( |
438 | bg => [0, 0, 0, 0.2], |
501 | #bg => [0, 0, 0, 0.2], |
439 | active_bg => [1, 1, 1, 0.5], |
502 | #active_bg => [1, 1, 1, 0.5], |
440 | @_ |
503 | @_ |
441 | ) |
504 | ) |
442 | } |
505 | } |
443 | |
506 | |
444 | sub _draw { |
507 | sub _draw { |
445 | my ($self) = @_; |
508 | my ($self) = @_; |
446 | |
509 | |
|
|
510 | my $color = $FOCUS == $self && $self->{active_bg} |
|
|
511 | ? $self->{active_bg} |
|
|
512 | : $self->{bg}; |
|
|
513 | |
|
|
514 | if ($color && (@$color < 4 || $color->[3])) { |
447 | my ($w, $h) = @$self{qw(w h)}; |
515 | my ($w, $h) = @$self{qw(w h)}; |
448 | |
516 | |
449 | glEnable GL_BLEND; |
517 | glEnable GL_BLEND; |
450 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
518 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
451 | glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; |
519 | glColor @$color; |
452 | |
520 | |
453 | glBegin GL_QUADS; |
521 | glBegin GL_QUADS; |
454 | glVertex 0 , 0; |
522 | glVertex 0 , 0; |
455 | glVertex 0 , $h; |
523 | glVertex 0 , $h; |
456 | glVertex $w, $h; |
524 | glVertex $w, $h; |
457 | glVertex $w, 0; |
525 | glVertex $w, 0; |
458 | glEnd; |
526 | glEnd; |
459 | |
527 | |
460 | glDisable GL_BLEND; |
528 | glDisable GL_BLEND; |
|
|
529 | } |
461 | } |
530 | } |
462 | |
531 | |
463 | ############################################################################# |
532 | ############################################################################# |
464 | |
533 | |
465 | package CFClient::UI::Empty; |
534 | package CFClient::UI::Empty; |
… | |
… | |
509 | $self->{children} = [ |
578 | $self->{children} = [ |
510 | sort { $a->{z} <=> $b->{z} } |
579 | sort { $a->{z} <=> $b->{z} } |
511 | @{$self->{children}}, @widgets |
580 | @{$self->{children}}, @widgets |
512 | ]; |
581 | ]; |
513 | |
582 | |
514 | $self->check_size; |
583 | $self->check_size (1); |
515 | $self->update; |
584 | $self->update; |
516 | } |
585 | } |
517 | |
586 | |
518 | sub children { |
587 | sub children { |
519 | @{ $_[0]{children} } |
588 | @{ $_[0]{children} } |
… | |
… | |
626 | } |
695 | } |
627 | |
696 | |
628 | sub update { |
697 | sub update { |
629 | my ($self) = @_; |
698 | my ($self) = @_; |
630 | |
699 | |
631 | $ROOT->on_refresh ($self => sub { $self->render_child }); |
700 | $ROOT->on_post_alloc ($self => sub { $self->render_child }); |
632 | $self->SUPER::update; |
701 | $self->SUPER::update; |
633 | } |
702 | } |
634 | |
703 | |
635 | sub size_allocate { |
704 | sub size_allocate { |
636 | my ($self, $w, $h) = @_; |
705 | my ($self, $w, $h) = @_; |
… | |
… | |
649 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
718 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
650 | glClearColor 0, 0, 0, 0; |
719 | glClearColor 0, 0, 0, 0; |
651 | glClear GL_COLOR_BUFFER_BIT; |
720 | glClear GL_COLOR_BUFFER_BIT; |
652 | |
721 | |
653 | $self->_render; |
722 | $self->_render; |
654 | # glColorMask 1, 1, 1, 0; |
|
|
655 | # glEnable GL_BLEND; |
|
|
656 | # glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
|
|
657 | # glRasterPos 0, 0; |
|
|
658 | # glCopyPixels 0, 0, $self->{w}, $self->{h}; |
|
|
659 | # glDisable GL_BLEND; |
|
|
660 | # glColorMask 1, 1, 1, 1; |
|
|
661 | }; |
723 | }; |
662 | } |
724 | } |
663 | |
725 | |
664 | sub _draw { |
726 | sub _draw { |
665 | my ($self) = @_; |
727 | my ($self) = @_; |
… | |
… | |
669 | my $tex = $self->{texture} |
731 | my $tex = $self->{texture} |
670 | or return; |
732 | or return; |
671 | |
733 | |
672 | glEnable GL_TEXTURE_2D; |
734 | glEnable GL_TEXTURE_2D; |
673 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
735 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
674 | glColor 0, 0, 0, 1; |
736 | glColor 1, 1, 1, 1; |
675 | |
737 | |
676 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
738 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
677 | |
739 | |
678 | glDisable GL_TEXTURE_2D; |
740 | glDisable GL_TEXTURE_2D; |
679 | } |
741 | } |
… | |
… | |
686 | |
748 | |
687 | sub size_request { |
749 | sub size_request { |
688 | my ($self) = @_; |
750 | my ($self) = @_; |
689 | |
751 | |
690 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
752 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
691 | $self->child->configure (0, 0, @$self{qw(child_w child_h)}); |
|
|
692 | |
753 | |
693 | @$self{qw(child_w child_h)} |
754 | @$self{qw(child_w child_h)} |
694 | } |
755 | } |
695 | |
756 | |
696 | sub size_allocate { |
757 | sub size_allocate { |
697 | my ($self, $w, $h) = @_; |
758 | my ($self, $w, $h) = @_; |
698 | |
759 | |
|
|
760 | my ($cw, $ch) = @$self{qw(child_w child_h)}; |
|
|
761 | # $w = $self->{w}; |
|
|
762 | $self->child->configure (0, 0, $cw, $ch); |
699 | $self->update; |
763 | $self->update; |
700 | } |
764 | } |
701 | |
765 | |
702 | sub set_offset { |
766 | sub set_offset { |
703 | my ($self, $x, $y) = @_; |
767 | my ($self, $x, $y) = @_; |
… | |
… | |
757 | |
821 | |
758 | my $slider = new CFClient::UI::Slider |
822 | my $slider = new CFClient::UI::Slider |
759 | vertical => 1, |
823 | vertical => 1, |
760 | range => [0, 0, 1, 0.01], # HACK fix |
824 | range => [0, 0, 1, 0.01], # HACK fix |
761 | connect_changed => sub { |
825 | connect_changed => sub { |
762 | $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); |
826 | $self->{vp}->set_offset (0, $_[1]); |
763 | }, |
827 | }, |
764 | ; |
828 | ; |
765 | |
829 | |
766 | $self = $class->SUPER::new ( |
830 | $self = $class->SUPER::new ( |
767 | vp => (new CFClient::UI::ViewPort), |
831 | vp => (new CFClient::UI::ViewPort expand => 1), |
768 | slider => $slider, |
832 | slider => $slider, |
769 | @_, |
833 | @_, |
770 | ); |
834 | ); |
771 | |
835 | |
772 | $self->{vp}->add ($self->{scrolled}); |
836 | $self->{vp}->add ($self->{scrolled}); |
… | |
… | |
774 | $self->add ($self->{slider}); |
838 | $self->add ($self->{slider}); |
775 | |
839 | |
776 | $self |
840 | $self |
777 | } |
841 | } |
778 | |
842 | |
|
|
843 | sub size_allocate { |
|
|
844 | my ($self, $w, $h) = @_; |
|
|
845 | |
|
|
846 | $self->SUPER::size_allocate ($w, $h); |
|
|
847 | |
|
|
848 | my $child = $self->{vp}->child; |
|
|
849 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
|
|
850 | } |
|
|
851 | |
779 | #TODO# update range on size_allocate depeneing on child |
852 | #TODO# update range on size_allocate depending on child |
780 | # update viewport offset on scroll |
853 | # update viewport offset on scroll |
781 | |
854 | |
782 | ############################################################################# |
855 | ############################################################################# |
783 | |
856 | |
784 | package CFClient::UI::Frame; |
857 | package CFClient::UI::Frame; |
… | |
… | |
788 | use CFClient::OpenGL; |
861 | use CFClient::OpenGL; |
789 | |
862 | |
790 | sub new { |
863 | sub new { |
791 | my $class = shift; |
864 | my $class = shift; |
792 | |
865 | |
793 | my $self = $class->SUPER::new ( |
866 | $class->SUPER::new ( |
794 | bg => [1, 1, 1, 1], |
867 | bg => undef, |
795 | border_bg => [1, 1, 1, 1], |
|
|
796 | border => 0.8, |
|
|
797 | @_ |
868 | @_, |
798 | ); |
869 | ) |
799 | |
|
|
800 | $self |
|
|
801 | } |
870 | } |
802 | |
871 | |
803 | sub _draw { |
872 | sub _draw { |
804 | my ($self) = @_; |
873 | my ($self) = @_; |
805 | |
874 | |
806 | my ($w, $h) = ($self->{w}, $self->{h}); |
875 | if ($self->{bg}) { |
|
|
876 | my ($w, $h) = @$self{qw(w h)}; |
807 | |
877 | |
808 | glEnable GL_BLEND; |
878 | glEnable GL_BLEND; |
809 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
879 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
810 | glEnable GL_TEXTURE_2D; |
880 | glColor @{ $self->{bg} }; |
811 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
812 | |
881 | |
813 | # glBegin GL_QUADS; |
882 | glBegin GL_QUADS; |
814 | # glColor 0, 0, 0, 0; |
|
|
815 | # glVertex 0 , 0; |
883 | glVertex 0 , 0; |
816 | # glVertex 0 , $h; |
884 | glVertex 0 , $h; |
817 | # glVertex $w, $h; |
885 | glVertex $w, $h; |
818 | # glVertex $w, 0; |
886 | glVertex $w, 0; |
819 | # glEnd; |
887 | glEnd; |
820 | |
888 | |
821 | |
|
|
822 | $self->child->draw; |
|
|
823 | glDisable GL_BLEND; |
889 | glDisable GL_BLEND; |
824 | glDisable GL_TEXTURE_2D; |
890 | } |
|
|
891 | |
|
|
892 | $self->SUPER::_draw; |
825 | } |
893 | } |
826 | |
894 | |
827 | ############################################################################# |
895 | ############################################################################# |
828 | |
896 | |
829 | package CFClient::UI::FancyFrame; |
897 | package CFClient::UI::FancyFrame; |
… | |
… | |
840 | my $class = shift; |
908 | my $class = shift; |
841 | |
909 | |
842 | # TODO: user_x, user_y, overwrite moveto? |
910 | # TODO: user_x, user_y, overwrite moveto? |
843 | |
911 | |
844 | my $self = $class->SUPER::new ( |
912 | my $self = $class->SUPER::new ( |
845 | bg => [1, 1, 1, 1], |
913 | bg => [1, 1, 1, 1], |
846 | border_bg => [1, 1, 1, 1], |
914 | border_bg => [1, 1, 1, 1], |
847 | border => 0.6, |
915 | border => 0.6, |
|
|
916 | is_toplevel => 1, |
848 | can_events => 1, |
917 | can_events => 1, |
849 | @_ |
918 | @_ |
850 | ); |
919 | ); |
851 | |
920 | |
852 | $self->{title} &&= new CFClient::UI::Label |
921 | $self->{title} &&= new CFClient::UI::Label |
853 | align => 0, |
922 | align => 0, |
… | |
… | |
877 | my ($self, $w, $h) = @_; |
946 | my ($self, $w, $h) = @_; |
878 | |
947 | |
879 | $h -= List::Util::max 0, $self->border * 2; |
948 | $h -= List::Util::max 0, $self->border * 2; |
880 | $w -= List::Util::max 0, $self->border * 2; |
949 | $w -= List::Util::max 0, $self->border * 2; |
881 | |
950 | |
882 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
951 | $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) |
883 | if $self->{title}; |
952 | if $self->{title}; |
884 | |
953 | |
885 | $self->child->configure ($self->border, $self->border, $w, $h); |
954 | $self->child->configure ($self->border, $self->border, $w, $h); |
886 | } |
955 | } |
887 | |
956 | |
… | |
… | |
945 | my ($self) = @_; |
1014 | my ($self) = @_; |
946 | |
1015 | |
947 | my ($w, $h ) = ($self->{w}, $self->{h}); |
1016 | my ($w, $h ) = ($self->{w}, $self->{h}); |
948 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
1017 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
949 | |
1018 | |
950 | glEnable GL_BLEND; |
|
|
951 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
952 | glEnable GL_TEXTURE_2D; |
1019 | glEnable GL_TEXTURE_2D; |
953 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1020 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
954 | |
1021 | |
955 | my $border = $self->border; |
1022 | my $border = $self->border; |
956 | |
1023 | |
957 | glColor @{ $self->{border_bg} }; |
1024 | glColor @{ $self->{border_bg} }; |
958 | $tex[1]->draw_quad (0, 0, $w, $border); |
1025 | $tex[1]->draw_quad_alpha (0, 0, $w, $border); |
959 | $tex[3]->draw_quad (0, $border, $border, $ch); |
1026 | $tex[3]->draw_quad_alpha (0, $border, $border, $ch); |
960 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
1027 | $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
961 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
1028 | $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border); |
962 | |
1029 | |
963 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1030 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
964 | my $bg = $tex[0]; |
1031 | my $bg = $tex[0]; |
965 | |
1032 | |
966 | # TODO: repeat texture not scale |
1033 | # TODO: repeat texture not scale |
… | |
… | |
970 | glColor @{ $self->{bg} }; |
1037 | glColor @{ $self->{bg} }; |
971 | |
1038 | |
972 | $bg->{s} = $rep_x; |
1039 | $bg->{s} = $rep_x; |
973 | $bg->{t} = $rep_y; |
1040 | $bg->{t} = $rep_y; |
974 | $bg->{wrap_mode} = 1; |
1041 | $bg->{wrap_mode} = 1; |
975 | $bg->draw_quad ($border, $border, $cw, $ch); |
1042 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
|
|
1043 | } |
976 | |
1044 | |
977 | glDisable GL_TEXTURE_2D; |
1045 | glDisable GL_TEXTURE_2D; |
978 | glDisable GL_BLEND; |
|
|
979 | } |
|
|
980 | |
1046 | |
981 | $self->{title}->draw if $self->{title}; |
1047 | $self->{title}->draw if $self->{title}; |
982 | |
1048 | |
983 | $self->child->draw; |
1049 | $self->child->draw; |
984 | } |
1050 | } |
… | |
… | |
1251 | |
1317 | |
1252 | ############################################################################# |
1318 | ############################################################################# |
1253 | |
1319 | |
1254 | package CFClient::UI::Label; |
1320 | package CFClient::UI::Label; |
1255 | |
1321 | |
1256 | our @ISA = CFClient::UI::Base::; |
1322 | our @ISA = CFClient::UI::DrawBG::; |
1257 | |
1323 | |
1258 | use CFClient::OpenGL; |
1324 | use CFClient::OpenGL; |
1259 | |
1325 | |
1260 | sub new { |
1326 | sub new { |
1261 | my ($class, %arg) = @_; |
1327 | my ($class, %arg) = @_; |
1262 | |
1328 | |
1263 | my $self = $class->SUPER::new ( |
1329 | my $self = $class->SUPER::new ( |
1264 | fg => [1, 1, 1], |
1330 | fg => [1, 1, 1], |
|
|
1331 | #bg => none |
|
|
1332 | #active_bg => none |
1265 | #font => default_font |
1333 | #font => default_font |
1266 | #text => initial text |
1334 | #text => initial text |
1267 | #markup => initial narkup |
1335 | #markup => initial narkup |
|
|
1336 | #max_w => maximum pixel width |
|
|
1337 | ellipsise => 3, # end |
1268 | layout => (new CFClient::Layout), |
1338 | layout => (new CFClient::Layout), |
1269 | fontsize => 1, |
1339 | fontsize => 1, |
1270 | align => -1, |
1340 | align => -1, |
1271 | valign => -1, |
1341 | valign => -1, |
1272 | padding => 2, |
1342 | padding => 2, |
… | |
… | |
1287 | } |
1357 | } |
1288 | |
1358 | |
1289 | $self |
1359 | $self |
1290 | } |
1360 | } |
1291 | |
1361 | |
1292 | sub escape { |
1362 | sub escape($) { |
1293 | local $_ = $_[1]; |
1363 | local $_ = $_[0]; |
1294 | |
1364 | |
1295 | s/&/&/g; |
1365 | s/&/&/g; |
1296 | s/>/>/g; |
1366 | s/>/>/g; |
1297 | s/</</g; |
1367 | s/</</g; |
1298 | |
1368 | |
1299 | $_[1] |
1369 | $_ |
1300 | } |
1370 | } |
1301 | |
1371 | |
1302 | sub update { |
1372 | sub update { |
1303 | my ($self) = @_; |
1373 | my ($self) = @_; |
1304 | |
1374 | |
… | |
… | |
1337 | sub size_request { |
1407 | sub size_request { |
1338 | my ($self) = @_; |
1408 | my ($self) = @_; |
1339 | |
1409 | |
1340 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1410 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1341 | $self->{layout}->set_width ($self->{max_w} || -1); |
1411 | $self->{layout}->set_width ($self->{max_w} || -1); |
|
|
1412 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
|
|
1413 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1342 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1414 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1343 | |
1415 | |
1344 | my ($w, $h) = $self->{layout}->size; |
1416 | my ($w, $h) = $self->{layout}->size; |
1345 | |
1417 | |
1346 | if (exists $self->{template}) { |
1418 | if (exists $self->{template}) { |
… | |
… | |
1376 | } |
1448 | } |
1377 | |
1449 | |
1378 | sub _draw { |
1450 | sub _draw { |
1379 | my ($self) = @_; |
1451 | my ($self) = @_; |
1380 | |
1452 | |
|
|
1453 | $self->SUPER::_draw; # draw background, if applicable |
|
|
1454 | |
1381 | my $tex = $self->{texture} ||= do { |
1455 | my $tex = $self->{texture} ||= do { |
1382 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1456 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1383 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1457 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1384 | $self->{layout}->set_width ($self->{w}); |
1458 | $self->{layout}->set_width ($self->{w}); |
|
|
1459 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
|
|
1460 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1385 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1461 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1386 | |
1462 | |
1387 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1463 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1388 | |
1464 | |
1389 | $self->{ox} = int $self->{align} < 0 ? $self->{padding} |
1465 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding} |
1390 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1466 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1391 | : ($self->{w} - $tex->{w}) * 0.5; |
1467 | : ($self->{w} - $tex->{w}) * 0.5); |
1392 | |
1468 | |
1393 | $self->{oy} = int $self->{valign} < 0 ? $self->{padding} |
1469 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding} |
1394 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1470 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1395 | : ($self->{h} - $tex->{h}) * 0.5; |
1471 | : ($self->{h} - $tex->{h}) * 0.5); |
1396 | |
1472 | |
1397 | $tex |
1473 | $tex |
1398 | }; |
1474 | }; |
1399 | |
1475 | |
1400 | glEnable GL_TEXTURE_2D; |
1476 | glEnable GL_TEXTURE_2D; |
… | |
… | |
1428 | active_fg => [0, 0, 0], |
1504 | active_fg => [0, 0, 0], |
1429 | can_hover => 1, |
1505 | can_hover => 1, |
1430 | can_focus => 1, |
1506 | can_focus => 1, |
1431 | valign => 0, |
1507 | valign => 0, |
1432 | can_events => 1, |
1508 | can_events => 1, |
|
|
1509 | #text => ... |
1433 | @_ |
1510 | @_ |
1434 | ) |
1511 | ) |
1435 | } |
1512 | } |
1436 | |
1513 | |
1437 | sub _set_text { |
1514 | sub _set_text { |
… | |
… | |
1455 | sub set_text { |
1532 | sub set_text { |
1456 | my ($self, $text) = @_; |
1533 | my ($self, $text) = @_; |
1457 | |
1534 | |
1458 | $self->{cursor} = length $text; |
1535 | $self->{cursor} = length $text; |
1459 | $self->_set_text ($text); |
1536 | $self->_set_text ($text); |
|
|
1537 | $self->update; |
1460 | $self->check_size; |
1538 | $self->check_size; |
1461 | $self->update; |
|
|
1462 | } |
1539 | } |
1463 | |
1540 | |
1464 | sub get_text { |
1541 | sub get_text { |
1465 | $_[0]{text} |
1542 | $_[0]{text} |
1466 | } |
1543 | } |
… | |
… | |
1486 | my $sym = $ev->{sym}; |
1563 | my $sym = $ev->{sym}; |
1487 | my $uni = $ev->{unicode}; |
1564 | my $uni = $ev->{unicode}; |
1488 | |
1565 | |
1489 | my $text = $self->get_text; |
1566 | my $text = $self->get_text; |
1490 | |
1567 | |
1491 | if ($sym == 8) { |
1568 | if ($uni == 8) { |
1492 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1569 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1493 | } elsif ($sym == 127) { |
1570 | } elsif ($uni == 127) { |
1494 | substr $text, $self->{cursor}, 1, ""; |
1571 | substr $text, $self->{cursor}, 1, ""; |
1495 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1572 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1496 | --$self->{cursor} if $self->{cursor}; |
1573 | --$self->{cursor} if $self->{cursor}; |
1497 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1574 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1498 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1575 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1499 | } elsif ($sym == CFClient::SDLK_HOME) { |
1576 | } elsif ($sym == CFClient::SDLK_HOME) { |
1500 | $self->{cursor} = 0; |
1577 | $self->{cursor} = 0; |
1501 | } elsif ($sym == CFClient::SDLK_END) { |
1578 | } elsif ($sym == CFClient::SDLK_END) { |
1502 | $self->{cursor} = length $text; |
1579 | $self->{cursor} = length $text; |
1503 | } elsif ($sym == 27) { |
1580 | } elsif ($uni == 27) { |
1504 | $self->emit ('escape'); |
1581 | $self->emit ('escape'); |
1505 | } elsif ($uni) { |
1582 | } elsif ($uni) { |
1506 | substr $text, $self->{cursor}++, 0, chr $uni; |
1583 | substr $text, $self->{cursor}++, 0, chr $uni; |
1507 | } |
1584 | } |
1508 | |
1585 | |
1509 | $self->_set_text ($text); |
1586 | $self->_set_text ($text); |
1510 | $self->update; |
1587 | $self->update; |
|
|
1588 | $self->check_size; |
1511 | } |
1589 | } |
1512 | |
1590 | |
1513 | sub focus_in { |
1591 | sub focus_in { |
1514 | my ($self) = @_; |
1592 | my ($self) = @_; |
1515 | |
1593 | |
… | |
… | |
1644 | my $class = shift; |
1722 | my $class = shift; |
1645 | |
1723 | |
1646 | $class->SUPER::new ( |
1724 | $class->SUPER::new ( |
1647 | padding => 4, |
1725 | padding => 4, |
1648 | fg => [1, 1, 1], |
1726 | fg => [1, 1, 1], |
1649 | bg => [1, 1, 1, 0.2], |
|
|
1650 | active_fg => [0, 0, 1], |
1727 | active_fg => [0, 0, 1], |
1651 | can_hover => 1, |
1728 | can_hover => 1, |
1652 | align => 0, |
1729 | align => 0, |
1653 | valign => 0, |
1730 | valign => 0, |
1654 | can_events => 1, |
1731 | can_events => 1, |
… | |
… | |
1702 | |
1779 | |
1703 | $class->SUPER::new ( |
1780 | $class->SUPER::new ( |
1704 | padding => 2, |
1781 | padding => 2, |
1705 | fg => [1, 1, 1], |
1782 | fg => [1, 1, 1], |
1706 | active_fg => [1, 1, 0], |
1783 | active_fg => [1, 1, 0], |
|
|
1784 | bg => [0, 0, 0, 0.2], |
|
|
1785 | active_bg => [1, 1, 1, 0.5], |
1707 | state => 0, |
1786 | state => 0, |
1708 | can_hover => 1, |
1787 | can_hover => 1, |
1709 | @_ |
1788 | @_ |
1710 | ) |
1789 | ) |
1711 | } |
1790 | } |
… | |
… | |
1735 | |
1814 | |
1736 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1815 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1737 | |
1816 | |
1738 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1817 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1739 | |
1818 | |
|
|
1819 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
1820 | |
1740 | glEnable GL_TEXTURE_2D; |
1821 | glEnable GL_TEXTURE_2D; |
1741 | |
|
|
1742 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
1743 | |
|
|
1744 | $tex->draw_quad_alpha (0, 0, $s, $s); |
1822 | $tex->draw_quad_alpha (0, 0, $s, $s); |
1745 | |
|
|
1746 | glDisable GL_TEXTURE_2D; |
1823 | glDisable GL_TEXTURE_2D; |
1747 | } |
1824 | } |
1748 | |
1825 | |
1749 | ############################################################################# |
1826 | ############################################################################# |
1750 | |
1827 | |
… | |
… | |
1997 | qw(s1_slider.png s1_slider_bg.png); |
2074 | qw(s1_slider.png s1_slider_bg.png); |
1998 | |
2075 | |
1999 | sub new { |
2076 | sub new { |
2000 | my $class = shift; |
2077 | my $class = shift; |
2001 | |
2078 | |
2002 | # range [value, low, high, page] |
2079 | # range [value, low, high, page, unit] |
2003 | |
2080 | |
2004 | # TODO: 0-width page |
2081 | # TODO: 0-width page |
2005 | # TODO: req_w/h are wrong with vertical |
2082 | # TODO: req_w/h are wrong with vertical |
2006 | # TODO: calculations are off |
2083 | # TODO: calculations are off |
2007 | my $self = $class->SUPER::new ( |
2084 | my $self = $class->SUPER::new ( |
2008 | fg => [1, 1, 1], |
2085 | fg => [1, 1, 1], |
2009 | active_fg => [0, 0, 0], |
2086 | active_fg => [0, 0, 0], |
|
|
2087 | bg => [0, 0, 0, 0.2], |
|
|
2088 | active_bg => [1, 1, 1, 0.5], |
2010 | range => [0, 0, 100, 10], |
2089 | range => [0, 0, 100, 10, 0], |
2011 | req_w => $::WIDTH / 80, |
2090 | req_w => $::WIDTH / 80, |
2012 | req_h => $::WIDTH / 80, |
2091 | req_h => $::WIDTH / 80, |
2013 | vertical => 0, |
2092 | vertical => 0, |
2014 | can_hover => 1, |
2093 | can_hover => 1, |
2015 | inner_pad => 5, |
2094 | inner_pad => 0.02, |
2016 | @_ |
2095 | @_ |
2017 | ); |
2096 | ); |
2018 | |
2097 | |
|
|
2098 | $self->set_value ($self->{range}[0]); |
|
|
2099 | $self->update; |
|
|
2100 | |
2019 | $self |
2101 | $self |
|
|
2102 | } |
|
|
2103 | |
|
|
2104 | sub set_range { |
|
|
2105 | my ($self, $range) = @_; |
|
|
2106 | |
|
|
2107 | $self->{range} = $range; |
|
|
2108 | |
|
|
2109 | $self->update; |
|
|
2110 | } |
|
|
2111 | |
|
|
2112 | sub set_value { |
|
|
2113 | my ($self, $value) = @_; |
|
|
2114 | |
|
|
2115 | my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; |
|
|
2116 | |
|
|
2117 | $hi = $lo + 1 if $hi <= $lo; |
|
|
2118 | |
|
|
2119 | $page = $hi - $lo if $page > $hi - $lo; |
|
|
2120 | |
|
|
2121 | $value = $lo if $value < $lo; |
|
|
2122 | $value = $hi - $page if $value > $hi - $page; |
|
|
2123 | |
|
|
2124 | $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit |
|
|
2125 | if $unit; |
|
|
2126 | |
|
|
2127 | @{$self->{range}} = ($value, $lo, $hi, $page, $unit); |
|
|
2128 | |
|
|
2129 | if ($value != $old_value) { |
|
|
2130 | $self->emit (changed => $value); |
|
|
2131 | $self->update; |
|
|
2132 | } |
2020 | } |
2133 | } |
2021 | |
2134 | |
2022 | sub size_request { |
2135 | sub size_request { |
2023 | my ($self) = @_; |
2136 | my ($self) = @_; |
2024 | |
2137 | |
… | |
… | |
2030 | |
2143 | |
2031 | sub button_down { |
2144 | sub button_down { |
2032 | my ($self, $ev, $x, $y) = @_; |
2145 | my ($self, $ev, $x, $y) = @_; |
2033 | |
2146 | |
2034 | $self->SUPER::button_down ($ev, $x, $y); |
2147 | $self->SUPER::button_down ($ev, $x, $y); |
|
|
2148 | |
|
|
2149 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
|
|
2150 | |
2035 | $self->mouse_motion ($ev, $x, $y); |
2151 | $self->mouse_motion ($ev, $x, $y); |
2036 | } |
2152 | } |
2037 | |
2153 | |
2038 | sub mouse_motion { |
2154 | sub mouse_motion { |
2039 | my ($self, $ev, $x, $y) = @_; |
2155 | my ($self, $ev, $x, $y) = @_; |
2040 | |
2156 | |
2041 | if ($GRAB == $self) { |
2157 | if ($GRAB == $self) { |
|
|
2158 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
|
|
2159 | |
|
|
2160 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
|
|
2161 | |
|
|
2162 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
|
|
2163 | |
|
|
2164 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
|
|
2165 | } |
|
|
2166 | } |
|
|
2167 | |
|
|
2168 | sub update { |
|
|
2169 | my ($self) = @_; |
|
|
2170 | |
|
|
2171 | $CFClient::UI::ROOT->on_post_alloc ($self => sub { |
|
|
2172 | $self->set_value ($self->{range}[0]); |
|
|
2173 | |
2042 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2174 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
|
|
2175 | my $range = ($hi - $page - $lo) || 1e-100; |
2043 | |
2176 | |
2044 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
2177 | my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1; |
2045 | |
2178 | |
2046 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
2179 | $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; |
2047 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
2180 | $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; |
2048 | |
2181 | |
2049 | $x -= $inner_pad_px; # substract the padding |
2182 | $value = ($value - $lo) / $range; |
2050 | $x = $x * ($hi - $lo) / $inner_w + $lo; |
2183 | $value = $value * $self->{scale} + $self->{offset}; |
2051 | $x = $lo if $x < $lo; |
|
|
2052 | $x = $hi - $page if $x > $hi - $page; |
|
|
2053 | $self->{range}[0] = $x; |
|
|
2054 | |
2184 | |
2055 | $self->emit (changed => $x); |
2185 | $self->{knob_x} = $value - $knob_w * 0.5; |
2056 | $self->update; |
2186 | $self->{knob_w} = $knob_w; |
2057 | } |
2187 | }); |
2058 | } |
|
|
2059 | |
2188 | |
2060 | # the inner_* stuff is for generating a padding for the slider handle, |
2189 | $self->SUPER::update; |
2061 | # so that the handle doesn't leave the texture. This calculation isn't 100% |
|
|
2062 | # correct propably, but it does the job for now |
|
|
2063 | sub _calc_inner_pad_px { |
|
|
2064 | my ($self, $w) = @_; |
|
|
2065 | ($w / 100) * $self->{inner_pad} # % to pixels |
|
|
2066 | } |
2190 | } |
2067 | |
2191 | |
2068 | sub _draw { |
2192 | sub _draw { |
2069 | my ($self) = @_; |
2193 | my ($self) = @_; |
2070 | |
2194 | |
2071 | $self->SUPER::_draw (); |
2195 | $self->SUPER::_draw (); |
2072 | |
2196 | |
2073 | my ($w, $h) = @$self{qw(w h)}; |
2197 | glScale $self->{w}, $self->{h}; |
2074 | |
2198 | |
2075 | if ($self->{vertical}) { |
2199 | if ($self->{vertical}) { |
2076 | # draw a vertical slider like a rotated horizontal slider |
2200 | # draw a vertical slider like a rotated horizontal slider |
2077 | |
2201 | |
|
|
2202 | glTranslate 1, 0, 0; |
2078 | glRotate 90, 0, 0, 1; |
2203 | glRotate 90, 0, 0, 1; |
2079 | glTranslate 0, -$self->{w}, 0; |
|
|
2080 | |
|
|
2081 | ($w, $h) = ($h, $w); |
|
|
2082 | } |
2204 | } |
2083 | |
2205 | |
2084 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2206 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2085 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2207 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2086 | |
2208 | |
2087 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
|
|
2088 | |
|
|
2089 | $hi = $value + 1 if $lo == $hi; |
|
|
2090 | |
|
|
2091 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
|
|
2092 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
|
|
2093 | |
|
|
2094 | $page = int $page * $inner_w / ($hi - $lo); |
|
|
2095 | $value = int +($value - $lo) * $inner_w / ($hi - $lo); |
|
|
2096 | |
|
|
2097 | $w -= $page; |
|
|
2098 | $page &= ~1; |
|
|
2099 | glTranslate $page * 0.5, 0, 0; |
|
|
2100 | $page ||= 2; |
|
|
2101 | |
|
|
2102 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
|
|
2103 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
|
|
2104 | |
|
|
2105 | glEnable GL_TEXTURE_2D; |
2209 | glEnable GL_TEXTURE_2D; |
2106 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2210 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2107 | |
2211 | |
2108 | # draw background |
2212 | # draw background |
2109 | $tex[1]->draw_quad_alpha (0, 0, $w, $h); |
2213 | $tex[1]->draw_quad_alpha (0, 0, 1, 1); |
2110 | |
2214 | |
2111 | # draw handle |
2215 | # draw handle |
2112 | $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h); |
2216 | $tex[0]->draw_quad_alpha ($self->{knob_x}, 0, $self->{knob_w}, 1); |
2113 | |
2217 | |
2114 | glDisable GL_TEXTURE_2D; |
2218 | glDisable GL_TEXTURE_2D; |
2115 | } |
2219 | } |
|
|
2220 | |
|
|
2221 | ############################################################################# |
|
|
2222 | |
|
|
2223 | package CFClient::UI::ValSlider; |
|
|
2224 | |
|
|
2225 | our @ISA = CFClient::UI::HBox::; |
|
|
2226 | |
|
|
2227 | sub new { |
|
|
2228 | my ($class, %arg) = @_; |
|
|
2229 | |
|
|
2230 | my $range = delete $arg{range}; |
|
|
2231 | |
|
|
2232 | my $self = $class->SUPER::new ( |
|
|
2233 | slider => (new CFClient::UI::Slider expand => 1, range => $range), |
|
|
2234 | entry => (new CFClient::UI::Label text => "", template => delete $arg{template}), |
|
|
2235 | to_value => sub { shift }, |
|
|
2236 | from_value => sub { shift }, |
|
|
2237 | %arg, |
|
|
2238 | ); |
|
|
2239 | |
|
|
2240 | $self->{slider}->connect (changed => sub { |
|
|
2241 | my ($self, $value) = @_; |
|
|
2242 | $self->{parent}{entry}->set_text ($self->{parent}{to_value}->($value)); |
|
|
2243 | $self->{parent}->emit (changed => $value); |
|
|
2244 | }); |
|
|
2245 | |
|
|
2246 | # $self->{entry}->connect (changed => sub { |
|
|
2247 | # my ($self, $value) = @_; |
|
|
2248 | # $self->{parent}{slider}->set_value ($self->{parent}{from_value}->($value)); |
|
|
2249 | # $self->{parent}->emit (changed => $value); |
|
|
2250 | # }); |
|
|
2251 | |
|
|
2252 | $self->add ($self->{slider}, $self->{entry}); |
|
|
2253 | |
|
|
2254 | $self->{slider}->emit (changed => $self->{slider}{range}[0]); |
|
|
2255 | |
|
|
2256 | $self |
|
|
2257 | } |
|
|
2258 | |
|
|
2259 | sub set_range { shift->{slider}->set_range (@_) } |
|
|
2260 | sub set_value { shift->{slider}->set_value (@_) } |
2116 | |
2261 | |
2117 | ############################################################################# |
2262 | ############################################################################# |
2118 | |
2263 | |
2119 | package CFClient::UI::TextView; |
2264 | package CFClient::UI::TextView; |
2120 | |
2265 | |
… | |
… | |
2150 | |
2295 | |
2151 | $self->{fontsize} = $fontsize; |
2296 | $self->{fontsize} = $fontsize; |
2152 | $self->reflow; |
2297 | $self->reflow; |
2153 | } |
2298 | } |
2154 | |
2299 | |
2155 | sub text_height { |
|
|
2156 | my ($self, $text) = @_; |
|
|
2157 | |
|
|
2158 | my $layout = $self->{layout}; |
|
|
2159 | |
|
|
2160 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
2161 | $layout->set_width ($self->{children}[0]{w}); |
|
|
2162 | $layout->set_markup ($text); |
|
|
2163 | |
|
|
2164 | ($layout->size)[1] |
|
|
2165 | } |
|
|
2166 | |
|
|
2167 | sub reflow { |
|
|
2168 | my ($self) = @_; |
|
|
2169 | |
|
|
2170 | $self->{need_reflow}++; |
|
|
2171 | $self->update; |
|
|
2172 | } |
|
|
2173 | |
|
|
2174 | sub size_allocate { |
2300 | sub size_allocate { |
2175 | my ($self, $w, $h) = @_; |
2301 | my ($self, $w, $h) = @_; |
2176 | |
2302 | |
2177 | $self->SUPER::size_allocate ($w, $h); |
2303 | $self->SUPER::size_allocate ($w, $h); |
2178 | |
2304 | |
… | |
… | |
2181 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2307 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2182 | |
2308 | |
2183 | $self->reflow; |
2309 | $self->reflow; |
2184 | } |
2310 | } |
2185 | |
2311 | |
|
|
2312 | sub text_size { |
|
|
2313 | my ($self, $text, $indent) = @_; |
|
|
2314 | |
|
|
2315 | my $layout = $self->{layout}; |
|
|
2316 | |
|
|
2317 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
2318 | $layout->set_width ($self->{children}[0]{w} - $indent); |
|
|
2319 | $layout->set_markup ($text); |
|
|
2320 | |
|
|
2321 | $layout->size |
|
|
2322 | } |
|
|
2323 | |
|
|
2324 | sub reflow { |
|
|
2325 | my ($self) = @_; |
|
|
2326 | |
|
|
2327 | $self->{need_reflow}++; |
|
|
2328 | $self->update; |
|
|
2329 | } |
|
|
2330 | |
|
|
2331 | sub set_offset { |
|
|
2332 | my ($self, $offset) = @_; |
|
|
2333 | |
|
|
2334 | # todo: base offset on lines or so, not on pixels |
|
|
2335 | $self->{children}[1]->set_value ($offset); |
|
|
2336 | } |
|
|
2337 | |
|
|
2338 | sub clear { |
|
|
2339 | my ($self) = @_; |
|
|
2340 | |
|
|
2341 | $self->{par} = []; |
|
|
2342 | $self->{height} = 0; |
|
|
2343 | $self->{children}[1]->set_range ([0, 0, 0, 1, 1]); |
|
|
2344 | } |
|
|
2345 | |
2186 | sub add_paragraph { |
2346 | sub add_paragraph { |
2187 | my ($self, $color, $text) = @_; |
2347 | my ($self, $color, $text, $indent) = @_; |
2188 | |
2348 | |
2189 | #TODO: intelligently "reformat" paragraph |
2349 | for my $line (split /\n/, $text) { |
2190 | |
2350 | my ($w, $h) = $self->text_size ($line); |
2191 | my $height = $self->text_height ($text); |
|
|
2192 | |
|
|
2193 | $self->{height} += $height; |
2351 | $self->{height} += $h; |
|
|
2352 | push @{$self->{par}}, [$w + $indent, $h, $color, $indent, $line]; |
|
|
2353 | } |
2194 | |
2354 | |
2195 | push @{$self->{par}}, [$height, $color, $text]; |
|
|
2196 | |
|
|
2197 | $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; |
2355 | $self->{children}[1]->set_range ([$self->{height}, 0, $self->{height}, $self->{h}, 1]); |
2198 | $self->{children}[1]->update; |
|
|
2199 | } |
2356 | } |
2200 | |
2357 | |
2201 | sub update { |
2358 | sub update { |
2202 | my ($self) = @_; |
2359 | my ($self) = @_; |
2203 | |
2360 | |
… | |
… | |
2205 | |
2362 | |
2206 | return unless $self->{h} > 0; |
2363 | return unless $self->{h} > 0; |
2207 | |
2364 | |
2208 | delete $self->{texture}; |
2365 | delete $self->{texture}; |
2209 | |
2366 | |
2210 | $ROOT->on_refresh ($self, sub { |
2367 | $ROOT->on_post_alloc ($self, sub { |
|
|
2368 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
|
|
2369 | |
2211 | if (delete $self->{need_reflow}) { |
2370 | if (delete $self->{need_reflow}) { |
2212 | my $height = 0; |
2371 | my $height = 0; |
2213 | |
2372 | |
2214 | $height += $_->[0] = $self->text_height ($_->[2]) |
2373 | my $layout = $self->{layout}; |
|
|
2374 | |
|
|
2375 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
2376 | |
2215 | for @{$self->{par}}; |
2377 | for (@{$self->{par}}) { |
|
|
2378 | if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support |
|
|
2379 | $layout->set_width ($W - $_->[3]); |
|
|
2380 | $layout->set_markup ($_->[4]); |
|
|
2381 | my ($w, $h) = $layout->size; |
|
|
2382 | $_->[0] = $w + $_->[3]; |
|
|
2383 | $_->[1] = $h; |
|
|
2384 | } |
|
|
2385 | |
|
|
2386 | $height += $_->[1]; |
|
|
2387 | } |
2216 | |
2388 | |
2217 | $self->{height} = $height; |
2389 | $self->{height} = $height; |
2218 | |
2390 | |
2219 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
2391 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2220 | |
2392 | |
2221 | delete $self->{texture}; |
2393 | delete $self->{texture}; |
2222 | } |
2394 | } |
2223 | |
2395 | |
2224 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2396 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2225 | glClearColor 0, 0, 0, 0; |
2397 | glClearColor 0.5, 0.5, 0.5, 0; |
2226 | glClear GL_COLOR_BUFFER_BIT; |
2398 | glClear GL_COLOR_BUFFER_BIT; |
2227 | |
2399 | |
2228 | glEnable GL_TEXTURE_2D; |
|
|
2229 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2230 | |
|
|
2231 | my $top = int $self->{children}[1]{range}[0]; |
2400 | my $top = int $self->{children}[1]{range}[0]; |
2232 | |
2401 | |
2233 | my $y0 = $top; |
2402 | my $y0 = $top; |
2234 | my $y1 = $top + $self->{h}; |
2403 | my $y1 = $top + $H; |
2235 | |
2404 | |
2236 | my $y = 0; |
2405 | my $y = 0; |
2237 | |
2406 | |
2238 | my $layout = $self->{layout}; |
2407 | my $layout = $self->{layout}; |
2239 | |
2408 | |
2240 | $layout->set_font ($self->{font}) if $self->{font}; |
2409 | $layout->set_font ($self->{font}) if $self->{font}; |
2241 | |
2410 | |
|
|
2411 | glEnable GL_BLEND; |
|
|
2412 | #TODO# not correct in windows where rgba is forced off |
|
|
2413 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2414 | |
2242 | for my $par (@{$self->{par}}) { |
2415 | for my $par (@{$self->{par}}) { |
2243 | my $h = $par->[0]; |
2416 | my $h = $par->[1]; |
2244 | |
2417 | |
2245 | if ($y0 < $y + $h && $y < $y1) { |
2418 | if ($y0 < $y + $h && $y < $y1) { |
2246 | $layout->set_foreground (@{ $par->[1] }); |
2419 | $layout->set_foreground (@{ $par->[2] }); |
|
|
2420 | $layout->set_width ($W - $par->[3]); |
2247 | $layout->set_markup ($par->[2]); |
2421 | $layout->set_markup ($par->[4]); |
2248 | |
2422 | |
2249 | my ($W, $H) = $layout->size; |
2423 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
2250 | CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); |
2424 | |
|
|
2425 | glRasterPos $par->[3], $y - $y0; |
|
|
2426 | glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data; |
2251 | } |
2427 | } |
2252 | |
2428 | |
2253 | $y += $h; |
2429 | $y += $h; |
2254 | } |
2430 | } |
2255 | |
2431 | |
2256 | glDisable GL_TEXTURE_2D; |
2432 | glDisable GL_BLEND; |
2257 | }; |
2433 | }; |
2258 | }); |
2434 | }); |
2259 | } |
2435 | } |
2260 | |
2436 | |
2261 | sub _draw { |
2437 | sub _draw { |
2262 | my ($self) = @_; |
2438 | my ($self) = @_; |
2263 | |
2439 | |
2264 | glEnable GL_TEXTURE_2D; |
2440 | glEnable GL_TEXTURE_2D; |
2265 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2441 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2266 | glColor 1, 1, 1, 1; |
2442 | glColor 1, 1, 1, 1; |
2267 | $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2443 | $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2268 | glDisable GL_TEXTURE_2D; |
2444 | glDisable GL_TEXTURE_2D; |
2269 | |
2445 | |
2270 | $self->{children}[1]->draw; |
2446 | $self->{children}[1]->draw; |
2271 | |
2447 | |
2272 | } |
2448 | } |
… | |
… | |
2367 | @_, |
2543 | @_, |
2368 | can_events => 0, |
2544 | can_events => 0, |
2369 | ) |
2545 | ) |
2370 | } |
2546 | } |
2371 | |
2547 | |
2372 | sub set_markup { |
2548 | sub set_tooltip_from { |
2373 | my ($self, $text, $font) = @_; |
2549 | my ($self, $widget) = @_; |
2374 | |
2550 | |
2375 | $self->{label} = new CFClient::UI::Label |
2551 | $self->add (new CFClient::UI::Label |
|
|
2552 | markup => $widget->{tooltip}, |
|
|
2553 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2376 | fontsize => 0.8, |
2554 | fontsize => 0.8, |
2377 | fg => [0, 0, 0], |
2555 | fg => [0, 0, 0, 1], |
|
|
2556 | ellipsise => 0, |
2378 | font => ($font || $::FONT_PROP); |
2557 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
2379 | |
2558 | ); |
2380 | $self->{label}->set_max_size ($::WIDTH * 0.3); |
|
|
2381 | $self->{label}->set_markup ($text); |
|
|
2382 | $self->add ($self->{label}); |
|
|
2383 | } |
2559 | } |
2384 | |
2560 | |
2385 | sub size_request { |
2561 | sub size_request { |
2386 | my ($self) = @_; |
2562 | my ($self) = @_; |
2387 | |
2563 | |
… | |
… | |
2397 | } |
2573 | } |
2398 | |
2574 | |
2399 | sub _draw { |
2575 | sub _draw { |
2400 | my ($self) = @_; |
2576 | my ($self) = @_; |
2401 | |
2577 | |
2402 | glPushMatrix; |
|
|
2403 | glTranslate 0.375, 0.375; |
2578 | glTranslate 0.375, 0.375; |
2404 | |
2579 | |
2405 | my ($w, $h) = @$self{qw(w h)}; |
2580 | my ($w, $h) = @$self{qw(w h)}; |
2406 | |
2581 | |
2407 | glColor 1, 0.8, 0.4; |
2582 | glColor 1, 0.8, 0.4; |
… | |
… | |
2418 | glVertex 0 , $h; |
2593 | glVertex 0 , $h; |
2419 | glVertex $w, $h; |
2594 | glVertex $w, $h; |
2420 | glVertex $w, 0; |
2595 | glVertex $w, 0; |
2421 | glEnd; |
2596 | glEnd; |
2422 | |
2597 | |
2423 | glPopMatrix; |
2598 | glTranslate 2 - 0.375, 2 - 0.375; |
2424 | |
|
|
2425 | glTranslate 2, 2; |
|
|
2426 | $self->SUPER::_draw; |
2599 | $self->SUPER::_draw; |
2427 | } |
2600 | } |
2428 | |
2601 | |
2429 | ############################################################################# |
2602 | ############################################################################# |
2430 | |
2603 | |
… | |
… | |
2435 | use CFClient::OpenGL; |
2608 | use CFClient::OpenGL; |
2436 | |
2609 | |
2437 | sub new { |
2610 | sub new { |
2438 | my $class = shift; |
2611 | my $class = shift; |
2439 | |
2612 | |
2440 | $class->SUPER::new ( |
2613 | my $self = $class->SUPER::new ( |
2441 | aspect => 1, |
2614 | aspect => 1, |
2442 | @_, |
2615 | @_, |
2443 | ) |
2616 | ); |
|
|
2617 | |
|
|
2618 | if ($self->{anim} && $self->{animspeed}) { |
|
|
2619 | Scalar::Util::weaken (my $widget = $self); |
|
|
2620 | |
|
|
2621 | $self->{timer} = Event->timer ( |
|
|
2622 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
|
|
2623 | hard => 1, |
|
|
2624 | interval => $self->{animspeed}, |
|
|
2625 | cb => sub { |
|
|
2626 | ++$widget->{frame}; |
|
|
2627 | $widget->update; |
|
|
2628 | }, |
|
|
2629 | ); |
|
|
2630 | } |
|
|
2631 | |
|
|
2632 | $self |
2444 | } |
2633 | } |
2445 | |
2634 | |
2446 | sub size_request { |
2635 | sub size_request { |
2447 | (32, 8) |
2636 | (32, 8) |
2448 | } |
2637 | } |
2449 | |
2638 | |
|
|
2639 | sub update { |
|
|
2640 | my ($self) = @_; |
|
|
2641 | |
|
|
2642 | return unless $self->{visible}; |
|
|
2643 | |
|
|
2644 | $self->SUPER::update; |
|
|
2645 | } |
|
|
2646 | |
2450 | sub _draw { |
2647 | sub _draw { |
2451 | my ($self) = @_; |
2648 | my ($self) = @_; |
2452 | |
2649 | |
2453 | return unless $::CONN;#d# manage and cache textures differently |
2650 | return unless $::CONN; |
|
|
2651 | |
|
|
2652 | my $face; |
|
|
2653 | |
|
|
2654 | if ($self->{frame}) { |
|
|
2655 | my $anim = $::CONN->{anim}[$self->{anim}]; |
|
|
2656 | |
|
|
2657 | $face = $anim->[ $self->{frame} % @$anim ] |
|
|
2658 | if $anim && @$anim; |
|
|
2659 | } |
|
|
2660 | |
2454 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2661 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2455 | |
2662 | |
2456 | # TODO animation |
|
|
2457 | if ($tex) { |
2663 | if ($tex) { |
2458 | glEnable GL_TEXTURE_2D; |
2664 | glEnable GL_TEXTURE_2D; |
2459 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2665 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2460 | glColor 1, 1, 1, 1; |
2666 | glColor 1, 1, 1, 1; |
2461 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2667 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2462 | glDisable GL_TEXTURE_2D; |
2668 | glDisable GL_TEXTURE_2D; |
2463 | } |
2669 | } |
2464 | } |
2670 | } |
2465 | |
2671 | |
|
|
2672 | sub DESTROY { |
|
|
2673 | my ($self) = @_; |
|
|
2674 | |
|
|
2675 | $self->{timer}->cancel |
|
|
2676 | if $self->{timer}; |
|
|
2677 | |
|
|
2678 | $self->SUPER::DESTROY; |
|
|
2679 | } |
|
|
2680 | |
2466 | ############################################################################# |
2681 | ############################################################################# |
2467 | |
2682 | |
2468 | package CFClient::UI::InventoryItem; |
2683 | package CFClient::UI::InventoryItem; |
2469 | |
2684 | |
2470 | our @ISA = CFClient::UI::HBox::; |
2685 | our @ISA = CFClient::UI::HBox::; |
|
|
2686 | |
|
|
2687 | sub _item_to_desc { |
|
|
2688 | my ($item) = @_; |
|
|
2689 | |
|
|
2690 | my $desc = |
|
|
2691 | $item->{nrof} < 2 |
|
|
2692 | ? $item->{name} |
|
|
2693 | : "$item->{nrof} × $item->{name_pl}"; |
|
|
2694 | |
|
|
2695 | $item->{flags} & Crossfire::Protocol::F_OPEN |
|
|
2696 | and $desc .= " (open)"; |
|
|
2697 | $item->{flags} & Crossfire::Protocol::F_APPLIED |
|
|
2698 | and $desc .= " (applied)"; |
|
|
2699 | $item->{flags} & Crossfire::Protocol::F_UNPAID |
|
|
2700 | and $desc .= " (unpaid)"; |
|
|
2701 | $item->{flags} & Crossfire::Protocol::F_MAGIC |
|
|
2702 | and $desc .= " (magic)"; |
|
|
2703 | $item->{flags} & Crossfire::Protocol::F_CURSED |
|
|
2704 | and $desc .= " (cursed)"; |
|
|
2705 | $item->{flags} & Crossfire::Protocol::F_DAMNED |
|
|
2706 | and $desc .= " (damned)"; |
|
|
2707 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2708 | and $desc .= " *"; |
|
|
2709 | |
|
|
2710 | $desc |
|
|
2711 | } |
2471 | |
2712 | |
2472 | sub new { |
2713 | sub new { |
2473 | my $class = shift; |
2714 | my $class = shift; |
2474 | |
2715 | |
2475 | my %args = @_; |
2716 | my %args = @_; |
2476 | |
2717 | |
2477 | my $item = delete $args{item}; |
2718 | my $item = delete $args{item}; |
2478 | |
2719 | |
2479 | my $desc = $item->{nrof} < 2 |
2720 | my $desc = _item_to_desc ($item); |
2480 | ? $item->{name} |
|
|
2481 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2482 | |
|
|
2483 | |
2721 | |
2484 | my $self = $class->SUPER::new ( |
2722 | my $self = $class->SUPER::new ( |
2485 | can_hover => 1, |
2723 | can_hover => 1, |
2486 | can_events => 1, |
2724 | can_events => 1, |
2487 | tooltip => (CFClient::UI::Label->escape ($desc) |
2725 | tooltip => ((CFClient::UI::Label::escape $desc) |
2488 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2726 | . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"), |
2489 | connect_button_down => sub { |
2727 | connect_button_down => sub { |
2490 | my ($self, $ev, $x, $y) = @_; |
2728 | my ($self, $ev, $x, $y) = @_; |
2491 | |
2729 | |
2492 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2730 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
2731 | if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { |
|
|
2732 | my $targ = $::CONN->{player}{tag}; |
|
|
2733 | |
|
|
2734 | if ($item->{container} == $::CONN->{player}{tag}) { |
|
|
2735 | $targ = $main::OPENCONT; |
|
|
2736 | } |
|
|
2737 | |
|
|
2738 | $::CONN->send ("move $targ $item->{tag} 0"); |
2493 | if ($ev->{button} == 1) { |
2739 | } elsif ($ev->{button} == 1) { |
2494 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
2740 | $::CONN->send ("examine $item->{tag}"); |
2495 | } elsif ($ev->{button} == 2) { |
2741 | } elsif ($ev->{button} == 2) { |
2496 | $::CONN->send ("apply $item->{tag}"); |
2742 | $::CONN->send ("apply $item->{tag}"); |
2497 | } elsif ($ev->{button} == 3) { |
2743 | } elsif ($ev->{button} == 3) { |
2498 | CFClient::UI::Menu->new ( |
2744 | my @menu_items = ( |
2499 | items => [ |
|
|
2500 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2745 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2501 | [ |
|
|
2502 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
|
|
2503 | sub { $::CONN->send ("lock $item->{tag}") }, |
|
|
2504 | ], |
|
|
2505 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
2746 | ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }], |
2506 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
2747 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2748 | ( |
|
|
2749 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2750 | ? ( |
|
|
2751 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }], |
|
|
2752 | ) |
|
|
2753 | : ( |
|
|
2754 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }], |
2507 | ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }], |
2755 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
|
|
2756 | ) |
2508 | ], |
2757 | ), |
2509 | )->popup ($ev); |
2758 | ); |
|
|
2759 | |
|
|
2760 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2510 | } |
2761 | } |
2511 | |
2762 | |
2512 | 1 |
2763 | 1 |
2513 | }, |
2764 | }, |
2514 | %args |
2765 | %args |
2515 | ); |
2766 | ); |
|
|
2767 | |
2516 | |
2768 | |
2517 | $self->add (new CFClient::UI::Face |
2769 | $self->add (new CFClient::UI::Face |
2518 | can_events => 0, |
2770 | can_events => 0, |
2519 | face => $item->{face}, |
2771 | face => $item->{face}, |
2520 | anim => $item->{anim}, |
2772 | anim => $item->{anim}, |
2521 | animspeed => $item->{animspeed}, |
2773 | animspeed => $item->{animspeed}, |
2522 | ); |
2774 | ); |
2523 | |
2775 | |
2524 | $self->add (new CFClient::UI::Label |
2776 | $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0); |
2525 | can_events => 0, |
2777 | |
2526 | text => $desc, |
2778 | $self->{item} = $item; |
2527 | ); |
2779 | |
|
|
2780 | $self->update_item; |
2528 | |
2781 | |
2529 | $self |
2782 | $self |
|
|
2783 | } |
|
|
2784 | |
|
|
2785 | sub update_item { |
|
|
2786 | my ($self) = @_; |
|
|
2787 | |
|
|
2788 | my $desc = _item_to_desc ($self->{item}); |
|
|
2789 | |
|
|
2790 | $self->{name_lbl}->set_text ($desc); |
2530 | } |
2791 | } |
2531 | |
2792 | |
2532 | ############################################################################# |
2793 | ############################################################################# |
2533 | |
2794 | |
2534 | package CFClient::UI::Inventory; |
2795 | package CFClient::UI::Inventory; |
… | |
… | |
2537 | |
2798 | |
2538 | sub new { |
2799 | sub new { |
2539 | my $class = shift; |
2800 | my $class = shift; |
2540 | |
2801 | |
2541 | my $self = $class->SUPER::new ( |
2802 | my $self = $class->SUPER::new ( |
2542 | scrolled => (new CFClient::UI::VBox), |
2803 | scrolled => (new CFClient::UI::Table), |
2543 | @_, |
2804 | @_, |
2544 | ); |
2805 | ); |
2545 | |
2806 | |
2546 | $self |
2807 | $self |
2547 | } |
2808 | } |
… | |
… | |
2550 | my ($self, $items) = @_; |
2811 | my ($self, $items) = @_; |
2551 | |
2812 | |
2552 | $self->{scrolled}->clear; |
2813 | $self->{scrolled}->clear; |
2553 | return unless $items; |
2814 | return unless $items; |
2554 | |
2815 | |
2555 | my @items = sort { $a->{type} <=> $b->{type} } @$items; |
2816 | my @items = sort { |
|
|
2817 | ($a->{type} <=> $b->{type}) |
|
|
2818 | or ($a->{name} cmp $b->{name}) |
|
|
2819 | } @$items; |
2556 | |
2820 | |
2557 | $self->{real_items} = \@items; |
2821 | $self->{real_items} = \@items; |
2558 | |
2822 | |
2559 | for my $item (@items) { |
2823 | for my $item (@items) { |
2560 | my $desc = $item->{nrof} < 2 |
2824 | $item->{item} = $item; |
2561 | ? $item->{name} |
|
|
2562 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2563 | |
|
|
2564 | $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item); |
2825 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
|
|
2826 | $item->update_item (); |
|
|
2827 | } |
|
|
2828 | |
|
|
2829 | my $i = 0; |
|
|
2830 | for (@items) { |
|
|
2831 | $self->{scrolled}->add (0, $i, $_); |
|
|
2832 | my $nrof = $_->{item}->{nrof} || 1; |
|
|
2833 | $self->{scrolled}->add (1, $i++, new CFClient::UI::Label text => ($_->{item}->{weight} * $nrof) / 1000); |
2565 | } |
2834 | } |
2566 | |
2835 | |
2567 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2836 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2568 | } |
2837 | } |
2569 | |
2838 | |
… | |
… | |
2648 | |
2917 | |
2649 | package CFClient::UI::Statusbox; |
2918 | package CFClient::UI::Statusbox; |
2650 | |
2919 | |
2651 | our @ISA = CFClient::UI::VBox::; |
2920 | our @ISA = CFClient::UI::VBox::; |
2652 | |
2921 | |
|
|
2922 | sub new { |
|
|
2923 | my $class = shift; |
|
|
2924 | |
|
|
2925 | $class->SUPER::new ( |
|
|
2926 | fontsize => 0.8, |
|
|
2927 | @_, |
|
|
2928 | ) |
|
|
2929 | } |
|
|
2930 | |
2653 | sub reorder { |
2931 | sub reorder { |
2654 | my ($self) = @_; |
2932 | my ($self) = @_; |
2655 | my $NOW = time; |
2933 | my $NOW = time; |
2656 | |
2934 | |
2657 | while (my ($k, $v) = each %{ $self->{item} }) { |
2935 | while (my ($k, $v) = each %{ $self->{item} }) { |
2658 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
2936 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
2659 | } |
2937 | } |
2660 | |
2938 | |
2661 | my @widgets; |
2939 | my @widgets; |
2662 | my @items = sort { $a->{time} <=> $b->{time} } values %{ $self->{item} }; |
2940 | |
|
|
2941 | my @items = sort { |
|
|
2942 | $a->{pri} <=> $b->{pri} |
|
|
2943 | or $b->{id} <=> $a->{id} |
|
|
2944 | } values %{ $self->{item} }; |
|
|
2945 | |
2663 | my $count = 10 + 1; |
2946 | my $count = 10 + 1; |
2664 | for my $item (@items) { |
2947 | for my $item (@items) { |
2665 | last unless --$count; |
2948 | last unless --$count; |
2666 | |
2949 | |
2667 | push @widgets, $item->{label} ||= do { |
2950 | push @widgets, $item->{label} ||= do { |
2668 | # TODO: doesn't handle markup well (read as: at all) |
2951 | # TODO: doesn't handle markup well (read as: at all) |
2669 | my $short = delete $item->{text}; |
2952 | my $short = $item->{count} > 1 |
|
|
2953 | ? "<b>$item->{count} ×</b> $item->{text}" |
|
|
2954 | : $item->{text}; |
|
|
2955 | |
2670 | for ($short) { |
2956 | for ($short) { |
2671 | s/^\s+//; |
2957 | s/^\s+//; |
2672 | s/\012.*//s; |
2958 | s/\s+/ /g; |
2673 | my $len = int 30 / $item->{fontsize}; |
|
|
2674 | substr $_, $len, length, "…" if $len < length; |
|
|
2675 | } |
2959 | } |
2676 | |
2960 | |
2677 | new CFClient::UI::Label |
2961 | new CFClient::UI::Label |
2678 | markup => $short, |
2962 | markup => $short, |
2679 | tooltip => delete $item->{tooltip}, |
2963 | tooltip => $item->{tooltip}, |
2680 | fontsize => delete $item->{fontsize}, |
2964 | tooltip_font => $::FONT_PROP, |
2681 | color => delete $item->{color}, |
2965 | tooltip_width => 0.67, |
|
|
2966 | fontsize => $item->{fontsize} || $self->{fontsize}, |
|
|
2967 | max_w => $::WIDTH * 0.44, |
|
|
2968 | fg => $item->{fg}, |
2682 | can_events => 1, |
2969 | can_events => 1, |
2683 | can_hover => 1, |
2970 | can_hover => 1 |
2684 | }; |
2971 | }; |
2685 | } |
2972 | } |
2686 | |
2973 | |
2687 | $self->clear; |
2974 | $self->clear; |
2688 | $self->SUPER::add (@widgets); |
2975 | $self->SUPER::add (reverse @widgets); |
2689 | } |
2976 | } |
2690 | |
2977 | |
2691 | sub add { |
2978 | sub add { |
2692 | my ($self, $text, %arg) = @_; |
2979 | my ($self, $text, %arg) = @_; |
2693 | |
2980 | |
2694 | my $item = { |
2981 | $text =~ s/^\s+//; |
2695 | time => time, |
2982 | $text =~ s/\s+$//; |
|
|
2983 | |
|
|
2984 | my $timeout = time + ((delete $arg{timeout}) || 60); |
|
|
2985 | |
|
|
2986 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
|
|
2987 | |
|
|
2988 | if (my $item = $self->{item}{$group}) { |
|
|
2989 | if ($item->{text} eq $text) { |
|
|
2990 | $item->{count}++; |
|
|
2991 | } else { |
|
|
2992 | $item->{count} = 1; |
|
|
2993 | $item->{text} = $item->{tooltip} = $text; |
|
|
2994 | } |
|
|
2995 | $item->{id} = ++$self->{id}; |
|
|
2996 | $item->{timeout} = $timeout; |
|
|
2997 | delete $item->{label}; |
|
|
2998 | } else { |
|
|
2999 | $self->{item}{$group} = { |
|
|
3000 | id => ++$self->{id}, |
2696 | text => $text, |
3001 | text => $text, |
2697 | timeout => 60, |
3002 | timeout => $timeout, |
2698 | tooltip => $text, |
3003 | tooltip => $text, |
2699 | fontsize => 0.8, |
|
|
2700 | color => [0.8, 0.8, 0.8, 0.8], |
3004 | fg => [0.8, 0.8, 0.8, 0.8], |
|
|
3005 | pri => 0, |
|
|
3006 | count => 1, |
2701 | %arg, |
3007 | %arg, |
|
|
3008 | }; |
2702 | }; |
3009 | } |
2703 | |
|
|
2704 | $item->{timeout} += time; |
|
|
2705 | $item->{group} ||= $item+0; |
|
|
2706 | |
|
|
2707 | $item = $self->{item}{$item->{group}} ||= $item; |
|
|
2708 | |
3010 | |
2709 | $self->reorder; |
3011 | $self->reorder; |
|
|
3012 | } |
|
|
3013 | |
|
|
3014 | sub reconfigure { |
|
|
3015 | my ($self) = @_; |
|
|
3016 | |
|
|
3017 | delete $_->{label} |
|
|
3018 | for values %{ $self->{item} || {} }; |
|
|
3019 | |
|
|
3020 | $self->reorder; |
|
|
3021 | $self->SUPER::reconfigure; |
2710 | } |
3022 | } |
2711 | |
3023 | |
2712 | ############################################################################# |
3024 | ############################################################################# |
2713 | |
3025 | |
2714 | package CFClient::UI::Root; |
3026 | package CFClient::UI::Root; |
… | |
… | |
2746 | } |
3058 | } |
2747 | |
3059 | |
2748 | sub size_allocate { |
3060 | sub size_allocate { |
2749 | my ($self, $w, $h) = @_; |
3061 | my ($self, $w, $h) = @_; |
2750 | |
3062 | |
2751 | my $old_w = $self->{old_w}; |
|
|
2752 | my $old_h = $self->{old_h}; |
|
|
2753 | |
|
|
2754 | if ($old_w && $old_h) { |
|
|
2755 | for my $child ($self->children) { |
|
|
2756 | $child->{x} = int 0.5 + $child->{x} * $w / $old_w; |
|
|
2757 | $child->{w} = int 0.5 + $child->{w} * $w / $old_w; |
|
|
2758 | $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w}; |
|
|
2759 | $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w}; |
|
|
2760 | $child->{y} = int 0.5 + $child->{y} * $h / $old_h; |
|
|
2761 | $child->{h} = int 0.5 + $child->{h} * $h / $old_h; |
|
|
2762 | $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; |
|
|
2763 | $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h}; |
|
|
2764 | } |
|
|
2765 | } |
|
|
2766 | |
|
|
2767 | for my $child ($self->children) { |
3063 | for my $child ($self->children) { |
2768 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
3064 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2769 | |
3065 | |
|
|
3066 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
|
|
3067 | if exists $child->{req_x}; |
|
|
3068 | |
|
|
3069 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
|
|
3070 | if exists $child->{req_y}; |
|
|
3071 | |
2770 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
3072 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
2771 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
3073 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
|
|
3074 | |
2772 | $child->configure ($X, $Y, $W, $H); |
3075 | $child->configure ($X, $Y, $W, $H); |
2773 | } |
3076 | } |
2774 | |
|
|
2775 | $self->{old_w} = $w; |
|
|
2776 | $self->{old_h} = $h; |
|
|
2777 | } |
3077 | } |
2778 | |
3078 | |
2779 | sub coord2local { |
3079 | sub coord2local { |
2780 | my ($self, $x, $y) = @_; |
3080 | my ($self, $x, $y) = @_; |
2781 | |
3081 | |
… | |
… | |
2794 | $self->check_size; |
3094 | $self->check_size; |
2795 | $::WANT_REFRESH++; |
3095 | $::WANT_REFRESH++; |
2796 | } |
3096 | } |
2797 | |
3097 | |
2798 | sub add { |
3098 | sub add { |
2799 | my ($self, $child) = @_; |
3099 | my ($self, @children) = @_; |
2800 | |
3100 | |
|
|
3101 | for (my @widgets = @children; my $w = pop @widgets; ) { |
|
|
3102 | push @widgets, $w->children; |
|
|
3103 | $w->{root} = $self; |
|
|
3104 | $w->{visible} = 1; |
|
|
3105 | } |
|
|
3106 | |
|
|
3107 | for my $child (@children) { |
|
|
3108 | $child->{is_toplevel} = 1; |
|
|
3109 | |
2801 | # integerise window positions |
3110 | # integerise window positions |
2802 | $child->{x} = int $child->{x}; |
3111 | $child->{x} = int $child->{x}; |
2803 | $child->{y} = int $child->{y}; |
3112 | $child->{y} = int $child->{y}; |
|
|
3113 | } |
2804 | |
3114 | |
2805 | $self->SUPER::add ($child); |
3115 | $self->SUPER::add (@children); |
|
|
3116 | } |
|
|
3117 | |
|
|
3118 | sub remove { |
|
|
3119 | my ($self, @children) = @_; |
|
|
3120 | |
|
|
3121 | $self->SUPER::remove (@children); |
|
|
3122 | |
|
|
3123 | while (@children) { |
|
|
3124 | my $w = pop @children; |
|
|
3125 | push @children, $w->children; |
|
|
3126 | delete $w->{visible}; |
|
|
3127 | } |
2806 | } |
3128 | } |
2807 | |
3129 | |
2808 | sub on_refresh { |
3130 | sub on_refresh { |
2809 | my ($self, $id, $cb) = @_; |
3131 | my ($self, $id, $cb) = @_; |
2810 | |
3132 | |
2811 | $self->{refresh_hook}{$id} = $cb; |
3133 | $self->{refresh_hook}{$id} = $cb; |
2812 | } |
3134 | } |
2813 | |
3135 | |
|
|
3136 | sub on_post_alloc { |
|
|
3137 | my ($self, $id, $cb) = @_; |
|
|
3138 | |
|
|
3139 | $self->{post_alloc_hook}{$id} = $cb; |
|
|
3140 | } |
|
|
3141 | |
2814 | sub draw { |
3142 | sub draw { |
2815 | my ($self) = @_; |
3143 | my ($self) = @_; |
|
|
3144 | |
|
|
3145 | while ($self->{refresh_hook}) { |
|
|
3146 | $_->() |
|
|
3147 | for values %{delete $self->{refresh_hook}}; |
|
|
3148 | } |
2816 | |
3149 | |
2817 | if ($self->{check_size}) { |
3150 | if ($self->{check_size}) { |
2818 | my @queue = ([], []); |
3151 | my @queue = ([], []); |
2819 | |
3152 | |
2820 | for (;;) { |
3153 | for (;;) { |
… | |
… | |
2828 | |
3161 | |
2829 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
3162 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
2830 | ? @$widget{qw(user_w user_h)} |
3163 | ? @$widget{qw(user_w user_h)} |
2831 | : $widget->size_request; |
3164 | : $widget->size_request; |
2832 | |
3165 | |
|
|
3166 | if (delete $widget->{force_alloc} |
2833 | if ($w != $widget->{req_w} || $h != $widget->{req_h}) { |
3167 | or $w != $widget->{req_w} or $h != $widget->{req_h}) { |
2834 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
3168 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
2835 | |
3169 | |
2836 | $widget->{req_w} = $w; |
3170 | $widget->{req_w} = $w; |
2837 | $widget->{req_h} = $h; |
3171 | $widget->{req_h} = $h; |
2838 | |
3172 | |
2839 | $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; |
3173 | $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; |
2840 | |
3174 | |
2841 | $widget->{parent}->check_size |
3175 | $widget->{parent}->check_size |
2842 | if $widget->{parent}; |
3176 | if $widget->{parent}; |
2843 | } |
3177 | } |
2844 | } |
3178 | } |
… | |
… | |
2856 | $widget->size_allocate ($w, $h); |
3190 | $widget->size_allocate ($w, $h); |
2857 | $widget->emit (size_allocate => $w, $h); |
3191 | $widget->emit (size_allocate => $w, $h); |
2858 | } |
3192 | } |
2859 | } |
3193 | } |
2860 | |
3194 | |
2861 | while ($self->{refresh_hook}) { |
3195 | while ($self->{post_alloc_hook}) { |
2862 | $_->() |
3196 | $_->() |
2863 | for values %{delete $self->{refresh_hook}}; |
3197 | for values %{delete $self->{post_alloc_hook}}; |
2864 | } |
3198 | } |
2865 | |
3199 | |
2866 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
3200 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
2867 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
3201 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
2868 | glClear GL_COLOR_BUFFER_BIT; |
3202 | glClear GL_COLOR_BUFFER_BIT; |
2869 | |
3203 | |
2870 | glMatrixMode GL_PROJECTION; |
3204 | glMatrixMode GL_PROJECTION; |
2871 | glLoadIdentity; |
3205 | glLoadIdentity; |
2872 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; |
3206 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
2873 | glMatrixMode GL_MODELVIEW; |
3207 | glMatrixMode GL_MODELVIEW; |
2874 | glLoadIdentity; |
3208 | glLoadIdentity; |
2875 | |
3209 | |
2876 | $self->_draw; |
3210 | $self->_draw; |
2877 | } |
3211 | } |
… | |
… | |
2879 | ############################################################################# |
3213 | ############################################################################# |
2880 | |
3214 | |
2881 | package CFClient::UI; |
3215 | package CFClient::UI; |
2882 | |
3216 | |
2883 | $ROOT = new CFClient::UI::Root; |
3217 | $ROOT = new CFClient::UI::Root; |
2884 | $TOOLTIP = new CFClient::UI::Tooltip; |
3218 | $TOOLTIP = new CFClient::UI::Tooltip z => 900; |
2885 | |
3219 | |
2886 | 1 |
3220 | 1 |
2887 | |
3221 | |