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.483 by root, Wed Jan 4 11:23:23 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines