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.374 by root, Mon Jul 16 12:36:48 2007 UTC vs.
Revision 1.413 by root, Mon Jul 23 15:30:45 2007 UTC

113 } 113 }
114 114
115 if ($GRAB) { 115 if ($GRAB) {
116 if ($ev->{button} == 4 || $ev->{button} == 5) { 116 if ($ev->{button} == 4 || $ev->{button} == 5) {
117 # mousewheel 117 # mousewheel
118 $ev->{dx} = 0;
119 $ev->{dy} = $ev->{button} * 2 - 9; 118 my $delta = $ev->{button} * 2 - 9;
119 my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT;
120
121 $ev->{dx} = $shift ? $delta : 0;
122 $ev->{dy} = $shift ? 0 : $delta;
123
120 $GRAB->emit (mouse_wheel => $ev); 124 $GRAB->emit (mouse_wheel => $ev);
121 } else { 125 } else {
122 $GRAB->emit (button_down => $ev) 126 $GRAB->emit (button_down => $ev)
123 } 127 }
124 } 128 }
547 551
548 # parent 552 # parent
549 $self->{parent} && $self->{parent}->emit ($signal, @args) 553 $self->{parent} && $self->{parent}->emit ($signal, @args)
550} 554}
551 555
552sub find_widget { 556#sub find_widget {
553 my ($self, $x, $y) = @_; 557# in .xs
554
555 return () unless $self->{can_events};
556
557 return $self
558 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
559 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
560
561 ()
562}
563 558
564sub set_parent { 559sub set_parent {
565 my ($self, $parent) = @_; 560 my ($self, $parent) = @_;
566 561
567 CFPlus::weaken ($self->{parent} = $parent); 562 CFPlus::weaken ($self->{parent} = $parent);
598 593
599# using global variables seems a bit hacky, but passing through all drawing 594# using global variables seems a bit hacky, but passing through all drawing
600# functions seems pointless. 595# functions seems pointless.
601our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn 596our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn
602 597
603sub draw { 598#sub draw {
604 my ($self) = @_; 599#CFPlus.xs
605
606 return unless $self->{h} && $self->{w};
607
608 # update screen rectangle
609 local $draw_x = $draw_x + $self->{x};
610 local $draw_y = $draw_y + $self->{y};
611
612 # skip widgets that are entirely outside the drawing area
613 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w)
614 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h);
615
616 glPushMatrix;
617 glTranslate $self->{x}, $self->{y}, 0;
618
619 if ($self == $HOVER && $self->{can_hover}) {
620 glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2;
621 glEnable GL_BLEND;
622 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
623 glBegin GL_QUADS;
624 glVertex 0 , 0;
625 glVertex $self->{w}, 0;
626 glVertex $self->{w}, $self->{h};
627 glVertex 0 , $self->{h};
628 glEnd;
629 glDisable GL_BLEND;
630 }
631
632 if ($ENV{CFPLUS_DEBUG} & 1) {
633 glPushMatrix;
634 glColor 1, 1, 0, 1;
635 glTranslate 0.375, 0.375;
636 glBegin GL_LINE_LOOP;
637 glVertex 0 , 0;
638 glVertex $self->{w} - 1, 0;
639 glVertex $self->{w} - 1, $self->{h} - 1;
640 glVertex 0 , $self->{h} - 1;
641 glEnd;
642 glPopMatrix;
643 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
644 }
645
646 $self->_draw;
647 glPopMatrix;
648}
649 600
650sub _draw { 601sub _draw {
651 my ($self) = @_; 602 my ($self) = @_;
652 603
653 warn "no draw defined for $self\n"; 604 warn "no draw defined for $self\n";
654} 605}
655 606
656my $cntx;#d#
657sub DESTROY { 607sub DESTROY {
658 my ($self) = @_; 608 my ($self) = @_;
659 609
660 return if CFPlus::in_destruct; 610 return if CFPlus::in_destruct;
661 611
746 can_events => 0, 696 can_events => 0,
747 %arg, 697 %arg,
748 ); 698 );
749 699
750 $self->add (@$children) 700 $self->add (@$children)
751 if $children; 701 if $children && @$children;
752 702
753 $self 703 $self
754} 704}
755 705
756sub realloc { 706sub realloc {
765 my ($self, @widgets) = @_; 715 my ($self, @widgets) = @_;
766 716
767 $_->set_parent ($self) 717 $_->set_parent ($self)
768 for @widgets; 718 for @widgets;
769 719
720 # TODO: only do this in widgets that need it, e.g. root, fixed
770 use sort 'stable'; 721 use sort 'stable';
771 722
772 $self->{children} = [ 723 $self->{children} = [
773 sort { $a->{z} <=> $b->{z} } 724 sort { $a->{z} <=> $b->{z} }
774 @{$self->{children}}, @widgets 725 @{$self->{children}}, @widgets
775 ]; 726 ];
776 727
777 $self->realloc; 728 $self->realloc;
729
730 $self->emit (c_add => \@widgets);
731
732 map $_+0, @widgets
778} 733}
779 734
780sub children { 735sub children {
781 @{ $_[0]{children} } 736 @{ $_[0]{children} }
782} 737}
783 738
784sub remove { 739sub remove {
785 my ($self, $child) = @_; 740 my ($self, @widgets) = @_;
786 741
742 $self->emit (c_remove => \@widgets);
743
744 for my $child (@widgets) {
787 delete $child->{parent}; 745 delete $child->{parent};
788 $child->hide; 746 $child->hide;
789
790 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 747 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
748 }
791 749
792 $self->realloc; 750 $self->realloc;
793} 751}
794 752
795sub clear { 753sub clear {
796 my ($self) = @_; 754 my ($self) = @_;
797 755
798 my $children = delete $self->{children}; 756 my $children = $self->{children};
799 $self->{children} = []; 757 $self->{children} = [];
800 758
801 for (@$children) { 759 for (@$children) {
802 delete $_->{parent}; 760 delete $_->{parent};
803 $_->hide; 761 $_->hide;
823} 781}
824 782
825sub _draw { 783sub _draw {
826 my ($self) = @_; 784 my ($self) = @_;
827 785
828 $_->draw for @{$self->{children}}; 786 $_->draw for $self->visible_children;
829} 787}
830 788
831############################################################################# 789#############################################################################
832 790
833package CFPlus::UI::Bin; 791package CFPlus::UI::Bin;
843} 801}
844 802
845sub add { 803sub add {
846 my ($self, $child) = @_; 804 my ($self, $child) = @_;
847 805
848 $self->SUPER::remove ($_) for @{ $self->{children} }; 806 $self->clear;
849 $self->SUPER::add ($child); 807 $self->SUPER::add ($child);
850} 808}
851 809
852sub remove { 810sub remove {
853 my ($self, $widget) = @_; 811 my ($self, $widget) = @_;
943} 901}
944 902
945############################################################################# 903#############################################################################
946 904
947package CFPlus::UI::ViewPort; 905package CFPlus::UI::ViewPort;
906
907use List::Util qw(min max);
948 908
949our @ISA = CFPlus::UI::Window::; 909our @ISA = CFPlus::UI::Window::;
950 910
951sub new { 911sub new {
952 my $class = shift; 912 my $class = shift;
961sub size_request { 921sub size_request {
962 my ($self) = @_; 922 my ($self) = @_;
963 923
964 my ($w, $h) = @{$self->child}{qw(req_w req_h)}; 924 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
965 925
966 $w = 10 if $self->{scroll_x}; 926 $w = 1 if $self->{scroll_x};
967 $h = 10 if $self->{scroll_y}; 927 $h = 1 if $self->{scroll_y};
968 928
969 ($w, $h) 929 ($w, $h)
970} 930}
971 931
972sub invoke_size_allocate { 932sub invoke_size_allocate {
984} 944}
985 945
986sub set_offset { 946sub set_offset {
987 my ($self, $x, $y) = @_; 947 my ($self, $x, $y) = @_;
988 948
949 my $x = max 0, min $self->child->{w} - $self->{w}, int $x;
950 my $y = max 0, min $self->child->{h} - $self->{h}, int $y;
951
952 if ($x != $self->{view_x} or $y != $self->{view_y}) {
989 $self->{view_x} = int $x; 953 $self->{view_x} = $x;
990 $self->{view_y} = int $y; 954 $self->{view_y} = $y;
991 955
956 $self->emit (changed => $x, $y);
992 $self->update; 957 $self->update;
958 }
993} 959}
994 960
995# hmm, this does not work for topleft of $self... but we should not ask for that 961# hmm, this does not work for topleft of $self... but we should not ask for that
996sub coord2local { 962sub coord2local {
997 my ($self, $x, $y) = @_; 963 my ($self, $x, $y) = @_;
1012 my ($self, $x, $y) = @_; 978 my ($self, $x, $y) = @_;
1013 979
1014 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 980 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
1015 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 981 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
1016 ) { 982 ) {
1017 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) 983 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
1018 } else { 984 } else {
1019 $self->CFPlus::UI::Base::find_widget ($x, $y) 985 $self->CFPlus::UI::Base::find_widget ($x, $y)
1020 } 986 }
1021} 987}
1022 988
1043 my $child = delete $arg{child}; 1009 my $child = delete $arg{child};
1044 1010
1045 my $self; 1011 my $self;
1046 1012
1047 my $hslider = new CFPlus::UI::Slider 1013 my $hslider = new CFPlus::UI::Slider
1014 col => 0,
1015 row => 1,
1048 vertical => 0, 1016 vertical => 0,
1049 range => [0, 0, 1, 0.01], # HACK fix 1017 range => [0, 0, 1, 0.01], # HACK fix
1050 on_changed => sub { 1018 on_changed => sub {
1051 $self->{hpos} = $_[1]; 1019 $self->{hpos} = $_[1];
1052 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1020 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1053 }, 1021 },
1054 ; 1022 ;
1055 1023
1056 my $vslider = new CFPlus::UI::Slider 1024 my $vslider = new CFPlus::UI::Slider
1025 col => 1,
1026 row => 0,
1057 vertical => 1, 1027 vertical => 1,
1058 range => [0, 0, 1, 0.01], # HACK fix 1028 range => [0, 0, 1, 0.01], # HACK fix
1059 on_changed => sub { 1029 on_changed => sub {
1060 $self->{vpos} = $_[1]; 1030 $self->{vpos} = $_[1];
1061 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1031 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1072 row_expand => [1, 0], 1042 row_expand => [1, 0],
1073 %arg, 1043 %arg,
1074 ); 1044 );
1075 1045
1076 $self->{vp} = new CFPlus::UI::ViewPort 1046 $self->{vp} = new CFPlus::UI::ViewPort
1047 col => 0,
1048 row => 0,
1077 expand => 1, 1049 expand => 1,
1078 scroll_x => $self->{scroll_x}, 1050 scroll_x => $self->{scroll_x},
1079 scroll_y => $self->{scroll_y}, 1051 scroll_y => $self->{scroll_y},
1052 on_changed => sub {
1053 my ($vp, $x, $y) = @_;
1054
1055 $vp->{parent}{hslider}->set_value ($x);
1056 $vp->{parent}{vslider}->set_value ($y);
1057
1058 0
1059 },
1060 on_size_allocate => sub {
1061 my ($vp, $w, $h) = @_;
1062 $vp->{parent}->update_slider;
1063 0
1064 },
1080 ; 1065 ;
1081 1066
1082 $self->SUPER::add (0, 0, $self->{vp}); 1067 $self->SUPER::add ($self->{vp});
1083 1068
1084 $self->add ($child) if $child; 1069 $self->add ($child) if $child;
1085 1070
1086 $self 1071 $self
1087} 1072}
1088
1089#TODO# update range on size_allocate depending on child
1090 1073
1091sub add { 1074sub add {
1092 my ($self, $widget) = @_; 1075 my ($self, $widget) = @_;
1093 1076
1094 $self->{vp}->add ($self->{child} = $widget); 1077 $self->{vp}->add ($self->{child} = $widget);
1095} 1078}
1096 1079
1080sub update_slider {
1081 my ($self) = @_;
1082
1083 my $child = ($self->{vp} or return)->child;
1084
1085 if ($self->{scroll_x}) {
1086 my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w});
1087 $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]);
1088
1089 my $visible = $w1 > $w2;
1090 if ($visible != $self->{hslider_visible}) {
1091 $self->{hslider_visible} = $visible;
1092 $visible ? $self->SUPER::add ($self->{hslider})
1093 : $self->SUPER::remove ($self->{hslider});
1094 }
1095 }
1096
1097 if ($self->{scroll_y}) {
1098 my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h});
1099 $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]);
1100
1101 my $visible = $h1 > $h2;
1102 if ($visible != $self->{vslider_visible}) {
1103 $self->{vslider_visible} = $visible;
1104 $visible ? $self->SUPER::add ($self->{vslider})
1105 : $self->SUPER::remove ($self->{vslider});
1106 }
1107 }
1108}
1109
1110sub start_dragging {
1111 my ($self, $ev) = @_;
1112
1113 $self->grab_focus;
1114
1115 my $ox = $self->{vp}{view_x};
1116 my $oy = $self->{vp}{view_y};
1117
1118 $self->{motion} = sub {
1119 my ($ev, $x, $y) = @_;
1120
1121 $ox -= $ev->{xrel};
1122 $oy -= $ev->{yrel};
1123
1124 $self->{vp}->set_offset ($ox, $oy);
1125 };
1126}
1127
1097sub invoke_mouse_wheel { 1128sub invoke_mouse_wheel {
1098 my ($self, $ev) = @_; 1129 my ($self, $ev) = @_;
1099 1130
1100 return 0 unless $ev->{dy}; # only vertical movements for now
1101
1102 $self->{vslider}->emit (mouse_wheel => $ev); 1131 $self->{vslider}->emit (mouse_wheel => $ev) if $self->{vslider_visible};
1132 $self->{hslider}->emit (mouse_wheel => $ev) if $self->{hslider_visible};
1103 1133
1104 1 1134 1
1105} 1135}
1106 1136
1107sub update_slider { 1137sub invoke_button_down {
1108 my ($self) = @_; 1138 my ($self, $ev, $x, $y) = @_;
1109 1139
1110 my $child = ($self->{vp} or return)->child; 1140 if ($ev->{button} == 2) {
1141 $self->start_dragging ($ev);
1142 return 1;
1143 }
1111 1144
1112 my ($w1, $w2) = ($child->{w}, $self->{vp}{w});
1113 $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]);
1114
1115 my $visible = $w1 > $w2;
1116 if ($visible != $self->{hslider}{visible}) {
1117 $visible ? $self->SUPER::add (0, 1, $self->{hslider})
1118 : $self->{hslider}->hide;
1119 } 1145 0
1146}
1120 1147
1121 my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); 1148sub invoke_button_up {
1122 $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); 1149 my ($self, $ev, $x, $y) = @_;
1123 1150
1124 my $visible = $h1 > $h2; 1151 if (delete $self->{motion}) {
1125 if ($visible != $self->{vslider}{visible}) { 1152 return 1;
1126 $visible ? $self->SUPER::add (1, 0, $self->{vslider}) 1153 }
1127 : $self->{vslider}->hide; 1154
1128 } 1155 0
1129} 1156}
1130 1157
1131sub update { 1158sub invoke_mouse_motion {
1132 my ($self) = @_; 1159 my ($self, $ev, $x, $y) = @_;
1133 1160
1134 $self->SUPER::update; 1161 if ($self->{motion}) {
1135 $self->update_slider; 1162 $self->{motion}->($ev, $x, $y);
1163 return 1;
1164 }
1165
1166 0
1136} 1167}
1137 1168
1138sub invoke_size_allocate { 1169sub invoke_size_allocate {
1139 my ($self, $w, $h) = @_; 1170 my ($self, $w, $h) = @_;
1140 1171
1296 1327
1297my @border = 1328my @border =
1298 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1329 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1299 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1330 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1300 1331
1332my @icon =
1333 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1334 qw(x1_move.png x1_resize.png);
1335
1301sub new { 1336sub new {
1302 my ($class, %arg) = @_; 1337 my ($class, %arg) = @_;
1303 1338
1304 my $self = $class->SUPER::new ( 1339 my $self = $class->SUPER::new (
1305 bg => [1, 1, 1, 1], 1340 bg => [1, 1, 1, 1],
1473 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1508 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1474 1509
1475 my $border = $self->border; 1510 my $border = $self->border;
1476 1511
1477 glColor @{ $self->{border_bg} }; 1512 glColor @{ $self->{border_bg} };
1478 $border[0]->draw_quad_alpha (0, 0, $w, $border); 1513 $border[0]->draw_quad_alpha ( 0, 0, $w, $border);
1479 $border[1]->draw_quad_alpha (0, $border, $border, $ch); 1514 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch);
1480 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); 1515 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
1481 $border[3]->draw_quad_alpha (0, $h - $border, $w, $border); 1516 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border);
1517
1518 # move
1519 my $w2 = ($w - $border) * .5;
1520 my $h2 = ($h - $border) * .5;
1521 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border);
1522 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border);
1523 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border);
1524
1525 # resize
1526 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border);
1527 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border)
1528 unless $self->{has_close_button};
1529 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border);
1530 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border);
1482 1531
1483 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 1532 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
1484 glColor @{ $self->{bg} }; 1533 glColor @{ $self->{bg} };
1485 1534
1486 # TODO: repeat texture not scale 1535 # TODO: repeat texture not scale
1507 1556
1508############################################################################# 1557#############################################################################
1509 1558
1510package CFPlus::UI::Table; 1559package CFPlus::UI::Table;
1511 1560
1512our @ISA = CFPlus::UI::Base::; 1561our @ISA = CFPlus::UI::Container::;
1513 1562
1514use List::Util qw(max sum); 1563use List::Util qw(max sum);
1515 1564
1516use CFPlus::OpenGL; 1565use CFPlus::OpenGL;
1517 1566
1518sub new { 1567sub new {
1519 my $class = shift; 1568 my $class = shift;
1520 1569
1521 $class->SUPER::new ( 1570 $class->SUPER::new (
1522 children => [],
1523 col_expand => [], 1571 col_expand => [],
1524 row_expand => [], 1572 row_expand => [],
1525 @_, 1573 @_,
1526 ) 1574 )
1527} 1575}
1528 1576
1529sub children {
1530 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1531}
1532
1533# TODO: store row/col info in child widget and use standard add/del
1534sub add { 1577sub add {
1578 my ($self, @widgets) = @_;
1579
1580 for my $child (@widgets) {
1581 $child->{rowspan} ||= 1;
1582 $child->{colspan} ||= 1;
1583 }
1584
1585 $self->SUPER::add (@widgets);
1586}
1587
1588sub add_at {
1535 my ($self) = shift; 1589 my $self = shift;
1590
1591 my @widgets;
1536 1592
1537 while (@_) { 1593 while (@_) {
1538 my ($x, $y, $child) = splice @_, 0, 3, (); 1594 my ($col, $row, $child) = splice @_, 0, 3, ();
1539 $child->set_parent ($self);
1540 $self->{children}[$y][$x] = $child;
1541 }
1542 1595
1543 $self->{force_realloc} = 1; 1596 $child->{row} = $row;
1544 $self->{force_size_alloc} = 1; 1597 $child->{col} = $col;
1545 $self->realloc;
1546}
1547 1598
1548sub remove { 1599 push @widgets, $child;
1600 }
1601
1602 $self->add (@widgets);
1603}
1604
1605sub get_wh {
1549 my ($self, $child) = @_; 1606 my ($self) = @_;
1550 1607
1551 for (@{ $self->{children} }) { 1608 my (@w, @h);
1552 for (@{ $_ || [] }) { 1609
1553 $_ = undef if $_ == $child; 1610 my @children = $self->children;
1611
1612 # first pass, columns
1613 for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) {
1614 my ($c, $w, $cs) = @$widget{qw(col req_w colspan)};
1615
1616 my $sw = sum @w[$c .. $c + $cs - 1];
1617
1618 if ($w > $sw) {
1619 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1];
1554 } 1620 }
1555 } 1621 }
1556}
1557 1622
1558# TODO: move to container class maybe? send children a signal on removal? 1623 # second pass, rows
1559sub clear { 1624 for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) {
1560 my ($self) = @_;
1561
1562 my @children = $self->children;
1563 delete $self->{children};
1564
1565 for (@children) {
1566 delete $_->{parent};
1567 $_->hide;
1568 }
1569
1570 $self->realloc;
1571}
1572
1573sub get_wh {
1574 my ($self) = @_;
1575
1576 my (@w, @h);
1577
1578 for my $y (0 .. $#{$self->{children}}) {
1579 my $row = $self->{children}[$y]
1580 or next;
1581
1582 for my $x (0 .. $#$row) {
1583 my $widget = $row->[$x]
1584 or next;
1585 my ($w, $h) = @$widget{qw(req_w req_h)}; 1625 my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)};
1586 1626
1587 $w[$x] = max $w[$x], $w; 1627 my $sh = sum @h[$r .. $r + $rs - 1];
1588 $h[$y] = max $h[$y], $h; 1628
1629 if ($h > $sh) {
1630 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1];
1589 } 1631 }
1590 } 1632 }
1591 1633
1592 (\@w, \@h) 1634 (\@w, \@h)
1593} 1635}
1609 my ($ws, $hs) = $self->get_wh; 1651 my ($ws, $hs) = $self->get_wh;
1610 1652
1611 my $req_w = (sum @$ws) || 1; 1653 my $req_w = (sum @$ws) || 1;
1612 my $req_h = (sum @$hs) || 1; 1654 my $req_h = (sum @$hs) || 1;
1613 1655
1614 # TODO: nicer code 1656 # now linearly scale the rows/columns to the allocated size
1615 my @col_expand = @{$self->{col_expand}}; 1657 my @col_expand = @{$self->{col_expand}};
1616 @col_expand = (1) x @$ws unless @col_expand; 1658 @col_expand = (1) x @$ws unless @col_expand;
1617 my $col_expand = (sum @col_expand) || 1; 1659 my $col_expand = (sum @col_expand) || 1;
1618 1660
1619 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1661 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1626 1668
1627 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; 1669 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1628 1670
1629 CFPlus::UI::harmonize $hs; 1671 CFPlus::UI::harmonize $hs;
1630 1672
1631 my $y; 1673 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] }
1674 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] }
1632 1675
1633 for my $r (0 .. $#{$self->{children}}) { 1676 for my $widget ($self->children) {
1634 my $row = $self->{children}[$r] 1677 my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)};
1635 or next;
1636 1678
1637 my $x = 0; 1679 $widget->configure (
1638 my $row_h = $hs->[$r]; 1680 $x[$c], $y[$r],
1681 $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r],
1639 1682 );
1640 for my $c (0 .. $#$row) {
1641 my $col_w = $ws->[$c];
1642
1643 if (my $widget = $row->[$c]) {
1644 $widget->configure ($x, $y, $col_w, $row_h);
1645 }
1646
1647 $x += $col_w;
1648 }
1649
1650 $y += $row_h;
1651 } 1683 }
1652 1684
1653 1 1685 1
1654} 1686}
1655 1687
1656sub find_widget {
1657 my ($self, $x, $y) = @_;
1658
1659 $x -= $self->{x};
1660 $y -= $self->{y};
1661
1662 my $res;
1663
1664 for (grep $_, map @$_, grep $_, @{ $self->{children} }) {
1665 $res = $_->find_widget ($x, $y)
1666 and return $res;
1667 }
1668
1669 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
1670}
1671
1672sub _draw {
1673 my ($self) = @_;
1674
1675 for (grep $_, @{$self->{children}}) {
1676 $_->draw for grep $_, @$_;
1677 }
1678}
1679
1680############################################################################# 1688#############################################################################
1681 1689
1682package CFPlus::UI::Fixed; 1690package CFPlus::UI::Fixed;
1683 1691
1684use List::Util qw(min max); 1692use List::Util qw(min max);
1685 1693
1686our @ISA = CFPlus::UI::Container::; 1694our @ISA = CFPlus::UI::Container::;
1687 1695
1688sub add {
1689 my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_;
1690
1691 $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h];
1692 $self->SUPER::add ($child);
1693}
1694
1695sub _scale($$$) { 1696sub _scale($$$) {
1696 my ($mode, $val, $max) = @_; 1697 my ($rel, $val, $max) = @_;
1697 1698
1698 $mode eq "abs" ? $val 1699 $rel ? $val * $max : $val
1699 : $mode eq "rel" ? $val * $max
1700 : 0
1701} 1700}
1702 1701
1703sub size_request { 1702sub size_request {
1704 my ($self) = @_; 1703 my ($self) = @_;
1705 1704
1706 my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); 1705 my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0);
1707 1706
1708 # determine overall size by querying abs widgets 1707 # determine overall size by querying abs widgets
1709 for my $child ($self->visible_children) { 1708 for my $child ($self->visible_children) {
1710 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1709 unless ($child->{c_rel}) {
1710 my $x = $child->{c_x};
1711 my $y = $child->{c_y};
1711 1712
1712 if ($pos eq "abs") {
1713 $w = _scale $size, $w, $child->{req_w};
1714 $h = _scale $size, $h, $child->{req_h};
1715
1716 $x1 = min $x1, $x; $x2 = max $x2, $x + $w; 1713 $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w};
1717 $y1 = min $y1, $y; $y2 = max $y2, $y + $h; 1714 $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h};
1718 } 1715 }
1719 } 1716 }
1720 1717
1721 my $W = $x2 - $x1; 1718 my $W = $x2 - $x1;
1722 my $H = $y2 - $y1; 1719 my $H = $y2 - $y1;
1723 1720
1724 # now layout remaining widgets 1721 # now layout remaining widgets
1725 for my $child ($self->visible_children) { 1722 for my $child ($self->visible_children) {
1726 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1723 if ($child->{c_rel}) {
1724 my $x = _scale $child->{c_rel}, $child->{c_x}, $W;
1725 my $y = _scale $child->{c_rel}, $child->{c_y}, $H;
1727 1726
1728 if ($pos ne "abs") {
1729 $x = _scale $pos, $x, $W;
1730 $y = _scale $pos, $x, $H;
1731 $w = _scale $size, $w, $child->{req_w};
1732 $h = _scale $size, $h, $child->{req_h};
1733
1734 $x1 = min $x1, $x; $x2 = max $x2, $x + $w; 1727 $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w};
1735 $y1 = min $y1, $y; $y2 = max $y2, $y + $h; 1728 $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h};
1736 } 1729 }
1737 } 1730 }
1738 1731
1739 my $W = $x2 - $x1; 1732 my $W = $x2 - $x1;
1740 my $H = $y2 - $y1; 1733 my $H = $y2 - $y1;
1744 1737
1745sub invoke_size_allocate { 1738sub invoke_size_allocate {
1746 my ($self, $W, $H) = @_; 1739 my ($self, $W, $H) = @_;
1747 1740
1748 for my $child ($self->visible_children) { 1741 for my $child ($self->visible_children) {
1749 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1742 my $x = _scale $child->{c_rel}, $child->{c_x}, $W;
1743 my $y = _scale $child->{c_rel}, $child->{c_y}, $H;
1750 1744
1751 $x = _scale $pos, $x, $W; 1745 $x += $child->{c_halign} * $child->{req_w};
1752 $y = _scale $pos, $x, $H; 1746 $y += $child->{c_valign} * $child->{req_h};
1753 $w = _scale $size, $w, $child->{req_w};
1754 $h = _scale $size, $h, $child->{req_h};
1755 1747
1756 $child->configure ($x, $y, $w, $h); 1748 $child->configure (int $x, int $y, $child->{req_w}, $child->{req_h});
1757 } 1749 }
1758 1750
1759 1 1751 1
1760} 1752}
1761 1753
1765 1757
1766our @ISA = CFPlus::UI::Container::; 1758our @ISA = CFPlus::UI::Container::;
1767 1759
1768sub size_request { 1760sub size_request {
1769 my ($self) = @_; 1761 my ($self) = @_;
1762
1763 my @children = $self->visible_children;
1770 1764
1771 $self->{vertical} 1765 $self->{vertical}
1772 ? ( 1766 ? (
1773 (List::Util::max map $_->{req_w}, @{$self->{children}}), 1767 (List::Util::max map $_->{req_w}, @children),
1774 (List::Util::sum map $_->{req_h}, @{$self->{children}}), 1768 (List::Util::sum map $_->{req_h}, @children),
1775 ) 1769 )
1776 : ( 1770 : (
1777 (List::Util::sum map $_->{req_w}, @{$self->{children}}), 1771 (List::Util::sum map $_->{req_w}, @children),
1778 (List::Util::max map $_->{req_h}, @{$self->{children}}), 1772 (List::Util::max map $_->{req_h}, @children),
1779 ) 1773 )
1780} 1774}
1781 1775
1782sub invoke_size_allocate { 1776sub invoke_size_allocate {
1783 my ($self, $w, $h) = @_; 1777 my ($self, $w, $h) = @_;
2024 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 2018 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2025 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} 2019 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2026 : ($self->{h} - $size->[1]) * 0.5); 2020 : ($self->{h} - $size->[1]) * 0.5);
2027 }; 2021 };
2028 2022
2029 my $w = List::Util::min $self->{w} + 4, $size->[0]; 2023# unless ($self->{list}) {
2030 my $h = List::Util::min $self->{h} + 2, $size->[1]; 2024# $self->{list} = CFPlus::OpenGL::glGenList;
2025# CFPlus::OpenGL::glNewList $self->{list};
2026# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2027# CFPlus::OpenGL::glEndList;
2028# }
2029#
2030# CFPlus::OpenGL::glCallList $self->{list};
2031 2031
2032 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2032 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2033} 2033}
2034
2035#sub destroy {
2036# my ($self) = @_;
2037#
2038# CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list};
2039#
2040# $self->SUPER::destroy;
2041#}
2034 2042
2035############################################################################# 2043#############################################################################
2036 2044
2037package CFPlus::UI::EntryBase; 2045package CFPlus::UI::EntryBase;
2038 2046
2322 2330
2323use CFPlus::OpenGL; 2331use CFPlus::OpenGL;
2324 2332
2325my @tex = 2333my @tex =
2326 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2334 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2327 qw(b1_button_active.png); 2335 qw(b1_button_inactive.png b1_button_active.png);
2328 2336
2329sub new { 2337sub new {
2330 my $class = shift; 2338 my $class = shift;
2331 2339
2332 $class->SUPER::new ( 2340 $class->SUPER::new (
2333 padding_x => 4, 2341 padding_x => 4,
2334 padding_y => 4, 2342 padding_y => 4,
2335 fg => [1, 1, 1], 2343 fg => [1.0, 1.0, 1.0],
2336 active_fg => [0, 0, 1], 2344 active_fg => [0.8, 0.8, 0.8],
2337 can_hover => 1, 2345 can_hover => 1,
2338 align => 0, 2346 align => 0,
2339 valign => 0, 2347 valign => 0,
2340 can_events => 1, 2348 can_events => 1,
2341 @_ 2349 @_
2359 2367
2360 glEnable GL_TEXTURE_2D; 2368 glEnable GL_TEXTURE_2D;
2361 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2369 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2362 glColor 0, 0, 0, 1; 2370 glColor 0, 0, 0, 1;
2363 2371
2372 my $tex = $tex[$GRAB == $self];
2364 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2373 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2365 2374
2366 glDisable GL_TEXTURE_2D; 2375 glDisable GL_TEXTURE_2D;
2367 2376
2368 $self->SUPER::_draw; 2377 $self->SUPER::_draw;
2369} 2378}
2822 2831
2823 $self->SUPER::invoke_button_down ($ev, $x, $y); 2832 $self->SUPER::invoke_button_down ($ev, $x, $y);
2824 2833
2825 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 2834 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2826 2835
2827 $self->invoke_mouse_motion ($ev, $x, $y) 2836 $self->invoke_mouse_motion ($ev, $x, $y);
2837
2838 1
2828} 2839}
2829 2840
2830sub invoke_mouse_motion { 2841sub invoke_mouse_motion {
2831 my ($self, $ev, $x, $y) = @_; 2842 my ($self, $ev, $x, $y) = @_;
2832 2843
2852 2863
2853 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; 2864 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2;
2854 2865
2855 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); 2866 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
2856 2867
2857 ! ! $delta 2868 1
2858} 2869}
2859 2870
2860sub update { 2871sub update {
2861 my ($self) = @_; 2872 my ($self) = @_;
2862 2873
2993} 3004}
2994 3005
2995sub size_request { 3006sub size_request {
2996 my ($self) = @_; 3007 my ($self) = @_;
2997 3008
2998 my ($empty, $slider) = @{ $self->{children} }; 3009 my ($empty, $slider) = $self->visible_children;
2999 3010
3000 local $self->{children} = [$empty, $slider]; 3011 local $self->{children} = [$empty, $slider];
3001 $self->SUPER::size_request 3012 $self->SUPER::size_request
3002} 3013}
3003 3014
3434 ); 3445 );
3435 3446
3436 if ($self->{anim} && $self->{animspeed}) { 3447 if ($self->{anim} && $self->{animspeed}) {
3437 CFPlus::weaken (my $widget = $self); 3448 CFPlus::weaken (my $widget = $self);
3438 3449
3450 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3451 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed};
3439 $self->{timer} = Event->timer ( 3452 $self->{timer} = Event->timer (
3440 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3441 hard => 1, 3453 parked => 1,
3442 interval => $self->{animspeed},
3443 cb => sub { 3454 cb => sub {
3444 return unless $::CONN; 3455 return unless $::CONN && $widget;
3445 3456
3446 ++$widget->{frame}; 3457 ++$widget->{frame};
3447 $self->update_face; 3458 $widget->update_face;
3448 $self->update; 3459 $widget->update;
3460
3461 $widget->update_timer;
3449 }, 3462 },
3450 ); 3463 );
3451 3464
3452 $self->update_face; 3465 $self->update_face;
3466 $self->update_timer;
3453 } 3467 }
3454 3468
3455 $self 3469 $self
3470}
3471
3472sub update_timer {
3473 my ($self) = @_;
3474
3475 return unless $self->{timer};
3476
3477 if ($self->{visible}) {
3478 $self->{timer}->at (
3479 $self->{anim_start}
3480 + $self->{animspeed}
3481 * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed}
3482 );
3483 $self->{timer}->start;
3484 } else {
3485 $self->{timer}->stop;
3486 }
3456} 3487}
3457 3488
3458sub update_face { 3489sub update_face {
3459 my ($self) = @_; 3490 my ($self) = @_;
3460 3491
3462 3493
3463 if (my $anim = $::CONN->{anim}[$self->{anim}]) { 3494 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3464 if ($anim && @$anim) { 3495 if ($anim && @$anim) {
3465 delete $self->{wait_face}; 3496 delete $self->{wait_face};
3466 $self->{face} = $anim->[ $self->{frame} % @$anim ]; 3497 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3498 $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ];
3467 } 3499 }
3468 } 3500 }
3469} 3501}
3470 3502
3471sub size_request { 3503sub size_request {
3472 my ($self) = @_; 3504 my ($self) = @_;
3473 3505
3474 if ($::CONN) { 3506 if ($::CONN) {
3475 if (my $faceid = $::CONN->{faceid}[$self->{face}]) { 3507 if (my $faceid = $::CONN->{faceid}[$self->{face}]) {
3476 if (my $tex = $::CONN->{texture}[$faceid]) { 3508 if (my $tex = $::CONN->{texture}[$faceid]) {
3509 $self->{tex} = $tex;
3477 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); 3510 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3478 } else { 3511 } else {
3479 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { 3512 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub {
3480 $self->realloc; 3513 $self->realloc;
3481 }); 3514 });
3492 return unless $self->{visible}; 3525 return unless $self->{visible};
3493 3526
3494 $self->SUPER::update; 3527 $self->SUPER::update;
3495} 3528}
3496 3529
3530sub invoke_visibility_change {
3531 my ($self) = @_;
3532
3533 $self->update_timer;
3534
3535 0
3536}
3537
3497sub _draw { 3538sub _draw {
3498 my ($self) = @_; 3539 my ($self) = @_;
3499 3540
3500 return unless $::CONN;
3501
3502 $self->SUPER::_draw; 3541 $self->SUPER::_draw;
3503 3542
3504 my $faceid = $::CONN->{faceid}[$self->{face}] 3543 if (my $tex = $self->{tex}) {
3505 or return;
3506
3507 my $tex = $::CONN->{texture}[$faceid];
3508
3509 if ($tex) {
3510 glEnable GL_TEXTURE_2D; 3544 glEnable GL_TEXTURE_2D;
3511 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 3545 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
3512 glColor 0, 0, 0, 1; 3546 glColor 0, 0, 0, 1;
3513 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 3547 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
3514 glDisable GL_TEXTURE_2D; 3548 glDisable GL_TEXTURE_2D;
3516} 3550}
3517 3551
3518sub destroy { 3552sub destroy {
3519 my ($self) = @_; 3553 my ($self) = @_;
3520 3554
3521 $self->{timer}->cancel 3555 (delete $self->{timer})->cancel
3522 if $self->{timer}; 3556 if $self->{timer};
3523 3557
3524 $self->SUPER::destroy; 3558 $self->SUPER::destroy;
3525} 3559}
3526 3560
3716 ); 3750 );
3717 3751
3718 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3752 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3719 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); 3753 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3720 3754
3755 {
3756 Scalar::Util::weaken (my $wself = $self);
3757
3758 $self->{multiplexer}->connect (c_add => sub {
3759 my ($mplex, $widgets) = @_;
3760
3761 for my $child (@$widgets) {
3762 Scalar::Util::weaken $child;
3763 $child->{c_tab_} ||= do {
3764 my $tab =
3765 (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base")
3766 ? $child->{c_tab}
3767 : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1];
3768
3769 $tab->connect (activate => sub {
3770 $wself->set_current_page ($child);
3771 });
3772
3773 $tab
3774 };
3775
3776 $self->{buttonbar}->add ($child->{c_tab_});
3777 }
3778 });
3779
3780 $self->{multiplexer}->connect (c_remove => sub {
3781 my ($mplex, $widgets) = @_;
3782
3783 for my $child (@$widgets) {
3784 $wself->{buttonbar}->remove ($child->{c_tab_});
3785 }
3786 });
3787 }
3788
3721 $self 3789 $self
3722} 3790}
3723 3791
3724sub add { 3792sub add {
3793 my ($self, @widgets) = @_;
3794
3795 $self->{multiplexer}->add (@widgets)
3796}
3797
3798sub remove {
3799 my ($self, @widgets) = @_;
3800
3801 $self->{multiplexer}->remove (@widgets)
3802}
3803
3804sub add_tab {
3725 my ($self, $title, $widget, $tooltip) = @_; 3805 my ($self, $title, $widget, $tooltip) = @_;
3726 3806
3727 CFPlus::weaken $self; 3807 $title = [$title, $tooltip] unless ref $title;
3808 $widget->{c_tab} = $title;
3728 3809
3729 $self->{buttonbar}->add (new CFPlus::UI::Button
3730 markup => $title,
3731 tooltip => $tooltip,
3732 on_activate => sub { $self->set_current_page ($widget) },
3733 );
3734
3735 $self->{multiplexer}->add ($widget); 3810 $self->add ($widget);
3736} 3811}
3737 3812
3738sub get_current_page { 3813sub get_current_page {
3739 my ($self) = @_; 3814 my ($self) = @_;
3740 3815
4070 while ($self->{refresh_hook}) { 4145 while ($self->{refresh_hook}) {
4071 $_->() 4146 $_->()
4072 for values %{delete $self->{refresh_hook}}; 4147 for values %{delete $self->{refresh_hook}};
4073 } 4148 }
4074 4149
4075 if ($self->{realloc}) { 4150 while ($self->{realloc}) {
4076 my %queue; 4151 my %queue;
4077 my @queue; 4152 my @queue;
4078 my $widget; 4153 my $widget;
4079 4154
4080 outer: 4155 outer:
4127 } 4202 }
4128 } 4203 }
4129 4204
4130 delete $self->{realloc}{$widget+0}; 4205 delete $self->{realloc}{$widget+0};
4131 } 4206 }
4132 }
4133 4207
4134 while (my $size_alloc = delete $self->{size_alloc}) { 4208 while (my $size_alloc = delete $self->{size_alloc}) {
4135 my @queue = sort { $b->{visible} <=> $a->{visible} } 4209 my @queue = sort { $a->{visible} <=> $b->{visible} }
4136 values %$size_alloc; 4210 values %$size_alloc;
4137 4211
4138 while () { 4212 while () {
4139 my $widget = pop @queue || last; 4213 my $widget = pop @queue || last;
4140 4214
4141 my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; 4215 my ($w, $h) = @$widget{qw(alloc_w alloc_h)};
4142 4216
4143 $w = 0 if $w < 0;
4144 $h = 0 if $h < 0;
4145
4146 $w = max $widget->{min_w}, $w; 4217 $w = max $widget->{min_w}, $w;
4147 $h = max $widget->{min_h}, $h; 4218 $h = max $widget->{min_h}, $h;
4148 4219
4149# $w = min $self->{w} - $widget->{x}, $w if $self->{w}; 4220# $w = min $self->{w} - $widget->{x}, $w if $self->{w};
4150# $h = min $self->{h} - $widget->{y}, $h if $self->{h}; 4221# $h = min $self->{h} - $widget->{y}, $h if $self->{h};
4151 4222
4152 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4223 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4153 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4224 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4154 4225
4155 $w = int $w + 0.5; 4226 $w = int $w + 0.5;
4156 $h = int $h + 0.5; 4227 $h = int $h + 0.5;
4157 4228
4158 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { 4229 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) {
4159 $widget->{old_w} = $widget->{w}; 4230 $widget->{old_w} = $widget->{w};
4160 $widget->{old_h} = $widget->{h}; 4231 $widget->{old_h} = $widget->{h};
4161 4232
4162 $widget->{w} = $w; 4233 $widget->{w} = $w;
4163 $widget->{h} = $h; 4234 $widget->{h} = $h;
4164 4235
4165 $widget->emit (size_allocate => $w, $h); 4236 $widget->emit (size_allocate => $w, $h);
4237 }
4166 } 4238 }
4167 } 4239 }
4168 } 4240 }
4169 4241
4170 while ($self->{post_alloc_hook}) { 4242 while ($self->{post_alloc_hook}) {
4171 $_->() 4243 $_->()
4172 for values %{delete $self->{post_alloc_hook}}; 4244 for values %{delete $self->{post_alloc_hook}};
4173 } 4245 }
4174
4175 4246
4176 glViewport 0, 0, $::WIDTH, $::HEIGHT; 4247 glViewport 0, 0, $::WIDTH, $::HEIGHT;
4177 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 4248 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
4178 glClear GL_COLOR_BUFFER_BIT; 4249 glClear GL_COLOR_BUFFER_BIT;
4179 4250

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines