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 Scalar::Util (); |
|
|
7 | use List::Util (); |
6 | use List::Util (); |
8 | use Event; |
|
|
9 | |
7 | |
10 | use CFPlus; |
8 | use DC; |
11 | use CFPlus::Pod; |
9 | use DC::Pod; |
12 | use CFPlus::Texture; |
10 | use DC::Texture; |
13 | |
11 | |
14 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
15 | |
13 | |
16 | our $LAYOUT; |
14 | our $LAYOUT; |
17 | our $ROOT; |
15 | our $ROOT; |
18 | our $TOOLTIP; |
16 | our $TOOLTIP; |
19 | our $BUTTON_STATE; |
17 | our $BUTTON_STATE; |
20 | |
18 | |
21 | our %WIDGET; # all widgets, weak-referenced |
19 | our %WIDGET; # all widgets, weak-referenced |
22 | |
20 | |
23 | 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 | |
24 | if (!$GRAB) { |
24 | if (!$GRAB) { |
25 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
25 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
26 | if (length $widget->{tooltip}) { |
26 | if (length $widget->{tooltip}) { |
27 | if ($TOOLTIP->{owner} != $widget) { |
27 | if ($TOOLTIP->{owner} != $widget) { |
|
|
28 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
28 | $TOOLTIP->hide; |
29 | $TOOLTIP->hide; |
29 | |
30 | |
30 | $TOOLTIP->{owner} = $widget; |
31 | $TOOLTIP->{owner} = $widget; |
|
|
32 | $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner}; |
31 | |
33 | |
32 | return if $ENV{CFPLUS_DEBUG} & 8; |
34 | return if $ENV{CFPLUS_DEBUG} & 8; |
33 | |
35 | |
34 | my $tip = $widget->{tooltip}; |
|
|
35 | |
|
|
36 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
|
|
37 | |
|
|
38 | $TOOLTIP->set_tooltip_from ($widget); |
36 | $TOOLTIP->set_tooltip_from ($widget); |
39 | $TOOLTIP->show; |
37 | $TOOLTIP->show; |
40 | } |
38 | } |
41 | |
39 | |
42 | return; |
40 | return; |
43 | } |
41 | } |
44 | } |
42 | } |
45 | } |
43 | } |
46 | |
44 | |
47 | $TOOLTIP->hide; |
45 | $TOOLTIP->hide; |
|
|
46 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
48 | delete $TOOLTIP->{owner}; |
47 | delete $TOOLTIP->{owner}; |
49 | }); |
48 | }; |
50 | |
49 | |
51 | sub get_layout { |
50 | sub get_layout { |
52 | my $layout; |
51 | my $layout; |
53 | |
52 | |
54 | for (grep { $_->{name} } values %WIDGET) { |
53 | for (grep { $_->{name} } values %WIDGET) { |
… | |
… | |
89 | my $hover = $HOVER; $HOVER = $widget; |
88 | my $hover = $HOVER; $HOVER = $widget; |
90 | |
89 | |
91 | $hover->update if $hover && $hover->{can_hover}; |
90 | $hover->update if $hover && $hover->{can_hover}; |
92 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
91 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
93 | |
92 | |
94 | $TOOLTIP_WATCHER->start; |
93 | $TOOLTIP_WATCHER->again; |
95 | } |
94 | } |
96 | } |
95 | } |
97 | |
96 | |
98 | sub feed_sdl_button_down_event { |
97 | sub feed_sdl_button_down_event { |
99 | my ($ev) = @_; |
98 | my ($ev) = @_; |
… | |
… | |
105 | my $widget = $ROOT->find_widget ($x, $y); |
104 | my $widget = $ROOT->find_widget ($x, $y); |
106 | |
105 | |
107 | $GRAB = $widget; |
106 | $GRAB = $widget; |
108 | $GRAB->update if $GRAB; |
107 | $GRAB->update if $GRAB; |
109 | |
108 | |
110 | $TOOLTIP_WATCHER->cb->(); |
109 | $TOOLTIP_WATCHER->invoke; |
111 | } |
110 | } |
112 | |
111 | |
113 | if ($GRAB) { |
112 | if ($GRAB) { |
114 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
113 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
115 | # mousewheel |
114 | # mousewheel |
116 | $ev->{dx} = 0; |
|
|
117 | $ev->{dy} = $ev->{button} * 2 - 9; |
115 | my $delta = $ev->{button} * 2 - 9; |
|
|
116 | my $shift = $ev->{mod} & DC::KMOD_SHIFT; |
|
|
117 | |
|
|
118 | $ev->{dx} = $shift ? $delta : 0; |
|
|
119 | $ev->{dy} = $shift ? 0 : $delta; |
|
|
120 | |
118 | $GRAB->emit (mouse_wheel => $ev); |
121 | $GRAB->emit (mouse_wheel => $ev); |
119 | } else { |
122 | } else { |
120 | $GRAB->emit (button_down => $ev) |
123 | $GRAB->emit (button_down => $ev) |
121 | } |
124 | } |
122 | } |
125 | } |
… | |
… | |
136 | my $grab = $GRAB; undef $GRAB; |
139 | my $grab = $GRAB; undef $GRAB; |
137 | $grab->update if $grab; |
140 | $grab->update if $grab; |
138 | $GRAB->update if $GRAB; |
141 | $GRAB->update if $GRAB; |
139 | |
142 | |
140 | check_hover $widget; |
143 | check_hover $widget; |
141 | $TOOLTIP_WATCHER->cb->(); |
144 | $TOOLTIP_WATCHER->invoke; |
142 | } |
145 | } |
143 | } |
146 | } |
144 | |
147 | |
145 | sub feed_sdl_motion_event { |
148 | sub feed_sdl_motion_event { |
146 | my ($ev) = @_; |
149 | my ($ev) = @_; |
… | |
… | |
208 | reconfigure_widgets; |
211 | reconfigure_widgets; |
209 | } |
212 | } |
210 | |
213 | |
211 | ############################################################################# |
214 | ############################################################################# |
212 | |
215 | |
213 | package CFPlus::UI::Event; |
216 | package DC::UI::Event; |
214 | |
217 | |
215 | sub xy { |
218 | sub xy { |
216 | $_[1]->coord2local ($_[0]{x}, $_[0]{y}) |
219 | $_[1]->coord2local ($_[0]{x}, $_[0]{y}) |
217 | } |
220 | } |
218 | |
221 | |
219 | ############################################################################# |
222 | ############################################################################# |
220 | |
223 | |
221 | package CFPlus::UI::Base; |
224 | package DC::UI::Base; |
222 | |
225 | |
223 | use strict; |
226 | use strict; |
224 | |
227 | |
225 | use CFPlus::OpenGL; |
228 | use DC::OpenGL; |
226 | |
229 | |
227 | sub new { |
230 | sub new { |
228 | my $class = shift; |
231 | my $class = shift; |
229 | |
232 | |
230 | my $self = bless { |
233 | my $self = bless { |
… | |
… | |
235 | h => undef, |
238 | h => undef, |
236 | can_events => 1, |
239 | can_events => 1, |
237 | @_ |
240 | @_ |
238 | }, $class; |
241 | }, $class; |
239 | |
242 | |
240 | Scalar::Util::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); |
243 | DC::weaken ($DC::UI::WIDGET{$self+0} = $self); |
241 | |
244 | |
242 | for (keys %$self) { |
245 | for (keys %$self) { |
243 | if (/^on_(.*)$/) { |
246 | if (/^on_(.*)$/) { |
244 | $self->connect ($1 => delete $self->{$_}); |
247 | $self->connect ($1 => delete $self->{$_}); |
245 | } |
248 | } |
246 | } |
249 | } |
247 | |
250 | |
248 | if (my $layout = $CFPlus::UI::LAYOUT->{$self->{name}}) { |
251 | if (my $layout = $DC::UI::LAYOUT->{$self->{name}}) { |
249 | $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}; |
250 | $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}; |
251 | $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}; |
252 | $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}; |
253 | |
256 | |
254 | $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; |
257 | $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; |
255 | $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; |
258 | $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; |
256 | |
259 | |
257 | $self->show if $layout->{show}; |
260 | $self->show if $layout->{show}; |
… | |
… | |
262 | |
265 | |
263 | sub destroy { |
266 | sub destroy { |
264 | my ($self) = @_; |
267 | my ($self) = @_; |
265 | |
268 | |
266 | $self->hide; |
269 | $self->hide; |
|
|
270 | $self->emit ("destroy"); |
267 | %$self = (); |
271 | %$self = (); |
268 | } |
272 | } |
269 | |
273 | |
|
|
274 | sub TO_JSON { |
|
|
275 | { "\fw" => $_[0]{s_id} } |
|
|
276 | } |
|
|
277 | |
270 | sub show { |
278 | sub show { |
271 | my ($self) = @_; |
279 | my ($self) = @_; |
272 | |
280 | |
273 | return if $self->{parent}; |
281 | return if $self->{parent}; |
274 | |
282 | |
275 | $CFPlus::UI::ROOT->add ($self); |
283 | $DC::UI::ROOT->add ($self); |
276 | } |
284 | } |
277 | |
285 | |
278 | sub set_visible { |
286 | sub set_visible { |
279 | my ($self) = @_; |
287 | my ($self) = @_; |
280 | |
288 | |
… | |
… | |
301 | delete $self->{root}; |
309 | delete $self->{root}; |
302 | |
310 | |
303 | undef $GRAB if $GRAB == $self; |
311 | undef $GRAB if $GRAB == $self; |
304 | undef $HOVER if $HOVER == $self; |
312 | undef $HOVER if $HOVER == $self; |
305 | |
313 | |
306 | $CFPlus::UI::TOOLTIP_WATCHER->cb->() |
314 | $DC::UI::TOOLTIP_WATCHER->invoke |
307 | if $TOOLTIP->{owner} == $self; |
315 | if $TOOLTIP->{owner} == $self; |
308 | |
316 | |
309 | $self->emit ("focus_out"); |
317 | $self->emit ("focus_out"); |
310 | $self->emit (visibility_change => 0); |
318 | $self->emit (visibility_change => 0); |
311 | } |
319 | } |
… | |
… | |
313 | sub set_visibility { |
321 | sub set_visibility { |
314 | my ($self, $visible) = @_; |
322 | my ($self, $visible) = @_; |
315 | |
323 | |
316 | return if $self->{visible} == $visible; |
324 | return if $self->{visible} == $visible; |
317 | |
325 | |
318 | $visible ? $self->hide |
326 | $visible ? $self->show |
319 | : $self->show; |
327 | : $self->hide; |
320 | } |
328 | } |
321 | |
329 | |
322 | sub toggle_visibility { |
330 | sub toggle_visibility { |
323 | my ($self) = @_; |
331 | my ($self) = @_; |
324 | |
332 | |
… | |
… | |
330 | sub hide { |
338 | sub hide { |
331 | my ($self) = @_; |
339 | my ($self) = @_; |
332 | |
340 | |
333 | $self->set_invisible; |
341 | $self->set_invisible; |
334 | |
342 | |
|
|
343 | # extra $parent copy for 5.8.8+ bug workaround |
|
|
344 | # (otherwise $_[0] in remove gets freed |
|
|
345 | if (my $parent = $self->{parent}) { |
335 | $self->{parent}->remove ($self) |
346 | $parent->remove ($self); |
336 | if $self->{parent}; |
347 | } |
337 | } |
348 | } |
338 | |
349 | |
339 | sub move_abs { |
350 | sub move_abs { |
340 | my ($self, $x, $y, $z) = @_; |
351 | my ($self, $x, $y, $z) = @_; |
341 | |
352 | |
… | |
… | |
353 | $self->{force_h} = $h; |
364 | $self->{force_h} = $h; |
354 | |
365 | |
355 | $self->realloc; |
366 | $self->realloc; |
356 | } |
367 | } |
357 | |
368 | |
|
|
369 | # traverse the widget chain up to find the maximum "physical" size constraints |
|
|
370 | sub get_max_wh { |
|
|
371 | my ($self) = @_; |
|
|
372 | |
|
|
373 | return $self->{parent}->get_max_wh |
|
|
374 | if $self->{parent}; |
|
|
375 | |
|
|
376 | ($::WIDTH, $::HEIGHT) |
|
|
377 | } |
|
|
378 | |
358 | sub size_request { |
379 | sub size_request { |
359 | require Carp; |
380 | require Carp; |
360 | Carp::confess "size_request is abstract"; |
381 | Carp::confess "size_request is abstract"; |
361 | } |
382 | } |
362 | |
383 | |
… | |
… | |
368 | my ($self, $x, $y, $w, $h) = @_; |
389 | my ($self, $x, $y, $w, $h) = @_; |
369 | |
390 | |
370 | if ($self->{aspect}) { |
391 | if ($self->{aspect}) { |
371 | my ($ow, $oh) = ($w, $h); |
392 | my ($ow, $oh) = ($w, $h); |
372 | |
393 | |
373 | $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect}; |
394 | $w = List::Util::min $w, DC::ceil $h * $self->{aspect}; |
374 | $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect}; |
395 | $h = List::Util::min $h, DC::ceil $w / $self->{aspect}; |
375 | |
396 | |
376 | # use alignment to adjust x, y |
397 | # use alignment to adjust x, y |
377 | |
398 | |
378 | $x += int 0.5 * ($ow - $w); |
399 | $x += int 0.5 * ($ow - $w); |
379 | $y += int 0.5 * ($oh - $h); |
400 | $y += int 0.5 * ($oh - $h); |
… | |
… | |
420 | |
441 | |
421 | return if $self->{tooltip} eq $tooltip; |
442 | return if $self->{tooltip} eq $tooltip; |
422 | |
443 | |
423 | $self->{tooltip} = $tooltip; |
444 | $self->{tooltip} = $tooltip; |
424 | |
445 | |
425 | if ($CFPlus::UI::TOOLTIP->{owner} == $self) { |
446 | if ($DC::UI::TOOLTIP->{owner} == $self) { |
426 | delete $CFPlus::UI::TOOLTIP->{owner}; |
447 | delete $DC::UI::TOOLTIP->{owner}; |
427 | $CFPlus::UI::TOOLTIP_WATCHER->cb->(); |
448 | $DC::UI::TOOLTIP_WATCHER->invoke; |
428 | } |
449 | } |
429 | } |
450 | } |
430 | |
451 | |
431 | # translate global coordinates to local coordinate system |
452 | # translate global coordinates to local coordinate system |
432 | sub coord2local { |
453 | sub coord2local { |
433 | my ($self, $x, $y) = @_; |
454 | my ($self, $x, $y) = @_; |
434 | |
455 | |
435 | Carp::confess unless $self->{parent};#d# |
456 | return (undef, undef) unless $self->{parent}; |
436 | |
457 | |
437 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
458 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
438 | } |
459 | } |
439 | |
460 | |
440 | # translate local coordinates to global coordinate system |
461 | # translate local coordinates to global coordinate system |
441 | sub coord2global { |
462 | sub coord2global { |
442 | my ($self, $x, $y) = @_; |
463 | my ($self, $x, $y) = @_; |
443 | |
464 | |
444 | Carp::confess unless $self->{parent};#d# |
465 | return (undef, undef) unless $self->{parent}; |
445 | |
466 | |
446 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
467 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
447 | } |
468 | } |
448 | |
469 | |
449 | sub invoke_focus_in { |
470 | sub invoke_focus_in { |
… | |
… | |
498 | sub connect { |
519 | sub connect { |
499 | my ($self, $signal, $cb) = @_; |
520 | my ($self, $signal, $cb) = @_; |
500 | |
521 | |
501 | push @{ $self->{signal_cb}{$signal} }, $cb; |
522 | push @{ $self->{signal_cb}{$signal} }, $cb; |
502 | |
523 | |
503 | defined wantarray and CFPlus::guard { |
524 | defined wantarray and DC::guard { |
504 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
525 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
505 | @{ $self->{signal_cb}{$signal} }; |
526 | @{ $self->{signal_cb}{$signal} }; |
506 | } |
527 | } |
|
|
528 | } |
|
|
529 | |
|
|
530 | sub disconnect_all { |
|
|
531 | my ($self, $signal) = @_; |
|
|
532 | |
|
|
533 | delete $self->{signal_cb}{$signal}; |
507 | } |
534 | } |
508 | |
535 | |
509 | my %has_coords = ( |
536 | my %has_coords = ( |
510 | button_down => 1, |
537 | button_down => 1, |
511 | button_up => 1, |
538 | button_up => 1, |
… | |
… | |
514 | ); |
541 | ); |
515 | |
542 | |
516 | sub emit { |
543 | sub emit { |
517 | my ($self, $signal, @args) = @_; |
544 | my ($self, $signal, @args) = @_; |
518 | |
545 | |
519 | # I do not really like this solution, but I dislike duplication |
546 | # I do not really like this solution, but I do not like duplication |
520 | # and needlessly verbose code, too. |
547 | # and needlessly verbose code, either. |
521 | my @append |
548 | my @append |
522 | = $has_coords{$signal} |
549 | = $has_coords{$signal} |
523 | ? $args[0]->xy ($self) |
550 | ? $args[0]->xy ($self) |
524 | : (); |
551 | : (); |
525 | |
552 | |
526 | #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# |
553 | #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# |
527 | |
554 | |
528 | #d##TODO# stop propagating at first true, do not use sum |
555 | for my $cb ( |
529 | (List::Util::sum map $_->($self, @args, @append), @{$self->{signal_cb}{$signal} || []}) # before |
556 | @{$self->{signal_cb}{$signal} || []}, # before |
530 | || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args, @append) # closure |
557 | ($self->can ("invoke_$signal") || sub { 1 }), # closure |
|
|
558 | ) { |
|
|
559 | return $cb->($self, @args, @append) || next; |
|
|
560 | } |
|
|
561 | |
|
|
562 | # parent |
531 | || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent |
563 | $self->{parent} && $self->{parent}->emit ($signal, @args) |
532 | } |
564 | } |
533 | |
565 | |
534 | sub find_widget { |
566 | #sub find_widget { |
535 | my ($self, $x, $y) = @_; |
567 | # in .xs |
536 | |
|
|
537 | return () unless $self->{can_events}; |
|
|
538 | |
|
|
539 | return $self |
|
|
540 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
541 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
|
|
542 | |
|
|
543 | () |
|
|
544 | } |
|
|
545 | |
568 | |
546 | sub set_parent { |
569 | sub set_parent { |
547 | my ($self, $parent) = @_; |
570 | my ($self, $parent) = @_; |
548 | |
571 | |
549 | Scalar::Util::weaken ($self->{parent} = $parent); |
572 | DC::weaken ($self->{parent} = $parent); |
550 | $self->set_visible if $parent->{visible}; |
573 | $self->set_visible if $parent->{visible}; |
551 | } |
574 | } |
552 | |
575 | |
553 | sub realloc { |
576 | sub realloc { |
554 | my ($self) = @_; |
577 | my ($self) = @_; |
… | |
… | |
580 | |
603 | |
581 | # using global variables seems a bit hacky, but passing through all drawing |
604 | # using global variables seems a bit hacky, but passing through all drawing |
582 | # functions seems pointless. |
605 | # functions seems pointless. |
583 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
606 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
584 | |
607 | |
585 | sub draw { |
608 | #sub draw { |
586 | my ($self) = @_; |
609 | #CFPlus.xs |
587 | |
|
|
588 | return unless $self->{h} && $self->{w}; |
|
|
589 | |
|
|
590 | # update screen rectangle |
|
|
591 | local $draw_x = $draw_x + $self->{x}; |
|
|
592 | local $draw_y = $draw_y + $self->{y}; |
|
|
593 | |
|
|
594 | # skip widgets that are entirely outside the drawing area |
|
|
595 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
|
|
596 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
|
|
597 | |
|
|
598 | glPushMatrix; |
|
|
599 | glTranslate $self->{x}, $self->{y}, 0; |
|
|
600 | |
|
|
601 | if ($self == $HOVER && $self->{can_hover}) { |
|
|
602 | glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2; |
|
|
603 | glEnable GL_BLEND; |
|
|
604 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
605 | glBegin GL_QUADS; |
|
|
606 | glVertex 0 , 0; |
|
|
607 | glVertex $self->{w}, 0; |
|
|
608 | glVertex $self->{w}, $self->{h}; |
|
|
609 | glVertex 0 , $self->{h}; |
|
|
610 | glEnd; |
|
|
611 | glDisable GL_BLEND; |
|
|
612 | } |
|
|
613 | |
|
|
614 | if ($ENV{CFPLUS_DEBUG} & 1) { |
|
|
615 | glPushMatrix; |
|
|
616 | glColor 1, 1, 0, 1; |
|
|
617 | glTranslate 0.375, 0.375; |
|
|
618 | glBegin GL_LINE_LOOP; |
|
|
619 | glVertex 0 , 0; |
|
|
620 | glVertex $self->{w} - 1, 0; |
|
|
621 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
622 | glVertex 0 , $self->{h} - 1; |
|
|
623 | glEnd; |
|
|
624 | glPopMatrix; |
|
|
625 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
626 | } |
|
|
627 | |
|
|
628 | $self->_draw; |
|
|
629 | glPopMatrix; |
|
|
630 | } |
|
|
631 | |
610 | |
632 | sub _draw { |
611 | sub _draw { |
633 | my ($self) = @_; |
612 | my ($self) = @_; |
634 | |
613 | |
635 | warn "no draw defined for $self\n"; |
614 | warn "no draw defined for $self\n"; |
636 | } |
615 | } |
637 | |
616 | |
638 | sub DESTROY { |
617 | sub DESTROY { |
639 | my ($self) = @_; |
618 | my ($self) = @_; |
640 | |
619 | |
641 | return if CFPlus::in_destruct; |
620 | return if DC::in_destruct; |
642 | |
621 | |
643 | delete $WIDGET{$self+0}; |
622 | local $@; |
644 | |
|
|
645 | eval { $self->destroy }; |
623 | eval { $self->destroy }; |
646 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
624 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
|
|
625 | |
|
|
626 | delete $WIDGET{$self+0}; |
647 | } |
627 | } |
648 | |
628 | |
649 | ############################################################################# |
629 | ############################################################################# |
650 | |
630 | |
651 | package CFPlus::UI::DrawBG; |
631 | package DC::UI::DrawBG; |
652 | |
632 | |
653 | our @ISA = CFPlus::UI::Base::; |
633 | our @ISA = DC::UI::Base::; |
654 | |
634 | |
655 | use strict; |
635 | use strict; |
656 | use CFPlus::OpenGL; |
636 | use DC::OpenGL; |
657 | |
637 | |
658 | sub new { |
638 | sub new { |
659 | my $class = shift; |
639 | my $class = shift; |
660 | |
|
|
661 | # range [value, low, high, page] |
|
|
662 | |
640 | |
663 | $class->SUPER::new ( |
641 | $class->SUPER::new ( |
664 | #bg => [0, 0, 0, 0.2], |
642 | #bg => [0, 0, 0, 0.2], |
665 | #active_bg => [1, 1, 1, 0.5], |
643 | #active_bg => [1, 1, 1, 0.5], |
666 | @_ |
644 | @_ |
… | |
… | |
678 | my ($w, $h) = @$self{qw(w h)}; |
656 | my ($w, $h) = @$self{qw(w h)}; |
679 | |
657 | |
680 | glEnable GL_BLEND; |
658 | glEnable GL_BLEND; |
681 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
659 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
682 | glColor_premultiply @$color; |
660 | glColor_premultiply @$color; |
683 | |
|
|
684 | glBegin GL_QUADS; |
|
|
685 | glVertex 0 , 0; |
|
|
686 | glVertex 0 , $h; |
|
|
687 | glVertex $w, $h; |
661 | glRect 0, 0, $w, $h; |
688 | glVertex $w, 0; |
|
|
689 | glEnd; |
|
|
690 | |
|
|
691 | glDisable GL_BLEND; |
662 | glDisable GL_BLEND; |
692 | } |
663 | } |
693 | } |
664 | } |
694 | |
665 | |
695 | ############################################################################# |
666 | ############################################################################# |
696 | |
667 | |
697 | package CFPlus::UI::Empty; |
668 | package DC::UI::Empty; |
698 | |
669 | |
699 | our @ISA = CFPlus::UI::Base::; |
670 | our @ISA = DC::UI::Base::; |
700 | |
671 | |
701 | sub new { |
672 | sub new { |
702 | my ($class, %arg) = @_; |
673 | my ($class, %arg) = @_; |
703 | $class->SUPER::new (can_events => 0, %arg); |
674 | $class->SUPER::new (can_events => 0, %arg); |
704 | } |
675 | } |
… | |
… | |
711 | |
682 | |
712 | sub draw { } |
683 | sub draw { } |
713 | |
684 | |
714 | ############################################################################# |
685 | ############################################################################# |
715 | |
686 | |
716 | package CFPlus::UI::Container; |
687 | package DC::UI::Container; |
717 | |
688 | |
718 | our @ISA = CFPlus::UI::Base::; |
689 | our @ISA = DC::UI::Base::; |
719 | |
690 | |
720 | sub new { |
691 | sub new { |
721 | my ($class, %arg) = @_; |
692 | my ($class, %arg) = @_; |
722 | |
693 | |
723 | my $children = delete $arg{children}; |
694 | my $children = delete $arg{children}; |
… | |
… | |
727 | can_events => 0, |
698 | can_events => 0, |
728 | %arg, |
699 | %arg, |
729 | ); |
700 | ); |
730 | |
701 | |
731 | $self->add (@$children) |
702 | $self->add (@$children) |
732 | if $children; |
703 | if $children && @$children; |
733 | |
704 | |
734 | $self |
705 | $self |
735 | } |
706 | } |
736 | |
707 | |
737 | sub realloc { |
708 | sub realloc { |
… | |
… | |
746 | my ($self, @widgets) = @_; |
717 | my ($self, @widgets) = @_; |
747 | |
718 | |
748 | $_->set_parent ($self) |
719 | $_->set_parent ($self) |
749 | for @widgets; |
720 | for @widgets; |
750 | |
721 | |
|
|
722 | # TODO: only do this in widgets that need it, e.g. root, fixed |
751 | use sort 'stable'; |
723 | use sort 'stable'; |
752 | |
724 | |
753 | $self->{children} = [ |
725 | $self->{children} = [ |
754 | sort { $a->{z} <=> $b->{z} } |
726 | sort { $a->{z} <=> $b->{z} } |
755 | @{$self->{children}}, @widgets |
727 | @{$self->{children}}, @widgets |
756 | ]; |
728 | ]; |
757 | |
729 | |
758 | $self->realloc; |
730 | $self->realloc; |
|
|
731 | |
|
|
732 | $self->emit (c_add => \@widgets); |
|
|
733 | |
|
|
734 | map $_+0, @widgets |
759 | } |
735 | } |
760 | |
736 | |
761 | sub children { |
737 | sub children { |
762 | @{ $_[0]{children} } |
738 | @{ $_[0]{children} } |
763 | } |
739 | } |
764 | |
740 | |
765 | sub remove { |
741 | sub remove { |
766 | my ($self, $child) = @_; |
742 | my ($self, @widgets) = @_; |
767 | |
743 | |
|
|
744 | $self->emit (c_remove => \@widgets); |
|
|
745 | |
|
|
746 | for my $child (@widgets) { |
768 | delete $child->{parent}; |
747 | delete $child->{parent}; |
769 | $child->hide; |
748 | $child->hide; |
770 | |
|
|
771 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
749 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
|
|
750 | } |
772 | |
751 | |
773 | $self->realloc; |
752 | $self->realloc; |
774 | } |
753 | } |
775 | |
754 | |
776 | sub clear { |
755 | sub clear { |
777 | my ($self) = @_; |
756 | my ($self) = @_; |
778 | |
757 | |
779 | my $children = delete $self->{children}; |
758 | my $children = $self->{children}; |
780 | $self->{children} = []; |
759 | $self->{children} = []; |
781 | |
760 | |
782 | for (@$children) { |
761 | for (@$children) { |
783 | delete $_->{parent}; |
762 | delete $_->{parent}; |
784 | $_->hide; |
763 | $_->hide; |
… | |
… | |
804 | } |
783 | } |
805 | |
784 | |
806 | sub _draw { |
785 | sub _draw { |
807 | my ($self) = @_; |
786 | my ($self) = @_; |
808 | |
787 | |
809 | $_->draw for @{$self->{children}}; |
788 | $_->draw for $self->visible_children; |
810 | } |
789 | } |
811 | |
790 | |
812 | ############################################################################# |
791 | ############################################################################# |
813 | |
792 | |
814 | package CFPlus::UI::Bin; |
793 | package DC::UI::Bin; |
815 | |
794 | |
816 | our @ISA = CFPlus::UI::Container::; |
795 | our @ISA = DC::UI::Container::; |
817 | |
796 | |
818 | sub new { |
797 | sub new { |
819 | my ($class, %arg) = @_; |
798 | my ($class, %arg) = @_; |
820 | |
799 | |
821 | my $child = (delete $arg{child}) || new CFPlus::UI::Empty::; |
800 | my $child = (delete $arg{child}) || new DC::UI::Empty::; |
822 | |
801 | |
823 | $class->SUPER::new (children => [$child], %arg) |
802 | $class->SUPER::new (children => [$child], %arg) |
824 | } |
803 | } |
825 | |
804 | |
826 | sub add { |
805 | sub add { |
827 | my ($self, $child) = @_; |
806 | my ($self, $child) = @_; |
828 | |
807 | |
829 | $self->SUPER::remove ($_) for @{ $self->{children} }; |
808 | $self->clear; |
830 | $self->SUPER::add ($child); |
809 | $self->SUPER::add ($child); |
831 | } |
810 | } |
832 | |
811 | |
833 | sub remove { |
812 | sub remove { |
834 | my ($self, $widget) = @_; |
813 | my ($self, $widget) = @_; |
835 | |
814 | |
836 | $self->SUPER::remove ($widget); |
815 | $self->SUPER::remove ($widget); |
837 | |
816 | |
838 | $self->{children} = [new CFPlus::UI::Empty] |
817 | $self->{children} = [new DC::UI::Empty] |
839 | unless @{$self->{children}}; |
818 | unless @{$self->{children}}; |
840 | } |
819 | } |
841 | |
820 | |
842 | sub child { $_[0]->{children}[0] } |
821 | sub child { $_[0]->{children}[0] } |
843 | |
822 | |
… | |
… | |
852 | |
831 | |
853 | 1 |
832 | 1 |
854 | } |
833 | } |
855 | |
834 | |
856 | ############################################################################# |
835 | ############################################################################# |
857 | |
|
|
858 | # back-buffered drawing area |
836 | # back-buffered drawing area |
859 | |
837 | |
860 | package CFPlus::UI::Window; |
838 | package DC::UI::Window; |
861 | |
839 | |
862 | our @ISA = CFPlus::UI::Bin::; |
840 | our @ISA = DC::UI::Bin::; |
863 | |
841 | |
864 | use CFPlus::OpenGL; |
842 | use DC::OpenGL; |
865 | |
843 | |
866 | sub new { |
844 | sub new { |
867 | my ($class, %arg) = @_; |
845 | my ($class, %arg) = @_; |
868 | |
846 | |
869 | my $self = $class->SUPER::new (%arg); |
847 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
891 | } |
869 | } |
892 | |
870 | |
893 | sub render_child { |
871 | sub render_child { |
894 | my ($self) = @_; |
872 | my ($self) = @_; |
895 | |
873 | |
896 | $self->{texture} = new_from_opengl CFPlus::Texture $self->{w}, $self->{h}, sub { |
874 | $self->{texture} = new_from_opengl DC::Texture $self->{w}, $self->{h}, sub { |
897 | glClearColor 0, 0, 0, 0; |
875 | glClearColor 0, 0, 0, 0; |
898 | glClear GL_COLOR_BUFFER_BIT; |
876 | glClear GL_COLOR_BUFFER_BIT; |
899 | |
877 | |
900 | { |
878 | { |
901 | package CFPlus::UI::Base; |
879 | package DC::UI::Base; |
902 | |
880 | |
903 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
881 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
904 | (0, 0, $self->{w}, $self->{h}); |
882 | (0, 0, $self->{w}, $self->{h}); |
|
|
883 | |
|
|
884 | $self->_render; |
905 | } |
885 | } |
906 | |
|
|
907 | $self->_render; |
|
|
908 | }; |
886 | }; |
909 | } |
887 | } |
910 | |
888 | |
911 | sub _draw { |
889 | sub _draw { |
912 | my ($self) = @_; |
890 | my ($self) = @_; |
… | |
… | |
923 | glDisable GL_TEXTURE_2D; |
901 | glDisable GL_TEXTURE_2D; |
924 | } |
902 | } |
925 | |
903 | |
926 | ############################################################################# |
904 | ############################################################################# |
927 | |
905 | |
928 | package CFPlus::UI::ViewPort; |
906 | package DC::UI::ViewPort; |
929 | |
907 | |
|
|
908 | use List::Util qw(min max); |
|
|
909 | |
930 | our @ISA = CFPlus::UI::Window::; |
910 | our @ISA = DC::UI::Window::; |
931 | |
911 | |
932 | sub new { |
912 | sub new { |
933 | my $class = shift; |
913 | my $class = shift; |
934 | |
914 | |
935 | $class->SUPER::new ( |
915 | $class->SUPER::new ( |
… | |
… | |
942 | sub size_request { |
922 | sub size_request { |
943 | my ($self) = @_; |
923 | my ($self) = @_; |
944 | |
924 | |
945 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
925 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
946 | |
926 | |
947 | $w = 10 if $self->{scroll_x}; |
927 | $w = 1 if $self->{scroll_x}; |
948 | $h = 10 if $self->{scroll_y}; |
928 | $h = 1 if $self->{scroll_y}; |
949 | |
929 | |
950 | ($w, $h) |
930 | ($w, $h) |
951 | } |
931 | } |
952 | |
932 | |
953 | sub invoke_size_allocate { |
933 | sub invoke_size_allocate { |
… | |
… | |
965 | } |
945 | } |
966 | |
946 | |
967 | sub set_offset { |
947 | sub set_offset { |
968 | my ($self, $x, $y) = @_; |
948 | my ($self, $x, $y) = @_; |
969 | |
949 | |
|
|
950 | my $x = max 0, min $self->child->{w} - $self->{w}, int $x; |
|
|
951 | my $y = max 0, min $self->child->{h} - $self->{h}, int $y; |
|
|
952 | |
|
|
953 | if ($x != $self->{view_x} or $y != $self->{view_y}) { |
970 | $self->{view_x} = int $x; |
954 | $self->{view_x} = $x; |
971 | $self->{view_y} = int $y; |
955 | $self->{view_y} = $y; |
972 | |
956 | |
|
|
957 | $self->emit (changed => $x, $y); |
973 | $self->update; |
958 | $self->update; |
|
|
959 | } |
|
|
960 | } |
|
|
961 | |
|
|
962 | sub set_center { |
|
|
963 | my ($self, $x, $y) = @_; |
|
|
964 | |
|
|
965 | $self->set_offset ($x - $self->{w} * .5, $y - $self->{h} * .5); |
|
|
966 | } |
|
|
967 | |
|
|
968 | sub make_visible { |
|
|
969 | my ($self, $x, $y, $border) = @_; |
|
|
970 | |
|
|
971 | if ( $x < $self->{view_x} + $self->{w} * $border |
|
|
972 | || $x > $self->{view_x} + $self->{w} * (1 - $border) |
|
|
973 | || $y < $self->{view_y} + $self->{h} * $border |
|
|
974 | || $y > $self->{view_y} + $self->{h} * (1 - $border) |
|
|
975 | ) { |
|
|
976 | $self->set_center ($x, $y); |
|
|
977 | } |
974 | } |
978 | } |
975 | |
979 | |
976 | # hmm, this does not work for topleft of $self... but we should not ask for that |
980 | # hmm, this does not work for topleft of $self... but we should not ask for that |
977 | sub coord2local { |
981 | sub coord2local { |
978 | my ($self, $x, $y) = @_; |
982 | my ($self, $x, $y) = @_; |
… | |
… | |
993 | my ($self, $x, $y) = @_; |
997 | my ($self, $x, $y) = @_; |
994 | |
998 | |
995 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
999 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
996 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
1000 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
997 | ) { |
1001 | ) { |
998 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
1002 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
999 | } else { |
1003 | } else { |
1000 | $self->CFPlus::UI::Base::find_widget ($x, $y) |
1004 | $self->DC::UI::Base::find_widget ($x, $y) |
1001 | } |
1005 | } |
1002 | } |
1006 | } |
1003 | |
1007 | |
1004 | sub _render { |
1008 | sub _render { |
1005 | my ($self) = @_; |
1009 | my ($self) = @_; |
1006 | |
1010 | |
1007 | local $CFPlus::UI::Base::draw_x = $CFPlus::UI::Base::draw_x - $self->{view_x}; |
1011 | local $DC::UI::Base::draw_x = $DC::UI::Base::draw_x - $self->{view_x}; |
1008 | local $CFPlus::UI::Base::draw_y = $CFPlus::UI::Base::draw_y - $self->{view_y}; |
1012 | local $DC::UI::Base::draw_y = $DC::UI::Base::draw_y - $self->{view_y}; |
1009 | |
1013 | |
1010 | CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
1014 | DC::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
1011 | |
1015 | |
1012 | $self->SUPER::_render; |
1016 | $self->SUPER::_render; |
1013 | } |
1017 | } |
1014 | |
1018 | |
1015 | ############################################################################# |
1019 | ############################################################################# |
1016 | |
1020 | |
1017 | package CFPlus::UI::ScrolledWindow; |
1021 | package DC::UI::ScrolledWindow; |
1018 | |
1022 | |
1019 | our @ISA = CFPlus::UI::HBox::; |
1023 | our @ISA = DC::UI::Table::; |
1020 | |
1024 | |
1021 | sub new { |
1025 | sub new { |
1022 | my ($class, %arg) = @_; |
1026 | my ($class, %arg) = @_; |
1023 | |
1027 | |
1024 | my $child = delete $arg{child}; |
1028 | my $child = delete $arg{child}; |
1025 | |
1029 | |
1026 | my $self; |
1030 | my $self; |
1027 | |
1031 | |
1028 | my $slider = new CFPlus::UI::Slider |
1032 | my $hslider = new DC::UI::Slider |
|
|
1033 | c_col => 0, |
|
|
1034 | c_row => 1, |
|
|
1035 | vertical => 0, |
|
|
1036 | range => [0, 0, 1, 0.01], # HACK fix |
|
|
1037 | on_changed => sub { |
|
|
1038 | $self->{hpos} = $_[1]; |
|
|
1039 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
|
|
1040 | }, |
|
|
1041 | ; |
|
|
1042 | |
|
|
1043 | my $vslider = new DC::UI::Slider |
|
|
1044 | c_col => 1, |
|
|
1045 | c_row => 0, |
1029 | vertical => 1, |
1046 | vertical => 1, |
1030 | range => [0, 0, 1, 0.01], # HACK fix |
1047 | range => [0, 0, 1, 0.01], # HACK fix |
1031 | on_changed => sub { |
1048 | on_changed => sub { |
1032 | $self->{vp}->set_offset (0, $_[1]); |
1049 | $self->{vpos} = $_[1]; |
|
|
1050 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1033 | }, |
1051 | }, |
1034 | ; |
1052 | ; |
1035 | |
1053 | |
1036 | $self = $class->SUPER::new ( |
1054 | $self = $class->SUPER::new ( |
1037 | vp => (new CFPlus::UI::ViewPort expand => 1), |
1055 | scroll_x => 0, |
|
|
1056 | scroll_y => 1, |
1038 | can_events => 1, |
1057 | can_events => 1, |
1039 | slider => $slider, |
1058 | hslider => $hslider, |
|
|
1059 | vslider => $vslider, |
|
|
1060 | col_expand => [1, 0], |
|
|
1061 | row_expand => [1, 0], |
1040 | %arg, |
1062 | %arg, |
1041 | ); |
1063 | ); |
1042 | |
1064 | |
|
|
1065 | $self->{vp} = new DC::UI::ViewPort |
|
|
1066 | c_col => 0, |
|
|
1067 | c_row => 0, |
|
|
1068 | expand => 1, |
|
|
1069 | scroll_x => $self->{scroll_x}, |
|
|
1070 | scroll_y => $self->{scroll_y}, |
|
|
1071 | on_changed => sub { |
|
|
1072 | my ($vp, $x, $y) = @_; |
|
|
1073 | |
|
|
1074 | $vp->{parent}{hslider}->set_value ($x); |
|
|
1075 | $vp->{parent}{vslider}->set_value ($y); |
|
|
1076 | |
|
|
1077 | 0 |
|
|
1078 | }, |
|
|
1079 | on_size_allocate => sub { |
|
|
1080 | my ($vp, $w, $h) = @_; |
|
|
1081 | $vp->{parent}->update_slider; |
|
|
1082 | 0 |
|
|
1083 | }, |
|
|
1084 | ; |
|
|
1085 | |
1043 | $self->SUPER::add ($self->{vp}, $self->{slider}); |
1086 | $self->SUPER::add ($self->{vp}); |
|
|
1087 | |
1044 | $self->add ($child) if $child; |
1088 | $self->add ($child) if $child; |
1045 | |
1089 | |
1046 | $self |
1090 | $self |
1047 | } |
1091 | } |
1048 | |
|
|
1049 | #TODO# update range on size_allocate depending on child |
|
|
1050 | |
1092 | |
1051 | sub add { |
1093 | sub add { |
1052 | my ($self, $widget) = @_; |
1094 | my ($self, $widget) = @_; |
1053 | |
1095 | |
1054 | $self->{vp}->add ($self->{child} = $widget); |
1096 | $self->{vp}->add ($self->{child} = $widget); |
1055 | } |
1097 | } |
1056 | |
1098 | |
|
|
1099 | sub set_offset { shift->{vp}->set_offset (@_) } |
|
|
1100 | sub set_center { shift->{vp}->set_center (@_) } |
|
|
1101 | sub make_visible { shift->{vp}->make_visible (@_) } |
|
|
1102 | |
|
|
1103 | sub update_slider { |
|
|
1104 | my ($self) = @_; |
|
|
1105 | |
|
|
1106 | my $child = ($self->{vp} or return)->child; |
|
|
1107 | |
|
|
1108 | if ($self->{scroll_x}) { |
|
|
1109 | my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w}); |
|
|
1110 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
|
|
1111 | |
|
|
1112 | my $visible = $w1 > $w2; |
|
|
1113 | if ($visible != $self->{hslider_visible}) { |
|
|
1114 | $self->{hslider_visible} = $visible; |
|
|
1115 | $visible ? $self->SUPER::add ($self->{hslider}) |
|
|
1116 | : $self->SUPER::remove ($self->{hslider}); |
|
|
1117 | } |
|
|
1118 | } |
|
|
1119 | |
|
|
1120 | if ($self->{scroll_y}) { |
|
|
1121 | my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h}); |
|
|
1122 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
|
|
1123 | |
|
|
1124 | my $visible = $h1 > $h2; |
|
|
1125 | if ($visible != $self->{vslider_visible}) { |
|
|
1126 | $self->{vslider_visible} = $visible; |
|
|
1127 | $visible ? $self->SUPER::add ($self->{vslider}) |
|
|
1128 | : $self->SUPER::remove ($self->{vslider}); |
|
|
1129 | } |
|
|
1130 | } |
|
|
1131 | } |
|
|
1132 | |
|
|
1133 | sub start_dragging { |
|
|
1134 | my ($self, $ev) = @_; |
|
|
1135 | |
|
|
1136 | $self->grab_focus; |
|
|
1137 | |
|
|
1138 | my $ox = $self->{vp}{view_x}; |
|
|
1139 | my $oy = $self->{vp}{view_y}; |
|
|
1140 | |
|
|
1141 | $self->{motion} = sub { |
|
|
1142 | my ($ev, $x, $y) = @_; |
|
|
1143 | |
|
|
1144 | $ox -= $ev->{xrel}; |
|
|
1145 | $oy -= $ev->{yrel}; |
|
|
1146 | |
|
|
1147 | $self->{vp}->set_offset ($ox, $oy); |
|
|
1148 | }; |
|
|
1149 | } |
|
|
1150 | |
1057 | sub invoke_mouse_wheel { |
1151 | sub invoke_mouse_wheel { |
1058 | my ($self, $ev) = @_; |
1152 | my ($self, $ev) = @_; |
1059 | |
1153 | |
1060 | return 0 unless $ev->{dy}; # only vertical movements |
|
|
1061 | |
|
|
1062 | $self->{slider}->emit (mouse_wheel => $ev); |
1154 | $self->{vslider}->emit (mouse_wheel => $ev) if $self->{vslider_visible}; |
|
|
1155 | $self->{hslider}->emit (mouse_wheel => $ev) if $self->{hslider_visible}; |
1063 | |
1156 | |
1064 | 1 |
1157 | 1 |
1065 | } |
1158 | } |
1066 | |
1159 | |
1067 | sub update_slider { |
1160 | sub invoke_button_down { |
1068 | my ($self) = @_; |
1161 | my ($self, $ev, $x, $y) = @_; |
1069 | |
1162 | |
1070 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); |
1163 | if ($ev->{button} == 2) { |
1071 | } |
1164 | $self->start_dragging ($ev); |
|
|
1165 | return 1; |
|
|
1166 | } |
1072 | |
1167 | |
1073 | sub update { |
1168 | 0 |
1074 | my ($self) = @_; |
1169 | } |
1075 | |
1170 | |
1076 | $self->SUPER::update; |
1171 | sub invoke_button_up { |
|
|
1172 | my ($self, $ev, $x, $y) = @_; |
1077 | |
1173 | |
1078 | $self->update_slider; |
1174 | if (delete $self->{motion}) { |
|
|
1175 | return 1; |
|
|
1176 | } |
|
|
1177 | |
|
|
1178 | 0 |
|
|
1179 | } |
|
|
1180 | |
|
|
1181 | sub invoke_mouse_motion { |
|
|
1182 | my ($self, $ev, $x, $y) = @_; |
|
|
1183 | |
|
|
1184 | if ($self->{motion}) { |
|
|
1185 | $self->{motion}->($ev, $x, $y); |
|
|
1186 | return 1; |
|
|
1187 | } |
|
|
1188 | |
|
|
1189 | 0 |
1079 | } |
1190 | } |
1080 | |
1191 | |
1081 | sub invoke_size_allocate { |
1192 | sub invoke_size_allocate { |
1082 | my ($self, $w, $h) = @_; |
1193 | my ($self, $w, $h) = @_; |
1083 | |
1194 | |
1084 | $self->update_slider; |
1195 | $self->update_slider; |
1085 | |
|
|
1086 | $self->SUPER::invoke_size_allocate ($w, $h) |
1196 | $self->SUPER::invoke_size_allocate ($w, $h) |
1087 | } |
1197 | } |
1088 | |
1198 | |
1089 | ############################################################################# |
1199 | ############################################################################# |
1090 | |
1200 | |
1091 | package CFPlus::UI::Frame; |
1201 | package DC::UI::Frame; |
1092 | |
1202 | |
1093 | our @ISA = CFPlus::UI::Bin::; |
1203 | our @ISA = DC::UI::Bin::; |
1094 | |
1204 | |
1095 | use CFPlus::OpenGL; |
1205 | use DC::OpenGL; |
1096 | |
1206 | |
1097 | sub new { |
1207 | sub new { |
1098 | my $class = shift; |
1208 | my $class = shift; |
1099 | |
1209 | |
1100 | $class->SUPER::new ( |
1210 | $class->SUPER::new ( |
… | |
… | |
1110 | my ($w, $h) = @$self{qw(w h)}; |
1220 | my ($w, $h) = @$self{qw(w h)}; |
1111 | |
1221 | |
1112 | glEnable GL_BLEND; |
1222 | glEnable GL_BLEND; |
1113 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1223 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1114 | glColor_premultiply @{ $self->{bg} }; |
1224 | glColor_premultiply @{ $self->{bg} }; |
1115 | |
|
|
1116 | glBegin GL_QUADS; |
|
|
1117 | glVertex 0 , 0; |
|
|
1118 | glVertex 0 , $h; |
|
|
1119 | glVertex $w, $h; |
1225 | glRect 0, 0, $w, $h; |
1120 | glVertex $w, 0; |
|
|
1121 | glEnd; |
|
|
1122 | |
|
|
1123 | glDisable GL_BLEND; |
1226 | glDisable GL_BLEND; |
1124 | } |
1227 | } |
1125 | |
1228 | |
1126 | $self->SUPER::_draw; |
1229 | $self->SUPER::_draw; |
1127 | } |
1230 | } |
1128 | |
1231 | |
1129 | ############################################################################# |
1232 | ############################################################################# |
1130 | |
1233 | |
1131 | package CFPlus::UI::FancyFrame; |
1234 | package DC::UI::FancyFrame; |
1132 | |
1235 | |
1133 | our @ISA = CFPlus::UI::Bin::; |
1236 | our @ISA = DC::UI::Bin::; |
1134 | |
1237 | |
1135 | use CFPlus::OpenGL; |
1238 | use DC::OpenGL; |
|
|
1239 | |
|
|
1240 | sub new { |
|
|
1241 | my ($class, %arg) = @_; |
|
|
1242 | |
|
|
1243 | if ((exists $arg{label}) && !ref $arg{label}) { |
|
|
1244 | $arg{label} = new DC::UI::Label |
|
|
1245 | align => 1, |
|
|
1246 | valign => 0, |
|
|
1247 | text => $arg{label}, |
|
|
1248 | fontsize => ($arg{border} || 0.8) * 0.75; |
|
|
1249 | } |
|
|
1250 | |
|
|
1251 | my $self = $class->SUPER::new ( |
|
|
1252 | # label => "", |
|
|
1253 | fg => [0.6, 0.3, 0.1], |
|
|
1254 | border => 0.8, |
|
|
1255 | style => 'single', |
|
|
1256 | %arg, |
|
|
1257 | ); |
|
|
1258 | |
|
|
1259 | $self |
|
|
1260 | } |
|
|
1261 | |
|
|
1262 | sub add { |
|
|
1263 | my ($self, @widgets) = @_; |
|
|
1264 | |
|
|
1265 | $self->SUPER::add (@widgets); |
|
|
1266 | $self->DC::UI::Container::add ($self->{label}) if $self->{label}; |
|
|
1267 | } |
|
|
1268 | |
|
|
1269 | sub border { |
|
|
1270 | int $_[0]{border} * $::FONTSIZE |
|
|
1271 | } |
|
|
1272 | |
|
|
1273 | sub size_request { |
|
|
1274 | my ($self) = @_; |
|
|
1275 | |
|
|
1276 | ($self->{label_w}, undef) = $self->{label}->size_request |
|
|
1277 | if $self->{label}; |
|
|
1278 | |
|
|
1279 | my ($w, $h) = $self->SUPER::size_request; |
|
|
1280 | |
|
|
1281 | ( |
|
|
1282 | $w + $self->border * 2, |
|
|
1283 | $h + $self->border * 2, |
|
|
1284 | ) |
|
|
1285 | } |
|
|
1286 | |
|
|
1287 | sub invoke_size_allocate { |
|
|
1288 | my ($self, $w, $h) = @_; |
|
|
1289 | |
|
|
1290 | my $border = $self->border; |
|
|
1291 | |
|
|
1292 | $w -= List::Util::max 0, $border * 2; |
|
|
1293 | $h -= List::Util::max 0, $border * 2; |
|
|
1294 | |
|
|
1295 | if (my $label = $self->{label}) { |
|
|
1296 | $label->{w} = List::Util::max 0, List::Util::min $self->{label_w}, $w - $border * 2; |
|
|
1297 | $label->{h} = List::Util::min $h, $border; |
|
|
1298 | $label->invoke_size_allocate ($label->{w}, $label->{h}); |
|
|
1299 | } |
|
|
1300 | |
|
|
1301 | $self->child->configure ($border, $border, $w, $h); |
|
|
1302 | |
|
|
1303 | 1 |
|
|
1304 | } |
|
|
1305 | |
|
|
1306 | sub _draw { |
|
|
1307 | my ($self) = @_; |
|
|
1308 | |
|
|
1309 | my $child = $self->{children}[0]; |
|
|
1310 | |
|
|
1311 | my $border = $self->border; |
|
|
1312 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1313 | |
|
|
1314 | $child->draw; |
|
|
1315 | |
|
|
1316 | glColor @{$self->{fg}}; |
|
|
1317 | glBegin GL_LINE_STRIP; |
|
|
1318 | glVertex $border * 1.5 , $border * 0.5 + 0.5; |
|
|
1319 | glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; |
|
|
1320 | glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
|
|
1321 | glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
|
|
1322 | glVertex $w - $border * 0.5 + 0.5, $border * 0.5 + 0.5; |
|
|
1323 | glVertex $self->{label} ? $border * 2 + $self->{label}{w} : $border * 1.5, $border * 0.5 + 0.5; |
|
|
1324 | glEnd; |
|
|
1325 | |
|
|
1326 | if ($self->{label}) { |
|
|
1327 | glTranslate $border * 2, 0; |
|
|
1328 | $self->{label}->_draw; |
|
|
1329 | } |
|
|
1330 | } |
|
|
1331 | |
|
|
1332 | ############################################################################# |
|
|
1333 | |
|
|
1334 | package DC::UI::Toplevel; |
|
|
1335 | |
|
|
1336 | our @ISA = DC::UI::Bin::; |
|
|
1337 | |
|
|
1338 | use DC::OpenGL; |
1136 | |
1339 | |
1137 | my $bg = |
1340 | my $bg = |
1138 | new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", |
1341 | new_from_file DC::Texture DC::find_rcfile "d1_bg.png", |
1139 | mipmap => 1, wrap => 1; |
1342 | mipmap => 1, wrap => 1; |
1140 | |
1343 | |
1141 | my @border = |
1344 | my @border = |
1142 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1345 | map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } |
1143 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1346 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
1347 | |
|
|
1348 | my @icon = |
|
|
1349 | map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } |
|
|
1350 | qw(x1_move.png x1_resize.png); |
1144 | |
1351 | |
1145 | sub new { |
1352 | sub new { |
1146 | my ($class, %arg) = @_; |
1353 | my ($class, %arg) = @_; |
1147 | |
1354 | |
1148 | my $self = $class->SUPER::new ( |
1355 | my $self = $class->SUPER::new ( |
… | |
… | |
1153 | min_w => 64, |
1360 | min_w => 64, |
1154 | min_h => 32, |
1361 | min_h => 32, |
1155 | %arg, |
1362 | %arg, |
1156 | ); |
1363 | ); |
1157 | |
1364 | |
1158 | $self->{title_widget} = new CFPlus::UI::Label |
1365 | $self->{title_widget} = new DC::UI::Label |
1159 | align => 0, |
1366 | align => 0, |
1160 | valign => 1, |
1367 | valign => 1, |
1161 | text => $self->{title}, |
1368 | text => $self->{title}, |
1162 | fontsize => $self->{border}, |
1369 | fontsize => $self->{border}, |
1163 | if exists $self->{title}; |
1370 | if exists $self->{title}; |
1164 | |
1371 | |
1165 | if ($self->{has_close_button}) { |
1372 | if ($self->{has_close_button}) { |
1166 | $self->{close_button} = |
1373 | $self->{close_button} = |
1167 | new CFPlus::UI::ImageButton |
1374 | new DC::UI::ImageButton |
1168 | path => 'x1_close.png', |
1375 | path => 'x1_close.png', |
1169 | on_activate => sub { $self->emit ("delete") }; |
1376 | on_activate => sub { $self->emit ("delete") }; |
1170 | |
1377 | |
1171 | $self->CFPlus::UI::Container::add ($self->{close_button}); |
1378 | $self->DC::UI::Container::add ($self->{close_button}); |
1172 | } |
1379 | } |
1173 | |
1380 | |
1174 | $self |
1381 | $self |
1175 | } |
1382 | } |
1176 | |
1383 | |
1177 | sub add { |
1384 | sub add { |
1178 | my ($self, @widgets) = @_; |
1385 | my ($self, @widgets) = @_; |
1179 | |
1386 | |
1180 | $self->SUPER::add (@widgets); |
1387 | $self->SUPER::add (@widgets); |
1181 | $self->CFPlus::UI::Container::add ($self->{close_button}) if $self->{close_button}; |
1388 | $self->DC::UI::Container::add ($self->{close_button}) if $self->{close_button}; |
1182 | $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1389 | $self->DC::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1183 | } |
1390 | } |
1184 | |
1391 | |
1185 | sub border { |
1392 | sub border { |
1186 | int $_[0]{border} * $::FONTSIZE |
1393 | int $_[0]{border} * $::FONTSIZE |
|
|
1394 | } |
|
|
1395 | |
|
|
1396 | sub get_max_wh { |
|
|
1397 | my ($self) = @_; |
|
|
1398 | |
|
|
1399 | return ($self->{w}, $self->{h}) |
|
|
1400 | if $self->{visible} && $self->{w}; |
|
|
1401 | |
|
|
1402 | $self->SUPER::get_max_wh |
1187 | } |
1403 | } |
1188 | |
1404 | |
1189 | sub size_request { |
1405 | sub size_request { |
1190 | my ($self) = @_; |
1406 | my ($self) = @_; |
1191 | |
1407 | |
… | |
… | |
1317 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1533 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1318 | |
1534 | |
1319 | my $border = $self->border; |
1535 | my $border = $self->border; |
1320 | |
1536 | |
1321 | glColor @{ $self->{border_bg} }; |
1537 | glColor @{ $self->{border_bg} }; |
1322 | $border[0]->draw_quad_alpha (0, 0, $w, $border); |
1538 | $border[0]->draw_quad_alpha ( 0, 0, $w, $border); |
1323 | $border[1]->draw_quad_alpha (0, $border, $border, $ch); |
1539 | $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); |
1324 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1540 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1325 | $border[3]->draw_quad_alpha (0, $h - $border, $w, $border); |
1541 | $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); |
|
|
1542 | |
|
|
1543 | # move |
|
|
1544 | my $w2 = ($w - $border) * .5; |
|
|
1545 | my $h2 = ($h - $border) * .5; |
|
|
1546 | $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); |
|
|
1547 | $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); |
|
|
1548 | $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); |
|
|
1549 | |
|
|
1550 | # resize |
|
|
1551 | $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); |
|
|
1552 | $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) |
|
|
1553 | unless $self->{has_close_button}; |
|
|
1554 | $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); |
|
|
1555 | $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); |
1326 | |
1556 | |
1327 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1557 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1328 | glColor @{ $self->{bg} }; |
1558 | glColor @{ $self->{bg} }; |
1329 | |
1559 | |
1330 | # TODO: repeat texture not scale |
1560 | # TODO: repeat texture not scale |
… | |
… | |
1349 | if $self->{close_button}; |
1579 | if $self->{close_button}; |
1350 | } |
1580 | } |
1351 | |
1581 | |
1352 | ############################################################################# |
1582 | ############################################################################# |
1353 | |
1583 | |
1354 | package CFPlus::UI::Table; |
1584 | package DC::UI::Table; |
1355 | |
1585 | |
1356 | our @ISA = CFPlus::UI::Base::; |
1586 | our @ISA = DC::UI::Container::; |
1357 | |
1587 | |
1358 | use List::Util qw(max sum); |
1588 | use List::Util qw(max sum); |
1359 | |
1589 | |
1360 | use CFPlus::OpenGL; |
1590 | use DC::OpenGL; |
1361 | |
1591 | |
1362 | sub new { |
1592 | sub new { |
1363 | my $class = shift; |
1593 | my $class = shift; |
1364 | |
1594 | |
1365 | $class->SUPER::new ( |
1595 | $class->SUPER::new ( |
1366 | col_expand => [], |
1596 | col_expand => [], |
|
|
1597 | row_expand => [], |
1367 | @_, |
1598 | @_, |
1368 | ) |
1599 | ) |
1369 | } |
1600 | } |
1370 | |
1601 | |
1371 | sub children { |
|
|
1372 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1373 | } |
|
|
1374 | |
|
|
1375 | sub add { |
1602 | sub add { |
|
|
1603 | my ($self, @widgets) = @_; |
|
|
1604 | |
|
|
1605 | for my $child (@widgets) { |
|
|
1606 | $child->{c_rowspan} ||= 1; |
|
|
1607 | $child->{c_colspan} ||= 1; |
|
|
1608 | } |
|
|
1609 | |
|
|
1610 | $self->SUPER::add (@widgets); |
|
|
1611 | } |
|
|
1612 | |
|
|
1613 | sub add_at { |
1376 | my ($self) = shift; |
1614 | my $self = shift; |
|
|
1615 | |
|
|
1616 | my @widgets; |
1377 | |
1617 | |
1378 | while (@_) { |
1618 | while (@_) { |
1379 | my ($x, $y, $child) = splice @_, 0, 3, (); |
1619 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1380 | $child->set_parent ($self); |
|
|
1381 | $self->{children}[$y][$x] = $child; |
|
|
1382 | } |
|
|
1383 | |
1620 | |
1384 | $self->{force_realloc} = 1; |
1621 | $child->{c_row} = $row; |
1385 | $self->{force_size_alloc} = 1; |
1622 | $child->{c_col} = $col; |
1386 | $self->realloc; |
|
|
1387 | } |
|
|
1388 | |
1623 | |
1389 | sub remove { |
1624 | push @widgets, $child; |
|
|
1625 | } |
|
|
1626 | |
|
|
1627 | $self->add (@widgets); |
|
|
1628 | } |
|
|
1629 | |
|
|
1630 | sub get_wh { |
1390 | my ($self, $child) = @_; |
1631 | my ($self) = @_; |
1391 | |
1632 | |
1392 | # TODO: not yet implemented |
1633 | my (@w, @h); |
1393 | } |
|
|
1394 | |
|
|
1395 | # TODO: move to container class maybe? send children a signal on removal? |
|
|
1396 | sub clear { |
|
|
1397 | my ($self) = @_; |
|
|
1398 | |
1634 | |
1399 | my @children = $self->children; |
1635 | my @children = $self->children; |
1400 | delete $self->{children}; |
1636 | |
|
|
1637 | # first pass, columns |
|
|
1638 | for my $widget (sort { $a->{c_colspan} <=> $b->{c_colspan} } @children) { |
|
|
1639 | my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; |
|
|
1640 | |
|
|
1641 | my $sw = sum @w[$c .. $c + $cs - 1]; |
|
|
1642 | |
|
|
1643 | if ($w > $sw) { |
|
|
1644 | $_ += ($w - $sw) / ($_ ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
|
|
1645 | } |
1401 | |
1646 | } |
1402 | for (@children) { |
|
|
1403 | delete $_->{parent}; |
|
|
1404 | $_->hide; |
|
|
1405 | } |
|
|
1406 | |
1647 | |
1407 | $self->realloc; |
1648 | # second pass, rows |
1408 | } |
1649 | for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { |
1409 | |
|
|
1410 | sub get_wh { |
|
|
1411 | my ($self) = @_; |
|
|
1412 | |
|
|
1413 | my (@w, @h); |
|
|
1414 | |
|
|
1415 | for my $y (0 .. $#{$self->{children}}) { |
|
|
1416 | my $row = $self->{children}[$y] |
|
|
1417 | or next; |
|
|
1418 | |
|
|
1419 | for my $x (0 .. $#$row) { |
|
|
1420 | my $widget = $row->[$x] |
|
|
1421 | or next; |
|
|
1422 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
1650 | my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; |
1423 | |
1651 | |
1424 | $w[$x] = max $w[$x], $w; |
1652 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1425 | $h[$y] = max $h[$y], $h; |
1653 | |
|
|
1654 | if ($h > $sh) { |
|
|
1655 | $_ += ($h - $sh) / ($_ ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1426 | } |
1656 | } |
1427 | } |
1657 | } |
1428 | |
1658 | |
1429 | (\@w, \@h) |
1659 | (\@w, \@h) |
1430 | } |
1660 | } |
… | |
… | |
1446 | my ($ws, $hs) = $self->get_wh; |
1676 | my ($ws, $hs) = $self->get_wh; |
1447 | |
1677 | |
1448 | my $req_w = (sum @$ws) || 1; |
1678 | my $req_w = (sum @$ws) || 1; |
1449 | my $req_h = (sum @$hs) || 1; |
1679 | my $req_h = (sum @$hs) || 1; |
1450 | |
1680 | |
1451 | # TODO: nicer code && do row_expand |
1681 | # now linearly scale the rows/columns to the allocated size |
1452 | my @col_expand = @{$self->{col_expand}}; |
1682 | my @col_expand = @{$self->{col_expand}}; |
1453 | @col_expand = (1) x @$ws unless @col_expand; |
1683 | @col_expand = (1) x @$ws unless @col_expand; |
1454 | my $col_expand = (sum @col_expand) || 1; |
1684 | my $col_expand = (sum @col_expand) || 1; |
1455 | |
1685 | |
1456 | # linearly scale sizes |
|
|
1457 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1686 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1458 | $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; |
|
|
1459 | |
1687 | |
1460 | CFPlus::UI::harmonize $ws; |
1688 | DC::UI::harmonize $ws; |
|
|
1689 | |
|
|
1690 | my @row_expand = @{$self->{row_expand}}; |
|
|
1691 | @row_expand = (1) x @$ws unless @row_expand; |
|
|
1692 | my $row_expand = (sum @row_expand) || 1; |
|
|
1693 | |
|
|
1694 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
|
|
1695 | |
1461 | CFPlus::UI::harmonize $hs; |
1696 | DC::UI::harmonize $hs; |
1462 | |
1697 | |
1463 | my $y; |
1698 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
|
|
1699 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1464 | |
1700 | |
1465 | for my $r (0 .. $#{$self->{children}}) { |
1701 | for my $widget ($self->children) { |
1466 | my $row = $self->{children}[$r] |
1702 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(c_row c_col req_w req_h c_rowspan c_colspan)}; |
1467 | or next; |
|
|
1468 | |
1703 | |
1469 | my $x = 0; |
1704 | $widget->configure ( |
1470 | my $row_h = $hs->[$r]; |
1705 | $x[$c], $y[$r], |
|
|
1706 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1471 | |
1707 | ); |
1472 | for my $c (0 .. $#$row) { |
1708 | } |
1473 | my $col_w = $ws->[$c]; |
|
|
1474 | |
1709 | |
1475 | if (my $widget = $row->[$c]) { |
1710 | 1 |
1476 | $widget->configure ($x, $y, $col_w, $row_h); |
1711 | } |
1477 | } |
|
|
1478 | |
1712 | |
1479 | $x += $col_w; |
1713 | ############################################################################# |
|
|
1714 | |
|
|
1715 | package DC::UI::Fixed; |
|
|
1716 | |
|
|
1717 | use List::Util qw(min max); |
|
|
1718 | |
|
|
1719 | our @ISA = DC::UI::Container::; |
|
|
1720 | |
|
|
1721 | sub _scale($$$) { |
|
|
1722 | my ($rel, $val, $max) = @_; |
|
|
1723 | |
|
|
1724 | $rel ? $val * $max : $val |
|
|
1725 | } |
|
|
1726 | |
|
|
1727 | sub size_request { |
|
|
1728 | my ($self) = @_; |
|
|
1729 | |
|
|
1730 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
|
|
1731 | |
|
|
1732 | # determine overall size by querying abs widgets |
|
|
1733 | for my $child ($self->visible_children) { |
|
|
1734 | unless ($child->{c_rel}) { |
|
|
1735 | my $x = $child->{c_x}; |
|
|
1736 | my $y = $child->{c_y}; |
|
|
1737 | |
|
|
1738 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
|
|
1739 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1480 | } |
1740 | } |
|
|
1741 | } |
1481 | |
1742 | |
1482 | $y += $row_h; |
1743 | my $W = $x2 - $x1; |
|
|
1744 | my $H = $y2 - $y1; |
|
|
1745 | |
|
|
1746 | # now layout remaining widgets |
|
|
1747 | for my $child ($self->visible_children) { |
|
|
1748 | if ($child->{c_rel}) { |
|
|
1749 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1750 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
|
|
1751 | |
|
|
1752 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
|
|
1753 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
|
|
1754 | } |
|
|
1755 | } |
|
|
1756 | |
|
|
1757 | my $W = $x2 - $x1; |
|
|
1758 | my $H = $y2 - $y1; |
|
|
1759 | |
|
|
1760 | ($W, $H) |
|
|
1761 | } |
|
|
1762 | |
|
|
1763 | sub invoke_size_allocate { |
|
|
1764 | my ($self, $W, $H) = @_; |
|
|
1765 | |
|
|
1766 | for my $child ($self->visible_children) { |
|
|
1767 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1768 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
|
|
1769 | |
|
|
1770 | $x += $child->{c_halign} * $child->{req_w}; |
|
|
1771 | $y += $child->{c_valign} * $child->{req_h}; |
|
|
1772 | |
|
|
1773 | $child->configure (int $x, int $y, $child->{req_w}, $child->{req_h}); |
1483 | } |
1774 | } |
1484 | |
1775 | |
1485 | 1 |
1776 | 1 |
1486 | } |
1777 | } |
1487 | |
1778 | |
1488 | sub find_widget { |
|
|
1489 | my ($self, $x, $y) = @_; |
|
|
1490 | |
|
|
1491 | $x -= $self->{x}; |
|
|
1492 | $y -= $self->{y}; |
|
|
1493 | |
|
|
1494 | my $res; |
|
|
1495 | |
|
|
1496 | for (grep $_, map @$_, grep $_, @{ $self->{children} }) { |
|
|
1497 | $res = $_->find_widget ($x, $y) |
|
|
1498 | and return $res; |
|
|
1499 | } |
|
|
1500 | |
|
|
1501 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
|
|
1502 | } |
|
|
1503 | |
|
|
1504 | sub _draw { |
|
|
1505 | my ($self) = @_; |
|
|
1506 | |
|
|
1507 | for (grep $_, @{$self->{children}}) { |
|
|
1508 | $_->draw for grep $_, @$_; |
|
|
1509 | } |
|
|
1510 | } |
|
|
1511 | |
|
|
1512 | ############################################################################# |
1779 | ############################################################################# |
1513 | |
1780 | |
1514 | package CFPlus::UI::Box; |
1781 | package DC::UI::Box; |
1515 | |
1782 | |
1516 | our @ISA = CFPlus::UI::Container::; |
1783 | our @ISA = DC::UI::Container::; |
1517 | |
1784 | |
1518 | sub size_request { |
1785 | sub size_request { |
1519 | my ($self) = @_; |
1786 | my ($self) = @_; |
|
|
1787 | |
|
|
1788 | my @children = $self->visible_children; |
1520 | |
1789 | |
1521 | $self->{vertical} |
1790 | $self->{vertical} |
1522 | ? ( |
1791 | ? ( |
1523 | (List::Util::max map $_->{req_w}, @{$self->{children}}), |
1792 | (List::Util::max map $_->{req_w}, @children), |
1524 | (List::Util::sum map $_->{req_h}, @{$self->{children}}), |
1793 | (List::Util::sum map $_->{req_h}, @children), |
1525 | ) |
1794 | ) |
1526 | : ( |
1795 | : ( |
1527 | (List::Util::sum map $_->{req_w}, @{$self->{children}}), |
1796 | (List::Util::sum map $_->{req_w}, @children), |
1528 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
1797 | (List::Util::max map $_->{req_h}, @children), |
1529 | ) |
1798 | ) |
1530 | } |
1799 | } |
1531 | |
1800 | |
1532 | sub invoke_size_allocate { |
1801 | sub invoke_size_allocate { |
1533 | my ($self, $w, $h) = @_; |
1802 | my ($self, $w, $h) = @_; |
… | |
… | |
1554 | $req[$_] += $space * $children[$_]{expand} |
1823 | $req[$_] += $space * $children[$_]{expand} |
1555 | for 0 .. $#children; |
1824 | for 0 .. $#children; |
1556 | } |
1825 | } |
1557 | } |
1826 | } |
1558 | |
1827 | |
1559 | CFPlus::UI::harmonize \@req; |
1828 | DC::UI::harmonize \@req; |
1560 | |
1829 | |
1561 | my $pos = 0; |
1830 | my $pos = 0; |
1562 | for (0 .. $#children) { |
1831 | for (0 .. $#children) { |
1563 | my $alloc = $req[$_]; |
1832 | my $alloc = $req[$_]; |
1564 | $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); |
1833 | $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); |
… | |
… | |
1569 | 1 |
1838 | 1 |
1570 | } |
1839 | } |
1571 | |
1840 | |
1572 | ############################################################################# |
1841 | ############################################################################# |
1573 | |
1842 | |
1574 | package CFPlus::UI::HBox; |
1843 | package DC::UI::HBox; |
1575 | |
1844 | |
1576 | our @ISA = CFPlus::UI::Box::; |
1845 | our @ISA = DC::UI::Box::; |
1577 | |
1846 | |
1578 | sub new { |
1847 | sub new { |
1579 | my $class = shift; |
1848 | my $class = shift; |
1580 | |
1849 | |
1581 | $class->SUPER::new ( |
1850 | $class->SUPER::new ( |
… | |
… | |
1584 | ) |
1853 | ) |
1585 | } |
1854 | } |
1586 | |
1855 | |
1587 | ############################################################################# |
1856 | ############################################################################# |
1588 | |
1857 | |
1589 | package CFPlus::UI::VBox; |
1858 | package DC::UI::VBox; |
1590 | |
1859 | |
1591 | our @ISA = CFPlus::UI::Box::; |
1860 | our @ISA = DC::UI::Box::; |
1592 | |
1861 | |
1593 | sub new { |
1862 | sub new { |
1594 | my $class = shift; |
1863 | my $class = shift; |
1595 | |
1864 | |
1596 | $class->SUPER::new ( |
1865 | $class->SUPER::new ( |
… | |
… | |
1599 | ) |
1868 | ) |
1600 | } |
1869 | } |
1601 | |
1870 | |
1602 | ############################################################################# |
1871 | ############################################################################# |
1603 | |
1872 | |
1604 | package CFPlus::UI::Label; |
1873 | package DC::UI::Label; |
1605 | |
1874 | |
1606 | our @ISA = CFPlus::UI::DrawBG::; |
1875 | our @ISA = DC::UI::DrawBG::; |
1607 | |
1876 | |
1608 | use CFPlus::OpenGL; |
1877 | use DC::OpenGL; |
1609 | |
1878 | |
1610 | sub new { |
1879 | sub new { |
1611 | my ($class, %arg) = @_; |
1880 | my ($class, %arg) = @_; |
1612 | |
1881 | |
1613 | my $self = $class->SUPER::new ( |
1882 | my $self = $class->SUPER::new ( |
… | |
… | |
1618 | #text => initial text |
1887 | #text => initial text |
1619 | #markup => initial narkup |
1888 | #markup => initial narkup |
1620 | #max_w => maximum pixel width |
1889 | #max_w => maximum pixel width |
1621 | #style => 0, # render flags |
1890 | #style => 0, # render flags |
1622 | ellipsise => 3, # end |
1891 | ellipsise => 3, # end |
1623 | layout => (new CFPlus::Layout), |
1892 | layout => (new DC::Layout), |
1624 | fontsize => 1, |
1893 | fontsize => 1, |
1625 | align => -1, |
1894 | align => -1, |
1626 | valign => -1, |
1895 | valign => -1, |
1627 | padding_x => 2, |
1896 | padding_x => 2, |
1628 | padding_y => 2, |
1897 | padding_y => 2, |
1629 | can_events => 0, |
1898 | can_events => 0, |
1630 | %arg |
1899 | %arg |
1631 | ); |
1900 | ); |
1632 | |
1901 | |
1633 | if (exists $self->{template}) { |
1902 | if (exists $self->{template}) { |
1634 | my $layout = new CFPlus::Layout; |
1903 | my $layout = new DC::Layout; |
1635 | $layout->set_text (delete $self->{template}); |
1904 | $layout->set_text (delete $self->{template}); |
1636 | $self->{template} = $layout; |
1905 | $self->{template} = $layout; |
1637 | } |
1906 | } |
1638 | |
1907 | |
1639 | if (exists $self->{markup}) { |
1908 | if (exists $self->{markup}) { |
… | |
… | |
1657 | |
1926 | |
1658 | delete $self->{ox}; |
1927 | delete $self->{ox}; |
1659 | $self->SUPER::realloc; |
1928 | $self->SUPER::realloc; |
1660 | } |
1929 | } |
1661 | |
1930 | |
|
|
1931 | sub clear { |
|
|
1932 | my ($self) = @_; |
|
|
1933 | |
|
|
1934 | $self->set_text (""); |
|
|
1935 | } |
|
|
1936 | |
1662 | sub set_text { |
1937 | sub set_text { |
1663 | my ($self, $text) = @_; |
1938 | my ($self, $text) = @_; |
1664 | |
1939 | |
1665 | return if $self->{text} eq "T$text"; |
1940 | return if $self->{text} eq "T$text"; |
1666 | $self->{text} = "T$text"; |
1941 | $self->{text} = "T$text"; |
… | |
… | |
1689 | |
1964 | |
1690 | sub size_request { |
1965 | sub size_request { |
1691 | my ($self) = @_; |
1966 | my ($self) = @_; |
1692 | |
1967 | |
1693 | $self->{size_req} ||= do { |
1968 | $self->{size_req} ||= do { |
|
|
1969 | my ($max_w, $max_h) = $self->get_max_wh; |
|
|
1970 | |
1694 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1971 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1695 | $self->{layout}->set_width ($self->{max_w} || -1); |
1972 | $self->{layout}->set_width ($self->{max_w} || $max_w || -1); |
1696 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1973 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1697 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1974 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1698 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1975 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1699 | |
1976 | |
1700 | my ($w, $h) = $self->{layout}->size; |
1977 | my ($w, $h) = $self->{layout}->size; |
… | |
… | |
1772 | : ($self->{w} - $size->[0]) * 0.5); |
2049 | : ($self->{w} - $size->[0]) * 0.5); |
1773 | |
2050 | |
1774 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2051 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
1775 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2052 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
1776 | : ($self->{h} - $size->[1]) * 0.5); |
2053 | : ($self->{h} - $size->[1]) * 0.5); |
|
|
2054 | |
|
|
2055 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
1777 | }; |
2056 | }; |
1778 | |
2057 | |
1779 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
2058 | # unless ($self->{list}) { |
1780 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
2059 | # $self->{list} = DC::OpenGL::glGenList; |
1781 | |
2060 | # DC::OpenGL::glNewList $self->{list}; |
1782 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2061 | # $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
|
|
2062 | # DC::OpenGL::glEndList; |
|
|
2063 | # } |
|
|
2064 | # |
|
|
2065 | # DC::OpenGL::glCallList $self->{list}; |
|
|
2066 | |
|
|
2067 | $self->{layout}->draw; |
1783 | } |
2068 | } |
|
|
2069 | |
|
|
2070 | #sub destroy { |
|
|
2071 | # my ($self) = @_; |
|
|
2072 | # |
|
|
2073 | # DC::OpenGL::glDeleteList delete $self->{list} if $self->{list}; |
|
|
2074 | # |
|
|
2075 | # $self->SUPER::destroy; |
|
|
2076 | #} |
1784 | |
2077 | |
1785 | ############################################################################# |
2078 | ############################################################################# |
1786 | |
2079 | |
1787 | package CFPlus::UI::EntryBase; |
2080 | package DC::UI::EntryBase; |
1788 | |
2081 | |
1789 | our @ISA = CFPlus::UI::Label::; |
2082 | our @ISA = DC::UI::Label::; |
1790 | |
2083 | |
1791 | use CFPlus::OpenGL; |
2084 | use DC::OpenGL; |
1792 | |
2085 | |
1793 | sub new { |
2086 | sub new { |
1794 | my $class = shift; |
2087 | my $class = shift; |
1795 | |
2088 | |
1796 | $class->SUPER::new ( |
2089 | $class->SUPER::new ( |
1797 | fg => [1, 1, 1], |
2090 | fg => [1, 1, 1], |
1798 | bg => [0, 0, 0, 0.2], |
2091 | bg => [0, 0, 0, 0.2], |
|
|
2092 | outline => [0.6, 0.3, 0.1], |
1799 | active_bg => [1, 1, 1, 0.5], |
2093 | active_bg => [0, 0, 1, .2], |
1800 | active_fg => [0, 0, 0], |
2094 | active_fg => [1, 1, 1], |
|
|
2095 | active_outline => [1, 1, 0], |
1801 | can_hover => 1, |
2096 | can_hover => 1, |
1802 | can_focus => 1, |
2097 | can_focus => 1, |
1803 | valign => 0, |
2098 | valign => 0, |
1804 | can_events => 1, |
2099 | can_events => 1, |
|
|
2100 | ellipsise => 0, |
|
|
2101 | padding_x => 4, |
|
|
2102 | padding_y => 2, |
1805 | #text => ... |
2103 | #text => ... |
1806 | #hidden => "*", |
2104 | #hidden => "*", |
1807 | @_ |
2105 | @_ |
1808 | ) |
2106 | ) |
1809 | } |
2107 | } |
… | |
… | |
1854 | my $sym = $ev->{sym}; |
2152 | my $sym = $ev->{sym}; |
1855 | my $uni = $ev->{unicode}; |
2153 | my $uni = $ev->{unicode}; |
1856 | |
2154 | |
1857 | my $text = $self->get_text; |
2155 | my $text = $self->get_text; |
1858 | |
2156 | |
|
|
2157 | $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; |
|
|
2158 | |
1859 | if ($uni == 8) { |
2159 | if ($uni == 8) { |
1860 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
2160 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1861 | } elsif ($uni == 127) { |
2161 | } elsif ($uni == 127) { |
1862 | substr $text, $self->{cursor}, 1, ""; |
2162 | substr $text, $self->{cursor}, 1, ""; |
1863 | } elsif ($sym == CFPlus::SDLK_LEFT) { |
2163 | } elsif ($sym == DC::SDLK_LEFT) { |
1864 | --$self->{cursor} if $self->{cursor}; |
2164 | --$self->{cursor} if $self->{cursor}; |
1865 | } elsif ($sym == CFPlus::SDLK_RIGHT) { |
2165 | } elsif ($sym == DC::SDLK_RIGHT) { |
1866 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
2166 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1867 | } elsif ($sym == CFPlus::SDLK_HOME) { |
2167 | } elsif ($sym == DC::SDLK_HOME) { |
|
|
2168 | # what a hack |
|
|
2169 | $self->{cursor} = |
|
|
2170 | (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ |
|
|
2171 | ? length $1 |
|
|
2172 | : 0; |
|
|
2173 | } elsif ($sym == DC::SDLK_END) { |
|
|
2174 | # uh, again |
|
|
2175 | $self->{cursor} = |
|
|
2176 | (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ |
|
|
2177 | ? $self->{cursor} + length $1 |
|
|
2178 | : length $self->{text}; |
|
|
2179 | } elsif ($uni == 21) { # ctrl-u |
|
|
2180 | $text = ""; |
1868 | $self->{cursor} = 0; |
2181 | $self->{cursor} = 0; |
1869 | } elsif ($sym == CFPlus::SDLK_END) { |
|
|
1870 | $self->{cursor} = length $text; |
|
|
1871 | } elsif ($uni == 27) { |
2182 | } elsif ($uni == 27) { |
1872 | $self->emit ('escape'); |
2183 | $self->emit ('escape'); |
1873 | } elsif ($uni) { |
2184 | } elsif ($uni == 0x0d) { |
|
|
2185 | substr $text, $self->{cursor}++, 0, "\012"; |
|
|
2186 | } elsif ($uni >= 0x20) { |
1874 | substr $text, $self->{cursor}++, 0, chr $uni; |
2187 | substr $text, $self->{cursor}++, 0, chr $uni; |
1875 | } else { |
2188 | } else { |
1876 | return 0; |
2189 | return 0; |
1877 | } |
2190 | } |
1878 | |
2191 | |
1879 | $self->_set_text ($text); |
2192 | $self->_set_text ($text); |
1880 | |
2193 | |
1881 | $self->realloc; |
2194 | $self->realloc; |
|
|
2195 | $self->update; |
1882 | |
2196 | |
1883 | 1 |
2197 | 1 |
1884 | } |
2198 | } |
1885 | |
2199 | |
1886 | sub invoke_focus_in { |
2200 | sub invoke_focus_in { |
… | |
… | |
1928 | glColor_premultiply @{$self->{bg}}; |
2242 | glColor_premultiply @{$self->{bg}}; |
1929 | } |
2243 | } |
1930 | |
2244 | |
1931 | glEnable GL_BLEND; |
2245 | glEnable GL_BLEND; |
1932 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2246 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1933 | glBegin GL_QUADS; |
|
|
1934 | glVertex 0 , 0; |
|
|
1935 | glVertex 0 , $self->{h}; |
|
|
1936 | glVertex $self->{w}, $self->{h}; |
2247 | glRect 0, 0, $self->{w}, $self->{h}; |
1937 | glVertex $self->{w}, 0; |
|
|
1938 | glEnd; |
|
|
1939 | glDisable GL_BLEND; |
2248 | glDisable GL_BLEND; |
1940 | |
2249 | |
1941 | $self->SUPER::_draw; |
2250 | $self->SUPER::_draw; |
1942 | |
2251 | |
1943 | #TODO: force update every cursor change :( |
2252 | #TODO: force update every cursor change :( |
… | |
… | |
1945 | |
2254 | |
1946 | unless (exists $self->{cur_h}) { |
2255 | unless (exists $self->{cur_h}) { |
1947 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2256 | my $text = substr $self->{text}, 0, $self->{cursor}; |
1948 | utf8::encode $text; |
2257 | utf8::encode $text; |
1949 | |
2258 | |
1950 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
2259 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
1951 | } |
2260 | } |
1952 | |
2261 | |
|
|
2262 | glColor_premultiply @{$self->{active_fg}}; |
1953 | glBegin GL_LINES; |
2263 | glBegin GL_LINES; |
1954 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2264 | glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy}; |
1955 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2265 | glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
1956 | glEnd; |
2266 | glEnd; |
1957 | } |
|
|
1958 | } |
|
|
1959 | |
2267 | |
|
|
2268 | glLineWidth 3; |
|
|
2269 | glColor @{$self->{active_outline}}; |
|
|
2270 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
|
|
2271 | glLineWidth 1; |
|
|
2272 | |
|
|
2273 | } else { |
|
|
2274 | glColor @{$self->{outline}}; |
|
|
2275 | glBegin GL_LINE_STRIP; |
|
|
2276 | glVertex .5, $self->{h} * .5; |
|
|
2277 | glVertex .5, $self->{h} - 2.5; |
|
|
2278 | glVertex $self->{w} - .5, $self->{h} - 2.5; |
|
|
2279 | glVertex $self->{w} - .5, $self->{h} * .5; |
|
|
2280 | glEnd; |
|
|
2281 | } |
|
|
2282 | } |
|
|
2283 | |
|
|
2284 | ############################################################################# |
|
|
2285 | |
1960 | package CFPlus::UI::Entry; |
2286 | package DC::UI::Entry; |
1961 | |
2287 | |
1962 | our @ISA = CFPlus::UI::EntryBase::; |
2288 | our @ISA = DC::UI::EntryBase::; |
1963 | |
2289 | |
1964 | use CFPlus::OpenGL; |
2290 | use DC::OpenGL; |
1965 | |
2291 | |
1966 | sub invoke_key_down { |
2292 | sub invoke_key_down { |
1967 | my ($self, $ev) = @_; |
2293 | my ($self, $ev) = @_; |
1968 | |
2294 | |
1969 | my $sym = $ev->{sym}; |
2295 | my $sym = $ev->{sym}; |
1970 | |
2296 | |
1971 | if ($sym == 13) { |
2297 | if ($ev->{uni} == 0x0d || $sym == 13) { |
1972 | unshift @{$self->{history}}, |
2298 | unshift @{$self->{history}}, |
1973 | my $txt = $self->get_text; |
2299 | my $txt = $self->get_text; |
1974 | |
2300 | |
1975 | $self->{history_pointer} = -1; |
2301 | $self->{history_pointer} = -1; |
1976 | $self->{history_saveback} = ''; |
2302 | $self->{history_saveback} = ''; |
1977 | $self->emit (activate => $txt); |
2303 | $self->emit (activate => $txt); |
1978 | $self->update; |
2304 | $self->update; |
1979 | |
2305 | |
1980 | } elsif ($sym == CFPlus::SDLK_UP) { |
2306 | } elsif ($sym == DC::SDLK_UP) { |
1981 | if ($self->{history_pointer} < 0) { |
2307 | if ($self->{history_pointer} < 0) { |
1982 | $self->{history_saveback} = $self->get_text; |
2308 | $self->{history_saveback} = $self->get_text; |
1983 | } |
2309 | } |
1984 | if (@{$self->{history} || []} > 0) { |
2310 | if (@{$self->{history} || []} > 0) { |
1985 | $self->{history_pointer}++; |
2311 | $self->{history_pointer}++; |
… | |
… | |
1987 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
2313 | $self->{history_pointer} = @{$self->{history} || []} - 1; |
1988 | } |
2314 | } |
1989 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2315 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
1990 | } |
2316 | } |
1991 | |
2317 | |
1992 | } elsif ($sym == CFPlus::SDLK_DOWN) { |
2318 | } elsif ($sym == DC::SDLK_DOWN) { |
1993 | $self->{history_pointer}--; |
2319 | $self->{history_pointer}--; |
1994 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
2320 | $self->{history_pointer} = -1 if $self->{history_pointer} < 0; |
1995 | |
2321 | |
1996 | if ($self->{history_pointer} >= 0) { |
2322 | if ($self->{history_pointer} >= 0) { |
1997 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
2323 | $self->set_text ($self->{history}->[$self->{history_pointer}]); |
… | |
… | |
2006 | 1 |
2332 | 1 |
2007 | } |
2333 | } |
2008 | |
2334 | |
2009 | ############################################################################# |
2335 | ############################################################################# |
2010 | |
2336 | |
2011 | package CFPlus::UI::Button; |
2337 | package DC::UI::TextEdit; |
2012 | |
2338 | |
2013 | our @ISA = CFPlus::UI::Label::; |
2339 | our @ISA = DC::UI::EntryBase::; |
2014 | |
2340 | |
2015 | use CFPlus::OpenGL; |
2341 | use DC::OpenGL; |
2016 | |
|
|
2017 | my @tex = |
|
|
2018 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
|
|
2019 | qw(b1_button_active.png); |
|
|
2020 | |
2342 | |
2021 | sub new { |
2343 | sub new { |
2022 | my $class = shift; |
2344 | my $class = shift; |
2023 | |
2345 | |
2024 | $class->SUPER::new ( |
2346 | $class->SUPER::new ( |
2025 | padding_x => 4, |
|
|
2026 | padding_y => 4, |
2347 | padding_y => 4, |
2027 | fg => [1, 1, 1], |
2348 | |
2028 | active_fg => [0, 0, 1], |
2349 | @_ |
|
|
2350 | ) |
|
|
2351 | } |
|
|
2352 | |
|
|
2353 | sub move_cursor_ver { |
|
|
2354 | my ($self, $dy) = @_; |
|
|
2355 | |
|
|
2356 | my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); |
|
|
2357 | warn "cursor $self->{cursor} => $x $line\n";#d# |
|
|
2358 | |
|
|
2359 | $line += $dy; |
|
|
2360 | |
|
|
2361 | if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) { |
|
|
2362 | warn "index $x $line => $index\n";#d# |
|
|
2363 | $self->{cursor} = $index; |
|
|
2364 | delete $self->{cur_h}; |
|
|
2365 | $self->update; |
|
|
2366 | return; |
|
|
2367 | } |
|
|
2368 | } |
|
|
2369 | |
|
|
2370 | sub invoke_key_down { |
|
|
2371 | my ($self, $ev) = @_; |
|
|
2372 | |
|
|
2373 | my $sym = $ev->{sym}; |
|
|
2374 | |
|
|
2375 | if ($sym == DC::SDLK_UP) { |
|
|
2376 | $self->move_cursor_ver (-1); |
|
|
2377 | } elsif ($sym == DC::SDLK_DOWN) { |
|
|
2378 | $self->move_cursor_ver (+1); |
|
|
2379 | } else { |
|
|
2380 | return $self->SUPER::invoke_key_down ($ev) |
|
|
2381 | } |
|
|
2382 | |
|
|
2383 | 1 |
|
|
2384 | } |
|
|
2385 | |
|
|
2386 | ############################################################################# |
|
|
2387 | |
|
|
2388 | package DC::UI::ButtonBin; |
|
|
2389 | |
|
|
2390 | our @ISA = DC::UI::Bin::; |
|
|
2391 | |
|
|
2392 | use DC::OpenGL; |
|
|
2393 | |
|
|
2394 | my @tex = |
|
|
2395 | map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } |
|
|
2396 | qw(b1_button_inactive.png b1_button_active.png); |
|
|
2397 | |
|
|
2398 | sub new { |
|
|
2399 | my $class = shift; |
|
|
2400 | |
|
|
2401 | $class->SUPER::new ( |
2029 | can_hover => 1, |
2402 | can_hover => 1, |
2030 | align => 0, |
2403 | align => 0, |
2031 | valign => 0, |
2404 | valign => 0, |
2032 | can_events => 1, |
2405 | can_events => 1, |
2033 | @_ |
2406 | @_ |
… | |
… | |
2045 | } |
2418 | } |
2046 | |
2419 | |
2047 | sub _draw { |
2420 | sub _draw { |
2048 | my ($self) = @_; |
2421 | my ($self) = @_; |
2049 | |
2422 | |
2050 | local $self->{fg} = $GRAB == $self ? $self->{active_fg} : $self->{fg}; |
|
|
2051 | |
|
|
2052 | glEnable GL_TEXTURE_2D; |
2423 | glEnable GL_TEXTURE_2D; |
2053 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2424 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2054 | glColor 0, 0, 0, 1; |
2425 | glColor 0, 0, 0, 1; |
2055 | |
2426 | |
|
|
2427 | my $tex = $tex[$GRAB == $self]; |
2056 | $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2428 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2057 | |
2429 | |
2058 | glDisable GL_TEXTURE_2D; |
2430 | glDisable GL_TEXTURE_2D; |
2059 | |
2431 | |
2060 | $self->SUPER::_draw; |
2432 | $self->SUPER::_draw; |
2061 | } |
2433 | } |
2062 | |
2434 | |
2063 | ############################################################################# |
2435 | ############################################################################# |
2064 | |
2436 | |
2065 | package CFPlus::UI::CheckBox; |
2437 | package DC::UI::Button; |
2066 | |
2438 | |
2067 | our @ISA = CFPlus::UI::DrawBG::; |
2439 | our @ISA = DC::UI::Label::; |
|
|
2440 | |
|
|
2441 | use DC::OpenGL; |
2068 | |
2442 | |
2069 | my @tex = |
2443 | my @tex = |
2070 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2444 | map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } |
|
|
2445 | qw(b1_button_inactive.png b1_button_active.png); |
|
|
2446 | |
|
|
2447 | sub new { |
|
|
2448 | my $class = shift; |
|
|
2449 | |
|
|
2450 | $class->SUPER::new ( |
|
|
2451 | padding_x => 8, |
|
|
2452 | padding_y => 4, |
|
|
2453 | fg => [1.0, 1.0, 1.0], |
|
|
2454 | active_fg => [0.8, 0.8, 0.8], |
|
|
2455 | can_hover => 1, |
|
|
2456 | align => 0, |
|
|
2457 | valign => 0, |
|
|
2458 | can_events => 1, |
|
|
2459 | @_ |
|
|
2460 | ) |
|
|
2461 | } |
|
|
2462 | |
|
|
2463 | sub invoke_button_up { |
|
|
2464 | my ($self, $ev, $x, $y) = @_; |
|
|
2465 | |
|
|
2466 | $self->emit ("activate") |
|
|
2467 | if $x >= 0 && $x < $self->{w} |
|
|
2468 | && $y >= 0 && $y < $self->{h}; |
|
|
2469 | |
|
|
2470 | 1 |
|
|
2471 | } |
|
|
2472 | |
|
|
2473 | sub _draw { |
|
|
2474 | my ($self) = @_; |
|
|
2475 | |
|
|
2476 | local $self->{fg} = $GRAB == $self ? $self->{active_fg} : $self->{fg}; |
|
|
2477 | |
|
|
2478 | glEnable GL_TEXTURE_2D; |
|
|
2479 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2480 | glColor 0, 0, 0, 1; |
|
|
2481 | |
|
|
2482 | my $tex = $tex[$GRAB == $self]; |
|
|
2483 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
|
|
2484 | |
|
|
2485 | glDisable GL_TEXTURE_2D; |
|
|
2486 | |
|
|
2487 | $self->SUPER::_draw; |
|
|
2488 | } |
|
|
2489 | |
|
|
2490 | ############################################################################# |
|
|
2491 | |
|
|
2492 | package DC::UI::CheckBox; |
|
|
2493 | |
|
|
2494 | our @ISA = DC::UI::DrawBG::; |
|
|
2495 | |
|
|
2496 | my @tex = |
|
|
2497 | map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } |
2071 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
2498 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
2072 | |
2499 | |
2073 | use CFPlus::OpenGL; |
2500 | use DC::OpenGL; |
2074 | |
2501 | |
2075 | sub new { |
2502 | sub new { |
2076 | my $class = shift; |
2503 | my $class = shift; |
2077 | |
2504 | |
2078 | $class->SUPER::new ( |
2505 | $class->SUPER::new ( |
… | |
… | |
2118 | sub _draw { |
2545 | sub _draw { |
2119 | my ($self) = @_; |
2546 | my ($self) = @_; |
2120 | |
2547 | |
2121 | $self->SUPER::_draw; |
2548 | $self->SUPER::_draw; |
2122 | |
2549 | |
2123 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
2550 | glTranslate $self->{padding_x}, $self->{padding_y}, 0; |
2124 | |
2551 | |
2125 | my ($w, $h) = @$self{qw(w h)}; |
2552 | my ($w, $h) = @$self{qw(w h)}; |
2126 | |
2553 | |
2127 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
2554 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
2128 | |
2555 | |
… | |
… | |
2135 | glDisable GL_TEXTURE_2D; |
2562 | glDisable GL_TEXTURE_2D; |
2136 | } |
2563 | } |
2137 | |
2564 | |
2138 | ############################################################################# |
2565 | ############################################################################# |
2139 | |
2566 | |
2140 | package CFPlus::UI::Image; |
2567 | package DC::UI::Image; |
2141 | |
2568 | |
2142 | our @ISA = CFPlus::UI::Base::; |
2569 | our @ISA = DC::UI::Base::; |
2143 | |
2570 | |
2144 | use CFPlus::OpenGL; |
2571 | use DC::OpenGL; |
2145 | |
2572 | |
2146 | our %texture_cache; |
2573 | our %texture_cache; |
2147 | |
2574 | |
2148 | sub new { |
2575 | sub new { |
2149 | my $class = shift; |
2576 | my $class = shift; |
2150 | |
2577 | |
2151 | my $self = $class->SUPER::new ( |
2578 | my $self = $class->SUPER::new ( |
2152 | can_events => 0, |
2579 | can_events => 0, |
|
|
2580 | scale => 1, |
2153 | @_, |
2581 | @_, |
2154 | ); |
2582 | ); |
2155 | |
2583 | |
2156 | $self->{path} || $self->{tex} |
2584 | $self->{path} || $self->{tex} |
2157 | or Carp::croak "'path' or 'tex' attributes required"; |
2585 | or Carp::croak "'path' or 'tex' attributes required"; |
2158 | |
2586 | |
2159 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
2587 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
2160 | new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; |
2588 | new_from_file DC::Texture DC::find_rcfile $self->{path}, mipmap => 1; |
2161 | |
2589 | |
2162 | Scalar::Util::weaken $texture_cache{$self->{path}}; |
2590 | DC::weaken $texture_cache{$self->{path}}; |
2163 | |
2591 | |
2164 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2592 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2165 | |
2593 | |
2166 | $self |
2594 | $self |
2167 | } |
2595 | } |
2168 | |
2596 | |
2169 | sub STORABLE_freeze { |
2597 | sub STORABLE_freeze { |
2170 | my ($self, $cloning) = @_; |
2598 | my ($self, $cloning) = @_; |
2171 | |
2599 | |
2172 | $self->{path} |
2600 | $self->{path} |
2173 | or die "cannot serialise CFPlus::UI::Image on non-loadable images\n"; |
2601 | or die "cannot serialise DC::UI::Image on non-loadable images\n"; |
2174 | |
2602 | |
2175 | $self->{path} |
2603 | $self->{path} |
2176 | } |
2604 | } |
2177 | |
2605 | |
2178 | sub STORABLE_attach { |
2606 | sub STORABLE_attach { |
… | |
… | |
2182 | } |
2610 | } |
2183 | |
2611 | |
2184 | sub size_request { |
2612 | sub size_request { |
2185 | my ($self) = @_; |
2613 | my ($self) = @_; |
2186 | |
2614 | |
2187 | ($self->{tex}{w}, $self->{tex}{h}) |
2615 | (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) |
2188 | } |
2616 | } |
2189 | |
2617 | |
2190 | sub _draw { |
2618 | sub _draw { |
2191 | my ($self) = @_; |
2619 | my ($self) = @_; |
2192 | |
2620 | |
… | |
… | |
2202 | } |
2630 | } |
2203 | |
2631 | |
2204 | glEnable GL_TEXTURE_2D; |
2632 | glEnable GL_TEXTURE_2D; |
2205 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2633 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2206 | |
2634 | |
2207 | $tex->draw_quad (0, 0, $w, $h); |
2635 | $tex->draw_quad_alpha (0, 0, $w, $h); |
2208 | |
2636 | |
2209 | glDisable GL_TEXTURE_2D; |
2637 | glDisable GL_TEXTURE_2D; |
2210 | } |
2638 | } |
2211 | |
2639 | |
2212 | ############################################################################# |
2640 | ############################################################################# |
2213 | |
2641 | |
2214 | package CFPlus::UI::ImageButton; |
2642 | package DC::UI::ImageButton; |
2215 | |
2643 | |
2216 | our @ISA = CFPlus::UI::Image::; |
2644 | our @ISA = DC::UI::Image::; |
2217 | |
2645 | |
2218 | use CFPlus::OpenGL; |
2646 | use DC::OpenGL; |
2219 | |
2647 | |
2220 | my %textures; |
2648 | my %textures; |
2221 | |
2649 | |
2222 | sub new { |
2650 | sub new { |
2223 | my $class = shift; |
2651 | my $class = shift; |
… | |
… | |
2233 | can_events => 1, |
2661 | can_events => 1, |
2234 | @_ |
2662 | @_ |
2235 | ); |
2663 | ); |
2236 | } |
2664 | } |
2237 | |
2665 | |
|
|
2666 | sub invoke_button_down { |
|
|
2667 | my ($self, $ev, $x, $y) = @_; |
|
|
2668 | |
|
|
2669 | 1 |
|
|
2670 | } |
|
|
2671 | |
2238 | sub invoke_button_up { |
2672 | sub invoke_button_up { |
2239 | my ($self, $ev, $x, $y) = @_; |
2673 | my ($self, $ev, $x, $y) = @_; |
2240 | |
2674 | |
2241 | $self->emit ("activate") |
2675 | $self->emit ("activate") |
2242 | if $x >= 0 && $x < $self->{w} |
2676 | if $x >= 0 && $x < $self->{w} |
… | |
… | |
2245 | 1 |
2679 | 1 |
2246 | } |
2680 | } |
2247 | |
2681 | |
2248 | ############################################################################# |
2682 | ############################################################################# |
2249 | |
2683 | |
2250 | package CFPlus::UI::VGauge; |
2684 | package DC::UI::VGauge; |
2251 | |
2685 | |
2252 | our @ISA = CFPlus::UI::Base::; |
2686 | our @ISA = DC::UI::Base::; |
2253 | |
2687 | |
2254 | use List::Util qw(min max); |
2688 | use List::Util qw(min max); |
2255 | |
2689 | |
2256 | use CFPlus::OpenGL; |
2690 | use DC::OpenGL; |
2257 | |
2691 | |
2258 | my %tex = ( |
2692 | my %tex = ( |
2259 | food => [ |
2693 | food => [ |
2260 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2694 | map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } |
2261 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
2695 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
2262 | ], |
2696 | ], |
2263 | grace => [ |
2697 | grace => [ |
2264 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2698 | map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } |
2265 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
2699 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
2266 | ], |
2700 | ], |
2267 | hp => [ |
2701 | hp => [ |
2268 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2702 | map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } |
2269 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
2703 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
2270 | ], |
2704 | ], |
2271 | mana => [ |
2705 | mana => [ |
2272 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2706 | map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } |
2273 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
2707 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
2274 | ], |
2708 | ], |
2275 | ); |
2709 | ); |
2276 | |
2710 | |
2277 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
2711 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
… | |
… | |
2380 | glDisable GL_TEXTURE_2D; |
2814 | glDisable GL_TEXTURE_2D; |
2381 | } |
2815 | } |
2382 | |
2816 | |
2383 | ############################################################################# |
2817 | ############################################################################# |
2384 | |
2818 | |
|
|
2819 | package DC::UI::Progress; |
|
|
2820 | |
|
|
2821 | our @ISA = DC::UI::Label::; |
|
|
2822 | |
|
|
2823 | use DC::OpenGL; |
|
|
2824 | |
|
|
2825 | sub new { |
|
|
2826 | my ($class, %arg) = @_; |
|
|
2827 | |
|
|
2828 | my $self = $class->SUPER::new ( |
|
|
2829 | fg => [1, 1, 1], |
|
|
2830 | bg => [0, 0, 1, 0.2], |
|
|
2831 | bar => [0.7, 0.5, 0.1, 0.8], |
|
|
2832 | outline => [0.4, 0.3, 0], |
|
|
2833 | fontsize => 0.9, |
|
|
2834 | valign => 0, |
|
|
2835 | align => 0, |
|
|
2836 | can_events => 1, |
|
|
2837 | ellipsise => 1, |
|
|
2838 | label => "%d%%", |
|
|
2839 | %arg, |
|
|
2840 | ); |
|
|
2841 | |
|
|
2842 | $self->set_value ($arg{value} || -1); |
|
|
2843 | |
|
|
2844 | $self |
|
|
2845 | } |
|
|
2846 | |
|
|
2847 | sub set_label { |
|
|
2848 | my ($self, $label) = @_; |
|
|
2849 | |
|
|
2850 | return if $self->{label} eq $label; |
|
|
2851 | $self->{label} = $label; |
|
|
2852 | |
|
|
2853 | $self->DC::UI::Progress::set_value (0 + delete $self->{value}); |
|
|
2854 | } |
|
|
2855 | |
|
|
2856 | sub set_value { |
|
|
2857 | my ($self, $value) = @_; |
|
|
2858 | |
|
|
2859 | if ($self->{value} ne $value) { |
|
|
2860 | $self->{value} = $value; |
|
|
2861 | |
|
|
2862 | if ($value < 0) { |
|
|
2863 | $self->set_text ("-"); |
|
|
2864 | } else { |
|
|
2865 | $self->set_text (sprintf $self->{label}, $value * 100); |
|
|
2866 | } |
|
|
2867 | |
|
|
2868 | $self->update; |
|
|
2869 | } |
|
|
2870 | } |
|
|
2871 | |
|
|
2872 | sub _draw { |
|
|
2873 | my ($self) = @_; |
|
|
2874 | |
|
|
2875 | glEnable GL_BLEND; |
|
|
2876 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2877 | |
|
|
2878 | if ($self->{value} >= 0) { |
|
|
2879 | my $s = int 2 + ($self->{w} - 4) * $self->{value}; |
|
|
2880 | |
|
|
2881 | glColor_premultiply @{$self->{bar}}; |
|
|
2882 | glRect 2, 2, $s, $self->{h} - 2; |
|
|
2883 | glColor_premultiply @{$self->{bg}}; |
|
|
2884 | glRect $s, 2, $self->{w} - 2, $self->{h} - 2; |
|
|
2885 | } |
|
|
2886 | |
|
|
2887 | glColor_premultiply @{$self->{outline}}; |
|
|
2888 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
|
|
2889 | |
|
|
2890 | glDisable GL_BLEND; |
|
|
2891 | |
|
|
2892 | { |
|
|
2893 | local $self->{bg}; # do not draw background |
|
|
2894 | $self->SUPER::_draw; |
|
|
2895 | } |
|
|
2896 | } |
|
|
2897 | |
|
|
2898 | ############################################################################# |
|
|
2899 | |
|
|
2900 | package DC::UI::ExperienceProgress; |
|
|
2901 | |
|
|
2902 | our @ISA = DC::UI::Progress::; |
|
|
2903 | |
|
|
2904 | sub new { |
|
|
2905 | my ($class, %arg) = @_; |
|
|
2906 | |
|
|
2907 | my $self = $class->SUPER::new ( |
|
|
2908 | tooltip => sub { |
|
|
2909 | my ($self) = @_; |
|
|
2910 | |
|
|
2911 | sprintf "level %d\n%s points\n%s next level\n%s to go", |
|
|
2912 | $self->{lvl}, |
|
|
2913 | ::formsep ($self->{exp}), |
|
|
2914 | ::formsep ($self->{nxt}), |
|
|
2915 | ::formsep ($self->{nxt} - $self->{exp}), |
|
|
2916 | }, |
|
|
2917 | %arg |
|
|
2918 | ); |
|
|
2919 | |
|
|
2920 | $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } |
|
|
2921 | if $::CONN; |
|
|
2922 | |
|
|
2923 | $self |
|
|
2924 | } |
|
|
2925 | |
|
|
2926 | sub DESTROY { |
|
|
2927 | my ($self) = @_; |
|
|
2928 | |
|
|
2929 | delete $::CONN->{on_exp_update}{$self+0} |
|
|
2930 | if $::CONN; |
|
|
2931 | |
|
|
2932 | $self->SUPER::DESTROY; |
|
|
2933 | } |
|
|
2934 | |
|
|
2935 | sub set_value { |
|
|
2936 | my ($self, $lvl, $exp) = @_; |
|
|
2937 | |
|
|
2938 | $self->{lvl} = $lvl; |
|
|
2939 | $self->{exp} = $exp; |
|
|
2940 | |
|
|
2941 | my $v = -1; |
|
|
2942 | |
|
|
2943 | if ($::CONN && (my $table = $::CONN->{exp_table})) { |
|
|
2944 | my $l0 = $table->[$lvl - 1]; |
|
|
2945 | my $l1 = $table->[$lvl]; |
|
|
2946 | |
|
|
2947 | $self->{nxt} = $l1; |
|
|
2948 | |
|
|
2949 | $v = ($exp - $l0) / ($l1 - $l0); |
|
|
2950 | } |
|
|
2951 | |
|
|
2952 | $self->SUPER::set_value ($v); |
|
|
2953 | } |
|
|
2954 | |
|
|
2955 | ############################################################################# |
|
|
2956 | |
2385 | package CFPlus::UI::Gauge; |
2957 | package DC::UI::Gauge; |
2386 | |
2958 | |
2387 | our @ISA = CFPlus::UI::VBox::; |
2959 | our @ISA = DC::UI::VBox::; |
2388 | |
2960 | |
2389 | sub new { |
2961 | sub new { |
2390 | my ($class, %arg) = @_; |
2962 | my ($class, %arg) = @_; |
2391 | |
2963 | |
2392 | my $self = $class->SUPER::new ( |
2964 | my $self = $class->SUPER::new ( |
… | |
… | |
2394 | can_hover => 1, |
2966 | can_hover => 1, |
2395 | can_events => 1, |
2967 | can_events => 1, |
2396 | %arg, |
2968 | %arg, |
2397 | ); |
2969 | ); |
2398 | |
2970 | |
2399 | $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999"); |
2971 | $self->add ($self->{value} = new DC::UI::Label valign => +1, align => 0, template => "999"); |
2400 | $self->add ($self->{gauge} = new CFPlus::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
2972 | $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
2401 | $self->add ($self->{max} = new CFPlus::UI::Label valign => -1, align => 0, template => "999"); |
2973 | $self->add ($self->{max} = new DC::UI::Label valign => -1, align => 0, template => "999"); |
2402 | |
2974 | |
2403 | $self |
2975 | $self |
2404 | } |
2976 | } |
2405 | |
2977 | |
2406 | sub set_fontsize { |
2978 | sub set_fontsize { |
… | |
… | |
2427 | $self->{value}->set_text ($val); |
2999 | $self->{value}->set_text ($val); |
2428 | } |
3000 | } |
2429 | |
3001 | |
2430 | ############################################################################# |
3002 | ############################################################################# |
2431 | |
3003 | |
2432 | package CFPlus::UI::Slider; |
3004 | package DC::UI::Slider; |
2433 | |
3005 | |
2434 | use strict; |
3006 | use strict; |
2435 | |
3007 | |
2436 | use CFPlus::OpenGL; |
3008 | use DC::OpenGL; |
2437 | |
3009 | |
2438 | our @ISA = CFPlus::UI::DrawBG::; |
3010 | our @ISA = DC::UI::DrawBG::; |
2439 | |
3011 | |
2440 | my @tex = |
3012 | my @tex = |
2441 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ } |
3013 | map { new_from_file DC::Texture DC::find_rcfile $_ } |
2442 | qw(s1_slider.png s1_slider_bg.png); |
3014 | qw(s1_slider.png s1_slider_bg.png); |
2443 | |
3015 | |
2444 | sub new { |
3016 | sub new { |
2445 | my $class = shift; |
3017 | my $class = shift; |
2446 | |
3018 | |
… | |
… | |
2514 | |
3086 | |
2515 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
3087 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2516 | |
3088 | |
2517 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
3089 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2518 | |
3090 | |
2519 | $self->invoke_mouse_motion ($ev, $x, $y) |
3091 | $self->invoke_mouse_motion ($ev, $x, $y); |
|
|
3092 | |
|
|
3093 | 1 |
2520 | } |
3094 | } |
2521 | |
3095 | |
2522 | sub invoke_mouse_motion { |
3096 | sub invoke_mouse_motion { |
2523 | my ($self, $ev, $x, $y) = @_; |
3097 | my ($self, $ev, $x, $y) = @_; |
2524 | |
3098 | |
… | |
… | |
2540 | sub invoke_mouse_wheel { |
3114 | sub invoke_mouse_wheel { |
2541 | my ($self, $ev) = @_; |
3115 | my ($self, $ev) = @_; |
2542 | |
3116 | |
2543 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
3117 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
2544 | |
3118 | |
|
|
3119 | my $pagepart = $ev->{mod} & DC::KMOD_SHIFT ? 1 : 0.2; |
|
|
3120 | |
2545 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.2); |
3121 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2546 | |
3122 | |
2547 | ! ! $delta |
3123 | 1 |
2548 | } |
3124 | } |
2549 | |
3125 | |
2550 | sub update { |
3126 | sub update { |
2551 | my ($self) = @_; |
3127 | my ($self) = @_; |
2552 | |
3128 | |
… | |
… | |
2601 | glDisable GL_TEXTURE_2D; |
3177 | glDisable GL_TEXTURE_2D; |
2602 | } |
3178 | } |
2603 | |
3179 | |
2604 | ############################################################################# |
3180 | ############################################################################# |
2605 | |
3181 | |
2606 | package CFPlus::UI::ValSlider; |
3182 | package DC::UI::ValSlider; |
2607 | |
3183 | |
2608 | our @ISA = CFPlus::UI::HBox::; |
3184 | our @ISA = DC::UI::HBox::; |
2609 | |
3185 | |
2610 | sub new { |
3186 | sub new { |
2611 | my ($class, %arg) = @_; |
3187 | my ($class, %arg) = @_; |
2612 | |
3188 | |
2613 | my $range = delete $arg{range}; |
3189 | my $range = delete $arg{range}; |
2614 | |
3190 | |
2615 | my $self = $class->SUPER::new ( |
3191 | my $self = $class->SUPER::new ( |
2616 | slider => (new CFPlus::UI::Slider expand => 1, range => $range), |
3192 | slider => (new DC::UI::Slider expand => 1, range => $range), |
2617 | entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}), |
3193 | entry => (new DC::UI::Label text => "", template => delete $arg{template}), |
2618 | to_value => sub { shift }, |
3194 | to_value => sub { shift }, |
2619 | from_value => sub { shift }, |
3195 | from_value => sub { shift }, |
2620 | %arg, |
3196 | %arg, |
2621 | ); |
3197 | ); |
2622 | |
3198 | |
… | |
… | |
2642 | sub set_range { shift->{slider}->set_range (@_) } |
3218 | sub set_range { shift->{slider}->set_range (@_) } |
2643 | sub set_value { shift->{slider}->set_value (@_) } |
3219 | sub set_value { shift->{slider}->set_value (@_) } |
2644 | |
3220 | |
2645 | ############################################################################# |
3221 | ############################################################################# |
2646 | |
3222 | |
2647 | package CFPlus::UI::TextScroller; |
3223 | package DC::UI::TextScroller; |
2648 | |
3224 | |
2649 | our @ISA = CFPlus::UI::HBox::; |
3225 | our @ISA = DC::UI::HBox::; |
2650 | |
3226 | |
2651 | use CFPlus::OpenGL; |
3227 | use DC::OpenGL; |
2652 | |
3228 | |
2653 | sub new { |
3229 | sub new { |
2654 | my $class = shift; |
3230 | my $class = shift; |
2655 | |
3231 | |
2656 | my $self = $class->SUPER::new ( |
3232 | my $self = $class->SUPER::new ( |
… | |
… | |
2658 | can_events => 1, |
3234 | can_events => 1, |
2659 | indent => 0, |
3235 | indent => 0, |
2660 | #font => default_font |
3236 | #font => default_font |
2661 | @_, |
3237 | @_, |
2662 | |
3238 | |
2663 | layout => (new CFPlus::Layout), |
3239 | layout => (new DC::Layout), |
2664 | par => [], |
3240 | par => [], |
|
|
3241 | max_par => 0, |
2665 | height => 0, |
3242 | height => 0, |
2666 | children => [ |
3243 | children => [ |
2667 | (new CFPlus::UI::Empty expand => 1), |
3244 | (new DC::UI::Empty expand => 1), |
2668 | (new CFPlus::UI::Slider vertical => 1), |
3245 | (new DC::UI::Slider vertical => 1), |
2669 | ], |
3246 | ], |
2670 | ); |
3247 | ); |
2671 | |
3248 | |
2672 | $self->{children}[1]->connect (changed => sub { $self->update }); |
3249 | $self->{children}[1]->connect (changed => sub { $self->update }); |
2673 | |
3250 | |
… | |
… | |
2682 | } |
3259 | } |
2683 | |
3260 | |
2684 | sub size_request { |
3261 | sub size_request { |
2685 | my ($self) = @_; |
3262 | my ($self) = @_; |
2686 | |
3263 | |
2687 | my ($empty, $slider) = @{ $self->{children} }; |
3264 | my ($empty, $slider) = $self->visible_children; |
2688 | |
3265 | |
2689 | local $self->{children} = [$empty, $slider]; |
3266 | local $self->{children} = [$empty, $slider]; |
2690 | $self->SUPER::size_request |
3267 | $self->SUPER::size_request |
2691 | } |
3268 | } |
2692 | |
3269 | |
… | |
… | |
2753 | } |
3330 | } |
2754 | |
3331 | |
2755 | sub current_paragraph { |
3332 | sub current_paragraph { |
2756 | my ($self) = @_; |
3333 | my ($self) = @_; |
2757 | |
3334 | |
2758 | $self->force_uptodate; |
|
|
2759 | $self->{top_paragraph} - 1 |
3335 | $self->{top_paragraph} - 1 |
2760 | } |
3336 | } |
2761 | |
3337 | |
2762 | sub scroll_to { |
3338 | sub scroll_to { |
2763 | my ($self, $para) = @_; |
3339 | my ($self, $para) = @_; |
2764 | |
3340 | |
2765 | $self->force_uptodate; |
|
|
2766 | |
|
|
2767 | $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para; |
3341 | $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para; |
2768 | |
3342 | |
2769 | $self->{children}[1]->set_value ($self->{par}[$para]{y}); |
3343 | $self->{scroll_to} = $para; |
|
|
3344 | $self->update; |
2770 | } |
3345 | } |
2771 | |
3346 | |
2772 | sub clear { |
3347 | sub clear { |
2773 | my ($self) = @_; |
3348 | my ($self) = @_; |
2774 | |
3349 | |
… | |
… | |
2796 | |
3371 | |
2797 | $self->add (@{ $para->{widget} }) if @{ $para->{widget} }; |
3372 | $self->add (@{ $para->{widget} }) if @{ $para->{widget} }; |
2798 | push @{$self->{par}}, $para; |
3373 | push @{$self->{par}}, $para; |
2799 | } |
3374 | } |
2800 | |
3375 | |
|
|
3376 | if (my $max = $self->{max_par}) { |
|
|
3377 | shift @{$self->{par}} while @{$self->{par}} > $max; |
|
|
3378 | } |
|
|
3379 | |
2801 | $self->{need_reflow}++; |
3380 | $self->{need_reflow}++; |
2802 | $self->update; |
3381 | $self->update; |
2803 | } |
3382 | } |
2804 | |
3383 | |
2805 | sub scroll_to_bottom { |
3384 | sub scroll_to_bottom { |
2806 | my ($self) = @_; |
3385 | my ($self) = @_; |
2807 | |
3386 | |
2808 | $self->{scroll_to_bottom} = 1; |
3387 | $self->{scroll_to} = $#{$self->{par}}; |
2809 | $self->update; |
3388 | $self->update; |
2810 | } |
3389 | } |
2811 | |
3390 | |
2812 | sub force_uptodate { |
3391 | sub force_uptodate { |
2813 | my ($self) = @_; |
3392 | my ($self) = @_; |
2814 | |
3393 | |
2815 | if (delete $self->{need_reflow}) { |
3394 | if (delete $self->{need_reflow}) { |
2816 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
3395 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2817 | |
3396 | |
2818 | my $height = 0; |
3397 | my $height = 0; |
2819 | my $paridx; |
|
|
2820 | my $top_paragraph; |
|
|
2821 | my $top = int $self->{children}[1]{range}[0]; |
|
|
2822 | |
3398 | |
2823 | for my $para (@{$self->{par}}) { |
3399 | for my $para (@{$self->{par}}) { |
2824 | if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { |
3400 | if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { |
2825 | my $layout = $self->get_layout ($para); |
3401 | my $layout = $self->get_layout ($para); |
2826 | my ($w, $h) = $layout->size; |
3402 | my ($w, $h) = $layout->size; |
… | |
… | |
2829 | $para->{h} = $h; |
3405 | $para->{h} = $h; |
2830 | $para->{wrapped} = $layout->has_wrapped; |
3406 | $para->{wrapped} = $layout->has_wrapped; |
2831 | } |
3407 | } |
2832 | |
3408 | |
2833 | $para->{y} = $height; |
3409 | $para->{y} = $height; |
2834 | |
|
|
2835 | $paridx++; |
|
|
2836 | $top_paragraph ||= $paridx if $height >= $top; |
|
|
2837 | |
|
|
2838 | $height += $para->{h}; |
3410 | $height += $para->{h}; |
2839 | } |
3411 | } |
2840 | |
3412 | |
2841 | $self->{top_paragraph} = $top_paragraph; |
|
|
2842 | $self->{height} = $height; |
3413 | $self->{height} = $height; |
2843 | |
|
|
2844 | $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); |
3414 | $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); |
2845 | |
3415 | |
2846 | delete $self->{texture}; |
3416 | delete $self->{texture}; |
2847 | } |
3417 | } |
2848 | |
3418 | |
2849 | if (delete $self->{scroll_to_bottom}) { |
3419 | if (my $paridx = delete $self->{scroll_to}) { |
2850 | $self->{children}[1]->set_value (1e10); |
3420 | $self->{children}[1]->set_value ($self->{par}[$paridx]{y}); |
2851 | } |
3421 | } |
2852 | } |
3422 | } |
2853 | |
3423 | |
2854 | sub update { |
3424 | sub update { |
2855 | my ($self) = @_; |
3425 | my ($self) = @_; |
… | |
… | |
2863 | $ROOT->on_post_alloc ($self => sub { |
3433 | $ROOT->on_post_alloc ($self => sub { |
2864 | $self->force_uptodate; |
3434 | $self->force_uptodate; |
2865 | |
3435 | |
2866 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
3436 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2867 | |
3437 | |
2868 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
3438 | $self->{texture} ||= new_from_opengl DC::Texture $W, $H, sub { |
2869 | glClearColor 0, 0, 0, 0; |
3439 | glClearColor 0, 0, 0, 0; |
2870 | glClear GL_COLOR_BUFFER_BIT; |
3440 | glClear GL_COLOR_BUFFER_BIT; |
2871 | |
3441 | |
|
|
3442 | package DC::UI::Base; |
|
|
3443 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
|
|
3444 | (0, 0, $self->{w}, $self->{h}); |
|
|
3445 | |
|
|
3446 | my $top = int $self->{children}[1]{range}[0]; |
|
|
3447 | |
|
|
3448 | my $paridx = 0; |
|
|
3449 | my $top_paragraph; |
2872 | my $top = int $self->{children}[1]{range}[0]; |
3450 | my $top = int $self->{children}[1]{range}[0]; |
2873 | |
3451 | |
2874 | my $y0 = $top; |
3452 | my $y0 = $top; |
2875 | my $y1 = $top + $H; |
3453 | my $y1 = $top + $H; |
2876 | |
3454 | |
… | |
… | |
2880 | |
3458 | |
2881 | if ($y0 < $y + $h && $y < $y1) { |
3459 | if ($y0 < $y + $h && $y < $y1) { |
2882 | my $layout = $self->get_layout ($para); |
3460 | my $layout = $self->get_layout ($para); |
2883 | |
3461 | |
2884 | $layout->render ($para->{indent}, $y - $y0); |
3462 | $layout->render ($para->{indent}, $y - $y0); |
|
|
3463 | $layout->draw; |
2885 | |
3464 | |
2886 | if (my @w = @{ $para->{widget} }) { |
3465 | if (my @w = @{ $para->{widget} }) { |
2887 | my @s = $layout->get_shapes; |
3466 | my @s = $layout->get_shapes; |
2888 | |
3467 | |
2889 | for (@w) { |
3468 | for (@w) { |
… | |
… | |
2894 | |
3473 | |
2895 | $_->draw; |
3474 | $_->draw; |
2896 | } |
3475 | } |
2897 | } |
3476 | } |
2898 | } |
3477 | } |
|
|
3478 | |
|
|
3479 | $paridx++; |
|
|
3480 | $top_paragraph ||= $paridx if $y >= $top; |
2899 | } |
3481 | } |
|
|
3482 | |
|
|
3483 | $self->{top_paragraph} = $top_paragraph; |
2900 | }; |
3484 | }; |
2901 | }); |
3485 | }); |
2902 | } |
3486 | } |
2903 | |
3487 | |
2904 | sub reconfigure { |
3488 | sub reconfigure { |
… | |
… | |
2922 | $self->{children}[1]->draw; |
3506 | $self->{children}[1]->draw; |
2923 | } |
3507 | } |
2924 | |
3508 | |
2925 | ############################################################################# |
3509 | ############################################################################# |
2926 | |
3510 | |
2927 | package CFPlus::UI::Animator; |
3511 | package DC::UI::Animator; |
2928 | |
3512 | |
2929 | use CFPlus::OpenGL; |
3513 | use DC::OpenGL; |
2930 | |
3514 | |
2931 | our @ISA = CFPlus::UI::Bin::; |
3515 | our @ISA = DC::UI::Bin::; |
2932 | |
3516 | |
2933 | sub moveto { |
3517 | sub moveto { |
2934 | my ($self, $x, $y) = @_; |
3518 | my ($self, $x, $y) = @_; |
2935 | |
3519 | |
2936 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
3520 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
… | |
… | |
2964 | glPopMatrix; |
3548 | glPopMatrix; |
2965 | } |
3549 | } |
2966 | |
3550 | |
2967 | ############################################################################# |
3551 | ############################################################################# |
2968 | |
3552 | |
2969 | package CFPlus::UI::Flopper; |
3553 | package DC::UI::Flopper; |
2970 | |
3554 | |
2971 | our @ISA = CFPlus::UI::Button::; |
3555 | our @ISA = DC::UI::Button::; |
2972 | |
3556 | |
2973 | sub new { |
3557 | sub new { |
2974 | my $class = shift; |
3558 | my $class = shift; |
2975 | |
3559 | |
2976 | my $self = $class->SUPER::new ( |
3560 | my $self = $class->SUPER::new ( |
… | |
… | |
2988 | $self->{other}->toggle_visibility; |
3572 | $self->{other}->toggle_visibility; |
2989 | } |
3573 | } |
2990 | |
3574 | |
2991 | ############################################################################# |
3575 | ############################################################################# |
2992 | |
3576 | |
2993 | package CFPlus::UI::Tooltip; |
3577 | package DC::UI::Tooltip; |
2994 | |
3578 | |
2995 | our @ISA = CFPlus::UI::Bin::; |
3579 | our @ISA = DC::UI::Bin::; |
2996 | |
3580 | |
2997 | use CFPlus::OpenGL; |
3581 | use DC::OpenGL; |
2998 | |
3582 | |
2999 | sub new { |
3583 | sub new { |
3000 | my $class = shift; |
3584 | my $class = shift; |
3001 | |
3585 | |
3002 | $class->SUPER::new ( |
3586 | $class->SUPER::new ( |
… | |
… | |
3006 | } |
3590 | } |
3007 | |
3591 | |
3008 | sub set_tooltip_from { |
3592 | sub set_tooltip_from { |
3009 | my ($self, $widget) = @_; |
3593 | my ($self, $widget) = @_; |
3010 | |
3594 | |
3011 | $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1 |
|
|
3012 | if $widget->{tooltip} =~ /^#(.*)$/; |
|
|
3013 | |
|
|
3014 | my $tooltip = $widget->{tooltip}; |
3595 | my $tip = $widget->{tooltip}; |
|
|
3596 | $tip = $tip->($widget) if "CODE" eq ref $tip; |
|
|
3597 | |
|
|
3598 | $tip = DC::Pod::section_label tooltip => $1 |
|
|
3599 | if $tip =~ /^#(.*)$/; |
3015 | |
3600 | |
3016 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3601 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3017 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
3602 | $tip .= "\n\n" . (ref $widget) . "\n" |
3018 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3603 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3019 | . "req $widget->{req_w} $widget->{req_h}\n" |
3604 | . "req $widget->{req_w} $widget->{req_h}\n" |
3020 | . "visible $widget->{visible}"; |
3605 | . "visible $widget->{visible}"; |
3021 | } |
3606 | } |
3022 | |
3607 | |
3023 | $tooltip =~ s/^\n+//; |
3608 | $tip =~ s/^\n+//; |
3024 | $tooltip =~ s/\n+$//; |
3609 | $tip =~ s/\n+$//; |
3025 | |
3610 | |
3026 | $self->add (new CFPlus::UI::Label |
3611 | $self->add (new DC::UI::Label |
3027 | markup => $tooltip, |
3612 | markup => $tip, |
3028 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3613 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3029 | fontsize => 0.8, |
3614 | fontsize => 0.8, |
3030 | style => 1, # FLAG_INVERSE |
3615 | style => 1, # FLAG_INVERSE |
3031 | ellipsise => 0, |
3616 | ellipsise => 0, |
3032 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3617 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
… | |
… | |
3070 | } |
3655 | } |
3071 | |
3656 | |
3072 | sub _draw { |
3657 | sub _draw { |
3073 | my ($self) = @_; |
3658 | my ($self) = @_; |
3074 | |
3659 | |
3075 | glTranslate 0.375, 0.375; |
|
|
3076 | |
|
|
3077 | my ($w, $h) = @$self{qw(w h)}; |
3660 | my ($w, $h) = @$self{qw(w h)}; |
3078 | |
3661 | |
3079 | glColor 1, 0.8, 0.4; |
3662 | glColor 1, 0.8, 0.4; |
3080 | glBegin GL_QUADS; |
3663 | glRect 0, 0, $w, $h; |
3081 | glVertex 0 , 0; |
|
|
3082 | glVertex 0 , $h; |
|
|
3083 | glVertex $w, $h; |
|
|
3084 | glVertex $w, 0; |
|
|
3085 | glEnd; |
|
|
3086 | |
3664 | |
3087 | glColor 0, 0, 0; |
3665 | glColor 0, 0, 0; |
3088 | glBegin GL_LINE_LOOP; |
3666 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3089 | glVertex 0 , 0; |
|
|
3090 | glVertex 0 , $h; |
|
|
3091 | glVertex $w, $h; |
|
|
3092 | glVertex $w, 0; |
|
|
3093 | glEnd; |
|
|
3094 | |
3667 | |
3095 | glTranslate 2 - 0.375, 2 - 0.375; |
3668 | glTranslate 2, 2; |
3096 | |
3669 | |
3097 | $self->SUPER::_draw; |
3670 | $self->SUPER::_draw; |
3098 | } |
3671 | } |
3099 | |
3672 | |
3100 | ############################################################################# |
3673 | ############################################################################# |
3101 | |
3674 | |
3102 | package CFPlus::UI::Face; |
3675 | package DC::UI::Face; |
3103 | |
3676 | |
3104 | our @ISA = CFPlus::UI::DrawBG::; |
3677 | our @ISA = DC::UI::DrawBG::; |
3105 | |
3678 | |
3106 | use CFPlus::OpenGL; |
3679 | use DC::OpenGL; |
3107 | |
3680 | |
3108 | sub new { |
3681 | sub new { |
3109 | my $class = shift; |
3682 | my $class = shift; |
3110 | |
3683 | |
3111 | my $self = $class->SUPER::new ( |
3684 | my $self = $class->SUPER::new ( |
|
|
3685 | size_w => 32, |
|
|
3686 | size_h => 8, |
3112 | aspect => 1, |
3687 | aspect => 1, |
3113 | can_events => 0, |
3688 | can_events => 0, |
3114 | @_, |
3689 | @_, |
3115 | ); |
3690 | ); |
3116 | |
3691 | |
3117 | if ($self->{anim} && $self->{animspeed}) { |
3692 | if ($self->{anim} && $self->{animspeed}) { |
3118 | Scalar::Util::weaken (my $widget = $self); |
3693 | DC::weaken (my $widget = $self); |
3119 | |
3694 | |
3120 | $self->{timer} = Event->timer ( |
3695 | $self->{animspeed} = List::Util::max 0.05, $self->{animspeed}; |
3121 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
3696 | $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub { |
3122 | hard => 1, |
3697 | return unless $::CONN; |
3123 | interval => $self->{animspeed}, |
3698 | |
3124 | cb => sub { |
3699 | my $w = $widget |
|
|
3700 | or return; |
|
|
3701 | |
3125 | ++$widget->{frame}; |
3702 | ++$w->{frame}; |
|
|
3703 | $w->update_face; |
|
|
3704 | |
|
|
3705 | # somehow, $widget can go away |
3126 | $widget->update; |
3706 | $w->update; |
3127 | }, |
3707 | $w->update_timer; |
3128 | ); |
3708 | }; |
|
|
3709 | |
|
|
3710 | $self->update_face; |
|
|
3711 | $self->update_timer; |
3129 | } |
3712 | } |
3130 | |
3713 | |
3131 | $self |
3714 | $self |
3132 | } |
3715 | } |
3133 | |
3716 | |
|
|
3717 | sub update_timer { |
|
|
3718 | my ($self) = @_; |
|
|
3719 | |
|
|
3720 | return unless $self->{timer}; |
|
|
3721 | |
|
|
3722 | if ($self->{visible}) { |
|
|
3723 | $self->{timer}->start; |
|
|
3724 | } else { |
|
|
3725 | $self->{timer}->stop; |
|
|
3726 | } |
|
|
3727 | } |
|
|
3728 | |
|
|
3729 | sub update_face { |
|
|
3730 | my ($self) = @_; |
|
|
3731 | |
|
|
3732 | if ($::CONN) { |
|
|
3733 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
|
|
3734 | if ($anim && @$anim) { |
|
|
3735 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
|
|
3736 | delete $self->{face_change_cb}; |
|
|
3737 | |
|
|
3738 | if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) { |
|
|
3739 | unless ($tex->{name} || $tex->{loading}) { |
|
|
3740 | $tex->upload (sub { $self->reconfigure }); |
|
|
3741 | } |
|
|
3742 | } |
|
|
3743 | } |
|
|
3744 | } |
|
|
3745 | } |
|
|
3746 | } |
|
|
3747 | |
3134 | sub size_request { |
3748 | sub size_request { |
3135 | (32, 8) |
3749 | my ($self) = @_; |
|
|
3750 | |
|
|
3751 | if ($::CONN) { |
|
|
3752 | if (my $faceid = $::CONN->{face}[$self->{face}]{id}) { |
|
|
3753 | if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) { |
|
|
3754 | if ($tex->{name}) { |
|
|
3755 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
|
|
3756 | } elsif (!$tex->{loading}) { |
|
|
3757 | $tex->upload (sub { $self->reconfigure }); |
|
|
3758 | } |
|
|
3759 | } |
|
|
3760 | |
|
|
3761 | $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure }); |
|
|
3762 | } |
|
|
3763 | } |
|
|
3764 | |
|
|
3765 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3136 | } |
3766 | } |
3137 | |
3767 | |
3138 | sub update { |
3768 | sub update { |
3139 | my ($self) = @_; |
3769 | my ($self) = @_; |
3140 | |
3770 | |
3141 | return unless $self->{visible}; |
3771 | return unless $self->{visible}; |
3142 | |
3772 | |
3143 | $self->SUPER::update; |
3773 | $self->SUPER::update; |
3144 | } |
3774 | } |
3145 | |
3775 | |
|
|
3776 | sub invoke_visibility_change { |
|
|
3777 | my ($self) = @_; |
|
|
3778 | |
|
|
3779 | $self->update_timer; |
|
|
3780 | |
|
|
3781 | 0 |
|
|
3782 | } |
|
|
3783 | |
3146 | sub _draw { |
3784 | sub _draw { |
3147 | my ($self) = @_; |
3785 | my ($self) = @_; |
3148 | |
3786 | |
3149 | return unless $::CONN; |
|
|
3150 | |
|
|
3151 | $self->SUPER::_draw; |
3787 | $self->SUPER::_draw; |
3152 | |
3788 | |
3153 | my $face; |
3789 | if (my $tex = $self->{tex}) { |
3154 | |
|
|
3155 | if ($self->{frame}) { |
|
|
3156 | my $anim = $::CONN->{anim}[$self->{anim}]; |
|
|
3157 | |
|
|
3158 | $face = $anim->[ $self->{frame} % @$anim ] |
|
|
3159 | if $anim && @$anim; |
|
|
3160 | } |
|
|
3161 | |
|
|
3162 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
|
|
3163 | |
|
|
3164 | if ($tex) { |
|
|
3165 | glEnable GL_TEXTURE_2D; |
3790 | glEnable GL_TEXTURE_2D; |
3166 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3791 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3167 | glColor 0, 0, 0, 1; |
3792 | glColor 0, 0, 0, 1; |
3168 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3793 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3169 | glDisable GL_TEXTURE_2D; |
3794 | glDisable GL_TEXTURE_2D; |
… | |
… | |
3171 | } |
3796 | } |
3172 | |
3797 | |
3173 | sub destroy { |
3798 | sub destroy { |
3174 | my ($self) = @_; |
3799 | my ($self) = @_; |
3175 | |
3800 | |
3176 | $self->{timer}->cancel |
3801 | (delete $self->{timer})->cancel |
3177 | if $self->{timer}; |
3802 | if $self->{timer}; |
3178 | |
3803 | |
3179 | $self->SUPER::destroy; |
3804 | $self->SUPER::destroy; |
3180 | } |
3805 | } |
3181 | |
3806 | |
3182 | ############################################################################# |
3807 | ############################################################################# |
3183 | |
3808 | |
3184 | package CFPlus::UI::Buttonbar; |
3809 | package DC::UI::Buttonbar; |
3185 | |
3810 | |
3186 | our @ISA = CFPlus::UI::HBox::; |
3811 | our @ISA = DC::UI::HBox::; |
3187 | |
3812 | |
3188 | # TODO: should actualyl wrap buttons and other goodies. |
3813 | # TODO: should actually wrap buttons and other goodies. |
3189 | |
3814 | |
3190 | ############################################################################# |
3815 | ############################################################################# |
3191 | |
3816 | |
3192 | package CFPlus::UI::Menu; |
3817 | package DC::UI::Menu; |
3193 | |
3818 | |
3194 | our @ISA = CFPlus::UI::FancyFrame::; |
3819 | our @ISA = DC::UI::Toplevel::; |
3195 | |
3820 | |
3196 | use CFPlus::OpenGL; |
3821 | use DC::OpenGL; |
3197 | |
3822 | |
3198 | sub new { |
3823 | sub new { |
3199 | my $class = shift; |
3824 | my $class = shift; |
3200 | |
3825 | |
3201 | my $self = $class->SUPER::new ( |
3826 | my $self = $class->SUPER::new ( |
3202 | items => [], |
3827 | items => [], |
3203 | z => 100, |
3828 | z => 100, |
3204 | @_, |
3829 | @_, |
3205 | ); |
3830 | ); |
3206 | |
3831 | |
3207 | $self->add ($self->{vbox} = new CFPlus::UI::VBox); |
3832 | $self->add ($self->{vbox} = new DC::UI::VBox); |
3208 | |
3833 | |
3209 | for my $item (@{ $self->{items} }) { |
3834 | for my $item (@{ $self->{items} }) { |
3210 | my ($widget, $cb, $tooltip) = @$item; |
3835 | my ($widget, $cb, $tooltip) = @$item; |
3211 | |
3836 | |
3212 | # handle various types of items, only text for now |
3837 | # handle various types of items, only text for now |
3213 | if (!ref $widget) { |
3838 | if (!ref $widget) { |
3214 | if ($widget =~ /\t/) { |
3839 | if ($widget =~ /\t/) { |
3215 | my ($left, $right) = split /\t/, $widget, 2; |
3840 | my ($left, $right) = split /\t/, $widget, 2; |
3216 | |
3841 | |
3217 | $widget = new CFPlus::UI::HBox |
3842 | $widget = new DC::UI::HBox |
3218 | can_hover => 1, |
3843 | can_hover => 1, |
3219 | can_events => 1, |
3844 | can_events => 1, |
3220 | tooltip => $tooltip, |
3845 | tooltip => $tooltip, |
3221 | children => [ |
3846 | children => [ |
3222 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3847 | (new DC::UI::Label markup => $left, expand => 1), |
3223 | (new CFPlus::UI::Label markup => $right, align => +1), |
3848 | (new DC::UI::Label markup => $right, align => +1), |
3224 | ], |
3849 | ], |
3225 | ; |
3850 | ; |
3226 | |
3851 | |
3227 | } else { |
3852 | } else { |
3228 | $widget = new CFPlus::UI::Label |
3853 | $widget = new DC::UI::Label |
3229 | can_hover => 1, |
3854 | can_hover => 1, |
3230 | can_events => 1, |
3855 | can_events => 1, |
3231 | markup => $widget, |
3856 | markup => $widget, |
3232 | tooltip => $tooltip; |
3857 | tooltip => $tooltip; |
3233 | } |
3858 | } |
… | |
… | |
3281 | 1 |
3906 | 1 |
3282 | } |
3907 | } |
3283 | |
3908 | |
3284 | ############################################################################# |
3909 | ############################################################################# |
3285 | |
3910 | |
3286 | package CFPlus::UI::Multiplexer; |
3911 | package DC::UI::Multiplexer; |
3287 | |
3912 | |
3288 | our @ISA = CFPlus::UI::Container::; |
3913 | our @ISA = DC::UI::Container::; |
3289 | |
3914 | |
3290 | sub new { |
3915 | sub new { |
3291 | my $class = shift; |
3916 | my $class = shift; |
3292 | |
3917 | |
3293 | my $self = $class->SUPER::new ( |
3918 | my $self = $class->SUPER::new ( |
… | |
… | |
3354 | $self->{current}->draw; |
3979 | $self->{current}->draw; |
3355 | } |
3980 | } |
3356 | |
3981 | |
3357 | ############################################################################# |
3982 | ############################################################################# |
3358 | |
3983 | |
3359 | package CFPlus::UI::Notebook; |
3984 | package DC::UI::Notebook; |
3360 | |
3985 | |
|
|
3986 | use DC::OpenGL; |
|
|
3987 | |
3361 | our @ISA = CFPlus::UI::VBox::; |
3988 | our @ISA = DC::UI::VBox::; |
3362 | |
3989 | |
3363 | sub new { |
3990 | sub new { |
3364 | my $class = shift; |
3991 | my $class = shift; |
3365 | |
3992 | |
3366 | my $self = $class->SUPER::new ( |
3993 | my $self = $class->SUPER::new ( |
3367 | buttonbar => (new CFPlus::UI::Buttonbar), |
3994 | buttonbar => (new DC::UI::Buttonbar), |
3368 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3995 | multiplexer => (new DC::UI::Multiplexer expand => 1), |
|
|
3996 | active_outline => [.7, .7, 0.2], |
3369 | # filter => # will be put between multiplexer and $self |
3997 | # filter => # will be put between multiplexer and $self |
3370 | @_, |
3998 | @_, |
3371 | ); |
3999 | ); |
3372 | |
4000 | |
3373 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
4001 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3374 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
4002 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3375 | |
4003 | |
|
|
4004 | { |
|
|
4005 | Scalar::Util::weaken (my $wself = $self); |
|
|
4006 | |
|
|
4007 | $self->{multiplexer}->connect (c_add => sub { |
|
|
4008 | my ($mplex, $widgets) = @_; |
|
|
4009 | |
|
|
4010 | for my $child (@$widgets) { |
|
|
4011 | Scalar::Util::weaken $child; |
|
|
4012 | $child->{c_tab_} ||= do { |
|
|
4013 | my $tab = |
|
|
4014 | (UNIVERSAL::isa $child->{c_tab}, "DC::UI::Base") |
|
|
4015 | ? $child->{c_tab} |
|
|
4016 | : new DC::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; |
|
|
4017 | |
|
|
4018 | $tab->connect (activate => sub { |
|
|
4019 | $wself->set_current_page ($child); |
|
|
4020 | }); |
|
|
4021 | |
|
|
4022 | $tab |
|
|
4023 | }; |
|
|
4024 | |
|
|
4025 | $self->{buttonbar}->add ($child->{c_tab_}); |
|
|
4026 | } |
|
|
4027 | }); |
|
|
4028 | |
|
|
4029 | $self->{multiplexer}->connect (c_remove => sub { |
|
|
4030 | my ($mplex, $widgets) = @_; |
|
|
4031 | |
|
|
4032 | for my $child (@$widgets) { |
|
|
4033 | $wself->{buttonbar}->remove ($child->{c_tab_}); |
|
|
4034 | } |
|
|
4035 | }); |
|
|
4036 | } |
|
|
4037 | |
3376 | $self |
4038 | $self |
3377 | } |
4039 | } |
3378 | |
4040 | |
3379 | sub add { |
4041 | sub add { |
|
|
4042 | my ($self, @widgets) = @_; |
|
|
4043 | |
|
|
4044 | $self->{multiplexer}->add (@widgets) |
|
|
4045 | } |
|
|
4046 | |
|
|
4047 | sub remove { |
|
|
4048 | my ($self, @widgets) = @_; |
|
|
4049 | |
|
|
4050 | $self->{multiplexer}->remove (@widgets) |
|
|
4051 | } |
|
|
4052 | |
|
|
4053 | sub pages { |
|
|
4054 | my ($self) = @_; |
|
|
4055 | $self->{multiplexer}->children |
|
|
4056 | } |
|
|
4057 | |
|
|
4058 | sub add_tab { |
3380 | my ($self, $title, $widget, $tooltip) = @_; |
4059 | my ($self, $title, $widget, $tooltip) = @_; |
3381 | |
4060 | |
3382 | Scalar::Util::weaken $self; |
4061 | $title = [$title, $tooltip] unless ref $title; |
|
|
4062 | $widget->{c_tab} = $title; |
3383 | |
4063 | |
3384 | $self->{buttonbar}->add (new CFPlus::UI::Button |
|
|
3385 | markup => $title, |
|
|
3386 | tooltip => $tooltip, |
|
|
3387 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3388 | ); |
|
|
3389 | |
|
|
3390 | $self->{multiplexer}->add ($widget); |
4064 | $self->add ($widget); |
3391 | } |
4065 | } |
3392 | |
4066 | |
3393 | sub get_current_page { |
4067 | sub get_current_page { |
3394 | my ($self) = @_; |
4068 | my ($self) = @_; |
3395 | |
4069 | |
… | |
… | |
3401 | |
4075 | |
3402 | $self->{multiplexer}->set_current_page ($page); |
4076 | $self->{multiplexer}->set_current_page ($page); |
3403 | $self->emit (page_changed => $self->{multiplexer}{current}); |
4077 | $self->emit (page_changed => $self->{multiplexer}{current}); |
3404 | } |
4078 | } |
3405 | |
4079 | |
|
|
4080 | sub _draw { |
|
|
4081 | my ($self) = @_; |
|
|
4082 | |
|
|
4083 | $self->SUPER::_draw (); |
|
|
4084 | |
|
|
4085 | if (my $cur = $self->{multiplexer}{current}) { |
|
|
4086 | if ($cur = $cur->{c_tab_}) { |
|
|
4087 | glTranslate $self->{buttonbar}{x} + $cur->{x}, |
|
|
4088 | $self->{buttonbar}{y} + $cur->{y}; |
|
|
4089 | glLineWidth 3; |
|
|
4090 | #glEnable GL_BLEND; |
|
|
4091 | #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
4092 | glColor @{$self->{active_outline}}; |
|
|
4093 | glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5; |
|
|
4094 | glLineWidth 1; |
|
|
4095 | #glDisable GL_BLEND; |
|
|
4096 | } |
|
|
4097 | } |
|
|
4098 | } |
|
|
4099 | |
3406 | ############################################################################# |
4100 | ############################################################################# |
3407 | |
4101 | |
3408 | package CFPlus::UI::Selector; |
4102 | package DC::UI::Selector; |
3409 | |
4103 | |
3410 | use utf8; |
4104 | use utf8; |
3411 | |
4105 | |
3412 | our @ISA = CFPlus::UI::Button::; |
4106 | our @ISA = DC::UI::Button::; |
3413 | |
4107 | |
3414 | sub new { |
4108 | sub new { |
3415 | my $class = shift; |
4109 | my $class = shift; |
3416 | |
4110 | |
3417 | my $self = $class->SUPER::new ( |
4111 | my $self = $class->SUPER::new ( |
… | |
… | |
3434 | my ($value, $title, $tooltip) = @$_; |
4128 | my ($value, $title, $tooltip) = @$_; |
3435 | |
4129 | |
3436 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
4130 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
3437 | } |
4131 | } |
3438 | |
4132 | |
3439 | CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); |
4133 | DC::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3440 | } |
4134 | } |
3441 | |
4135 | |
3442 | sub _set_value { |
4136 | sub _set_value { |
3443 | my ($self, $value) = @_; |
4137 | my ($self, $value) = @_; |
3444 | |
4138 | |
3445 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
4139 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} }; |
|
|
4140 | $item ||= $self->{options}[0] |
3446 | or return; |
4141 | or return; |
3447 | |
4142 | |
3448 | $self->{value} = $item->[0]; |
4143 | $self->{value} = $item->[0]; |
3449 | $self->set_markup ("$item->[1] ⇓"); |
4144 | $self->set_markup ("$item->[1] ⇓"); |
3450 | $self->set_tooltip ($item->[2]); |
4145 | # $self->set_tooltip ($item->[2]); |
3451 | } |
4146 | } |
3452 | |
4147 | |
3453 | sub set_value { |
4148 | sub set_value { |
3454 | my ($self, $value) = @_; |
4149 | my ($self, $value) = @_; |
3455 | |
4150 | |
… | |
… | |
3457 | |
4152 | |
3458 | $self->_set_value ($value); |
4153 | $self->_set_value ($value); |
3459 | $self->emit (changed => $value); |
4154 | $self->emit (changed => $value); |
3460 | } |
4155 | } |
3461 | |
4156 | |
|
|
4157 | sub set_options { |
|
|
4158 | my ($self, $options) = @_; |
|
|
4159 | |
|
|
4160 | $self->{options} = $options; |
|
|
4161 | $self->_set_value ($self->{value}); |
|
|
4162 | } |
|
|
4163 | |
3462 | ############################################################################# |
4164 | ############################################################################# |
3463 | |
4165 | |
3464 | package CFPlus::UI::Statusbox; |
4166 | package DC::UI::Statusbox; |
3465 | |
4167 | |
3466 | our @ISA = CFPlus::UI::VBox::; |
4168 | our @ISA = DC::UI::VBox::; |
3467 | |
4169 | |
3468 | sub new { |
4170 | sub new { |
3469 | my $class = shift; |
4171 | my $class = shift; |
3470 | |
4172 | |
3471 | my $self = $class->SUPER::new ( |
4173 | my $self = $class->SUPER::new ( |
3472 | fontsize => 0.8, |
4174 | fontsize => 0.8, |
3473 | @_, |
4175 | @_, |
3474 | ); |
4176 | ); |
3475 | |
4177 | |
3476 | Scalar::Util::weaken (my $this = $self); |
4178 | DC::weaken (my $this = $self); |
3477 | |
4179 | |
3478 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
4180 | $self->{timer} = EV::timer 1, 1, sub { $this->reorder }; |
3479 | |
4181 | |
3480 | $self |
4182 | $self |
3481 | } |
4183 | } |
3482 | |
4184 | |
3483 | sub reorder { |
4185 | sub reorder { |
3484 | my ($self) = @_; |
4186 | my ($self) = @_; |
3485 | my $NOW = Time::HiRes::time; |
4187 | my $NOW = Time::HiRes::time; |
3486 | |
4188 | |
3487 | # freeze display when hovering over any label |
4189 | # freeze display when hovering over any label |
3488 | return if $CFPlus::UI::TOOLTIP->{owner} |
4190 | return if $DC::UI::TOOLTIP->{owner} |
3489 | && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label}, |
4191 | && grep $DC::UI::TOOLTIP->{owner} == $_->{label}, |
3490 | values %{ $self->{item} }; |
4192 | values %{ $self->{item} }; |
3491 | |
4193 | |
3492 | while (my ($k, $v) = each %{ $self->{item} }) { |
4194 | while (my ($k, $v) = each %{ $self->{item} }) { |
3493 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
4195 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
3494 | } |
4196 | } |
|
|
4197 | |
|
|
4198 | $self->{timer}->set (1, 1); |
3495 | |
4199 | |
3496 | my @widgets; |
4200 | my @widgets; |
3497 | |
4201 | |
3498 | my @items = sort { |
4202 | my @items = sort { |
3499 | $a->{pri} <=> $b->{pri} |
4203 | $a->{pri} <=> $b->{pri} |
3500 | or $b->{id} <=> $a->{id} |
4204 | or $b->{id} <=> $a->{id} |
3501 | } values %{ $self->{item} }; |
4205 | } values %{ $self->{item} }; |
3502 | |
|
|
3503 | $self->{timer}->interval (1); |
|
|
3504 | |
4206 | |
3505 | my $count = 10 + 1; |
4207 | my $count = 10 + 1; |
3506 | for my $item (@items) { |
4208 | for my $item (@items) { |
3507 | last unless --$count; |
4209 | last unless --$count; |
3508 | |
4210 | |
… | |
… | |
3515 | for ($short) { |
4217 | for ($short) { |
3516 | s/^\s+//; |
4218 | s/^\s+//; |
3517 | s/\s+/ /g; |
4219 | s/\s+/ /g; |
3518 | } |
4220 | } |
3519 | |
4221 | |
3520 | new CFPlus::UI::Label |
4222 | new DC::UI::Label |
3521 | markup => $short, |
4223 | markup => $short, |
3522 | tooltip => $item->{tooltip}, |
4224 | tooltip => $item->{tooltip}, |
3523 | tooltip_font => $::FONT_PROP, |
4225 | tooltip_font => $::FONT_PROP, |
3524 | tooltip_width => 0.67, |
4226 | tooltip_width => 0.67, |
3525 | fontsize => $item->{fontsize} || $self->{fontsize}, |
4227 | fontsize => $item->{fontsize} || $self->{fontsize}, |
… | |
… | |
3532 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
4234 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
3533 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
4235 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
3534 | $label->update; |
4236 | $label->update; |
3535 | $label->set_max_size (undef, $label->{req_h} * $diff) |
4237 | $label->set_max_size (undef, $label->{req_h} * $diff) |
3536 | if $diff < 1; |
4238 | if $diff < 1; |
3537 | $self->{timer}->interval (1/30); |
4239 | $self->{timer}->set (1/30, 1/30); |
3538 | } else { |
4240 | } else { |
3539 | $label->{fg}[3] = $item->{fg}[3] || 1; |
4241 | $label->{fg}[3] = $item->{fg}[3] || 1; |
3540 | } |
4242 | } |
3541 | |
4243 | |
3542 | push @widgets, $label; |
4244 | push @widgets, $label; |
… | |
… | |
3604 | $self->SUPER::destroy; |
4306 | $self->SUPER::destroy; |
3605 | } |
4307 | } |
3606 | |
4308 | |
3607 | ############################################################################# |
4309 | ############################################################################# |
3608 | |
4310 | |
3609 | package CFPlus::UI::Inventory; |
|
|
3610 | |
|
|
3611 | our @ISA = CFPlus::UI::Table::; |
|
|
3612 | |
|
|
3613 | sub new { |
|
|
3614 | my $class = shift; |
|
|
3615 | |
|
|
3616 | my $self = $class->SUPER::new ( |
|
|
3617 | col_expand => [0, 1, 0], |
|
|
3618 | items => [], |
|
|
3619 | @_, |
|
|
3620 | ); |
|
|
3621 | |
|
|
3622 | $self->set_sort_order (undef); |
|
|
3623 | |
|
|
3624 | $self |
|
|
3625 | } |
|
|
3626 | |
|
|
3627 | sub update_items { |
|
|
3628 | my ($self) = @_; |
|
|
3629 | |
|
|
3630 | $self->clear; |
|
|
3631 | |
|
|
3632 | my @item = $self->{sort}->(@{ $self->{items} }); |
|
|
3633 | |
|
|
3634 | my @adds; |
|
|
3635 | my $row = 0; |
|
|
3636 | for my $item ($self->{sort}->(@{ $self->{items} })) { |
|
|
3637 | CFPlus::Item::update_widgets $item; |
|
|
3638 | |
|
|
3639 | push @adds, 0, $row, $item->{face_widget}; |
|
|
3640 | push @adds, 1, $row, $item->{desc_widget}; |
|
|
3641 | push @adds, 2, $row, $item->{weight_widget}; |
|
|
3642 | |
|
|
3643 | $row++; |
|
|
3644 | } |
|
|
3645 | |
|
|
3646 | $self->add (@adds); |
|
|
3647 | } |
|
|
3648 | |
|
|
3649 | sub set_sort_order { |
|
|
3650 | my ($self, $order) = @_; |
|
|
3651 | |
|
|
3652 | $self->{sort} = $order ||= sub { |
|
|
3653 | sort { |
|
|
3654 | $a->{type} <=> $b->{type} |
|
|
3655 | or $a->{name} cmp $b->{name} |
|
|
3656 | } @_ |
|
|
3657 | }; |
|
|
3658 | |
|
|
3659 | $self->update_items; |
|
|
3660 | } |
|
|
3661 | |
|
|
3662 | sub set_items { |
|
|
3663 | my ($self, $items) = @_; |
|
|
3664 | |
|
|
3665 | $self->{items} = [$items ? values %$items : ()]; |
|
|
3666 | $self->update_items; |
|
|
3667 | } |
|
|
3668 | |
|
|
3669 | ############################################################################# |
|
|
3670 | |
|
|
3671 | package CFPlus::UI::SpellList; |
|
|
3672 | |
|
|
3673 | our @ISA = CFPlus::UI::Table::; |
|
|
3674 | |
|
|
3675 | sub new { |
|
|
3676 | my $class = shift; |
|
|
3677 | |
|
|
3678 | my $self = $class->SUPER::new ( |
|
|
3679 | binding => [], |
|
|
3680 | commands => [], |
|
|
3681 | @_, |
|
|
3682 | ) |
|
|
3683 | } |
|
|
3684 | |
|
|
3685 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>"; |
|
|
3686 | |
|
|
3687 | my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3688 | "<b>Name</b>. The name of the spell.$TOOLTIP_ALL"); |
|
|
3689 | my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3690 | "<b>Skill</b>. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL"); |
|
|
3691 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3692 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL"); |
|
|
3693 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3694 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL"); |
|
|
3695 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3696 | "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL"); |
|
|
3697 | |
|
|
3698 | sub rebuild_spell_list { |
|
|
3699 | my ($self) = @_; |
|
|
3700 | |
|
|
3701 | $CFPlus::UI::ROOT->on_refresh ($self => sub { |
|
|
3702 | $self->clear; |
|
|
3703 | |
|
|
3704 | return unless $::CONN; |
|
|
3705 | |
|
|
3706 | $self->add (1, 0, new CFPlus::UI::Label text => "Spell Name", @TOOLTIP_NAME); |
|
|
3707 | $self->add (2, 0, new CFPlus::UI::Label text => "Skill", @TOOLTIP_SKILL); |
|
|
3708 | $self->add (3, 0, new CFPlus::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
|
|
3709 | $self->add (4, 0, new CFPlus::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
|
|
3710 | $self->add (5, 0, new CFPlus::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
|
|
3711 | |
|
|
3712 | my $row = 0; |
|
|
3713 | |
|
|
3714 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
|
|
3715 | my $spell = $self->{spell}{$_}; |
|
|
3716 | |
|
|
3717 | $row++; |
|
|
3718 | |
|
|
3719 | my $spell_cb = sub { |
|
|
3720 | my ($widget, $ev) = @_; |
|
|
3721 | |
|
|
3722 | if ($ev->{button} == 1) { |
|
|
3723 | $::CONN->user_send ("cast $spell->{name}"); |
|
|
3724 | } elsif ($ev->{button} == 2) { |
|
|
3725 | $::CONN->user_send ("invoke $spell->{name}"); |
|
|
3726 | } elsif ($ev->{button} == 3) { |
|
|
3727 | (new CFPlus::UI::Menu |
|
|
3728 | items => [ |
|
|
3729 | ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
|
|
3730 | ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
|
|
3731 | ], |
|
|
3732 | )->popup ($ev); |
|
|
3733 | } else { |
|
|
3734 | return 0; |
|
|
3735 | } |
|
|
3736 | |
|
|
3737 | 1 |
|
|
3738 | }; |
|
|
3739 | |
|
|
3740 | my $tooltip = "$spell->{message}$TOOLTIP_ALL"; |
|
|
3741 | |
|
|
3742 | #TODO: add path info to tooltip |
|
|
3743 | #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path}); |
|
|
3744 | |
|
|
3745 | $self->add (0, $row, new CFPlus::UI::Face |
|
|
3746 | face => $spell->{face}, |
|
|
3747 | can_hover => 1, |
|
|
3748 | can_events => 1, |
|
|
3749 | tooltip => $tooltip, |
|
|
3750 | on_button_down => $spell_cb, |
|
|
3751 | ); |
|
|
3752 | |
|
|
3753 | $self->add (1, $row, new CFPlus::UI::Label |
|
|
3754 | expand => 1, |
|
|
3755 | text => $spell->{name}, |
|
|
3756 | can_hover => 1, |
|
|
3757 | can_events => 1, |
|
|
3758 | tooltip => $tooltip, |
|
|
3759 | on_button_down => $spell_cb, |
|
|
3760 | ); |
|
|
3761 | |
|
|
3762 | $self->add (2, $row, new CFPlus::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL); |
|
|
3763 | $self->add (3, $row, new CFPlus::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
|
|
3764 | $self->add (4, $row, new CFPlus::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
|
|
3765 | $self->add (5, $row, new CFPlus::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
|
|
3766 | } |
|
|
3767 | }); |
|
|
3768 | } |
|
|
3769 | |
|
|
3770 | sub add_spell { |
|
|
3771 | my ($self, $spell) = @_; |
|
|
3772 | |
|
|
3773 | $self->{spell}->{$spell->{name}} = $spell; |
|
|
3774 | $self->rebuild_spell_list; |
|
|
3775 | } |
|
|
3776 | |
|
|
3777 | sub remove_spell { |
|
|
3778 | my ($self, $spell) = @_; |
|
|
3779 | |
|
|
3780 | delete $self->{spell}->{$spell->{name}}; |
|
|
3781 | $self->rebuild_spell_list; |
|
|
3782 | } |
|
|
3783 | |
|
|
3784 | sub clear_spells { |
|
|
3785 | my ($self) = @_; |
|
|
3786 | |
|
|
3787 | $self->{spell} = {}; |
|
|
3788 | $self->rebuild_spell_list; |
|
|
3789 | } |
|
|
3790 | |
|
|
3791 | ############################################################################# |
|
|
3792 | |
|
|
3793 | package CFPlus::UI::Root; |
4311 | package DC::UI::Root; |
3794 | |
4312 | |
3795 | our @ISA = CFPlus::UI::Container::; |
4313 | our @ISA = DC::UI::Container::; |
3796 | |
4314 | |
3797 | use List::Util qw(min max); |
4315 | use List::Util qw(min max); |
3798 | |
4316 | |
3799 | use CFPlus::OpenGL; |
4317 | use DC::OpenGL; |
3800 | |
4318 | |
3801 | sub new { |
4319 | sub new { |
3802 | my $class = shift; |
4320 | my $class = shift; |
3803 | |
4321 | |
3804 | my $self = $class->SUPER::new ( |
4322 | my $self = $class->SUPER::new ( |
3805 | visible => 1, |
4323 | visible => 1, |
3806 | @_, |
4324 | @_, |
3807 | ); |
4325 | ); |
3808 | |
4326 | |
3809 | Scalar::Util::weaken ($self->{root} = $self); |
4327 | DC::weaken ($self->{root} = $self); |
3810 | |
4328 | |
3811 | $self |
4329 | $self |
3812 | } |
4330 | } |
3813 | |
4331 | |
3814 | sub size_request { |
4332 | sub size_request { |
… | |
… | |
3862 | } |
4380 | } |
3863 | |
4381 | |
3864 | sub update { |
4382 | sub update { |
3865 | my ($self) = @_; |
4383 | my ($self) = @_; |
3866 | |
4384 | |
3867 | $::WANT_REFRESH++; |
4385 | $::WANT_REFRESH = 1; |
3868 | } |
4386 | } |
3869 | |
4387 | |
3870 | sub add { |
4388 | sub add { |
3871 | my ($self, @children) = @_; |
4389 | my ($self, @children) = @_; |
3872 | |
4390 | |
… | |
… | |
3909 | while ($self->{refresh_hook}) { |
4427 | while ($self->{refresh_hook}) { |
3910 | $_->() |
4428 | $_->() |
3911 | for values %{delete $self->{refresh_hook}}; |
4429 | for values %{delete $self->{refresh_hook}}; |
3912 | } |
4430 | } |
3913 | |
4431 | |
3914 | if ($self->{realloc}) { |
4432 | while ($self->{realloc}) { |
3915 | my %queue; |
4433 | my %queue; |
3916 | my @queue; |
4434 | my @queue; |
3917 | my $widget; |
4435 | my $widget; |
3918 | |
4436 | |
3919 | outer: |
4437 | outer: |
… | |
… | |
3966 | } |
4484 | } |
3967 | } |
4485 | } |
3968 | |
4486 | |
3969 | delete $self->{realloc}{$widget+0}; |
4487 | delete $self->{realloc}{$widget+0}; |
3970 | } |
4488 | } |
3971 | } |
|
|
3972 | |
4489 | |
3973 | while (my $size_alloc = delete $self->{size_alloc}) { |
4490 | while (my $size_alloc = delete $self->{size_alloc}) { |
3974 | my @queue = sort { $b->{visible} <=> $a->{visible} } |
4491 | my @queue = sort { $a->{visible} <=> $b->{visible} } |
3975 | values %$size_alloc; |
4492 | values %$size_alloc; |
3976 | |
4493 | |
3977 | while () { |
4494 | while () { |
3978 | my $widget = pop @queue || last; |
4495 | my $widget = pop @queue || last; |
3979 | |
4496 | |
3980 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4497 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
3981 | |
4498 | |
3982 | $w = 0 if $w < 0; |
|
|
3983 | $h = 0 if $h < 0; |
|
|
3984 | |
|
|
3985 | $w = max $widget->{min_w}, $w; |
4499 | $w = max $widget->{min_w}, $w; |
3986 | $h = max $widget->{min_h}, $h; |
4500 | $h = max $widget->{min_h}, $h; |
3987 | |
4501 | |
3988 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4502 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
3989 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4503 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
3990 | |
4504 | |
3991 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4505 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
3992 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4506 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
3993 | |
4507 | |
3994 | $w = int $w + 0.5; |
4508 | $w = int $w + 0.5; |
3995 | $h = int $h + 0.5; |
4509 | $h = int $h + 0.5; |
3996 | |
4510 | |
3997 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4511 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
3998 | $widget->{old_w} = $widget->{w}; |
4512 | $widget->{old_w} = $widget->{w}; |
3999 | $widget->{old_h} = $widget->{h}; |
4513 | $widget->{old_h} = $widget->{h}; |
4000 | |
4514 | |
4001 | $widget->{w} = $w; |
4515 | $widget->{w} = $w; |
4002 | $widget->{h} = $h; |
4516 | $widget->{h} = $h; |
4003 | |
4517 | |
4004 | $widget->emit (size_allocate => $w, $h); |
4518 | $widget->emit (size_allocate => $w, $h); |
|
|
4519 | } |
4005 | } |
4520 | } |
4006 | } |
4521 | } |
4007 | } |
4522 | } |
4008 | |
4523 | |
4009 | while ($self->{post_alloc_hook}) { |
4524 | while ($self->{post_alloc_hook}) { |
4010 | $_->() |
4525 | $_->() |
4011 | for values %{delete $self->{post_alloc_hook}}; |
4526 | for values %{delete $self->{post_alloc_hook}}; |
4012 | } |
4527 | } |
4013 | |
|
|
4014 | |
4528 | |
4015 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
4529 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
4016 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
4530 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
4017 | glClear GL_COLOR_BUFFER_BIT; |
4531 | glClear GL_COLOR_BUFFER_BIT; |
4018 | |
4532 | |
… | |
… | |
4021 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
4535 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
4022 | glMatrixMode GL_MODELVIEW; |
4536 | glMatrixMode GL_MODELVIEW; |
4023 | glLoadIdentity; |
4537 | glLoadIdentity; |
4024 | |
4538 | |
4025 | { |
4539 | { |
4026 | package CFPlus::UI::Base; |
4540 | package DC::UI::Base; |
4027 | |
4541 | |
4028 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
4542 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
4029 | (0, 0, $self->{w}, $self->{h}); |
4543 | (0, 0, $self->{w}, $self->{h}); |
4030 | } |
|
|
4031 | |
4544 | |
4032 | $self->_draw; |
4545 | $self->_draw; |
|
|
4546 | } |
4033 | } |
4547 | } |
4034 | |
4548 | |
4035 | ############################################################################# |
4549 | ############################################################################# |
4036 | |
4550 | |
4037 | package CFPlus::UI; |
4551 | package DC::UI; |
4038 | |
4552 | |
4039 | $ROOT = new CFPlus::UI::Root; |
4553 | $ROOT = new DC::UI::Root; |
4040 | $TOOLTIP = new CFPlus::UI::Tooltip z => 900; |
4554 | $TOOLTIP = new DC::UI::Tooltip z => 900; |
4041 | |
4555 | |
4042 | 1 |
4556 | 1 |
4043 | |
4557 | |