ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.402 by root, Sat Jul 21 20:49:44 2007 UTC vs.
Revision 1.458 by root, Fri Dec 28 15:05:33 2007 UTC

1package CFPlus::UI; 1package DC::UI;
2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5 5
6use List::Util (); 6use List::Util ();
7use Event;
8 7
9use CFPlus; 8use DC;
10use CFPlus::Pod; 9use DC::Pod;
11use CFPlus::Texture; 10use DC::Texture;
12 11
13our ($FOCUS, $HOVER, $GRAB); # various widgets 12our ($FOCUS, $HOVER, $GRAB); # various widgets
14 13
15our $LAYOUT; 14our $LAYOUT;
16our $ROOT; 15our $ROOT;
17our $TOOLTIP; 16our $TOOLTIP;
18our $BUTTON_STATE; 17our $BUTTON_STATE;
19 18
20our %WIDGET; # all widgets, weak-referenced 19our %WIDGET; # all widgets, weak-referenced
21 20
22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { 21our $TOOLTIP_WATCHER = EV::timer_ns 0, 0.03, sub {
22 $_[0]->stop;
23
23 if (!$GRAB) { 24 if (!$GRAB) {
24 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 25 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
25 if (length $widget->{tooltip}) { 26 if (length $widget->{tooltip}) {
26 if ($TOOLTIP->{owner} != $widget) { 27 if ($TOOLTIP->{owner} != $widget) {
27 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; 28 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
30 $TOOLTIP->{owner} = $widget; 31 $TOOLTIP->{owner} = $widget;
31 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner}; 32 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner};
32 33
33 return if $ENV{CFPLUS_DEBUG} & 8; 34 return if $ENV{CFPLUS_DEBUG} & 8;
34 35
35 my $tip = $widget->{tooltip};
36
37 $tip = $tip->($widget) if CODE:: eq ref $tip;
38
39 $TOOLTIP->set_tooltip_from ($widget); 36 $TOOLTIP->set_tooltip_from ($widget);
40 $TOOLTIP->show; 37 $TOOLTIP->show;
41 } 38 }
42 39
43 return; 40 return;
46 } 43 }
47 44
48 $TOOLTIP->hide; 45 $TOOLTIP->hide;
49 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; 46 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
50 delete $TOOLTIP->{owner}; 47 delete $TOOLTIP->{owner};
51}); 48};
52 49
53sub get_layout { 50sub get_layout {
54 my $layout; 51 my $layout;
55 52
56 for (grep { $_->{name} } values %WIDGET) { 53 for (grep { $_->{name} } values %WIDGET) {
91 my $hover = $HOVER; $HOVER = $widget; 88 my $hover = $HOVER; $HOVER = $widget;
92 89
93 $hover->update if $hover && $hover->{can_hover}; 90 $hover->update if $hover && $hover->{can_hover};
94 $HOVER->update if $HOVER && $HOVER->{can_hover}; 91 $HOVER->update if $HOVER && $HOVER->{can_hover};
95 92
96 $TOOLTIP_WATCHER->start; 93 $TOOLTIP_WATCHER->again;
97 } 94 }
98} 95}
99 96
100sub feed_sdl_button_down_event { 97sub feed_sdl_button_down_event {
101 my ($ev) = @_; 98 my ($ev) = @_;
107 my $widget = $ROOT->find_widget ($x, $y); 104 my $widget = $ROOT->find_widget ($x, $y);
108 105
109 $GRAB = $widget; 106 $GRAB = $widget;
110 $GRAB->update if $GRAB; 107 $GRAB->update if $GRAB;
111 108
112 $TOOLTIP_WATCHER->cb->(); 109 $TOOLTIP_WATCHER->invoke;
113 } 110 }
114 111
115 if ($GRAB) { 112 if ($GRAB) {
116 if ($ev->{button} == 4 || $ev->{button} == 5) { 113 if ($ev->{button} == 4 || $ev->{button} == 5) {
117 # mousewheel 114 # mousewheel
118 my $delta = $ev->{button} * 2 - 9; 115 my $delta = $ev->{button} * 2 - 9;
119 my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT; 116 my $shift = $ev->{mod} & DC::KMOD_SHIFT;
120 117
121 $ev->{dx} = $shift ? $delta : 0; 118 $ev->{dx} = $shift ? $delta : 0;
122 $ev->{dy} = $shift ? 0 : $delta; 119 $ev->{dy} = $shift ? 0 : $delta;
123 120
124 $GRAB->emit (mouse_wheel => $ev); 121 $GRAB->emit (mouse_wheel => $ev);
142 my $grab = $GRAB; undef $GRAB; 139 my $grab = $GRAB; undef $GRAB;
143 $grab->update if $grab; 140 $grab->update if $grab;
144 $GRAB->update if $GRAB; 141 $GRAB->update if $GRAB;
145 142
146 check_hover $widget; 143 check_hover $widget;
147 $TOOLTIP_WATCHER->cb->(); 144 $TOOLTIP_WATCHER->invoke;
148 } 145 }
149} 146}
150 147
151sub feed_sdl_motion_event { 148sub feed_sdl_motion_event {
152 my ($ev) = @_; 149 my ($ev) = @_;
214 reconfigure_widgets; 211 reconfigure_widgets;
215} 212}
216 213
217############################################################################# 214#############################################################################
218 215
219package CFPlus::UI::Event; 216package DC::UI::Event;
220 217
221sub xy { 218sub xy {
222 $_[1]->coord2local ($_[0]{x}, $_[0]{y}) 219 $_[1]->coord2local ($_[0]{x}, $_[0]{y})
223} 220}
224 221
225############################################################################# 222#############################################################################
226 223
227package CFPlus::UI::Base; 224package DC::UI::Base;
228 225
229use strict; 226use strict;
230 227
231use CFPlus::OpenGL; 228use DC::OpenGL;
232 229
233sub new { 230sub new {
234 my $class = shift; 231 my $class = shift;
235 232
236 my $self = bless { 233 my $self = bless {
241 h => undef, 238 h => undef,
242 can_events => 1, 239 can_events => 1,
243 @_ 240 @_
244 }, $class; 241 }, $class;
245 242
246 CFPlus::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); 243 DC::weaken ($DC::UI::WIDGET{$self+0} = $self);
247 244
248 for (keys %$self) { 245 for (keys %$self) {
249 if (/^on_(.*)$/) { 246 if (/^on_(.*)$/) {
250 $self->connect ($1 => delete $self->{$_}); 247 $self->connect ($1 => delete $self->{$_});
251 } 248 }
252 } 249 }
253 250
254 if (my $layout = $CFPlus::UI::LAYOUT->{$self->{name}}) { 251 if (my $layout = $DC::UI::LAYOUT->{$self->{name}}) {
255 $self->{x} = $layout->{x} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{x}; 252 $self->{x} = $layout->{x} * $DC::UI::ROOT->{alloc_w} if exists $layout->{x};
256 $self->{y} = $layout->{y} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{y}; 253 $self->{y} = $layout->{y} * $DC::UI::ROOT->{alloc_h} if exists $layout->{y};
257 $self->{force_w} = $layout->{w} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{w}; 254 $self->{force_w} = $layout->{w} * $DC::UI::ROOT->{alloc_w} if exists $layout->{w};
258 $self->{force_h} = $layout->{h} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{h}; 255 $self->{force_h} = $layout->{h} * $DC::UI::ROOT->{alloc_h} if exists $layout->{h};
259 256
260 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; 257 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x};
261 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; 258 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y};
262 259
263 $self->show if $layout->{show}; 260 $self->show if $layout->{show};
273 $self->emit ("destroy"); 270 $self->emit ("destroy");
274 %$self = (); 271 %$self = ();
275} 272}
276 273
277sub TO_JSON { 274sub TO_JSON {
278 { __widget_ref__ => $_[0]{s_id} } 275 { "\fw" => $_[0]{s_id} }
279} 276}
280 277
281sub show { 278sub show {
282 my ($self) = @_; 279 my ($self) = @_;
283 280
284 return if $self->{parent}; 281 return if $self->{parent};
285 282
286 $CFPlus::UI::ROOT->add ($self); 283 $DC::UI::ROOT->add ($self);
287} 284}
288 285
289sub set_visible { 286sub set_visible {
290 my ($self) = @_; 287 my ($self) = @_;
291 288
312 delete $self->{root}; 309 delete $self->{root};
313 310
314 undef $GRAB if $GRAB == $self; 311 undef $GRAB if $GRAB == $self;
315 undef $HOVER if $HOVER == $self; 312 undef $HOVER if $HOVER == $self;
316 313
317 $CFPlus::UI::TOOLTIP_WATCHER->cb->() 314 $DC::UI::TOOLTIP_WATCHER->invoke
318 if $TOOLTIP->{owner} == $self; 315 if $TOOLTIP->{owner} == $self;
319 316
320 $self->emit ("focus_out"); 317 $self->emit ("focus_out");
321 $self->emit (visibility_change => 0); 318 $self->emit (visibility_change => 0);
322} 319}
341sub hide { 338sub hide {
342 my ($self) = @_; 339 my ($self) = @_;
343 340
344 $self->set_invisible; 341 $self->set_invisible;
345 342
343 # extra $parent copy for 5.8.8+ bug workaround
344 # (otherwise $_[0] in remove gets freed
345 if (my $parent = $self->{parent}) {
346 $self->{parent}->remove ($self) 346 $parent->remove ($self);
347 if $self->{parent}; 347 }
348} 348}
349 349
350sub move_abs { 350sub move_abs {
351 my ($self, $x, $y, $z) = @_; 351 my ($self, $x, $y, $z) = @_;
352 352
364 $self->{force_h} = $h; 364 $self->{force_h} = $h;
365 365
366 $self->realloc; 366 $self->realloc;
367} 367}
368 368
369# traverse the widget chain up to find the maximum "physical" size constraints
370sub get_max_wh {
371 my ($self) = @_;
372
373 return $self->{parent}->get_max_wh
374 if $self->{parent};
375
376 ($::WIDTH, $::HEIGHT)
377}
378
369sub size_request { 379sub size_request {
370 require Carp; 380 require Carp;
371 Carp::confess "size_request is abstract"; 381 Carp::confess "size_request is abstract";
372} 382}
373 383
379 my ($self, $x, $y, $w, $h) = @_; 389 my ($self, $x, $y, $w, $h) = @_;
380 390
381 if ($self->{aspect}) { 391 if ($self->{aspect}) {
382 my ($ow, $oh) = ($w, $h); 392 my ($ow, $oh) = ($w, $h);
383 393
384 $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect}; 394 $w = List::Util::min $w, DC::ceil $h * $self->{aspect};
385 $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect}; 395 $h = List::Util::min $h, DC::ceil $w / $self->{aspect};
386 396
387 # use alignment to adjust x, y 397 # use alignment to adjust x, y
388 398
389 $x += int 0.5 * ($ow - $w); 399 $x += int 0.5 * ($ow - $w);
390 $y += int 0.5 * ($oh - $h); 400 $y += int 0.5 * ($oh - $h);
431 441
432 return if $self->{tooltip} eq $tooltip; 442 return if $self->{tooltip} eq $tooltip;
433 443
434 $self->{tooltip} = $tooltip; 444 $self->{tooltip} = $tooltip;
435 445
436 if ($CFPlus::UI::TOOLTIP->{owner} == $self) { 446 if ($DC::UI::TOOLTIP->{owner} == $self) {
437 delete $CFPlus::UI::TOOLTIP->{owner}; 447 delete $DC::UI::TOOLTIP->{owner};
438 $CFPlus::UI::TOOLTIP_WATCHER->cb->(); 448 $DC::UI::TOOLTIP_WATCHER->invoke;
439 } 449 }
440} 450}
441 451
442# translate global coordinates to local coordinate system 452# translate global coordinates to local coordinate system
443sub coord2local { 453sub coord2local {
444 my ($self, $x, $y) = @_; 454 my ($self, $x, $y) = @_;
445 455
446 Carp::confess unless $self->{parent};#d# 456 return (undef, undef) unless $self->{parent};
447 457
448 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) 458 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
449} 459}
450 460
451# translate local coordinates to global coordinate system 461# translate local coordinates to global coordinate system
452sub coord2global { 462sub coord2global {
453 my ($self, $x, $y) = @_; 463 my ($self, $x, $y) = @_;
454 464
455 Carp::confess unless $self->{parent};#d# 465 return (undef, undef) unless $self->{parent};
456 466
457 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) 467 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
458} 468}
459 469
460sub invoke_focus_in { 470sub invoke_focus_in {
509sub connect { 519sub connect {
510 my ($self, $signal, $cb) = @_; 520 my ($self, $signal, $cb) = @_;
511 521
512 push @{ $self->{signal_cb}{$signal} }, $cb; 522 push @{ $self->{signal_cb}{$signal} }, $cb;
513 523
514 defined wantarray and CFPlus::guard { 524 defined wantarray and DC::guard {
515 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, 525 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
516 @{ $self->{signal_cb}{$signal} }; 526 @{ $self->{signal_cb}{$signal} };
517 } 527 }
518} 528}
519 529
557# in .xs 567# in .xs
558 568
559sub set_parent { 569sub set_parent {
560 my ($self, $parent) = @_; 570 my ($self, $parent) = @_;
561 571
562 CFPlus::weaken ($self->{parent} = $parent); 572 DC::weaken ($self->{parent} = $parent);
563 $self->set_visible if $parent->{visible}; 573 $self->set_visible if $parent->{visible};
564} 574}
565 575
566sub realloc { 576sub realloc {
567 my ($self) = @_; 577 my ($self) = @_;
593 603
594# 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
595# functions seems pointless. 605# functions seems pointless.
596our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn 606our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn
597 607
598sub draw { 608#sub draw {
599 my ($self) = @_; 609#CFPlus.xs
600
601 return unless $self->{h} && $self->{w};
602
603 # update screen rectangle
604 local $draw_x = $draw_x + $self->{x};
605 local $draw_y = $draw_y + $self->{y};
606
607 # skip widgets that are entirely outside the drawing area
608 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w)
609 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h);
610
611 glPushMatrix;
612 glTranslate $self->{x}, $self->{y}, 0;
613
614 if ($self == $HOVER && $self->{can_hover}) {
615 glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2;
616 glEnable GL_BLEND;
617 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
618 glBegin GL_QUADS;
619 glVertex 0 , 0;
620 glVertex $self->{w}, 0;
621 glVertex $self->{w}, $self->{h};
622 glVertex 0 , $self->{h};
623 glEnd;
624 glDisable GL_BLEND;
625 }
626
627 if ($ENV{CFPLUS_DEBUG} & 1) {
628 glPushMatrix;
629 glColor 1, 1, 0, 1;
630 glTranslate 0.375, 0.375;
631 glBegin GL_LINE_LOOP;
632 glVertex 0 , 0;
633 glVertex $self->{w} - 1, 0;
634 glVertex $self->{w} - 1, $self->{h} - 1;
635 glVertex 0 , $self->{h} - 1;
636 glEnd;
637 glPopMatrix;
638 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
639 }
640
641 $self->_draw;
642 glPopMatrix;
643}
644 610
645sub _draw { 611sub _draw {
646 my ($self) = @_; 612 my ($self) = @_;
647 613
648 warn "no draw defined for $self\n"; 614 warn "no draw defined for $self\n";
649} 615}
650 616
651sub DESTROY { 617sub DESTROY {
652 my ($self) = @_; 618 my ($self) = @_;
653 619
654 return if CFPlus::in_destruct; 620 return if DC::in_destruct;
655 621
622 local $@;
656 eval { $self->destroy }; 623 eval { $self->destroy };
657 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 624 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
658 625
659 delete $WIDGET{$self+0}; 626 delete $WIDGET{$self+0};
660} 627}
661 628
662############################################################################# 629#############################################################################
663 630
664package CFPlus::UI::DrawBG; 631package DC::UI::DrawBG;
665 632
666our @ISA = CFPlus::UI::Base::; 633our @ISA = DC::UI::Base::;
667 634
668use strict; 635use strict;
669use CFPlus::OpenGL; 636use DC::OpenGL;
670 637
671sub new { 638sub new {
672 my $class = shift; 639 my $class = shift;
673
674 # range [value, low, high, page]
675 640
676 $class->SUPER::new ( 641 $class->SUPER::new (
677 #bg => [0, 0, 0, 0.2], 642 #bg => [0, 0, 0, 0.2],
678 #active_bg => [1, 1, 1, 0.5], 643 #active_bg => [1, 1, 1, 0.5],
679 @_ 644 @_
691 my ($w, $h) = @$self{qw(w h)}; 656 my ($w, $h) = @$self{qw(w h)};
692 657
693 glEnable GL_BLEND; 658 glEnable GL_BLEND;
694 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 659 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
695 glColor_premultiply @$color; 660 glColor_premultiply @$color;
696
697 glBegin GL_QUADS;
698 glVertex 0 , 0;
699 glVertex 0 , $h;
700 glVertex $w, $h; 661 glRect 0, 0, $w, $h;
701 glVertex $w, 0;
702 glEnd;
703
704 glDisable GL_BLEND; 662 glDisable GL_BLEND;
705 } 663 }
706} 664}
707 665
708############################################################################# 666#############################################################################
709 667
710package CFPlus::UI::Empty; 668package DC::UI::Empty;
711 669
712our @ISA = CFPlus::UI::Base::; 670our @ISA = DC::UI::Base::;
713 671
714sub new { 672sub new {
715 my ($class, %arg) = @_; 673 my ($class, %arg) = @_;
716 $class->SUPER::new (can_events => 0, %arg); 674 $class->SUPER::new (can_events => 0, %arg);
717} 675}
724 682
725sub draw { } 683sub draw { }
726 684
727############################################################################# 685#############################################################################
728 686
729package CFPlus::UI::Container; 687package DC::UI::Container;
730 688
731our @ISA = CFPlus::UI::Base::; 689our @ISA = DC::UI::Base::;
732 690
733sub new { 691sub new {
734 my ($class, %arg) = @_; 692 my ($class, %arg) = @_;
735 693
736 my $children = delete $arg{children}; 694 my $children = delete $arg{children};
769 @{$self->{children}}, @widgets 727 @{$self->{children}}, @widgets
770 ]; 728 ];
771 729
772 $self->realloc; 730 $self->realloc;
773 731
732 $self->emit (c_add => \@widgets);
733
774 map $_+0, @widgets 734 map $_+0, @widgets
775} 735}
776 736
777sub children { 737sub children {
778 @{ $_[0]{children} } 738 @{ $_[0]{children} }
779} 739}
780 740
781sub remove { 741sub remove {
782 my ($self, $child) = @_; 742 my ($self, @widgets) = @_;
783 743
744 $self->emit (c_remove => \@widgets);
745
746 for my $child (@widgets) {
784 delete $child->{parent}; 747 delete $child->{parent};
785 $child->hide; 748 $child->hide;
786
787 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 749 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
750 }
788 751
789 $self->realloc; 752 $self->realloc;
790} 753}
791 754
792sub clear { 755sub clear {
820} 783}
821 784
822sub _draw { 785sub _draw {
823 my ($self) = @_; 786 my ($self) = @_;
824 787
825 $_->draw for @{$self->{children}}; 788 $_->draw for $self->visible_children;
826} 789}
827 790
828############################################################################# 791#############################################################################
829 792
830package CFPlus::UI::Bin; 793package DC::UI::Bin;
831 794
832our @ISA = CFPlus::UI::Container::; 795our @ISA = DC::UI::Container::;
833 796
834sub new { 797sub new {
835 my ($class, %arg) = @_; 798 my ($class, %arg) = @_;
836 799
837 my $child = (delete $arg{child}) || new CFPlus::UI::Empty::; 800 my $child = (delete $arg{child}) || new DC::UI::Empty::;
838 801
839 $class->SUPER::new (children => [$child], %arg) 802 $class->SUPER::new (children => [$child], %arg)
840} 803}
841 804
842sub add { 805sub add {
843 my ($self, $child) = @_; 806 my ($self, $child) = @_;
844 807
845 $self->SUPER::remove ($_) for @{ $self->{children} }; 808 $self->clear;
846 $self->SUPER::add ($child); 809 $self->SUPER::add ($child);
847} 810}
848 811
849sub remove { 812sub remove {
850 my ($self, $widget) = @_; 813 my ($self, $widget) = @_;
851 814
852 $self->SUPER::remove ($widget); 815 $self->SUPER::remove ($widget);
853 816
854 $self->{children} = [new CFPlus::UI::Empty] 817 $self->{children} = [new DC::UI::Empty]
855 unless @{$self->{children}}; 818 unless @{$self->{children}};
856} 819}
857 820
858sub child { $_[0]->{children}[0] } 821sub child { $_[0]->{children}[0] }
859 822
868 831
869 1 832 1
870} 833}
871 834
872############################################################################# 835#############################################################################
873
874# back-buffered drawing area 836# back-buffered drawing area
875 837
876package CFPlus::UI::Window; 838package DC::UI::Window;
877 839
878our @ISA = CFPlus::UI::Bin::; 840our @ISA = DC::UI::Bin::;
879 841
880use CFPlus::OpenGL; 842use DC::OpenGL;
881 843
882sub new { 844sub new {
883 my ($class, %arg) = @_; 845 my ($class, %arg) = @_;
884 846
885 my $self = $class->SUPER::new (%arg); 847 my $self = $class->SUPER::new (%arg);
907} 869}
908 870
909sub render_child { 871sub render_child {
910 my ($self) = @_; 872 my ($self) = @_;
911 873
912 $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 {
913 glClearColor 0, 0, 0, 0; 875 glClearColor 0, 0, 0, 0;
914 glClear GL_COLOR_BUFFER_BIT; 876 glClear GL_COLOR_BUFFER_BIT;
915 877
916 { 878 {
917 package CFPlus::UI::Base; 879 package DC::UI::Base;
918 880
919 local ($draw_x, $draw_y, $draw_w, $draw_h) = 881 local ($draw_x, $draw_y, $draw_w, $draw_h) =
920 (0, 0, $self->{w}, $self->{h}); 882 (0, 0, $self->{w}, $self->{h});
921 883
922 $self->_render; 884 $self->_render;
939 glDisable GL_TEXTURE_2D; 901 glDisable GL_TEXTURE_2D;
940} 902}
941 903
942############################################################################# 904#############################################################################
943 905
944package CFPlus::UI::ViewPort; 906package DC::UI::ViewPort;
945 907
946use List::Util qw(min max); 908use List::Util qw(min max);
947 909
948our @ISA = CFPlus::UI::Window::; 910our @ISA = DC::UI::Window::;
949 911
950sub new { 912sub new {
951 my $class = shift; 913 my $class = shift;
952 914
953 $class->SUPER::new ( 915 $class->SUPER::new (
995 $self->emit (changed => $x, $y); 957 $self->emit (changed => $x, $y);
996 $self->update; 958 $self->update;
997 } 959 }
998} 960}
999 961
962sub set_center {
963 my ($self, $x, $y) = @_;
964
965 $self->set_offset ($x - $self->{w} * .5, $y - $self->{h} * .5);
966}
967
968sub 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 }
978}
979
1000# 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
1001sub coord2local { 981sub coord2local {
1002 my ($self, $x, $y) = @_; 982 my ($self, $x, $y) = @_;
1003 983
1004 $self->SUPER::coord2local ($x + $self->{view_x}, $y + $self->{view_y}) 984 $self->SUPER::coord2local ($x + $self->{view_x}, $y + $self->{view_y})
1019 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 999 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
1020 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1000 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
1021 ) { 1001 ) {
1022 $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})
1023 } else { 1003 } else {
1024 $self->CFPlus::UI::Base::find_widget ($x, $y) 1004 $self->DC::UI::Base::find_widget ($x, $y)
1025 } 1005 }
1026} 1006}
1027 1007
1028sub _render { 1008sub _render {
1029 my ($self) = @_; 1009 my ($self) = @_;
1030 1010
1031 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};
1032 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};
1033 1013
1034 CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 1014 DC::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
1035 1015
1036 $self->SUPER::_render; 1016 $self->SUPER::_render;
1037} 1017}
1038 1018
1039############################################################################# 1019#############################################################################
1040 1020
1041package CFPlus::UI::ScrolledWindow; 1021package DC::UI::ScrolledWindow;
1042 1022
1043our @ISA = CFPlus::UI::Table::; 1023our @ISA = DC::UI::Table::;
1044 1024
1045sub new { 1025sub new {
1046 my ($class, %arg) = @_; 1026 my ($class, %arg) = @_;
1047 1027
1048 my $child = delete $arg{child}; 1028 my $child = delete $arg{child};
1049 1029
1050 my $self; 1030 my $self;
1051 1031
1052 my $hslider = new CFPlus::UI::Slider 1032 my $hslider = new DC::UI::Slider
1053 col => 0, 1033 c_col => 0,
1054 row => 1, 1034 c_row => 1,
1055 vertical => 0, 1035 vertical => 0,
1056 range => [0, 0, 1, 0.01], # HACK fix 1036 range => [0, 0, 1, 0.01], # HACK fix
1057 on_changed => sub { 1037 on_changed => sub {
1058 $self->{hpos} = $_[1]; 1038 $self->{hpos} = $_[1];
1059 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1039 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1060 }, 1040 },
1061 ; 1041 ;
1062 1042
1063 my $vslider = new CFPlus::UI::Slider 1043 my $vslider = new DC::UI::Slider
1064 col => 1, 1044 c_col => 1,
1065 row => 0, 1045 c_row => 0,
1066 vertical => 1, 1046 vertical => 1,
1067 range => [0, 0, 1, 0.01], # HACK fix 1047 range => [0, 0, 1, 0.01], # HACK fix
1068 on_changed => sub { 1048 on_changed => sub {
1069 $self->{vpos} = $_[1]; 1049 $self->{vpos} = $_[1];
1070 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1050 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1080 col_expand => [1, 0], 1060 col_expand => [1, 0],
1081 row_expand => [1, 0], 1061 row_expand => [1, 0],
1082 %arg, 1062 %arg,
1083 ); 1063 );
1084 1064
1085 $self->{vp} = new CFPlus::UI::ViewPort 1065 $self->{vp} = new DC::UI::ViewPort
1086 col => 0, 1066 c_col => 0,
1087 row => 0, 1067 c_row => 0,
1088 expand => 1, 1068 expand => 1,
1089 scroll_x => $self->{scroll_x}, 1069 scroll_x => $self->{scroll_x},
1090 scroll_y => $self->{scroll_y}, 1070 scroll_y => $self->{scroll_y},
1091 on_changed => sub { 1071 on_changed => sub {
1092 my ($vp, $x, $y) = @_; 1072 my ($vp, $x, $y) = @_;
1114 my ($self, $widget) = @_; 1094 my ($self, $widget) = @_;
1115 1095
1116 $self->{vp}->add ($self->{child} = $widget); 1096 $self->{vp}->add ($self->{child} = $widget);
1117} 1097}
1118 1098
1099sub set_offset { shift->{vp}->set_offset (@_) }
1100sub set_center { shift->{vp}->set_center (@_) }
1101sub make_visible { shift->{vp}->make_visible (@_) }
1102
1119sub update_slider { 1103sub update_slider {
1120 my ($self) = @_; 1104 my ($self) = @_;
1121 1105
1122 my $child = ($self->{vp} or return)->child; 1106 my $child = ($self->{vp} or return)->child;
1123 1107
1212 $self->SUPER::invoke_size_allocate ($w, $h) 1196 $self->SUPER::invoke_size_allocate ($w, $h)
1213} 1197}
1214 1198
1215############################################################################# 1199#############################################################################
1216 1200
1217package CFPlus::UI::Frame; 1201package DC::UI::Frame;
1218 1202
1219our @ISA = CFPlus::UI::Bin::; 1203our @ISA = DC::UI::Bin::;
1220 1204
1221use CFPlus::OpenGL; 1205use DC::OpenGL;
1222 1206
1223sub new { 1207sub new {
1224 my $class = shift; 1208 my $class = shift;
1225 1209
1226 $class->SUPER::new ( 1210 $class->SUPER::new (
1236 my ($w, $h) = @$self{qw(w h)}; 1220 my ($w, $h) = @$self{qw(w h)};
1237 1221
1238 glEnable GL_BLEND; 1222 glEnable GL_BLEND;
1239 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 1223 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
1240 glColor_premultiply @{ $self->{bg} }; 1224 glColor_premultiply @{ $self->{bg} };
1241
1242 glBegin GL_QUADS;
1243 glVertex 0 , 0;
1244 glVertex 0 , $h;
1245 glVertex $w, $h; 1225 glRect 0, 0, $w, $h;
1246 glVertex $w, 0;
1247 glEnd;
1248
1249 glDisable GL_BLEND; 1226 glDisable GL_BLEND;
1250 } 1227 }
1251 1228
1252 $self->SUPER::_draw; 1229 $self->SUPER::_draw;
1253} 1230}
1254 1231
1255############################################################################# 1232#############################################################################
1256 1233
1257package CFPlus::UI::FancyFrame; 1234package DC::UI::FancyFrame;
1258 1235
1259our @ISA = CFPlus::UI::Bin::; 1236our @ISA = DC::UI::Bin::;
1260 1237
1261use CFPlus::OpenGL; 1238use DC::OpenGL;
1262 1239
1263sub new { 1240sub new {
1264 my ($class, %arg) = @_; 1241 my ($class, %arg) = @_;
1265 1242
1266 if ((exists $arg{label}) && !ref $arg{label}) { 1243 if ((exists $arg{label}) && !ref $arg{label}) {
1267 $arg{label} = new CFPlus::UI::Label 1244 $arg{label} = new DC::UI::Label
1268 align => 1, 1245 align => 1,
1269 valign => 0, 1246 valign => 0,
1270 text => $arg{label}, 1247 text => $arg{label},
1271 fontsize => ($arg{border} || 0.8) * 0.75; 1248 fontsize => ($arg{border} || 0.8) * 0.75;
1272 } 1249 }
1284 1261
1285sub add { 1262sub add {
1286 my ($self, @widgets) = @_; 1263 my ($self, @widgets) = @_;
1287 1264
1288 $self->SUPER::add (@widgets); 1265 $self->SUPER::add (@widgets);
1289 $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label}; 1266 $self->DC::UI::Container::add ($self->{label}) if $self->{label};
1290} 1267}
1291 1268
1292sub border { 1269sub border {
1293 int $_[0]{border} * $::FONTSIZE 1270 int $_[0]{border} * $::FONTSIZE
1294} 1271}
1352 } 1329 }
1353} 1330}
1354 1331
1355############################################################################# 1332#############################################################################
1356 1333
1357package CFPlus::UI::Toplevel; 1334package DC::UI::Toplevel;
1358 1335
1359our @ISA = CFPlus::UI::Bin::; 1336our @ISA = DC::UI::Bin::;
1360 1337
1361use CFPlus::OpenGL; 1338use DC::OpenGL;
1362 1339
1363my $bg = 1340my $bg =
1364 new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", 1341 new_from_file DC::Texture DC::find_rcfile "d1_bg.png",
1365 mipmap => 1, wrap => 1; 1342 mipmap => 1, wrap => 1;
1366 1343
1367my @border = 1344my @border =
1368 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1345 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
1369 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);
1370 1347
1371my @icon = 1348my @icon =
1372 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1349 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
1373 qw(x1_move.png x1_resize.png); 1350 qw(x1_move.png x1_resize.png);
1374 1351
1375sub new { 1352sub new {
1376 my ($class, %arg) = @_; 1353 my ($class, %arg) = @_;
1377 1354
1383 min_w => 64, 1360 min_w => 64,
1384 min_h => 32, 1361 min_h => 32,
1385 %arg, 1362 %arg,
1386 ); 1363 );
1387 1364
1388 $self->{title_widget} = new CFPlus::UI::Label 1365 $self->{title_widget} = new DC::UI::Label
1389 align => 0, 1366 align => 0,
1390 valign => 1, 1367 valign => 1,
1391 text => $self->{title}, 1368 text => $self->{title},
1392 fontsize => $self->{border}, 1369 fontsize => $self->{border},
1393 if exists $self->{title}; 1370 if exists $self->{title};
1394 1371
1395 if ($self->{has_close_button}) { 1372 if ($self->{has_close_button}) {
1396 $self->{close_button} = 1373 $self->{close_button} =
1397 new CFPlus::UI::ImageButton 1374 new DC::UI::ImageButton
1398 path => 'x1_close.png', 1375 path => 'x1_close.png',
1399 on_activate => sub { $self->emit ("delete") }; 1376 on_activate => sub { $self->emit ("delete") };
1400 1377
1401 $self->CFPlus::UI::Container::add ($self->{close_button}); 1378 $self->DC::UI::Container::add ($self->{close_button});
1402 } 1379 }
1403 1380
1404 $self 1381 $self
1405} 1382}
1406 1383
1407sub add { 1384sub add {
1408 my ($self, @widgets) = @_; 1385 my ($self, @widgets) = @_;
1409 1386
1410 $self->SUPER::add (@widgets); 1387 $self->SUPER::add (@widgets);
1411 $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};
1412 $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};
1413} 1390}
1414 1391
1415sub border { 1392sub border {
1416 int $_[0]{border} * $::FONTSIZE 1393 int $_[0]{border} * $::FONTSIZE
1394}
1395
1396sub 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
1417} 1403}
1418 1404
1419sub size_request { 1405sub size_request {
1420 my ($self) = @_; 1406 my ($self) = @_;
1421 1407
1593 if $self->{close_button}; 1579 if $self->{close_button};
1594} 1580}
1595 1581
1596############################################################################# 1582#############################################################################
1597 1583
1598package CFPlus::UI::Table; 1584package DC::UI::Table;
1599 1585
1600our @ISA = CFPlus::UI::Container::; 1586our @ISA = DC::UI::Container::;
1601 1587
1602use List::Util qw(max sum); 1588use List::Util qw(max sum);
1603 1589
1604use CFPlus::OpenGL; 1590use DC::OpenGL;
1605 1591
1606sub new { 1592sub new {
1607 my $class = shift; 1593 my $class = shift;
1608 1594
1609 $class->SUPER::new ( 1595 $class->SUPER::new (
1615 1601
1616sub add { 1602sub add {
1617 my ($self, @widgets) = @_; 1603 my ($self, @widgets) = @_;
1618 1604
1619 for my $child (@widgets) { 1605 for my $child (@widgets) {
1620 $child->{rowspan} ||= 1; 1606 $child->{c_rowspan} ||= 1;
1621 $child->{colspan} ||= 1; 1607 $child->{c_colspan} ||= 1;
1622 } 1608 }
1623 1609
1624 $self->SUPER::add (@widgets); 1610 $self->SUPER::add (@widgets);
1625} 1611}
1626 1612
1630 my @widgets; 1616 my @widgets;
1631 1617
1632 while (@_) { 1618 while (@_) {
1633 my ($col, $row, $child) = splice @_, 0, 3, (); 1619 my ($col, $row, $child) = splice @_, 0, 3, ();
1634 1620
1635 $child->{row} = $row; 1621 $child->{c_row} = $row;
1636 $child->{col} = $col; 1622 $child->{c_col} = $col;
1637 1623
1638 push @widgets, $child; 1624 push @widgets, $child;
1639 } 1625 }
1640 1626
1641 $self->add (@widgets); 1627 $self->add (@widgets);
1647 my (@w, @h); 1633 my (@w, @h);
1648 1634
1649 my @children = $self->children; 1635 my @children = $self->children;
1650 1636
1651 # first pass, columns 1637 # first pass, columns
1652 for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { 1638 for my $widget (sort { $a->{c_colspan} <=> $b->{c_colspan} } @children) {
1653 my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; 1639 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)};
1654 1640
1655 my $sw = sum @w[$c .. $c + $cs - 1]; 1641 my $sw = sum @w[$c .. $c + $cs - 1];
1656 1642
1657 if ($w > $sw) { 1643 if ($w > $sw) {
1658 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; 1644 $_ += ($w - $sw) / ($_ ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1];
1659 } 1645 }
1660 } 1646 }
1661 1647
1662 # second pass, rows 1648 # second pass, rows
1663 for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { 1649 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) {
1664 my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; 1650 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)};
1665 1651
1666 my $sh = sum @h[$r .. $r + $rs - 1]; 1652 my $sh = sum @h[$r .. $r + $rs - 1];
1667 1653
1668 if ($h > $sh) { 1654 if ($h > $sh) {
1669 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; 1655 $_ += ($h - $sh) / ($_ ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1];
1670 } 1656 }
1671 } 1657 }
1672 1658
1673 (\@w, \@h) 1659 (\@w, \@h)
1674} 1660}
1697 @col_expand = (1) x @$ws unless @col_expand; 1683 @col_expand = (1) x @$ws unless @col_expand;
1698 my $col_expand = (sum @col_expand) || 1; 1684 my $col_expand = (sum @col_expand) || 1;
1699 1685
1700 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1686 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1701 1687
1702 CFPlus::UI::harmonize $ws; 1688 DC::UI::harmonize $ws;
1703 1689
1704 my @row_expand = @{$self->{row_expand}}; 1690 my @row_expand = @{$self->{row_expand}};
1705 @row_expand = (1) x @$ws unless @row_expand; 1691 @row_expand = (1) x @$ws unless @row_expand;
1706 my $row_expand = (sum @row_expand) || 1; 1692 my $row_expand = (sum @row_expand) || 1;
1707 1693
1708 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; 1694 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1709 1695
1710 CFPlus::UI::harmonize $hs; 1696 DC::UI::harmonize $hs;
1711 1697
1712 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } 1698 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] }
1713 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } 1699 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] }
1714 1700
1715 for my $widget ($self->children) { 1701 for my $widget ($self->children) {
1716 my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; 1702 my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(c_row c_col req_w req_h c_rowspan c_colspan)};
1717 1703
1718 $widget->configure ( 1704 $widget->configure (
1719 $x[$c], $y[$r], 1705 $x[$c], $y[$r],
1720 $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], 1706 $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r],
1721 ); 1707 );
1724 1 1710 1
1725} 1711}
1726 1712
1727############################################################################# 1713#############################################################################
1728 1714
1729package CFPlus::UI::Fixed; 1715package DC::UI::Fixed;
1730 1716
1731use List::Util qw(min max); 1717use List::Util qw(min max);
1732 1718
1733our @ISA = CFPlus::UI::Container::; 1719our @ISA = DC::UI::Container::;
1734
1735sub add_fixed {
1736 my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_;
1737
1738 $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h];
1739 $self->SUPER::add ($child);
1740}
1741 1720
1742sub _scale($$$) { 1721sub _scale($$$) {
1743 my ($mode, $val, $max) = @_; 1722 my ($rel, $val, $max) = @_;
1744 1723
1745 $mode eq "abs" ? $val 1724 $rel ? $val * $max : $val
1746 : $mode eq "rel" ? $val * $max
1747 : 0
1748} 1725}
1749 1726
1750sub size_request { 1727sub size_request {
1751 my ($self) = @_; 1728 my ($self) = @_;
1752 1729
1753 my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); 1730 my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0);
1754 1731
1755 # determine overall size by querying abs widgets 1732 # determine overall size by querying abs widgets
1756 for my $child ($self->visible_children) { 1733 for my $child ($self->visible_children) {
1757 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1734 unless ($child->{c_rel}) {
1735 my $x = $child->{c_x};
1736 my $y = $child->{c_y};
1758 1737
1759 if ($pos eq "abs") {
1760 $w = _scale $size, $w, $child->{req_w};
1761 $h = _scale $size, $h, $child->{req_h};
1762
1763 $x1 = min $x1, $x; $x2 = max $x2, $x + $w; 1738 $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w};
1764 $y1 = min $y1, $y; $y2 = max $y2, $y + $h; 1739 $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h};
1765 } 1740 }
1766 } 1741 }
1767 1742
1768 my $W = $x2 - $x1; 1743 my $W = $x2 - $x1;
1769 my $H = $y2 - $y1; 1744 my $H = $y2 - $y1;
1770 1745
1771 # now layout remaining widgets 1746 # now layout remaining widgets
1772 for my $child ($self->visible_children) { 1747 for my $child ($self->visible_children) {
1773 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 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;
1774 1751
1775 if ($pos ne "abs") {
1776 $x = _scale $pos, $x, $W;
1777 $y = _scale $pos, $x, $H;
1778 $w = _scale $size, $w, $child->{req_w};
1779 $h = _scale $size, $h, $child->{req_h};
1780
1781 $x1 = min $x1, $x; $x2 = max $x2, $x + $w; 1752 $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w};
1782 $y1 = min $y1, $y; $y2 = max $y2, $y + $h; 1753 $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h};
1783 } 1754 }
1784 } 1755 }
1785 1756
1786 my $W = $x2 - $x1; 1757 my $W = $x2 - $x1;
1787 my $H = $y2 - $y1; 1758 my $H = $y2 - $y1;
1791 1762
1792sub invoke_size_allocate { 1763sub invoke_size_allocate {
1793 my ($self, $W, $H) = @_; 1764 my ($self, $W, $H) = @_;
1794 1765
1795 for my $child ($self->visible_children) { 1766 for my $child ($self->visible_children) {
1796 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1767 my $x = _scale $child->{c_rel}, $child->{c_x}, $W;
1768 my $y = _scale $child->{c_rel}, $child->{c_y}, $H;
1797 1769
1798 $x = _scale $pos, $x, $W; 1770 $x += $child->{c_halign} * $child->{req_w};
1799 $y = _scale $pos, $x, $H; 1771 $y += $child->{c_valign} * $child->{req_h};
1800 $w = _scale $size, $w, $W;
1801 $h = _scale $size, $h, $H;
1802 1772
1803 $child->configure ($x, $y, $w, $h); 1773 $child->configure (int $x, int $y, $child->{req_w}, $child->{req_h});
1804 } 1774 }
1805 1775
1806 1 1776 1
1807} 1777}
1808 1778
1809############################################################################# 1779#############################################################################
1810 1780
1811package CFPlus::UI::Box; 1781package DC::UI::Box;
1812 1782
1813our @ISA = CFPlus::UI::Container::; 1783our @ISA = DC::UI::Container::;
1814 1784
1815sub size_request { 1785sub size_request {
1816 my ($self) = @_; 1786 my ($self) = @_;
1787
1788 my @children = $self->visible_children;
1817 1789
1818 $self->{vertical} 1790 $self->{vertical}
1819 ? ( 1791 ? (
1820 (List::Util::max map $_->{req_w}, @{$self->{children}}), 1792 (List::Util::max map $_->{req_w}, @children),
1821 (List::Util::sum map $_->{req_h}, @{$self->{children}}), 1793 (List::Util::sum map $_->{req_h}, @children),
1822 ) 1794 )
1823 : ( 1795 : (
1824 (List::Util::sum map $_->{req_w}, @{$self->{children}}), 1796 (List::Util::sum map $_->{req_w}, @children),
1825 (List::Util::max map $_->{req_h}, @{$self->{children}}), 1797 (List::Util::max map $_->{req_h}, @children),
1826 ) 1798 )
1827} 1799}
1828 1800
1829sub invoke_size_allocate { 1801sub invoke_size_allocate {
1830 my ($self, $w, $h) = @_; 1802 my ($self, $w, $h) = @_;
1851 $req[$_] += $space * $children[$_]{expand} 1823 $req[$_] += $space * $children[$_]{expand}
1852 for 0 .. $#children; 1824 for 0 .. $#children;
1853 } 1825 }
1854 } 1826 }
1855 1827
1856 CFPlus::UI::harmonize \@req; 1828 DC::UI::harmonize \@req;
1857 1829
1858 my $pos = 0; 1830 my $pos = 0;
1859 for (0 .. $#children) { 1831 for (0 .. $#children) {
1860 my $alloc = $req[$_]; 1832 my $alloc = $req[$_];
1861 $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));
1866 1 1838 1
1867} 1839}
1868 1840
1869############################################################################# 1841#############################################################################
1870 1842
1871package CFPlus::UI::HBox; 1843package DC::UI::HBox;
1872 1844
1873our @ISA = CFPlus::UI::Box::; 1845our @ISA = DC::UI::Box::;
1874 1846
1875sub new { 1847sub new {
1876 my $class = shift; 1848 my $class = shift;
1877 1849
1878 $class->SUPER::new ( 1850 $class->SUPER::new (
1881 ) 1853 )
1882} 1854}
1883 1855
1884############################################################################# 1856#############################################################################
1885 1857
1886package CFPlus::UI::VBox; 1858package DC::UI::VBox;
1887 1859
1888our @ISA = CFPlus::UI::Box::; 1860our @ISA = DC::UI::Box::;
1889 1861
1890sub new { 1862sub new {
1891 my $class = shift; 1863 my $class = shift;
1892 1864
1893 $class->SUPER::new ( 1865 $class->SUPER::new (
1896 ) 1868 )
1897} 1869}
1898 1870
1899############################################################################# 1871#############################################################################
1900 1872
1901package CFPlus::UI::Label; 1873package DC::UI::Label;
1902 1874
1903our @ISA = CFPlus::UI::DrawBG::; 1875our @ISA = DC::UI::DrawBG::;
1904 1876
1905use CFPlus::OpenGL; 1877use DC::OpenGL;
1906 1878
1907sub new { 1879sub new {
1908 my ($class, %arg) = @_; 1880 my ($class, %arg) = @_;
1909 1881
1910 my $self = $class->SUPER::new ( 1882 my $self = $class->SUPER::new (
1915 #text => initial text 1887 #text => initial text
1916 #markup => initial narkup 1888 #markup => initial narkup
1917 #max_w => maximum pixel width 1889 #max_w => maximum pixel width
1918 #style => 0, # render flags 1890 #style => 0, # render flags
1919 ellipsise => 3, # end 1891 ellipsise => 3, # end
1920 layout => (new CFPlus::Layout), 1892 layout => (new DC::Layout),
1921 fontsize => 1, 1893 fontsize => 1,
1922 align => -1, 1894 align => -1,
1923 valign => -1, 1895 valign => -1,
1924 padding_x => 2, 1896 padding_x => 2,
1925 padding_y => 2, 1897 padding_y => 2,
1926 can_events => 0, 1898 can_events => 0,
1927 %arg 1899 %arg
1928 ); 1900 );
1929 1901
1930 if (exists $self->{template}) { 1902 if (exists $self->{template}) {
1931 my $layout = new CFPlus::Layout; 1903 my $layout = new DC::Layout;
1932 $layout->set_text (delete $self->{template}); 1904 $layout->set_text (delete $self->{template});
1933 $self->{template} = $layout; 1905 $self->{template} = $layout;
1934 } 1906 }
1935 1907
1936 if (exists $self->{markup}) { 1908 if (exists $self->{markup}) {
1954 1926
1955 delete $self->{ox}; 1927 delete $self->{ox};
1956 $self->SUPER::realloc; 1928 $self->SUPER::realloc;
1957} 1929}
1958 1930
1931sub clear {
1932 my ($self) = @_;
1933
1934 $self->set_text ("");
1935}
1936
1959sub set_text { 1937sub set_text {
1960 my ($self, $text) = @_; 1938 my ($self, $text) = @_;
1961 1939
1962 return if $self->{text} eq "T$text"; 1940 return if $self->{text} eq "T$text";
1963 $self->{text} = "T$text"; 1941 $self->{text} = "T$text";
1986 1964
1987sub size_request { 1965sub size_request {
1988 my ($self) = @_; 1966 my ($self) = @_;
1989 1967
1990 $self->{size_req} ||= do { 1968 $self->{size_req} ||= do {
1969 my ($max_w, $max_h) = $self->get_max_wh;
1970
1991 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1971 $self->{layout}->set_font ($self->{font}) if $self->{font};
1992 $self->{layout}->set_width ($self->{max_w} || -1); 1972 $self->{layout}->set_width ($self->{max_w} || $max_w || -1);
1993 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1973 $self->{layout}->set_ellipsise ($self->{ellipsise});
1994 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1974 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1995 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1975 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1996 1976
1997 my ($w, $h) = $self->{layout}->size; 1977 my ($w, $h) = $self->{layout}->size;
2069 : ($self->{w} - $size->[0]) * 0.5); 2049 : ($self->{w} - $size->[0]) * 0.5);
2070 2050
2071 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 2051 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2072 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} 2052 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2073 : ($self->{h} - $size->[1]) * 0.5); 2053 : ($self->{h} - $size->[1]) * 0.5);
2054
2055 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2074 }; 2056 };
2075 2057
2076 my $w = List::Util::min $self->{w} + 4, $size->[0]; 2058# unless ($self->{list}) {
2077 my $h = List::Util::min $self->{h} + 2, $size->[1]; 2059# $self->{list} = DC::OpenGL::glGenList;
2078 2060# DC::OpenGL::glNewList $self->{list};
2079 $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;
2080} 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#}
2081 2077
2082############################################################################# 2078#############################################################################
2083 2079
2084package CFPlus::UI::EntryBase; 2080package DC::UI::EntryBase;
2085 2081
2086our @ISA = CFPlus::UI::Label::; 2082our @ISA = DC::UI::Label::;
2087 2083
2088use CFPlus::OpenGL; 2084use DC::OpenGL;
2089 2085
2090sub new { 2086sub new {
2091 my $class = shift; 2087 my $class = shift;
2092 2088
2093 $class->SUPER::new ( 2089 $class->SUPER::new (
2094 fg => [1, 1, 1], 2090 fg => [1, 1, 1],
2095 bg => [0, 0, 0, 0.2], 2091 bg => [0, 0, 0, 0.2],
2092 outline => [0.6, 0.3, 0.1],
2096 active_bg => [1, 1, 1, 0.5], 2093 active_bg => [0, 0, 1, .2],
2097 active_fg => [0, 0, 0], 2094 active_fg => [1, 1, 1],
2095 active_outline => [1, 1, 0],
2098 can_hover => 1, 2096 can_hover => 1,
2099 can_focus => 1, 2097 can_focus => 1,
2100 valign => 0, 2098 valign => 0,
2101 can_events => 1, 2099 can_events => 1,
2102 ellipsise => 0, 2100 ellipsise => 0,
2101 padding_x => 4,
2102 padding_y => 2,
2103 #text => ... 2103 #text => ...
2104 #hidden => "*", 2104 #hidden => "*",
2105 @_ 2105 @_
2106 ) 2106 )
2107} 2107}
2158 2158
2159 if ($uni == 8) { 2159 if ($uni == 8) {
2160 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2160 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
2161 } elsif ($uni == 127) { 2161 } elsif ($uni == 127) {
2162 substr $text, $self->{cursor}, 1, ""; 2162 substr $text, $self->{cursor}, 1, "";
2163 } elsif ($sym == CFPlus::SDLK_LEFT) { 2163 } elsif ($sym == DC::SDLK_LEFT) {
2164 --$self->{cursor} if $self->{cursor}; 2164 --$self->{cursor} if $self->{cursor};
2165 } elsif ($sym == CFPlus::SDLK_RIGHT) { 2165 } elsif ($sym == DC::SDLK_RIGHT) {
2166 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 2166 ++$self->{cursor} if $self->{cursor} < length $self->{text};
2167 } elsif ($sym == CFPlus::SDLK_HOME) { 2167 } elsif ($sym == DC::SDLK_HOME) {
2168 # what a hack 2168 # what a hack
2169 $self->{cursor} = 2169 $self->{cursor} =
2170 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ 2170 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/
2171 ? length $1 2171 ? length $1
2172 : 0; 2172 : 0;
2173 } elsif ($sym == CFPlus::SDLK_END) { 2173 } elsif ($sym == DC::SDLK_END) {
2174 # uh, again 2174 # uh, again
2175 $self->{cursor} = 2175 $self->{cursor} =
2176 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ 2176 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/
2177 ? $self->{cursor} + length $1 2177 ? $self->{cursor} + length $1
2178 : length $self->{text}; 2178 : length $self->{text};
2242 glColor_premultiply @{$self->{bg}}; 2242 glColor_premultiply @{$self->{bg}};
2243 } 2243 }
2244 2244
2245 glEnable GL_BLEND; 2245 glEnable GL_BLEND;
2246 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2246 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2247 glBegin GL_QUADS;
2248 glVertex 0 , 0;
2249 glVertex 0 , $self->{h};
2250 glVertex $self->{w}, $self->{h}; 2247 glRect 0, 0, $self->{w}, $self->{h};
2251 glVertex $self->{w}, 0;
2252 glEnd;
2253 glDisable GL_BLEND; 2248 glDisable GL_BLEND;
2254 2249
2255 $self->SUPER::_draw; 2250 $self->SUPER::_draw;
2256 2251
2257 #TODO: force update every cursor change :( 2252 #TODO: force update every cursor change :(
2259 2254
2260 unless (exists $self->{cur_h}) { 2255 unless (exists $self->{cur_h}) {
2261 my $text = substr $self->{text}, 0, $self->{cursor}; 2256 my $text = substr $self->{text}, 0, $self->{cursor};
2262 utf8::encode $text; 2257 utf8::encode $text;
2263 2258
2264 @$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);
2265 } 2260 }
2266 2261
2262 glColor_premultiply @{$self->{active_fg}};
2267 glBegin GL_LINES; 2263 glBegin GL_LINES;
2268 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};
2269 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};
2270 glEnd; 2266 glEnd;
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;
2271 } 2281 }
2272} 2282}
2273 2283
2274############################################################################# 2284#############################################################################
2275 2285
2276package CFPlus::UI::Entry; 2286package DC::UI::Entry;
2277 2287
2278our @ISA = CFPlus::UI::EntryBase::; 2288our @ISA = DC::UI::EntryBase::;
2279 2289
2280use CFPlus::OpenGL; 2290use DC::OpenGL;
2281 2291
2282sub invoke_key_down { 2292sub invoke_key_down {
2283 my ($self, $ev) = @_; 2293 my ($self, $ev) = @_;
2284 2294
2285 my $sym = $ev->{sym}; 2295 my $sym = $ev->{sym};
2291 $self->{history_pointer} = -1; 2301 $self->{history_pointer} = -1;
2292 $self->{history_saveback} = ''; 2302 $self->{history_saveback} = '';
2293 $self->emit (activate => $txt); 2303 $self->emit (activate => $txt);
2294 $self->update; 2304 $self->update;
2295 2305
2296 } elsif ($sym == CFPlus::SDLK_UP) { 2306 } elsif ($sym == DC::SDLK_UP) {
2297 if ($self->{history_pointer} < 0) { 2307 if ($self->{history_pointer} < 0) {
2298 $self->{history_saveback} = $self->get_text; 2308 $self->{history_saveback} = $self->get_text;
2299 } 2309 }
2300 if (@{$self->{history} || []} > 0) { 2310 if (@{$self->{history} || []} > 0) {
2301 $self->{history_pointer}++; 2311 $self->{history_pointer}++;
2303 $self->{history_pointer} = @{$self->{history} || []} - 1; 2313 $self->{history_pointer} = @{$self->{history} || []} - 1;
2304 } 2314 }
2305 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2315 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2306 } 2316 }
2307 2317
2308 } elsif ($sym == CFPlus::SDLK_DOWN) { 2318 } elsif ($sym == DC::SDLK_DOWN) {
2309 $self->{history_pointer}--; 2319 $self->{history_pointer}--;
2310 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2320 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
2311 2321
2312 if ($self->{history_pointer} >= 0) { 2322 if ($self->{history_pointer} >= 0) {
2313 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2323 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2322 1 2332 1
2323} 2333}
2324 2334
2325############################################################################# 2335#############################################################################
2326 2336
2327package CFPlus::UI::TextEdit; 2337package DC::UI::TextEdit;
2328 2338
2329our @ISA = CFPlus::UI::EntryBase::; 2339our @ISA = DC::UI::EntryBase::;
2330 2340
2331use CFPlus::OpenGL; 2341use DC::OpenGL;
2342
2343sub new {
2344 my $class = shift;
2345
2346 $class->SUPER::new (
2347 padding_y => 4,
2348
2349 @_
2350 )
2351}
2332 2352
2333sub move_cursor_ver { 2353sub move_cursor_ver {
2334 my ($self, $dy) = @_; 2354 my ($self, $dy) = @_;
2335 2355
2336 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2356 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2337 2357
2338 $y += $dy; 2358 $line += $dy;
2339 2359
2340 if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { 2360 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) {
2341 $self->{cursor} = $index; 2361 $self->{cursor} = $index;
2342 delete $self->{cur_h}; 2362 delete $self->{cur_h};
2343 $self->update; 2363 $self->update;
2344 return; 2364 return;
2345 } 2365 }
2348sub invoke_key_down { 2368sub invoke_key_down {
2349 my ($self, $ev) = @_; 2369 my ($self, $ev) = @_;
2350 2370
2351 my $sym = $ev->{sym}; 2371 my $sym = $ev->{sym};
2352 2372
2353 if ($sym == CFPlus::SDLK_UP) { 2373 if ($sym == DC::SDLK_UP) {
2354 $self->move_cursor_ver (-1); 2374 $self->move_cursor_ver (-1);
2355 } elsif ($sym == CFPlus::SDLK_DOWN) { 2375 } elsif ($sym == DC::SDLK_DOWN) {
2356 $self->move_cursor_ver (+1); 2376 $self->move_cursor_ver (+1);
2357 } else { 2377 } else {
2358 return $self->SUPER::invoke_key_down ($ev) 2378 return $self->SUPER::invoke_key_down ($ev)
2359 } 2379 }
2360 2380
2361 1 2381 1
2362} 2382}
2363 2383
2364############################################################################# 2384#############################################################################
2365 2385
2366package CFPlus::UI::Button; 2386package DC::UI::ButtonBin;
2367 2387
2368our @ISA = CFPlus::UI::Label::; 2388our @ISA = DC::UI::Bin::;
2369 2389
2370use CFPlus::OpenGL; 2390use DC::OpenGL;
2371 2391
2372my @tex = 2392my @tex =
2373 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2393 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2374 qw(b1_button_inactive.png b1_button_active.png); 2394 qw(b1_button_inactive.png b1_button_active.png);
2375 2395
2376sub new { 2396sub new {
2377 my $class = shift; 2397 my $class = shift;
2378 2398
2379 $class->SUPER::new ( 2399 $class->SUPER::new (
2400 can_hover => 1,
2401 align => 0,
2402 valign => 0,
2403 can_events => 1,
2404 @_
2405 )
2406}
2407
2408sub invoke_button_up {
2409 my ($self, $ev, $x, $y) = @_;
2410
2411 $self->emit ("activate")
2412 if $x >= 0 && $x < $self->{w}
2413 && $y >= 0 && $y < $self->{h};
2414
2415 1
2416}
2417
2418sub _draw {
2419 my ($self) = @_;
2420
2421 glEnable GL_TEXTURE_2D;
2422 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2423 glColor 0, 0, 0, 1;
2424
2425 my $tex = $tex[$GRAB == $self];
2426 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2427
2428 glDisable GL_TEXTURE_2D;
2429
2430 $self->SUPER::_draw;
2431}
2432
2433#############################################################################
2434
2435package DC::UI::Button;
2436
2437our @ISA = DC::UI::Label::;
2438
2439use DC::OpenGL;
2440
2441my @tex =
2442 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2443 qw(b1_button_inactive.png b1_button_active.png);
2444
2445sub new {
2446 my $class = shift;
2447
2448 $class->SUPER::new (
2380 padding_x => 4, 2449 padding_x => 8,
2381 padding_y => 4, 2450 padding_y => 4,
2382 fg => [1.0, 1.0, 1.0], 2451 fg => [1.0, 1.0, 1.0],
2383 active_fg => [0.8, 0.8, 0.8], 2452 active_fg => [0.8, 0.8, 0.8],
2384 can_hover => 1, 2453 can_hover => 1,
2385 align => 0, 2454 align => 0,
2416 $self->SUPER::_draw; 2485 $self->SUPER::_draw;
2417} 2486}
2418 2487
2419############################################################################# 2488#############################################################################
2420 2489
2421package CFPlus::UI::CheckBox; 2490package DC::UI::CheckBox;
2422 2491
2423our @ISA = CFPlus::UI::DrawBG::; 2492our @ISA = DC::UI::DrawBG::;
2424 2493
2425my @tex = 2494my @tex =
2426 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2495 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2427 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2496 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2428 2497
2429use CFPlus::OpenGL; 2498use DC::OpenGL;
2430 2499
2431sub new { 2500sub new {
2432 my $class = shift; 2501 my $class = shift;
2433 2502
2434 $class->SUPER::new ( 2503 $class->SUPER::new (
2474sub _draw { 2543sub _draw {
2475 my ($self) = @_; 2544 my ($self) = @_;
2476 2545
2477 $self->SUPER::_draw; 2546 $self->SUPER::_draw;
2478 2547
2479 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; 2548 glTranslate $self->{padding_x}, $self->{padding_y}, 0;
2480 2549
2481 my ($w, $h) = @$self{qw(w h)}; 2550 my ($w, $h) = @$self{qw(w h)};
2482 2551
2483 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; 2552 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2484 2553
2491 glDisable GL_TEXTURE_2D; 2560 glDisable GL_TEXTURE_2D;
2492} 2561}
2493 2562
2494############################################################################# 2563#############################################################################
2495 2564
2496package CFPlus::UI::Image; 2565package DC::UI::Image;
2497 2566
2498our @ISA = CFPlus::UI::Base::; 2567our @ISA = DC::UI::Base::;
2499 2568
2500use CFPlus::OpenGL; 2569use DC::OpenGL;
2501 2570
2502our %texture_cache; 2571our %texture_cache;
2503 2572
2504sub new { 2573sub new {
2505 my $class = shift; 2574 my $class = shift;
2506 2575
2507 my $self = $class->SUPER::new ( 2576 my $self = $class->SUPER::new (
2508 can_events => 0, 2577 can_events => 0,
2578 scale => 1,
2509 @_, 2579 @_,
2510 ); 2580 );
2511 2581
2512 $self->{path} || $self->{tex} 2582 $self->{path} || $self->{tex}
2513 or Carp::croak "'path' or 'tex' attributes required"; 2583 or Carp::croak "'path' or 'tex' attributes required";
2514 2584
2515 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2585 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2516 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; 2586 new_from_file DC::Texture DC::find_rcfile $self->{path}, mipmap => 1;
2517 2587
2518 CFPlus::weaken $texture_cache{$self->{path}}; 2588 DC::weaken $texture_cache{$self->{path}};
2519 2589
2520 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2590 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2521 2591
2522 $self 2592 $self
2523} 2593}
2524 2594
2525sub STORABLE_freeze { 2595sub STORABLE_freeze {
2526 my ($self, $cloning) = @_; 2596 my ($self, $cloning) = @_;
2527 2597
2528 $self->{path} 2598 $self->{path}
2529 or die "cannot serialise CFPlus::UI::Image on non-loadable images\n"; 2599 or die "cannot serialise DC::UI::Image on non-loadable images\n";
2530 2600
2531 $self->{path} 2601 $self->{path}
2532} 2602}
2533 2603
2534sub STORABLE_attach { 2604sub STORABLE_attach {
2538} 2608}
2539 2609
2540sub size_request { 2610sub size_request {
2541 my ($self) = @_; 2611 my ($self) = @_;
2542 2612
2543 ($self->{tex}{w}, $self->{tex}{h}) 2613 (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale})
2544} 2614}
2545 2615
2546sub _draw { 2616sub _draw {
2547 my ($self) = @_; 2617 my ($self) = @_;
2548 2618
2558 } 2628 }
2559 2629
2560 glEnable GL_TEXTURE_2D; 2630 glEnable GL_TEXTURE_2D;
2561 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2631 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2562 2632
2563 $tex->draw_quad (0, 0, $w, $h); 2633 $tex->draw_quad_alpha (0, 0, $w, $h);
2564 2634
2565 glDisable GL_TEXTURE_2D; 2635 glDisable GL_TEXTURE_2D;
2566} 2636}
2567 2637
2568############################################################################# 2638#############################################################################
2569 2639
2570package CFPlus::UI::ImageButton; 2640package DC::UI::ImageButton;
2571 2641
2572our @ISA = CFPlus::UI::Image::; 2642our @ISA = DC::UI::Image::;
2573 2643
2574use CFPlus::OpenGL; 2644use DC::OpenGL;
2575 2645
2576my %textures; 2646my %textures;
2577 2647
2578sub new { 2648sub new {
2579 my $class = shift; 2649 my $class = shift;
2589 can_events => 1, 2659 can_events => 1,
2590 @_ 2660 @_
2591 ); 2661 );
2592} 2662}
2593 2663
2664sub invoke_button_down {
2665 my ($self, $ev, $x, $y) = @_;
2666
2667 1
2668}
2669
2594sub invoke_button_up { 2670sub invoke_button_up {
2595 my ($self, $ev, $x, $y) = @_; 2671 my ($self, $ev, $x, $y) = @_;
2596 2672
2597 $self->emit ("activate") 2673 $self->emit ("activate")
2598 if $x >= 0 && $x < $self->{w} 2674 if $x >= 0 && $x < $self->{w}
2601 1 2677 1
2602} 2678}
2603 2679
2604############################################################################# 2680#############################################################################
2605 2681
2606package CFPlus::UI::VGauge; 2682package DC::UI::VGauge;
2607 2683
2608our @ISA = CFPlus::UI::Base::; 2684our @ISA = DC::UI::Base::;
2609 2685
2610use List::Util qw(min max); 2686use List::Util qw(min max);
2611 2687
2612use CFPlus::OpenGL; 2688use DC::OpenGL;
2613 2689
2614my %tex = ( 2690my %tex = (
2615 food => [ 2691 food => [
2616 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2692 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2617 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2693 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2618 ], 2694 ],
2619 grace => [ 2695 grace => [
2620 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2696 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2621 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2697 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2622 ], 2698 ],
2623 hp => [ 2699 hp => [
2624 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2700 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2625 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2701 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2626 ], 2702 ],
2627 mana => [ 2703 mana => [
2628 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2704 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2629 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2705 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2630 ], 2706 ],
2631); 2707);
2632 2708
2633# eg. VGauge->new (gauge => 'food'), default gauge: food 2709# eg. VGauge->new (gauge => 'food'), default gauge: food
2736 glDisable GL_TEXTURE_2D; 2812 glDisable GL_TEXTURE_2D;
2737} 2813}
2738 2814
2739############################################################################# 2815#############################################################################
2740 2816
2817package DC::UI::Progress;
2818
2819our @ISA = DC::UI::Label::;
2820
2821use DC::OpenGL;
2822
2823sub new {
2824 my ($class, %arg) = @_;
2825
2826 my $self = $class->SUPER::new (
2827 fg => [1, 1, 1],
2828 bg => [0, 0, 1, 0.2],
2829 bar => [0.7, 0.5, 0.1, 0.8],
2830 outline => [0.4, 0.3, 0],
2831 fontsize => 0.9,
2832 valign => 0,
2833 align => 0,
2834 can_events => 1,
2835 ellipsise => 1,
2836 label => "%d%%",
2837 %arg,
2838 );
2839
2840 $self->set_value ($arg{value} || -1);
2841
2842 $self
2843}
2844
2845sub set_label {
2846 my ($self, $label) = @_;
2847
2848 return if $self->{label} eq $label;
2849 $self->{label} = $label;
2850
2851 $self->DC::UI::Progress::set_value (0 + delete $self->{value});
2852}
2853
2854sub set_value {
2855 my ($self, $value) = @_;
2856
2857 if ($self->{value} ne $value) {
2858 $self->{value} = $value;
2859
2860 if ($value < 0) {
2861 $self->set_text ("-");
2862 } else {
2863 $self->set_text (sprintf $self->{label}, $value * 100);
2864 }
2865
2866 $self->update;
2867 }
2868}
2869
2870sub _draw {
2871 my ($self) = @_;
2872
2873 glEnable GL_BLEND;
2874 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2875
2876 if ($self->{value} >= 0) {
2877 my $s = int 2 + ($self->{w} - 4) * $self->{value};
2878
2879 glColor_premultiply @{$self->{bar}};
2880 glRect 2, 2, $s, $self->{h} - 2;
2881 glColor_premultiply @{$self->{bg}};
2882 glRect $s, 2, $self->{w} - 2, $self->{h} - 2;
2883 }
2884
2885 glColor_premultiply @{$self->{outline}};
2886 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2887
2888 glDisable GL_BLEND;
2889
2890 {
2891 local $self->{bg}; # do not draw background
2892 $self->SUPER::_draw;
2893 }
2894}
2895
2896#############################################################################
2897
2898package DC::UI::ExperienceProgress;
2899
2900our @ISA = DC::UI::Progress::;
2901
2902sub new {
2903 my ($class, %arg) = @_;
2904
2905 my $self = $class->SUPER::new (
2906 tooltip => sub {
2907 my ($self) = @_;
2908
2909 sprintf "level %d\n%s points\n%s next level\n%s to go",
2910 $self->{lvl},
2911 ::formsep ($self->{exp}),
2912 ::formsep ($self->{nxt}),
2913 ::formsep ($self->{nxt} - $self->{exp}),
2914 },
2915 %arg
2916 );
2917
2918 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2919 if $::CONN;
2920
2921 $self
2922}
2923
2924sub DESTROY {
2925 my ($self) = @_;
2926
2927 delete $::CONN->{on_exp_update}{$self+0}
2928 if $::CONN;
2929
2930 $self->SUPER::DESTROY;
2931}
2932
2933sub set_value {
2934 my ($self, $lvl, $exp) = @_;
2935
2936 $self->{lvl} = $lvl;
2937 $self->{exp} = $exp;
2938
2939 my $v = -1;
2940
2941 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2942 my $l0 = $table->[$lvl - 1];
2943 my $l1 = $table->[$lvl];
2944
2945 $self->{nxt} = $l1;
2946
2947 $v = ($exp - $l0) / ($l1 - $l0);
2948 }
2949
2950 $self->SUPER::set_value ($v);
2951}
2952
2953#############################################################################
2954
2741package CFPlus::UI::Gauge; 2955package DC::UI::Gauge;
2742 2956
2743our @ISA = CFPlus::UI::VBox::; 2957our @ISA = DC::UI::VBox::;
2744 2958
2745sub new { 2959sub new {
2746 my ($class, %arg) = @_; 2960 my ($class, %arg) = @_;
2747 2961
2748 my $self = $class->SUPER::new ( 2962 my $self = $class->SUPER::new (
2750 can_hover => 1, 2964 can_hover => 1,
2751 can_events => 1, 2965 can_events => 1,
2752 %arg, 2966 %arg,
2753 ); 2967 );
2754 2968
2755 $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999"); 2969 $self->add ($self->{value} = new DC::UI::Label valign => +1, align => 0, template => "999");
2756 $self->add ($self->{gauge} = new CFPlus::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 2970 $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
2757 $self->add ($self->{max} = new CFPlus::UI::Label valign => -1, align => 0, template => "999"); 2971 $self->add ($self->{max} = new DC::UI::Label valign => -1, align => 0, template => "999");
2758 2972
2759 $self 2973 $self
2760} 2974}
2761 2975
2762sub set_fontsize { 2976sub set_fontsize {
2783 $self->{value}->set_text ($val); 2997 $self->{value}->set_text ($val);
2784} 2998}
2785 2999
2786############################################################################# 3000#############################################################################
2787 3001
2788package CFPlus::UI::Slider; 3002package DC::UI::Slider;
2789 3003
2790use strict; 3004use strict;
2791 3005
2792use CFPlus::OpenGL; 3006use DC::OpenGL;
2793 3007
2794our @ISA = CFPlus::UI::DrawBG::; 3008our @ISA = DC::UI::DrawBG::;
2795 3009
2796my @tex = 3010my @tex =
2797 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ } 3011 map { new_from_file DC::Texture DC::find_rcfile $_ }
2798 qw(s1_slider.png s1_slider_bg.png); 3012 qw(s1_slider.png s1_slider_bg.png);
2799 3013
2800sub new { 3014sub new {
2801 my $class = shift; 3015 my $class = shift;
2802 3016
2870 3084
2871 $self->SUPER::invoke_button_down ($ev, $x, $y); 3085 $self->SUPER::invoke_button_down ($ev, $x, $y);
2872 3086
2873 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 3087 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2874 3088
2875 $self->invoke_mouse_motion ($ev, $x, $y) 3089 $self->invoke_mouse_motion ($ev, $x, $y);
3090
3091 1
2876} 3092}
2877 3093
2878sub invoke_mouse_motion { 3094sub invoke_mouse_motion {
2879 my ($self, $ev, $x, $y) = @_; 3095 my ($self, $ev, $x, $y) = @_;
2880 3096
2896sub invoke_mouse_wheel { 3112sub invoke_mouse_wheel {
2897 my ($self, $ev) = @_; 3113 my ($self, $ev) = @_;
2898 3114
2899 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 3115 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
2900 3116
2901 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; 3117 my $pagepart = $ev->{mod} & DC::KMOD_SHIFT ? 1 : 0.2;
2902 3118
2903 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); 3119 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
2904 3120
2905 ! ! $delta 3121 1
2906} 3122}
2907 3123
2908sub update { 3124sub update {
2909 my ($self) = @_; 3125 my ($self) = @_;
2910 3126
2959 glDisable GL_TEXTURE_2D; 3175 glDisable GL_TEXTURE_2D;
2960} 3176}
2961 3177
2962############################################################################# 3178#############################################################################
2963 3179
2964package CFPlus::UI::ValSlider; 3180package DC::UI::ValSlider;
2965 3181
2966our @ISA = CFPlus::UI::HBox::; 3182our @ISA = DC::UI::HBox::;
2967 3183
2968sub new { 3184sub new {
2969 my ($class, %arg) = @_; 3185 my ($class, %arg) = @_;
2970 3186
2971 my $range = delete $arg{range}; 3187 my $range = delete $arg{range};
2972 3188
2973 my $self = $class->SUPER::new ( 3189 my $self = $class->SUPER::new (
2974 slider => (new CFPlus::UI::Slider expand => 1, range => $range), 3190 slider => (new DC::UI::Slider expand => 1, range => $range),
2975 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}), 3191 entry => (new DC::UI::Label text => "", template => delete $arg{template}),
2976 to_value => sub { shift }, 3192 to_value => sub { shift },
2977 from_value => sub { shift }, 3193 from_value => sub { shift },
2978 %arg, 3194 %arg,
2979 ); 3195 );
2980 3196
3000sub set_range { shift->{slider}->set_range (@_) } 3216sub set_range { shift->{slider}->set_range (@_) }
3001sub set_value { shift->{slider}->set_value (@_) } 3217sub set_value { shift->{slider}->set_value (@_) }
3002 3218
3003############################################################################# 3219#############################################################################
3004 3220
3005package CFPlus::UI::TextScroller; 3221package DC::UI::TextScroller;
3006 3222
3007our @ISA = CFPlus::UI::HBox::; 3223our @ISA = DC::UI::HBox::;
3008 3224
3009use CFPlus::OpenGL; 3225use DC::OpenGL;
3010 3226
3011sub new { 3227sub new {
3012 my $class = shift; 3228 my $class = shift;
3013 3229
3014 my $self = $class->SUPER::new ( 3230 my $self = $class->SUPER::new (
3016 can_events => 1, 3232 can_events => 1,
3017 indent => 0, 3233 indent => 0,
3018 #font => default_font 3234 #font => default_font
3019 @_, 3235 @_,
3020 3236
3021 layout => (new CFPlus::Layout), 3237 layout => (new DC::Layout),
3022 par => [], 3238 par => [],
3023 max_par => 0, 3239 max_par => 0,
3024 height => 0, 3240 height => 0,
3025 children => [ 3241 children => [
3026 (new CFPlus::UI::Empty expand => 1), 3242 (new DC::UI::Empty expand => 1),
3027 (new CFPlus::UI::Slider vertical => 1), 3243 (new DC::UI::Slider vertical => 1),
3028 ], 3244 ],
3029 ); 3245 );
3030 3246
3031 $self->{children}[1]->connect (changed => sub { $self->update }); 3247 $self->{children}[1]->connect (changed => sub { $self->update });
3032 3248
3041} 3257}
3042 3258
3043sub size_request { 3259sub size_request {
3044 my ($self) = @_; 3260 my ($self) = @_;
3045 3261
3046 my ($empty, $slider) = @{ $self->{children} }; 3262 my ($empty, $slider) = $self->visible_children;
3047 3263
3048 local $self->{children} = [$empty, $slider]; 3264 local $self->{children} = [$empty, $slider];
3049 $self->SUPER::size_request 3265 $self->SUPER::size_request
3050} 3266}
3051 3267
3215 $ROOT->on_post_alloc ($self => sub { 3431 $ROOT->on_post_alloc ($self => sub {
3216 $self->force_uptodate; 3432 $self->force_uptodate;
3217 3433
3218 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 3434 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
3219 3435
3220 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 3436 $self->{texture} ||= new_from_opengl DC::Texture $W, $H, sub {
3221 glClearColor 0, 0, 0, 0; 3437 glClearColor 0, 0, 0, 0;
3222 glClear GL_COLOR_BUFFER_BIT; 3438 glClear GL_COLOR_BUFFER_BIT;
3223 3439
3224 package CFPlus::UI::Base; 3440 package DC::UI::Base;
3225 local ($draw_x, $draw_y, $draw_w, $draw_h) = 3441 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3226 (0, 0, $self->{w}, $self->{h}); 3442 (0, 0, $self->{w}, $self->{h});
3227 3443
3228 my $top = int $self->{children}[1]{range}[0]; 3444 my $top = int $self->{children}[1]{range}[0];
3229 3445
3240 3456
3241 if ($y0 < $y + $h && $y < $y1) { 3457 if ($y0 < $y + $h && $y < $y1) {
3242 my $layout = $self->get_layout ($para); 3458 my $layout = $self->get_layout ($para);
3243 3459
3244 $layout->render ($para->{indent}, $y - $y0); 3460 $layout->render ($para->{indent}, $y - $y0);
3461 $layout->draw;
3245 3462
3246 if (my @w = @{ $para->{widget} }) { 3463 if (my @w = @{ $para->{widget} }) {
3247 my @s = $layout->get_shapes; 3464 my @s = $layout->get_shapes;
3248 3465
3249 for (@w) { 3466 for (@w) {
3287 $self->{children}[1]->draw; 3504 $self->{children}[1]->draw;
3288} 3505}
3289 3506
3290############################################################################# 3507#############################################################################
3291 3508
3292package CFPlus::UI::Animator; 3509package DC::UI::Animator;
3293 3510
3294use CFPlus::OpenGL; 3511use DC::OpenGL;
3295 3512
3296our @ISA = CFPlus::UI::Bin::; 3513our @ISA = DC::UI::Bin::;
3297 3514
3298sub moveto { 3515sub moveto {
3299 my ($self, $x, $y) = @_; 3516 my ($self, $x, $y) = @_;
3300 3517
3301 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 3518 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
3329 glPopMatrix; 3546 glPopMatrix;
3330} 3547}
3331 3548
3332############################################################################# 3549#############################################################################
3333 3550
3334package CFPlus::UI::Flopper; 3551package DC::UI::Flopper;
3335 3552
3336our @ISA = CFPlus::UI::Button::; 3553our @ISA = DC::UI::Button::;
3337 3554
3338sub new { 3555sub new {
3339 my $class = shift; 3556 my $class = shift;
3340 3557
3341 my $self = $class->SUPER::new ( 3558 my $self = $class->SUPER::new (
3353 $self->{other}->toggle_visibility; 3570 $self->{other}->toggle_visibility;
3354} 3571}
3355 3572
3356############################################################################# 3573#############################################################################
3357 3574
3358package CFPlus::UI::Tooltip; 3575package DC::UI::Tooltip;
3359 3576
3360our @ISA = CFPlus::UI::Bin::; 3577our @ISA = DC::UI::Bin::;
3361 3578
3362use CFPlus::OpenGL; 3579use DC::OpenGL;
3363 3580
3364sub new { 3581sub new {
3365 my $class = shift; 3582 my $class = shift;
3366 3583
3367 $class->SUPER::new ( 3584 $class->SUPER::new (
3371} 3588}
3372 3589
3373sub set_tooltip_from { 3590sub set_tooltip_from {
3374 my ($self, $widget) = @_; 3591 my ($self, $widget) = @_;
3375 3592
3376 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3377 if $widget->{tooltip} =~ /^#(.*)$/;
3378
3379 my $tooltip = $widget->{tooltip}; 3593 my $tip = $widget->{tooltip};
3594 $tip = $tip->($widget) if "CODE" eq ref $tip;
3595
3596 $tip = DC::Pod::section_label tooltip => $1
3597 if $tip =~ /^#(.*)$/;
3380 3598
3381 if ($ENV{CFPLUS_DEBUG} & 2) { 3599 if ($ENV{CFPLUS_DEBUG} & 2) {
3382 $tooltip .= "\n\n" . (ref $widget) . "\n" 3600 $tip .= "\n\n" . (ref $widget) . "\n"
3383 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3601 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3384 . "req $widget->{req_w} $widget->{req_h}\n" 3602 . "req $widget->{req_w} $widget->{req_h}\n"
3385 . "visible $widget->{visible}"; 3603 . "visible $widget->{visible}";
3386 } 3604 }
3387 3605
3388 $tooltip =~ s/^\n+//; 3606 $tip =~ s/^\n+//;
3389 $tooltip =~ s/\n+$//; 3607 $tip =~ s/\n+$//;
3390 3608
3391 $self->add (new CFPlus::UI::Label 3609 $self->add (new DC::UI::Label
3392 markup => $tooltip, 3610 markup => $tip,
3393 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3611 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3394 fontsize => 0.8, 3612 fontsize => 0.8,
3395 style => 1, # FLAG_INVERSE 3613 style => 1, # FLAG_INVERSE
3396 ellipsise => 0, 3614 ellipsise => 0,
3397 font => ($widget->{tooltip_font} || $::FONT_PROP), 3615 font => ($widget->{tooltip_font} || $::FONT_PROP),
3435} 3653}
3436 3654
3437sub _draw { 3655sub _draw {
3438 my ($self) = @_; 3656 my ($self) = @_;
3439 3657
3440 glTranslate 0.375, 0.375;
3441
3442 my ($w, $h) = @$self{qw(w h)}; 3658 my ($w, $h) = @$self{qw(w h)};
3443 3659
3444 glColor 1, 0.8, 0.4; 3660 glColor 1, 0.8, 0.4;
3445 glBegin GL_QUADS; 3661 glRect 0, 0, $w, $h;
3446 glVertex 0 , 0;
3447 glVertex 0 , $h;
3448 glVertex $w, $h;
3449 glVertex $w, 0;
3450 glEnd;
3451 3662
3452 glColor 0, 0, 0; 3663 glColor 0, 0, 0;
3453 glBegin GL_LINE_LOOP; 3664 glRect_lineloop .5, .5, $w + .5, $h + .5;
3454 glVertex 0 , 0;
3455 glVertex 0 , $h;
3456 glVertex $w, $h;
3457 glVertex $w, 0;
3458 glEnd;
3459 3665
3460 glTranslate 2 - 0.375, 2 - 0.375; 3666 glTranslate 2, 2;
3461 3667
3462 $self->SUPER::_draw; 3668 $self->SUPER::_draw;
3463} 3669}
3464 3670
3465############################################################################# 3671#############################################################################
3466 3672
3467package CFPlus::UI::Face; 3673package DC::UI::Face;
3468 3674
3469our @ISA = CFPlus::UI::DrawBG::; 3675our @ISA = DC::UI::DrawBG::;
3470 3676
3471use CFPlus::OpenGL; 3677use DC::OpenGL;
3472 3678
3473sub new { 3679sub new {
3474 my $class = shift; 3680 my $class = shift;
3475 3681
3476 my $self = $class->SUPER::new ( 3682 my $self = $class->SUPER::new (
3480 can_events => 0, 3686 can_events => 0,
3481 @_, 3687 @_,
3482 ); 3688 );
3483 3689
3484 if ($self->{anim} && $self->{animspeed}) { 3690 if ($self->{anim} && $self->{animspeed}) {
3485 CFPlus::weaken (my $widget = $self); 3691 DC::weaken (my $widget = $self);
3486 3692
3487 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3693 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed};
3488 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; 3694 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub {
3489 $self->{timer} = Event->timer (
3490 parked => 1,
3491 cb => sub {
3492 return unless $::CONN && $widget; 3695 return unless $::CONN;
3493 3696
3697 my $w = $widget
3698 or return;
3699
3494 ++$widget->{frame}; 3700 ++$w->{frame};
3495 $widget->update_face; 3701 $w->update_face;
3702
3703 # somehow, $widget can go away
3496 $widget->update; 3704 $w->update;
3497
3498 $widget->update_timer; 3705 $w->update_timer;
3499 },
3500 ); 3706 };
3501 3707
3502 $self->update_face; 3708 $self->update_face;
3503 $self->update_timer; 3709 $self->update_timer;
3504 } 3710 }
3505 3711
3510 my ($self) = @_; 3716 my ($self) = @_;
3511 3717
3512 return unless $self->{timer}; 3718 return unless $self->{timer};
3513 3719
3514 if ($self->{visible}) { 3720 if ($self->{visible}) {
3515 $self->{timer}->at (
3516 $self->{anim_start}
3517 + $self->{animspeed}
3518 * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed}
3519 );
3520 $self->{timer}->start; 3721 $self->{timer}->start;
3521 } else { 3722 } else {
3522 $self->{timer}->stop; 3723 $self->{timer}->stop;
3523 } 3724 }
3524} 3725}
3525 3726
3526sub update_face { 3727sub update_face {
3527 my ($self) = @_; 3728 my ($self) = @_;
3528 3729
3529 return unless $::CONN; 3730 if ($::CONN) {
3530
3531 if (my $anim = $::CONN->{anim}[$self->{anim}]) { 3731 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3532 if ($anim && @$anim) { 3732 if ($anim && @$anim) {
3533 delete $self->{wait_face};
3534 $self->{face} = $anim->[ $self->{frame} % @$anim ]; 3733 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3734 delete $self->{face_change_cb};
3735
3736 if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) {
3737 unless ($tex->{name} || $tex->{loading}) {
3738 $tex->upload (sub { $self->reconfigure });
3739 }
3740 }
3741 }
3535 } 3742 }
3536 } 3743 }
3537} 3744}
3538 3745
3539sub size_request { 3746sub size_request {
3540 my ($self) = @_; 3747 my ($self) = @_;
3541 3748
3542 if ($::CONN) { 3749 if ($::CONN) {
3543 if (my $faceid = $::CONN->{faceid}[$self->{face}]) { 3750 if (my $faceid = $::CONN->{face}[$self->{face}]{id}) {
3544 if (my $tex = $::CONN->{texture}[$faceid]) { 3751 if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) {
3545 $self->{tex} = $tex; 3752 if ($tex->{name}) {
3546 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); 3753 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3547 } else { 3754 } elsif (!$tex->{loading}) {
3548 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { 3755 $tex->upload (sub { $self->reconfigure });
3549 $self->realloc;
3550 }); 3756 }
3551 } 3757 }
3758
3759 $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure });
3552 } 3760 }
3553 } 3761 }
3554 3762
3555 ($self->{size_w} || 8, $self->{size_h} || 8) 3763 ($self->{size_w} || 8, $self->{size_h} || 8)
3556} 3764}
3594 $self->SUPER::destroy; 3802 $self->SUPER::destroy;
3595} 3803}
3596 3804
3597############################################################################# 3805#############################################################################
3598 3806
3599package CFPlus::UI::Buttonbar; 3807package DC::UI::Buttonbar;
3600 3808
3601our @ISA = CFPlus::UI::HBox::; 3809our @ISA = DC::UI::HBox::;
3602 3810
3603# TODO: should actually wrap buttons and other goodies. 3811# TODO: should actually wrap buttons and other goodies.
3604 3812
3605############################################################################# 3813#############################################################################
3606 3814
3607package CFPlus::UI::Menu; 3815package DC::UI::Menu;
3608 3816
3609our @ISA = CFPlus::UI::Toplevel::; 3817our @ISA = DC::UI::Toplevel::;
3610 3818
3611use CFPlus::OpenGL; 3819use DC::OpenGL;
3612 3820
3613sub new { 3821sub new {
3614 my $class = shift; 3822 my $class = shift;
3615 3823
3616 my $self = $class->SUPER::new ( 3824 my $self = $class->SUPER::new (
3617 items => [], 3825 items => [],
3618 z => 100, 3826 z => 100,
3619 @_, 3827 @_,
3620 ); 3828 );
3621 3829
3622 $self->add ($self->{vbox} = new CFPlus::UI::VBox); 3830 $self->add ($self->{vbox} = new DC::UI::VBox);
3623 3831
3624 for my $item (@{ $self->{items} }) { 3832 for my $item (@{ $self->{items} }) {
3625 my ($widget, $cb, $tooltip) = @$item; 3833 my ($widget, $cb, $tooltip) = @$item;
3626 3834
3627 # handle various types of items, only text for now 3835 # handle various types of items, only text for now
3628 if (!ref $widget) { 3836 if (!ref $widget) {
3629 if ($widget =~ /\t/) { 3837 if ($widget =~ /\t/) {
3630 my ($left, $right) = split /\t/, $widget, 2; 3838 my ($left, $right) = split /\t/, $widget, 2;
3631 3839
3632 $widget = new CFPlus::UI::HBox 3840 $widget = new DC::UI::HBox
3633 can_hover => 1, 3841 can_hover => 1,
3634 can_events => 1, 3842 can_events => 1,
3635 tooltip => $tooltip, 3843 tooltip => $tooltip,
3636 children => [ 3844 children => [
3637 (new CFPlus::UI::Label markup => $left, expand => 1), 3845 (new DC::UI::Label markup => $left, expand => 1),
3638 (new CFPlus::UI::Label markup => $right, align => +1), 3846 (new DC::UI::Label markup => $right, align => +1),
3639 ], 3847 ],
3640 ; 3848 ;
3641 3849
3642 } else { 3850 } else {
3643 $widget = new CFPlus::UI::Label 3851 $widget = new DC::UI::Label
3644 can_hover => 1, 3852 can_hover => 1,
3645 can_events => 1, 3853 can_events => 1,
3646 markup => $widget, 3854 markup => $widget,
3647 tooltip => $tooltip; 3855 tooltip => $tooltip;
3648 } 3856 }
3696 1 3904 1
3697} 3905}
3698 3906
3699############################################################################# 3907#############################################################################
3700 3908
3701package CFPlus::UI::Multiplexer; 3909package DC::UI::Multiplexer;
3702 3910
3703our @ISA = CFPlus::UI::Container::; 3911our @ISA = DC::UI::Container::;
3704 3912
3705sub new { 3913sub new {
3706 my $class = shift; 3914 my $class = shift;
3707 3915
3708 my $self = $class->SUPER::new ( 3916 my $self = $class->SUPER::new (
3769 $self->{current}->draw; 3977 $self->{current}->draw;
3770} 3978}
3771 3979
3772############################################################################# 3980#############################################################################
3773 3981
3774package CFPlus::UI::Notebook; 3982package DC::UI::Notebook;
3775 3983
3984use DC::OpenGL;
3985
3776our @ISA = CFPlus::UI::VBox::; 3986our @ISA = DC::UI::VBox::;
3777 3987
3778sub new { 3988sub new {
3779 my $class = shift; 3989 my $class = shift;
3780 3990
3781 my $self = $class->SUPER::new ( 3991 my $self = $class->SUPER::new (
3782 buttonbar => (new CFPlus::UI::Buttonbar), 3992 buttonbar => (new DC::UI::Buttonbar),
3783 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3993 multiplexer => (new DC::UI::Multiplexer expand => 1),
3994 active_outline => [.7, .7, 0.2],
3784 # filter => # will be put between multiplexer and $self 3995 # filter => # will be put between multiplexer and $self
3785 @_, 3996 @_,
3786 ); 3997 );
3787 3998
3788 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3999 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3789 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); 4000 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3790 4001
4002 {
4003 Scalar::Util::weaken (my $wself = $self);
4004
4005 $self->{multiplexer}->connect (c_add => sub {
4006 my ($mplex, $widgets) = @_;
4007
4008 for my $child (@$widgets) {
4009 Scalar::Util::weaken $child;
4010 $child->{c_tab_} ||= do {
4011 my $tab =
4012 (UNIVERSAL::isa $child->{c_tab}, "DC::UI::Base")
4013 ? $child->{c_tab}
4014 : new DC::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1];
4015
4016 $tab->connect (activate => sub {
4017 $wself->set_current_page ($child);
4018 });
4019
4020 $tab
4021 };
4022
4023 $self->{buttonbar}->add ($child->{c_tab_});
4024 }
4025 });
4026
4027 $self->{multiplexer}->connect (c_remove => sub {
4028 my ($mplex, $widgets) = @_;
4029
4030 for my $child (@$widgets) {
4031 $wself->{buttonbar}->remove ($child->{c_tab_});
4032 }
4033 });
4034 }
4035
3791 $self 4036 $self
3792} 4037}
3793 4038
3794sub add { 4039sub add {
4040 my ($self, @widgets) = @_;
4041
4042 $self->{multiplexer}->add (@widgets)
4043}
4044
4045sub remove {
4046 my ($self, @widgets) = @_;
4047
4048 $self->{multiplexer}->remove (@widgets)
4049}
4050
4051sub pages {
4052 my ($self) = @_;
4053 $self->{multiplexer}->children
4054}
4055
4056sub add_tab {
3795 my ($self, $title, $widget, $tooltip) = @_; 4057 my ($self, $title, $widget, $tooltip) = @_;
3796 4058
3797 CFPlus::weaken $self; 4059 $title = [$title, $tooltip] unless ref $title;
4060 $widget->{c_tab} = $title;
3798 4061
3799 $self->{buttonbar}->add (new CFPlus::UI::Button
3800 markup => $title,
3801 tooltip => $tooltip,
3802 on_activate => sub { $self->set_current_page ($widget) },
3803 );
3804
3805 $self->{multiplexer}->add ($widget); 4062 $self->add ($widget);
3806} 4063}
3807 4064
3808sub get_current_page { 4065sub get_current_page {
3809 my ($self) = @_; 4066 my ($self) = @_;
3810 4067
3816 4073
3817 $self->{multiplexer}->set_current_page ($page); 4074 $self->{multiplexer}->set_current_page ($page);
3818 $self->emit (page_changed => $self->{multiplexer}{current}); 4075 $self->emit (page_changed => $self->{multiplexer}{current});
3819} 4076}
3820 4077
4078sub _draw {
4079 my ($self) = @_;
4080
4081 $self->SUPER::_draw ();
4082
4083 if (my $cur = $self->{multiplexer}{current}) {
4084 if ($cur = $cur->{c_tab_}) {
4085 glTranslate $self->{buttonbar}{x} + $cur->{x},
4086 $self->{buttonbar}{y} + $cur->{y};
4087 glLineWidth 3;
4088 #glEnable GL_BLEND;
4089 #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
4090 glColor @{$self->{active_outline}};
4091 glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5;
4092 glLineWidth 1;
4093 #glDisable GL_BLEND;
4094 }
4095 }
4096}
4097
3821############################################################################# 4098#############################################################################
3822 4099
3823package CFPlus::UI::Selector; 4100package DC::UI::Selector;
3824 4101
3825use utf8; 4102use utf8;
3826 4103
3827our @ISA = CFPlus::UI::Button::; 4104our @ISA = DC::UI::Button::;
3828 4105
3829sub new { 4106sub new {
3830 my $class = shift; 4107 my $class = shift;
3831 4108
3832 my $self = $class->SUPER::new ( 4109 my $self = $class->SUPER::new (
3849 my ($value, $title, $tooltip) = @$_; 4126 my ($value, $title, $tooltip) = @$_;
3850 4127
3851 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 4128 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
3852 } 4129 }
3853 4130
3854 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); 4131 DC::UI::Menu->new (items => \@menu_items)->popup ($ev);
3855} 4132}
3856 4133
3857sub _set_value { 4134sub _set_value {
3858 my ($self, $value) = @_; 4135 my ($self, $value) = @_;
3859 4136
3860 my ($item) = grep $_->[0] eq $value, @{ $self->{options} } 4137 my ($item) = grep $_->[0] eq $value, @{ $self->{options} };
4138 $item ||= $self->{options}[0]
3861 or return; 4139 or return;
3862 4140
3863 $self->{value} = $item->[0]; 4141 $self->{value} = $item->[0];
3864 $self->set_markup ("$item->[1] ⇓"); 4142 $self->set_markup ("$item->[1] ⇓");
3865 $self->set_tooltip ($item->[2]); 4143# $self->set_tooltip ($item->[2]);
3866} 4144}
3867 4145
3868sub set_value { 4146sub set_value {
3869 my ($self, $value) = @_; 4147 my ($self, $value) = @_;
3870 4148
3872 4150
3873 $self->_set_value ($value); 4151 $self->_set_value ($value);
3874 $self->emit (changed => $value); 4152 $self->emit (changed => $value);
3875} 4153}
3876 4154
4155sub set_options {
4156 my ($self, $options) = @_;
4157
4158 $self->{options} = $options;
4159 $self->_set_value ($self->{value});
4160}
4161
3877############################################################################# 4162#############################################################################
3878 4163
3879package CFPlus::UI::Statusbox; 4164package DC::UI::Statusbox;
3880 4165
3881our @ISA = CFPlus::UI::VBox::; 4166our @ISA = DC::UI::VBox::;
3882 4167
3883sub new { 4168sub new {
3884 my $class = shift; 4169 my $class = shift;
3885 4170
3886 my $self = $class->SUPER::new ( 4171 my $self = $class->SUPER::new (
3887 fontsize => 0.8, 4172 fontsize => 0.8,
3888 @_, 4173 @_,
3889 ); 4174 );
3890 4175
3891 CFPlus::weaken (my $this = $self); 4176 DC::weaken (my $this = $self);
3892 4177
3893 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 4178 $self->{timer} = EV::timer 1, 1, sub { $this->reorder };
3894 4179
3895 $self 4180 $self
3896} 4181}
3897 4182
3898sub reorder { 4183sub reorder {
3899 my ($self) = @_; 4184 my ($self) = @_;
3900 my $NOW = Time::HiRes::time; 4185 my $NOW = Time::HiRes::time;
3901 4186
3902 # freeze display when hovering over any label 4187 # freeze display when hovering over any label
3903 return if $CFPlus::UI::TOOLTIP->{owner} 4188 return if $DC::UI::TOOLTIP->{owner}
3904 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label}, 4189 && grep $DC::UI::TOOLTIP->{owner} == $_->{label},
3905 values %{ $self->{item} }; 4190 values %{ $self->{item} };
3906 4191
3907 while (my ($k, $v) = each %{ $self->{item} }) { 4192 while (my ($k, $v) = each %{ $self->{item} }) {
3908 delete $self->{item}{$k} if $v->{timeout} < $NOW; 4193 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3909 } 4194 }
4195
4196 $self->{timer}->set (1, 1);
3910 4197
3911 my @widgets; 4198 my @widgets;
3912 4199
3913 my @items = sort { 4200 my @items = sort {
3914 $a->{pri} <=> $b->{pri} 4201 $a->{pri} <=> $b->{pri}
3915 or $b->{id} <=> $a->{id} 4202 or $b->{id} <=> $a->{id}
3916 } values %{ $self->{item} }; 4203 } values %{ $self->{item} };
3917
3918 $self->{timer}->interval (1);
3919 4204
3920 my $count = 10 + 1; 4205 my $count = 10 + 1;
3921 for my $item (@items) { 4206 for my $item (@items) {
3922 last unless --$count; 4207 last unless --$count;
3923 4208
3930 for ($short) { 4215 for ($short) {
3931 s/^\s+//; 4216 s/^\s+//;
3932 s/\s+/ /g; 4217 s/\s+/ /g;
3933 } 4218 }
3934 4219
3935 new CFPlus::UI::Label 4220 new DC::UI::Label
3936 markup => $short, 4221 markup => $short,
3937 tooltip => $item->{tooltip}, 4222 tooltip => $item->{tooltip},
3938 tooltip_font => $::FONT_PROP, 4223 tooltip_font => $::FONT_PROP,
3939 tooltip_width => 0.67, 4224 tooltip_width => 0.67,
3940 fontsize => $item->{fontsize} || $self->{fontsize}, 4225 fontsize => $item->{fontsize} || $self->{fontsize},
3947 if ((my $diff = $item->{timeout} - $NOW) < 2) { 4232 if ((my $diff = $item->{timeout} - $NOW) < 2) {
3948 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; 4233 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2;
3949 $label->update; 4234 $label->update;
3950 $label->set_max_size (undef, $label->{req_h} * $diff) 4235 $label->set_max_size (undef, $label->{req_h} * $diff)
3951 if $diff < 1; 4236 if $diff < 1;
3952 $self->{timer}->interval (1/30); 4237 $self->{timer}->set (1/30, 1/30);
3953 } else { 4238 } else {
3954 $label->{fg}[3] = $item->{fg}[3] || 1; 4239 $label->{fg}[3] = $item->{fg}[3] || 1;
3955 } 4240 }
3956 4241
3957 push @widgets, $label; 4242 push @widgets, $label;
4019 $self->SUPER::destroy; 4304 $self->SUPER::destroy;
4020} 4305}
4021 4306
4022############################################################################# 4307#############################################################################
4023 4308
4024package CFPlus::UI::Root; 4309package DC::UI::Root;
4025 4310
4026our @ISA = CFPlus::UI::Container::; 4311our @ISA = DC::UI::Container::;
4027 4312
4028use List::Util qw(min max); 4313use List::Util qw(min max);
4029 4314
4030use CFPlus::OpenGL; 4315use DC::OpenGL;
4031 4316
4032sub new { 4317sub new {
4033 my $class = shift; 4318 my $class = shift;
4034 4319
4035 my $self = $class->SUPER::new ( 4320 my $self = $class->SUPER::new (
4036 visible => 1, 4321 visible => 1,
4037 @_, 4322 @_,
4038 ); 4323 );
4039 4324
4040 CFPlus::weaken ($self->{root} = $self); 4325 DC::weaken ($self->{root} = $self);
4041 4326
4042 $self 4327 $self
4043} 4328}
4044 4329
4045sub size_request { 4330sub size_request {
4093} 4378}
4094 4379
4095sub update { 4380sub update {
4096 my ($self) = @_; 4381 my ($self) = @_;
4097 4382
4098 $::WANT_REFRESH++; 4383 $::WANT_REFRESH = 1;
4099} 4384}
4100 4385
4101sub add { 4386sub add {
4102 my ($self, @children) = @_; 4387 my ($self, @children) = @_;
4103 4388
4248 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 4533 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
4249 glMatrixMode GL_MODELVIEW; 4534 glMatrixMode GL_MODELVIEW;
4250 glLoadIdentity; 4535 glLoadIdentity;
4251 4536
4252 { 4537 {
4253 package CFPlus::UI::Base; 4538 package DC::UI::Base;
4254 4539
4255 local ($draw_x, $draw_y, $draw_w, $draw_h) = 4540 local ($draw_x, $draw_y, $draw_w, $draw_h) =
4256 (0, 0, $self->{w}, $self->{h}); 4541 (0, 0, $self->{w}, $self->{h});
4257 4542
4258 $self->_draw; 4543 $self->_draw;
4259 } 4544 }
4260} 4545}
4261 4546
4262############################################################################# 4547#############################################################################
4263 4548
4264package CFPlus::UI; 4549package DC::UI;
4265 4550
4266$ROOT = new CFPlus::UI::Root; 4551$ROOT = new DC::UI::Root;
4267$TOOLTIP = new CFPlus::UI::Tooltip z => 900; 4552$TOOLTIP = new DC::UI::Tooltip z => 900;
4268 4553
42691 45541
4270 4555

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines