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.476 by root, Sun Jan 11 23:45:52 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 (
649 } 676 }
650} 677}
651 678
652############################################################################# 679#############################################################################
653 680
654package CFPlus::UI::Empty; 681package DC::UI::Empty;
655 682
656our @ISA = CFPlus::UI::Base::; 683our @ISA = DC::UI::Base::;
657 684
658sub new { 685sub new {
659 my ($class, %arg) = @_; 686 my ($class, %arg) = @_;
660 $class->SUPER::new (can_events => 0, %arg); 687 $class->SUPER::new (can_events => 0, %arg);
661} 688}
668 695
669sub draw { } 696sub draw { }
670 697
671############################################################################# 698#############################################################################
672 699
673package CFPlus::UI::Container; 700package DC::UI::Container;
674 701
675our @ISA = CFPlus::UI::Base::; 702our @ISA = DC::UI::Base::;
676 703
677sub new { 704sub new {
678 my ($class, %arg) = @_; 705 my ($class, %arg) = @_;
679 706
680 my $children = delete $arg{children}; 707 my $children = delete $arg{children};
774 $_->draw for $self->visible_children; 801 $_->draw for $self->visible_children;
775} 802}
776 803
777############################################################################# 804#############################################################################
778 805
779package CFPlus::UI::Bin; 806package DC::UI::Bin;
780 807
781our @ISA = CFPlus::UI::Container::; 808our @ISA = DC::UI::Container::;
782 809
783sub new { 810sub new {
784 my ($class, %arg) = @_; 811 my ($class, %arg) = @_;
785 812
786 my $child = (delete $arg{child}) || new CFPlus::UI::Empty::; 813 my $child = (delete $arg{child}) || new DC::UI::Empty::;
787 814
788 $class->SUPER::new (children => [$child], %arg) 815 $class->SUPER::new (children => [$child], %arg)
789} 816}
790 817
791sub add { 818sub add {
798sub remove { 825sub remove {
799 my ($self, $widget) = @_; 826 my ($self, $widget) = @_;
800 827
801 $self->SUPER::remove ($widget); 828 $self->SUPER::remove ($widget);
802 829
803 $self->{children} = [new CFPlus::UI::Empty] 830 $self->{children} = [new DC::UI::Empty]
804 unless @{$self->{children}}; 831 unless @{$self->{children}};
805} 832}
806 833
807sub child { $_[0]->{children}[0] } 834sub child { $_[0]->{children}[0] }
808 835
817 844
818 1 845 1
819} 846}
820 847
821############################################################################# 848#############################################################################
822
823# back-buffered drawing area 849# back-buffered drawing area
824 850
825package CFPlus::UI::Window; 851package DC::UI::Window;
826 852
827our @ISA = CFPlus::UI::Bin::; 853our @ISA = DC::UI::Bin::;
828 854
829use CFPlus::OpenGL; 855use DC::OpenGL;
830 856
831sub new { 857sub new {
832 my ($class, %arg) = @_; 858 my ($class, %arg) = @_;
833 859
834 my $self = $class->SUPER::new (%arg); 860 my $self = $class->SUPER::new (%arg);
856} 882}
857 883
858sub render_child { 884sub render_child {
859 my ($self) = @_; 885 my ($self) = @_;
860 886
861 $self->{texture} = new_from_opengl CFPlus::Texture $self->{w}, $self->{h}, sub { 887 $self->{texture} = new_from_opengl DC::Texture $self->{w}, $self->{h}, sub {
862 glClearColor 0, 0, 0, 0; 888 glClearColor 0, 0, 0, 0;
863 glClear GL_COLOR_BUFFER_BIT; 889 glClear GL_COLOR_BUFFER_BIT;
864 890
865 { 891 {
866 package CFPlus::UI::Base; 892 package DC::UI::Base;
867 893
868 local ($draw_x, $draw_y, $draw_w, $draw_h) = 894 local ($draw_x, $draw_y, $draw_w, $draw_h) =
869 (0, 0, $self->{w}, $self->{h}); 895 (0, 0, $self->{w}, $self->{h});
870 896
871 $self->_render; 897 $self->_render;
888 glDisable GL_TEXTURE_2D; 914 glDisable GL_TEXTURE_2D;
889} 915}
890 916
891############################################################################# 917#############################################################################
892 918
893package CFPlus::UI::ViewPort; 919package DC::UI::ViewPort;
894 920
895use List::Util qw(min max); 921use List::Util qw(min max);
896 922
897our @ISA = CFPlus::UI::Window::; 923our @ISA = DC::UI::Window::;
898 924
899sub new { 925sub new {
900 my $class = shift; 926 my $class = shift;
901 927
902 $class->SUPER::new ( 928 $class->SUPER::new (
986 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 1012 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
987 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1013 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
988 ) { 1014 ) {
989 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) 1015 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
990 } else { 1016 } else {
991 $self->CFPlus::UI::Base::find_widget ($x, $y) 1017 $self->DC::UI::Base::find_widget ($x, $y)
992 } 1018 }
993} 1019}
994 1020
995sub _render { 1021sub _render {
996 my ($self) = @_; 1022 my ($self) = @_;
997 1023
998 local $CFPlus::UI::Base::draw_x = $CFPlus::UI::Base::draw_x - $self->{view_x}; 1024 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}; 1025 local $DC::UI::Base::draw_y = $DC::UI::Base::draw_y - $self->{view_y};
1000 1026
1001 CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 1027 DC::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
1002 1028
1003 $self->SUPER::_render; 1029 $self->SUPER::_render;
1004} 1030}
1005 1031
1006############################################################################# 1032#############################################################################
1007 1033
1008package CFPlus::UI::ScrolledWindow; 1034package DC::UI::ScrolledWindow;
1009 1035
1010our @ISA = CFPlus::UI::Table::; 1036our @ISA = DC::UI::Table::;
1011 1037
1012sub new { 1038sub new {
1013 my ($class, %arg) = @_; 1039 my ($class, %arg) = @_;
1014 1040
1015 my $child = delete $arg{child}; 1041 my $child = delete $arg{child};
1016 1042
1017 my $self; 1043 my $self;
1018 1044
1019 my $hslider = new CFPlus::UI::Slider 1045 my $hslider = new DC::UI::Slider
1020 c_col => 0, 1046 c_col => 0,
1021 c_row => 1, 1047 c_row => 1,
1022 vertical => 0, 1048 vertical => 0,
1023 range => [0, 0, 1, 0.01], # HACK fix 1049 range => [0, 0, 1, 0.01], # HACK fix
1024 on_changed => sub { 1050 on_changed => sub {
1025 $self->{hpos} = $_[1]; 1051 $self->{hpos} = $_[1];
1026 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1052 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1027 }, 1053 },
1028 ; 1054 ;
1029 1055
1030 my $vslider = new CFPlus::UI::Slider 1056 my $vslider = new DC::UI::Slider
1031 c_col => 1, 1057 c_col => 1,
1032 c_row => 0, 1058 c_row => 0,
1033 vertical => 1, 1059 vertical => 1,
1034 range => [0, 0, 1, 0.01], # HACK fix 1060 range => [0, 0, 1, 0.01], # HACK fix
1035 on_changed => sub { 1061 on_changed => sub {
1047 col_expand => [1, 0], 1073 col_expand => [1, 0],
1048 row_expand => [1, 0], 1074 row_expand => [1, 0],
1049 %arg, 1075 %arg,
1050 ); 1076 );
1051 1077
1052 $self->{vp} = new CFPlus::UI::ViewPort 1078 $self->{vp} = new DC::UI::ViewPort
1053 c_col => 0, 1079 c_col => 0,
1054 c_row => 0, 1080 c_row => 0,
1055 expand => 1, 1081 expand => 1,
1056 scroll_x => $self->{scroll_x}, 1082 scroll_x => $self->{scroll_x},
1057 scroll_y => $self->{scroll_y}, 1083 scroll_y => $self->{scroll_y},
1183 $self->SUPER::invoke_size_allocate ($w, $h) 1209 $self->SUPER::invoke_size_allocate ($w, $h)
1184} 1210}
1185 1211
1186############################################################################# 1212#############################################################################
1187 1213
1188package CFPlus::UI::Frame; 1214package DC::UI::Frame;
1189 1215
1190our @ISA = CFPlus::UI::Bin::; 1216our @ISA = DC::UI::Bin::;
1191 1217
1192use CFPlus::OpenGL; 1218use DC::OpenGL;
1193 1219
1194sub new { 1220sub new {
1195 my $class = shift; 1221 my $class = shift;
1196 1222
1197 $class->SUPER::new ( 1223 $class->SUPER::new (
1216 $self->SUPER::_draw; 1242 $self->SUPER::_draw;
1217} 1243}
1218 1244
1219############################################################################# 1245#############################################################################
1220 1246
1221package CFPlus::UI::FancyFrame; 1247package DC::UI::FancyFrame;
1222 1248
1223our @ISA = CFPlus::UI::Bin::; 1249our @ISA = DC::UI::Bin::;
1224 1250
1225use CFPlus::OpenGL; 1251use DC::OpenGL;
1226 1252
1227sub new { 1253sub new {
1228 my ($class, %arg) = @_; 1254 my ($class, %arg) = @_;
1229 1255
1230 if ((exists $arg{label}) && !ref $arg{label}) { 1256 if ((exists $arg{label}) && !ref $arg{label}) {
1231 $arg{label} = new CFPlus::UI::Label 1257 $arg{label} = new DC::UI::Label
1232 align => 1, 1258 align => 1,
1233 valign => 0, 1259 valign => 0.5,
1234 text => $arg{label}, 1260 text => $arg{label},
1235 fontsize => ($arg{border} || 0.8) * 0.75; 1261 fontsize => ($arg{border} || 0.8) * 0.75;
1236 } 1262 }
1237 1263
1238 my $self = $class->SUPER::new ( 1264 my $self = $class->SUPER::new (
1239 # label => "", 1265 # label => "",
1240 fg => [0.6, 0.3, 0.1], 1266 fg => undef,
1241 border => 0.8, 1267 border => 0.8,
1242 style => 'single', 1268 style => 'single',
1243 %arg, 1269 %arg,
1244 ); 1270 );
1245 1271
1248 1274
1249sub add { 1275sub add {
1250 my ($self, @widgets) = @_; 1276 my ($self, @widgets) = @_;
1251 1277
1252 $self->SUPER::add (@widgets); 1278 $self->SUPER::add (@widgets);
1253 $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label}; 1279 $self->DC::UI::Container::add ($self->{label}) if $self->{label};
1254} 1280}
1255 1281
1256sub border { 1282sub border {
1257 int $_[0]{border} * $::FONTSIZE 1283 int $_[0]{border} * $::FONTSIZE
1258} 1284}
1298 my $border = $self->border; 1324 my $border = $self->border;
1299 my ($w, $h) = ($self->{w}, $self->{h}); 1325 my ($w, $h) = ($self->{w}, $self->{h});
1300 1326
1301 $child->draw; 1327 $child->draw;
1302 1328
1303 glColor @{$self->{fg}}; 1329 glColor @{$self->{fg} || $DC::THEME{fancyframe}};
1304 glBegin GL_LINE_STRIP; 1330 glBegin GL_LINE_STRIP;
1305 glVertex $border * 1.5 , $border * 0.5 + 0.5; 1331 glVertex $border * 1.5 , $border * 0.5 + 0.5;
1306 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; 1332 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5;
1307 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; 1333 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; 1334 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1316 } 1342 }
1317} 1343}
1318 1344
1319############################################################################# 1345#############################################################################
1320 1346
1321package CFPlus::UI::Toplevel; 1347package DC::UI::Toplevel;
1322 1348
1323our @ISA = CFPlus::UI::Bin::; 1349our @ISA = DC::UI::Bin::;
1324 1350
1325use CFPlus::OpenGL; 1351use DC::OpenGL;
1326 1352
1327my $bg = 1353my $bg =
1328 new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", 1354 new_from_resource DC::Texture "d1_bg.png",
1329 mipmap => 1, wrap => 1; 1355 mipmap => 1, wrap => 1;
1330 1356
1331my @border = 1357my @border =
1332 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1358 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); 1359 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1334 1360
1335my @icon = 1361my @icon =
1336 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1362 map { new_from_resource DC::Texture $_, mipmap => 1 }
1337 qw(x1_move.png x1_resize.png); 1363 qw(x1_move.png x1_resize.png);
1338 1364
1339sub new { 1365sub new {
1340 my ($class, %arg) = @_; 1366 my ($class, %arg) = @_;
1341 1367
1342 my $self = $class->SUPER::new ( 1368 my $self = $class->SUPER::new (
1343 bg => [1, 1, 1, 1], 1369 bg => [1, 1, 1, 1],
1344 border_bg => [1, 1, 1, 1], 1370 border_bg => [1, 1, 1, 1],
1345 border => 0.6, 1371 border => 0.8,
1346 can_events => 1, 1372 can_events => 1,
1347 min_w => 64, 1373 min_w => 64,
1348 min_h => 32, 1374 min_h => 32,
1349 %arg, 1375 %arg,
1350 ); 1376 );
1351 1377
1352 $self->{title_widget} = new CFPlus::UI::Label 1378 $self->{title_widget} = new DC::UI::Label
1353 align => 0, 1379 align => 0.5,
1354 valign => 1, 1380 valign => 1,
1355 text => $self->{title}, 1381 text => $self->{title},
1356 fontsize => $self->{border}, 1382 fontsize => $self->{border},
1357 if exists $self->{title}; 1383 if exists $self->{title};
1358 1384
1359 if ($self->{has_close_button}) { 1385 if ($self->{has_close_button}) {
1360 $self->{close_button} = 1386 $self->{close_button} =
1361 new CFPlus::UI::ImageButton 1387 new DC::UI::ImageButton
1362 path => 'x1_close.png', 1388 path => 'x1_close.png',
1363 on_activate => sub { $self->emit ("delete") }; 1389 on_activate => sub { $self->emit ("delete") };
1364 1390
1365 $self->CFPlus::UI::Container::add ($self->{close_button}); 1391 $self->DC::UI::Container::add ($self->{close_button});
1366 } 1392 }
1367 1393
1368 $self 1394 $self
1369} 1395}
1370 1396
1371sub add { 1397sub add {
1372 my ($self, @widgets) = @_; 1398 my ($self, @widgets) = @_;
1373 1399
1374 $self->SUPER::add (@widgets); 1400 $self->SUPER::add (@widgets);
1375 $self->CFPlus::UI::Container::add ($self->{close_button}) if $self->{close_button}; 1401 $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}; 1402 $self->DC::UI::Container::add ($self->{title_widget}) if $self->{title_widget};
1377} 1403}
1378 1404
1379sub border { 1405sub border {
1380 int $_[0]{border} * $::FONTSIZE 1406 int $_[0]{border} * $::FONTSIZE
1407}
1408
1409sub get_max_wh {
1410 my ($self) = @_;
1411
1412 return ($self->{w}, $self->{h})
1413 if $self->{visible} && $self->{w};
1414
1415 $self->SUPER::get_max_wh
1381} 1416}
1382 1417
1383sub size_request { 1418sub size_request {
1384 my ($self) = @_; 1419 my ($self) = @_;
1385 1420
1510 glEnable GL_TEXTURE_2D; 1545 glEnable GL_TEXTURE_2D;
1511 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1546 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1512 1547
1513 my $border = $self->border; 1548 my $border = $self->border;
1514 1549
1550 if ($border) {
1515 glColor @{ $self->{border_bg} }; 1551 glColor @{ $self->{border_bg} };
1516 $border[0]->draw_quad_alpha ( 0, 0, $w, $border); 1552 $border[0]->draw_quad_alpha ( 0, 0, $w, $border);
1517 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); 1553 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch);
1518 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); 1554 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
1519 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); 1555 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border);
1520 1556
1521 # move 1557 # move
1522 my $w2 = ($w - $border) * .5; 1558 my $w2 = ($w - $border) * .5;
1523 my $h2 = ($h - $border) * .5; 1559 my $h2 = ($h - $border) * .5;
1524 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); 1560 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border);
1525 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); 1561 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border);
1526 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); 1562 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border);
1527 1563
1528 # resize 1564 # resize
1529 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); 1565 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border);
1530 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) 1566 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border)
1531 unless $self->{has_close_button}; 1567 unless $self->{has_close_button};
1532 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); 1568 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border);
1533 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); 1569 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border);
1570 }
1534 1571
1535 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 1572 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
1536 glColor @{ $self->{bg} }; 1573 glColor @{ $self->{bg} };
1537 1574
1538 # TODO: repeat texture not scale 1575 # TODO: repeat texture not scale
1557 if $self->{close_button}; 1594 if $self->{close_button};
1558} 1595}
1559 1596
1560############################################################################# 1597#############################################################################
1561 1598
1562package CFPlus::UI::Table; 1599package DC::UI::Table;
1563 1600
1564our @ISA = CFPlus::UI::Container::; 1601our @ISA = DC::UI::Container::;
1565 1602
1566use List::Util qw(max sum); 1603use List::Util qw(max sum);
1567 1604
1568use CFPlus::OpenGL; 1605use DC::OpenGL;
1569 1606
1570sub new { 1607sub new {
1571 my $class = shift; 1608 my $class = shift;
1572 1609
1573 $class->SUPER::new ( 1610 $class->SUPER::new (
1617 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; 1654 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)};
1618 1655
1619 my $sw = sum @w[$c .. $c + $cs - 1]; 1656 my $sw = sum @w[$c .. $c + $cs - 1];
1620 1657
1621 if ($w > $sw) { 1658 if ($w > $sw) {
1622 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; 1659 $_ += ($w - $sw) / ($_ ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1];
1623 } 1660 }
1624 } 1661 }
1625 1662
1626 # second pass, rows 1663 # second pass, rows
1627 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { 1664 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) {
1628 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; 1665 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)};
1629 1666
1630 my $sh = sum @h[$r .. $r + $rs - 1]; 1667 my $sh = sum @h[$r .. $r + $rs - 1];
1631 1668
1632 if ($h > $sh) { 1669 if ($h > $sh) {
1633 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; 1670 $_ += ($h - $sh) / ($_ ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1];
1634 } 1671 }
1635 } 1672 }
1636 1673
1637 (\@w, \@h) 1674 (\@w, \@h)
1638} 1675}
1661 @col_expand = (1) x @$ws unless @col_expand; 1698 @col_expand = (1) x @$ws unless @col_expand;
1662 my $col_expand = (sum @col_expand) || 1; 1699 my $col_expand = (sum @col_expand) || 1;
1663 1700
1664 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1701 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1665 1702
1666 CFPlus::UI::harmonize $ws; 1703 DC::UI::harmonize $ws;
1667 1704
1668 my @row_expand = @{$self->{row_expand}}; 1705 my @row_expand = @{$self->{row_expand}};
1669 @row_expand = (1) x @$ws unless @row_expand; 1706 @row_expand = (1) x @$ws unless @row_expand;
1670 my $row_expand = (sum @row_expand) || 1; 1707 my $row_expand = (sum @row_expand) || 1;
1671 1708
1672 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; 1709 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1673 1710
1674 CFPlus::UI::harmonize $hs; 1711 DC::UI::harmonize $hs;
1675 1712
1676 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } 1713 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] }
1677 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } 1714 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] }
1678 1715
1679 for my $widget ($self->children) { 1716 for my $widget ($self->children) {
1688 1 1725 1
1689} 1726}
1690 1727
1691############################################################################# 1728#############################################################################
1692 1729
1693package CFPlus::UI::Fixed; 1730package DC::UI::Fixed;
1694 1731
1695use List::Util qw(min max); 1732use List::Util qw(min max);
1696 1733
1697our @ISA = CFPlus::UI::Container::; 1734our @ISA = DC::UI::Container::;
1698 1735
1699sub _scale($$$) { 1736sub _scale($$$) {
1700 my ($rel, $val, $max) = @_; 1737 my ($rel, $val, $max) = @_;
1701 1738
1702 $rel ? $val * $max : $val 1739 $rel ? $val * $max : $val
1754 1 1791 1
1755} 1792}
1756 1793
1757############################################################################# 1794#############################################################################
1758 1795
1759package CFPlus::UI::Box; 1796package DC::UI::Box;
1760 1797
1761our @ISA = CFPlus::UI::Container::; 1798our @ISA = DC::UI::Container::;
1762 1799
1763sub size_request { 1800sub size_request {
1764 my ($self) = @_; 1801 my ($self) = @_;
1765 1802
1766 my @children = $self->visible_children; 1803 my @children = $self->visible_children;
1801 $req[$_] += $space * $children[$_]{expand} 1838 $req[$_] += $space * $children[$_]{expand}
1802 for 0 .. $#children; 1839 for 0 .. $#children;
1803 } 1840 }
1804 } 1841 }
1805 1842
1806 CFPlus::UI::harmonize \@req; 1843 DC::UI::harmonize \@req;
1807 1844
1808 my $pos = 0; 1845 my $pos = 0;
1809 for (0 .. $#children) { 1846 for (0 .. $#children) {
1810 my $alloc = $req[$_]; 1847 my $alloc = $req[$_];
1811 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); 1848 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h));
1816 1 1853 1
1817} 1854}
1818 1855
1819############################################################################# 1856#############################################################################
1820 1857
1821package CFPlus::UI::HBox; 1858package DC::UI::HBox;
1822 1859
1823our @ISA = CFPlus::UI::Box::; 1860our @ISA = DC::UI::Box::;
1824 1861
1825sub new { 1862sub new {
1826 my $class = shift; 1863 my $class = shift;
1827 1864
1828 $class->SUPER::new ( 1865 $class->SUPER::new (
1831 ) 1868 )
1832} 1869}
1833 1870
1834############################################################################# 1871#############################################################################
1835 1872
1836package CFPlus::UI::VBox; 1873package DC::UI::VBox;
1837 1874
1838our @ISA = CFPlus::UI::Box::; 1875our @ISA = DC::UI::Box::;
1839 1876
1840sub new { 1877sub new {
1841 my $class = shift; 1878 my $class = shift;
1842 1879
1843 $class->SUPER::new ( 1880 $class->SUPER::new (
1846 ) 1883 )
1847} 1884}
1848 1885
1849############################################################################# 1886#############################################################################
1850 1887
1851package CFPlus::UI::Label; 1888package DC::UI::Label;
1852 1889
1853our @ISA = CFPlus::UI::DrawBG::; 1890our @ISA = DC::UI::DrawBG::;
1854 1891
1855use CFPlus::OpenGL; 1892use DC::OpenGL;
1856 1893
1857sub new { 1894sub new {
1858 my ($class, %arg) = @_; 1895 my ($class, %arg) = @_;
1859 1896
1860 my $self = $class->SUPER::new ( 1897 my $self = $class->SUPER::new (
1865 #text => initial text 1902 #text => initial text
1866 #markup => initial narkup 1903 #markup => initial narkup
1867 #max_w => maximum pixel width 1904 #max_w => maximum pixel width
1868 #style => 0, # render flags 1905 #style => 0, # render flags
1869 ellipsise => 3, # end 1906 ellipsise => 3, # end
1870 layout => (new CFPlus::Layout), 1907 layout => (new DC::Layout),
1871 fontsize => 1, 1908 fontsize => 1,
1872 align => -1, 1909 align => 0.5,
1873 valign => -1, 1910 valign => 0.5,
1874 padding_x => 2, 1911 padding_x => 4,
1875 padding_y => 2, 1912 padding_y => 2,
1876 can_events => 0, 1913 can_events => 0,
1877 %arg 1914 %arg
1878 ); 1915 );
1879 1916
1880 if (exists $self->{template}) { 1917 if (exists $self->{template}) {
1881 my $layout = new CFPlus::Layout; 1918 my $layout = new DC::Layout;
1882 $layout->set_text (delete $self->{template}); 1919 $layout->set_text (delete $self->{template});
1883 $self->{template} = $layout; 1920 $self->{template} = $layout;
1884 } 1921 }
1885 1922
1886 if (exists $self->{markup}) { 1923 if (exists $self->{markup}) {
1942 1979
1943sub size_request { 1980sub size_request {
1944 my ($self) = @_; 1981 my ($self) = @_;
1945 1982
1946 $self->{size_req} ||= do { 1983 $self->{size_req} ||= do {
1984 my ($max_w, $max_h) = $self->get_max_wh;
1985
1947 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1986 $self->{layout}->set_font ($self->{font}) if $self->{font};
1948 $self->{layout}->set_width ($self->{max_w} || -1); 1987 $self->{layout}->set_width ($max_w);
1949 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1988 $self->{layout}->set_ellipsise ($self->{ellipsise});
1950 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1989 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1951 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1990 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1952 1991
1953 my ($w, $h) = $self->{layout}->size; 1992 my ($w, $h) = $self->{layout}->size;
1954 1993
1955 if (exists $self->{template}) { 1994 if (exists $self->{template}) {
1956 $self->{template}->set_font ($self->{font}) if $self->{font}; 1995 $self->{template}->set_font ($self->{font}) if $self->{font};
1957 $self->{template}->set_width ($self->{max_w} || -1); 1996 $self->{template}->set_width ($max_w);
1958 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1997 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1959 1998
1960 my ($w2, $h2) = $self->{template}->size; 1999 my ($w2, $h2) = $self->{template}->size;
1961 2000
1962 $w = List::Util::max $w, $w2; 2001 $w = List::Util::max $w, $w2;
2018 2057
2019 [$self->{layout}->size] 2058 [$self->{layout}->size]
2020 }; 2059 };
2021 2060
2022 unless (exists $self->{ox}) { 2061 unless (exists $self->{ox}) {
2023 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 2062 $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} 2063 $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 2064
2031 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2065 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2032 }; 2066 };
2033 2067
2034# unless ($self->{list}) { 2068# unless ($self->{list}) {
2035# $self->{list} = CFPlus::OpenGL::glGenList; 2069# $self->{list} = DC::OpenGL::glGenList;
2036# CFPlus::OpenGL::glNewList $self->{list}; 2070# DC::OpenGL::glNewList $self->{list};
2037# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2071# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2038# CFPlus::OpenGL::glEndList; 2072# DC::OpenGL::glEndList;
2039# } 2073# }
2040# 2074#
2041# CFPlus::OpenGL::glCallList $self->{list}; 2075# DC::OpenGL::glCallList $self->{list};
2042 2076
2043 $self->{layout}->draw; 2077 $self->{layout}->draw;
2044} 2078}
2045 2079
2046#sub destroy { 2080#sub destroy {
2047# my ($self) = @_; 2081# my ($self) = @_;
2048# 2082#
2049# CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; 2083# DC::OpenGL::glDeleteList delete $self->{list} if $self->{list};
2050# 2084#
2051# $self->SUPER::destroy; 2085# $self->SUPER::destroy;
2052#} 2086#}
2053 2087
2054############################################################################# 2088#############################################################################
2055 2089
2056package CFPlus::UI::EntryBase; 2090package DC::UI::EntryBase;
2057 2091
2058our @ISA = CFPlus::UI::Label::; 2092our @ISA = DC::UI::Label::;
2059 2093
2060use CFPlus::OpenGL; 2094use DC::OpenGL;
2061 2095
2062sub new { 2096sub new {
2063 my $class = shift; 2097 my $class = shift;
2064 2098
2065 $class->SUPER::new ( 2099 $class->SUPER::new (
2066 fg => [1, 1, 1], 2100 fg => [1, 1, 1],
2067 bg => [0, 0, 0, 0.2], 2101 bg => [0, 0, 0, 0.2],
2068 outline => [0.6, 0.3, 0.1], 2102 outline => undef,
2069 active_bg => [0, 0, 1, .2], 2103 active_bg => [0, 0, 1, .2],
2070 active_fg => [1, 1, 1], 2104 active_fg => [1, 1, 1],
2071 active_outline => [1, 1, 0], 2105 active_outline => [1, 1, 0],
2072 can_hover => 1, 2106 can_hover => 1,
2073 can_focus => 1, 2107 can_focus => 1,
2108 align => 0,
2074 valign => 0, 2109 valign => 0.5,
2075 can_events => 1, 2110 can_events => 1,
2076 ellipsise => 0, 2111 ellipsise => 0,
2112 padding_x => 4,
2113 padding_y => 2,
2077 #text => ... 2114 #text => ...
2078 #hidden => "*", 2115 #hidden => "*",
2079 @_ 2116 @_
2080 ) 2117 )
2081} 2118}
2128 2165
2129 my $text = $self->get_text; 2166 my $text = $self->get_text;
2130 2167
2131 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; 2168 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text;
2132 2169
2133 if ($uni == 8) { 2170 if ($sym == DC::SDLK_BACKSPACE) {
2134 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2171 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
2135 } elsif ($uni == 127) { 2172 } elsif ($sym == DC::SDLK_DELETE) {
2136 substr $text, $self->{cursor}, 1, ""; 2173 substr $text, $self->{cursor}, 1, "";
2137 } elsif ($sym == CFPlus::SDLK_LEFT) { 2174 } elsif ($sym == DC::SDLK_LEFT) {
2138 --$self->{cursor} if $self->{cursor}; 2175 --$self->{cursor} if $self->{cursor};
2139 } elsif ($sym == CFPlus::SDLK_RIGHT) { 2176 } elsif ($sym == DC::SDLK_RIGHT) {
2140 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 2177 ++$self->{cursor} if $self->{cursor} < length $self->{text};
2141 } elsif ($sym == CFPlus::SDLK_HOME) { 2178 } elsif ($sym == DC::SDLK_HOME) {
2142 # what a hack 2179 # what a hack
2143 $self->{cursor} = 2180 $self->{cursor} =
2144 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ 2181 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/
2145 ? length $1 2182 ? length $1
2146 : 0; 2183 : 0;
2147 } elsif ($sym == CFPlus::SDLK_END) { 2184 } elsif ($sym == DC::SDLK_END) {
2148 # uh, again 2185 # uh, again
2149 $self->{cursor} = 2186 $self->{cursor} =
2150 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ 2187 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/
2151 ? $self->{cursor} + length $1 2188 ? $self->{cursor} + length $1
2152 : length $self->{text}; 2189 : length $self->{text};
2233 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); 2270 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
2234 } 2271 }
2235 2272
2236 glColor_premultiply @{$self->{active_fg}}; 2273 glColor_premultiply @{$self->{active_fg}};
2237 glBegin GL_LINES; 2274 glBegin GL_LINES;
2238 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; 2275 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}; 2276 glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h};
2240 glEnd; 2277 glEnd;
2241 2278
2242 glLineWidth 3; 2279 glLineWidth 3;
2243 glColor @{$self->{active_outline}}; 2280 glColor @{$self->{active_outline}};
2244 glRect_lineloop 0, 0, $self->{w} - 1, $self->{h} - 1; 2281 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2245 glLineWidth 1; 2282 glLineWidth 1;
2246 2283
2247 } else { 2284 } else {
2248 glColor @{$self->{outline}}; 2285 glColor @{$self->{outline} || $DC::THEME{entry_outline}};
2249 glTranslate .375, .375;
2250 glBegin GL_LINE_STRIP; 2286 glBegin GL_LINE_STRIP;
2251 glVertex 0, $self->{h} * .5; 2287 glVertex .5, $self->{h} * .5;
2252 glVertex 0, $self->{h} - 3; 2288 glVertex .5, $self->{h} - 2.5;
2253 glVertex $self->{w} - 1, $self->{h} - 3; 2289 glVertex $self->{w} - .5, $self->{h} - 2.5;
2254 glVertex $self->{w} - 1, $self->{h} * .5; 2290 glVertex $self->{w} - .5, $self->{h} * .5;
2255 glEnd; 2291 glEnd;
2256 } 2292 }
2257} 2293}
2258 2294
2259############################################################################# 2295#############################################################################
2260 2296
2261package CFPlus::UI::Entry; 2297package DC::UI::Entry;
2262 2298
2263our @ISA = CFPlus::UI::EntryBase::; 2299our @ISA = DC::UI::EntryBase::;
2264 2300
2265use CFPlus::OpenGL; 2301use DC::OpenGL;
2302
2303sub new {
2304 my $class = shift;
2305
2306 $class->SUPER::new (
2307 history_pointer => -1,
2308 @_
2309 )
2310}
2311
2266 2312
2267sub invoke_key_down { 2313sub invoke_key_down {
2268 my ($self, $ev) = @_; 2314 my ($self, $ev) = @_;
2269 2315
2270 my $sym = $ev->{sym}; 2316 my $sym = $ev->{sym};
2276 $self->{history_pointer} = -1; 2322 $self->{history_pointer} = -1;
2277 $self->{history_saveback} = ''; 2323 $self->{history_saveback} = '';
2278 $self->emit (activate => $txt); 2324 $self->emit (activate => $txt);
2279 $self->update; 2325 $self->update;
2280 2326
2281 } elsif ($sym == CFPlus::SDLK_UP) { 2327 } elsif ($sym == DC::SDLK_UP) {
2282 if ($self->{history_pointer} < 0) { 2328 if ($self->{history_pointer} < 0) {
2283 $self->{history_saveback} = $self->get_text; 2329 $self->{history_saveback} = $self->get_text;
2284 } 2330 }
2285 if (@{$self->{history} || []} > 0) { 2331 if (@{$self->{history} || []} > 0) {
2286 $self->{history_pointer}++; 2332 $self->{history_pointer}++;
2288 $self->{history_pointer} = @{$self->{history} || []} - 1; 2334 $self->{history_pointer} = @{$self->{history} || []} - 1;
2289 } 2335 }
2290 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2336 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2291 } 2337 }
2292 2338
2293 } elsif ($sym == CFPlus::SDLK_DOWN) { 2339 } elsif ($sym == DC::SDLK_DOWN) {
2294 $self->{history_pointer}--; 2340 $self->{history_pointer}--;
2295 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2341 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
2296 2342
2297 if ($self->{history_pointer} >= 0) { 2343 if ($self->{history_pointer} >= 0) {
2298 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2344 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2299 } else { 2345 } else {
2346 if (defined $self->{history_saveback}) {
2300 $self->set_text ($self->{history_saveback}); 2347 $self->set_text ($self->{history_saveback});
2348 $self->{history_saveback} = undef;
2349 }
2301 } 2350 }
2302 2351
2303 } else { 2352 } else {
2304 return $self->SUPER::invoke_key_down ($ev) 2353 return $self->SUPER::invoke_key_down ($ev)
2305 } 2354 }
2307 1 2356 1
2308} 2357}
2309 2358
2310############################################################################# 2359#############################################################################
2311 2360
2312package CFPlus::UI::TextEdit; 2361package DC::UI::TextEdit;
2313 2362
2314our @ISA = CFPlus::UI::EntryBase::; 2363our @ISA = DC::UI::EntryBase::;
2315 2364
2316use CFPlus::OpenGL; 2365use DC::OpenGL;
2366
2367sub new {
2368 my $class = shift;
2369
2370 $class->SUPER::new (
2371 padding_y => 4,
2372
2373 @_
2374 )
2375}
2317 2376
2318sub move_cursor_ver { 2377sub move_cursor_ver {
2319 my ($self, $dy) = @_; 2378 my ($self, $dy) = @_;
2320 2379
2321 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2380 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2322 2381
2323 $y += $dy; 2382 $line += $dy;
2324 2383
2325 if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { 2384 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) {
2326 $self->{cursor} = $index; 2385 $self->{cursor} = $index;
2327 delete $self->{cur_h}; 2386 delete $self->{cur_h};
2328 $self->update; 2387 $self->update;
2329 return; 2388 return;
2330 } 2389 }
2333sub invoke_key_down { 2392sub invoke_key_down {
2334 my ($self, $ev) = @_; 2393 my ($self, $ev) = @_;
2335 2394
2336 my $sym = $ev->{sym}; 2395 my $sym = $ev->{sym};
2337 2396
2338 if ($sym == CFPlus::SDLK_UP) { 2397 if ($sym == DC::SDLK_UP) {
2339 $self->move_cursor_ver (-1); 2398 $self->move_cursor_ver (-1);
2340 } elsif ($sym == CFPlus::SDLK_DOWN) { 2399 } elsif ($sym == DC::SDLK_DOWN) {
2341 $self->move_cursor_ver (+1); 2400 $self->move_cursor_ver (+1);
2342 } else { 2401 } else {
2343 return $self->SUPER::invoke_key_down ($ev) 2402 return $self->SUPER::invoke_key_down ($ev)
2344 } 2403 }
2345 2404
2346 1 2405 1
2347} 2406}
2348 2407
2349############################################################################# 2408#############################################################################
2350 2409
2351package CFPlus::UI::ButtonBin; 2410package DC::UI::ButtonBin;
2352 2411
2353our @ISA = CFPlus::UI::Bin::; 2412our @ISA = DC::UI::Bin::;
2354 2413
2355use CFPlus::OpenGL; 2414use DC::OpenGL;
2356 2415
2357my @tex = 2416my @tex =
2358 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2417 map { new_from_resource DC::Texture $_, mipmap => 1 }
2359 qw(b1_button_inactive.png b1_button_active.png); 2418 qw(b1_button_inactive.png b1_button_active.png);
2360 2419
2361sub new { 2420sub new {
2362 my $class = shift; 2421 my $class = shift;
2363 2422
2364 $class->SUPER::new ( 2423 $class->SUPER::new (
2365 can_hover => 1, 2424 can_hover => 1,
2366 align => 0, 2425 align => 0.5,
2367 valign => 0, 2426 valign => 0.5,
2368 can_events => 1, 2427 can_events => 1,
2369 @_ 2428 @_
2370 ) 2429 )
2371} 2430}
2372 2431
2395 $self->SUPER::_draw; 2454 $self->SUPER::_draw;
2396} 2455}
2397 2456
2398############################################################################# 2457#############################################################################
2399 2458
2400package CFPlus::UI::Button; 2459package DC::UI::Button;
2401 2460
2402our @ISA = CFPlus::UI::Label::; 2461our @ISA = DC::UI::Label::;
2403 2462
2404use CFPlus::OpenGL; 2463use DC::OpenGL;
2405 2464
2406my @tex = 2465my @tex =
2407 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2466 map { new_from_resource DC::Texture $_, mipmap => 1 }
2408 qw(b1_button_inactive.png b1_button_active.png); 2467 qw(b1_button_inactive.png b1_button_active.png);
2409 2468
2410sub new { 2469sub new {
2411 my $class = shift; 2470 my $class = shift;
2412 2471
2413 $class->SUPER::new ( 2472 $class->SUPER::new (
2414 padding_x => 4, 2473 padding_x => 8,
2415 padding_y => 4, 2474 padding_y => 4,
2416 fg => [1.0, 1.0, 1.0], 2475 fg => [1.0, 1.0, 1.0],
2417 active_fg => [0.8, 0.8, 0.8], 2476 active_fg => [0.8, 0.8, 0.8],
2418 can_hover => 1, 2477 can_hover => 1,
2419 align => 0, 2478 align => 0.5,
2420 valign => 0, 2479 valign => 0.5,
2421 can_events => 1, 2480 can_events => 1,
2422 @_ 2481 @_
2423 ) 2482 )
2424} 2483}
2425 2484
2450 $self->SUPER::_draw; 2509 $self->SUPER::_draw;
2451} 2510}
2452 2511
2453############################################################################# 2512#############################################################################
2454 2513
2455package CFPlus::UI::CheckBox; 2514package DC::UI::CheckBox;
2456 2515
2457our @ISA = CFPlus::UI::DrawBG::; 2516our @ISA = DC::UI::DrawBG::;
2458 2517
2459my @tex = 2518my @tex =
2460 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2519 map { new_from_resource DC::Texture $_, mipmap => 1 }
2461 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2520 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2462 2521
2463use CFPlus::OpenGL; 2522use DC::OpenGL;
2464 2523
2465sub new { 2524sub new {
2466 my $class = shift; 2525 my $class = shift;
2467 2526
2468 $class->SUPER::new ( 2527 $class->SUPER::new (
2528 fontsize => 1,
2469 padding_x => 2, 2529 padding_x => 2,
2470 padding_y => 2, 2530 padding_y => 2,
2471 fg => [1, 1, 1], 2531 fg => [1, 1, 1],
2472 active_fg => [1, 1, 0], 2532 active_fg => [1, 1, 0],
2473 bg => [0, 0, 0, 0.2], 2533 bg => [0, 0, 0, 0.2],
2479} 2539}
2480 2540
2481sub size_request { 2541sub size_request {
2482 my ($self) = @_; 2542 my ($self) = @_;
2483 2543
2484 (6) x 2 2544 ($self->{fontsize} * $::FONTSIZE) x 2
2485} 2545}
2486 2546
2487sub toggle { 2547sub toggle {
2488 my ($self) = @_; 2548 my ($self) = @_;
2489 2549
2508sub _draw { 2568sub _draw {
2509 my ($self) = @_; 2569 my ($self) = @_;
2510 2570
2511 $self->SUPER::_draw; 2571 $self->SUPER::_draw;
2512 2572
2513 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; 2573 glTranslate $self->{padding_x}, $self->{padding_y}, 0;
2514 2574
2515 my ($w, $h) = @$self{qw(w h)}; 2575 my ($w, $h) = @$self{qw(w h)};
2516 2576
2517 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; 2577 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2518 2578
2525 glDisable GL_TEXTURE_2D; 2585 glDisable GL_TEXTURE_2D;
2526} 2586}
2527 2587
2528############################################################################# 2588#############################################################################
2529 2589
2530package CFPlus::UI::Image; 2590package DC::UI::Image;
2531 2591
2532our @ISA = CFPlus::UI::Base::; 2592our @ISA = DC::UI::Base::;
2533 2593
2534use CFPlus::OpenGL; 2594use DC::OpenGL;
2535 2595
2536our %texture_cache; 2596our %texture_cache;
2537 2597
2538sub new { 2598sub new {
2539 my $class = shift; 2599 my $class = shift;
2546 2606
2547 $self->{path} || $self->{tex} 2607 $self->{path} || $self->{tex}
2548 or Carp::croak "'path' or 'tex' attributes required"; 2608 or Carp::croak "'path' or 'tex' attributes required";
2549 2609
2550 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2610 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2551 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; 2611 new_from_resource DC::Texture $self->{path}, mipmap => 1;
2552 2612
2553 CFPlus::weaken $texture_cache{$self->{path}}; 2613 DC::weaken $texture_cache{$self->{path}};
2554 2614
2555 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2615 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2556 2616
2557 $self 2617 $self
2558} 2618}
2559 2619
2560sub STORABLE_freeze { 2620sub STORABLE_freeze {
2561 my ($self, $cloning) = @_; 2621 my ($self, $cloning) = @_;
2562 2622
2563 $self->{path} 2623 $self->{path}
2564 or die "cannot serialise CFPlus::UI::Image on non-loadable images\n"; 2624 or die "cannot serialise DC::UI::Image on non-loadable images\n";
2565 2625
2566 $self->{path} 2626 $self->{path}
2567} 2627}
2568 2628
2569sub STORABLE_attach { 2629sub STORABLE_attach {
2600 glDisable GL_TEXTURE_2D; 2660 glDisable GL_TEXTURE_2D;
2601} 2661}
2602 2662
2603############################################################################# 2663#############################################################################
2604 2664
2605package CFPlus::UI::ImageButton; 2665package DC::UI::ImageButton;
2606 2666
2607our @ISA = CFPlus::UI::Image::; 2667our @ISA = DC::UI::Image::;
2608 2668
2609use CFPlus::OpenGL; 2669use DC::OpenGL;
2610 2670
2611my %textures; 2671my %textures;
2612 2672
2613sub new { 2673sub new {
2614 my $class = shift; 2674 my $class = shift;
2617 padding_x => 4, 2677 padding_x => 4,
2618 padding_y => 4, 2678 padding_y => 4,
2619 fg => [1, 1, 1], 2679 fg => [1, 1, 1],
2620 active_fg => [0, 0, 1], 2680 active_fg => [0, 0, 1],
2621 can_hover => 1, 2681 can_hover => 1,
2622 align => 0, 2682 align => 0.5,
2623 valign => 0, 2683 valign => 0.5,
2624 can_events => 1, 2684 can_events => 1,
2625 @_ 2685 @_
2626 ); 2686 );
2627} 2687}
2628 2688
2642 1 2702 1
2643} 2703}
2644 2704
2645############################################################################# 2705#############################################################################
2646 2706
2647package CFPlus::UI::VGauge; 2707package DC::UI::VGauge;
2648 2708
2649our @ISA = CFPlus::UI::Base::; 2709our @ISA = DC::UI::Base::;
2650 2710
2651use List::Util qw(min max); 2711use List::Util qw(min max);
2652 2712
2653use CFPlus::OpenGL; 2713use DC::OpenGL;
2654 2714
2655my %tex = ( 2715my %tex = (
2656 food => [ 2716 food => [
2657 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2717 map { new_from_resource DC::Texture $_, mipmap => 1 }
2658 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2718 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2659 ], 2719 ],
2660 grace => [ 2720 grace => [
2661 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2721 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/ 2722 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2663 ], 2723 ],
2664 hp => [ 2724 hp => [
2665 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2725 map { new_from_resource DC::Texture $_, mipmap => 1 }
2666 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2726 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2667 ], 2727 ],
2668 mana => [ 2728 mana => [
2669 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2729 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/ 2730 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2671 ], 2731 ],
2672); 2732);
2673 2733
2674# eg. VGauge->new (gauge => 'food'), default gauge: food 2734# eg. VGauge->new (gauge => 'food'), default gauge: food
2777 glDisable GL_TEXTURE_2D; 2837 glDisable GL_TEXTURE_2D;
2778} 2838}
2779 2839
2780############################################################################# 2840#############################################################################
2781 2841
2782package CFPlus::UI::Progress; 2842package DC::UI::Progress;
2783 2843
2784our @ISA = CFPlus::UI::Label::; 2844our @ISA = DC::UI::Label::;
2785 2845
2786use CFPlus::OpenGL; 2846use DC::OpenGL;
2787 2847
2788sub new { 2848sub new {
2789 my ($class, %arg) = @_; 2849 my ($class, %arg) = @_;
2790 2850
2791 my $self = $class->SUPER::new ( 2851 my $self = $class->SUPER::new (
2852 padding_x => 2,
2853 padding_y => 2,
2792 fg => [1, 1, 1], 2854 fg => [1, 1, 1],
2793 bg => [0, 0, 1, 0.2], 2855 bg => [0, 0, 1, 0.2],
2794 bar => [0.7, 0.5, 0.1, 0.8], 2856 bar => [0.7, 0.5, 0.1, 0.8],
2795 outline => [0.4, 0.3, 0], 2857 outline => [0.4, 0.3, 0],
2796 fontsize => 0.9, 2858 fontsize => 0.9,
2797 valign => 0, 2859 valign => 0.5,
2798 align => 0, 2860 align => 0.5,
2799 can_events => 1, 2861 can_events => 1,
2800 ellipsise => 1, 2862 ellipsise => 1,
2801 label => "%d%%", 2863 label => "%d%%",
2802 %arg, 2864 %arg,
2803 ); 2865 );
2811 my ($self, $label) = @_; 2873 my ($self, $label) = @_;
2812 2874
2813 return if $self->{label} eq $label; 2875 return if $self->{label} eq $label;
2814 $self->{label} = $label; 2876 $self->{label} = $label;
2815 2877
2816 $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value}); 2878 $self->DC::UI::Progress::set_value (0 + delete $self->{value});
2817} 2879}
2818 2880
2819sub set_value { 2881sub set_value {
2820 my ($self, $value) = @_; 2882 my ($self, $value) = @_;
2821 2883
2836 my ($self) = @_; 2898 my ($self) = @_;
2837 2899
2838 glEnable GL_BLEND; 2900 glEnable GL_BLEND;
2839 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2901 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2840 2902
2903 my $px = $self->{padding_x};
2904 my $py = $self->{padding_y};
2905
2841 if ($self->{value} >= 0) { 2906 if ($self->{value} >= 0) {
2842 my $s = 3 + ($self->{w} - 6) * $self->{value}; 2907 my $s = int $px + ($self->{w} - $px * 2) * $self->{value};
2843 2908
2844 glColor_premultiply @{$self->{bar}}; 2909 glColor_premultiply @{$self->{bar}};
2845 glRect 2, 2, $s, $self->{h} - 2; 2910 glRect $px, $py, $s, $self->{h} - $py;
2846 glColor_premultiply @{$self->{bg}}; 2911 glColor_premultiply @{$self->{bg}};
2847 glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2; 2912 glRect $s , $py, $self->{w} - $px, $self->{h} - $py;
2848 } 2913 }
2849 2914
2850 glColor_premultiply @{$self->{outline}}; 2915 glColor_premultiply @{$self->{outline}};
2916
2917 $px -= .5;
2918 $py -= .5;
2919
2851 glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2; 2920 glRect_lineloop $px, $py, $self->{w} - $px, $self->{h} - $py;
2852 2921
2853 glDisable GL_BLEND; 2922 glDisable GL_BLEND;
2854 2923
2855 { 2924 {
2856 local $self->{bg}; # do not draw background 2925 local $self->{bg}; # do not draw background
2858 } 2927 }
2859} 2928}
2860 2929
2861############################################################################# 2930#############################################################################
2862 2931
2863package CFPlus::UI::ExperienceProgress; 2932package DC::UI::ExperienceProgress;
2864 2933
2865our @ISA = CFPlus::UI::Progress::; 2934our @ISA = DC::UI::Progress::;
2866 2935
2867sub new { 2936sub new {
2868 my ($class, %arg) = @_; 2937 my ($class, %arg) = @_;
2869 2938
2939 my $tt = exists $arg{tooltip} ? "$arg{tooltip}\n\n" : "";
2940
2870 my $self = $class->SUPER::new ( 2941 my $self = $class->SUPER::new (
2942 %arg,
2871 tooltip => sub { 2943 tooltip => sub {
2872 my ($self) = @_; 2944 my ($self) = @_;
2873 2945
2874 sprintf "level %d\n%s points\n%s next level\n%s to go", 2946 sprintf "%slevel %d\n%s points\n%s next level\n%s to go, %d%% done",
2947 $tt,
2875 $self->{lvl}, 2948 $self->{lvl},
2876 ::formsep ($self->{exp}), 2949 ::formsep ($self->{exp}),
2877 ::formsep ($self->{nxt}), 2950 ::formsep ($self->{nxt}),
2878 ::formsep ($self->{nxt} - $self->{exp}), 2951 ::formsep ($self->{nxt} - $self->{exp}),
2952 $self->_percent * 100,
2879 }, 2953 },
2880 %arg
2881 ); 2954 );
2882 2955
2883 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } 2956 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2884 if $::CONN; 2957 if $::CONN;
2885 2958
2893 if $::CONN; 2966 if $::CONN;
2894 2967
2895 $self->SUPER::DESTROY; 2968 $self->SUPER::DESTROY;
2896} 2969}
2897 2970
2971sub _percent {
2972 my ($self) = @_;
2973
2974 my $table = $::CONN && $::CONN->{exp_table}
2975 or return -1;
2976
2977 my $l0 = $table->[$self->{lvl} - 1];
2978 my $l1 = $table->[$self->{lvl}];
2979
2980 $self->{nxt} = $l1;
2981
2982 ($self->{exp} - $l0) / ($l1 - $l0)
2983}
2984
2898sub set_value { 2985sub set_value {
2899 my ($self, $lvl, $exp) = @_; 2986 my ($self, $lvl, $exp) = @_;
2900 2987
2901 $self->{lvl} = $lvl; 2988 $self->{lvl} = $lvl;
2902 $self->{exp} = $exp; 2989 $self->{exp} = $exp;
2903 2990
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); 2991 $self->SUPER::set_value ($self->_percent);
2916} 2992}
2917 2993
2918############################################################################# 2994#############################################################################
2919 2995
2920package CFPlus::UI::Gauge; 2996package DC::UI::Gauge;
2921 2997
2922our @ISA = CFPlus::UI::VBox::; 2998our @ISA = DC::UI::VBox::;
2923 2999
2924sub new { 3000sub new {
2925 my ($class, %arg) = @_; 3001 my ($class, %arg) = @_;
2926 3002
2927 my $self = $class->SUPER::new ( 3003 my $self = $class->SUPER::new (
2929 can_hover => 1, 3005 can_hover => 1,
2930 can_events => 1, 3006 can_events => 1,
2931 %arg, 3007 %arg,
2932 ); 3008 );
2933 3009
2934 $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999"); 3010 $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); 3011 $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"); 3012 $self->add ($self->{max} = new DC::UI::Label valign => 0, align => 0.5, template => "999");
2937 3013
2938 $self 3014 $self
2939} 3015}
2940 3016
2941sub set_fontsize { 3017sub set_fontsize {
2962 $self->{value}->set_text ($val); 3038 $self->{value}->set_text ($val);
2963} 3039}
2964 3040
2965############################################################################# 3041#############################################################################
2966 3042
2967package CFPlus::UI::Slider; 3043package DC::UI::Slider;
2968 3044
2969use strict; 3045use strict;
2970 3046
2971use CFPlus::OpenGL; 3047use DC::OpenGL;
2972 3048
2973our @ISA = CFPlus::UI::DrawBG::; 3049our @ISA = DC::UI::DrawBG::;
2974 3050
2975my @tex = 3051my @tex =
2976 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ } 3052 map { new_from_resource DC::Texture $_ }
2977 qw(s1_slider.png s1_slider_bg.png); 3053 qw(s1_slider.png s1_slider_bg.png);
2978 3054
2979sub new { 3055sub new {
2980 my $class = shift; 3056 my $class = shift;
2981 3057
3018sub set_value { 3094sub set_value {
3019 my ($self, $value) = @_; 3095 my ($self, $value) = @_;
3020 3096
3021 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; 3097 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
3022 3098
3023 $hi = $lo + 1 if $hi <= $lo; 3099 $hi = $lo if $hi < $lo;
3024 3100
3025 $page = $hi - $lo if $page > $hi - $lo; 3101 $value = $hi - $page if $value > $hi - $page;
3026
3027 $value = $lo if $value < $lo; 3102 $value = $lo if $value < $lo;
3028 $value = $hi - $page if $value > $hi - $page;
3029 3103
3030 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit 3104 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
3031 if $unit; 3105 if $unit;
3032 3106
3033 @{$self->{range}} = ($value, $lo, $hi, $page, $unit); 3107 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
3077sub invoke_mouse_wheel { 3151sub invoke_mouse_wheel {
3078 my ($self, $ev) = @_; 3152 my ($self, $ev) = @_;
3079 3153
3080 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 3154 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
3081 3155
3082 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; 3156 my $pagepart = $ev->{mod} & DC::KMOD_SHIFT ? 1 : 0.2;
3083 3157
3084 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); 3158 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
3085 3159
3086 1 3160 1
3087} 3161}
3097 my ($self) = @_; 3171 my ($self) = @_;
3098 3172
3099 unless ($self->{knob_w}) { 3173 unless ($self->{knob_w}) {
3100 $self->set_value ($self->{range}[0]); 3174 $self->set_value ($self->{range}[0]);
3101 3175
3102 my ($value, $lo, $hi, $page) = @{$self->{range}}; 3176 my ($value, $lo, $hi, $page, $unit) = @{$self->{range}};
3103 my $range = ($hi - $page - $lo) || 1e-100; 3177 my $range = ($hi - $page - $lo) || 1e-10;
3104 3178
3105 my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1; 3179 my $knob_w = List::Util::min 1, $page / (($hi - $lo) || 1e-10) || 24 / $self->{w};
3106 3180
3107 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; 3181 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5;
3108 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; 3182 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100;
3109 3183
3110 $value = ($value - $lo) / $range; 3184 $value = ($value - $lo) / $range;
3140 glDisable GL_TEXTURE_2D; 3214 glDisable GL_TEXTURE_2D;
3141} 3215}
3142 3216
3143############################################################################# 3217#############################################################################
3144 3218
3145package CFPlus::UI::ValSlider; 3219package DC::UI::ValSlider;
3146 3220
3147our @ISA = CFPlus::UI::HBox::; 3221our @ISA = DC::UI::HBox::;
3148 3222
3149sub new { 3223sub new {
3150 my ($class, %arg) = @_; 3224 my ($class, %arg) = @_;
3151 3225
3152 my $range = delete $arg{range}; 3226 my $range = delete $arg{range};
3153 3227
3154 my $self = $class->SUPER::new ( 3228 my $self = $class->SUPER::new (
3155 slider => (new CFPlus::UI::Slider expand => 1, range => $range), 3229 slider => (new DC::UI::Slider expand => 1, range => $range),
3156 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}), 3230 entry => (new DC::UI::Label text => "", template => delete $arg{template}),
3157 to_value => sub { shift }, 3231 to_value => sub { shift },
3158 from_value => sub { shift }, 3232 from_value => sub { shift },
3159 %arg, 3233 %arg,
3160 ); 3234 );
3161 3235
3181sub set_range { shift->{slider}->set_range (@_) } 3255sub set_range { shift->{slider}->set_range (@_) }
3182sub set_value { shift->{slider}->set_value (@_) } 3256sub set_value { shift->{slider}->set_value (@_) }
3183 3257
3184############################################################################# 3258#############################################################################
3185 3259
3186package CFPlus::UI::TextScroller; 3260package DC::UI::TextScroller;
3187 3261
3188our @ISA = CFPlus::UI::HBox::; 3262our @ISA = DC::UI::HBox::;
3189 3263
3190use CFPlus::OpenGL; 3264use DC::OpenGL;
3191 3265
3192sub new { 3266sub new {
3193 my $class = shift; 3267 my $class = shift;
3194 3268
3195 my $self = $class->SUPER::new ( 3269 my $self = $class->SUPER::new (
3197 can_events => 1, 3271 can_events => 1,
3198 indent => 0, 3272 indent => 0,
3199 #font => default_font 3273 #font => default_font
3200 @_, 3274 @_,
3201 3275
3202 layout => (new CFPlus::Layout), 3276 layout => (new DC::Layout),
3203 par => [], 3277 par => [],
3204 max_par => 0, 3278 max_par => 0,
3205 height => 0, 3279 height => 0,
3206 children => [ 3280 children => [
3207 (new CFPlus::UI::Empty expand => 1), 3281 (new DC::UI::Empty expand => 1),
3208 (new CFPlus::UI::Slider vertical => 1), 3282 (new DC::UI::Slider vertical => 1),
3209 ], 3283 ],
3210 ); 3284 );
3211 3285
3212 $self->{children}[1]->connect (changed => sub { $self->update }); 3286 $self->{children}[1]->connect (changed => sub { $self->update });
3213 3287
3269 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); 3343 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
3270 $layout->set_markup ($para->{markup}); 3344 $layout->set_markup ($para->{markup});
3271 3345
3272 $layout->set_shapes ( 3346 $layout->set_shapes (
3273 map 3347 map
3274 +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), 3348 +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}),
3275 @{$para->{widget}} 3349 @{$para->{widget}}
3276 ); 3350 );
3277 3351
3278 $layout 3352 $layout
3279} 3353}
3396 $ROOT->on_post_alloc ($self => sub { 3470 $ROOT->on_post_alloc ($self => sub {
3397 $self->force_uptodate; 3471 $self->force_uptodate;
3398 3472
3399 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 3473 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
3400 3474
3401 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 3475 $self->{texture} ||= new_from_opengl DC::Texture $W, $H, sub {
3402 glClearColor 0, 0, 0, 0; 3476 glClearColor 0, 0, 0, 0;
3403 glClear GL_COLOR_BUFFER_BIT; 3477 glClear GL_COLOR_BUFFER_BIT;
3404 3478
3405 package CFPlus::UI::Base; 3479 package DC::UI::Base;
3406 local ($draw_x, $draw_y, $draw_w, $draw_h) = 3480 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3407 (0, 0, $self->{w}, $self->{h}); 3481 (0, 0, $self->{w}, $self->{h});
3408 3482
3409 my $top = int $self->{children}[1]{range}[0]; 3483 my $top = int $self->{children}[1]{range}[0];
3410 3484
3469 $self->{children}[1]->draw; 3543 $self->{children}[1]->draw;
3470} 3544}
3471 3545
3472############################################################################# 3546#############################################################################
3473 3547
3474package CFPlus::UI::Animator; 3548package DC::UI::Animator;
3475 3549
3476use CFPlus::OpenGL; 3550use DC::OpenGL;
3477 3551
3478our @ISA = CFPlus::UI::Bin::; 3552our @ISA = DC::UI::Bin::;
3479 3553
3480sub moveto { 3554sub moveto {
3481 my ($self, $x, $y) = @_; 3555 my ($self, $x, $y) = @_;
3482 3556
3483 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 3557 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
3511 glPopMatrix; 3585 glPopMatrix;
3512} 3586}
3513 3587
3514############################################################################# 3588#############################################################################
3515 3589
3516package CFPlus::UI::Flopper; 3590package DC::UI::Flopper;
3517 3591
3518our @ISA = CFPlus::UI::Button::; 3592our @ISA = DC::UI::Button::;
3519 3593
3520sub new { 3594sub new {
3521 my $class = shift; 3595 my $class = shift;
3522 3596
3523 my $self = $class->SUPER::new ( 3597 my $self = $class->SUPER::new (
3535 $self->{other}->toggle_visibility; 3609 $self->{other}->toggle_visibility;
3536} 3610}
3537 3611
3538############################################################################# 3612#############################################################################
3539 3613
3540package CFPlus::UI::Tooltip; 3614package DC::UI::Tooltip;
3541 3615
3542our @ISA = CFPlus::UI::Bin::; 3616our @ISA = DC::UI::Bin::;
3543 3617
3544use CFPlus::OpenGL; 3618use DC::OpenGL;
3545 3619
3546sub new { 3620sub new {
3547 my $class = shift; 3621 my $class = shift;
3548 3622
3549 $class->SUPER::new ( 3623 $class->SUPER::new (
3556 my ($self, $widget) = @_; 3630 my ($self, $widget) = @_;
3557 3631
3558 my $tip = $widget->{tooltip}; 3632 my $tip = $widget->{tooltip};
3559 $tip = $tip->($widget) if "CODE" eq ref $tip; 3633 $tip = $tip->($widget) if "CODE" eq ref $tip;
3560 3634
3561 $tip = CFPlus::Pod::section_label tooltip => $1 3635 $tip = DC::Pod::section_label tooltip => $1
3562 if $tip =~ /^#(.*)$/; 3636 if $tip =~ /^#(.*)$/;
3563 3637
3564 if ($ENV{CFPLUS_DEBUG} & 2) { 3638 if ($ENV{CFPLUS_DEBUG} & 2) {
3565 $tip .= "\n\n" . (ref $widget) . "\n" 3639 $tip .= "\n\n" . (ref $widget) . "\n"
3566 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3640 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3569 } 3643 }
3570 3644
3571 $tip =~ s/^\n+//; 3645 $tip =~ s/^\n+//;
3572 $tip =~ s/\n+$//; 3646 $tip =~ s/\n+$//;
3573 3647
3574 $self->add (new CFPlus::UI::Label 3648 $self->add (new DC::UI::Label
3649 fg => $DC::THEME{tooltip_fg},
3575 markup => $tip, 3650 markup => $tip,
3576 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3651 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3652 align => 0,
3577 fontsize => 0.8, 3653 fontsize => 0.8,
3578 style => 1, # FLAG_INVERSE 3654 style => $DC::THEME{tooltip_style}, # FLAG_INVERSE
3579 ellipsise => 0, 3655 ellipsise => 0,
3580 font => ($widget->{tooltip_font} || $::FONT_PROP), 3656 font => ($widget->{tooltip_font} || $::FONT_PROP),
3581 ); 3657 );
3582} 3658}
3583 3659
3618} 3694}
3619 3695
3620sub _draw { 3696sub _draw {
3621 my ($self) = @_; 3697 my ($self) = @_;
3622 3698
3623 glTranslate 0.375, 0.375;
3624
3625 my ($w, $h) = @$self{qw(w h)}; 3699 my ($w, $h) = @$self{qw(w h)};
3626 3700
3627 glColor 1, 0.8, 0.4; 3701 glColor @{ $DC::THEME{tooltip_bg} };
3628 glRect 0, 0, $w, $h; 3702 glRect 0, 0, $w, $h;
3629 3703
3630 glColor 0, 0, 0; 3704 glColor @{ $DC::THEME{tooltip_border} };
3631 glRect_lineloop 0, 0, $w, $h; 3705 glRect_lineloop .5, .5, $w + .5, $h + .5;
3632 3706
3633 glTranslate 2 - 0.375, 2 - 0.375; 3707 glTranslate 2, 2;
3634 3708
3635 $self->SUPER::_draw; 3709 $self->SUPER::_draw;
3636} 3710}
3637 3711
3638############################################################################# 3712#############################################################################
3639 3713
3640package CFPlus::UI::Face; 3714package DC::UI::Face;
3641 3715
3642our @ISA = CFPlus::UI::DrawBG::; 3716our @ISA = DC::UI::DrawBG::;
3643 3717
3644use CFPlus::OpenGL; 3718use DC::OpenGL;
3645 3719
3646sub new { 3720sub new {
3647 my $class = shift; 3721 my $class = shift;
3648 3722
3649 my $self = $class->SUPER::new ( 3723 my $self = $class->SUPER::new (
3652 aspect => 1, 3726 aspect => 1,
3653 can_events => 0, 3727 can_events => 0,
3654 @_, 3728 @_,
3655 ); 3729 );
3656 3730
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; 3731 $self->update_anim;
3681 }
3682 3732
3683 $self 3733 $self
3684} 3734}
3685 3735
3686sub update_timer { 3736sub update_timer {
3687 my ($self) = @_; 3737 my ($self) = @_;
3688 3738
3689 return unless $self->{timer}; 3739 return unless $self->{timer};
3690 3740
3691 if ($self->{visible}) { 3741 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; 3742 $self->{timer}->start;
3698 } else { 3743 } else {
3699 $self->{timer}->stop; 3744 $self->{timer}->stop;
3700 } 3745 }
3701} 3746}
3714 $tex->upload (sub { $self->reconfigure }); 3759 $tex->upload (sub { $self->reconfigure });
3715 } 3760 }
3716 } 3761 }
3717 } 3762 }
3718 } 3763 }
3764 }
3765}
3766
3767sub update_anim {
3768 my ($self) = @_;
3769
3770 if ($self->{anim} && $self->{animspeed}) {
3771 DC::weaken (my $widget = $self);
3772
3773 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed};
3774 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub {
3775 return unless $::CONN;
3776
3777 my $w = $widget
3778 or return;
3779
3780 ++$w->{frame};
3781 $w->update_face;
3782
3783 # somehow, $widget can go away
3784 $w->update;
3785 $w->update_timer;
3786 };
3787
3788 $self->update_face;
3789 $self->update_timer;
3790 } else {
3791 delete $self->{timer};
3719 } 3792 }
3720} 3793}
3721 3794
3722sub size_request { 3795sub size_request {
3723 my ($self) = @_; 3796 my ($self) = @_;
3745 return unless $self->{visible}; 3818 return unless $self->{visible};
3746 3819
3747 $self->SUPER::update; 3820 $self->SUPER::update;
3748} 3821}
3749 3822
3823sub set_face {
3824 my ($self, $face) = @_;
3825
3826 $self->{face} = $face;
3827 $self->reconfigure;
3828}
3829
3830sub set_anim {
3831 my ($self, $anim) = @_;
3832
3833 $self->{anim} = $anim;
3834 $self->update_anim;
3835}
3836
3837sub set_animspeed {
3838 my ($self, $animspeed) = @_;
3839
3840 $self->{animspeed} = $animspeed;
3841 $self->update_anim;
3842}
3843
3750sub invoke_visibility_change { 3844sub invoke_visibility_change {
3751 my ($self) = @_; 3845 my ($self) = @_;
3752 3846
3753 $self->update_timer; 3847 $self->update_timer;
3754 3848
3778 $self->SUPER::destroy; 3872 $self->SUPER::destroy;
3779} 3873}
3780 3874
3781############################################################################# 3875#############################################################################
3782 3876
3783package CFPlus::UI::Buttonbar; 3877package DC::UI::Buttonbar;
3784 3878
3785our @ISA = CFPlus::UI::HBox::; 3879our @ISA = DC::UI::HBox::;
3786 3880
3787# TODO: should actually wrap buttons and other goodies. 3881# TODO: should actually wrap buttons and other goodies.
3788 3882
3789############################################################################# 3883#############################################################################
3790 3884
3791package CFPlus::UI::Menu; 3885package DC::UI::Menu;
3792 3886
3793our @ISA = CFPlus::UI::Toplevel::; 3887our @ISA = DC::UI::Toplevel::;
3794 3888
3795use CFPlus::OpenGL; 3889use DC::OpenGL;
3796 3890
3797sub new { 3891sub new {
3798 my $class = shift; 3892 my $class = shift;
3799 3893
3800 my $self = $class->SUPER::new ( 3894 my $self = $class->SUPER::new (
3801 items => [], 3895 items => [],
3802 z => 100, 3896 z => 100,
3803 @_, 3897 @_,
3804 ); 3898 );
3805 3899
3806 $self->add ($self->{vbox} = new CFPlus::UI::VBox); 3900 $self->add ($self->{vbox} = new DC::UI::VBox);
3807 3901
3808 for my $item (@{ $self->{items} }) { 3902 for my $item (@{ $self->{items} }) {
3809 my ($widget, $cb, $tooltip) = @$item; 3903 my ($widget, $cb, $tooltip) = @$item;
3810 3904
3811 # handle various types of items, only text for now 3905 # handle various types of items, only text for now
3812 if (!ref $widget) { 3906 if (!ref $widget) {
3813 if ($widget =~ /\t/) { 3907 if ($widget =~ /\t/) {
3814 my ($left, $right) = split /\t/, $widget, 2; 3908 my ($left, $right) = split /\t/, $widget, 2;
3815 3909
3816 $widget = new CFPlus::UI::HBox 3910 $widget = new DC::UI::HBox
3817 can_hover => 1, 3911 can_hover => 1,
3818 can_events => 1, 3912 can_events => 1,
3819 tooltip => $tooltip, 3913 tooltip => $tooltip,
3820 children => [ 3914 children => [
3821 (new CFPlus::UI::Label markup => $left, expand => 1), 3915 (new DC::UI::Label markup => $left , align => 0, expand => 1),
3822 (new CFPlus::UI::Label markup => $right, align => +1), 3916 (new DC::UI::Label markup => $right, align => 1),
3823 ], 3917 ],
3824 ; 3918 ;
3825 3919
3826 } else { 3920 } else {
3827 $widget = new CFPlus::UI::Label 3921 $widget = new DC::UI::Label
3828 can_hover => 1, 3922 can_hover => 1,
3829 can_events => 1, 3923 can_events => 1,
3924 align => 0,
3830 markup => $widget, 3925 markup => $widget,
3831 tooltip => $tooltip; 3926 tooltip => $tooltip;
3832 } 3927 }
3833 } 3928 }
3834 3929
3849 # maybe save $GRAB? must be careful about events... 3944 # maybe save $GRAB? must be careful about events...
3850 $GRAB = $self; 3945 $GRAB = $self;
3851 $self->{button} = $ev->{button}; 3946 $self->{button} = $ev->{button};
3852 3947
3853 $self->show; 3948 $self->show;
3854 $self->move_abs ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); 3949
3950 my $x = $ev->{x};
3951 my $y = $ev->{y};
3952
3953 $self->{root}->on_post_alloc ($self => sub {
3954 $self->move_abs ($x - $self->{w} * 0.25, $y - $self->{border} * $::FONTSIZE * .5);
3955 });
3956
3957 1 # so it can be used inside event handlers
3855} 3958}
3856 3959
3857sub invoke_mouse_motion { 3960sub invoke_mouse_motion {
3858 my ($self, $ev, $x, $y) = @_; 3961 my ($self, $ev, $x, $y) = @_;
3859 3962
3880 1 3983 1
3881} 3984}
3882 3985
3883############################################################################# 3986#############################################################################
3884 3987
3885package CFPlus::UI::Multiplexer; 3988package DC::UI::Multiplexer;
3886 3989
3887our @ISA = CFPlus::UI::Container::; 3990our @ISA = DC::UI::Container::;
3888 3991
3889sub new { 3992sub new {
3890 my $class = shift; 3993 my $class = shift;
3891 3994
3892 my $self = $class->SUPER::new ( 3995 my $self = $class->SUPER::new (
3893 @_, 3996 @_,
3894 ); 3997 );
3895 3998
3896 $self->{current} = $self->{children}[0] 3999 $self->set_current_page (0);
3897 if @{ $self->{children} };
3898 4000
3899 $self 4001 $self
3900} 4002}
3901 4003
3902sub add { 4004sub add {
3903 my ($self, @widgets) = @_; 4005 my ($self, @widgets) = @_;
3904 4006
3905 $self->SUPER::add (@widgets); 4007 $self->SUPER::add (@widgets);
3906 4008
3907 $self->{current} = $self->{children}[0] 4009 $self->set_current_page (0)
3908 if @{ $self->{children} }; 4010 if @widgets == @{ $self->{children} };
3909} 4011}
3910 4012
3911sub get_current_page { 4013sub get_current_page {
3912 my ($self) = @_; 4014 my ($self) = @_;
3913 4015
3919 4021
3920 my $widget = ref $page_or_widget 4022 my $widget = ref $page_or_widget
3921 ? $page_or_widget 4023 ? $page_or_widget
3922 : $self->{children}[$page_or_widget]; 4024 : $self->{children}[$page_or_widget];
3923 4025
4026 $self->{current}->set_invisible if $self->{current} && $self->{visible};
4027
3924 $self->{current} = $widget; 4028 if (($self->{current} = $widget)) {
4029 $self->{current}->set_visible if $self->{current} && $self->{visible};
3925 $self->{current}->configure (0, 0, $self->{w}, $self->{h}); 4030 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
3926 4031
3927 $self->emit (page_changed => $self->{current}); 4032 $self->emit (page_changed => $self->{current});
4033 }
3928 4034
3929 $self->realloc; 4035 $self->realloc;
3930} 4036}
3931 4037
3932sub visible_children { 4038sub visible_children {
3933 $_[0]{current} 4039 $_[0]{current} || ()
3934} 4040}
3935 4041
3936sub size_request { 4042sub size_request {
3937 my ($self) = @_; 4043 my ($self) = @_;
3938 4044
4045 $self->{current}
3939 $self->{current}->size_request 4046 ? $self->{current}->size_request
4047 : (0, 0)
3940} 4048}
3941 4049
3942sub invoke_size_allocate { 4050sub invoke_size_allocate {
3943 my ($self, $w, $h) = @_; 4051 my ($self, $w, $h) = @_;
3944 4052
3945 $self->{current}->configure (0, 0, $w, $h); 4053 $self->{current}->configure (0, 0, $w, $h)
4054 if $self->{current};
3946 4055
3947 1 4056 1
3948} 4057}
3949 4058
3950sub _draw { 4059sub _draw {
3951 my ($self) = @_; 4060 my ($self) = @_;
3952 4061
3953 $self->{current}->draw; 4062 $self->{current}->draw
4063 if $self->{current};
3954} 4064}
3955 4065
3956############################################################################# 4066#############################################################################
3957 4067
3958package CFPlus::UI::Notebook; 4068package DC::UI::Notebook;
3959 4069
3960use CFPlus::OpenGL; 4070use DC::OpenGL;
3961 4071
3962our @ISA = CFPlus::UI::VBox::; 4072our @ISA = DC::UI::VBox::;
3963 4073
3964sub new { 4074sub new {
3965 my $class = shift; 4075 my $class = shift;
3966 4076
3967 my $self = $class->SUPER::new ( 4077 my $self = $class->SUPER::new (
3968 buttonbar => (new CFPlus::UI::Buttonbar), 4078 buttonbar => (new DC::UI::Buttonbar),
3969 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 4079 multiplexer => (new DC::UI::Multiplexer expand => 1),
3970 active_outline => [1, 1, 0], 4080 active_outline => [.7, .7, 0.2],
3971 # filter => # will be put between multiplexer and $self 4081 # filter => # will be put between multiplexer and $self
3972 @_, 4082 @_,
3973 ); 4083 );
3974 4084
3975 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 4085 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3983 4093
3984 for my $child (@$widgets) { 4094 for my $child (@$widgets) {
3985 Scalar::Util::weaken $child; 4095 Scalar::Util::weaken $child;
3986 $child->{c_tab_} ||= do { 4096 $child->{c_tab_} ||= do {
3987 my $tab = 4097 my $tab =
3988 (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") 4098 (UNIVERSAL::isa $child->{c_tab}, "DC::UI::Base")
3989 ? $child->{c_tab} 4099 ? $child->{c_tab}
3990 : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; 4100 : new DC::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1];
3991 4101
3992 $tab->connect (activate => sub { 4102 $tab->connect (activate => sub {
3993 $wself->set_current_page ($child); 4103 $wself->set_current_page ($child);
3994 }); 4104 });
3995 4105
4027sub pages { 4137sub pages {
4028 my ($self) = @_; 4138 my ($self) = @_;
4029 $self->{multiplexer}->children 4139 $self->{multiplexer}->children
4030} 4140}
4031 4141
4142sub page_index {
4143 my ($self, $widget) = @_;
4144
4145 my $i = 0;
4146 for ($self->pages) {
4147 if ($_ eq $widget) { return $i };
4148 $i++;
4149 }
4150
4151 undef
4152}
4153
4032sub add_tab { 4154sub add_tab {
4033 my ($self, $title, $widget, $tooltip) = @_; 4155 my ($self, $title, $widget, $tooltip) = @_;
4034 4156
4035 $title = [$title, $tooltip] unless ref $title; 4157 $title = [$title, $tooltip] unless ref $title;
4036 $widget->{c_tab} = $title; 4158 $widget->{c_tab} = $title;
4056 4178
4057 $self->SUPER::_draw (); 4179 $self->SUPER::_draw ();
4058 4180
4059 if (my $cur = $self->{multiplexer}{current}) { 4181 if (my $cur = $self->{multiplexer}{current}) {
4060 if ($cur = $cur->{c_tab_}) { 4182 if ($cur = $cur->{c_tab_}) {
4061 glTranslate $cur->{x}, $cur->{y}; 4183 glTranslate $self->{buttonbar}{x} + $cur->{x},
4184 $self->{buttonbar}{y} + $cur->{y};
4062 glLineWidth 3; 4185 glLineWidth 3;
4186 #glEnable GL_BLEND;
4187 #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
4063 glColor @{$self->{active_outline}}; 4188 glColor @{$self->{active_outline}};
4064 glRect_lineloop 1, 1, $cur->{w} - 2, $cur->{h} - 2; 4189 glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5;
4065 glLineWidth 1; 4190 glLineWidth 1;
4191 #glDisable GL_BLEND;
4066 } 4192 }
4067 } 4193 }
4068} 4194}
4069 4195
4070############################################################################# 4196#############################################################################
4071 4197
4072package CFPlus::UI::Selector; 4198package DC::UI::Selector;
4073 4199
4074use utf8; 4200use utf8;
4075 4201
4076our @ISA = CFPlus::UI::Button::; 4202our @ISA = DC::UI::Button::;
4077 4203
4078sub new { 4204sub new {
4079 my $class = shift; 4205 my $class = shift;
4080 4206
4081 my $self = $class->SUPER::new ( 4207 my $self = $class->SUPER::new (
4098 my ($value, $title, $tooltip) = @$_; 4224 my ($value, $title, $tooltip) = @$_;
4099 4225
4100 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 4226 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
4101 } 4227 }
4102 4228
4103 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); 4229 DC::UI::Menu->new (items => \@menu_items)->popup ($ev);
4104} 4230}
4105 4231
4106sub _set_value { 4232sub _set_value {
4107 my ($self, $value) = @_; 4233 my ($self, $value) = @_;
4108 4234
4109 my ($item) = grep $_->[0] eq $value, @{ $self->{options} } 4235 my ($item) = grep $_->[0] eq $value, @{ $self->{options} };
4236 $item ||= $self->{options}[0]
4110 or return; 4237 or return;
4111 4238
4112 $self->{value} = $item->[0]; 4239 $self->{value} = $item->[0];
4113 $self->set_markup ("$item->[1] ⇓"); 4240 $self->set_markup ("$item->[1] ⇓");
4114 $self->set_tooltip ($item->[2]); 4241# $self->set_tooltip ($item->[2]);
4115} 4242}
4116 4243
4117sub set_value { 4244sub set_value {
4118 my ($self, $value) = @_; 4245 my ($self, $value) = @_;
4119 4246
4121 4248
4122 $self->_set_value ($value); 4249 $self->_set_value ($value);
4123 $self->emit (changed => $value); 4250 $self->emit (changed => $value);
4124} 4251}
4125 4252
4253sub set_options {
4254 my ($self, $options) = @_;
4255
4256 $self->{options} = $options;
4257 $self->_set_value ($self->{value});
4258}
4259
4126############################################################################# 4260#############################################################################
4127 4261
4128package CFPlus::UI::Statusbox; 4262package DC::UI::Statusbox;
4129 4263
4130our @ISA = CFPlus::UI::VBox::; 4264our @ISA = DC::UI::VBox::;
4131 4265
4132sub new { 4266sub new {
4133 my $class = shift; 4267 my $class = shift;
4134 4268
4135 my $self = $class->SUPER::new ( 4269 my $self = $class->SUPER::new (
4136 fontsize => 0.8, 4270 fontsize => 0.8,
4137 @_, 4271 @_,
4138 ); 4272 );
4139 4273
4140 CFPlus::weaken (my $this = $self); 4274 DC::weaken (my $this = $self);
4141 4275
4142 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 4276 $self->{timer} = EV::timer 1, 1, sub { $this->reorder };
4143 4277
4144 $self 4278 $self
4145} 4279}
4146 4280
4147sub reorder { 4281sub reorder {
4148 my ($self) = @_; 4282 my ($self) = @_;
4149 my $NOW = Time::HiRes::time; 4283 my $NOW = EV::time;
4150 4284
4151 # freeze display when hovering over any label 4285 # freeze display when hovering over any label
4152 return if $CFPlus::UI::TOOLTIP->{owner} 4286 return if $DC::UI::TOOLTIP->{owner}
4153 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label}, 4287 && grep $DC::UI::TOOLTIP->{owner} == $_->{label},
4154 values %{ $self->{item} }; 4288 values %{ $self->{item} };
4155 4289
4156 while (my ($k, $v) = each %{ $self->{item} }) { 4290 while (my ($k, $v) = each %{ $self->{item} }) {
4157 delete $self->{item}{$k} if $v->{timeout} < $NOW; 4291 delete $self->{item}{$k} if $v->{timeout} < $NOW;
4158 } 4292 }
4293
4294 $self->{timer}->set (1, 1);
4159 4295
4160 my @widgets; 4296 my @widgets;
4161 4297
4162 my @items = sort { 4298 my @items = sort {
4163 $a->{pri} <=> $b->{pri} 4299 $a->{pri} <=> $b->{pri}
4164 or $b->{id} <=> $a->{id} 4300 or $b->{id} <=> $a->{id}
4165 } values %{ $self->{item} }; 4301 } values %{ $self->{item} };
4166
4167 $self->{timer}->interval (1);
4168 4302
4169 my $count = 10 + 1; 4303 my $count = 10 + 1;
4170 for my $item (@items) { 4304 for my $item (@items) {
4171 last unless --$count; 4305 last unless --$count;
4172 4306
4179 for ($short) { 4313 for ($short) {
4180 s/^\s+//; 4314 s/^\s+//;
4181 s/\s+/ /g; 4315 s/\s+/ /g;
4182 } 4316 }
4183 4317
4184 new CFPlus::UI::Label 4318 new DC::UI::Label
4185 markup => $short, 4319 markup => $short,
4186 tooltip => $item->{tooltip}, 4320 tooltip => $item->{tooltip},
4187 tooltip_font => $::FONT_PROP, 4321 tooltip_font => $::FONT_PROP,
4188 tooltip_width => 0.67, 4322 tooltip_width => 0.67,
4189 fontsize => $item->{fontsize} || $self->{fontsize}, 4323 fontsize => $item->{fontsize} || $self->{fontsize},
4190 max_w => $::WIDTH * 0.44, 4324 max_w => $::WIDTH * 0.44,
4325 align => 0,
4191 fg => [@{ $item->{fg} }], 4326 fg => [@{ $item->{fg} }],
4192 can_events => 1, 4327 can_events => 1,
4193 can_hover => 1 4328 can_hover => 1
4194 }; 4329 };
4195 4330
4196 if ((my $diff = $item->{timeout} - $NOW) < 2) { 4331 if ((my $diff = $item->{timeout} - $NOW) < 2) {
4197 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; 4332 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2;
4198 $label->update; 4333 $label->update;
4199 $label->set_max_size (undef, $label->{req_h} * $diff) 4334 $label->set_max_size (undef, $label->{req_h} * $diff)
4200 if $diff < 1; 4335 if $diff < 1;
4201 $self->{timer}->interval (1/30); 4336 $self->{timer}->set (1/30, 1/30);
4202 } else { 4337 } else {
4203 $label->{fg}[3] = $item->{fg}[3] || 1; 4338 $label->{fg}[3] = $item->{fg}[3] || 1;
4204 } 4339 }
4205 4340
4206 push @widgets, $label; 4341 push @widgets, $label;
4207 } 4342 }
4343
4344 my $hash = join ",", @widgets;
4345 return if $hash eq $self->{last_widget_hash};
4346 $self->{last_widget_hash} = $hash;
4208 4347
4209 $self->clear; 4348 $self->clear;
4210 $self->SUPER::add (reverse @widgets); 4349 $self->SUPER::add (reverse @widgets);
4211} 4350}
4212 4351
4268 $self->SUPER::destroy; 4407 $self->SUPER::destroy;
4269} 4408}
4270 4409
4271############################################################################# 4410#############################################################################
4272 4411
4273package CFPlus::UI::Root; 4412package DC::UI::Root;
4274 4413
4275our @ISA = CFPlus::UI::Container::; 4414our @ISA = DC::UI::Container::;
4276 4415
4277use List::Util qw(min max); 4416use List::Util qw(min max);
4278 4417
4279use CFPlus::OpenGL; 4418use DC::OpenGL;
4280 4419
4281sub new { 4420sub new {
4282 my $class = shift; 4421 my $class = shift;
4283 4422
4284 my $self = $class->SUPER::new ( 4423 my $self = $class->SUPER::new (
4285 visible => 1, 4424 visible => 1,
4286 @_, 4425 @_,
4287 ); 4426 );
4288 4427
4289 CFPlus::weaken ($self->{root} = $self); 4428 DC::weaken ($self->{root} = $self);
4290 4429
4291 $self 4430 $self
4292} 4431}
4293 4432
4294sub size_request { 4433sub size_request {
4342} 4481}
4343 4482
4344sub update { 4483sub update {
4345 my ($self) = @_; 4484 my ($self) = @_;
4346 4485
4347 $::WANT_REFRESH->start; 4486 $::WANT_REFRESH = 1;
4348} 4487}
4349 4488
4350sub add { 4489sub add {
4351 my ($self, @children) = @_; 4490 my ($self, @children) = @_;
4352 4491
4419 4558
4420 delete $queue{$widget+0}; 4559 delete $queue{$widget+0};
4421 4560
4422 my ($w, $h) = $widget->size_request; 4561 my ($w, $h) = $widget->size_request;
4423 4562
4424 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; 4563 $w += $widget->{padding_x} * 2;
4425 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; 4564 $h += $widget->{padding_y} * 2;
4565
4566 $w = max $widget->{min_w}, $w;
4567 $h = max $widget->{min_h}, $h;
4426 4568
4427 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4569 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4428 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4570 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4429 4571
4430 $w = $widget->{force_w} if exists $widget->{force_w}; 4572 $w = $widget->{force_w} if exists $widget->{force_w};
4497 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 4639 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
4498 glMatrixMode GL_MODELVIEW; 4640 glMatrixMode GL_MODELVIEW;
4499 glLoadIdentity; 4641 glLoadIdentity;
4500 4642
4501 { 4643 {
4502 package CFPlus::UI::Base; 4644 package DC::UI::Base;
4503 4645
4504 local ($draw_x, $draw_y, $draw_w, $draw_h) = 4646 local ($draw_x, $draw_y, $draw_w, $draw_h) =
4505 (0, 0, $self->{w}, $self->{h}); 4647 (0, 0, $self->{w}, $self->{h});
4506 4648
4507 $self->_draw; 4649 $self->_draw;
4508 } 4650 }
4509} 4651}
4510 4652
4511############################################################################# 4653#############################################################################
4512 4654
4513package CFPlus::UI; 4655package DC::UI;
4514 4656
4515$ROOT = new CFPlus::UI::Root; 4657$ROOT = new DC::UI::Root;
4516$TOOLTIP = new CFPlus::UI::Tooltip z => 900; 4658$TOOLTIP = new DC::UI::Tooltip z => 900;
4517 4659
45181 46601
4519

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines