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.439 by root, Sun Sep 16 13:04:36 2007 UTC vs.
Revision 1.478 by root, Tue Dec 22 00:35:44 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines