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.447 by root, Sat Dec 22 06:50:45 2007 UTC vs.
Revision 1.472 by root, Wed Dec 24 04:09:27 2008 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 ();
7 7
8use CFPlus; 8use DC;
9use CFPlus::Pod; 9use DC::Pod;
10use CFPlus::Texture; 10use DC::Texture;
11 11
12our ($FOCUS, $HOVER, $GRAB); # various widgets 12our ($FOCUS, $HOVER, $GRAB); # various widgets
13 13
14our $LAYOUT; 14our $LAYOUT;
15our $ROOT; 15our $ROOT;
16our $TOOLTIP; 16our $TOOLTIP;
17our $BUTTON_STATE; 17our $BUTTON_STATE;
18 18
19our %WIDGET; # all widgets, weak-referenced 19our %WIDGET; # all widgets, weak-referenced
20 20
21our $TOOLTIP_WATCHER = EV::timer_ns 0, 1/60, sub { 21our $TOOLTIP_WATCHER = EV::timer_ns 0, 0.03, sub {
22 $_[0]->stop; 22 $_[0]->stop;
23 23
24 if (!$GRAB) { 24 if (!$GRAB) {
25 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 25 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
26 if (length $widget->{tooltip}) { 26 if (length $widget->{tooltip}) {
111 111
112 if ($GRAB) { 112 if ($GRAB) {
113 if ($ev->{button} == 4 || $ev->{button} == 5) { 113 if ($ev->{button} == 4 || $ev->{button} == 5) {
114 # mousewheel 114 # mousewheel
115 my $delta = $ev->{button} * 2 - 9; 115 my $delta = $ev->{button} * 2 - 9;
116 my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT; 116 my $shift = $ev->{mod} & DC::KMOD_SHIFT;
117 117
118 $ev->{dx} = $shift ? $delta : 0; 118 $ev->{dx} = $shift ? $delta : 0;
119 $ev->{dy} = $shift ? 0 : $delta; 119 $ev->{dy} = $shift ? 0 : $delta;
120 120
121 $GRAB->emit (mouse_wheel => $ev); 121 $GRAB->emit (mouse_wheel => $ev);
211 reconfigure_widgets; 211 reconfigure_widgets;
212} 212}
213 213
214############################################################################# 214#############################################################################
215 215
216package CFPlus::UI::Event; 216package DC::UI::Event;
217 217
218sub xy { 218sub xy {
219 $_[1]->coord2local ($_[0]{x}, $_[0]{y}) 219 $_[1]->coord2local ($_[0]{x}, $_[0]{y})
220} 220}
221 221
222############################################################################# 222#############################################################################
223 223
224package CFPlus::UI::Base; 224package DC::UI::Base;
225 225
226use strict; 226use strict;
227 227
228use CFPlus::OpenGL; 228use DC::OpenGL;
229 229
230sub new { 230sub new {
231 my $class = shift; 231 my $class = shift;
232 232
233 my $self = bless { 233 my $self = bless {
238 h => undef, 238 h => undef,
239 can_events => 1, 239 can_events => 1,
240 @_ 240 @_
241 }, $class; 241 }, $class;
242 242
243 CFPlus::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); 243 DC::weaken ($DC::UI::WIDGET{$self+0} = $self);
244 244
245 for (keys %$self) { 245 for (keys %$self) {
246 if (/^on_(.*)$/) { 246 if (/^on_(.*)$/) {
247 $self->connect ($1 => delete $self->{$_}); 247 $self->connect ($1 => delete $self->{$_});
248 } 248 }
249 } 249 }
250 250
251 if (my $layout = $CFPlus::UI::LAYOUT->{$self->{name}}) { 251 if (my $layout = $DC::UI::LAYOUT->{$self->{name}}) {
252 $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};
253 $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};
254 $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};
255 $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};
256 256
257 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; 257 $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x};
258 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; 258 $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y};
259 259
260 $self->show if $layout->{show}; 260 $self->show if $layout->{show};
278sub show { 278sub show {
279 my ($self) = @_; 279 my ($self) = @_;
280 280
281 return if $self->{parent}; 281 return if $self->{parent};
282 282
283 $CFPlus::UI::ROOT->add ($self); 283 $DC::UI::ROOT->add ($self);
284} 284}
285 285
286sub set_visible { 286sub set_visible {
287 my ($self) = @_; 287 my ($self) = @_;
288 288
289 return if $self->{visible}; 289 return if $self->{visible};
290
291 $self->{parent} && $self->{parent}{root}#d#
292 or return ::clienterror ("set_visible called without parent ($self->{parent}) or root\n" => 1);
290 293
291 $self->{root} = $self->{parent}{root}; 294 $self->{root} = $self->{parent}{root};
292 $self->{visible} = $self->{parent}{visible} + 1; 295 $self->{visible} = $self->{parent}{visible} + 1;
293 296
294 $self->emit (visibility_change => 1); 297 $self->emit (visibility_change => 1);
295 298
296 $self->realloc if !exists $self->{req_w}; 299 $self->realloc if !exists $self->{req_w};
297 300
298 $_->set_visible for $self->children; 301 $_->set_visible for $self->visible_children;
299} 302}
300 303
301sub set_invisible { 304sub set_invisible {
302 my ($self) = @_; 305 my ($self) = @_;
303 306
309 delete $self->{root}; 312 delete $self->{root};
310 313
311 undef $GRAB if $GRAB == $self; 314 undef $GRAB if $GRAB == $self;
312 undef $HOVER if $HOVER == $self; 315 undef $HOVER if $HOVER == $self;
313 316
314 $CFPlus::UI::TOOLTIP_WATCHER->invoke 317 $DC::UI::TOOLTIP_WATCHER->invoke
315 if $TOOLTIP->{owner} == $self; 318 if $TOOLTIP->{owner} == $self;
316 319
317 $self->emit ("focus_out"); 320 $self->emit ("focus_out");
318 $self->emit (visibility_change => 0); 321 $self->emit (visibility_change => 0);
319} 322}
338sub hide { 341sub hide {
339 my ($self) = @_; 342 my ($self) = @_;
340 343
341 $self->set_invisible; 344 $self->set_invisible;
342 345
346 # extra $parent copy for 5.8.8+ bug workaround
347 # (otherwise $_[0] in remove gets freed
348 if (my $parent = $self->{parent}) {
343 $self->{parent}->remove ($self) 349 $parent->remove ($self);
344 if $self->{parent}; 350 }
345} 351}
346 352
347sub move_abs { 353sub move_abs {
348 my ($self, $x, $y, $z) = @_; 354 my ($self, $x, $y, $z) = @_;
349 355
365 371
366# traverse the widget chain up to find the maximum "physical" size constraints 372# traverse the widget chain up to find the maximum "physical" size constraints
367sub get_max_wh { 373sub get_max_wh {
368 my ($self) = @_; 374 my ($self) = @_;
369 375
376 my ($w, $h) = @$self{qw(max_w max_h)};
377
378 if ($w <= 0 || $h <= 0) {
379 my ($mw, $mh) = $self->{parent}
370 return $self->{parent}->get_max_wh 380 ? $self->{parent}->get_max_wh
371 if $self->{parent};
372
373 ($::WIDTH, $::HEIGHT) 381 : ($::WIDTH, $::HEIGHT);
382
383 $w = $mw if $w <= 0;
384 $h = $mh if $h <= 0;
385 }
386
387 ($w, $h)
374} 388}
375 389
376sub size_request { 390sub size_request {
377 require Carp; 391 require Carp;
378 Carp::confess "size_request is abstract"; 392 Carp::confess "size_request is abstract";
386 my ($self, $x, $y, $w, $h) = @_; 400 my ($self, $x, $y, $w, $h) = @_;
387 401
388 if ($self->{aspect}) { 402 if ($self->{aspect}) {
389 my ($ow, $oh) = ($w, $h); 403 my ($ow, $oh) = ($w, $h);
390 404
391 $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect}; 405 $w = List::Util::min $w, DC::ceil $h * $self->{aspect};
392 $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect}; 406 $h = List::Util::min $h, DC::ceil $w / $self->{aspect};
393 407
394 # use alignment to adjust x, y 408 # use alignment to adjust x, y
395 409
396 $x += int 0.5 * ($ow - $w); 410 $x += int 0.5 * ($ow - $w);
397 $y += int 0.5 * ($oh - $h); 411 $y += int 0.5 * ($oh - $h);
438 452
439 return if $self->{tooltip} eq $tooltip; 453 return if $self->{tooltip} eq $tooltip;
440 454
441 $self->{tooltip} = $tooltip; 455 $self->{tooltip} = $tooltip;
442 456
443 if ($CFPlus::UI::TOOLTIP->{owner} == $self) { 457 if ($DC::UI::TOOLTIP->{owner} == $self) {
444 delete $CFPlus::UI::TOOLTIP->{owner}; 458 delete $DC::UI::TOOLTIP->{owner};
445 $CFPlus::UI::TOOLTIP_WATCHER->invoke; 459 $DC::UI::TOOLTIP_WATCHER->invoke;
446 } 460 }
447} 461}
448 462
449# translate global coordinates to local coordinate system 463# translate global coordinates to local coordinate system
450sub coord2local { 464sub coord2local {
516sub connect { 530sub connect {
517 my ($self, $signal, $cb) = @_; 531 my ($self, $signal, $cb) = @_;
518 532
519 push @{ $self->{signal_cb}{$signal} }, $cb; 533 push @{ $self->{signal_cb}{$signal} }, $cb;
520 534
521 defined wantarray and CFPlus::guard { 535 defined wantarray and DC::guard {
522 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, 536 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
523 @{ $self->{signal_cb}{$signal} }; 537 @{ $self->{signal_cb}{$signal} };
524 } 538 }
525} 539}
526 540
564# in .xs 578# in .xs
565 579
566sub set_parent { 580sub set_parent {
567 my ($self, $parent) = @_; 581 my ($self, $parent) = @_;
568 582
569 CFPlus::weaken ($self->{parent} = $parent); 583 DC::weaken ($self->{parent} = $parent);
570 $self->set_visible if $parent->{visible}; 584 $self->set_visible if $parent->{visible};
571} 585}
572 586
573sub realloc { 587sub realloc {
574 my ($self) = @_; 588 my ($self) = @_;
612} 626}
613 627
614sub DESTROY { 628sub DESTROY {
615 my ($self) = @_; 629 my ($self) = @_;
616 630
617 return if CFPlus::in_destruct; 631 return if DC::in_destruct;
618 632
619 local $@; 633 local $@;
620 eval { $self->destroy }; 634 eval { $self->destroy };
621 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 635 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
622 636
623 delete $WIDGET{$self+0}; 637 delete $WIDGET{$self+0};
624} 638}
625 639
626############################################################################# 640#############################################################################
627 641
628package CFPlus::UI::DrawBG; 642package DC::UI::DrawBG;
629 643
630our @ISA = CFPlus::UI::Base::; 644our @ISA = DC::UI::Base::;
631 645
632use strict; 646use strict;
633use CFPlus::OpenGL; 647use DC::OpenGL;
634 648
635sub new { 649sub new {
636 my $class = shift; 650 my $class = shift;
637 651
638 $class->SUPER::new ( 652 $class->SUPER::new (
660 } 674 }
661} 675}
662 676
663############################################################################# 677#############################################################################
664 678
665package CFPlus::UI::Empty; 679package DC::UI::Empty;
666 680
667our @ISA = CFPlus::UI::Base::; 681our @ISA = DC::UI::Base::;
668 682
669sub new { 683sub new {
670 my ($class, %arg) = @_; 684 my ($class, %arg) = @_;
671 $class->SUPER::new (can_events => 0, %arg); 685 $class->SUPER::new (can_events => 0, %arg);
672} 686}
679 693
680sub draw { } 694sub draw { }
681 695
682############################################################################# 696#############################################################################
683 697
684package CFPlus::UI::Container; 698package DC::UI::Container;
685 699
686our @ISA = CFPlus::UI::Base::; 700our @ISA = DC::UI::Base::;
687 701
688sub new { 702sub new {
689 my ($class, %arg) = @_; 703 my ($class, %arg) = @_;
690 704
691 my $children = delete $arg{children}; 705 my $children = delete $arg{children};
785 $_->draw for $self->visible_children; 799 $_->draw for $self->visible_children;
786} 800}
787 801
788############################################################################# 802#############################################################################
789 803
790package CFPlus::UI::Bin; 804package DC::UI::Bin;
791 805
792our @ISA = CFPlus::UI::Container::; 806our @ISA = DC::UI::Container::;
793 807
794sub new { 808sub new {
795 my ($class, %arg) = @_; 809 my ($class, %arg) = @_;
796 810
797 my $child = (delete $arg{child}) || new CFPlus::UI::Empty::; 811 my $child = (delete $arg{child}) || new DC::UI::Empty::;
798 812
799 $class->SUPER::new (children => [$child], %arg) 813 $class->SUPER::new (children => [$child], %arg)
800} 814}
801 815
802sub add { 816sub add {
809sub remove { 823sub remove {
810 my ($self, $widget) = @_; 824 my ($self, $widget) = @_;
811 825
812 $self->SUPER::remove ($widget); 826 $self->SUPER::remove ($widget);
813 827
814 $self->{children} = [new CFPlus::UI::Empty] 828 $self->{children} = [new DC::UI::Empty]
815 unless @{$self->{children}}; 829 unless @{$self->{children}};
816} 830}
817 831
818sub child { $_[0]->{children}[0] } 832sub child { $_[0]->{children}[0] }
819 833
830} 844}
831 845
832############################################################################# 846#############################################################################
833# back-buffered drawing area 847# back-buffered drawing area
834 848
835package CFPlus::UI::Window; 849package DC::UI::Window;
836 850
837our @ISA = CFPlus::UI::Bin::; 851our @ISA = DC::UI::Bin::;
838 852
839use CFPlus::OpenGL; 853use DC::OpenGL;
840 854
841sub new { 855sub new {
842 my ($class, %arg) = @_; 856 my ($class, %arg) = @_;
843 857
844 my $self = $class->SUPER::new (%arg); 858 my $self = $class->SUPER::new (%arg);
866} 880}
867 881
868sub render_child { 882sub render_child {
869 my ($self) = @_; 883 my ($self) = @_;
870 884
871 $self->{texture} = new_from_opengl CFPlus::Texture $self->{w}, $self->{h}, sub { 885 $self->{texture} = new_from_opengl DC::Texture $self->{w}, $self->{h}, sub {
872 glClearColor 0, 0, 0, 0; 886 glClearColor 0, 0, 0, 0;
873 glClear GL_COLOR_BUFFER_BIT; 887 glClear GL_COLOR_BUFFER_BIT;
874 888
875 { 889 {
876 package CFPlus::UI::Base; 890 package DC::UI::Base;
877 891
878 local ($draw_x, $draw_y, $draw_w, $draw_h) = 892 local ($draw_x, $draw_y, $draw_w, $draw_h) =
879 (0, 0, $self->{w}, $self->{h}); 893 (0, 0, $self->{w}, $self->{h});
880 894
881 $self->_render; 895 $self->_render;
898 glDisable GL_TEXTURE_2D; 912 glDisable GL_TEXTURE_2D;
899} 913}
900 914
901############################################################################# 915#############################################################################
902 916
903package CFPlus::UI::ViewPort; 917package DC::UI::ViewPort;
904 918
905use List::Util qw(min max); 919use List::Util qw(min max);
906 920
907our @ISA = CFPlus::UI::Window::; 921our @ISA = DC::UI::Window::;
908 922
909sub new { 923sub new {
910 my $class = shift; 924 my $class = shift;
911 925
912 $class->SUPER::new ( 926 $class->SUPER::new (
996 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 1010 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
997 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1011 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
998 ) { 1012 ) {
999 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) 1013 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
1000 } else { 1014 } else {
1001 $self->CFPlus::UI::Base::find_widget ($x, $y) 1015 $self->DC::UI::Base::find_widget ($x, $y)
1002 } 1016 }
1003} 1017}
1004 1018
1005sub _render { 1019sub _render {
1006 my ($self) = @_; 1020 my ($self) = @_;
1007 1021
1008 local $CFPlus::UI::Base::draw_x = $CFPlus::UI::Base::draw_x - $self->{view_x}; 1022 local $DC::UI::Base::draw_x = $DC::UI::Base::draw_x - $self->{view_x};
1009 local $CFPlus::UI::Base::draw_y = $CFPlus::UI::Base::draw_y - $self->{view_y}; 1023 local $DC::UI::Base::draw_y = $DC::UI::Base::draw_y - $self->{view_y};
1010 1024
1011 CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 1025 DC::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
1012 1026
1013 $self->SUPER::_render; 1027 $self->SUPER::_render;
1014} 1028}
1015 1029
1016############################################################################# 1030#############################################################################
1017 1031
1018package CFPlus::UI::ScrolledWindow; 1032package DC::UI::ScrolledWindow;
1019 1033
1020our @ISA = CFPlus::UI::Table::; 1034our @ISA = DC::UI::Table::;
1021 1035
1022sub new { 1036sub new {
1023 my ($class, %arg) = @_; 1037 my ($class, %arg) = @_;
1024 1038
1025 my $child = delete $arg{child}; 1039 my $child = delete $arg{child};
1026 1040
1027 my $self; 1041 my $self;
1028 1042
1029 my $hslider = new CFPlus::UI::Slider 1043 my $hslider = new DC::UI::Slider
1030 c_col => 0, 1044 c_col => 0,
1031 c_row => 1, 1045 c_row => 1,
1032 vertical => 0, 1046 vertical => 0,
1033 range => [0, 0, 1, 0.01], # HACK fix 1047 range => [0, 0, 1, 0.01], # HACK fix
1034 on_changed => sub { 1048 on_changed => sub {
1035 $self->{hpos} = $_[1]; 1049 $self->{hpos} = $_[1];
1036 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1050 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1037 }, 1051 },
1038 ; 1052 ;
1039 1053
1040 my $vslider = new CFPlus::UI::Slider 1054 my $vslider = new DC::UI::Slider
1041 c_col => 1, 1055 c_col => 1,
1042 c_row => 0, 1056 c_row => 0,
1043 vertical => 1, 1057 vertical => 1,
1044 range => [0, 0, 1, 0.01], # HACK fix 1058 range => [0, 0, 1, 0.01], # HACK fix
1045 on_changed => sub { 1059 on_changed => sub {
1057 col_expand => [1, 0], 1071 col_expand => [1, 0],
1058 row_expand => [1, 0], 1072 row_expand => [1, 0],
1059 %arg, 1073 %arg,
1060 ); 1074 );
1061 1075
1062 $self->{vp} = new CFPlus::UI::ViewPort 1076 $self->{vp} = new DC::UI::ViewPort
1063 c_col => 0, 1077 c_col => 0,
1064 c_row => 0, 1078 c_row => 0,
1065 expand => 1, 1079 expand => 1,
1066 scroll_x => $self->{scroll_x}, 1080 scroll_x => $self->{scroll_x},
1067 scroll_y => $self->{scroll_y}, 1081 scroll_y => $self->{scroll_y},
1193 $self->SUPER::invoke_size_allocate ($w, $h) 1207 $self->SUPER::invoke_size_allocate ($w, $h)
1194} 1208}
1195 1209
1196############################################################################# 1210#############################################################################
1197 1211
1198package CFPlus::UI::Frame; 1212package DC::UI::Frame;
1199 1213
1200our @ISA = CFPlus::UI::Bin::; 1214our @ISA = DC::UI::Bin::;
1201 1215
1202use CFPlus::OpenGL; 1216use DC::OpenGL;
1203 1217
1204sub new { 1218sub new {
1205 my $class = shift; 1219 my $class = shift;
1206 1220
1207 $class->SUPER::new ( 1221 $class->SUPER::new (
1226 $self->SUPER::_draw; 1240 $self->SUPER::_draw;
1227} 1241}
1228 1242
1229############################################################################# 1243#############################################################################
1230 1244
1231package CFPlus::UI::FancyFrame; 1245package DC::UI::FancyFrame;
1232 1246
1233our @ISA = CFPlus::UI::Bin::; 1247our @ISA = DC::UI::Bin::;
1234 1248
1235use CFPlus::OpenGL; 1249use DC::OpenGL;
1236 1250
1237sub new { 1251sub new {
1238 my ($class, %arg) = @_; 1252 my ($class, %arg) = @_;
1239 1253
1240 if ((exists $arg{label}) && !ref $arg{label}) { 1254 if ((exists $arg{label}) && !ref $arg{label}) {
1241 $arg{label} = new CFPlus::UI::Label 1255 $arg{label} = new DC::UI::Label
1242 align => 1, 1256 align => 1,
1243 valign => 0, 1257 valign => 0.5,
1244 text => $arg{label}, 1258 text => $arg{label},
1245 fontsize => ($arg{border} || 0.8) * 0.75; 1259 fontsize => ($arg{border} || 0.8) * 0.75;
1246 } 1260 }
1247 1261
1248 my $self = $class->SUPER::new ( 1262 my $self = $class->SUPER::new (
1249 # label => "", 1263 # label => "",
1250 fg => [0.6, 0.3, 0.1], 1264 fg => undef,
1251 border => 0.8, 1265 border => 0.8,
1252 style => 'single', 1266 style => 'single',
1253 %arg, 1267 %arg,
1254 ); 1268 );
1255 1269
1258 1272
1259sub add { 1273sub add {
1260 my ($self, @widgets) = @_; 1274 my ($self, @widgets) = @_;
1261 1275
1262 $self->SUPER::add (@widgets); 1276 $self->SUPER::add (@widgets);
1263 $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label}; 1277 $self->DC::UI::Container::add ($self->{label}) if $self->{label};
1264} 1278}
1265 1279
1266sub border { 1280sub border {
1267 int $_[0]{border} * $::FONTSIZE 1281 int $_[0]{border} * $::FONTSIZE
1268} 1282}
1308 my $border = $self->border; 1322 my $border = $self->border;
1309 my ($w, $h) = ($self->{w}, $self->{h}); 1323 my ($w, $h) = ($self->{w}, $self->{h});
1310 1324
1311 $child->draw; 1325 $child->draw;
1312 1326
1313 glColor @{$self->{fg}}; 1327 glColor @{$self->{fg} || $DC::THEME{fancyframe}};
1314 glBegin GL_LINE_STRIP; 1328 glBegin GL_LINE_STRIP;
1315 glVertex $border * 1.5 , $border * 0.5 + 0.5; 1329 glVertex $border * 1.5 , $border * 0.5 + 0.5;
1316 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; 1330 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5;
1317 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; 1331 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1318 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; 1332 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1326 } 1340 }
1327} 1341}
1328 1342
1329############################################################################# 1343#############################################################################
1330 1344
1331package CFPlus::UI::Toplevel; 1345package DC::UI::Toplevel;
1332 1346
1333our @ISA = CFPlus::UI::Bin::; 1347our @ISA = DC::UI::Bin::;
1334 1348
1335use CFPlus::OpenGL; 1349use DC::OpenGL;
1336 1350
1337my $bg = 1351my $bg =
1338 new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", 1352 new_from_resource DC::Texture "d1_bg.png",
1339 mipmap => 1, wrap => 1; 1353 mipmap => 1, wrap => 1;
1340 1354
1341my @border = 1355my @border =
1342 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1356 map { new_from_resource DC::Texture $_, mipmap => 1 }
1343 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1357 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1344 1358
1345my @icon = 1359my @icon =
1346 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1360 map { new_from_resource DC::Texture $_, mipmap => 1 }
1347 qw(x1_move.png x1_resize.png); 1361 qw(x1_move.png x1_resize.png);
1348 1362
1349sub new { 1363sub new {
1350 my ($class, %arg) = @_; 1364 my ($class, %arg) = @_;
1351 1365
1352 my $self = $class->SUPER::new ( 1366 my $self = $class->SUPER::new (
1353 bg => [1, 1, 1, 1], 1367 bg => [1, 1, 1, 1],
1354 border_bg => [1, 1, 1, 1], 1368 border_bg => [1, 1, 1, 1],
1355 border => 0.6, 1369 border => 0.8,
1356 can_events => 1, 1370 can_events => 1,
1357 min_w => 64, 1371 min_w => 64,
1358 min_h => 32, 1372 min_h => 32,
1359 %arg, 1373 %arg,
1360 ); 1374 );
1361 1375
1362 $self->{title_widget} = new CFPlus::UI::Label 1376 $self->{title_widget} = new DC::UI::Label
1363 align => 0, 1377 align => 0.5,
1364 valign => 1, 1378 valign => 1,
1365 text => $self->{title}, 1379 text => $self->{title},
1366 fontsize => $self->{border}, 1380 fontsize => $self->{border},
1367 if exists $self->{title}; 1381 if exists $self->{title};
1368 1382
1369 if ($self->{has_close_button}) { 1383 if ($self->{has_close_button}) {
1370 $self->{close_button} = 1384 $self->{close_button} =
1371 new CFPlus::UI::ImageButton 1385 new DC::UI::ImageButton
1372 path => 'x1_close.png', 1386 path => 'x1_close.png',
1373 on_activate => sub { $self->emit ("delete") }; 1387 on_activate => sub { $self->emit ("delete") };
1374 1388
1375 $self->CFPlus::UI::Container::add ($self->{close_button}); 1389 $self->DC::UI::Container::add ($self->{close_button});
1376 } 1390 }
1377 1391
1378 $self 1392 $self
1379} 1393}
1380 1394
1381sub add { 1395sub add {
1382 my ($self, @widgets) = @_; 1396 my ($self, @widgets) = @_;
1383 1397
1384 $self->SUPER::add (@widgets); 1398 $self->SUPER::add (@widgets);
1385 $self->CFPlus::UI::Container::add ($self->{close_button}) if $self->{close_button}; 1399 $self->DC::UI::Container::add ($self->{close_button}) if $self->{close_button};
1386 $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; 1400 $self->DC::UI::Container::add ($self->{title_widget}) if $self->{title_widget};
1387} 1401}
1388 1402
1389sub border { 1403sub border {
1390 int $_[0]{border} * $::FONTSIZE 1404 int $_[0]{border} * $::FONTSIZE
1391} 1405}
1576 if $self->{close_button}; 1590 if $self->{close_button};
1577} 1591}
1578 1592
1579############################################################################# 1593#############################################################################
1580 1594
1581package CFPlus::UI::Table; 1595package DC::UI::Table;
1582 1596
1583our @ISA = CFPlus::UI::Container::; 1597our @ISA = DC::UI::Container::;
1584 1598
1585use List::Util qw(max sum); 1599use List::Util qw(max sum);
1586 1600
1587use CFPlus::OpenGL; 1601use DC::OpenGL;
1588 1602
1589sub new { 1603sub new {
1590 my $class = shift; 1604 my $class = shift;
1591 1605
1592 $class->SUPER::new ( 1606 $class->SUPER::new (
1636 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; 1650 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)};
1637 1651
1638 my $sw = sum @w[$c .. $c + $cs - 1]; 1652 my $sw = sum @w[$c .. $c + $cs - 1];
1639 1653
1640 if ($w > $sw) { 1654 if ($w > $sw) {
1641 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; 1655 $_ += ($w - $sw) / ($_ ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1];
1642 } 1656 }
1643 } 1657 }
1644 1658
1645 # second pass, rows 1659 # second pass, rows
1646 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { 1660 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) {
1647 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; 1661 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)};
1648 1662
1649 my $sh = sum @h[$r .. $r + $rs - 1]; 1663 my $sh = sum @h[$r .. $r + $rs - 1];
1650 1664
1651 if ($h > $sh) { 1665 if ($h > $sh) {
1652 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; 1666 $_ += ($h - $sh) / ($_ ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1];
1653 } 1667 }
1654 } 1668 }
1655 1669
1656 (\@w, \@h) 1670 (\@w, \@h)
1657} 1671}
1680 @col_expand = (1) x @$ws unless @col_expand; 1694 @col_expand = (1) x @$ws unless @col_expand;
1681 my $col_expand = (sum @col_expand) || 1; 1695 my $col_expand = (sum @col_expand) || 1;
1682 1696
1683 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1697 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1684 1698
1685 CFPlus::UI::harmonize $ws; 1699 DC::UI::harmonize $ws;
1686 1700
1687 my @row_expand = @{$self->{row_expand}}; 1701 my @row_expand = @{$self->{row_expand}};
1688 @row_expand = (1) x @$ws unless @row_expand; 1702 @row_expand = (1) x @$ws unless @row_expand;
1689 my $row_expand = (sum @row_expand) || 1; 1703 my $row_expand = (sum @row_expand) || 1;
1690 1704
1691 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; 1705 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1692 1706
1693 CFPlus::UI::harmonize $hs; 1707 DC::UI::harmonize $hs;
1694 1708
1695 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } 1709 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] }
1696 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } 1710 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] }
1697 1711
1698 for my $widget ($self->children) { 1712 for my $widget ($self->children) {
1707 1 1721 1
1708} 1722}
1709 1723
1710############################################################################# 1724#############################################################################
1711 1725
1712package CFPlus::UI::Fixed; 1726package DC::UI::Fixed;
1713 1727
1714use List::Util qw(min max); 1728use List::Util qw(min max);
1715 1729
1716our @ISA = CFPlus::UI::Container::; 1730our @ISA = DC::UI::Container::;
1717 1731
1718sub _scale($$$) { 1732sub _scale($$$) {
1719 my ($rel, $val, $max) = @_; 1733 my ($rel, $val, $max) = @_;
1720 1734
1721 $rel ? $val * $max : $val 1735 $rel ? $val * $max : $val
1773 1 1787 1
1774} 1788}
1775 1789
1776############################################################################# 1790#############################################################################
1777 1791
1778package CFPlus::UI::Box; 1792package DC::UI::Box;
1779 1793
1780our @ISA = CFPlus::UI::Container::; 1794our @ISA = DC::UI::Container::;
1781 1795
1782sub size_request { 1796sub size_request {
1783 my ($self) = @_; 1797 my ($self) = @_;
1784 1798
1785 my @children = $self->visible_children; 1799 my @children = $self->visible_children;
1820 $req[$_] += $space * $children[$_]{expand} 1834 $req[$_] += $space * $children[$_]{expand}
1821 for 0 .. $#children; 1835 for 0 .. $#children;
1822 } 1836 }
1823 } 1837 }
1824 1838
1825 CFPlus::UI::harmonize \@req; 1839 DC::UI::harmonize \@req;
1826 1840
1827 my $pos = 0; 1841 my $pos = 0;
1828 for (0 .. $#children) { 1842 for (0 .. $#children) {
1829 my $alloc = $req[$_]; 1843 my $alloc = $req[$_];
1830 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); 1844 $children[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h));
1835 1 1849 1
1836} 1850}
1837 1851
1838############################################################################# 1852#############################################################################
1839 1853
1840package CFPlus::UI::HBox; 1854package DC::UI::HBox;
1841 1855
1842our @ISA = CFPlus::UI::Box::; 1856our @ISA = DC::UI::Box::;
1843 1857
1844sub new { 1858sub new {
1845 my $class = shift; 1859 my $class = shift;
1846 1860
1847 $class->SUPER::new ( 1861 $class->SUPER::new (
1850 ) 1864 )
1851} 1865}
1852 1866
1853############################################################################# 1867#############################################################################
1854 1868
1855package CFPlus::UI::VBox; 1869package DC::UI::VBox;
1856 1870
1857our @ISA = CFPlus::UI::Box::; 1871our @ISA = DC::UI::Box::;
1858 1872
1859sub new { 1873sub new {
1860 my $class = shift; 1874 my $class = shift;
1861 1875
1862 $class->SUPER::new ( 1876 $class->SUPER::new (
1865 ) 1879 )
1866} 1880}
1867 1881
1868############################################################################# 1882#############################################################################
1869 1883
1870package CFPlus::UI::Label; 1884package DC::UI::Label;
1871 1885
1872our @ISA = CFPlus::UI::DrawBG::; 1886our @ISA = DC::UI::DrawBG::;
1873 1887
1874use CFPlus::OpenGL; 1888use DC::OpenGL;
1875 1889
1876sub new { 1890sub new {
1877 my ($class, %arg) = @_; 1891 my ($class, %arg) = @_;
1878 1892
1879 my $self = $class->SUPER::new ( 1893 my $self = $class->SUPER::new (
1884 #text => initial text 1898 #text => initial text
1885 #markup => initial narkup 1899 #markup => initial narkup
1886 #max_w => maximum pixel width 1900 #max_w => maximum pixel width
1887 #style => 0, # render flags 1901 #style => 0, # render flags
1888 ellipsise => 3, # end 1902 ellipsise => 3, # end
1889 layout => (new CFPlus::Layout), 1903 layout => (new DC::Layout),
1890 fontsize => 1, 1904 fontsize => 1,
1891 align => -1, 1905 align => 0.5,
1892 valign => -1, 1906 valign => 0.5,
1893 padding_x => 2, 1907 padding_x => 4,
1894 padding_y => 2, 1908 padding_y => 2,
1895 can_events => 0, 1909 can_events => 0,
1896 %arg 1910 %arg
1897 ); 1911 );
1898 1912
1899 if (exists $self->{template}) { 1913 if (exists $self->{template}) {
1900 my $layout = new CFPlus::Layout; 1914 my $layout = new DC::Layout;
1901 $layout->set_text (delete $self->{template}); 1915 $layout->set_text (delete $self->{template});
1902 $self->{template} = $layout; 1916 $self->{template} = $layout;
1903 } 1917 }
1904 1918
1905 if (exists $self->{markup}) { 1919 if (exists $self->{markup}) {
1964 1978
1965 $self->{size_req} ||= do { 1979 $self->{size_req} ||= do {
1966 my ($max_w, $max_h) = $self->get_max_wh; 1980 my ($max_w, $max_h) = $self->get_max_wh;
1967 1981
1968 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1982 $self->{layout}->set_font ($self->{font}) if $self->{font};
1969 $self->{layout}->set_width ($self->{max_w} || $max_w || -1); 1983 $self->{layout}->set_width ($max_w);
1970 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1984 $self->{layout}->set_ellipsise ($self->{ellipsise});
1971 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1985 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1972 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1986 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1973 1987
1974 my ($w, $h) = $self->{layout}->size; 1988 my ($w, $h) = $self->{layout}->size;
1975 1989
1976 if (exists $self->{template}) { 1990 if (exists $self->{template}) {
1977 $self->{template}->set_font ($self->{font}) if $self->{font}; 1991 $self->{template}->set_font ($self->{font}) if $self->{font};
1978 $self->{template}->set_width ($self->{max_w} || -1); 1992 $self->{template}->set_width ($max_w);
1979 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1993 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1980 1994
1981 my ($w2, $h2) = $self->{template}->size; 1995 my ($w2, $h2) = $self->{template}->size;
1982 1996
1983 $w = List::Util::max $w, $w2; 1997 $w = List::Util::max $w, $w2;
2039 2053
2040 [$self->{layout}->size] 2054 [$self->{layout}->size]
2041 }; 2055 };
2042 2056
2043 unless (exists $self->{ox}) { 2057 unless (exists $self->{ox}) {
2044 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 2058 $self->{ox} = $self->{padding_x} + int $self->{align} * ($self->{w} - $size->[0] - $self->{padding_x} * 2);
2045 : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} 2059 $self->{oy} = $self->{padding_y} + int $self->{valign} * ($self->{h} - $size->[1] - $self->{padding_y} * 2);
2046 : ($self->{w} - $size->[0]) * 0.5);
2047
2048 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2049 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2050 : ($self->{h} - $size->[1]) * 0.5);
2051 2060
2052 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2061 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2053 }; 2062 };
2054 2063
2055# unless ($self->{list}) { 2064# unless ($self->{list}) {
2056# $self->{list} = CFPlus::OpenGL::glGenList; 2065# $self->{list} = DC::OpenGL::glGenList;
2057# CFPlus::OpenGL::glNewList $self->{list}; 2066# DC::OpenGL::glNewList $self->{list};
2058# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2067# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2059# CFPlus::OpenGL::glEndList; 2068# DC::OpenGL::glEndList;
2060# } 2069# }
2061# 2070#
2062# CFPlus::OpenGL::glCallList $self->{list}; 2071# DC::OpenGL::glCallList $self->{list};
2063 2072
2064 $self->{layout}->draw; 2073 $self->{layout}->draw;
2065} 2074}
2066 2075
2067#sub destroy { 2076#sub destroy {
2068# my ($self) = @_; 2077# my ($self) = @_;
2069# 2078#
2070# CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; 2079# DC::OpenGL::glDeleteList delete $self->{list} if $self->{list};
2071# 2080#
2072# $self->SUPER::destroy; 2081# $self->SUPER::destroy;
2073#} 2082#}
2074 2083
2075############################################################################# 2084#############################################################################
2076 2085
2077package CFPlus::UI::EntryBase; 2086package DC::UI::EntryBase;
2078 2087
2079our @ISA = CFPlus::UI::Label::; 2088our @ISA = DC::UI::Label::;
2080 2089
2081use CFPlus::OpenGL; 2090use DC::OpenGL;
2082 2091
2083sub new { 2092sub new {
2084 my $class = shift; 2093 my $class = shift;
2085 2094
2086 $class->SUPER::new ( 2095 $class->SUPER::new (
2087 fg => [1, 1, 1], 2096 fg => [1, 1, 1],
2088 bg => [0, 0, 0, 0.2], 2097 bg => [0, 0, 0, 0.2],
2089 outline => [0.6, 0.3, 0.1], 2098 outline => undef,
2090 active_bg => [0, 0, 1, .2], 2099 active_bg => [0, 0, 1, .2],
2091 active_fg => [1, 1, 1], 2100 active_fg => [1, 1, 1],
2092 active_outline => [1, 1, 0], 2101 active_outline => [1, 1, 0],
2093 can_hover => 1, 2102 can_hover => 1,
2094 can_focus => 1, 2103 can_focus => 1,
2104 align => 0,
2095 valign => 0, 2105 valign => 0.5,
2096 can_events => 1, 2106 can_events => 1,
2097 ellipsise => 0, 2107 ellipsise => 0,
2108 padding_x => 4,
2109 padding_y => 2,
2098 #text => ... 2110 #text => ...
2099 #hidden => "*", 2111 #hidden => "*",
2100 @_ 2112 @_
2101 ) 2113 )
2102} 2114}
2149 2161
2150 my $text = $self->get_text; 2162 my $text = $self->get_text;
2151 2163
2152 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; 2164 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text;
2153 2165
2154 if ($uni == 8) { 2166 if ($sym == DC::SDLK_BACKSPACE) {
2155 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2167 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
2156 } elsif ($uni == 127) { 2168 } elsif ($sym == DC::SDLK_DELETE) {
2157 substr $text, $self->{cursor}, 1, ""; 2169 substr $text, $self->{cursor}, 1, "";
2158 } elsif ($sym == CFPlus::SDLK_LEFT) { 2170 } elsif ($sym == DC::SDLK_LEFT) {
2159 --$self->{cursor} if $self->{cursor}; 2171 --$self->{cursor} if $self->{cursor};
2160 } elsif ($sym == CFPlus::SDLK_RIGHT) { 2172 } elsif ($sym == DC::SDLK_RIGHT) {
2161 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 2173 ++$self->{cursor} if $self->{cursor} < length $self->{text};
2162 } elsif ($sym == CFPlus::SDLK_HOME) { 2174 } elsif ($sym == DC::SDLK_HOME) {
2163 # what a hack 2175 # what a hack
2164 $self->{cursor} = 2176 $self->{cursor} =
2165 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ 2177 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/
2166 ? length $1 2178 ? length $1
2167 : 0; 2179 : 0;
2168 } elsif ($sym == CFPlus::SDLK_END) { 2180 } elsif ($sym == DC::SDLK_END) {
2169 # uh, again 2181 # uh, again
2170 $self->{cursor} = 2182 $self->{cursor} =
2171 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ 2183 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/
2172 ? $self->{cursor} + length $1 2184 ? $self->{cursor} + length $1
2173 : length $self->{text}; 2185 : length $self->{text};
2264 glColor @{$self->{active_outline}}; 2276 glColor @{$self->{active_outline}};
2265 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; 2277 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2266 glLineWidth 1; 2278 glLineWidth 1;
2267 2279
2268 } else { 2280 } else {
2269 glColor @{$self->{outline}}; 2281 glColor @{$self->{outline} || $DC::THEME{entry_outline}};
2270 glBegin GL_LINE_STRIP; 2282 glBegin GL_LINE_STRIP;
2271 glVertex .5, $self->{h} * .5; 2283 glVertex .5, $self->{h} * .5;
2272 glVertex .5, $self->{h} - 2.5; 2284 glVertex .5, $self->{h} - 2.5;
2273 glVertex $self->{w} - .5, $self->{h} - 2.5; 2285 glVertex $self->{w} - .5, $self->{h} - 2.5;
2274 glVertex $self->{w} - .5, $self->{h} * .5; 2286 glVertex $self->{w} - .5, $self->{h} * .5;
2276 } 2288 }
2277} 2289}
2278 2290
2279############################################################################# 2291#############################################################################
2280 2292
2281package CFPlus::UI::Entry; 2293package DC::UI::Entry;
2282 2294
2283our @ISA = CFPlus::UI::EntryBase::; 2295our @ISA = DC::UI::EntryBase::;
2284 2296
2285use CFPlus::OpenGL; 2297use DC::OpenGL;
2298
2299sub new {
2300 my $class = shift;
2301
2302 $class->SUPER::new (
2303 history_pointer => -1,
2304 @_
2305 )
2306}
2307
2286 2308
2287sub invoke_key_down { 2309sub invoke_key_down {
2288 my ($self, $ev) = @_; 2310 my ($self, $ev) = @_;
2289 2311
2290 my $sym = $ev->{sym}; 2312 my $sym = $ev->{sym};
2296 $self->{history_pointer} = -1; 2318 $self->{history_pointer} = -1;
2297 $self->{history_saveback} = ''; 2319 $self->{history_saveback} = '';
2298 $self->emit (activate => $txt); 2320 $self->emit (activate => $txt);
2299 $self->update; 2321 $self->update;
2300 2322
2301 } elsif ($sym == CFPlus::SDLK_UP) { 2323 } elsif ($sym == DC::SDLK_UP) {
2302 if ($self->{history_pointer} < 0) { 2324 if ($self->{history_pointer} < 0) {
2303 $self->{history_saveback} = $self->get_text; 2325 $self->{history_saveback} = $self->get_text;
2304 } 2326 }
2305 if (@{$self->{history} || []} > 0) { 2327 if (@{$self->{history} || []} > 0) {
2306 $self->{history_pointer}++; 2328 $self->{history_pointer}++;
2308 $self->{history_pointer} = @{$self->{history} || []} - 1; 2330 $self->{history_pointer} = @{$self->{history} || []} - 1;
2309 } 2331 }
2310 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2332 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2311 } 2333 }
2312 2334
2313 } elsif ($sym == CFPlus::SDLK_DOWN) { 2335 } elsif ($sym == DC::SDLK_DOWN) {
2314 $self->{history_pointer}--; 2336 $self->{history_pointer}--;
2315 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2337 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
2316 2338
2317 if ($self->{history_pointer} >= 0) { 2339 if ($self->{history_pointer} >= 0) {
2318 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2340 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2319 } else { 2341 } else {
2342 if (defined $self->{history_saveback}) {
2320 $self->set_text ($self->{history_saveback}); 2343 $self->set_text ($self->{history_saveback});
2344 $self->{history_saveback} = undef;
2345 }
2321 } 2346 }
2322 2347
2323 } else { 2348 } else {
2324 return $self->SUPER::invoke_key_down ($ev) 2349 return $self->SUPER::invoke_key_down ($ev)
2325 } 2350 }
2327 1 2352 1
2328} 2353}
2329 2354
2330############################################################################# 2355#############################################################################
2331 2356
2332package CFPlus::UI::TextEdit; 2357package DC::UI::TextEdit;
2333 2358
2334our @ISA = CFPlus::UI::EntryBase::; 2359our @ISA = DC::UI::EntryBase::;
2335 2360
2336use CFPlus::OpenGL; 2361use DC::OpenGL;
2362
2363sub new {
2364 my $class = shift;
2365
2366 $class->SUPER::new (
2367 padding_y => 4,
2368
2369 @_
2370 )
2371}
2337 2372
2338sub move_cursor_ver { 2373sub move_cursor_ver {
2339 my ($self, $dy) = @_; 2374 my ($self, $dy) = @_;
2340 2375
2341 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2376 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2342 2377
2343 $y += $dy; 2378 $line += $dy;
2344 2379
2345 if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { 2380 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) {
2346 $self->{cursor} = $index; 2381 $self->{cursor} = $index;
2347 delete $self->{cur_h}; 2382 delete $self->{cur_h};
2348 $self->update; 2383 $self->update;
2349 return; 2384 return;
2350 } 2385 }
2353sub invoke_key_down { 2388sub invoke_key_down {
2354 my ($self, $ev) = @_; 2389 my ($self, $ev) = @_;
2355 2390
2356 my $sym = $ev->{sym}; 2391 my $sym = $ev->{sym};
2357 2392
2358 if ($sym == CFPlus::SDLK_UP) { 2393 if ($sym == DC::SDLK_UP) {
2359 $self->move_cursor_ver (-1); 2394 $self->move_cursor_ver (-1);
2360 } elsif ($sym == CFPlus::SDLK_DOWN) { 2395 } elsif ($sym == DC::SDLK_DOWN) {
2361 $self->move_cursor_ver (+1); 2396 $self->move_cursor_ver (+1);
2362 } else { 2397 } else {
2363 return $self->SUPER::invoke_key_down ($ev) 2398 return $self->SUPER::invoke_key_down ($ev)
2364 } 2399 }
2365 2400
2366 1 2401 1
2367} 2402}
2368 2403
2369############################################################################# 2404#############################################################################
2370 2405
2371package CFPlus::UI::ButtonBin; 2406package DC::UI::ButtonBin;
2372 2407
2373our @ISA = CFPlus::UI::Bin::; 2408our @ISA = DC::UI::Bin::;
2374 2409
2375use CFPlus::OpenGL; 2410use DC::OpenGL;
2376 2411
2377my @tex = 2412my @tex =
2378 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2413 map { new_from_resource DC::Texture $_, mipmap => 1 }
2379 qw(b1_button_inactive.png b1_button_active.png); 2414 qw(b1_button_inactive.png b1_button_active.png);
2380 2415
2381sub new { 2416sub new {
2382 my $class = shift; 2417 my $class = shift;
2383 2418
2384 $class->SUPER::new ( 2419 $class->SUPER::new (
2385 can_hover => 1, 2420 can_hover => 1,
2386 align => 0, 2421 align => 0.5,
2387 valign => 0, 2422 valign => 0.5,
2388 can_events => 1, 2423 can_events => 1,
2389 @_ 2424 @_
2390 ) 2425 )
2391} 2426}
2392 2427
2415 $self->SUPER::_draw; 2450 $self->SUPER::_draw;
2416} 2451}
2417 2452
2418############################################################################# 2453#############################################################################
2419 2454
2420package CFPlus::UI::Button; 2455package DC::UI::Button;
2421 2456
2422our @ISA = CFPlus::UI::Label::; 2457our @ISA = DC::UI::Label::;
2423 2458
2424use CFPlus::OpenGL; 2459use DC::OpenGL;
2425 2460
2426my @tex = 2461my @tex =
2427 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2462 map { new_from_resource DC::Texture $_, mipmap => 1 }
2428 qw(b1_button_inactive.png b1_button_active.png); 2463 qw(b1_button_inactive.png b1_button_active.png);
2429 2464
2430sub new { 2465sub new {
2431 my $class = shift; 2466 my $class = shift;
2432 2467
2433 $class->SUPER::new ( 2468 $class->SUPER::new (
2434 padding_x => 4, 2469 padding_x => 8,
2435 padding_y => 4, 2470 padding_y => 4,
2436 fg => [1.0, 1.0, 1.0], 2471 fg => [1.0, 1.0, 1.0],
2437 active_fg => [0.8, 0.8, 0.8], 2472 active_fg => [0.8, 0.8, 0.8],
2438 can_hover => 1, 2473 can_hover => 1,
2439 align => 0, 2474 align => 0.5,
2440 valign => 0, 2475 valign => 0.5,
2441 can_events => 1, 2476 can_events => 1,
2442 @_ 2477 @_
2443 ) 2478 )
2444} 2479}
2445 2480
2470 $self->SUPER::_draw; 2505 $self->SUPER::_draw;
2471} 2506}
2472 2507
2473############################################################################# 2508#############################################################################
2474 2509
2475package CFPlus::UI::CheckBox; 2510package DC::UI::CheckBox;
2476 2511
2477our @ISA = CFPlus::UI::DrawBG::; 2512our @ISA = DC::UI::DrawBG::;
2478 2513
2479my @tex = 2514my @tex =
2480 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2515 map { new_from_resource DC::Texture $_, mipmap => 1 }
2481 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2516 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2482 2517
2483use CFPlus::OpenGL; 2518use DC::OpenGL;
2484 2519
2485sub new { 2520sub new {
2486 my $class = shift; 2521 my $class = shift;
2487 2522
2488 $class->SUPER::new ( 2523 $class->SUPER::new (
2545 glDisable GL_TEXTURE_2D; 2580 glDisable GL_TEXTURE_2D;
2546} 2581}
2547 2582
2548############################################################################# 2583#############################################################################
2549 2584
2550package CFPlus::UI::Image; 2585package DC::UI::Image;
2551 2586
2552our @ISA = CFPlus::UI::Base::; 2587our @ISA = DC::UI::Base::;
2553 2588
2554use CFPlus::OpenGL; 2589use DC::OpenGL;
2555 2590
2556our %texture_cache; 2591our %texture_cache;
2557 2592
2558sub new { 2593sub new {
2559 my $class = shift; 2594 my $class = shift;
2566 2601
2567 $self->{path} || $self->{tex} 2602 $self->{path} || $self->{tex}
2568 or Carp::croak "'path' or 'tex' attributes required"; 2603 or Carp::croak "'path' or 'tex' attributes required";
2569 2604
2570 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2605 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2571 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; 2606 new_from_resource DC::Texture $self->{path}, mipmap => 1;
2572 2607
2573 CFPlus::weaken $texture_cache{$self->{path}}; 2608 DC::weaken $texture_cache{$self->{path}};
2574 2609
2575 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2610 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2576 2611
2577 $self 2612 $self
2578} 2613}
2579 2614
2580sub STORABLE_freeze { 2615sub STORABLE_freeze {
2581 my ($self, $cloning) = @_; 2616 my ($self, $cloning) = @_;
2582 2617
2583 $self->{path} 2618 $self->{path}
2584 or die "cannot serialise CFPlus::UI::Image on non-loadable images\n"; 2619 or die "cannot serialise DC::UI::Image on non-loadable images\n";
2585 2620
2586 $self->{path} 2621 $self->{path}
2587} 2622}
2588 2623
2589sub STORABLE_attach { 2624sub STORABLE_attach {
2620 glDisable GL_TEXTURE_2D; 2655 glDisable GL_TEXTURE_2D;
2621} 2656}
2622 2657
2623############################################################################# 2658#############################################################################
2624 2659
2625package CFPlus::UI::ImageButton; 2660package DC::UI::ImageButton;
2626 2661
2627our @ISA = CFPlus::UI::Image::; 2662our @ISA = DC::UI::Image::;
2628 2663
2629use CFPlus::OpenGL; 2664use DC::OpenGL;
2630 2665
2631my %textures; 2666my %textures;
2632 2667
2633sub new { 2668sub new {
2634 my $class = shift; 2669 my $class = shift;
2637 padding_x => 4, 2672 padding_x => 4,
2638 padding_y => 4, 2673 padding_y => 4,
2639 fg => [1, 1, 1], 2674 fg => [1, 1, 1],
2640 active_fg => [0, 0, 1], 2675 active_fg => [0, 0, 1],
2641 can_hover => 1, 2676 can_hover => 1,
2642 align => 0, 2677 align => 0.5,
2643 valign => 0, 2678 valign => 0.5,
2644 can_events => 1, 2679 can_events => 1,
2645 @_ 2680 @_
2646 ); 2681 );
2647} 2682}
2648 2683
2662 1 2697 1
2663} 2698}
2664 2699
2665############################################################################# 2700#############################################################################
2666 2701
2667package CFPlus::UI::VGauge; 2702package DC::UI::VGauge;
2668 2703
2669our @ISA = CFPlus::UI::Base::; 2704our @ISA = DC::UI::Base::;
2670 2705
2671use List::Util qw(min max); 2706use List::Util qw(min max);
2672 2707
2673use CFPlus::OpenGL; 2708use DC::OpenGL;
2674 2709
2675my %tex = ( 2710my %tex = (
2676 food => [ 2711 food => [
2677 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2712 map { new_from_resource DC::Texture $_, mipmap => 1 }
2678 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2713 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2679 ], 2714 ],
2680 grace => [ 2715 grace => [
2681 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2716 map { new_from_resource DC::Texture $_, mipmap => 1 }
2682 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2717 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2683 ], 2718 ],
2684 hp => [ 2719 hp => [
2685 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2720 map { new_from_resource DC::Texture $_, mipmap => 1 }
2686 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2721 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2687 ], 2722 ],
2688 mana => [ 2723 mana => [
2689 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2724 map { new_from_resource DC::Texture $_, mipmap => 1 }
2690 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2725 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2691 ], 2726 ],
2692); 2727);
2693 2728
2694# eg. VGauge->new (gauge => 'food'), default gauge: food 2729# eg. VGauge->new (gauge => 'food'), default gauge: food
2797 glDisable GL_TEXTURE_2D; 2832 glDisable GL_TEXTURE_2D;
2798} 2833}
2799 2834
2800############################################################################# 2835#############################################################################
2801 2836
2802package CFPlus::UI::Progress; 2837package DC::UI::Progress;
2803 2838
2804our @ISA = CFPlus::UI::Label::; 2839our @ISA = DC::UI::Label::;
2805 2840
2806use CFPlus::OpenGL; 2841use DC::OpenGL;
2807 2842
2808sub new { 2843sub new {
2809 my ($class, %arg) = @_; 2844 my ($class, %arg) = @_;
2810 2845
2811 my $self = $class->SUPER::new ( 2846 my $self = $class->SUPER::new (
2812 fg => [1, 1, 1], 2847 fg => [1, 1, 1],
2813 bg => [0, 0, 1, 0.2], 2848 bg => [0, 0, 1, 0.2],
2814 bar => [0.7, 0.5, 0.1, 0.8], 2849 bar => [0.7, 0.5, 0.1, 0.8],
2815 outline => [0.4, 0.3, 0], 2850 outline => [0.4, 0.3, 0],
2816 fontsize => 0.9, 2851 fontsize => 0.9,
2817 valign => 0, 2852 valign => 0.5,
2818 align => 0, 2853 align => 0.5,
2819 can_events => 1, 2854 can_events => 1,
2820 ellipsise => 1, 2855 ellipsise => 1,
2821 label => "%d%%", 2856 label => "%d%%",
2822 %arg, 2857 %arg,
2823 ); 2858 );
2831 my ($self, $label) = @_; 2866 my ($self, $label) = @_;
2832 2867
2833 return if $self->{label} eq $label; 2868 return if $self->{label} eq $label;
2834 $self->{label} = $label; 2869 $self->{label} = $label;
2835 2870
2836 $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value}); 2871 $self->DC::UI::Progress::set_value (0 + delete $self->{value});
2837} 2872}
2838 2873
2839sub set_value { 2874sub set_value {
2840 my ($self, $value) = @_; 2875 my ($self, $value) = @_;
2841 2876
2878 } 2913 }
2879} 2914}
2880 2915
2881############################################################################# 2916#############################################################################
2882 2917
2883package CFPlus::UI::ExperienceProgress; 2918package DC::UI::ExperienceProgress;
2884 2919
2885our @ISA = CFPlus::UI::Progress::; 2920our @ISA = DC::UI::Progress::;
2886 2921
2887sub new { 2922sub new {
2888 my ($class, %arg) = @_; 2923 my ($class, %arg) = @_;
2889 2924
2890 my $self = $class->SUPER::new ( 2925 my $self = $class->SUPER::new (
2935 $self->SUPER::set_value ($v); 2970 $self->SUPER::set_value ($v);
2936} 2971}
2937 2972
2938############################################################################# 2973#############################################################################
2939 2974
2940package CFPlus::UI::Gauge; 2975package DC::UI::Gauge;
2941 2976
2942our @ISA = CFPlus::UI::VBox::; 2977our @ISA = DC::UI::VBox::;
2943 2978
2944sub new { 2979sub new {
2945 my ($class, %arg) = @_; 2980 my ($class, %arg) = @_;
2946 2981
2947 my $self = $class->SUPER::new ( 2982 my $self = $class->SUPER::new (
2949 can_hover => 1, 2984 can_hover => 1,
2950 can_events => 1, 2985 can_events => 1,
2951 %arg, 2986 %arg,
2952 ); 2987 );
2953 2988
2954 $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999"); 2989 $self->add ($self->{value} = new DC::UI::Label valign => 1, align => 0.5, template => "999");
2955 $self->add ($self->{gauge} = new CFPlus::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 2990 $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
2956 $self->add ($self->{max} = new CFPlus::UI::Label valign => -1, align => 0, template => "999"); 2991 $self->add ($self->{max} = new DC::UI::Label valign => 0, align => 0.5, template => "999");
2957 2992
2958 $self 2993 $self
2959} 2994}
2960 2995
2961sub set_fontsize { 2996sub set_fontsize {
2982 $self->{value}->set_text ($val); 3017 $self->{value}->set_text ($val);
2983} 3018}
2984 3019
2985############################################################################# 3020#############################################################################
2986 3021
2987package CFPlus::UI::Slider; 3022package DC::UI::Slider;
2988 3023
2989use strict; 3024use strict;
2990 3025
2991use CFPlus::OpenGL; 3026use DC::OpenGL;
2992 3027
2993our @ISA = CFPlus::UI::DrawBG::; 3028our @ISA = DC::UI::DrawBG::;
2994 3029
2995my @tex = 3030my @tex =
2996 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ } 3031 map { new_from_resource DC::Texture $_ }
2997 qw(s1_slider.png s1_slider_bg.png); 3032 qw(s1_slider.png s1_slider_bg.png);
2998 3033
2999sub new { 3034sub new {
3000 my $class = shift; 3035 my $class = shift;
3001 3036
3038sub set_value { 3073sub set_value {
3039 my ($self, $value) = @_; 3074 my ($self, $value) = @_;
3040 3075
3041 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; 3076 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
3042 3077
3043 $hi = $lo + 1 if $hi <= $lo; 3078 $hi = $lo if $hi < $lo;
3044 3079
3045 $page = $hi - $lo if $page > $hi - $lo; 3080 $value = $hi - $page if $value > $hi - $page;
3046
3047 $value = $lo if $value < $lo; 3081 $value = $lo if $value < $lo;
3048 $value = $hi - $page if $value > $hi - $page;
3049 3082
3050 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit 3083 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
3051 if $unit; 3084 if $unit;
3052 3085
3053 @{$self->{range}} = ($value, $lo, $hi, $page, $unit); 3086 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
3097sub invoke_mouse_wheel { 3130sub invoke_mouse_wheel {
3098 my ($self, $ev) = @_; 3131 my ($self, $ev) = @_;
3099 3132
3100 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 3133 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
3101 3134
3102 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; 3135 my $pagepart = $ev->{mod} & DC::KMOD_SHIFT ? 1 : 0.2;
3103 3136
3104 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); 3137 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
3105 3138
3106 1 3139 1
3107} 3140}
3117 my ($self) = @_; 3150 my ($self) = @_;
3118 3151
3119 unless ($self->{knob_w}) { 3152 unless ($self->{knob_w}) {
3120 $self->set_value ($self->{range}[0]); 3153 $self->set_value ($self->{range}[0]);
3121 3154
3122 my ($value, $lo, $hi, $page) = @{$self->{range}}; 3155 my ($value, $lo, $hi, $page, $unit) = @{$self->{range}};
3123 my $range = ($hi - $page - $lo) || 1e-100; 3156 my $range = ($hi - $page - $lo) || 1e-10;
3124 3157
3125 my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1; 3158 my $knob_w = List::Util::min 1, $page / (($hi - $lo) || 1e-10) || 24 / $self->{w};
3126 3159
3127 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; 3160 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5;
3128 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; 3161 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100;
3129 3162
3130 $value = ($value - $lo) / $range; 3163 $value = ($value - $lo) / $range;
3160 glDisable GL_TEXTURE_2D; 3193 glDisable GL_TEXTURE_2D;
3161} 3194}
3162 3195
3163############################################################################# 3196#############################################################################
3164 3197
3165package CFPlus::UI::ValSlider; 3198package DC::UI::ValSlider;
3166 3199
3167our @ISA = CFPlus::UI::HBox::; 3200our @ISA = DC::UI::HBox::;
3168 3201
3169sub new { 3202sub new {
3170 my ($class, %arg) = @_; 3203 my ($class, %arg) = @_;
3171 3204
3172 my $range = delete $arg{range}; 3205 my $range = delete $arg{range};
3173 3206
3174 my $self = $class->SUPER::new ( 3207 my $self = $class->SUPER::new (
3175 slider => (new CFPlus::UI::Slider expand => 1, range => $range), 3208 slider => (new DC::UI::Slider expand => 1, range => $range),
3176 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}), 3209 entry => (new DC::UI::Label text => "", template => delete $arg{template}),
3177 to_value => sub { shift }, 3210 to_value => sub { shift },
3178 from_value => sub { shift }, 3211 from_value => sub { shift },
3179 %arg, 3212 %arg,
3180 ); 3213 );
3181 3214
3201sub set_range { shift->{slider}->set_range (@_) } 3234sub set_range { shift->{slider}->set_range (@_) }
3202sub set_value { shift->{slider}->set_value (@_) } 3235sub set_value { shift->{slider}->set_value (@_) }
3203 3236
3204############################################################################# 3237#############################################################################
3205 3238
3206package CFPlus::UI::TextScroller; 3239package DC::UI::TextScroller;
3207 3240
3208our @ISA = CFPlus::UI::HBox::; 3241our @ISA = DC::UI::HBox::;
3209 3242
3210use CFPlus::OpenGL; 3243use DC::OpenGL;
3211 3244
3212sub new { 3245sub new {
3213 my $class = shift; 3246 my $class = shift;
3214 3247
3215 my $self = $class->SUPER::new ( 3248 my $self = $class->SUPER::new (
3217 can_events => 1, 3250 can_events => 1,
3218 indent => 0, 3251 indent => 0,
3219 #font => default_font 3252 #font => default_font
3220 @_, 3253 @_,
3221 3254
3222 layout => (new CFPlus::Layout), 3255 layout => (new DC::Layout),
3223 par => [], 3256 par => [],
3224 max_par => 0, 3257 max_par => 0,
3225 height => 0, 3258 height => 0,
3226 children => [ 3259 children => [
3227 (new CFPlus::UI::Empty expand => 1), 3260 (new DC::UI::Empty expand => 1),
3228 (new CFPlus::UI::Slider vertical => 1), 3261 (new DC::UI::Slider vertical => 1),
3229 ], 3262 ],
3230 ); 3263 );
3231 3264
3232 $self->{children}[1]->connect (changed => sub { $self->update }); 3265 $self->{children}[1]->connect (changed => sub { $self->update });
3233 3266
3289 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); 3322 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
3290 $layout->set_markup ($para->{markup}); 3323 $layout->set_markup ($para->{markup});
3291 3324
3292 $layout->set_shapes ( 3325 $layout->set_shapes (
3293 map 3326 map
3294 +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), 3327 +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}),
3295 @{$para->{widget}} 3328 @{$para->{widget}}
3296 ); 3329 );
3297 3330
3298 $layout 3331 $layout
3299} 3332}
3416 $ROOT->on_post_alloc ($self => sub { 3449 $ROOT->on_post_alloc ($self => sub {
3417 $self->force_uptodate; 3450 $self->force_uptodate;
3418 3451
3419 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 3452 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
3420 3453
3421 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 3454 $self->{texture} ||= new_from_opengl DC::Texture $W, $H, sub {
3422 glClearColor 0, 0, 0, 0; 3455 glClearColor 0, 0, 0, 0;
3423 glClear GL_COLOR_BUFFER_BIT; 3456 glClear GL_COLOR_BUFFER_BIT;
3424 3457
3425 package CFPlus::UI::Base; 3458 package DC::UI::Base;
3426 local ($draw_x, $draw_y, $draw_w, $draw_h) = 3459 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3427 (0, 0, $self->{w}, $self->{h}); 3460 (0, 0, $self->{w}, $self->{h});
3428 3461
3429 my $top = int $self->{children}[1]{range}[0]; 3462 my $top = int $self->{children}[1]{range}[0];
3430 3463
3489 $self->{children}[1]->draw; 3522 $self->{children}[1]->draw;
3490} 3523}
3491 3524
3492############################################################################# 3525#############################################################################
3493 3526
3494package CFPlus::UI::Animator; 3527package DC::UI::Animator;
3495 3528
3496use CFPlus::OpenGL; 3529use DC::OpenGL;
3497 3530
3498our @ISA = CFPlus::UI::Bin::; 3531our @ISA = DC::UI::Bin::;
3499 3532
3500sub moveto { 3533sub moveto {
3501 my ($self, $x, $y) = @_; 3534 my ($self, $x, $y) = @_;
3502 3535
3503 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 3536 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
3531 glPopMatrix; 3564 glPopMatrix;
3532} 3565}
3533 3566
3534############################################################################# 3567#############################################################################
3535 3568
3536package CFPlus::UI::Flopper; 3569package DC::UI::Flopper;
3537 3570
3538our @ISA = CFPlus::UI::Button::; 3571our @ISA = DC::UI::Button::;
3539 3572
3540sub new { 3573sub new {
3541 my $class = shift; 3574 my $class = shift;
3542 3575
3543 my $self = $class->SUPER::new ( 3576 my $self = $class->SUPER::new (
3555 $self->{other}->toggle_visibility; 3588 $self->{other}->toggle_visibility;
3556} 3589}
3557 3590
3558############################################################################# 3591#############################################################################
3559 3592
3560package CFPlus::UI::Tooltip; 3593package DC::UI::Tooltip;
3561 3594
3562our @ISA = CFPlus::UI::Bin::; 3595our @ISA = DC::UI::Bin::;
3563 3596
3564use CFPlus::OpenGL; 3597use DC::OpenGL;
3565 3598
3566sub new { 3599sub new {
3567 my $class = shift; 3600 my $class = shift;
3568 3601
3569 $class->SUPER::new ( 3602 $class->SUPER::new (
3576 my ($self, $widget) = @_; 3609 my ($self, $widget) = @_;
3577 3610
3578 my $tip = $widget->{tooltip}; 3611 my $tip = $widget->{tooltip};
3579 $tip = $tip->($widget) if "CODE" eq ref $tip; 3612 $tip = $tip->($widget) if "CODE" eq ref $tip;
3580 3613
3581 $tip = CFPlus::Pod::section_label tooltip => $1 3614 $tip = DC::Pod::section_label tooltip => $1
3582 if $tip =~ /^#(.*)$/; 3615 if $tip =~ /^#(.*)$/;
3583 3616
3584 if ($ENV{CFPLUS_DEBUG} & 2) { 3617 if ($ENV{CFPLUS_DEBUG} & 2) {
3585 $tip .= "\n\n" . (ref $widget) . "\n" 3618 $tip .= "\n\n" . (ref $widget) . "\n"
3586 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3619 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3589 } 3622 }
3590 3623
3591 $tip =~ s/^\n+//; 3624 $tip =~ s/^\n+//;
3592 $tip =~ s/\n+$//; 3625 $tip =~ s/\n+$//;
3593 3626
3594 $self->add (new CFPlus::UI::Label 3627 $self->add (new DC::UI::Label
3628 fg => $DC::THEME{tooltip_fg},
3595 markup => $tip, 3629 markup => $tip,
3596 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3630 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3631 align => 0,
3597 fontsize => 0.8, 3632 fontsize => 0.8,
3598 style => 1, # FLAG_INVERSE 3633 style => $DC::THEME{tooltip_style}, # FLAG_INVERSE
3599 ellipsise => 0, 3634 ellipsise => 0,
3600 font => ($widget->{tooltip_font} || $::FONT_PROP), 3635 font => ($widget->{tooltip_font} || $::FONT_PROP),
3601 ); 3636 );
3602} 3637}
3603 3638
3640sub _draw { 3675sub _draw {
3641 my ($self) = @_; 3676 my ($self) = @_;
3642 3677
3643 my ($w, $h) = @$self{qw(w h)}; 3678 my ($w, $h) = @$self{qw(w h)};
3644 3679
3645 glColor 1, 0.8, 0.4; 3680 glColor @{ $DC::THEME{tooltip_bg} };
3646 glRect 0, 0, $w, $h; 3681 glRect 0, 0, $w, $h;
3647 3682
3648 glColor 0, 0, 0; 3683 glColor @{ $DC::THEME{tooltip_border} };
3649 glRect_lineloop .5, .5, $w + .5, $h + .5; 3684 glRect_lineloop .5, .5, $w + .5, $h + .5;
3650 3685
3651 glTranslate 2, 2; 3686 glTranslate 2, 2;
3652 3687
3653 $self->SUPER::_draw; 3688 $self->SUPER::_draw;
3654} 3689}
3655 3690
3656############################################################################# 3691#############################################################################
3657 3692
3658package CFPlus::UI::Face; 3693package DC::UI::Face;
3659 3694
3660our @ISA = CFPlus::UI::DrawBG::; 3695our @ISA = DC::UI::DrawBG::;
3661 3696
3662use CFPlus::OpenGL; 3697use DC::OpenGL;
3663 3698
3664sub new { 3699sub new {
3665 my $class = shift; 3700 my $class = shift;
3666 3701
3667 my $self = $class->SUPER::new ( 3702 my $self = $class->SUPER::new (
3671 can_events => 0, 3706 can_events => 0,
3672 @_, 3707 @_,
3673 ); 3708 );
3674 3709
3675 if ($self->{anim} && $self->{animspeed}) { 3710 if ($self->{anim} && $self->{animspeed}) {
3676 CFPlus::weaken (my $widget = $self); 3711 DC::weaken (my $widget = $self);
3677 3712
3678 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3713 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed};
3679 $widget->{anim_start} = $self->{animspeed} * int EV::now / $self->{animspeed}; 3714 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub {
3680 $self->{timer} = EV::timer_ns 0, 0, sub {
3681 return unless $::CONN; 3715 return unless $::CONN;
3682 3716
3683 my $w = $widget 3717 my $w = $widget
3684 or return; 3718 or return;
3685 3719
3701sub update_timer { 3735sub update_timer {
3702 my ($self) = @_; 3736 my ($self) = @_;
3703 3737
3704 return unless $self->{timer}; 3738 return unless $self->{timer};
3705 3739
3706 $self->{timer}->stop;
3707 if ($self->{visible}) { 3740 if ($self->{visible}) {
3708 $self->{timer}->set (
3709 $self->{anim_start}
3710 + $self->{animspeed}
3711 * int 1.5 + (EV::now - $self->{anim_start}) / $self->{animspeed}
3712 );
3713 $self->{timer}->start; 3741 $self->{timer}->start;
3742 } else {
3743 $self->{timer}->stop;
3714 } 3744 }
3715} 3745}
3716 3746
3717sub update_face { 3747sub update_face {
3718 my ($self) = @_; 3748 my ($self) = @_;
3792 $self->SUPER::destroy; 3822 $self->SUPER::destroy;
3793} 3823}
3794 3824
3795############################################################################# 3825#############################################################################
3796 3826
3797package CFPlus::UI::Buttonbar; 3827package DC::UI::Buttonbar;
3798 3828
3799our @ISA = CFPlus::UI::HBox::; 3829our @ISA = DC::UI::HBox::;
3800 3830
3801# TODO: should actually wrap buttons and other goodies. 3831# TODO: should actually wrap buttons and other goodies.
3802 3832
3803############################################################################# 3833#############################################################################
3804 3834
3805package CFPlus::UI::Menu; 3835package DC::UI::Menu;
3806 3836
3807our @ISA = CFPlus::UI::Toplevel::; 3837our @ISA = DC::UI::Toplevel::;
3808 3838
3809use CFPlus::OpenGL; 3839use DC::OpenGL;
3810 3840
3811sub new { 3841sub new {
3812 my $class = shift; 3842 my $class = shift;
3813 3843
3814 my $self = $class->SUPER::new ( 3844 my $self = $class->SUPER::new (
3815 items => [], 3845 items => [],
3816 z => 100, 3846 z => 100,
3817 @_, 3847 @_,
3818 ); 3848 );
3819 3849
3820 $self->add ($self->{vbox} = new CFPlus::UI::VBox); 3850 $self->add ($self->{vbox} = new DC::UI::VBox);
3821 3851
3822 for my $item (@{ $self->{items} }) { 3852 for my $item (@{ $self->{items} }) {
3823 my ($widget, $cb, $tooltip) = @$item; 3853 my ($widget, $cb, $tooltip) = @$item;
3824 3854
3825 # handle various types of items, only text for now 3855 # handle various types of items, only text for now
3826 if (!ref $widget) { 3856 if (!ref $widget) {
3827 if ($widget =~ /\t/) { 3857 if ($widget =~ /\t/) {
3828 my ($left, $right) = split /\t/, $widget, 2; 3858 my ($left, $right) = split /\t/, $widget, 2;
3829 3859
3830 $widget = new CFPlus::UI::HBox 3860 $widget = new DC::UI::HBox
3831 can_hover => 1, 3861 can_hover => 1,
3832 can_events => 1, 3862 can_events => 1,
3833 tooltip => $tooltip, 3863 tooltip => $tooltip,
3834 children => [ 3864 children => [
3835 (new CFPlus::UI::Label markup => $left, expand => 1), 3865 (new DC::UI::Label markup => $left , align => 0, expand => 1),
3836 (new CFPlus::UI::Label markup => $right, align => +1), 3866 (new DC::UI::Label markup => $right, align => 1),
3837 ], 3867 ],
3838 ; 3868 ;
3839 3869
3840 } else { 3870 } else {
3841 $widget = new CFPlus::UI::Label 3871 $widget = new DC::UI::Label
3842 can_hover => 1, 3872 can_hover => 1,
3843 can_events => 1, 3873 can_events => 1,
3874 align => 0,
3844 markup => $widget, 3875 markup => $widget,
3845 tooltip => $tooltip; 3876 tooltip => $tooltip;
3846 } 3877 }
3847 } 3878 }
3848 3879
3894 1 3925 1
3895} 3926}
3896 3927
3897############################################################################# 3928#############################################################################
3898 3929
3899package CFPlus::UI::Multiplexer; 3930package DC::UI::Multiplexer;
3900 3931
3901our @ISA = CFPlus::UI::Container::; 3932our @ISA = DC::UI::Container::;
3902 3933
3903sub new { 3934sub new {
3904 my $class = shift; 3935 my $class = shift;
3905 3936
3906 my $self = $class->SUPER::new ( 3937 my $self = $class->SUPER::new (
3907 @_, 3938 @_,
3908 ); 3939 );
3909 3940
3910 $self->{current} = $self->{children}[0] 3941 $self->set_current_page (0);
3911 if @{ $self->{children} };
3912 3942
3913 $self 3943 $self
3914} 3944}
3915 3945
3916sub add { 3946sub add {
3917 my ($self, @widgets) = @_; 3947 my ($self, @widgets) = @_;
3918 3948
3919 $self->SUPER::add (@widgets); 3949 $self->SUPER::add (@widgets);
3920 3950
3921 $self->{current} = $self->{children}[0] 3951 $self->set_current_page (0)
3922 if @{ $self->{children} }; 3952 if @widgets == @{ $self->{children} };
3923} 3953}
3924 3954
3925sub get_current_page { 3955sub get_current_page {
3926 my ($self) = @_; 3956 my ($self) = @_;
3927 3957
3933 3963
3934 my $widget = ref $page_or_widget 3964 my $widget = ref $page_or_widget
3935 ? $page_or_widget 3965 ? $page_or_widget
3936 : $self->{children}[$page_or_widget]; 3966 : $self->{children}[$page_or_widget];
3937 3967
3968 $self->{current}->set_invisible if $self->{current} && $self->{visible};
3969
3938 $self->{current} = $widget; 3970 if (($self->{current} = $widget)) {
3971 $self->{current}->set_visible if $self->{current} && $self->{visible};
3939 $self->{current}->configure (0, 0, $self->{w}, $self->{h}); 3972 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
3940 3973
3941 $self->emit (page_changed => $self->{current}); 3974 $self->emit (page_changed => $self->{current});
3975 }
3942 3976
3943 $self->realloc; 3977 $self->realloc;
3944} 3978}
3945 3979
3946sub visible_children { 3980sub visible_children {
3947 $_[0]{current} 3981 $_[0]{current} || ()
3948} 3982}
3949 3983
3950sub size_request { 3984sub size_request {
3951 my ($self) = @_; 3985 my ($self) = @_;
3952 3986
3987 $self->{current}
3953 $self->{current}->size_request 3988 ? $self->{current}->size_request
3989 : (0, 0)
3954} 3990}
3955 3991
3956sub invoke_size_allocate { 3992sub invoke_size_allocate {
3957 my ($self, $w, $h) = @_; 3993 my ($self, $w, $h) = @_;
3958 3994
3959 $self->{current}->configure (0, 0, $w, $h); 3995 $self->{current}->configure (0, 0, $w, $h)
3996 if $self->{current};
3960 3997
3961 1 3998 1
3962} 3999}
3963 4000
3964sub _draw { 4001sub _draw {
3965 my ($self) = @_; 4002 my ($self) = @_;
3966 4003
3967 $self->{current}->draw; 4004 $self->{current}->draw
4005 if $self->{current};
3968} 4006}
3969 4007
3970############################################################################# 4008#############################################################################
3971 4009
3972package CFPlus::UI::Notebook; 4010package DC::UI::Notebook;
3973 4011
3974use CFPlus::OpenGL; 4012use DC::OpenGL;
3975 4013
3976our @ISA = CFPlus::UI::VBox::; 4014our @ISA = DC::UI::VBox::;
3977 4015
3978sub new { 4016sub new {
3979 my $class = shift; 4017 my $class = shift;
3980 4018
3981 my $self = $class->SUPER::new ( 4019 my $self = $class->SUPER::new (
3982 buttonbar => (new CFPlus::UI::Buttonbar), 4020 buttonbar => (new DC::UI::Buttonbar),
3983 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 4021 multiplexer => (new DC::UI::Multiplexer expand => 1),
3984 active_outline => [.7, .7, 0.2], 4022 active_outline => [.7, .7, 0.2],
3985 # filter => # will be put between multiplexer and $self 4023 # filter => # will be put between multiplexer and $self
3986 @_, 4024 @_,
3987 ); 4025 );
3988 4026
3997 4035
3998 for my $child (@$widgets) { 4036 for my $child (@$widgets) {
3999 Scalar::Util::weaken $child; 4037 Scalar::Util::weaken $child;
4000 $child->{c_tab_} ||= do { 4038 $child->{c_tab_} ||= do {
4001 my $tab = 4039 my $tab =
4002 (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") 4040 (UNIVERSAL::isa $child->{c_tab}, "DC::UI::Base")
4003 ? $child->{c_tab} 4041 ? $child->{c_tab}
4004 : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; 4042 : new DC::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1];
4005 4043
4006 $tab->connect (activate => sub { 4044 $tab->connect (activate => sub {
4007 $wself->set_current_page ($child); 4045 $wself->set_current_page ($child);
4008 }); 4046 });
4009 4047
4039} 4077}
4040 4078
4041sub pages { 4079sub pages {
4042 my ($self) = @_; 4080 my ($self) = @_;
4043 $self->{multiplexer}->children 4081 $self->{multiplexer}->children
4082}
4083
4084sub page_index {
4085 my ($self, $widget) = @_;
4086
4087 my $i = 0;
4088 for ($self->pages) {
4089 if ($_ eq $widget) { return $i };
4090 $i++;
4091 }
4092
4093 undef
4044} 4094}
4045 4095
4046sub add_tab { 4096sub add_tab {
4047 my ($self, $title, $widget, $tooltip) = @_; 4097 my ($self, $title, $widget, $tooltip) = @_;
4048 4098
4085 } 4135 }
4086} 4136}
4087 4137
4088############################################################################# 4138#############################################################################
4089 4139
4090package CFPlus::UI::Selector; 4140package DC::UI::Selector;
4091 4141
4092use utf8; 4142use utf8;
4093 4143
4094our @ISA = CFPlus::UI::Button::; 4144our @ISA = DC::UI::Button::;
4095 4145
4096sub new { 4146sub new {
4097 my $class = shift; 4147 my $class = shift;
4098 4148
4099 my $self = $class->SUPER::new ( 4149 my $self = $class->SUPER::new (
4116 my ($value, $title, $tooltip) = @$_; 4166 my ($value, $title, $tooltip) = @$_;
4117 4167
4118 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 4168 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
4119 } 4169 }
4120 4170
4121 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); 4171 DC::UI::Menu->new (items => \@menu_items)->popup ($ev);
4122} 4172}
4123 4173
4124sub _set_value { 4174sub _set_value {
4125 my ($self, $value) = @_; 4175 my ($self, $value) = @_;
4126 4176
4149 $self->_set_value ($self->{value}); 4199 $self->_set_value ($self->{value});
4150} 4200}
4151 4201
4152############################################################################# 4202#############################################################################
4153 4203
4154package CFPlus::UI::Statusbox; 4204package DC::UI::Statusbox;
4155 4205
4156our @ISA = CFPlus::UI::VBox::; 4206our @ISA = DC::UI::VBox::;
4157 4207
4158sub new { 4208sub new {
4159 my $class = shift; 4209 my $class = shift;
4160 4210
4161 my $self = $class->SUPER::new ( 4211 my $self = $class->SUPER::new (
4162 fontsize => 0.8, 4212 fontsize => 0.8,
4163 @_, 4213 @_,
4164 ); 4214 );
4165 4215
4166 CFPlus::weaken (my $this = $self); 4216 DC::weaken (my $this = $self);
4167 4217
4168 $self->{timer} = EV::timer 1, 1, sub { $this->reorder }; 4218 $self->{timer} = EV::timer 1, 1, sub { $this->reorder };
4169 4219
4170 $self 4220 $self
4171} 4221}
4172 4222
4173sub reorder { 4223sub reorder {
4174 my ($self) = @_; 4224 my ($self) = @_;
4175 my $NOW = Time::HiRes::time; 4225 my $NOW = EV::time;
4176 4226
4177 # freeze display when hovering over any label 4227 # freeze display when hovering over any label
4178 return if $CFPlus::UI::TOOLTIP->{owner} 4228 return if $DC::UI::TOOLTIP->{owner}
4179 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label}, 4229 && grep $DC::UI::TOOLTIP->{owner} == $_->{label},
4180 values %{ $self->{item} }; 4230 values %{ $self->{item} };
4181 4231
4182 while (my ($k, $v) = each %{ $self->{item} }) { 4232 while (my ($k, $v) = each %{ $self->{item} }) {
4183 delete $self->{item}{$k} if $v->{timeout} < $NOW; 4233 delete $self->{item}{$k} if $v->{timeout} < $NOW;
4184 } 4234 }
4235
4236 $self->{timer}->set (1, 1);
4185 4237
4186 my @widgets; 4238 my @widgets;
4187 4239
4188 my @items = sort { 4240 my @items = sort {
4189 $a->{pri} <=> $b->{pri} 4241 $a->{pri} <=> $b->{pri}
4203 for ($short) { 4255 for ($short) {
4204 s/^\s+//; 4256 s/^\s+//;
4205 s/\s+/ /g; 4257 s/\s+/ /g;
4206 } 4258 }
4207 4259
4208 new CFPlus::UI::Label 4260 new DC::UI::Label
4209 markup => $short, 4261 markup => $short,
4210 tooltip => $item->{tooltip}, 4262 tooltip => $item->{tooltip},
4211 tooltip_font => $::FONT_PROP, 4263 tooltip_font => $::FONT_PROP,
4212 tooltip_width => 0.67, 4264 tooltip_width => 0.67,
4213 fontsize => $item->{fontsize} || $self->{fontsize}, 4265 fontsize => $item->{fontsize} || $self->{fontsize},
4214 max_w => $::WIDTH * 0.44, 4266 max_w => $::WIDTH * 0.44,
4267 align => 0,
4215 fg => [@{ $item->{fg} }], 4268 fg => [@{ $item->{fg} }],
4216 can_events => 1, 4269 can_events => 1,
4217 can_hover => 1 4270 can_hover => 1
4218 }; 4271 };
4219 4272
4227 $label->{fg}[3] = $item->{fg}[3] || 1; 4280 $label->{fg}[3] = $item->{fg}[3] || 1;
4228 } 4281 }
4229 4282
4230 push @widgets, $label; 4283 push @widgets, $label;
4231 } 4284 }
4285
4286 my $hash = join ",", @widgets;
4287 return if $hash eq $self->{last_widget_hash};
4288 $self->{last_widget_hash} = $hash;
4232 4289
4233 $self->clear; 4290 $self->clear;
4234 $self->SUPER::add (reverse @widgets); 4291 $self->SUPER::add (reverse @widgets);
4235} 4292}
4236 4293
4292 $self->SUPER::destroy; 4349 $self->SUPER::destroy;
4293} 4350}
4294 4351
4295############################################################################# 4352#############################################################################
4296 4353
4297package CFPlus::UI::Root; 4354package DC::UI::Root;
4298 4355
4299our @ISA = CFPlus::UI::Container::; 4356our @ISA = DC::UI::Container::;
4300 4357
4301use List::Util qw(min max); 4358use List::Util qw(min max);
4302 4359
4303use CFPlus::OpenGL; 4360use DC::OpenGL;
4304 4361
4305sub new { 4362sub new {
4306 my $class = shift; 4363 my $class = shift;
4307 4364
4308 my $self = $class->SUPER::new ( 4365 my $self = $class->SUPER::new (
4309 visible => 1, 4366 visible => 1,
4310 @_, 4367 @_,
4311 ); 4368 );
4312 4369
4313 CFPlus::weaken ($self->{root} = $self); 4370 DC::weaken ($self->{root} = $self);
4314 4371
4315 $self 4372 $self
4316} 4373}
4317 4374
4318sub size_request { 4375sub size_request {
4366} 4423}
4367 4424
4368sub update { 4425sub update {
4369 my ($self) = @_; 4426 my ($self) = @_;
4370 4427
4371 $::WANT_REFRESH->start; 4428 $::WANT_REFRESH = 1;
4372} 4429}
4373 4430
4374sub add { 4431sub add {
4375 my ($self, @children) = @_; 4432 my ($self, @children) = @_;
4376 4433
4443 4500
4444 delete $queue{$widget+0}; 4501 delete $queue{$widget+0};
4445 4502
4446 my ($w, $h) = $widget->size_request; 4503 my ($w, $h) = $widget->size_request;
4447 4504
4448 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; 4505 $w += $widget->{padding_x} * 2;
4449 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; 4506 $h += $widget->{padding_y} * 2;
4507
4508 $w = max $widget->{min_w}, $w;
4509 $h = max $widget->{min_h}, $h;
4450 4510
4451 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4511 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4452 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4512 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4453 4513
4454 $w = $widget->{force_w} if exists $widget->{force_w}; 4514 $w = $widget->{force_w} if exists $widget->{force_w};
4521 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 4581 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
4522 glMatrixMode GL_MODELVIEW; 4582 glMatrixMode GL_MODELVIEW;
4523 glLoadIdentity; 4583 glLoadIdentity;
4524 4584
4525 { 4585 {
4526 package CFPlus::UI::Base; 4586 package DC::UI::Base;
4527 4587
4528 local ($draw_x, $draw_y, $draw_w, $draw_h) = 4588 local ($draw_x, $draw_y, $draw_w, $draw_h) =
4529 (0, 0, $self->{w}, $self->{h}); 4589 (0, 0, $self->{w}, $self->{h});
4530 4590
4531 $self->_draw; 4591 $self->_draw;
4532 } 4592 }
4533} 4593}
4534 4594
4535############################################################################# 4595#############################################################################
4536 4596
4537package CFPlus::UI; 4597package DC::UI;
4538 4598
4539$ROOT = new CFPlus::UI::Root; 4599$ROOT = new DC::UI::Root;
4540$TOOLTIP = new CFPlus::UI::Tooltip z => 900; 4600$TOOLTIP = new DC::UI::Tooltip z => 900;
4541 4601
45421 46021
4543 4603

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines