… | |
… | |
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}) { |
… | |
… | |
29 | $TOOLTIP->set_tooltip_from ($widget); |
31 | $TOOLTIP->set_tooltip_from ($widget); |
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) { |
|
|
35 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); |
36 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0) |
36 | } |
37 | if $x + $TOOLTIP->{w} > $::WIDTH; |
37 | |
38 | |
38 | $TOOLTIP->move ($x, $y); |
39 | $TOOLTIP->move ($x, $y); |
39 | $TOOLTIP->check_size; |
40 | $TOOLTIP->check_size; |
40 | $TOOLTIP->update; |
41 | $TOOLTIP->update; |
41 | } |
42 | } |
… | |
… | |
132 | |
133 | |
133 | for (@$vals) { |
134 | for (@$vals) { |
134 | my $i = int $_ + $rem; |
135 | my $i = int $_ + $rem; |
135 | $rem += $_ - $i; |
136 | $rem += $_ - $i; |
136 | $_ = $i; |
137 | $_ = $i; |
|
|
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 | # call when resolution changes etc. |
|
|
150 | sub rescale_widgets { |
|
|
151 | my ($sx, $sy) = @_; |
|
|
152 | |
|
|
153 | # make a copy, otherwise for complains about freed values. |
|
|
154 | my @widgets = values %WIDGET; |
|
|
155 | |
|
|
156 | for my $widget (@widgets) { |
|
|
157 | if ($widget->{toplevel}) { |
|
|
158 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
|
|
159 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
|
|
160 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
|
|
161 | $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; |
|
|
162 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
|
|
163 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
|
|
164 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
|
|
165 | $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; |
|
|
166 | } |
|
|
167 | |
|
|
168 | $widget->reconfigure; |
137 | } |
169 | } |
138 | } |
170 | } |
139 | |
171 | |
140 | ############################################################################# |
172 | ############################################################################# |
141 | |
173 | |
… | |
… | |
160 | if (/^connect_(.*)$/) { |
192 | if (/^connect_(.*)$/) { |
161 | $self->connect ($1 => delete $self->{$_}); |
193 | $self->connect ($1 => delete $self->{$_}); |
162 | } |
194 | } |
163 | } |
195 | } |
164 | |
196 | |
|
|
197 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
|
|
198 | |
165 | $self |
199 | $self |
166 | } |
200 | } |
167 | |
201 | |
168 | sub destroy { |
202 | sub destroy { |
169 | my ($self) = @_; |
203 | my ($self) = @_; |
… | |
… | |
172 | %$self = (); |
206 | %$self = (); |
173 | } |
207 | } |
174 | |
208 | |
175 | sub show { |
209 | sub show { |
176 | my ($self) = @_; |
210 | my ($self) = @_; |
177 | |
|
|
178 | return if $self->{parent}; |
211 | return if $self->{parent}; |
179 | |
212 | |
180 | $CFClient::UI::ROOT->add ($self); |
213 | $CFClient::UI::ROOT->add ($self); |
181 | } |
214 | } |
182 | |
215 | |
… | |
… | |
242 | |
275 | |
243 | sub size_allocate { |
276 | sub size_allocate { |
244 | # nothing to be done |
277 | # nothing to be done |
245 | } |
278 | } |
246 | |
279 | |
|
|
280 | sub reconfigure { |
|
|
281 | my ($self) = @_; |
|
|
282 | |
|
|
283 | $self->check_size (1); |
|
|
284 | $self->update; |
|
|
285 | } |
|
|
286 | |
247 | sub children { |
287 | sub children { |
248 | } |
|
|
249 | |
|
|
250 | # call when resolution changes etc. |
|
|
251 | sub reconfigure { |
|
|
252 | my ($self) = @_; |
|
|
253 | |
|
|
254 | $_->reconfigure |
|
|
255 | for $self->children; |
|
|
256 | |
|
|
257 | $self->check_size; |
|
|
258 | $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $self->{w}, $self->{h}]; |
|
|
259 | $self->update; |
|
|
260 | } |
288 | } |
261 | |
289 | |
262 | sub set_max_size { |
290 | sub set_max_size { |
263 | my ($self, $w, $h) = @_; |
291 | my ($self, $w, $h) = @_; |
264 | |
292 | |
265 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
293 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
266 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
294 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
|
|
295 | } |
|
|
296 | |
|
|
297 | sub set_tooltip { |
|
|
298 | my ($self, $tooltip) = @_; |
|
|
299 | |
|
|
300 | $self->{tooltip} = $tooltip; |
|
|
301 | |
|
|
302 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
|
|
303 | delete $CFClient::UI::TOOLTIP->{owner}; |
|
|
304 | CFClient::UI::check_tooltip; |
|
|
305 | } |
267 | } |
306 | } |
268 | |
307 | |
269 | # translate global coordinates to local coordinate system |
308 | # translate global coordinates to local coordinate system |
270 | sub coord2local { |
309 | sub coord2local { |
271 | my ($self, $x, $y) = @_; |
310 | my ($self, $x, $y) = @_; |
… | |
… | |
357 | glVertex $self->{w}, 0; |
396 | glVertex $self->{w}, 0; |
358 | glVertex $self->{w}, $self->{h}; |
397 | glVertex $self->{w}, $self->{h}; |
359 | glVertex 0 , $self->{h}; |
398 | glVertex 0 , $self->{h}; |
360 | glEnd; |
399 | glEnd; |
361 | glPopMatrix; |
400 | glPopMatrix; |
362 | CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
401 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
363 | } |
402 | } |
364 | } |
403 | } |
365 | |
404 | |
366 | sub _draw { |
405 | sub _draw { |
367 | my ($self) = @_; |
406 | my ($self) = @_; |
… | |
… | |
384 | sub set_parent { |
423 | sub set_parent { |
385 | my ($self, $parent) = @_; |
424 | my ($self, $parent) = @_; |
386 | |
425 | |
387 | Scalar::Util::weaken ($self->{parent} = $parent); |
426 | Scalar::Util::weaken ($self->{parent} = $parent); |
388 | |
427 | |
|
|
428 | # TODO: req_w _does_change after ->reconfigure |
389 | $self->check_size |
429 | $self->check_size |
390 | unless exists $self->{req_w}; |
430 | unless exists $self->{req_w}; |
|
|
431 | |
|
|
432 | $self->show; |
391 | } |
433 | } |
392 | |
434 | |
393 | sub check_size { |
435 | sub check_size { |
394 | my ($self, $forced) = @_; |
436 | my ($self, $forced) = @_; |
395 | |
437 | |
… | |
… | |
417 | } |
459 | } |
418 | |
460 | |
419 | sub DESTROY { |
461 | sub DESTROY { |
420 | my ($self) = @_; |
462 | my ($self) = @_; |
421 | |
463 | |
|
|
464 | delete $WIDGET{$self+0}; |
422 | #$self->deactivate; |
465 | #$self->deactivate; |
423 | } |
466 | } |
424 | |
467 | |
425 | ############################################################################# |
468 | ############################################################################# |
426 | |
469 | |
… | |
… | |
435 | my $class = shift; |
478 | my $class = shift; |
436 | |
479 | |
437 | # range [value, low, high, page] |
480 | # range [value, low, high, page] |
438 | |
481 | |
439 | $class->SUPER::new ( |
482 | $class->SUPER::new ( |
440 | bg => [0, 0, 0, 0.2], |
483 | #bg => [0, 0, 0, 0.2], |
441 | active_bg => [1, 1, 1, 0.5], |
484 | #active_bg => [1, 1, 1, 0.5], |
442 | @_ |
485 | @_ |
443 | ) |
486 | ) |
444 | } |
487 | } |
445 | |
488 | |
446 | sub _draw { |
489 | sub _draw { |
447 | my ($self) = @_; |
490 | my ($self) = @_; |
448 | |
491 | |
|
|
492 | my $color = $FOCUS == $self && $self->{active_bg} |
|
|
493 | ? $self->{active_bg} |
|
|
494 | : $self->{bg}; |
|
|
495 | |
|
|
496 | if ($color && (@$color < 4 || $color->[3])) { |
449 | my ($w, $h) = @$self{qw(w h)}; |
497 | my ($w, $h) = @$self{qw(w h)}; |
450 | |
498 | |
451 | glEnable GL_BLEND; |
499 | glEnable GL_BLEND; |
452 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
500 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
453 | glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; |
501 | glColor @$color; |
454 | |
502 | |
455 | glBegin GL_QUADS; |
503 | glBegin GL_QUADS; |
456 | glVertex 0 , 0; |
504 | glVertex 0 , 0; |
457 | glVertex 0 , $h; |
505 | glVertex 0 , $h; |
458 | glVertex $w, $h; |
506 | glVertex $w, $h; |
459 | glVertex $w, 0; |
507 | glVertex $w, 0; |
460 | glEnd; |
508 | glEnd; |
461 | |
509 | |
462 | glDisable GL_BLEND; |
510 | glDisable GL_BLEND; |
|
|
511 | } |
463 | } |
512 | } |
464 | |
513 | |
465 | ############################################################################# |
514 | ############################################################################# |
466 | |
515 | |
467 | package CFClient::UI::Empty; |
516 | package CFClient::UI::Empty; |
… | |
… | |
628 | } |
677 | } |
629 | |
678 | |
630 | sub update { |
679 | sub update { |
631 | my ($self) = @_; |
680 | my ($self) = @_; |
632 | |
681 | |
633 | $ROOT->on_refresh ($self => sub { $self->render_child }); |
682 | $ROOT->on_post_alloc ($self => sub { $self->render_child }); |
634 | $self->SUPER::update; |
683 | $self->SUPER::update; |
635 | } |
684 | } |
636 | |
685 | |
637 | sub size_allocate { |
686 | sub size_allocate { |
638 | my ($self, $w, $h) = @_; |
687 | my ($self, $w, $h) = @_; |
… | |
… | |
651 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
700 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
652 | glClearColor 0, 0, 0, 0; |
701 | glClearColor 0, 0, 0, 0; |
653 | glClear GL_COLOR_BUFFER_BIT; |
702 | glClear GL_COLOR_BUFFER_BIT; |
654 | |
703 | |
655 | $self->_render; |
704 | $self->_render; |
656 | # glColorMask 1, 1, 1, 0; |
|
|
657 | # glEnable GL_BLEND; |
|
|
658 | # glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
|
|
659 | # glRasterPos 0, 0; |
|
|
660 | # glCopyPixels 0, 0, $self->{w}, $self->{h}; |
|
|
661 | # glDisable GL_BLEND; |
|
|
662 | # glColorMask 1, 1, 1, 1; |
|
|
663 | }; |
705 | }; |
664 | } |
706 | } |
665 | |
707 | |
666 | sub _draw { |
708 | sub _draw { |
667 | my ($self) = @_; |
709 | my ($self) = @_; |
… | |
… | |
671 | my $tex = $self->{texture} |
713 | my $tex = $self->{texture} |
672 | or return; |
714 | or return; |
673 | |
715 | |
674 | glEnable GL_TEXTURE_2D; |
716 | glEnable GL_TEXTURE_2D; |
675 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
717 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
676 | glColor 0, 0, 0, 1; |
718 | glColor 1, 1, 1, 1; |
677 | |
719 | |
678 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
720 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
679 | |
721 | |
680 | glDisable GL_TEXTURE_2D; |
722 | glDisable GL_TEXTURE_2D; |
681 | } |
723 | } |
… | |
… | |
764 | $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); |
806 | $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); |
765 | }, |
807 | }, |
766 | ; |
808 | ; |
767 | |
809 | |
768 | $self = $class->SUPER::new ( |
810 | $self = $class->SUPER::new ( |
769 | vp => (new CFClient::UI::ViewPort), |
811 | vp => (new CFClient::UI::ViewPort expand => 1), |
770 | slider => $slider, |
812 | slider => $slider, |
771 | @_, |
813 | @_, |
772 | ); |
814 | ); |
773 | |
815 | |
774 | $self->{vp}->add ($self->{scrolled}); |
816 | $self->{vp}->add ($self->{scrolled}); |
… | |
… | |
776 | $self->add ($self->{slider}); |
818 | $self->add ($self->{slider}); |
777 | |
819 | |
778 | $self |
820 | $self |
779 | } |
821 | } |
780 | |
822 | |
781 | #TODO# update range on size_allocate depeneing on child |
823 | #TODO# update range on size_allocate depending on child |
782 | # update viewport offset on scroll |
824 | # update viewport offset on scroll |
783 | |
825 | |
784 | ############################################################################# |
826 | ############################################################################# |
785 | |
827 | |
786 | package CFClient::UI::Frame; |
828 | package CFClient::UI::Frame; |
787 | |
829 | |
788 | our @ISA = CFClient::UI::Bin::; |
830 | our @ISA = CFClient::UI::Bin::; |
789 | |
831 | |
790 | use CFClient::OpenGL; |
832 | use CFClient::OpenGL; |
|
|
833 | |
|
|
834 | sub new { |
|
|
835 | my $class = shift; |
|
|
836 | |
|
|
837 | $class->SUPER::new ( |
|
|
838 | bg => undef, |
|
|
839 | @_, |
|
|
840 | ) |
|
|
841 | } |
|
|
842 | |
|
|
843 | sub _draw { |
|
|
844 | my ($self) = @_; |
|
|
845 | |
|
|
846 | if ($self->{bg}) { |
|
|
847 | my ($w, $h) = @$self{qw(w h)}; |
|
|
848 | |
|
|
849 | glEnable GL_BLEND; |
|
|
850 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
851 | glColor @{ $self->{bg} }; |
|
|
852 | |
|
|
853 | glBegin GL_QUADS; |
|
|
854 | glVertex 0 , 0; |
|
|
855 | glVertex 0 , $h; |
|
|
856 | glVertex $w, $h; |
|
|
857 | glVertex $w, 0; |
|
|
858 | glEnd; |
|
|
859 | |
|
|
860 | glDisable GL_BLEND; |
|
|
861 | } |
|
|
862 | |
|
|
863 | $self->SUPER::_draw; |
|
|
864 | } |
791 | |
865 | |
792 | ############################################################################# |
866 | ############################################################################# |
793 | |
867 | |
794 | package CFClient::UI::FancyFrame; |
868 | package CFClient::UI::FancyFrame; |
795 | |
869 | |
… | |
… | |
808 | |
882 | |
809 | my $self = $class->SUPER::new ( |
883 | my $self = $class->SUPER::new ( |
810 | bg => [1, 1, 1, 1], |
884 | bg => [1, 1, 1, 1], |
811 | border_bg => [1, 1, 1, 1], |
885 | border_bg => [1, 1, 1, 1], |
812 | border => 0.6, |
886 | border => 0.6, |
|
|
887 | toplevel => 1, |
813 | can_events => 1, |
888 | can_events => 1, |
814 | @_ |
889 | @_ |
815 | ); |
890 | ); |
816 | |
891 | |
817 | $self->{title} &&= new CFClient::UI::Label |
892 | $self->{title} &&= new CFClient::UI::Label |
… | |
… | |
842 | my ($self, $w, $h) = @_; |
917 | my ($self, $w, $h) = @_; |
843 | |
918 | |
844 | $h -= List::Util::max 0, $self->border * 2; |
919 | $h -= List::Util::max 0, $self->border * 2; |
845 | $w -= List::Util::max 0, $self->border * 2; |
920 | $w -= List::Util::max 0, $self->border * 2; |
846 | |
921 | |
847 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
922 | $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) |
848 | if $self->{title}; |
923 | if $self->{title}; |
849 | |
924 | |
850 | $self->child->configure ($self->border, $self->border, $w, $h); |
925 | $self->child->configure ($self->border, $self->border, $w, $h); |
851 | } |
926 | } |
852 | |
927 | |
… | |
… | |
1213 | |
1288 | |
1214 | ############################################################################# |
1289 | ############################################################################# |
1215 | |
1290 | |
1216 | package CFClient::UI::Label; |
1291 | package CFClient::UI::Label; |
1217 | |
1292 | |
1218 | our @ISA = CFClient::UI::Base::; |
1293 | our @ISA = CFClient::UI::DrawBG::; |
1219 | |
1294 | |
1220 | use CFClient::OpenGL; |
1295 | use CFClient::OpenGL; |
1221 | |
1296 | |
1222 | sub new { |
1297 | sub new { |
1223 | my ($class, %arg) = @_; |
1298 | my ($class, %arg) = @_; |
1224 | |
1299 | |
1225 | my $self = $class->SUPER::new ( |
1300 | my $self = $class->SUPER::new ( |
1226 | fg => [1, 1, 1], |
1301 | fg => [1, 1, 1], |
|
|
1302 | #bg => none |
|
|
1303 | #active_bg => none |
1227 | #font => default_font |
1304 | #font => default_font |
1228 | #text => initial text |
1305 | #text => initial text |
1229 | #markup => initial narkup |
1306 | #markup => initial narkup |
|
|
1307 | #max_w => maximum pixel width |
|
|
1308 | ellipsise => 3, # end |
1230 | layout => (new CFClient::Layout), |
1309 | layout => (new CFClient::Layout), |
1231 | fontsize => 1, |
1310 | fontsize => 1, |
1232 | align => -1, |
1311 | align => -1, |
1233 | valign => -1, |
1312 | valign => -1, |
1234 | padding => 2, |
1313 | padding => 2, |
… | |
… | |
1249 | } |
1328 | } |
1250 | |
1329 | |
1251 | $self |
1330 | $self |
1252 | } |
1331 | } |
1253 | |
1332 | |
1254 | sub escape { |
1333 | sub escape($) { |
1255 | local $_ = $_[1]; |
1334 | local $_ = $_[0]; |
1256 | |
1335 | |
1257 | s/&/&/g; |
1336 | s/&/&/g; |
1258 | s/>/>/g; |
1337 | s/>/>/g; |
1259 | s/</</g; |
1338 | s/</</g; |
1260 | |
1339 | |
1261 | $_[1] |
1340 | $_ |
1262 | } |
1341 | } |
1263 | |
1342 | |
1264 | sub update { |
1343 | sub update { |
1265 | my ($self) = @_; |
1344 | my ($self) = @_; |
1266 | |
1345 | |
… | |
… | |
1299 | sub size_request { |
1378 | sub size_request { |
1300 | my ($self) = @_; |
1379 | my ($self) = @_; |
1301 | |
1380 | |
1302 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1381 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1303 | $self->{layout}->set_width ($self->{max_w} || -1); |
1382 | $self->{layout}->set_width ($self->{max_w} || -1); |
|
|
1383 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
|
|
1384 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1304 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1385 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1305 | |
1386 | |
1306 | my ($w, $h) = $self->{layout}->size; |
1387 | my ($w, $h) = $self->{layout}->size; |
1307 | |
1388 | |
1308 | if (exists $self->{template}) { |
1389 | if (exists $self->{template}) { |
… | |
… | |
1338 | } |
1419 | } |
1339 | |
1420 | |
1340 | sub _draw { |
1421 | sub _draw { |
1341 | my ($self) = @_; |
1422 | my ($self) = @_; |
1342 | |
1423 | |
|
|
1424 | $self->SUPER::_draw; # draw background, if applicable |
|
|
1425 | |
1343 | my $tex = $self->{texture} ||= do { |
1426 | my $tex = $self->{texture} ||= do { |
1344 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1427 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1345 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1428 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1346 | $self->{layout}->set_width ($self->{w}); |
1429 | $self->{layout}->set_width ($self->{w}); |
|
|
1430 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
|
|
1431 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1347 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1432 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1348 | |
1433 | |
1349 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1434 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1350 | |
1435 | |
1351 | $self->{ox} = int $self->{align} < 0 ? $self->{padding} |
1436 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding} |
1352 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1437 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1353 | : ($self->{w} - $tex->{w}) * 0.5; |
1438 | : ($self->{w} - $tex->{w}) * 0.5); |
1354 | |
1439 | |
1355 | $self->{oy} = int $self->{valign} < 0 ? $self->{padding} |
1440 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding} |
1356 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1441 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1357 | : ($self->{h} - $tex->{h}) * 0.5; |
1442 | : ($self->{h} - $tex->{h}) * 0.5); |
1358 | |
1443 | |
1359 | $tex |
1444 | $tex |
1360 | }; |
1445 | }; |
1361 | |
1446 | |
1362 | glEnable GL_TEXTURE_2D; |
1447 | glEnable GL_TEXTURE_2D; |
… | |
… | |
1417 | sub set_text { |
1502 | sub set_text { |
1418 | my ($self, $text) = @_; |
1503 | my ($self, $text) = @_; |
1419 | |
1504 | |
1420 | $self->{cursor} = length $text; |
1505 | $self->{cursor} = length $text; |
1421 | $self->_set_text ($text); |
1506 | $self->_set_text ($text); |
|
|
1507 | $self->update; |
1422 | $self->check_size; |
1508 | $self->check_size; |
1423 | $self->update; |
|
|
1424 | } |
1509 | } |
1425 | |
1510 | |
1426 | sub get_text { |
1511 | sub get_text { |
1427 | $_[0]{text} |
1512 | $_[0]{text} |
1428 | } |
1513 | } |
… | |
… | |
1448 | my $sym = $ev->{sym}; |
1533 | my $sym = $ev->{sym}; |
1449 | my $uni = $ev->{unicode}; |
1534 | my $uni = $ev->{unicode}; |
1450 | |
1535 | |
1451 | my $text = $self->get_text; |
1536 | my $text = $self->get_text; |
1452 | |
1537 | |
1453 | if ($sym == 8) { |
1538 | if ($uni == 8) { |
1454 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1539 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1455 | } elsif ($sym == 127) { |
1540 | } elsif ($uni == 127) { |
1456 | substr $text, $self->{cursor}, 1, ""; |
1541 | substr $text, $self->{cursor}, 1, ""; |
1457 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1542 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1458 | --$self->{cursor} if $self->{cursor}; |
1543 | --$self->{cursor} if $self->{cursor}; |
1459 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1544 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1460 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1545 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1461 | } elsif ($sym == CFClient::SDLK_HOME) { |
1546 | } elsif ($sym == CFClient::SDLK_HOME) { |
1462 | $self->{cursor} = 0; |
1547 | $self->{cursor} = 0; |
1463 | } elsif ($sym == CFClient::SDLK_END) { |
1548 | } elsif ($sym == CFClient::SDLK_END) { |
1464 | $self->{cursor} = length $text; |
1549 | $self->{cursor} = length $text; |
1465 | } elsif ($sym == 27) { |
1550 | } elsif ($uni == 27) { |
1466 | $self->emit ('escape'); |
1551 | $self->emit ('escape'); |
1467 | } elsif ($uni) { |
1552 | } elsif ($uni) { |
1468 | substr $text, $self->{cursor}++, 0, chr $uni; |
1553 | substr $text, $self->{cursor}++, 0, chr $uni; |
1469 | } |
1554 | } |
1470 | |
1555 | |
1471 | $self->_set_text ($text); |
1556 | $self->_set_text ($text); |
1472 | $self->update; |
1557 | $self->update; |
|
|
1558 | $self->check_size; |
1473 | } |
1559 | } |
1474 | |
1560 | |
1475 | sub focus_in { |
1561 | sub focus_in { |
1476 | my ($self) = @_; |
1562 | my ($self) = @_; |
1477 | |
1563 | |
… | |
… | |
1606 | my $class = shift; |
1692 | my $class = shift; |
1607 | |
1693 | |
1608 | $class->SUPER::new ( |
1694 | $class->SUPER::new ( |
1609 | padding => 4, |
1695 | padding => 4, |
1610 | fg => [1, 1, 1], |
1696 | fg => [1, 1, 1], |
1611 | bg => [1, 1, 1, 0.2], |
|
|
1612 | active_fg => [0, 0, 1], |
1697 | active_fg => [0, 0, 1], |
1613 | can_hover => 1, |
1698 | can_hover => 1, |
1614 | align => 0, |
1699 | align => 0, |
1615 | valign => 0, |
1700 | valign => 0, |
1616 | can_events => 1, |
1701 | can_events => 1, |
… | |
… | |
1664 | |
1749 | |
1665 | $class->SUPER::new ( |
1750 | $class->SUPER::new ( |
1666 | padding => 2, |
1751 | padding => 2, |
1667 | fg => [1, 1, 1], |
1752 | fg => [1, 1, 1], |
1668 | active_fg => [1, 1, 0], |
1753 | active_fg => [1, 1, 0], |
|
|
1754 | bg => [0, 0, 0, 0.2], |
|
|
1755 | active_bg => [1, 1, 1, 0.5], |
1669 | state => 0, |
1756 | state => 0, |
1670 | can_hover => 1, |
1757 | can_hover => 1, |
1671 | @_ |
1758 | @_ |
1672 | ) |
1759 | ) |
1673 | } |
1760 | } |
… | |
… | |
1957 | qw(s1_slider.png s1_slider_bg.png); |
2044 | qw(s1_slider.png s1_slider_bg.png); |
1958 | |
2045 | |
1959 | sub new { |
2046 | sub new { |
1960 | my $class = shift; |
2047 | my $class = shift; |
1961 | |
2048 | |
1962 | # range [value, low, high, page] |
2049 | # range [value, low, high, page, unit] |
1963 | |
2050 | |
1964 | # TODO: 0-width page |
2051 | # TODO: 0-width page |
1965 | # TODO: req_w/h are wrong with vertical |
2052 | # TODO: req_w/h are wrong with vertical |
1966 | # TODO: calculations are off |
2053 | # TODO: calculations are off |
1967 | my $self = $class->SUPER::new ( |
2054 | my $self = $class->SUPER::new ( |
1968 | fg => [1, 1, 1], |
2055 | fg => [1, 1, 1], |
1969 | active_fg => [0, 0, 0], |
2056 | active_fg => [0, 0, 0], |
|
|
2057 | bg => [0, 0, 0, 0.2], |
|
|
2058 | active_bg => [1, 1, 1, 0.5], |
1970 | range => [0, 0, 100, 10], |
2059 | range => [0, 0, 100, 10], |
1971 | req_w => $::WIDTH / 80, |
2060 | req_w => $::WIDTH / 80, |
1972 | req_h => $::WIDTH / 80, |
2061 | req_h => $::WIDTH / 80, |
1973 | vertical => 0, |
2062 | vertical => 0, |
1974 | can_hover => 1, |
2063 | can_hover => 1, |
1975 | inner_pad => 5, |
2064 | inner_pad => 0.02, |
1976 | @_ |
2065 | @_ |
1977 | ); |
2066 | ); |
1978 | |
2067 | |
|
|
2068 | $self->set_value ($self->{range}[0]); |
|
|
2069 | $self->update; |
|
|
2070 | |
1979 | $self |
2071 | $self |
|
|
2072 | } |
|
|
2073 | |
|
|
2074 | sub set_value { |
|
|
2075 | my ($self, $value) = @_; |
|
|
2076 | |
|
|
2077 | my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; |
|
|
2078 | |
|
|
2079 | $hi = $lo + 1 if $hi <= $lo; |
|
|
2080 | |
|
|
2081 | $value = $lo if $value < $lo; |
|
|
2082 | $value = $hi if $value > $hi; |
|
|
2083 | |
|
|
2084 | $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit |
|
|
2085 | if $unit; |
|
|
2086 | |
|
|
2087 | $page = $hi - $lo if $page > $hi - $lo; |
|
|
2088 | |
|
|
2089 | @{$self->{range}} = ($value, $lo, $hi, $page, $unit); |
|
|
2090 | |
|
|
2091 | if ($value != $old_value) { |
|
|
2092 | $self->emit (changed => $value); |
|
|
2093 | $self->update; |
|
|
2094 | } |
1980 | } |
2095 | } |
1981 | |
2096 | |
1982 | sub size_request { |
2097 | sub size_request { |
1983 | my ($self) = @_; |
2098 | my ($self) = @_; |
1984 | |
2099 | |
… | |
… | |
1997 | |
2112 | |
1998 | sub mouse_motion { |
2113 | sub mouse_motion { |
1999 | my ($self, $ev, $x, $y) = @_; |
2114 | my ($self, $ev, $x, $y) = @_; |
2000 | |
2115 | |
2001 | if ($GRAB == $self) { |
2116 | if ($GRAB == $self) { |
|
|
2117 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
|
|
2118 | |
|
|
2119 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
|
|
2120 | |
|
|
2121 | $x = $x / ($w * (1 - 2 * $self->{inner_pad})) - $self->{inner_pad}; |
|
|
2122 | |
|
|
2123 | $self->set_value ($x * ($hi - $lo) + $lo); |
|
|
2124 | } |
|
|
2125 | } |
|
|
2126 | |
|
|
2127 | sub update { |
|
|
2128 | my ($self) = @_; |
|
|
2129 | |
|
|
2130 | $CFClient::UI::ROOT->on_post_alloc ($self => sub { |
|
|
2131 | $self->set_value ($self->{range}[0]); |
|
|
2132 | |
2002 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2133 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2003 | |
2134 | |
2004 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
2135 | my $inner_w = 1 - 2 * $self->{inner_pad}; |
2005 | |
2136 | |
2006 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
2137 | $self->{scale} = ($inner_w / ($hi - $lo)) || 1; |
2007 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
|
|
2008 | |
2138 | |
2009 | $x -= $inner_pad_px; # substract the padding |
2139 | $page = $self->{scale} * $page || 10 / ($self->{w} || 1); |
2010 | $x = $x * ($hi - $lo) / $inner_w + $lo; |
2140 | $value = $self->{scale} * ($value - $lo); |
2011 | $x = $lo if $x < $lo; |
|
|
2012 | $x = $hi - $page if $x > $hi - $page; |
|
|
2013 | $self->{range}[0] = $x; |
|
|
2014 | |
2141 | |
2015 | $self->emit (changed => $x); |
2142 | $value = $self->{inner_pad} + ($value - $page * 0.5); |
2016 | $self->update; |
2143 | |
|
|
2144 | $value = 0 if $value < 0; |
|
|
2145 | $page = 1 - $value if $value + $page > 1; |
|
|
2146 | |
|
|
2147 | $self->{knob_x} = $value; |
|
|
2148 | $self->{knob_w} = $page; |
2017 | } |
2149 | }); |
2018 | } |
|
|
2019 | |
2150 | |
2020 | # the inner_* stuff is for generating a padding for the slider handle, |
2151 | $self->SUPER::update; |
2021 | # so that the handle doesn't leave the texture. This calculation isn't 100% |
|
|
2022 | # correct propably, but it does the job for now |
|
|
2023 | sub _calc_inner_pad_px { |
|
|
2024 | my ($self, $w) = @_; |
|
|
2025 | ($w / 100) * $self->{inner_pad} # % to pixels |
|
|
2026 | } |
2152 | } |
2027 | |
2153 | |
2028 | sub _draw { |
2154 | sub _draw { |
2029 | my ($self) = @_; |
2155 | my ($self) = @_; |
2030 | |
2156 | |
2031 | $self->SUPER::_draw (); |
2157 | $self->SUPER::_draw (); |
2032 | |
2158 | |
2033 | my ($w, $h) = @$self{qw(w h)}; |
2159 | glScale $self->{w}, $self->{h}; |
2034 | |
2160 | |
2035 | if ($self->{vertical}) { |
2161 | if ($self->{vertical}) { |
2036 | # draw a vertical slider like a rotated horizontal slider |
2162 | # draw a vertical slider like a rotated horizontal slider |
2037 | |
2163 | |
|
|
2164 | glTranslate 1, 0, 0; |
2038 | glRotate 90, 0, 0, 1; |
2165 | glRotate 90, 0, 0, 1; |
2039 | glTranslate 0, -$self->{w}, 0; |
|
|
2040 | |
|
|
2041 | ($w, $h) = ($h, $w); |
|
|
2042 | } |
2166 | } |
2043 | |
2167 | |
2044 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2168 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2045 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2169 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2046 | |
2170 | |
2047 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
|
|
2048 | |
|
|
2049 | $hi = $value + 1 if $lo == $hi; |
|
|
2050 | |
|
|
2051 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
|
|
2052 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
|
|
2053 | |
|
|
2054 | $page = int $page * $inner_w / ($hi - $lo); |
|
|
2055 | $value = int +($value - $lo) * $inner_w / ($hi - $lo); |
|
|
2056 | |
|
|
2057 | $w -= $page; |
|
|
2058 | $page &= ~1; |
|
|
2059 | glTranslate $page * 0.5, 0, 0; |
|
|
2060 | $page ||= 2; |
|
|
2061 | |
|
|
2062 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
|
|
2063 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
|
|
2064 | |
|
|
2065 | glEnable GL_TEXTURE_2D; |
2171 | glEnable GL_TEXTURE_2D; |
2066 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2172 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2067 | |
2173 | |
2068 | # draw background |
2174 | # draw background |
2069 | $tex[1]->draw_quad_alpha (0, 0, $w, $h); |
2175 | $tex[1]->draw_quad_alpha (0, 0, 1, 1); |
2070 | |
2176 | |
2071 | # draw handle |
2177 | # draw handle |
2072 | $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h); |
2178 | $tex[0]->draw_quad_alpha ($self->{knob_x}, 0, $self->{knob_w}, 1); |
2073 | |
2179 | |
2074 | glDisable GL_TEXTURE_2D; |
2180 | glDisable GL_TEXTURE_2D; |
2075 | } |
2181 | } |
2076 | |
2182 | |
2077 | ############################################################################# |
2183 | ############################################################################# |
… | |
… | |
2110 | |
2216 | |
2111 | $self->{fontsize} = $fontsize; |
2217 | $self->{fontsize} = $fontsize; |
2112 | $self->reflow; |
2218 | $self->reflow; |
2113 | } |
2219 | } |
2114 | |
2220 | |
|
|
2221 | sub size_allocate { |
|
|
2222 | my ($self, $w, $h) = @_; |
|
|
2223 | |
|
|
2224 | $self->SUPER::size_allocate ($w, $h); |
|
|
2225 | |
|
|
2226 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
|
|
2227 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
2228 | $self->{layout}->set_width ($self->{children}[0]{w}); |
|
|
2229 | |
|
|
2230 | $self->reflow; |
|
|
2231 | } |
|
|
2232 | |
2115 | sub text_height { |
2233 | sub text_height { |
2116 | my ($self, $text) = @_; |
2234 | my ($self, $text, $indent) = @_; |
2117 | |
2235 | |
2118 | my $layout = $self->{layout}; |
2236 | my $layout = $self->{layout}; |
2119 | |
2237 | |
2120 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2238 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2121 | $layout->set_width ($self->{children}[0]{w}); |
2239 | $layout->set_width ($self->{children}[0]{w} - $indent); |
2122 | $layout->set_markup ($text); |
2240 | $layout->set_markup ($text); |
2123 | |
2241 | |
2124 | ($layout->size)[1] |
2242 | ($layout->size)[1] |
2125 | } |
2243 | } |
2126 | |
2244 | |
… | |
… | |
2129 | |
2247 | |
2130 | $self->{need_reflow}++; |
2248 | $self->{need_reflow}++; |
2131 | $self->update; |
2249 | $self->update; |
2132 | } |
2250 | } |
2133 | |
2251 | |
2134 | sub size_allocate { |
|
|
2135 | my ($self, $w, $h) = @_; |
|
|
2136 | |
|
|
2137 | $self->SUPER::size_allocate ($w, $h); |
|
|
2138 | |
|
|
2139 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
|
|
2140 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
2141 | $self->{layout}->set_width ($self->{children}[0]{w}); |
|
|
2142 | |
|
|
2143 | $self->reflow; |
|
|
2144 | } |
|
|
2145 | |
|
|
2146 | sub add_paragraph { |
2252 | sub add_paragraph { |
2147 | my ($self, $color, $text) = @_; |
2253 | my ($self, $color, $text, $indent) = @_; |
2148 | |
2254 | |
2149 | #TODO: intelligently "reformat" paragraph |
2255 | #TODO: intelligently "reformat" paragraph |
2150 | |
2256 | |
|
|
2257 | for my $line (split /\n/, $text) { |
2151 | my $height = $self->text_height ($text); |
2258 | my $height = $self->text_height ($line); |
2152 | |
|
|
2153 | $self->{height} += $height; |
2259 | $self->{height} += $height; |
2154 | |
|
|
2155 | push @{$self->{par}}, [$height, $color, $text]; |
2260 | push @{$self->{par}}, [$height, $color, $indent, $line]; |
|
|
2261 | } |
2156 | |
2262 | |
2157 | $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; |
2263 | $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; |
2158 | $self->{children}[1]->update; |
2264 | $self->{children}[1]->update; |
2159 | } |
2265 | } |
2160 | |
2266 | |
… | |
… | |
2165 | |
2271 | |
2166 | return unless $self->{h} > 0; |
2272 | return unless $self->{h} > 0; |
2167 | |
2273 | |
2168 | delete $self->{texture}; |
2274 | delete $self->{texture}; |
2169 | |
2275 | |
2170 | $ROOT->on_refresh ($self, sub { |
2276 | $ROOT->on_post_alloc ($self, sub { |
2171 | if (delete $self->{need_reflow}) { |
2277 | if (delete $self->{need_reflow}) { |
2172 | my $height = 0; |
2278 | my $height = 0; |
2173 | |
2279 | |
2174 | $height += $_->[0] = $self->text_height ($_->[2]) |
2280 | $height += $_->[0] = $self->text_height ($_->[3], $_->[2]) |
2175 | for @{$self->{par}}; |
2281 | for @{$self->{par}}; |
2176 | |
2282 | |
2177 | $self->{height} = $height; |
2283 | $self->{height} = $height; |
2178 | |
2284 | |
2179 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
2285 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
|
|
2286 | $self->{children}[1]->update; |
2180 | |
2287 | |
2181 | delete $self->{texture}; |
2288 | delete $self->{texture}; |
2182 | } |
2289 | } |
2183 | |
2290 | |
2184 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2291 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2185 | glClearColor 0, 0, 0, 0; |
2292 | glClearColor 0.5, 0.5, 0.5, 0; |
2186 | glClear GL_COLOR_BUFFER_BIT; |
2293 | glClear GL_COLOR_BUFFER_BIT; |
2187 | |
|
|
2188 | glEnable GL_TEXTURE_2D; |
|
|
2189 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2190 | |
2294 | |
2191 | my $top = int $self->{children}[1]{range}[0]; |
2295 | my $top = int $self->{children}[1]{range}[0]; |
2192 | |
2296 | |
2193 | my $y0 = $top; |
2297 | my $y0 = $top; |
2194 | my $y1 = $top + $self->{h}; |
2298 | my $y1 = $top + $self->{h}; |
… | |
… | |
2197 | |
2301 | |
2198 | my $layout = $self->{layout}; |
2302 | my $layout = $self->{layout}; |
2199 | |
2303 | |
2200 | $layout->set_font ($self->{font}) if $self->{font}; |
2304 | $layout->set_font ($self->{font}) if $self->{font}; |
2201 | |
2305 | |
|
|
2306 | glEnable GL_BLEND; |
|
|
2307 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2308 | |
2202 | for my $par (@{$self->{par}}) { |
2309 | for my $par (@{$self->{par}}) { |
2203 | my $h = $par->[0]; |
2310 | my $h = $par->[0]; |
2204 | |
2311 | |
2205 | if ($y0 < $y + $h && $y < $y1) { |
2312 | if ($y0 < $y + $h && $y < $y1) { |
2206 | $layout->set_foreground (@{ $par->[1] }); |
2313 | $layout->set_foreground (@{ $par->[1] }); |
|
|
2314 | $layout->set_width ($self->{w} - $par->[2]); |
2207 | $layout->set_markup ($par->[2]); |
2315 | $layout->set_markup ($par->[3]); |
2208 | |
2316 | |
2209 | my ($W, $H) = $layout->size; |
2317 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
2210 | CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); |
2318 | |
|
|
2319 | glRasterPos $par->[2], $y - $y0; |
|
|
2320 | glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data; |
2211 | } |
2321 | } |
2212 | |
2322 | |
2213 | $y += $h; |
2323 | $y += $h; |
2214 | } |
2324 | } |
2215 | |
2325 | |
2216 | glDisable GL_TEXTURE_2D; |
2326 | glDisable GL_BLEND; |
2217 | }; |
2327 | }; |
2218 | }); |
2328 | }); |
2219 | } |
2329 | } |
2220 | |
2330 | |
2221 | sub _draw { |
2331 | sub _draw { |
2222 | my ($self) = @_; |
2332 | my ($self) = @_; |
2223 | |
2333 | |
2224 | glEnable GL_TEXTURE_2D; |
2334 | glEnable GL_TEXTURE_2D; |
2225 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2335 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2226 | glColor 1, 1, 1, 1; |
2336 | glColor 1, 1, 1, 1; |
2227 | $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2337 | $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2228 | glDisable GL_TEXTURE_2D; |
2338 | glDisable GL_TEXTURE_2D; |
2229 | |
2339 | |
2230 | $self->{children}[1]->draw; |
2340 | $self->{children}[1]->draw; |
2231 | |
2341 | |
2232 | } |
2342 | } |
… | |
… | |
2331 | |
2441 | |
2332 | sub set_tooltip_from { |
2442 | sub set_tooltip_from { |
2333 | my ($self, $widget) = @_; |
2443 | my ($self, $widget) = @_; |
2334 | |
2444 | |
2335 | $self->add (new CFClient::UI::Label |
2445 | $self->add (new CFClient::UI::Label |
2336 | markup => $widget->{tooltip}, |
2446 | markup => $widget->{tooltip}, |
2337 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2447 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2338 | fontsize => 0.8, |
2448 | fontsize => 0.8, |
2339 | fg => [0, 0, 0, 1], |
2449 | fg => [0, 0, 0, 1], |
|
|
2450 | ellipsise => 0, |
2340 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
2451 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
2341 | ); |
2452 | ); |
2342 | } |
2453 | } |
2343 | |
2454 | |
2344 | sub size_request { |
2455 | sub size_request { |
2345 | my ($self) = @_; |
2456 | my ($self) = @_; |
… | |
… | |
2391 | use CFClient::OpenGL; |
2502 | use CFClient::OpenGL; |
2392 | |
2503 | |
2393 | sub new { |
2504 | sub new { |
2394 | my $class = shift; |
2505 | my $class = shift; |
2395 | |
2506 | |
2396 | $class->SUPER::new ( |
2507 | my $self = $class->SUPER::new ( |
2397 | aspect => 1, |
2508 | aspect => 1, |
2398 | @_, |
2509 | @_, |
2399 | ) |
2510 | ); |
|
|
2511 | |
|
|
2512 | if ($self->{anim} && $self->{animspeed}) { |
|
|
2513 | Scalar::Util::weaken (my $widget = $self); |
|
|
2514 | |
|
|
2515 | $self->{timer} = Event->timer ( |
|
|
2516 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
|
|
2517 | hard => 1, |
|
|
2518 | interval => $self->{animspeed}, |
|
|
2519 | cb => sub { |
|
|
2520 | ++$widget->{frame}; |
|
|
2521 | $widget->update; |
|
|
2522 | }, |
|
|
2523 | ); |
|
|
2524 | } |
|
|
2525 | |
|
|
2526 | $self |
2400 | } |
2527 | } |
2401 | |
2528 | |
2402 | sub size_request { |
2529 | sub size_request { |
2403 | (32, 8) |
2530 | (32, 8) |
2404 | } |
2531 | } |
2405 | |
2532 | |
|
|
2533 | sub update { |
|
|
2534 | my ($self) = @_; |
|
|
2535 | |
|
|
2536 | return unless $self->{visible}; |
|
|
2537 | |
|
|
2538 | $self->SUPER::update; |
|
|
2539 | } |
|
|
2540 | |
2406 | sub _draw { |
2541 | sub _draw { |
2407 | my ($self) = @_; |
2542 | my ($self) = @_; |
2408 | |
2543 | |
2409 | return unless $::CONN;#d# manage and cache textures differently |
2544 | return unless $::CONN;#d# manage and cache textures differently |
|
|
2545 | |
|
|
2546 | my $face; |
|
|
2547 | |
|
|
2548 | if ($self->{frame}) { |
|
|
2549 | my $anim = $::CONN->{anim}[$self->{anim}]; |
|
|
2550 | |
|
|
2551 | $face = $anim->[ $self->{frame} % @$anim ] |
|
|
2552 | if $anim && @$anim; |
|
|
2553 | } |
|
|
2554 | |
2410 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2555 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2411 | |
2556 | |
2412 | # TODO animation |
|
|
2413 | if ($tex) { |
2557 | if ($tex) { |
2414 | glEnable GL_TEXTURE_2D; |
2558 | glEnable GL_TEXTURE_2D; |
2415 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2559 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2416 | glColor 1, 1, 1, 1; |
2560 | glColor 1, 1, 1, 1; |
2417 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2561 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2418 | glDisable GL_TEXTURE_2D; |
2562 | glDisable GL_TEXTURE_2D; |
2419 | } |
2563 | } |
2420 | } |
2564 | } |
2421 | |
2565 | |
|
|
2566 | sub DESTROY { |
|
|
2567 | my ($self) = @_; |
|
|
2568 | |
|
|
2569 | $self->{timer}->cancel |
|
|
2570 | if $self->{timer}; |
|
|
2571 | |
|
|
2572 | $self->SUPER::DESTROY; |
|
|
2573 | } |
|
|
2574 | |
2422 | ############################################################################# |
2575 | ############################################################################# |
2423 | |
2576 | |
2424 | package CFClient::UI::InventoryItem; |
2577 | package CFClient::UI::InventoryItem; |
2425 | |
2578 | |
2426 | our @ISA = CFClient::UI::HBox::; |
2579 | our @ISA = CFClient::UI::HBox::; |
|
|
2580 | |
|
|
2581 | sub _item_to_desc { |
|
|
2582 | my ($item) = @_; |
|
|
2583 | |
|
|
2584 | my $desc = |
|
|
2585 | $item->{nrof} < 2 |
|
|
2586 | ? $item->{name} |
|
|
2587 | : "$item->{nrof} × $item->{name_pl}"; |
|
|
2588 | |
|
|
2589 | $item->{flags} & Crossfire::Protocol::F_OPEN |
|
|
2590 | and $desc .= " (open)"; |
|
|
2591 | $item->{flags} & Crossfire::Protocol::F_APPLIED |
|
|
2592 | and $desc .= " (applied)"; |
|
|
2593 | $item->{flags} & Crossfire::Protocol::F_UNPAID |
|
|
2594 | and $desc .= " (unpaid)"; |
|
|
2595 | $item->{flags} & Crossfire::Protocol::F_MAGIC |
|
|
2596 | and $desc .= " (magic)"; |
|
|
2597 | $item->{flags} & Crossfire::Protocol::F_CURSED |
|
|
2598 | and $desc .= " (cursed)"; |
|
|
2599 | $item->{flags} & Crossfire::Protocol::F_DAMNED |
|
|
2600 | and $desc .= " (damned)"; |
|
|
2601 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2602 | and $desc .= " *"; |
|
|
2603 | |
|
|
2604 | $desc |
|
|
2605 | } |
2427 | |
2606 | |
2428 | sub new { |
2607 | sub new { |
2429 | my $class = shift; |
2608 | my $class = shift; |
2430 | |
2609 | |
2431 | my %args = @_; |
2610 | my %args = @_; |
2432 | |
2611 | |
2433 | my $item = delete $args{item}; |
2612 | my $item = delete $args{item}; |
2434 | |
2613 | |
2435 | my $desc = $item->{nrof} < 2 |
2614 | my $desc = _item_to_desc ($item); |
2436 | ? $item->{name} |
|
|
2437 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2438 | |
|
|
2439 | |
2615 | |
2440 | my $self = $class->SUPER::new ( |
2616 | my $self = $class->SUPER::new ( |
2441 | can_hover => 1, |
2617 | can_hover => 1, |
2442 | can_events => 1, |
2618 | can_events => 1, |
2443 | tooltip => (CFClient::UI::Label->escape ($desc) |
2619 | tooltip => ((CFClient::UI::Label::escape $desc) |
2444 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2620 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2445 | connect_button_down => sub { |
2621 | connect_button_down => sub { |
2446 | my ($self, $ev, $x, $y) = @_; |
2622 | my ($self, $ev, $x, $y) = @_; |
2447 | |
2623 | |
2448 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2624 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2449 | if ($ev->{button} == 1) { |
2625 | if ($ev->{button} == 1) { |
|
|
2626 | my $targ = $::CONN->{player}{tag}; |
|
|
2627 | |
|
|
2628 | if ($item->{container} == $::CONN->{player}{tag}) { |
|
|
2629 | $targ = $main::OPENCONT; |
|
|
2630 | } |
|
|
2631 | |
2450 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
2632 | $::CONN->send ("move $targ $item->{tag} 0"); |
2451 | } elsif ($ev->{button} == 2) { |
2633 | } elsif ($ev->{button} == 2) { |
2452 | $::CONN->send ("apply $item->{tag}"); |
2634 | $::CONN->send ("apply $item->{tag}"); |
2453 | } elsif ($ev->{button} == 3) { |
2635 | } elsif ($ev->{button} == 3) { |
2454 | CFClient::UI::Menu->new ( |
2636 | my @menu_items = ( |
2455 | items => [ |
|
|
2456 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2637 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2457 | [ |
|
|
2458 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
|
|
2459 | sub { $::CONN->send ("lock $item->{tag}") }, |
|
|
2460 | ], |
|
|
2461 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
2638 | ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }], |
2462 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
2639 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2640 | ( |
|
|
2641 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2642 | ? ( |
|
|
2643 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }], |
|
|
2644 | ) |
|
|
2645 | : ( |
|
|
2646 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }], |
2463 | ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }], |
2647 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
|
|
2648 | ) |
2464 | ], |
2649 | ), |
2465 | )->popup ($ev); |
2650 | ); |
|
|
2651 | |
|
|
2652 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2466 | } |
2653 | } |
2467 | |
2654 | |
2468 | 1 |
2655 | 1 |
2469 | }, |
2656 | }, |
2470 | %args |
2657 | %args |
2471 | ); |
2658 | ); |
|
|
2659 | |
2472 | |
2660 | |
2473 | $self->add (new CFClient::UI::Face |
2661 | $self->add (new CFClient::UI::Face |
2474 | can_events => 0, |
2662 | can_events => 0, |
2475 | face => $item->{face}, |
2663 | face => $item->{face}, |
2476 | anim => $item->{anim}, |
2664 | anim => $item->{anim}, |
2477 | animspeed => $item->{animspeed}, |
2665 | animspeed => $item->{animspeed}, |
2478 | ); |
2666 | ); |
2479 | |
2667 | |
2480 | $self->add (new CFClient::UI::Label |
2668 | $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0); |
2481 | can_events => 0, |
2669 | |
2482 | text => $desc, |
2670 | $self->{item} = $item; |
2483 | ); |
2671 | |
|
|
2672 | $self->update_item; |
2484 | |
2673 | |
2485 | $self |
2674 | $self |
|
|
2675 | } |
|
|
2676 | |
|
|
2677 | sub update_item { |
|
|
2678 | my ($self) = @_; |
|
|
2679 | |
|
|
2680 | my $desc = _item_to_desc ($self->{item}); |
|
|
2681 | |
|
|
2682 | $self->{name_lbl}->set_text ($desc); |
2486 | } |
2683 | } |
2487 | |
2684 | |
2488 | ############################################################################# |
2685 | ############################################################################# |
2489 | |
2686 | |
2490 | package CFClient::UI::Inventory; |
2687 | package CFClient::UI::Inventory; |
… | |
… | |
2506 | my ($self, $items) = @_; |
2703 | my ($self, $items) = @_; |
2507 | |
2704 | |
2508 | $self->{scrolled}->clear; |
2705 | $self->{scrolled}->clear; |
2509 | return unless $items; |
2706 | return unless $items; |
2510 | |
2707 | |
2511 | my @items = sort { $a->{type} <=> $b->{type} } @$items; |
2708 | my @items = sort { |
|
|
2709 | ($a->{type} <=> $b->{type}) |
|
|
2710 | or ($a->{name} cmp $b->{name}) |
|
|
2711 | } @$items; |
2512 | |
2712 | |
2513 | $self->{real_items} = \@items; |
2713 | $self->{real_items} = \@items; |
2514 | |
2714 | |
2515 | for my $item (@items) { |
2715 | for my $item (@items) { |
2516 | my $desc = $item->{nrof} < 2 |
|
|
2517 | ? $item->{name} |
|
|
2518 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2519 | |
|
|
2520 | $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item); |
2716 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
|
|
2717 | $item->update_item (); |
2521 | } |
2718 | } |
|
|
2719 | |
|
|
2720 | $self->{scrolled}->add (@items); |
2522 | |
2721 | |
2523 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2722 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2524 | } |
2723 | } |
2525 | |
2724 | |
2526 | sub size_request { |
2725 | sub size_request { |
… | |
… | |
2604 | |
2803 | |
2605 | package CFClient::UI::Statusbox; |
2804 | package CFClient::UI::Statusbox; |
2606 | |
2805 | |
2607 | our @ISA = CFClient::UI::VBox::; |
2806 | our @ISA = CFClient::UI::VBox::; |
2608 | |
2807 | |
|
|
2808 | sub new { |
|
|
2809 | my $class = shift; |
|
|
2810 | |
|
|
2811 | $class->SUPER::new ( |
|
|
2812 | fontsize => 0.8, |
|
|
2813 | @_, |
|
|
2814 | ) |
|
|
2815 | } |
|
|
2816 | |
2609 | sub reorder { |
2817 | sub reorder { |
2610 | my ($self) = @_; |
2818 | my ($self) = @_; |
2611 | my $NOW = time; |
2819 | my $NOW = time; |
2612 | |
2820 | |
2613 | while (my ($k, $v) = each %{ $self->{item} }) { |
2821 | while (my ($k, $v) = each %{ $self->{item} }) { |
… | |
… | |
2631 | ? "<b>$item->{count} ×</b> $item->{text}" |
2839 | ? "<b>$item->{count} ×</b> $item->{text}" |
2632 | : $item->{text}; |
2840 | : $item->{text}; |
2633 | |
2841 | |
2634 | for ($short) { |
2842 | for ($short) { |
2635 | s/^\s+//; |
2843 | s/^\s+//; |
2636 | s/\012.*/…/s; |
2844 | s/\s+/ /g; |
2637 | my $len = int 30 / $item->{fontsize}; |
|
|
2638 | substr $_, $len, length, "…" if $len < length; |
|
|
2639 | } |
2845 | } |
2640 | |
2846 | |
2641 | new CFClient::UI::Label |
2847 | new CFClient::UI::Label |
2642 | markup => $short, |
2848 | markup => $short, |
2643 | tooltip => $item->{tooltip}, |
2849 | tooltip => $item->{tooltip}, |
2644 | tooltip_font => $::FONT_PROP, |
2850 | tooltip_font => $::FONT_PROP, |
2645 | tooltip_width => 0.67, |
2851 | tooltip_width => 0.67, |
2646 | fontsize => $item->{fontsize}, |
2852 | fontsize => $item->{fontsize} || $self->{fontsize}, |
|
|
2853 | max_w => $::WIDTH * 0.44, |
2647 | color => $item->{color}, |
2854 | fg => $item->{fg}, |
2648 | can_events => 1, |
2855 | can_events => 1, |
2649 | can_hover => 1 |
2856 | can_hover => 1 |
2650 | }; |
2857 | }; |
2651 | } |
2858 | } |
2652 | |
2859 | |
… | |
… | |
2654 | $self->SUPER::add (reverse @widgets); |
2861 | $self->SUPER::add (reverse @widgets); |
2655 | } |
2862 | } |
2656 | |
2863 | |
2657 | sub add { |
2864 | sub add { |
2658 | my ($self, $text, %arg) = @_; |
2865 | my ($self, $text, %arg) = @_; |
|
|
2866 | |
|
|
2867 | $text =~ s/^\s+//; |
|
|
2868 | $text =~ s/\s+$//; |
2659 | |
2869 | |
2660 | my $timeout = time + ((delete $arg{timeout}) || 60); |
2870 | my $timeout = time + ((delete $arg{timeout}) || 60); |
2661 | |
2871 | |
2662 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
2872 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
2663 | |
2873 | |
… | |
… | |
2666 | $item->{count}++; |
2876 | $item->{count}++; |
2667 | } else { |
2877 | } else { |
2668 | $item->{count} = 1; |
2878 | $item->{count} = 1; |
2669 | $item->{text} = $item->{tooltip} = $text; |
2879 | $item->{text} = $item->{tooltip} = $text; |
2670 | } |
2880 | } |
|
|
2881 | $item->{id} = ++$self->{id}; |
2671 | $item->{timeout} = $timeout; |
2882 | $item->{timeout} = $timeout; |
2672 | delete $item->{label}; |
2883 | delete $item->{label}; |
2673 | } else { |
2884 | } else { |
2674 | $self->{item}{$group} = { |
2885 | $self->{item}{$group} = { |
2675 | id => ++$self->{id}, |
2886 | id => ++$self->{id}, |
2676 | text => $text, |
2887 | text => $text, |
2677 | timeout => $timeout, |
2888 | timeout => $timeout, |
2678 | tooltip => $text, |
2889 | tooltip => $text, |
2679 | fontsize => 0.8, |
|
|
2680 | color => [0.8, 0.8, 0.8, 0.8], |
2890 | fg => [0.8, 0.8, 0.8, 0.8], |
2681 | pri => 0, |
2891 | pri => 0, |
2682 | count => 1, |
2892 | count => 1, |
2683 | %arg, |
2893 | %arg, |
2684 | }; |
2894 | }; |
2685 | } |
2895 | } |
2686 | |
2896 | |
2687 | $self->reorder; |
2897 | $self->reorder; |
2688 | } |
2898 | } |
2689 | |
2899 | |
|
|
2900 | sub reconfigure { |
|
|
2901 | my ($self) = @_; |
|
|
2902 | |
|
|
2903 | delete $_->{label} |
|
|
2904 | for values %{ $self->{item} || {} }; |
|
|
2905 | |
|
|
2906 | $self->reorder; |
|
|
2907 | $self->SUPER::reconfigure; |
|
|
2908 | } |
|
|
2909 | |
2690 | ############################################################################# |
2910 | ############################################################################# |
2691 | |
2911 | |
2692 | package CFClient::UI::Root; |
2912 | package CFClient::UI::Root; |
2693 | |
2913 | |
2694 | our @ISA = CFClient::UI::Container::; |
2914 | our @ISA = CFClient::UI::Container::; |
… | |
… | |
2724 | } |
2944 | } |
2725 | |
2945 | |
2726 | sub size_allocate { |
2946 | sub size_allocate { |
2727 | my ($self, $w, $h) = @_; |
2947 | my ($self, $w, $h) = @_; |
2728 | |
2948 | |
2729 | my $old_w = $self->{old_w}; |
2949 | my $old_w = $self->{old_w}; $self->{old_w} = $w; |
2730 | my $old_h = $self->{old_h}; |
2950 | my $old_h = $self->{old_h}; $self->{old_h} = $h; |
2731 | |
2951 | |
2732 | if ($old_w && $old_h) { |
2952 | CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h |
2733 | for my $child ($self->children) { |
2953 | if $old_w && $old_h && ($old_w != $w || $old_h != $h); |
2734 | $child->{x} = int 0.5 + $child->{x} * $w / $old_w; |
|
|
2735 | $child->{w} = int 0.5 + $child->{w} * $w / $old_w; |
|
|
2736 | $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w}; |
|
|
2737 | $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w}; |
|
|
2738 | $child->{y} = int 0.5 + $child->{y} * $h / $old_h; |
|
|
2739 | $child->{h} = int 0.5 + $child->{h} * $h / $old_h; |
|
|
2740 | $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; |
|
|
2741 | $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h}; |
|
|
2742 | } |
|
|
2743 | } |
|
|
2744 | |
2954 | |
2745 | for my $child ($self->children) { |
2955 | for my $child ($self->children) { |
2746 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2956 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2747 | |
2957 | |
|
|
2958 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
|
|
2959 | if exists $child->{req_x}; |
|
|
2960 | |
|
|
2961 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
|
|
2962 | if exists $child->{req_y}; |
|
|
2963 | |
2748 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2964 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
2749 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2965 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
|
|
2966 | |
2750 | $child->configure ($X, $Y, $W, $H); |
2967 | $child->configure ($X, $Y, $W, $H); |
2751 | } |
2968 | } |
2752 | |
|
|
2753 | $self->{old_w} = $w; |
|
|
2754 | $self->{old_h} = $h; |
|
|
2755 | } |
2969 | } |
2756 | |
2970 | |
2757 | sub coord2local { |
2971 | sub coord2local { |
2758 | my ($self, $x, $y) = @_; |
2972 | my ($self, $x, $y) = @_; |
2759 | |
2973 | |
… | |
… | |
2772 | $self->check_size; |
2986 | $self->check_size; |
2773 | $::WANT_REFRESH++; |
2987 | $::WANT_REFRESH++; |
2774 | } |
2988 | } |
2775 | |
2989 | |
2776 | sub add { |
2990 | sub add { |
2777 | my ($self, $child) = @_; |
2991 | my ($self, @children) = @_; |
2778 | |
2992 | |
|
|
2993 | for my $child (@children) { |
|
|
2994 | $child->{toplevel} = 1; |
|
|
2995 | |
2779 | # integerise window positions |
2996 | # integerise window positions |
2780 | $child->{x} = int $child->{x}; |
2997 | $child->{x} = int $child->{x}; |
2781 | $child->{y} = int $child->{y}; |
2998 | $child->{y} = int $child->{y}; |
|
|
2999 | } |
2782 | |
3000 | |
2783 | $self->SUPER::add ($child); |
3001 | $self->SUPER::add (@children); |
|
|
3002 | |
|
|
3003 | while (@children) { |
|
|
3004 | my $w = pop @children; |
|
|
3005 | push @children, $w->children; |
|
|
3006 | $w->{visible} = 1; |
|
|
3007 | } |
|
|
3008 | } |
|
|
3009 | |
|
|
3010 | sub remove { |
|
|
3011 | my ($self, @children) = @_; |
|
|
3012 | |
|
|
3013 | $self->SUPER::remove (@children); |
|
|
3014 | |
|
|
3015 | while (@children) { |
|
|
3016 | my $w = pop @children; |
|
|
3017 | push @children, $w->children; |
|
|
3018 | delete $w->{visible}; |
|
|
3019 | } |
2784 | } |
3020 | } |
2785 | |
3021 | |
2786 | sub on_refresh { |
3022 | sub on_refresh { |
2787 | my ($self, $id, $cb) = @_; |
3023 | my ($self, $id, $cb) = @_; |
2788 | |
3024 | |
2789 | $self->{refresh_hook}{$id} = $cb; |
3025 | $self->{refresh_hook}{$id} = $cb; |
2790 | } |
3026 | } |
2791 | |
3027 | |
|
|
3028 | sub on_post_alloc { |
|
|
3029 | my ($self, $id, $cb) = @_; |
|
|
3030 | |
|
|
3031 | $self->{post_alloc_hook}{$id} = $cb; |
|
|
3032 | } |
|
|
3033 | |
2792 | sub draw { |
3034 | sub draw { |
2793 | my ($self) = @_; |
3035 | my ($self) = @_; |
|
|
3036 | |
|
|
3037 | while ($self->{refresh_hook}) { |
|
|
3038 | $_->() |
|
|
3039 | for values %{delete $self->{refresh_hook}}; |
|
|
3040 | } |
2794 | |
3041 | |
2795 | if ($self->{check_size}) { |
3042 | if ($self->{check_size}) { |
2796 | my @queue = ([], []); |
3043 | my @queue = ([], []); |
2797 | |
3044 | |
2798 | for (;;) { |
3045 | for (;;) { |
… | |
… | |
2835 | $widget->size_allocate ($w, $h); |
3082 | $widget->size_allocate ($w, $h); |
2836 | $widget->emit (size_allocate => $w, $h); |
3083 | $widget->emit (size_allocate => $w, $h); |
2837 | } |
3084 | } |
2838 | } |
3085 | } |
2839 | |
3086 | |
2840 | while ($self->{refresh_hook}) { |
3087 | while ($self->{post_alloc_hook}) { |
2841 | $_->() |
3088 | $_->() |
2842 | for values %{delete $self->{refresh_hook}}; |
3089 | for values %{delete $self->{post_alloc_hook}}; |
2843 | } |
3090 | } |
2844 | |
3091 | |
2845 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
3092 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
2846 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
3093 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
2847 | glClear GL_COLOR_BUFFER_BIT; |
3094 | glClear GL_COLOR_BUFFER_BIT; |
2848 | |
3095 | |
2849 | glMatrixMode GL_PROJECTION; |
3096 | glMatrixMode GL_PROJECTION; |
2850 | glLoadIdentity; |
3097 | glLoadIdentity; |
2851 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; |
3098 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
2852 | glMatrixMode GL_MODELVIEW; |
3099 | glMatrixMode GL_MODELVIEW; |
2853 | glLoadIdentity; |
3100 | glLoadIdentity; |
2854 | |
3101 | |
2855 | $self->_draw; |
3102 | $self->_draw; |
2856 | } |
3103 | } |
… | |
… | |
2858 | ############################################################################# |
3105 | ############################################################################# |
2859 | |
3106 | |
2860 | package CFClient::UI; |
3107 | package CFClient::UI; |
2861 | |
3108 | |
2862 | $ROOT = new CFClient::UI::Root; |
3109 | $ROOT = new CFClient::UI::Root; |
2863 | $TOOLTIP = new CFClient::UI::Tooltip; |
3110 | $TOOLTIP = new CFClient::UI::Tooltip z => 900; |
2864 | |
3111 | |
2865 | 1 |
3112 | 1 |
2866 | |
3113 | |