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.479 by root, Thu Feb 4 20:01:09 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines