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.436 by root, Wed Aug 22 21:40:57 2007 UTC vs.
Revision 1.477 by root, Sun Jan 11 23:50:27 2009 UTC

1package CFPlus::UI; 1package DC::UI;
2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5 5
6use List::Util (); 6use List::Util ();
7use Event;
8 7
9use CFPlus; 8use Guard ();
9
10use DC;
10use CFPlus::Pod; 11use DC::Pod;
11use CFPlus::Texture; 12use DC::Texture;
12 13
13our ($FOCUS, $HOVER, $GRAB); # various widgets 14our ($FOCUS, $HOVER, $GRAB); # various widgets
14 15
15our $LAYOUT; 16our $LAYOUT;
16our $ROOT; 17our $ROOT;
17our $TOOLTIP; 18our $TOOLTIP;
18our $BUTTON_STATE; 19our $BUTTON_STATE;
19 20
20our %WIDGET; # all widgets, weak-referenced 21our %WIDGET; # all widgets, weak-referenced
21 22
22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { 23our $TOOLTIP_WATCHER = EV::timer_ns 0, 0.03, sub {
24 $_[0]->stop;
25
23 if (!$GRAB) { 26 if (!$GRAB) {
24 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 27 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
25 if (length $widget->{tooltip}) { 28 if (length $widget->{tooltip}) {
26 if ($TOOLTIP->{owner} != $widget) { 29 if ($TOOLTIP->{owner} != $widget) {
27 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; 30 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
42 } 45 }
43 46
44 $TOOLTIP->hide; 47 $TOOLTIP->hide;
45 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; 48 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
46 delete $TOOLTIP->{owner}; 49 delete $TOOLTIP->{owner};
47}); 50};
48 51
49sub get_layout { 52sub get_layout {
50 my $layout; 53 my $layout;
51 54
52 for (grep { $_->{name} } values %WIDGET) { 55 for (grep { $_->{name} } values %WIDGET) {
87 my $hover = $HOVER; $HOVER = $widget; 90 my $hover = $HOVER; $HOVER = $widget;
88 91
89 $hover->update if $hover && $hover->{can_hover}; 92 $hover->update if $hover && $hover->{can_hover};
90 $HOVER->update if $HOVER && $HOVER->{can_hover}; 93 $HOVER->update if $HOVER && $HOVER->{can_hover};
91 94
92 $TOOLTIP_WATCHER->start; 95 $TOOLTIP_WATCHER->again;
93 } 96 }
94} 97}
95 98
96sub feed_sdl_button_down_event { 99sub feed_sdl_button_down_event {
97 my ($ev) = @_; 100 my ($ev) = @_;
103 my $widget = $ROOT->find_widget ($x, $y); 106 my $widget = $ROOT->find_widget ($x, $y);
104 107
105 $GRAB = $widget; 108 $GRAB = $widget;
106 $GRAB->update if $GRAB; 109 $GRAB->update if $GRAB;
107 110
108 $TOOLTIP_WATCHER->cb->(); 111 $TOOLTIP_WATCHER->invoke;
109 } 112 }
110 113
111 if ($GRAB) { 114 if ($GRAB) {
112 if ($ev->{button} == 4 || $ev->{button} == 5) { 115 if ($ev->{button} == 4 || $ev->{button} == 5) {
113 # mousewheel 116 # mousewheel
114 my $delta = $ev->{button} * 2 - 9; 117 my $delta = $ev->{button} * 2 - 9;
115 my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT; 118 my $shift = $ev->{mod} & DC::KMOD_SHIFT;
116 119
117 $ev->{dx} = $shift ? $delta : 0; 120 $ev->{dx} = $shift ? $delta : 0;
118 $ev->{dy} = $shift ? 0 : $delta; 121 $ev->{dy} = $shift ? 0 : $delta;
119 122
120 $GRAB->emit (mouse_wheel => $ev); 123 $GRAB->emit (mouse_wheel => $ev);
138 my $grab = $GRAB; undef $GRAB; 141 my $grab = $GRAB; undef $GRAB;
139 $grab->update if $grab; 142 $grab->update if $grab;
140 $GRAB->update if $GRAB; 143 $GRAB->update if $GRAB;
141 144
142 check_hover $widget; 145 check_hover $widget;
143 $TOOLTIP_WATCHER->cb->(); 146 $TOOLTIP_WATCHER->invoke;
144 } 147 }
145} 148}
146 149
147sub feed_sdl_motion_event { 150sub feed_sdl_motion_event {
148 my ($ev) = @_; 151 my ($ev) = @_;
188# call when resolution changes etc. 191# call when resolution changes etc.
189sub rescale_widgets { 192sub rescale_widgets {
190 my ($sx, $sy) = @_; 193 my ($sx, $sy) = @_;
191 194
192 for my $widget (values %WIDGET) { 195 for my $widget (values %WIDGET) {
193 if ($widget->{is_toplevel}) { 196 if ($widget->{is_toplevel} || $widget->{c_rescale}) {
194 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 197 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
195 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 198 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
196 199
197 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; 200 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/;
198 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 201 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
210 reconfigure_widgets; 213 reconfigure_widgets;
211} 214}
212 215
213############################################################################# 216#############################################################################
214 217
215package CFPlus::UI::Event; 218package DC::UI::Event;
216 219
217sub xy { 220sub xy {
218 $_[1]->coord2local ($_[0]{x}, $_[0]{y}) 221 $_[1]->coord2local ($_[0]{x}, $_[0]{y})
219} 222}
220 223
221############################################################################# 224#############################################################################
222 225
223package CFPlus::UI::Base; 226package DC::UI::Base;
224 227
225use strict; 228use strict;
226 229
227use CFPlus::OpenGL; 230use DC::OpenGL;
228 231
229sub new { 232sub new {
230 my $class = shift; 233 my $class = shift;
231 234
232 my $self = bless { 235 my $self = bless {
237 h => undef, 240 h => undef,
238 can_events => 1, 241 can_events => 1,
239 @_ 242 @_
240 }, $class; 243 }, $class;
241 244
242 CFPlus::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); 245 DC::weaken ($DC::UI::WIDGET{$self+0} = $self);
243 246
244 for (keys %$self) { 247 for (keys %$self) {
245 if (/^on_(.*)$/) { 248 if (/^on_(.*)$/) {
246 $self->connect ($1 => delete $self->{$_}); 249 $self->connect ($1 => delete $self->{$_});
247 } 250 }
248 } 251 }
249 252
250 if (my $layout = $CFPlus::UI::LAYOUT->{$self->{name}}) { 253 if (my $layout = $DC::UI::LAYOUT->{$self->{name}}) {
251 $self->{x} = $layout->{x} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{x}; 254 $self->{x} = $layout->{x} * $DC::UI::ROOT->{alloc_w} if exists $layout->{x};
252 $self->{y} = $layout->{y} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{y}; 255 $self->{y} = $layout->{y} * $DC::UI::ROOT->{alloc_h} if exists $layout->{y};
253 $self->{force_w} = $layout->{w} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{w}; 256 $self->{force_w} = $layout->{w} * $DC::UI::ROOT->{alloc_w} if exists $layout->{w};
254 $self->{force_h} = $layout->{h} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{h}; 257 $self->{force_h} = $layout->{h} * $DC::UI::ROOT->{alloc_h} if exists $layout->{h};
255 258
256 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; 259 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x};
257 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; 260 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y};
258 261
259 $self->show if $layout->{show}; 262 $self->show if $layout->{show};
269 $self->emit ("destroy"); 272 $self->emit ("destroy");
270 %$self = (); 273 %$self = ();
271} 274}
272 275
273sub TO_JSON { 276sub TO_JSON {
274 { __w_ => $_[0]{s_id} } 277 { "\fw" => $_[0]{s_id} }
275} 278}
276 279
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
374# traverse the widget chain up to find the maximum "physical" size constraints
375sub get_max_wh {
376 my ($self) = @_;
377
378 my ($w, $h) = @$self{qw(max_w max_h)};
379
380 if ($w <= 0 || $h <= 0) {
381 my ($mw, $mh) = $self->{parent}
382 ? $self->{parent}->get_max_wh
383 : ($::WIDTH, $::HEIGHT);
384
385 $w = $mw if $w <= 0;
386 $h = $mh if $h <= 0;
387 }
388
389 ($w, $h)
390}
391
365sub size_request { 392sub size_request {
366 require Carp; 393 require Carp;
367 Carp::confess "size_request is abstract"; 394 Carp::confess "size_request is abstract";
368} 395}
369 396
375 my ($self, $x, $y, $w, $h) = @_; 402 my ($self, $x, $y, $w, $h) = @_;
376 403
377 if ($self->{aspect}) { 404 if ($self->{aspect}) {
378 my ($ow, $oh) = ($w, $h); 405 my ($ow, $oh) = ($w, $h);
379 406
380 $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect}; 407 $w = List::Util::min $w, DC::ceil $h * $self->{aspect};
381 $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect}; 408 $h = List::Util::min $h, DC::ceil $w / $self->{aspect};
382 409
383 # use alignment to adjust x, y 410 # use alignment to adjust x, y
384 411
385 $x += int 0.5 * ($ow - $w); 412 $x += int 0.5 * ($ow - $w);
386 $y += int 0.5 * ($oh - $h); 413 $y += int 0.5 * ($oh - $h);
427 454
428 return if $self->{tooltip} eq $tooltip; 455 return if $self->{tooltip} eq $tooltip;
429 456
430 $self->{tooltip} = $tooltip; 457 $self->{tooltip} = $tooltip;
431 458
432 if ($CFPlus::UI::TOOLTIP->{owner} == $self) { 459 if ($DC::UI::TOOLTIP->{owner} == $self) {
433 delete $CFPlus::UI::TOOLTIP->{owner}; 460 delete $DC::UI::TOOLTIP->{owner};
434 $CFPlus::UI::TOOLTIP_WATCHER->cb->(); 461 $DC::UI::TOOLTIP_WATCHER->invoke;
435 } 462 }
436} 463}
437 464
438# translate global coordinates to local coordinate system 465# translate global coordinates to local coordinate system
439sub coord2local { 466sub coord2local {
440 my ($self, $x, $y) = @_; 467 my ($self, $x, $y) = @_;
441 468
442 Carp::confess unless $self->{parent};#d# 469 return (undef, undef) unless $self->{parent};
443 470
444 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) 471 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
445} 472}
446 473
447# translate local coordinates to global coordinate system 474# translate local coordinates to global coordinate system
448sub coord2global { 475sub coord2global {
449 my ($self, $x, $y) = @_; 476 my ($self, $x, $y) = @_;
450 477
451 Carp::confess unless $self->{parent};#d# 478 return (undef, undef) unless $self->{parent};
452 479
453 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) 480 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
454} 481}
455 482
456sub invoke_focus_in { 483sub invoke_focus_in {
505sub connect { 532sub connect {
506 my ($self, $signal, $cb) = @_; 533 my ($self, $signal, $cb) = @_;
507 534
508 push @{ $self->{signal_cb}{$signal} }, $cb; 535 push @{ $self->{signal_cb}{$signal} }, $cb;
509 536
510 defined wantarray and CFPlus::guard { 537 defined wantarray and Guard::guard {
511 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, 538 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
512 @{ $self->{signal_cb}{$signal} }; 539 @{ $self->{signal_cb}{$signal} };
513 } 540 }
514} 541}
515 542
553# in .xs 580# in .xs
554 581
555sub set_parent { 582sub set_parent {
556 my ($self, $parent) = @_; 583 my ($self, $parent) = @_;
557 584
558 CFPlus::weaken ($self->{parent} = $parent); 585 DC::weaken ($self->{parent} = $parent);
559 $self->set_visible if $parent->{visible}; 586 $self->set_visible if $parent->{visible};
560} 587}
561 588
562sub realloc { 589sub realloc {
563 my ($self) = @_; 590 my ($self) = @_;
601} 628}
602 629
603sub DESTROY { 630sub DESTROY {
604 my ($self) = @_; 631 my ($self) = @_;
605 632
606 return if CFPlus::in_destruct; 633 return if DC::in_destruct;
607 634
608 local $@; 635 local $@;
609 eval { $self->destroy }; 636 eval { $self->destroy };
610 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 637 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
611 638
612 delete $WIDGET{$self+0}; 639 delete $WIDGET{$self+0};
613} 640}
614 641
615############################################################################# 642#############################################################################
616 643
617package CFPlus::UI::DrawBG; 644package DC::UI::DrawBG;
618 645
619our @ISA = CFPlus::UI::Base::; 646our @ISA = DC::UI::Base::;
620 647
621use strict; 648use strict;
622use CFPlus::OpenGL; 649use DC::OpenGL;
623 650
624sub new { 651sub new {
625 my $class = shift; 652 my $class = shift;
626 653
627 $class->SUPER::new ( 654 $class->SUPER::new (
629 #active_bg => [1, 1, 1, 0.5], 656 #active_bg => [1, 1, 1, 0.5],
630 @_ 657 @_
631 ) 658 )
632} 659}
633 660
661sub set_bg {
662 my ($self, $bg) = @_;
663
664 $self->{bg} = $bg;
665 $self->update;
666}
667
634sub _draw { 668sub _draw {
635 my ($self) = @_; 669 my ($self) = @_;
636 670
637 my $color = $FOCUS == $self && $self->{active_bg} 671 my $color = $FOCUS == $self && $self->{active_bg}
638 ? $self->{active_bg} 672 ? $self->{active_bg}
649 } 683 }
650} 684}
651 685
652############################################################################# 686#############################################################################
653 687
654package CFPlus::UI::Empty; 688package DC::UI::Empty;
655 689
656our @ISA = CFPlus::UI::Base::; 690our @ISA = DC::UI::Base::;
657 691
658sub new { 692sub new {
659 my ($class, %arg) = @_; 693 my ($class, %arg) = @_;
660 $class->SUPER::new (can_events => 0, %arg); 694 $class->SUPER::new (can_events => 0, %arg);
661} 695}
668 702
669sub draw { } 703sub draw { }
670 704
671############################################################################# 705#############################################################################
672 706
673package CFPlus::UI::Container; 707package DC::UI::Container;
674 708
675our @ISA = CFPlus::UI::Base::; 709our @ISA = DC::UI::Base::;
676 710
677sub new { 711sub new {
678 my ($class, %arg) = @_; 712 my ($class, %arg) = @_;
679 713
680 my $children = delete $arg{children}; 714 my $children = delete $arg{children};
774 $_->draw for $self->visible_children; 808 $_->draw for $self->visible_children;
775} 809}
776 810
777############################################################################# 811#############################################################################
778 812
779package CFPlus::UI::Bin; 813package DC::UI::Bin;
780 814
781our @ISA = CFPlus::UI::Container::; 815our @ISA = DC::UI::Container::;
782 816
783sub new { 817sub new {
784 my ($class, %arg) = @_; 818 my ($class, %arg) = @_;
785 819
786 my $child = (delete $arg{child}) || new CFPlus::UI::Empty::; 820 my $child = (delete $arg{child}) || new DC::UI::Empty::;
787 821
788 $class->SUPER::new (children => [$child], %arg) 822 $class->SUPER::new (children => [$child], %arg)
789} 823}
790 824
791sub add { 825sub add {
798sub remove { 832sub remove {
799 my ($self, $widget) = @_; 833 my ($self, $widget) = @_;
800 834
801 $self->SUPER::remove ($widget); 835 $self->SUPER::remove ($widget);
802 836
803 $self->{children} = [new CFPlus::UI::Empty] 837 $self->{children} = [new DC::UI::Empty]
804 unless @{$self->{children}}; 838 unless @{$self->{children}};
805} 839}
806 840
807sub child { $_[0]->{children}[0] } 841sub child { $_[0]->{children}[0] }
808 842
817 851
818 1 852 1
819} 853}
820 854
821############################################################################# 855#############################################################################
822
823# back-buffered drawing area 856# back-buffered drawing area
824 857
825package CFPlus::UI::Window; 858package DC::UI::Window;
826 859
827our @ISA = CFPlus::UI::Bin::; 860our @ISA = DC::UI::Bin::;
828 861
829use CFPlus::OpenGL; 862use DC::OpenGL;
830 863
831sub new { 864sub new {
832 my ($class, %arg) = @_; 865 my ($class, %arg) = @_;
833 866
834 my $self = $class->SUPER::new (%arg); 867 my $self = $class->SUPER::new (%arg);
856} 889}
857 890
858sub render_child { 891sub render_child {
859 my ($self) = @_; 892 my ($self) = @_;
860 893
861 $self->{texture} = new_from_opengl CFPlus::Texture $self->{w}, $self->{h}, sub { 894 $self->{texture} = new_from_opengl DC::Texture $self->{w}, $self->{h}, sub {
862 glClearColor 0, 0, 0, 0; 895 glClearColor 0, 0, 0, 0;
863 glClear GL_COLOR_BUFFER_BIT; 896 glClear GL_COLOR_BUFFER_BIT;
864 897
865 { 898 {
866 package CFPlus::UI::Base; 899 package DC::UI::Base;
867 900
868 local ($draw_x, $draw_y, $draw_w, $draw_h) = 901 local ($draw_x, $draw_y, $draw_w, $draw_h) =
869 (0, 0, $self->{w}, $self->{h}); 902 (0, 0, $self->{w}, $self->{h});
870 903
871 $self->_render; 904 $self->_render;
888 glDisable GL_TEXTURE_2D; 921 glDisable GL_TEXTURE_2D;
889} 922}
890 923
891############################################################################# 924#############################################################################
892 925
893package CFPlus::UI::ViewPort; 926package DC::UI::ViewPort;
894 927
895use List::Util qw(min max); 928use List::Util qw(min max);
896 929
897our @ISA = CFPlus::UI::Window::; 930our @ISA = DC::UI::Window::;
898 931
899sub new { 932sub new {
900 my $class = shift; 933 my $class = shift;
901 934
902 $class->SUPER::new ( 935 $class->SUPER::new (
986 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 1019 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
987 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1020 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
988 ) { 1021 ) {
989 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) 1022 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
990 } else { 1023 } else {
991 $self->CFPlus::UI::Base::find_widget ($x, $y) 1024 $self->DC::UI::Base::find_widget ($x, $y)
992 } 1025 }
993} 1026}
994 1027
995sub _render { 1028sub _render {
996 my ($self) = @_; 1029 my ($self) = @_;
997 1030
998 local $CFPlus::UI::Base::draw_x = $CFPlus::UI::Base::draw_x - $self->{view_x}; 1031 local $DC::UI::Base::draw_x = $DC::UI::Base::draw_x - $self->{view_x};
999 local $CFPlus::UI::Base::draw_y = $CFPlus::UI::Base::draw_y - $self->{view_y}; 1032 local $DC::UI::Base::draw_y = $DC::UI::Base::draw_y - $self->{view_y};
1000 1033
1001 CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 1034 DC::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
1002 1035
1003 $self->SUPER::_render; 1036 $self->SUPER::_render;
1004} 1037}
1005 1038
1006############################################################################# 1039#############################################################################
1007 1040
1008package CFPlus::UI::ScrolledWindow; 1041package DC::UI::ScrolledWindow;
1009 1042
1010our @ISA = CFPlus::UI::Table::; 1043our @ISA = DC::UI::Table::;
1011 1044
1012sub new { 1045sub new {
1013 my ($class, %arg) = @_; 1046 my ($class, %arg) = @_;
1014 1047
1015 my $child = delete $arg{child}; 1048 my $child = delete $arg{child};
1016 1049
1017 my $self; 1050 my $self;
1018 1051
1019 my $hslider = new CFPlus::UI::Slider 1052 my $hslider = new DC::UI::Slider
1020 c_col => 0, 1053 c_col => 0,
1021 c_row => 1, 1054 c_row => 1,
1022 vertical => 0, 1055 vertical => 0,
1023 range => [0, 0, 1, 0.01], # HACK fix 1056 range => [0, 0, 1, 0.01], # HACK fix
1024 on_changed => sub { 1057 on_changed => sub {
1025 $self->{hpos} = $_[1]; 1058 $self->{hpos} = $_[1];
1026 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1059 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1027 }, 1060 },
1028 ; 1061 ;
1029 1062
1030 my $vslider = new CFPlus::UI::Slider 1063 my $vslider = new DC::UI::Slider
1031 c_col => 1, 1064 c_col => 1,
1032 c_row => 0, 1065 c_row => 0,
1033 vertical => 1, 1066 vertical => 1,
1034 range => [0, 0, 1, 0.01], # HACK fix 1067 range => [0, 0, 1, 0.01], # HACK fix
1035 on_changed => sub { 1068 on_changed => sub {
1047 col_expand => [1, 0], 1080 col_expand => [1, 0],
1048 row_expand => [1, 0], 1081 row_expand => [1, 0],
1049 %arg, 1082 %arg,
1050 ); 1083 );
1051 1084
1052 $self->{vp} = new CFPlus::UI::ViewPort 1085 $self->{vp} = new DC::UI::ViewPort
1053 c_col => 0, 1086 c_col => 0,
1054 c_row => 0, 1087 c_row => 0,
1055 expand => 1, 1088 expand => 1,
1056 scroll_x => $self->{scroll_x}, 1089 scroll_x => $self->{scroll_x},
1057 scroll_y => $self->{scroll_y}, 1090 scroll_y => $self->{scroll_y},
1183 $self->SUPER::invoke_size_allocate ($w, $h) 1216 $self->SUPER::invoke_size_allocate ($w, $h)
1184} 1217}
1185 1218
1186############################################################################# 1219#############################################################################
1187 1220
1188package CFPlus::UI::Frame; 1221package DC::UI::Frame;
1189 1222
1190our @ISA = CFPlus::UI::Bin::; 1223our @ISA = DC::UI::Bin::;
1191 1224
1192use CFPlus::OpenGL; 1225use DC::OpenGL;
1193 1226
1194sub new { 1227sub new {
1195 my $class = shift; 1228 my $class = shift;
1196 1229
1197 $class->SUPER::new ( 1230 $class->SUPER::new (
1216 $self->SUPER::_draw; 1249 $self->SUPER::_draw;
1217} 1250}
1218 1251
1219############################################################################# 1252#############################################################################
1220 1253
1221package CFPlus::UI::FancyFrame; 1254package DC::UI::FancyFrame;
1222 1255
1223our @ISA = CFPlus::UI::Bin::; 1256our @ISA = DC::UI::Bin::;
1224 1257
1225use CFPlus::OpenGL; 1258use DC::OpenGL;
1226 1259
1227sub new { 1260sub new {
1228 my ($class, %arg) = @_; 1261 my ($class, %arg) = @_;
1229 1262
1230 if ((exists $arg{label}) && !ref $arg{label}) { 1263 if ((exists $arg{label}) && !ref $arg{label}) {
1231 $arg{label} = new CFPlus::UI::Label 1264 $arg{label} = new DC::UI::Label
1232 align => 1, 1265 align => 1,
1233 valign => 0, 1266 valign => 0.5,
1234 text => $arg{label}, 1267 text => $arg{label},
1235 fontsize => ($arg{border} || 0.8) * 0.75; 1268 fontsize => ($arg{border} || 0.8) * 0.75;
1236 } 1269 }
1237 1270
1238 my $self = $class->SUPER::new ( 1271 my $self = $class->SUPER::new (
1239 # label => "", 1272 # label => "",
1240 fg => [0.6, 0.3, 0.1], 1273 fg => undef,
1241 border => 0.8, 1274 border => 0.8,
1242 style => 'single', 1275 style => 'single',
1243 %arg, 1276 %arg,
1244 ); 1277 );
1245 1278
1248 1281
1249sub add { 1282sub add {
1250 my ($self, @widgets) = @_; 1283 my ($self, @widgets) = @_;
1251 1284
1252 $self->SUPER::add (@widgets); 1285 $self->SUPER::add (@widgets);
1253 $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label}; 1286 $self->DC::UI::Container::add ($self->{label}) if $self->{label};
1254} 1287}
1255 1288
1256sub border { 1289sub border {
1257 int $_[0]{border} * $::FONTSIZE 1290 int $_[0]{border} * $::FONTSIZE
1258} 1291}
1298 my $border = $self->border; 1331 my $border = $self->border;
1299 my ($w, $h) = ($self->{w}, $self->{h}); 1332 my ($w, $h) = ($self->{w}, $self->{h});
1300 1333
1301 $child->draw; 1334 $child->draw;
1302 1335
1303 glColor @{$self->{fg}}; 1336 glColor @{$self->{fg} || $DC::THEME{fancyframe}};
1304 glBegin GL_LINE_STRIP; 1337 glBegin GL_LINE_STRIP;
1305 glVertex $border * 1.5 , $border * 0.5 + 0.5; 1338 glVertex $border * 1.5 , $border * 0.5 + 0.5;
1306 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; 1339 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5;
1307 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; 1340 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1308 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; 1341 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1316 } 1349 }
1317} 1350}
1318 1351
1319############################################################################# 1352#############################################################################
1320 1353
1321package CFPlus::UI::Toplevel; 1354package DC::UI::Toplevel;
1322 1355
1323our @ISA = CFPlus::UI::Bin::; 1356our @ISA = DC::UI::Bin::;
1324 1357
1325use CFPlus::OpenGL; 1358use DC::OpenGL;
1326 1359
1327my $bg = 1360my $bg =
1328 new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", 1361 new_from_resource DC::Texture "d1_bg.png",
1329 mipmap => 1, wrap => 1; 1362 mipmap => 1, wrap => 1;
1330 1363
1331my @border = 1364my @border =
1332 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1365 map { new_from_resource DC::Texture $_, mipmap => 1 }
1333 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1366 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1334 1367
1335my @icon = 1368my @icon =
1336 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1369 map { new_from_resource DC::Texture $_, mipmap => 1 }
1337 qw(x1_move.png x1_resize.png); 1370 qw(x1_move.png x1_resize.png);
1338 1371
1339sub new { 1372sub new {
1340 my ($class, %arg) = @_; 1373 my ($class, %arg) = @_;
1341 1374
1342 my $self = $class->SUPER::new ( 1375 my $self = $class->SUPER::new (
1343 bg => [1, 1, 1, 1], 1376 bg => [1, 1, 1, 1],
1344 border_bg => [1, 1, 1, 1], 1377 border_bg => [1, 1, 1, 1],
1345 border => 0.6, 1378 border => 0.8,
1346 can_events => 1, 1379 can_events => 1,
1347 min_w => 64, 1380 min_w => 64,
1348 min_h => 32, 1381 min_h => 32,
1349 %arg, 1382 %arg,
1350 ); 1383 );
1351 1384
1352 $self->{title_widget} = new CFPlus::UI::Label 1385 $self->{title_widget} = new DC::UI::Label
1353 align => 0, 1386 align => 0.5,
1354 valign => 1, 1387 valign => 1,
1355 text => $self->{title}, 1388 text => $self->{title},
1356 fontsize => $self->{border}, 1389 fontsize => $self->{border},
1357 if exists $self->{title}; 1390 if exists $self->{title};
1358 1391
1359 if ($self->{has_close_button}) { 1392 if ($self->{has_close_button}) {
1360 $self->{close_button} = 1393 $self->{close_button} =
1361 new CFPlus::UI::ImageButton 1394 new DC::UI::ImageButton
1362 path => 'x1_close.png', 1395 path => 'x1_close.png',
1363 on_activate => sub { $self->emit ("delete") }; 1396 on_activate => sub { $self->emit ("delete") };
1364 1397
1365 $self->CFPlus::UI::Container::add ($self->{close_button}); 1398 $self->DC::UI::Container::add ($self->{close_button});
1366 } 1399 }
1367 1400
1368 $self 1401 $self
1369} 1402}
1370 1403
1371sub add { 1404sub add {
1372 my ($self, @widgets) = @_; 1405 my ($self, @widgets) = @_;
1373 1406
1374 $self->SUPER::add (@widgets); 1407 $self->SUPER::add (@widgets);
1375 $self->CFPlus::UI::Container::add ($self->{close_button}) if $self->{close_button}; 1408 $self->DC::UI::Container::add ($self->{close_button}) if $self->{close_button};
1376 $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; 1409 $self->DC::UI::Container::add ($self->{title_widget}) if $self->{title_widget};
1377} 1410}
1378 1411
1379sub border { 1412sub border {
1380 int $_[0]{border} * $::FONTSIZE 1413 int $_[0]{border} * $::FONTSIZE
1414}
1415
1416sub get_max_wh {
1417 my ($self) = @_;
1418
1419 return ($self->{w}, $self->{h})
1420 if $self->{visible} && $self->{w};
1421
1422 $self->SUPER::get_max_wh
1381} 1423}
1382 1424
1383sub size_request { 1425sub size_request {
1384 my ($self) = @_; 1426 my ($self) = @_;
1385 1427
1510 glEnable GL_TEXTURE_2D; 1552 glEnable GL_TEXTURE_2D;
1511 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1553 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1512 1554
1513 my $border = $self->border; 1555 my $border = $self->border;
1514 1556
1557 if ($border) {
1515 glColor @{ $self->{border_bg} }; 1558 glColor @{ $self->{border_bg} };
1516 $border[0]->draw_quad_alpha ( 0, 0, $w, $border); 1559 $border[0]->draw_quad_alpha ( 0, 0, $w, $border);
1517 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); 1560 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch);
1518 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); 1561 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
1519 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); 1562 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border);
1520 1563
1521 # move 1564 # move
1522 my $w2 = ($w - $border) * .5; 1565 my $w2 = ($w - $border) * .5;
1523 my $h2 = ($h - $border) * .5; 1566 my $h2 = ($h - $border) * .5;
1524 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); 1567 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border);
1525 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); 1568 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border);
1526 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); 1569 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border);
1527 1570
1528 # resize 1571 # resize
1529 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); 1572 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border);
1530 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) 1573 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border)
1531 unless $self->{has_close_button}; 1574 unless $self->{has_close_button};
1532 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); 1575 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border);
1533 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); 1576 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border);
1577 }
1534 1578
1535 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 1579 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
1536 glColor @{ $self->{bg} }; 1580 glColor @{ $self->{bg} };
1537 1581
1538 # TODO: repeat texture not scale 1582 # TODO: repeat texture not scale
1557 if $self->{close_button}; 1601 if $self->{close_button};
1558} 1602}
1559 1603
1560############################################################################# 1604#############################################################################
1561 1605
1562package CFPlus::UI::Table; 1606package DC::UI::Table;
1563 1607
1564our @ISA = CFPlus::UI::Container::; 1608our @ISA = DC::UI::Container::;
1565 1609
1566use List::Util qw(max sum); 1610use List::Util qw(max sum);
1567 1611
1568use CFPlus::OpenGL; 1612use DC::OpenGL;
1569 1613
1570sub new { 1614sub new {
1571 my $class = shift; 1615 my $class = shift;
1572 1616
1573 $class->SUPER::new ( 1617 $class->SUPER::new (
1617 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; 1661 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)};
1618 1662
1619 my $sw = sum @w[$c .. $c + $cs - 1]; 1663 my $sw = sum @w[$c .. $c + $cs - 1];
1620 1664
1621 if ($w > $sw) { 1665 if ($w > $sw) {
1622 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; 1666 $_ += ($w - $sw) / ($_ ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1];
1623 } 1667 }
1624 } 1668 }
1625 1669
1626 # second pass, rows 1670 # second pass, rows
1627 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { 1671 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) {
1628 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; 1672 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)};
1629 1673
1630 my $sh = sum @h[$r .. $r + $rs - 1]; 1674 my $sh = sum @h[$r .. $r + $rs - 1];
1631 1675
1632 if ($h > $sh) { 1676 if ($h > $sh) {
1633 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; 1677 $_ += ($h - $sh) / ($_ ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1];
1634 } 1678 }
1635 } 1679 }
1636 1680
1637 (\@w, \@h) 1681 (\@w, \@h)
1638} 1682}
1661 @col_expand = (1) x @$ws unless @col_expand; 1705 @col_expand = (1) x @$ws unless @col_expand;
1662 my $col_expand = (sum @col_expand) || 1; 1706 my $col_expand = (sum @col_expand) || 1;
1663 1707
1664 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1708 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1665 1709
1666 CFPlus::UI::harmonize $ws; 1710 DC::UI::harmonize $ws;
1667 1711
1668 my @row_expand = @{$self->{row_expand}}; 1712 my @row_expand = @{$self->{row_expand}};
1669 @row_expand = (1) x @$ws unless @row_expand; 1713 @row_expand = (1) x @$ws unless @row_expand;
1670 my $row_expand = (sum @row_expand) || 1; 1714 my $row_expand = (sum @row_expand) || 1;
1671 1715
1672 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; 1716 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1673 1717
1674 CFPlus::UI::harmonize $hs; 1718 DC::UI::harmonize $hs;
1675 1719
1676 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } 1720 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] }
1677 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } 1721 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] }
1678 1722
1679 for my $widget ($self->children) { 1723 for my $widget ($self->children) {
1688 1 1732 1
1689} 1733}
1690 1734
1691############################################################################# 1735#############################################################################
1692 1736
1693package CFPlus::UI::Fixed; 1737package DC::UI::Fixed;
1694 1738
1695use List::Util qw(min max); 1739use List::Util qw(min max);
1696 1740
1697our @ISA = CFPlus::UI::Container::; 1741our @ISA = DC::UI::Container::;
1698 1742
1699sub _scale($$$) { 1743sub _scale($$$) {
1700 my ($rel, $val, $max) = @_; 1744 my ($rel, $val, $max) = @_;
1701 1745
1702 $rel ? $val * $max : $val 1746 $rel ? $val * $max : $val
1754 1 1798 1
1755} 1799}
1756 1800
1757############################################################################# 1801#############################################################################
1758 1802
1759package CFPlus::UI::Box; 1803package DC::UI::Box;
1760 1804
1761our @ISA = CFPlus::UI::Container::; 1805our @ISA = DC::UI::Container::;
1762 1806
1763sub size_request { 1807sub size_request {
1764 my ($self) = @_; 1808 my ($self) = @_;
1765 1809
1766 my @children = $self->visible_children; 1810 my @children = $self->visible_children;
1801 $req[$_] += $space * $children[$_]{expand} 1845 $req[$_] += $space * $children[$_]{expand}
1802 for 0 .. $#children; 1846 for 0 .. $#children;
1803 } 1847 }
1804 } 1848 }
1805 1849
1806 CFPlus::UI::harmonize \@req; 1850 DC::UI::harmonize \@req;
1807 1851
1808 my $pos = 0; 1852 my $pos = 0;
1809 for (0 .. $#children) { 1853 for (0 .. $#children) {
1810 my $alloc = $req[$_]; 1854 my $alloc = $req[$_];
1811 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); 1855 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h));
1816 1 1860 1
1817} 1861}
1818 1862
1819############################################################################# 1863#############################################################################
1820 1864
1821package CFPlus::UI::HBox; 1865package DC::UI::HBox;
1822 1866
1823our @ISA = CFPlus::UI::Box::; 1867our @ISA = DC::UI::Box::;
1824 1868
1825sub new { 1869sub new {
1826 my $class = shift; 1870 my $class = shift;
1827 1871
1828 $class->SUPER::new ( 1872 $class->SUPER::new (
1831 ) 1875 )
1832} 1876}
1833 1877
1834############################################################################# 1878#############################################################################
1835 1879
1836package CFPlus::UI::VBox; 1880package DC::UI::VBox;
1837 1881
1838our @ISA = CFPlus::UI::Box::; 1882our @ISA = DC::UI::Box::;
1839 1883
1840sub new { 1884sub new {
1841 my $class = shift; 1885 my $class = shift;
1842 1886
1843 $class->SUPER::new ( 1887 $class->SUPER::new (
1846 ) 1890 )
1847} 1891}
1848 1892
1849############################################################################# 1893#############################################################################
1850 1894
1851package CFPlus::UI::Label; 1895package DC::UI::Label;
1852 1896
1853our @ISA = CFPlus::UI::DrawBG::; 1897our @ISA = DC::UI::DrawBG::;
1854 1898
1855use CFPlus::OpenGL; 1899use DC::OpenGL;
1856 1900
1857sub new { 1901sub new {
1858 my ($class, %arg) = @_; 1902 my ($class, %arg) = @_;
1859 1903
1860 my $self = $class->SUPER::new ( 1904 my $self = $class->SUPER::new (
1865 #text => initial text 1909 #text => initial text
1866 #markup => initial narkup 1910 #markup => initial narkup
1867 #max_w => maximum pixel width 1911 #max_w => maximum pixel width
1868 #style => 0, # render flags 1912 #style => 0, # render flags
1869 ellipsise => 3, # end 1913 ellipsise => 3, # end
1870 layout => (new CFPlus::Layout), 1914 layout => (new DC::Layout),
1871 fontsize => 1, 1915 fontsize => 1,
1872 align => -1, 1916 align => 0.5,
1873 valign => -1, 1917 valign => 0.5,
1874 padding_x => 2, 1918 padding_x => 4,
1875 padding_y => 2, 1919 padding_y => 2,
1876 can_events => 0, 1920 can_events => 0,
1877 %arg 1921 %arg
1878 ); 1922 );
1879 1923
1880 if (exists $self->{template}) { 1924 if (exists $self->{template}) {
1881 my $layout = new CFPlus::Layout; 1925 my $layout = new DC::Layout;
1882 $layout->set_text (delete $self->{template}); 1926 $layout->set_text (delete $self->{template});
1883 $self->{template} = $layout; 1927 $self->{template} = $layout;
1884 } 1928 }
1885 1929
1886 if (exists $self->{markup}) { 1930 if (exists $self->{markup}) {
1942 1986
1943sub size_request { 1987sub size_request {
1944 my ($self) = @_; 1988 my ($self) = @_;
1945 1989
1946 $self->{size_req} ||= do { 1990 $self->{size_req} ||= do {
1991 my ($max_w, $max_h) = $self->get_max_wh;
1992
1947 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1993 $self->{layout}->set_font ($self->{font}) if $self->{font};
1948 $self->{layout}->set_width ($self->{max_w} || -1); 1994 $self->{layout}->set_width ($max_w);
1949 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1995 $self->{layout}->set_ellipsise ($self->{ellipsise});
1950 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1996 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1951 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1997 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1952 1998
1953 my ($w, $h) = $self->{layout}->size; 1999 my ($w, $h) = $self->{layout}->size;
1954 2000
1955 if (exists $self->{template}) { 2001 if (exists $self->{template}) {
1956 $self->{template}->set_font ($self->{font}) if $self->{font}; 2002 $self->{template}->set_font ($self->{font}) if $self->{font};
1957 $self->{template}->set_width ($self->{max_w} || -1); 2003 $self->{template}->set_width ($max_w);
1958 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 2004 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1959 2005
1960 my ($w2, $h2) = $self->{template}->size; 2006 my ($w2, $h2) = $self->{template}->size;
1961 2007
1962 $w = List::Util::max $w, $w2; 2008 $w = List::Util::max $w, $w2;
2018 2064
2019 [$self->{layout}->size] 2065 [$self->{layout}->size]
2020 }; 2066 };
2021 2067
2022 unless (exists $self->{ox}) { 2068 unless (exists $self->{ox}) {
2023 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 2069 $self->{ox} = $self->{padding_x} + int $self->{align} * ($self->{w} - $size->[0] - $self->{padding_x} * 2);
2024 : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} 2070 $self->{oy} = $self->{padding_y} + int $self->{valign} * ($self->{h} - $size->[1] - $self->{padding_y} * 2);
2025 : ($self->{w} - $size->[0]) * 0.5);
2026
2027 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2028 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2029 : ($self->{h} - $size->[1]) * 0.5);
2030 2071
2031 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2072 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2032 }; 2073 };
2033 2074
2034# unless ($self->{list}) { 2075# unless ($self->{list}) {
2035# $self->{list} = CFPlus::OpenGL::glGenList; 2076# $self->{list} = DC::OpenGL::glGenList;
2036# CFPlus::OpenGL::glNewList $self->{list}; 2077# DC::OpenGL::glNewList $self->{list};
2037# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2078# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2038# CFPlus::OpenGL::glEndList; 2079# DC::OpenGL::glEndList;
2039# } 2080# }
2040# 2081#
2041# CFPlus::OpenGL::glCallList $self->{list}; 2082# DC::OpenGL::glCallList $self->{list};
2042 2083
2043 $self->{layout}->draw; 2084 $self->{layout}->draw;
2044} 2085}
2045 2086
2046#sub destroy { 2087#sub destroy {
2047# my ($self) = @_; 2088# my ($self) = @_;
2048# 2089#
2049# CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; 2090# DC::OpenGL::glDeleteList delete $self->{list} if $self->{list};
2050# 2091#
2051# $self->SUPER::destroy; 2092# $self->SUPER::destroy;
2052#} 2093#}
2053 2094
2054############################################################################# 2095#############################################################################
2055 2096
2056package CFPlus::UI::EntryBase; 2097package DC::UI::EntryBase;
2057 2098
2058our @ISA = CFPlus::UI::Label::; 2099our @ISA = DC::UI::Label::;
2059 2100
2060use CFPlus::OpenGL; 2101use DC::OpenGL;
2061 2102
2062sub new { 2103sub new {
2063 my $class = shift; 2104 my $class = shift;
2064 2105
2065 $class->SUPER::new ( 2106 $class->SUPER::new (
2066 fg => [1, 1, 1], 2107 fg => [1, 1, 1],
2067 bg => [0, 0, 0, 0.2], 2108 bg => [0, 0, 0, 0.2],
2068 outline => [0.6, 0.3, 0.1], 2109 outline => undef,
2069 active_bg => [0, 0, 1, .2], 2110 active_bg => [0, 0, 1, .2],
2070 active_fg => [1, 1, 1], 2111 active_fg => [1, 1, 1],
2071 active_outline => [1, 1, 0], 2112 active_outline => [1, 1, 0],
2072 can_hover => 1, 2113 can_hover => 1,
2073 can_focus => 1, 2114 can_focus => 1,
2115 align => 0,
2074 valign => 0, 2116 valign => 0.5,
2075 can_events => 1, 2117 can_events => 1,
2076 ellipsise => 0, 2118 ellipsise => 0,
2119 padding_x => 4,
2120 padding_y => 2,
2077 #text => ... 2121 #text => ...
2078 #hidden => "*", 2122 #hidden => "*",
2079 @_ 2123 @_
2080 ) 2124 )
2081} 2125}
2128 2172
2129 my $text = $self->get_text; 2173 my $text = $self->get_text;
2130 2174
2131 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; 2175 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text;
2132 2176
2133 if ($uni == 8) { 2177 if ($sym == DC::SDLK_BACKSPACE) {
2134 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2178 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
2135 } elsif ($uni == 127) { 2179 } elsif ($sym == DC::SDLK_DELETE) {
2136 substr $text, $self->{cursor}, 1, ""; 2180 substr $text, $self->{cursor}, 1, "";
2137 } elsif ($sym == CFPlus::SDLK_LEFT) { 2181 } elsif ($sym == DC::SDLK_LEFT) {
2138 --$self->{cursor} if $self->{cursor}; 2182 --$self->{cursor} if $self->{cursor};
2139 } elsif ($sym == CFPlus::SDLK_RIGHT) { 2183 } elsif ($sym == DC::SDLK_RIGHT) {
2140 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 2184 ++$self->{cursor} if $self->{cursor} < length $self->{text};
2141 } elsif ($sym == CFPlus::SDLK_HOME) { 2185 } elsif ($sym == DC::SDLK_HOME) {
2142 # what a hack 2186 # what a hack
2143 $self->{cursor} = 2187 $self->{cursor} =
2144 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ 2188 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/
2145 ? length $1 2189 ? length $1
2146 : 0; 2190 : 0;
2147 } elsif ($sym == CFPlus::SDLK_END) { 2191 } elsif ($sym == DC::SDLK_END) {
2148 # uh, again 2192 # uh, again
2149 $self->{cursor} = 2193 $self->{cursor} =
2150 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ 2194 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/
2151 ? $self->{cursor} + length $1 2195 ? $self->{cursor} + length $1
2152 : length $self->{text}; 2196 : length $self->{text};
2233 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); 2277 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
2234 } 2278 }
2235 2279
2236 glColor_premultiply @{$self->{active_fg}}; 2280 glColor_premultiply @{$self->{active_fg}};
2237 glBegin GL_LINES; 2281 glBegin GL_LINES;
2238 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; 2282 glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy};
2239 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; 2283 glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h};
2240 glEnd; 2284 glEnd;
2241 2285
2242 glLineWidth 3; 2286 glLineWidth 3;
2243 glColor @{$self->{active_outline}}; 2287 glColor @{$self->{active_outline}};
2244 glRect_lineloop 0, 0, $self->{w} - 1, $self->{h} - 1; 2288 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2245 glLineWidth 1; 2289 glLineWidth 1;
2246 2290
2247 } else { 2291 } else {
2248 glColor @{$self->{outline}}; 2292 glColor @{$self->{outline} || $DC::THEME{entry_outline}};
2249 glTranslate .375, .375;
2250 glBegin GL_LINE_STRIP; 2293 glBegin GL_LINE_STRIP;
2251 glVertex 0, $self->{h} * .5; 2294 glVertex .5, $self->{h} * .5;
2252 glVertex 0, $self->{h} - 3; 2295 glVertex .5, $self->{h} - 2.5;
2253 glVertex $self->{w} - 1, $self->{h} - 3; 2296 glVertex $self->{w} - .5, $self->{h} - 2.5;
2254 glVertex $self->{w} - 1, $self->{h} * .5; 2297 glVertex $self->{w} - .5, $self->{h} * .5;
2255 glEnd; 2298 glEnd;
2256 } 2299 }
2257} 2300}
2258 2301
2259############################################################################# 2302#############################################################################
2260 2303
2261package CFPlus::UI::Entry; 2304package DC::UI::Entry;
2262 2305
2263our @ISA = CFPlus::UI::EntryBase::; 2306our @ISA = DC::UI::EntryBase::;
2264 2307
2265use CFPlus::OpenGL; 2308use DC::OpenGL;
2309
2310sub new {
2311 my $class = shift;
2312
2313 $class->SUPER::new (
2314 history_pointer => -1,
2315 @_
2316 )
2317}
2318
2266 2319
2267sub invoke_key_down { 2320sub invoke_key_down {
2268 my ($self, $ev) = @_; 2321 my ($self, $ev) = @_;
2269 2322
2270 my $sym = $ev->{sym}; 2323 my $sym = $ev->{sym};
2276 $self->{history_pointer} = -1; 2329 $self->{history_pointer} = -1;
2277 $self->{history_saveback} = ''; 2330 $self->{history_saveback} = '';
2278 $self->emit (activate => $txt); 2331 $self->emit (activate => $txt);
2279 $self->update; 2332 $self->update;
2280 2333
2281 } elsif ($sym == CFPlus::SDLK_UP) { 2334 } elsif ($sym == DC::SDLK_UP) {
2282 if ($self->{history_pointer} < 0) { 2335 if ($self->{history_pointer} < 0) {
2283 $self->{history_saveback} = $self->get_text; 2336 $self->{history_saveback} = $self->get_text;
2284 } 2337 }
2285 if (@{$self->{history} || []} > 0) { 2338 if (@{$self->{history} || []} > 0) {
2286 $self->{history_pointer}++; 2339 $self->{history_pointer}++;
2288 $self->{history_pointer} = @{$self->{history} || []} - 1; 2341 $self->{history_pointer} = @{$self->{history} || []} - 1;
2289 } 2342 }
2290 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2343 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2291 } 2344 }
2292 2345
2293 } elsif ($sym == CFPlus::SDLK_DOWN) { 2346 } elsif ($sym == DC::SDLK_DOWN) {
2294 $self->{history_pointer}--; 2347 $self->{history_pointer}--;
2295 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2348 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
2296 2349
2297 if ($self->{history_pointer} >= 0) { 2350 if ($self->{history_pointer} >= 0) {
2298 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2351 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2299 } else { 2352 } else {
2353 if (defined $self->{history_saveback}) {
2300 $self->set_text ($self->{history_saveback}); 2354 $self->set_text ($self->{history_saveback});
2355 $self->{history_saveback} = undef;
2356 }
2301 } 2357 }
2302 2358
2303 } else { 2359 } else {
2304 return $self->SUPER::invoke_key_down ($ev) 2360 return $self->SUPER::invoke_key_down ($ev)
2305 } 2361 }
2307 1 2363 1
2308} 2364}
2309 2365
2310############################################################################# 2366#############################################################################
2311 2367
2312package CFPlus::UI::TextEdit; 2368package DC::UI::TextEdit;
2313 2369
2314our @ISA = CFPlus::UI::EntryBase::; 2370our @ISA = DC::UI::EntryBase::;
2315 2371
2316use CFPlus::OpenGL; 2372use DC::OpenGL;
2373
2374sub new {
2375 my $class = shift;
2376
2377 $class->SUPER::new (
2378 padding_y => 4,
2379
2380 @_
2381 )
2382}
2317 2383
2318sub move_cursor_ver { 2384sub move_cursor_ver {
2319 my ($self, $dy) = @_; 2385 my ($self, $dy) = @_;
2320 2386
2321 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2387 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2322 2388
2323 $y += $dy; 2389 $line += $dy;
2324 2390
2325 if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { 2391 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) {
2326 $self->{cursor} = $index; 2392 $self->{cursor} = $index;
2327 delete $self->{cur_h}; 2393 delete $self->{cur_h};
2328 $self->update; 2394 $self->update;
2329 return; 2395 return;
2330 } 2396 }
2333sub invoke_key_down { 2399sub invoke_key_down {
2334 my ($self, $ev) = @_; 2400 my ($self, $ev) = @_;
2335 2401
2336 my $sym = $ev->{sym}; 2402 my $sym = $ev->{sym};
2337 2403
2338 if ($sym == CFPlus::SDLK_UP) { 2404 if ($sym == DC::SDLK_UP) {
2339 $self->move_cursor_ver (-1); 2405 $self->move_cursor_ver (-1);
2340 } elsif ($sym == CFPlus::SDLK_DOWN) { 2406 } elsif ($sym == DC::SDLK_DOWN) {
2341 $self->move_cursor_ver (+1); 2407 $self->move_cursor_ver (+1);
2342 } else { 2408 } else {
2343 return $self->SUPER::invoke_key_down ($ev) 2409 return $self->SUPER::invoke_key_down ($ev)
2344 } 2410 }
2345 2411
2346 1 2412 1
2347} 2413}
2348 2414
2349############################################################################# 2415#############################################################################
2350 2416
2351package CFPlus::UI::ButtonBin; 2417package DC::UI::ButtonBin;
2352 2418
2353our @ISA = CFPlus::UI::Bin::; 2419our @ISA = DC::UI::Bin::;
2354 2420
2355use CFPlus::OpenGL; 2421use DC::OpenGL;
2356 2422
2357my @tex = 2423my @tex =
2358 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2424 map { new_from_resource DC::Texture $_, mipmap => 1 }
2359 qw(b1_button_inactive.png b1_button_active.png); 2425 qw(b1_button_inactive.png b1_button_active.png);
2360 2426
2361sub new { 2427sub new {
2362 my $class = shift; 2428 my $class = shift;
2363 2429
2364 $class->SUPER::new ( 2430 $class->SUPER::new (
2365 can_hover => 1, 2431 can_hover => 1,
2366 align => 0, 2432 align => 0.5,
2367 valign => 0, 2433 valign => 0.5,
2368 can_events => 1, 2434 can_events => 1,
2369 @_ 2435 @_
2370 ) 2436 )
2371} 2437}
2372 2438
2395 $self->SUPER::_draw; 2461 $self->SUPER::_draw;
2396} 2462}
2397 2463
2398############################################################################# 2464#############################################################################
2399 2465
2400package CFPlus::UI::Button; 2466package DC::UI::Button;
2401 2467
2402our @ISA = CFPlus::UI::Label::; 2468our @ISA = DC::UI::Label::;
2403 2469
2404use CFPlus::OpenGL; 2470use DC::OpenGL;
2405 2471
2406my @tex = 2472my @tex =
2407 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2473 map { new_from_resource DC::Texture $_, mipmap => 1 }
2408 qw(b1_button_inactive.png b1_button_active.png); 2474 qw(b1_button_inactive.png b1_button_active.png);
2409 2475
2410sub new { 2476sub new {
2411 my $class = shift; 2477 my $class = shift;
2412 2478
2413 $class->SUPER::new ( 2479 $class->SUPER::new (
2414 padding_x => 4, 2480 padding_x => 8,
2415 padding_y => 4, 2481 padding_y => 4,
2416 fg => [1.0, 1.0, 1.0], 2482 fg => [1.0, 1.0, 1.0],
2417 active_fg => [0.8, 0.8, 0.8], 2483 active_fg => [0.8, 0.8, 0.8],
2418 can_hover => 1, 2484 can_hover => 1,
2419 align => 0, 2485 align => 0.5,
2420 valign => 0, 2486 valign => 0.5,
2421 can_events => 1, 2487 can_events => 1,
2422 @_ 2488 @_
2423 ) 2489 )
2424} 2490}
2425 2491
2450 $self->SUPER::_draw; 2516 $self->SUPER::_draw;
2451} 2517}
2452 2518
2453############################################################################# 2519#############################################################################
2454 2520
2455package CFPlus::UI::CheckBox; 2521package DC::UI::CheckBox;
2456 2522
2457our @ISA = CFPlus::UI::DrawBG::; 2523our @ISA = DC::UI::DrawBG::;
2458 2524
2459my @tex = 2525my @tex =
2460 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2526 map { new_from_resource DC::Texture $_, mipmap => 1 }
2461 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2527 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2462 2528
2463use CFPlus::OpenGL; 2529use DC::OpenGL;
2464 2530
2465sub new { 2531sub new {
2466 my $class = shift; 2532 my $class = shift;
2467 2533
2468 $class->SUPER::new ( 2534 $class->SUPER::new (
2535 fontsize => 1,
2469 padding_x => 2, 2536 padding_x => 2,
2470 padding_y => 2, 2537 padding_y => 2,
2471 fg => [1, 1, 1], 2538 fg => [1, 1, 1],
2472 active_fg => [1, 1, 0], 2539 active_fg => [1, 1, 0],
2473 bg => [0, 0, 0, 0.2], 2540 bg => [0, 0, 0, 0.2],
2479} 2546}
2480 2547
2481sub size_request { 2548sub size_request {
2482 my ($self) = @_; 2549 my ($self) = @_;
2483 2550
2484 (6) x 2 2551 ($self->{fontsize} * $::FONTSIZE) x 2
2485} 2552}
2486 2553
2487sub toggle { 2554sub toggle {
2488 my ($self) = @_; 2555 my ($self) = @_;
2489 2556
2508sub _draw { 2575sub _draw {
2509 my ($self) = @_; 2576 my ($self) = @_;
2510 2577
2511 $self->SUPER::_draw; 2578 $self->SUPER::_draw;
2512 2579
2513 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; 2580 glTranslate $self->{padding_x}, $self->{padding_y}, 0;
2514 2581
2515 my ($w, $h) = @$self{qw(w h)}; 2582 my ($w, $h) = @$self{qw(w h)};
2516 2583
2517 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; 2584 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2518 2585
2525 glDisable GL_TEXTURE_2D; 2592 glDisable GL_TEXTURE_2D;
2526} 2593}
2527 2594
2528############################################################################# 2595#############################################################################
2529 2596
2530package CFPlus::UI::Image; 2597package DC::UI::Image;
2531 2598
2532our @ISA = CFPlus::UI::Base::; 2599our @ISA = DC::UI::Base::;
2533 2600
2534use CFPlus::OpenGL; 2601use DC::OpenGL;
2535 2602
2536our %texture_cache; 2603our %texture_cache;
2537 2604
2538sub new { 2605sub new {
2539 my $class = shift; 2606 my $class = shift;
2546 2613
2547 $self->{path} || $self->{tex} 2614 $self->{path} || $self->{tex}
2548 or Carp::croak "'path' or 'tex' attributes required"; 2615 or Carp::croak "'path' or 'tex' attributes required";
2549 2616
2550 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2617 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2551 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; 2618 new_from_resource DC::Texture $self->{path}, mipmap => 1;
2552 2619
2553 CFPlus::weaken $texture_cache{$self->{path}}; 2620 DC::weaken $texture_cache{$self->{path}};
2554 2621
2555 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2622 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2556 2623
2557 $self 2624 $self
2558} 2625}
2559 2626
2560sub STORABLE_freeze { 2627sub STORABLE_freeze {
2561 my ($self, $cloning) = @_; 2628 my ($self, $cloning) = @_;
2562 2629
2563 $self->{path} 2630 $self->{path}
2564 or die "cannot serialise CFPlus::UI::Image on non-loadable images\n"; 2631 or die "cannot serialise DC::UI::Image on non-loadable images\n";
2565 2632
2566 $self->{path} 2633 $self->{path}
2567} 2634}
2568 2635
2569sub STORABLE_attach { 2636sub STORABLE_attach {
2600 glDisable GL_TEXTURE_2D; 2667 glDisable GL_TEXTURE_2D;
2601} 2668}
2602 2669
2603############################################################################# 2670#############################################################################
2604 2671
2605package CFPlus::UI::ImageButton; 2672package DC::UI::ImageButton;
2606 2673
2607our @ISA = CFPlus::UI::Image::; 2674our @ISA = DC::UI::Image::;
2608 2675
2609use CFPlus::OpenGL; 2676use DC::OpenGL;
2610 2677
2611my %textures; 2678my %textures;
2612 2679
2613sub new { 2680sub new {
2614 my $class = shift; 2681 my $class = shift;
2617 padding_x => 4, 2684 padding_x => 4,
2618 padding_y => 4, 2685 padding_y => 4,
2619 fg => [1, 1, 1], 2686 fg => [1, 1, 1],
2620 active_fg => [0, 0, 1], 2687 active_fg => [0, 0, 1],
2621 can_hover => 1, 2688 can_hover => 1,
2622 align => 0, 2689 align => 0.5,
2623 valign => 0, 2690 valign => 0.5,
2624 can_events => 1, 2691 can_events => 1,
2625 @_ 2692 @_
2626 ); 2693 );
2627} 2694}
2628 2695
2642 1 2709 1
2643} 2710}
2644 2711
2645############################################################################# 2712#############################################################################
2646 2713
2647package CFPlus::UI::VGauge; 2714package DC::UI::VGauge;
2648 2715
2649our @ISA = CFPlus::UI::Base::; 2716our @ISA = DC::UI::Base::;
2650 2717
2651use List::Util qw(min max); 2718use List::Util qw(min max);
2652 2719
2653use CFPlus::OpenGL; 2720use DC::OpenGL;
2654 2721
2655my %tex = ( 2722my %tex = (
2656 food => [ 2723 food => [
2657 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2724 map { new_from_resource DC::Texture $_, mipmap => 1 }
2658 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2725 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2659 ], 2726 ],
2660 grace => [ 2727 grace => [
2661 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2728 map { new_from_resource DC::Texture $_, mipmap => 1 }
2662 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2729 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2663 ], 2730 ],
2664 hp => [ 2731 hp => [
2665 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2732 map { new_from_resource DC::Texture $_, mipmap => 1 }
2666 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2733 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2667 ], 2734 ],
2668 mana => [ 2735 mana => [
2669 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2736 map { new_from_resource DC::Texture $_, mipmap => 1 }
2670 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2737 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2671 ], 2738 ],
2672); 2739);
2673 2740
2674# eg. VGauge->new (gauge => 'food'), default gauge: food 2741# eg. VGauge->new (gauge => 'food'), default gauge: food
2777 glDisable GL_TEXTURE_2D; 2844 glDisable GL_TEXTURE_2D;
2778} 2845}
2779 2846
2780############################################################################# 2847#############################################################################
2781 2848
2782package CFPlus::UI::Progress; 2849package DC::UI::Progress;
2783 2850
2784our @ISA = CFPlus::UI::Label::; 2851our @ISA = DC::UI::Label::;
2785 2852
2786use CFPlus::OpenGL; 2853use DC::OpenGL;
2787 2854
2788sub new { 2855sub new {
2789 my ($class, %arg) = @_; 2856 my ($class, %arg) = @_;
2790 2857
2791 my $self = $class->SUPER::new ( 2858 my $self = $class->SUPER::new (
2859 padding_x => 2,
2860 padding_y => 2,
2792 fg => [1, 1, 1], 2861 fg => [1, 1, 1],
2793 bg => [0, 0, 1, 0.2], 2862 bg => [0, 0, 1, 0.2],
2794 bar => [0.7, 0.5, 0.1, 0.8], 2863 bar => [0.7, 0.5, 0.1, 0.8],
2795 outline => [0.4, 0.3, 0], 2864 outline => [0.4, 0.3, 0],
2796 fontsize => 0.9, 2865 fontsize => 0.9,
2797 valign => 0, 2866 valign => 0.5,
2798 align => 0, 2867 align => 0.5,
2799 can_events => 1, 2868 can_events => 1,
2800 ellipsise => 1, 2869 ellipsise => 1,
2801 label => "%d%%", 2870 label => "%d%%",
2802 %arg, 2871 %arg,
2803 ); 2872 );
2811 my ($self, $label) = @_; 2880 my ($self, $label) = @_;
2812 2881
2813 return if $self->{label} eq $label; 2882 return if $self->{label} eq $label;
2814 $self->{label} = $label; 2883 $self->{label} = $label;
2815 2884
2816 $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value}); 2885 $self->DC::UI::Progress::set_value (0 + delete $self->{value});
2817} 2886}
2818 2887
2819sub set_value { 2888sub set_value {
2820 my ($self, $value) = @_; 2889 my ($self, $value) = @_;
2821 2890
2836 my ($self) = @_; 2905 my ($self) = @_;
2837 2906
2838 glEnable GL_BLEND; 2907 glEnable GL_BLEND;
2839 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2908 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2840 2909
2910 my $px = $self->{padding_x};
2911 my $py = $self->{padding_y};
2912
2841 if ($self->{value} >= 0) { 2913 if ($self->{value} >= 0) {
2842 my $s = 3 + ($self->{w} - 6) * $self->{value}; 2914 my $s = int $px + ($self->{w} - $px * 2) * $self->{value};
2843 2915
2844 glColor_premultiply @{$self->{bar}}; 2916 glColor_premultiply @{$self->{bar}};
2845 glRect 2, 2, $s, $self->{h} - 2; 2917 glRect $px, $py, $s, $self->{h} - $py;
2846 glColor_premultiply @{$self->{bg}}; 2918 glColor_premultiply @{$self->{bg}};
2847 glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2; 2919 glRect $s , $py, $self->{w} - $px, $self->{h} - $py;
2848 } 2920 }
2849 2921
2850 glColor_premultiply @{$self->{outline}}; 2922 glColor_premultiply @{$self->{outline}};
2923
2924 $px -= .5;
2925 $py -= .5;
2926
2851 glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2; 2927 glRect_lineloop $px, $py, $self->{w} - $px, $self->{h} - $py;
2852 2928
2853 glDisable GL_BLEND; 2929 glDisable GL_BLEND;
2854 2930
2855 { 2931 {
2856 local $self->{bg}; # do not draw background 2932 local $self->{bg}; # do not draw background
2858 } 2934 }
2859} 2935}
2860 2936
2861############################################################################# 2937#############################################################################
2862 2938
2863package CFPlus::UI::ExperienceProgress; 2939package DC::UI::ExperienceProgress;
2864 2940
2865our @ISA = CFPlus::UI::Progress::; 2941our @ISA = DC::UI::Progress::;
2866 2942
2867sub new { 2943sub new {
2868 my ($class, %arg) = @_; 2944 my ($class, %arg) = @_;
2869 2945
2946 my $tt = exists $arg{tooltip} ? "$arg{tooltip}\n\n" : "";
2947
2870 my $self = $class->SUPER::new ( 2948 my $self = $class->SUPER::new (
2949 %arg,
2871 tooltip => sub { 2950 tooltip => sub {
2872 my ($self) = @_; 2951 my ($self) = @_;
2873 2952
2874 sprintf "level %d\n%s points\n%s next level\n%s to go", 2953 sprintf "%slevel %d\n%s points\n%s next level\n%s to go, %d%% done",
2954 $tt,
2875 $self->{lvl}, 2955 $self->{lvl},
2876 ::formsep ($self->{exp}), 2956 ::formsep ($self->{exp}),
2877 ::formsep ($self->{nxt}), 2957 ::formsep ($self->{nxt}),
2878 ::formsep ($self->{nxt} - $self->{exp}), 2958 ::formsep ($self->{nxt} - $self->{exp}),
2959 $self->_percent * 100,
2879 }, 2960 },
2880 %arg
2881 ); 2961 );
2882 2962
2883 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } 2963 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2884 if $::CONN; 2964 if $::CONN;
2885 2965
2893 if $::CONN; 2973 if $::CONN;
2894 2974
2895 $self->SUPER::DESTROY; 2975 $self->SUPER::DESTROY;
2896} 2976}
2897 2977
2978sub _percent {
2979 my ($self) = @_;
2980
2981 my $table = $::CONN && $::CONN->{exp_table}
2982 or return -1;
2983
2984 my $l0 = $table->[$self->{lvl} - 1];
2985 my $l1 = $table->[$self->{lvl}];
2986
2987 $self->{nxt} = $l1;
2988
2989 ($self->{exp} - $l0) / ($l1 - $l0)
2990}
2991
2898sub set_value { 2992sub set_value {
2899 my ($self, $lvl, $exp) = @_; 2993 my ($self, $lvl, $exp) = @_;
2900 2994
2901 $self->{lvl} = $lvl; 2995 $self->{lvl} = $lvl;
2902 $self->{exp} = $exp; 2996 $self->{exp} = $exp;
2903 2997
2904 my $v = -1;
2905
2906 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2907 my $l0 = $table->[$lvl - 1];
2908 my $l1 = $table->[$lvl];
2909
2910 $self->{nxt} = $l1;
2911
2912 $v = ($exp - $l0) / ($l1 - $l0);
2913 }
2914
2915 $self->SUPER::set_value ($v); 2998 $self->SUPER::set_value ($self->_percent);
2916} 2999}
2917 3000
2918############################################################################# 3001#############################################################################
2919 3002
2920package CFPlus::UI::Gauge; 3003package DC::UI::Gauge;
2921 3004
2922our @ISA = CFPlus::UI::VBox::; 3005our @ISA = DC::UI::VBox::;
2923 3006
2924sub new { 3007sub new {
2925 my ($class, %arg) = @_; 3008 my ($class, %arg) = @_;
2926 3009
2927 my $self = $class->SUPER::new ( 3010 my $self = $class->SUPER::new (
2929 can_hover => 1, 3012 can_hover => 1,
2930 can_events => 1, 3013 can_events => 1,
2931 %arg, 3014 %arg,
2932 ); 3015 );
2933 3016
2934 $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999"); 3017 $self->add ($self->{value} = new DC::UI::Label valign => 1, align => 0.5, template => "999");
2935 $self->add ($self->{gauge} = new CFPlus::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 3018 $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
2936 $self->add ($self->{max} = new CFPlus::UI::Label valign => -1, align => 0, template => "999"); 3019 $self->add ($self->{max} = new DC::UI::Label valign => 0, align => 0.5, template => "999");
2937 3020
2938 $self 3021 $self
2939} 3022}
2940 3023
2941sub set_fontsize { 3024sub set_fontsize {
2962 $self->{value}->set_text ($val); 3045 $self->{value}->set_text ($val);
2963} 3046}
2964 3047
2965############################################################################# 3048#############################################################################
2966 3049
2967package CFPlus::UI::Slider; 3050package DC::UI::Slider;
2968 3051
2969use strict; 3052use strict;
2970 3053
2971use CFPlus::OpenGL; 3054use DC::OpenGL;
2972 3055
2973our @ISA = CFPlus::UI::DrawBG::; 3056our @ISA = DC::UI::DrawBG::;
2974 3057
2975my @tex = 3058my @tex =
2976 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ } 3059 map { new_from_resource DC::Texture $_ }
2977 qw(s1_slider.png s1_slider_bg.png); 3060 qw(s1_slider.png s1_slider_bg.png);
2978 3061
2979sub new { 3062sub new {
2980 my $class = shift; 3063 my $class = shift;
2981 3064
3018sub set_value { 3101sub set_value {
3019 my ($self, $value) = @_; 3102 my ($self, $value) = @_;
3020 3103
3021 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; 3104 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
3022 3105
3023 $hi = $lo + 1 if $hi <= $lo; 3106 $hi = $lo if $hi < $lo;
3024 3107
3025 $page = $hi - $lo if $page > $hi - $lo; 3108 $value = $hi - $page if $value > $hi - $page;
3026
3027 $value = $lo if $value < $lo; 3109 $value = $lo if $value < $lo;
3028 $value = $hi - $page if $value > $hi - $page;
3029 3110
3030 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit 3111 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
3031 if $unit; 3112 if $unit;
3032 3113
3033 @{$self->{range}} = ($value, $lo, $hi, $page, $unit); 3114 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
3077sub invoke_mouse_wheel { 3158sub invoke_mouse_wheel {
3078 my ($self, $ev) = @_; 3159 my ($self, $ev) = @_;
3079 3160
3080 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 3161 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
3081 3162
3082 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; 3163 my $pagepart = $ev->{mod} & DC::KMOD_SHIFT ? 1 : 0.2;
3083 3164
3084 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); 3165 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
3085 3166
3086 1 3167 1
3087} 3168}
3097 my ($self) = @_; 3178 my ($self) = @_;
3098 3179
3099 unless ($self->{knob_w}) { 3180 unless ($self->{knob_w}) {
3100 $self->set_value ($self->{range}[0]); 3181 $self->set_value ($self->{range}[0]);
3101 3182
3102 my ($value, $lo, $hi, $page) = @{$self->{range}}; 3183 my ($value, $lo, $hi, $page, $unit) = @{$self->{range}};
3103 my $range = ($hi - $page - $lo) || 1e-100; 3184 my $range = ($hi - $page - $lo) || 1e-10;
3104 3185
3105 my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1; 3186 my $knob_w = List::Util::min 1, $page / (($hi - $lo) || 1e-10) || 24 / $self->{w};
3106 3187
3107 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; 3188 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5;
3108 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; 3189 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100;
3109 3190
3110 $value = ($value - $lo) / $range; 3191 $value = ($value - $lo) / $range;
3140 glDisable GL_TEXTURE_2D; 3221 glDisable GL_TEXTURE_2D;
3141} 3222}
3142 3223
3143############################################################################# 3224#############################################################################
3144 3225
3145package CFPlus::UI::ValSlider; 3226package DC::UI::ValSlider;
3146 3227
3147our @ISA = CFPlus::UI::HBox::; 3228our @ISA = DC::UI::HBox::;
3148 3229
3149sub new { 3230sub new {
3150 my ($class, %arg) = @_; 3231 my ($class, %arg) = @_;
3151 3232
3152 my $range = delete $arg{range}; 3233 my $range = delete $arg{range};
3153 3234
3154 my $self = $class->SUPER::new ( 3235 my $self = $class->SUPER::new (
3155 slider => (new CFPlus::UI::Slider expand => 1, range => $range), 3236 slider => (new DC::UI::Slider expand => 1, range => $range),
3156 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}), 3237 entry => (new DC::UI::Label text => "", template => delete $arg{template}),
3157 to_value => sub { shift }, 3238 to_value => sub { shift },
3158 from_value => sub { shift }, 3239 from_value => sub { shift },
3159 %arg, 3240 %arg,
3160 ); 3241 );
3161 3242
3181sub set_range { shift->{slider}->set_range (@_) } 3262sub set_range { shift->{slider}->set_range (@_) }
3182sub set_value { shift->{slider}->set_value (@_) } 3263sub set_value { shift->{slider}->set_value (@_) }
3183 3264
3184############################################################################# 3265#############################################################################
3185 3266
3186package CFPlus::UI::TextScroller; 3267package DC::UI::TextScroller;
3187 3268
3188our @ISA = CFPlus::UI::HBox::; 3269our @ISA = DC::UI::HBox::;
3189 3270
3190use CFPlus::OpenGL; 3271use DC::OpenGL;
3191 3272
3192sub new { 3273sub new {
3193 my $class = shift; 3274 my $class = shift;
3194 3275
3195 my $self = $class->SUPER::new ( 3276 my $self = $class->SUPER::new (
3197 can_events => 1, 3278 can_events => 1,
3198 indent => 0, 3279 indent => 0,
3199 #font => default_font 3280 #font => default_font
3200 @_, 3281 @_,
3201 3282
3202 layout => (new CFPlus::Layout), 3283 layout => (new DC::Layout),
3203 par => [], 3284 par => [],
3204 max_par => 0, 3285 max_par => 0,
3205 height => 0, 3286 height => 0,
3206 children => [ 3287 children => [
3207 (new CFPlus::UI::Empty expand => 1), 3288 (new DC::UI::Empty expand => 1),
3208 (new CFPlus::UI::Slider vertical => 1), 3289 (new DC::UI::Slider vertical => 1),
3209 ], 3290 ],
3210 ); 3291 );
3211 3292
3212 $self->{children}[1]->connect (changed => sub { $self->update }); 3293 $self->{children}[1]->connect (changed => sub { $self->update });
3213 3294
3269 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); 3350 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
3270 $layout->set_markup ($para->{markup}); 3351 $layout->set_markup ($para->{markup});
3271 3352
3272 $layout->set_shapes ( 3353 $layout->set_shapes (
3273 map 3354 map
3274 +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), 3355 +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}),
3275 @{$para->{widget}} 3356 @{$para->{widget}}
3276 ); 3357 );
3277 3358
3278 $layout 3359 $layout
3279} 3360}
3396 $ROOT->on_post_alloc ($self => sub { 3477 $ROOT->on_post_alloc ($self => sub {
3397 $self->force_uptodate; 3478 $self->force_uptodate;
3398 3479
3399 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 3480 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
3400 3481
3401 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 3482 $self->{texture} ||= new_from_opengl DC::Texture $W, $H, sub {
3402 glClearColor 0, 0, 0, 0; 3483 glClearColor 0, 0, 0, 0;
3403 glClear GL_COLOR_BUFFER_BIT; 3484 glClear GL_COLOR_BUFFER_BIT;
3404 3485
3405 package CFPlus::UI::Base; 3486 package DC::UI::Base;
3406 local ($draw_x, $draw_y, $draw_w, $draw_h) = 3487 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3407 (0, 0, $self->{w}, $self->{h}); 3488 (0, 0, $self->{w}, $self->{h});
3408 3489
3409 my $top = int $self->{children}[1]{range}[0]; 3490 my $top = int $self->{children}[1]{range}[0];
3410 3491
3469 $self->{children}[1]->draw; 3550 $self->{children}[1]->draw;
3470} 3551}
3471 3552
3472############################################################################# 3553#############################################################################
3473 3554
3474package CFPlus::UI::Animator; 3555package DC::UI::Animator;
3475 3556
3476use CFPlus::OpenGL; 3557use DC::OpenGL;
3477 3558
3478our @ISA = CFPlus::UI::Bin::; 3559our @ISA = DC::UI::Bin::;
3479 3560
3480sub moveto { 3561sub moveto {
3481 my ($self, $x, $y) = @_; 3562 my ($self, $x, $y) = @_;
3482 3563
3483 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 3564 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
3511 glPopMatrix; 3592 glPopMatrix;
3512} 3593}
3513 3594
3514############################################################################# 3595#############################################################################
3515 3596
3516package CFPlus::UI::Flopper; 3597package DC::UI::Flopper;
3517 3598
3518our @ISA = CFPlus::UI::Button::; 3599our @ISA = DC::UI::Button::;
3519 3600
3520sub new { 3601sub new {
3521 my $class = shift; 3602 my $class = shift;
3522 3603
3523 my $self = $class->SUPER::new ( 3604 my $self = $class->SUPER::new (
3535 $self->{other}->toggle_visibility; 3616 $self->{other}->toggle_visibility;
3536} 3617}
3537 3618
3538############################################################################# 3619#############################################################################
3539 3620
3540package CFPlus::UI::Tooltip; 3621package DC::UI::Tooltip;
3541 3622
3542our @ISA = CFPlus::UI::Bin::; 3623our @ISA = DC::UI::Bin::;
3543 3624
3544use CFPlus::OpenGL; 3625use DC::OpenGL;
3545 3626
3546sub new { 3627sub new {
3547 my $class = shift; 3628 my $class = shift;
3548 3629
3549 $class->SUPER::new ( 3630 $class->SUPER::new (
3556 my ($self, $widget) = @_; 3637 my ($self, $widget) = @_;
3557 3638
3558 my $tip = $widget->{tooltip}; 3639 my $tip = $widget->{tooltip};
3559 $tip = $tip->($widget) if "CODE" eq ref $tip; 3640 $tip = $tip->($widget) if "CODE" eq ref $tip;
3560 3641
3561 $tip = CFPlus::Pod::section_label tooltip => $1 3642 $tip = DC::Pod::section_label tooltip => $1
3562 if $tip =~ /^#(.*)$/; 3643 if $tip =~ /^#(.*)$/;
3563 3644
3564 if ($ENV{CFPLUS_DEBUG} & 2) { 3645 if ($ENV{CFPLUS_DEBUG} & 2) {
3565 $tip .= "\n\n" . (ref $widget) . "\n" 3646 $tip .= "\n\n" . (ref $widget) . "\n"
3566 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3647 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3569 } 3650 }
3570 3651
3571 $tip =~ s/^\n+//; 3652 $tip =~ s/^\n+//;
3572 $tip =~ s/\n+$//; 3653 $tip =~ s/\n+$//;
3573 3654
3574 $self->add (new CFPlus::UI::Label 3655 $self->add (new DC::UI::Label
3656 fg => $DC::THEME{tooltip_fg},
3575 markup => $tip, 3657 markup => $tip,
3576 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3658 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3659 align => 0,
3577 fontsize => 0.8, 3660 fontsize => 0.8,
3578 style => 1, # FLAG_INVERSE 3661 style => $DC::THEME{tooltip_style}, # FLAG_INVERSE
3579 ellipsise => 0, 3662 ellipsise => 0,
3580 font => ($widget->{tooltip_font} || $::FONT_PROP), 3663 font => ($widget->{tooltip_font} || $::FONT_PROP),
3581 ); 3664 );
3582} 3665}
3583 3666
3618} 3701}
3619 3702
3620sub _draw { 3703sub _draw {
3621 my ($self) = @_; 3704 my ($self) = @_;
3622 3705
3623 glTranslate 0.375, 0.375;
3624
3625 my ($w, $h) = @$self{qw(w h)}; 3706 my ($w, $h) = @$self{qw(w h)};
3626 3707
3627 glColor 1, 0.8, 0.4; 3708 glColor @{ $DC::THEME{tooltip_bg} };
3628 glRect 0, 0, $w, $h; 3709 glRect 0, 0, $w, $h;
3629 3710
3630 glColor 0, 0, 0; 3711 glColor @{ $DC::THEME{tooltip_border} };
3631 glRect_lineloop 0, 0, $w, $h; 3712 glRect_lineloop .5, .5, $w + .5, $h + .5;
3632 3713
3633 glTranslate 2 - 0.375, 2 - 0.375; 3714 glTranslate 2, 2;
3634 3715
3635 $self->SUPER::_draw; 3716 $self->SUPER::_draw;
3636} 3717}
3637 3718
3638############################################################################# 3719#############################################################################
3639 3720
3640package CFPlus::UI::Face; 3721package DC::UI::Face;
3641 3722
3642our @ISA = CFPlus::UI::DrawBG::; 3723our @ISA = DC::UI::DrawBG::;
3643 3724
3644use CFPlus::OpenGL; 3725use DC::OpenGL;
3645 3726
3646sub new { 3727sub new {
3647 my $class = shift; 3728 my $class = shift;
3648 3729
3649 my $self = $class->SUPER::new ( 3730 my $self = $class->SUPER::new (
3652 aspect => 1, 3733 aspect => 1,
3653 can_events => 0, 3734 can_events => 0,
3654 @_, 3735 @_,
3655 ); 3736 );
3656 3737
3657 if ($self->{anim} && $self->{animspeed}) {
3658 CFPlus::weaken (my $widget = $self);
3659
3660 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3661 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed};
3662 $self->{timer} = Event->timer (
3663 parked => 1,
3664 cb => sub {
3665 return unless $::CONN;
3666
3667 my $w = $widget
3668 or return;
3669
3670 ++$w->{frame};
3671 $w->update_face;
3672
3673 # somehow, $widget can go away
3674 $w->update;
3675 $w->update_timer;
3676 },
3677 );
3678
3679 $self->update_face;
3680 $self->update_timer; 3738 $self->update_anim;
3681 }
3682 3739
3683 $self 3740 $self
3684} 3741}
3685 3742
3686sub update_timer { 3743sub update_timer {
3687 my ($self) = @_; 3744 my ($self) = @_;
3688 3745
3689 return unless $self->{timer}; 3746 return unless $self->{timer};
3690 3747
3691 if ($self->{visible}) { 3748 if ($self->{visible}) {
3692 $self->{timer}->at (
3693 $self->{anim_start}
3694 + $self->{animspeed}
3695 * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed}
3696 );
3697 $self->{timer}->start; 3749 $self->{timer}->start;
3698 } else { 3750 } else {
3699 $self->{timer}->stop; 3751 $self->{timer}->stop;
3700 } 3752 }
3701} 3753}
3714 $tex->upload (sub { $self->reconfigure }); 3766 $tex->upload (sub { $self->reconfigure });
3715 } 3767 }
3716 } 3768 }
3717 } 3769 }
3718 } 3770 }
3771 }
3772}
3773
3774sub update_anim {
3775 my ($self) = @_;
3776
3777 if ($self->{anim} && $self->{animspeed}) {
3778 DC::weaken (my $widget = $self);
3779
3780 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed};
3781 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub {
3782 return unless $::CONN;
3783
3784 my $w = $widget
3785 or return;
3786
3787 ++$w->{frame};
3788 $w->update_face;
3789
3790 # somehow, $widget can go away
3791 $w->update;
3792 $w->update_timer;
3793 };
3794
3795 $self->update_face;
3796 $self->update_timer;
3797 } else {
3798 delete $self->{timer};
3719 } 3799 }
3720} 3800}
3721 3801
3722sub size_request { 3802sub size_request {
3723 my ($self) = @_; 3803 my ($self) = @_;
3745 return unless $self->{visible}; 3825 return unless $self->{visible};
3746 3826
3747 $self->SUPER::update; 3827 $self->SUPER::update;
3748} 3828}
3749 3829
3830sub set_face {
3831 my ($self, $face) = @_;
3832
3833 $self->{face} = $face;
3834 $self->reconfigure;
3835}
3836
3837sub set_anim {
3838 my ($self, $anim) = @_;
3839
3840 $self->{anim} = $anim;
3841 $self->update_anim;
3842}
3843
3844sub set_animspeed {
3845 my ($self, $animspeed) = @_;
3846
3847 $self->{animspeed} = $animspeed;
3848 $self->update_anim;
3849}
3850
3750sub invoke_visibility_change { 3851sub invoke_visibility_change {
3751 my ($self) = @_; 3852 my ($self) = @_;
3752 3853
3753 $self->update_timer; 3854 $self->update_timer;
3754 3855
3778 $self->SUPER::destroy; 3879 $self->SUPER::destroy;
3779} 3880}
3780 3881
3781############################################################################# 3882#############################################################################
3782 3883
3783package CFPlus::UI::Buttonbar; 3884package DC::UI::Buttonbar;
3784 3885
3785our @ISA = CFPlus::UI::HBox::; 3886our @ISA = DC::UI::HBox::;
3786 3887
3787# TODO: should actually wrap buttons and other goodies. 3888# TODO: should actually wrap buttons and other goodies.
3788 3889
3789############################################################################# 3890#############################################################################
3790 3891
3791package CFPlus::UI::Menu; 3892package DC::UI::Menu;
3792 3893
3793our @ISA = CFPlus::UI::Toplevel::; 3894our @ISA = DC::UI::Toplevel::;
3794 3895
3795use CFPlus::OpenGL; 3896use DC::OpenGL;
3796 3897
3797sub new { 3898sub new {
3798 my $class = shift; 3899 my $class = shift;
3799 3900
3800 my $self = $class->SUPER::new ( 3901 my $self = $class->SUPER::new (
3801 items => [], 3902 items => [],
3802 z => 100, 3903 z => 100,
3803 @_, 3904 @_,
3804 ); 3905 );
3805 3906
3806 $self->add ($self->{vbox} = new CFPlus::UI::VBox); 3907 $self->add ($self->{vbox} = new DC::UI::VBox);
3807 3908
3808 for my $item (@{ $self->{items} }) { 3909 for my $item (@{ $self->{items} }) {
3809 my ($widget, $cb, $tooltip) = @$item; 3910 my ($widget, $cb, $tooltip) = @$item;
3810 3911
3811 # handle various types of items, only text for now 3912 # handle various types of items, only text for now
3812 if (!ref $widget) { 3913 if (!ref $widget) {
3813 if ($widget =~ /\t/) { 3914 if ($widget =~ /\t/) {
3814 my ($left, $right) = split /\t/, $widget, 2; 3915 my ($left, $right) = split /\t/, $widget, 2;
3815 3916
3816 $widget = new CFPlus::UI::HBox 3917 $widget = new DC::UI::HBox
3817 can_hover => 1, 3918 can_hover => 1,
3818 can_events => 1, 3919 can_events => 1,
3819 tooltip => $tooltip, 3920 tooltip => $tooltip,
3820 children => [ 3921 children => [
3821 (new CFPlus::UI::Label markup => $left, expand => 1), 3922 (new DC::UI::Label markup => $left , align => 0, expand => 1),
3822 (new CFPlus::UI::Label markup => $right, align => +1), 3923 (new DC::UI::Label markup => $right, align => 1),
3823 ], 3924 ],
3824 ; 3925 ;
3825 3926
3826 } else { 3927 } else {
3827 $widget = new CFPlus::UI::Label 3928 $widget = new DC::UI::Label
3828 can_hover => 1, 3929 can_hover => 1,
3829 can_events => 1, 3930 can_events => 1,
3931 align => 0,
3830 markup => $widget, 3932 markup => $widget,
3831 tooltip => $tooltip; 3933 tooltip => $tooltip;
3832 } 3934 }
3833 } 3935 }
3834 3936
3849 # maybe save $GRAB? must be careful about events... 3951 # maybe save $GRAB? must be careful about events...
3850 $GRAB = $self; 3952 $GRAB = $self;
3851 $self->{button} = $ev->{button}; 3953 $self->{button} = $ev->{button};
3852 3954
3853 $self->show; 3955 $self->show;
3854 $self->move_abs ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); 3956
3957 my $x = $ev->{x};
3958 my $y = $ev->{y};
3959
3960 $self->{root}->on_post_alloc ($self => sub {
3961 $self->move_abs ($x - $self->{w} * 0.25, $y - $self->{border} * $::FONTSIZE * .5);
3962 });
3963
3964 1 # so it can be used inside event handlers
3855} 3965}
3856 3966
3857sub invoke_mouse_motion { 3967sub invoke_mouse_motion {
3858 my ($self, $ev, $x, $y) = @_; 3968 my ($self, $ev, $x, $y) = @_;
3859 3969
3880 1 3990 1
3881} 3991}
3882 3992
3883############################################################################# 3993#############################################################################
3884 3994
3885package CFPlus::UI::Multiplexer; 3995package DC::UI::Multiplexer;
3886 3996
3887our @ISA = CFPlus::UI::Container::; 3997our @ISA = DC::UI::Container::;
3888 3998
3889sub new { 3999sub new {
3890 my $class = shift; 4000 my $class = shift;
3891 4001
3892 my $self = $class->SUPER::new ( 4002 my $self = $class->SUPER::new (
3893 @_, 4003 @_,
3894 ); 4004 );
3895 4005
3896 $self->{current} = $self->{children}[0] 4006 $self->set_current_page (0);
3897 if @{ $self->{children} };
3898 4007
3899 $self 4008 $self
3900} 4009}
3901 4010
3902sub add { 4011sub add {
3903 my ($self, @widgets) = @_; 4012 my ($self, @widgets) = @_;
3904 4013
3905 $self->SUPER::add (@widgets); 4014 $self->SUPER::add (@widgets);
3906 4015
3907 $self->{current} = $self->{children}[0] 4016 $self->set_current_page (0)
3908 if @{ $self->{children} }; 4017 if @widgets == @{ $self->{children} };
3909} 4018}
3910 4019
3911sub get_current_page { 4020sub get_current_page {
3912 my ($self) = @_; 4021 my ($self) = @_;
3913 4022
3919 4028
3920 my $widget = ref $page_or_widget 4029 my $widget = ref $page_or_widget
3921 ? $page_or_widget 4030 ? $page_or_widget
3922 : $self->{children}[$page_or_widget]; 4031 : $self->{children}[$page_or_widget];
3923 4032
4033 $self->{current}->set_invisible if $self->{current} && $self->{visible};
4034
3924 $self->{current} = $widget; 4035 if (($self->{current} = $widget)) {
4036 $self->{current}->set_visible if $self->{current} && $self->{visible};
3925 $self->{current}->configure (0, 0, $self->{w}, $self->{h}); 4037 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
3926 4038
3927 $self->emit (page_changed => $self->{current}); 4039 $self->emit (page_changed => $self->{current});
4040 }
3928 4041
3929 $self->realloc; 4042 $self->realloc;
3930} 4043}
3931 4044
3932sub visible_children { 4045sub visible_children {
3933 $_[0]{current} 4046 $_[0]{current} || ()
3934} 4047}
3935 4048
3936sub size_request { 4049sub size_request {
3937 my ($self) = @_; 4050 my ($self) = @_;
3938 4051
4052 $self->{current}
3939 $self->{current}->size_request 4053 ? $self->{current}->size_request
4054 : (0, 0)
3940} 4055}
3941 4056
3942sub invoke_size_allocate { 4057sub invoke_size_allocate {
3943 my ($self, $w, $h) = @_; 4058 my ($self, $w, $h) = @_;
3944 4059
3945 $self->{current}->configure (0, 0, $w, $h); 4060 $self->{current}->configure (0, 0, $w, $h)
4061 if $self->{current};
3946 4062
3947 1 4063 1
3948} 4064}
3949 4065
3950sub _draw { 4066sub _draw {
3951 my ($self) = @_; 4067 my ($self) = @_;
3952 4068
3953 $self->{current}->draw; 4069 $self->{current}->draw
4070 if $self->{current};
3954} 4071}
3955 4072
3956############################################################################# 4073#############################################################################
3957 4074
3958package CFPlus::UI::Notebook; 4075package DC::UI::Notebook;
3959 4076
3960use CFPlus::OpenGL; 4077use DC::OpenGL;
3961 4078
3962our @ISA = CFPlus::UI::VBox::; 4079our @ISA = DC::UI::VBox::;
3963 4080
3964sub new { 4081sub new {
3965 my $class = shift; 4082 my $class = shift;
3966 4083
3967 my $self = $class->SUPER::new ( 4084 my $self = $class->SUPER::new (
3968 buttonbar => (new CFPlus::UI::Buttonbar), 4085 buttonbar => (new DC::UI::Buttonbar),
3969 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 4086 multiplexer => (new DC::UI::Multiplexer expand => 1),
3970 active_outline => [1, 1, 0], 4087 active_outline => [.7, .7, 0.2],
3971 # filter => # will be put between multiplexer and $self 4088 # filter => # will be put between multiplexer and $self
3972 @_, 4089 @_,
3973 ); 4090 );
3974 4091
3975 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 4092 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3983 4100
3984 for my $child (@$widgets) { 4101 for my $child (@$widgets) {
3985 Scalar::Util::weaken $child; 4102 Scalar::Util::weaken $child;
3986 $child->{c_tab_} ||= do { 4103 $child->{c_tab_} ||= do {
3987 my $tab = 4104 my $tab =
3988 (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") 4105 (UNIVERSAL::isa $child->{c_tab}, "DC::UI::Base")
3989 ? $child->{c_tab} 4106 ? $child->{c_tab}
3990 : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; 4107 : new DC::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1];
3991 4108
3992 $tab->connect (activate => sub { 4109 $tab->connect (activate => sub {
3993 $wself->set_current_page ($child); 4110 $wself->set_current_page ($child);
3994 }); 4111 });
3995 4112
4027sub pages { 4144sub pages {
4028 my ($self) = @_; 4145 my ($self) = @_;
4029 $self->{multiplexer}->children 4146 $self->{multiplexer}->children
4030} 4147}
4031 4148
4149sub page_index {
4150 my ($self, $widget) = @_;
4151
4152 my $i = 0;
4153 for ($self->pages) {
4154 if ($_ eq $widget) { return $i };
4155 $i++;
4156 }
4157
4158 undef
4159}
4160
4032sub add_tab { 4161sub add_tab {
4033 my ($self, $title, $widget, $tooltip) = @_; 4162 my ($self, $title, $widget, $tooltip) = @_;
4034 4163
4035 $title = [$title, $tooltip] unless ref $title; 4164 $title = [$title, $tooltip] unless ref $title;
4036 $widget->{c_tab} = $title; 4165 $widget->{c_tab} = $title;
4056 4185
4057 $self->SUPER::_draw (); 4186 $self->SUPER::_draw ();
4058 4187
4059 if (my $cur = $self->{multiplexer}{current}) { 4188 if (my $cur = $self->{multiplexer}{current}) {
4060 if ($cur = $cur->{c_tab_}) { 4189 if ($cur = $cur->{c_tab_}) {
4061 glTranslate $cur->{x}, $cur->{y}; 4190 glTranslate $self->{buttonbar}{x} + $cur->{x},
4191 $self->{buttonbar}{y} + $cur->{y};
4062 glLineWidth 3; 4192 glLineWidth 3;
4193 #glEnable GL_BLEND;
4194 #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
4063 glColor @{$self->{active_outline}}; 4195 glColor @{$self->{active_outline}};
4064 glRect_lineloop 1, 1, $cur->{w} - 2, $cur->{h} - 2; 4196 glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5;
4065 glLineWidth 1; 4197 glLineWidth 1;
4198 #glDisable GL_BLEND;
4066 } 4199 }
4067 } 4200 }
4068} 4201}
4069 4202
4070############################################################################# 4203#############################################################################
4071 4204
4072package CFPlus::UI::Selector; 4205package DC::UI::Selector;
4073 4206
4074use utf8; 4207use utf8;
4075 4208
4076our @ISA = CFPlus::UI::Button::; 4209our @ISA = DC::UI::Button::;
4077 4210
4078sub new { 4211sub new {
4079 my $class = shift; 4212 my $class = shift;
4080 4213
4081 my $self = $class->SUPER::new ( 4214 my $self = $class->SUPER::new (
4098 my ($value, $title, $tooltip) = @$_; 4231 my ($value, $title, $tooltip) = @$_;
4099 4232
4100 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 4233 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
4101 } 4234 }
4102 4235
4103 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); 4236 DC::UI::Menu->new (items => \@menu_items)->popup ($ev);
4104} 4237}
4105 4238
4106sub _set_value { 4239sub _set_value {
4107 my ($self, $value) = @_; 4240 my ($self, $value) = @_;
4108 4241
4109 my ($item) = grep $_->[0] eq $value, @{ $self->{options} } 4242 my ($item) = grep $_->[0] eq $value, @{ $self->{options} };
4243 $item ||= $self->{options}[0]
4110 or return; 4244 or return;
4111 4245
4112 $self->{value} = $item->[0]; 4246 $self->{value} = $item->[0];
4113 $self->set_markup ("$item->[1] ⇓"); 4247 $self->set_markup ("$item->[1] ⇓");
4114 $self->set_tooltip ($item->[2]); 4248# $self->set_tooltip ($item->[2]);
4115} 4249}
4116 4250
4117sub set_value { 4251sub set_value {
4118 my ($self, $value) = @_; 4252 my ($self, $value) = @_;
4119 4253
4121 4255
4122 $self->_set_value ($value); 4256 $self->_set_value ($value);
4123 $self->emit (changed => $value); 4257 $self->emit (changed => $value);
4124} 4258}
4125 4259
4260sub set_options {
4261 my ($self, $options) = @_;
4262
4263 $self->{options} = $options;
4264 $self->_set_value ($self->{value});
4265}
4266
4126############################################################################# 4267#############################################################################
4127 4268
4128package CFPlus::UI::Statusbox; 4269package DC::UI::Statusbox;
4129 4270
4130our @ISA = CFPlus::UI::VBox::; 4271our @ISA = DC::UI::VBox::;
4131 4272
4132sub new { 4273sub new {
4133 my $class = shift; 4274 my $class = shift;
4134 4275
4135 my $self = $class->SUPER::new ( 4276 my $self = $class->SUPER::new (
4136 fontsize => 0.8, 4277 fontsize => 0.8,
4137 @_, 4278 @_,
4138 ); 4279 );
4139 4280
4140 CFPlus::weaken (my $this = $self); 4281 DC::weaken (my $this = $self);
4141 4282
4142 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 4283 $self->{timer} = EV::timer 1, 1, sub { $this->reorder };
4143 4284
4144 $self 4285 $self
4145} 4286}
4146 4287
4147sub reorder { 4288sub reorder {
4148 my ($self) = @_; 4289 my ($self) = @_;
4149 my $NOW = Time::HiRes::time; 4290 my $NOW = EV::time;
4150 4291
4151 # freeze display when hovering over any label 4292 # freeze display when hovering over any label
4152 return if $CFPlus::UI::TOOLTIP->{owner} 4293 return if $DC::UI::TOOLTIP->{owner}
4153 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label}, 4294 && grep $DC::UI::TOOLTIP->{owner} == $_->{label},
4154 values %{ $self->{item} }; 4295 values %{ $self->{item} };
4155 4296
4156 while (my ($k, $v) = each %{ $self->{item} }) { 4297 while (my ($k, $v) = each %{ $self->{item} }) {
4157 delete $self->{item}{$k} if $v->{timeout} < $NOW; 4298 delete $self->{item}{$k} if $v->{timeout} < $NOW;
4158 } 4299 }
4300
4301 $self->{timer}->set (1, 1);
4159 4302
4160 my @widgets; 4303 my @widgets;
4161 4304
4162 my @items = sort { 4305 my @items = sort {
4163 $a->{pri} <=> $b->{pri} 4306 $a->{pri} <=> $b->{pri}
4164 or $b->{id} <=> $a->{id} 4307 or $b->{id} <=> $a->{id}
4165 } values %{ $self->{item} }; 4308 } values %{ $self->{item} };
4166
4167 $self->{timer}->interval (1);
4168 4309
4169 my $count = 10 + 1; 4310 my $count = 10 + 1;
4170 for my $item (@items) { 4311 for my $item (@items) {
4171 last unless --$count; 4312 last unless --$count;
4172 4313
4179 for ($short) { 4320 for ($short) {
4180 s/^\s+//; 4321 s/^\s+//;
4181 s/\s+/ /g; 4322 s/\s+/ /g;
4182 } 4323 }
4183 4324
4184 new CFPlus::UI::Label 4325 new DC::UI::Label
4185 markup => $short, 4326 markup => $short,
4186 tooltip => $item->{tooltip}, 4327 tooltip => $item->{tooltip},
4187 tooltip_font => $::FONT_PROP, 4328 tooltip_font => $::FONT_PROP,
4188 tooltip_width => 0.67, 4329 tooltip_width => 0.67,
4189 fontsize => $item->{fontsize} || $self->{fontsize}, 4330 fontsize => $item->{fontsize} || $self->{fontsize},
4190 max_w => $::WIDTH * 0.44, 4331 max_w => $::WIDTH * 0.44,
4332 align => 0,
4191 fg => [@{ $item->{fg} }], 4333 fg => [@{ $item->{fg} }],
4192 can_events => 1, 4334 can_events => 1,
4193 can_hover => 1 4335 can_hover => 1
4194 }; 4336 };
4195 4337
4196 if ((my $diff = $item->{timeout} - $NOW) < 2) { 4338 if ((my $diff = $item->{timeout} - $NOW) < 2) {
4197 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; 4339 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2;
4198 $label->update; 4340 $label->update;
4199 $label->set_max_size (undef, $label->{req_h} * $diff) 4341 $label->set_max_size (undef, $label->{req_h} * $diff)
4200 if $diff < 1; 4342 if $diff < 1;
4201 $self->{timer}->interval (1/30); 4343 $self->{timer}->set (1/30, 1/30);
4202 } else { 4344 } else {
4203 $label->{fg}[3] = $item->{fg}[3] || 1; 4345 $label->{fg}[3] = $item->{fg}[3] || 1;
4204 } 4346 }
4205 4347
4206 push @widgets, $label; 4348 push @widgets, $label;
4207 } 4349 }
4350
4351 my $hash = join ",", @widgets;
4352 return if $hash eq $self->{last_widget_hash};
4353 $self->{last_widget_hash} = $hash;
4208 4354
4209 $self->clear; 4355 $self->clear;
4210 $self->SUPER::add (reverse @widgets); 4356 $self->SUPER::add (reverse @widgets);
4211} 4357}
4212 4358
4268 $self->SUPER::destroy; 4414 $self->SUPER::destroy;
4269} 4415}
4270 4416
4271############################################################################# 4417#############################################################################
4272 4418
4273package CFPlus::UI::Root; 4419package DC::UI::Root;
4274 4420
4275our @ISA = CFPlus::UI::Container::; 4421our @ISA = DC::UI::Container::;
4276 4422
4277use List::Util qw(min max); 4423use List::Util qw(min max);
4278 4424
4279use CFPlus::OpenGL; 4425use DC::OpenGL;
4280 4426
4281sub new { 4427sub new {
4282 my $class = shift; 4428 my $class = shift;
4283 4429
4284 my $self = $class->SUPER::new ( 4430 my $self = $class->SUPER::new (
4285 visible => 1, 4431 visible => 1,
4286 @_, 4432 @_,
4287 ); 4433 );
4288 4434
4289 CFPlus::weaken ($self->{root} = $self); 4435 DC::weaken ($self->{root} = $self);
4290 4436
4291 $self 4437 $self
4292} 4438}
4293 4439
4294sub size_request { 4440sub size_request {
4342} 4488}
4343 4489
4344sub update { 4490sub update {
4345 my ($self) = @_; 4491 my ($self) = @_;
4346 4492
4347 $::WANT_REFRESH->start; 4493 $::WANT_REFRESH = 1;
4348} 4494}
4349 4495
4350sub add { 4496sub add {
4351 my ($self, @children) = @_; 4497 my ($self, @children) = @_;
4352 4498
4419 4565
4420 delete $queue{$widget+0}; 4566 delete $queue{$widget+0};
4421 4567
4422 my ($w, $h) = $widget->size_request; 4568 my ($w, $h) = $widget->size_request;
4423 4569
4424 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; 4570 $w += $widget->{padding_x} * 2;
4425 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; 4571 $h += $widget->{padding_y} * 2;
4572
4573 $w = max $widget->{min_w}, $w;
4574 $h = max $widget->{min_h}, $h;
4426 4575
4427 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4576 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4428 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4577 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4429 4578
4430 $w = $widget->{force_w} if exists $widget->{force_w}; 4579 $w = $widget->{force_w} if exists $widget->{force_w};
4497 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 4646 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
4498 glMatrixMode GL_MODELVIEW; 4647 glMatrixMode GL_MODELVIEW;
4499 glLoadIdentity; 4648 glLoadIdentity;
4500 4649
4501 { 4650 {
4502 package CFPlus::UI::Base; 4651 package DC::UI::Base;
4503 4652
4504 local ($draw_x, $draw_y, $draw_w, $draw_h) = 4653 local ($draw_x, $draw_y, $draw_w, $draw_h) =
4505 (0, 0, $self->{w}, $self->{h}); 4654 (0, 0, $self->{w}, $self->{h});
4506 4655
4507 $self->_draw; 4656 $self->_draw;
4508 } 4657 }
4509} 4658}
4510 4659
4511############################################################################# 4660#############################################################################
4512 4661
4513package CFPlus::UI; 4662package DC::UI;
4514 4663
4515$ROOT = new CFPlus::UI::Root; 4664$ROOT = new DC::UI::Root;
4516$TOOLTIP = new CFPlus::UI::Tooltip z => 900; 4665$TOOLTIP = new DC::UI::Tooltip z => 900;
4517 4666
45181 46671
4519

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines