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 DC; |
10 | use CFPlus::Pod; |
9 | use DC::Pod; |
11 | use CFPlus::Texture; |
10 | use DC::Texture; |
12 | |
11 | |
13 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
14 | |
13 | |
15 | our $LAYOUT; |
14 | our $LAYOUT; |
16 | our $ROOT; |
15 | our $ROOT; |
17 | our $TOOLTIP; |
16 | our $TOOLTIP; |
18 | our $BUTTON_STATE; |
17 | our $BUTTON_STATE; |
19 | |
18 | |
20 | our %WIDGET; # all widgets, weak-referenced |
19 | our %WIDGET; # all widgets, weak-referenced |
21 | |
20 | |
22 | our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { |
21 | our $TOOLTIP_WATCHER = EV::timer_ns 0, 0.03, sub { |
|
|
22 | $_[0]->stop; |
|
|
23 | |
23 | if (!$GRAB) { |
24 | if (!$GRAB) { |
24 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
25 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
25 | if (length $widget->{tooltip}) { |
26 | if (length $widget->{tooltip}) { |
26 | if ($TOOLTIP->{owner} != $widget) { |
27 | if ($TOOLTIP->{owner} != $widget) { |
27 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
28 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
… | |
… | |
30 | $TOOLTIP->{owner} = $widget; |
31 | $TOOLTIP->{owner} = $widget; |
31 | $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner}; |
32 | $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner}; |
32 | |
33 | |
33 | return if $ENV{CFPLUS_DEBUG} & 8; |
34 | return if $ENV{CFPLUS_DEBUG} & 8; |
34 | |
35 | |
35 | my $tip = $widget->{tooltip}; |
|
|
36 | |
|
|
37 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
|
|
38 | |
|
|
39 | $TOOLTIP->set_tooltip_from ($widget); |
36 | $TOOLTIP->set_tooltip_from ($widget); |
40 | $TOOLTIP->show; |
37 | $TOOLTIP->show; |
41 | } |
38 | } |
42 | |
39 | |
43 | return; |
40 | return; |
… | |
… | |
46 | } |
43 | } |
47 | |
44 | |
48 | $TOOLTIP->hide; |
45 | $TOOLTIP->hide; |
49 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
46 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
50 | delete $TOOLTIP->{owner}; |
47 | delete $TOOLTIP->{owner}; |
51 | }); |
48 | }; |
52 | |
49 | |
53 | sub get_layout { |
50 | sub get_layout { |
54 | my $layout; |
51 | my $layout; |
55 | |
52 | |
56 | for (grep { $_->{name} } values %WIDGET) { |
53 | for (grep { $_->{name} } values %WIDGET) { |
… | |
… | |
91 | my $hover = $HOVER; $HOVER = $widget; |
88 | my $hover = $HOVER; $HOVER = $widget; |
92 | |
89 | |
93 | $hover->update if $hover && $hover->{can_hover}; |
90 | $hover->update if $hover && $hover->{can_hover}; |
94 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
91 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
95 | |
92 | |
96 | $TOOLTIP_WATCHER->start; |
93 | $TOOLTIP_WATCHER->again; |
97 | } |
94 | } |
98 | } |
95 | } |
99 | |
96 | |
100 | sub feed_sdl_button_down_event { |
97 | sub feed_sdl_button_down_event { |
101 | my ($ev) = @_; |
98 | my ($ev) = @_; |
… | |
… | |
107 | my $widget = $ROOT->find_widget ($x, $y); |
104 | my $widget = $ROOT->find_widget ($x, $y); |
108 | |
105 | |
109 | $GRAB = $widget; |
106 | $GRAB = $widget; |
110 | $GRAB->update if $GRAB; |
107 | $GRAB->update if $GRAB; |
111 | |
108 | |
112 | $TOOLTIP_WATCHER->cb->(); |
109 | $TOOLTIP_WATCHER->invoke; |
113 | } |
110 | } |
114 | |
111 | |
115 | if ($GRAB) { |
112 | if ($GRAB) { |
116 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
113 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
117 | # mousewheel |
114 | # mousewheel |
118 | my $delta = $ev->{button} * 2 - 9; |
115 | my $delta = $ev->{button} * 2 - 9; |
119 | my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT; |
116 | my $shift = $ev->{mod} & DC::KMOD_SHIFT; |
120 | |
117 | |
121 | $ev->{dx} = $shift ? $delta : 0; |
118 | $ev->{dx} = $shift ? $delta : 0; |
122 | $ev->{dy} = $shift ? 0 : $delta; |
119 | $ev->{dy} = $shift ? 0 : $delta; |
123 | |
120 | |
124 | $GRAB->emit (mouse_wheel => $ev); |
121 | $GRAB->emit (mouse_wheel => $ev); |
… | |
… | |
142 | my $grab = $GRAB; undef $GRAB; |
139 | my $grab = $GRAB; undef $GRAB; |
143 | $grab->update if $grab; |
140 | $grab->update if $grab; |
144 | $GRAB->update if $GRAB; |
141 | $GRAB->update if $GRAB; |
145 | |
142 | |
146 | check_hover $widget; |
143 | check_hover $widget; |
147 | $TOOLTIP_WATCHER->cb->(); |
144 | $TOOLTIP_WATCHER->invoke; |
148 | } |
145 | } |
149 | } |
146 | } |
150 | |
147 | |
151 | sub feed_sdl_motion_event { |
148 | sub feed_sdl_motion_event { |
152 | my ($ev) = @_; |
149 | my ($ev) = @_; |
… | |
… | |
214 | reconfigure_widgets; |
211 | reconfigure_widgets; |
215 | } |
212 | } |
216 | |
213 | |
217 | ############################################################################# |
214 | ############################################################################# |
218 | |
215 | |
219 | package CFPlus::UI::Event; |
216 | package DC::UI::Event; |
220 | |
217 | |
221 | sub xy { |
218 | sub xy { |
222 | $_[1]->coord2local ($_[0]{x}, $_[0]{y}) |
219 | $_[1]->coord2local ($_[0]{x}, $_[0]{y}) |
223 | } |
220 | } |
224 | |
221 | |
225 | ############################################################################# |
222 | ############################################################################# |
226 | |
223 | |
227 | package CFPlus::UI::Base; |
224 | package DC::UI::Base; |
228 | |
225 | |
229 | use strict; |
226 | use strict; |
230 | |
227 | |
231 | use CFPlus::OpenGL; |
228 | use DC::OpenGL; |
232 | |
229 | |
233 | sub new { |
230 | sub new { |
234 | my $class = shift; |
231 | my $class = shift; |
235 | |
232 | |
236 | my $self = bless { |
233 | my $self = bless { |
… | |
… | |
241 | h => undef, |
238 | h => undef, |
242 | can_events => 1, |
239 | can_events => 1, |
243 | @_ |
240 | @_ |
244 | }, $class; |
241 | }, $class; |
245 | |
242 | |
246 | CFPlus::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); |
243 | DC::weaken ($DC::UI::WIDGET{$self+0} = $self); |
247 | |
244 | |
248 | for (keys %$self) { |
245 | for (keys %$self) { |
249 | if (/^on_(.*)$/) { |
246 | if (/^on_(.*)$/) { |
250 | $self->connect ($1 => delete $self->{$_}); |
247 | $self->connect ($1 => delete $self->{$_}); |
251 | } |
248 | } |
252 | } |
249 | } |
253 | |
250 | |
254 | if (my $layout = $CFPlus::UI::LAYOUT->{$self->{name}}) { |
251 | if (my $layout = $DC::UI::LAYOUT->{$self->{name}}) { |
255 | $self->{x} = $layout->{x} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{x}; |
252 | $self->{x} = $layout->{x} * $DC::UI::ROOT->{alloc_w} if exists $layout->{x}; |
256 | $self->{y} = $layout->{y} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{y}; |
253 | $self->{y} = $layout->{y} * $DC::UI::ROOT->{alloc_h} if exists $layout->{y}; |
257 | $self->{force_w} = $layout->{w} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{w}; |
254 | $self->{force_w} = $layout->{w} * $DC::UI::ROOT->{alloc_w} if exists $layout->{w}; |
258 | $self->{force_h} = $layout->{h} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{h}; |
255 | $self->{force_h} = $layout->{h} * $DC::UI::ROOT->{alloc_h} if exists $layout->{h}; |
259 | |
256 | |
260 | $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; |
257 | $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; |
261 | $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; |
258 | $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; |
262 | |
259 | |
263 | $self->show if $layout->{show}; |
260 | $self->show if $layout->{show}; |
… | |
… | |
273 | $self->emit ("destroy"); |
270 | $self->emit ("destroy"); |
274 | %$self = (); |
271 | %$self = (); |
275 | } |
272 | } |
276 | |
273 | |
277 | sub TO_JSON { |
274 | sub TO_JSON { |
278 | { __widget_ref__ => $_[0]{s_id} } |
275 | { "\fw" => $_[0]{s_id} } |
279 | } |
276 | } |
280 | |
277 | |
281 | sub show { |
278 | sub show { |
282 | my ($self) = @_; |
279 | my ($self) = @_; |
283 | |
280 | |
284 | return if $self->{parent}; |
281 | return if $self->{parent}; |
285 | |
282 | |
286 | $CFPlus::UI::ROOT->add ($self); |
283 | $DC::UI::ROOT->add ($self); |
287 | } |
284 | } |
288 | |
285 | |
289 | sub set_visible { |
286 | sub set_visible { |
290 | my ($self) = @_; |
287 | my ($self) = @_; |
291 | |
288 | |
… | |
… | |
312 | delete $self->{root}; |
309 | delete $self->{root}; |
313 | |
310 | |
314 | undef $GRAB if $GRAB == $self; |
311 | undef $GRAB if $GRAB == $self; |
315 | undef $HOVER if $HOVER == $self; |
312 | undef $HOVER if $HOVER == $self; |
316 | |
313 | |
317 | $CFPlus::UI::TOOLTIP_WATCHER->cb->() |
314 | $DC::UI::TOOLTIP_WATCHER->invoke |
318 | if $TOOLTIP->{owner} == $self; |
315 | if $TOOLTIP->{owner} == $self; |
319 | |
316 | |
320 | $self->emit ("focus_out"); |
317 | $self->emit ("focus_out"); |
321 | $self->emit (visibility_change => 0); |
318 | $self->emit (visibility_change => 0); |
322 | } |
319 | } |
… | |
… | |
341 | sub hide { |
338 | sub hide { |
342 | my ($self) = @_; |
339 | my ($self) = @_; |
343 | |
340 | |
344 | $self->set_invisible; |
341 | $self->set_invisible; |
345 | |
342 | |
|
|
343 | # extra $parent copy for 5.8.8+ bug workaround |
|
|
344 | # (otherwise $_[0] in remove gets freed |
|
|
345 | if (my $parent = $self->{parent}) { |
346 | $self->{parent}->remove ($self) |
346 | $parent->remove ($self); |
347 | if $self->{parent}; |
347 | } |
348 | } |
348 | } |
349 | |
349 | |
350 | sub move_abs { |
350 | sub move_abs { |
351 | my ($self, $x, $y, $z) = @_; |
351 | my ($self, $x, $y, $z) = @_; |
352 | |
352 | |
… | |
… | |
364 | $self->{force_h} = $h; |
364 | $self->{force_h} = $h; |
365 | |
365 | |
366 | $self->realloc; |
366 | $self->realloc; |
367 | } |
367 | } |
368 | |
368 | |
|
|
369 | # traverse the widget chain up to find the maximum "physical" size constraints |
|
|
370 | sub get_max_wh { |
|
|
371 | my ($self) = @_; |
|
|
372 | |
|
|
373 | my ($w, $h) = @$self{qw(max_w max_h)}; |
|
|
374 | |
|
|
375 | if ($w <= 0 || $h <= 0) { |
|
|
376 | my ($mw, $mh) = $self->{parent} |
|
|
377 | ? $self->{parent}->get_max_wh |
|
|
378 | : ($::WIDTH, $::HEIGHT); |
|
|
379 | |
|
|
380 | $w = $mw if $w <= 0; |
|
|
381 | $h = $mh if $h <= 0; |
|
|
382 | } |
|
|
383 | |
|
|
384 | ($w, $h) |
|
|
385 | } |
|
|
386 | |
369 | sub size_request { |
387 | sub size_request { |
370 | require Carp; |
388 | require Carp; |
371 | Carp::confess "size_request is abstract"; |
389 | Carp::confess "size_request is abstract"; |
372 | } |
390 | } |
373 | |
391 | |
… | |
… | |
379 | my ($self, $x, $y, $w, $h) = @_; |
397 | my ($self, $x, $y, $w, $h) = @_; |
380 | |
398 | |
381 | if ($self->{aspect}) { |
399 | if ($self->{aspect}) { |
382 | my ($ow, $oh) = ($w, $h); |
400 | my ($ow, $oh) = ($w, $h); |
383 | |
401 | |
384 | $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect}; |
402 | $w = List::Util::min $w, DC::ceil $h * $self->{aspect}; |
385 | $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect}; |
403 | $h = List::Util::min $h, DC::ceil $w / $self->{aspect}; |
386 | |
404 | |
387 | # use alignment to adjust x, y |
405 | # use alignment to adjust x, y |
388 | |
406 | |
389 | $x += int 0.5 * ($ow - $w); |
407 | $x += int 0.5 * ($ow - $w); |
390 | $y += int 0.5 * ($oh - $h); |
408 | $y += int 0.5 * ($oh - $h); |
… | |
… | |
431 | |
449 | |
432 | return if $self->{tooltip} eq $tooltip; |
450 | return if $self->{tooltip} eq $tooltip; |
433 | |
451 | |
434 | $self->{tooltip} = $tooltip; |
452 | $self->{tooltip} = $tooltip; |
435 | |
453 | |
436 | if ($CFPlus::UI::TOOLTIP->{owner} == $self) { |
454 | if ($DC::UI::TOOLTIP->{owner} == $self) { |
437 | delete $CFPlus::UI::TOOLTIP->{owner}; |
455 | delete $DC::UI::TOOLTIP->{owner}; |
438 | $CFPlus::UI::TOOLTIP_WATCHER->cb->(); |
456 | $DC::UI::TOOLTIP_WATCHER->invoke; |
439 | } |
457 | } |
440 | } |
458 | } |
441 | |
459 | |
442 | # translate global coordinates to local coordinate system |
460 | # translate global coordinates to local coordinate system |
443 | sub coord2local { |
461 | sub coord2local { |
444 | my ($self, $x, $y) = @_; |
462 | my ($self, $x, $y) = @_; |
445 | |
463 | |
446 | Carp::confess unless $self->{parent};#d# |
464 | return (undef, undef) unless $self->{parent}; |
447 | |
465 | |
448 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
466 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
449 | } |
467 | } |
450 | |
468 | |
451 | # translate local coordinates to global coordinate system |
469 | # translate local coordinates to global coordinate system |
452 | sub coord2global { |
470 | sub coord2global { |
453 | my ($self, $x, $y) = @_; |
471 | my ($self, $x, $y) = @_; |
454 | |
472 | |
455 | Carp::confess unless $self->{parent};#d# |
473 | return (undef, undef) unless $self->{parent}; |
456 | |
474 | |
457 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
475 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
458 | } |
476 | } |
459 | |
477 | |
460 | sub invoke_focus_in { |
478 | sub invoke_focus_in { |
… | |
… | |
509 | sub connect { |
527 | sub connect { |
510 | my ($self, $signal, $cb) = @_; |
528 | my ($self, $signal, $cb) = @_; |
511 | |
529 | |
512 | push @{ $self->{signal_cb}{$signal} }, $cb; |
530 | push @{ $self->{signal_cb}{$signal} }, $cb; |
513 | |
531 | |
514 | defined wantarray and CFPlus::guard { |
532 | defined wantarray and DC::guard { |
515 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
533 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
516 | @{ $self->{signal_cb}{$signal} }; |
534 | @{ $self->{signal_cb}{$signal} }; |
517 | } |
535 | } |
518 | } |
536 | } |
519 | |
537 | |
… | |
… | |
557 | # in .xs |
575 | # in .xs |
558 | |
576 | |
559 | sub set_parent { |
577 | sub set_parent { |
560 | my ($self, $parent) = @_; |
578 | my ($self, $parent) = @_; |
561 | |
579 | |
562 | CFPlus::weaken ($self->{parent} = $parent); |
580 | DC::weaken ($self->{parent} = $parent); |
563 | $self->set_visible if $parent->{visible}; |
581 | $self->set_visible if $parent->{visible}; |
564 | } |
582 | } |
565 | |
583 | |
566 | sub realloc { |
584 | sub realloc { |
567 | my ($self) = @_; |
585 | my ($self) = @_; |
… | |
… | |
593 | |
611 | |
594 | # using global variables seems a bit hacky, but passing through all drawing |
612 | # using global variables seems a bit hacky, but passing through all drawing |
595 | # functions seems pointless. |
613 | # functions seems pointless. |
596 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
614 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
597 | |
615 | |
598 | sub draw { |
616 | #sub draw { |
599 | my ($self) = @_; |
617 | #CFPlus.xs |
600 | |
|
|
601 | return unless $self->{h} && $self->{w}; |
|
|
602 | |
|
|
603 | # update screen rectangle |
|
|
604 | local $draw_x = $draw_x + $self->{x}; |
|
|
605 | local $draw_y = $draw_y + $self->{y}; |
|
|
606 | |
|
|
607 | # skip widgets that are entirely outside the drawing area |
|
|
608 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
|
|
609 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
|
|
610 | |
|
|
611 | glPushMatrix; |
|
|
612 | glTranslate $self->{x}, $self->{y}, 0; |
|
|
613 | |
|
|
614 | if ($self == $HOVER && $self->{can_hover}) { |
|
|
615 | glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2; |
|
|
616 | glEnable GL_BLEND; |
|
|
617 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
618 | glBegin GL_QUADS; |
|
|
619 | glVertex 0 , 0; |
|
|
620 | glVertex $self->{w}, 0; |
|
|
621 | glVertex $self->{w}, $self->{h}; |
|
|
622 | glVertex 0 , $self->{h}; |
|
|
623 | glEnd; |
|
|
624 | glDisable GL_BLEND; |
|
|
625 | } |
|
|
626 | |
|
|
627 | if ($ENV{CFPLUS_DEBUG} & 1) { |
|
|
628 | glPushMatrix; |
|
|
629 | glColor 1, 1, 0, 1; |
|
|
630 | glTranslate 0.375, 0.375; |
|
|
631 | glBegin GL_LINE_LOOP; |
|
|
632 | glVertex 0 , 0; |
|
|
633 | glVertex $self->{w} - 1, 0; |
|
|
634 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
635 | glVertex 0 , $self->{h} - 1; |
|
|
636 | glEnd; |
|
|
637 | glPopMatrix; |
|
|
638 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
639 | } |
|
|
640 | |
|
|
641 | $self->_draw; |
|
|
642 | glPopMatrix; |
|
|
643 | } |
|
|
644 | |
618 | |
645 | sub _draw { |
619 | sub _draw { |
646 | my ($self) = @_; |
620 | my ($self) = @_; |
647 | |
621 | |
648 | warn "no draw defined for $self\n"; |
622 | warn "no draw defined for $self\n"; |
649 | } |
623 | } |
650 | |
624 | |
651 | sub DESTROY { |
625 | sub DESTROY { |
652 | my ($self) = @_; |
626 | my ($self) = @_; |
653 | |
627 | |
654 | return if CFPlus::in_destruct; |
628 | return if DC::in_destruct; |
655 | |
629 | |
|
|
630 | local $@; |
656 | eval { $self->destroy }; |
631 | eval { $self->destroy }; |
657 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
632 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
658 | |
633 | |
659 | delete $WIDGET{$self+0}; |
634 | delete $WIDGET{$self+0}; |
660 | } |
635 | } |
661 | |
636 | |
662 | ############################################################################# |
637 | ############################################################################# |
663 | |
638 | |
664 | package CFPlus::UI::DrawBG; |
639 | package DC::UI::DrawBG; |
665 | |
640 | |
666 | our @ISA = CFPlus::UI::Base::; |
641 | our @ISA = DC::UI::Base::; |
667 | |
642 | |
668 | use strict; |
643 | use strict; |
669 | use CFPlus::OpenGL; |
644 | use DC::OpenGL; |
670 | |
645 | |
671 | sub new { |
646 | sub new { |
672 | my $class = shift; |
647 | my $class = shift; |
673 | |
|
|
674 | # range [value, low, high, page] |
|
|
675 | |
648 | |
676 | $class->SUPER::new ( |
649 | $class->SUPER::new ( |
677 | #bg => [0, 0, 0, 0.2], |
650 | #bg => [0, 0, 0, 0.2], |
678 | #active_bg => [1, 1, 1, 0.5], |
651 | #active_bg => [1, 1, 1, 0.5], |
679 | @_ |
652 | @_ |
… | |
… | |
691 | my ($w, $h) = @$self{qw(w h)}; |
664 | my ($w, $h) = @$self{qw(w h)}; |
692 | |
665 | |
693 | glEnable GL_BLEND; |
666 | glEnable GL_BLEND; |
694 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
667 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
695 | glColor_premultiply @$color; |
668 | glColor_premultiply @$color; |
696 | |
|
|
697 | glBegin GL_QUADS; |
|
|
698 | glVertex 0 , 0; |
|
|
699 | glVertex 0 , $h; |
|
|
700 | glVertex $w, $h; |
669 | glRect 0, 0, $w, $h; |
701 | glVertex $w, 0; |
|
|
702 | glEnd; |
|
|
703 | |
|
|
704 | glDisable GL_BLEND; |
670 | glDisable GL_BLEND; |
705 | } |
671 | } |
706 | } |
672 | } |
707 | |
673 | |
708 | ############################################################################# |
674 | ############################################################################# |
709 | |
675 | |
710 | package CFPlus::UI::Empty; |
676 | package DC::UI::Empty; |
711 | |
677 | |
712 | our @ISA = CFPlus::UI::Base::; |
678 | our @ISA = DC::UI::Base::; |
713 | |
679 | |
714 | sub new { |
680 | sub new { |
715 | my ($class, %arg) = @_; |
681 | my ($class, %arg) = @_; |
716 | $class->SUPER::new (can_events => 0, %arg); |
682 | $class->SUPER::new (can_events => 0, %arg); |
717 | } |
683 | } |
… | |
… | |
724 | |
690 | |
725 | sub draw { } |
691 | sub draw { } |
726 | |
692 | |
727 | ############################################################################# |
693 | ############################################################################# |
728 | |
694 | |
729 | package CFPlus::UI::Container; |
695 | package DC::UI::Container; |
730 | |
696 | |
731 | our @ISA = CFPlus::UI::Base::; |
697 | our @ISA = DC::UI::Base::; |
732 | |
698 | |
733 | sub new { |
699 | sub new { |
734 | my ($class, %arg) = @_; |
700 | my ($class, %arg) = @_; |
735 | |
701 | |
736 | my $children = delete $arg{children}; |
702 | my $children = delete $arg{children}; |
… | |
… | |
769 | @{$self->{children}}, @widgets |
735 | @{$self->{children}}, @widgets |
770 | ]; |
736 | ]; |
771 | |
737 | |
772 | $self->realloc; |
738 | $self->realloc; |
773 | |
739 | |
|
|
740 | $self->emit (c_add => \@widgets); |
|
|
741 | |
774 | map $_+0, @widgets |
742 | map $_+0, @widgets |
775 | } |
743 | } |
776 | |
744 | |
777 | sub children { |
745 | sub children { |
778 | @{ $_[0]{children} } |
746 | @{ $_[0]{children} } |
779 | } |
747 | } |
780 | |
748 | |
781 | sub remove { |
749 | sub remove { |
782 | my ($self, $child) = @_; |
750 | my ($self, @widgets) = @_; |
783 | |
751 | |
|
|
752 | $self->emit (c_remove => \@widgets); |
|
|
753 | |
|
|
754 | for my $child (@widgets) { |
784 | delete $child->{parent}; |
755 | delete $child->{parent}; |
785 | $child->hide; |
756 | $child->hide; |
786 | |
|
|
787 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
757 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
|
|
758 | } |
788 | |
759 | |
789 | $self->realloc; |
760 | $self->realloc; |
790 | } |
761 | } |
791 | |
762 | |
792 | sub clear { |
763 | sub clear { |
… | |
… | |
820 | } |
791 | } |
821 | |
792 | |
822 | sub _draw { |
793 | sub _draw { |
823 | my ($self) = @_; |
794 | my ($self) = @_; |
824 | |
795 | |
825 | $_->draw for @{$self->{children}}; |
796 | $_->draw for $self->visible_children; |
826 | } |
797 | } |
827 | |
798 | |
828 | ############################################################################# |
799 | ############################################################################# |
829 | |
800 | |
830 | package CFPlus::UI::Bin; |
801 | package DC::UI::Bin; |
831 | |
802 | |
832 | our @ISA = CFPlus::UI::Container::; |
803 | our @ISA = DC::UI::Container::; |
833 | |
804 | |
834 | sub new { |
805 | sub new { |
835 | my ($class, %arg) = @_; |
806 | my ($class, %arg) = @_; |
836 | |
807 | |
837 | my $child = (delete $arg{child}) || new CFPlus::UI::Empty::; |
808 | my $child = (delete $arg{child}) || new DC::UI::Empty::; |
838 | |
809 | |
839 | $class->SUPER::new (children => [$child], %arg) |
810 | $class->SUPER::new (children => [$child], %arg) |
840 | } |
811 | } |
841 | |
812 | |
842 | sub add { |
813 | sub add { |
843 | my ($self, $child) = @_; |
814 | my ($self, $child) = @_; |
844 | |
815 | |
845 | $self->SUPER::remove ($_) for @{ $self->{children} }; |
816 | $self->clear; |
846 | $self->SUPER::add ($child); |
817 | $self->SUPER::add ($child); |
847 | } |
818 | } |
848 | |
819 | |
849 | sub remove { |
820 | sub remove { |
850 | my ($self, $widget) = @_; |
821 | my ($self, $widget) = @_; |
851 | |
822 | |
852 | $self->SUPER::remove ($widget); |
823 | $self->SUPER::remove ($widget); |
853 | |
824 | |
854 | $self->{children} = [new CFPlus::UI::Empty] |
825 | $self->{children} = [new DC::UI::Empty] |
855 | unless @{$self->{children}}; |
826 | unless @{$self->{children}}; |
856 | } |
827 | } |
857 | |
828 | |
858 | sub child { $_[0]->{children}[0] } |
829 | sub child { $_[0]->{children}[0] } |
859 | |
830 | |
… | |
… | |
868 | |
839 | |
869 | 1 |
840 | 1 |
870 | } |
841 | } |
871 | |
842 | |
872 | ############################################################################# |
843 | ############################################################################# |
873 | |
|
|
874 | # back-buffered drawing area |
844 | # back-buffered drawing area |
875 | |
845 | |
876 | package CFPlus::UI::Window; |
846 | package DC::UI::Window; |
877 | |
847 | |
878 | our @ISA = CFPlus::UI::Bin::; |
848 | our @ISA = DC::UI::Bin::; |
879 | |
849 | |
880 | use CFPlus::OpenGL; |
850 | use DC::OpenGL; |
881 | |
851 | |
882 | sub new { |
852 | sub new { |
883 | my ($class, %arg) = @_; |
853 | my ($class, %arg) = @_; |
884 | |
854 | |
885 | my $self = $class->SUPER::new (%arg); |
855 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
907 | } |
877 | } |
908 | |
878 | |
909 | sub render_child { |
879 | sub render_child { |
910 | my ($self) = @_; |
880 | my ($self) = @_; |
911 | |
881 | |
912 | $self->{texture} = new_from_opengl CFPlus::Texture $self->{w}, $self->{h}, sub { |
882 | $self->{texture} = new_from_opengl DC::Texture $self->{w}, $self->{h}, sub { |
913 | glClearColor 0, 0, 0, 0; |
883 | glClearColor 0, 0, 0, 0; |
914 | glClear GL_COLOR_BUFFER_BIT; |
884 | glClear GL_COLOR_BUFFER_BIT; |
915 | |
885 | |
916 | { |
886 | { |
917 | package CFPlus::UI::Base; |
887 | package DC::UI::Base; |
918 | |
888 | |
919 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
889 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
920 | (0, 0, $self->{w}, $self->{h}); |
890 | (0, 0, $self->{w}, $self->{h}); |
921 | |
891 | |
922 | $self->_render; |
892 | $self->_render; |
… | |
… | |
939 | glDisable GL_TEXTURE_2D; |
909 | glDisable GL_TEXTURE_2D; |
940 | } |
910 | } |
941 | |
911 | |
942 | ############################################################################# |
912 | ############################################################################# |
943 | |
913 | |
944 | package CFPlus::UI::ViewPort; |
914 | package DC::UI::ViewPort; |
945 | |
915 | |
946 | use List::Util qw(min max); |
916 | use List::Util qw(min max); |
947 | |
917 | |
948 | our @ISA = CFPlus::UI::Window::; |
918 | our @ISA = DC::UI::Window::; |
949 | |
919 | |
950 | sub new { |
920 | sub new { |
951 | my $class = shift; |
921 | my $class = shift; |
952 | |
922 | |
953 | $class->SUPER::new ( |
923 | $class->SUPER::new ( |
… | |
… | |
995 | $self->emit (changed => $x, $y); |
965 | $self->emit (changed => $x, $y); |
996 | $self->update; |
966 | $self->update; |
997 | } |
967 | } |
998 | } |
968 | } |
999 | |
969 | |
|
|
970 | sub set_center { |
|
|
971 | my ($self, $x, $y) = @_; |
|
|
972 | |
|
|
973 | $self->set_offset ($x - $self->{w} * .5, $y - $self->{h} * .5); |
|
|
974 | } |
|
|
975 | |
|
|
976 | sub make_visible { |
|
|
977 | my ($self, $x, $y, $border) = @_; |
|
|
978 | |
|
|
979 | if ( $x < $self->{view_x} + $self->{w} * $border |
|
|
980 | || $x > $self->{view_x} + $self->{w} * (1 - $border) |
|
|
981 | || $y < $self->{view_y} + $self->{h} * $border |
|
|
982 | || $y > $self->{view_y} + $self->{h} * (1 - $border) |
|
|
983 | ) { |
|
|
984 | $self->set_center ($x, $y); |
|
|
985 | } |
|
|
986 | } |
|
|
987 | |
1000 | # hmm, this does not work for topleft of $self... but we should not ask for that |
988 | # hmm, this does not work for topleft of $self... but we should not ask for that |
1001 | sub coord2local { |
989 | sub coord2local { |
1002 | my ($self, $x, $y) = @_; |
990 | my ($self, $x, $y) = @_; |
1003 | |
991 | |
1004 | $self->SUPER::coord2local ($x + $self->{view_x}, $y + $self->{view_y}) |
992 | $self->SUPER::coord2local ($x + $self->{view_x}, $y + $self->{view_y}) |
… | |
… | |
1019 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
1007 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
1020 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
1008 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
1021 | ) { |
1009 | ) { |
1022 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
1010 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
1023 | } else { |
1011 | } else { |
1024 | $self->CFPlus::UI::Base::find_widget ($x, $y) |
1012 | $self->DC::UI::Base::find_widget ($x, $y) |
1025 | } |
1013 | } |
1026 | } |
1014 | } |
1027 | |
1015 | |
1028 | sub _render { |
1016 | sub _render { |
1029 | my ($self) = @_; |
1017 | my ($self) = @_; |
1030 | |
1018 | |
1031 | local $CFPlus::UI::Base::draw_x = $CFPlus::UI::Base::draw_x - $self->{view_x}; |
1019 | local $DC::UI::Base::draw_x = $DC::UI::Base::draw_x - $self->{view_x}; |
1032 | local $CFPlus::UI::Base::draw_y = $CFPlus::UI::Base::draw_y - $self->{view_y}; |
1020 | local $DC::UI::Base::draw_y = $DC::UI::Base::draw_y - $self->{view_y}; |
1033 | |
1021 | |
1034 | CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
1022 | DC::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
1035 | |
1023 | |
1036 | $self->SUPER::_render; |
1024 | $self->SUPER::_render; |
1037 | } |
1025 | } |
1038 | |
1026 | |
1039 | ############################################################################# |
1027 | ############################################################################# |
1040 | |
1028 | |
1041 | package CFPlus::UI::ScrolledWindow; |
1029 | package DC::UI::ScrolledWindow; |
1042 | |
1030 | |
1043 | our @ISA = CFPlus::UI::Table::; |
1031 | our @ISA = DC::UI::Table::; |
1044 | |
1032 | |
1045 | sub new { |
1033 | sub new { |
1046 | my ($class, %arg) = @_; |
1034 | my ($class, %arg) = @_; |
1047 | |
1035 | |
1048 | my $child = delete $arg{child}; |
1036 | my $child = delete $arg{child}; |
1049 | |
1037 | |
1050 | my $self; |
1038 | my $self; |
1051 | |
1039 | |
1052 | my $hslider = new CFPlus::UI::Slider |
1040 | my $hslider = new DC::UI::Slider |
1053 | col => 0, |
1041 | c_col => 0, |
1054 | row => 1, |
1042 | c_row => 1, |
1055 | vertical => 0, |
1043 | vertical => 0, |
1056 | range => [0, 0, 1, 0.01], # HACK fix |
1044 | range => [0, 0, 1, 0.01], # HACK fix |
1057 | on_changed => sub { |
1045 | on_changed => sub { |
1058 | $self->{hpos} = $_[1]; |
1046 | $self->{hpos} = $_[1]; |
1059 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1047 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1060 | }, |
1048 | }, |
1061 | ; |
1049 | ; |
1062 | |
1050 | |
1063 | my $vslider = new CFPlus::UI::Slider |
1051 | my $vslider = new DC::UI::Slider |
1064 | col => 1, |
1052 | c_col => 1, |
1065 | row => 0, |
1053 | c_row => 0, |
1066 | vertical => 1, |
1054 | vertical => 1, |
1067 | range => [0, 0, 1, 0.01], # HACK fix |
1055 | range => [0, 0, 1, 0.01], # HACK fix |
1068 | on_changed => sub { |
1056 | on_changed => sub { |
1069 | $self->{vpos} = $_[1]; |
1057 | $self->{vpos} = $_[1]; |
1070 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1058 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
… | |
… | |
1080 | col_expand => [1, 0], |
1068 | col_expand => [1, 0], |
1081 | row_expand => [1, 0], |
1069 | row_expand => [1, 0], |
1082 | %arg, |
1070 | %arg, |
1083 | ); |
1071 | ); |
1084 | |
1072 | |
1085 | $self->{vp} = new CFPlus::UI::ViewPort |
1073 | $self->{vp} = new DC::UI::ViewPort |
1086 | col => 0, |
1074 | c_col => 0, |
1087 | row => 0, |
1075 | c_row => 0, |
1088 | expand => 1, |
1076 | expand => 1, |
1089 | scroll_x => $self->{scroll_x}, |
1077 | scroll_x => $self->{scroll_x}, |
1090 | scroll_y => $self->{scroll_y}, |
1078 | scroll_y => $self->{scroll_y}, |
1091 | on_changed => sub { |
1079 | on_changed => sub { |
1092 | my ($vp, $x, $y) = @_; |
1080 | my ($vp, $x, $y) = @_; |
… | |
… | |
1094 | $vp->{parent}{hslider}->set_value ($x); |
1082 | $vp->{parent}{hslider}->set_value ($x); |
1095 | $vp->{parent}{vslider}->set_value ($y); |
1083 | $vp->{parent}{vslider}->set_value ($y); |
1096 | |
1084 | |
1097 | 0 |
1085 | 0 |
1098 | }, |
1086 | }, |
|
|
1087 | on_size_allocate => sub { |
|
|
1088 | my ($vp, $w, $h) = @_; |
|
|
1089 | $vp->{parent}->update_slider; |
|
|
1090 | 0 |
|
|
1091 | }, |
1099 | ; |
1092 | ; |
1100 | |
1093 | |
1101 | $self->SUPER::add ($self->{vp}); |
1094 | $self->SUPER::add ($self->{vp}); |
1102 | |
1095 | |
1103 | $self->add ($child) if $child; |
1096 | $self->add ($child) if $child; |
… | |
… | |
1109 | my ($self, $widget) = @_; |
1102 | my ($self, $widget) = @_; |
1110 | |
1103 | |
1111 | $self->{vp}->add ($self->{child} = $widget); |
1104 | $self->{vp}->add ($self->{child} = $widget); |
1112 | } |
1105 | } |
1113 | |
1106 | |
|
|
1107 | sub set_offset { shift->{vp}->set_offset (@_) } |
|
|
1108 | sub set_center { shift->{vp}->set_center (@_) } |
|
|
1109 | sub make_visible { shift->{vp}->make_visible (@_) } |
|
|
1110 | |
1114 | sub update_slider { |
1111 | sub update_slider { |
1115 | my ($self) = @_; |
1112 | my ($self) = @_; |
1116 | |
1113 | |
1117 | my $child = ($self->{vp} or return)->child; |
1114 | my $child = ($self->{vp} or return)->child; |
1118 | |
1115 | |
|
|
1116 | if ($self->{scroll_x}) { |
1119 | my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); |
1117 | my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w}); |
1120 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1118 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1121 | |
1119 | |
1122 | my $visible = $w1 > $w2; |
1120 | my $visible = $w1 > $w2; |
1123 | if ($visible != $self->{hslider_visible}) { |
1121 | if ($visible != $self->{hslider_visible}) { |
1124 | $self->{hslider_visible} = $visible; |
1122 | $self->{hslider_visible} = $visible; |
1125 | $visible ? $self->SUPER::add ($self->{hslider}) |
1123 | $visible ? $self->SUPER::add ($self->{hslider}) |
1126 | : $self->SUPER::remove ($self->{hslider}); |
1124 | : $self->SUPER::remove ($self->{hslider}); |
|
|
1125 | } |
1127 | } |
1126 | } |
1128 | |
1127 | |
|
|
1128 | if ($self->{scroll_y}) { |
1129 | my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); |
1129 | my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h}); |
1130 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1130 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1131 | |
1131 | |
1132 | my $visible = $h1 > $h2; |
1132 | my $visible = $h1 > $h2; |
1133 | if ($visible != $self->{vslider_visible}) { |
1133 | if ($visible != $self->{vslider_visible}) { |
1134 | $self->{vslider_visible} = $visible; |
1134 | $self->{vslider_visible} = $visible; |
1135 | $visible ? $self->SUPER::add ($self->{vslider}) |
1135 | $visible ? $self->SUPER::add ($self->{vslider}) |
1136 | : $self->SUPER::remove ($self->{vslider}); |
1136 | : $self->SUPER::remove ($self->{vslider}); |
|
|
1137 | } |
1137 | } |
1138 | } |
1138 | } |
1139 | } |
1139 | |
1140 | |
1140 | sub start_dragging { |
1141 | sub start_dragging { |
1141 | my ($self, $ev) = @_; |
1142 | my ($self, $ev) = @_; |
… | |
… | |
1203 | $self->SUPER::invoke_size_allocate ($w, $h) |
1204 | $self->SUPER::invoke_size_allocate ($w, $h) |
1204 | } |
1205 | } |
1205 | |
1206 | |
1206 | ############################################################################# |
1207 | ############################################################################# |
1207 | |
1208 | |
1208 | package CFPlus::UI::Frame; |
1209 | package DC::UI::Frame; |
1209 | |
1210 | |
1210 | our @ISA = CFPlus::UI::Bin::; |
1211 | our @ISA = DC::UI::Bin::; |
1211 | |
1212 | |
1212 | use CFPlus::OpenGL; |
1213 | use DC::OpenGL; |
1213 | |
1214 | |
1214 | sub new { |
1215 | sub new { |
1215 | my $class = shift; |
1216 | my $class = shift; |
1216 | |
1217 | |
1217 | $class->SUPER::new ( |
1218 | $class->SUPER::new ( |
… | |
… | |
1227 | my ($w, $h) = @$self{qw(w h)}; |
1228 | my ($w, $h) = @$self{qw(w h)}; |
1228 | |
1229 | |
1229 | glEnable GL_BLEND; |
1230 | glEnable GL_BLEND; |
1230 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1231 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1231 | glColor_premultiply @{ $self->{bg} }; |
1232 | glColor_premultiply @{ $self->{bg} }; |
1232 | |
|
|
1233 | glBegin GL_QUADS; |
|
|
1234 | glVertex 0 , 0; |
|
|
1235 | glVertex 0 , $h; |
|
|
1236 | glVertex $w, $h; |
1233 | glRect 0, 0, $w, $h; |
1237 | glVertex $w, 0; |
|
|
1238 | glEnd; |
|
|
1239 | |
|
|
1240 | glDisable GL_BLEND; |
1234 | glDisable GL_BLEND; |
1241 | } |
1235 | } |
1242 | |
1236 | |
1243 | $self->SUPER::_draw; |
1237 | $self->SUPER::_draw; |
1244 | } |
1238 | } |
1245 | |
1239 | |
1246 | ############################################################################# |
1240 | ############################################################################# |
1247 | |
1241 | |
1248 | package CFPlus::UI::FancyFrame; |
1242 | package DC::UI::FancyFrame; |
1249 | |
1243 | |
1250 | our @ISA = CFPlus::UI::Bin::; |
1244 | our @ISA = DC::UI::Bin::; |
1251 | |
1245 | |
1252 | use CFPlus::OpenGL; |
1246 | use DC::OpenGL; |
1253 | |
1247 | |
1254 | sub new { |
1248 | sub new { |
1255 | my ($class, %arg) = @_; |
1249 | my ($class, %arg) = @_; |
1256 | |
1250 | |
1257 | if ((exists $arg{label}) && !ref $arg{label}) { |
1251 | if ((exists $arg{label}) && !ref $arg{label}) { |
1258 | $arg{label} = new CFPlus::UI::Label |
1252 | $arg{label} = new DC::UI::Label |
1259 | align => 1, |
1253 | align => 1, |
1260 | valign => 0, |
1254 | valign => 0.5, |
1261 | text => $arg{label}, |
1255 | text => $arg{label}, |
1262 | fontsize => ($arg{border} || 0.8) * 0.75; |
1256 | fontsize => ($arg{border} || 0.8) * 0.75; |
1263 | } |
1257 | } |
1264 | |
1258 | |
1265 | my $self = $class->SUPER::new ( |
1259 | my $self = $class->SUPER::new ( |
… | |
… | |
1275 | |
1269 | |
1276 | sub add { |
1270 | sub add { |
1277 | my ($self, @widgets) = @_; |
1271 | my ($self, @widgets) = @_; |
1278 | |
1272 | |
1279 | $self->SUPER::add (@widgets); |
1273 | $self->SUPER::add (@widgets); |
1280 | $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label}; |
1274 | $self->DC::UI::Container::add ($self->{label}) if $self->{label}; |
1281 | } |
1275 | } |
1282 | |
1276 | |
1283 | sub border { |
1277 | sub border { |
1284 | int $_[0]{border} * $::FONTSIZE |
1278 | int $_[0]{border} * $::FONTSIZE |
1285 | } |
1279 | } |
… | |
… | |
1343 | } |
1337 | } |
1344 | } |
1338 | } |
1345 | |
1339 | |
1346 | ############################################################################# |
1340 | ############################################################################# |
1347 | |
1341 | |
1348 | package CFPlus::UI::Toplevel; |
1342 | package DC::UI::Toplevel; |
1349 | |
1343 | |
1350 | our @ISA = CFPlus::UI::Bin::; |
1344 | our @ISA = DC::UI::Bin::; |
1351 | |
1345 | |
1352 | use CFPlus::OpenGL; |
1346 | use DC::OpenGL; |
1353 | |
1347 | |
1354 | my $bg = |
1348 | my $bg = |
1355 | new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", |
1349 | new_from_resource DC::Texture "d1_bg.png", |
1356 | mipmap => 1, wrap => 1; |
1350 | mipmap => 1, wrap => 1; |
1357 | |
1351 | |
1358 | my @border = |
1352 | my @border = |
1359 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1353 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
1360 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1354 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1361 | |
1355 | |
1362 | my @icon = |
1356 | my @icon = |
1363 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1357 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
1364 | qw(x1_move.png x1_resize.png); |
1358 | qw(x1_move.png x1_resize.png); |
1365 | |
1359 | |
1366 | sub new { |
1360 | sub new { |
1367 | my ($class, %arg) = @_; |
1361 | my ($class, %arg) = @_; |
1368 | |
1362 | |
1369 | my $self = $class->SUPER::new ( |
1363 | my $self = $class->SUPER::new ( |
1370 | bg => [1, 1, 1, 1], |
1364 | bg => [1, 1, 1, 1], |
1371 | border_bg => [1, 1, 1, 1], |
1365 | border_bg => [1, 1, 1, 1], |
1372 | border => 0.6, |
1366 | border => 1, |
1373 | can_events => 1, |
1367 | can_events => 1, |
1374 | min_w => 64, |
1368 | min_w => 64, |
1375 | min_h => 32, |
1369 | min_h => 32, |
1376 | %arg, |
1370 | %arg, |
1377 | ); |
1371 | ); |
1378 | |
1372 | |
1379 | $self->{title_widget} = new CFPlus::UI::Label |
1373 | $self->{title_widget} = new DC::UI::Label |
1380 | align => 0, |
1374 | align => 0.5, |
1381 | valign => 1, |
1375 | valign => 1, |
1382 | text => $self->{title}, |
1376 | text => $self->{title}, |
1383 | fontsize => $self->{border}, |
1377 | fontsize => $self->{border}, |
1384 | if exists $self->{title}; |
1378 | if exists $self->{title}; |
1385 | |
1379 | |
1386 | if ($self->{has_close_button}) { |
1380 | if ($self->{has_close_button}) { |
1387 | $self->{close_button} = |
1381 | $self->{close_button} = |
1388 | new CFPlus::UI::ImageButton |
1382 | new DC::UI::ImageButton |
1389 | path => 'x1_close.png', |
1383 | path => 'x1_close.png', |
1390 | on_activate => sub { $self->emit ("delete") }; |
1384 | on_activate => sub { $self->emit ("delete") }; |
1391 | |
1385 | |
1392 | $self->CFPlus::UI::Container::add ($self->{close_button}); |
1386 | $self->DC::UI::Container::add ($self->{close_button}); |
1393 | } |
1387 | } |
1394 | |
1388 | |
1395 | $self |
1389 | $self |
1396 | } |
1390 | } |
1397 | |
1391 | |
1398 | sub add { |
1392 | sub add { |
1399 | my ($self, @widgets) = @_; |
1393 | my ($self, @widgets) = @_; |
1400 | |
1394 | |
1401 | $self->SUPER::add (@widgets); |
1395 | $self->SUPER::add (@widgets); |
1402 | $self->CFPlus::UI::Container::add ($self->{close_button}) if $self->{close_button}; |
1396 | $self->DC::UI::Container::add ($self->{close_button}) if $self->{close_button}; |
1403 | $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1397 | $self->DC::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1404 | } |
1398 | } |
1405 | |
1399 | |
1406 | sub border { |
1400 | sub border { |
1407 | int $_[0]{border} * $::FONTSIZE |
1401 | int $_[0]{border} * $::FONTSIZE |
|
|
1402 | } |
|
|
1403 | |
|
|
1404 | sub get_max_wh { |
|
|
1405 | my ($self) = @_; |
|
|
1406 | |
|
|
1407 | return ($self->{w}, $self->{h}) |
|
|
1408 | if $self->{visible} && $self->{w}; |
|
|
1409 | |
|
|
1410 | $self->SUPER::get_max_wh |
1408 | } |
1411 | } |
1409 | |
1412 | |
1410 | sub size_request { |
1413 | sub size_request { |
1411 | my ($self) = @_; |
1414 | my ($self) = @_; |
1412 | |
1415 | |
… | |
… | |
1584 | if $self->{close_button}; |
1587 | if $self->{close_button}; |
1585 | } |
1588 | } |
1586 | |
1589 | |
1587 | ############################################################################# |
1590 | ############################################################################# |
1588 | |
1591 | |
1589 | package CFPlus::UI::Table; |
1592 | package DC::UI::Table; |
1590 | |
1593 | |
1591 | our @ISA = CFPlus::UI::Container::; |
1594 | our @ISA = DC::UI::Container::; |
1592 | |
1595 | |
1593 | use List::Util qw(max sum); |
1596 | use List::Util qw(max sum); |
1594 | |
1597 | |
1595 | use CFPlus::OpenGL; |
1598 | use DC::OpenGL; |
1596 | |
1599 | |
1597 | sub new { |
1600 | sub new { |
1598 | my $class = shift; |
1601 | my $class = shift; |
1599 | |
1602 | |
1600 | $class->SUPER::new ( |
1603 | $class->SUPER::new ( |
… | |
… | |
1606 | |
1609 | |
1607 | sub add { |
1610 | sub add { |
1608 | my ($self, @widgets) = @_; |
1611 | my ($self, @widgets) = @_; |
1609 | |
1612 | |
1610 | for my $child (@widgets) { |
1613 | for my $child (@widgets) { |
1611 | $child->{rowspan} ||= 1; |
1614 | $child->{c_rowspan} ||= 1; |
1612 | $child->{colspan} ||= 1; |
1615 | $child->{c_colspan} ||= 1; |
1613 | } |
1616 | } |
1614 | |
1617 | |
1615 | $self->SUPER::add (@widgets); |
1618 | $self->SUPER::add (@widgets); |
1616 | } |
1619 | } |
1617 | |
1620 | |
… | |
… | |
1621 | my @widgets; |
1624 | my @widgets; |
1622 | |
1625 | |
1623 | while (@_) { |
1626 | while (@_) { |
1624 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1627 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1625 | |
1628 | |
1626 | $child->{row} = $row; |
1629 | $child->{c_row} = $row; |
1627 | $child->{col} = $col; |
1630 | $child->{c_col} = $col; |
1628 | |
1631 | |
1629 | push @widgets, $child; |
1632 | push @widgets, $child; |
1630 | } |
1633 | } |
1631 | |
1634 | |
1632 | $self->add (@widgets); |
1635 | $self->add (@widgets); |
… | |
… | |
1638 | my (@w, @h); |
1641 | my (@w, @h); |
1639 | |
1642 | |
1640 | my @children = $self->children; |
1643 | my @children = $self->children; |
1641 | |
1644 | |
1642 | # first pass, columns |
1645 | # first pass, columns |
1643 | for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { |
1646 | for my $widget (sort { $a->{c_colspan} <=> $b->{c_colspan} } @children) { |
1644 | my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; |
1647 | my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; |
1645 | |
1648 | |
1646 | my $sw = sum @w[$c .. $c + $cs - 1]; |
1649 | my $sw = sum @w[$c .. $c + $cs - 1]; |
1647 | |
1650 | |
1648 | if ($w > $sw) { |
1651 | if ($w > $sw) { |
1649 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1652 | $_ += ($w - $sw) / ($_ ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1650 | } |
1653 | } |
1651 | } |
1654 | } |
1652 | |
1655 | |
1653 | # second pass, rows |
1656 | # second pass, rows |
1654 | for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { |
1657 | for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { |
1655 | my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; |
1658 | my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; |
1656 | |
1659 | |
1657 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1660 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1658 | |
1661 | |
1659 | if ($h > $sh) { |
1662 | if ($h > $sh) { |
1660 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1663 | $_ += ($h - $sh) / ($_ ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1661 | } |
1664 | } |
1662 | } |
1665 | } |
1663 | |
1666 | |
1664 | (\@w, \@h) |
1667 | (\@w, \@h) |
1665 | } |
1668 | } |
… | |
… | |
1688 | @col_expand = (1) x @$ws unless @col_expand; |
1691 | @col_expand = (1) x @$ws unless @col_expand; |
1689 | my $col_expand = (sum @col_expand) || 1; |
1692 | my $col_expand = (sum @col_expand) || 1; |
1690 | |
1693 | |
1691 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1694 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1692 | |
1695 | |
1693 | CFPlus::UI::harmonize $ws; |
1696 | DC::UI::harmonize $ws; |
1694 | |
1697 | |
1695 | my @row_expand = @{$self->{row_expand}}; |
1698 | my @row_expand = @{$self->{row_expand}}; |
1696 | @row_expand = (1) x @$ws unless @row_expand; |
1699 | @row_expand = (1) x @$ws unless @row_expand; |
1697 | my $row_expand = (sum @row_expand) || 1; |
1700 | my $row_expand = (sum @row_expand) || 1; |
1698 | |
1701 | |
1699 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1702 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1700 | |
1703 | |
1701 | CFPlus::UI::harmonize $hs; |
1704 | DC::UI::harmonize $hs; |
1702 | |
1705 | |
1703 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
1706 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
1704 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1707 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1705 | |
1708 | |
1706 | for my $widget ($self->children) { |
1709 | for my $widget ($self->children) { |
1707 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; |
1710 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(c_row c_col req_w req_h c_rowspan c_colspan)}; |
1708 | |
1711 | |
1709 | $widget->configure ( |
1712 | $widget->configure ( |
1710 | $x[$c], $y[$r], |
1713 | $x[$c], $y[$r], |
1711 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1714 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1712 | ); |
1715 | ); |
… | |
… | |
1715 | 1 |
1718 | 1 |
1716 | } |
1719 | } |
1717 | |
1720 | |
1718 | ############################################################################# |
1721 | ############################################################################# |
1719 | |
1722 | |
1720 | package CFPlus::UI::Fixed; |
1723 | package DC::UI::Fixed; |
1721 | |
1724 | |
1722 | use List::Util qw(min max); |
1725 | use List::Util qw(min max); |
1723 | |
1726 | |
1724 | our @ISA = CFPlus::UI::Container::; |
1727 | our @ISA = DC::UI::Container::; |
1725 | |
|
|
1726 | sub add { |
|
|
1727 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
|
|
1728 | |
|
|
1729 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
|
|
1730 | $self->SUPER::add ($child); |
|
|
1731 | } |
|
|
1732 | |
1728 | |
1733 | sub _scale($$$) { |
1729 | sub _scale($$$) { |
1734 | my ($mode, $val, $max) = @_; |
1730 | my ($rel, $val, $max) = @_; |
1735 | |
1731 | |
1736 | $mode eq "abs" ? $val |
1732 | $rel ? $val * $max : $val |
1737 | : $mode eq "rel" ? $val * $max |
|
|
1738 | : 0 |
|
|
1739 | } |
1733 | } |
1740 | |
1734 | |
1741 | sub size_request { |
1735 | sub size_request { |
1742 | my ($self) = @_; |
1736 | my ($self) = @_; |
1743 | |
1737 | |
1744 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1738 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1745 | |
1739 | |
1746 | # determine overall size by querying abs widgets |
1740 | # determine overall size by querying abs widgets |
1747 | for my $child ($self->visible_children) { |
1741 | for my $child ($self->visible_children) { |
1748 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1742 | unless ($child->{c_rel}) { |
|
|
1743 | my $x = $child->{c_x}; |
|
|
1744 | my $y = $child->{c_y}; |
1749 | |
1745 | |
1750 | if ($pos eq "abs") { |
|
|
1751 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1752 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1753 | |
|
|
1754 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1746 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1755 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1747 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1756 | } |
1748 | } |
1757 | } |
1749 | } |
1758 | |
1750 | |
1759 | my $W = $x2 - $x1; |
1751 | my $W = $x2 - $x1; |
1760 | my $H = $y2 - $y1; |
1752 | my $H = $y2 - $y1; |
1761 | |
1753 | |
1762 | # now layout remaining widgets |
1754 | # now layout remaining widgets |
1763 | for my $child ($self->visible_children) { |
1755 | for my $child ($self->visible_children) { |
1764 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1756 | if ($child->{c_rel}) { |
|
|
1757 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1758 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1765 | |
1759 | |
1766 | if ($pos ne "abs") { |
|
|
1767 | $x = _scale $pos, $x, $W; |
|
|
1768 | $y = _scale $pos, $x, $H; |
|
|
1769 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1770 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1771 | |
|
|
1772 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1760 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1773 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1761 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1774 | } |
1762 | } |
1775 | } |
1763 | } |
1776 | |
1764 | |
1777 | my $W = $x2 - $x1; |
1765 | my $W = $x2 - $x1; |
1778 | my $H = $y2 - $y1; |
1766 | my $H = $y2 - $y1; |
… | |
… | |
1782 | |
1770 | |
1783 | sub invoke_size_allocate { |
1771 | sub invoke_size_allocate { |
1784 | my ($self, $W, $H) = @_; |
1772 | my ($self, $W, $H) = @_; |
1785 | |
1773 | |
1786 | for my $child ($self->visible_children) { |
1774 | for my $child ($self->visible_children) { |
1787 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1775 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1776 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1788 | |
1777 | |
1789 | $x = _scale $pos, $x, $W; |
1778 | $x += $child->{c_halign} * $child->{req_w}; |
1790 | $y = _scale $pos, $x, $H; |
1779 | $y += $child->{c_valign} * $child->{req_h}; |
1791 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1792 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1793 | |
1780 | |
1794 | $child->configure ($x, $y, $w, $h); |
1781 | $child->configure (int $x, int $y, $child->{req_w}, $child->{req_h}); |
1795 | } |
1782 | } |
1796 | |
1783 | |
1797 | 1 |
1784 | 1 |
1798 | } |
1785 | } |
1799 | |
1786 | |
1800 | ############################################################################# |
1787 | ############################################################################# |
1801 | |
1788 | |
1802 | package CFPlus::UI::Box; |
1789 | package DC::UI::Box; |
1803 | |
1790 | |
1804 | our @ISA = CFPlus::UI::Container::; |
1791 | our @ISA = DC::UI::Container::; |
1805 | |
1792 | |
1806 | sub size_request { |
1793 | sub size_request { |
1807 | my ($self) = @_; |
1794 | my ($self) = @_; |
|
|
1795 | |
|
|
1796 | my @children = $self->visible_children; |
1808 | |
1797 | |
1809 | $self->{vertical} |
1798 | $self->{vertical} |
1810 | ? ( |
1799 | ? ( |
1811 | (List::Util::max map $_->{req_w}, @{$self->{children}}), |
1800 | (List::Util::max map $_->{req_w}, @children), |
1812 | (List::Util::sum map $_->{req_h}, @{$self->{children}}), |
1801 | (List::Util::sum map $_->{req_h}, @children), |
1813 | ) |
1802 | ) |
1814 | : ( |
1803 | : ( |
1815 | (List::Util::sum map $_->{req_w}, @{$self->{children}}), |
1804 | (List::Util::sum map $_->{req_w}, @children), |
1816 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
1805 | (List::Util::max map $_->{req_h}, @children), |
1817 | ) |
1806 | ) |
1818 | } |
1807 | } |
1819 | |
1808 | |
1820 | sub invoke_size_allocate { |
1809 | sub invoke_size_allocate { |
1821 | my ($self, $w, $h) = @_; |
1810 | my ($self, $w, $h) = @_; |
… | |
… | |
1842 | $req[$_] += $space * $children[$_]{expand} |
1831 | $req[$_] += $space * $children[$_]{expand} |
1843 | for 0 .. $#children; |
1832 | for 0 .. $#children; |
1844 | } |
1833 | } |
1845 | } |
1834 | } |
1846 | |
1835 | |
1847 | CFPlus::UI::harmonize \@req; |
1836 | DC::UI::harmonize \@req; |
1848 | |
1837 | |
1849 | my $pos = 0; |
1838 | my $pos = 0; |
1850 | for (0 .. $#children) { |
1839 | for (0 .. $#children) { |
1851 | my $alloc = $req[$_]; |
1840 | my $alloc = $req[$_]; |
1852 | $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); |
1841 | $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); |
… | |
… | |
1857 | 1 |
1846 | 1 |
1858 | } |
1847 | } |
1859 | |
1848 | |
1860 | ############################################################################# |
1849 | ############################################################################# |
1861 | |
1850 | |
1862 | package CFPlus::UI::HBox; |
1851 | package DC::UI::HBox; |
1863 | |
1852 | |
1864 | our @ISA = CFPlus::UI::Box::; |
1853 | our @ISA = DC::UI::Box::; |
1865 | |
1854 | |
1866 | sub new { |
1855 | sub new { |
1867 | my $class = shift; |
1856 | my $class = shift; |
1868 | |
1857 | |
1869 | $class->SUPER::new ( |
1858 | $class->SUPER::new ( |
… | |
… | |
1872 | ) |
1861 | ) |
1873 | } |
1862 | } |
1874 | |
1863 | |
1875 | ############################################################################# |
1864 | ############################################################################# |
1876 | |
1865 | |
1877 | package CFPlus::UI::VBox; |
1866 | package DC::UI::VBox; |
1878 | |
1867 | |
1879 | our @ISA = CFPlus::UI::Box::; |
1868 | our @ISA = DC::UI::Box::; |
1880 | |
1869 | |
1881 | sub new { |
1870 | sub new { |
1882 | my $class = shift; |
1871 | my $class = shift; |
1883 | |
1872 | |
1884 | $class->SUPER::new ( |
1873 | $class->SUPER::new ( |
… | |
… | |
1887 | ) |
1876 | ) |
1888 | } |
1877 | } |
1889 | |
1878 | |
1890 | ############################################################################# |
1879 | ############################################################################# |
1891 | |
1880 | |
1892 | package CFPlus::UI::Label; |
1881 | package DC::UI::Label; |
1893 | |
1882 | |
1894 | our @ISA = CFPlus::UI::DrawBG::; |
1883 | our @ISA = DC::UI::DrawBG::; |
1895 | |
1884 | |
1896 | use CFPlus::OpenGL; |
1885 | use DC::OpenGL; |
1897 | |
1886 | |
1898 | sub new { |
1887 | sub new { |
1899 | my ($class, %arg) = @_; |
1888 | my ($class, %arg) = @_; |
1900 | |
1889 | |
1901 | my $self = $class->SUPER::new ( |
1890 | my $self = $class->SUPER::new ( |
… | |
… | |
1906 | #text => initial text |
1895 | #text => initial text |
1907 | #markup => initial narkup |
1896 | #markup => initial narkup |
1908 | #max_w => maximum pixel width |
1897 | #max_w => maximum pixel width |
1909 | #style => 0, # render flags |
1898 | #style => 0, # render flags |
1910 | ellipsise => 3, # end |
1899 | ellipsise => 3, # end |
1911 | layout => (new CFPlus::Layout), |
1900 | layout => (new DC::Layout), |
1912 | fontsize => 1, |
1901 | fontsize => 1, |
1913 | align => -1, |
1902 | align => 0.5, |
1914 | valign => -1, |
1903 | valign => 0.5, |
1915 | padding_x => 2, |
1904 | padding_x => 4, |
1916 | padding_y => 2, |
1905 | padding_y => 2, |
1917 | can_events => 0, |
1906 | can_events => 0, |
1918 | %arg |
1907 | %arg |
1919 | ); |
1908 | ); |
1920 | |
1909 | |
1921 | if (exists $self->{template}) { |
1910 | if (exists $self->{template}) { |
1922 | my $layout = new CFPlus::Layout; |
1911 | my $layout = new DC::Layout; |
1923 | $layout->set_text (delete $self->{template}); |
1912 | $layout->set_text (delete $self->{template}); |
1924 | $self->{template} = $layout; |
1913 | $self->{template} = $layout; |
1925 | } |
1914 | } |
1926 | |
1915 | |
1927 | if (exists $self->{markup}) { |
1916 | if (exists $self->{markup}) { |
… | |
… | |
1945 | |
1934 | |
1946 | delete $self->{ox}; |
1935 | delete $self->{ox}; |
1947 | $self->SUPER::realloc; |
1936 | $self->SUPER::realloc; |
1948 | } |
1937 | } |
1949 | |
1938 | |
|
|
1939 | sub clear { |
|
|
1940 | my ($self) = @_; |
|
|
1941 | |
|
|
1942 | $self->set_text (""); |
|
|
1943 | } |
|
|
1944 | |
1950 | sub set_text { |
1945 | sub set_text { |
1951 | my ($self, $text) = @_; |
1946 | my ($self, $text) = @_; |
1952 | |
1947 | |
1953 | return if $self->{text} eq "T$text"; |
1948 | return if $self->{text} eq "T$text"; |
1954 | $self->{text} = "T$text"; |
1949 | $self->{text} = "T$text"; |
… | |
… | |
1977 | |
1972 | |
1978 | sub size_request { |
1973 | sub size_request { |
1979 | my ($self) = @_; |
1974 | my ($self) = @_; |
1980 | |
1975 | |
1981 | $self->{size_req} ||= do { |
1976 | $self->{size_req} ||= do { |
|
|
1977 | my ($max_w, $max_h) = $self->get_max_wh; |
|
|
1978 | |
1982 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1979 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1983 | $self->{layout}->set_width ($self->{max_w} || -1); |
1980 | $self->{layout}->set_width ($max_w); |
1984 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1981 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1985 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1982 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1986 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1983 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1987 | |
1984 | |
1988 | my ($w, $h) = $self->{layout}->size; |
1985 | my ($w, $h) = $self->{layout}->size; |
1989 | |
1986 | |
1990 | if (exists $self->{template}) { |
1987 | if (exists $self->{template}) { |
1991 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1988 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1992 | $self->{template}->set_width ($self->{max_w} || -1); |
1989 | $self->{template}->set_width ($max_w); |
1993 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1990 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1994 | |
1991 | |
1995 | my ($w2, $h2) = $self->{template}->size; |
1992 | my ($w2, $h2) = $self->{template}->size; |
1996 | |
1993 | |
1997 | $w = List::Util::max $w, $w2; |
1994 | $w = List::Util::max $w, $w2; |
… | |
… | |
2053 | |
2050 | |
2054 | [$self->{layout}->size] |
2051 | [$self->{layout}->size] |
2055 | }; |
2052 | }; |
2056 | |
2053 | |
2057 | unless (exists $self->{ox}) { |
2054 | unless (exists $self->{ox}) { |
2058 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
2055 | $self->{ox} = $self->{padding_x} + int $self->{align} * ($self->{w} - $size->[0] - $self->{padding_x} * 2); |
2059 | : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} |
2056 | $self->{oy} = $self->{padding_y} + int $self->{valign} * ($self->{h} - $size->[1] - $self->{padding_y} * 2); |
2060 | : ($self->{w} - $size->[0]) * 0.5); |
|
|
2061 | |
2057 | |
2062 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2058 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2063 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
|
|
2064 | : ($self->{h} - $size->[1]) * 0.5); |
|
|
2065 | }; |
2059 | }; |
2066 | |
2060 | |
2067 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
2061 | # unless ($self->{list}) { |
2068 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
2062 | # $self->{list} = DC::OpenGL::glGenList; |
2069 | |
2063 | # DC::OpenGL::glNewList $self->{list}; |
2070 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2064 | # $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
|
|
2065 | # DC::OpenGL::glEndList; |
|
|
2066 | # } |
|
|
2067 | # |
|
|
2068 | # DC::OpenGL::glCallList $self->{list}; |
|
|
2069 | |
|
|
2070 | $self->{layout}->draw; |
2071 | } |
2071 | } |
|
|
2072 | |
|
|
2073 | #sub destroy { |
|
|
2074 | # my ($self) = @_; |
|
|
2075 | # |
|
|
2076 | # DC::OpenGL::glDeleteList delete $self->{list} if $self->{list}; |
|
|
2077 | # |
|
|
2078 | # $self->SUPER::destroy; |
|
|
2079 | #} |
2072 | |
2080 | |
2073 | ############################################################################# |
2081 | ############################################################################# |
2074 | |
2082 | |
2075 | package CFPlus::UI::EntryBase; |
2083 | package DC::UI::EntryBase; |
2076 | |
2084 | |
2077 | our @ISA = CFPlus::UI::Label::; |
2085 | our @ISA = DC::UI::Label::; |
2078 | |
2086 | |
2079 | use CFPlus::OpenGL; |
2087 | use DC::OpenGL; |
2080 | |
2088 | |
2081 | sub new { |
2089 | sub new { |
2082 | my $class = shift; |
2090 | my $class = shift; |
2083 | |
2091 | |
2084 | $class->SUPER::new ( |
2092 | $class->SUPER::new ( |
2085 | fg => [1, 1, 1], |
2093 | fg => [1, 1, 1], |
2086 | bg => [0, 0, 0, 0.2], |
2094 | bg => [0, 0, 0, 0.2], |
|
|
2095 | outline => [0.6, 0.3, 0.1], |
2087 | active_bg => [1, 1, 1, 0.5], |
2096 | active_bg => [0, 0, 1, .2], |
2088 | active_fg => [0, 0, 0], |
2097 | active_fg => [1, 1, 1], |
|
|
2098 | active_outline => [1, 1, 0], |
2089 | can_hover => 1, |
2099 | can_hover => 1, |
2090 | can_focus => 1, |
2100 | can_focus => 1, |
|
|
2101 | align => 0, |
2091 | valign => 0, |
2102 | valign => 0.5, |
2092 | can_events => 1, |
2103 | can_events => 1, |
2093 | ellipsise => 0, |
2104 | ellipsise => 0, |
|
|
2105 | padding_x => 4, |
|
|
2106 | padding_y => 2, |
2094 | #text => ... |
2107 | #text => ... |
2095 | #hidden => "*", |
2108 | #hidden => "*", |
2096 | @_ |
2109 | @_ |
2097 | ) |
2110 | ) |
2098 | } |
2111 | } |
… | |
… | |
2145 | |
2158 | |
2146 | my $text = $self->get_text; |
2159 | my $text = $self->get_text; |
2147 | |
2160 | |
2148 | $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; |
2161 | $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; |
2149 | |
2162 | |
2150 | if ($uni == 8) { |
2163 | if ($sym == DC::SDLK_BACKSPACE) { |
2151 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
2164 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
2152 | } elsif ($uni == 127) { |
2165 | } elsif ($sym == DC::SDLK_DELETE) { |
2153 | substr $text, $self->{cursor}, 1, ""; |
2166 | substr $text, $self->{cursor}, 1, ""; |
2154 | } elsif ($sym == CFPlus::SDLK_LEFT) { |
2167 | } elsif ($sym == DC::SDLK_LEFT) { |
2155 | --$self->{cursor} if $self->{cursor}; |
2168 | --$self->{cursor} if $self->{cursor}; |
2156 | } elsif ($sym == CFPlus::SDLK_RIGHT) { |
2169 | } elsif ($sym == DC::SDLK_RIGHT) { |
2157 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
2170 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
2158 | } elsif ($sym == CFPlus::SDLK_HOME) { |
2171 | } elsif ($sym == DC::SDLK_HOME) { |
2159 | # what a hack |
2172 | # what a hack |
2160 | $self->{cursor} = |
2173 | $self->{cursor} = |
2161 | (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ |
2174 | (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ |
2162 | ? length $1 |
2175 | ? length $1 |
2163 | : 0; |
2176 | : 0; |
2164 | } elsif ($sym == CFPlus::SDLK_END) { |
2177 | } elsif ($sym == DC::SDLK_END) { |
2165 | # uh, again |
2178 | # uh, again |
2166 | $self->{cursor} = |
2179 | $self->{cursor} = |
2167 | (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ |
2180 | (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ |
2168 | ? $self->{cursor} + length $1 |
2181 | ? $self->{cursor} + length $1 |
2169 | : length $self->{text}; |
2182 | : length $self->{text}; |
… | |
… | |
2233 | glColor_premultiply @{$self->{bg}}; |
2246 | glColor_premultiply @{$self->{bg}}; |
2234 | } |
2247 | } |
2235 | |
2248 | |
2236 | glEnable GL_BLEND; |
2249 | glEnable GL_BLEND; |
2237 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2250 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2238 | glBegin GL_QUADS; |
|
|
2239 | glVertex 0 , 0; |
|
|
2240 | glVertex 0 , $self->{h}; |
|
|
2241 | glVertex $self->{w}, $self->{h}; |
2251 | glRect 0, 0, $self->{w}, $self->{h}; |
2242 | glVertex $self->{w}, 0; |
|
|
2243 | glEnd; |
|
|
2244 | glDisable GL_BLEND; |
2252 | glDisable GL_BLEND; |
2245 | |
2253 | |
2246 | $self->SUPER::_draw; |
2254 | $self->SUPER::_draw; |
2247 | |
2255 | |
2248 | #TODO: force update every cursor change :( |
2256 | #TODO: force update every cursor change :( |
… | |
… | |
2250 | |
2258 | |
2251 | unless (exists $self->{cur_h}) { |
2259 | unless (exists $self->{cur_h}) { |
2252 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2260 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2253 | utf8::encode $text; |
2261 | utf8::encode $text; |
2254 | |
2262 | |
2255 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
2263 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
2256 | } |
2264 | } |
2257 | |
2265 | |
|
|
2266 | glColor_premultiply @{$self->{active_fg}}; |
2258 | glBegin GL_LINES; |
2267 | glBegin GL_LINES; |
2259 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2268 | glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy}; |
2260 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2269 | glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2261 | glEnd; |
2270 | glEnd; |
|
|
2271 | |
|
|
2272 | glLineWidth 3; |
|
|
2273 | glColor @{$self->{active_outline}}; |
|
|
2274 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
|
|
2275 | glLineWidth 1; |
|
|
2276 | |
|
|
2277 | } else { |
|
|
2278 | glColor @{$self->{outline}}; |
|
|
2279 | glBegin GL_LINE_STRIP; |
|
|
2280 | glVertex .5, $self->{h} * .5; |
|
|
2281 | glVertex .5, $self->{h} - 2.5; |
|
|
2282 | glVertex $self->{w} - .5, $self->{h} - 2.5; |
|
|
2283 | glVertex $self->{w} - .5, $self->{h} * .5; |
|
|
2284 | glEnd; |
2262 | } |
2285 | } |
2263 | } |
2286 | } |
2264 | |
2287 | |
2265 | ############################################################################# |
2288 | ############################################################################# |
2266 | |
2289 | |
2267 | package CFPlus::UI::Entry; |
2290 | package DC::UI::Entry; |
2268 | |
2291 | |
2269 | our @ISA = CFPlus::UI::EntryBase::; |
2292 | our @ISA = DC::UI::EntryBase::; |
2270 | |
2293 | |
2271 | use CFPlus::OpenGL; |
2294 | use DC::OpenGL; |
|
|
2295 | |
|
|
2296 | sub new { |
|
|
2297 | my $class = shift; |
|
|
2298 | |
|
|
2299 | $class->SUPER::new ( |
|
|
2300 | history_pointer => -1, |
|
|
2301 | @_ |
|
|
2302 | ) |
|
|
2303 | } |
|
|
2304 | |
2272 | |
2305 | |
2273 | sub invoke_key_down { |
2306 | sub invoke_key_down { |
2274 | my ($self, $ev) = @_; |
2307 | my ($self, $ev) = @_; |
2275 | |
2308 | |
2276 | my $sym = $ev->{sym}; |
2309 | my $sym = $ev->{sym}; |
… | |
… | |
2282 | $self->{history_pointer} = -1; |
2315 | $self->{history_pointer} = -1; |
2283 | $self->{history_saveback} = ''; |
2316 | $self->{history_saveback} = ''; |
2284 | $self->emit (activate => $txt); |
2317 | $self->emit (activate => $txt); |
2285 | $self->update; |
2318 | $self->update; |
2286 | |
2319 | |
2287 | } elsif ($sym == CFPlus::SDLK_UP) { |
2320 | } elsif ($sym == DC::SDLK_UP) { |
2288 | if ($self->{history_pointer} < 0) { |
2321 | if ($self->{history_pointer} < 0) { |
2289 | $self->{history_saveback} = $self->get_text; |
2322 | $self->{history_saveback} = $self->get_text; |
2290 | } |
2323 | } |
2291 | if (@{$self->{history} || []} > 0) { |
2324 | if (@{$self->{history} || []} > 0) { |
2292 | $self->{history_pointer}++; |
2325 | $self->{history_pointer}++; |
… | |
… | |
2294 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
2327 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
2295 | } |
2328 | } |
2296 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2329 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2297 | } |
2330 | } |
2298 | |
2331 | |
2299 | } elsif ($sym == CFPlus::SDLK_DOWN) { |
2332 | } elsif ($sym == DC::SDLK_DOWN) { |
2300 | $self->{history_pointer}--; |
2333 | $self->{history_pointer}--; |
2301 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
2334 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
2302 | |
2335 | |
2303 | if ($self->{history_pointer} >= 0) { |
2336 | if ($self->{history_pointer} >= 0) { |
2304 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2337 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2305 | } else { |
2338 | } else { |
|
|
2339 | if (defined $self->{history_saveback}) { |
2306 | $self->set_text ($self->{history_saveback}); |
2340 | $self->set_text ($self->{history_saveback}); |
|
|
2341 | $self->{history_saveback} = undef; |
|
|
2342 | } |
2307 | } |
2343 | } |
2308 | |
2344 | |
2309 | } else { |
2345 | } else { |
2310 | return $self->SUPER::invoke_key_down ($ev) |
2346 | return $self->SUPER::invoke_key_down ($ev) |
2311 | } |
2347 | } |
… | |
… | |
2313 | 1 |
2349 | 1 |
2314 | } |
2350 | } |
2315 | |
2351 | |
2316 | ############################################################################# |
2352 | ############################################################################# |
2317 | |
2353 | |
2318 | package CFPlus::UI::TextEdit; |
2354 | package DC::UI::TextEdit; |
2319 | |
2355 | |
2320 | our @ISA = CFPlus::UI::EntryBase::; |
2356 | our @ISA = DC::UI::EntryBase::; |
2321 | |
2357 | |
2322 | use CFPlus::OpenGL; |
2358 | use DC::OpenGL; |
|
|
2359 | |
|
|
2360 | sub new { |
|
|
2361 | my $class = shift; |
|
|
2362 | |
|
|
2363 | $class->SUPER::new ( |
|
|
2364 | padding_y => 4, |
|
|
2365 | |
|
|
2366 | @_ |
|
|
2367 | ) |
|
|
2368 | } |
2323 | |
2369 | |
2324 | sub move_cursor_ver { |
2370 | sub move_cursor_ver { |
2325 | my ($self, $dy) = @_; |
2371 | my ($self, $dy) = @_; |
2326 | |
2372 | |
2327 | my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); |
2373 | my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); |
2328 | |
2374 | |
2329 | $y += $dy; |
2375 | $line += $dy; |
2330 | |
2376 | |
2331 | if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { |
2377 | if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) { |
2332 | $self->{cursor} = $index; |
2378 | $self->{cursor} = $index; |
2333 | delete $self->{cur_h}; |
2379 | delete $self->{cur_h}; |
2334 | $self->update; |
2380 | $self->update; |
2335 | return; |
2381 | return; |
2336 | } |
2382 | } |
… | |
… | |
2339 | sub invoke_key_down { |
2385 | sub invoke_key_down { |
2340 | my ($self, $ev) = @_; |
2386 | my ($self, $ev) = @_; |
2341 | |
2387 | |
2342 | my $sym = $ev->{sym}; |
2388 | my $sym = $ev->{sym}; |
2343 | |
2389 | |
2344 | if ($sym == CFPlus::SDLK_UP) { |
2390 | if ($sym == DC::SDLK_UP) { |
2345 | $self->move_cursor_ver (-1); |
2391 | $self->move_cursor_ver (-1); |
2346 | } elsif ($sym == CFPlus::SDLK_DOWN) { |
2392 | } elsif ($sym == DC::SDLK_DOWN) { |
2347 | $self->move_cursor_ver (+1); |
2393 | $self->move_cursor_ver (+1); |
2348 | } else { |
2394 | } else { |
2349 | return $self->SUPER::invoke_key_down ($ev) |
2395 | return $self->SUPER::invoke_key_down ($ev) |
2350 | } |
2396 | } |
2351 | |
2397 | |
2352 | 1 |
2398 | 1 |
2353 | } |
2399 | } |
2354 | |
2400 | |
2355 | ############################################################################# |
2401 | ############################################################################# |
2356 | |
2402 | |
2357 | package CFPlus::UI::Button; |
2403 | package DC::UI::ButtonBin; |
2358 | |
2404 | |
2359 | our @ISA = CFPlus::UI::Label::; |
2405 | our @ISA = DC::UI::Bin::; |
2360 | |
2406 | |
2361 | use CFPlus::OpenGL; |
2407 | use DC::OpenGL; |
2362 | |
2408 | |
2363 | my @tex = |
2409 | my @tex = |
2364 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2410 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2365 | qw(b1_button_inactive.png b1_button_active.png); |
2411 | qw(b1_button_inactive.png b1_button_active.png); |
2366 | |
2412 | |
2367 | sub new { |
2413 | sub new { |
2368 | my $class = shift; |
2414 | my $class = shift; |
2369 | |
2415 | |
2370 | $class->SUPER::new ( |
2416 | $class->SUPER::new ( |
|
|
2417 | can_hover => 1, |
|
|
2418 | align => 0.5, |
|
|
2419 | valign => 0.5, |
|
|
2420 | can_events => 1, |
|
|
2421 | @_ |
|
|
2422 | ) |
|
|
2423 | } |
|
|
2424 | |
|
|
2425 | sub invoke_button_up { |
|
|
2426 | my ($self, $ev, $x, $y) = @_; |
|
|
2427 | |
|
|
2428 | $self->emit ("activate") |
|
|
2429 | if $x >= 0 && $x < $self->{w} |
|
|
2430 | && $y >= 0 && $y < $self->{h}; |
|
|
2431 | |
|
|
2432 | 1 |
|
|
2433 | } |
|
|
2434 | |
|
|
2435 | sub _draw { |
|
|
2436 | my ($self) = @_; |
|
|
2437 | |
|
|
2438 | glEnable GL_TEXTURE_2D; |
|
|
2439 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2440 | glColor 0, 0, 0, 1; |
|
|
2441 | |
|
|
2442 | my $tex = $tex[$GRAB == $self]; |
|
|
2443 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
|
|
2444 | |
|
|
2445 | glDisable GL_TEXTURE_2D; |
|
|
2446 | |
|
|
2447 | $self->SUPER::_draw; |
|
|
2448 | } |
|
|
2449 | |
|
|
2450 | ############################################################################# |
|
|
2451 | |
|
|
2452 | package DC::UI::Button; |
|
|
2453 | |
|
|
2454 | our @ISA = DC::UI::Label::; |
|
|
2455 | |
|
|
2456 | use DC::OpenGL; |
|
|
2457 | |
|
|
2458 | my @tex = |
|
|
2459 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
|
|
2460 | qw(b1_button_inactive.png b1_button_active.png); |
|
|
2461 | |
|
|
2462 | sub new { |
|
|
2463 | my $class = shift; |
|
|
2464 | |
|
|
2465 | $class->SUPER::new ( |
2371 | padding_x => 4, |
2466 | padding_x => 8, |
2372 | padding_y => 4, |
2467 | padding_y => 4, |
2373 | fg => [1.0, 1.0, 1.0], |
2468 | fg => [1.0, 1.0, 1.0], |
2374 | active_fg => [0.8, 0.8, 0.8], |
2469 | active_fg => [0.8, 0.8, 0.8], |
2375 | can_hover => 1, |
2470 | can_hover => 1, |
2376 | align => 0, |
2471 | align => 0.5, |
2377 | valign => 0, |
2472 | valign => 0.5, |
2378 | can_events => 1, |
2473 | can_events => 1, |
2379 | @_ |
2474 | @_ |
2380 | ) |
2475 | ) |
2381 | } |
2476 | } |
2382 | |
2477 | |
… | |
… | |
2407 | $self->SUPER::_draw; |
2502 | $self->SUPER::_draw; |
2408 | } |
2503 | } |
2409 | |
2504 | |
2410 | ############################################################################# |
2505 | ############################################################################# |
2411 | |
2506 | |
2412 | package CFPlus::UI::CheckBox; |
2507 | package DC::UI::CheckBox; |
2413 | |
2508 | |
2414 | our @ISA = CFPlus::UI::DrawBG::; |
2509 | our @ISA = DC::UI::DrawBG::; |
2415 | |
2510 | |
2416 | my @tex = |
2511 | my @tex = |
2417 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2512 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2418 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
2513 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
2419 | |
2514 | |
2420 | use CFPlus::OpenGL; |
2515 | use DC::OpenGL; |
2421 | |
2516 | |
2422 | sub new { |
2517 | sub new { |
2423 | my $class = shift; |
2518 | my $class = shift; |
2424 | |
2519 | |
2425 | $class->SUPER::new ( |
2520 | $class->SUPER::new ( |
… | |
… | |
2465 | sub _draw { |
2560 | sub _draw { |
2466 | my ($self) = @_; |
2561 | my ($self) = @_; |
2467 | |
2562 | |
2468 | $self->SUPER::_draw; |
2563 | $self->SUPER::_draw; |
2469 | |
2564 | |
2470 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
2565 | glTranslate $self->{padding_x}, $self->{padding_y}, 0; |
2471 | |
2566 | |
2472 | my ($w, $h) = @$self{qw(w h)}; |
2567 | my ($w, $h) = @$self{qw(w h)}; |
2473 | |
2568 | |
2474 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
2569 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
2475 | |
2570 | |
… | |
… | |
2482 | glDisable GL_TEXTURE_2D; |
2577 | glDisable GL_TEXTURE_2D; |
2483 | } |
2578 | } |
2484 | |
2579 | |
2485 | ############################################################################# |
2580 | ############################################################################# |
2486 | |
2581 | |
2487 | package CFPlus::UI::Image; |
2582 | package DC::UI::Image; |
2488 | |
2583 | |
2489 | our @ISA = CFPlus::UI::Base::; |
2584 | our @ISA = DC::UI::Base::; |
2490 | |
2585 | |
2491 | use CFPlus::OpenGL; |
2586 | use DC::OpenGL; |
2492 | |
2587 | |
2493 | our %texture_cache; |
2588 | our %texture_cache; |
2494 | |
2589 | |
2495 | sub new { |
2590 | sub new { |
2496 | my $class = shift; |
2591 | my $class = shift; |
2497 | |
2592 | |
2498 | my $self = $class->SUPER::new ( |
2593 | my $self = $class->SUPER::new ( |
2499 | can_events => 0, |
2594 | can_events => 0, |
|
|
2595 | scale => 1, |
2500 | @_, |
2596 | @_, |
2501 | ); |
2597 | ); |
2502 | |
2598 | |
2503 | $self->{path} || $self->{tex} |
2599 | $self->{path} || $self->{tex} |
2504 | or Carp::croak "'path' or 'tex' attributes required"; |
2600 | or Carp::croak "'path' or 'tex' attributes required"; |
2505 | |
2601 | |
2506 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
2602 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
2507 | new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; |
2603 | new_from_resource DC::Texture $self->{path}, mipmap => 1; |
2508 | |
2604 | |
2509 | CFPlus::weaken $texture_cache{$self->{path}}; |
2605 | DC::weaken $texture_cache{$self->{path}}; |
2510 | |
2606 | |
2511 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2607 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2512 | |
2608 | |
2513 | $self |
2609 | $self |
2514 | } |
2610 | } |
2515 | |
2611 | |
2516 | sub STORABLE_freeze { |
2612 | sub STORABLE_freeze { |
2517 | my ($self, $cloning) = @_; |
2613 | my ($self, $cloning) = @_; |
2518 | |
2614 | |
2519 | $self->{path} |
2615 | $self->{path} |
2520 | or die "cannot serialise CFPlus::UI::Image on non-loadable images\n"; |
2616 | or die "cannot serialise DC::UI::Image on non-loadable images\n"; |
2521 | |
2617 | |
2522 | $self->{path} |
2618 | $self->{path} |
2523 | } |
2619 | } |
2524 | |
2620 | |
2525 | sub STORABLE_attach { |
2621 | sub STORABLE_attach { |
… | |
… | |
2529 | } |
2625 | } |
2530 | |
2626 | |
2531 | sub size_request { |
2627 | sub size_request { |
2532 | my ($self) = @_; |
2628 | my ($self) = @_; |
2533 | |
2629 | |
2534 | ($self->{tex}{w}, $self->{tex}{h}) |
2630 | (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) |
2535 | } |
2631 | } |
2536 | |
2632 | |
2537 | sub _draw { |
2633 | sub _draw { |
2538 | my ($self) = @_; |
2634 | my ($self) = @_; |
2539 | |
2635 | |
… | |
… | |
2549 | } |
2645 | } |
2550 | |
2646 | |
2551 | glEnable GL_TEXTURE_2D; |
2647 | glEnable GL_TEXTURE_2D; |
2552 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2648 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2553 | |
2649 | |
2554 | $tex->draw_quad (0, 0, $w, $h); |
2650 | $tex->draw_quad_alpha (0, 0, $w, $h); |
2555 | |
2651 | |
2556 | glDisable GL_TEXTURE_2D; |
2652 | glDisable GL_TEXTURE_2D; |
2557 | } |
2653 | } |
2558 | |
2654 | |
2559 | ############################################################################# |
2655 | ############################################################################# |
2560 | |
2656 | |
2561 | package CFPlus::UI::ImageButton; |
2657 | package DC::UI::ImageButton; |
2562 | |
2658 | |
2563 | our @ISA = CFPlus::UI::Image::; |
2659 | our @ISA = DC::UI::Image::; |
2564 | |
2660 | |
2565 | use CFPlus::OpenGL; |
2661 | use DC::OpenGL; |
2566 | |
2662 | |
2567 | my %textures; |
2663 | my %textures; |
2568 | |
2664 | |
2569 | sub new { |
2665 | sub new { |
2570 | my $class = shift; |
2666 | my $class = shift; |
… | |
… | |
2573 | padding_x => 4, |
2669 | padding_x => 4, |
2574 | padding_y => 4, |
2670 | padding_y => 4, |
2575 | fg => [1, 1, 1], |
2671 | fg => [1, 1, 1], |
2576 | active_fg => [0, 0, 1], |
2672 | active_fg => [0, 0, 1], |
2577 | can_hover => 1, |
2673 | can_hover => 1, |
2578 | align => 0, |
2674 | align => 0.5, |
2579 | valign => 0, |
2675 | valign => 0.5, |
2580 | can_events => 1, |
2676 | can_events => 1, |
2581 | @_ |
2677 | @_ |
2582 | ); |
2678 | ); |
2583 | } |
2679 | } |
2584 | |
2680 | |
|
|
2681 | sub invoke_button_down { |
|
|
2682 | my ($self, $ev, $x, $y) = @_; |
|
|
2683 | |
|
|
2684 | 1 |
|
|
2685 | } |
|
|
2686 | |
2585 | sub invoke_button_up { |
2687 | sub invoke_button_up { |
2586 | my ($self, $ev, $x, $y) = @_; |
2688 | my ($self, $ev, $x, $y) = @_; |
2587 | |
2689 | |
2588 | $self->emit ("activate") |
2690 | $self->emit ("activate") |
2589 | if $x >= 0 && $x < $self->{w} |
2691 | if $x >= 0 && $x < $self->{w} |
… | |
… | |
2592 | 1 |
2694 | 1 |
2593 | } |
2695 | } |
2594 | |
2696 | |
2595 | ############################################################################# |
2697 | ############################################################################# |
2596 | |
2698 | |
2597 | package CFPlus::UI::VGauge; |
2699 | package DC::UI::VGauge; |
2598 | |
2700 | |
2599 | our @ISA = CFPlus::UI::Base::; |
2701 | our @ISA = DC::UI::Base::; |
2600 | |
2702 | |
2601 | use List::Util qw(min max); |
2703 | use List::Util qw(min max); |
2602 | |
2704 | |
2603 | use CFPlus::OpenGL; |
2705 | use DC::OpenGL; |
2604 | |
2706 | |
2605 | my %tex = ( |
2707 | my %tex = ( |
2606 | food => [ |
2708 | food => [ |
2607 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2709 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2608 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
2710 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
2609 | ], |
2711 | ], |
2610 | grace => [ |
2712 | grace => [ |
2611 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2713 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2612 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
2714 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
2613 | ], |
2715 | ], |
2614 | hp => [ |
2716 | hp => [ |
2615 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2717 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2616 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
2718 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
2617 | ], |
2719 | ], |
2618 | mana => [ |
2720 | mana => [ |
2619 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2721 | map { new_from_resource DC::Texture $_, mipmap => 1 } |
2620 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
2722 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
2621 | ], |
2723 | ], |
2622 | ); |
2724 | ); |
2623 | |
2725 | |
2624 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
2726 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
… | |
… | |
2727 | glDisable GL_TEXTURE_2D; |
2829 | glDisable GL_TEXTURE_2D; |
2728 | } |
2830 | } |
2729 | |
2831 | |
2730 | ############################################################################# |
2832 | ############################################################################# |
2731 | |
2833 | |
|
|
2834 | package DC::UI::Progress; |
|
|
2835 | |
|
|
2836 | our @ISA = DC::UI::Label::; |
|
|
2837 | |
|
|
2838 | use DC::OpenGL; |
|
|
2839 | |
|
|
2840 | sub new { |
|
|
2841 | my ($class, %arg) = @_; |
|
|
2842 | |
|
|
2843 | my $self = $class->SUPER::new ( |
|
|
2844 | fg => [1, 1, 1], |
|
|
2845 | bg => [0, 0, 1, 0.2], |
|
|
2846 | bar => [0.7, 0.5, 0.1, 0.8], |
|
|
2847 | outline => [0.4, 0.3, 0], |
|
|
2848 | fontsize => 0.9, |
|
|
2849 | valign => 0.5, |
|
|
2850 | align => 0.5, |
|
|
2851 | can_events => 1, |
|
|
2852 | ellipsise => 1, |
|
|
2853 | label => "%d%%", |
|
|
2854 | %arg, |
|
|
2855 | ); |
|
|
2856 | |
|
|
2857 | $self->set_value ($arg{value} || -1); |
|
|
2858 | |
|
|
2859 | $self |
|
|
2860 | } |
|
|
2861 | |
|
|
2862 | sub set_label { |
|
|
2863 | my ($self, $label) = @_; |
|
|
2864 | |
|
|
2865 | return if $self->{label} eq $label; |
|
|
2866 | $self->{label} = $label; |
|
|
2867 | |
|
|
2868 | $self->DC::UI::Progress::set_value (0 + delete $self->{value}); |
|
|
2869 | } |
|
|
2870 | |
|
|
2871 | sub set_value { |
|
|
2872 | my ($self, $value) = @_; |
|
|
2873 | |
|
|
2874 | if ($self->{value} ne $value) { |
|
|
2875 | $self->{value} = $value; |
|
|
2876 | |
|
|
2877 | if ($value < 0) { |
|
|
2878 | $self->set_text ("-"); |
|
|
2879 | } else { |
|
|
2880 | $self->set_text (sprintf $self->{label}, $value * 100); |
|
|
2881 | } |
|
|
2882 | |
|
|
2883 | $self->update; |
|
|
2884 | } |
|
|
2885 | } |
|
|
2886 | |
|
|
2887 | sub _draw { |
|
|
2888 | my ($self) = @_; |
|
|
2889 | |
|
|
2890 | glEnable GL_BLEND; |
|
|
2891 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2892 | |
|
|
2893 | if ($self->{value} >= 0) { |
|
|
2894 | my $s = int 2 + ($self->{w} - 4) * $self->{value}; |
|
|
2895 | |
|
|
2896 | glColor_premultiply @{$self->{bar}}; |
|
|
2897 | glRect 2, 2, $s, $self->{h} - 2; |
|
|
2898 | glColor_premultiply @{$self->{bg}}; |
|
|
2899 | glRect $s, 2, $self->{w} - 2, $self->{h} - 2; |
|
|
2900 | } |
|
|
2901 | |
|
|
2902 | glColor_premultiply @{$self->{outline}}; |
|
|
2903 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
|
|
2904 | |
|
|
2905 | glDisable GL_BLEND; |
|
|
2906 | |
|
|
2907 | { |
|
|
2908 | local $self->{bg}; # do not draw background |
|
|
2909 | $self->SUPER::_draw; |
|
|
2910 | } |
|
|
2911 | } |
|
|
2912 | |
|
|
2913 | ############################################################################# |
|
|
2914 | |
|
|
2915 | package DC::UI::ExperienceProgress; |
|
|
2916 | |
|
|
2917 | our @ISA = DC::UI::Progress::; |
|
|
2918 | |
|
|
2919 | sub new { |
|
|
2920 | my ($class, %arg) = @_; |
|
|
2921 | |
|
|
2922 | my $self = $class->SUPER::new ( |
|
|
2923 | tooltip => sub { |
|
|
2924 | my ($self) = @_; |
|
|
2925 | |
|
|
2926 | sprintf "level %d\n%s points\n%s next level\n%s to go", |
|
|
2927 | $self->{lvl}, |
|
|
2928 | ::formsep ($self->{exp}), |
|
|
2929 | ::formsep ($self->{nxt}), |
|
|
2930 | ::formsep ($self->{nxt} - $self->{exp}), |
|
|
2931 | }, |
|
|
2932 | %arg |
|
|
2933 | ); |
|
|
2934 | |
|
|
2935 | $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } |
|
|
2936 | if $::CONN; |
|
|
2937 | |
|
|
2938 | $self |
|
|
2939 | } |
|
|
2940 | |
|
|
2941 | sub DESTROY { |
|
|
2942 | my ($self) = @_; |
|
|
2943 | |
|
|
2944 | delete $::CONN->{on_exp_update}{$self+0} |
|
|
2945 | if $::CONN; |
|
|
2946 | |
|
|
2947 | $self->SUPER::DESTROY; |
|
|
2948 | } |
|
|
2949 | |
|
|
2950 | sub set_value { |
|
|
2951 | my ($self, $lvl, $exp) = @_; |
|
|
2952 | |
|
|
2953 | $self->{lvl} = $lvl; |
|
|
2954 | $self->{exp} = $exp; |
|
|
2955 | |
|
|
2956 | my $v = -1; |
|
|
2957 | |
|
|
2958 | if ($::CONN && (my $table = $::CONN->{exp_table})) { |
|
|
2959 | my $l0 = $table->[$lvl - 1]; |
|
|
2960 | my $l1 = $table->[$lvl]; |
|
|
2961 | |
|
|
2962 | $self->{nxt} = $l1; |
|
|
2963 | |
|
|
2964 | $v = ($exp - $l0) / ($l1 - $l0); |
|
|
2965 | } |
|
|
2966 | |
|
|
2967 | $self->SUPER::set_value ($v); |
|
|
2968 | } |
|
|
2969 | |
|
|
2970 | ############################################################################# |
|
|
2971 | |
2732 | package CFPlus::UI::Gauge; |
2972 | package DC::UI::Gauge; |
2733 | |
2973 | |
2734 | our @ISA = CFPlus::UI::VBox::; |
2974 | our @ISA = DC::UI::VBox::; |
2735 | |
2975 | |
2736 | sub new { |
2976 | sub new { |
2737 | my ($class, %arg) = @_; |
2977 | my ($class, %arg) = @_; |
2738 | |
2978 | |
2739 | my $self = $class->SUPER::new ( |
2979 | my $self = $class->SUPER::new ( |
… | |
… | |
2741 | can_hover => 1, |
2981 | can_hover => 1, |
2742 | can_events => 1, |
2982 | can_events => 1, |
2743 | %arg, |
2983 | %arg, |
2744 | ); |
2984 | ); |
2745 | |
2985 | |
2746 | $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999"); |
2986 | $self->add ($self->{value} = new DC::UI::Label valign => 1, align => 0.5, template => "999"); |
2747 | $self->add ($self->{gauge} = new CFPlus::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
2987 | $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
2748 | $self->add ($self->{max} = new CFPlus::UI::Label valign => -1, align => 0, template => "999"); |
2988 | $self->add ($self->{max} = new DC::UI::Label valign => 0, align => 0.5, template => "999"); |
2749 | |
2989 | |
2750 | $self |
2990 | $self |
2751 | } |
2991 | } |
2752 | |
2992 | |
2753 | sub set_fontsize { |
2993 | sub set_fontsize { |
… | |
… | |
2774 | $self->{value}->set_text ($val); |
3014 | $self->{value}->set_text ($val); |
2775 | } |
3015 | } |
2776 | |
3016 | |
2777 | ############################################################################# |
3017 | ############################################################################# |
2778 | |
3018 | |
2779 | package CFPlus::UI::Slider; |
3019 | package DC::UI::Slider; |
2780 | |
3020 | |
2781 | use strict; |
3021 | use strict; |
2782 | |
3022 | |
2783 | use CFPlus::OpenGL; |
3023 | use DC::OpenGL; |
2784 | |
3024 | |
2785 | our @ISA = CFPlus::UI::DrawBG::; |
3025 | our @ISA = DC::UI::DrawBG::; |
2786 | |
3026 | |
2787 | my @tex = |
3027 | my @tex = |
2788 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ } |
3028 | map { new_from_resource DC::Texture $_ } |
2789 | qw(s1_slider.png s1_slider_bg.png); |
3029 | qw(s1_slider.png s1_slider_bg.png); |
2790 | |
3030 | |
2791 | sub new { |
3031 | sub new { |
2792 | my $class = shift; |
3032 | my $class = shift; |
2793 | |
3033 | |
… | |
… | |
2830 | sub set_value { |
3070 | sub set_value { |
2831 | my ($self, $value) = @_; |
3071 | my ($self, $value) = @_; |
2832 | |
3072 | |
2833 | my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; |
3073 | my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; |
2834 | |
3074 | |
2835 | $hi = $lo + 1 if $hi <= $lo; |
3075 | $hi = $lo if $hi < $lo; |
2836 | |
3076 | |
2837 | $page = $hi - $lo if $page > $hi - $lo; |
3077 | $value = $hi - $page if $value > $hi - $page; |
2838 | |
|
|
2839 | $value = $lo if $value < $lo; |
3078 | $value = $lo if $value < $lo; |
2840 | $value = $hi - $page if $value > $hi - $page; |
|
|
2841 | |
3079 | |
2842 | $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit |
3080 | $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit |
2843 | if $unit; |
3081 | if $unit; |
2844 | |
3082 | |
2845 | @{$self->{range}} = ($value, $lo, $hi, $page, $unit); |
3083 | @{$self->{range}} = ($value, $lo, $hi, $page, $unit); |
… | |
… | |
2861 | |
3099 | |
2862 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
3100 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2863 | |
3101 | |
2864 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
3102 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2865 | |
3103 | |
2866 | $self->invoke_mouse_motion ($ev, $x, $y) |
3104 | $self->invoke_mouse_motion ($ev, $x, $y); |
|
|
3105 | |
|
|
3106 | 1 |
2867 | } |
3107 | } |
2868 | |
3108 | |
2869 | sub invoke_mouse_motion { |
3109 | sub invoke_mouse_motion { |
2870 | my ($self, $ev, $x, $y) = @_; |
3110 | my ($self, $ev, $x, $y) = @_; |
2871 | |
3111 | |
… | |
… | |
2887 | sub invoke_mouse_wheel { |
3127 | sub invoke_mouse_wheel { |
2888 | my ($self, $ev) = @_; |
3128 | my ($self, $ev) = @_; |
2889 | |
3129 | |
2890 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
3130 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
2891 | |
3131 | |
2892 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
3132 | my $pagepart = $ev->{mod} & DC::KMOD_SHIFT ? 1 : 0.2; |
2893 | |
3133 | |
2894 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
3134 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2895 | |
3135 | |
2896 | ! ! $delta |
3136 | 1 |
2897 | } |
3137 | } |
2898 | |
3138 | |
2899 | sub update { |
3139 | sub update { |
2900 | my ($self) = @_; |
3140 | my ($self) = @_; |
2901 | |
3141 | |
… | |
… | |
2907 | my ($self) = @_; |
3147 | my ($self) = @_; |
2908 | |
3148 | |
2909 | unless ($self->{knob_w}) { |
3149 | unless ($self->{knob_w}) { |
2910 | $self->set_value ($self->{range}[0]); |
3150 | $self->set_value ($self->{range}[0]); |
2911 | |
3151 | |
2912 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
3152 | my ($value, $lo, $hi, $page, $unit) = @{$self->{range}}; |
2913 | my $range = ($hi - $page - $lo) || 1e-100; |
3153 | my $range = ($hi - $page - $lo) || 1e-10; |
2914 | |
3154 | |
2915 | my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1; |
3155 | my $knob_w = List::Util::min 1, $page / (($hi - $lo) || 1e-10) || 24 / $self->{w}; |
2916 | |
3156 | |
2917 | $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; |
3157 | $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; |
2918 | $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; |
3158 | $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; |
2919 | |
3159 | |
2920 | $value = ($value - $lo) / $range; |
3160 | $value = ($value - $lo) / $range; |
… | |
… | |
2950 | glDisable GL_TEXTURE_2D; |
3190 | glDisable GL_TEXTURE_2D; |
2951 | } |
3191 | } |
2952 | |
3192 | |
2953 | ############################################################################# |
3193 | ############################################################################# |
2954 | |
3194 | |
2955 | package CFPlus::UI::ValSlider; |
3195 | package DC::UI::ValSlider; |
2956 | |
3196 | |
2957 | our @ISA = CFPlus::UI::HBox::; |
3197 | our @ISA = DC::UI::HBox::; |
2958 | |
3198 | |
2959 | sub new { |
3199 | sub new { |
2960 | my ($class, %arg) = @_; |
3200 | my ($class, %arg) = @_; |
2961 | |
3201 | |
2962 | my $range = delete $arg{range}; |
3202 | my $range = delete $arg{range}; |
2963 | |
3203 | |
2964 | my $self = $class->SUPER::new ( |
3204 | my $self = $class->SUPER::new ( |
2965 | slider => (new CFPlus::UI::Slider expand => 1, range => $range), |
3205 | slider => (new DC::UI::Slider expand => 1, range => $range), |
2966 | entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}), |
3206 | entry => (new DC::UI::Label text => "", template => delete $arg{template}), |
2967 | to_value => sub { shift }, |
3207 | to_value => sub { shift }, |
2968 | from_value => sub { shift }, |
3208 | from_value => sub { shift }, |
2969 | %arg, |
3209 | %arg, |
2970 | ); |
3210 | ); |
2971 | |
3211 | |
… | |
… | |
2991 | sub set_range { shift->{slider}->set_range (@_) } |
3231 | sub set_range { shift->{slider}->set_range (@_) } |
2992 | sub set_value { shift->{slider}->set_value (@_) } |
3232 | sub set_value { shift->{slider}->set_value (@_) } |
2993 | |
3233 | |
2994 | ############################################################################# |
3234 | ############################################################################# |
2995 | |
3235 | |
2996 | package CFPlus::UI::TextScroller; |
3236 | package DC::UI::TextScroller; |
2997 | |
3237 | |
2998 | our @ISA = CFPlus::UI::HBox::; |
3238 | our @ISA = DC::UI::HBox::; |
2999 | |
3239 | |
3000 | use CFPlus::OpenGL; |
3240 | use DC::OpenGL; |
3001 | |
3241 | |
3002 | sub new { |
3242 | sub new { |
3003 | my $class = shift; |
3243 | my $class = shift; |
3004 | |
3244 | |
3005 | my $self = $class->SUPER::new ( |
3245 | my $self = $class->SUPER::new ( |
… | |
… | |
3007 | can_events => 1, |
3247 | can_events => 1, |
3008 | indent => 0, |
3248 | indent => 0, |
3009 | #font => default_font |
3249 | #font => default_font |
3010 | @_, |
3250 | @_, |
3011 | |
3251 | |
3012 | layout => (new CFPlus::Layout), |
3252 | layout => (new DC::Layout), |
3013 | par => [], |
3253 | par => [], |
3014 | max_par => 0, |
3254 | max_par => 0, |
3015 | height => 0, |
3255 | height => 0, |
3016 | children => [ |
3256 | children => [ |
3017 | (new CFPlus::UI::Empty expand => 1), |
3257 | (new DC::UI::Empty expand => 1), |
3018 | (new CFPlus::UI::Slider vertical => 1), |
3258 | (new DC::UI::Slider vertical => 1), |
3019 | ], |
3259 | ], |
3020 | ); |
3260 | ); |
3021 | |
3261 | |
3022 | $self->{children}[1]->connect (changed => sub { $self->update }); |
3262 | $self->{children}[1]->connect (changed => sub { $self->update }); |
3023 | |
3263 | |
… | |
… | |
3032 | } |
3272 | } |
3033 | |
3273 | |
3034 | sub size_request { |
3274 | sub size_request { |
3035 | my ($self) = @_; |
3275 | my ($self) = @_; |
3036 | |
3276 | |
3037 | my ($empty, $slider) = @{ $self->{children} }; |
3277 | my ($empty, $slider) = $self->visible_children; |
3038 | |
3278 | |
3039 | local $self->{children} = [$empty, $slider]; |
3279 | local $self->{children} = [$empty, $slider]; |
3040 | $self->SUPER::size_request |
3280 | $self->SUPER::size_request |
3041 | } |
3281 | } |
3042 | |
3282 | |
… | |
… | |
3079 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
3319 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
3080 | $layout->set_markup ($para->{markup}); |
3320 | $layout->set_markup ($para->{markup}); |
3081 | |
3321 | |
3082 | $layout->set_shapes ( |
3322 | $layout->set_shapes ( |
3083 | map |
3323 | map |
3084 | +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), |
3324 | +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), |
3085 | @{$para->{widget}} |
3325 | @{$para->{widget}} |
3086 | ); |
3326 | ); |
3087 | |
3327 | |
3088 | $layout |
3328 | $layout |
3089 | } |
3329 | } |
… | |
… | |
3206 | $ROOT->on_post_alloc ($self => sub { |
3446 | $ROOT->on_post_alloc ($self => sub { |
3207 | $self->force_uptodate; |
3447 | $self->force_uptodate; |
3208 | |
3448 | |
3209 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
3449 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
3210 | |
3450 | |
3211 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
3451 | $self->{texture} ||= new_from_opengl DC::Texture $W, $H, sub { |
3212 | glClearColor 0, 0, 0, 0; |
3452 | glClearColor 0, 0, 0, 0; |
3213 | glClear GL_COLOR_BUFFER_BIT; |
3453 | glClear GL_COLOR_BUFFER_BIT; |
3214 | |
3454 | |
3215 | package CFPlus::UI::Base; |
3455 | package DC::UI::Base; |
3216 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
3456 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
3217 | (0, 0, $self->{w}, $self->{h}); |
3457 | (0, 0, $self->{w}, $self->{h}); |
3218 | |
3458 | |
3219 | my $top = int $self->{children}[1]{range}[0]; |
3459 | my $top = int $self->{children}[1]{range}[0]; |
3220 | |
3460 | |
… | |
… | |
3231 | |
3471 | |
3232 | if ($y0 < $y + $h && $y < $y1) { |
3472 | if ($y0 < $y + $h && $y < $y1) { |
3233 | my $layout = $self->get_layout ($para); |
3473 | my $layout = $self->get_layout ($para); |
3234 | |
3474 | |
3235 | $layout->render ($para->{indent}, $y - $y0); |
3475 | $layout->render ($para->{indent}, $y - $y0); |
|
|
3476 | $layout->draw; |
3236 | |
3477 | |
3237 | if (my @w = @{ $para->{widget} }) { |
3478 | if (my @w = @{ $para->{widget} }) { |
3238 | my @s = $layout->get_shapes; |
3479 | my @s = $layout->get_shapes; |
3239 | |
3480 | |
3240 | for (@w) { |
3481 | for (@w) { |
… | |
… | |
3278 | $self->{children}[1]->draw; |
3519 | $self->{children}[1]->draw; |
3279 | } |
3520 | } |
3280 | |
3521 | |
3281 | ############################################################################# |
3522 | ############################################################################# |
3282 | |
3523 | |
3283 | package CFPlus::UI::Animator; |
3524 | package DC::UI::Animator; |
3284 | |
3525 | |
3285 | use CFPlus::OpenGL; |
3526 | use DC::OpenGL; |
3286 | |
3527 | |
3287 | our @ISA = CFPlus::UI::Bin::; |
3528 | our @ISA = DC::UI::Bin::; |
3288 | |
3529 | |
3289 | sub moveto { |
3530 | sub moveto { |
3290 | my ($self, $x, $y) = @_; |
3531 | my ($self, $x, $y) = @_; |
3291 | |
3532 | |
3292 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
3533 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
… | |
… | |
3320 | glPopMatrix; |
3561 | glPopMatrix; |
3321 | } |
3562 | } |
3322 | |
3563 | |
3323 | ############################################################################# |
3564 | ############################################################################# |
3324 | |
3565 | |
3325 | package CFPlus::UI::Flopper; |
3566 | package DC::UI::Flopper; |
3326 | |
3567 | |
3327 | our @ISA = CFPlus::UI::Button::; |
3568 | our @ISA = DC::UI::Button::; |
3328 | |
3569 | |
3329 | sub new { |
3570 | sub new { |
3330 | my $class = shift; |
3571 | my $class = shift; |
3331 | |
3572 | |
3332 | my $self = $class->SUPER::new ( |
3573 | my $self = $class->SUPER::new ( |
… | |
… | |
3344 | $self->{other}->toggle_visibility; |
3585 | $self->{other}->toggle_visibility; |
3345 | } |
3586 | } |
3346 | |
3587 | |
3347 | ############################################################################# |
3588 | ############################################################################# |
3348 | |
3589 | |
3349 | package CFPlus::UI::Tooltip; |
3590 | package DC::UI::Tooltip; |
3350 | |
3591 | |
3351 | our @ISA = CFPlus::UI::Bin::; |
3592 | our @ISA = DC::UI::Bin::; |
3352 | |
3593 | |
3353 | use CFPlus::OpenGL; |
3594 | use DC::OpenGL; |
3354 | |
3595 | |
3355 | sub new { |
3596 | sub new { |
3356 | my $class = shift; |
3597 | my $class = shift; |
3357 | |
3598 | |
3358 | $class->SUPER::new ( |
3599 | $class->SUPER::new ( |
… | |
… | |
3362 | } |
3603 | } |
3363 | |
3604 | |
3364 | sub set_tooltip_from { |
3605 | sub set_tooltip_from { |
3365 | my ($self, $widget) = @_; |
3606 | my ($self, $widget) = @_; |
3366 | |
3607 | |
3367 | $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1 |
|
|
3368 | if $widget->{tooltip} =~ /^#(.*)$/; |
|
|
3369 | |
|
|
3370 | my $tooltip = $widget->{tooltip}; |
3608 | my $tip = $widget->{tooltip}; |
|
|
3609 | $tip = $tip->($widget) if "CODE" eq ref $tip; |
|
|
3610 | |
|
|
3611 | $tip = DC::Pod::section_label tooltip => $1 |
|
|
3612 | if $tip =~ /^#(.*)$/; |
3371 | |
3613 | |
3372 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3614 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3373 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
3615 | $tip .= "\n\n" . (ref $widget) . "\n" |
3374 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3616 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3375 | . "req $widget->{req_w} $widget->{req_h}\n" |
3617 | . "req $widget->{req_w} $widget->{req_h}\n" |
3376 | . "visible $widget->{visible}"; |
3618 | . "visible $widget->{visible}"; |
3377 | } |
3619 | } |
3378 | |
3620 | |
3379 | $tooltip =~ s/^\n+//; |
3621 | $tip =~ s/^\n+//; |
3380 | $tooltip =~ s/\n+$//; |
3622 | $tip =~ s/\n+$//; |
3381 | |
3623 | |
3382 | $self->add (new CFPlus::UI::Label |
3624 | $self->add (new DC::UI::Label |
3383 | markup => $tooltip, |
3625 | markup => $tip, |
3384 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3626 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
|
|
3627 | align => 0, |
3385 | fontsize => 0.8, |
3628 | fontsize => 0.8, |
3386 | style => 1, # FLAG_INVERSE |
3629 | style => 1, # FLAG_INVERSE |
3387 | ellipsise => 0, |
3630 | ellipsise => 0, |
3388 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3631 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3389 | ); |
3632 | ); |
… | |
… | |
3426 | } |
3669 | } |
3427 | |
3670 | |
3428 | sub _draw { |
3671 | sub _draw { |
3429 | my ($self) = @_; |
3672 | my ($self) = @_; |
3430 | |
3673 | |
3431 | glTranslate 0.375, 0.375; |
|
|
3432 | |
|
|
3433 | my ($w, $h) = @$self{qw(w h)}; |
3674 | my ($w, $h) = @$self{qw(w h)}; |
3434 | |
3675 | |
3435 | glColor 1, 0.8, 0.4; |
3676 | glColor 1, 0.8, 0.4; |
3436 | glBegin GL_QUADS; |
3677 | glRect 0, 0, $w, $h; |
3437 | glVertex 0 , 0; |
|
|
3438 | glVertex 0 , $h; |
|
|
3439 | glVertex $w, $h; |
|
|
3440 | glVertex $w, 0; |
|
|
3441 | glEnd; |
|
|
3442 | |
3678 | |
3443 | glColor 0, 0, 0; |
3679 | glColor 0, 0, 0; |
3444 | glBegin GL_LINE_LOOP; |
3680 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3445 | glVertex 0 , 0; |
|
|
3446 | glVertex 0 , $h; |
|
|
3447 | glVertex $w, $h; |
|
|
3448 | glVertex $w, 0; |
|
|
3449 | glEnd; |
|
|
3450 | |
3681 | |
3451 | glTranslate 2 - 0.375, 2 - 0.375; |
3682 | glTranslate 2, 2; |
3452 | |
3683 | |
3453 | $self->SUPER::_draw; |
3684 | $self->SUPER::_draw; |
3454 | } |
3685 | } |
3455 | |
3686 | |
3456 | ############################################################################# |
3687 | ############################################################################# |
3457 | |
3688 | |
3458 | package CFPlus::UI::Face; |
3689 | package DC::UI::Face; |
3459 | |
3690 | |
3460 | our @ISA = CFPlus::UI::DrawBG::; |
3691 | our @ISA = DC::UI::DrawBG::; |
3461 | |
3692 | |
3462 | use CFPlus::OpenGL; |
3693 | use DC::OpenGL; |
3463 | |
3694 | |
3464 | sub new { |
3695 | sub new { |
3465 | my $class = shift; |
3696 | my $class = shift; |
3466 | |
3697 | |
3467 | my $self = $class->SUPER::new ( |
3698 | my $self = $class->SUPER::new ( |
… | |
… | |
3471 | can_events => 0, |
3702 | can_events => 0, |
3472 | @_, |
3703 | @_, |
3473 | ); |
3704 | ); |
3474 | |
3705 | |
3475 | if ($self->{anim} && $self->{animspeed}) { |
3706 | if ($self->{anim} && $self->{animspeed}) { |
3476 | CFPlus::weaken (my $widget = $self); |
3707 | DC::weaken (my $widget = $self); |
3477 | |
3708 | |
3478 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3709 | $self->{animspeed} = List::Util::max 0.05, $self->{animspeed}; |
3479 | $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; |
3710 | $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub { |
3480 | $self->{timer} = Event->timer ( |
|
|
3481 | parked => 1, |
|
|
3482 | cb => sub { |
|
|
3483 | return unless $::CONN && $widget; |
3711 | return unless $::CONN; |
3484 | |
3712 | |
|
|
3713 | my $w = $widget |
|
|
3714 | or return; |
|
|
3715 | |
3485 | ++$widget->{frame}; |
3716 | ++$w->{frame}; |
3486 | $widget->update_face; |
3717 | $w->update_face; |
|
|
3718 | |
|
|
3719 | # somehow, $widget can go away |
3487 | $widget->update; |
3720 | $w->update; |
3488 | |
|
|
3489 | $widget->update_timer; |
3721 | $w->update_timer; |
3490 | }, |
|
|
3491 | ); |
3722 | }; |
3492 | |
3723 | |
3493 | $self->update_face; |
3724 | $self->update_face; |
3494 | $self->update_timer; |
3725 | $self->update_timer; |
3495 | } |
3726 | } |
3496 | |
3727 | |
… | |
… | |
3501 | my ($self) = @_; |
3732 | my ($self) = @_; |
3502 | |
3733 | |
3503 | return unless $self->{timer}; |
3734 | return unless $self->{timer}; |
3504 | |
3735 | |
3505 | if ($self->{visible}) { |
3736 | if ($self->{visible}) { |
3506 | $self->{timer}->at ( |
|
|
3507 | $self->{anim_start} |
|
|
3508 | + $self->{animspeed} |
|
|
3509 | * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed} |
|
|
3510 | ); |
|
|
3511 | $self->{timer}->start; |
3737 | $self->{timer}->start; |
3512 | } else { |
3738 | } else { |
3513 | $self->{timer}->stop; |
3739 | $self->{timer}->stop; |
3514 | } |
3740 | } |
3515 | } |
3741 | } |
3516 | |
3742 | |
3517 | sub update_face { |
3743 | sub update_face { |
3518 | my ($self) = @_; |
3744 | my ($self) = @_; |
3519 | |
3745 | |
3520 | return unless $::CONN; |
|
|
3521 | |
|
|
3522 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
|
|
3523 | if ($anim && @$anim) { |
|
|
3524 | delete $self->{wait_face}; |
|
|
3525 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
|
|
3526 | } |
|
|
3527 | } |
|
|
3528 | } |
|
|
3529 | |
|
|
3530 | sub size_request { |
|
|
3531 | my ($self) = @_; |
|
|
3532 | |
|
|
3533 | if ($::CONN) { |
3746 | if ($::CONN) { |
3534 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3747 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3535 | if (my $tex = $::CONN->{texture}[$faceid]) { |
3748 | if ($anim && @$anim) { |
3536 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3749 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
3537 | } else { |
3750 | delete $self->{face_change_cb}; |
3538 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3751 | |
3539 | $self->realloc; |
3752 | if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) { |
|
|
3753 | unless ($tex->{name} || $tex->{loading}) { |
|
|
3754 | $tex->upload (sub { $self->reconfigure }); |
|
|
3755 | } |
3540 | }); |
3756 | } |
3541 | } |
3757 | } |
3542 | } |
3758 | } |
3543 | } |
3759 | } |
|
|
3760 | } |
|
|
3761 | |
|
|
3762 | sub size_request { |
|
|
3763 | my ($self) = @_; |
|
|
3764 | |
|
|
3765 | if ($::CONN) { |
|
|
3766 | if (my $faceid = $::CONN->{face}[$self->{face}]{id}) { |
|
|
3767 | if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) { |
|
|
3768 | if ($tex->{name}) { |
|
|
3769 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
|
|
3770 | } elsif (!$tex->{loading}) { |
|
|
3771 | $tex->upload (sub { $self->reconfigure }); |
|
|
3772 | } |
|
|
3773 | } |
|
|
3774 | |
|
|
3775 | $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure }); |
|
|
3776 | } |
|
|
3777 | } |
3544 | |
3778 | |
3545 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3779 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3546 | } |
3780 | } |
3547 | |
3781 | |
3548 | sub update { |
3782 | sub update { |
… | |
… | |
3562 | } |
3796 | } |
3563 | |
3797 | |
3564 | sub _draw { |
3798 | sub _draw { |
3565 | my ($self) = @_; |
3799 | my ($self) = @_; |
3566 | |
3800 | |
3567 | return unless $::CONN; |
|
|
3568 | |
|
|
3569 | $self->SUPER::_draw; |
3801 | $self->SUPER::_draw; |
3570 | |
3802 | |
3571 | my $faceid = $::CONN->{faceid}[$self->{face}] |
3803 | if (my $tex = $self->{tex}) { |
3572 | or return; |
|
|
3573 | |
|
|
3574 | my $tex = $::CONN->{texture}[$faceid]; |
|
|
3575 | |
|
|
3576 | if ($tex) { |
|
|
3577 | glEnable GL_TEXTURE_2D; |
3804 | glEnable GL_TEXTURE_2D; |
3578 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3805 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3579 | glColor 0, 0, 0, 1; |
3806 | glColor 0, 0, 0, 1; |
3580 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3807 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3581 | glDisable GL_TEXTURE_2D; |
3808 | glDisable GL_TEXTURE_2D; |
… | |
… | |
3591 | $self->SUPER::destroy; |
3818 | $self->SUPER::destroy; |
3592 | } |
3819 | } |
3593 | |
3820 | |
3594 | ############################################################################# |
3821 | ############################################################################# |
3595 | |
3822 | |
3596 | package CFPlus::UI::Buttonbar; |
3823 | package DC::UI::Buttonbar; |
3597 | |
3824 | |
3598 | our @ISA = CFPlus::UI::HBox::; |
3825 | our @ISA = DC::UI::HBox::; |
3599 | |
3826 | |
3600 | # TODO: should actually wrap buttons and other goodies. |
3827 | # TODO: should actually wrap buttons and other goodies. |
3601 | |
3828 | |
3602 | ############################################################################# |
3829 | ############################################################################# |
3603 | |
3830 | |
3604 | package CFPlus::UI::Menu; |
3831 | package DC::UI::Menu; |
3605 | |
3832 | |
3606 | our @ISA = CFPlus::UI::Toplevel::; |
3833 | our @ISA = DC::UI::Toplevel::; |
3607 | |
3834 | |
3608 | use CFPlus::OpenGL; |
3835 | use DC::OpenGL; |
3609 | |
3836 | |
3610 | sub new { |
3837 | sub new { |
3611 | my $class = shift; |
3838 | my $class = shift; |
3612 | |
3839 | |
3613 | my $self = $class->SUPER::new ( |
3840 | my $self = $class->SUPER::new ( |
3614 | items => [], |
3841 | items => [], |
3615 | z => 100, |
3842 | z => 100, |
3616 | @_, |
3843 | @_, |
3617 | ); |
3844 | ); |
3618 | |
3845 | |
3619 | $self->add ($self->{vbox} = new CFPlus::UI::VBox); |
3846 | $self->add ($self->{vbox} = new DC::UI::VBox); |
3620 | |
3847 | |
3621 | for my $item (@{ $self->{items} }) { |
3848 | for my $item (@{ $self->{items} }) { |
3622 | my ($widget, $cb, $tooltip) = @$item; |
3849 | my ($widget, $cb, $tooltip) = @$item; |
3623 | |
3850 | |
3624 | # handle various types of items, only text for now |
3851 | # handle various types of items, only text for now |
3625 | if (!ref $widget) { |
3852 | if (!ref $widget) { |
3626 | if ($widget =~ /\t/) { |
3853 | if ($widget =~ /\t/) { |
3627 | my ($left, $right) = split /\t/, $widget, 2; |
3854 | my ($left, $right) = split /\t/, $widget, 2; |
3628 | |
3855 | |
3629 | $widget = new CFPlus::UI::HBox |
3856 | $widget = new DC::UI::HBox |
3630 | can_hover => 1, |
3857 | can_hover => 1, |
3631 | can_events => 1, |
3858 | can_events => 1, |
3632 | tooltip => $tooltip, |
3859 | tooltip => $tooltip, |
3633 | children => [ |
3860 | children => [ |
3634 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3861 | (new DC::UI::Label markup => $left , align => 0, expand => 1), |
3635 | (new CFPlus::UI::Label markup => $right, align => +1), |
3862 | (new DC::UI::Label markup => $right, align => 1), |
3636 | ], |
3863 | ], |
3637 | ; |
3864 | ; |
3638 | |
3865 | |
3639 | } else { |
3866 | } else { |
3640 | $widget = new CFPlus::UI::Label |
3867 | $widget = new DC::UI::Label |
3641 | can_hover => 1, |
3868 | can_hover => 1, |
3642 | can_events => 1, |
3869 | can_events => 1, |
|
|
3870 | align => 0, |
3643 | markup => $widget, |
3871 | markup => $widget, |
3644 | tooltip => $tooltip; |
3872 | tooltip => $tooltip; |
3645 | } |
3873 | } |
3646 | } |
3874 | } |
3647 | |
3875 | |
… | |
… | |
3693 | 1 |
3921 | 1 |
3694 | } |
3922 | } |
3695 | |
3923 | |
3696 | ############################################################################# |
3924 | ############################################################################# |
3697 | |
3925 | |
3698 | package CFPlus::UI::Multiplexer; |
3926 | package DC::UI::Multiplexer; |
3699 | |
3927 | |
3700 | our @ISA = CFPlus::UI::Container::; |
3928 | our @ISA = DC::UI::Container::; |
3701 | |
3929 | |
3702 | sub new { |
3930 | sub new { |
3703 | my $class = shift; |
3931 | my $class = shift; |
3704 | |
3932 | |
3705 | my $self = $class->SUPER::new ( |
3933 | my $self = $class->SUPER::new ( |
… | |
… | |
3766 | $self->{current}->draw; |
3994 | $self->{current}->draw; |
3767 | } |
3995 | } |
3768 | |
3996 | |
3769 | ############################################################################# |
3997 | ############################################################################# |
3770 | |
3998 | |
3771 | package CFPlus::UI::Notebook; |
3999 | package DC::UI::Notebook; |
3772 | |
4000 | |
|
|
4001 | use DC::OpenGL; |
|
|
4002 | |
3773 | our @ISA = CFPlus::UI::VBox::; |
4003 | our @ISA = DC::UI::VBox::; |
3774 | |
4004 | |
3775 | sub new { |
4005 | sub new { |
3776 | my $class = shift; |
4006 | my $class = shift; |
3777 | |
4007 | |
3778 | my $self = $class->SUPER::new ( |
4008 | my $self = $class->SUPER::new ( |
3779 | buttonbar => (new CFPlus::UI::Buttonbar), |
4009 | buttonbar => (new DC::UI::Buttonbar), |
3780 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
4010 | multiplexer => (new DC::UI::Multiplexer expand => 1), |
|
|
4011 | active_outline => [.7, .7, 0.2], |
3781 | # filter => # will be put between multiplexer and $self |
4012 | # filter => # will be put between multiplexer and $self |
3782 | @_, |
4013 | @_, |
3783 | ); |
4014 | ); |
3784 | |
4015 | |
3785 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
4016 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3786 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
4017 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3787 | |
4018 | |
|
|
4019 | { |
|
|
4020 | Scalar::Util::weaken (my $wself = $self); |
|
|
4021 | |
|
|
4022 | $self->{multiplexer}->connect (c_add => sub { |
|
|
4023 | my ($mplex, $widgets) = @_; |
|
|
4024 | |
|
|
4025 | for my $child (@$widgets) { |
|
|
4026 | Scalar::Util::weaken $child; |
|
|
4027 | $child->{c_tab_} ||= do { |
|
|
4028 | my $tab = |
|
|
4029 | (UNIVERSAL::isa $child->{c_tab}, "DC::UI::Base") |
|
|
4030 | ? $child->{c_tab} |
|
|
4031 | : new DC::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; |
|
|
4032 | |
|
|
4033 | $tab->connect (activate => sub { |
|
|
4034 | $wself->set_current_page ($child); |
|
|
4035 | }); |
|
|
4036 | |
|
|
4037 | $tab |
|
|
4038 | }; |
|
|
4039 | |
|
|
4040 | $self->{buttonbar}->add ($child->{c_tab_}); |
|
|
4041 | } |
|
|
4042 | }); |
|
|
4043 | |
|
|
4044 | $self->{multiplexer}->connect (c_remove => sub { |
|
|
4045 | my ($mplex, $widgets) = @_; |
|
|
4046 | |
|
|
4047 | for my $child (@$widgets) { |
|
|
4048 | $wself->{buttonbar}->remove ($child->{c_tab_}); |
|
|
4049 | } |
|
|
4050 | }); |
|
|
4051 | } |
|
|
4052 | |
3788 | $self |
4053 | $self |
3789 | } |
4054 | } |
3790 | |
4055 | |
3791 | sub add { |
4056 | sub add { |
|
|
4057 | my ($self, @widgets) = @_; |
|
|
4058 | |
|
|
4059 | $self->{multiplexer}->add (@widgets) |
|
|
4060 | } |
|
|
4061 | |
|
|
4062 | sub remove { |
|
|
4063 | my ($self, @widgets) = @_; |
|
|
4064 | |
|
|
4065 | $self->{multiplexer}->remove (@widgets) |
|
|
4066 | } |
|
|
4067 | |
|
|
4068 | sub pages { |
|
|
4069 | my ($self) = @_; |
|
|
4070 | $self->{multiplexer}->children |
|
|
4071 | } |
|
|
4072 | |
|
|
4073 | sub page_index { |
|
|
4074 | my ($self, $widget) = @_; |
|
|
4075 | |
|
|
4076 | my $i = 0; |
|
|
4077 | for ($self->pages) { |
|
|
4078 | if ($_ eq $widget) { return $i }; |
|
|
4079 | $i++; |
|
|
4080 | } |
|
|
4081 | |
|
|
4082 | undef |
|
|
4083 | } |
|
|
4084 | |
|
|
4085 | sub add_tab { |
3792 | my ($self, $title, $widget, $tooltip) = @_; |
4086 | my ($self, $title, $widget, $tooltip) = @_; |
3793 | |
4087 | |
3794 | CFPlus::weaken $self; |
4088 | $title = [$title, $tooltip] unless ref $title; |
|
|
4089 | $widget->{c_tab} = $title; |
3795 | |
4090 | |
3796 | $self->{buttonbar}->add (new CFPlus::UI::Button |
|
|
3797 | markup => $title, |
|
|
3798 | tooltip => $tooltip, |
|
|
3799 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3800 | ); |
|
|
3801 | |
|
|
3802 | $self->{multiplexer}->add ($widget); |
4091 | $self->add ($widget); |
3803 | } |
4092 | } |
3804 | |
4093 | |
3805 | sub get_current_page { |
4094 | sub get_current_page { |
3806 | my ($self) = @_; |
4095 | my ($self) = @_; |
3807 | |
4096 | |
… | |
… | |
3813 | |
4102 | |
3814 | $self->{multiplexer}->set_current_page ($page); |
4103 | $self->{multiplexer}->set_current_page ($page); |
3815 | $self->emit (page_changed => $self->{multiplexer}{current}); |
4104 | $self->emit (page_changed => $self->{multiplexer}{current}); |
3816 | } |
4105 | } |
3817 | |
4106 | |
|
|
4107 | sub _draw { |
|
|
4108 | my ($self) = @_; |
|
|
4109 | |
|
|
4110 | $self->SUPER::_draw (); |
|
|
4111 | |
|
|
4112 | if (my $cur = $self->{multiplexer}{current}) { |
|
|
4113 | if ($cur = $cur->{c_tab_}) { |
|
|
4114 | glTranslate $self->{buttonbar}{x} + $cur->{x}, |
|
|
4115 | $self->{buttonbar}{y} + $cur->{y}; |
|
|
4116 | glLineWidth 3; |
|
|
4117 | #glEnable GL_BLEND; |
|
|
4118 | #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
4119 | glColor @{$self->{active_outline}}; |
|
|
4120 | glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5; |
|
|
4121 | glLineWidth 1; |
|
|
4122 | #glDisable GL_BLEND; |
|
|
4123 | } |
|
|
4124 | } |
|
|
4125 | } |
|
|
4126 | |
3818 | ############################################################################# |
4127 | ############################################################################# |
3819 | |
4128 | |
3820 | package CFPlus::UI::Selector; |
4129 | package DC::UI::Selector; |
3821 | |
4130 | |
3822 | use utf8; |
4131 | use utf8; |
3823 | |
4132 | |
3824 | our @ISA = CFPlus::UI::Button::; |
4133 | our @ISA = DC::UI::Button::; |
3825 | |
4134 | |
3826 | sub new { |
4135 | sub new { |
3827 | my $class = shift; |
4136 | my $class = shift; |
3828 | |
4137 | |
3829 | my $self = $class->SUPER::new ( |
4138 | my $self = $class->SUPER::new ( |
… | |
… | |
3846 | my ($value, $title, $tooltip) = @$_; |
4155 | my ($value, $title, $tooltip) = @$_; |
3847 | |
4156 | |
3848 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
4157 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
3849 | } |
4158 | } |
3850 | |
4159 | |
3851 | CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); |
4160 | DC::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3852 | } |
4161 | } |
3853 | |
4162 | |
3854 | sub _set_value { |
4163 | sub _set_value { |
3855 | my ($self, $value) = @_; |
4164 | my ($self, $value) = @_; |
3856 | |
4165 | |
3857 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
4166 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} }; |
|
|
4167 | $item ||= $self->{options}[0] |
3858 | or return; |
4168 | or return; |
3859 | |
4169 | |
3860 | $self->{value} = $item->[0]; |
4170 | $self->{value} = $item->[0]; |
3861 | $self->set_markup ("$item->[1] ⇓"); |
4171 | $self->set_markup ("$item->[1] ⇓"); |
3862 | $self->set_tooltip ($item->[2]); |
4172 | # $self->set_tooltip ($item->[2]); |
3863 | } |
4173 | } |
3864 | |
4174 | |
3865 | sub set_value { |
4175 | sub set_value { |
3866 | my ($self, $value) = @_; |
4176 | my ($self, $value) = @_; |
3867 | |
4177 | |
… | |
… | |
3869 | |
4179 | |
3870 | $self->_set_value ($value); |
4180 | $self->_set_value ($value); |
3871 | $self->emit (changed => $value); |
4181 | $self->emit (changed => $value); |
3872 | } |
4182 | } |
3873 | |
4183 | |
|
|
4184 | sub set_options { |
|
|
4185 | my ($self, $options) = @_; |
|
|
4186 | |
|
|
4187 | $self->{options} = $options; |
|
|
4188 | $self->_set_value ($self->{value}); |
|
|
4189 | } |
|
|
4190 | |
3874 | ############################################################################# |
4191 | ############################################################################# |
3875 | |
4192 | |
3876 | package CFPlus::UI::Statusbox; |
4193 | package DC::UI::Statusbox; |
3877 | |
4194 | |
3878 | our @ISA = CFPlus::UI::VBox::; |
4195 | our @ISA = DC::UI::VBox::; |
3879 | |
4196 | |
3880 | sub new { |
4197 | sub new { |
3881 | my $class = shift; |
4198 | my $class = shift; |
3882 | |
4199 | |
3883 | my $self = $class->SUPER::new ( |
4200 | my $self = $class->SUPER::new ( |
3884 | fontsize => 0.8, |
4201 | fontsize => 0.8, |
3885 | @_, |
4202 | @_, |
3886 | ); |
4203 | ); |
3887 | |
4204 | |
3888 | CFPlus::weaken (my $this = $self); |
4205 | DC::weaken (my $this = $self); |
3889 | |
4206 | |
3890 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
4207 | $self->{timer} = EV::timer 1, 1, sub { $this->reorder }; |
3891 | |
4208 | |
3892 | $self |
4209 | $self |
3893 | } |
4210 | } |
3894 | |
4211 | |
3895 | sub reorder { |
4212 | sub reorder { |
3896 | my ($self) = @_; |
4213 | my ($self) = @_; |
3897 | my $NOW = Time::HiRes::time; |
4214 | my $NOW = Time::HiRes::time; |
3898 | |
4215 | |
3899 | # freeze display when hovering over any label |
4216 | # freeze display when hovering over any label |
3900 | return if $CFPlus::UI::TOOLTIP->{owner} |
4217 | return if $DC::UI::TOOLTIP->{owner} |
3901 | && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label}, |
4218 | && grep $DC::UI::TOOLTIP->{owner} == $_->{label}, |
3902 | values %{ $self->{item} }; |
4219 | values %{ $self->{item} }; |
3903 | |
4220 | |
3904 | while (my ($k, $v) = each %{ $self->{item} }) { |
4221 | while (my ($k, $v) = each %{ $self->{item} }) { |
3905 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
4222 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
3906 | } |
4223 | } |
|
|
4224 | |
|
|
4225 | $self->{timer}->set (1, 1); |
3907 | |
4226 | |
3908 | my @widgets; |
4227 | my @widgets; |
3909 | |
4228 | |
3910 | my @items = sort { |
4229 | my @items = sort { |
3911 | $a->{pri} <=> $b->{pri} |
4230 | $a->{pri} <=> $b->{pri} |
3912 | or $b->{id} <=> $a->{id} |
4231 | or $b->{id} <=> $a->{id} |
3913 | } values %{ $self->{item} }; |
4232 | } values %{ $self->{item} }; |
3914 | |
|
|
3915 | $self->{timer}->interval (1); |
|
|
3916 | |
4233 | |
3917 | my $count = 10 + 1; |
4234 | my $count = 10 + 1; |
3918 | for my $item (@items) { |
4235 | for my $item (@items) { |
3919 | last unless --$count; |
4236 | last unless --$count; |
3920 | |
4237 | |
… | |
… | |
3927 | for ($short) { |
4244 | for ($short) { |
3928 | s/^\s+//; |
4245 | s/^\s+//; |
3929 | s/\s+/ /g; |
4246 | s/\s+/ /g; |
3930 | } |
4247 | } |
3931 | |
4248 | |
3932 | new CFPlus::UI::Label |
4249 | new DC::UI::Label |
3933 | markup => $short, |
4250 | markup => $short, |
3934 | tooltip => $item->{tooltip}, |
4251 | tooltip => $item->{tooltip}, |
3935 | tooltip_font => $::FONT_PROP, |
4252 | tooltip_font => $::FONT_PROP, |
3936 | tooltip_width => 0.67, |
4253 | tooltip_width => 0.67, |
3937 | fontsize => $item->{fontsize} || $self->{fontsize}, |
4254 | fontsize => $item->{fontsize} || $self->{fontsize}, |
3938 | max_w => $::WIDTH * 0.44, |
4255 | max_w => $::WIDTH * 0.44, |
|
|
4256 | align => 0, |
3939 | fg => [@{ $item->{fg} }], |
4257 | fg => [@{ $item->{fg} }], |
3940 | can_events => 1, |
4258 | can_events => 1, |
3941 | can_hover => 1 |
4259 | can_hover => 1 |
3942 | }; |
4260 | }; |
3943 | |
4261 | |
3944 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
4262 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
3945 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
4263 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
3946 | $label->update; |
4264 | $label->update; |
3947 | $label->set_max_size (undef, $label->{req_h} * $diff) |
4265 | $label->set_max_size (undef, $label->{req_h} * $diff) |
3948 | if $diff < 1; |
4266 | if $diff < 1; |
3949 | $self->{timer}->interval (1/30); |
4267 | $self->{timer}->set (1/30, 1/30); |
3950 | } else { |
4268 | } else { |
3951 | $label->{fg}[3] = $item->{fg}[3] || 1; |
4269 | $label->{fg}[3] = $item->{fg}[3] || 1; |
3952 | } |
4270 | } |
3953 | |
4271 | |
3954 | push @widgets, $label; |
4272 | push @widgets, $label; |
… | |
… | |
4016 | $self->SUPER::destroy; |
4334 | $self->SUPER::destroy; |
4017 | } |
4335 | } |
4018 | |
4336 | |
4019 | ############################################################################# |
4337 | ############################################################################# |
4020 | |
4338 | |
4021 | package CFPlus::UI::Root; |
4339 | package DC::UI::Root; |
4022 | |
4340 | |
4023 | our @ISA = CFPlus::UI::Container::; |
4341 | our @ISA = DC::UI::Container::; |
4024 | |
4342 | |
4025 | use List::Util qw(min max); |
4343 | use List::Util qw(min max); |
4026 | |
4344 | |
4027 | use CFPlus::OpenGL; |
4345 | use DC::OpenGL; |
4028 | |
4346 | |
4029 | sub new { |
4347 | sub new { |
4030 | my $class = shift; |
4348 | my $class = shift; |
4031 | |
4349 | |
4032 | my $self = $class->SUPER::new ( |
4350 | my $self = $class->SUPER::new ( |
4033 | visible => 1, |
4351 | visible => 1, |
4034 | @_, |
4352 | @_, |
4035 | ); |
4353 | ); |
4036 | |
4354 | |
4037 | CFPlus::weaken ($self->{root} = $self); |
4355 | DC::weaken ($self->{root} = $self); |
4038 | |
4356 | |
4039 | $self |
4357 | $self |
4040 | } |
4358 | } |
4041 | |
4359 | |
4042 | sub size_request { |
4360 | sub size_request { |
… | |
… | |
4090 | } |
4408 | } |
4091 | |
4409 | |
4092 | sub update { |
4410 | sub update { |
4093 | my ($self) = @_; |
4411 | my ($self) = @_; |
4094 | |
4412 | |
4095 | $::WANT_REFRESH++; |
4413 | $::WANT_REFRESH = 1; |
4096 | } |
4414 | } |
4097 | |
4415 | |
4098 | sub add { |
4416 | sub add { |
4099 | my ($self, @children) = @_; |
4417 | my ($self, @children) = @_; |
4100 | |
4418 | |
… | |
… | |
4137 | while ($self->{refresh_hook}) { |
4455 | while ($self->{refresh_hook}) { |
4138 | $_->() |
4456 | $_->() |
4139 | for values %{delete $self->{refresh_hook}}; |
4457 | for values %{delete $self->{refresh_hook}}; |
4140 | } |
4458 | } |
4141 | |
4459 | |
4142 | if ($self->{realloc}) { |
4460 | while ($self->{realloc}) { |
4143 | my %queue; |
4461 | my %queue; |
4144 | my @queue; |
4462 | my @queue; |
4145 | my $widget; |
4463 | my $widget; |
4146 | |
4464 | |
4147 | outer: |
4465 | outer: |
… | |
… | |
4167 | |
4485 | |
4168 | delete $queue{$widget+0}; |
4486 | delete $queue{$widget+0}; |
4169 | |
4487 | |
4170 | my ($w, $h) = $widget->size_request; |
4488 | my ($w, $h) = $widget->size_request; |
4171 | |
4489 | |
4172 | $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
4490 | $w += $widget->{padding_x} * 2; |
4173 | $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
4491 | $h += $widget->{padding_y} * 2; |
|
|
4492 | |
|
|
4493 | $w = max $widget->{min_w}, $w; |
|
|
4494 | $h = max $widget->{min_h}, $h; |
4174 | |
4495 | |
4175 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4496 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4176 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4497 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4177 | |
4498 | |
4178 | $w = $widget->{force_w} if exists $widget->{force_w}; |
4499 | $w = $widget->{force_w} if exists $widget->{force_w}; |
… | |
… | |
4194 | } |
4515 | } |
4195 | } |
4516 | } |
4196 | |
4517 | |
4197 | delete $self->{realloc}{$widget+0}; |
4518 | delete $self->{realloc}{$widget+0}; |
4198 | } |
4519 | } |
4199 | } |
|
|
4200 | |
4520 | |
4201 | while (my $size_alloc = delete $self->{size_alloc}) { |
4521 | while (my $size_alloc = delete $self->{size_alloc}) { |
4202 | my @queue = sort { $b->{visible} <=> $a->{visible} } |
4522 | my @queue = sort { $a->{visible} <=> $b->{visible} } |
4203 | values %$size_alloc; |
4523 | values %$size_alloc; |
4204 | |
4524 | |
4205 | while () { |
4525 | while () { |
4206 | my $widget = pop @queue || last; |
4526 | my $widget = pop @queue || last; |
4207 | |
4527 | |
4208 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4528 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4209 | |
4529 | |
4210 | $w = 0 if $w < 0; |
|
|
4211 | $h = 0 if $h < 0; |
|
|
4212 | |
|
|
4213 | $w = max $widget->{min_w}, $w; |
4530 | $w = max $widget->{min_w}, $w; |
4214 | $h = max $widget->{min_h}, $h; |
4531 | $h = max $widget->{min_h}, $h; |
4215 | |
4532 | |
4216 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4533 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4217 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4534 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4218 | |
4535 | |
4219 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4536 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4220 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4537 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4221 | |
4538 | |
4222 | $w = int $w + 0.5; |
4539 | $w = int $w + 0.5; |
4223 | $h = int $h + 0.5; |
4540 | $h = int $h + 0.5; |
4224 | |
4541 | |
4225 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4542 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4226 | $widget->{old_w} = $widget->{w}; |
4543 | $widget->{old_w} = $widget->{w}; |
4227 | $widget->{old_h} = $widget->{h}; |
4544 | $widget->{old_h} = $widget->{h}; |
4228 | |
4545 | |
4229 | $widget->{w} = $w; |
4546 | $widget->{w} = $w; |
4230 | $widget->{h} = $h; |
4547 | $widget->{h} = $h; |
4231 | |
4548 | |
4232 | $widget->emit (size_allocate => $w, $h); |
4549 | $widget->emit (size_allocate => $w, $h); |
|
|
4550 | } |
4233 | } |
4551 | } |
4234 | } |
4552 | } |
4235 | } |
4553 | } |
4236 | |
4554 | |
4237 | while ($self->{post_alloc_hook}) { |
4555 | while ($self->{post_alloc_hook}) { |
… | |
… | |
4248 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
4566 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
4249 | glMatrixMode GL_MODELVIEW; |
4567 | glMatrixMode GL_MODELVIEW; |
4250 | glLoadIdentity; |
4568 | glLoadIdentity; |
4251 | |
4569 | |
4252 | { |
4570 | { |
4253 | package CFPlus::UI::Base; |
4571 | package DC::UI::Base; |
4254 | |
4572 | |
4255 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
4573 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
4256 | (0, 0, $self->{w}, $self->{h}); |
4574 | (0, 0, $self->{w}, $self->{h}); |
4257 | |
4575 | |
4258 | $self->_draw; |
4576 | $self->_draw; |
4259 | } |
4577 | } |
4260 | } |
4578 | } |
4261 | |
4579 | |
4262 | ############################################################################# |
4580 | ############################################################################# |
4263 | |
4581 | |
4264 | package CFPlus::UI; |
4582 | package DC::UI; |
4265 | |
4583 | |
4266 | $ROOT = new CFPlus::UI::Root; |
4584 | $ROOT = new DC::UI::Root; |
4267 | $TOOLTIP = new CFPlus::UI::Tooltip z => 900; |
4585 | $TOOLTIP = new DC::UI::Tooltip z => 900; |
4268 | |
4586 | |
4269 | 1 |
4587 | 1 |
4270 | |
4588 | |