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.250 by root, Sun May 28 02:31:03 2006 UTC vs.
Revision 1.255 by root, Mon May 29 02:01:56 2006 UTC

40 if (!$GRAB) { 40 if (!$GRAB) {
41 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 41 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
42 if (length $widget->{tooltip}) { 42 if (length $widget->{tooltip}) {
43 43
44 if ($TOOLTIP->{owner} != $widget) { 44 if ($TOOLTIP->{owner} != $widget) {
45 $TOOLTIP->hide;
46
45 $TOOLTIP->{owner} = $widget; 47 $TOOLTIP->{owner} = $widget;
46 48
47 my $tip = $widget->{tooltip}; 49 my $tip = $widget->{tooltip};
48 50
49 $tip = $tip->($widget) if CODE:: eq ref $tip; 51 $tip = $tip->($widget) if CODE:: eq ref $tip;
50 52
51 $TOOLTIP->set_tooltip_from ($widget); 53 $TOOLTIP->set_tooltip_from ($widget);
52 $TOOLTIP->show; 54 $TOOLTIP->show;
53
54 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
55
56 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0)
57 if $x + $TOOLTIP->{w} > $::WIDTH;
58
59 $TOOLTIP->move ($x, $y);
60 $TOOLTIP->check_size;
61 $TOOLTIP->update;
62 } 55 }
63 56
64 return; 57 return;
65 } 58 }
66 } 59 }
257 250
258 $self->{root} = $self->{parent}{root}; 251 $self->{root} = $self->{parent}{root};
259 $self->{visible} = $self->{parent}{visible} + 1; 252 $self->{visible} = $self->{parent}{visible} + 1;
260 253
261 $self->emit (visibility_change => 1); 254 $self->emit (visibility_change => 1);
255
256 $self->realloc if !exists $self->{req_w};
257
258 $_->set_visible for $self->children;
262} 259}
263 260
264sub set_invisible { 261sub set_invisible {
265 my ($self) = @_; 262 my ($self) = @_;
266 263
267 return unless $self->{visible}; 264 return unless $self->{visible};
268 265
269 # broken show/hide model 266 $_->set_invisible for $self->children;
270 267
271 delete $self->{root}; 268 delete $self->{root};
272 delete $self->{visible}; 269 delete $self->{visible};
273 270
274 undef $GRAB if $GRAB == $self; 271 undef $GRAB if $GRAB == $self;
275 undef $HOVER if $HOVER == $self; 272 undef $HOVER if $HOVER == $self;
276 273
277 CFClient::UI::check_tooltip 274 CFClient::UI::check_tooltip
278 if $CFClient::UI::TOOLTIP->{owner} == $self; 275 if $TOOLTIP->{owner} == $self;
279 276
280 $self->focus_out; 277 $self->focus_out;
281 278
282 $self->emit (visibility_change => 0); 279 $self->emit (visibility_change => 0);
283} 280}
322 my ($self, $w, $h) = @_; 319 my ($self, $w, $h) = @_;
323 320
324 $self->{def_w} = $w; 321 $self->{def_w} = $w;
325 $self->{def_h} = $h; 322 $self->{def_h} = $h;
326 323
327 $self->check_size; 324 $self->realloc;
328} 325}
329 326
330sub size_request { 327sub size_request {
331 require Carp; 328 require Carp;
332 Carp::confess "size_request is abstract"; 329 Carp::confess "size_request is abstract";
352 $self->{y} = $y; 349 $self->{y} = $y;
353 $self->update; 350 $self->update;
354 } 351 }
355 352
356 if ($self->{w} != $w || $self->{h} != $h) { 353 if ($self->{w} != $w || $self->{h} != $h) {
354 return unless $self->{visible};
355
357 $CFClient::UI::ROOT->{size_alloc}{$self+0} = [$self, $w, $h]; 356 $self->{root}->{size_alloc}{$self+0} = [$self, $w, $h];
358 } 357 }
359} 358}
360 359
361sub size_allocate { 360sub size_allocate {
362 # nothing to be done 361 # nothing to be done
363}
364
365sub reconfigure {
366 my ($self) = @_;
367
368 $self->check_size (1);
369 $self->update;
370} 362}
371 363
372sub children { 364sub children {
373} 365}
374 366
452sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } 444sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} }
453sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } 445sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} }
454sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } 446sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} }
455sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } 447sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} }
456sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } 448sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} }
449
450sub find_widget {
451 my ($self, $x, $y) = @_;
452
453 return () unless $self->{can_events};
454
455 return $self
456 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
457 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
458
459 ()
460}
461
462sub set_parent {
463 my ($self, $parent) = @_;
464
465 Scalar::Util::weaken ($self->{parent} = $parent);
466
467 $self->set_visible if $parent->{visible};
468}
469
470sub connect {
471 my ($self, $signal, $cb) = @_;
472
473 push @{ $self->{signal_cb}{$signal} }, $cb;
474}
475
476sub _emit {
477 my ($self, $signal, @args) = @_;
478
479 List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}
480}
481
482sub emit {
483 my ($self, $signal, @args) = @_;
484
485 $self->_emit ($signal, @args)
486 || $self->$signal (@args);
487}
488
489sub visibility_change {
490 #my ($self, $visible) = @_;
491}
492
493sub realloc {
494 my ($self) = @_;
495
496 if ($self->{visible}) {
497 return if $self->{root}{realloc}{$self};
498
499 $self->{root}{realloc}{$self} = $self;
500 $self->{root}->update;
501 } else {
502 delete $self->{req_w};
503 }
504}
505
506sub update {
507 my ($self) = @_;
508
509 $self->{parent}->update
510 if $self->{parent};
511}
457 512
458sub draw { 513sub draw {
459 my ($self) = @_; 514 my ($self) = @_;
460 515
461 return unless $self->{h} && $self->{w}; 516 return unless $self->{h} && $self->{w};
499 my ($self) = @_; 554 my ($self) = @_;
500 555
501 warn "no draw defined for $self\n"; 556 warn "no draw defined for $self\n";
502} 557}
503 558
504sub find_widget {
505 my ($self, $x, $y) = @_;
506
507 return () unless $self->{can_events};
508
509 return $self
510 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
511 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
512
513 ()
514}
515
516sub set_parent {
517 my ($self, $parent) = @_;
518
519 Scalar::Util::weaken ($self->{parent} = $parent);
520
521 $self->set_visible; #TODO why breakssssss borked damn if $parent->{visible};
522
523 $self->check_size;
524}
525
526sub check_size {
527 my ($self, $forced) = @_;
528
529 $self->{force_alloc} = 1 if $forced;
530 $CFClient::UI::ROOT->{check_size}{$self} = $self;
531}
532
533sub update {
534 my ($self) = @_;
535
536 $self->{parent}->update
537 if $self->{parent};
538}
539
540sub connect {
541 my ($self, $signal, $cb) = @_;
542
543 push @{ $self->{signal_cb}{$signal} }, $cb;
544}
545
546sub _emit {
547 my ($self, $signal, @args) = @_;
548
549 List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}
550}
551
552sub emit {
553 my ($self, $signal, @args) = @_;
554
555 $self->_emit ($signal, @args)
556 || $self->$signal (@args);
557}
558
559sub visibility_change {
560 #my ($self, $visible) = @_;
561}
562
563sub DESTROY { 559sub DESTROY {
564 my ($self) = @_; 560 my ($self) = @_;
565 561
566 delete $WIDGET{$self+0}; 562 delete $WIDGET{$self+0};
567 #$self->deactivate; 563 #$self->deactivate;
662 $self->{children} = [ 658 $self->{children} = [
663 sort { $a->{z} <=> $b->{z} } 659 sort { $a->{z} <=> $b->{z} }
664 @{$self->{children}}, @widgets 660 @{$self->{children}}, @widgets
665 ]; 661 ];
666 662
667 $self->check_size (1); 663 $self->realloc;
668 $self->update;
669} 664}
670 665
671sub children { 666sub children {
672 @{ $_[0]{children} } 667 @{ $_[0]{children} }
673} 668}
678 delete $child->{parent}; 673 delete $child->{parent};
679 $child->hide; 674 $child->hide;
680 675
681 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 676 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
682 677
683 $self->check_size (1); 678 $self->realloc;
684 $self->update;
685} 679}
686 680
687sub clear { 681sub clear {
688 my ($self) = @_; 682 my ($self) = @_;
689 683
693 for (@$children) { 687 for (@$children) {
694 delete $_->{parent}; 688 delete $_->{parent};
695 $_->hide; 689 $_->hide;
696 } 690 }
697 691
698 $self->check_size; 692 $self->realloc;
699 $self->update;
700} 693}
701 694
702sub find_widget { 695sub find_widget {
703 my ($self, $x, $y) = @_; 696 my ($self, $x, $y) = @_;
704 697
757sub size_request { 750sub size_request {
758 $_[0]{children}[0]->size_request 751 $_[0]{children}[0]->size_request
759} 752}
760 753
761sub size_allocate { 754sub size_allocate {
762 my ($self, $w, $h) = @_; 755 my ($self, $w, $h, $changed) = @_;
763 756
764 $self->{children}[0]->configure (0, 0, $w, $h); 757 $self->{children}[0]->configure (0, 0, $w, $h);
765} 758}
766 759
767############################################################################# 760#############################################################################
784 $ROOT->on_post_alloc ($self => sub { $self->render_child }); 777 $ROOT->on_post_alloc ($self => sub { $self->render_child });
785 $self->SUPER::update; 778 $self->SUPER::update;
786} 779}
787 780
788sub size_allocate { 781sub size_allocate {
789 my ($self, $w, $h) = @_; 782 my ($self, $w, $h, $changed) = @_;
790 783
791 $self->SUPER::size_allocate ($w, $h); 784 $self->SUPER::size_allocate ($w, $h, $changed);
792 $self->update; 785 $self->update
786 if $changed;
793} 787}
794 788
795sub _render { 789sub _render {
796 $_[0]{children}[0]->draw; 790 $_[0]{children}[0]->draw;
797} 791}
850 844
851 ($w, $h) 845 ($w, $h)
852} 846}
853 847
854sub size_allocate { 848sub size_allocate {
855 my ($self, $w, $h) = @_; 849 my ($self, $w, $h, $changed) = @_;
856 850
857 $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; 851 $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w};
858 $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; 852 $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h};
859 853
860 $self->child->configure (0, 0, $w, $h); 854 $self->child->configure (0, 0, $w, $h);
947 my $child = $self->{vp}->child; 941 my $child = $self->{vp}->child;
948 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); 942 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
949} 943}
950 944
951sub size_allocate { 945sub size_allocate {
952 my ($self, $w, $h) = @_; 946 my ($self, $w, $h, $changed) = @_;
953 947
954 $self->SUPER::size_allocate ($w, $h); 948 $self->SUPER::size_allocate ($w, $h, $changed);
955 949
956 my $child = $self->{vp}->child; 950 my $child = $self->{vp}->child;
957 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); 951 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
958} 952}
959 953
1006 1000
1007our @ISA = CFClient::UI::Bin::; 1001our @ISA = CFClient::UI::Bin::;
1008 1002
1009use CFClient::OpenGL; 1003use CFClient::OpenGL;
1010 1004
1011my @tex = 1005my $bg =
1006 new_from_file CFClient::Texture CFClient::find_rcfile "d1_bg.png",
1007 mipmap => 1, wrap => 1;
1008
1009my @border =
1012 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1010 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1013 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1011 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1014 1012
1015sub new { 1013sub new {
1016 my $class = shift; 1014 my $class = shift;
1017 1015
1018 my $self = $class->SUPER::new ( 1016 my $self = $class->SUPER::new (
1047 $h + $self->border * 2, 1045 $h + $self->border * 2,
1048 ) 1046 )
1049} 1047}
1050 1048
1051sub size_allocate { 1049sub size_allocate {
1052 my ($self, $w, $h) = @_; 1050 my ($self, $w, $h, $changed) = @_;
1051
1052 return unless $changed;
1053 1053
1054 $h -= List::Util::max 0, $self->border * 2; 1054 $h -= List::Util::max 0, $self->border * 2;
1055 $w -= List::Util::max 0, $self->border * 2; 1055 $w -= List::Util::max 0, $self->border * 2;
1056 1056
1057 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) 1057 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2)
1086 $self->{user_x} = $wx + $dx * $mx; 1086 $self->{user_x} = $wx + $dx * $mx;
1087 $self->{user_y} = $wy + $dy * $my; 1087 $self->{user_y} = $wy + $dy * $my;
1088 $self->{def_w} = $bw + $dx * ($mx ? -1 : 1); 1088 $self->{def_w} = $bw + $dx * ($mx ? -1 : 1);
1089 $self->{def_h} = $bh + $dy * ($my ? -1 : 1); 1089 $self->{def_h} = $bh + $dy * ($my ? -1 : 1);
1090 $self->move ($self->{user_x}, $self->{user_y}); 1090 $self->move ($self->{user_x}, $self->{user_y});
1091 $self->check_size; 1091 $self->realloc;
1092 }; 1092 };
1093 1093
1094 } elsif ($lr ^ $td) { 1094 } elsif ($lr ^ $td) {
1095 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 1095 my ($ox, $oy) = ($ev->{x}, $ev->{y});
1096 my ($bx, $by) = ($self->{x}, $self->{y}); 1096 my ($bx, $by) = ($self->{x}, $self->{y});
1102 1102
1103 $self->{user_x} = $bx + $x - $ox; 1103 $self->{user_x} = $bx + $x - $ox;
1104 $self->{user_y} = $by + $y - $oy; 1104 $self->{user_y} = $by + $y - $oy;
1105 1105
1106 $self->move ($self->{user_x}, $self->{user_y}); 1106 $self->move ($self->{user_x}, $self->{user_y});
1107 $self->update; 1107 $self->realloc;
1108 }; 1108 };
1109 } 1109 }
1110} 1110}
1111 1111
1112sub button_up { 1112sub button_up {
1131 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1131 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1132 1132
1133 my $border = $self->border; 1133 my $border = $self->border;
1134 1134
1135 glColor @{ $self->{border_bg} }; 1135 glColor @{ $self->{border_bg} };
1136 $tex[1]->draw_quad_alpha (0, 0, $w, $border); 1136 $border[0]->draw_quad_alpha (0, 0, $w, $border);
1137 $tex[3]->draw_quad_alpha (0, $border, $border, $ch); 1137 $border[1]->draw_quad_alpha (0, $border, $border, $ch);
1138 $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); 1138 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
1139 $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border); 1139 $border[3]->draw_quad_alpha (0, $h - $border, $w, $border);
1140 1140
1141 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 1141 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
1142 my $bg = $tex[0]; 1142 glColor @{ $self->{bg} };
1143 1143
1144 # TODO: repeat texture not scale 1144 # TODO: repeat texture not scale
1145 # solve this better(?)
1145 my $rep_x = $cw / $bg->{w}; 1146 $bg->{s} = $cw / $bg->{w};
1146 my $rep_y = $ch / $bg->{h}; 1147 $bg->{t} = $ch / $bg->{h};
1147
1148 glColor @{ $self->{bg} };
1149
1150 $bg->{s} = $rep_x;
1151 $bg->{t} = $rep_y;
1152 $bg->{wrap_mode} = 1;
1153 $bg->draw_quad_alpha ($border, $border, $cw, $ch); 1148 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
1154 } 1149 }
1155 1150
1156 glDisable GL_TEXTURE_2D; 1151 glDisable GL_TEXTURE_2D;
1157 1152
1187 my ($self, $x, $y, $child) = @_; 1182 my ($self, $x, $y, $child) = @_;
1188 1183
1189 $child->set_parent ($self); 1184 $child->set_parent ($self);
1190 $self->{children}[$y][$x] = $child; 1185 $self->{children}[$y][$x] = $child;
1191 1186
1192 $self->check_size (1); 1187 $self->realloc;
1193} 1188}
1194 1189
1195# TODO: move to container class maybe? send children a signal on removal? 1190# TODO: move to container class maybe? send children a signal on removal?
1196sub clear { 1191sub clear {
1197 my ($self) = @_; 1192 my ($self) = @_;
1202 for (@children) { 1197 for (@children) {
1203 delete $_->{parent}; 1198 delete $_->{parent};
1204 $_->hide; 1199 $_->hide;
1205 } 1200 }
1206 1201
1207 $self->check_size (1); 1202 $self->realloc;
1208 $self->update;
1209} 1203}
1210 1204
1211sub get_wh { 1205sub get_wh {
1212 my ($self) = @_; 1206 my ($self) = @_;
1213 1207
1240 (sum @$hs), 1234 (sum @$hs),
1241 ) 1235 )
1242} 1236}
1243 1237
1244sub size_allocate { 1238sub size_allocate {
1245 my ($self, $w, $h) = @_; 1239 my ($self, $w, $h, $changed) = @_;
1246 1240
1247 my ($ws, $hs) = $self->get_wh; 1241 my ($ws, $hs) = $self->get_wh;
1248 1242
1249 my $req_w = (sum @$ws) || 1; 1243 my $req_w = (sum @$ws) || 1;
1250 my $req_h = (sum @$hs) || 1; 1244 my $req_h = (sum @$hs) || 1;
1328 (List::Util::max map $_->{req_h}, @{$self->{children}}), 1322 (List::Util::max map $_->{req_h}, @{$self->{children}}),
1329 ) 1323 )
1330} 1324}
1331 1325
1332sub size_allocate { 1326sub size_allocate {
1333 my ($self, $w, $h) = @_; 1327 my ($self, $w, $h, $changed) = @_;
1334 1328
1335 my $space = $self->{vertical} ? $h : $w; 1329 my $space = $self->{vertical} ? $h : $w;
1336 my $children = $self->{children}; 1330 my $children = $self->{children};
1337 1331
1338 my @req; 1332 my @req;
1467 $self->{text} = "T$text"; 1461 $self->{text} = "T$text";
1468 1462
1469 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; 1463 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
1470 $self->{layout}->set_text ($text); 1464 $self->{layout}->set_text ($text);
1471 1465
1466 $self->realloc;
1472 $self->update; 1467 $self->update;
1473 $self->check_size;
1474} 1468}
1475 1469
1476sub set_markup { 1470sub set_markup {
1477 my ($self, $markup) = @_; 1471 my ($self, $markup) = @_;
1478 1472
1482 my $rgba = $markup =~ /span.*(?:foreground|background)/; 1476 my $rgba = $markup =~ /span.*(?:foreground|background)/;
1483 1477
1484 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; 1478 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1485 $self->{layout}->set_markup ($markup); 1479 $self->{layout}->set_markup ($markup);
1486 1480
1481 $self->realloc;
1487 $self->update; 1482 $self->update;
1488 $self->check_size;
1489} 1483}
1490 1484
1491sub size_request { 1485sub size_request {
1492 my ($self) = @_; 1486 my ($self) = @_;
1493 1487
1514 $h + $self->{padding} * 2, 1508 $h + $self->{padding} * 2,
1515 ) 1509 )
1516} 1510}
1517 1511
1518sub size_allocate { 1512sub size_allocate {
1519 my ($self, $w, $h) = @_; 1513 my ($self, $w, $h, $changed) = @_;
1520 1514
1521 delete $self->{texture}; 1515 delete $self->{texture}
1516 if $changed;
1522} 1517}
1523 1518
1524sub set_fontsize { 1519sub set_fontsize {
1525 my ($self, $fontsize) = @_; 1520 my ($self, $fontsize) = @_;
1526 1521
1527 $self->{fontsize} = $fontsize; 1522 $self->{fontsize} = $fontsize;
1528 delete $self->{texture}; 1523 delete $self->{texture};
1529 1524
1530 $self->update; 1525 $self->realloc;
1531 $self->check_size;
1532} 1526}
1533 1527
1534sub _draw { 1528sub _draw {
1535 my ($self) = @_; 1529 my ($self) = @_;
1536 1530
1616sub set_text { 1610sub set_text {
1617 my ($self, $text) = @_; 1611 my ($self, $text) = @_;
1618 1612
1619 $self->{cursor} = length $text; 1613 $self->{cursor} = length $text;
1620 $self->_set_text ($text); 1614 $self->_set_text ($text);
1621 $self->update; 1615
1622 $self->check_size; 1616 $self->realloc;
1623} 1617}
1624 1618
1625sub get_text { 1619sub get_text {
1626 $_[0]{text} 1620 $_[0]{text}
1627} 1621}
1660 } elsif ($uni) { 1654 } elsif ($uni) {
1661 substr $text, $self->{cursor}++, 0, chr $uni; 1655 substr $text, $self->{cursor}++, 0, chr $uni;
1662 } 1656 }
1663 1657
1664 $self->_set_text ($text); 1658 $self->_set_text ($text);
1665 $self->update; 1659
1666 $self->check_size; 1660 $self->realloc;
1667} 1661}
1668 1662
1669sub focus_in { 1663sub focus_in {
1670 my ($self) = @_; 1664 my ($self) = @_;
1671 1665
2178 $self->update; 2172 $self->update;
2179 2173
2180 $self 2174 $self
2181} 2175}
2182 2176
2177sub changed { }
2178
2183sub set_range { 2179sub set_range {
2184 my ($self, $range) = @_; 2180 my ($self, $range) = @_;
2185 2181
2186 ($range, $self->{range}) = ($self->{range}, $range); 2182 ($range, $self->{range}) = ($self->{range}, $range);
2187 2183
2376 $self->{fontsize} = $fontsize; 2372 $self->{fontsize} = $fontsize;
2377 $self->reflow; 2373 $self->reflow;
2378} 2374}
2379 2375
2380sub size_allocate { 2376sub size_allocate {
2381 my ($self, $w, $h) = @_; 2377 my ($self, $w, $h, $changed) = @_;
2382 2378
2383 $self->SUPER::size_allocate ($w, $h); 2379 $self->SUPER::size_allocate ($w, $h, $changed);
2380
2381 return unless $changed;
2384 2382
2385 $self->{layout}->set_font ($self->{font}) if $self->{font}; 2383 $self->{layout}->set_font ($self->{font}) if $self->{font};
2386 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 2384 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2387 $self->{layout}->set_width ($self->{children}[0]{w}); 2385 $self->{layout}->set_width ($self->{children}[0]{w});
2388 2386
2630 2628
2631 ($w + 4, $h + 4) 2629 ($w + 4, $h + 4)
2632} 2630}
2633 2631
2634sub size_allocate { 2632sub size_allocate {
2635 my ($self, $w, $h) = @_; 2633 my ($self, $w, $h, $changed) = @_;
2636 2634
2635 return unless $changed;
2636
2637 $self->SUPER::size_allocate ($w - 4, $h - 4); 2637 $self->SUPER::size_allocate ($w - 4, $h - 4, $changed);
2638}
2639
2640sub visibility_change {
2641 my ($self, $visible) = @_;
2642
2643 return unless $visible;
2644
2645 $self->{root}->on_post_alloc ("move_$self" => sub {
2646 my $widget = $self->{owner}
2647 or return;
2648
2649 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2650
2651 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2652 if $x + $self->{w} > $::WIDTH;
2653
2654 $self->move ($x, $y);
2655 });
2638} 2656}
2639 2657
2640sub _draw { 2658sub _draw {
2641 my ($self) = @_; 2659 my ($self) = @_;
2642 2660
2659 glVertex $w, $h; 2677 glVertex $w, $h;
2660 glVertex $w, 0; 2678 glVertex $w, 0;
2661 glEnd; 2679 glEnd;
2662 2680
2663 glTranslate 2 - 0.375, 2 - 0.375; 2681 glTranslate 2 - 0.375, 2 - 0.375;
2682
2664 $self->SUPER::_draw; 2683 $self->SUPER::_draw;
2665} 2684}
2666 2685
2667############################################################################# 2686#############################################################################
2668 2687
2977use CFClient::OpenGL; 2996use CFClient::OpenGL;
2978 2997
2979sub new { 2998sub new {
2980 my $class = shift; 2999 my $class = shift;
2981 3000
2982 $class->SUPER::new ( 3001 my $self = $class->SUPER::new (
2983 visible => 1, 3002 visible => 1,
2984 @_, 3003 @_,
2985 ) 3004 );
3005
3006 Scalar::Util::weaken ($self->{root} = $self);
3007
3008 $self
2986} 3009}
2987 3010
2988sub configure { 3011sub configure {
2989 my ($self, $x, $y, $w, $h) = @_; 3012 my ($self, $x, $y, $w, $h) = @_;
2990 3013
2991 $self->{w} = $w; 3014 $self->{w} = $w;
2992 $self->{h} = $h; 3015 $self->{h} = $h;
2993} 3016}
2994 3017
2995sub check_size { 3018sub reconfigure {
2996 my ($self) = @_; 3019 my ($self) = @_;
2997 3020
3021 $self->SUPER::reconfigure;
3022
2998 $self->size_allocate ($self->{w}, $self->{h}) 3023 $self->size_allocate ($self->{w}, $self->{h}, 1)
2999 if $self->{w}; 3024 if $self->{w};
3000} 3025}
3001 3026
3002sub size_request { 3027sub size_request {
3003 my ($self) = @_; 3028 my ($self) = @_;
3004 3029
3005 ($self->{w}, $self->{h}) 3030 ($self->{w}, $self->{h})
3006} 3031}
3007 3032
3008sub size_allocate { 3033sub size_allocate {
3009 my ($self, $w, $h) = @_; 3034 my ($self, $w, $h, $changed) = @_;
3010 3035
3011 for my $child ($self->children) { 3036 for my $child ($self->children) {
3012 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 3037 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
3013 3038
3014 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 3039 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1
3039} 3064}
3040 3065
3041sub update { 3066sub update {
3042 my ($self) = @_; 3067 my ($self) = @_;
3043 3068
3044 $self->check_size;
3045 $::WANT_REFRESH++; 3069 $::WANT_REFRESH++;
3046} 3070}
3047 3071
3048sub add { 3072sub add {
3049 my ($self, @children) = @_; 3073 my ($self, @children) = @_;
3055 $child->{x} = int $child->{x}; 3079 $child->{x} = int $child->{x};
3056 $child->{y} = int $child->{y}; 3080 $child->{y} = int $child->{y};
3057 } 3081 }
3058 3082
3059 $self->SUPER::add (@children); 3083 $self->SUPER::add (@children);
3060
3061 for (my @widgets = @children; my $w = pop @widgets; ) {
3062 push @widgets, $w->children;
3063 $w->set_visible;
3064 }
3065
3066} 3084}
3067 3085
3068sub remove { 3086sub remove {
3069 my ($self, @children) = @_; 3087 my ($self, @children) = @_;
3070 3088
3095 while ($self->{refresh_hook}) { 3113 while ($self->{refresh_hook}) {
3096 $_->() 3114 $_->()
3097 for values %{delete $self->{refresh_hook}}; 3115 for values %{delete $self->{refresh_hook}};
3098 } 3116 }
3099 3117
3100 if ($self->{check_size}) { 3118 if ($self->{realloc}) {
3101 my @queue; 3119 my @queue;
3102 3120
3103 while () { 3121 while () {
3104 if ($self->{check_size}) { 3122 if ($self->{realloc}) {
3105 #TODO use array-of-depth approach 3123 #TODO use array-of-depth approach
3106 3124
3107 @queue = sort { $a->{visible} <=> $b->{visible} } 3125 @queue = sort { $a->{visible} <=> $b->{visible} }
3108 @queue, values %{delete $self->{check_size}}; 3126 @queue, values %{delete $self->{realloc}};
3109 } 3127 }
3110 3128
3111 my $widget = pop @queue || last; 3129 my $widget = pop @queue || last;
3112 3130
3113 defined $widget->{visible} or last; # do not resize invisible widgets 3131 $widget->{visible} or last; # do not resize invisible widgets
3114 3132
3115 my ($w, $h) = $widget->{def_w} && $widget->{def_h} 3133 my ($w, $h) = $widget->{def_w} && $widget->{def_h}
3116 ? @$widget{qw(def_w def_h)} 3134 ? @$widget{qw(def_w def_h)}
3117 : $widget->size_request; 3135 : $widget->size_request;
3118 3136
3119 if (delete $widget->{force_alloc}
3120 or $w != $widget->{req_w} or $h != $widget->{req_h}) {
3121 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# 3137 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
3122 3138
3123 $widget->{req_w} = $w; 3139 $widget->{req_w} = $w;
3124 $widget->{req_h} = $h; 3140 $widget->{req_h} = $h;
3125 3141
3126 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; 3142 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h];
3127 3143
3128 $widget->{parent}->check_size 3144 push @queue, $widget->{parent}
3129 if $widget->{parent}; 3145 if $widget->{parent};
3130 }
3131 } 3146 }
3132 } 3147 }
3133 3148
3134 while (my $size_alloc = delete $self->{size_alloc}) { 3149 while (my $size_alloc = delete $self->{size_alloc}) {
3135 my @queue = sort $b->[0]{visible} <=> $a->[0]{visible}, 3150 my @queue = sort $b->[0]{visible} <=> $a->[0]{visible},
3139 my ($widget, $w, $h) = @{ pop @queue or last }; 3154 my ($widget, $w, $h) = @{ pop @queue or last };
3140 3155
3141 $w = 0 if $w < 0; 3156 $w = 0 if $w < 0;
3142 $h = 0 if $h < 0; 3157 $h = 0 if $h < 0;
3143 3158
3159 my $changed = $widget->{w} != $w || $widget->{h} != $h;
3160
3144 $widget->{w} = $w; 3161 $widget->{w} = $w;
3145 $widget->{h} = $h; 3162 $widget->{h} = $h;
3163
3146 $widget->emit (size_allocate => $w, $h); 3164 $widget->emit (size_allocate => $w, $h, $changed);
3147 } 3165 }
3148 } 3166 }
3149 3167
3150 while ($self->{post_alloc_hook}) { 3168 while ($self->{post_alloc_hook}) {
3151 $_->() 3169 $_->()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines