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.430 by root, Tue Aug 21 02:39:17 2007 UTC vs.
Revision 1.458 by root, Fri Dec 28 15:05:33 2007 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 DC;
10use CFPlus::Pod; 9use DC::Pod;
11use CFPlus::Texture; 10use DC::Texture;
12 11
13our ($FOCUS, $HOVER, $GRAB); # various widgets 12our ($FOCUS, $HOVER, $GRAB); # various widgets
14 13
15our $LAYOUT; 14our $LAYOUT;
16our $ROOT; 15our $ROOT;
17our $TOOLTIP; 16our $TOOLTIP;
18our $BUTTON_STATE; 17our $BUTTON_STATE;
19 18
20our %WIDGET; # all widgets, weak-referenced 19our %WIDGET; # all widgets, weak-referenced
21 20
22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { 21our $TOOLTIP_WATCHER = EV::timer_ns 0, 0.03, sub {
22 $_[0]->stop;
23
23 if (!$GRAB) { 24 if (!$GRAB) {
24 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 25 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
25 if (length $widget->{tooltip}) { 26 if (length $widget->{tooltip}) {
26 if ($TOOLTIP->{owner} != $widget) { 27 if ($TOOLTIP->{owner} != $widget) {
27 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; 28 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
30 $TOOLTIP->{owner} = $widget; 31 $TOOLTIP->{owner} = $widget;
31 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner}; 32 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner};
32 33
33 return if $ENV{CFPLUS_DEBUG} & 8; 34 return if $ENV{CFPLUS_DEBUG} & 8;
34 35
35 my $tip = $widget->{tooltip};
36
37 $tip = $tip->($widget) if CODE:: eq ref $tip;
38
39 $TOOLTIP->set_tooltip_from ($widget); 36 $TOOLTIP->set_tooltip_from ($widget);
40 $TOOLTIP->show; 37 $TOOLTIP->show;
41 } 38 }
42 39
43 return; 40 return;
46 } 43 }
47 44
48 $TOOLTIP->hide; 45 $TOOLTIP->hide;
49 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; 46 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
50 delete $TOOLTIP->{owner}; 47 delete $TOOLTIP->{owner};
51}); 48};
52 49
53sub get_layout { 50sub get_layout {
54 my $layout; 51 my $layout;
55 52
56 for (grep { $_->{name} } values %WIDGET) { 53 for (grep { $_->{name} } values %WIDGET) {
91 my $hover = $HOVER; $HOVER = $widget; 88 my $hover = $HOVER; $HOVER = $widget;
92 89
93 $hover->update if $hover && $hover->{can_hover}; 90 $hover->update if $hover && $hover->{can_hover};
94 $HOVER->update if $HOVER && $HOVER->{can_hover}; 91 $HOVER->update if $HOVER && $HOVER->{can_hover};
95 92
96 $TOOLTIP_WATCHER->start; 93 $TOOLTIP_WATCHER->again;
97 } 94 }
98} 95}
99 96
100sub feed_sdl_button_down_event { 97sub feed_sdl_button_down_event {
101 my ($ev) = @_; 98 my ($ev) = @_;
107 my $widget = $ROOT->find_widget ($x, $y); 104 my $widget = $ROOT->find_widget ($x, $y);
108 105
109 $GRAB = $widget; 106 $GRAB = $widget;
110 $GRAB->update if $GRAB; 107 $GRAB->update if $GRAB;
111 108
112 $TOOLTIP_WATCHER->cb->(); 109 $TOOLTIP_WATCHER->invoke;
113 } 110 }
114 111
115 if ($GRAB) { 112 if ($GRAB) {
116 if ($ev->{button} == 4 || $ev->{button} == 5) { 113 if ($ev->{button} == 4 || $ev->{button} == 5) {
117 # mousewheel 114 # mousewheel
118 my $delta = $ev->{button} * 2 - 9; 115 my $delta = $ev->{button} * 2 - 9;
119 my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT; 116 my $shift = $ev->{mod} & DC::KMOD_SHIFT;
120 117
121 $ev->{dx} = $shift ? $delta : 0; 118 $ev->{dx} = $shift ? $delta : 0;
122 $ev->{dy} = $shift ? 0 : $delta; 119 $ev->{dy} = $shift ? 0 : $delta;
123 120
124 $GRAB->emit (mouse_wheel => $ev); 121 $GRAB->emit (mouse_wheel => $ev);
142 my $grab = $GRAB; undef $GRAB; 139 my $grab = $GRAB; undef $GRAB;
143 $grab->update if $grab; 140 $grab->update if $grab;
144 $GRAB->update if $GRAB; 141 $GRAB->update if $GRAB;
145 142
146 check_hover $widget; 143 check_hover $widget;
147 $TOOLTIP_WATCHER->cb->(); 144 $TOOLTIP_WATCHER->invoke;
148 } 145 }
149} 146}
150 147
151sub feed_sdl_motion_event { 148sub feed_sdl_motion_event {
152 my ($ev) = @_; 149 my ($ev) = @_;
214 reconfigure_widgets; 211 reconfigure_widgets;
215} 212}
216 213
217############################################################################# 214#############################################################################
218 215
219package CFPlus::UI::Event; 216package DC::UI::Event;
220 217
221sub xy { 218sub xy {
222 $_[1]->coord2local ($_[0]{x}, $_[0]{y}) 219 $_[1]->coord2local ($_[0]{x}, $_[0]{y})
223} 220}
224 221
225############################################################################# 222#############################################################################
226 223
227package CFPlus::UI::Base; 224package DC::UI::Base;
228 225
229use strict; 226use strict;
230 227
231use CFPlus::OpenGL; 228use DC::OpenGL;
232 229
233sub new { 230sub new {
234 my $class = shift; 231 my $class = shift;
235 232
236 my $self = bless { 233 my $self = bless {
241 h => undef, 238 h => undef,
242 can_events => 1, 239 can_events => 1,
243 @_ 240 @_
244 }, $class; 241 }, $class;
245 242
246 CFPlus::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); 243 DC::weaken ($DC::UI::WIDGET{$self+0} = $self);
247 244
248 for (keys %$self) { 245 for (keys %$self) {
249 if (/^on_(.*)$/) { 246 if (/^on_(.*)$/) {
250 $self->connect ($1 => delete $self->{$_}); 247 $self->connect ($1 => delete $self->{$_});
251 } 248 }
252 } 249 }
253 250
254 if (my $layout = $CFPlus::UI::LAYOUT->{$self->{name}}) { 251 if (my $layout = $DC::UI::LAYOUT->{$self->{name}}) {
255 $self->{x} = $layout->{x} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{x}; 252 $self->{x} = $layout->{x} * $DC::UI::ROOT->{alloc_w} if exists $layout->{x};
256 $self->{y} = $layout->{y} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{y}; 253 $self->{y} = $layout->{y} * $DC::UI::ROOT->{alloc_h} if exists $layout->{y};
257 $self->{force_w} = $layout->{w} * $CFPlus::UI::ROOT->{alloc_w} if exists $layout->{w}; 254 $self->{force_w} = $layout->{w} * $DC::UI::ROOT->{alloc_w} if exists $layout->{w};
258 $self->{force_h} = $layout->{h} * $CFPlus::UI::ROOT->{alloc_h} if exists $layout->{h}; 255 $self->{force_h} = $layout->{h} * $DC::UI::ROOT->{alloc_h} if exists $layout->{h};
259 256
260 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; 257 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x};
261 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; 258 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y};
262 259
263 $self->show if $layout->{show}; 260 $self->show if $layout->{show};
273 $self->emit ("destroy"); 270 $self->emit ("destroy");
274 %$self = (); 271 %$self = ();
275} 272}
276 273
277sub TO_JSON { 274sub TO_JSON {
278 { __w_ => $_[0]{s_id} } 275 { "\fw" => $_[0]{s_id} }
279} 276}
280 277
281sub show { 278sub show {
282 my ($self) = @_; 279 my ($self) = @_;
283 280
284 return if $self->{parent}; 281 return if $self->{parent};
285 282
286 $CFPlus::UI::ROOT->add ($self); 283 $DC::UI::ROOT->add ($self);
287} 284}
288 285
289sub set_visible { 286sub set_visible {
290 my ($self) = @_; 287 my ($self) = @_;
291 288
312 delete $self->{root}; 309 delete $self->{root};
313 310
314 undef $GRAB if $GRAB == $self; 311 undef $GRAB if $GRAB == $self;
315 undef $HOVER if $HOVER == $self; 312 undef $HOVER if $HOVER == $self;
316 313
317 $CFPlus::UI::TOOLTIP_WATCHER->cb->() 314 $DC::UI::TOOLTIP_WATCHER->invoke
318 if $TOOLTIP->{owner} == $self; 315 if $TOOLTIP->{owner} == $self;
319 316
320 $self->emit ("focus_out"); 317 $self->emit ("focus_out");
321 $self->emit (visibility_change => 0); 318 $self->emit (visibility_change => 0);
322} 319}
341sub hide { 338sub hide {
342 my ($self) = @_; 339 my ($self) = @_;
343 340
344 $self->set_invisible; 341 $self->set_invisible;
345 342
343 # extra $parent copy for 5.8.8+ bug workaround
344 # (otherwise $_[0] in remove gets freed
345 if (my $parent = $self->{parent}) {
346 $self->{parent}->remove ($self) 346 $parent->remove ($self);
347 if $self->{parent}; 347 }
348} 348}
349 349
350sub move_abs { 350sub move_abs {
351 my ($self, $x, $y, $z) = @_; 351 my ($self, $x, $y, $z) = @_;
352 352
364 $self->{force_h} = $h; 364 $self->{force_h} = $h;
365 365
366 $self->realloc; 366 $self->realloc;
367} 367}
368 368
369# traverse the widget chain up to find the maximum "physical" size constraints
370sub get_max_wh {
371 my ($self) = @_;
372
373 return $self->{parent}->get_max_wh
374 if $self->{parent};
375
376 ($::WIDTH, $::HEIGHT)
377}
378
369sub size_request { 379sub size_request {
370 require Carp; 380 require Carp;
371 Carp::confess "size_request is abstract"; 381 Carp::confess "size_request is abstract";
372} 382}
373 383
379 my ($self, $x, $y, $w, $h) = @_; 389 my ($self, $x, $y, $w, $h) = @_;
380 390
381 if ($self->{aspect}) { 391 if ($self->{aspect}) {
382 my ($ow, $oh) = ($w, $h); 392 my ($ow, $oh) = ($w, $h);
383 393
384 $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect}; 394 $w = List::Util::min $w, DC::ceil $h * $self->{aspect};
385 $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect}; 395 $h = List::Util::min $h, DC::ceil $w / $self->{aspect};
386 396
387 # use alignment to adjust x, y 397 # use alignment to adjust x, y
388 398
389 $x += int 0.5 * ($ow - $w); 399 $x += int 0.5 * ($ow - $w);
390 $y += int 0.5 * ($oh - $h); 400 $y += int 0.5 * ($oh - $h);
431 441
432 return if $self->{tooltip} eq $tooltip; 442 return if $self->{tooltip} eq $tooltip;
433 443
434 $self->{tooltip} = $tooltip; 444 $self->{tooltip} = $tooltip;
435 445
436 if ($CFPlus::UI::TOOLTIP->{owner} == $self) { 446 if ($DC::UI::TOOLTIP->{owner} == $self) {
437 delete $CFPlus::UI::TOOLTIP->{owner}; 447 delete $DC::UI::TOOLTIP->{owner};
438 $CFPlus::UI::TOOLTIP_WATCHER->cb->(); 448 $DC::UI::TOOLTIP_WATCHER->invoke;
439 } 449 }
440} 450}
441 451
442# translate global coordinates to local coordinate system 452# translate global coordinates to local coordinate system
443sub coord2local { 453sub coord2local {
444 my ($self, $x, $y) = @_; 454 my ($self, $x, $y) = @_;
445 455
446 Carp::confess unless $self->{parent};#d# 456 return (undef, undef) unless $self->{parent};
447 457
448 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) 458 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
449} 459}
450 460
451# translate local coordinates to global coordinate system 461# translate local coordinates to global coordinate system
452sub coord2global { 462sub coord2global {
453 my ($self, $x, $y) = @_; 463 my ($self, $x, $y) = @_;
454 464
455 Carp::confess unless $self->{parent};#d# 465 return (undef, undef) unless $self->{parent};
456 466
457 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) 467 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
458} 468}
459 469
460sub invoke_focus_in { 470sub invoke_focus_in {
509sub connect { 519sub connect {
510 my ($self, $signal, $cb) = @_; 520 my ($self, $signal, $cb) = @_;
511 521
512 push @{ $self->{signal_cb}{$signal} }, $cb; 522 push @{ $self->{signal_cb}{$signal} }, $cb;
513 523
514 defined wantarray and CFPlus::guard { 524 defined wantarray and DC::guard {
515 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, 525 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
516 @{ $self->{signal_cb}{$signal} }; 526 @{ $self->{signal_cb}{$signal} };
517 } 527 }
518} 528}
519 529
557# in .xs 567# in .xs
558 568
559sub set_parent { 569sub set_parent {
560 my ($self, $parent) = @_; 570 my ($self, $parent) = @_;
561 571
562 CFPlus::weaken ($self->{parent} = $parent); 572 DC::weaken ($self->{parent} = $parent);
563 $self->set_visible if $parent->{visible}; 573 $self->set_visible if $parent->{visible};
564} 574}
565 575
566sub realloc { 576sub realloc {
567 my ($self) = @_; 577 my ($self) = @_;
605} 615}
606 616
607sub DESTROY { 617sub DESTROY {
608 my ($self) = @_; 618 my ($self) = @_;
609 619
610 return if CFPlus::in_destruct; 620 return if DC::in_destruct;
611 621
612 local $@; 622 local $@;
613 eval { $self->destroy }; 623 eval { $self->destroy };
614 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 624 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
615 625
616 delete $WIDGET{$self+0}; 626 delete $WIDGET{$self+0};
617} 627}
618 628
619############################################################################# 629#############################################################################
620 630
621package CFPlus::UI::DrawBG; 631package DC::UI::DrawBG;
622 632
623our @ISA = CFPlus::UI::Base::; 633our @ISA = DC::UI::Base::;
624 634
625use strict; 635use strict;
626use CFPlus::OpenGL; 636use DC::OpenGL;
627 637
628sub new { 638sub new {
629 my $class = shift; 639 my $class = shift;
630 640
631 $class->SUPER::new ( 641 $class->SUPER::new (
653 } 663 }
654} 664}
655 665
656############################################################################# 666#############################################################################
657 667
658package CFPlus::UI::Empty; 668package DC::UI::Empty;
659 669
660our @ISA = CFPlus::UI::Base::; 670our @ISA = DC::UI::Base::;
661 671
662sub new { 672sub new {
663 my ($class, %arg) = @_; 673 my ($class, %arg) = @_;
664 $class->SUPER::new (can_events => 0, %arg); 674 $class->SUPER::new (can_events => 0, %arg);
665} 675}
672 682
673sub draw { } 683sub draw { }
674 684
675############################################################################# 685#############################################################################
676 686
677package CFPlus::UI::Container; 687package DC::UI::Container;
678 688
679our @ISA = CFPlus::UI::Base::; 689our @ISA = DC::UI::Base::;
680 690
681sub new { 691sub new {
682 my ($class, %arg) = @_; 692 my ($class, %arg) = @_;
683 693
684 my $children = delete $arg{children}; 694 my $children = delete $arg{children};
778 $_->draw for $self->visible_children; 788 $_->draw for $self->visible_children;
779} 789}
780 790
781############################################################################# 791#############################################################################
782 792
783package CFPlus::UI::Bin; 793package DC::UI::Bin;
784 794
785our @ISA = CFPlus::UI::Container::; 795our @ISA = DC::UI::Container::;
786 796
787sub new { 797sub new {
788 my ($class, %arg) = @_; 798 my ($class, %arg) = @_;
789 799
790 my $child = (delete $arg{child}) || new CFPlus::UI::Empty::; 800 my $child = (delete $arg{child}) || new DC::UI::Empty::;
791 801
792 $class->SUPER::new (children => [$child], %arg) 802 $class->SUPER::new (children => [$child], %arg)
793} 803}
794 804
795sub add { 805sub add {
802sub remove { 812sub remove {
803 my ($self, $widget) = @_; 813 my ($self, $widget) = @_;
804 814
805 $self->SUPER::remove ($widget); 815 $self->SUPER::remove ($widget);
806 816
807 $self->{children} = [new CFPlus::UI::Empty] 817 $self->{children} = [new DC::UI::Empty]
808 unless @{$self->{children}}; 818 unless @{$self->{children}};
809} 819}
810 820
811sub child { $_[0]->{children}[0] } 821sub child { $_[0]->{children}[0] }
812 822
821 831
822 1 832 1
823} 833}
824 834
825############################################################################# 835#############################################################################
826
827# back-buffered drawing area 836# back-buffered drawing area
828 837
829package CFPlus::UI::Window; 838package DC::UI::Window;
830 839
831our @ISA = CFPlus::UI::Bin::; 840our @ISA = DC::UI::Bin::;
832 841
833use CFPlus::OpenGL; 842use DC::OpenGL;
834 843
835sub new { 844sub new {
836 my ($class, %arg) = @_; 845 my ($class, %arg) = @_;
837 846
838 my $self = $class->SUPER::new (%arg); 847 my $self = $class->SUPER::new (%arg);
860} 869}
861 870
862sub render_child { 871sub render_child {
863 my ($self) = @_; 872 my ($self) = @_;
864 873
865 $self->{texture} = new_from_opengl CFPlus::Texture $self->{w}, $self->{h}, sub { 874 $self->{texture} = new_from_opengl DC::Texture $self->{w}, $self->{h}, sub {
866 glClearColor 0, 0, 0, 0; 875 glClearColor 0, 0, 0, 0;
867 glClear GL_COLOR_BUFFER_BIT; 876 glClear GL_COLOR_BUFFER_BIT;
868 877
869 { 878 {
870 package CFPlus::UI::Base; 879 package DC::UI::Base;
871 880
872 local ($draw_x, $draw_y, $draw_w, $draw_h) = 881 local ($draw_x, $draw_y, $draw_w, $draw_h) =
873 (0, 0, $self->{w}, $self->{h}); 882 (0, 0, $self->{w}, $self->{h});
874 883
875 $self->_render; 884 $self->_render;
892 glDisable GL_TEXTURE_2D; 901 glDisable GL_TEXTURE_2D;
893} 902}
894 903
895############################################################################# 904#############################################################################
896 905
897package CFPlus::UI::ViewPort; 906package DC::UI::ViewPort;
898 907
899use List::Util qw(min max); 908use List::Util qw(min max);
900 909
901our @ISA = CFPlus::UI::Window::; 910our @ISA = DC::UI::Window::;
902 911
903sub new { 912sub new {
904 my $class = shift; 913 my $class = shift;
905 914
906 $class->SUPER::new ( 915 $class->SUPER::new (
990 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 999 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
991 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1000 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
992 ) { 1001 ) {
993 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) 1002 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
994 } else { 1003 } else {
995 $self->CFPlus::UI::Base::find_widget ($x, $y) 1004 $self->DC::UI::Base::find_widget ($x, $y)
996 } 1005 }
997} 1006}
998 1007
999sub _render { 1008sub _render {
1000 my ($self) = @_; 1009 my ($self) = @_;
1001 1010
1002 local $CFPlus::UI::Base::draw_x = $CFPlus::UI::Base::draw_x - $self->{view_x}; 1011 local $DC::UI::Base::draw_x = $DC::UI::Base::draw_x - $self->{view_x};
1003 local $CFPlus::UI::Base::draw_y = $CFPlus::UI::Base::draw_y - $self->{view_y}; 1012 local $DC::UI::Base::draw_y = $DC::UI::Base::draw_y - $self->{view_y};
1004 1013
1005 CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 1014 DC::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
1006 1015
1007 $self->SUPER::_render; 1016 $self->SUPER::_render;
1008} 1017}
1009 1018
1010############################################################################# 1019#############################################################################
1011 1020
1012package CFPlus::UI::ScrolledWindow; 1021package DC::UI::ScrolledWindow;
1013 1022
1014our @ISA = CFPlus::UI::Table::; 1023our @ISA = DC::UI::Table::;
1015 1024
1016sub new { 1025sub new {
1017 my ($class, %arg) = @_; 1026 my ($class, %arg) = @_;
1018 1027
1019 my $child = delete $arg{child}; 1028 my $child = delete $arg{child};
1020 1029
1021 my $self; 1030 my $self;
1022 1031
1023 my $hslider = new CFPlus::UI::Slider 1032 my $hslider = new DC::UI::Slider
1024 c_col => 0, 1033 c_col => 0,
1025 c_row => 1, 1034 c_row => 1,
1026 vertical => 0, 1035 vertical => 0,
1027 range => [0, 0, 1, 0.01], # HACK fix 1036 range => [0, 0, 1, 0.01], # HACK fix
1028 on_changed => sub { 1037 on_changed => sub {
1029 $self->{hpos} = $_[1]; 1038 $self->{hpos} = $_[1];
1030 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1039 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1031 }, 1040 },
1032 ; 1041 ;
1033 1042
1034 my $vslider = new CFPlus::UI::Slider 1043 my $vslider = new DC::UI::Slider
1035 c_col => 1, 1044 c_col => 1,
1036 c_row => 0, 1045 c_row => 0,
1037 vertical => 1, 1046 vertical => 1,
1038 range => [0, 0, 1, 0.01], # HACK fix 1047 range => [0, 0, 1, 0.01], # HACK fix
1039 on_changed => sub { 1048 on_changed => sub {
1051 col_expand => [1, 0], 1060 col_expand => [1, 0],
1052 row_expand => [1, 0], 1061 row_expand => [1, 0],
1053 %arg, 1062 %arg,
1054 ); 1063 );
1055 1064
1056 $self->{vp} = new CFPlus::UI::ViewPort 1065 $self->{vp} = new DC::UI::ViewPort
1057 c_col => 0, 1066 c_col => 0,
1058 c_row => 0, 1067 c_row => 0,
1059 expand => 1, 1068 expand => 1,
1060 scroll_x => $self->{scroll_x}, 1069 scroll_x => $self->{scroll_x},
1061 scroll_y => $self->{scroll_y}, 1070 scroll_y => $self->{scroll_y},
1187 $self->SUPER::invoke_size_allocate ($w, $h) 1196 $self->SUPER::invoke_size_allocate ($w, $h)
1188} 1197}
1189 1198
1190############################################################################# 1199#############################################################################
1191 1200
1192package CFPlus::UI::Frame; 1201package DC::UI::Frame;
1193 1202
1194our @ISA = CFPlus::UI::Bin::; 1203our @ISA = DC::UI::Bin::;
1195 1204
1196use CFPlus::OpenGL; 1205use DC::OpenGL;
1197 1206
1198sub new { 1207sub new {
1199 my $class = shift; 1208 my $class = shift;
1200 1209
1201 $class->SUPER::new ( 1210 $class->SUPER::new (
1220 $self->SUPER::_draw; 1229 $self->SUPER::_draw;
1221} 1230}
1222 1231
1223############################################################################# 1232#############################################################################
1224 1233
1225package CFPlus::UI::FancyFrame; 1234package DC::UI::FancyFrame;
1226 1235
1227our @ISA = CFPlus::UI::Bin::; 1236our @ISA = DC::UI::Bin::;
1228 1237
1229use CFPlus::OpenGL; 1238use DC::OpenGL;
1230 1239
1231sub new { 1240sub new {
1232 my ($class, %arg) = @_; 1241 my ($class, %arg) = @_;
1233 1242
1234 if ((exists $arg{label}) && !ref $arg{label}) { 1243 if ((exists $arg{label}) && !ref $arg{label}) {
1235 $arg{label} = new CFPlus::UI::Label 1244 $arg{label} = new DC::UI::Label
1236 align => 1, 1245 align => 1,
1237 valign => 0, 1246 valign => 0,
1238 text => $arg{label}, 1247 text => $arg{label},
1239 fontsize => ($arg{border} || 0.8) * 0.75; 1248 fontsize => ($arg{border} || 0.8) * 0.75;
1240 } 1249 }
1252 1261
1253sub add { 1262sub add {
1254 my ($self, @widgets) = @_; 1263 my ($self, @widgets) = @_;
1255 1264
1256 $self->SUPER::add (@widgets); 1265 $self->SUPER::add (@widgets);
1257 $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label}; 1266 $self->DC::UI::Container::add ($self->{label}) if $self->{label};
1258} 1267}
1259 1268
1260sub border { 1269sub border {
1261 int $_[0]{border} * $::FONTSIZE 1270 int $_[0]{border} * $::FONTSIZE
1262} 1271}
1320 } 1329 }
1321} 1330}
1322 1331
1323############################################################################# 1332#############################################################################
1324 1333
1325package CFPlus::UI::Toplevel; 1334package DC::UI::Toplevel;
1326 1335
1327our @ISA = CFPlus::UI::Bin::; 1336our @ISA = DC::UI::Bin::;
1328 1337
1329use CFPlus::OpenGL; 1338use DC::OpenGL;
1330 1339
1331my $bg = 1340my $bg =
1332 new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", 1341 new_from_file DC::Texture DC::find_rcfile "d1_bg.png",
1333 mipmap => 1, wrap => 1; 1342 mipmap => 1, wrap => 1;
1334 1343
1335my @border = 1344my @border =
1336 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1345 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
1337 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1346 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1338 1347
1339my @icon = 1348my @icon =
1340 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1349 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
1341 qw(x1_move.png x1_resize.png); 1350 qw(x1_move.png x1_resize.png);
1342 1351
1343sub new { 1352sub new {
1344 my ($class, %arg) = @_; 1353 my ($class, %arg) = @_;
1345 1354
1351 min_w => 64, 1360 min_w => 64,
1352 min_h => 32, 1361 min_h => 32,
1353 %arg, 1362 %arg,
1354 ); 1363 );
1355 1364
1356 $self->{title_widget} = new CFPlus::UI::Label 1365 $self->{title_widget} = new DC::UI::Label
1357 align => 0, 1366 align => 0,
1358 valign => 1, 1367 valign => 1,
1359 text => $self->{title}, 1368 text => $self->{title},
1360 fontsize => $self->{border}, 1369 fontsize => $self->{border},
1361 if exists $self->{title}; 1370 if exists $self->{title};
1362 1371
1363 if ($self->{has_close_button}) { 1372 if ($self->{has_close_button}) {
1364 $self->{close_button} = 1373 $self->{close_button} =
1365 new CFPlus::UI::ImageButton 1374 new DC::UI::ImageButton
1366 path => 'x1_close.png', 1375 path => 'x1_close.png',
1367 on_activate => sub { $self->emit ("delete") }; 1376 on_activate => sub { $self->emit ("delete") };
1368 1377
1369 $self->CFPlus::UI::Container::add ($self->{close_button}); 1378 $self->DC::UI::Container::add ($self->{close_button});
1370 } 1379 }
1371 1380
1372 $self 1381 $self
1373} 1382}
1374 1383
1375sub add { 1384sub add {
1376 my ($self, @widgets) = @_; 1385 my ($self, @widgets) = @_;
1377 1386
1378 $self->SUPER::add (@widgets); 1387 $self->SUPER::add (@widgets);
1379 $self->CFPlus::UI::Container::add ($self->{close_button}) if $self->{close_button}; 1388 $self->DC::UI::Container::add ($self->{close_button}) if $self->{close_button};
1380 $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; 1389 $self->DC::UI::Container::add ($self->{title_widget}) if $self->{title_widget};
1381} 1390}
1382 1391
1383sub border { 1392sub border {
1384 int $_[0]{border} * $::FONTSIZE 1393 int $_[0]{border} * $::FONTSIZE
1394}
1395
1396sub get_max_wh {
1397 my ($self) = @_;
1398
1399 return ($self->{w}, $self->{h})
1400 if $self->{visible} && $self->{w};
1401
1402 $self->SUPER::get_max_wh
1385} 1403}
1386 1404
1387sub size_request { 1405sub size_request {
1388 my ($self) = @_; 1406 my ($self) = @_;
1389 1407
1561 if $self->{close_button}; 1579 if $self->{close_button};
1562} 1580}
1563 1581
1564############################################################################# 1582#############################################################################
1565 1583
1566package CFPlus::UI::Table; 1584package DC::UI::Table;
1567 1585
1568our @ISA = CFPlus::UI::Container::; 1586our @ISA = DC::UI::Container::;
1569 1587
1570use List::Util qw(max sum); 1588use List::Util qw(max sum);
1571 1589
1572use CFPlus::OpenGL; 1590use DC::OpenGL;
1573 1591
1574sub new { 1592sub new {
1575 my $class = shift; 1593 my $class = shift;
1576 1594
1577 $class->SUPER::new ( 1595 $class->SUPER::new (
1621 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; 1639 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)};
1622 1640
1623 my $sw = sum @w[$c .. $c + $cs - 1]; 1641 my $sw = sum @w[$c .. $c + $cs - 1];
1624 1642
1625 if ($w > $sw) { 1643 if ($w > $sw) {
1626 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; 1644 $_ += ($w - $sw) / ($_ ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1];
1627 } 1645 }
1628 } 1646 }
1629 1647
1630 # second pass, rows 1648 # second pass, rows
1631 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { 1649 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) {
1632 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; 1650 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)};
1633 1651
1634 my $sh = sum @h[$r .. $r + $rs - 1]; 1652 my $sh = sum @h[$r .. $r + $rs - 1];
1635 1653
1636 if ($h > $sh) { 1654 if ($h > $sh) {
1637 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; 1655 $_ += ($h - $sh) / ($_ ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1];
1638 } 1656 }
1639 } 1657 }
1640 1658
1641 (\@w, \@h) 1659 (\@w, \@h)
1642} 1660}
1665 @col_expand = (1) x @$ws unless @col_expand; 1683 @col_expand = (1) x @$ws unless @col_expand;
1666 my $col_expand = (sum @col_expand) || 1; 1684 my $col_expand = (sum @col_expand) || 1;
1667 1685
1668 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1686 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1669 1687
1670 CFPlus::UI::harmonize $ws; 1688 DC::UI::harmonize $ws;
1671 1689
1672 my @row_expand = @{$self->{row_expand}}; 1690 my @row_expand = @{$self->{row_expand}};
1673 @row_expand = (1) x @$ws unless @row_expand; 1691 @row_expand = (1) x @$ws unless @row_expand;
1674 my $row_expand = (sum @row_expand) || 1; 1692 my $row_expand = (sum @row_expand) || 1;
1675 1693
1676 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; 1694 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1677 1695
1678 CFPlus::UI::harmonize $hs; 1696 DC::UI::harmonize $hs;
1679 1697
1680 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } 1698 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] }
1681 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } 1699 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] }
1682 1700
1683 for my $widget ($self->children) { 1701 for my $widget ($self->children) {
1692 1 1710 1
1693} 1711}
1694 1712
1695############################################################################# 1713#############################################################################
1696 1714
1697package CFPlus::UI::Fixed; 1715package DC::UI::Fixed;
1698 1716
1699use List::Util qw(min max); 1717use List::Util qw(min max);
1700 1718
1701our @ISA = CFPlus::UI::Container::; 1719our @ISA = DC::UI::Container::;
1702 1720
1703sub _scale($$$) { 1721sub _scale($$$) {
1704 my ($rel, $val, $max) = @_; 1722 my ($rel, $val, $max) = @_;
1705 1723
1706 $rel ? $val * $max : $val 1724 $rel ? $val * $max : $val
1758 1 1776 1
1759} 1777}
1760 1778
1761############################################################################# 1779#############################################################################
1762 1780
1763package CFPlus::UI::Box; 1781package DC::UI::Box;
1764 1782
1765our @ISA = CFPlus::UI::Container::; 1783our @ISA = DC::UI::Container::;
1766 1784
1767sub size_request { 1785sub size_request {
1768 my ($self) = @_; 1786 my ($self) = @_;
1769 1787
1770 my @children = $self->visible_children; 1788 my @children = $self->visible_children;
1805 $req[$_] += $space * $children[$_]{expand} 1823 $req[$_] += $space * $children[$_]{expand}
1806 for 0 .. $#children; 1824 for 0 .. $#children;
1807 } 1825 }
1808 } 1826 }
1809 1827
1810 CFPlus::UI::harmonize \@req; 1828 DC::UI::harmonize \@req;
1811 1829
1812 my $pos = 0; 1830 my $pos = 0;
1813 for (0 .. $#children) { 1831 for (0 .. $#children) {
1814 my $alloc = $req[$_]; 1832 my $alloc = $req[$_];
1815 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); 1833 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h));
1820 1 1838 1
1821} 1839}
1822 1840
1823############################################################################# 1841#############################################################################
1824 1842
1825package CFPlus::UI::HBox; 1843package DC::UI::HBox;
1826 1844
1827our @ISA = CFPlus::UI::Box::; 1845our @ISA = DC::UI::Box::;
1828 1846
1829sub new { 1847sub new {
1830 my $class = shift; 1848 my $class = shift;
1831 1849
1832 $class->SUPER::new ( 1850 $class->SUPER::new (
1835 ) 1853 )
1836} 1854}
1837 1855
1838############################################################################# 1856#############################################################################
1839 1857
1840package CFPlus::UI::VBox; 1858package DC::UI::VBox;
1841 1859
1842our @ISA = CFPlus::UI::Box::; 1860our @ISA = DC::UI::Box::;
1843 1861
1844sub new { 1862sub new {
1845 my $class = shift; 1863 my $class = shift;
1846 1864
1847 $class->SUPER::new ( 1865 $class->SUPER::new (
1850 ) 1868 )
1851} 1869}
1852 1870
1853############################################################################# 1871#############################################################################
1854 1872
1855package CFPlus::UI::Label; 1873package DC::UI::Label;
1856 1874
1857our @ISA = CFPlus::UI::DrawBG::; 1875our @ISA = DC::UI::DrawBG::;
1858 1876
1859use CFPlus::OpenGL; 1877use DC::OpenGL;
1860 1878
1861sub new { 1879sub new {
1862 my ($class, %arg) = @_; 1880 my ($class, %arg) = @_;
1863 1881
1864 my $self = $class->SUPER::new ( 1882 my $self = $class->SUPER::new (
1869 #text => initial text 1887 #text => initial text
1870 #markup => initial narkup 1888 #markup => initial narkup
1871 #max_w => maximum pixel width 1889 #max_w => maximum pixel width
1872 #style => 0, # render flags 1890 #style => 0, # render flags
1873 ellipsise => 3, # end 1891 ellipsise => 3, # end
1874 layout => (new CFPlus::Layout), 1892 layout => (new DC::Layout),
1875 fontsize => 1, 1893 fontsize => 1,
1876 align => -1, 1894 align => -1,
1877 valign => -1, 1895 valign => -1,
1878 padding_x => 2, 1896 padding_x => 2,
1879 padding_y => 2, 1897 padding_y => 2,
1880 can_events => 0, 1898 can_events => 0,
1881 %arg 1899 %arg
1882 ); 1900 );
1883 1901
1884 if (exists $self->{template}) { 1902 if (exists $self->{template}) {
1885 my $layout = new CFPlus::Layout; 1903 my $layout = new DC::Layout;
1886 $layout->set_text (delete $self->{template}); 1904 $layout->set_text (delete $self->{template});
1887 $self->{template} = $layout; 1905 $self->{template} = $layout;
1888 } 1906 }
1889 1907
1890 if (exists $self->{markup}) { 1908 if (exists $self->{markup}) {
1946 1964
1947sub size_request { 1965sub size_request {
1948 my ($self) = @_; 1966 my ($self) = @_;
1949 1967
1950 $self->{size_req} ||= do { 1968 $self->{size_req} ||= do {
1969 my ($max_w, $max_h) = $self->get_max_wh;
1970
1951 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1971 $self->{layout}->set_font ($self->{font}) if $self->{font};
1952 $self->{layout}->set_width ($self->{max_w} || -1); 1972 $self->{layout}->set_width ($self->{max_w} || $max_w || -1);
1953 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1973 $self->{layout}->set_ellipsise ($self->{ellipsise});
1954 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1974 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1955 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1975 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1956 1976
1957 my ($w, $h) = $self->{layout}->size; 1977 my ($w, $h) = $self->{layout}->size;
2034 2054
2035 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2055 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2036 }; 2056 };
2037 2057
2038# unless ($self->{list}) { 2058# unless ($self->{list}) {
2039# $self->{list} = CFPlus::OpenGL::glGenList; 2059# $self->{list} = DC::OpenGL::glGenList;
2040# CFPlus::OpenGL::glNewList $self->{list}; 2060# DC::OpenGL::glNewList $self->{list};
2041# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2061# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2042# CFPlus::OpenGL::glEndList; 2062# DC::OpenGL::glEndList;
2043# } 2063# }
2044# 2064#
2045# CFPlus::OpenGL::glCallList $self->{list}; 2065# DC::OpenGL::glCallList $self->{list};
2046 2066
2047 $self->{layout}->draw; 2067 $self->{layout}->draw;
2048} 2068}
2049 2069
2050#sub destroy { 2070#sub destroy {
2051# my ($self) = @_; 2071# my ($self) = @_;
2052# 2072#
2053# CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; 2073# DC::OpenGL::glDeleteList delete $self->{list} if $self->{list};
2054# 2074#
2055# $self->SUPER::destroy; 2075# $self->SUPER::destroy;
2056#} 2076#}
2057 2077
2058############################################################################# 2078#############################################################################
2059 2079
2060package CFPlus::UI::EntryBase; 2080package DC::UI::EntryBase;
2061 2081
2062our @ISA = CFPlus::UI::Label::; 2082our @ISA = DC::UI::Label::;
2063 2083
2064use CFPlus::OpenGL; 2084use DC::OpenGL;
2065 2085
2066sub new { 2086sub new {
2067 my $class = shift; 2087 my $class = shift;
2068 2088
2069 $class->SUPER::new ( 2089 $class->SUPER::new (
2076 can_hover => 1, 2096 can_hover => 1,
2077 can_focus => 1, 2097 can_focus => 1,
2078 valign => 0, 2098 valign => 0,
2079 can_events => 1, 2099 can_events => 1,
2080 ellipsise => 0, 2100 ellipsise => 0,
2101 padding_x => 4,
2102 padding_y => 2,
2081 #text => ... 2103 #text => ...
2082 #hidden => "*", 2104 #hidden => "*",
2083 @_ 2105 @_
2084 ) 2106 )
2085} 2107}
2136 2158
2137 if ($uni == 8) { 2159 if ($uni == 8) {
2138 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2160 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
2139 } elsif ($uni == 127) { 2161 } elsif ($uni == 127) {
2140 substr $text, $self->{cursor}, 1, ""; 2162 substr $text, $self->{cursor}, 1, "";
2141 } elsif ($sym == CFPlus::SDLK_LEFT) { 2163 } elsif ($sym == DC::SDLK_LEFT) {
2142 --$self->{cursor} if $self->{cursor}; 2164 --$self->{cursor} if $self->{cursor};
2143 } elsif ($sym == CFPlus::SDLK_RIGHT) { 2165 } elsif ($sym == DC::SDLK_RIGHT) {
2144 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 2166 ++$self->{cursor} if $self->{cursor} < length $self->{text};
2145 } elsif ($sym == CFPlus::SDLK_HOME) { 2167 } elsif ($sym == DC::SDLK_HOME) {
2146 # what a hack 2168 # what a hack
2147 $self->{cursor} = 2169 $self->{cursor} =
2148 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ 2170 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/
2149 ? length $1 2171 ? length $1
2150 : 0; 2172 : 0;
2151 } elsif ($sym == CFPlus::SDLK_END) { 2173 } elsif ($sym == DC::SDLK_END) {
2152 # uh, again 2174 # uh, again
2153 $self->{cursor} = 2175 $self->{cursor} =
2154 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ 2176 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/
2155 ? $self->{cursor} + length $1 2177 ? $self->{cursor} + length $1
2156 : length $self->{text}; 2178 : length $self->{text};
2237 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); 2259 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
2238 } 2260 }
2239 2261
2240 glColor_premultiply @{$self->{active_fg}}; 2262 glColor_premultiply @{$self->{active_fg}};
2241 glBegin GL_LINES; 2263 glBegin GL_LINES;
2242 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; 2264 glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy};
2243 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; 2265 glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h};
2244 glEnd; 2266 glEnd;
2245 2267
2246 glLineWidth 3; 2268 glLineWidth 3;
2247 glColor @{$self->{active_outline}}; 2269 glColor @{$self->{active_outline}};
2248 glRect_lineloop 0, 0, $self->{w} - 1, $self->{h} - 1; 2270 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2249 glLineWidth 1; 2271 glLineWidth 1;
2250 2272
2251 } else { 2273 } else {
2252 glColor @{$self->{outline}}; 2274 glColor @{$self->{outline}};
2253 glTranslate .375, .375;
2254 glBegin GL_LINE_STRIP; 2275 glBegin GL_LINE_STRIP;
2255 glVertex 0, $self->{h} * .5; 2276 glVertex .5, $self->{h} * .5;
2256 glVertex 0, $self->{h} - 3; 2277 glVertex .5, $self->{h} - 2.5;
2257 glVertex $self->{w} - 1, $self->{h} - 3; 2278 glVertex $self->{w} - .5, $self->{h} - 2.5;
2258 glVertex $self->{w} - 1, $self->{h} * .5; 2279 glVertex $self->{w} - .5, $self->{h} * .5;
2259 glEnd; 2280 glEnd;
2260 } 2281 }
2261} 2282}
2262 2283
2263############################################################################# 2284#############################################################################
2264 2285
2265package CFPlus::UI::Entry; 2286package DC::UI::Entry;
2266 2287
2267our @ISA = CFPlus::UI::EntryBase::; 2288our @ISA = DC::UI::EntryBase::;
2268 2289
2269use CFPlus::OpenGL; 2290use DC::OpenGL;
2270 2291
2271sub invoke_key_down { 2292sub invoke_key_down {
2272 my ($self, $ev) = @_; 2293 my ($self, $ev) = @_;
2273 2294
2274 my $sym = $ev->{sym}; 2295 my $sym = $ev->{sym};
2280 $self->{history_pointer} = -1; 2301 $self->{history_pointer} = -1;
2281 $self->{history_saveback} = ''; 2302 $self->{history_saveback} = '';
2282 $self->emit (activate => $txt); 2303 $self->emit (activate => $txt);
2283 $self->update; 2304 $self->update;
2284 2305
2285 } elsif ($sym == CFPlus::SDLK_UP) { 2306 } elsif ($sym == DC::SDLK_UP) {
2286 if ($self->{history_pointer} < 0) { 2307 if ($self->{history_pointer} < 0) {
2287 $self->{history_saveback} = $self->get_text; 2308 $self->{history_saveback} = $self->get_text;
2288 } 2309 }
2289 if (@{$self->{history} || []} > 0) { 2310 if (@{$self->{history} || []} > 0) {
2290 $self->{history_pointer}++; 2311 $self->{history_pointer}++;
2292 $self->{history_pointer} = @{$self->{history} || []} - 1; 2313 $self->{history_pointer} = @{$self->{history} || []} - 1;
2293 } 2314 }
2294 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2315 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2295 } 2316 }
2296 2317
2297 } elsif ($sym == CFPlus::SDLK_DOWN) { 2318 } elsif ($sym == DC::SDLK_DOWN) {
2298 $self->{history_pointer}--; 2319 $self->{history_pointer}--;
2299 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2320 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
2300 2321
2301 if ($self->{history_pointer} >= 0) { 2322 if ($self->{history_pointer} >= 0) {
2302 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2323 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2311 1 2332 1
2312} 2333}
2313 2334
2314############################################################################# 2335#############################################################################
2315 2336
2316package CFPlus::UI::TextEdit; 2337package DC::UI::TextEdit;
2317 2338
2318our @ISA = CFPlus::UI::EntryBase::; 2339our @ISA = DC::UI::EntryBase::;
2319 2340
2320use CFPlus::OpenGL; 2341use DC::OpenGL;
2342
2343sub new {
2344 my $class = shift;
2345
2346 $class->SUPER::new (
2347 padding_y => 4,
2348
2349 @_
2350 )
2351}
2321 2352
2322sub move_cursor_ver { 2353sub move_cursor_ver {
2323 my ($self, $dy) = @_; 2354 my ($self, $dy) = @_;
2324 2355
2325 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2356 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2326 2357
2327 $y += $dy; 2358 $line += $dy;
2328 2359
2329 if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { 2360 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) {
2330 $self->{cursor} = $index; 2361 $self->{cursor} = $index;
2331 delete $self->{cur_h}; 2362 delete $self->{cur_h};
2332 $self->update; 2363 $self->update;
2333 return; 2364 return;
2334 } 2365 }
2337sub invoke_key_down { 2368sub invoke_key_down {
2338 my ($self, $ev) = @_; 2369 my ($self, $ev) = @_;
2339 2370
2340 my $sym = $ev->{sym}; 2371 my $sym = $ev->{sym};
2341 2372
2342 if ($sym == CFPlus::SDLK_UP) { 2373 if ($sym == DC::SDLK_UP) {
2343 $self->move_cursor_ver (-1); 2374 $self->move_cursor_ver (-1);
2344 } elsif ($sym == CFPlus::SDLK_DOWN) { 2375 } elsif ($sym == DC::SDLK_DOWN) {
2345 $self->move_cursor_ver (+1); 2376 $self->move_cursor_ver (+1);
2346 } else { 2377 } else {
2347 return $self->SUPER::invoke_key_down ($ev) 2378 return $self->SUPER::invoke_key_down ($ev)
2348 } 2379 }
2349 2380
2350 1 2381 1
2351} 2382}
2352 2383
2353############################################################################# 2384#############################################################################
2354 2385
2355package CFPlus::UI::ButtonBin; 2386package DC::UI::ButtonBin;
2356 2387
2357our @ISA = CFPlus::UI::Bin::; 2388our @ISA = DC::UI::Bin::;
2358 2389
2359use CFPlus::OpenGL; 2390use DC::OpenGL;
2360 2391
2361my @tex = 2392my @tex =
2362 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2393 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2363 qw(b1_button_inactive.png b1_button_active.png); 2394 qw(b1_button_inactive.png b1_button_active.png);
2364 2395
2365sub new { 2396sub new {
2366 my $class = shift; 2397 my $class = shift;
2367 2398
2399 $self->SUPER::_draw; 2430 $self->SUPER::_draw;
2400} 2431}
2401 2432
2402############################################################################# 2433#############################################################################
2403 2434
2404package CFPlus::UI::Button; 2435package DC::UI::Button;
2405 2436
2406our @ISA = CFPlus::UI::Label::; 2437our @ISA = DC::UI::Label::;
2407 2438
2408use CFPlus::OpenGL; 2439use DC::OpenGL;
2409 2440
2410my @tex = 2441my @tex =
2411 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2442 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2412 qw(b1_button_inactive.png b1_button_active.png); 2443 qw(b1_button_inactive.png b1_button_active.png);
2413 2444
2414sub new { 2445sub new {
2415 my $class = shift; 2446 my $class = shift;
2416 2447
2417 $class->SUPER::new ( 2448 $class->SUPER::new (
2418 padding_x => 4, 2449 padding_x => 8,
2419 padding_y => 4, 2450 padding_y => 4,
2420 fg => [1.0, 1.0, 1.0], 2451 fg => [1.0, 1.0, 1.0],
2421 active_fg => [0.8, 0.8, 0.8], 2452 active_fg => [0.8, 0.8, 0.8],
2422 can_hover => 1, 2453 can_hover => 1,
2423 align => 0, 2454 align => 0,
2454 $self->SUPER::_draw; 2485 $self->SUPER::_draw;
2455} 2486}
2456 2487
2457############################################################################# 2488#############################################################################
2458 2489
2459package CFPlus::UI::CheckBox; 2490package DC::UI::CheckBox;
2460 2491
2461our @ISA = CFPlus::UI::DrawBG::; 2492our @ISA = DC::UI::DrawBG::;
2462 2493
2463my @tex = 2494my @tex =
2464 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2495 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2465 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2496 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2466 2497
2467use CFPlus::OpenGL; 2498use DC::OpenGL;
2468 2499
2469sub new { 2500sub new {
2470 my $class = shift; 2501 my $class = shift;
2471 2502
2472 $class->SUPER::new ( 2503 $class->SUPER::new (
2512sub _draw { 2543sub _draw {
2513 my ($self) = @_; 2544 my ($self) = @_;
2514 2545
2515 $self->SUPER::_draw; 2546 $self->SUPER::_draw;
2516 2547
2517 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; 2548 glTranslate $self->{padding_x}, $self->{padding_y}, 0;
2518 2549
2519 my ($w, $h) = @$self{qw(w h)}; 2550 my ($w, $h) = @$self{qw(w h)};
2520 2551
2521 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; 2552 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2522 2553
2529 glDisable GL_TEXTURE_2D; 2560 glDisable GL_TEXTURE_2D;
2530} 2561}
2531 2562
2532############################################################################# 2563#############################################################################
2533 2564
2534package CFPlus::UI::Image; 2565package DC::UI::Image;
2535 2566
2536our @ISA = CFPlus::UI::Base::; 2567our @ISA = DC::UI::Base::;
2537 2568
2538use CFPlus::OpenGL; 2569use DC::OpenGL;
2539 2570
2540our %texture_cache; 2571our %texture_cache;
2541 2572
2542sub new { 2573sub new {
2543 my $class = shift; 2574 my $class = shift;
2550 2581
2551 $self->{path} || $self->{tex} 2582 $self->{path} || $self->{tex}
2552 or Carp::croak "'path' or 'tex' attributes required"; 2583 or Carp::croak "'path' or 'tex' attributes required";
2553 2584
2554 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2585 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2555 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; 2586 new_from_file DC::Texture DC::find_rcfile $self->{path}, mipmap => 1;
2556 2587
2557 CFPlus::weaken $texture_cache{$self->{path}}; 2588 DC::weaken $texture_cache{$self->{path}};
2558 2589
2559 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2590 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2560 2591
2561 $self 2592 $self
2562} 2593}
2563 2594
2564sub STORABLE_freeze { 2595sub STORABLE_freeze {
2565 my ($self, $cloning) = @_; 2596 my ($self, $cloning) = @_;
2566 2597
2567 $self->{path} 2598 $self->{path}
2568 or die "cannot serialise CFPlus::UI::Image on non-loadable images\n"; 2599 or die "cannot serialise DC::UI::Image on non-loadable images\n";
2569 2600
2570 $self->{path} 2601 $self->{path}
2571} 2602}
2572 2603
2573sub STORABLE_attach { 2604sub STORABLE_attach {
2604 glDisable GL_TEXTURE_2D; 2635 glDisable GL_TEXTURE_2D;
2605} 2636}
2606 2637
2607############################################################################# 2638#############################################################################
2608 2639
2609package CFPlus::UI::ImageButton; 2640package DC::UI::ImageButton;
2610 2641
2611our @ISA = CFPlus::UI::Image::; 2642our @ISA = DC::UI::Image::;
2612 2643
2613use CFPlus::OpenGL; 2644use DC::OpenGL;
2614 2645
2615my %textures; 2646my %textures;
2616 2647
2617sub new { 2648sub new {
2618 my $class = shift; 2649 my $class = shift;
2646 1 2677 1
2647} 2678}
2648 2679
2649############################################################################# 2680#############################################################################
2650 2681
2651package CFPlus::UI::VGauge; 2682package DC::UI::VGauge;
2652 2683
2653our @ISA = CFPlus::UI::Base::; 2684our @ISA = DC::UI::Base::;
2654 2685
2655use List::Util qw(min max); 2686use List::Util qw(min max);
2656 2687
2657use CFPlus::OpenGL; 2688use DC::OpenGL;
2658 2689
2659my %tex = ( 2690my %tex = (
2660 food => [ 2691 food => [
2661 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2692 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2662 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2693 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2663 ], 2694 ],
2664 grace => [ 2695 grace => [
2665 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2696 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2666 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2697 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2667 ], 2698 ],
2668 hp => [ 2699 hp => [
2669 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2700 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2670 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2701 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2671 ], 2702 ],
2672 mana => [ 2703 mana => [
2673 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2704 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2674 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2705 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2675 ], 2706 ],
2676); 2707);
2677 2708
2678# eg. VGauge->new (gauge => 'food'), default gauge: food 2709# eg. VGauge->new (gauge => 'food'), default gauge: food
2781 glDisable GL_TEXTURE_2D; 2812 glDisable GL_TEXTURE_2D;
2782} 2813}
2783 2814
2784############################################################################# 2815#############################################################################
2785 2816
2786package CFPlus::UI::Progress; 2817package DC::UI::Progress;
2787 2818
2788our @ISA = CFPlus::UI::Label::; 2819our @ISA = DC::UI::Label::;
2789 2820
2790use CFPlus::OpenGL; 2821use DC::OpenGL;
2791 2822
2792sub new { 2823sub new {
2793 my ($class, %arg) = @_; 2824 my ($class, %arg) = @_;
2794 2825
2795 my $self = $class->SUPER::new ( 2826 my $self = $class->SUPER::new (
2800 fontsize => 0.9, 2831 fontsize => 0.9,
2801 valign => 0, 2832 valign => 0,
2802 align => 0, 2833 align => 0,
2803 can_events => 1, 2834 can_events => 1,
2804 ellipsise => 1, 2835 ellipsise => 1,
2836 label => "%d%%",
2805 %arg, 2837 %arg,
2806 text => "-",
2807 value => -1,
2808 ); 2838 );
2809 2839
2810 $self->set_value ($arg{value}) if exists $arg{value}; 2840 $self->set_value ($arg{value} || -1);
2811 2841
2812 $self 2842 $self
2843}
2844
2845sub set_label {
2846 my ($self, $label) = @_;
2847
2848 return if $self->{label} eq $label;
2849 $self->{label} = $label;
2850
2851 $self->DC::UI::Progress::set_value (0 + delete $self->{value});
2813} 2852}
2814 2853
2815sub set_value { 2854sub set_value {
2816 my ($self, $value) = @_; 2855 my ($self, $value) = @_;
2817 2856
2818 if ($self->{value} != $value) { 2857 if ($self->{value} ne $value) {
2819 $self->{value} = $value; 2858 $self->{value} = $value;
2859
2860 if ($value < 0) {
2861 $self->set_text ("-");
2862 } else {
2820 $self->set_text (sprintf "%d%%", $value * 100); 2863 $self->set_text (sprintf $self->{label}, $value * 100);
2864 }
2865
2821 $self->update; 2866 $self->update;
2822 } 2867 }
2823} 2868}
2824 2869
2825sub _draw { 2870sub _draw {
2827 2872
2828 glEnable GL_BLEND; 2873 glEnable GL_BLEND;
2829 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2874 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2830 2875
2831 if ($self->{value} >= 0) { 2876 if ($self->{value} >= 0) {
2832 my $s = 3 + ($self->{w} - 6) * $self->{value}; 2877 my $s = int 2 + ($self->{w} - 4) * $self->{value};
2833 2878
2834 glColor_premultiply @{$self->{bar}}; 2879 glColor_premultiply @{$self->{bar}};
2835 glRect 2, 2, $s, $self->{h} - 2; 2880 glRect 2, 2, $s, $self->{h} - 2;
2836 glColor_premultiply @{$self->{bg}}; 2881 glColor_premultiply @{$self->{bg}};
2837 glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2; 2882 glRect $s, 2, $self->{w} - 2, $self->{h} - 2;
2838 } 2883 }
2839 2884
2840 glColor_premultiply @{$self->{outline}}; 2885 glColor_premultiply @{$self->{outline}};
2841 glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2; 2886 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2842 2887
2843 glDisable GL_BLEND; 2888 glDisable GL_BLEND;
2844 2889
2845 { 2890 {
2846 local $self->{bg}; # do not draw background 2891 local $self->{bg}; # do not draw background
2848 } 2893 }
2849} 2894}
2850 2895
2851############################################################################# 2896#############################################################################
2852 2897
2853package CFPlus::UI::ExperienceProgress; 2898package DC::UI::ExperienceProgress;
2854 2899
2855our @ISA = CFPlus::UI::Progress::; 2900our @ISA = DC::UI::Progress::;
2856 2901
2857sub new { 2902sub new {
2858 my ($class, %arg) = @_; 2903 my ($class, %arg) = @_;
2859 2904
2860 my $self = $class->SUPER::new ( 2905 my $self = $class->SUPER::new (
2906 tooltip => sub {
2907 my ($self) = @_;
2908
2909 sprintf "level %d\n%s points\n%s next level\n%s to go",
2910 $self->{lvl},
2911 ::formsep ($self->{exp}),
2912 ::formsep ($self->{nxt}),
2913 ::formsep ($self->{nxt} - $self->{exp}),
2914 },
2861 %arg 2915 %arg
2862 ); 2916 );
2863 2917
2864 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } 2918 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2865 if $::CONN; 2919 if $::CONN;
2877} 2931}
2878 2932
2879sub set_value { 2933sub set_value {
2880 my ($self, $lvl, $exp) = @_; 2934 my ($self, $lvl, $exp) = @_;
2881 2935
2936 $self->{lvl} = $lvl;
2937 $self->{exp} = $exp;
2938
2882 my $v = 0; 2939 my $v = -1;
2883 2940
2884 if ($::CONN && (my $table = $::CONN->{exp_table})) { 2941 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2885 my $l0 = $table->[$lvl - 1]; 2942 my $l0 = $table->[$lvl - 1];
2886 my $l1 = $table->[$lvl]; 2943 my $l1 = $table->[$lvl];
2887 2944
2945 $self->{nxt} = $l1;
2946
2888 $v = ($exp - $l0) / ($l1 - $l0); 2947 $v = ($exp - $l0) / ($l1 - $l0);
2889 } 2948 }
2890 2949
2891 $self->SUPER::set_value ($v); 2950 $self->SUPER::set_value ($v);
2892} 2951}
2893 2952
2894############################################################################# 2953#############################################################################
2895 2954
2896package CFPlus::UI::Gauge; 2955package DC::UI::Gauge;
2897 2956
2898our @ISA = CFPlus::UI::VBox::; 2957our @ISA = DC::UI::VBox::;
2899 2958
2900sub new { 2959sub new {
2901 my ($class, %arg) = @_; 2960 my ($class, %arg) = @_;
2902 2961
2903 my $self = $class->SUPER::new ( 2962 my $self = $class->SUPER::new (
2905 can_hover => 1, 2964 can_hover => 1,
2906 can_events => 1, 2965 can_events => 1,
2907 %arg, 2966 %arg,
2908 ); 2967 );
2909 2968
2910 $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999"); 2969 $self->add ($self->{value} = new DC::UI::Label valign => +1, align => 0, template => "999");
2911 $self->add ($self->{gauge} = new CFPlus::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 2970 $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
2912 $self->add ($self->{max} = new CFPlus::UI::Label valign => -1, align => 0, template => "999"); 2971 $self->add ($self->{max} = new DC::UI::Label valign => -1, align => 0, template => "999");
2913 2972
2914 $self 2973 $self
2915} 2974}
2916 2975
2917sub set_fontsize { 2976sub set_fontsize {
2938 $self->{value}->set_text ($val); 2997 $self->{value}->set_text ($val);
2939} 2998}
2940 2999
2941############################################################################# 3000#############################################################################
2942 3001
2943package CFPlus::UI::Slider; 3002package DC::UI::Slider;
2944 3003
2945use strict; 3004use strict;
2946 3005
2947use CFPlus::OpenGL; 3006use DC::OpenGL;
2948 3007
2949our @ISA = CFPlus::UI::DrawBG::; 3008our @ISA = DC::UI::DrawBG::;
2950 3009
2951my @tex = 3010my @tex =
2952 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ } 3011 map { new_from_file DC::Texture DC::find_rcfile $_ }
2953 qw(s1_slider.png s1_slider_bg.png); 3012 qw(s1_slider.png s1_slider_bg.png);
2954 3013
2955sub new { 3014sub new {
2956 my $class = shift; 3015 my $class = shift;
2957 3016
3053sub invoke_mouse_wheel { 3112sub invoke_mouse_wheel {
3054 my ($self, $ev) = @_; 3113 my ($self, $ev) = @_;
3055 3114
3056 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 3115 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
3057 3116
3058 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; 3117 my $pagepart = $ev->{mod} & DC::KMOD_SHIFT ? 1 : 0.2;
3059 3118
3060 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); 3119 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
3061 3120
3062 1 3121 1
3063} 3122}
3116 glDisable GL_TEXTURE_2D; 3175 glDisable GL_TEXTURE_2D;
3117} 3176}
3118 3177
3119############################################################################# 3178#############################################################################
3120 3179
3121package CFPlus::UI::ValSlider; 3180package DC::UI::ValSlider;
3122 3181
3123our @ISA = CFPlus::UI::HBox::; 3182our @ISA = DC::UI::HBox::;
3124 3183
3125sub new { 3184sub new {
3126 my ($class, %arg) = @_; 3185 my ($class, %arg) = @_;
3127 3186
3128 my $range = delete $arg{range}; 3187 my $range = delete $arg{range};
3129 3188
3130 my $self = $class->SUPER::new ( 3189 my $self = $class->SUPER::new (
3131 slider => (new CFPlus::UI::Slider expand => 1, range => $range), 3190 slider => (new DC::UI::Slider expand => 1, range => $range),
3132 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}), 3191 entry => (new DC::UI::Label text => "", template => delete $arg{template}),
3133 to_value => sub { shift }, 3192 to_value => sub { shift },
3134 from_value => sub { shift }, 3193 from_value => sub { shift },
3135 %arg, 3194 %arg,
3136 ); 3195 );
3137 3196
3157sub set_range { shift->{slider}->set_range (@_) } 3216sub set_range { shift->{slider}->set_range (@_) }
3158sub set_value { shift->{slider}->set_value (@_) } 3217sub set_value { shift->{slider}->set_value (@_) }
3159 3218
3160############################################################################# 3219#############################################################################
3161 3220
3162package CFPlus::UI::TextScroller; 3221package DC::UI::TextScroller;
3163 3222
3164our @ISA = CFPlus::UI::HBox::; 3223our @ISA = DC::UI::HBox::;
3165 3224
3166use CFPlus::OpenGL; 3225use DC::OpenGL;
3167 3226
3168sub new { 3227sub new {
3169 my $class = shift; 3228 my $class = shift;
3170 3229
3171 my $self = $class->SUPER::new ( 3230 my $self = $class->SUPER::new (
3173 can_events => 1, 3232 can_events => 1,
3174 indent => 0, 3233 indent => 0,
3175 #font => default_font 3234 #font => default_font
3176 @_, 3235 @_,
3177 3236
3178 layout => (new CFPlus::Layout), 3237 layout => (new DC::Layout),
3179 par => [], 3238 par => [],
3180 max_par => 0, 3239 max_par => 0,
3181 height => 0, 3240 height => 0,
3182 children => [ 3241 children => [
3183 (new CFPlus::UI::Empty expand => 1), 3242 (new DC::UI::Empty expand => 1),
3184 (new CFPlus::UI::Slider vertical => 1), 3243 (new DC::UI::Slider vertical => 1),
3185 ], 3244 ],
3186 ); 3245 );
3187 3246
3188 $self->{children}[1]->connect (changed => sub { $self->update }); 3247 $self->{children}[1]->connect (changed => sub { $self->update });
3189 3248
3372 $ROOT->on_post_alloc ($self => sub { 3431 $ROOT->on_post_alloc ($self => sub {
3373 $self->force_uptodate; 3432 $self->force_uptodate;
3374 3433
3375 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 3434 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
3376 3435
3377 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 3436 $self->{texture} ||= new_from_opengl DC::Texture $W, $H, sub {
3378 glClearColor 0, 0, 0, 0; 3437 glClearColor 0, 0, 0, 0;
3379 glClear GL_COLOR_BUFFER_BIT; 3438 glClear GL_COLOR_BUFFER_BIT;
3380 3439
3381 package CFPlus::UI::Base; 3440 package DC::UI::Base;
3382 local ($draw_x, $draw_y, $draw_w, $draw_h) = 3441 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3383 (0, 0, $self->{w}, $self->{h}); 3442 (0, 0, $self->{w}, $self->{h});
3384 3443
3385 my $top = int $self->{children}[1]{range}[0]; 3444 my $top = int $self->{children}[1]{range}[0];
3386 3445
3445 $self->{children}[1]->draw; 3504 $self->{children}[1]->draw;
3446} 3505}
3447 3506
3448############################################################################# 3507#############################################################################
3449 3508
3450package CFPlus::UI::Animator; 3509package DC::UI::Animator;
3451 3510
3452use CFPlus::OpenGL; 3511use DC::OpenGL;
3453 3512
3454our @ISA = CFPlus::UI::Bin::; 3513our @ISA = DC::UI::Bin::;
3455 3514
3456sub moveto { 3515sub moveto {
3457 my ($self, $x, $y) = @_; 3516 my ($self, $x, $y) = @_;
3458 3517
3459 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 3518 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
3487 glPopMatrix; 3546 glPopMatrix;
3488} 3547}
3489 3548
3490############################################################################# 3549#############################################################################
3491 3550
3492package CFPlus::UI::Flopper; 3551package DC::UI::Flopper;
3493 3552
3494our @ISA = CFPlus::UI::Button::; 3553our @ISA = DC::UI::Button::;
3495 3554
3496sub new { 3555sub new {
3497 my $class = shift; 3556 my $class = shift;
3498 3557
3499 my $self = $class->SUPER::new ( 3558 my $self = $class->SUPER::new (
3511 $self->{other}->toggle_visibility; 3570 $self->{other}->toggle_visibility;
3512} 3571}
3513 3572
3514############################################################################# 3573#############################################################################
3515 3574
3516package CFPlus::UI::Tooltip; 3575package DC::UI::Tooltip;
3517 3576
3518our @ISA = CFPlus::UI::Bin::; 3577our @ISA = DC::UI::Bin::;
3519 3578
3520use CFPlus::OpenGL; 3579use DC::OpenGL;
3521 3580
3522sub new { 3581sub new {
3523 my $class = shift; 3582 my $class = shift;
3524 3583
3525 $class->SUPER::new ( 3584 $class->SUPER::new (
3529} 3588}
3530 3589
3531sub set_tooltip_from { 3590sub set_tooltip_from {
3532 my ($self, $widget) = @_; 3591 my ($self, $widget) = @_;
3533 3592
3534 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3535 if $widget->{tooltip} =~ /^#(.*)$/;
3536
3537 my $tooltip = $widget->{tooltip}; 3593 my $tip = $widget->{tooltip};
3594 $tip = $tip->($widget) if "CODE" eq ref $tip;
3595
3596 $tip = DC::Pod::section_label tooltip => $1
3597 if $tip =~ /^#(.*)$/;
3538 3598
3539 if ($ENV{CFPLUS_DEBUG} & 2) { 3599 if ($ENV{CFPLUS_DEBUG} & 2) {
3540 $tooltip .= "\n\n" . (ref $widget) . "\n" 3600 $tip .= "\n\n" . (ref $widget) . "\n"
3541 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3601 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3542 . "req $widget->{req_w} $widget->{req_h}\n" 3602 . "req $widget->{req_w} $widget->{req_h}\n"
3543 . "visible $widget->{visible}"; 3603 . "visible $widget->{visible}";
3544 } 3604 }
3545 3605
3546 $tooltip =~ s/^\n+//; 3606 $tip =~ s/^\n+//;
3547 $tooltip =~ s/\n+$//; 3607 $tip =~ s/\n+$//;
3548 3608
3549 $self->add (new CFPlus::UI::Label 3609 $self->add (new DC::UI::Label
3550 markup => $tooltip, 3610 markup => $tip,
3551 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3611 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3552 fontsize => 0.8, 3612 fontsize => 0.8,
3553 style => 1, # FLAG_INVERSE 3613 style => 1, # FLAG_INVERSE
3554 ellipsise => 0, 3614 ellipsise => 0,
3555 font => ($widget->{tooltip_font} || $::FONT_PROP), 3615 font => ($widget->{tooltip_font} || $::FONT_PROP),
3593} 3653}
3594 3654
3595sub _draw { 3655sub _draw {
3596 my ($self) = @_; 3656 my ($self) = @_;
3597 3657
3598 glTranslate 0.375, 0.375;
3599
3600 my ($w, $h) = @$self{qw(w h)}; 3658 my ($w, $h) = @$self{qw(w h)};
3601 3659
3602 glColor 1, 0.8, 0.4; 3660 glColor 1, 0.8, 0.4;
3603 glRect 0, 0, $w, $h; 3661 glRect 0, 0, $w, $h;
3604 3662
3605 glColor 0, 0, 0; 3663 glColor 0, 0, 0;
3606 glRect_lineloop 0, 0, $w, $h; 3664 glRect_lineloop .5, .5, $w + .5, $h + .5;
3607 3665
3608 glTranslate 2 - 0.375, 2 - 0.375; 3666 glTranslate 2, 2;
3609 3667
3610 $self->SUPER::_draw; 3668 $self->SUPER::_draw;
3611} 3669}
3612 3670
3613############################################################################# 3671#############################################################################
3614 3672
3615package CFPlus::UI::Face; 3673package DC::UI::Face;
3616 3674
3617our @ISA = CFPlus::UI::DrawBG::; 3675our @ISA = DC::UI::DrawBG::;
3618 3676
3619use CFPlus::OpenGL; 3677use DC::OpenGL;
3620 3678
3621sub new { 3679sub new {
3622 my $class = shift; 3680 my $class = shift;
3623 3681
3624 my $self = $class->SUPER::new ( 3682 my $self = $class->SUPER::new (
3628 can_events => 0, 3686 can_events => 0,
3629 @_, 3687 @_,
3630 ); 3688 );
3631 3689
3632 if ($self->{anim} && $self->{animspeed}) { 3690 if ($self->{anim} && $self->{animspeed}) {
3633 CFPlus::weaken (my $widget = $self); 3691 DC::weaken (my $widget = $self);
3634 3692
3635 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3693 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed};
3636 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; 3694 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub {
3637 $self->{timer} = Event->timer (
3638 parked => 1,
3639 cb => sub {
3640 return unless $::CONN; 3695 return unless $::CONN;
3641 3696
3642 my $w = $widget 3697 my $w = $widget
3643 or return; 3698 or return;
3644 3699
3645 ++$w->{frame}; 3700 ++$w->{frame};
3646 $w->update_face; 3701 $w->update_face;
3647 3702
3648 # somehow, $widget can go away 3703 # somehow, $widget can go away
3649 $w->update; 3704 $w->update;
3650 $w->update_timer; 3705 $w->update_timer;
3651 },
3652 ); 3706 };
3653 3707
3654 $self->update_face; 3708 $self->update_face;
3655 $self->update_timer; 3709 $self->update_timer;
3656 } 3710 }
3657 3711
3662 my ($self) = @_; 3716 my ($self) = @_;
3663 3717
3664 return unless $self->{timer}; 3718 return unless $self->{timer};
3665 3719
3666 if ($self->{visible}) { 3720 if ($self->{visible}) {
3667 $self->{timer}->at (
3668 $self->{anim_start}
3669 + $self->{animspeed}
3670 * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed}
3671 );
3672 $self->{timer}->start; 3721 $self->{timer}->start;
3673 } else { 3722 } else {
3674 $self->{timer}->stop; 3723 $self->{timer}->stop;
3675 } 3724 }
3676} 3725}
3753 $self->SUPER::destroy; 3802 $self->SUPER::destroy;
3754} 3803}
3755 3804
3756############################################################################# 3805#############################################################################
3757 3806
3758package CFPlus::UI::Buttonbar; 3807package DC::UI::Buttonbar;
3759 3808
3760our @ISA = CFPlus::UI::HBox::; 3809our @ISA = DC::UI::HBox::;
3761 3810
3762# TODO: should actually wrap buttons and other goodies. 3811# TODO: should actually wrap buttons and other goodies.
3763 3812
3764############################################################################# 3813#############################################################################
3765 3814
3766package CFPlus::UI::Menu; 3815package DC::UI::Menu;
3767 3816
3768our @ISA = CFPlus::UI::Toplevel::; 3817our @ISA = DC::UI::Toplevel::;
3769 3818
3770use CFPlus::OpenGL; 3819use DC::OpenGL;
3771 3820
3772sub new { 3821sub new {
3773 my $class = shift; 3822 my $class = shift;
3774 3823
3775 my $self = $class->SUPER::new ( 3824 my $self = $class->SUPER::new (
3776 items => [], 3825 items => [],
3777 z => 100, 3826 z => 100,
3778 @_, 3827 @_,
3779 ); 3828 );
3780 3829
3781 $self->add ($self->{vbox} = new CFPlus::UI::VBox); 3830 $self->add ($self->{vbox} = new DC::UI::VBox);
3782 3831
3783 for my $item (@{ $self->{items} }) { 3832 for my $item (@{ $self->{items} }) {
3784 my ($widget, $cb, $tooltip) = @$item; 3833 my ($widget, $cb, $tooltip) = @$item;
3785 3834
3786 # handle various types of items, only text for now 3835 # handle various types of items, only text for now
3787 if (!ref $widget) { 3836 if (!ref $widget) {
3788 if ($widget =~ /\t/) { 3837 if ($widget =~ /\t/) {
3789 my ($left, $right) = split /\t/, $widget, 2; 3838 my ($left, $right) = split /\t/, $widget, 2;
3790 3839
3791 $widget = new CFPlus::UI::HBox 3840 $widget = new DC::UI::HBox
3792 can_hover => 1, 3841 can_hover => 1,
3793 can_events => 1, 3842 can_events => 1,
3794 tooltip => $tooltip, 3843 tooltip => $tooltip,
3795 children => [ 3844 children => [
3796 (new CFPlus::UI::Label markup => $left, expand => 1), 3845 (new DC::UI::Label markup => $left, expand => 1),
3797 (new CFPlus::UI::Label markup => $right, align => +1), 3846 (new DC::UI::Label markup => $right, align => +1),
3798 ], 3847 ],
3799 ; 3848 ;
3800 3849
3801 } else { 3850 } else {
3802 $widget = new CFPlus::UI::Label 3851 $widget = new DC::UI::Label
3803 can_hover => 1, 3852 can_hover => 1,
3804 can_events => 1, 3853 can_events => 1,
3805 markup => $widget, 3854 markup => $widget,
3806 tooltip => $tooltip; 3855 tooltip => $tooltip;
3807 } 3856 }
3855 1 3904 1
3856} 3905}
3857 3906
3858############################################################################# 3907#############################################################################
3859 3908
3860package CFPlus::UI::Multiplexer; 3909package DC::UI::Multiplexer;
3861 3910
3862our @ISA = CFPlus::UI::Container::; 3911our @ISA = DC::UI::Container::;
3863 3912
3864sub new { 3913sub new {
3865 my $class = shift; 3914 my $class = shift;
3866 3915
3867 my $self = $class->SUPER::new ( 3916 my $self = $class->SUPER::new (
3928 $self->{current}->draw; 3977 $self->{current}->draw;
3929} 3978}
3930 3979
3931############################################################################# 3980#############################################################################
3932 3981
3933package CFPlus::UI::Notebook; 3982package DC::UI::Notebook;
3934 3983
3984use DC::OpenGL;
3985
3935our @ISA = CFPlus::UI::VBox::; 3986our @ISA = DC::UI::VBox::;
3936 3987
3937sub new { 3988sub new {
3938 my $class = shift; 3989 my $class = shift;
3939 3990
3940 my $self = $class->SUPER::new ( 3991 my $self = $class->SUPER::new (
3941 buttonbar => (new CFPlus::UI::Buttonbar), 3992 buttonbar => (new DC::UI::Buttonbar),
3942 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3993 multiplexer => (new DC::UI::Multiplexer expand => 1),
3994 active_outline => [.7, .7, 0.2],
3943 # filter => # will be put between multiplexer and $self 3995 # filter => # will be put between multiplexer and $self
3944 @_, 3996 @_,
3945 ); 3997 );
3946 3998
3947 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3999 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3955 4007
3956 for my $child (@$widgets) { 4008 for my $child (@$widgets) {
3957 Scalar::Util::weaken $child; 4009 Scalar::Util::weaken $child;
3958 $child->{c_tab_} ||= do { 4010 $child->{c_tab_} ||= do {
3959 my $tab = 4011 my $tab =
3960 (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") 4012 (UNIVERSAL::isa $child->{c_tab}, "DC::UI::Base")
3961 ? $child->{c_tab} 4013 ? $child->{c_tab}
3962 : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; 4014 : new DC::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1];
3963 4015
3964 $tab->connect (activate => sub { 4016 $tab->connect (activate => sub {
3965 $wself->set_current_page ($child); 4017 $wself->set_current_page ($child);
3966 }); 4018 });
3967 4019
4021 4073
4022 $self->{multiplexer}->set_current_page ($page); 4074 $self->{multiplexer}->set_current_page ($page);
4023 $self->emit (page_changed => $self->{multiplexer}{current}); 4075 $self->emit (page_changed => $self->{multiplexer}{current});
4024} 4076}
4025 4077
4078sub _draw {
4079 my ($self) = @_;
4080
4081 $self->SUPER::_draw ();
4082
4083 if (my $cur = $self->{multiplexer}{current}) {
4084 if ($cur = $cur->{c_tab_}) {
4085 glTranslate $self->{buttonbar}{x} + $cur->{x},
4086 $self->{buttonbar}{y} + $cur->{y};
4087 glLineWidth 3;
4088 #glEnable GL_BLEND;
4089 #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
4090 glColor @{$self->{active_outline}};
4091 glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5;
4092 glLineWidth 1;
4093 #glDisable GL_BLEND;
4094 }
4095 }
4096}
4097
4026############################################################################# 4098#############################################################################
4027 4099
4028package CFPlus::UI::Selector; 4100package DC::UI::Selector;
4029 4101
4030use utf8; 4102use utf8;
4031 4103
4032our @ISA = CFPlus::UI::Button::; 4104our @ISA = DC::UI::Button::;
4033 4105
4034sub new { 4106sub new {
4035 my $class = shift; 4107 my $class = shift;
4036 4108
4037 my $self = $class->SUPER::new ( 4109 my $self = $class->SUPER::new (
4054 my ($value, $title, $tooltip) = @$_; 4126 my ($value, $title, $tooltip) = @$_;
4055 4127
4056 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 4128 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
4057 } 4129 }
4058 4130
4059 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); 4131 DC::UI::Menu->new (items => \@menu_items)->popup ($ev);
4060} 4132}
4061 4133
4062sub _set_value { 4134sub _set_value {
4063 my ($self, $value) = @_; 4135 my ($self, $value) = @_;
4064 4136
4065 my ($item) = grep $_->[0] eq $value, @{ $self->{options} } 4137 my ($item) = grep $_->[0] eq $value, @{ $self->{options} };
4138 $item ||= $self->{options}[0]
4066 or return; 4139 or return;
4067 4140
4068 $self->{value} = $item->[0]; 4141 $self->{value} = $item->[0];
4069 $self->set_markup ("$item->[1] ⇓"); 4142 $self->set_markup ("$item->[1] ⇓");
4070 $self->set_tooltip ($item->[2]); 4143# $self->set_tooltip ($item->[2]);
4071} 4144}
4072 4145
4073sub set_value { 4146sub set_value {
4074 my ($self, $value) = @_; 4147 my ($self, $value) = @_;
4075 4148
4077 4150
4078 $self->_set_value ($value); 4151 $self->_set_value ($value);
4079 $self->emit (changed => $value); 4152 $self->emit (changed => $value);
4080} 4153}
4081 4154
4155sub set_options {
4156 my ($self, $options) = @_;
4157
4158 $self->{options} = $options;
4159 $self->_set_value ($self->{value});
4160}
4161
4082############################################################################# 4162#############################################################################
4083 4163
4084package CFPlus::UI::Statusbox; 4164package DC::UI::Statusbox;
4085 4165
4086our @ISA = CFPlus::UI::VBox::; 4166our @ISA = DC::UI::VBox::;
4087 4167
4088sub new { 4168sub new {
4089 my $class = shift; 4169 my $class = shift;
4090 4170
4091 my $self = $class->SUPER::new ( 4171 my $self = $class->SUPER::new (
4092 fontsize => 0.8, 4172 fontsize => 0.8,
4093 @_, 4173 @_,
4094 ); 4174 );
4095 4175
4096 CFPlus::weaken (my $this = $self); 4176 DC::weaken (my $this = $self);
4097 4177
4098 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 4178 $self->{timer} = EV::timer 1, 1, sub { $this->reorder };
4099 4179
4100 $self 4180 $self
4101} 4181}
4102 4182
4103sub reorder { 4183sub reorder {
4104 my ($self) = @_; 4184 my ($self) = @_;
4105 my $NOW = Time::HiRes::time; 4185 my $NOW = Time::HiRes::time;
4106 4186
4107 # freeze display when hovering over any label 4187 # freeze display when hovering over any label
4108 return if $CFPlus::UI::TOOLTIP->{owner} 4188 return if $DC::UI::TOOLTIP->{owner}
4109 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label}, 4189 && grep $DC::UI::TOOLTIP->{owner} == $_->{label},
4110 values %{ $self->{item} }; 4190 values %{ $self->{item} };
4111 4191
4112 while (my ($k, $v) = each %{ $self->{item} }) { 4192 while (my ($k, $v) = each %{ $self->{item} }) {
4113 delete $self->{item}{$k} if $v->{timeout} < $NOW; 4193 delete $self->{item}{$k} if $v->{timeout} < $NOW;
4114 } 4194 }
4195
4196 $self->{timer}->set (1, 1);
4115 4197
4116 my @widgets; 4198 my @widgets;
4117 4199
4118 my @items = sort { 4200 my @items = sort {
4119 $a->{pri} <=> $b->{pri} 4201 $a->{pri} <=> $b->{pri}
4120 or $b->{id} <=> $a->{id} 4202 or $b->{id} <=> $a->{id}
4121 } values %{ $self->{item} }; 4203 } values %{ $self->{item} };
4122
4123 $self->{timer}->interval (1);
4124 4204
4125 my $count = 10 + 1; 4205 my $count = 10 + 1;
4126 for my $item (@items) { 4206 for my $item (@items) {
4127 last unless --$count; 4207 last unless --$count;
4128 4208
4135 for ($short) { 4215 for ($short) {
4136 s/^\s+//; 4216 s/^\s+//;
4137 s/\s+/ /g; 4217 s/\s+/ /g;
4138 } 4218 }
4139 4219
4140 new CFPlus::UI::Label 4220 new DC::UI::Label
4141 markup => $short, 4221 markup => $short,
4142 tooltip => $item->{tooltip}, 4222 tooltip => $item->{tooltip},
4143 tooltip_font => $::FONT_PROP, 4223 tooltip_font => $::FONT_PROP,
4144 tooltip_width => 0.67, 4224 tooltip_width => 0.67,
4145 fontsize => $item->{fontsize} || $self->{fontsize}, 4225 fontsize => $item->{fontsize} || $self->{fontsize},
4152 if ((my $diff = $item->{timeout} - $NOW) < 2) { 4232 if ((my $diff = $item->{timeout} - $NOW) < 2) {
4153 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; 4233 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2;
4154 $label->update; 4234 $label->update;
4155 $label->set_max_size (undef, $label->{req_h} * $diff) 4235 $label->set_max_size (undef, $label->{req_h} * $diff)
4156 if $diff < 1; 4236 if $diff < 1;
4157 $self->{timer}->interval (1/30); 4237 $self->{timer}->set (1/30, 1/30);
4158 } else { 4238 } else {
4159 $label->{fg}[3] = $item->{fg}[3] || 1; 4239 $label->{fg}[3] = $item->{fg}[3] || 1;
4160 } 4240 }
4161 4241
4162 push @widgets, $label; 4242 push @widgets, $label;
4224 $self->SUPER::destroy; 4304 $self->SUPER::destroy;
4225} 4305}
4226 4306
4227############################################################################# 4307#############################################################################
4228 4308
4229package CFPlus::UI::Root; 4309package DC::UI::Root;
4230 4310
4231our @ISA = CFPlus::UI::Container::; 4311our @ISA = DC::UI::Container::;
4232 4312
4233use List::Util qw(min max); 4313use List::Util qw(min max);
4234 4314
4235use CFPlus::OpenGL; 4315use DC::OpenGL;
4236 4316
4237sub new { 4317sub new {
4238 my $class = shift; 4318 my $class = shift;
4239 4319
4240 my $self = $class->SUPER::new ( 4320 my $self = $class->SUPER::new (
4241 visible => 1, 4321 visible => 1,
4242 @_, 4322 @_,
4243 ); 4323 );
4244 4324
4245 CFPlus::weaken ($self->{root} = $self); 4325 DC::weaken ($self->{root} = $self);
4246 4326
4247 $self 4327 $self
4248} 4328}
4249 4329
4250sub size_request { 4330sub size_request {
4298} 4378}
4299 4379
4300sub update { 4380sub update {
4301 my ($self) = @_; 4381 my ($self) = @_;
4302 4382
4303 $::WANT_REFRESH->start; 4383 $::WANT_REFRESH = 1;
4304} 4384}
4305 4385
4306sub add { 4386sub add {
4307 my ($self, @children) = @_; 4387 my ($self, @children) = @_;
4308 4388
4453 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 4533 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
4454 glMatrixMode GL_MODELVIEW; 4534 glMatrixMode GL_MODELVIEW;
4455 glLoadIdentity; 4535 glLoadIdentity;
4456 4536
4457 { 4537 {
4458 package CFPlus::UI::Base; 4538 package DC::UI::Base;
4459 4539
4460 local ($draw_x, $draw_y, $draw_w, $draw_h) = 4540 local ($draw_x, $draw_y, $draw_w, $draw_h) =
4461 (0, 0, $self->{w}, $self->{h}); 4541 (0, 0, $self->{w}, $self->{h});
4462 4542
4463 $self->_draw; 4543 $self->_draw;
4464 } 4544 }
4465} 4545}
4466 4546
4467############################################################################# 4547#############################################################################
4468 4548
4469package CFPlus::UI; 4549package DC::UI;
4470 4550
4471$ROOT = new CFPlus::UI::Root; 4551$ROOT = new DC::UI::Root;
4472$TOOLTIP = new CFPlus::UI::Tooltip z => 900; 4552$TOOLTIP = new DC::UI::Tooltip z => 900;
4473 4553
44741 45541
4475 4555

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines