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.453 by root, Wed Dec 26 20:46:39 2007 UTC vs.
Revision 1.457 by root, Fri Dec 28 15:05:20 2007 UTC

1package dc::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 dc; 8use DC;
9use dc::Pod; 9use DC::Pod;
10use dc::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;
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} & dc::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 dc::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 dc::UI::Base; 224package DC::UI::Base;
225 225
226use strict; 226use strict;
227 227
228use dc::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 dc::weaken ($dc::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 = $dc::UI::LAYOUT->{$self->{name}}) { 251 if (my $layout = $DC::UI::LAYOUT->{$self->{name}}) {
252 $self->{x} = $layout->{x} * $dc::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} * $dc::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} * $dc::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} * $dc::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 $dc::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 $dc::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}
389 my ($self, $x, $y, $w, $h) = @_; 389 my ($self, $x, $y, $w, $h) = @_;
390 390
391 if ($self->{aspect}) { 391 if ($self->{aspect}) {
392 my ($ow, $oh) = ($w, $h); 392 my ($ow, $oh) = ($w, $h);
393 393
394 $w = List::Util::min $w, dc::ceil $h * $self->{aspect}; 394 $w = List::Util::min $w, DC::ceil $h * $self->{aspect};
395 $h = List::Util::min $h, dc::ceil $w / $self->{aspect}; 395 $h = List::Util::min $h, DC::ceil $w / $self->{aspect};
396 396
397 # use alignment to adjust x, y 397 # use alignment to adjust x, y
398 398
399 $x += int 0.5 * ($ow - $w); 399 $x += int 0.5 * ($ow - $w);
400 $y += int 0.5 * ($oh - $h); 400 $y += int 0.5 * ($oh - $h);
441 441
442 return if $self->{tooltip} eq $tooltip; 442 return if $self->{tooltip} eq $tooltip;
443 443
444 $self->{tooltip} = $tooltip; 444 $self->{tooltip} = $tooltip;
445 445
446 if ($dc::UI::TOOLTIP->{owner} == $self) { 446 if ($DC::UI::TOOLTIP->{owner} == $self) {
447 delete $dc::UI::TOOLTIP->{owner}; 447 delete $DC::UI::TOOLTIP->{owner};
448 $dc::UI::TOOLTIP_WATCHER->invoke; 448 $DC::UI::TOOLTIP_WATCHER->invoke;
449 } 449 }
450} 450}
451 451
452# translate global coordinates to local coordinate system 452# translate global coordinates to local coordinate system
453sub coord2local { 453sub coord2local {
519sub connect { 519sub connect {
520 my ($self, $signal, $cb) = @_; 520 my ($self, $signal, $cb) = @_;
521 521
522 push @{ $self->{signal_cb}{$signal} }, $cb; 522 push @{ $self->{signal_cb}{$signal} }, $cb;
523 523
524 defined wantarray and dc::guard { 524 defined wantarray and DC::guard {
525 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, 525 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
526 @{ $self->{signal_cb}{$signal} }; 526 @{ $self->{signal_cb}{$signal} };
527 } 527 }
528} 528}
529 529
567# in .xs 567# in .xs
568 568
569sub set_parent { 569sub set_parent {
570 my ($self, $parent) = @_; 570 my ($self, $parent) = @_;
571 571
572 dc::weaken ($self->{parent} = $parent); 572 DC::weaken ($self->{parent} = $parent);
573 $self->set_visible if $parent->{visible}; 573 $self->set_visible if $parent->{visible};
574} 574}
575 575
576sub realloc { 576sub realloc {
577 my ($self) = @_; 577 my ($self) = @_;
615} 615}
616 616
617sub DESTROY { 617sub DESTROY {
618 my ($self) = @_; 618 my ($self) = @_;
619 619
620 return if dc::in_destruct; 620 return if DC::in_destruct;
621 621
622 local $@; 622 local $@;
623 eval { $self->destroy }; 623 eval { $self->destroy };
624 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 624 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
625 625
626 delete $WIDGET{$self+0}; 626 delete $WIDGET{$self+0};
627} 627}
628 628
629############################################################################# 629#############################################################################
630 630
631package dc::UI::DrawBG; 631package DC::UI::DrawBG;
632 632
633our @ISA = dc::UI::Base::; 633our @ISA = DC::UI::Base::;
634 634
635use strict; 635use strict;
636use dc::OpenGL; 636use DC::OpenGL;
637 637
638sub new { 638sub new {
639 my $class = shift; 639 my $class = shift;
640 640
641 $class->SUPER::new ( 641 $class->SUPER::new (
663 } 663 }
664} 664}
665 665
666############################################################################# 666#############################################################################
667 667
668package dc::UI::Empty; 668package DC::UI::Empty;
669 669
670our @ISA = dc::UI::Base::; 670our @ISA = DC::UI::Base::;
671 671
672sub new { 672sub new {
673 my ($class, %arg) = @_; 673 my ($class, %arg) = @_;
674 $class->SUPER::new (can_events => 0, %arg); 674 $class->SUPER::new (can_events => 0, %arg);
675} 675}
682 682
683sub draw { } 683sub draw { }
684 684
685############################################################################# 685#############################################################################
686 686
687package dc::UI::Container; 687package DC::UI::Container;
688 688
689our @ISA = dc::UI::Base::; 689our @ISA = DC::UI::Base::;
690 690
691sub new { 691sub new {
692 my ($class, %arg) = @_; 692 my ($class, %arg) = @_;
693 693
694 my $children = delete $arg{children}; 694 my $children = delete $arg{children};
788 $_->draw for $self->visible_children; 788 $_->draw for $self->visible_children;
789} 789}
790 790
791############################################################################# 791#############################################################################
792 792
793package dc::UI::Bin; 793package DC::UI::Bin;
794 794
795our @ISA = dc::UI::Container::; 795our @ISA = DC::UI::Container::;
796 796
797sub new { 797sub new {
798 my ($class, %arg) = @_; 798 my ($class, %arg) = @_;
799 799
800 my $child = (delete $arg{child}) || new dc::UI::Empty::; 800 my $child = (delete $arg{child}) || new DC::UI::Empty::;
801 801
802 $class->SUPER::new (children => [$child], %arg) 802 $class->SUPER::new (children => [$child], %arg)
803} 803}
804 804
805sub add { 805sub add {
812sub remove { 812sub remove {
813 my ($self, $widget) = @_; 813 my ($self, $widget) = @_;
814 814
815 $self->SUPER::remove ($widget); 815 $self->SUPER::remove ($widget);
816 816
817 $self->{children} = [new dc::UI::Empty] 817 $self->{children} = [new DC::UI::Empty]
818 unless @{$self->{children}}; 818 unless @{$self->{children}};
819} 819}
820 820
821sub child { $_[0]->{children}[0] } 821sub child { $_[0]->{children}[0] }
822 822
833} 833}
834 834
835############################################################################# 835#############################################################################
836# back-buffered drawing area 836# back-buffered drawing area
837 837
838package dc::UI::Window; 838package DC::UI::Window;
839 839
840our @ISA = dc::UI::Bin::; 840our @ISA = DC::UI::Bin::;
841 841
842use dc::OpenGL; 842use DC::OpenGL;
843 843
844sub new { 844sub new {
845 my ($class, %arg) = @_; 845 my ($class, %arg) = @_;
846 846
847 my $self = $class->SUPER::new (%arg); 847 my $self = $class->SUPER::new (%arg);
869} 869}
870 870
871sub render_child { 871sub render_child {
872 my ($self) = @_; 872 my ($self) = @_;
873 873
874 $self->{texture} = new_from_opengl dc::Texture $self->{w}, $self->{h}, sub { 874 $self->{texture} = new_from_opengl DC::Texture $self->{w}, $self->{h}, sub {
875 glClearColor 0, 0, 0, 0; 875 glClearColor 0, 0, 0, 0;
876 glClear GL_COLOR_BUFFER_BIT; 876 glClear GL_COLOR_BUFFER_BIT;
877 877
878 { 878 {
879 package dc::UI::Base; 879 package DC::UI::Base;
880 880
881 local ($draw_x, $draw_y, $draw_w, $draw_h) = 881 local ($draw_x, $draw_y, $draw_w, $draw_h) =
882 (0, 0, $self->{w}, $self->{h}); 882 (0, 0, $self->{w}, $self->{h});
883 883
884 $self->_render; 884 $self->_render;
901 glDisable GL_TEXTURE_2D; 901 glDisable GL_TEXTURE_2D;
902} 902}
903 903
904############################################################################# 904#############################################################################
905 905
906package dc::UI::ViewPort; 906package DC::UI::ViewPort;
907 907
908use List::Util qw(min max); 908use List::Util qw(min max);
909 909
910our @ISA = dc::UI::Window::; 910our @ISA = DC::UI::Window::;
911 911
912sub new { 912sub new {
913 my $class = shift; 913 my $class = shift;
914 914
915 $class->SUPER::new ( 915 $class->SUPER::new (
999 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 999 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
1000 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1000 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
1001 ) { 1001 ) {
1002 $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})
1003 } else { 1003 } else {
1004 $self->dc::UI::Base::find_widget ($x, $y) 1004 $self->DC::UI::Base::find_widget ($x, $y)
1005 } 1005 }
1006} 1006}
1007 1007
1008sub _render { 1008sub _render {
1009 my ($self) = @_; 1009 my ($self) = @_;
1010 1010
1011 local $dc::UI::Base::draw_x = $dc::UI::Base::draw_x - $self->{view_x}; 1011 local $DC::UI::Base::draw_x = $DC::UI::Base::draw_x - $self->{view_x};
1012 local $dc::UI::Base::draw_y = $dc::UI::Base::draw_y - $self->{view_y}; 1012 local $DC::UI::Base::draw_y = $DC::UI::Base::draw_y - $self->{view_y};
1013 1013
1014 dc::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 1014 DC::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
1015 1015
1016 $self->SUPER::_render; 1016 $self->SUPER::_render;
1017} 1017}
1018 1018
1019############################################################################# 1019#############################################################################
1020 1020
1021package dc::UI::ScrolledWindow; 1021package DC::UI::ScrolledWindow;
1022 1022
1023our @ISA = dc::UI::Table::; 1023our @ISA = DC::UI::Table::;
1024 1024
1025sub new { 1025sub new {
1026 my ($class, %arg) = @_; 1026 my ($class, %arg) = @_;
1027 1027
1028 my $child = delete $arg{child}; 1028 my $child = delete $arg{child};
1029 1029
1030 my $self; 1030 my $self;
1031 1031
1032 my $hslider = new dc::UI::Slider 1032 my $hslider = new DC::UI::Slider
1033 c_col => 0, 1033 c_col => 0,
1034 c_row => 1, 1034 c_row => 1,
1035 vertical => 0, 1035 vertical => 0,
1036 range => [0, 0, 1, 0.01], # HACK fix 1036 range => [0, 0, 1, 0.01], # HACK fix
1037 on_changed => sub { 1037 on_changed => sub {
1038 $self->{hpos} = $_[1]; 1038 $self->{hpos} = $_[1];
1039 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1039 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1040 }, 1040 },
1041 ; 1041 ;
1042 1042
1043 my $vslider = new dc::UI::Slider 1043 my $vslider = new DC::UI::Slider
1044 c_col => 1, 1044 c_col => 1,
1045 c_row => 0, 1045 c_row => 0,
1046 vertical => 1, 1046 vertical => 1,
1047 range => [0, 0, 1, 0.01], # HACK fix 1047 range => [0, 0, 1, 0.01], # HACK fix
1048 on_changed => sub { 1048 on_changed => sub {
1060 col_expand => [1, 0], 1060 col_expand => [1, 0],
1061 row_expand => [1, 0], 1061 row_expand => [1, 0],
1062 %arg, 1062 %arg,
1063 ); 1063 );
1064 1064
1065 $self->{vp} = new dc::UI::ViewPort 1065 $self->{vp} = new DC::UI::ViewPort
1066 c_col => 0, 1066 c_col => 0,
1067 c_row => 0, 1067 c_row => 0,
1068 expand => 1, 1068 expand => 1,
1069 scroll_x => $self->{scroll_x}, 1069 scroll_x => $self->{scroll_x},
1070 scroll_y => $self->{scroll_y}, 1070 scroll_y => $self->{scroll_y},
1196 $self->SUPER::invoke_size_allocate ($w, $h) 1196 $self->SUPER::invoke_size_allocate ($w, $h)
1197} 1197}
1198 1198
1199############################################################################# 1199#############################################################################
1200 1200
1201package dc::UI::Frame; 1201package DC::UI::Frame;
1202 1202
1203our @ISA = dc::UI::Bin::; 1203our @ISA = DC::UI::Bin::;
1204 1204
1205use dc::OpenGL; 1205use DC::OpenGL;
1206 1206
1207sub new { 1207sub new {
1208 my $class = shift; 1208 my $class = shift;
1209 1209
1210 $class->SUPER::new ( 1210 $class->SUPER::new (
1229 $self->SUPER::_draw; 1229 $self->SUPER::_draw;
1230} 1230}
1231 1231
1232############################################################################# 1232#############################################################################
1233 1233
1234package dc::UI::FancyFrame; 1234package DC::UI::FancyFrame;
1235 1235
1236our @ISA = dc::UI::Bin::; 1236our @ISA = DC::UI::Bin::;
1237 1237
1238use dc::OpenGL; 1238use DC::OpenGL;
1239 1239
1240sub new { 1240sub new {
1241 my ($class, %arg) = @_; 1241 my ($class, %arg) = @_;
1242 1242
1243 if ((exists $arg{label}) && !ref $arg{label}) { 1243 if ((exists $arg{label}) && !ref $arg{label}) {
1244 $arg{label} = new dc::UI::Label 1244 $arg{label} = new DC::UI::Label
1245 align => 1, 1245 align => 1,
1246 valign => 0, 1246 valign => 0,
1247 text => $arg{label}, 1247 text => $arg{label},
1248 fontsize => ($arg{border} || 0.8) * 0.75; 1248 fontsize => ($arg{border} || 0.8) * 0.75;
1249 } 1249 }
1261 1261
1262sub add { 1262sub add {
1263 my ($self, @widgets) = @_; 1263 my ($self, @widgets) = @_;
1264 1264
1265 $self->SUPER::add (@widgets); 1265 $self->SUPER::add (@widgets);
1266 $self->dc::UI::Container::add ($self->{label}) if $self->{label}; 1266 $self->DC::UI::Container::add ($self->{label}) if $self->{label};
1267} 1267}
1268 1268
1269sub border { 1269sub border {
1270 int $_[0]{border} * $::FONTSIZE 1270 int $_[0]{border} * $::FONTSIZE
1271} 1271}
1329 } 1329 }
1330} 1330}
1331 1331
1332############################################################################# 1332#############################################################################
1333 1333
1334package dc::UI::Toplevel; 1334package DC::UI::Toplevel;
1335 1335
1336our @ISA = dc::UI::Bin::; 1336our @ISA = DC::UI::Bin::;
1337 1337
1338use dc::OpenGL; 1338use DC::OpenGL;
1339 1339
1340my $bg = 1340my $bg =
1341 new_from_file dc::Texture dc::find_rcfile "d1_bg.png", 1341 new_from_file DC::Texture DC::find_rcfile "d1_bg.png",
1342 mipmap => 1, wrap => 1; 1342 mipmap => 1, wrap => 1;
1343 1343
1344my @border = 1344my @border =
1345 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 } 1345 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
1346 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);
1347 1347
1348my @icon = 1348my @icon =
1349 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 } 1349 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
1350 qw(x1_move.png x1_resize.png); 1350 qw(x1_move.png x1_resize.png);
1351 1351
1352sub new { 1352sub new {
1353 my ($class, %arg) = @_; 1353 my ($class, %arg) = @_;
1354 1354
1360 min_w => 64, 1360 min_w => 64,
1361 min_h => 32, 1361 min_h => 32,
1362 %arg, 1362 %arg,
1363 ); 1363 );
1364 1364
1365 $self->{title_widget} = new dc::UI::Label 1365 $self->{title_widget} = new DC::UI::Label
1366 align => 0, 1366 align => 0,
1367 valign => 1, 1367 valign => 1,
1368 text => $self->{title}, 1368 text => $self->{title},
1369 fontsize => $self->{border}, 1369 fontsize => $self->{border},
1370 if exists $self->{title}; 1370 if exists $self->{title};
1371 1371
1372 if ($self->{has_close_button}) { 1372 if ($self->{has_close_button}) {
1373 $self->{close_button} = 1373 $self->{close_button} =
1374 new dc::UI::ImageButton 1374 new DC::UI::ImageButton
1375 path => 'x1_close.png', 1375 path => 'x1_close.png',
1376 on_activate => sub { $self->emit ("delete") }; 1376 on_activate => sub { $self->emit ("delete") };
1377 1377
1378 $self->dc::UI::Container::add ($self->{close_button}); 1378 $self->DC::UI::Container::add ($self->{close_button});
1379 } 1379 }
1380 1380
1381 $self 1381 $self
1382} 1382}
1383 1383
1384sub add { 1384sub add {
1385 my ($self, @widgets) = @_; 1385 my ($self, @widgets) = @_;
1386 1386
1387 $self->SUPER::add (@widgets); 1387 $self->SUPER::add (@widgets);
1388 $self->dc::UI::Container::add ($self->{close_button}) if $self->{close_button}; 1388 $self->DC::UI::Container::add ($self->{close_button}) if $self->{close_button};
1389 $self->dc::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; 1389 $self->DC::UI::Container::add ($self->{title_widget}) if $self->{title_widget};
1390} 1390}
1391 1391
1392sub border { 1392sub border {
1393 int $_[0]{border} * $::FONTSIZE 1393 int $_[0]{border} * $::FONTSIZE
1394} 1394}
1579 if $self->{close_button}; 1579 if $self->{close_button};
1580} 1580}
1581 1581
1582############################################################################# 1582#############################################################################
1583 1583
1584package dc::UI::Table; 1584package DC::UI::Table;
1585 1585
1586our @ISA = dc::UI::Container::; 1586our @ISA = DC::UI::Container::;
1587 1587
1588use List::Util qw(max sum); 1588use List::Util qw(max sum);
1589 1589
1590use dc::OpenGL; 1590use DC::OpenGL;
1591 1591
1592sub new { 1592sub new {
1593 my $class = shift; 1593 my $class = shift;
1594 1594
1595 $class->SUPER::new ( 1595 $class->SUPER::new (
1639 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; 1639 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)};
1640 1640
1641 my $sw = sum @w[$c .. $c + $cs - 1]; 1641 my $sw = sum @w[$c .. $c + $cs - 1];
1642 1642
1643 if ($w > $sw) { 1643 if ($w > $sw) {
1644 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; 1644 $_ += ($w - $sw) / ($_ ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1];
1645 } 1645 }
1646 } 1646 }
1647 1647
1648 # second pass, rows 1648 # second pass, rows
1649 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { 1649 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) {
1650 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; 1650 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)};
1651 1651
1652 my $sh = sum @h[$r .. $r + $rs - 1]; 1652 my $sh = sum @h[$r .. $r + $rs - 1];
1653 1653
1654 if ($h > $sh) { 1654 if ($h > $sh) {
1655 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; 1655 $_ += ($h - $sh) / ($_ ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1];
1656 } 1656 }
1657 } 1657 }
1658 1658
1659 (\@w, \@h) 1659 (\@w, \@h)
1660} 1660}
1683 @col_expand = (1) x @$ws unless @col_expand; 1683 @col_expand = (1) x @$ws unless @col_expand;
1684 my $col_expand = (sum @col_expand) || 1; 1684 my $col_expand = (sum @col_expand) || 1;
1685 1685
1686 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1686 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1687 1687
1688 dc::UI::harmonize $ws; 1688 DC::UI::harmonize $ws;
1689 1689
1690 my @row_expand = @{$self->{row_expand}}; 1690 my @row_expand = @{$self->{row_expand}};
1691 @row_expand = (1) x @$ws unless @row_expand; 1691 @row_expand = (1) x @$ws unless @row_expand;
1692 my $row_expand = (sum @row_expand) || 1; 1692 my $row_expand = (sum @row_expand) || 1;
1693 1693
1694 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; 1694 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1695 1695
1696 dc::UI::harmonize $hs; 1696 DC::UI::harmonize $hs;
1697 1697
1698 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } 1698 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] }
1699 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } 1699 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] }
1700 1700
1701 for my $widget ($self->children) { 1701 for my $widget ($self->children) {
1710 1 1710 1
1711} 1711}
1712 1712
1713############################################################################# 1713#############################################################################
1714 1714
1715package dc::UI::Fixed; 1715package DC::UI::Fixed;
1716 1716
1717use List::Util qw(min max); 1717use List::Util qw(min max);
1718 1718
1719our @ISA = dc::UI::Container::; 1719our @ISA = DC::UI::Container::;
1720 1720
1721sub _scale($$$) { 1721sub _scale($$$) {
1722 my ($rel, $val, $max) = @_; 1722 my ($rel, $val, $max) = @_;
1723 1723
1724 $rel ? $val * $max : $val 1724 $rel ? $val * $max : $val
1776 1 1776 1
1777} 1777}
1778 1778
1779############################################################################# 1779#############################################################################
1780 1780
1781package dc::UI::Box; 1781package DC::UI::Box;
1782 1782
1783our @ISA = dc::UI::Container::; 1783our @ISA = DC::UI::Container::;
1784 1784
1785sub size_request { 1785sub size_request {
1786 my ($self) = @_; 1786 my ($self) = @_;
1787 1787
1788 my @children = $self->visible_children; 1788 my @children = $self->visible_children;
1823 $req[$_] += $space * $children[$_]{expand} 1823 $req[$_] += $space * $children[$_]{expand}
1824 for 0 .. $#children; 1824 for 0 .. $#children;
1825 } 1825 }
1826 } 1826 }
1827 1827
1828 dc::UI::harmonize \@req; 1828 DC::UI::harmonize \@req;
1829 1829
1830 my $pos = 0; 1830 my $pos = 0;
1831 for (0 .. $#children) { 1831 for (0 .. $#children) {
1832 my $alloc = $req[$_]; 1832 my $alloc = $req[$_];
1833 $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));
1838 1 1838 1
1839} 1839}
1840 1840
1841############################################################################# 1841#############################################################################
1842 1842
1843package dc::UI::HBox; 1843package DC::UI::HBox;
1844 1844
1845our @ISA = dc::UI::Box::; 1845our @ISA = DC::UI::Box::;
1846 1846
1847sub new { 1847sub new {
1848 my $class = shift; 1848 my $class = shift;
1849 1849
1850 $class->SUPER::new ( 1850 $class->SUPER::new (
1853 ) 1853 )
1854} 1854}
1855 1855
1856############################################################################# 1856#############################################################################
1857 1857
1858package dc::UI::VBox; 1858package DC::UI::VBox;
1859 1859
1860our @ISA = dc::UI::Box::; 1860our @ISA = DC::UI::Box::;
1861 1861
1862sub new { 1862sub new {
1863 my $class = shift; 1863 my $class = shift;
1864 1864
1865 $class->SUPER::new ( 1865 $class->SUPER::new (
1868 ) 1868 )
1869} 1869}
1870 1870
1871############################################################################# 1871#############################################################################
1872 1872
1873package dc::UI::Label; 1873package DC::UI::Label;
1874 1874
1875our @ISA = dc::UI::DrawBG::; 1875our @ISA = DC::UI::DrawBG::;
1876 1876
1877use dc::OpenGL; 1877use DC::OpenGL;
1878 1878
1879sub new { 1879sub new {
1880 my ($class, %arg) = @_; 1880 my ($class, %arg) = @_;
1881 1881
1882 my $self = $class->SUPER::new ( 1882 my $self = $class->SUPER::new (
1887 #text => initial text 1887 #text => initial text
1888 #markup => initial narkup 1888 #markup => initial narkup
1889 #max_w => maximum pixel width 1889 #max_w => maximum pixel width
1890 #style => 0, # render flags 1890 #style => 0, # render flags
1891 ellipsise => 3, # end 1891 ellipsise => 3, # end
1892 layout => (new dc::Layout), 1892 layout => (new DC::Layout),
1893 fontsize => 1, 1893 fontsize => 1,
1894 align => -1, 1894 align => -1,
1895 valign => -1, 1895 valign => -1,
1896 padding_x => 2, 1896 padding_x => 2,
1897 padding_y => 2, 1897 padding_y => 2,
1898 can_events => 0, 1898 can_events => 0,
1899 %arg 1899 %arg
1900 ); 1900 );
1901 1901
1902 if (exists $self->{template}) { 1902 if (exists $self->{template}) {
1903 my $layout = new dc::Layout; 1903 my $layout = new DC::Layout;
1904 $layout->set_text (delete $self->{template}); 1904 $layout->set_text (delete $self->{template});
1905 $self->{template} = $layout; 1905 $self->{template} = $layout;
1906 } 1906 }
1907 1907
1908 if (exists $self->{markup}) { 1908 if (exists $self->{markup}) {
2054 2054
2055 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2055 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2056 }; 2056 };
2057 2057
2058# unless ($self->{list}) { 2058# unless ($self->{list}) {
2059# $self->{list} = dc::OpenGL::glGenList; 2059# $self->{list} = DC::OpenGL::glGenList;
2060# dc::OpenGL::glNewList $self->{list}; 2060# DC::OpenGL::glNewList $self->{list};
2061# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2061# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2062# dc::OpenGL::glEndList; 2062# DC::OpenGL::glEndList;
2063# } 2063# }
2064# 2064#
2065# dc::OpenGL::glCallList $self->{list}; 2065# DC::OpenGL::glCallList $self->{list};
2066 2066
2067 $self->{layout}->draw; 2067 $self->{layout}->draw;
2068} 2068}
2069 2069
2070#sub destroy { 2070#sub destroy {
2071# my ($self) = @_; 2071# my ($self) = @_;
2072# 2072#
2073# dc::OpenGL::glDeleteList delete $self->{list} if $self->{list}; 2073# DC::OpenGL::glDeleteList delete $self->{list} if $self->{list};
2074# 2074#
2075# $self->SUPER::destroy; 2075# $self->SUPER::destroy;
2076#} 2076#}
2077 2077
2078############################################################################# 2078#############################################################################
2079 2079
2080package dc::UI::EntryBase; 2080package DC::UI::EntryBase;
2081 2081
2082our @ISA = dc::UI::Label::; 2082our @ISA = DC::UI::Label::;
2083 2083
2084use dc::OpenGL; 2084use DC::OpenGL;
2085 2085
2086sub new { 2086sub new {
2087 my $class = shift; 2087 my $class = shift;
2088 2088
2089 $class->SUPER::new ( 2089 $class->SUPER::new (
2096 can_hover => 1, 2096 can_hover => 1,
2097 can_focus => 1, 2097 can_focus => 1,
2098 valign => 0, 2098 valign => 0,
2099 can_events => 1, 2099 can_events => 1,
2100 ellipsise => 0, 2100 ellipsise => 0,
2101 padding_x => 4,
2102 padding_y => 2,
2101 #text => ... 2103 #text => ...
2102 #hidden => "*", 2104 #hidden => "*",
2103 @_ 2105 @_
2104 ) 2106 )
2105} 2107}
2156 2158
2157 if ($uni == 8) { 2159 if ($uni == 8) {
2158 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2160 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
2159 } elsif ($uni == 127) { 2161 } elsif ($uni == 127) {
2160 substr $text, $self->{cursor}, 1, ""; 2162 substr $text, $self->{cursor}, 1, "";
2161 } elsif ($sym == dc::SDLK_LEFT) { 2163 } elsif ($sym == DC::SDLK_LEFT) {
2162 --$self->{cursor} if $self->{cursor}; 2164 --$self->{cursor} if $self->{cursor};
2163 } elsif ($sym == dc::SDLK_RIGHT) { 2165 } elsif ($sym == DC::SDLK_RIGHT) {
2164 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 2166 ++$self->{cursor} if $self->{cursor} < length $self->{text};
2165 } elsif ($sym == dc::SDLK_HOME) { 2167 } elsif ($sym == DC::SDLK_HOME) {
2166 # what a hack 2168 # what a hack
2167 $self->{cursor} = 2169 $self->{cursor} =
2168 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ 2170 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/
2169 ? length $1 2171 ? length $1
2170 : 0; 2172 : 0;
2171 } elsif ($sym == dc::SDLK_END) { 2173 } elsif ($sym == DC::SDLK_END) {
2172 # uh, again 2174 # uh, again
2173 $self->{cursor} = 2175 $self->{cursor} =
2174 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ 2176 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/
2175 ? $self->{cursor} + length $1 2177 ? $self->{cursor} + length $1
2176 : length $self->{text}; 2178 : length $self->{text};
2279 } 2281 }
2280} 2282}
2281 2283
2282############################################################################# 2284#############################################################################
2283 2285
2284package dc::UI::Entry; 2286package DC::UI::Entry;
2285 2287
2286our @ISA = dc::UI::EntryBase::; 2288our @ISA = DC::UI::EntryBase::;
2287 2289
2288use dc::OpenGL; 2290use DC::OpenGL;
2289 2291
2290sub invoke_key_down { 2292sub invoke_key_down {
2291 my ($self, $ev) = @_; 2293 my ($self, $ev) = @_;
2292 2294
2293 my $sym = $ev->{sym}; 2295 my $sym = $ev->{sym};
2299 $self->{history_pointer} = -1; 2301 $self->{history_pointer} = -1;
2300 $self->{history_saveback} = ''; 2302 $self->{history_saveback} = '';
2301 $self->emit (activate => $txt); 2303 $self->emit (activate => $txt);
2302 $self->update; 2304 $self->update;
2303 2305
2304 } elsif ($sym == dc::SDLK_UP) { 2306 } elsif ($sym == DC::SDLK_UP) {
2305 if ($self->{history_pointer} < 0) { 2307 if ($self->{history_pointer} < 0) {
2306 $self->{history_saveback} = $self->get_text; 2308 $self->{history_saveback} = $self->get_text;
2307 } 2309 }
2308 if (@{$self->{history} || []} > 0) { 2310 if (@{$self->{history} || []} > 0) {
2309 $self->{history_pointer}++; 2311 $self->{history_pointer}++;
2311 $self->{history_pointer} = @{$self->{history} || []} - 1; 2313 $self->{history_pointer} = @{$self->{history} || []} - 1;
2312 } 2314 }
2313 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2315 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2314 } 2316 }
2315 2317
2316 } elsif ($sym == dc::SDLK_DOWN) { 2318 } elsif ($sym == DC::SDLK_DOWN) {
2317 $self->{history_pointer}--; 2319 $self->{history_pointer}--;
2318 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2320 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
2319 2321
2320 if ($self->{history_pointer} >= 0) { 2322 if ($self->{history_pointer} >= 0) {
2321 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2323 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2330 1 2332 1
2331} 2333}
2332 2334
2333############################################################################# 2335#############################################################################
2334 2336
2335package dc::UI::TextEdit; 2337package DC::UI::TextEdit;
2336 2338
2337our @ISA = dc::UI::EntryBase::; 2339our @ISA = DC::UI::EntryBase::;
2338 2340
2339use dc::OpenGL; 2341use DC::OpenGL;
2342
2343sub new {
2344 my $class = shift;
2345
2346 $class->SUPER::new (
2347 padding_y => 4,
2348
2349 @_
2350 )
2351}
2340 2352
2341sub move_cursor_ver { 2353sub move_cursor_ver {
2342 my ($self, $dy) = @_; 2354 my ($self, $dy) = @_;
2343 2355
2344 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2356 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2357 warn "cursor $self->{cursor} => $x $line\n";#d#
2345 2358
2346 $y += $dy; 2359 $line += $dy;
2347 2360
2348 if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { 2361 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) {
2362 warn "index $x $line => $index\n";#d#
2349 $self->{cursor} = $index; 2363 $self->{cursor} = $index;
2350 delete $self->{cur_h}; 2364 delete $self->{cur_h};
2351 $self->update; 2365 $self->update;
2352 return; 2366 return;
2353 } 2367 }
2356sub invoke_key_down { 2370sub invoke_key_down {
2357 my ($self, $ev) = @_; 2371 my ($self, $ev) = @_;
2358 2372
2359 my $sym = $ev->{sym}; 2373 my $sym = $ev->{sym};
2360 2374
2361 if ($sym == dc::SDLK_UP) { 2375 if ($sym == DC::SDLK_UP) {
2362 $self->move_cursor_ver (-1); 2376 $self->move_cursor_ver (-1);
2363 } elsif ($sym == dc::SDLK_DOWN) { 2377 } elsif ($sym == DC::SDLK_DOWN) {
2364 $self->move_cursor_ver (+1); 2378 $self->move_cursor_ver (+1);
2365 } else { 2379 } else {
2366 return $self->SUPER::invoke_key_down ($ev) 2380 return $self->SUPER::invoke_key_down ($ev)
2367 } 2381 }
2368 2382
2369 1 2383 1
2370} 2384}
2371 2385
2372############################################################################# 2386#############################################################################
2373 2387
2374package dc::UI::ButtonBin; 2388package DC::UI::ButtonBin;
2375 2389
2376our @ISA = dc::UI::Bin::; 2390our @ISA = DC::UI::Bin::;
2377 2391
2378use dc::OpenGL; 2392use DC::OpenGL;
2379 2393
2380my @tex = 2394my @tex =
2381 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 } 2395 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2382 qw(b1_button_inactive.png b1_button_active.png); 2396 qw(b1_button_inactive.png b1_button_active.png);
2383 2397
2384sub new { 2398sub new {
2385 my $class = shift; 2399 my $class = shift;
2386 2400
2418 $self->SUPER::_draw; 2432 $self->SUPER::_draw;
2419} 2433}
2420 2434
2421############################################################################# 2435#############################################################################
2422 2436
2423package dc::UI::Button; 2437package DC::UI::Button;
2424 2438
2425our @ISA = dc::UI::Label::; 2439our @ISA = DC::UI::Label::;
2426 2440
2427use dc::OpenGL; 2441use DC::OpenGL;
2428 2442
2429my @tex = 2443my @tex =
2430 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 } 2444 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2431 qw(b1_button_inactive.png b1_button_active.png); 2445 qw(b1_button_inactive.png b1_button_active.png);
2432 2446
2433sub new { 2447sub new {
2434 my $class = shift; 2448 my $class = shift;
2435 2449
2436 $class->SUPER::new ( 2450 $class->SUPER::new (
2437 padding_x => 4, 2451 padding_x => 8,
2438 padding_y => 4, 2452 padding_y => 4,
2439 fg => [1.0, 1.0, 1.0], 2453 fg => [1.0, 1.0, 1.0],
2440 active_fg => [0.8, 0.8, 0.8], 2454 active_fg => [0.8, 0.8, 0.8],
2441 can_hover => 1, 2455 can_hover => 1,
2442 align => 0, 2456 align => 0,
2473 $self->SUPER::_draw; 2487 $self->SUPER::_draw;
2474} 2488}
2475 2489
2476############################################################################# 2490#############################################################################
2477 2491
2478package dc::UI::CheckBox; 2492package DC::UI::CheckBox;
2479 2493
2480our @ISA = dc::UI::DrawBG::; 2494our @ISA = DC::UI::DrawBG::;
2481 2495
2482my @tex = 2496my @tex =
2483 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 } 2497 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2484 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2498 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2485 2499
2486use dc::OpenGL; 2500use DC::OpenGL;
2487 2501
2488sub new { 2502sub new {
2489 my $class = shift; 2503 my $class = shift;
2490 2504
2491 $class->SUPER::new ( 2505 $class->SUPER::new (
2548 glDisable GL_TEXTURE_2D; 2562 glDisable GL_TEXTURE_2D;
2549} 2563}
2550 2564
2551############################################################################# 2565#############################################################################
2552 2566
2553package dc::UI::Image; 2567package DC::UI::Image;
2554 2568
2555our @ISA = dc::UI::Base::; 2569our @ISA = DC::UI::Base::;
2556 2570
2557use dc::OpenGL; 2571use DC::OpenGL;
2558 2572
2559our %texture_cache; 2573our %texture_cache;
2560 2574
2561sub new { 2575sub new {
2562 my $class = shift; 2576 my $class = shift;
2569 2583
2570 $self->{path} || $self->{tex} 2584 $self->{path} || $self->{tex}
2571 or Carp::croak "'path' or 'tex' attributes required"; 2585 or Carp::croak "'path' or 'tex' attributes required";
2572 2586
2573 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2587 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2574 new_from_file dc::Texture dc::find_rcfile $self->{path}, mipmap => 1; 2588 new_from_file DC::Texture DC::find_rcfile $self->{path}, mipmap => 1;
2575 2589
2576 dc::weaken $texture_cache{$self->{path}}; 2590 DC::weaken $texture_cache{$self->{path}};
2577 2591
2578 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2592 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2579 2593
2580 $self 2594 $self
2581} 2595}
2582 2596
2583sub STORABLE_freeze { 2597sub STORABLE_freeze {
2584 my ($self, $cloning) = @_; 2598 my ($self, $cloning) = @_;
2585 2599
2586 $self->{path} 2600 $self->{path}
2587 or die "cannot serialise dc::UI::Image on non-loadable images\n"; 2601 or die "cannot serialise DC::UI::Image on non-loadable images\n";
2588 2602
2589 $self->{path} 2603 $self->{path}
2590} 2604}
2591 2605
2592sub STORABLE_attach { 2606sub STORABLE_attach {
2623 glDisable GL_TEXTURE_2D; 2637 glDisable GL_TEXTURE_2D;
2624} 2638}
2625 2639
2626############################################################################# 2640#############################################################################
2627 2641
2628package dc::UI::ImageButton; 2642package DC::UI::ImageButton;
2629 2643
2630our @ISA = dc::UI::Image::; 2644our @ISA = DC::UI::Image::;
2631 2645
2632use dc::OpenGL; 2646use DC::OpenGL;
2633 2647
2634my %textures; 2648my %textures;
2635 2649
2636sub new { 2650sub new {
2637 my $class = shift; 2651 my $class = shift;
2665 1 2679 1
2666} 2680}
2667 2681
2668############################################################################# 2682#############################################################################
2669 2683
2670package dc::UI::VGauge; 2684package DC::UI::VGauge;
2671 2685
2672our @ISA = dc::UI::Base::; 2686our @ISA = DC::UI::Base::;
2673 2687
2674use List::Util qw(min max); 2688use List::Util qw(min max);
2675 2689
2676use dc::OpenGL; 2690use DC::OpenGL;
2677 2691
2678my %tex = ( 2692my %tex = (
2679 food => [ 2693 food => [
2680 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 } 2694 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2681 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2695 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2682 ], 2696 ],
2683 grace => [ 2697 grace => [
2684 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 } 2698 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2685 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2699 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2686 ], 2700 ],
2687 hp => [ 2701 hp => [
2688 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 } 2702 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2689 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2703 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2690 ], 2704 ],
2691 mana => [ 2705 mana => [
2692 map { new_from_file dc::Texture dc::find_rcfile $_, mipmap => 1 } 2706 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 }
2693 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2707 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2694 ], 2708 ],
2695); 2709);
2696 2710
2697# eg. VGauge->new (gauge => 'food'), default gauge: food 2711# eg. VGauge->new (gauge => 'food'), default gauge: food
2800 glDisable GL_TEXTURE_2D; 2814 glDisable GL_TEXTURE_2D;
2801} 2815}
2802 2816
2803############################################################################# 2817#############################################################################
2804 2818
2805package dc::UI::Progress; 2819package DC::UI::Progress;
2806 2820
2807our @ISA = dc::UI::Label::; 2821our @ISA = DC::UI::Label::;
2808 2822
2809use dc::OpenGL; 2823use DC::OpenGL;
2810 2824
2811sub new { 2825sub new {
2812 my ($class, %arg) = @_; 2826 my ($class, %arg) = @_;
2813 2827
2814 my $self = $class->SUPER::new ( 2828 my $self = $class->SUPER::new (
2834 my ($self, $label) = @_; 2848 my ($self, $label) = @_;
2835 2849
2836 return if $self->{label} eq $label; 2850 return if $self->{label} eq $label;
2837 $self->{label} = $label; 2851 $self->{label} = $label;
2838 2852
2839 $self->dc::UI::Progress::set_value (0 + delete $self->{value}); 2853 $self->DC::UI::Progress::set_value (0 + delete $self->{value});
2840} 2854}
2841 2855
2842sub set_value { 2856sub set_value {
2843 my ($self, $value) = @_; 2857 my ($self, $value) = @_;
2844 2858
2881 } 2895 }
2882} 2896}
2883 2897
2884############################################################################# 2898#############################################################################
2885 2899
2886package dc::UI::ExperienceProgress; 2900package DC::UI::ExperienceProgress;
2887 2901
2888our @ISA = dc::UI::Progress::; 2902our @ISA = DC::UI::Progress::;
2889 2903
2890sub new { 2904sub new {
2891 my ($class, %arg) = @_; 2905 my ($class, %arg) = @_;
2892 2906
2893 my $self = $class->SUPER::new ( 2907 my $self = $class->SUPER::new (
2938 $self->SUPER::set_value ($v); 2952 $self->SUPER::set_value ($v);
2939} 2953}
2940 2954
2941############################################################################# 2955#############################################################################
2942 2956
2943package dc::UI::Gauge; 2957package DC::UI::Gauge;
2944 2958
2945our @ISA = dc::UI::VBox::; 2959our @ISA = DC::UI::VBox::;
2946 2960
2947sub new { 2961sub new {
2948 my ($class, %arg) = @_; 2962 my ($class, %arg) = @_;
2949 2963
2950 my $self = $class->SUPER::new ( 2964 my $self = $class->SUPER::new (
2952 can_hover => 1, 2966 can_hover => 1,
2953 can_events => 1, 2967 can_events => 1,
2954 %arg, 2968 %arg,
2955 ); 2969 );
2956 2970
2957 $self->add ($self->{value} = new dc::UI::Label valign => +1, align => 0, template => "999"); 2971 $self->add ($self->{value} = new DC::UI::Label valign => +1, align => 0, template => "999");
2958 $self->add ($self->{gauge} = new dc::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 2972 $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
2959 $self->add ($self->{max} = new dc::UI::Label valign => -1, align => 0, template => "999"); 2973 $self->add ($self->{max} = new DC::UI::Label valign => -1, align => 0, template => "999");
2960 2974
2961 $self 2975 $self
2962} 2976}
2963 2977
2964sub set_fontsize { 2978sub set_fontsize {
2985 $self->{value}->set_text ($val); 2999 $self->{value}->set_text ($val);
2986} 3000}
2987 3001
2988############################################################################# 3002#############################################################################
2989 3003
2990package dc::UI::Slider; 3004package DC::UI::Slider;
2991 3005
2992use strict; 3006use strict;
2993 3007
2994use dc::OpenGL; 3008use DC::OpenGL;
2995 3009
2996our @ISA = dc::UI::DrawBG::; 3010our @ISA = DC::UI::DrawBG::;
2997 3011
2998my @tex = 3012my @tex =
2999 map { new_from_file dc::Texture dc::find_rcfile $_ } 3013 map { new_from_file DC::Texture DC::find_rcfile $_ }
3000 qw(s1_slider.png s1_slider_bg.png); 3014 qw(s1_slider.png s1_slider_bg.png);
3001 3015
3002sub new { 3016sub new {
3003 my $class = shift; 3017 my $class = shift;
3004 3018
3100sub invoke_mouse_wheel { 3114sub invoke_mouse_wheel {
3101 my ($self, $ev) = @_; 3115 my ($self, $ev) = @_;
3102 3116
3103 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 3117 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
3104 3118
3105 my $pagepart = $ev->{mod} & dc::KMOD_SHIFT ? 1 : 0.2; 3119 my $pagepart = $ev->{mod} & DC::KMOD_SHIFT ? 1 : 0.2;
3106 3120
3107 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); 3121 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
3108 3122
3109 1 3123 1
3110} 3124}
3163 glDisable GL_TEXTURE_2D; 3177 glDisable GL_TEXTURE_2D;
3164} 3178}
3165 3179
3166############################################################################# 3180#############################################################################
3167 3181
3168package dc::UI::ValSlider; 3182package DC::UI::ValSlider;
3169 3183
3170our @ISA = dc::UI::HBox::; 3184our @ISA = DC::UI::HBox::;
3171 3185
3172sub new { 3186sub new {
3173 my ($class, %arg) = @_; 3187 my ($class, %arg) = @_;
3174 3188
3175 my $range = delete $arg{range}; 3189 my $range = delete $arg{range};
3176 3190
3177 my $self = $class->SUPER::new ( 3191 my $self = $class->SUPER::new (
3178 slider => (new dc::UI::Slider expand => 1, range => $range), 3192 slider => (new DC::UI::Slider expand => 1, range => $range),
3179 entry => (new dc::UI::Label text => "", template => delete $arg{template}), 3193 entry => (new DC::UI::Label text => "", template => delete $arg{template}),
3180 to_value => sub { shift }, 3194 to_value => sub { shift },
3181 from_value => sub { shift }, 3195 from_value => sub { shift },
3182 %arg, 3196 %arg,
3183 ); 3197 );
3184 3198
3204sub set_range { shift->{slider}->set_range (@_) } 3218sub set_range { shift->{slider}->set_range (@_) }
3205sub set_value { shift->{slider}->set_value (@_) } 3219sub set_value { shift->{slider}->set_value (@_) }
3206 3220
3207############################################################################# 3221#############################################################################
3208 3222
3209package dc::UI::TextScroller; 3223package DC::UI::TextScroller;
3210 3224
3211our @ISA = dc::UI::HBox::; 3225our @ISA = DC::UI::HBox::;
3212 3226
3213use dc::OpenGL; 3227use DC::OpenGL;
3214 3228
3215sub new { 3229sub new {
3216 my $class = shift; 3230 my $class = shift;
3217 3231
3218 my $self = $class->SUPER::new ( 3232 my $self = $class->SUPER::new (
3220 can_events => 1, 3234 can_events => 1,
3221 indent => 0, 3235 indent => 0,
3222 #font => default_font 3236 #font => default_font
3223 @_, 3237 @_,
3224 3238
3225 layout => (new dc::Layout), 3239 layout => (new DC::Layout),
3226 par => [], 3240 par => [],
3227 max_par => 0, 3241 max_par => 0,
3228 height => 0, 3242 height => 0,
3229 children => [ 3243 children => [
3230 (new dc::UI::Empty expand => 1), 3244 (new DC::UI::Empty expand => 1),
3231 (new dc::UI::Slider vertical => 1), 3245 (new DC::UI::Slider vertical => 1),
3232 ], 3246 ],
3233 ); 3247 );
3234 3248
3235 $self->{children}[1]->connect (changed => sub { $self->update }); 3249 $self->{children}[1]->connect (changed => sub { $self->update });
3236 3250
3419 $ROOT->on_post_alloc ($self => sub { 3433 $ROOT->on_post_alloc ($self => sub {
3420 $self->force_uptodate; 3434 $self->force_uptodate;
3421 3435
3422 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 3436 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
3423 3437
3424 $self->{texture} ||= new_from_opengl dc::Texture $W, $H, sub { 3438 $self->{texture} ||= new_from_opengl DC::Texture $W, $H, sub {
3425 glClearColor 0, 0, 0, 0; 3439 glClearColor 0, 0, 0, 0;
3426 glClear GL_COLOR_BUFFER_BIT; 3440 glClear GL_COLOR_BUFFER_BIT;
3427 3441
3428 package dc::UI::Base; 3442 package DC::UI::Base;
3429 local ($draw_x, $draw_y, $draw_w, $draw_h) = 3443 local ($draw_x, $draw_y, $draw_w, $draw_h) =
3430 (0, 0, $self->{w}, $self->{h}); 3444 (0, 0, $self->{w}, $self->{h});
3431 3445
3432 my $top = int $self->{children}[1]{range}[0]; 3446 my $top = int $self->{children}[1]{range}[0];
3433 3447
3492 $self->{children}[1]->draw; 3506 $self->{children}[1]->draw;
3493} 3507}
3494 3508
3495############################################################################# 3509#############################################################################
3496 3510
3497package dc::UI::Animator; 3511package DC::UI::Animator;
3498 3512
3499use dc::OpenGL; 3513use DC::OpenGL;
3500 3514
3501our @ISA = dc::UI::Bin::; 3515our @ISA = DC::UI::Bin::;
3502 3516
3503sub moveto { 3517sub moveto {
3504 my ($self, $x, $y) = @_; 3518 my ($self, $x, $y) = @_;
3505 3519
3506 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 3520 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
3534 glPopMatrix; 3548 glPopMatrix;
3535} 3549}
3536 3550
3537############################################################################# 3551#############################################################################
3538 3552
3539package dc::UI::Flopper; 3553package DC::UI::Flopper;
3540 3554
3541our @ISA = dc::UI::Button::; 3555our @ISA = DC::UI::Button::;
3542 3556
3543sub new { 3557sub new {
3544 my $class = shift; 3558 my $class = shift;
3545 3559
3546 my $self = $class->SUPER::new ( 3560 my $self = $class->SUPER::new (
3558 $self->{other}->toggle_visibility; 3572 $self->{other}->toggle_visibility;
3559} 3573}
3560 3574
3561############################################################################# 3575#############################################################################
3562 3576
3563package dc::UI::Tooltip; 3577package DC::UI::Tooltip;
3564 3578
3565our @ISA = dc::UI::Bin::; 3579our @ISA = DC::UI::Bin::;
3566 3580
3567use dc::OpenGL; 3581use DC::OpenGL;
3568 3582
3569sub new { 3583sub new {
3570 my $class = shift; 3584 my $class = shift;
3571 3585
3572 $class->SUPER::new ( 3586 $class->SUPER::new (
3579 my ($self, $widget) = @_; 3593 my ($self, $widget) = @_;
3580 3594
3581 my $tip = $widget->{tooltip}; 3595 my $tip = $widget->{tooltip};
3582 $tip = $tip->($widget) if "CODE" eq ref $tip; 3596 $tip = $tip->($widget) if "CODE" eq ref $tip;
3583 3597
3584 $tip = dc::Pod::section_label tooltip => $1 3598 $tip = DC::Pod::section_label tooltip => $1
3585 if $tip =~ /^#(.*)$/; 3599 if $tip =~ /^#(.*)$/;
3586 3600
3587 if ($ENV{CFPLUS_DEBUG} & 2) { 3601 if ($ENV{CFPLUS_DEBUG} & 2) {
3588 $tip .= "\n\n" . (ref $widget) . "\n" 3602 $tip .= "\n\n" . (ref $widget) . "\n"
3589 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3603 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3592 } 3606 }
3593 3607
3594 $tip =~ s/^\n+//; 3608 $tip =~ s/^\n+//;
3595 $tip =~ s/\n+$//; 3609 $tip =~ s/\n+$//;
3596 3610
3597 $self->add (new dc::UI::Label 3611 $self->add (new DC::UI::Label
3598 markup => $tip, 3612 markup => $tip,
3599 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3613 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3600 fontsize => 0.8, 3614 fontsize => 0.8,
3601 style => 1, # FLAG_INVERSE 3615 style => 1, # FLAG_INVERSE
3602 ellipsise => 0, 3616 ellipsise => 0,
3656 $self->SUPER::_draw; 3670 $self->SUPER::_draw;
3657} 3671}
3658 3672
3659############################################################################# 3673#############################################################################
3660 3674
3661package dc::UI::Face; 3675package DC::UI::Face;
3662 3676
3663our @ISA = dc::UI::DrawBG::; 3677our @ISA = DC::UI::DrawBG::;
3664 3678
3665use dc::OpenGL; 3679use DC::OpenGL;
3666 3680
3667sub new { 3681sub new {
3668 my $class = shift; 3682 my $class = shift;
3669 3683
3670 my $self = $class->SUPER::new ( 3684 my $self = $class->SUPER::new (
3674 can_events => 0, 3688 can_events => 0,
3675 @_, 3689 @_,
3676 ); 3690 );
3677 3691
3678 if ($self->{anim} && $self->{animspeed}) { 3692 if ($self->{anim} && $self->{animspeed}) {
3679 dc::weaken (my $widget = $self); 3693 DC::weaken (my $widget = $self);
3680 3694
3681 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed}; 3695 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed};
3682 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub { 3696 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub {
3683 return unless $::CONN; 3697 return unless $::CONN;
3684 3698
3790 $self->SUPER::destroy; 3804 $self->SUPER::destroy;
3791} 3805}
3792 3806
3793############################################################################# 3807#############################################################################
3794 3808
3795package dc::UI::Buttonbar; 3809package DC::UI::Buttonbar;
3796 3810
3797our @ISA = dc::UI::HBox::; 3811our @ISA = DC::UI::HBox::;
3798 3812
3799# TODO: should actually wrap buttons and other goodies. 3813# TODO: should actually wrap buttons and other goodies.
3800 3814
3801############################################################################# 3815#############################################################################
3802 3816
3803package dc::UI::Menu; 3817package DC::UI::Menu;
3804 3818
3805our @ISA = dc::UI::Toplevel::; 3819our @ISA = DC::UI::Toplevel::;
3806 3820
3807use dc::OpenGL; 3821use DC::OpenGL;
3808 3822
3809sub new { 3823sub new {
3810 my $class = shift; 3824 my $class = shift;
3811 3825
3812 my $self = $class->SUPER::new ( 3826 my $self = $class->SUPER::new (
3813 items => [], 3827 items => [],
3814 z => 100, 3828 z => 100,
3815 @_, 3829 @_,
3816 ); 3830 );
3817 3831
3818 $self->add ($self->{vbox} = new dc::UI::VBox); 3832 $self->add ($self->{vbox} = new DC::UI::VBox);
3819 3833
3820 for my $item (@{ $self->{items} }) { 3834 for my $item (@{ $self->{items} }) {
3821 my ($widget, $cb, $tooltip) = @$item; 3835 my ($widget, $cb, $tooltip) = @$item;
3822 3836
3823 # handle various types of items, only text for now 3837 # handle various types of items, only text for now
3824 if (!ref $widget) { 3838 if (!ref $widget) {
3825 if ($widget =~ /\t/) { 3839 if ($widget =~ /\t/) {
3826 my ($left, $right) = split /\t/, $widget, 2; 3840 my ($left, $right) = split /\t/, $widget, 2;
3827 3841
3828 $widget = new dc::UI::HBox 3842 $widget = new DC::UI::HBox
3829 can_hover => 1, 3843 can_hover => 1,
3830 can_events => 1, 3844 can_events => 1,
3831 tooltip => $tooltip, 3845 tooltip => $tooltip,
3832 children => [ 3846 children => [
3833 (new dc::UI::Label markup => $left, expand => 1), 3847 (new DC::UI::Label markup => $left, expand => 1),
3834 (new dc::UI::Label markup => $right, align => +1), 3848 (new DC::UI::Label markup => $right, align => +1),
3835 ], 3849 ],
3836 ; 3850 ;
3837 3851
3838 } else { 3852 } else {
3839 $widget = new dc::UI::Label 3853 $widget = new DC::UI::Label
3840 can_hover => 1, 3854 can_hover => 1,
3841 can_events => 1, 3855 can_events => 1,
3842 markup => $widget, 3856 markup => $widget,
3843 tooltip => $tooltip; 3857 tooltip => $tooltip;
3844 } 3858 }
3892 1 3906 1
3893} 3907}
3894 3908
3895############################################################################# 3909#############################################################################
3896 3910
3897package dc::UI::Multiplexer; 3911package DC::UI::Multiplexer;
3898 3912
3899our @ISA = dc::UI::Container::; 3913our @ISA = DC::UI::Container::;
3900 3914
3901sub new { 3915sub new {
3902 my $class = shift; 3916 my $class = shift;
3903 3917
3904 my $self = $class->SUPER::new ( 3918 my $self = $class->SUPER::new (
3965 $self->{current}->draw; 3979 $self->{current}->draw;
3966} 3980}
3967 3981
3968############################################################################# 3982#############################################################################
3969 3983
3970package dc::UI::Notebook; 3984package DC::UI::Notebook;
3971 3985
3972use dc::OpenGL; 3986use DC::OpenGL;
3973 3987
3974our @ISA = dc::UI::VBox::; 3988our @ISA = DC::UI::VBox::;
3975 3989
3976sub new { 3990sub new {
3977 my $class = shift; 3991 my $class = shift;
3978 3992
3979 my $self = $class->SUPER::new ( 3993 my $self = $class->SUPER::new (
3980 buttonbar => (new dc::UI::Buttonbar), 3994 buttonbar => (new DC::UI::Buttonbar),
3981 multiplexer => (new dc::UI::Multiplexer expand => 1), 3995 multiplexer => (new DC::UI::Multiplexer expand => 1),
3982 active_outline => [.7, .7, 0.2], 3996 active_outline => [.7, .7, 0.2],
3983 # filter => # will be put between multiplexer and $self 3997 # filter => # will be put between multiplexer and $self
3984 @_, 3998 @_,
3985 ); 3999 );
3986 4000
3995 4009
3996 for my $child (@$widgets) { 4010 for my $child (@$widgets) {
3997 Scalar::Util::weaken $child; 4011 Scalar::Util::weaken $child;
3998 $child->{c_tab_} ||= do { 4012 $child->{c_tab_} ||= do {
3999 my $tab = 4013 my $tab =
4000 (UNIVERSAL::isa $child->{c_tab}, "dc::UI::Base") 4014 (UNIVERSAL::isa $child->{c_tab}, "DC::UI::Base")
4001 ? $child->{c_tab} 4015 ? $child->{c_tab}
4002 : new dc::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; 4016 : new DC::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1];
4003 4017
4004 $tab->connect (activate => sub { 4018 $tab->connect (activate => sub {
4005 $wself->set_current_page ($child); 4019 $wself->set_current_page ($child);
4006 }); 4020 });
4007 4021
4083 } 4097 }
4084} 4098}
4085 4099
4086############################################################################# 4100#############################################################################
4087 4101
4088package dc::UI::Selector; 4102package DC::UI::Selector;
4089 4103
4090use utf8; 4104use utf8;
4091 4105
4092our @ISA = dc::UI::Button::; 4106our @ISA = DC::UI::Button::;
4093 4107
4094sub new { 4108sub new {
4095 my $class = shift; 4109 my $class = shift;
4096 4110
4097 my $self = $class->SUPER::new ( 4111 my $self = $class->SUPER::new (
4114 my ($value, $title, $tooltip) = @$_; 4128 my ($value, $title, $tooltip) = @$_;
4115 4129
4116 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; 4130 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
4117 } 4131 }
4118 4132
4119 dc::UI::Menu->new (items => \@menu_items)->popup ($ev); 4133 DC::UI::Menu->new (items => \@menu_items)->popup ($ev);
4120} 4134}
4121 4135
4122sub _set_value { 4136sub _set_value {
4123 my ($self, $value) = @_; 4137 my ($self, $value) = @_;
4124 4138
4147 $self->_set_value ($self->{value}); 4161 $self->_set_value ($self->{value});
4148} 4162}
4149 4163
4150############################################################################# 4164#############################################################################
4151 4165
4152package dc::UI::Statusbox; 4166package DC::UI::Statusbox;
4153 4167
4154our @ISA = dc::UI::VBox::; 4168our @ISA = DC::UI::VBox::;
4155 4169
4156sub new { 4170sub new {
4157 my $class = shift; 4171 my $class = shift;
4158 4172
4159 my $self = $class->SUPER::new ( 4173 my $self = $class->SUPER::new (
4160 fontsize => 0.8, 4174 fontsize => 0.8,
4161 @_, 4175 @_,
4162 ); 4176 );
4163 4177
4164 dc::weaken (my $this = $self); 4178 DC::weaken (my $this = $self);
4165 4179
4166 $self->{timer} = EV::timer 1, 1, sub { $this->reorder }; 4180 $self->{timer} = EV::timer 1, 1, sub { $this->reorder };
4167 4181
4168 $self 4182 $self
4169} 4183}
4171sub reorder { 4185sub reorder {
4172 my ($self) = @_; 4186 my ($self) = @_;
4173 my $NOW = Time::HiRes::time; 4187 my $NOW = Time::HiRes::time;
4174 4188
4175 # freeze display when hovering over any label 4189 # freeze display when hovering over any label
4176 return if $dc::UI::TOOLTIP->{owner} 4190 return if $DC::UI::TOOLTIP->{owner}
4177 && grep $dc::UI::TOOLTIP->{owner} == $_->{label}, 4191 && grep $DC::UI::TOOLTIP->{owner} == $_->{label},
4178 values %{ $self->{item} }; 4192 values %{ $self->{item} };
4179 4193
4180 while (my ($k, $v) = each %{ $self->{item} }) { 4194 while (my ($k, $v) = each %{ $self->{item} }) {
4181 delete $self->{item}{$k} if $v->{timeout} < $NOW; 4195 delete $self->{item}{$k} if $v->{timeout} < $NOW;
4182 } 4196 }
4203 for ($short) { 4217 for ($short) {
4204 s/^\s+//; 4218 s/^\s+//;
4205 s/\s+/ /g; 4219 s/\s+/ /g;
4206 } 4220 }
4207 4221
4208 new dc::UI::Label 4222 new DC::UI::Label
4209 markup => $short, 4223 markup => $short,
4210 tooltip => $item->{tooltip}, 4224 tooltip => $item->{tooltip},
4211 tooltip_font => $::FONT_PROP, 4225 tooltip_font => $::FONT_PROP,
4212 tooltip_width => 0.67, 4226 tooltip_width => 0.67,
4213 fontsize => $item->{fontsize} || $self->{fontsize}, 4227 fontsize => $item->{fontsize} || $self->{fontsize},
4292 $self->SUPER::destroy; 4306 $self->SUPER::destroy;
4293} 4307}
4294 4308
4295############################################################################# 4309#############################################################################
4296 4310
4297package dc::UI::Root; 4311package DC::UI::Root;
4298 4312
4299our @ISA = dc::UI::Container::; 4313our @ISA = DC::UI::Container::;
4300 4314
4301use List::Util qw(min max); 4315use List::Util qw(min max);
4302 4316
4303use dc::OpenGL; 4317use DC::OpenGL;
4304 4318
4305sub new { 4319sub new {
4306 my $class = shift; 4320 my $class = shift;
4307 4321
4308 my $self = $class->SUPER::new ( 4322 my $self = $class->SUPER::new (
4309 visible => 1, 4323 visible => 1,
4310 @_, 4324 @_,
4311 ); 4325 );
4312 4326
4313 dc::weaken ($self->{root} = $self); 4327 DC::weaken ($self->{root} = $self);
4314 4328
4315 $self 4329 $self
4316} 4330}
4317 4331
4318sub size_request { 4332sub size_request {
4521 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 4535 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
4522 glMatrixMode GL_MODELVIEW; 4536 glMatrixMode GL_MODELVIEW;
4523 glLoadIdentity; 4537 glLoadIdentity;
4524 4538
4525 { 4539 {
4526 package dc::UI::Base; 4540 package DC::UI::Base;
4527 4541
4528 local ($draw_x, $draw_y, $draw_w, $draw_h) = 4542 local ($draw_x, $draw_y, $draw_w, $draw_h) =
4529 (0, 0, $self->{w}, $self->{h}); 4543 (0, 0, $self->{w}, $self->{h});
4530 4544
4531 $self->_draw; 4545 $self->_draw;
4532 } 4546 }
4533} 4547}
4534 4548
4535############################################################################# 4549#############################################################################
4536 4550
4537package dc::UI; 4551package DC::UI;
4538 4552
4539$ROOT = new dc::UI::Root; 4553$ROOT = new DC::UI::Root;
4540$TOOLTIP = new dc::UI::Tooltip z => 900; 4554$TOOLTIP = new DC::UI::Tooltip z => 900;
4541 4555
45421 45561
4543 4557

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines