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.442 by root, Mon Oct 8 17:01:03 2007 UTC vs.
Revision 1.481 by root, Tue Oct 12 05:11:38 2010 UTC

1package CFPlus::UI; 1package DC::UI;
2 2
3use utf8; 3use common::sense;
4use strict;
5 4
6use List::Util (); 5use List::Util ();
7use Event;
8 6
9use CFPlus; 7use Guard ();
8
9use DC;
10use CFPlus::Pod; 10use DC::Pod;
11use CFPlus::Texture; 11use DC::Texture;
12 12
13our ($FOCUS, $HOVER, $GRAB); # various widgets 13our ($FOCUS, $HOVER, $GRAB); # various widgets
14 14
15our $LAYOUT; 15our $LAYOUT;
16our $ROOT; 16our $ROOT;
17our $TOOLTIP; 17our $TOOLTIP;
18our $BUTTON_STATE; 18our $BUTTON_STATE;
19 19
20our %WIDGET; # all widgets, weak-referenced 20our %WIDGET; # all widgets, weak-referenced
21 21
22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { 22our $TOOLTIP_WATCHER = EV::timer_ns 0, 0.03, sub {
23 $_[0]->stop;
24
23 if (!$GRAB) { 25 if (!$GRAB) {
24 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 26 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
25 if (length $widget->{tooltip}) { 27 if (length $widget->{tooltip}) {
26 if ($TOOLTIP->{owner} != $widget) { 28 if ($TOOLTIP->{owner} != $widget) {
27 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; 29 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
42 } 44 }
43 45
44 $TOOLTIP->hide; 46 $TOOLTIP->hide;
45 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; 47 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
46 delete $TOOLTIP->{owner}; 48 delete $TOOLTIP->{owner};
47}); 49};
48 50
49sub get_layout { 51sub get_layout {
50 my $layout; 52 my $layout;
51 53
52 for (grep { $_->{name} } values %WIDGET) { 54 for (grep { $_->{name} } values %WIDGET) {
87 my $hover = $HOVER; $HOVER = $widget; 89 my $hover = $HOVER; $HOVER = $widget;
88 90
89 $hover->update if $hover && $hover->{can_hover}; 91 $hover->update if $hover && $hover->{can_hover};
90 $HOVER->update if $HOVER && $HOVER->{can_hover}; 92 $HOVER->update if $HOVER && $HOVER->{can_hover};
91 93
92 $TOOLTIP_WATCHER->start; 94 $TOOLTIP_WATCHER->again;
93 } 95 }
94} 96}
95 97
96sub feed_sdl_button_down_event { 98sub feed_sdl_button_down_event {
97 my ($ev) = @_; 99 my ($ev) = @_;
103 my $widget = $ROOT->find_widget ($x, $y); 105 my $widget = $ROOT->find_widget ($x, $y);
104 106
105 $GRAB = $widget; 107 $GRAB = $widget;
106 $GRAB->update if $GRAB; 108 $GRAB->update if $GRAB;
107 109
108 $TOOLTIP_WATCHER->cb->(); 110 $TOOLTIP_WATCHER->invoke;
109 } 111 }
110 112
111 if ($GRAB) { 113 if ($GRAB) {
112 if ($ev->{button} == 4 || $ev->{button} == 5) { 114 if ($ev->{button} == 4 || $ev->{button} == 5) {
113 # mousewheel 115 # mousewheel
114 my $delta = $ev->{button} * 2 - 9; 116 my $delta = $ev->{button} * 2 - 9;
115 my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT; 117 my $shift = $ev->{mod} & DC::KMOD_SHIFT;
116 118
117 $ev->{dx} = $shift ? $delta : 0; 119 $ev->{dx} = $shift ? $delta : 0;
118 $ev->{dy} = $shift ? 0 : $delta; 120 $ev->{dy} = $shift ? 0 : $delta;
119 121
120 $GRAB->emit (mouse_wheel => $ev); 122 $GRAB->emit (mouse_wheel => $ev);
138 my $grab = $GRAB; undef $GRAB; 140 my $grab = $GRAB; undef $GRAB;
139 $grab->update if $grab; 141 $grab->update if $grab;
140 $GRAB->update if $GRAB; 142 $GRAB->update if $GRAB;
141 143
142 check_hover $widget; 144 check_hover $widget;
143 $TOOLTIP_WATCHER->cb->(); 145 $TOOLTIP_WATCHER->invoke;
144 } 146 }
145} 147}
146 148
147sub feed_sdl_motion_event { 149sub feed_sdl_motion_event {
148 my ($ev) = @_; 150 my ($ev) = @_;
188# call when resolution changes etc. 190# call when resolution changes etc.
189sub rescale_widgets { 191sub rescale_widgets {
190 my ($sx, $sy) = @_; 192 my ($sx, $sy) = @_;
191 193
192 for my $widget (values %WIDGET) { 194 for my $widget (values %WIDGET) {
193 if ($widget->{is_toplevel}) { 195 if ($widget->{is_toplevel} || $widget->{c_rescale}) {
194 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 196 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
195 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 197 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
196 198
197 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; 199 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/;
198 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 200 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
210 reconfigure_widgets; 212 reconfigure_widgets;
211} 213}
212 214
213############################################################################# 215#############################################################################
214 216
215package CFPlus::UI::Event; 217package DC::UI::Event;
216 218
217sub xy { 219sub xy {
218 $_[1]->coord2local ($_[0]{x}, $_[0]{y}) 220 $_[1]->coord2local ($_[0]{x}, $_[0]{y})
219} 221}
220 222
221############################################################################# 223#############################################################################
222 224
223package CFPlus::UI::Base; 225package DC::UI::Base;
224 226
225use strict; 227use common::sense;
226 228
227use CFPlus::OpenGL; 229use DC::OpenGL;
228 230
229sub new { 231sub new {
230 my $class = shift; 232 my $class = shift;
231 233
232 my $self = bless { 234 my $self = bless {
237 h => undef, 239 h => undef,
238 can_events => 1, 240 can_events => 1,
239 @_ 241 @_
240 }, $class; 242 }, $class;
241 243
242 CFPlus::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); 244 DC::weaken ($DC::UI::WIDGET{$self+0} = $self);
243 245
244 for (keys %$self) { 246 for (keys %$self) {
245 if (/^on_(.*)$/) { 247 if (/^on_(.*)$/) {
246 $self->connect ($1 => delete $self->{$_}); 248 $self->connect ($1 => delete $self->{$_});
247 } 249 }
248 } 250 }
249 251
250 if (my $layout = $CFPlus::UI::LAYOUT->{$self->{name}}) { 252 if (my $layout = $DC::UI::LAYOUT->{$self->{name}}) {
251 $self->{x} = $layout->{x} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{x}; 253 $self->{x} = $layout->{x} * $DC::UI::ROOT->{alloc_w} if exists $layout->{x};
252 $self->{y} = $layout->{y} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{y}; 254 $self->{y} = $layout->{y} * $DC::UI::ROOT->{alloc_h} if exists $layout->{y};
253 $self->{force_w} = $layout->{w} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{w}; 255 $self->{force_w} = $layout->{w} * $DC::UI::ROOT->{alloc_w} if exists $layout->{w};
254 $self->{force_h} = $layout->{h} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{h}; 256 $self->{force_h} = $layout->{h} * $DC::UI::ROOT->{alloc_h} if exists $layout->{h};
255 257
256 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; 258 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x};
257 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; 259 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y};
258 260
259 $self->show if $layout->{show}; 261 $self->show if $layout->{show};
277sub show { 279sub show {
278 my ($self) = @_; 280 my ($self) = @_;
279 281
280 return if $self->{parent}; 282 return if $self->{parent};
281 283
282 $CFPlus::UI::ROOT->add ($self); 284 $DC::UI::ROOT->add ($self);
283} 285}
284 286
285sub set_visible { 287sub set_visible {
286 my ($self) = @_; 288 my ($self) = @_;
287 289
288 return if $self->{visible}; 290 return if $self->{visible};
291
292 $self->{parent} && $self->{parent}{root}#d#
293 or return ::clienterror ("set_visible called without parent ($self->{parent}) or root\n" => 1);
289 294
290 $self->{root} = $self->{parent}{root}; 295 $self->{root} = $self->{parent}{root};
291 $self->{visible} = $self->{parent}{visible} + 1; 296 $self->{visible} = $self->{parent}{visible} + 1;
292 297
293 $self->emit (visibility_change => 1); 298 $self->emit (visibility_change => 1);
294 299
295 $self->realloc if !exists $self->{req_w}; 300 $self->realloc if !exists $self->{req_w};
296 301
297 $_->set_visible for $self->children; 302 $_->set_visible for $self->visible_children;
298} 303}
299 304
300sub set_invisible { 305sub set_invisible {
301 my ($self) = @_; 306 my ($self) = @_;
302 307
308 delete $self->{root}; 313 delete $self->{root};
309 314
310 undef $GRAB if $GRAB == $self; 315 undef $GRAB if $GRAB == $self;
311 undef $HOVER if $HOVER == $self; 316 undef $HOVER if $HOVER == $self;
312 317
313 $CFPlus::UI::TOOLTIP_WATCHER->cb->() 318 $DC::UI::TOOLTIP_WATCHER->invoke
314 if $TOOLTIP->{owner} == $self; 319 if $TOOLTIP->{owner} == $self;
315 320
316 $self->emit ("focus_out"); 321 $self->emit ("focus_out");
317 $self->emit (visibility_change => 0); 322 $self->emit (visibility_change => 0);
318} 323}
337sub hide { 342sub hide {
338 my ($self) = @_; 343 my ($self) = @_;
339 344
340 $self->set_invisible; 345 $self->set_invisible;
341 346
347 # extra $parent copy for 5.8.8+ bug workaround
348 # (otherwise $_[0] in remove gets freed
349 if (my $parent = $self->{parent}) {
342 $self->{parent}->remove ($self) 350 $parent->remove ($self);
343 if $self->{parent}; 351 }
344} 352}
345 353
346sub move_abs { 354sub move_abs {
347 my ($self, $x, $y, $z) = @_; 355 my ($self, $x, $y, $z) = @_;
348 356
364 372
365# traverse the widget chain up to find the maximum "physical" size constraints 373# traverse the widget chain up to find the maximum "physical" size constraints
366sub get_max_wh { 374sub get_max_wh {
367 my ($self) = @_; 375 my ($self) = @_;
368 376
377 my ($w, $h) = @$self{qw(max_w max_h)};
378
379 if ($w <= 0 || $h <= 0) {
380 my ($mw, $mh) = $self->{parent}
369 return $self->{parent}->get_max_wh 381 ? $self->{parent}->get_max_wh
370 if $self->{parent};
371
372 ($::WIDTH, $::HEIGHT) 382 : ($::WIDTH, $::HEIGHT);
383
384 $w = $mw if $w <= 0;
385 $h = $mh if $h <= 0;
386 }
387
388 ($w, $h)
373} 389}
374 390
375sub size_request { 391sub size_request {
376 require Carp; 392 require Carp;
377 Carp::confess "size_request is abstract"; 393 Carp::confess "size_request is abstract";
385 my ($self, $x, $y, $w, $h) = @_; 401 my ($self, $x, $y, $w, $h) = @_;
386 402
387 if ($self->{aspect}) { 403 if ($self->{aspect}) {
388 my ($ow, $oh) = ($w, $h); 404 my ($ow, $oh) = ($w, $h);
389 405
390 $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect}; 406 $w = List::Util::min $w, DC::ceil $h * $self->{aspect};
391 $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect}; 407 $h = List::Util::min $h, DC::ceil $w / $self->{aspect};
392 408
393 # use alignment to adjust x, y 409 # use alignment to adjust x, y
394 410
395 $x += int 0.5 * ($ow - $w); 411 $x += int 0.5 * ($ow - $w);
396 $y += int 0.5 * ($oh - $h); 412 $y += int 0.5 * ($oh - $h);
437 453
438 return if $self->{tooltip} eq $tooltip; 454 return if $self->{tooltip} eq $tooltip;
439 455
440 $self->{tooltip} = $tooltip; 456 $self->{tooltip} = $tooltip;
441 457
442 if ($CFPlus::UI::TOOLTIP->{owner} == $self) { 458 if ($DC::UI::TOOLTIP->{owner} == $self) {
443 delete $CFPlus::UI::TOOLTIP->{owner}; 459 delete $DC::UI::TOOLTIP->{owner};
444 $CFPlus::UI::TOOLTIP_WATCHER->cb->(); 460 $DC::UI::TOOLTIP_WATCHER->invoke;
445 } 461 }
446} 462}
447 463
448# translate global coordinates to local coordinate system 464# translate global coordinates to local coordinate system
449sub coord2local { 465sub coord2local {
450 my ($self, $x, $y) = @_; 466 my ($self, $x, $y) = @_;
451 467
452 Carp::confess unless $self->{parent};#d# 468 return (undef, undef) unless $self->{parent};
453 469
454 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) 470 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
455} 471}
456 472
457# translate local coordinates to global coordinate system 473# translate local coordinates to global coordinate system
458sub coord2global { 474sub coord2global {
459 my ($self, $x, $y) = @_; 475 my ($self, $x, $y) = @_;
460 476
461 Carp::confess unless $self->{parent};#d# 477 return (undef, undef) unless $self->{parent};
462 478
463 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) 479 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
464} 480}
465 481
466sub invoke_focus_in { 482sub invoke_focus_in {
515sub connect { 531sub connect {
516 my ($self, $signal, $cb) = @_; 532 my ($self, $signal, $cb) = @_;
517 533
518 push @{ $self->{signal_cb}{$signal} }, $cb; 534 push @{ $self->{signal_cb}{$signal} }, $cb;
519 535
520 defined wantarray and CFPlus::guard { 536 defined wantarray and Guard::guard {
521 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, 537 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
522 @{ $self->{signal_cb}{$signal} }; 538 @{ $self->{signal_cb}{$signal} };
523 } 539 }
524} 540}
525 541
563# in .xs 579# in .xs
564 580
565sub set_parent { 581sub set_parent {
566 my ($self, $parent) = @_; 582 my ($self, $parent) = @_;
567 583
568 CFPlus::weaken ($self->{parent} = $parent); 584 DC::weaken ($self->{parent} = $parent);
569 $self->set_visible if $parent->{visible}; 585 $self->set_visible if $parent->{visible};
570} 586}
571 587
572sub realloc { 588sub realloc {
573 my ($self) = @_; 589 my ($self) = @_;
611} 627}
612 628
613sub DESTROY { 629sub DESTROY {
614 my ($self) = @_; 630 my ($self) = @_;
615 631
616 return if CFPlus::in_destruct; 632 return if DC::in_destruct;
617 633
618 local $@; 634 local $@;
619 eval { $self->destroy }; 635 eval { $self->destroy };
620 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 636 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
621 637
622 delete $WIDGET{$self+0}; 638 delete $WIDGET{$self+0};
623} 639}
624 640
625############################################################################# 641#############################################################################
626 642
627package CFPlus::UI::DrawBG; 643package DC::UI::DrawBG;
628 644
629our @ISA = CFPlus::UI::Base::; 645our @ISA = DC::UI::Base::;
630 646
631use strict; 647use common::sense;
648
632use CFPlus::OpenGL; 649use DC::OpenGL;
633 650
634sub new { 651sub new {
635 my $class = shift; 652 my $class = shift;
636 653
637 $class->SUPER::new ( 654 $class->SUPER::new (
639 #active_bg => [1, 1, 1, 0.5], 656 #active_bg => [1, 1, 1, 0.5],
640 @_ 657 @_
641 ) 658 )
642} 659}
643 660
661sub set_bg {
662 my ($self, $bg) = @_;
663
664 $self->{bg} = $bg;
665 $self->update;
666}
667
644sub _draw { 668sub _draw {
645 my ($self) = @_; 669 my ($self) = @_;
646 670
647 my $color = $FOCUS == $self && $self->{active_bg} 671 my $color = $FOCUS == $self
648 ? $self->{active_bg} 672 ? $self->{active_bg} || $self->{bg}
649 : $self->{bg}; 673 : $self->{bg};
650 674
651 if ($color && (@$color < 4 || $color->[3])) { 675 if ($color && (@$color < 4 || $color->[3])) {
652 my ($w, $h) = @$self{qw(w h)}; 676 my ($w, $h) = @$self{qw(w h)};
653 677
659 } 683 }
660} 684}
661 685
662############################################################################# 686#############################################################################
663 687
664package CFPlus::UI::Empty; 688package DC::UI::Empty;
665 689
666our @ISA = CFPlus::UI::Base::; 690our @ISA = DC::UI::Base::;
667 691
668sub new { 692sub new {
669 my ($class, %arg) = @_; 693 my ($class, %arg) = @_;
670 $class->SUPER::new (can_events => 0, %arg); 694 $class->SUPER::new (can_events => 0, %arg);
671} 695}
678 702
679sub draw { } 703sub draw { }
680 704
681############################################################################# 705#############################################################################
682 706
683package CFPlus::UI::Container; 707package DC::UI::Container;
684 708
685our @ISA = CFPlus::UI::Base::; 709our @ISA = DC::UI::Base::;
686 710
687sub new { 711sub new {
688 my ($class, %arg) = @_; 712 my ($class, %arg) = @_;
689 713
690 my $children = delete $arg{children}; 714 my $children = delete $arg{children};
784 $_->draw for $self->visible_children; 808 $_->draw for $self->visible_children;
785} 809}
786 810
787############################################################################# 811#############################################################################
788 812
789package CFPlus::UI::Bin; 813package DC::UI::Bin;
790 814
791our @ISA = CFPlus::UI::Container::; 815our @ISA = DC::UI::Container::;
792 816
793sub new { 817sub new {
794 my ($class, %arg) = @_; 818 my ($class, %arg) = @_;
795 819
796 my $child = (delete $arg{child}) || new CFPlus::UI::Empty::; 820 my $child = (delete $arg{child}) || new DC::UI::Empty::;
797 821
798 $class->SUPER::new (children => [$child], %arg) 822 $class->SUPER::new (children => [$child], %arg)
799} 823}
800 824
801sub add { 825sub add {
808sub remove { 832sub remove {
809 my ($self, $widget) = @_; 833 my ($self, $widget) = @_;
810 834
811 $self->SUPER::remove ($widget); 835 $self->SUPER::remove ($widget);
812 836
813 $self->{children} = [new CFPlus::UI::Empty] 837 $self->{children} = [new DC::UI::Empty]
814 unless @{$self->{children}}; 838 unless @{$self->{children}};
815} 839}
816 840
817sub child { $_[0]->{children}[0] } 841sub child { $_[0]->{children}[0] }
818 842
829} 853}
830 854
831############################################################################# 855#############################################################################
832# back-buffered drawing area 856# back-buffered drawing area
833 857
834package CFPlus::UI::Window; 858package DC::UI::Window;
835 859
836our @ISA = CFPlus::UI::Bin::; 860our @ISA = DC::UI::Bin::;
837 861
838use CFPlus::OpenGL; 862use DC::OpenGL;
839 863
840sub new { 864sub new {
841 my ($class, %arg) = @_; 865 my ($class, %arg) = @_;
842 866
843 my $self = $class->SUPER::new (%arg); 867 my $self = $class->SUPER::new (%arg);
865} 889}
866 890
867sub render_child { 891sub render_child {
868 my ($self) = @_; 892 my ($self) = @_;
869 893
870 $self->{texture} = new_from_opengl CFPlus::Texture $self->{w}, $self->{h}, sub { 894 $self->{texture} = new_from_opengl DC::Texture $self->{w}, $self->{h}, sub {
871 glClearColor 0, 0, 0, 0; 895 glClearColor 0, 0, 0, 0;
872 glClear GL_COLOR_BUFFER_BIT; 896 glClear GL_COLOR_BUFFER_BIT;
873 897
874 { 898 {
875 package CFPlus::UI::Base; 899 package DC::UI::Base;
876 900
877 local ($draw_x, $draw_y, $draw_w, $draw_h) = 901 local ($draw_x, $draw_y, $draw_w, $draw_h) =
878 (0, 0, $self->{w}, $self->{h}); 902 (0, 0, $self->{w}, $self->{h});
879 903
880 $self->_render; 904 $self->_render;
897 glDisable GL_TEXTURE_2D; 921 glDisable GL_TEXTURE_2D;
898} 922}
899 923
900############################################################################# 924#############################################################################
901 925
902package CFPlus::UI::ViewPort; 926package DC::UI::ViewPort;
903 927
904use List::Util qw(min max); 928use List::Util qw(min max);
905 929
906our @ISA = CFPlus::UI::Window::; 930our @ISA = DC::UI::Window::;
907 931
908sub new { 932sub new {
909 my $class = shift; 933 my $class = shift;
910 934
911 $class->SUPER::new ( 935 $class->SUPER::new (
995 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 1019 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
996 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1020 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
997 ) { 1021 ) {
998 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) 1022 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
999 } else { 1023 } else {
1000 $self->CFPlus::UI::Base::find_widget ($x, $y) 1024 $self->DC::UI::Base::find_widget ($x, $y)
1001 } 1025 }
1002} 1026}
1003 1027
1004sub _render { 1028sub _render {
1005 my ($self) = @_; 1029 my ($self) = @_;
1006 1030
1007 local $CFPlus::UI::Base::draw_x = $CFPlus::UI::Base::draw_x - $self->{view_x}; 1031 local $DC::UI::Base::draw_x = $DC::UI::Base::draw_x - $self->{view_x};
1008 local $CFPlus::UI::Base::draw_y = $CFPlus::UI::Base::draw_y - $self->{view_y}; 1032 local $DC::UI::Base::draw_y = $DC::UI::Base::draw_y - $self->{view_y};
1009 1033
1010 CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 1034 DC::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
1011 1035
1012 $self->SUPER::_render; 1036 $self->SUPER::_render;
1013} 1037}
1014 1038
1015############################################################################# 1039#############################################################################
1016 1040
1017package CFPlus::UI::ScrolledWindow; 1041package DC::UI::ScrolledWindow;
1018 1042
1019our @ISA = CFPlus::UI::Table::; 1043our @ISA = DC::UI::Table::;
1020 1044
1021sub new { 1045sub new {
1022 my ($class, %arg) = @_; 1046 my ($class, %arg) = @_;
1023 1047
1024 my $child = delete $arg{child}; 1048 my $child = delete $arg{child};
1025 1049
1026 my $self; 1050 my $self;
1027 1051
1028 my $hslider = new CFPlus::UI::Slider 1052 my $hslider = new DC::UI::Slider
1029 c_col => 0, 1053 c_col => 0,
1030 c_row => 1, 1054 c_row => 1,
1031 vertical => 0, 1055 vertical => 0,
1032 range => [0, 0, 1, 0.01], # HACK fix 1056 range => [0, 0, 1, 0.01], # HACK fix
1033 on_changed => sub { 1057 on_changed => sub {
1034 $self->{hpos} = $_[1]; 1058 $self->{hpos} = $_[1];
1035 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1059 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1036 }, 1060 },
1037 ; 1061 ;
1038 1062
1039 my $vslider = new CFPlus::UI::Slider 1063 my $vslider = new DC::UI::Slider
1040 c_col => 1, 1064 c_col => 1,
1041 c_row => 0, 1065 c_row => 0,
1042 vertical => 1, 1066 vertical => 1,
1043 range => [0, 0, 1, 0.01], # HACK fix 1067 range => [0, 0, 1, 0.01], # HACK fix
1044 on_changed => sub { 1068 on_changed => sub {
1056 col_expand => [1, 0], 1080 col_expand => [1, 0],
1057 row_expand => [1, 0], 1081 row_expand => [1, 0],
1058 %arg, 1082 %arg,
1059 ); 1083 );
1060 1084
1061 $self->{vp} = new CFPlus::UI::ViewPort 1085 $self->{vp} = new DC::UI::ViewPort
1062 c_col => 0, 1086 c_col => 0,
1063 c_row => 0, 1087 c_row => 0,
1064 expand => 1, 1088 expand => 1,
1065 scroll_x => $self->{scroll_x}, 1089 scroll_x => $self->{scroll_x},
1066 scroll_y => $self->{scroll_y}, 1090 scroll_y => $self->{scroll_y},
1192 $self->SUPER::invoke_size_allocate ($w, $h) 1216 $self->SUPER::invoke_size_allocate ($w, $h)
1193} 1217}
1194 1218
1195############################################################################# 1219#############################################################################
1196 1220
1197package CFPlus::UI::Frame; 1221package DC::UI::Frame;
1198 1222
1199our @ISA = CFPlus::UI::Bin::; 1223our @ISA = DC::UI::Bin::;
1200 1224
1201use CFPlus::OpenGL; 1225use DC::OpenGL;
1202 1226
1203sub new { 1227sub new {
1204 my $class = shift; 1228 my $class = shift;
1205 1229
1206 $class->SUPER::new ( 1230 $class->SUPER::new (
1225 $self->SUPER::_draw; 1249 $self->SUPER::_draw;
1226} 1250}
1227 1251
1228############################################################################# 1252#############################################################################
1229 1253
1230package CFPlus::UI::FancyFrame; 1254package DC::UI::FancyFrame;
1231 1255
1232our @ISA = CFPlus::UI::Bin::; 1256our @ISA = DC::UI::Bin::;
1233 1257
1234use CFPlus::OpenGL; 1258use DC::OpenGL;
1235 1259
1236sub new { 1260sub new {
1237 my ($class, %arg) = @_; 1261 my ($class, %arg) = @_;
1238 1262
1239 if ((exists $arg{label}) && !ref $arg{label}) { 1263 if ((exists $arg{label}) && !ref $arg{label}) {
1240 $arg{label} = new CFPlus::UI::Label 1264 $arg{label} = new DC::UI::Label
1241 align => 1, 1265 align => 1,
1242 valign => 0, 1266 valign => 0.5,
1243 text => $arg{label}, 1267 text => $arg{label},
1244 fontsize => ($arg{border} || 0.8) * 0.75; 1268 fontsize => ($arg{border} || 0.8) * 0.75;
1245 } 1269 }
1246 1270
1247 my $self = $class->SUPER::new ( 1271 my $self = $class->SUPER::new (
1248 # label => "", 1272 # label => "",
1249 fg => [0.6, 0.3, 0.1], 1273 fg => undef,
1250 border => 0.8, 1274 border => 0.8,
1251 style => 'single', 1275 style => 'single',
1252 %arg, 1276 %arg,
1253 ); 1277 );
1254 1278
1257 1281
1258sub add { 1282sub add {
1259 my ($self, @widgets) = @_; 1283 my ($self, @widgets) = @_;
1260 1284
1261 $self->SUPER::add (@widgets); 1285 $self->SUPER::add (@widgets);
1262 $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label}; 1286 $self->DC::UI::Container::add ($self->{label}) if $self->{label};
1263} 1287}
1264 1288
1265sub border { 1289sub border {
1266 int $_[0]{border} * $::FONTSIZE 1290 int $_[0]{border} * $::FONTSIZE
1267} 1291}
1307 my $border = $self->border; 1331 my $border = $self->border;
1308 my ($w, $h) = ($self->{w}, $self->{h}); 1332 my ($w, $h) = ($self->{w}, $self->{h});
1309 1333
1310 $child->draw; 1334 $child->draw;
1311 1335
1312 glColor @{$self->{fg}}; 1336 glColor @{$self->{fg} || $DC::THEME{fancyframe}};
1313 glBegin GL_LINE_STRIP; 1337 glBegin GL_LINE_STRIP;
1314 glVertex $border * 1.5 , $border * 0.5 + 0.5; 1338 glVertex $border * 1.5 , $border * 0.5 + 0.5;
1315 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; 1339 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5;
1316 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; 1340 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1317 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; 1341 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1325 } 1349 }
1326} 1350}
1327 1351
1328############################################################################# 1352#############################################################################
1329 1353
1330package CFPlus::UI::Toplevel; 1354package DC::UI::Toplevel;
1331 1355
1332our @ISA = CFPlus::UI::Bin::; 1356our @ISA = DC::UI::Bin::;
1333 1357
1334use CFPlus::OpenGL; 1358use DC::OpenGL;
1335 1359
1336my $bg = 1360my $bg =
1337 new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", 1361 new_from_resource DC::Texture "d1_bg.png",
1338 mipmap => 1, wrap => 1; 1362 mipmap => 1, wrap => 1;
1339 1363
1340my @border = 1364my @border =
1341 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1365 map { new_from_resource DC::Texture $_, mipmap => 1 }
1342 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1366 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1343 1367
1344my @icon = 1368my @icon =
1345 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1369 map { new_from_resource DC::Texture $_, mipmap => 1 }
1346 qw(x1_move.png x1_resize.png); 1370 qw(x1_move.png x1_resize.png);
1347 1371
1348sub new { 1372sub new {
1349 my ($class, %arg) = @_; 1373 my ($class, %arg) = @_;
1350 1374
1351 my $self = $class->SUPER::new ( 1375 my $self = $class->SUPER::new (
1352 bg => [1, 1, 1, 1], 1376 bg => [1, 1, 1, 1],
1353 border_bg => [1, 1, 1, 1], 1377 border_bg => [1, 1, 1, 1],
1354 border => 0.6, 1378 border => 0.8,
1355 can_events => 1, 1379 can_events => 1,
1356 min_w => 64, 1380 min_w => 64,
1357 min_h => 32, 1381 min_h => 32,
1358 %arg, 1382 %arg,
1359 ); 1383 );
1360 1384
1361 $self->{title_widget} = new CFPlus::UI::Label 1385 $self->{title_widget} = new DC::UI::Label
1362 align => 0, 1386 align => 0.5,
1363 valign => 1, 1387 valign => 1,
1364 text => $self->{title}, 1388 text => $self->{title},
1365 fontsize => $self->{border}, 1389 fontsize => $self->{border},
1366 if exists $self->{title}; 1390 if exists $self->{title};
1367 1391
1368 if ($self->{has_close_button}) { 1392 if ($self->{has_close_button}) {
1369 $self->{close_button} = 1393 $self->{close_button} =
1370 new CFPlus::UI::ImageButton 1394 new DC::UI::ImageButton
1371 path => 'x1_close.png', 1395 path => 'x1_close.png',
1372 on_activate => sub { $self->emit ("delete") }; 1396 on_activate => sub { $self->emit ("delete") };
1373 1397
1374 $self->CFPlus::UI::Container::add ($self->{close_button}); 1398 $self->DC::UI::Container::add ($self->{close_button});
1375 } 1399 }
1376 1400
1377 $self 1401 $self
1378} 1402}
1379 1403
1380sub add { 1404sub add {
1381 my ($self, @widgets) = @_; 1405 my ($self, @widgets) = @_;
1382 1406
1383 $self->SUPER::add (@widgets); 1407 $self->SUPER::add (@widgets);
1384 $self->CFPlus::UI::Container::add ($self->{close_button}) if $self->{close_button}; 1408 $self->DC::UI::Container::add ($self->{close_button}) if $self->{close_button};
1385 $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; 1409 $self->DC::UI::Container::add ($self->{title_widget}) if $self->{title_widget};
1386} 1410}
1387 1411
1388sub border { 1412sub border {
1389 int $_[0]{border} * $::FONTSIZE 1413 int $_[0]{border} * $::FONTSIZE
1390} 1414}
1528 glEnable GL_TEXTURE_2D; 1552 glEnable GL_TEXTURE_2D;
1529 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1553 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1530 1554
1531 my $border = $self->border; 1555 my $border = $self->border;
1532 1556
1557 if ($border) {
1533 glColor @{ $self->{border_bg} }; 1558 glColor @{ $self->{border_bg} };
1534 $border[0]->draw_quad_alpha ( 0, 0, $w, $border); 1559 $border[0]->draw_quad_alpha ( 0, 0, $w, $border);
1535 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); 1560 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch);
1536 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); 1561 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
1537 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); 1562 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border);
1538 1563
1539 # move 1564 # move
1540 my $w2 = ($w - $border) * .5; 1565 my $w2 = ($w - $border) * .5;
1541 my $h2 = ($h - $border) * .5; 1566 my $h2 = ($h - $border) * .5;
1542 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); 1567 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border);
1543 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); 1568 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border);
1544 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); 1569 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border);
1545 1570
1546 # resize 1571 # resize
1547 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); 1572 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border);
1548 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) 1573 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border)
1549 unless $self->{has_close_button}; 1574 unless $self->{has_close_button};
1550 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); 1575 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border);
1551 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); 1576 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border);
1577 }
1552 1578
1553 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 1579 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
1554 glColor @{ $self->{bg} }; 1580 glColor @{ $self->{bg} };
1555 1581
1556 # TODO: repeat texture not scale 1582 # TODO: repeat texture not scale
1575 if $self->{close_button}; 1601 if $self->{close_button};
1576} 1602}
1577 1603
1578############################################################################# 1604#############################################################################
1579 1605
1580package CFPlus::UI::Table; 1606package DC::UI::Table;
1581 1607
1582our @ISA = CFPlus::UI::Container::; 1608our @ISA = DC::UI::Container::;
1583 1609
1584use List::Util qw(max sum); 1610use List::Util qw(max sum);
1585 1611
1586use CFPlus::OpenGL; 1612use DC::OpenGL;
1587 1613
1588sub new { 1614sub new {
1589 my $class = shift; 1615 my $class = shift;
1590 1616
1591 $class->SUPER::new ( 1617 $class->SUPER::new (
1635 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; 1661 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)};
1636 1662
1637 my $sw = sum @w[$c .. $c + $cs - 1]; 1663 my $sw = sum @w[$c .. $c + $cs - 1];
1638 1664
1639 if ($w > $sw) { 1665 if ($w > $sw) {
1640 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; 1666 $_ += ($w - $sw) / ($_ ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1];
1641 } 1667 }
1642 } 1668 }
1643 1669
1644 # second pass, rows 1670 # second pass, rows
1645 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { 1671 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) {
1646 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; 1672 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)};
1647 1673
1648 my $sh = sum @h[$r .. $r + $rs - 1]; 1674 my $sh = sum @h[$r .. $r + $rs - 1];
1649 1675
1650 if ($h > $sh) { 1676 if ($h > $sh) {
1651 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; 1677 $_ += ($h - $sh) / ($_ ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1];
1652 } 1678 }
1653 } 1679 }
1654 1680
1655 (\@w, \@h) 1681 (\@w, \@h)
1656} 1682}
1679 @col_expand = (1) x @$ws unless @col_expand; 1705 @col_expand = (1) x @$ws unless @col_expand;
1680 my $col_expand = (sum @col_expand) || 1; 1706 my $col_expand = (sum @col_expand) || 1;
1681 1707
1682 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1708 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1683 1709
1684 CFPlus::UI::harmonize $ws; 1710 DC::UI::harmonize $ws;
1685 1711
1686 my @row_expand = @{$self->{row_expand}}; 1712 my @row_expand = @{$self->{row_expand}};
1687 @row_expand = (1) x @$ws unless @row_expand; 1713 @row_expand = (1) x @$ws unless @row_expand;
1688 my $row_expand = (sum @row_expand) || 1; 1714 my $row_expand = (sum @row_expand) || 1;
1689 1715
1690 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; 1716 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1691 1717
1692 CFPlus::UI::harmonize $hs; 1718 DC::UI::harmonize $hs;
1693 1719
1694 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } 1720 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] }
1695 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } 1721 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] }
1696 1722
1697 for my $widget ($self->children) { 1723 for my $widget ($self->children) {
1706 1 1732 1
1707} 1733}
1708 1734
1709############################################################################# 1735#############################################################################
1710 1736
1711package CFPlus::UI::Fixed; 1737package DC::UI::Fixed;
1712 1738
1713use List::Util qw(min max); 1739use List::Util qw(min max);
1714 1740
1715our @ISA = CFPlus::UI::Container::; 1741our @ISA = DC::UI::Container::;
1716 1742
1717sub _scale($$$) { 1743sub _scale($$$) {
1718 my ($rel, $val, $max) = @_; 1744 my ($rel, $val, $max) = @_;
1719 1745
1720 $rel ? $val * $max : $val 1746 $rel ? $val * $max : $val
1772 1 1798 1
1773} 1799}
1774 1800
1775############################################################################# 1801#############################################################################
1776 1802
1777package CFPlus::UI::Box; 1803package DC::UI::Box;
1778 1804
1779our @ISA = CFPlus::UI::Container::; 1805our @ISA = DC::UI::Container::;
1780 1806
1781sub size_request { 1807sub size_request {
1782 my ($self) = @_; 1808 my ($self) = @_;
1783 1809
1784 my @children = $self->visible_children; 1810 my @children = $self->visible_children;
1819 $req[$_] += $space * $children[$_]{expand} 1845 $req[$_] += $space * $children[$_]{expand}
1820 for 0 .. $#children; 1846 for 0 .. $#children;
1821 } 1847 }
1822 } 1848 }
1823 1849
1824 CFPlus::UI::harmonize \@req; 1850 DC::UI::harmonize \@req;
1825 1851
1826 my $pos = 0; 1852 my $pos = 0;
1827 for (0 .. $#children) { 1853 for (0 .. $#children) {
1828 my $alloc = $req[$_]; 1854 my $alloc = $req[$_];
1829 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); 1855 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h));
1834 1 1860 1
1835} 1861}
1836 1862
1837############################################################################# 1863#############################################################################
1838 1864
1839package CFPlus::UI::HBox; 1865package DC::UI::HBox;
1840 1866
1841our @ISA = CFPlus::UI::Box::; 1867our @ISA = DC::UI::Box::;
1842 1868
1843sub new { 1869sub new {
1844 my $class = shift; 1870 my $class = shift;
1845 1871
1846 $class->SUPER::new ( 1872 $class->SUPER::new (
1849 ) 1875 )
1850} 1876}
1851 1877
1852############################################################################# 1878#############################################################################
1853 1879
1854package CFPlus::UI::VBox; 1880package DC::UI::VBox;
1855 1881
1856our @ISA = CFPlus::UI::Box::; 1882our @ISA = DC::UI::Box::;
1857 1883
1858sub new { 1884sub new {
1859 my $class = shift; 1885 my $class = shift;
1860 1886
1861 $class->SUPER::new ( 1887 $class->SUPER::new (
1864 ) 1890 )
1865} 1891}
1866 1892
1867############################################################################# 1893#############################################################################
1868 1894
1869package CFPlus::UI::Label; 1895package DC::UI::Label;
1870 1896
1871our @ISA = CFPlus::UI::DrawBG::; 1897our @ISA = DC::UI::DrawBG::;
1872 1898
1873use CFPlus::OpenGL; 1899use DC::OpenGL;
1874 1900
1875sub new { 1901sub new {
1876 my ($class, %arg) = @_; 1902 my ($class, %arg) = @_;
1877 1903
1878 my $self = $class->SUPER::new ( 1904 my $self = $class->SUPER::new (
1883 #text => initial text 1909 #text => initial text
1884 #markup => initial narkup 1910 #markup => initial narkup
1885 #max_w => maximum pixel width 1911 #max_w => maximum pixel width
1886 #style => 0, # render flags 1912 #style => 0, # render flags
1887 ellipsise => 3, # end 1913 ellipsise => 3, # end
1888 layout => (new CFPlus::Layout), 1914 layout => (new DC::Layout),
1889 fontsize => 1, 1915 fontsize => 1,
1890 align => -1, 1916 align => 0.5,
1891 valign => -1, 1917 valign => 0.5,
1892 padding_x => 2, 1918 padding_x => 4,
1893 padding_y => 2, 1919 padding_y => 2,
1894 can_events => 0, 1920 can_events => 0,
1895 %arg 1921 %arg
1896 ); 1922 );
1897 1923
1898 if (exists $self->{template}) { 1924 if (exists $self->{template}) {
1899 my $layout = new CFPlus::Layout; 1925 my $layout = new DC::Layout;
1900 $layout->set_text (delete $self->{template}); 1926 $layout->set_text (delete $self->{template});
1901 $self->{template} = $layout; 1927 $self->{template} = $layout;
1902 } 1928 }
1903 1929
1904 if (exists $self->{markup}) { 1930 if (exists $self->{markup}) {
1963 1989
1964 $self->{size_req} ||= do { 1990 $self->{size_req} ||= do {
1965 my ($max_w, $max_h) = $self->get_max_wh; 1991 my ($max_w, $max_h) = $self->get_max_wh;
1966 1992
1967 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1993 $self->{layout}->set_font ($self->{font}) if $self->{font};
1968 $self->{layout}->set_width ($self->{max_w} || $max_w || -1); 1994 $self->{layout}->set_width ($max_w);
1969 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1995 $self->{layout}->set_ellipsise ($self->{ellipsise});
1970 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1996 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1971 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1997 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1972 1998
1973 my ($w, $h) = $self->{layout}->size; 1999 my ($w, $h) = $self->{layout}->size;
1974 2000
1975 if (exists $self->{template}) { 2001 if (exists $self->{template}) {
1976 $self->{template}->set_font ($self->{font}) if $self->{font}; 2002 $self->{template}->set_font ($self->{font}) if $self->{font};
1977 $self->{template}->set_width ($self->{max_w} || -1); 2003 $self->{template}->set_width ($max_w);
1978 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 2004 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1979 2005
1980 my ($w2, $h2) = $self->{template}->size; 2006 my ($w2, $h2) = $self->{template}->size;
1981 2007
1982 $w = List::Util::max $w, $w2; 2008 $w = List::Util::max $w, $w2;
2038 2064
2039 [$self->{layout}->size] 2065 [$self->{layout}->size]
2040 }; 2066 };
2041 2067
2042 unless (exists $self->{ox}) { 2068 unless (exists $self->{ox}) {
2043 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 2069 $self->{ox} = $self->{padding_x} + int $self->{align} * ($self->{w} - $size->[0] - $self->{padding_x} * 2);
2044 : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} 2070 $self->{oy} = $self->{padding_y} + int $self->{valign} * ($self->{h} - $size->[1] - $self->{padding_y} * 2);
2045 : ($self->{w} - $size->[0]) * 0.5);
2046
2047 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2048 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2049 : ($self->{h} - $size->[1]) * 0.5);
2050 2071
2051 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2072 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2052 }; 2073 };
2053 2074
2054# unless ($self->{list}) { 2075# unless ($self->{list}) {
2055# $self->{list} = CFPlus::OpenGL::glGenList; 2076# $self->{list} = DC::OpenGL::glGenList;
2056# CFPlus::OpenGL::glNewList $self->{list}; 2077# DC::OpenGL::glNewList $self->{list};
2057# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2078# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2058# CFPlus::OpenGL::glEndList; 2079# DC::OpenGL::glEndList;
2059# } 2080# }
2060# 2081#
2061# CFPlus::OpenGL::glCallList $self->{list}; 2082# DC::OpenGL::glCallList $self->{list};
2062 2083
2063 $self->{layout}->draw; 2084 $self->{layout}->draw;
2064} 2085}
2065 2086
2066#sub destroy { 2087#sub destroy {
2067# my ($self) = @_; 2088# my ($self) = @_;
2068# 2089#
2069# CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; 2090# DC::OpenGL::glDeleteList delete $self->{list} if $self->{list};
2070# 2091#
2071# $self->SUPER::destroy; 2092# $self->SUPER::destroy;
2072#} 2093#}
2073 2094
2074############################################################################# 2095#############################################################################
2075 2096
2076package CFPlus::UI::EntryBase; 2097package DC::UI::EntryBase;
2077 2098
2078our @ISA = CFPlus::UI::Label::; 2099our @ISA = DC::UI::Label::;
2079 2100
2080use CFPlus::OpenGL; 2101use DC::OpenGL;
2081 2102
2082sub new { 2103sub new {
2083 my $class = shift; 2104 my $class = shift;
2084 2105
2085 $class->SUPER::new ( 2106 $class->SUPER::new (
2086 fg => [1, 1, 1], 2107 fg => [1, 1, 1],
2087 bg => [0, 0, 0, 0.2], 2108 bg => [0, 0, 0, 0.2],
2088 outline => [0.6, 0.3, 0.1], 2109 outline => undef,
2089 active_bg => [0, 0, 1, .2], 2110 active_bg => [0, 0, 1, .2],
2090 active_fg => [1, 1, 1], 2111 active_fg => [1, 1, 1],
2091 active_outline => [1, 1, 0], 2112 active_outline => [1, 1, 0],
2092 can_hover => 1, 2113 can_hover => 1,
2093 can_focus => 1, 2114 can_focus => 1,
2115 align => 0,
2094 valign => 0, 2116 valign => 0.5,
2095 can_events => 1, 2117 can_events => 1,
2096 ellipsise => 0, 2118 ellipsise => 0,
2119 padding_x => 4,
2120 padding_y => 2,
2097 #text => ... 2121 #text => ...
2098 #hidden => "*", 2122 #hidden => "*",
2099 @_ 2123 @_
2100 ) 2124 )
2101} 2125}
2148 2172
2149 my $text = $self->get_text; 2173 my $text = $self->get_text;
2150 2174
2151 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; 2175 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text;
2152 2176
2153 if ($uni == 8) { 2177 if ($sym == DC::SDLK_BACKSPACE) {
2154 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2178 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
2155 } elsif ($uni == 127) { 2179 } elsif ($sym == DC::SDLK_DELETE) {
2156 substr $text, $self->{cursor}, 1, ""; 2180 substr $text, $self->{cursor}, 1, "";
2157 } elsif ($sym == CFPlus::SDLK_LEFT) { 2181 } elsif ($sym == DC::SDLK_LEFT) {
2158 --$self->{cursor} if $self->{cursor}; 2182 --$self->{cursor} if $self->{cursor};
2159 } elsif ($sym == CFPlus::SDLK_RIGHT) { 2183 } elsif ($sym == DC::SDLK_RIGHT) {
2160 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 2184 ++$self->{cursor} if $self->{cursor} < length $self->{text};
2161 } elsif ($sym == CFPlus::SDLK_HOME) { 2185 } elsif ($sym == DC::SDLK_HOME) {
2162 # what a hack 2186 # what a hack
2163 $self->{cursor} = 2187 $self->{cursor} =
2164 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ 2188 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/
2165 ? length $1 2189 ? length $1
2166 : 0; 2190 : 0;
2167 } elsif ($sym == CFPlus::SDLK_END) { 2191 } elsif ($sym == DC::SDLK_END) {
2168 # uh, again 2192 # uh, again
2169 $self->{cursor} = 2193 $self->{cursor} =
2170 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ 2194 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/
2171 ? $self->{cursor} + length $1 2195 ? $self->{cursor} + length $1
2172 : length $self->{text}; 2196 : length $self->{text};
2263 glColor @{$self->{active_outline}}; 2287 glColor @{$self->{active_outline}};
2264 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; 2288 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2265 glLineWidth 1; 2289 glLineWidth 1;
2266 2290
2267 } else { 2291 } else {
2268 glColor @{$self->{outline}}; 2292 glColor @{$self->{outline} || $DC::THEME{entry_outline}};
2269 glBegin GL_LINE_STRIP; 2293 glBegin GL_LINE_STRIP;
2270 glVertex .5, $self->{h} * .5; 2294 glVertex .5, $self->{h} * .5;
2271 glVertex .5, $self->{h} - 2.5; 2295 glVertex .5, $self->{h} - 2.5;
2272 glVertex $self->{w} - .5, $self->{h} - 2.5; 2296 glVertex $self->{w} - .5, $self->{h} - 2.5;
2273 glVertex $self->{w} - .5, $self->{h} * .5; 2297 glVertex $self->{w} - .5, $self->{h} * .5;
2275 } 2299 }
2276} 2300}
2277 2301
2278############################################################################# 2302#############################################################################
2279 2303
2280package CFPlus::UI::Entry; 2304package DC::UI::Entry;
2281 2305
2282our @ISA = CFPlus::UI::EntryBase::; 2306our @ISA = DC::UI::EntryBase::;
2283 2307
2284use CFPlus::OpenGL; 2308use DC::OpenGL;
2309
2310sub new {
2311 my $class = shift;
2312
2313 $class->SUPER::new (
2314 history_pointer => -1,
2315 @_
2316 )
2317}
2318
2285 2319
2286sub invoke_key_down { 2320sub invoke_key_down {
2287 my ($self, $ev) = @_; 2321 my ($self, $ev) = @_;
2288 2322
2289 my $sym = $ev->{sym}; 2323 my $sym = $ev->{sym};
2295 $self->{history_pointer} = -1; 2329 $self->{history_pointer} = -1;
2296 $self->{history_saveback} = ''; 2330 $self->{history_saveback} = '';
2297 $self->emit (activate => $txt); 2331 $self->emit (activate => $txt);
2298 $self->update; 2332 $self->update;
2299 2333
2300 } elsif ($sym == CFPlus::SDLK_UP) { 2334 } elsif ($sym == DC::SDLK_UP) {
2301 if ($self->{history_pointer} < 0) { 2335 if ($self->{history_pointer} < 0) {
2302 $self->{history_saveback} = $self->get_text; 2336 $self->{history_saveback} = $self->get_text;
2303 } 2337 }
2304 if (@{$self->{history} || []} > 0) { 2338 if (@{$self->{history} || []} > 0) {
2305 $self->{history_pointer}++; 2339 $self->{history_pointer}++;
2307 $self->{history_pointer} = @{$self->{history} || []} - 1; 2341 $self->{history_pointer} = @{$self->{history} || []} - 1;
2308 } 2342 }
2309 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2343 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2310 } 2344 }
2311 2345
2312 } elsif ($sym == CFPlus::SDLK_DOWN) { 2346 } elsif ($sym == DC::SDLK_DOWN) {
2313 $self->{history_pointer}--; 2347 $self->{history_pointer}--;
2314 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2348 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
2315 2349
2316 if ($self->{history_pointer} >= 0) { 2350 if ($self->{history_pointer} >= 0) {
2317 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2351 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2318 } else { 2352 } else {
2353 if (defined $self->{history_saveback}) {
2319 $self->set_text ($self->{history_saveback}); 2354 $self->set_text ($self->{history_saveback});
2355 $self->{history_saveback} = undef;
2356 }
2320 } 2357 }
2321 2358
2322 } else { 2359 } else {
2323 return $self->SUPER::invoke_key_down ($ev) 2360 return $self->SUPER::invoke_key_down ($ev)
2324 } 2361 }
2326 1 2363 1
2327} 2364}
2328 2365
2329############################################################################# 2366#############################################################################
2330 2367
2331package CFPlus::UI::TextEdit; 2368package DC::UI::TextEdit;
2332 2369
2333our @ISA = CFPlus::UI::EntryBase::; 2370our @ISA = DC::UI::EntryBase::;
2334 2371
2335use CFPlus::OpenGL; 2372use DC::OpenGL;
2373
2374sub new {
2375 my $class = shift;
2376
2377 $class->SUPER::new (
2378 padding_y => 4,
2379
2380 @_
2381 )
2382}
2336 2383
2337sub move_cursor_ver { 2384sub move_cursor_ver {
2338 my ($self, $dy) = @_; 2385 my ($self, $dy) = @_;
2339 2386
2340 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2387 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2341 2388
2342 $y += $dy; 2389 $line += $dy;
2343 2390
2344 if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { 2391 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) {
2345 $self->{cursor} = $index; 2392 $self->{cursor} = $index;
2346 delete $self->{cur_h}; 2393 delete $self->{cur_h};
2347 $self->update; 2394 $self->update;
2348 return; 2395 return;
2349 } 2396 }
2352sub invoke_key_down { 2399sub invoke_key_down {
2353 my ($self, $ev) = @_; 2400 my ($self, $ev) = @_;
2354 2401
2355 my $sym = $ev->{sym}; 2402 my $sym = $ev->{sym};
2356 2403
2357 if ($sym == CFPlus::SDLK_UP) { 2404 if ($sym == DC::SDLK_UP) {
2358 $self->move_cursor_ver (-1); 2405 $self->move_cursor_ver (-1);
2359 } elsif ($sym == CFPlus::SDLK_DOWN) { 2406 } elsif ($sym == DC::SDLK_DOWN) {
2360 $self->move_cursor_ver (+1); 2407 $self->move_cursor_ver (+1);
2361 } else { 2408 } else {
2362 return $self->SUPER::invoke_key_down ($ev) 2409 return $self->SUPER::invoke_key_down ($ev)
2363 } 2410 }
2364 2411
2365 1 2412 1
2366} 2413}
2367 2414
2368############################################################################# 2415#############################################################################
2369 2416
2370package CFPlus::UI::ButtonBin; 2417package DC::UI::ButtonBin;
2371 2418
2372our @ISA = CFPlus::UI::Bin::; 2419our @ISA = DC::UI::Bin::;
2373 2420
2374use CFPlus::OpenGL; 2421use DC::OpenGL;
2375 2422
2376my @tex = 2423my @tex =
2377 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2424 map { new_from_resource DC::Texture $_, mipmap => 1 }
2378 qw(b1_button_inactive.png b1_button_active.png); 2425 qw(b1_button_inactive.png b1_button_active.png);
2379 2426
2380sub new { 2427sub new {
2381 my $class = shift; 2428 my $class = shift;
2382 2429
2383 $class->SUPER::new ( 2430 $class->SUPER::new (
2384 can_hover => 1, 2431 can_hover => 1,
2385 align => 0, 2432 align => 0.5,
2386 valign => 0, 2433 valign => 0.5,
2387 can_events => 1, 2434 can_events => 1,
2388 @_ 2435 @_
2389 ) 2436 )
2390} 2437}
2391 2438
2414 $self->SUPER::_draw; 2461 $self->SUPER::_draw;
2415} 2462}
2416 2463
2417############################################################################# 2464#############################################################################
2418 2465
2419package CFPlus::UI::Button; 2466package DC::UI::Button;
2420 2467
2421our @ISA = CFPlus::UI::Label::; 2468our @ISA = DC::UI::Label::;
2422 2469
2423use CFPlus::OpenGL; 2470use DC::OpenGL;
2424 2471
2425my @tex = 2472my @tex =
2426 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2473 map { new_from_resource DC::Texture $_, mipmap => 1 }
2427 qw(b1_button_inactive.png b1_button_active.png); 2474 qw(b1_button_inactive.png b1_button_active.png);
2428 2475
2429sub new { 2476sub new {
2430 my $class = shift; 2477 my $class = shift;
2431 2478
2432 $class->SUPER::new ( 2479 $class->SUPER::new (
2433 padding_x => 4, 2480 padding_x => 8,
2434 padding_y => 4, 2481 padding_y => 4,
2435 fg => [1.0, 1.0, 1.0], 2482 fg => [1.0, 1.0, 1.0],
2436 active_fg => [0.8, 0.8, 0.8], 2483 active_fg => [0.8, 0.8, 0.8],
2437 can_hover => 1, 2484 can_hover => 1,
2438 align => 0, 2485 align => 0.5,
2439 valign => 0, 2486 valign => 0.5,
2440 can_events => 1, 2487 can_events => 1,
2441 @_ 2488 @_
2442 ) 2489 )
2443} 2490}
2444 2491
2469 $self->SUPER::_draw; 2516 $self->SUPER::_draw;
2470} 2517}
2471 2518
2472############################################################################# 2519#############################################################################
2473 2520
2474package CFPlus::UI::CheckBox; 2521package DC::UI::CheckBox;
2475 2522
2476our @ISA = CFPlus::UI::DrawBG::; 2523our @ISA = DC::UI::DrawBG::;
2477 2524
2478my @tex = 2525my @tex =
2479 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2526 map { new_from_resource DC::Texture $_, mipmap => 1 }
2480 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2527 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2481 2528
2482use CFPlus::OpenGL; 2529use DC::OpenGL;
2483 2530
2484sub new { 2531sub new {
2485 my $class = shift; 2532 my $class = shift;
2486 2533
2487 $class->SUPER::new ( 2534 $class->SUPER::new (
2535 fontsize => 1,
2488 padding_x => 2, 2536 padding_x => 2,
2489 padding_y => 2, 2537 padding_y => 2,
2490 fg => [1, 1, 1], 2538 fg => [1, 1, 1],
2491 active_fg => [1, 1, 0], 2539 active_fg => [1, 1, 0],
2492 bg => [0, 0, 0, 0.2], 2540 bg => [0, 0, 0, 0.2],
2498} 2546}
2499 2547
2500sub size_request { 2548sub size_request {
2501 my ($self) = @_; 2549 my ($self) = @_;
2502 2550
2503 (6) x 2 2551 ($self->{fontsize} * $::FONTSIZE) x 2
2504} 2552}
2505 2553
2506sub toggle { 2554sub toggle {
2507 my ($self) = @_; 2555 my ($self) = @_;
2508 2556
2544 glDisable GL_TEXTURE_2D; 2592 glDisable GL_TEXTURE_2D;
2545} 2593}
2546 2594
2547############################################################################# 2595#############################################################################
2548 2596
2549package CFPlus::UI::Image; 2597package DC::UI::Image;
2550 2598
2551our @ISA = CFPlus::UI::Base::; 2599our @ISA = DC::UI::DrawBG::;
2552 2600
2553use CFPlus::OpenGL; 2601use DC::OpenGL;
2554 2602
2555our %texture_cache; 2603our %texture_cache;
2556 2604
2557sub new { 2605sub new {
2558 my $class = shift; 2606 my $class = shift;
2565 2613
2566 $self->{path} || $self->{tex} 2614 $self->{path} || $self->{tex}
2567 or Carp::croak "'path' or 'tex' attributes required"; 2615 or Carp::croak "'path' or 'tex' attributes required";
2568 2616
2569 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2617 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2570 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; 2618 new_from_resource DC::Texture $self->{path}, mipmap => 1;
2571 2619
2572 CFPlus::weaken $texture_cache{$self->{path}}; 2620 DC::weaken $texture_cache{$self->{path}};
2573 2621
2574 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2622 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2575 2623
2576 $self 2624 $self
2577} 2625}
2578 2626
2579sub STORABLE_freeze { 2627sub STORABLE_freeze {
2580 my ($self, $cloning) = @_; 2628 my ($self, $cloning) = @_;
2581 2629
2582 $self->{path} 2630 $self->{path}
2583 or die "cannot serialise CFPlus::UI::Image on non-loadable images\n"; 2631 or die "cannot serialise DC::UI::Image on non-loadable images\n";
2584 2632
2585 $self->{path} 2633 $self->{path}
2586} 2634}
2587 2635
2588sub STORABLE_attach { 2636sub STORABLE_attach {
2589 my ($self, $cloning, $path) = @_; 2637 my ($self, $cloning, $path) = @_;
2590 2638
2591 $self->new (path => $path) 2639 $self->new (path => $path)
2592} 2640}
2593 2641
2642sub set_texture {
2643 my ($self, $tex) = @_;
2644
2645 $self->{tex} = $tex;
2646 $self->update;
2647}
2648
2594sub size_request { 2649sub size_request {
2595 my ($self) = @_; 2650 my ($self) = @_;
2596 2651
2597 (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) 2652 (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale})
2598} 2653}
2599 2654
2600sub _draw { 2655sub _draw {
2601 my ($self) = @_; 2656 my ($self) = @_;
2657
2658 $self->SUPER::_draw;
2602 2659
2603 my $tex = $self->{tex}; 2660 my $tex = $self->{tex};
2604 2661
2605 my ($w, $h) = ($self->{w}, $self->{h}); 2662 my ($w, $h) = ($self->{w}, $self->{h});
2606 2663
2619 glDisable GL_TEXTURE_2D; 2676 glDisable GL_TEXTURE_2D;
2620} 2677}
2621 2678
2622############################################################################# 2679#############################################################################
2623 2680
2624package CFPlus::UI::ImageButton; 2681package DC::UI::ImageButton;
2625 2682
2626our @ISA = CFPlus::UI::Image::; 2683our @ISA = DC::UI::Image::;
2627 2684
2628use CFPlus::OpenGL; 2685use DC::OpenGL;
2629
2630my %textures;
2631 2686
2632sub new { 2687sub new {
2633 my $class = shift; 2688 my $class = shift;
2634 2689
2635 my $self = $class->SUPER::new ( 2690 my $self = $class->SUPER::new (
2636 padding_x => 4, 2691 padding_x => 4,
2637 padding_y => 4, 2692 padding_y => 4,
2638 fg => [1, 1, 1], 2693 fg => [1, 1, 1],
2639 active_fg => [0, 0, 1], 2694 active_fg => [0, 0, 1],
2640 can_hover => 1, 2695 can_hover => 1,
2641 align => 0, 2696 align => 0.5,
2642 valign => 0, 2697 valign => 0.5,
2643 can_events => 1, 2698 can_events => 1,
2644 @_ 2699 @_
2645 ); 2700 );
2646} 2701}
2647 2702
2661 1 2716 1
2662} 2717}
2663 2718
2664############################################################################# 2719#############################################################################
2665 2720
2666package CFPlus::UI::VGauge; 2721package DC::UI::VGauge;
2667 2722
2668our @ISA = CFPlus::UI::Base::; 2723our @ISA = DC::UI::Base::;
2669 2724
2670use List::Util qw(min max); 2725use List::Util qw(min max);
2671 2726
2672use CFPlus::OpenGL; 2727use DC::OpenGL;
2673 2728
2674my %tex = ( 2729my %tex = (
2675 food => [ 2730 food => [
2676 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2731 map { new_from_resource DC::Texture $_, mipmap => 1 }
2677 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2732 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2678 ], 2733 ],
2679 grace => [ 2734 grace => [
2680 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2735 map { new_from_resource DC::Texture $_, mipmap => 1 }
2681 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2736 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2682 ], 2737 ],
2683 hp => [ 2738 hp => [
2684 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2739 map { new_from_resource DC::Texture $_, mipmap => 1 }
2685 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2740 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2686 ], 2741 ],
2687 mana => [ 2742 mana => [
2688 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2743 map { new_from_resource DC::Texture $_, mipmap => 1 }
2689 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2744 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2690 ], 2745 ],
2691); 2746);
2692 2747
2693# eg. VGauge->new (gauge => 'food'), default gauge: food 2748# eg. VGauge->new (gauge => 'food'), default gauge: food
2796 glDisable GL_TEXTURE_2D; 2851 glDisable GL_TEXTURE_2D;
2797} 2852}
2798 2853
2799############################################################################# 2854#############################################################################
2800 2855
2801package CFPlus::UI::Progress; 2856package DC::UI::Progress;
2802 2857
2803our @ISA = CFPlus::UI::Label::; 2858our @ISA = DC::UI::Label::;
2804 2859
2805use CFPlus::OpenGL; 2860use DC::OpenGL;
2806 2861
2807sub new { 2862sub new {
2808 my ($class, %arg) = @_; 2863 my ($class, %arg) = @_;
2809 2864
2810 my $self = $class->SUPER::new ( 2865 my $self = $class->SUPER::new (
2866 padding_x => 2,
2867 padding_y => 2,
2811 fg => [1, 1, 1], 2868 fg => [1, 1, 1],
2812 bg => [0, 0, 1, 0.2], 2869 bg => [0, 0, 1, 0.2],
2813 bar => [0.7, 0.5, 0.1, 0.8], 2870 bar => [0.7, 0.5, 0.1, 0.8],
2814 outline => [0.4, 0.3, 0], 2871 outline => [0.4, 0.3, 0],
2815 fontsize => 0.9, 2872 fontsize => 0.9,
2816 valign => 0, 2873 valign => 0.5,
2817 align => 0, 2874 align => 0.5,
2818 can_events => 1, 2875 can_events => 1,
2819 ellipsise => 1, 2876 ellipsise => 1,
2820 label => "%d%%", 2877 label => "%d%%",
2821 %arg, 2878 %arg,
2822 ); 2879 );
2830 my ($self, $label) = @_; 2887 my ($self, $label) = @_;
2831 2888
2832 return if $self->{label} eq $label; 2889 return if $self->{label} eq $label;
2833 $self->{label} = $label; 2890 $self->{label} = $label;
2834 2891
2835 $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value}); 2892 $self->DC::UI::Progress::set_value (0 + delete $self->{value});
2836} 2893}
2837 2894
2838sub set_value { 2895sub set_value {
2839 my ($self, $value) = @_; 2896 my ($self, $value) = @_;
2840 2897
2855 my ($self) = @_; 2912 my ($self) = @_;
2856 2913
2857 glEnable GL_BLEND; 2914 glEnable GL_BLEND;
2858 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2915 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2859 2916
2917 my $px = $self->{padding_x};
2918 my $py = $self->{padding_y};
2919
2860 if ($self->{value} >= 0) { 2920 if ($self->{value} >= 0) {
2861 my $s = int 2 + ($self->{w} - 4) * $self->{value}; 2921 my $s = int $px + ($self->{w} - $px * 2) * $self->{value};
2862 2922
2863 glColor_premultiply @{$self->{bar}}; 2923 glColor_premultiply @{$self->{bar}};
2864 glRect 2, 2, $s, $self->{h} - 2; 2924 glRect $px, $py, $s, $self->{h} - $py;
2865 glColor_premultiply @{$self->{bg}}; 2925 glColor_premultiply @{$self->{bg}};
2866 glRect $s, 2, $self->{w} - 2, $self->{h} - 2; 2926 glRect $s , $py, $self->{w} - $px, $self->{h} - $py;
2867 } 2927 }
2868 2928
2869 glColor_premultiply @{$self->{outline}}; 2929 glColor_premultiply @{$self->{outline}};
2930
2931 $px -= .5;
2932 $py -= .5;
2933
2870 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; 2934 glRect_lineloop $px, $py, $self->{w} - $px, $self->{h} - $py;
2871 2935
2872 glDisable GL_BLEND; 2936 glDisable GL_BLEND;
2873 2937
2874 { 2938 {
2875 local $self->{bg}; # do not draw background 2939 local $self->{bg}; # do not draw background
2877 } 2941 }
2878} 2942}
2879 2943
2880############################################################################# 2944#############################################################################
2881 2945
2882package CFPlus::UI::ExperienceProgress; 2946package DC::UI::ExperienceProgress;
2883 2947
2884our @ISA = CFPlus::UI::Progress::; 2948our @ISA = DC::UI::Progress::;
2885 2949
2886sub new { 2950sub new {
2887 my ($class, %arg) = @_; 2951 my ($class, %arg) = @_;
2888 2952
2953 my $tt = exists $arg{tooltip} ? "$arg{tooltip}\n\n" : "";
2954
2889 my $self = $class->SUPER::new ( 2955 my $self = $class->SUPER::new (
2956 %arg,
2890 tooltip => sub { 2957 tooltip => sub {
2891 my ($self) = @_; 2958 my ($self) = @_;
2892 2959
2893 sprintf "level %d\n%s points\n%s next level\n%s to go", 2960 sprintf "%slevel %d\n%s points\n%s next level\n%s to go, %d%% done",
2961 $tt,
2894 $self->{lvl}, 2962 $self->{lvl},
2895 ::formsep ($self->{exp}), 2963 ::formsep ($self->{exp}),
2896 ::formsep ($self->{nxt}), 2964 ::formsep ($self->{nxt}),
2897 ::formsep ($self->{nxt} - $self->{exp}), 2965 ::formsep ($self->{nxt} - $self->{exp}),
2966 $self->_percent * 100,
2898 }, 2967 },
2899 %arg
2900 ); 2968 );
2901 2969
2902 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } 2970 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2903 if $::CONN; 2971 if $::CONN;
2904 2972
2912 if $::CONN; 2980 if $::CONN;
2913 2981
2914 $self->SUPER::DESTROY; 2982 $self->SUPER::DESTROY;
2915} 2983}
2916 2984
2985sub _percent {
2986 my ($self) = @_;
2987
2988 my $table = $::CONN && $::CONN->{exp_table}
2989 or return -1;
2990
2991 my $l0 = $table->[$self->{lvl} - 1];
2992 my $l1 = $table->[$self->{lvl}];
2993
2994 $self->{nxt} = $l1;
2995
2996 ($self->{exp} - $l0) / ($l1 - $l0)
2997}
2998
2917sub set_value { 2999sub set_value {
2918 my ($self, $lvl, $exp) = @_; 3000 my ($self, $lvl, $exp) = @_;
2919 3001
2920 $self->{lvl} = $lvl; 3002 $self->{lvl} = $lvl;
2921 $self->{exp} = $exp; 3003 $self->{exp} = $exp;
2922 3004
2923 my $v = -1;
2924
2925 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2926 my $l0 = $table->[$lvl - 1];
2927 my $l1 = $table->[$lvl];
2928
2929 $self->{nxt} = $l1;
2930
2931 $v = ($exp - $l0) / ($l1 - $l0);
2932 }
2933
2934 $self->SUPER::set_value ($v); 3005 $self->SUPER::set_value ($self->_percent);
2935} 3006}
2936 3007
2937############################################################################# 3008#############################################################################
2938 3009
2939package CFPlus::UI::Gauge; 3010package DC::UI::Gauge;
2940 3011
2941our @ISA = CFPlus::UI::VBox::; 3012our @ISA = DC::UI::VBox::;
2942 3013
2943sub new { 3014sub new {
2944 my ($class, %arg) = @_; 3015 my ($class, %arg) = @_;
2945 3016
2946 my $self = $class->SUPER::new ( 3017 my $self = $class->SUPER::new (
2948 can_hover => 1, 3019 can_hover => 1,
2949 can_events => 1, 3020 can_events => 1,
2950 %arg, 3021 %arg,
2951 ); 3022 );
2952 3023
2953 $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999"); 3024 $self->add ($self->{value} = new DC::UI::Label valign => 1, align => 0.5, template => "999");
2954 $self->add ($self->{gauge} = new CFPlus::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 3025 $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
2955 $self->add ($self->{max} = new CFPlus::UI::Label valign => -1, align => 0, template => "999"); 3026 $self->add ($self->{max} = new DC::UI::Label valign => 0, align => 0.5, template => "999");
2956 3027
2957 $self 3028 $self
2958} 3029}
2959 3030
2960sub set_fontsize { 3031sub set_fontsize {
2981 $self->{value}->set_text ($val); 3052 $self->{value}->set_text ($val);
2982} 3053}
2983 3054
2984############################################################################# 3055#############################################################################
2985 3056
2986package CFPlus::UI::Slider; 3057package DC::UI::Slider;
2987 3058
2988use strict; 3059use common::sense;
2989 3060
2990use CFPlus::OpenGL; 3061use DC::OpenGL;
2991 3062
2992our @ISA = CFPlus::UI::DrawBG::; 3063our @ISA = DC::UI::DrawBG::;
2993 3064
2994my @tex = 3065my @tex =
2995 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ } 3066 map { new_from_resource DC::Texture $_ }
2996 qw(s1_slider.png s1_slider_bg.png); 3067 qw(s1_slider.png s1_slider_bg.png);
2997 3068
2998sub new { 3069sub new {
2999 my $class = shift; 3070 my $class = shift;
3000 3071
3037sub set_value { 3108sub set_value {
3038 my ($self, $value) = @_; 3109 my ($self, $value) = @_;
3039 3110
3040 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; 3111 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
3041 3112
3042 $hi = $lo + 1 if $hi <= $lo; 3113 $hi = $lo if $hi < $lo;
3043 3114
3044 $page = $hi - $lo if $page > $hi - $lo; 3115 $value = $hi - $page if $value > $hi - $page;
3045
3046 $value = $lo if $value < $lo; 3116 $value = $lo if $value < $lo;
3047 $value = $hi - $page if $value > $hi - $page;
3048 3117
3049 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit 3118 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
3050 if $unit; 3119 if $unit;
3051 3120
3052 @{$self->{range}} = ($value, $lo, $hi, $page, $unit); 3121 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
3081 if ($GRAB == $self) { 3150 if ($GRAB == $self) {
3082 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); 3151 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
3083 3152
3084 my (undef, $lo, $hi, $page) = @{$self->{range}}; 3153 my (undef, $lo, $hi, $page) = @{$self->{range}};
3085 3154
3086 $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); 3155 $x = ($x - $self->{click}[1]) / ($w * $self->{scale} || 1e999);
3087 3156
3088 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); 3157 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo));
3089 } else { 3158 } else {
3090 return 0; 3159 return 0;
3091 } 3160 }
3096sub invoke_mouse_wheel { 3165sub invoke_mouse_wheel {
3097 my ($self, $ev) = @_; 3166 my ($self, $ev) = @_;
3098 3167
3099 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 3168 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
3100 3169
3101 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; 3170 my $pagepart = $ev->{mod} & DC::KMOD_SHIFT ? 1 : 0.2;
3102 3171
3103 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); 3172 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
3104 3173
3105 1 3174 1
3106} 3175}
3116 my ($self) = @_; 3185 my ($self) = @_;
3117 3186
3118 unless ($self->{knob_w}) { 3187 unless ($self->{knob_w}) {
3119 $self->set_value ($self->{range}[0]); 3188 $self->set_value ($self->{range}[0]);
3120 3189
3121 my ($value, $lo, $hi, $page) = @{$self->{range}}; 3190 my ($value, $lo, $hi, $page, $unit) = @{$self->{range}};
3122 my $range = ($hi - $page - $lo) || 1e-100; 3191 my $range = ($hi - $page - $lo) || 1e-10;
3123 3192
3124 my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1; 3193 my $knob_w = List::Util::min 1, $page / (($hi - $lo) || 1e-10) || 24 / $self->{w};
3125 3194
3126 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; 3195 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5;
3127 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; 3196 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100;
3128 3197
3129 $value = ($value - $lo) / $range; 3198 $value = ($value - $lo) / $range;
3159 glDisable GL_TEXTURE_2D; 3228 glDisable GL_TEXTURE_2D;
3160} 3229}
3161 3230
3162############################################################################# 3231#############################################################################
3163 3232
3164package CFPlus::UI::ValSlider; 3233package DC::UI::ValSlider;
3165 3234
3166our @ISA = CFPlus::UI::HBox::; 3235our @ISA = DC::UI::HBox::;
3167 3236
3168sub new { 3237sub new {
3169 my ($class, %arg) = @_; 3238 my ($class, %arg) = @_;
3170 3239
3171 my $range = delete $arg{range}; 3240 my $range = delete $arg{range};
3172 3241
3173 my $self = $class->SUPER::new ( 3242 my $self = $class->SUPER::new (
3174 slider => (new CFPlus::UI::Slider expand => 1, range => $range), 3243 slider => (new DC::UI::Slider expand => 1, range => $range),
3175 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}), 3244 entry => (new DC::UI::Label text => "", template => delete $arg{template}),
3176 to_value => sub { shift }, 3245 to_value => sub { shift },
3177 from_value => sub { shift }, 3246 from_value => sub { shift },
3178 %arg, 3247 %arg,
3179 ); 3248 );
3180 3249
3200sub set_range { shift->{slider}->set_range (@_) } 3269sub set_range { shift->{slider}->set_range (@_) }
3201sub set_value { shift->{slider}->set_value (@_) } 3270sub set_value { shift->{slider}->set_value (@_) }
3202 3271
3203############################################################################# 3272#############################################################################
3204 3273
3205package CFPlus::UI::TextScroller; 3274package DC::UI::TextScroller;
3206 3275
3207our @ISA = CFPlus::UI::HBox::; 3276our @ISA = DC::UI::HBox::;
3208 3277
3209use CFPlus::OpenGL; 3278use DC::OpenGL;
3210 3279
3211sub new { 3280sub new {
3212 my $class = shift; 3281 my $class = shift;
3213 3282
3214 my $self = $class->SUPER::new ( 3283 my $self = $class->SUPER::new (
3216 can_events => 1, 3285 can_events => 1,
3217 indent => 0, 3286 indent => 0,
3218 #font => default_font 3287 #font => default_font
3219 @_, 3288 @_,
3220 3289
3221 layout => (new CFPlus::Layout), 3290 layout => (new DC::Layout),
3222 par => [], 3291 par => [],
3223 max_par => 0, 3292 max_par => 0,
3224 height => 0, 3293 height => 0,
3225 children => [ 3294 children => [
3226 (new CFPlus::UI::Empty expand => 1), 3295 (new DC::UI::Empty expand => 1),
3227 (new CFPlus::UI::Slider vertical => 1), 3296 (new DC::UI::Slider vertical => 1),
3228 ], 3297 ],
3229 ); 3298 );
3230 3299
3231 $self->{children}[1]->connect (changed => sub { $self->update }); 3300 $self->{children}[1]->connect (changed => sub { $self->update });
3232 3301
3288 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); 3357 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
3289 $layout->set_markup ($para->{markup}); 3358 $layout->set_markup ($para->{markup});
3290 3359
3291 $layout->set_shapes ( 3360 $layout->set_shapes (
3292 map 3361 map
3293 +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), 3362 +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}),
3294 @{$para->{widget}} 3363 @{$para->{widget}}
3295 ); 3364 );
3296 3365
3297 $layout 3366 $layout
3298} 3367}
3415 $ROOT->on_post_alloc ($self => sub { 3484 $ROOT->on_post_alloc ($self => sub {
3416 $self->force_uptodate; 3485 $self->force_uptodate;
3417 3486
3418 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 3487 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
3419 3488
3420 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 3489 $self->{texture} ||= new_from_opengl DC::Texture $W, $H, sub {
3421 glClearColor 0, 0, 0, 0; 3490 glClearColor 0, 0, 0, 0;
3422 glClear GL_COLOR_BUFFER_BIT; 3491 glClear GL_COLOR_BUFFER_BIT;
3423 3492
3424 package CFPlus::UI::Base; 3493 package DC::UI::Base;
3425 local ($draw_x, $draw_y, $draw_w, $draw_h) = 3494 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3426 (0, 0, $self->{w}, $self->{h}); 3495 (0, 0, $self->{w}, $self->{h});
3427 3496
3428 my $top = int $self->{children}[1]{range}[0]; 3497 my $top = int $self->{children}[1]{range}[0];
3429 3498
3488 $self->{children}[1]->draw; 3557 $self->{children}[1]->draw;
3489} 3558}
3490 3559
3491############################################################################# 3560#############################################################################
3492 3561
3493package CFPlus::UI::Animator; 3562package DC::UI::Animator;
3494 3563
3495use CFPlus::OpenGL; 3564use DC::OpenGL;
3496 3565
3497our @ISA = CFPlus::UI::Bin::; 3566our @ISA = DC::UI::Bin::;
3498 3567
3499sub moveto { 3568sub moveto {
3500 my ($self, $x, $y) = @_; 3569 my ($self, $x, $y) = @_;
3501 3570
3502 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 3571 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
3530 glPopMatrix; 3599 glPopMatrix;
3531} 3600}
3532 3601
3533############################################################################# 3602#############################################################################
3534 3603
3535package CFPlus::UI::Flopper; 3604package DC::UI::Flopper;
3536 3605
3537our @ISA = CFPlus::UI::Button::; 3606our @ISA = DC::UI::Button::;
3538 3607
3539sub new { 3608sub new {
3540 my $class = shift; 3609 my $class = shift;
3541 3610
3542 my $self = $class->SUPER::new ( 3611 my $self = $class->SUPER::new (
3554 $self->{other}->toggle_visibility; 3623 $self->{other}->toggle_visibility;
3555} 3624}
3556 3625
3557############################################################################# 3626#############################################################################
3558 3627
3559package CFPlus::UI::Tooltip; 3628package DC::UI::Tooltip;
3560 3629
3561our @ISA = CFPlus::UI::Bin::; 3630our @ISA = DC::UI::Bin::;
3562 3631
3563use CFPlus::OpenGL; 3632use DC::OpenGL;
3564 3633
3565sub new { 3634sub new {
3566 my $class = shift; 3635 my $class = shift;
3567 3636
3568 $class->SUPER::new ( 3637 $class->SUPER::new (
3575 my ($self, $widget) = @_; 3644 my ($self, $widget) = @_;
3576 3645
3577 my $tip = $widget->{tooltip}; 3646 my $tip = $widget->{tooltip};
3578 $tip = $tip->($widget) if "CODE" eq ref $tip; 3647 $tip = $tip->($widget) if "CODE" eq ref $tip;
3579 3648
3580 $tip = CFPlus::Pod::section_label tooltip => $1 3649 $tip = DC::Pod::section_label tooltip => $1
3581 if $tip =~ /^#(.*)$/; 3650 if $tip =~ /^#(.*)$/;
3582 3651
3583 if ($ENV{CFPLUS_DEBUG} & 2) { 3652 if ($ENV{CFPLUS_DEBUG} & 2) {
3584 $tip .= "\n\n" . (ref $widget) . "\n" 3653 $tip .= "\n\n" . (ref $widget) . "\n"
3585 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3654 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3588 } 3657 }
3589 3658
3590 $tip =~ s/^\n+//; 3659 $tip =~ s/^\n+//;
3591 $tip =~ s/\n+$//; 3660 $tip =~ s/\n+$//;
3592 3661
3593 $self->add (new CFPlus::UI::Label 3662 $self->add (new DC::UI::Label
3663 fg => $DC::THEME{tooltip_fg},
3594 markup => $tip, 3664 markup => $tip,
3595 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3665 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3666 align => 0,
3596 fontsize => 0.8, 3667 fontsize => 0.8,
3597 style => 1, # FLAG_INVERSE 3668 style => $DC::THEME{tooltip_style}, # FLAG_INVERSE
3598 ellipsise => 0, 3669 ellipsise => 0,
3599 font => ($widget->{tooltip_font} || $::FONT_PROP), 3670 font => ($widget->{tooltip_font} || $::FONT_PROP),
3600 ); 3671 );
3601} 3672}
3602 3673
3639sub _draw { 3710sub _draw {
3640 my ($self) = @_; 3711 my ($self) = @_;
3641 3712
3642 my ($w, $h) = @$self{qw(w h)}; 3713 my ($w, $h) = @$self{qw(w h)};
3643 3714
3644 glColor 1, 0.8, 0.4; 3715 glColor @{ $DC::THEME{tooltip_bg} };
3645 glRect 0, 0, $w, $h; 3716 glRect 0, 0, $w, $h;
3646 3717
3647 glColor 0, 0, 0; 3718 glColor @{ $DC::THEME{tooltip_border} };
3648 glRect_lineloop .5, .5, $w + .5, $h + .5; 3719 glRect_lineloop .5, .5, $w + .5, $h + .5;
3649 3720
3650 glTranslate 2, 2; 3721 glTranslate 2, 2;
3651 3722
3652 $self->SUPER::_draw; 3723 $self->SUPER::_draw;
3653} 3724}
3654 3725
3655############################################################################# 3726#############################################################################
3656 3727
3657package CFPlus::UI::Face; 3728package DC::UI::Face;
3658 3729
3659our @ISA = CFPlus::UI::DrawBG::; 3730our @ISA = DC::UI::DrawBG::;
3660 3731
3661use CFPlus::OpenGL; 3732use DC::OpenGL;
3662 3733
3663sub new { 3734sub new {
3664 my $class = shift; 3735 my $class = shift;
3665 3736
3666 my $self = $class->SUPER::new ( 3737 my $self = $class->SUPER::new (
3669 aspect => 1, 3740 aspect => 1,
3670 can_events => 0, 3741 can_events => 0,
3671 @_, 3742 @_,
3672 ); 3743 );
3673 3744
3674 if ($self->{anim} && $self->{animspeed}) {
3675 CFPlus::weaken (my $widget = $self);
3676
3677 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3678 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed};
3679 $self->{timer} = Event->timer (
3680 parked => 1,
3681 cb => sub {
3682 return unless $::CONN;
3683
3684 my $w = $widget
3685 or return;
3686
3687 ++$w->{frame};
3688 $w->update_face;
3689
3690 # somehow, $widget can go away
3691 $w->update;
3692 $w->update_timer;
3693 },
3694 );
3695
3696 $self->update_face;
3697 $self->update_timer; 3745 $self->update_anim;
3698 }
3699 3746
3700 $self 3747 $self
3701} 3748}
3702 3749
3703sub update_timer { 3750sub update_timer {
3704 my ($self) = @_; 3751 my ($self) = @_;
3705 3752
3706 return unless $self->{timer}; 3753 return unless $self->{timer};
3707 3754
3708 if ($self->{visible}) { 3755 if ($self->{visible}) {
3709 $self->{timer}->at (
3710 $self->{anim_start}
3711 + $self->{animspeed}
3712 * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed}
3713 );
3714 $self->{timer}->start; 3756 $self->{timer}->start;
3715 } else { 3757 } else {
3716 $self->{timer}->stop; 3758 $self->{timer}->stop;
3717 } 3759 }
3718} 3760}
3731 $tex->upload (sub { $self->reconfigure }); 3773 $tex->upload (sub { $self->reconfigure });
3732 } 3774 }
3733 } 3775 }
3734 } 3776 }
3735 } 3777 }
3778 }
3779}
3780
3781sub update_anim {
3782 my ($self) = @_;
3783
3784 if ($self->{anim} && $self->{animspeed}) {
3785 DC::weaken (my $widget = $self);
3786
3787 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed};
3788 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub {
3789 return unless $::CONN;
3790
3791 my $w = $widget
3792 or return;
3793
3794 ++$w->{frame};
3795 $w->update_face;
3796
3797 # somehow, $widget can go away
3798 $w->update;
3799 $w->update_timer;
3800 };
3801
3802 $self->update_face;
3803 $self->update_timer;
3804 } else {
3805 delete $self->{timer};
3736 } 3806 }
3737} 3807}
3738 3808
3739sub size_request { 3809sub size_request {
3740 my ($self) = @_; 3810 my ($self) = @_;
3762 return unless $self->{visible}; 3832 return unless $self->{visible};
3763 3833
3764 $self->SUPER::update; 3834 $self->SUPER::update;
3765} 3835}
3766 3836
3837sub set_face {
3838 my ($self, $face) = @_;
3839
3840 $self->{face} = $face;
3841 $self->reconfigure;
3842}
3843
3844sub set_anim {
3845 my ($self, $anim) = @_;
3846
3847 $self->{anim} = $anim;
3848 $self->update_anim;
3849}
3850
3851sub set_animspeed {
3852 my ($self, $animspeed) = @_;
3853
3854 $self->{animspeed} = $animspeed;
3855 $self->update_anim;
3856}
3857
3767sub invoke_visibility_change { 3858sub invoke_visibility_change {
3768 my ($self) = @_; 3859 my ($self) = @_;
3769 3860
3770 $self->update_timer; 3861 $self->update_timer;
3771 3862
3795 $self->SUPER::destroy; 3886 $self->SUPER::destroy;
3796} 3887}
3797 3888
3798############################################################################# 3889#############################################################################
3799 3890
3800package CFPlus::UI::Buttonbar; 3891package DC::UI::Buttonbar;
3801 3892
3802our @ISA = CFPlus::UI::HBox::; 3893our @ISA = DC::UI::HBox::;
3803 3894
3804# TODO: should actually wrap buttons and other goodies. 3895# TODO: should actually wrap buttons and other goodies.
3805 3896
3806############################################################################# 3897#############################################################################
3807 3898
3808package CFPlus::UI::Menu; 3899package DC::UI::Menu;
3809 3900
3810our @ISA = CFPlus::UI::Toplevel::; 3901our @ISA = DC::UI::Toplevel::;
3811 3902
3812use CFPlus::OpenGL; 3903use DC::OpenGL;
3813 3904
3814sub new { 3905sub new {
3815 my $class = shift; 3906 my $class = shift;
3816 3907
3817 my $self = $class->SUPER::new ( 3908 my $self = $class->SUPER::new (
3818 items => [], 3909 items => [],
3819 z => 100, 3910 z => 100,
3820 @_, 3911 @_,
3821 ); 3912 );
3822 3913
3823 $self->add ($self->{vbox} = new CFPlus::UI::VBox); 3914 $self->add ($self->{vbox} = new DC::UI::VBox);
3824 3915
3825 for my $item (@{ $self->{items} }) { 3916 for my $item (@{ $self->{items} }) {
3826 my ($widget, $cb, $tooltip) = @$item; 3917 my ($widget, $cb, $tooltip) = @$item;
3827 3918
3828 # handle various types of items, only text for now 3919 # handle various types of items, only text for now
3829 if (!ref $widget) { 3920 if (!ref $widget) {
3830 if ($widget =~ /\t/) { 3921 if ($widget =~ /\t/) {
3831 my ($left, $right) = split /\t/, $widget, 2; 3922 my ($left, $right) = split /\t/, $widget, 2;
3832 3923
3833 $widget = new CFPlus::UI::HBox 3924 $widget = new DC::UI::HBox
3834 can_hover => 1, 3925 can_hover => 1,
3835 can_events => 1, 3926 can_events => 1,
3836 tooltip => $tooltip, 3927 tooltip => $tooltip,
3837 children => [ 3928 children => [
3838 (new CFPlus::UI::Label markup => $left, expand => 1), 3929 (new DC::UI::Label markup => $left , align => 0, expand => 1),
3839 (new CFPlus::UI::Label markup => $right, align => +1), 3930 (new DC::UI::Label markup => $right, align => 1),
3840 ], 3931 ],
3841 ; 3932 ;
3842 3933
3843 } else { 3934 } else {
3844 $widget = new CFPlus::UI::Label 3935 $widget = new DC::UI::Label
3845 can_hover => 1, 3936 can_hover => 1,
3846 can_events => 1, 3937 can_events => 1,
3938 align => 0,
3847 markup => $widget, 3939 markup => $widget,
3848 tooltip => $tooltip; 3940 tooltip => $tooltip;
3849 } 3941 }
3850 } 3942 }
3851 3943
3866 # maybe save $GRAB? must be careful about events... 3958 # maybe save $GRAB? must be careful about events...
3867 $GRAB = $self; 3959 $GRAB = $self;
3868 $self->{button} = $ev->{button}; 3960 $self->{button} = $ev->{button};
3869 3961
3870 $self->show; 3962 $self->show;
3871 $self->move_abs ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); 3963
3964 my $x = $ev->{x};
3965 my $y = $ev->{y};
3966
3967 $self->{root}->on_post_alloc ($self => sub {
3968 $self->move_abs ($x - $self->{w} * 0.25, $y - $self->{border} * $::FONTSIZE * .5);
3969 });
3970
3971 1 # so it can be used inside event handlers
3872} 3972}
3873 3973
3874sub invoke_mouse_motion { 3974sub invoke_mouse_motion {
3875 my ($self, $ev, $x, $y) = @_; 3975 my ($self, $ev, $x, $y) = @_;
3876 3976
3897 1 3997 1
3898} 3998}
3899 3999
3900############################################################################# 4000#############################################################################
3901 4001
3902package CFPlus::UI::Multiplexer; 4002package DC::UI::Multiplexer;
3903 4003
3904our @ISA = CFPlus::UI::Container::; 4004our @ISA = DC::UI::Container::;
3905 4005
3906sub new { 4006sub new {
3907 my $class = shift; 4007 my $class = shift;
3908 4008
3909 my $self = $class->SUPER::new ( 4009 my $self = $class->SUPER::new (
3910 @_, 4010 @_,
3911 ); 4011 );
3912 4012
3913 $self->{current} = $self->{children}[0] 4013 $self->set_current_page (0);
3914 if @{ $self->{children} };
3915 4014
3916 $self 4015 $self
3917} 4016}
3918 4017
3919sub add { 4018sub add {
3920 my ($self, @widgets) = @_; 4019 my ($self, @widgets) = @_;
3921 4020
3922 $self->SUPER::add (@widgets); 4021 $self->SUPER::add (@widgets);
3923 4022
3924 $self->{current} = $self->{children}[0] 4023 $self->set_current_page (0)
3925 if @{ $self->{children} }; 4024 if @widgets == @{ $self->{children} };
3926} 4025}
3927 4026
3928sub get_current_page { 4027sub get_current_page {
3929 my ($self) = @_; 4028 my ($self) = @_;
3930 4029
3936 4035
3937 my $widget = ref $page_or_widget 4036 my $widget = ref $page_or_widget
3938 ? $page_or_widget 4037 ? $page_or_widget
3939 : $self->{children}[$page_or_widget]; 4038 : $self->{children}[$page_or_widget];
3940 4039
4040 $self->{current}->set_invisible if $self->{current} && $self->{visible};
4041
3941 $self->{current} = $widget; 4042 if (($self->{current} = $widget)) {
4043 $self->{current}->set_visible if $self->{current} && $self->{visible};
3942 $self->{current}->configure (0, 0, $self->{w}, $self->{h}); 4044 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
3943 4045
3944 $self->emit (page_changed => $self->{current}); 4046 $self->emit (page_changed => $self->{current});
4047 }
3945 4048
3946 $self->realloc; 4049 $self->realloc;
3947} 4050}
3948 4051
3949sub visible_children { 4052sub visible_children {
3950 $_[0]{current} 4053 $_[0]{current} || ()
3951} 4054}
3952 4055
3953sub size_request { 4056sub size_request {
3954 my ($self) = @_; 4057 my ($self) = @_;
3955 4058
4059 $self->{current}
3956 $self->{current}->size_request 4060 ? $self->{current}->size_request
4061 : (0, 0)
3957} 4062}
3958 4063
3959sub invoke_size_allocate { 4064sub invoke_size_allocate {
3960 my ($self, $w, $h) = @_; 4065 my ($self, $w, $h) = @_;
3961 4066
3962 $self->{current}->configure (0, 0, $w, $h); 4067 $self->{current}->configure (0, 0, $w, $h)
4068 if $self->{current};
3963 4069
3964 1 4070 1
3965} 4071}
3966 4072
3967sub _draw { 4073sub _draw {
3968 my ($self) = @_; 4074 my ($self) = @_;
3969 4075
3970 $self->{current}->draw; 4076 $self->{current}->draw
4077 if $self->{current};
3971} 4078}
3972 4079
3973############################################################################# 4080#############################################################################
3974 4081
3975package CFPlus::UI::Notebook; 4082package DC::UI::Notebook;
3976 4083
3977use CFPlus::OpenGL; 4084use DC::OpenGL;
3978 4085
3979our @ISA = CFPlus::UI::VBox::; 4086our @ISA = DC::UI::VBox::;
3980 4087
3981sub new { 4088sub new {
3982 my $class = shift; 4089 my $class = shift;
3983 4090
3984 my $self = $class->SUPER::new ( 4091 my $self = $class->SUPER::new (
3985 buttonbar => (new CFPlus::UI::Buttonbar), 4092 buttonbar => (new DC::UI::Buttonbar),
3986 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 4093 multiplexer => (new DC::UI::Multiplexer expand => 1),
3987 active_outline => [.7, .7, 0.2], 4094 active_outline => [.7, .7, 0.2],
3988 # filter => # will be put between multiplexer and $self 4095 # filter => # will be put between multiplexer and $self
3989 @_, 4096 @_,
3990 ); 4097 );
3991 4098
4000 4107
4001 for my $child (@$widgets) { 4108 for my $child (@$widgets) {
4002 Scalar::Util::weaken $child; 4109 Scalar::Util::weaken $child;
4003 $child->{c_tab_} ||= do { 4110 $child->{c_tab_} ||= do {
4004 my $tab = 4111 my $tab =
4005 (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") 4112 (UNIVERSAL::isa $child->{c_tab}, "DC::UI::Base")
4006 ? $child->{c_tab} 4113 ? $child->{c_tab}
4007 : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; 4114 : new DC::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1];
4008 4115
4009 $tab->connect (activate => sub { 4116 $tab->connect (activate => sub {
4010 $wself->set_current_page ($child); 4117 $wself->set_current_page ($child);
4011 }); 4118 });
4012 4119
4042} 4149}
4043 4150
4044sub pages { 4151sub pages {
4045 my ($self) = @_; 4152 my ($self) = @_;
4046 $self->{multiplexer}->children 4153 $self->{multiplexer}->children
4154}
4155
4156sub page_index {
4157 my ($self, $widget) = @_;
4158
4159 my $i = 0;
4160 for ($self->pages) {
4161 if ($_ eq $widget) { return $i };
4162 $i++;
4163 }
4164
4165 undef
4047} 4166}
4048 4167
4049sub add_tab { 4168sub add_tab {
4050 my ($self, $title, $widget, $tooltip) = @_; 4169 my ($self, $title, $widget, $tooltip) = @_;
4051 4170
4088 } 4207 }
4089} 4208}
4090 4209
4091############################################################################# 4210#############################################################################
4092 4211
4093package CFPlus::UI::Selector; 4212package DC::UI::Selector;
4094 4213
4095use utf8; 4214use utf8;
4096 4215
4097our @ISA = CFPlus::UI::Button::; 4216our @ISA = DC::UI::Button::;
4098 4217
4099sub new { 4218sub new {
4100 my $class = shift; 4219 my $class = shift;
4101 4220
4102 my $self = $class->SUPER::new ( 4221 my $self = $class->SUPER::new (
4119 my ($value, $title, $tooltip) = @$_; 4238 my ($value, $title, $tooltip) = @$_;
4120 4239
4121 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 4240 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
4122 } 4241 }
4123 4242
4124 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); 4243 DC::UI::Menu->new (items => \@menu_items)->popup ($ev);
4125} 4244}
4126 4245
4127sub _set_value { 4246sub _set_value {
4128 my ($self, $value) = @_; 4247 my ($self, $value) = @_;
4129 4248
4152 $self->_set_value ($self->{value}); 4271 $self->_set_value ($self->{value});
4153} 4272}
4154 4273
4155############################################################################# 4274#############################################################################
4156 4275
4157package CFPlus::UI::Statusbox; 4276package DC::UI::Statusbox;
4158 4277
4159our @ISA = CFPlus::UI::VBox::; 4278our @ISA = DC::UI::VBox::;
4160 4279
4161sub new { 4280sub new {
4162 my $class = shift; 4281 my $class = shift;
4163 4282
4164 my $self = $class->SUPER::new ( 4283 my $self = $class->SUPER::new (
4165 fontsize => 0.8, 4284 fontsize => 0.8,
4166 @_, 4285 @_,
4167 ); 4286 );
4168 4287
4169 CFPlus::weaken (my $this = $self); 4288 DC::weaken (my $this = $self);
4170 4289
4171 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 4290 $self->{timer} = EV::timer 1, 1, sub { $this->reorder };
4172 4291
4173 $self 4292 $self
4174} 4293}
4175 4294
4176sub reorder { 4295sub reorder {
4177 my ($self) = @_; 4296 my ($self) = @_;
4178 my $NOW = Time::HiRes::time; 4297 my $NOW = EV::time;
4179 4298
4180 # freeze display when hovering over any label 4299 # freeze display when hovering over any label
4181 return if $CFPlus::UI::TOOLTIP->{owner} 4300 return if $DC::UI::TOOLTIP->{owner}
4182 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label}, 4301 && grep $DC::UI::TOOLTIP->{owner} == $_->{label},
4183 values %{ $self->{item} }; 4302 values %{ $self->{item} };
4184 4303
4185 while (my ($k, $v) = each %{ $self->{item} }) { 4304 while (my ($k, $v) = each %{ $self->{item} }) {
4186 delete $self->{item}{$k} if $v->{timeout} < $NOW; 4305 delete $self->{item}{$k} if $v->{timeout} < $NOW;
4187 } 4306 }
4307
4308 $self->{timer}->set (1, 1);
4188 4309
4189 my @widgets; 4310 my @widgets;
4190 4311
4191 my @items = sort { 4312 my @items = sort {
4192 $a->{pri} <=> $b->{pri} 4313 $a->{pri} <=> $b->{pri}
4193 or $b->{id} <=> $a->{id} 4314 or $b->{id} <=> $a->{id}
4194 } values %{ $self->{item} }; 4315 } values %{ $self->{item} };
4195
4196 $self->{timer}->interval (1);
4197 4316
4198 my $count = 10 + 1; 4317 my $count = 10 + 1;
4199 for my $item (@items) { 4318 for my $item (@items) {
4200 last unless --$count; 4319 last unless --$count;
4201 4320
4208 for ($short) { 4327 for ($short) {
4209 s/^\s+//; 4328 s/^\s+//;
4210 s/\s+/ /g; 4329 s/\s+/ /g;
4211 } 4330 }
4212 4331
4213 new CFPlus::UI::Label 4332 new DC::UI::Label
4214 markup => $short, 4333 markup => $short,
4215 tooltip => $item->{tooltip}, 4334 tooltip => $item->{tooltip},
4216 tooltip_font => $::FONT_PROP, 4335 tooltip_font => $::FONT_PROP,
4217 tooltip_width => 0.67, 4336 tooltip_width => 0.67,
4218 fontsize => $item->{fontsize} || $self->{fontsize}, 4337 fontsize => $item->{fontsize} || $self->{fontsize},
4219 max_w => $::WIDTH * 0.44, 4338 max_w => $::WIDTH * 0.44,
4339 align => 0,
4220 fg => [@{ $item->{fg} }], 4340 fg => [@{ $item->{fg} }],
4221 can_events => 1, 4341 can_events => 1,
4222 can_hover => 1 4342 can_hover => 1
4223 }; 4343 };
4224 4344
4225 if ((my $diff = $item->{timeout} - $NOW) < 2) { 4345 if ((my $diff = $item->{timeout} - $NOW) < 2) {
4226 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; 4346 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2;
4227 $label->update; 4347 $label->update;
4228 $label->set_max_size (undef, $label->{req_h} * $diff) 4348 $label->set_max_size (undef, $label->{req_h} * $diff)
4229 if $diff < 1; 4349 if $diff < 1;
4230 $self->{timer}->interval (1/30); 4350 $self->{timer}->set (1/30, 1/30);
4231 } else { 4351 } else {
4232 $label->{fg}[3] = $item->{fg}[3] || 1; 4352 $label->{fg}[3] = $item->{fg}[3] || 1;
4233 } 4353 }
4234 4354
4235 push @widgets, $label; 4355 push @widgets, $label;
4236 } 4356 }
4357
4358 my $hash = join ",", @widgets;
4359 return if $hash eq $self->{last_widget_hash};
4360 $self->{last_widget_hash} = $hash;
4237 4361
4238 $self->clear; 4362 $self->clear;
4239 $self->SUPER::add (reverse @widgets); 4363 $self->SUPER::add (reverse @widgets);
4240} 4364}
4241 4365
4297 $self->SUPER::destroy; 4421 $self->SUPER::destroy;
4298} 4422}
4299 4423
4300############################################################################# 4424#############################################################################
4301 4425
4302package CFPlus::UI::Root; 4426package DC::UI::Root;
4303 4427
4304our @ISA = CFPlus::UI::Container::; 4428our @ISA = DC::UI::Container::;
4305 4429
4306use List::Util qw(min max); 4430use List::Util qw(min max);
4307 4431
4308use CFPlus::OpenGL; 4432use DC::OpenGL;
4309 4433
4310sub new { 4434sub new {
4311 my $class = shift; 4435 my $class = shift;
4312 4436
4313 my $self = $class->SUPER::new ( 4437 my $self = $class->SUPER::new (
4314 visible => 1, 4438 visible => 1,
4315 @_, 4439 @_,
4316 ); 4440 );
4317 4441
4318 CFPlus::weaken ($self->{root} = $self); 4442 DC::weaken ($self->{root} = $self);
4319 4443
4320 $self 4444 $self
4321} 4445}
4322 4446
4323sub size_request { 4447sub size_request {
4371} 4495}
4372 4496
4373sub update { 4497sub update {
4374 my ($self) = @_; 4498 my ($self) = @_;
4375 4499
4376 $::WANT_REFRESH->start; 4500 $::WANT_REFRESH = 1;
4377} 4501}
4378 4502
4379sub add { 4503sub add {
4380 my ($self, @children) = @_; 4504 my ($self, @children) = @_;
4381 4505
4448 4572
4449 delete $queue{$widget+0}; 4573 delete $queue{$widget+0};
4450 4574
4451 my ($w, $h) = $widget->size_request; 4575 my ($w, $h) = $widget->size_request;
4452 4576
4453 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; 4577 $w += $widget->{padding_x} * 2;
4454 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; 4578 $h += $widget->{padding_y} * 2;
4579
4580 $w = max $widget->{min_w}, $w;
4581 $h = max $widget->{min_h}, $h;
4455 4582
4456 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4583 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4457 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4584 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4458 4585
4459 $w = $widget->{force_w} if exists $widget->{force_w}; 4586 $w = $widget->{force_w} if exists $widget->{force_w};
4526 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 4653 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
4527 glMatrixMode GL_MODELVIEW; 4654 glMatrixMode GL_MODELVIEW;
4528 glLoadIdentity; 4655 glLoadIdentity;
4529 4656
4530 { 4657 {
4531 package CFPlus::UI::Base; 4658 package DC::UI::Base;
4532 4659
4533 local ($draw_x, $draw_y, $draw_w, $draw_h) = 4660 local ($draw_x, $draw_y, $draw_w, $draw_h) =
4534 (0, 0, $self->{w}, $self->{h}); 4661 (0, 0, $self->{w}, $self->{h});
4535 4662
4536 $self->_draw; 4663 $self->_draw;
4537 } 4664 }
4538} 4665}
4539 4666
4540############################################################################# 4667#############################################################################
4541 4668
4542package CFPlus::UI; 4669package DC::UI;
4543 4670
4544$ROOT = new CFPlus::UI::Root; 4671$ROOT = new DC::UI::Root;
4545$TOOLTIP = new CFPlus::UI::Tooltip z => 900; 4672$TOOLTIP = new DC::UI::Tooltip z => 900;
4546 4673
45471 46741
4548

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines