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.449 by root, Wed Dec 26 15:07:08 2007 UTC vs.
Revision 1.453 by root, Wed Dec 26 20:46:39 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 ();
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
309 delete $self->{root}; 309 delete $self->{root};
310 310
311 undef $GRAB if $GRAB == $self; 311 undef $GRAB if $GRAB == $self;
312 undef $HOVER if $HOVER == $self; 312 undef $HOVER if $HOVER == $self;
313 313
314 $CFPlus::UI::TOOLTIP_WATCHER->invoke 314 $dc::UI::TOOLTIP_WATCHER->invoke
315 if $TOOLTIP->{owner} == $self; 315 if $TOOLTIP->{owner} == $self;
316 316
317 $self->emit ("focus_out"); 317 $self->emit ("focus_out");
318 $self->emit (visibility_change => 0); 318 $self->emit (visibility_change => 0);
319} 319}
338sub hide { 338sub hide {
339 my ($self) = @_; 339 my ($self) = @_;
340 340
341 $self->set_invisible; 341 $self->set_invisible;
342 342
343 # extra $parent copy for 5.8.8+ bug workaround
344 # (otherwise $_[0] in remove gets freed
345 if (my $parent = $self->{parent}) {
343 $self->{parent}->remove ($self) 346 $parent->remove ($self);
344 if $self->{parent}; 347 }
345} 348}
346 349
347sub move_abs { 350sub move_abs {
348 my ($self, $x, $y, $z) = @_; 351 my ($self, $x, $y, $z) = @_;
349 352
386 my ($self, $x, $y, $w, $h) = @_; 389 my ($self, $x, $y, $w, $h) = @_;
387 390
388 if ($self->{aspect}) { 391 if ($self->{aspect}) {
389 my ($ow, $oh) = ($w, $h); 392 my ($ow, $oh) = ($w, $h);
390 393
391 $w = List::Util::min $w, CFPlus::ceil $h * $self->{aspect}; 394 $w = List::Util::min $w, dc::ceil $h * $self->{aspect};
392 $h = List::Util::min $h, CFPlus::ceil $w / $self->{aspect}; 395 $h = List::Util::min $h, dc::ceil $w / $self->{aspect};
393 396
394 # use alignment to adjust x, y 397 # use alignment to adjust x, y
395 398
396 $x += int 0.5 * ($ow - $w); 399 $x += int 0.5 * ($ow - $w);
397 $y += int 0.5 * ($oh - $h); 400 $y += int 0.5 * ($oh - $h);
438 441
439 return if $self->{tooltip} eq $tooltip; 442 return if $self->{tooltip} eq $tooltip;
440 443
441 $self->{tooltip} = $tooltip; 444 $self->{tooltip} = $tooltip;
442 445
443 if ($CFPlus::UI::TOOLTIP->{owner} == $self) { 446 if ($dc::UI::TOOLTIP->{owner} == $self) {
444 delete $CFPlus::UI::TOOLTIP->{owner}; 447 delete $dc::UI::TOOLTIP->{owner};
445 $CFPlus::UI::TOOLTIP_WATCHER->invoke; 448 $dc::UI::TOOLTIP_WATCHER->invoke;
446 } 449 }
447} 450}
448 451
449# translate global coordinates to local coordinate system 452# translate global coordinates to local coordinate system
450sub coord2local { 453sub coord2local {
516sub connect { 519sub connect {
517 my ($self, $signal, $cb) = @_; 520 my ($self, $signal, $cb) = @_;
518 521
519 push @{ $self->{signal_cb}{$signal} }, $cb; 522 push @{ $self->{signal_cb}{$signal} }, $cb;
520 523
521 defined wantarray and CFPlus::guard { 524 defined wantarray and dc::guard {
522 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, 525 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
523 @{ $self->{signal_cb}{$signal} }; 526 @{ $self->{signal_cb}{$signal} };
524 } 527 }
525} 528}
526 529
564# in .xs 567# in .xs
565 568
566sub set_parent { 569sub set_parent {
567 my ($self, $parent) = @_; 570 my ($self, $parent) = @_;
568 571
569 CFPlus::weaken ($self->{parent} = $parent); 572 dc::weaken ($self->{parent} = $parent);
570 $self->set_visible if $parent->{visible}; 573 $self->set_visible if $parent->{visible};
571} 574}
572 575
573sub realloc { 576sub realloc {
574 my ($self) = @_; 577 my ($self) = @_;
612} 615}
613 616
614sub DESTROY { 617sub DESTROY {
615 my ($self) = @_; 618 my ($self) = @_;
616 619
617 return if CFPlus::in_destruct; 620 return if dc::in_destruct;
618 621
619 local $@; 622 local $@;
620 eval { $self->destroy }; 623 eval { $self->destroy };
621 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 624 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
622 625
623 delete $WIDGET{$self+0}; 626 delete $WIDGET{$self+0};
624} 627}
625 628
626############################################################################# 629#############################################################################
627 630
628package CFPlus::UI::DrawBG; 631package dc::UI::DrawBG;
629 632
630our @ISA = CFPlus::UI::Base::; 633our @ISA = dc::UI::Base::;
631 634
632use strict; 635use strict;
633use CFPlus::OpenGL; 636use dc::OpenGL;
634 637
635sub new { 638sub new {
636 my $class = shift; 639 my $class = shift;
637 640
638 $class->SUPER::new ( 641 $class->SUPER::new (
660 } 663 }
661} 664}
662 665
663############################################################################# 666#############################################################################
664 667
665package CFPlus::UI::Empty; 668package dc::UI::Empty;
666 669
667our @ISA = CFPlus::UI::Base::; 670our @ISA = dc::UI::Base::;
668 671
669sub new { 672sub new {
670 my ($class, %arg) = @_; 673 my ($class, %arg) = @_;
671 $class->SUPER::new (can_events => 0, %arg); 674 $class->SUPER::new (can_events => 0, %arg);
672} 675}
679 682
680sub draw { } 683sub draw { }
681 684
682############################################################################# 685#############################################################################
683 686
684package CFPlus::UI::Container; 687package dc::UI::Container;
685 688
686our @ISA = CFPlus::UI::Base::; 689our @ISA = dc::UI::Base::;
687 690
688sub new { 691sub new {
689 my ($class, %arg) = @_; 692 my ($class, %arg) = @_;
690 693
691 my $children = delete $arg{children}; 694 my $children = delete $arg{children};
785 $_->draw for $self->visible_children; 788 $_->draw for $self->visible_children;
786} 789}
787 790
788############################################################################# 791#############################################################################
789 792
790package CFPlus::UI::Bin; 793package dc::UI::Bin;
791 794
792our @ISA = CFPlus::UI::Container::; 795our @ISA = dc::UI::Container::;
793 796
794sub new { 797sub new {
795 my ($class, %arg) = @_; 798 my ($class, %arg) = @_;
796 799
797 my $child = (delete $arg{child}) || new CFPlus::UI::Empty::; 800 my $child = (delete $arg{child}) || new dc::UI::Empty::;
798 801
799 $class->SUPER::new (children => [$child], %arg) 802 $class->SUPER::new (children => [$child], %arg)
800} 803}
801 804
802sub add { 805sub add {
809sub remove { 812sub remove {
810 my ($self, $widget) = @_; 813 my ($self, $widget) = @_;
811 814
812 $self->SUPER::remove ($widget); 815 $self->SUPER::remove ($widget);
813 816
814 $self->{children} = [new CFPlus::UI::Empty] 817 $self->{children} = [new dc::UI::Empty]
815 unless @{$self->{children}}; 818 unless @{$self->{children}};
816} 819}
817 820
818sub child { $_[0]->{children}[0] } 821sub child { $_[0]->{children}[0] }
819 822
830} 833}
831 834
832############################################################################# 835#############################################################################
833# back-buffered drawing area 836# back-buffered drawing area
834 837
835package CFPlus::UI::Window; 838package dc::UI::Window;
836 839
837our @ISA = CFPlus::UI::Bin::; 840our @ISA = dc::UI::Bin::;
838 841
839use CFPlus::OpenGL; 842use dc::OpenGL;
840 843
841sub new { 844sub new {
842 my ($class, %arg) = @_; 845 my ($class, %arg) = @_;
843 846
844 my $self = $class->SUPER::new (%arg); 847 my $self = $class->SUPER::new (%arg);
866} 869}
867 870
868sub render_child { 871sub render_child {
869 my ($self) = @_; 872 my ($self) = @_;
870 873
871 $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 {
872 glClearColor 0, 0, 0, 0; 875 glClearColor 0, 0, 0, 0;
873 glClear GL_COLOR_BUFFER_BIT; 876 glClear GL_COLOR_BUFFER_BIT;
874 877
875 { 878 {
876 package CFPlus::UI::Base; 879 package dc::UI::Base;
877 880
878 local ($draw_x, $draw_y, $draw_w, $draw_h) = 881 local ($draw_x, $draw_y, $draw_w, $draw_h) =
879 (0, 0, $self->{w}, $self->{h}); 882 (0, 0, $self->{w}, $self->{h});
880 883
881 $self->_render; 884 $self->_render;
898 glDisable GL_TEXTURE_2D; 901 glDisable GL_TEXTURE_2D;
899} 902}
900 903
901############################################################################# 904#############################################################################
902 905
903package CFPlus::UI::ViewPort; 906package dc::UI::ViewPort;
904 907
905use List::Util qw(min max); 908use List::Util qw(min max);
906 909
907our @ISA = CFPlus::UI::Window::; 910our @ISA = dc::UI::Window::;
908 911
909sub new { 912sub new {
910 my $class = shift; 913 my $class = shift;
911 914
912 $class->SUPER::new ( 915 $class->SUPER::new (
996 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 999 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
997 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1000 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
998 ) { 1001 ) {
999 $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})
1000 } else { 1003 } else {
1001 $self->CFPlus::UI::Base::find_widget ($x, $y) 1004 $self->dc::UI::Base::find_widget ($x, $y)
1002 } 1005 }
1003} 1006}
1004 1007
1005sub _render { 1008sub _render {
1006 my ($self) = @_; 1009 my ($self) = @_;
1007 1010
1008 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};
1009 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};
1010 1013
1011 CFPlus::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 1014 dc::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
1012 1015
1013 $self->SUPER::_render; 1016 $self->SUPER::_render;
1014} 1017}
1015 1018
1016############################################################################# 1019#############################################################################
1017 1020
1018package CFPlus::UI::ScrolledWindow; 1021package dc::UI::ScrolledWindow;
1019 1022
1020our @ISA = CFPlus::UI::Table::; 1023our @ISA = dc::UI::Table::;
1021 1024
1022sub new { 1025sub new {
1023 my ($class, %arg) = @_; 1026 my ($class, %arg) = @_;
1024 1027
1025 my $child = delete $arg{child}; 1028 my $child = delete $arg{child};
1026 1029
1027 my $self; 1030 my $self;
1028 1031
1029 my $hslider = new CFPlus::UI::Slider 1032 my $hslider = new dc::UI::Slider
1030 c_col => 0, 1033 c_col => 0,
1031 c_row => 1, 1034 c_row => 1,
1032 vertical => 0, 1035 vertical => 0,
1033 range => [0, 0, 1, 0.01], # HACK fix 1036 range => [0, 0, 1, 0.01], # HACK fix
1034 on_changed => sub { 1037 on_changed => sub {
1035 $self->{hpos} = $_[1]; 1038 $self->{hpos} = $_[1];
1036 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1039 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1037 }, 1040 },
1038 ; 1041 ;
1039 1042
1040 my $vslider = new CFPlus::UI::Slider 1043 my $vslider = new dc::UI::Slider
1041 c_col => 1, 1044 c_col => 1,
1042 c_row => 0, 1045 c_row => 0,
1043 vertical => 1, 1046 vertical => 1,
1044 range => [0, 0, 1, 0.01], # HACK fix 1047 range => [0, 0, 1, 0.01], # HACK fix
1045 on_changed => sub { 1048 on_changed => sub {
1057 col_expand => [1, 0], 1060 col_expand => [1, 0],
1058 row_expand => [1, 0], 1061 row_expand => [1, 0],
1059 %arg, 1062 %arg,
1060 ); 1063 );
1061 1064
1062 $self->{vp} = new CFPlus::UI::ViewPort 1065 $self->{vp} = new dc::UI::ViewPort
1063 c_col => 0, 1066 c_col => 0,
1064 c_row => 0, 1067 c_row => 0,
1065 expand => 1, 1068 expand => 1,
1066 scroll_x => $self->{scroll_x}, 1069 scroll_x => $self->{scroll_x},
1067 scroll_y => $self->{scroll_y}, 1070 scroll_y => $self->{scroll_y},
1193 $self->SUPER::invoke_size_allocate ($w, $h) 1196 $self->SUPER::invoke_size_allocate ($w, $h)
1194} 1197}
1195 1198
1196############################################################################# 1199#############################################################################
1197 1200
1198package CFPlus::UI::Frame; 1201package dc::UI::Frame;
1199 1202
1200our @ISA = CFPlus::UI::Bin::; 1203our @ISA = dc::UI::Bin::;
1201 1204
1202use CFPlus::OpenGL; 1205use dc::OpenGL;
1203 1206
1204sub new { 1207sub new {
1205 my $class = shift; 1208 my $class = shift;
1206 1209
1207 $class->SUPER::new ( 1210 $class->SUPER::new (
1226 $self->SUPER::_draw; 1229 $self->SUPER::_draw;
1227} 1230}
1228 1231
1229############################################################################# 1232#############################################################################
1230 1233
1231package CFPlus::UI::FancyFrame; 1234package dc::UI::FancyFrame;
1232 1235
1233our @ISA = CFPlus::UI::Bin::; 1236our @ISA = dc::UI::Bin::;
1234 1237
1235use CFPlus::OpenGL; 1238use dc::OpenGL;
1236 1239
1237sub new { 1240sub new {
1238 my ($class, %arg) = @_; 1241 my ($class, %arg) = @_;
1239 1242
1240 if ((exists $arg{label}) && !ref $arg{label}) { 1243 if ((exists $arg{label}) && !ref $arg{label}) {
1241 $arg{label} = new CFPlus::UI::Label 1244 $arg{label} = new dc::UI::Label
1242 align => 1, 1245 align => 1,
1243 valign => 0, 1246 valign => 0,
1244 text => $arg{label}, 1247 text => $arg{label},
1245 fontsize => ($arg{border} || 0.8) * 0.75; 1248 fontsize => ($arg{border} || 0.8) * 0.75;
1246 } 1249 }
1258 1261
1259sub add { 1262sub add {
1260 my ($self, @widgets) = @_; 1263 my ($self, @widgets) = @_;
1261 1264
1262 $self->SUPER::add (@widgets); 1265 $self->SUPER::add (@widgets);
1263 $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label}; 1266 $self->dc::UI::Container::add ($self->{label}) if $self->{label};
1264} 1267}
1265 1268
1266sub border { 1269sub border {
1267 int $_[0]{border} * $::FONTSIZE 1270 int $_[0]{border} * $::FONTSIZE
1268} 1271}
1326 } 1329 }
1327} 1330}
1328 1331
1329############################################################################# 1332#############################################################################
1330 1333
1331package CFPlus::UI::Toplevel; 1334package dc::UI::Toplevel;
1332 1335
1333our @ISA = CFPlus::UI::Bin::; 1336our @ISA = dc::UI::Bin::;
1334 1337
1335use CFPlus::OpenGL; 1338use dc::OpenGL;
1336 1339
1337my $bg = 1340my $bg =
1338 new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", 1341 new_from_file dc::Texture dc::find_rcfile "d1_bg.png",
1339 mipmap => 1, wrap => 1; 1342 mipmap => 1, wrap => 1;
1340 1343
1341my @border = 1344my @border =
1342 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1345 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 }
1343 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);
1344 1347
1345my @icon = 1348my @icon =
1346 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1349 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 }
1347 qw(x1_move.png x1_resize.png); 1350 qw(x1_move.png x1_resize.png);
1348 1351
1349sub new { 1352sub new {
1350 my ($class, %arg) = @_; 1353 my ($class, %arg) = @_;
1351 1354
1357 min_w => 64, 1360 min_w => 64,
1358 min_h => 32, 1361 min_h => 32,
1359 %arg, 1362 %arg,
1360 ); 1363 );
1361 1364
1362 $self->{title_widget} = new CFPlus::UI::Label 1365 $self->{title_widget} = new dc::UI::Label
1363 align => 0, 1366 align => 0,
1364 valign => 1, 1367 valign => 1,
1365 text => $self->{title}, 1368 text => $self->{title},
1366 fontsize => $self->{border}, 1369 fontsize => $self->{border},
1367 if exists $self->{title}; 1370 if exists $self->{title};
1368 1371
1369 if ($self->{has_close_button}) { 1372 if ($self->{has_close_button}) {
1370 $self->{close_button} = 1373 $self->{close_button} =
1371 new CFPlus::UI::ImageButton 1374 new dc::UI::ImageButton
1372 path => 'x1_close.png', 1375 path => 'x1_close.png',
1373 on_activate => sub { $self->emit ("delete") }; 1376 on_activate => sub { $self->emit ("delete") };
1374 1377
1375 $self->CFPlus::UI::Container::add ($self->{close_button}); 1378 $self->dc::UI::Container::add ($self->{close_button});
1376 } 1379 }
1377 1380
1378 $self 1381 $self
1379} 1382}
1380 1383
1381sub add { 1384sub add {
1382 my ($self, @widgets) = @_; 1385 my ($self, @widgets) = @_;
1383 1386
1384 $self->SUPER::add (@widgets); 1387 $self->SUPER::add (@widgets);
1385 $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};
1386 $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};
1387} 1390}
1388 1391
1389sub border { 1392sub border {
1390 int $_[0]{border} * $::FONTSIZE 1393 int $_[0]{border} * $::FONTSIZE
1391} 1394}
1576 if $self->{close_button}; 1579 if $self->{close_button};
1577} 1580}
1578 1581
1579############################################################################# 1582#############################################################################
1580 1583
1581package CFPlus::UI::Table; 1584package dc::UI::Table;
1582 1585
1583our @ISA = CFPlus::UI::Container::; 1586our @ISA = dc::UI::Container::;
1584 1587
1585use List::Util qw(max sum); 1588use List::Util qw(max sum);
1586 1589
1587use CFPlus::OpenGL; 1590use dc::OpenGL;
1588 1591
1589sub new { 1592sub new {
1590 my $class = shift; 1593 my $class = shift;
1591 1594
1592 $class->SUPER::new ( 1595 $class->SUPER::new (
1680 @col_expand = (1) x @$ws unless @col_expand; 1683 @col_expand = (1) x @$ws unless @col_expand;
1681 my $col_expand = (sum @col_expand) || 1; 1684 my $col_expand = (sum @col_expand) || 1;
1682 1685
1683 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1686 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1684 1687
1685 CFPlus::UI::harmonize $ws; 1688 dc::UI::harmonize $ws;
1686 1689
1687 my @row_expand = @{$self->{row_expand}}; 1690 my @row_expand = @{$self->{row_expand}};
1688 @row_expand = (1) x @$ws unless @row_expand; 1691 @row_expand = (1) x @$ws unless @row_expand;
1689 my $row_expand = (sum @row_expand) || 1; 1692 my $row_expand = (sum @row_expand) || 1;
1690 1693
1691 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; 1694 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1692 1695
1693 CFPlus::UI::harmonize $hs; 1696 dc::UI::harmonize $hs;
1694 1697
1695 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } 1698 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] }
1696 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } 1699 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] }
1697 1700
1698 for my $widget ($self->children) { 1701 for my $widget ($self->children) {
1707 1 1710 1
1708} 1711}
1709 1712
1710############################################################################# 1713#############################################################################
1711 1714
1712package CFPlus::UI::Fixed; 1715package dc::UI::Fixed;
1713 1716
1714use List::Util qw(min max); 1717use List::Util qw(min max);
1715 1718
1716our @ISA = CFPlus::UI::Container::; 1719our @ISA = dc::UI::Container::;
1717 1720
1718sub _scale($$$) { 1721sub _scale($$$) {
1719 my ($rel, $val, $max) = @_; 1722 my ($rel, $val, $max) = @_;
1720 1723
1721 $rel ? $val * $max : $val 1724 $rel ? $val * $max : $val
1773 1 1776 1
1774} 1777}
1775 1778
1776############################################################################# 1779#############################################################################
1777 1780
1778package CFPlus::UI::Box; 1781package dc::UI::Box;
1779 1782
1780our @ISA = CFPlus::UI::Container::; 1783our @ISA = dc::UI::Container::;
1781 1784
1782sub size_request { 1785sub size_request {
1783 my ($self) = @_; 1786 my ($self) = @_;
1784 1787
1785 my @children = $self->visible_children; 1788 my @children = $self->visible_children;
1820 $req[$_] += $space * $children[$_]{expand} 1823 $req[$_] += $space * $children[$_]{expand}
1821 for 0 .. $#children; 1824 for 0 .. $#children;
1822 } 1825 }
1823 } 1826 }
1824 1827
1825 CFPlus::UI::harmonize \@req; 1828 dc::UI::harmonize \@req;
1826 1829
1827 my $pos = 0; 1830 my $pos = 0;
1828 for (0 .. $#children) { 1831 for (0 .. $#children) {
1829 my $alloc = $req[$_]; 1832 my $alloc = $req[$_];
1830 $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));
1835 1 1838 1
1836} 1839}
1837 1840
1838############################################################################# 1841#############################################################################
1839 1842
1840package CFPlus::UI::HBox; 1843package dc::UI::HBox;
1841 1844
1842our @ISA = CFPlus::UI::Box::; 1845our @ISA = dc::UI::Box::;
1843 1846
1844sub new { 1847sub new {
1845 my $class = shift; 1848 my $class = shift;
1846 1849
1847 $class->SUPER::new ( 1850 $class->SUPER::new (
1850 ) 1853 )
1851} 1854}
1852 1855
1853############################################################################# 1856#############################################################################
1854 1857
1855package CFPlus::UI::VBox; 1858package dc::UI::VBox;
1856 1859
1857our @ISA = CFPlus::UI::Box::; 1860our @ISA = dc::UI::Box::;
1858 1861
1859sub new { 1862sub new {
1860 my $class = shift; 1863 my $class = shift;
1861 1864
1862 $class->SUPER::new ( 1865 $class->SUPER::new (
1865 ) 1868 )
1866} 1869}
1867 1870
1868############################################################################# 1871#############################################################################
1869 1872
1870package CFPlus::UI::Label; 1873package dc::UI::Label;
1871 1874
1872our @ISA = CFPlus::UI::DrawBG::; 1875our @ISA = dc::UI::DrawBG::;
1873 1876
1874use CFPlus::OpenGL; 1877use dc::OpenGL;
1875 1878
1876sub new { 1879sub new {
1877 my ($class, %arg) = @_; 1880 my ($class, %arg) = @_;
1878 1881
1879 my $self = $class->SUPER::new ( 1882 my $self = $class->SUPER::new (
1884 #text => initial text 1887 #text => initial text
1885 #markup => initial narkup 1888 #markup => initial narkup
1886 #max_w => maximum pixel width 1889 #max_w => maximum pixel width
1887 #style => 0, # render flags 1890 #style => 0, # render flags
1888 ellipsise => 3, # end 1891 ellipsise => 3, # end
1889 layout => (new CFPlus::Layout), 1892 layout => (new dc::Layout),
1890 fontsize => 1, 1893 fontsize => 1,
1891 align => -1, 1894 align => -1,
1892 valign => -1, 1895 valign => -1,
1893 padding_x => 2, 1896 padding_x => 2,
1894 padding_y => 2, 1897 padding_y => 2,
1895 can_events => 0, 1898 can_events => 0,
1896 %arg 1899 %arg
1897 ); 1900 );
1898 1901
1899 if (exists $self->{template}) { 1902 if (exists $self->{template}) {
1900 my $layout = new CFPlus::Layout; 1903 my $layout = new dc::Layout;
1901 $layout->set_text (delete $self->{template}); 1904 $layout->set_text (delete $self->{template});
1902 $self->{template} = $layout; 1905 $self->{template} = $layout;
1903 } 1906 }
1904 1907
1905 if (exists $self->{markup}) { 1908 if (exists $self->{markup}) {
2051 2054
2052 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2055 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2053 }; 2056 };
2054 2057
2055# unless ($self->{list}) { 2058# unless ($self->{list}) {
2056# $self->{list} = CFPlus::OpenGL::glGenList; 2059# $self->{list} = dc::OpenGL::glGenList;
2057# CFPlus::OpenGL::glNewList $self->{list}; 2060# dc::OpenGL::glNewList $self->{list};
2058# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2061# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2059# CFPlus::OpenGL::glEndList; 2062# dc::OpenGL::glEndList;
2060# } 2063# }
2061# 2064#
2062# CFPlus::OpenGL::glCallList $self->{list}; 2065# dc::OpenGL::glCallList $self->{list};
2063 2066
2064 $self->{layout}->draw; 2067 $self->{layout}->draw;
2065} 2068}
2066 2069
2067#sub destroy { 2070#sub destroy {
2068# my ($self) = @_; 2071# my ($self) = @_;
2069# 2072#
2070# CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; 2073# dc::OpenGL::glDeleteList delete $self->{list} if $self->{list};
2071# 2074#
2072# $self->SUPER::destroy; 2075# $self->SUPER::destroy;
2073#} 2076#}
2074 2077
2075############################################################################# 2078#############################################################################
2076 2079
2077package CFPlus::UI::EntryBase; 2080package dc::UI::EntryBase;
2078 2081
2079our @ISA = CFPlus::UI::Label::; 2082our @ISA = dc::UI::Label::;
2080 2083
2081use CFPlus::OpenGL; 2084use dc::OpenGL;
2082 2085
2083sub new { 2086sub new {
2084 my $class = shift; 2087 my $class = shift;
2085 2088
2086 $class->SUPER::new ( 2089 $class->SUPER::new (
2153 2156
2154 if ($uni == 8) { 2157 if ($uni == 8) {
2155 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2158 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
2156 } elsif ($uni == 127) { 2159 } elsif ($uni == 127) {
2157 substr $text, $self->{cursor}, 1, ""; 2160 substr $text, $self->{cursor}, 1, "";
2158 } elsif ($sym == CFPlus::SDLK_LEFT) { 2161 } elsif ($sym == dc::SDLK_LEFT) {
2159 --$self->{cursor} if $self->{cursor}; 2162 --$self->{cursor} if $self->{cursor};
2160 } elsif ($sym == CFPlus::SDLK_RIGHT) { 2163 } elsif ($sym == dc::SDLK_RIGHT) {
2161 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 2164 ++$self->{cursor} if $self->{cursor} < length $self->{text};
2162 } elsif ($sym == CFPlus::SDLK_HOME) { 2165 } elsif ($sym == dc::SDLK_HOME) {
2163 # what a hack 2166 # what a hack
2164 $self->{cursor} = 2167 $self->{cursor} =
2165 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ 2168 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/
2166 ? length $1 2169 ? length $1
2167 : 0; 2170 : 0;
2168 } elsif ($sym == CFPlus::SDLK_END) { 2171 } elsif ($sym == dc::SDLK_END) {
2169 # uh, again 2172 # uh, again
2170 $self->{cursor} = 2173 $self->{cursor} =
2171 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ 2174 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/
2172 ? $self->{cursor} + length $1 2175 ? $self->{cursor} + length $1
2173 : length $self->{text}; 2176 : length $self->{text};
2276 } 2279 }
2277} 2280}
2278 2281
2279############################################################################# 2282#############################################################################
2280 2283
2281package CFPlus::UI::Entry; 2284package dc::UI::Entry;
2282 2285
2283our @ISA = CFPlus::UI::EntryBase::; 2286our @ISA = dc::UI::EntryBase::;
2284 2287
2285use CFPlus::OpenGL; 2288use dc::OpenGL;
2286 2289
2287sub invoke_key_down { 2290sub invoke_key_down {
2288 my ($self, $ev) = @_; 2291 my ($self, $ev) = @_;
2289 2292
2290 my $sym = $ev->{sym}; 2293 my $sym = $ev->{sym};
2296 $self->{history_pointer} = -1; 2299 $self->{history_pointer} = -1;
2297 $self->{history_saveback} = ''; 2300 $self->{history_saveback} = '';
2298 $self->emit (activate => $txt); 2301 $self->emit (activate => $txt);
2299 $self->update; 2302 $self->update;
2300 2303
2301 } elsif ($sym == CFPlus::SDLK_UP) { 2304 } elsif ($sym == dc::SDLK_UP) {
2302 if ($self->{history_pointer} < 0) { 2305 if ($self->{history_pointer} < 0) {
2303 $self->{history_saveback} = $self->get_text; 2306 $self->{history_saveback} = $self->get_text;
2304 } 2307 }
2305 if (@{$self->{history} || []} > 0) { 2308 if (@{$self->{history} || []} > 0) {
2306 $self->{history_pointer}++; 2309 $self->{history_pointer}++;
2308 $self->{history_pointer} = @{$self->{history} || []} - 1; 2311 $self->{history_pointer} = @{$self->{history} || []} - 1;
2309 } 2312 }
2310 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2313 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2311 } 2314 }
2312 2315
2313 } elsif ($sym == CFPlus::SDLK_DOWN) { 2316 } elsif ($sym == dc::SDLK_DOWN) {
2314 $self->{history_pointer}--; 2317 $self->{history_pointer}--;
2315 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2318 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
2316 2319
2317 if ($self->{history_pointer} >= 0) { 2320 if ($self->{history_pointer} >= 0) {
2318 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2321 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2327 1 2330 1
2328} 2331}
2329 2332
2330############################################################################# 2333#############################################################################
2331 2334
2332package CFPlus::UI::TextEdit; 2335package dc::UI::TextEdit;
2333 2336
2334our @ISA = CFPlus::UI::EntryBase::; 2337our @ISA = dc::UI::EntryBase::;
2335 2338
2336use CFPlus::OpenGL; 2339use dc::OpenGL;
2337 2340
2338sub move_cursor_ver { 2341sub move_cursor_ver {
2339 my ($self, $dy) = @_; 2342 my ($self, $dy) = @_;
2340 2343
2341 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2344 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2353sub invoke_key_down { 2356sub invoke_key_down {
2354 my ($self, $ev) = @_; 2357 my ($self, $ev) = @_;
2355 2358
2356 my $sym = $ev->{sym}; 2359 my $sym = $ev->{sym};
2357 2360
2358 if ($sym == CFPlus::SDLK_UP) { 2361 if ($sym == dc::SDLK_UP) {
2359 $self->move_cursor_ver (-1); 2362 $self->move_cursor_ver (-1);
2360 } elsif ($sym == CFPlus::SDLK_DOWN) { 2363 } elsif ($sym == dc::SDLK_DOWN) {
2361 $self->move_cursor_ver (+1); 2364 $self->move_cursor_ver (+1);
2362 } else { 2365 } else {
2363 return $self->SUPER::invoke_key_down ($ev) 2366 return $self->SUPER::invoke_key_down ($ev)
2364 } 2367 }
2365 2368
2366 1 2369 1
2367} 2370}
2368 2371
2369############################################################################# 2372#############################################################################
2370 2373
2371package CFPlus::UI::ButtonBin; 2374package dc::UI::ButtonBin;
2372 2375
2373our @ISA = CFPlus::UI::Bin::; 2376our @ISA = dc::UI::Bin::;
2374 2377
2375use CFPlus::OpenGL; 2378use dc::OpenGL;
2376 2379
2377my @tex = 2380my @tex =
2378 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2381 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 }
2379 qw(b1_button_inactive.png b1_button_active.png); 2382 qw(b1_button_inactive.png b1_button_active.png);
2380 2383
2381sub new { 2384sub new {
2382 my $class = shift; 2385 my $class = shift;
2383 2386
2415 $self->SUPER::_draw; 2418 $self->SUPER::_draw;
2416} 2419}
2417 2420
2418############################################################################# 2421#############################################################################
2419 2422
2420package CFPlus::UI::Button; 2423package dc::UI::Button;
2421 2424
2422our @ISA = CFPlus::UI::Label::; 2425our @ISA = dc::UI::Label::;
2423 2426
2424use CFPlus::OpenGL; 2427use dc::OpenGL;
2425 2428
2426my @tex = 2429my @tex =
2427 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2430 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 }
2428 qw(b1_button_inactive.png b1_button_active.png); 2431 qw(b1_button_inactive.png b1_button_active.png);
2429 2432
2430sub new { 2433sub new {
2431 my $class = shift; 2434 my $class = shift;
2432 2435
2470 $self->SUPER::_draw; 2473 $self->SUPER::_draw;
2471} 2474}
2472 2475
2473############################################################################# 2476#############################################################################
2474 2477
2475package CFPlus::UI::CheckBox; 2478package dc::UI::CheckBox;
2476 2479
2477our @ISA = CFPlus::UI::DrawBG::; 2480our @ISA = dc::UI::DrawBG::;
2478 2481
2479my @tex = 2482my @tex =
2480 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2483 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 }
2481 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2484 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2482 2485
2483use CFPlus::OpenGL; 2486use dc::OpenGL;
2484 2487
2485sub new { 2488sub new {
2486 my $class = shift; 2489 my $class = shift;
2487 2490
2488 $class->SUPER::new ( 2491 $class->SUPER::new (
2545 glDisable GL_TEXTURE_2D; 2548 glDisable GL_TEXTURE_2D;
2546} 2549}
2547 2550
2548############################################################################# 2551#############################################################################
2549 2552
2550package CFPlus::UI::Image; 2553package dc::UI::Image;
2551 2554
2552our @ISA = CFPlus::UI::Base::; 2555our @ISA = dc::UI::Base::;
2553 2556
2554use CFPlus::OpenGL; 2557use dc::OpenGL;
2555 2558
2556our %texture_cache; 2559our %texture_cache;
2557 2560
2558sub new { 2561sub new {
2559 my $class = shift; 2562 my $class = shift;
2566 2569
2567 $self->{path} || $self->{tex} 2570 $self->{path} || $self->{tex}
2568 or Carp::croak "'path' or 'tex' attributes required"; 2571 or Carp::croak "'path' or 'tex' attributes required";
2569 2572
2570 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2573 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2571 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; 2574 new_from_file dc::Texture dc::find_rcfile $self->{path}, mipmap => 1;
2572 2575
2573 CFPlus::weaken $texture_cache{$self->{path}}; 2576 dc::weaken $texture_cache{$self->{path}};
2574 2577
2575 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2578 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2576 2579
2577 $self 2580 $self
2578} 2581}
2579 2582
2580sub STORABLE_freeze { 2583sub STORABLE_freeze {
2581 my ($self, $cloning) = @_; 2584 my ($self, $cloning) = @_;
2582 2585
2583 $self->{path} 2586 $self->{path}
2584 or die "cannot serialise CFPlus::UI::Image on non-loadable images\n"; 2587 or die "cannot serialise dc::UI::Image on non-loadable images\n";
2585 2588
2586 $self->{path} 2589 $self->{path}
2587} 2590}
2588 2591
2589sub STORABLE_attach { 2592sub STORABLE_attach {
2620 glDisable GL_TEXTURE_2D; 2623 glDisable GL_TEXTURE_2D;
2621} 2624}
2622 2625
2623############################################################################# 2626#############################################################################
2624 2627
2625package CFPlus::UI::ImageButton; 2628package dc::UI::ImageButton;
2626 2629
2627our @ISA = CFPlus::UI::Image::; 2630our @ISA = dc::UI::Image::;
2628 2631
2629use CFPlus::OpenGL; 2632use dc::OpenGL;
2630 2633
2631my %textures; 2634my %textures;
2632 2635
2633sub new { 2636sub new {
2634 my $class = shift; 2637 my $class = shift;
2662 1 2665 1
2663} 2666}
2664 2667
2665############################################################################# 2668#############################################################################
2666 2669
2667package CFPlus::UI::VGauge; 2670package dc::UI::VGauge;
2668 2671
2669our @ISA = CFPlus::UI::Base::; 2672our @ISA = dc::UI::Base::;
2670 2673
2671use List::Util qw(min max); 2674use List::Util qw(min max);
2672 2675
2673use CFPlus::OpenGL; 2676use dc::OpenGL;
2674 2677
2675my %tex = ( 2678my %tex = (
2676 food => [ 2679 food => [
2677 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2680 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 }
2678 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2681 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2679 ], 2682 ],
2680 grace => [ 2683 grace => [
2681 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2684 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 }
2682 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2685 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2683 ], 2686 ],
2684 hp => [ 2687 hp => [
2685 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2688 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 }
2686 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2689 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2687 ], 2690 ],
2688 mana => [ 2691 mana => [
2689 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2692 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 }
2690 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2693 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2691 ], 2694 ],
2692); 2695);
2693 2696
2694# eg. VGauge->new (gauge => 'food'), default gauge: food 2697# eg. VGauge->new (gauge => 'food'), default gauge: food
2797 glDisable GL_TEXTURE_2D; 2800 glDisable GL_TEXTURE_2D;
2798} 2801}
2799 2802
2800############################################################################# 2803#############################################################################
2801 2804
2802package CFPlus::UI::Progress; 2805package dc::UI::Progress;
2803 2806
2804our @ISA = CFPlus::UI::Label::; 2807our @ISA = dc::UI::Label::;
2805 2808
2806use CFPlus::OpenGL; 2809use dc::OpenGL;
2807 2810
2808sub new { 2811sub new {
2809 my ($class, %arg) = @_; 2812 my ($class, %arg) = @_;
2810 2813
2811 my $self = $class->SUPER::new ( 2814 my $self = $class->SUPER::new (
2831 my ($self, $label) = @_; 2834 my ($self, $label) = @_;
2832 2835
2833 return if $self->{label} eq $label; 2836 return if $self->{label} eq $label;
2834 $self->{label} = $label; 2837 $self->{label} = $label;
2835 2838
2836 $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value}); 2839 $self->dc::UI::Progress::set_value (0 + delete $self->{value});
2837} 2840}
2838 2841
2839sub set_value { 2842sub set_value {
2840 my ($self, $value) = @_; 2843 my ($self, $value) = @_;
2841 2844
2878 } 2881 }
2879} 2882}
2880 2883
2881############################################################################# 2884#############################################################################
2882 2885
2883package CFPlus::UI::ExperienceProgress; 2886package dc::UI::ExperienceProgress;
2884 2887
2885our @ISA = CFPlus::UI::Progress::; 2888our @ISA = dc::UI::Progress::;
2886 2889
2887sub new { 2890sub new {
2888 my ($class, %arg) = @_; 2891 my ($class, %arg) = @_;
2889 2892
2890 my $self = $class->SUPER::new ( 2893 my $self = $class->SUPER::new (
2935 $self->SUPER::set_value ($v); 2938 $self->SUPER::set_value ($v);
2936} 2939}
2937 2940
2938############################################################################# 2941#############################################################################
2939 2942
2940package CFPlus::UI::Gauge; 2943package dc::UI::Gauge;
2941 2944
2942our @ISA = CFPlus::UI::VBox::; 2945our @ISA = dc::UI::VBox::;
2943 2946
2944sub new { 2947sub new {
2945 my ($class, %arg) = @_; 2948 my ($class, %arg) = @_;
2946 2949
2947 my $self = $class->SUPER::new ( 2950 my $self = $class->SUPER::new (
2949 can_hover => 1, 2952 can_hover => 1,
2950 can_events => 1, 2953 can_events => 1,
2951 %arg, 2954 %arg,
2952 ); 2955 );
2953 2956
2954 $self->add ($self->{value} = new CFPlus::UI::Label valign => +1, align => 0, template => "999"); 2957 $self->add ($self->{value} = new dc::UI::Label valign => +1, align => 0, template => "999");
2955 $self->add ($self->{gauge} = new CFPlus::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 2958 $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"); 2959 $self->add ($self->{max} = new dc::UI::Label valign => -1, align => 0, template => "999");
2957 2960
2958 $self 2961 $self
2959} 2962}
2960 2963
2961sub set_fontsize { 2964sub set_fontsize {
2982 $self->{value}->set_text ($val); 2985 $self->{value}->set_text ($val);
2983} 2986}
2984 2987
2985############################################################################# 2988#############################################################################
2986 2989
2987package CFPlus::UI::Slider; 2990package dc::UI::Slider;
2988 2991
2989use strict; 2992use strict;
2990 2993
2991use CFPlus::OpenGL; 2994use dc::OpenGL;
2992 2995
2993our @ISA = CFPlus::UI::DrawBG::; 2996our @ISA = dc::UI::DrawBG::;
2994 2997
2995my @tex = 2998my @tex =
2996 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_ } 2999 map { new_from_file dc::Texture dc::find_rcfile $_ }
2997 qw(s1_slider.png s1_slider_bg.png); 3000 qw(s1_slider.png s1_slider_bg.png);
2998 3001
2999sub new { 3002sub new {
3000 my $class = shift; 3003 my $class = shift;
3001 3004
3097sub invoke_mouse_wheel { 3100sub invoke_mouse_wheel {
3098 my ($self, $ev) = @_; 3101 my ($self, $ev) = @_;
3099 3102
3100 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 3103 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
3101 3104
3102 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; 3105 my $pagepart = $ev->{mod} & dc::KMOD_SHIFT ? 1 : 0.2;
3103 3106
3104 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); 3107 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
3105 3108
3106 1 3109 1
3107} 3110}
3160 glDisable GL_TEXTURE_2D; 3163 glDisable GL_TEXTURE_2D;
3161} 3164}
3162 3165
3163############################################################################# 3166#############################################################################
3164 3167
3165package CFPlus::UI::ValSlider; 3168package dc::UI::ValSlider;
3166 3169
3167our @ISA = CFPlus::UI::HBox::; 3170our @ISA = dc::UI::HBox::;
3168 3171
3169sub new { 3172sub new {
3170 my ($class, %arg) = @_; 3173 my ($class, %arg) = @_;
3171 3174
3172 my $range = delete $arg{range}; 3175 my $range = delete $arg{range};
3173 3176
3174 my $self = $class->SUPER::new ( 3177 my $self = $class->SUPER::new (
3175 slider => (new CFPlus::UI::Slider expand => 1, range => $range), 3178 slider => (new dc::UI::Slider expand => 1, range => $range),
3176 entry => (new CFPlus::UI::Label text => "", template => delete $arg{template}), 3179 entry => (new dc::UI::Label text => "", template => delete $arg{template}),
3177 to_value => sub { shift }, 3180 to_value => sub { shift },
3178 from_value => sub { shift }, 3181 from_value => sub { shift },
3179 %arg, 3182 %arg,
3180 ); 3183 );
3181 3184
3201sub set_range { shift->{slider}->set_range (@_) } 3204sub set_range { shift->{slider}->set_range (@_) }
3202sub set_value { shift->{slider}->set_value (@_) } 3205sub set_value { shift->{slider}->set_value (@_) }
3203 3206
3204############################################################################# 3207#############################################################################
3205 3208
3206package CFPlus::UI::TextScroller; 3209package dc::UI::TextScroller;
3207 3210
3208our @ISA = CFPlus::UI::HBox::; 3211our @ISA = dc::UI::HBox::;
3209 3212
3210use CFPlus::OpenGL; 3213use dc::OpenGL;
3211 3214
3212sub new { 3215sub new {
3213 my $class = shift; 3216 my $class = shift;
3214 3217
3215 my $self = $class->SUPER::new ( 3218 my $self = $class->SUPER::new (
3217 can_events => 1, 3220 can_events => 1,
3218 indent => 0, 3221 indent => 0,
3219 #font => default_font 3222 #font => default_font
3220 @_, 3223 @_,
3221 3224
3222 layout => (new CFPlus::Layout), 3225 layout => (new dc::Layout),
3223 par => [], 3226 par => [],
3224 max_par => 0, 3227 max_par => 0,
3225 height => 0, 3228 height => 0,
3226 children => [ 3229 children => [
3227 (new CFPlus::UI::Empty expand => 1), 3230 (new dc::UI::Empty expand => 1),
3228 (new CFPlus::UI::Slider vertical => 1), 3231 (new dc::UI::Slider vertical => 1),
3229 ], 3232 ],
3230 ); 3233 );
3231 3234
3232 $self->{children}[1]->connect (changed => sub { $self->update }); 3235 $self->{children}[1]->connect (changed => sub { $self->update });
3233 3236
3416 $ROOT->on_post_alloc ($self => sub { 3419 $ROOT->on_post_alloc ($self => sub {
3417 $self->force_uptodate; 3420 $self->force_uptodate;
3418 3421
3419 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 3422 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
3420 3423
3421 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 3424 $self->{texture} ||= new_from_opengl dc::Texture $W, $H, sub {
3422 glClearColor 0, 0, 0, 0; 3425 glClearColor 0, 0, 0, 0;
3423 glClear GL_COLOR_BUFFER_BIT; 3426 glClear GL_COLOR_BUFFER_BIT;
3424 3427
3425 package CFPlus::UI::Base; 3428 package dc::UI::Base;
3426 local ($draw_x, $draw_y, $draw_w, $draw_h) = 3429 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3427 (0, 0, $self->{w}, $self->{h}); 3430 (0, 0, $self->{w}, $self->{h});
3428 3431
3429 my $top = int $self->{children}[1]{range}[0]; 3432 my $top = int $self->{children}[1]{range}[0];
3430 3433
3489 $self->{children}[1]->draw; 3492 $self->{children}[1]->draw;
3490} 3493}
3491 3494
3492############################################################################# 3495#############################################################################
3493 3496
3494package CFPlus::UI::Animator; 3497package dc::UI::Animator;
3495 3498
3496use CFPlus::OpenGL; 3499use dc::OpenGL;
3497 3500
3498our @ISA = CFPlus::UI::Bin::; 3501our @ISA = dc::UI::Bin::;
3499 3502
3500sub moveto { 3503sub moveto {
3501 my ($self, $x, $y) = @_; 3504 my ($self, $x, $y) = @_;
3502 3505
3503 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 3506 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
3531 glPopMatrix; 3534 glPopMatrix;
3532} 3535}
3533 3536
3534############################################################################# 3537#############################################################################
3535 3538
3536package CFPlus::UI::Flopper; 3539package dc::UI::Flopper;
3537 3540
3538our @ISA = CFPlus::UI::Button::; 3541our @ISA = dc::UI::Button::;
3539 3542
3540sub new { 3543sub new {
3541 my $class = shift; 3544 my $class = shift;
3542 3545
3543 my $self = $class->SUPER::new ( 3546 my $self = $class->SUPER::new (
3555 $self->{other}->toggle_visibility; 3558 $self->{other}->toggle_visibility;
3556} 3559}
3557 3560
3558############################################################################# 3561#############################################################################
3559 3562
3560package CFPlus::UI::Tooltip; 3563package dc::UI::Tooltip;
3561 3564
3562our @ISA = CFPlus::UI::Bin::; 3565our @ISA = dc::UI::Bin::;
3563 3566
3564use CFPlus::OpenGL; 3567use dc::OpenGL;
3565 3568
3566sub new { 3569sub new {
3567 my $class = shift; 3570 my $class = shift;
3568 3571
3569 $class->SUPER::new ( 3572 $class->SUPER::new (
3576 my ($self, $widget) = @_; 3579 my ($self, $widget) = @_;
3577 3580
3578 my $tip = $widget->{tooltip}; 3581 my $tip = $widget->{tooltip};
3579 $tip = $tip->($widget) if "CODE" eq ref $tip; 3582 $tip = $tip->($widget) if "CODE" eq ref $tip;
3580 3583
3581 $tip = CFPlus::Pod::section_label tooltip => $1 3584 $tip = dc::Pod::section_label tooltip => $1
3582 if $tip =~ /^#(.*)$/; 3585 if $tip =~ /^#(.*)$/;
3583 3586
3584 if ($ENV{CFPLUS_DEBUG} & 2) { 3587 if ($ENV{CFPLUS_DEBUG} & 2) {
3585 $tip .= "\n\n" . (ref $widget) . "\n" 3588 $tip .= "\n\n" . (ref $widget) . "\n"
3586 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3589 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3589 } 3592 }
3590 3593
3591 $tip =~ s/^\n+//; 3594 $tip =~ s/^\n+//;
3592 $tip =~ s/\n+$//; 3595 $tip =~ s/\n+$//;
3593 3596
3594 $self->add (new CFPlus::UI::Label 3597 $self->add (new dc::UI::Label
3595 markup => $tip, 3598 markup => $tip,
3596 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3599 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3597 fontsize => 0.8, 3600 fontsize => 0.8,
3598 style => 1, # FLAG_INVERSE 3601 style => 1, # FLAG_INVERSE
3599 ellipsise => 0, 3602 ellipsise => 0,
3653 $self->SUPER::_draw; 3656 $self->SUPER::_draw;
3654} 3657}
3655 3658
3656############################################################################# 3659#############################################################################
3657 3660
3658package CFPlus::UI::Face; 3661package dc::UI::Face;
3659 3662
3660our @ISA = CFPlus::UI::DrawBG::; 3663our @ISA = dc::UI::DrawBG::;
3661 3664
3662use CFPlus::OpenGL; 3665use dc::OpenGL;
3663 3666
3664sub new { 3667sub new {
3665 my $class = shift; 3668 my $class = shift;
3666 3669
3667 my $self = $class->SUPER::new ( 3670 my $self = $class->SUPER::new (
3671 can_events => 0, 3674 can_events => 0,
3672 @_, 3675 @_,
3673 ); 3676 );
3674 3677
3675 if ($self->{anim} && $self->{animspeed}) { 3678 if ($self->{anim} && $self->{animspeed}) {
3676 CFPlus::weaken (my $widget = $self); 3679 dc::weaken (my $widget = $self);
3677 3680
3678 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed}; 3681 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed};
3679 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub { 3682 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub {
3680 return unless $::CONN; 3683 return unless $::CONN;
3681 3684
3787 $self->SUPER::destroy; 3790 $self->SUPER::destroy;
3788} 3791}
3789 3792
3790############################################################################# 3793#############################################################################
3791 3794
3792package CFPlus::UI::Buttonbar; 3795package dc::UI::Buttonbar;
3793 3796
3794our @ISA = CFPlus::UI::HBox::; 3797our @ISA = dc::UI::HBox::;
3795 3798
3796# TODO: should actually wrap buttons and other goodies. 3799# TODO: should actually wrap buttons and other goodies.
3797 3800
3798############################################################################# 3801#############################################################################
3799 3802
3800package CFPlus::UI::Menu; 3803package dc::UI::Menu;
3801 3804
3802our @ISA = CFPlus::UI::Toplevel::; 3805our @ISA = dc::UI::Toplevel::;
3803 3806
3804use CFPlus::OpenGL; 3807use dc::OpenGL;
3805 3808
3806sub new { 3809sub new {
3807 my $class = shift; 3810 my $class = shift;
3808 3811
3809 my $self = $class->SUPER::new ( 3812 my $self = $class->SUPER::new (
3810 items => [], 3813 items => [],
3811 z => 100, 3814 z => 100,
3812 @_, 3815 @_,
3813 ); 3816 );
3814 3817
3815 $self->add ($self->{vbox} = new CFPlus::UI::VBox); 3818 $self->add ($self->{vbox} = new dc::UI::VBox);
3816 3819
3817 for my $item (@{ $self->{items} }) { 3820 for my $item (@{ $self->{items} }) {
3818 my ($widget, $cb, $tooltip) = @$item; 3821 my ($widget, $cb, $tooltip) = @$item;
3819 3822
3820 # handle various types of items, only text for now 3823 # handle various types of items, only text for now
3821 if (!ref $widget) { 3824 if (!ref $widget) {
3822 if ($widget =~ /\t/) { 3825 if ($widget =~ /\t/) {
3823 my ($left, $right) = split /\t/, $widget, 2; 3826 my ($left, $right) = split /\t/, $widget, 2;
3824 3827
3825 $widget = new CFPlus::UI::HBox 3828 $widget = new dc::UI::HBox
3826 can_hover => 1, 3829 can_hover => 1,
3827 can_events => 1, 3830 can_events => 1,
3828 tooltip => $tooltip, 3831 tooltip => $tooltip,
3829 children => [ 3832 children => [
3830 (new CFPlus::UI::Label markup => $left, expand => 1), 3833 (new dc::UI::Label markup => $left, expand => 1),
3831 (new CFPlus::UI::Label markup => $right, align => +1), 3834 (new dc::UI::Label markup => $right, align => +1),
3832 ], 3835 ],
3833 ; 3836 ;
3834 3837
3835 } else { 3838 } else {
3836 $widget = new CFPlus::UI::Label 3839 $widget = new dc::UI::Label
3837 can_hover => 1, 3840 can_hover => 1,
3838 can_events => 1, 3841 can_events => 1,
3839 markup => $widget, 3842 markup => $widget,
3840 tooltip => $tooltip; 3843 tooltip => $tooltip;
3841 } 3844 }
3889 1 3892 1
3890} 3893}
3891 3894
3892############################################################################# 3895#############################################################################
3893 3896
3894package CFPlus::UI::Multiplexer; 3897package dc::UI::Multiplexer;
3895 3898
3896our @ISA = CFPlus::UI::Container::; 3899our @ISA = dc::UI::Container::;
3897 3900
3898sub new { 3901sub new {
3899 my $class = shift; 3902 my $class = shift;
3900 3903
3901 my $self = $class->SUPER::new ( 3904 my $self = $class->SUPER::new (
3962 $self->{current}->draw; 3965 $self->{current}->draw;
3963} 3966}
3964 3967
3965############################################################################# 3968#############################################################################
3966 3969
3967package CFPlus::UI::Notebook; 3970package dc::UI::Notebook;
3968 3971
3969use CFPlus::OpenGL; 3972use dc::OpenGL;
3970 3973
3971our @ISA = CFPlus::UI::VBox::; 3974our @ISA = dc::UI::VBox::;
3972 3975
3973sub new { 3976sub new {
3974 my $class = shift; 3977 my $class = shift;
3975 3978
3976 my $self = $class->SUPER::new ( 3979 my $self = $class->SUPER::new (
3977 buttonbar => (new CFPlus::UI::Buttonbar), 3980 buttonbar => (new dc::UI::Buttonbar),
3978 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3981 multiplexer => (new dc::UI::Multiplexer expand => 1),
3979 active_outline => [.7, .7, 0.2], 3982 active_outline => [.7, .7, 0.2],
3980 # filter => # will be put between multiplexer and $self 3983 # filter => # will be put between multiplexer and $self
3981 @_, 3984 @_,
3982 ); 3985 );
3983 3986
3992 3995
3993 for my $child (@$widgets) { 3996 for my $child (@$widgets) {
3994 Scalar::Util::weaken $child; 3997 Scalar::Util::weaken $child;
3995 $child->{c_tab_} ||= do { 3998 $child->{c_tab_} ||= do {
3996 my $tab = 3999 my $tab =
3997 (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") 4000 (UNIVERSAL::isa $child->{c_tab}, "dc::UI::Base")
3998 ? $child->{c_tab} 4001 ? $child->{c_tab}
3999 : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; 4002 : new dc::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1];
4000 4003
4001 $tab->connect (activate => sub { 4004 $tab->connect (activate => sub {
4002 $wself->set_current_page ($child); 4005 $wself->set_current_page ($child);
4003 }); 4006 });
4004 4007
4080 } 4083 }
4081} 4084}
4082 4085
4083############################################################################# 4086#############################################################################
4084 4087
4085package CFPlus::UI::Selector; 4088package dc::UI::Selector;
4086 4089
4087use utf8; 4090use utf8;
4088 4091
4089our @ISA = CFPlus::UI::Button::; 4092our @ISA = dc::UI::Button::;
4090 4093
4091sub new { 4094sub new {
4092 my $class = shift; 4095 my $class = shift;
4093 4096
4094 my $self = $class->SUPER::new ( 4097 my $self = $class->SUPER::new (
4111 my ($value, $title, $tooltip) = @$_; 4114 my ($value, $title, $tooltip) = @$_;
4112 4115
4113 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 4116 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
4114 } 4117 }
4115 4118
4116 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev); 4119 dc::UI::Menu->new (items => \@menu_items)->popup ($ev);
4117} 4120}
4118 4121
4119sub _set_value { 4122sub _set_value {
4120 my ($self, $value) = @_; 4123 my ($self, $value) = @_;
4121 4124
4144 $self->_set_value ($self->{value}); 4147 $self->_set_value ($self->{value});
4145} 4148}
4146 4149
4147############################################################################# 4150#############################################################################
4148 4151
4149package CFPlus::UI::Statusbox; 4152package dc::UI::Statusbox;
4150 4153
4151our @ISA = CFPlus::UI::VBox::; 4154our @ISA = dc::UI::VBox::;
4152 4155
4153sub new { 4156sub new {
4154 my $class = shift; 4157 my $class = shift;
4155 4158
4156 my $self = $class->SUPER::new ( 4159 my $self = $class->SUPER::new (
4157 fontsize => 0.8, 4160 fontsize => 0.8,
4158 @_, 4161 @_,
4159 ); 4162 );
4160 4163
4161 CFPlus::weaken (my $this = $self); 4164 dc::weaken (my $this = $self);
4162 4165
4163 $self->{timer} = EV::timer 1, 1, sub { $this->reorder }; 4166 $self->{timer} = EV::timer 1, 1, sub { $this->reorder };
4164 4167
4165 $self 4168 $self
4166} 4169}
4168sub reorder { 4171sub reorder {
4169 my ($self) = @_; 4172 my ($self) = @_;
4170 my $NOW = Time::HiRes::time; 4173 my $NOW = Time::HiRes::time;
4171 4174
4172 # freeze display when hovering over any label 4175 # freeze display when hovering over any label
4173 return if $CFPlus::UI::TOOLTIP->{owner} 4176 return if $dc::UI::TOOLTIP->{owner}
4174 && grep $CFPlus::UI::TOOLTIP->{owner} == $_->{label}, 4177 && grep $dc::UI::TOOLTIP->{owner} == $_->{label},
4175 values %{ $self->{item} }; 4178 values %{ $self->{item} };
4176 4179
4177 while (my ($k, $v) = each %{ $self->{item} }) { 4180 while (my ($k, $v) = each %{ $self->{item} }) {
4178 delete $self->{item}{$k} if $v->{timeout} < $NOW; 4181 delete $self->{item}{$k} if $v->{timeout} < $NOW;
4179 } 4182 }
4200 for ($short) { 4203 for ($short) {
4201 s/^\s+//; 4204 s/^\s+//;
4202 s/\s+/ /g; 4205 s/\s+/ /g;
4203 } 4206 }
4204 4207
4205 new CFPlus::UI::Label 4208 new dc::UI::Label
4206 markup => $short, 4209 markup => $short,
4207 tooltip => $item->{tooltip}, 4210 tooltip => $item->{tooltip},
4208 tooltip_font => $::FONT_PROP, 4211 tooltip_font => $::FONT_PROP,
4209 tooltip_width => 0.67, 4212 tooltip_width => 0.67,
4210 fontsize => $item->{fontsize} || $self->{fontsize}, 4213 fontsize => $item->{fontsize} || $self->{fontsize},
4289 $self->SUPER::destroy; 4292 $self->SUPER::destroy;
4290} 4293}
4291 4294
4292############################################################################# 4295#############################################################################
4293 4296
4294package CFPlus::UI::Root; 4297package dc::UI::Root;
4295 4298
4296our @ISA = CFPlus::UI::Container::; 4299our @ISA = dc::UI::Container::;
4297 4300
4298use List::Util qw(min max); 4301use List::Util qw(min max);
4299 4302
4300use CFPlus::OpenGL; 4303use dc::OpenGL;
4301 4304
4302sub new { 4305sub new {
4303 my $class = shift; 4306 my $class = shift;
4304 4307
4305 my $self = $class->SUPER::new ( 4308 my $self = $class->SUPER::new (
4306 visible => 1, 4309 visible => 1,
4307 @_, 4310 @_,
4308 ); 4311 );
4309 4312
4310 CFPlus::weaken ($self->{root} = $self); 4313 dc::weaken ($self->{root} = $self);
4311 4314
4312 $self 4315 $self
4313} 4316}
4314 4317
4315sub size_request { 4318sub size_request {
4363} 4366}
4364 4367
4365sub update { 4368sub update {
4366 my ($self) = @_; 4369 my ($self) = @_;
4367 4370
4368 $::WANT_REFRESH->start; 4371 $::WANT_REFRESH = 1;
4369} 4372}
4370 4373
4371sub add { 4374sub add {
4372 my ($self, @children) = @_; 4375 my ($self, @children) = @_;
4373 4376
4518 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 4521 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
4519 glMatrixMode GL_MODELVIEW; 4522 glMatrixMode GL_MODELVIEW;
4520 glLoadIdentity; 4523 glLoadIdentity;
4521 4524
4522 { 4525 {
4523 package CFPlus::UI::Base; 4526 package dc::UI::Base;
4524 4527
4525 local ($draw_x, $draw_y, $draw_w, $draw_h) = 4528 local ($draw_x, $draw_y, $draw_w, $draw_h) =
4526 (0, 0, $self->{w}, $self->{h}); 4529 (0, 0, $self->{w}, $self->{h});
4527 4530
4528 $self->_draw; 4531 $self->_draw;
4529 } 4532 }
4530} 4533}
4531 4534
4532############################################################################# 4535#############################################################################
4533 4536
4534package CFPlus::UI; 4537package dc::UI;
4535 4538
4536$ROOT = new CFPlus::UI::Root; 4539$ROOT = new dc::UI::Root;
4537$TOOLTIP = new CFPlus::UI::Tooltip z => 900; 4540$TOOLTIP = new dc::UI::Tooltip z => 900;
4538 4541
45391 45421
4540 4543

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines