1 | package CFPlus::UI; |
1 | package DC::UI; |
2 | |
2 | |
3 | use utf8; |
3 | use utf8; |
4 | use strict; |
4 | use strict; |
5 | |
5 | |
6 | use List::Util (); |
6 | use List::Util (); |
7 | use Event; |
|
|
8 | |
7 | |
9 | use CFPlus; |
8 | use Guard (); |
|
|
9 | |
|
|
10 | use DC; |
10 | use CFPlus::Pod; |
11 | use DC::Pod; |
11 | use CFPlus::Texture; |
12 | use DC::Texture; |
12 | |
13 | |
13 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
14 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
14 | |
15 | |
15 | our $LAYOUT; |
16 | our $LAYOUT; |
16 | our $ROOT; |
17 | our $ROOT; |
17 | our $TOOLTIP; |
18 | our $TOOLTIP; |
18 | our $BUTTON_STATE; |
19 | our $BUTTON_STATE; |
19 | |
20 | |
20 | our %WIDGET; # all widgets, weak-referenced |
21 | our %WIDGET; # all widgets, weak-referenced |
21 | |
22 | |
22 | our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { |
23 | our $TOOLTIP_WATCHER = EV::timer_ns 0, 0.03, sub { |
|
|
24 | $_[0]->stop; |
|
|
25 | |
23 | if (!$GRAB) { |
26 | if (!$GRAB) { |
24 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
27 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
25 | if (length $widget->{tooltip}) { |
28 | if (length $widget->{tooltip}) { |
26 | if ($TOOLTIP->{owner} != $widget) { |
29 | if ($TOOLTIP->{owner} != $widget) { |
27 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
30 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
… | |
… | |
42 | } |
45 | } |
43 | |
46 | |
44 | $TOOLTIP->hide; |
47 | $TOOLTIP->hide; |
45 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
48 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
46 | delete $TOOLTIP->{owner}; |
49 | delete $TOOLTIP->{owner}; |
47 | }); |
50 | }; |
48 | |
51 | |
49 | sub get_layout { |
52 | sub get_layout { |
50 | my $layout; |
53 | my $layout; |
51 | |
54 | |
52 | for (grep { $_->{name} } values %WIDGET) { |
55 | for (grep { $_->{name} } values %WIDGET) { |
… | |
… | |
87 | my $hover = $HOVER; $HOVER = $widget; |
90 | my $hover = $HOVER; $HOVER = $widget; |
88 | |
91 | |
89 | $hover->update if $hover && $hover->{can_hover}; |
92 | $hover->update if $hover && $hover->{can_hover}; |
90 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
93 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
91 | |
94 | |
92 | $TOOLTIP_WATCHER->start; |
95 | $TOOLTIP_WATCHER->again; |
93 | } |
96 | } |
94 | } |
97 | } |
95 | |
98 | |
96 | sub feed_sdl_button_down_event { |
99 | sub feed_sdl_button_down_event { |
97 | my ($ev) = @_; |
100 | my ($ev) = @_; |
… | |
… | |
103 | my $widget = $ROOT->find_widget ($x, $y); |
106 | my $widget = $ROOT->find_widget ($x, $y); |
104 | |
107 | |
105 | $GRAB = $widget; |
108 | $GRAB = $widget; |
106 | $GRAB->update if $GRAB; |
109 | $GRAB->update if $GRAB; |
107 | |
110 | |
108 | $TOOLTIP_WATCHER->cb->(); |
111 | $TOOLTIP_WATCHER->invoke; |
109 | } |
112 | } |
110 | |
113 | |
111 | if ($GRAB) { |
114 | if ($GRAB) { |
112 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
115 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
113 | # mousewheel |
116 | # mousewheel |
114 | my $delta = $ev->{button} * 2 - 9; |
117 | my $delta = $ev->{button} * 2 - 9; |
115 | my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT; |
118 | my $shift = $ev->{mod} & DC::KMOD_SHIFT; |
116 | |
119 | |
117 | $ev->{dx} = $shift ? $delta : 0; |
120 | $ev->{dx} = $shift ? $delta : 0; |
118 | $ev->{dy} = $shift ? 0 : $delta; |
121 | $ev->{dy} = $shift ? 0 : $delta; |
119 | |
122 | |
120 | $GRAB->emit (mouse_wheel => $ev); |
123 | $GRAB->emit (mouse_wheel => $ev); |
… | |
… | |
138 | my $grab = $GRAB; undef $GRAB; |
141 | my $grab = $GRAB; undef $GRAB; |
139 | $grab->update if $grab; |
142 | $grab->update if $grab; |
140 | $GRAB->update if $GRAB; |
143 | $GRAB->update if $GRAB; |
141 | |
144 | |
142 | check_hover $widget; |
145 | check_hover $widget; |
143 | $TOOLTIP_WATCHER->cb->(); |
146 | $TOOLTIP_WATCHER->invoke; |
144 | } |
147 | } |
145 | } |
148 | } |
146 | |
149 | |
147 | sub feed_sdl_motion_event { |
150 | sub feed_sdl_motion_event { |
148 | my ($ev) = @_; |
151 | my ($ev) = @_; |
… | |
… | |
188 | # call when resolution changes etc. |
191 | # call when resolution changes etc. |
189 | sub rescale_widgets { |
192 | sub rescale_widgets { |
190 | my ($sx, $sy) = @_; |
193 | my ($sx, $sy) = @_; |
191 | |
194 | |
192 | for my $widget (values %WIDGET) { |
195 | for my $widget (values %WIDGET) { |
193 | if ($widget->{is_toplevel}) { |
196 | if ($widget->{is_toplevel} || $widget->{c_rescale}) { |
194 | $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
197 | $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
195 | $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
198 | $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
196 | |
199 | |
197 | $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; |
200 | $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; |
198 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
201 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
… | |
… | |
210 | reconfigure_widgets; |
213 | reconfigure_widgets; |
211 | } |
214 | } |
212 | |
215 | |
213 | ############################################################################# |
216 | ############################################################################# |
214 | |
217 | |
215 | package CFPlus::UI::Event; |
218 | package DC::UI::Event; |
216 | |
219 | |
217 | sub xy { |
220 | sub xy { |
218 | $_[1]->coord2local ($_[0]{x}, $_[0]{y}) |
221 | $_[1]->coord2local ($_[0]{x}, $_[0]{y}) |
219 | } |
222 | } |
220 | |
223 | |
221 | ############################################################################# |
224 | ############################################################################# |
222 | |
225 | |
223 | package CFPlus::UI::Base; |
226 | package DC::UI::Base; |
224 | |
227 | |
225 | use strict; |
228 | use strict; |
226 | |
229 | |
227 | use CFPlus::OpenGL; |
230 | use DC::OpenGL; |
228 | |
231 | |
229 | sub new { |
232 | sub new { |
230 | my $class = shift; |
233 | my $class = shift; |
231 | |
234 | |
232 | my $self = bless { |
235 | my $self = bless { |
… | |
… | |
237 | h => undef, |
240 | h => undef, |
238 | can_events => 1, |
241 | can_events => 1, |
239 | @_ |
242 | @_ |
240 | }, $class; |
243 | }, $class; |
241 | |
244 | |
242 | CFPlus::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); |
245 | DC::weaken ($DC::UI::WIDGET{$self+0} = $self); |
243 | |
246 | |
244 | for (keys %$self) { |
247 | for (keys %$self) { |
245 | if (/^on_(.*)$/) { |
248 | if (/^on_(.*)$/) { |
246 | $self->connect ($1 => delete $self->{$_}); |
249 | $self->connect ($1 => delete $self->{$_}); |
247 | } |
250 | } |
248 | } |
251 | } |
249 | |
252 | |
250 | if (my $layout = $CFPlus::UI::LAYOUT->{$self->{name}}) { |
253 | if (my $layout = $DC::UI::LAYOUT->{$self->{name}}) { |
251 | $self->{x} = $layout->{x} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{x}; |
254 | $self->{x} = $layout->{x} * $DC::UI::ROOT->{alloc_w} if exists $layout->{x}; |
252 | $self->{y} = $layout->{y} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{y}; |
255 | $self->{y} = $layout->{y} * $DC::UI::ROOT->{alloc_h} if exists $layout->{y}; |
253 | $self->{force_w} = $layout->{w} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{w}; |
256 | $self->{force_w} = $layout->{w} * $DC::UI::ROOT->{alloc_w} if exists $layout->{w}; |
254 | $self->{force_h} = $layout->{h} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{h}; |
257 | $self->{force_h} = $layout->{h} * $DC::UI::ROOT->{alloc_h} if exists $layout->{h}; |
255 | |
258 | |
256 | $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; |
259 | $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; |
257 | $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; |
260 | $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; |
258 | |
261 | |
259 | $self->show if $layout->{show}; |
262 | $self->show if $layout->{show}; |
… | |
… | |
277 | sub show { |
280 | sub show { |
278 | my ($self) = @_; |
281 | my ($self) = @_; |
279 | |
282 | |
280 | return if $self->{parent}; |
283 | return if $self->{parent}; |
281 | |
284 | |
282 | $CFPlus::UI::ROOT->add ($self); |
285 | $DC::UI::ROOT->add ($self); |
283 | } |
286 | } |
284 | |
287 | |
285 | sub set_visible { |
288 | sub set_visible { |
286 | my ($self) = @_; |
289 | my ($self) = @_; |
287 | |
290 | |
288 | return if $self->{visible}; |
291 | return if $self->{visible}; |
|
|
292 | |
|
|
293 | $self->{parent} && $self->{parent}{root}#d# |
|
|
294 | or return ::clienterror ("set_visible called without parent ($self->{parent}) or root\n" => 1); |
289 | |
295 | |
290 | $self->{root} = $self->{parent}{root}; |
296 | $self->{root} = $self->{parent}{root}; |
291 | $self->{visible} = $self->{parent}{visible} + 1; |
297 | $self->{visible} = $self->{parent}{visible} + 1; |
292 | |
298 | |
293 | $self->emit (visibility_change => 1); |
299 | $self->emit (visibility_change => 1); |
294 | |
300 | |
295 | $self->realloc if !exists $self->{req_w}; |
301 | $self->realloc if !exists $self->{req_w}; |
296 | |
302 | |
297 | $_->set_visible for $self->children; |
303 | $_->set_visible for $self->visible_children; |
298 | } |
304 | } |
299 | |
305 | |
300 | sub set_invisible { |
306 | sub set_invisible { |
301 | my ($self) = @_; |
307 | my ($self) = @_; |
302 | |
308 | |
… | |
… | |
308 | delete $self->{root}; |
314 | delete $self->{root}; |
309 | |
315 | |
310 | undef $GRAB if $GRAB == $self; |
316 | undef $GRAB if $GRAB == $self; |
311 | undef $HOVER if $HOVER == $self; |
317 | undef $HOVER if $HOVER == $self; |
312 | |
318 | |
313 | $CFPlus::UI::TOOLTIP_WATCHER->cb->() |
319 | $DC::UI::TOOLTIP_WATCHER->invoke |
314 | if $TOOLTIP->{owner} == $self; |
320 | if $TOOLTIP->{owner} == $self; |
315 | |
321 | |
316 | $self->emit ("focus_out"); |
322 | $self->emit ("focus_out"); |
317 | $self->emit (visibility_change => 0); |
323 | $self->emit (visibility_change => 0); |
318 | } |
324 | } |
… | |
… | |
337 | sub hide { |
343 | sub hide { |
338 | my ($self) = @_; |
344 | my ($self) = @_; |
339 | |
345 | |
340 | $self->set_invisible; |
346 | $self->set_invisible; |
341 | |
347 | |
|
|
348 | # extra $parent copy for 5.8.8+ bug workaround |
|
|
349 | # (otherwise $_[0] in remove gets freed |
|
|
350 | if (my $parent = $self->{parent}) { |
342 | $self->{parent}->remove ($self) |
351 | $parent->remove ($self); |
343 | if $self->{parent}; |
352 | } |
344 | } |
353 | } |
345 | |
354 | |
346 | sub move_abs { |
355 | sub move_abs { |
347 | my ($self, $x, $y, $z) = @_; |
356 | my ($self, $x, $y, $z) = @_; |
348 | |
357 | |
… | |
… | |
360 | $self->{force_h} = $h; |
369 | $self->{force_h} = $h; |
361 | |
370 | |
362 | $self->realloc; |
371 | $self->realloc; |
363 | } |
372 | } |
364 | |
373 | |
|
|
374 | # traverse the widget chain up to find the maximum "physical" size constraints |
|
|
375 | sub get_max_wh { |
|
|
376 | my ($self) = @_; |
|
|
377 | |
|
|
378 | my ($w, $h) = @$self{qw(max_w max_h)}; |
|
|
379 | |
|
|
380 | if ($w <= 0 || $h <= 0) { |
|
|
381 | my ($mw, $mh) = $self->{parent} |
|
|
382 | ? $self->{parent}->get_max_wh |
|
|
383 | : ($::WIDTH, $::HEIGHT); |
|
|
384 | |
|
|
385 | $w = $mw if $w <= 0; |
|
|
386 | $h = $mh if $h <= 0; |
|
|
387 | } |
|
|
388 | |
|
|
389 | ($w, $h) |
|
|
390 | } |
|
|
391 | |
365 | sub size_request { |
392 | sub size_request { |
366 | require Carp; |
393 | require Carp; |
367 | Carp::confess "size_request is abstract"; |
394 | Carp::confess "size_request is abstract"; |
368 | } |
395 | } |
369 | |
396 | |
… | |
… | |
375 | my ($self, $x, $y, $w, $h) = @_; |
402 | my ($self, $x, $y, $w, $h) = @_; |
376 | |
403 | |
377 | if ($self->{aspect}) { |
404 | if ($self->{aspect}) { |
378 | my ($ow, $oh) = ($w, $h); |
405 | my ($ow, $oh) = ($w, $h); |
379 | |
406 | |
380 | $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect}; |
407 | $w = List::Util::min $w, DC::ceil $h * $self->{aspect}; |
381 | $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect}; |
408 | $h = List::Util::min $h, DC::ceil $w / $self->{aspect}; |
382 | |
409 | |
383 | # use alignment to adjust x, y |
410 | # use alignment to adjust x, y |
384 | |
411 | |
385 | $x += int 0.5 * ($ow - $w); |
412 | $x += int 0.5 * ($ow - $w); |
386 | $y += int 0.5 * ($oh - $h); |
413 | $y += int 0.5 * ($oh - $h); |
… | |
… | |
427 | |
454 | |
428 | return if $self->{tooltip} eq $tooltip; |
455 | return if $self->{tooltip} eq $tooltip; |
429 | |
456 | |
430 | $self->{tooltip} = $tooltip; |
457 | $self->{tooltip} = $tooltip; |
431 | |
458 | |
432 | if ($CFPlus::UI::TOOLTIP->{owner} == $self) { |
459 | if ($DC::UI::TOOLTIP->{owner} == $self) { |
433 | delete $CFPlus::UI::TOOLTIP->{owner}; |
460 | delete $DC::UI::TOOLTIP->{owner}; |
434 | $CFPlus::UI::TOOLTIP_WATCHER->cb->(); |
461 | $DC::UI::TOOLTIP_WATCHER->invoke; |
435 | } |
462 | } |
436 | } |
463 | } |
437 | |
464 | |
438 | # translate global coordinates to local coordinate system |
465 | # translate global coordinates to local coordinate system |
439 | sub coord2local { |
466 | sub coord2local { |
440 | my ($self, $x, $y) = @_; |
467 | my ($self, $x, $y) = @_; |
441 | |
468 | |
442 | Carp::confess unless $self->{parent};#d# |
469 | return (undef, undef) unless $self->{parent}; |
443 | |
470 | |
444 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
471 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
445 | } |
472 | } |
446 | |
473 | |
447 | # translate local coordinates to global coordinate system |
474 | # translate local coordinates to global coordinate system |
448 | sub coord2global { |
475 | sub coord2global { |
449 | my ($self, $x, $y) = @_; |
476 | my ($self, $x, $y) = @_; |
450 | |
477 | |
451 | Carp::confess unless $self->{parent};#d# |
478 | return (undef, undef) unless $self->{parent}; |
452 | |
479 | |
453 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
480 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
454 | } |
481 | } |
455 | |
482 | |
456 | sub invoke_focus_in { |
483 | sub invoke_focus_in { |
… | |
… | |
505 | sub connect { |
532 | sub connect { |
506 | my ($self, $signal, $cb) = @_; |
533 | my ($self, $signal, $cb) = @_; |
507 | |
534 | |
508 | push @{ $self->{signal_cb}{$signal} }, $cb; |
535 | push @{ $self->{signal_cb}{$signal} }, $cb; |
509 | |
536 | |
510 | defined wantarray and CFPlus::guard { |
537 | defined wantarray and Guard::guard { |
511 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
538 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
512 | @{ $self->{signal_cb}{$signal} }; |
539 | @{ $self->{signal_cb}{$signal} }; |
513 | } |
540 | } |
514 | } |
541 | } |
515 | |
542 | |
… | |
… | |
553 | # in .xs |
580 | # in .xs |
554 | |
581 | |
555 | sub set_parent { |
582 | sub set_parent { |
556 | my ($self, $parent) = @_; |
583 | my ($self, $parent) = @_; |
557 | |
584 | |
558 | CFPlus::weaken ($self->{parent} = $parent); |
585 | DC::weaken ($self->{parent} = $parent); |
559 | $self->set_visible if $parent->{visible}; |
586 | $self->set_visible if $parent->{visible}; |
560 | } |
587 | } |
561 | |
588 | |
562 | sub realloc { |
589 | sub realloc { |
563 | my ($self) = @_; |
590 | my ($self) = @_; |
… | |
… | |
601 | } |
628 | } |
602 | |
629 | |
603 | sub DESTROY { |
630 | sub DESTROY { |
604 | my ($self) = @_; |
631 | my ($self) = @_; |
605 | |
632 | |
606 | return if CFPlus::in_destruct; |
633 | return if DC::in_destruct; |
607 | |
634 | |
608 | local $@; |
635 | local $@; |
609 | eval { $self->destroy }; |
636 | eval { $self->destroy }; |
610 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
637 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
611 | |
638 | |
612 | delete $WIDGET{$self+0}; |
639 | delete $WIDGET{$self+0}; |
613 | } |
640 | } |
614 | |
641 | |
615 | ############################################################################# |
642 | ############################################################################# |
616 | |
643 | |
617 | package CFPlus::UI::DrawBG; |
644 | package DC::UI::DrawBG; |
618 | |
645 | |
619 | our @ISA = CFPlus::UI::Base::; |
646 | our @ISA = DC::UI::Base::; |
620 | |
647 | |
621 | use strict; |
648 | use strict; |
622 | use CFPlus::OpenGL; |
649 | use DC::OpenGL; |
623 | |
650 | |
624 | sub new { |
651 | sub new { |
625 | my $class = shift; |
652 | my $class = shift; |
626 | |
653 | |
627 | $class->SUPER::new ( |
654 | $class->SUPER::new ( |
… | |
… | |
629 | #active_bg => [1, 1, 1, 0.5], |
656 | #active_bg => [1, 1, 1, 0.5], |
630 | @_ |
657 | @_ |
631 | ) |
658 | ) |
632 | } |
659 | } |
633 | |
660 | |
|
|
661 | sub set_bg { |
|
|
662 | my ($self, $bg) = @_; |
|
|
663 | |
|
|
664 | $self->{bg} = $bg; |
|
|
665 | $self->update; |
|
|
666 | } |
|
|
667 | |
634 | sub _draw { |
668 | sub _draw { |
635 | my ($self) = @_; |
669 | my ($self) = @_; |
636 | |
670 | |
637 | my $color = $FOCUS == $self && $self->{active_bg} |
671 | my $color = $FOCUS == $self && $self->{active_bg} |
638 | ? $self->{active_bg} |
672 | ? $self->{active_bg} |
… | |
… | |
649 | } |
683 | } |
650 | } |
684 | } |
651 | |
685 | |
652 | ############################################################################# |
686 | ############################################################################# |
653 | |
687 | |
654 | package CFPlus::UI::Empty; |
688 | package DC::UI::Empty; |
655 | |
689 | |
656 | our @ISA = CFPlus::UI::Base::; |
690 | our @ISA = DC::UI::Base::; |
657 | |
691 | |
658 | sub new { |
692 | sub new { |
659 | my ($class, %arg) = @_; |
693 | my ($class, %arg) = @_; |
660 | $class->SUPER::new (can_events => 0, %arg); |
694 | $class->SUPER::new (can_events => 0, %arg); |
661 | } |
695 | } |
… | |
… | |
668 | |
702 | |
669 | sub draw { } |
703 | sub draw { } |
670 | |
704 | |
671 | ############################################################################# |
705 | ############################################################################# |
672 | |
706 | |
673 | package CFPlus::UI::Container; |
707 | package DC::UI::Container; |
674 | |
708 | |
675 | our @ISA = CFPlus::UI::Base::; |
709 | our @ISA = DC::UI::Base::; |
676 | |
710 | |
677 | sub new { |
711 | sub new { |
678 | my ($class, %arg) = @_; |
712 | my ($class, %arg) = @_; |
679 | |
713 | |
680 | my $children = delete $arg{children}; |
714 | my $children = delete $arg{children}; |
… | |
… | |
774 | $_->draw for $self->visible_children; |
808 | $_->draw for $self->visible_children; |
775 | } |
809 | } |
776 | |
810 | |
777 | ############################################################################# |
811 | ############################################################################# |
778 | |
812 | |
779 | package CFPlus::UI::Bin; |
813 | package DC::UI::Bin; |
780 | |
814 | |
781 | our @ISA = CFPlus::UI::Container::; |
815 | our @ISA = DC::UI::Container::; |
782 | |
816 | |
783 | sub new { |
817 | sub new { |
784 | my ($class, %arg) = @_; |
818 | my ($class, %arg) = @_; |
785 | |
819 | |
786 | my $child = (delete $arg{child}) || new CFPlus::UI::Empty::; |
820 | my $child = (delete $arg{child}) || new DC::UI::Empty::; |
787 | |
821 | |
788 | $class->SUPER::new (children => [$child], %arg) |
822 | $class->SUPER::new (children => [$child], %arg) |
789 | } |
823 | } |
790 | |
824 | |
791 | sub add { |
825 | sub add { |
… | |
… | |
798 | sub remove { |
832 | sub remove { |
799 | my ($self, $widget) = @_; |
833 | my ($self, $widget) = @_; |
800 | |
834 | |
801 | $self->SUPER::remove ($widget); |
835 | $self->SUPER::remove ($widget); |
802 | |
836 | |
803 | $self->{children} = [new CFPlus::UI::Empty] |
837 | $self->{children} = [new DC::UI::Empty] |
804 | unless @{$self->{children}}; |
838 | unless @{$self->{children}}; |
805 | } |
839 | } |
806 | |
840 | |
807 | sub child { $_[0]->{children}[0] } |
841 | sub child { $_[0]->{children}[0] } |
808 | |
842 | |
… | |
… | |
817 | |
851 | |
818 | 1 |
852 | 1 |
819 | } |
853 | } |
820 | |
854 | |
821 | ############################################################################# |
855 | ############################################################################# |
822 | |
|
|
823 | # back-buffered drawing area |
856 | # back-buffered drawing area |
824 | |
857 | |
825 | package CFPlus::UI::Window; |
858 | package DC::UI::Window; |
826 | |
859 | |
827 | our @ISA = CFPlus::UI::Bin::; |
860 | our @ISA = DC::UI::Bin::; |
828 | |
861 | |
829 | use CFPlus::OpenGL; |
862 | use DC::OpenGL; |
830 | |
863 | |
831 | sub new { |
864 | sub new { |
832 | my ($class, %arg) = @_; |
865 | my ($class, %arg) = @_; |
833 | |
866 | |
834 | my $self = $class->SUPER::new (%arg); |
867 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
856 | } |
889 | } |
857 | |
890 | |
858 | sub render_child { |
891 | sub render_child { |
859 | my ($self) = @_; |
892 | my ($self) = @_; |
860 | |
893 | |
861 | $self->{texture} = new_from_opengl CFPlus::Texture $self->{w}, $self->{h}, sub { |
894 | $self->{texture} = new_from_opengl DC::Texture $self->{w}, $self->{h}, sub { |
862 | glClearColor 0, 0, 0, 0; |
895 | glClearColor 0, 0, 0, 0; |
863 | glClear GL_COLOR_BUFFER_BIT; |
896 | glClear GL_COLOR_BUFFER_BIT; |
864 | |
897 | |
865 | { |
898 | { |
866 | package CFPlus::UI::Base; |
899 | package DC::UI::Base; |
867 | |
900 | |
868 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
901 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
869 | (0, 0, $self->{w}, $self->{h}); |
902 | (0, 0, $self->{w}, $self->{h}); |
870 | |
903 | |
871 | $self->_render; |
904 | $self->_render; |
… | |
… | |
888 | glDisable GL_TEXTURE_2D; |
921 | glDisable GL_TEXTURE_2D; |
889 | } |
922 | } |
890 | |
923 | |
891 | ############################################################################# |
924 | ############################################################################# |
892 | |
925 | |
893 | package CFPlus::UI::ViewPort; |
926 | package DC::UI::ViewPort; |
894 | |
927 | |
895 | use List::Util qw(min max); |
928 | use List::Util qw(min max); |
896 | |
929 | |
897 | our @ISA = CFPlus::UI::Window::; |
930 | our @ISA = DC::UI::Window::; |
898 | |
931 | |
899 | sub new { |
932 | sub new { |
900 | my $class = shift; |
933 | my $class = shift; |
901 | |
934 | |
902 | $class->SUPER::new ( |
935 | $class->SUPER::new ( |
… | |
… | |
986 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
1019 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
987 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
1020 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
988 | ) { |
1021 | ) { |
989 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
1022 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
990 | } else { |
1023 | } else { |
991 | $self->CFPlus::UI::Base::find_widget ($x, $y) |
1024 | $self->DC::UI::Base::find_widget ($x, $y) |
992 | } |
1025 | } |
993 | } |
1026 | } |
994 | |
1027 | |
995 | sub _render { |
1028 | sub _render { |
996 | my ($self) = @_; |
1029 | my ($self) = @_; |
997 | |
1030 | |
998 | local $CFPlus::UI::Base::draw_x = $CFPlus::UI::Base::draw_x - $self->{view_x}; |
1031 | local $DC::UI::Base::draw_x = $DC::UI::Base::draw_x - $self->{view_x}; |
999 | local $CFPlus::UI::Base::draw_y = $CFPlus::UI::Base::draw_y - $self->{view_y}; |
1032 | local $DC::UI::Base::draw_y = $DC::UI::Base::draw_y - $self->{view_y}; |
1000 | |
1033 | |
1001 | CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
1034 | DC::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
1002 | |
1035 | |
1003 | $self->SUPER::_render; |
1036 | $self->SUPER::_render; |
1004 | } |
1037 | } |
1005 | |
1038 | |
1006 | ############################################################################# |
1039 | ############################################################################# |
1007 | |
1040 | |
1008 | package CFPlus::UI::ScrolledWindow; |
1041 | package DC::UI::ScrolledWindow; |
1009 | |
1042 | |
1010 | our @ISA = CFPlus::UI::Table::; |
1043 | our @ISA = DC::UI::Table::; |
1011 | |
1044 | |
1012 | sub new { |
1045 | sub new { |
1013 | my ($class, %arg) = @_; |
1046 | my ($class, %arg) = @_; |
1014 | |
1047 | |
1015 | my $child = delete $arg{child}; |
1048 | my $child = delete $arg{child}; |
1016 | |
1049 | |
1017 | my $self; |
1050 | my $self; |
1018 | |
1051 | |
1019 | my $hslider = new CFPlus::UI::Slider |
1052 | my $hslider = new DC::UI::Slider |
1020 | c_col => 0, |
1053 | c_col => 0, |
1021 | c_row => 1, |
1054 | c_row => 1, |
1022 | vertical => 0, |
1055 | vertical => 0, |
1023 | range => [0, 0, 1, 0.01], # HACK fix |
1056 | range => [0, 0, 1, 0.01], # HACK fix |
1024 | on_changed => sub { |
1057 | on_changed => sub { |
1025 | $self->{hpos} = $_[1]; |
1058 | $self->{hpos} = $_[1]; |
1026 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1059 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1027 | }, |
1060 | }, |
1028 | ; |
1061 | ; |
1029 | |
1062 | |
1030 | my $vslider = new CFPlus::UI::Slider |
1063 | my $vslider = new DC::UI::Slider |
1031 | c_col => 1, |
1064 | c_col => 1, |
1032 | c_row => 0, |
1065 | c_row => 0, |
1033 | vertical => 1, |
1066 | vertical => 1, |
1034 | range => [0, 0, 1, 0.01], # HACK fix |
1067 | range => [0, 0, 1, 0.01], # HACK fix |
1035 | on_changed => sub { |
1068 | on_changed => sub { |
… | |
… | |
1047 | col_expand => [1, 0], |
1080 | col_expand => [1, 0], |
1048 | row_expand => [1, 0], |
1081 | row_expand => [1, 0], |
1049 | %arg, |
1082 | %arg, |
1050 | ); |
1083 | ); |
1051 | |
1084 | |
1052 | $self->{vp} = new CFPlus::UI::ViewPort |
1085 | $self->{vp} = new DC::UI::ViewPort |
1053 | c_col => 0, |
1086 | c_col => 0, |
1054 | c_row => 0, |
1087 | c_row => 0, |
1055 | expand => 1, |
1088 | expand => 1, |
1056 | scroll_x => $self->{scroll_x}, |
1089 | scroll_x => $self->{scroll_x}, |
1057 | scroll_y => $self->{scroll_y}, |
1090 | scroll_y => $self->{scroll_y}, |
… | |
… | |
1183 | $self->SUPER::invoke_size_allocate ($w, $h) |
1216 | $self->SUPER::invoke_size_allocate ($w, $h) |
1184 | } |
1217 | } |
1185 | |
1218 | |
1186 | ############################################################################# |
1219 | ############################################################################# |
1187 | |
1220 | |
1188 | package CFPlus::UI::Frame; |
1221 | package DC::UI::Frame; |
1189 | |
1222 | |
1190 | our @ISA = CFPlus::UI::Bin::; |
1223 | our @ISA = DC::UI::Bin::; |
1191 | |
1224 | |
1192 | use CFPlus::OpenGL; |
1225 | use DC::OpenGL; |
1193 | |
1226 | |
1194 | sub new { |
1227 | sub new { |
1195 | my $class = shift; |
1228 | my $class = shift; |
1196 | |
1229 | |
1197 | $class->SUPER::new ( |
1230 | $class->SUPER::new ( |
… | |
… | |
1216 | $self->SUPER::_draw; |
1249 | $self->SUPER::_draw; |
1217 | } |
1250 | } |
1218 | |
1251 | |
1219 | ############################################################################# |
1252 | ############################################################################# |
1220 | |
1253 | |
1221 | package CFPlus::UI::FancyFrame; |
1254 | package DC::UI::FancyFrame; |
1222 | |
1255 | |
1223 | our @ISA = CFPlus::UI::Bin::; |
1256 | our @ISA = DC::UI::Bin::; |
1224 | |
1257 | |
1225 | use CFPlus::OpenGL; |
1258 | use DC::OpenGL; |
1226 | |
1259 | |
1227 | sub new { |
1260 | sub new { |
1228 | my ($class, %arg) = @_; |
1261 | my ($class, %arg) = @_; |
1229 | |
1262 | |
1230 | if ((exists $arg{label}) && !ref $arg{label}) { |
1263 | if ((exists $arg{label}) && !ref $arg{label}) { |
1231 | $arg{label} = new CFPlus::UI::Label |
1264 | $arg{label} = new DC::UI::Label |
1232 | align => 1, |
1265 | align => 1, |
1233 | valign => 0, |
1266 | valign => 0.5, |
1234 | text => $arg{label}, |
1267 | text => $arg{label}, |
1235 | fontsize => ($arg{border} || 0.8) * 0.75; |
1268 | fontsize => ($arg{border} || 0.8) * 0.75; |
1236 | } |
1269 | } |
1237 | |
1270 | |
1238 | my $self = $class->SUPER::new ( |
1271 | my $self = $class->SUPER::new ( |
1239 | # label => "", |
1272 | # label => "", |
1240 | fg => [0.6, 0.3, 0.1], |
1273 | fg => undef, |
1241 | border => 0.8, |
1274 | border => 0.8, |
1242 | style => 'single', |
1275 | style => 'single', |
1243 | %arg, |
1276 | %arg, |
1244 | ); |
1277 | ); |
1245 | |
1278 | |
… | |
… | |
1248 | |
1281 | |
1249 | sub add { |
1282 | sub add { |
1250 | my ($self, @widgets) = @_; |
1283 | my ($self, @widgets) = @_; |
1251 | |
1284 | |
1252 | $self->SUPER::add (@widgets); |
1285 | $self->SUPER::add (@widgets); |
1253 | $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label}; |
1286 | $self->DC::UI::Container::add ($self->{label}) if $self->{label}; |
1254 | } |
1287 | } |
1255 | |
1288 | |
1256 | sub border { |
1289 | sub border { |
1257 | int $_[0]{border} * $::FONTSIZE |
1290 | int $_[0]{border} * $::FONTSIZE |
1258 | } |
1291 | } |
… | |
… | |
1298 | my $border = $self->border; |
1331 | my $border = $self->border; |
1299 | my ($w, $h) = ($self->{w}, $self->{h}); |
1332 | my ($w, $h) = ($self->{w}, $self->{h}); |
1300 | |
1333 | |
1301 | $child->draw; |
1334 | $child->draw; |
1302 | |
1335 | |
1303 | glColor @{$self->{fg}}; |
1336 | glColor @{$self->{fg} || $DC::THEME{fancyframe}}; |
1304 | glBegin GL_LINE_STRIP; |
1337 | glBegin GL_LINE_STRIP; |
1305 | glVertex $border * 1.5 , $border * 0.5 + 0.5; |
1338 | glVertex $border * 1.5 , $border * 0.5 + 0.5; |
1306 | glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; |
1339 | glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; |
1307 | glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
1340 | glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
1308 | glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
1341 | glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
… | |
… | |
1316 | } |
1349 | } |
1317 | } |
1350 | } |
1318 | |
1351 | |
1319 | ############################################################################# |
1352 | ############################################################################# |
1320 | |
1353 | |
1321 | package CFPlus::UI::Toplevel; |
1354 | package DC::UI::Toplevel; |
1322 | |
1355 | |
1323 | our @ISA = CFPlus::UI::Bin::; |
1356 | our @ISA = DC::UI::Bin::; |
1324 | |
1357 | |
1325 | use CFPlus::OpenGL; |
1358 | use DC::OpenGL; |
1326 | |
1359 | |
1327 | my $bg = |
1360 | my $bg = |
1328 | new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", |
1361 | new_from_resource DC::Texture "d1_bg.png", |
1329 | mipmap => 1, wrap => 1; |
1362 | mipmap => 1, wrap => 1; |
1330 | |
1363 | |
1331 | my @border = |
1364 | my @border = |
1332 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1365 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
1333 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1366 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1334 | |
1367 | |
1335 | my @icon = |
1368 | my @icon = |
1336 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1369 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
1337 | qw(x1_move.png x1_resize.png); |
1370 | qw(x1_move.png x1_resize.png); |
1338 | |
1371 | |
1339 | sub new { |
1372 | sub new { |
1340 | my ($class, %arg) = @_; |
1373 | my ($class, %arg) = @_; |
1341 | |
1374 | |
1342 | my $self = $class->SUPER::new ( |
1375 | my $self = $class->SUPER::new ( |
1343 | bg => [1, 1, 1, 1], |
1376 | bg => [1, 1, 1, 1], |
1344 | border_bg => [1, 1, 1, 1], |
1377 | border_bg => [1, 1, 1, 1], |
1345 | border => 0.6, |
1378 | border => 0.8, |
1346 | can_events => 1, |
1379 | can_events => 1, |
1347 | min_w => 64, |
1380 | min_w => 64, |
1348 | min_h => 32, |
1381 | min_h => 32, |
1349 | %arg, |
1382 | %arg, |
1350 | ); |
1383 | ); |
1351 | |
1384 | |
1352 | $self->{title_widget} = new CFPlus::UI::Label |
1385 | $self->{title_widget} = new DC::UI::Label |
1353 | align => 0, |
1386 | align => 0.5, |
1354 | valign => 1, |
1387 | valign => 1, |
1355 | text => $self->{title}, |
1388 | text => $self->{title}, |
1356 | fontsize => $self->{border}, |
1389 | fontsize => $self->{border}, |
1357 | if exists $self->{title}; |
1390 | if exists $self->{title}; |
1358 | |
1391 | |
1359 | if ($self->{has_close_button}) { |
1392 | if ($self->{has_close_button}) { |
1360 | $self->{close_button} = |
1393 | $self->{close_button} = |
1361 | new CFPlus::UI::ImageButton |
1394 | new DC::UI::ImageButton |
1362 | path => 'x1_close.png', |
1395 | path => 'x1_close.png', |
1363 | on_activate => sub { $self->emit ("delete") }; |
1396 | on_activate => sub { $self->emit ("delete") }; |
1364 | |
1397 | |
1365 | $self->CFPlus::UI::Container::add ($self->{close_button}); |
1398 | $self->DC::UI::Container::add ($self->{close_button}); |
1366 | } |
1399 | } |
1367 | |
1400 | |
1368 | $self |
1401 | $self |
1369 | } |
1402 | } |
1370 | |
1403 | |
1371 | sub add { |
1404 | sub add { |
1372 | my ($self, @widgets) = @_; |
1405 | my ($self, @widgets) = @_; |
1373 | |
1406 | |
1374 | $self->SUPER::add (@widgets); |
1407 | $self->SUPER::add (@widgets); |
1375 | $self->CFPlus::UI::Container::add ($self->{close_button}) if $self->{close_button}; |
1408 | $self->DC::UI::Container::add ($self->{close_button}) if $self->{close_button}; |
1376 | $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1409 | $self->DC::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1377 | } |
1410 | } |
1378 | |
1411 | |
1379 | sub border { |
1412 | sub border { |
1380 | int $_[0]{border} * $::FONTSIZE |
1413 | int $_[0]{border} * $::FONTSIZE |
|
|
1414 | } |
|
|
1415 | |
|
|
1416 | sub get_max_wh { |
|
|
1417 | my ($self) = @_; |
|
|
1418 | |
|
|
1419 | return ($self->{w}, $self->{h}) |
|
|
1420 | if $self->{visible} && $self->{w}; |
|
|
1421 | |
|
|
1422 | $self->SUPER::get_max_wh |
1381 | } |
1423 | } |
1382 | |
1424 | |
1383 | sub size_request { |
1425 | sub size_request { |
1384 | my ($self) = @_; |
1426 | my ($self) = @_; |
1385 | |
1427 | |
… | |
… | |
1510 | glEnable GL_TEXTURE_2D; |
1552 | glEnable GL_TEXTURE_2D; |
1511 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1553 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1512 | |
1554 | |
1513 | my $border = $self->border; |
1555 | my $border = $self->border; |
1514 | |
1556 | |
|
|
1557 | if ($border) { |
1515 | glColor @{ $self->{border_bg} }; |
1558 | glColor @{ $self->{border_bg} }; |
1516 | $border[0]->draw_quad_alpha ( 0, 0, $w, $border); |
1559 | $border[0]->draw_quad_alpha ( 0, 0, $w, $border); |
1517 | $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); |
1560 | $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); |
1518 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1561 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1519 | $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); |
1562 | $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); |
1520 | |
1563 | |
1521 | # move |
1564 | # move |
1522 | my $w2 = ($w - $border) * .5; |
1565 | my $w2 = ($w - $border) * .5; |
1523 | my $h2 = ($h - $border) * .5; |
1566 | my $h2 = ($h - $border) * .5; |
1524 | $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); |
1567 | $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); |
1525 | $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); |
1568 | $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); |
1526 | $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); |
1569 | $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); |
1527 | |
1570 | |
1528 | # resize |
1571 | # resize |
1529 | $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); |
1572 | $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); |
1530 | $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) |
1573 | $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) |
1531 | unless $self->{has_close_button}; |
1574 | unless $self->{has_close_button}; |
1532 | $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); |
1575 | $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); |
1533 | $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); |
1576 | $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); |
|
|
1577 | } |
1534 | |
1578 | |
1535 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1579 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1536 | glColor @{ $self->{bg} }; |
1580 | glColor @{ $self->{bg} }; |
1537 | |
1581 | |
1538 | # TODO: repeat texture not scale |
1582 | # TODO: repeat texture not scale |
… | |
… | |
1557 | if $self->{close_button}; |
1601 | if $self->{close_button}; |
1558 | } |
1602 | } |
1559 | |
1603 | |
1560 | ############################################################################# |
1604 | ############################################################################# |
1561 | |
1605 | |
1562 | package CFPlus::UI::Table; |
1606 | package DC::UI::Table; |
1563 | |
1607 | |
1564 | our @ISA = CFPlus::UI::Container::; |
1608 | our @ISA = DC::UI::Container::; |
1565 | |
1609 | |
1566 | use List::Util qw(max sum); |
1610 | use List::Util qw(max sum); |
1567 | |
1611 | |
1568 | use CFPlus::OpenGL; |
1612 | use DC::OpenGL; |
1569 | |
1613 | |
1570 | sub new { |
1614 | sub new { |
1571 | my $class = shift; |
1615 | my $class = shift; |
1572 | |
1616 | |
1573 | $class->SUPER::new ( |
1617 | $class->SUPER::new ( |
… | |
… | |
1617 | my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; |
1661 | my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; |
1618 | |
1662 | |
1619 | my $sw = sum @w[$c .. $c + $cs - 1]; |
1663 | my $sw = sum @w[$c .. $c + $cs - 1]; |
1620 | |
1664 | |
1621 | if ($w > $sw) { |
1665 | if ($w > $sw) { |
1622 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1666 | $_ += ($w - $sw) / ($_ ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1623 | } |
1667 | } |
1624 | } |
1668 | } |
1625 | |
1669 | |
1626 | # second pass, rows |
1670 | # second pass, rows |
1627 | for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { |
1671 | for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { |
1628 | my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; |
1672 | my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; |
1629 | |
1673 | |
1630 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1674 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1631 | |
1675 | |
1632 | if ($h > $sh) { |
1676 | if ($h > $sh) { |
1633 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1677 | $_ += ($h - $sh) / ($_ ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1634 | } |
1678 | } |
1635 | } |
1679 | } |
1636 | |
1680 | |
1637 | (\@w, \@h) |
1681 | (\@w, \@h) |
1638 | } |
1682 | } |
… | |
… | |
1661 | @col_expand = (1) x @$ws unless @col_expand; |
1705 | @col_expand = (1) x @$ws unless @col_expand; |
1662 | my $col_expand = (sum @col_expand) || 1; |
1706 | my $col_expand = (sum @col_expand) || 1; |
1663 | |
1707 | |
1664 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1708 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1665 | |
1709 | |
1666 | CFPlus::UI::harmonize $ws; |
1710 | DC::UI::harmonize $ws; |
1667 | |
1711 | |
1668 | my @row_expand = @{$self->{row_expand}}; |
1712 | my @row_expand = @{$self->{row_expand}}; |
1669 | @row_expand = (1) x @$ws unless @row_expand; |
1713 | @row_expand = (1) x @$ws unless @row_expand; |
1670 | my $row_expand = (sum @row_expand) || 1; |
1714 | my $row_expand = (sum @row_expand) || 1; |
1671 | |
1715 | |
1672 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1716 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1673 | |
1717 | |
1674 | CFPlus::UI::harmonize $hs; |
1718 | DC::UI::harmonize $hs; |
1675 | |
1719 | |
1676 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
1720 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
1677 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1721 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1678 | |
1722 | |
1679 | for my $widget ($self->children) { |
1723 | for my $widget ($self->children) { |
… | |
… | |
1688 | 1 |
1732 | 1 |
1689 | } |
1733 | } |
1690 | |
1734 | |
1691 | ############################################################################# |
1735 | ############################################################################# |
1692 | |
1736 | |
1693 | package CFPlus::UI::Fixed; |
1737 | package DC::UI::Fixed; |
1694 | |
1738 | |
1695 | use List::Util qw(min max); |
1739 | use List::Util qw(min max); |
1696 | |
1740 | |
1697 | our @ISA = CFPlus::UI::Container::; |
1741 | our @ISA = DC::UI::Container::; |
1698 | |
1742 | |
1699 | sub _scale($$$) { |
1743 | sub _scale($$$) { |
1700 | my ($rel, $val, $max) = @_; |
1744 | my ($rel, $val, $max) = @_; |
1701 | |
1745 | |
1702 | $rel ? $val * $max : $val |
1746 | $rel ? $val * $max : $val |
… | |
… | |
1754 | 1 |
1798 | 1 |
1755 | } |
1799 | } |
1756 | |
1800 | |
1757 | ############################################################################# |
1801 | ############################################################################# |
1758 | |
1802 | |
1759 | package CFPlus::UI::Box; |
1803 | package DC::UI::Box; |
1760 | |
1804 | |
1761 | our @ISA = CFPlus::UI::Container::; |
1805 | our @ISA = DC::UI::Container::; |
1762 | |
1806 | |
1763 | sub size_request { |
1807 | sub size_request { |
1764 | my ($self) = @_; |
1808 | my ($self) = @_; |
1765 | |
1809 | |
1766 | my @children = $self->visible_children; |
1810 | my @children = $self->visible_children; |
… | |
… | |
1801 | $req[$_] += $space * $children[$_]{expand} |
1845 | $req[$_] += $space * $children[$_]{expand} |
1802 | for 0 .. $#children; |
1846 | for 0 .. $#children; |
1803 | } |
1847 | } |
1804 | } |
1848 | } |
1805 | |
1849 | |
1806 | CFPlus::UI::harmonize \@req; |
1850 | DC::UI::harmonize \@req; |
1807 | |
1851 | |
1808 | my $pos = 0; |
1852 | my $pos = 0; |
1809 | for (0 .. $#children) { |
1853 | for (0 .. $#children) { |
1810 | my $alloc = $req[$_]; |
1854 | my $alloc = $req[$_]; |
1811 | $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); |
1855 | $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); |
… | |
… | |
1816 | 1 |
1860 | 1 |
1817 | } |
1861 | } |
1818 | |
1862 | |
1819 | ############################################################################# |
1863 | ############################################################################# |
1820 | |
1864 | |
1821 | package CFPlus::UI::HBox; |
1865 | package DC::UI::HBox; |
1822 | |
1866 | |
1823 | our @ISA = CFPlus::UI::Box::; |
1867 | our @ISA = DC::UI::Box::; |
1824 | |
1868 | |
1825 | sub new { |
1869 | sub new { |
1826 | my $class = shift; |
1870 | my $class = shift; |
1827 | |
1871 | |
1828 | $class->SUPER::new ( |
1872 | $class->SUPER::new ( |
… | |
… | |
1831 | ) |
1875 | ) |
1832 | } |
1876 | } |
1833 | |
1877 | |
1834 | ############################################################################# |
1878 | ############################################################################# |
1835 | |
1879 | |
1836 | package CFPlus::UI::VBox; |
1880 | package DC::UI::VBox; |
1837 | |
1881 | |
1838 | our @ISA = CFPlus::UI::Box::; |
1882 | our @ISA = DC::UI::Box::; |
1839 | |
1883 | |
1840 | sub new { |
1884 | sub new { |
1841 | my $class = shift; |
1885 | my $class = shift; |
1842 | |
1886 | |
1843 | $class->SUPER::new ( |
1887 | $class->SUPER::new ( |
… | |
… | |
1846 | ) |
1890 | ) |
1847 | } |
1891 | } |
1848 | |
1892 | |
1849 | ############################################################################# |
1893 | ############################################################################# |
1850 | |
1894 | |
1851 | package CFPlus::UI::Label; |
1895 | package DC::UI::Label; |
1852 | |
1896 | |
1853 | our @ISA = CFPlus::UI::DrawBG::; |
1897 | our @ISA = DC::UI::DrawBG::; |
1854 | |
1898 | |
1855 | use CFPlus::OpenGL; |
1899 | use DC::OpenGL; |
1856 | |
1900 | |
1857 | sub new { |
1901 | sub new { |
1858 | my ($class, %arg) = @_; |
1902 | my ($class, %arg) = @_; |
1859 | |
1903 | |
1860 | my $self = $class->SUPER::new ( |
1904 | my $self = $class->SUPER::new ( |
… | |
… | |
1865 | #text => initial text |
1909 | #text => initial text |
1866 | #markup => initial narkup |
1910 | #markup => initial narkup |
1867 | #max_w => maximum pixel width |
1911 | #max_w => maximum pixel width |
1868 | #style => 0, # render flags |
1912 | #style => 0, # render flags |
1869 | ellipsise => 3, # end |
1913 | ellipsise => 3, # end |
1870 | layout => (new CFPlus::Layout), |
1914 | layout => (new DC::Layout), |
1871 | fontsize => 1, |
1915 | fontsize => 1, |
1872 | align => -1, |
1916 | align => 0.5, |
1873 | valign => -1, |
1917 | valign => 0.5, |
1874 | padding_x => 2, |
1918 | padding_x => 4, |
1875 | padding_y => 2, |
1919 | padding_y => 2, |
1876 | can_events => 0, |
1920 | can_events => 0, |
1877 | %arg |
1921 | %arg |
1878 | ); |
1922 | ); |
1879 | |
1923 | |
1880 | if (exists $self->{template}) { |
1924 | if (exists $self->{template}) { |
1881 | my $layout = new CFPlus::Layout; |
1925 | my $layout = new DC::Layout; |
1882 | $layout->set_text (delete $self->{template}); |
1926 | $layout->set_text (delete $self->{template}); |
1883 | $self->{template} = $layout; |
1927 | $self->{template} = $layout; |
1884 | } |
1928 | } |
1885 | |
1929 | |
1886 | if (exists $self->{markup}) { |
1930 | if (exists $self->{markup}) { |
… | |
… | |
1942 | |
1986 | |
1943 | sub size_request { |
1987 | sub size_request { |
1944 | my ($self) = @_; |
1988 | my ($self) = @_; |
1945 | |
1989 | |
1946 | $self->{size_req} ||= do { |
1990 | $self->{size_req} ||= do { |
|
|
1991 | my ($max_w, $max_h) = $self->get_max_wh; |
|
|
1992 | |
1947 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1993 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1948 | $self->{layout}->set_width ($self->{max_w} || -1); |
1994 | $self->{layout}->set_width ($max_w); |
1949 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1995 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1950 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1996 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1951 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1997 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1952 | |
1998 | |
1953 | my ($w, $h) = $self->{layout}->size; |
1999 | my ($w, $h) = $self->{layout}->size; |
1954 | |
2000 | |
1955 | if (exists $self->{template}) { |
2001 | if (exists $self->{template}) { |
1956 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
2002 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1957 | $self->{template}->set_width ($self->{max_w} || -1); |
2003 | $self->{template}->set_width ($max_w); |
1958 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
2004 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1959 | |
2005 | |
1960 | my ($w2, $h2) = $self->{template}->size; |
2006 | my ($w2, $h2) = $self->{template}->size; |
1961 | |
2007 | |
1962 | $w = List::Util::max $w, $w2; |
2008 | $w = List::Util::max $w, $w2; |
… | |
… | |
2018 | |
2064 | |
2019 | [$self->{layout}->size] |
2065 | [$self->{layout}->size] |
2020 | }; |
2066 | }; |
2021 | |
2067 | |
2022 | unless (exists $self->{ox}) { |
2068 | unless (exists $self->{ox}) { |
2023 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
2069 | $self->{ox} = $self->{padding_x} + int $self->{align} * ($self->{w} - $size->[0] - $self->{padding_x} * 2); |
2024 | : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} |
2070 | $self->{oy} = $self->{padding_y} + int $self->{valign} * ($self->{h} - $size->[1] - $self->{padding_y} * 2); |
2025 | : ($self->{w} - $size->[0]) * 0.5); |
|
|
2026 | |
|
|
2027 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
|
|
2028 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
|
|
2029 | : ($self->{h} - $size->[1]) * 0.5); |
|
|
2030 | |
2071 | |
2031 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2072 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2032 | }; |
2073 | }; |
2033 | |
2074 | |
2034 | # unless ($self->{list}) { |
2075 | # unless ($self->{list}) { |
2035 | # $self->{list} = CFPlus::OpenGL::glGenList; |
2076 | # $self->{list} = DC::OpenGL::glGenList; |
2036 | # CFPlus::OpenGL::glNewList $self->{list}; |
2077 | # DC::OpenGL::glNewList $self->{list}; |
2037 | # $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2078 | # $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2038 | # CFPlus::OpenGL::glEndList; |
2079 | # DC::OpenGL::glEndList; |
2039 | # } |
2080 | # } |
2040 | # |
2081 | # |
2041 | # CFPlus::OpenGL::glCallList $self->{list}; |
2082 | # DC::OpenGL::glCallList $self->{list}; |
2042 | |
2083 | |
2043 | $self->{layout}->draw; |
2084 | $self->{layout}->draw; |
2044 | } |
2085 | } |
2045 | |
2086 | |
2046 | #sub destroy { |
2087 | #sub destroy { |
2047 | # my ($self) = @_; |
2088 | # my ($self) = @_; |
2048 | # |
2089 | # |
2049 | # CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; |
2090 | # DC::OpenGL::glDeleteList delete $self->{list} if $self->{list}; |
2050 | # |
2091 | # |
2051 | # $self->SUPER::destroy; |
2092 | # $self->SUPER::destroy; |
2052 | #} |
2093 | #} |
2053 | |
2094 | |
2054 | ############################################################################# |
2095 | ############################################################################# |
2055 | |
2096 | |
2056 | package CFPlus::UI::EntryBase; |
2097 | package DC::UI::EntryBase; |
2057 | |
2098 | |
2058 | our @ISA = CFPlus::UI::Label::; |
2099 | our @ISA = DC::UI::Label::; |
2059 | |
2100 | |
2060 | use CFPlus::OpenGL; |
2101 | use DC::OpenGL; |
2061 | |
2102 | |
2062 | sub new { |
2103 | sub new { |
2063 | my $class = shift; |
2104 | my $class = shift; |
2064 | |
2105 | |
2065 | $class->SUPER::new ( |
2106 | $class->SUPER::new ( |
2066 | fg => [1, 1, 1], |
2107 | fg => [1, 1, 1], |
2067 | bg => [0, 0, 0, 0.2], |
2108 | bg => [0, 0, 0, 0.2], |
2068 | outline => [0.6, 0.3, 0.1], |
2109 | outline => undef, |
2069 | active_bg => [0, 0, 1, .2], |
2110 | active_bg => [0, 0, 1, .2], |
2070 | active_fg => [1, 1, 1], |
2111 | active_fg => [1, 1, 1], |
2071 | active_outline => [1, 1, 0], |
2112 | active_outline => [1, 1, 0], |
2072 | can_hover => 1, |
2113 | can_hover => 1, |
2073 | can_focus => 1, |
2114 | can_focus => 1, |
|
|
2115 | align => 0, |
2074 | valign => 0, |
2116 | valign => 0.5, |
2075 | can_events => 1, |
2117 | can_events => 1, |
2076 | ellipsise => 0, |
2118 | ellipsise => 0, |
|
|
2119 | padding_x => 4, |
|
|
2120 | padding_y => 2, |
2077 | #text => ... |
2121 | #text => ... |
2078 | #hidden => "*", |
2122 | #hidden => "*", |
2079 | @_ |
2123 | @_ |
2080 | ) |
2124 | ) |
2081 | } |
2125 | } |
… | |
… | |
2128 | |
2172 | |
2129 | my $text = $self->get_text; |
2173 | my $text = $self->get_text; |
2130 | |
2174 | |
2131 | $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; |
2175 | $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; |
2132 | |
2176 | |
2133 | if ($uni == 8) { |
2177 | if ($sym == DC::SDLK_BACKSPACE) { |
2134 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
2178 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
2135 | } elsif ($uni == 127) { |
2179 | } elsif ($sym == DC::SDLK_DELETE) { |
2136 | substr $text, $self->{cursor}, 1, ""; |
2180 | substr $text, $self->{cursor}, 1, ""; |
2137 | } elsif ($sym == CFPlus::SDLK_LEFT) { |
2181 | } elsif ($sym == DC::SDLK_LEFT) { |
2138 | --$self->{cursor} if $self->{cursor}; |
2182 | --$self->{cursor} if $self->{cursor}; |
2139 | } elsif ($sym == CFPlus::SDLK_RIGHT) { |
2183 | } elsif ($sym == DC::SDLK_RIGHT) { |
2140 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
2184 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
2141 | } elsif ($sym == CFPlus::SDLK_HOME) { |
2185 | } elsif ($sym == DC::SDLK_HOME) { |
2142 | # what a hack |
2186 | # what a hack |
2143 | $self->{cursor} = |
2187 | $self->{cursor} = |
2144 | (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ |
2188 | (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ |
2145 | ? length $1 |
2189 | ? length $1 |
2146 | : 0; |
2190 | : 0; |
2147 | } elsif ($sym == CFPlus::SDLK_END) { |
2191 | } elsif ($sym == DC::SDLK_END) { |
2148 | # uh, again |
2192 | # uh, again |
2149 | $self->{cursor} = |
2193 | $self->{cursor} = |
2150 | (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ |
2194 | (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ |
2151 | ? $self->{cursor} + length $1 |
2195 | ? $self->{cursor} + length $1 |
2152 | : length $self->{text}; |
2196 | : length $self->{text}; |
… | |
… | |
2243 | glColor @{$self->{active_outline}}; |
2287 | glColor @{$self->{active_outline}}; |
2244 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
2288 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
2245 | glLineWidth 1; |
2289 | glLineWidth 1; |
2246 | |
2290 | |
2247 | } else { |
2291 | } else { |
2248 | glColor @{$self->{outline}}; |
2292 | glColor @{$self->{outline} || $DC::THEME{entry_outline}}; |
2249 | glBegin GL_LINE_STRIP; |
2293 | glBegin GL_LINE_STRIP; |
2250 | glVertex .5, $self->{h} * .5; |
2294 | glVertex .5, $self->{h} * .5; |
2251 | glVertex .5, $self->{h} - 2.5; |
2295 | glVertex .5, $self->{h} - 2.5; |
2252 | glVertex $self->{w} - .5, $self->{h} - 2.5; |
2296 | glVertex $self->{w} - .5, $self->{h} - 2.5; |
2253 | glVertex $self->{w} - .5, $self->{h} * .5; |
2297 | glVertex $self->{w} - .5, $self->{h} * .5; |
… | |
… | |
2255 | } |
2299 | } |
2256 | } |
2300 | } |
2257 | |
2301 | |
2258 | ############################################################################# |
2302 | ############################################################################# |
2259 | |
2303 | |
2260 | package CFPlus::UI::Entry; |
2304 | package DC::UI::Entry; |
2261 | |
2305 | |
2262 | our @ISA = CFPlus::UI::EntryBase::; |
2306 | our @ISA = DC::UI::EntryBase::; |
2263 | |
2307 | |
2264 | use CFPlus::OpenGL; |
2308 | use DC::OpenGL; |
|
|
2309 | |
|
|
2310 | sub new { |
|
|
2311 | my $class = shift; |
|
|
2312 | |
|
|
2313 | $class->SUPER::new ( |
|
|
2314 | history_pointer => -1, |
|
|
2315 | @_ |
|
|
2316 | ) |
|
|
2317 | } |
|
|
2318 | |
2265 | |
2319 | |
2266 | sub invoke_key_down { |
2320 | sub invoke_key_down { |
2267 | my ($self, $ev) = @_; |
2321 | my ($self, $ev) = @_; |
2268 | |
2322 | |
2269 | my $sym = $ev->{sym}; |
2323 | my $sym = $ev->{sym}; |
… | |
… | |
2275 | $self->{history_pointer} = -1; |
2329 | $self->{history_pointer} = -1; |
2276 | $self->{history_saveback} = ''; |
2330 | $self->{history_saveback} = ''; |
2277 | $self->emit (activate => $txt); |
2331 | $self->emit (activate => $txt); |
2278 | $self->update; |
2332 | $self->update; |
2279 | |
2333 | |
2280 | } elsif ($sym == CFPlus::SDLK_UP) { |
2334 | } elsif ($sym == DC::SDLK_UP) { |
2281 | if ($self->{history_pointer} < 0) { |
2335 | if ($self->{history_pointer} < 0) { |
2282 | $self->{history_saveback} = $self->get_text; |
2336 | $self->{history_saveback} = $self->get_text; |
2283 | } |
2337 | } |
2284 | if (@{$self->{history} || []} > 0) { |
2338 | if (@{$self->{history} || []} > 0) { |
2285 | $self->{history_pointer}++; |
2339 | $self->{history_pointer}++; |
… | |
… | |
2287 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
2341 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
2288 | } |
2342 | } |
2289 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2343 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2290 | } |
2344 | } |
2291 | |
2345 | |
2292 | } elsif ($sym == CFPlus::SDLK_DOWN) { |
2346 | } elsif ($sym == DC::SDLK_DOWN) { |
2293 | $self->{history_pointer}--; |
2347 | $self->{history_pointer}--; |
2294 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
2348 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
2295 | |
2349 | |
2296 | if ($self->{history_pointer} >= 0) { |
2350 | if ($self->{history_pointer} >= 0) { |
2297 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2351 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2298 | } else { |
2352 | } else { |
|
|
2353 | if (defined $self->{history_saveback}) { |
2299 | $self->set_text ($self->{history_saveback}); |
2354 | $self->set_text ($self->{history_saveback}); |
|
|
2355 | $self->{history_saveback} = undef; |
|
|
2356 | } |
2300 | } |
2357 | } |
2301 | |
2358 | |
2302 | } else { |
2359 | } else { |
2303 | return $self->SUPER::invoke_key_down ($ev) |
2360 | return $self->SUPER::invoke_key_down ($ev) |
2304 | } |
2361 | } |
… | |
… | |
2306 | 1 |
2363 | 1 |
2307 | } |
2364 | } |
2308 | |
2365 | |
2309 | ############################################################################# |
2366 | ############################################################################# |
2310 | |
2367 | |
2311 | package CFPlus::UI::TextEdit; |
2368 | package DC::UI::TextEdit; |
2312 | |
2369 | |
2313 | our @ISA = CFPlus::UI::EntryBase::; |
2370 | our @ISA = DC::UI::EntryBase::; |
2314 | |
2371 | |
2315 | use CFPlus::OpenGL; |
2372 | use DC::OpenGL; |
|
|
2373 | |
|
|
2374 | sub new { |
|
|
2375 | my $class = shift; |
|
|
2376 | |
|
|
2377 | $class->SUPER::new ( |
|
|
2378 | padding_y => 4, |
|
|
2379 | |
|
|
2380 | @_ |
|
|
2381 | ) |
|
|
2382 | } |
2316 | |
2383 | |
2317 | sub move_cursor_ver { |
2384 | sub move_cursor_ver { |
2318 | my ($self, $dy) = @_; |
2385 | my ($self, $dy) = @_; |
2319 | |
2386 | |
2320 | my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); |
2387 | my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); |
2321 | |
2388 | |
2322 | $y += $dy; |
2389 | $line += $dy; |
2323 | |
2390 | |
2324 | if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { |
2391 | if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) { |
2325 | $self->{cursor} = $index; |
2392 | $self->{cursor} = $index; |
2326 | delete $self->{cur_h}; |
2393 | delete $self->{cur_h}; |
2327 | $self->update; |
2394 | $self->update; |
2328 | return; |
2395 | return; |
2329 | } |
2396 | } |
… | |
… | |
2332 | sub invoke_key_down { |
2399 | sub invoke_key_down { |
2333 | my ($self, $ev) = @_; |
2400 | my ($self, $ev) = @_; |
2334 | |
2401 | |
2335 | my $sym = $ev->{sym}; |
2402 | my $sym = $ev->{sym}; |
2336 | |
2403 | |
2337 | if ($sym == CFPlus::SDLK_UP) { |
2404 | if ($sym == DC::SDLK_UP) { |
2338 | $self->move_cursor_ver (-1); |
2405 | $self->move_cursor_ver (-1); |
2339 | } elsif ($sym == CFPlus::SDLK_DOWN) { |
2406 | } elsif ($sym == DC::SDLK_DOWN) { |
2340 | $self->move_cursor_ver (+1); |
2407 | $self->move_cursor_ver (+1); |
2341 | } else { |
2408 | } else { |
2342 | return $self->SUPER::invoke_key_down ($ev) |
2409 | return $self->SUPER::invoke_key_down ($ev) |
2343 | } |
2410 | } |
2344 | |
2411 | |
2345 | 1 |
2412 | 1 |
2346 | } |
2413 | } |
2347 | |
2414 | |
2348 | ############################################################################# |
2415 | ############################################################################# |
2349 | |
2416 | |
2350 | package CFPlus::UI::ButtonBin; |
2417 | package DC::UI::ButtonBin; |
2351 | |
2418 | |
2352 | our @ISA = CFPlus::UI::Bin::; |
2419 | our @ISA = DC::UI::Bin::; |
2353 | |
2420 | |
2354 | use CFPlus::OpenGL; |
2421 | use DC::OpenGL; |
2355 | |
2422 | |
2356 | my @tex = |
2423 | my @tex = |
2357 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2424 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2358 | qw(b1_button_inactive.png b1_button_active.png); |
2425 | qw(b1_button_inactive.png b1_button_active.png); |
2359 | |
2426 | |
2360 | sub new { |
2427 | sub new { |
2361 | my $class = shift; |
2428 | my $class = shift; |
2362 | |
2429 | |
2363 | $class->SUPER::new ( |
2430 | $class->SUPER::new ( |
2364 | can_hover => 1, |
2431 | can_hover => 1, |
2365 | align => 0, |
2432 | align => 0.5, |
2366 | valign => 0, |
2433 | valign => 0.5, |
2367 | can_events => 1, |
2434 | can_events => 1, |
2368 | @_ |
2435 | @_ |
2369 | ) |
2436 | ) |
2370 | } |
2437 | } |
2371 | |
2438 | |
… | |
… | |
2394 | $self->SUPER::_draw; |
2461 | $self->SUPER::_draw; |
2395 | } |
2462 | } |
2396 | |
2463 | |
2397 | ############################################################################# |
2464 | ############################################################################# |
2398 | |
2465 | |
2399 | package CFPlus::UI::Button; |
2466 | package DC::UI::Button; |
2400 | |
2467 | |
2401 | our @ISA = CFPlus::UI::Label::; |
2468 | our @ISA = DC::UI::Label::; |
2402 | |
2469 | |
2403 | use CFPlus::OpenGL; |
2470 | use DC::OpenGL; |
2404 | |
2471 | |
2405 | my @tex = |
2472 | my @tex = |
2406 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2473 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2407 | qw(b1_button_inactive.png b1_button_active.png); |
2474 | qw(b1_button_inactive.png b1_button_active.png); |
2408 | |
2475 | |
2409 | sub new { |
2476 | sub new { |
2410 | my $class = shift; |
2477 | my $class = shift; |
2411 | |
2478 | |
2412 | $class->SUPER::new ( |
2479 | $class->SUPER::new ( |
2413 | padding_x => 4, |
2480 | padding_x => 8, |
2414 | padding_y => 4, |
2481 | padding_y => 4, |
2415 | fg => [1.0, 1.0, 1.0], |
2482 | fg => [1.0, 1.0, 1.0], |
2416 | active_fg => [0.8, 0.8, 0.8], |
2483 | active_fg => [0.8, 0.8, 0.8], |
2417 | can_hover => 1, |
2484 | can_hover => 1, |
2418 | align => 0, |
2485 | align => 0.5, |
2419 | valign => 0, |
2486 | valign => 0.5, |
2420 | can_events => 1, |
2487 | can_events => 1, |
2421 | @_ |
2488 | @_ |
2422 | ) |
2489 | ) |
2423 | } |
2490 | } |
2424 | |
2491 | |
… | |
… | |
2449 | $self->SUPER::_draw; |
2516 | $self->SUPER::_draw; |
2450 | } |
2517 | } |
2451 | |
2518 | |
2452 | ############################################################################# |
2519 | ############################################################################# |
2453 | |
2520 | |
2454 | package CFPlus::UI::CheckBox; |
2521 | package DC::UI::CheckBox; |
2455 | |
2522 | |
2456 | our @ISA = CFPlus::UI::DrawBG::; |
2523 | our @ISA = DC::UI::DrawBG::; |
2457 | |
2524 | |
2458 | my @tex = |
2525 | my @tex = |
2459 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2526 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2460 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
2527 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
2461 | |
2528 | |
2462 | use CFPlus::OpenGL; |
2529 | use DC::OpenGL; |
2463 | |
2530 | |
2464 | sub new { |
2531 | sub new { |
2465 | my $class = shift; |
2532 | my $class = shift; |
2466 | |
2533 | |
2467 | $class->SUPER::new ( |
2534 | $class->SUPER::new ( |
|
|
2535 | fontsize => 1, |
2468 | padding_x => 2, |
2536 | padding_x => 2, |
2469 | padding_y => 2, |
2537 | padding_y => 2, |
2470 | fg => [1, 1, 1], |
2538 | fg => [1, 1, 1], |
2471 | active_fg => [1, 1, 0], |
2539 | active_fg => [1, 1, 0], |
2472 | bg => [0, 0, 0, 0.2], |
2540 | bg => [0, 0, 0, 0.2], |
… | |
… | |
2478 | } |
2546 | } |
2479 | |
2547 | |
2480 | sub size_request { |
2548 | sub size_request { |
2481 | my ($self) = @_; |
2549 | my ($self) = @_; |
2482 | |
2550 | |
2483 | (6) x 2 |
2551 | ($self->{fontsize} * $::FONTSIZE) x 2 |
2484 | } |
2552 | } |
2485 | |
2553 | |
2486 | sub toggle { |
2554 | sub toggle { |
2487 | my ($self) = @_; |
2555 | my ($self) = @_; |
2488 | |
2556 | |
… | |
… | |
2524 | glDisable GL_TEXTURE_2D; |
2592 | glDisable GL_TEXTURE_2D; |
2525 | } |
2593 | } |
2526 | |
2594 | |
2527 | ############################################################################# |
2595 | ############################################################################# |
2528 | |
2596 | |
2529 | package CFPlus::UI::Image; |
2597 | package DC::UI::Image; |
2530 | |
2598 | |
2531 | our @ISA = CFPlus::UI::Base::; |
2599 | our @ISA = DC::UI::Base::; |
2532 | |
2600 | |
2533 | use CFPlus::OpenGL; |
2601 | use DC::OpenGL; |
2534 | |
2602 | |
2535 | our %texture_cache; |
2603 | our %texture_cache; |
2536 | |
2604 | |
2537 | sub new { |
2605 | sub new { |
2538 | my $class = shift; |
2606 | my $class = shift; |
… | |
… | |
2545 | |
2613 | |
2546 | $self->{path} || $self->{tex} |
2614 | $self->{path} || $self->{tex} |
2547 | or Carp::croak "'path' or 'tex' attributes required"; |
2615 | or Carp::croak "'path' or 'tex' attributes required"; |
2548 | |
2616 | |
2549 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
2617 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
2550 | new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; |
2618 | new_from_resource DC::Texture $self->{path}, mipmap => 1; |
2551 | |
2619 | |
2552 | CFPlus::weaken $texture_cache{$self->{path}}; |
2620 | DC::weaken $texture_cache{$self->{path}}; |
2553 | |
2621 | |
2554 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2622 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2555 | |
2623 | |
2556 | $self |
2624 | $self |
2557 | } |
2625 | } |
2558 | |
2626 | |
2559 | sub STORABLE_freeze { |
2627 | sub STORABLE_freeze { |
2560 | my ($self, $cloning) = @_; |
2628 | my ($self, $cloning) = @_; |
2561 | |
2629 | |
2562 | $self->{path} |
2630 | $self->{path} |
2563 | or die "cannot serialise CFPlus::UI::Image on non-loadable images\n"; |
2631 | or die "cannot serialise DC::UI::Image on non-loadable images\n"; |
2564 | |
2632 | |
2565 | $self->{path} |
2633 | $self->{path} |
2566 | } |
2634 | } |
2567 | |
2635 | |
2568 | sub STORABLE_attach { |
2636 | sub STORABLE_attach { |
… | |
… | |
2599 | glDisable GL_TEXTURE_2D; |
2667 | glDisable GL_TEXTURE_2D; |
2600 | } |
2668 | } |
2601 | |
2669 | |
2602 | ############################################################################# |
2670 | ############################################################################# |
2603 | |
2671 | |
2604 | package CFPlus::UI::ImageButton; |
2672 | package DC::UI::ImageButton; |
2605 | |
2673 | |
2606 | our @ISA = CFPlus::UI::Image::; |
2674 | our @ISA = DC::UI::Image::; |
2607 | |
2675 | |
2608 | use CFPlus::OpenGL; |
2676 | use DC::OpenGL; |
2609 | |
2677 | |
2610 | my %textures; |
2678 | my %textures; |
2611 | |
2679 | |
2612 | sub new { |
2680 | sub new { |
2613 | my $class = shift; |
2681 | my $class = shift; |
… | |
… | |
2616 | padding_x => 4, |
2684 | padding_x => 4, |
2617 | padding_y => 4, |
2685 | padding_y => 4, |
2618 | fg => [1, 1, 1], |
2686 | fg => [1, 1, 1], |
2619 | active_fg => [0, 0, 1], |
2687 | active_fg => [0, 0, 1], |
2620 | can_hover => 1, |
2688 | can_hover => 1, |
2621 | align => 0, |
2689 | align => 0.5, |
2622 | valign => 0, |
2690 | valign => 0.5, |
2623 | can_events => 1, |
2691 | can_events => 1, |
2624 | @_ |
2692 | @_ |
2625 | ); |
2693 | ); |
2626 | } |
2694 | } |
2627 | |
2695 | |
… | |
… | |
2641 | 1 |
2709 | 1 |
2642 | } |
2710 | } |
2643 | |
2711 | |
2644 | ############################################################################# |
2712 | ############################################################################# |
2645 | |
2713 | |
2646 | package CFPlus::UI::VGauge; |
2714 | package DC::UI::VGauge; |
2647 | |
2715 | |
2648 | our @ISA = CFPlus::UI::Base::; |
2716 | our @ISA = DC::UI::Base::; |
2649 | |
2717 | |
2650 | use List::Util qw(min max); |
2718 | use List::Util qw(min max); |
2651 | |
2719 | |
2652 | use CFPlus::OpenGL; |
2720 | use DC::OpenGL; |
2653 | |
2721 | |
2654 | my %tex = ( |
2722 | my %tex = ( |
2655 | food => [ |
2723 | food => [ |
2656 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2724 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2657 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
2725 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
2658 | ], |
2726 | ], |
2659 | grace => [ |
2727 | grace => [ |
2660 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2728 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2661 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
2729 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
2662 | ], |
2730 | ], |
2663 | hp => [ |
2731 | hp => [ |
2664 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2732 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2665 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
2733 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
2666 | ], |
2734 | ], |
2667 | mana => [ |
2735 | mana => [ |
2668 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2736 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2669 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
2737 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
2670 | ], |
2738 | ], |
2671 | ); |
2739 | ); |
2672 | |
2740 | |
2673 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
2741 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
… | |
… | |
2776 | glDisable GL_TEXTURE_2D; |
2844 | glDisable GL_TEXTURE_2D; |
2777 | } |
2845 | } |
2778 | |
2846 | |
2779 | ############################################################################# |
2847 | ############################################################################# |
2780 | |
2848 | |
2781 | package CFPlus::UI::Progress; |
2849 | package DC::UI::Progress; |
2782 | |
2850 | |
2783 | our @ISA = CFPlus::UI::Label::; |
2851 | our @ISA = DC::UI::Label::; |
2784 | |
2852 | |
2785 | use CFPlus::OpenGL; |
2853 | use DC::OpenGL; |
2786 | |
2854 | |
2787 | sub new { |
2855 | sub new { |
2788 | my ($class, %arg) = @_; |
2856 | my ($class, %arg) = @_; |
2789 | |
2857 | |
2790 | my $self = $class->SUPER::new ( |
2858 | my $self = $class->SUPER::new ( |
|
|
2859 | padding_x => 2, |
|
|
2860 | padding_y => 2, |
2791 | fg => [1, 1, 1], |
2861 | fg => [1, 1, 1], |
2792 | bg => [0, 0, 1, 0.2], |
2862 | bg => [0, 0, 1, 0.2], |
2793 | bar => [0.7, 0.5, 0.1, 0.8], |
2863 | bar => [0.7, 0.5, 0.1, 0.8], |
2794 | outline => [0.4, 0.3, 0], |
2864 | outline => [0.4, 0.3, 0], |
2795 | fontsize => 0.9, |
2865 | fontsize => 0.9, |
2796 | valign => 0, |
2866 | valign => 0.5, |
2797 | align => 0, |
2867 | align => 0.5, |
2798 | can_events => 1, |
2868 | can_events => 1, |
2799 | ellipsise => 1, |
2869 | ellipsise => 1, |
2800 | label => "%d%%", |
2870 | label => "%d%%", |
2801 | %arg, |
2871 | %arg, |
2802 | ); |
2872 | ); |
… | |
… | |
2810 | my ($self, $label) = @_; |
2880 | my ($self, $label) = @_; |
2811 | |
2881 | |
2812 | return if $self->{label} eq $label; |
2882 | return if $self->{label} eq $label; |
2813 | $self->{label} = $label; |
2883 | $self->{label} = $label; |
2814 | |
2884 | |
2815 | $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value}); |
2885 | $self->DC::UI::Progress::set_value (0 + delete $self->{value}); |
2816 | } |
2886 | } |
2817 | |
2887 | |
2818 | sub set_value { |
2888 | sub set_value { |
2819 | my ($self, $value) = @_; |
2889 | my ($self, $value) = @_; |
2820 | |
2890 | |
… | |
… | |
2835 | my ($self) = @_; |
2905 | my ($self) = @_; |
2836 | |
2906 | |
2837 | glEnable GL_BLEND; |
2907 | glEnable GL_BLEND; |
2838 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2908 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2839 | |
2909 | |
|
|
2910 | my $px = $self->{padding_x}; |
|
|
2911 | my $py = $self->{padding_y}; |
|
|
2912 | |
2840 | if ($self->{value} >= 0) { |
2913 | if ($self->{value} >= 0) { |
2841 | my $s = int 2 + ($self->{w} - 4) * $self->{value}; |
2914 | my $s = int $px + ($self->{w} - $px * 2) * $self->{value}; |
2842 | |
2915 | |
2843 | glColor_premultiply @{$self->{bar}}; |
2916 | glColor_premultiply @{$self->{bar}}; |
2844 | glRect 2, 2, $s, $self->{h} - 2; |
2917 | glRect $px, $py, $s, $self->{h} - $py; |
2845 | glColor_premultiply @{$self->{bg}}; |
2918 | glColor_premultiply @{$self->{bg}}; |
2846 | glRect $s, 2, $self->{w} - 2, $self->{h} - 2; |
2919 | glRect $s , $py, $self->{w} - $px, $self->{h} - $py; |
2847 | } |
2920 | } |
2848 | |
2921 | |
2849 | glColor_premultiply @{$self->{outline}}; |
2922 | glColor_premultiply @{$self->{outline}}; |
|
|
2923 | |
|
|
2924 | $px -= .5; |
|
|
2925 | $py -= .5; |
|
|
2926 | |
2850 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
2927 | glRect_lineloop $px, $py, $self->{w} - $px, $self->{h} - $py; |
2851 | |
2928 | |
2852 | glDisable GL_BLEND; |
2929 | glDisable GL_BLEND; |
2853 | |
2930 | |
2854 | { |
2931 | { |
2855 | local $self->{bg}; # do not draw background |
2932 | local $self->{bg}; # do not draw background |
… | |
… | |
2857 | } |
2934 | } |
2858 | } |
2935 | } |
2859 | |
2936 | |
2860 | ############################################################################# |
2937 | ############################################################################# |
2861 | |
2938 | |
2862 | package CFPlus::UI::ExperienceProgress; |
2939 | package DC::UI::ExperienceProgress; |
2863 | |
2940 | |
2864 | our @ISA = CFPlus::UI::Progress::; |
2941 | our @ISA = DC::UI::Progress::; |
2865 | |
2942 | |
2866 | sub new { |
2943 | sub new { |
2867 | my ($class, %arg) = @_; |
2944 | my ($class, %arg) = @_; |
2868 | |
2945 | |
|
|
2946 | my $tt = exists $arg{tooltip} ? "$arg{tooltip}\n\n" : ""; |
|
|
2947 | |
2869 | my $self = $class->SUPER::new ( |
2948 | my $self = $class->SUPER::new ( |
|
|
2949 | %arg, |
2870 | tooltip => sub { |
2950 | tooltip => sub { |
2871 | my ($self) = @_; |
2951 | my ($self) = @_; |
2872 | |
2952 | |
2873 | sprintf "level %d\n%s points\n%s next level\n%s to go", |
2953 | sprintf "%slevel %d\n%s points\n%s next level\n%s to go, %d%% done", |
|
|
2954 | $tt, |
2874 | $self->{lvl}, |
2955 | $self->{lvl}, |
2875 | ::formsep ($self->{exp}), |
2956 | ::formsep ($self->{exp}), |
2876 | ::formsep ($self->{nxt}), |
2957 | ::formsep ($self->{nxt}), |
2877 | ::formsep ($self->{nxt} - $self->{exp}), |
2958 | ::formsep ($self->{nxt} - $self->{exp}), |
|
|
2959 | $self->_percent * 100, |
2878 | }, |
2960 | }, |
2879 | %arg |
|
|
2880 | ); |
2961 | ); |
2881 | |
2962 | |
2882 | $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } |
2963 | $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } |
2883 | if $::CONN; |
2964 | if $::CONN; |
2884 | |
2965 | |
… | |
… | |
2892 | if $::CONN; |
2973 | if $::CONN; |
2893 | |
2974 | |
2894 | $self->SUPER::DESTROY; |
2975 | $self->SUPER::DESTROY; |
2895 | } |
2976 | } |
2896 | |
2977 | |
|
|
2978 | sub _percent { |
|
|
2979 | my ($self) = @_; |
|
|
2980 | |
|
|
2981 | my $table = $::CONN && $::CONN->{exp_table} |
|
|
2982 | or return -1; |
|
|
2983 | |
|
|
2984 | my $l0 = $table->[$self->{lvl} - 1]; |
|
|
2985 | my $l1 = $table->[$self->{lvl}]; |
|
|
2986 | |
|
|
2987 | $self->{nxt} = $l1; |
|
|
2988 | |
|
|
2989 | ($self->{exp} - $l0) / ($l1 - $l0) |
|
|
2990 | } |
|
|
2991 | |
2897 | sub set_value { |
2992 | sub set_value { |
2898 | my ($self, $lvl, $exp) = @_; |
2993 | my ($self, $lvl, $exp) = @_; |
2899 | |
2994 | |
2900 | $self->{lvl} = $lvl; |
2995 | $self->{lvl} = $lvl; |
2901 | $self->{exp} = $exp; |
2996 | $self->{exp} = $exp; |
2902 | |
2997 | |
2903 | my $v = -1; |
|
|
2904 | |
|
|
2905 | if ($::CONN && (my $table = $::CONN->{exp_table})) { |
|
|
2906 | my $l0 = $table->[$lvl - 1]; |
|
|
2907 | my $l1 = $table->[$lvl]; |
|
|
2908 | |
|
|
2909 | $self->{nxt} = $l1; |
|
|
2910 | |
|
|
2911 | $v = ($exp - $l0) / ($l1 - $l0); |
|
|
2912 | } |
|
|
2913 | |
|
|
2914 | $self->SUPER::set_value ($v); |
2998 | $self->SUPER::set_value ($self->_percent); |
2915 | } |
2999 | } |
2916 | |
3000 | |
2917 | ############################################################################# |
3001 | ############################################################################# |
2918 | |
3002 | |
2919 | package CFPlus::UI::Gauge; |
3003 | package DC::UI::Gauge; |
2920 | |
3004 | |
2921 | our @ISA = CFPlus::UI::VBox::; |
3005 | our @ISA = DC::UI::VBox::; |
2922 | |
3006 | |
2923 | sub new { |
3007 | sub new { |
2924 | my ($class, %arg) = @_; |
3008 | my ($class, %arg) = @_; |
2925 | |
3009 | |
2926 | my $self = $class->SUPER::new ( |
3010 | my $self = $class->SUPER::new ( |
… | |
… | |
2928 | can_hover => 1, |
3012 | can_hover => 1, |
2929 | can_events => 1, |
3013 | can_events => 1, |
2930 | %arg, |
3014 | %arg, |
2931 | ); |
3015 | ); |
2932 | |
3016 | |
2933 | $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999"); |
3017 | $self->add ($self->{value} = new DC::UI::Label valign => 1, align => 0.5, template => "999"); |
2934 | $self->add ($self->{gauge} = new CFPlus::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
3018 | $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
2935 | $self->add ($self->{max} = new CFPlus::UI::Label valign => -1, align => 0, template => "999"); |
3019 | $self->add ($self->{max} = new DC::UI::Label valign => 0, align => 0.5, template => "999"); |
2936 | |
3020 | |
2937 | $self |
3021 | $self |
2938 | } |
3022 | } |
2939 | |
3023 | |
2940 | sub set_fontsize { |
3024 | sub set_fontsize { |
… | |
… | |
2961 | $self->{value}->set_text ($val); |
3045 | $self->{value}->set_text ($val); |
2962 | } |
3046 | } |
2963 | |
3047 | |
2964 | ############################################################################# |
3048 | ############################################################################# |
2965 | |
3049 | |
2966 | package CFPlus::UI::Slider; |
3050 | package DC::UI::Slider; |
2967 | |
3051 | |
2968 | use strict; |
3052 | use strict; |
2969 | |
3053 | |
2970 | use CFPlus::OpenGL; |
3054 | use DC::OpenGL; |
2971 | |
3055 | |
2972 | our @ISA = CFPlus::UI::DrawBG::; |
3056 | our @ISA = DC::UI::DrawBG::; |
2973 | |
3057 | |
2974 | my @tex = |
3058 | my @tex = |
2975 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ } |
3059 | map { new_from_resource DC::Texture $_ } |
2976 | qw(s1_slider.png s1_slider_bg.png); |
3060 | qw(s1_slider.png s1_slider_bg.png); |
2977 | |
3061 | |
2978 | sub new { |
3062 | sub new { |
2979 | my $class = shift; |
3063 | my $class = shift; |
2980 | |
3064 | |
… | |
… | |
3017 | sub set_value { |
3101 | sub set_value { |
3018 | my ($self, $value) = @_; |
3102 | my ($self, $value) = @_; |
3019 | |
3103 | |
3020 | my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; |
3104 | my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; |
3021 | |
3105 | |
3022 | $hi = $lo + 1 if $hi <= $lo; |
3106 | $hi = $lo if $hi < $lo; |
3023 | |
3107 | |
3024 | $page = $hi - $lo if $page > $hi - $lo; |
3108 | $value = $hi - $page if $value > $hi - $page; |
3025 | |
|
|
3026 | $value = $lo if $value < $lo; |
3109 | $value = $lo if $value < $lo; |
3027 | $value = $hi - $page if $value > $hi - $page; |
|
|
3028 | |
3110 | |
3029 | $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit |
3111 | $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit |
3030 | if $unit; |
3112 | if $unit; |
3031 | |
3113 | |
3032 | @{$self->{range}} = ($value, $lo, $hi, $page, $unit); |
3114 | @{$self->{range}} = ($value, $lo, $hi, $page, $unit); |
… | |
… | |
3076 | sub invoke_mouse_wheel { |
3158 | sub invoke_mouse_wheel { |
3077 | my ($self, $ev) = @_; |
3159 | my ($self, $ev) = @_; |
3078 | |
3160 | |
3079 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
3161 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
3080 | |
3162 | |
3081 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
3163 | my $pagepart = $ev->{mod} & DC::KMOD_SHIFT ? 1 : 0.2; |
3082 | |
3164 | |
3083 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
3165 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
3084 | |
3166 | |
3085 | 1 |
3167 | 1 |
3086 | } |
3168 | } |
… | |
… | |
3096 | my ($self) = @_; |
3178 | my ($self) = @_; |
3097 | |
3179 | |
3098 | unless ($self->{knob_w}) { |
3180 | unless ($self->{knob_w}) { |
3099 | $self->set_value ($self->{range}[0]); |
3181 | $self->set_value ($self->{range}[0]); |
3100 | |
3182 | |
3101 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
3183 | my ($value, $lo, $hi, $page, $unit) = @{$self->{range}}; |
3102 | my $range = ($hi - $page - $lo) || 1e-100; |
3184 | my $range = ($hi - $page - $lo) || 1e-10; |
3103 | |
3185 | |
3104 | my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1; |
3186 | my $knob_w = List::Util::min 1, $page / (($hi - $lo) || 1e-10) || 24 / $self->{w}; |
3105 | |
3187 | |
3106 | $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; |
3188 | $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; |
3107 | $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; |
3189 | $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; |
3108 | |
3190 | |
3109 | $value = ($value - $lo) / $range; |
3191 | $value = ($value - $lo) / $range; |
… | |
… | |
3139 | glDisable GL_TEXTURE_2D; |
3221 | glDisable GL_TEXTURE_2D; |
3140 | } |
3222 | } |
3141 | |
3223 | |
3142 | ############################################################################# |
3224 | ############################################################################# |
3143 | |
3225 | |
3144 | package CFPlus::UI::ValSlider; |
3226 | package DC::UI::ValSlider; |
3145 | |
3227 | |
3146 | our @ISA = CFPlus::UI::HBox::; |
3228 | our @ISA = DC::UI::HBox::; |
3147 | |
3229 | |
3148 | sub new { |
3230 | sub new { |
3149 | my ($class, %arg) = @_; |
3231 | my ($class, %arg) = @_; |
3150 | |
3232 | |
3151 | my $range = delete $arg{range}; |
3233 | my $range = delete $arg{range}; |
3152 | |
3234 | |
3153 | my $self = $class->SUPER::new ( |
3235 | my $self = $class->SUPER::new ( |
3154 | slider => (new CFPlus::UI::Slider expand => 1, range => $range), |
3236 | slider => (new DC::UI::Slider expand => 1, range => $range), |
3155 | entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}), |
3237 | entry => (new DC::UI::Label text => "", template => delete $arg{template}), |
3156 | to_value => sub { shift }, |
3238 | to_value => sub { shift }, |
3157 | from_value => sub { shift }, |
3239 | from_value => sub { shift }, |
3158 | %arg, |
3240 | %arg, |
3159 | ); |
3241 | ); |
3160 | |
3242 | |
… | |
… | |
3180 | sub set_range { shift->{slider}->set_range (@_) } |
3262 | sub set_range { shift->{slider}->set_range (@_) } |
3181 | sub set_value { shift->{slider}->set_value (@_) } |
3263 | sub set_value { shift->{slider}->set_value (@_) } |
3182 | |
3264 | |
3183 | ############################################################################# |
3265 | ############################################################################# |
3184 | |
3266 | |
3185 | package CFPlus::UI::TextScroller; |
3267 | package DC::UI::TextScroller; |
3186 | |
3268 | |
3187 | our @ISA = CFPlus::UI::HBox::; |
3269 | our @ISA = DC::UI::HBox::; |
3188 | |
3270 | |
3189 | use CFPlus::OpenGL; |
3271 | use DC::OpenGL; |
3190 | |
3272 | |
3191 | sub new { |
3273 | sub new { |
3192 | my $class = shift; |
3274 | my $class = shift; |
3193 | |
3275 | |
3194 | my $self = $class->SUPER::new ( |
3276 | my $self = $class->SUPER::new ( |
… | |
… | |
3196 | can_events => 1, |
3278 | can_events => 1, |
3197 | indent => 0, |
3279 | indent => 0, |
3198 | #font => default_font |
3280 | #font => default_font |
3199 | @_, |
3281 | @_, |
3200 | |
3282 | |
3201 | layout => (new CFPlus::Layout), |
3283 | layout => (new DC::Layout), |
3202 | par => [], |
3284 | par => [], |
3203 | max_par => 0, |
3285 | max_par => 0, |
3204 | height => 0, |
3286 | height => 0, |
3205 | children => [ |
3287 | children => [ |
3206 | (new CFPlus::UI::Empty expand => 1), |
3288 | (new DC::UI::Empty expand => 1), |
3207 | (new CFPlus::UI::Slider vertical => 1), |
3289 | (new DC::UI::Slider vertical => 1), |
3208 | ], |
3290 | ], |
3209 | ); |
3291 | ); |
3210 | |
3292 | |
3211 | $self->{children}[1]->connect (changed => sub { $self->update }); |
3293 | $self->{children}[1]->connect (changed => sub { $self->update }); |
3212 | |
3294 | |
… | |
… | |
3268 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
3350 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
3269 | $layout->set_markup ($para->{markup}); |
3351 | $layout->set_markup ($para->{markup}); |
3270 | |
3352 | |
3271 | $layout->set_shapes ( |
3353 | $layout->set_shapes ( |
3272 | map |
3354 | map |
3273 | +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), |
3355 | +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), |
3274 | @{$para->{widget}} |
3356 | @{$para->{widget}} |
3275 | ); |
3357 | ); |
3276 | |
3358 | |
3277 | $layout |
3359 | $layout |
3278 | } |
3360 | } |
… | |
… | |
3395 | $ROOT->on_post_alloc ($self => sub { |
3477 | $ROOT->on_post_alloc ($self => sub { |
3396 | $self->force_uptodate; |
3478 | $self->force_uptodate; |
3397 | |
3479 | |
3398 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
3480 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
3399 | |
3481 | |
3400 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
3482 | $self->{texture} ||= new_from_opengl DC::Texture $W, $H, sub { |
3401 | glClearColor 0, 0, 0, 0; |
3483 | glClearColor 0, 0, 0, 0; |
3402 | glClear GL_COLOR_BUFFER_BIT; |
3484 | glClear GL_COLOR_BUFFER_BIT; |
3403 | |
3485 | |
3404 | package CFPlus::UI::Base; |
3486 | package DC::UI::Base; |
3405 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
3487 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
3406 | (0, 0, $self->{w}, $self->{h}); |
3488 | (0, 0, $self->{w}, $self->{h}); |
3407 | |
3489 | |
3408 | my $top = int $self->{children}[1]{range}[0]; |
3490 | my $top = int $self->{children}[1]{range}[0]; |
3409 | |
3491 | |
… | |
… | |
3468 | $self->{children}[1]->draw; |
3550 | $self->{children}[1]->draw; |
3469 | } |
3551 | } |
3470 | |
3552 | |
3471 | ############################################################################# |
3553 | ############################################################################# |
3472 | |
3554 | |
3473 | package CFPlus::UI::Animator; |
3555 | package DC::UI::Animator; |
3474 | |
3556 | |
3475 | use CFPlus::OpenGL; |
3557 | use DC::OpenGL; |
3476 | |
3558 | |
3477 | our @ISA = CFPlus::UI::Bin::; |
3559 | our @ISA = DC::UI::Bin::; |
3478 | |
3560 | |
3479 | sub moveto { |
3561 | sub moveto { |
3480 | my ($self, $x, $y) = @_; |
3562 | my ($self, $x, $y) = @_; |
3481 | |
3563 | |
3482 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
3564 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
… | |
… | |
3510 | glPopMatrix; |
3592 | glPopMatrix; |
3511 | } |
3593 | } |
3512 | |
3594 | |
3513 | ############################################################################# |
3595 | ############################################################################# |
3514 | |
3596 | |
3515 | package CFPlus::UI::Flopper; |
3597 | package DC::UI::Flopper; |
3516 | |
3598 | |
3517 | our @ISA = CFPlus::UI::Button::; |
3599 | our @ISA = DC::UI::Button::; |
3518 | |
3600 | |
3519 | sub new { |
3601 | sub new { |
3520 | my $class = shift; |
3602 | my $class = shift; |
3521 | |
3603 | |
3522 | my $self = $class->SUPER::new ( |
3604 | my $self = $class->SUPER::new ( |
… | |
… | |
3534 | $self->{other}->toggle_visibility; |
3616 | $self->{other}->toggle_visibility; |
3535 | } |
3617 | } |
3536 | |
3618 | |
3537 | ############################################################################# |
3619 | ############################################################################# |
3538 | |
3620 | |
3539 | package CFPlus::UI::Tooltip; |
3621 | package DC::UI::Tooltip; |
3540 | |
3622 | |
3541 | our @ISA = CFPlus::UI::Bin::; |
3623 | our @ISA = DC::UI::Bin::; |
3542 | |
3624 | |
3543 | use CFPlus::OpenGL; |
3625 | use DC::OpenGL; |
3544 | |
3626 | |
3545 | sub new { |
3627 | sub new { |
3546 | my $class = shift; |
3628 | my $class = shift; |
3547 | |
3629 | |
3548 | $class->SUPER::new ( |
3630 | $class->SUPER::new ( |
… | |
… | |
3555 | my ($self, $widget) = @_; |
3637 | my ($self, $widget) = @_; |
3556 | |
3638 | |
3557 | my $tip = $widget->{tooltip}; |
3639 | my $tip = $widget->{tooltip}; |
3558 | $tip = $tip->($widget) if "CODE" eq ref $tip; |
3640 | $tip = $tip->($widget) if "CODE" eq ref $tip; |
3559 | |
3641 | |
3560 | $tip = CFPlus::Pod::section_label tooltip => $1 |
3642 | $tip = DC::Pod::section_label tooltip => $1 |
3561 | if $tip =~ /^#(.*)$/; |
3643 | if $tip =~ /^#(.*)$/; |
3562 | |
3644 | |
3563 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3645 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3564 | $tip .= "\n\n" . (ref $widget) . "\n" |
3646 | $tip .= "\n\n" . (ref $widget) . "\n" |
3565 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3647 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
… | |
… | |
3568 | } |
3650 | } |
3569 | |
3651 | |
3570 | $tip =~ s/^\n+//; |
3652 | $tip =~ s/^\n+//; |
3571 | $tip =~ s/\n+$//; |
3653 | $tip =~ s/\n+$//; |
3572 | |
3654 | |
3573 | $self->add (new CFPlus::UI::Label |
3655 | $self->add (new DC::UI::Label |
|
|
3656 | fg => $DC::THEME{tooltip_fg}, |
3574 | markup => $tip, |
3657 | markup => $tip, |
3575 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3658 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
|
|
3659 | align => 0, |
3576 | fontsize => 0.8, |
3660 | fontsize => 0.8, |
3577 | style => 1, # FLAG_INVERSE |
3661 | style => $DC::THEME{tooltip_style}, # FLAG_INVERSE |
3578 | ellipsise => 0, |
3662 | ellipsise => 0, |
3579 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3663 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3580 | ); |
3664 | ); |
3581 | } |
3665 | } |
3582 | |
3666 | |
… | |
… | |
3619 | sub _draw { |
3703 | sub _draw { |
3620 | my ($self) = @_; |
3704 | my ($self) = @_; |
3621 | |
3705 | |
3622 | my ($w, $h) = @$self{qw(w h)}; |
3706 | my ($w, $h) = @$self{qw(w h)}; |
3623 | |
3707 | |
3624 | glColor 1, 0.8, 0.4; |
3708 | glColor @{ $DC::THEME{tooltip_bg} }; |
3625 | glRect 0, 0, $w, $h; |
3709 | glRect 0, 0, $w, $h; |
3626 | |
3710 | |
3627 | glColor 0, 0, 0; |
3711 | glColor @{ $DC::THEME{tooltip_border} }; |
3628 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3712 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3629 | |
3713 | |
3630 | glTranslate 2, 2; |
3714 | glTranslate 2, 2; |
3631 | |
3715 | |
3632 | $self->SUPER::_draw; |
3716 | $self->SUPER::_draw; |
3633 | } |
3717 | } |
3634 | |
3718 | |
3635 | ############################################################################# |
3719 | ############################################################################# |
3636 | |
3720 | |
3637 | package CFPlus::UI::Face; |
3721 | package DC::UI::Face; |
3638 | |
3722 | |
3639 | our @ISA = CFPlus::UI::DrawBG::; |
3723 | our @ISA = DC::UI::DrawBG::; |
3640 | |
3724 | |
3641 | use CFPlus::OpenGL; |
3725 | use DC::OpenGL; |
3642 | |
3726 | |
3643 | sub new { |
3727 | sub new { |
3644 | my $class = shift; |
3728 | my $class = shift; |
3645 | |
3729 | |
3646 | my $self = $class->SUPER::new ( |
3730 | my $self = $class->SUPER::new ( |
… | |
… | |
3649 | aspect => 1, |
3733 | aspect => 1, |
3650 | can_events => 0, |
3734 | can_events => 0, |
3651 | @_, |
3735 | @_, |
3652 | ); |
3736 | ); |
3653 | |
3737 | |
3654 | if ($self->{anim} && $self->{animspeed}) { |
|
|
3655 | CFPlus::weaken (my $widget = $self); |
|
|
3656 | |
|
|
3657 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
|
|
3658 | $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; |
|
|
3659 | $self->{timer} = Event->timer ( |
|
|
3660 | parked => 1, |
|
|
3661 | cb => sub { |
|
|
3662 | return unless $::CONN; |
|
|
3663 | |
|
|
3664 | my $w = $widget |
|
|
3665 | or return; |
|
|
3666 | |
|
|
3667 | ++$w->{frame}; |
|
|
3668 | $w->update_face; |
|
|
3669 | |
|
|
3670 | # somehow, $widget can go away |
|
|
3671 | $w->update; |
|
|
3672 | $w->update_timer; |
|
|
3673 | }, |
|
|
3674 | ); |
|
|
3675 | |
|
|
3676 | $self->update_face; |
|
|
3677 | $self->update_timer; |
3738 | $self->update_anim; |
3678 | } |
|
|
3679 | |
3739 | |
3680 | $self |
3740 | $self |
3681 | } |
3741 | } |
3682 | |
3742 | |
3683 | sub update_timer { |
3743 | sub update_timer { |
3684 | my ($self) = @_; |
3744 | my ($self) = @_; |
3685 | |
3745 | |
3686 | return unless $self->{timer}; |
3746 | return unless $self->{timer}; |
3687 | |
3747 | |
3688 | if ($self->{visible}) { |
3748 | if ($self->{visible}) { |
3689 | $self->{timer}->at ( |
|
|
3690 | $self->{anim_start} |
|
|
3691 | + $self->{animspeed} |
|
|
3692 | * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed} |
|
|
3693 | ); |
|
|
3694 | $self->{timer}->start; |
3749 | $self->{timer}->start; |
3695 | } else { |
3750 | } else { |
3696 | $self->{timer}->stop; |
3751 | $self->{timer}->stop; |
3697 | } |
3752 | } |
3698 | } |
3753 | } |
… | |
… | |
3711 | $tex->upload (sub { $self->reconfigure }); |
3766 | $tex->upload (sub { $self->reconfigure }); |
3712 | } |
3767 | } |
3713 | } |
3768 | } |
3714 | } |
3769 | } |
3715 | } |
3770 | } |
|
|
3771 | } |
|
|
3772 | } |
|
|
3773 | |
|
|
3774 | sub update_anim { |
|
|
3775 | my ($self) = @_; |
|
|
3776 | |
|
|
3777 | if ($self->{anim} && $self->{animspeed}) { |
|
|
3778 | DC::weaken (my $widget = $self); |
|
|
3779 | |
|
|
3780 | $self->{animspeed} = List::Util::max 0.05, $self->{animspeed}; |
|
|
3781 | $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub { |
|
|
3782 | return unless $::CONN; |
|
|
3783 | |
|
|
3784 | my $w = $widget |
|
|
3785 | or return; |
|
|
3786 | |
|
|
3787 | ++$w->{frame}; |
|
|
3788 | $w->update_face; |
|
|
3789 | |
|
|
3790 | # somehow, $widget can go away |
|
|
3791 | $w->update; |
|
|
3792 | $w->update_timer; |
|
|
3793 | }; |
|
|
3794 | |
|
|
3795 | $self->update_face; |
|
|
3796 | $self->update_timer; |
|
|
3797 | } else { |
|
|
3798 | delete $self->{timer}; |
3716 | } |
3799 | } |
3717 | } |
3800 | } |
3718 | |
3801 | |
3719 | sub size_request { |
3802 | sub size_request { |
3720 | my ($self) = @_; |
3803 | my ($self) = @_; |
… | |
… | |
3742 | return unless $self->{visible}; |
3825 | return unless $self->{visible}; |
3743 | |
3826 | |
3744 | $self->SUPER::update; |
3827 | $self->SUPER::update; |
3745 | } |
3828 | } |
3746 | |
3829 | |
|
|
3830 | sub set_face { |
|
|
3831 | my ($self, $face) = @_; |
|
|
3832 | |
|
|
3833 | $self->{face} = $face; |
|
|
3834 | $self->reconfigure; |
|
|
3835 | } |
|
|
3836 | |
|
|
3837 | sub set_anim { |
|
|
3838 | my ($self, $anim) = @_; |
|
|
3839 | |
|
|
3840 | $self->{anim} = $anim; |
|
|
3841 | $self->update_anim; |
|
|
3842 | } |
|
|
3843 | |
|
|
3844 | sub set_animspeed { |
|
|
3845 | my ($self, $animspeed) = @_; |
|
|
3846 | |
|
|
3847 | $self->{animspeed} = $animspeed; |
|
|
3848 | $self->update_anim; |
|
|
3849 | } |
|
|
3850 | |
3747 | sub invoke_visibility_change { |
3851 | sub invoke_visibility_change { |
3748 | my ($self) = @_; |
3852 | my ($self) = @_; |
3749 | |
3853 | |
3750 | $self->update_timer; |
3854 | $self->update_timer; |
3751 | |
3855 | |
… | |
… | |
3775 | $self->SUPER::destroy; |
3879 | $self->SUPER::destroy; |
3776 | } |
3880 | } |
3777 | |
3881 | |
3778 | ############################################################################# |
3882 | ############################################################################# |
3779 | |
3883 | |
3780 | package CFPlus::UI::Buttonbar; |
3884 | package DC::UI::Buttonbar; |
3781 | |
3885 | |
3782 | our @ISA = CFPlus::UI::HBox::; |
3886 | our @ISA = DC::UI::HBox::; |
3783 | |
3887 | |
3784 | # TODO: should actually wrap buttons and other goodies. |
3888 | # TODO: should actually wrap buttons and other goodies. |
3785 | |
3889 | |
3786 | ############################################################################# |
3890 | ############################################################################# |
3787 | |
3891 | |
3788 | package CFPlus::UI::Menu; |
3892 | package DC::UI::Menu; |
3789 | |
3893 | |
3790 | our @ISA = CFPlus::UI::Toplevel::; |
3894 | our @ISA = DC::UI::Toplevel::; |
3791 | |
3895 | |
3792 | use CFPlus::OpenGL; |
3896 | use DC::OpenGL; |
3793 | |
3897 | |
3794 | sub new { |
3898 | sub new { |
3795 | my $class = shift; |
3899 | my $class = shift; |
3796 | |
3900 | |
3797 | my $self = $class->SUPER::new ( |
3901 | my $self = $class->SUPER::new ( |
3798 | items => [], |
3902 | items => [], |
3799 | z => 100, |
3903 | z => 100, |
3800 | @_, |
3904 | @_, |
3801 | ); |
3905 | ); |
3802 | |
3906 | |
3803 | $self->add ($self->{vbox} = new CFPlus::UI::VBox); |
3907 | $self->add ($self->{vbox} = new DC::UI::VBox); |
3804 | |
3908 | |
3805 | for my $item (@{ $self->{items} }) { |
3909 | for my $item (@{ $self->{items} }) { |
3806 | my ($widget, $cb, $tooltip) = @$item; |
3910 | my ($widget, $cb, $tooltip) = @$item; |
3807 | |
3911 | |
3808 | # handle various types of items, only text for now |
3912 | # handle various types of items, only text for now |
3809 | if (!ref $widget) { |
3913 | if (!ref $widget) { |
3810 | if ($widget =~ /\t/) { |
3914 | if ($widget =~ /\t/) { |
3811 | my ($left, $right) = split /\t/, $widget, 2; |
3915 | my ($left, $right) = split /\t/, $widget, 2; |
3812 | |
3916 | |
3813 | $widget = new CFPlus::UI::HBox |
3917 | $widget = new DC::UI::HBox |
3814 | can_hover => 1, |
3918 | can_hover => 1, |
3815 | can_events => 1, |
3919 | can_events => 1, |
3816 | tooltip => $tooltip, |
3920 | tooltip => $tooltip, |
3817 | children => [ |
3921 | children => [ |
3818 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3922 | (new DC::UI::Label markup => $left , align => 0, expand => 1), |
3819 | (new CFPlus::UI::Label markup => $right, align => +1), |
3923 | (new DC::UI::Label markup => $right, align => 1), |
3820 | ], |
3924 | ], |
3821 | ; |
3925 | ; |
3822 | |
3926 | |
3823 | } else { |
3927 | } else { |
3824 | $widget = new CFPlus::UI::Label |
3928 | $widget = new DC::UI::Label |
3825 | can_hover => 1, |
3929 | can_hover => 1, |
3826 | can_events => 1, |
3930 | can_events => 1, |
|
|
3931 | align => 0, |
3827 | markup => $widget, |
3932 | markup => $widget, |
3828 | tooltip => $tooltip; |
3933 | tooltip => $tooltip; |
3829 | } |
3934 | } |
3830 | } |
3935 | } |
3831 | |
3936 | |
… | |
… | |
3846 | # maybe save $GRAB? must be careful about events... |
3951 | # maybe save $GRAB? must be careful about events... |
3847 | $GRAB = $self; |
3952 | $GRAB = $self; |
3848 | $self->{button} = $ev->{button}; |
3953 | $self->{button} = $ev->{button}; |
3849 | |
3954 | |
3850 | $self->show; |
3955 | $self->show; |
3851 | $self->move_abs ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); |
3956 | |
|
|
3957 | my $x = $ev->{x}; |
|
|
3958 | my $y = $ev->{y}; |
|
|
3959 | |
|
|
3960 | $self->{root}->on_post_alloc ($self => sub { |
|
|
3961 | $self->move_abs ($x - $self->{w} * 0.25, $y - $self->{border} * $::FONTSIZE * .5); |
|
|
3962 | }); |
|
|
3963 | |
|
|
3964 | 1 # so it can be used inside event handlers |
3852 | } |
3965 | } |
3853 | |
3966 | |
3854 | sub invoke_mouse_motion { |
3967 | sub invoke_mouse_motion { |
3855 | my ($self, $ev, $x, $y) = @_; |
3968 | my ($self, $ev, $x, $y) = @_; |
3856 | |
3969 | |
… | |
… | |
3877 | 1 |
3990 | 1 |
3878 | } |
3991 | } |
3879 | |
3992 | |
3880 | ############################################################################# |
3993 | ############################################################################# |
3881 | |
3994 | |
3882 | package CFPlus::UI::Multiplexer; |
3995 | package DC::UI::Multiplexer; |
3883 | |
3996 | |
3884 | our @ISA = CFPlus::UI::Container::; |
3997 | our @ISA = DC::UI::Container::; |
3885 | |
3998 | |
3886 | sub new { |
3999 | sub new { |
3887 | my $class = shift; |
4000 | my $class = shift; |
3888 | |
4001 | |
3889 | my $self = $class->SUPER::new ( |
4002 | my $self = $class->SUPER::new ( |
3890 | @_, |
4003 | @_, |
3891 | ); |
4004 | ); |
3892 | |
4005 | |
3893 | $self->{current} = $self->{children}[0] |
4006 | $self->set_current_page (0); |
3894 | if @{ $self->{children} }; |
|
|
3895 | |
4007 | |
3896 | $self |
4008 | $self |
3897 | } |
4009 | } |
3898 | |
4010 | |
3899 | sub add { |
4011 | sub add { |
3900 | my ($self, @widgets) = @_; |
4012 | my ($self, @widgets) = @_; |
3901 | |
4013 | |
3902 | $self->SUPER::add (@widgets); |
4014 | $self->SUPER::add (@widgets); |
3903 | |
4015 | |
3904 | $self->{current} = $self->{children}[0] |
4016 | $self->set_current_page (0) |
3905 | if @{ $self->{children} }; |
4017 | if @widgets == @{ $self->{children} }; |
3906 | } |
4018 | } |
3907 | |
4019 | |
3908 | sub get_current_page { |
4020 | sub get_current_page { |
3909 | my ($self) = @_; |
4021 | my ($self) = @_; |
3910 | |
4022 | |
… | |
… | |
3916 | |
4028 | |
3917 | my $widget = ref $page_or_widget |
4029 | my $widget = ref $page_or_widget |
3918 | ? $page_or_widget |
4030 | ? $page_or_widget |
3919 | : $self->{children}[$page_or_widget]; |
4031 | : $self->{children}[$page_or_widget]; |
3920 | |
4032 | |
|
|
4033 | $self->{current}->set_invisible if $self->{current} && $self->{visible}; |
|
|
4034 | |
3921 | $self->{current} = $widget; |
4035 | if (($self->{current} = $widget)) { |
|
|
4036 | $self->{current}->set_visible if $self->{current} && $self->{visible}; |
3922 | $self->{current}->configure (0, 0, $self->{w}, $self->{h}); |
4037 | $self->{current}->configure (0, 0, $self->{w}, $self->{h}); |
3923 | |
4038 | |
3924 | $self->emit (page_changed => $self->{current}); |
4039 | $self->emit (page_changed => $self->{current}); |
|
|
4040 | } |
3925 | |
4041 | |
3926 | $self->realloc; |
4042 | $self->realloc; |
3927 | } |
4043 | } |
3928 | |
4044 | |
3929 | sub visible_children { |
4045 | sub visible_children { |
3930 | $_[0]{current} |
4046 | $_[0]{current} || () |
3931 | } |
4047 | } |
3932 | |
4048 | |
3933 | sub size_request { |
4049 | sub size_request { |
3934 | my ($self) = @_; |
4050 | my ($self) = @_; |
3935 | |
4051 | |
|
|
4052 | $self->{current} |
3936 | $self->{current}->size_request |
4053 | ? $self->{current}->size_request |
|
|
4054 | : (0, 0) |
3937 | } |
4055 | } |
3938 | |
4056 | |
3939 | sub invoke_size_allocate { |
4057 | sub invoke_size_allocate { |
3940 | my ($self, $w, $h) = @_; |
4058 | my ($self, $w, $h) = @_; |
3941 | |
4059 | |
3942 | $self->{current}->configure (0, 0, $w, $h); |
4060 | $self->{current}->configure (0, 0, $w, $h) |
|
|
4061 | if $self->{current}; |
3943 | |
4062 | |
3944 | 1 |
4063 | 1 |
3945 | } |
4064 | } |
3946 | |
4065 | |
3947 | sub _draw { |
4066 | sub _draw { |
3948 | my ($self) = @_; |
4067 | my ($self) = @_; |
3949 | |
4068 | |
3950 | $self->{current}->draw; |
4069 | $self->{current}->draw |
|
|
4070 | if $self->{current}; |
3951 | } |
4071 | } |
3952 | |
4072 | |
3953 | ############################################################################# |
4073 | ############################################################################# |
3954 | |
4074 | |
3955 | package CFPlus::UI::Notebook; |
4075 | package DC::UI::Notebook; |
3956 | |
4076 | |
3957 | use CFPlus::OpenGL; |
4077 | use DC::OpenGL; |
3958 | |
4078 | |
3959 | our @ISA = CFPlus::UI::VBox::; |
4079 | our @ISA = DC::UI::VBox::; |
3960 | |
4080 | |
3961 | sub new { |
4081 | sub new { |
3962 | my $class = shift; |
4082 | my $class = shift; |
3963 | |
4083 | |
3964 | my $self = $class->SUPER::new ( |
4084 | my $self = $class->SUPER::new ( |
3965 | buttonbar => (new CFPlus::UI::Buttonbar), |
4085 | buttonbar => (new DC::UI::Buttonbar), |
3966 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
4086 | multiplexer => (new DC::UI::Multiplexer expand => 1), |
3967 | active_outline => [.7, .7, 0.2], |
4087 | active_outline => [.7, .7, 0.2], |
3968 | # filter => # will be put between multiplexer and $self |
4088 | # filter => # will be put between multiplexer and $self |
3969 | @_, |
4089 | @_, |
3970 | ); |
4090 | ); |
3971 | |
4091 | |
… | |
… | |
3980 | |
4100 | |
3981 | for my $child (@$widgets) { |
4101 | for my $child (@$widgets) { |
3982 | Scalar::Util::weaken $child; |
4102 | Scalar::Util::weaken $child; |
3983 | $child->{c_tab_} ||= do { |
4103 | $child->{c_tab_} ||= do { |
3984 | my $tab = |
4104 | my $tab = |
3985 | (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") |
4105 | (UNIVERSAL::isa $child->{c_tab}, "DC::UI::Base") |
3986 | ? $child->{c_tab} |
4106 | ? $child->{c_tab} |
3987 | : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; |
4107 | : new DC::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; |
3988 | |
4108 | |
3989 | $tab->connect (activate => sub { |
4109 | $tab->connect (activate => sub { |
3990 | $wself->set_current_page ($child); |
4110 | $wself->set_current_page ($child); |
3991 | }); |
4111 | }); |
3992 | |
4112 | |
… | |
… | |
4022 | } |
4142 | } |
4023 | |
4143 | |
4024 | sub pages { |
4144 | sub pages { |
4025 | my ($self) = @_; |
4145 | my ($self) = @_; |
4026 | $self->{multiplexer}->children |
4146 | $self->{multiplexer}->children |
|
|
4147 | } |
|
|
4148 | |
|
|
4149 | sub page_index { |
|
|
4150 | my ($self, $widget) = @_; |
|
|
4151 | |
|
|
4152 | my $i = 0; |
|
|
4153 | for ($self->pages) { |
|
|
4154 | if ($_ eq $widget) { return $i }; |
|
|
4155 | $i++; |
|
|
4156 | } |
|
|
4157 | |
|
|
4158 | undef |
4027 | } |
4159 | } |
4028 | |
4160 | |
4029 | sub add_tab { |
4161 | sub add_tab { |
4030 | my ($self, $title, $widget, $tooltip) = @_; |
4162 | my ($self, $title, $widget, $tooltip) = @_; |
4031 | |
4163 | |
… | |
… | |
4068 | } |
4200 | } |
4069 | } |
4201 | } |
4070 | |
4202 | |
4071 | ############################################################################# |
4203 | ############################################################################# |
4072 | |
4204 | |
4073 | package CFPlus::UI::Selector; |
4205 | package DC::UI::Selector; |
4074 | |
4206 | |
4075 | use utf8; |
4207 | use utf8; |
4076 | |
4208 | |
4077 | our @ISA = CFPlus::UI::Button::; |
4209 | our @ISA = DC::UI::Button::; |
4078 | |
4210 | |
4079 | sub new { |
4211 | sub new { |
4080 | my $class = shift; |
4212 | my $class = shift; |
4081 | |
4213 | |
4082 | my $self = $class->SUPER::new ( |
4214 | my $self = $class->SUPER::new ( |
… | |
… | |
4099 | my ($value, $title, $tooltip) = @$_; |
4231 | my ($value, $title, $tooltip) = @$_; |
4100 | |
4232 | |
4101 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
4233 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
4102 | } |
4234 | } |
4103 | |
4235 | |
4104 | CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); |
4236 | DC::UI::Menu->new (items => \@menu_items)->popup ($ev); |
4105 | } |
4237 | } |
4106 | |
4238 | |
4107 | sub _set_value { |
4239 | sub _set_value { |
4108 | my ($self, $value) = @_; |
4240 | my ($self, $value) = @_; |
4109 | |
4241 | |
4110 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
4242 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} }; |
|
|
4243 | $item ||= $self->{options}[0] |
4111 | or return; |
4244 | or return; |
4112 | |
4245 | |
4113 | $self->{value} = $item->[0]; |
4246 | $self->{value} = $item->[0]; |
4114 | $self->set_markup ("$item->[1] ⇓"); |
4247 | $self->set_markup ("$item->[1] ⇓"); |
4115 | $self->set_tooltip ($item->[2]); |
4248 | # $self->set_tooltip ($item->[2]); |
4116 | } |
4249 | } |
4117 | |
4250 | |
4118 | sub set_value { |
4251 | sub set_value { |
4119 | my ($self, $value) = @_; |
4252 | my ($self, $value) = @_; |
4120 | |
4253 | |
… | |
… | |
4122 | |
4255 | |
4123 | $self->_set_value ($value); |
4256 | $self->_set_value ($value); |
4124 | $self->emit (changed => $value); |
4257 | $self->emit (changed => $value); |
4125 | } |
4258 | } |
4126 | |
4259 | |
|
|
4260 | sub set_options { |
|
|
4261 | my ($self, $options) = @_; |
|
|
4262 | |
|
|
4263 | $self->{options} = $options; |
|
|
4264 | $self->_set_value ($self->{value}); |
|
|
4265 | } |
|
|
4266 | |
4127 | ############################################################################# |
4267 | ############################################################################# |
4128 | |
4268 | |
4129 | package CFPlus::UI::Statusbox; |
4269 | package DC::UI::Statusbox; |
4130 | |
4270 | |
4131 | our @ISA = CFPlus::UI::VBox::; |
4271 | our @ISA = DC::UI::VBox::; |
4132 | |
4272 | |
4133 | sub new { |
4273 | sub new { |
4134 | my $class = shift; |
4274 | my $class = shift; |
4135 | |
4275 | |
4136 | my $self = $class->SUPER::new ( |
4276 | my $self = $class->SUPER::new ( |
4137 | fontsize => 0.8, |
4277 | fontsize => 0.8, |
4138 | @_, |
4278 | @_, |
4139 | ); |
4279 | ); |
4140 | |
4280 | |
4141 | CFPlus::weaken (my $this = $self); |
4281 | DC::weaken (my $this = $self); |
4142 | |
4282 | |
4143 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
4283 | $self->{timer} = EV::timer 1, 1, sub { $this->reorder }; |
4144 | |
4284 | |
4145 | $self |
4285 | $self |
4146 | } |
4286 | } |
4147 | |
4287 | |
4148 | sub reorder { |
4288 | sub reorder { |
4149 | my ($self) = @_; |
4289 | my ($self) = @_; |
4150 | my $NOW = Time::HiRes::time; |
4290 | my $NOW = EV::time; |
4151 | |
4291 | |
4152 | # freeze display when hovering over any label |
4292 | # freeze display when hovering over any label |
4153 | return if $CFPlus::UI::TOOLTIP->{owner} |
4293 | return if $DC::UI::TOOLTIP->{owner} |
4154 | && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label}, |
4294 | && grep $DC::UI::TOOLTIP->{owner} == $_->{label}, |
4155 | values %{ $self->{item} }; |
4295 | values %{ $self->{item} }; |
4156 | |
4296 | |
4157 | while (my ($k, $v) = each %{ $self->{item} }) { |
4297 | while (my ($k, $v) = each %{ $self->{item} }) { |
4158 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
4298 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
4159 | } |
4299 | } |
|
|
4300 | |
|
|
4301 | $self->{timer}->set (1, 1); |
4160 | |
4302 | |
4161 | my @widgets; |
4303 | my @widgets; |
4162 | |
4304 | |
4163 | my @items = sort { |
4305 | my @items = sort { |
4164 | $a->{pri} <=> $b->{pri} |
4306 | $a->{pri} <=> $b->{pri} |
4165 | or $b->{id} <=> $a->{id} |
4307 | or $b->{id} <=> $a->{id} |
4166 | } values %{ $self->{item} }; |
4308 | } values %{ $self->{item} }; |
4167 | |
|
|
4168 | $self->{timer}->interval (1); |
|
|
4169 | |
4309 | |
4170 | my $count = 10 + 1; |
4310 | my $count = 10 + 1; |
4171 | for my $item (@items) { |
4311 | for my $item (@items) { |
4172 | last unless --$count; |
4312 | last unless --$count; |
4173 | |
4313 | |
… | |
… | |
4180 | for ($short) { |
4320 | for ($short) { |
4181 | s/^\s+//; |
4321 | s/^\s+//; |
4182 | s/\s+/ /g; |
4322 | s/\s+/ /g; |
4183 | } |
4323 | } |
4184 | |
4324 | |
4185 | new CFPlus::UI::Label |
4325 | new DC::UI::Label |
4186 | markup => $short, |
4326 | markup => $short, |
4187 | tooltip => $item->{tooltip}, |
4327 | tooltip => $item->{tooltip}, |
4188 | tooltip_font => $::FONT_PROP, |
4328 | tooltip_font => $::FONT_PROP, |
4189 | tooltip_width => 0.67, |
4329 | tooltip_width => 0.67, |
4190 | fontsize => $item->{fontsize} || $self->{fontsize}, |
4330 | fontsize => $item->{fontsize} || $self->{fontsize}, |
4191 | max_w => $::WIDTH * 0.44, |
4331 | max_w => $::WIDTH * 0.44, |
|
|
4332 | align => 0, |
4192 | fg => [@{ $item->{fg} }], |
4333 | fg => [@{ $item->{fg} }], |
4193 | can_events => 1, |
4334 | can_events => 1, |
4194 | can_hover => 1 |
4335 | can_hover => 1 |
4195 | }; |
4336 | }; |
4196 | |
4337 | |
4197 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
4338 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
4198 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
4339 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
4199 | $label->update; |
4340 | $label->update; |
4200 | $label->set_max_size (undef, $label->{req_h} * $diff) |
4341 | $label->set_max_size (undef, $label->{req_h} * $diff) |
4201 | if $diff < 1; |
4342 | if $diff < 1; |
4202 | $self->{timer}->interval (1/30); |
4343 | $self->{timer}->set (1/30, 1/30); |
4203 | } else { |
4344 | } else { |
4204 | $label->{fg}[3] = $item->{fg}[3] || 1; |
4345 | $label->{fg}[3] = $item->{fg}[3] || 1; |
4205 | } |
4346 | } |
4206 | |
4347 | |
4207 | push @widgets, $label; |
4348 | push @widgets, $label; |
4208 | } |
4349 | } |
|
|
4350 | |
|
|
4351 | my $hash = join ",", @widgets; |
|
|
4352 | return if $hash eq $self->{last_widget_hash}; |
|
|
4353 | $self->{last_widget_hash} = $hash; |
4209 | |
4354 | |
4210 | $self->clear; |
4355 | $self->clear; |
4211 | $self->SUPER::add (reverse @widgets); |
4356 | $self->SUPER::add (reverse @widgets); |
4212 | } |
4357 | } |
4213 | |
4358 | |
… | |
… | |
4269 | $self->SUPER::destroy; |
4414 | $self->SUPER::destroy; |
4270 | } |
4415 | } |
4271 | |
4416 | |
4272 | ############################################################################# |
4417 | ############################################################################# |
4273 | |
4418 | |
4274 | package CFPlus::UI::Root; |
4419 | package DC::UI::Root; |
4275 | |
4420 | |
4276 | our @ISA = CFPlus::UI::Container::; |
4421 | our @ISA = DC::UI::Container::; |
4277 | |
4422 | |
4278 | use List::Util qw(min max); |
4423 | use List::Util qw(min max); |
4279 | |
4424 | |
4280 | use CFPlus::OpenGL; |
4425 | use DC::OpenGL; |
4281 | |
4426 | |
4282 | sub new { |
4427 | sub new { |
4283 | my $class = shift; |
4428 | my $class = shift; |
4284 | |
4429 | |
4285 | my $self = $class->SUPER::new ( |
4430 | my $self = $class->SUPER::new ( |
4286 | visible => 1, |
4431 | visible => 1, |
4287 | @_, |
4432 | @_, |
4288 | ); |
4433 | ); |
4289 | |
4434 | |
4290 | CFPlus::weaken ($self->{root} = $self); |
4435 | DC::weaken ($self->{root} = $self); |
4291 | |
4436 | |
4292 | $self |
4437 | $self |
4293 | } |
4438 | } |
4294 | |
4439 | |
4295 | sub size_request { |
4440 | sub size_request { |
… | |
… | |
4343 | } |
4488 | } |
4344 | |
4489 | |
4345 | sub update { |
4490 | sub update { |
4346 | my ($self) = @_; |
4491 | my ($self) = @_; |
4347 | |
4492 | |
4348 | $::WANT_REFRESH->start; |
4493 | $::WANT_REFRESH = 1; |
4349 | } |
4494 | } |
4350 | |
4495 | |
4351 | sub add { |
4496 | sub add { |
4352 | my ($self, @children) = @_; |
4497 | my ($self, @children) = @_; |
4353 | |
4498 | |
… | |
… | |
4420 | |
4565 | |
4421 | delete $queue{$widget+0}; |
4566 | delete $queue{$widget+0}; |
4422 | |
4567 | |
4423 | my ($w, $h) = $widget->size_request; |
4568 | my ($w, $h) = $widget->size_request; |
4424 | |
4569 | |
4425 | $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
4570 | $w += $widget->{padding_x} * 2; |
4426 | $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
4571 | $h += $widget->{padding_y} * 2; |
|
|
4572 | |
|
|
4573 | $w = max $widget->{min_w}, $w; |
|
|
4574 | $h = max $widget->{min_h}, $h; |
4427 | |
4575 | |
4428 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4576 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4429 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4577 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4430 | |
4578 | |
4431 | $w = $widget->{force_w} if exists $widget->{force_w}; |
4579 | $w = $widget->{force_w} if exists $widget->{force_w}; |
… | |
… | |
4498 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
4646 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
4499 | glMatrixMode GL_MODELVIEW; |
4647 | glMatrixMode GL_MODELVIEW; |
4500 | glLoadIdentity; |
4648 | glLoadIdentity; |
4501 | |
4649 | |
4502 | { |
4650 | { |
4503 | package CFPlus::UI::Base; |
4651 | package DC::UI::Base; |
4504 | |
4652 | |
4505 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
4653 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
4506 | (0, 0, $self->{w}, $self->{h}); |
4654 | (0, 0, $self->{w}, $self->{h}); |
4507 | |
4655 | |
4508 | $self->_draw; |
4656 | $self->_draw; |
4509 | } |
4657 | } |
4510 | } |
4658 | } |
4511 | |
4659 | |
4512 | ############################################################################# |
4660 | ############################################################################# |
4513 | |
4661 | |
4514 | package CFPlus::UI; |
4662 | package DC::UI; |
4515 | |
4663 | |
4516 | $ROOT = new CFPlus::UI::Root; |
4664 | $ROOT = new DC::UI::Root; |
4517 | $TOOLTIP = new CFPlus::UI::Tooltip z => 900; |
4665 | $TOOLTIP = new DC::UI::Tooltip z => 900; |
4518 | |
4666 | |
4519 | 1 |
4667 | 1 |
4520 | |
|
|