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.400 by root, Sat Jul 21 16:15:03 2007 UTC vs.
Revision 1.445 by root, Sat Dec 8 19:17:02 2007 UTC

2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5 5
6use List::Util (); 6use List::Util ();
7use Event;
8 7
9use CFPlus; 8use CFPlus;
10use CFPlus::Pod; 9use CFPlus::Pod;
11use CFPlus::Texture; 10use CFPlus::Texture;
12 11
17our $TOOLTIP; 16our $TOOLTIP;
18our $BUTTON_STATE; 17our $BUTTON_STATE;
19 18
20our %WIDGET; # all widgets, weak-referenced 19our %WIDGET; # all widgets, weak-referenced
21 20
22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { 21our $TOOLTIP_WATCHER = EV::timer_ns 0, 1/60, sub {
22 $_[0]->stop;
23
23 if (!$GRAB) { 24 if (!$GRAB) {
24 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 25 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
25 if (length $widget->{tooltip}) { 26 if (length $widget->{tooltip}) {
26 if ($TOOLTIP->{owner} != $widget) { 27 if ($TOOLTIP->{owner} != $widget) {
27 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; 28 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
30 $TOOLTIP->{owner} = $widget; 31 $TOOLTIP->{owner} = $widget;
31 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner}; 32 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner};
32 33
33 return if $ENV{CFPLUS_DEBUG} & 8; 34 return if $ENV{CFPLUS_DEBUG} & 8;
34 35
35 my $tip = $widget->{tooltip};
36
37 $tip = $tip->($widget) if CODE:: eq ref $tip;
38
39 $TOOLTIP->set_tooltip_from ($widget); 36 $TOOLTIP->set_tooltip_from ($widget);
40 $TOOLTIP->show; 37 $TOOLTIP->show;
41 } 38 }
42 39
43 return; 40 return;
46 } 43 }
47 44
48 $TOOLTIP->hide; 45 $TOOLTIP->hide;
49 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; 46 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
50 delete $TOOLTIP->{owner}; 47 delete $TOOLTIP->{owner};
51}); 48};
52 49
53sub get_layout { 50sub get_layout {
54 my $layout; 51 my $layout;
55 52
56 for (grep { $_->{name} } values %WIDGET) { 53 for (grep { $_->{name} } values %WIDGET) {
91 my $hover = $HOVER; $HOVER = $widget; 88 my $hover = $HOVER; $HOVER = $widget;
92 89
93 $hover->update if $hover && $hover->{can_hover}; 90 $hover->update if $hover && $hover->{can_hover};
94 $HOVER->update if $HOVER && $HOVER->{can_hover}; 91 $HOVER->update if $HOVER && $HOVER->{can_hover};
95 92
96 $TOOLTIP_WATCHER->start; 93 $TOOLTIP_WATCHER->again;
97 } 94 }
98} 95}
99 96
100sub feed_sdl_button_down_event { 97sub feed_sdl_button_down_event {
101 my ($ev) = @_; 98 my ($ev) = @_;
107 my $widget = $ROOT->find_widget ($x, $y); 104 my $widget = $ROOT->find_widget ($x, $y);
108 105
109 $GRAB = $widget; 106 $GRAB = $widget;
110 $GRAB->update if $GRAB; 107 $GRAB->update if $GRAB;
111 108
112 $TOOLTIP_WATCHER->cb->(); 109 $TOOLTIP_WATCHER->invoke;
113 } 110 }
114 111
115 if ($GRAB) { 112 if ($GRAB) {
116 if ($ev->{button} == 4 || $ev->{button} == 5) { 113 if ($ev->{button} == 4 || $ev->{button} == 5) {
117 # mousewheel 114 # mousewheel
142 my $grab = $GRAB; undef $GRAB; 139 my $grab = $GRAB; undef $GRAB;
143 $grab->update if $grab; 140 $grab->update if $grab;
144 $GRAB->update if $GRAB; 141 $GRAB->update if $GRAB;
145 142
146 check_hover $widget; 143 check_hover $widget;
147 $TOOLTIP_WATCHER->cb->(); 144 $TOOLTIP_WATCHER->invoke;
148 } 145 }
149} 146}
150 147
151sub feed_sdl_motion_event { 148sub feed_sdl_motion_event {
152 my ($ev) = @_; 149 my ($ev) = @_;
273 $self->emit ("destroy"); 270 $self->emit ("destroy");
274 %$self = (); 271 %$self = ();
275} 272}
276 273
277sub TO_JSON { 274sub TO_JSON {
278 { __widget_ref__ => $_[0]{s_id} } 275 { "\fw" => $_[0]{s_id} }
279} 276}
280 277
281sub show { 278sub show {
282 my ($self) = @_; 279 my ($self) = @_;
283 280
312 delete $self->{root}; 309 delete $self->{root};
313 310
314 undef $GRAB if $GRAB == $self; 311 undef $GRAB if $GRAB == $self;
315 undef $HOVER if $HOVER == $self; 312 undef $HOVER if $HOVER == $self;
316 313
317 $CFPlus::UI::TOOLTIP_WATCHER->cb->() 314 $CFPlus::UI::TOOLTIP_WATCHER->invoke
318 if $TOOLTIP->{owner} == $self; 315 if $TOOLTIP->{owner} == $self;
319 316
320 $self->emit ("focus_out"); 317 $self->emit ("focus_out");
321 $self->emit (visibility_change => 0); 318 $self->emit (visibility_change => 0);
322} 319}
362 359
363 $self->{force_w} = $w; 360 $self->{force_w} = $w;
364 $self->{force_h} = $h; 361 $self->{force_h} = $h;
365 362
366 $self->realloc; 363 $self->realloc;
364}
365
366# traverse the widget chain up to find the maximum "physical" size constraints
367sub get_max_wh {
368 my ($self) = @_;
369
370 return $self->{parent}->get_max_wh
371 if $self->{parent};
372
373 ($::WIDTH, $::HEIGHT)
367} 374}
368 375
369sub size_request { 376sub size_request {
370 require Carp; 377 require Carp;
371 Carp::confess "size_request is abstract"; 378 Carp::confess "size_request is abstract";
433 440
434 $self->{tooltip} = $tooltip; 441 $self->{tooltip} = $tooltip;
435 442
436 if ($CFPlus::UI::TOOLTIP->{owner} == $self) { 443 if ($CFPlus::UI::TOOLTIP->{owner} == $self) {
437 delete $CFPlus::UI::TOOLTIP->{owner}; 444 delete $CFPlus::UI::TOOLTIP->{owner};
438 $CFPlus::UI::TOOLTIP_WATCHER->cb->(); 445 $CFPlus::UI::TOOLTIP_WATCHER->invoke;
439 } 446 }
440} 447}
441 448
442# translate global coordinates to local coordinate system 449# translate global coordinates to local coordinate system
443sub coord2local { 450sub coord2local {
593 600
594# using global variables seems a bit hacky, but passing through all drawing 601# using global variables seems a bit hacky, but passing through all drawing
595# functions seems pointless. 602# functions seems pointless.
596our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn 603our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn
597 604
598sub draw { 605#sub draw {
599 my ($self) = @_; 606#CFPlus.xs
600
601 return unless $self->{h} && $self->{w};
602
603 # update screen rectangle
604 local $draw_x = $draw_x + $self->{x};
605 local $draw_y = $draw_y + $self->{y};
606
607 # skip widgets that are entirely outside the drawing area
608 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w)
609 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h);
610
611 glPushMatrix;
612 glTranslate $self->{x}, $self->{y}, 0;
613
614 if ($self == $HOVER && $self->{can_hover}) {
615 glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2;
616 glEnable GL_BLEND;
617 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
618 glBegin GL_QUADS;
619 glVertex 0 , 0;
620 glVertex $self->{w}, 0;
621 glVertex $self->{w}, $self->{h};
622 glVertex 0 , $self->{h};
623 glEnd;
624 glDisable GL_BLEND;
625 }
626
627 if ($ENV{CFPLUS_DEBUG} & 1) {
628 glPushMatrix;
629 glColor 1, 1, 0, 1;
630 glTranslate 0.375, 0.375;
631 glBegin GL_LINE_LOOP;
632 glVertex 0 , 0;
633 glVertex $self->{w} - 1, 0;
634 glVertex $self->{w} - 1, $self->{h} - 1;
635 glVertex 0 , $self->{h} - 1;
636 glEnd;
637 glPopMatrix;
638 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
639 }
640
641 $self->_draw;
642 glPopMatrix;
643}
644 607
645sub _draw { 608sub _draw {
646 my ($self) = @_; 609 my ($self) = @_;
647 610
648 warn "no draw defined for $self\n"; 611 warn "no draw defined for $self\n";
651sub DESTROY { 614sub DESTROY {
652 my ($self) = @_; 615 my ($self) = @_;
653 616
654 return if CFPlus::in_destruct; 617 return if CFPlus::in_destruct;
655 618
619 local $@;
656 eval { $self->destroy }; 620 eval { $self->destroy };
657 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 621 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
658 622
659 delete $WIDGET{$self+0}; 623 delete $WIDGET{$self+0};
660} 624}
668use strict; 632use strict;
669use CFPlus::OpenGL; 633use CFPlus::OpenGL;
670 634
671sub new { 635sub new {
672 my $class = shift; 636 my $class = shift;
673
674 # range [value, low, high, page]
675 637
676 $class->SUPER::new ( 638 $class->SUPER::new (
677 #bg => [0, 0, 0, 0.2], 639 #bg => [0, 0, 0, 0.2],
678 #active_bg => [1, 1, 1, 0.5], 640 #active_bg => [1, 1, 1, 0.5],
679 @_ 641 @_
691 my ($w, $h) = @$self{qw(w h)}; 653 my ($w, $h) = @$self{qw(w h)};
692 654
693 glEnable GL_BLEND; 655 glEnable GL_BLEND;
694 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 656 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
695 glColor_premultiply @$color; 657 glColor_premultiply @$color;
696
697 glBegin GL_QUADS;
698 glVertex 0 , 0;
699 glVertex 0 , $h;
700 glVertex $w, $h; 658 glRect 0, 0, $w, $h;
701 glVertex $w, 0;
702 glEnd;
703
704 glDisable GL_BLEND; 659 glDisable GL_BLEND;
705 } 660 }
706} 661}
707 662
708############################################################################# 663#############################################################################
769 @{$self->{children}}, @widgets 724 @{$self->{children}}, @widgets
770 ]; 725 ];
771 726
772 $self->realloc; 727 $self->realloc;
773 728
729 $self->emit (c_add => \@widgets);
730
774 map $_+0, @widgets 731 map $_+0, @widgets
775} 732}
776 733
777sub children { 734sub children {
778 @{ $_[0]{children} } 735 @{ $_[0]{children} }
779} 736}
780 737
781sub remove { 738sub remove {
782 my ($self, $child) = @_; 739 my ($self, @widgets) = @_;
783 740
741 $self->emit (c_remove => \@widgets);
742
743 for my $child (@widgets) {
784 delete $child->{parent}; 744 delete $child->{parent};
785 $child->hide; 745 $child->hide;
786
787 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 746 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
747 }
788 748
789 $self->realloc; 749 $self->realloc;
790} 750}
791 751
792sub clear { 752sub clear {
820} 780}
821 781
822sub _draw { 782sub _draw {
823 my ($self) = @_; 783 my ($self) = @_;
824 784
825 $_->draw for @{$self->{children}}; 785 $_->draw for $self->visible_children;
826} 786}
827 787
828############################################################################# 788#############################################################################
829 789
830package CFPlus::UI::Bin; 790package CFPlus::UI::Bin;
840} 800}
841 801
842sub add { 802sub add {
843 my ($self, $child) = @_; 803 my ($self, $child) = @_;
844 804
845 $self->SUPER::remove ($_) for @{ $self->{children} }; 805 $self->clear;
846 $self->SUPER::add ($child); 806 $self->SUPER::add ($child);
847} 807}
848 808
849sub remove { 809sub remove {
850 my ($self, $widget) = @_; 810 my ($self, $widget) = @_;
868 828
869 1 829 1
870} 830}
871 831
872############################################################################# 832#############################################################################
873
874# back-buffered drawing area 833# back-buffered drawing area
875 834
876package CFPlus::UI::Window; 835package CFPlus::UI::Window;
877 836
878our @ISA = CFPlus::UI::Bin::; 837our @ISA = CFPlus::UI::Bin::;
992 $self->{view_x} = $x; 951 $self->{view_x} = $x;
993 $self->{view_y} = $y; 952 $self->{view_y} = $y;
994 953
995 $self->emit (changed => $x, $y); 954 $self->emit (changed => $x, $y);
996 $self->update; 955 $self->update;
956 }
957}
958
959sub set_center {
960 my ($self, $x, $y) = @_;
961
962 $self->set_offset ($x - $self->{w} * .5, $y - $self->{h} * .5);
963}
964
965sub make_visible {
966 my ($self, $x, $y, $border) = @_;
967
968 if ( $x < $self->{view_x} + $self->{w} * $border
969 || $x > $self->{view_x} + $self->{w} * (1 - $border)
970 || $y < $self->{view_y} + $self->{h} * $border
971 || $y > $self->{view_y} + $self->{h} * (1 - $border)
972 ) {
973 $self->set_center ($x, $y);
997 } 974 }
998} 975}
999 976
1000# hmm, this does not work for topleft of $self... but we should not ask for that 977# hmm, this does not work for topleft of $self... but we should not ask for that
1001sub coord2local { 978sub coord2local {
1048 my $child = delete $arg{child}; 1025 my $child = delete $arg{child};
1049 1026
1050 my $self; 1027 my $self;
1051 1028
1052 my $hslider = new CFPlus::UI::Slider 1029 my $hslider = new CFPlus::UI::Slider
1053 col => 0, 1030 c_col => 0,
1054 row => 1, 1031 c_row => 1,
1055 vertical => 0, 1032 vertical => 0,
1056 range => [0, 0, 1, 0.01], # HACK fix 1033 range => [0, 0, 1, 0.01], # HACK fix
1057 on_changed => sub { 1034 on_changed => sub {
1058 $self->{hpos} = $_[1]; 1035 $self->{hpos} = $_[1];
1059 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1036 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1060 }, 1037 },
1061 ; 1038 ;
1062 1039
1063 my $vslider = new CFPlus::UI::Slider 1040 my $vslider = new CFPlus::UI::Slider
1064 col => 1, 1041 c_col => 1,
1065 row => 0, 1042 c_row => 0,
1066 vertical => 1, 1043 vertical => 1,
1067 range => [0, 0, 1, 0.01], # HACK fix 1044 range => [0, 0, 1, 0.01], # HACK fix
1068 on_changed => sub { 1045 on_changed => sub {
1069 $self->{vpos} = $_[1]; 1046 $self->{vpos} = $_[1];
1070 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); 1047 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1081 row_expand => [1, 0], 1058 row_expand => [1, 0],
1082 %arg, 1059 %arg,
1083 ); 1060 );
1084 1061
1085 $self->{vp} = new CFPlus::UI::ViewPort 1062 $self->{vp} = new CFPlus::UI::ViewPort
1086 col => 0, 1063 c_col => 0,
1087 row => 0, 1064 c_row => 0,
1088 expand => 1, 1065 expand => 1,
1089 scroll_x => $self->{scroll_x}, 1066 scroll_x => $self->{scroll_x},
1090 scroll_y => $self->{scroll_y}, 1067 scroll_y => $self->{scroll_y},
1091 on_changed => sub { 1068 on_changed => sub {
1092 my ($vp, $x, $y) = @_; 1069 my ($vp, $x, $y) = @_;
1094 $vp->{parent}{hslider}->set_value ($x); 1071 $vp->{parent}{hslider}->set_value ($x);
1095 $vp->{parent}{vslider}->set_value ($y); 1072 $vp->{parent}{vslider}->set_value ($y);
1096 1073
1097 0 1074 0
1098 }, 1075 },
1076 on_size_allocate => sub {
1077 my ($vp, $w, $h) = @_;
1078 $vp->{parent}->update_slider;
1079 0
1080 },
1099 ; 1081 ;
1100 1082
1101 $self->SUPER::add ($self->{vp}); 1083 $self->SUPER::add ($self->{vp});
1102 1084
1103 $self->add ($child) if $child; 1085 $self->add ($child) if $child;
1109 my ($self, $widget) = @_; 1091 my ($self, $widget) = @_;
1110 1092
1111 $self->{vp}->add ($self->{child} = $widget); 1093 $self->{vp}->add ($self->{child} = $widget);
1112} 1094}
1113 1095
1096sub set_offset { shift->{vp}->set_offset (@_) }
1097sub set_center { shift->{vp}->set_center (@_) }
1098sub make_visible { shift->{vp}->make_visible (@_) }
1099
1114sub update_slider { 1100sub update_slider {
1115 my ($self) = @_; 1101 my ($self) = @_;
1116 1102
1117 my $child = ($self->{vp} or return)->child; 1103 my $child = ($self->{vp} or return)->child;
1118 1104
1105 if ($self->{scroll_x}) {
1119 my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); 1106 my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w});
1120 $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); 1107 $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]);
1121 1108
1122 my $visible = $w1 > $w2; 1109 my $visible = $w1 > $w2;
1123 if ($visible != $self->{hslider_visible}) { 1110 if ($visible != $self->{hslider_visible}) {
1124 $self->{hslider_visible} = $visible; 1111 $self->{hslider_visible} = $visible;
1125 $visible ? $self->SUPER::add ($self->{hslider}) 1112 $visible ? $self->SUPER::add ($self->{hslider})
1126 : $self->SUPER::remove ($self->{hslider}); 1113 : $self->SUPER::remove ($self->{hslider});
1114 }
1127 } 1115 }
1128 1116
1117 if ($self->{scroll_y}) {
1129 my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); 1118 my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h});
1130 $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); 1119 $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]);
1131 1120
1132 my $visible = $h1 > $h2; 1121 my $visible = $h1 > $h2;
1133 if ($visible != $self->{vslider_visible}) { 1122 if ($visible != $self->{vslider_visible}) {
1134 $self->{vslider_visible} = $visible; 1123 $self->{vslider_visible} = $visible;
1135 $visible ? $self->SUPER::add ($self->{vslider}) 1124 $visible ? $self->SUPER::add ($self->{vslider})
1136 : $self->SUPER::remove ($self->{vslider}); 1125 : $self->SUPER::remove ($self->{vslider});
1126 }
1137 } 1127 }
1138} 1128}
1139 1129
1140sub start_dragging { 1130sub start_dragging {
1141 my ($self, $ev) = @_; 1131 my ($self, $ev) = @_;
1227 my ($w, $h) = @$self{qw(w h)}; 1217 my ($w, $h) = @$self{qw(w h)};
1228 1218
1229 glEnable GL_BLEND; 1219 glEnable GL_BLEND;
1230 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 1220 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
1231 glColor_premultiply @{ $self->{bg} }; 1221 glColor_premultiply @{ $self->{bg} };
1232
1233 glBegin GL_QUADS;
1234 glVertex 0 , 0;
1235 glVertex 0 , $h;
1236 glVertex $w, $h; 1222 glRect 0, 0, $w, $h;
1237 glVertex $w, 0;
1238 glEnd;
1239
1240 glDisable GL_BLEND; 1223 glDisable GL_BLEND;
1241 } 1224 }
1242 1225
1243 $self->SUPER::_draw; 1226 $self->SUPER::_draw;
1244} 1227}
1405 1388
1406sub border { 1389sub border {
1407 int $_[0]{border} * $::FONTSIZE 1390 int $_[0]{border} * $::FONTSIZE
1408} 1391}
1409 1392
1393sub get_max_wh {
1394 my ($self) = @_;
1395
1396 return ($self->{w}, $self->{h})
1397 if $self->{visible} && $self->{w};
1398
1399 $self->SUPER::get_max_wh
1400}
1401
1410sub size_request { 1402sub size_request {
1411 my ($self) = @_; 1403 my ($self) = @_;
1412 1404
1413 $self->{title_widget}->size_request 1405 $self->{title_widget}->size_request
1414 if $self->{title_widget}; 1406 if $self->{title_widget};
1606 1598
1607sub add { 1599sub add {
1608 my ($self, @widgets) = @_; 1600 my ($self, @widgets) = @_;
1609 1601
1610 for my $child (@widgets) { 1602 for my $child (@widgets) {
1611 $child->{rowspan} ||= 1; 1603 $child->{c_rowspan} ||= 1;
1612 $child->{colspan} ||= 1; 1604 $child->{c_colspan} ||= 1;
1613 } 1605 }
1614 1606
1615 $self->SUPER::add (@widgets); 1607 $self->SUPER::add (@widgets);
1616} 1608}
1617 1609
1621 my @widgets; 1613 my @widgets;
1622 1614
1623 while (@_) { 1615 while (@_) {
1624 my ($col, $row, $child) = splice @_, 0, 3, (); 1616 my ($col, $row, $child) = splice @_, 0, 3, ();
1625 1617
1626 $child->{row} = $row; 1618 $child->{c_row} = $row;
1627 $child->{col} = $col; 1619 $child->{c_col} = $col;
1628 1620
1629 push @widgets, $child; 1621 push @widgets, $child;
1630 } 1622 }
1631 1623
1632 $self->add (@widgets); 1624 $self->add (@widgets);
1638 my (@w, @h); 1630 my (@w, @h);
1639 1631
1640 my @children = $self->children; 1632 my @children = $self->children;
1641 1633
1642 # first pass, columns 1634 # first pass, columns
1643 for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { 1635 for my $widget (sort { $a->{c_colspan} <=> $b->{c_colspan} } @children) {
1644 my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; 1636 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)};
1645 1637
1646 my $sw = sum @w[$c .. $c + $cs - 1]; 1638 my $sw = sum @w[$c .. $c + $cs - 1];
1647 1639
1648 if ($w > $sw) { 1640 if ($w > $sw) {
1649 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; 1641 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1];
1650 } 1642 }
1651 } 1643 }
1652 1644
1653 # second pass, rows 1645 # second pass, rows
1654 for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { 1646 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) {
1655 my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; 1647 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)};
1656 1648
1657 my $sh = sum @h[$r .. $r + $rs - 1]; 1649 my $sh = sum @h[$r .. $r + $rs - 1];
1658 1650
1659 if ($h > $sh) { 1651 if ($h > $sh) {
1660 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; 1652 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1];
1702 1694
1703 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } 1695 my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] }
1704 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } 1696 my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] }
1705 1697
1706 for my $widget ($self->children) { 1698 for my $widget ($self->children) {
1707 my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; 1699 my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(c_row c_col req_w req_h c_rowspan c_colspan)};
1708 1700
1709 $widget->configure ( 1701 $widget->configure (
1710 $x[$c], $y[$r], 1702 $x[$c], $y[$r],
1711 $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], 1703 $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r],
1712 ); 1704 );
1721 1713
1722use List::Util qw(min max); 1714use List::Util qw(min max);
1723 1715
1724our @ISA = CFPlus::UI::Container::; 1716our @ISA = CFPlus::UI::Container::;
1725 1717
1726sub add {
1727 my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_;
1728
1729 $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h];
1730 $self->SUPER::add ($child);
1731}
1732
1733sub _scale($$$) { 1718sub _scale($$$) {
1734 my ($mode, $val, $max) = @_; 1719 my ($rel, $val, $max) = @_;
1735 1720
1736 $mode eq "abs" ? $val 1721 $rel ? $val * $max : $val
1737 : $mode eq "rel" ? $val * $max
1738 : 0
1739} 1722}
1740 1723
1741sub size_request { 1724sub size_request {
1742 my ($self) = @_; 1725 my ($self) = @_;
1743 1726
1744 my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); 1727 my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0);
1745 1728
1746 # determine overall size by querying abs widgets 1729 # determine overall size by querying abs widgets
1747 for my $child ($self->visible_children) { 1730 for my $child ($self->visible_children) {
1748 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1731 unless ($child->{c_rel}) {
1732 my $x = $child->{c_x};
1733 my $y = $child->{c_y};
1749 1734
1750 if ($pos eq "abs") {
1751 $w = _scale $size, $w, $child->{req_w};
1752 $h = _scale $size, $h, $child->{req_h};
1753
1754 $x1 = min $x1, $x; $x2 = max $x2, $x + $w; 1735 $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w};
1755 $y1 = min $y1, $y; $y2 = max $y2, $y + $h; 1736 $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h};
1756 } 1737 }
1757 } 1738 }
1758 1739
1759 my $W = $x2 - $x1; 1740 my $W = $x2 - $x1;
1760 my $H = $y2 - $y1; 1741 my $H = $y2 - $y1;
1761 1742
1762 # now layout remaining widgets 1743 # now layout remaining widgets
1763 for my $child ($self->visible_children) { 1744 for my $child ($self->visible_children) {
1764 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1745 if ($child->{c_rel}) {
1746 my $x = _scale $child->{c_rel}, $child->{c_x}, $W;
1747 my $y = _scale $child->{c_rel}, $child->{c_y}, $H;
1765 1748
1766 if ($pos ne "abs") {
1767 $x = _scale $pos, $x, $W;
1768 $y = _scale $pos, $x, $H;
1769 $w = _scale $size, $w, $child->{req_w};
1770 $h = _scale $size, $h, $child->{req_h};
1771
1772 $x1 = min $x1, $x; $x2 = max $x2, $x + $w; 1749 $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w};
1773 $y1 = min $y1, $y; $y2 = max $y2, $y + $h; 1750 $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h};
1774 } 1751 }
1775 } 1752 }
1776 1753
1777 my $W = $x2 - $x1; 1754 my $W = $x2 - $x1;
1778 my $H = $y2 - $y1; 1755 my $H = $y2 - $y1;
1782 1759
1783sub invoke_size_allocate { 1760sub invoke_size_allocate {
1784 my ($self, $W, $H) = @_; 1761 my ($self, $W, $H) = @_;
1785 1762
1786 for my $child ($self->visible_children) { 1763 for my $child ($self->visible_children) {
1787 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1764 my $x = _scale $child->{c_rel}, $child->{c_x}, $W;
1765 my $y = _scale $child->{c_rel}, $child->{c_y}, $H;
1788 1766
1789 $x = _scale $pos, $x, $W; 1767 $x += $child->{c_halign} * $child->{req_w};
1790 $y = _scale $pos, $x, $H; 1768 $y += $child->{c_valign} * $child->{req_h};
1791 $w = _scale $size, $w, $child->{req_w};
1792 $h = _scale $size, $h, $child->{req_h};
1793 1769
1794 $child->configure ($x, $y, $w, $h); 1770 $child->configure (int $x, int $y, $child->{req_w}, $child->{req_h});
1795 } 1771 }
1796 1772
1797 1 1773 1
1798} 1774}
1799 1775
1803 1779
1804our @ISA = CFPlus::UI::Container::; 1780our @ISA = CFPlus::UI::Container::;
1805 1781
1806sub size_request { 1782sub size_request {
1807 my ($self) = @_; 1783 my ($self) = @_;
1784
1785 my @children = $self->visible_children;
1808 1786
1809 $self->{vertical} 1787 $self->{vertical}
1810 ? ( 1788 ? (
1811 (List::Util::max map $_->{req_w}, @{$self->{children}}), 1789 (List::Util::max map $_->{req_w}, @children),
1812 (List::Util::sum map $_->{req_h}, @{$self->{children}}), 1790 (List::Util::sum map $_->{req_h}, @children),
1813 ) 1791 )
1814 : ( 1792 : (
1815 (List::Util::sum map $_->{req_w}, @{$self->{children}}), 1793 (List::Util::sum map $_->{req_w}, @children),
1816 (List::Util::max map $_->{req_h}, @{$self->{children}}), 1794 (List::Util::max map $_->{req_h}, @children),
1817 ) 1795 )
1818} 1796}
1819 1797
1820sub invoke_size_allocate { 1798sub invoke_size_allocate {
1821 my ($self, $w, $h) = @_; 1799 my ($self, $w, $h) = @_;
1945 1923
1946 delete $self->{ox}; 1924 delete $self->{ox};
1947 $self->SUPER::realloc; 1925 $self->SUPER::realloc;
1948} 1926}
1949 1927
1928sub clear {
1929 my ($self) = @_;
1930
1931 $self->set_text ("");
1932}
1933
1950sub set_text { 1934sub set_text {
1951 my ($self, $text) = @_; 1935 my ($self, $text) = @_;
1952 1936
1953 return if $self->{text} eq "T$text"; 1937 return if $self->{text} eq "T$text";
1954 $self->{text} = "T$text"; 1938 $self->{text} = "T$text";
1977 1961
1978sub size_request { 1962sub size_request {
1979 my ($self) = @_; 1963 my ($self) = @_;
1980 1964
1981 $self->{size_req} ||= do { 1965 $self->{size_req} ||= do {
1966 my ($max_w, $max_h) = $self->get_max_wh;
1967
1982 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1968 $self->{layout}->set_font ($self->{font}) if $self->{font};
1983 $self->{layout}->set_width ($self->{max_w} || -1); 1969 $self->{layout}->set_width ($self->{max_w} || $max_w || -1);
1984 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1970 $self->{layout}->set_ellipsise ($self->{ellipsise});
1985 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1971 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1986 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1972 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1987 1973
1988 my ($w, $h) = $self->{layout}->size; 1974 my ($w, $h) = $self->{layout}->size;
2060 : ($self->{w} - $size->[0]) * 0.5); 2046 : ($self->{w} - $size->[0]) * 0.5);
2061 2047
2062 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 2048 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2063 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} 2049 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2064 : ($self->{h} - $size->[1]) * 0.5); 2050 : ($self->{h} - $size->[1]) * 0.5);
2051
2052 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2065 }; 2053 };
2066 2054
2067 my $w = List::Util::min $self->{w} + 4, $size->[0]; 2055# unless ($self->{list}) {
2068 my $h = List::Util::min $self->{h} + 2, $size->[1]; 2056# $self->{list} = CFPlus::OpenGL::glGenList;
2069 2057# CFPlus::OpenGL::glNewList $self->{list};
2070 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2058# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2059# CFPlus::OpenGL::glEndList;
2060# }
2061#
2062# CFPlus::OpenGL::glCallList $self->{list};
2063
2064 $self->{layout}->draw;
2071} 2065}
2066
2067#sub destroy {
2068# my ($self) = @_;
2069#
2070# CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list};
2071#
2072# $self->SUPER::destroy;
2073#}
2072 2074
2073############################################################################# 2075#############################################################################
2074 2076
2075package CFPlus::UI::EntryBase; 2077package CFPlus::UI::EntryBase;
2076 2078
2082 my $class = shift; 2084 my $class = shift;
2083 2085
2084 $class->SUPER::new ( 2086 $class->SUPER::new (
2085 fg => [1, 1, 1], 2087 fg => [1, 1, 1],
2086 bg => [0, 0, 0, 0.2], 2088 bg => [0, 0, 0, 0.2],
2089 outline => [0.6, 0.3, 0.1],
2087 active_bg => [1, 1, 1, 0.5], 2090 active_bg => [0, 0, 1, .2],
2088 active_fg => [0, 0, 0], 2091 active_fg => [1, 1, 1],
2092 active_outline => [1, 1, 0],
2089 can_hover => 1, 2093 can_hover => 1,
2090 can_focus => 1, 2094 can_focus => 1,
2091 valign => 0, 2095 valign => 0,
2092 can_events => 1, 2096 can_events => 1,
2093 ellipsise => 0, 2097 ellipsise => 0,
2233 glColor_premultiply @{$self->{bg}}; 2237 glColor_premultiply @{$self->{bg}};
2234 } 2238 }
2235 2239
2236 glEnable GL_BLEND; 2240 glEnable GL_BLEND;
2237 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2241 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2238 glBegin GL_QUADS;
2239 glVertex 0 , 0;
2240 glVertex 0 , $self->{h};
2241 glVertex $self->{w}, $self->{h}; 2242 glRect 0, 0, $self->{w}, $self->{h};
2242 glVertex $self->{w}, 0;
2243 glEnd;
2244 glDisable GL_BLEND; 2243 glDisable GL_BLEND;
2245 2244
2246 $self->SUPER::_draw; 2245 $self->SUPER::_draw;
2247 2246
2248 #TODO: force update every cursor change :( 2247 #TODO: force update every cursor change :(
2250 2249
2251 unless (exists $self->{cur_h}) { 2250 unless (exists $self->{cur_h}) {
2252 my $text = substr $self->{text}, 0, $self->{cursor}; 2251 my $text = substr $self->{text}, 0, $self->{cursor};
2253 utf8::encode $text; 2252 utf8::encode $text;
2254 2253
2255 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) 2254 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
2256 } 2255 }
2257 2256
2257 glColor_premultiply @{$self->{active_fg}};
2258 glBegin GL_LINES; 2258 glBegin GL_LINES;
2259 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; 2259 glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy};
2260 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; 2260 glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h};
2261 glEnd;
2262
2263 glLineWidth 3;
2264 glColor @{$self->{active_outline}};
2265 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2266 glLineWidth 1;
2267
2268 } else {
2269 glColor @{$self->{outline}};
2270 glBegin GL_LINE_STRIP;
2271 glVertex .5, $self->{h} * .5;
2272 glVertex .5, $self->{h} - 2.5;
2273 glVertex $self->{w} - .5, $self->{h} - 2.5;
2274 glVertex $self->{w} - .5, $self->{h} * .5;
2261 glEnd; 2275 glEnd;
2262 } 2276 }
2263} 2277}
2264 2278
2265############################################################################# 2279#############################################################################
2352 1 2366 1
2353} 2367}
2354 2368
2355############################################################################# 2369#############################################################################
2356 2370
2371package CFPlus::UI::ButtonBin;
2372
2373our @ISA = CFPlus::UI::Bin::;
2374
2375use CFPlus::OpenGL;
2376
2377my @tex =
2378 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2379 qw(b1_button_inactive.png b1_button_active.png);
2380
2381sub new {
2382 my $class = shift;
2383
2384 $class->SUPER::new (
2385 can_hover => 1,
2386 align => 0,
2387 valign => 0,
2388 can_events => 1,
2389 @_
2390 )
2391}
2392
2393sub invoke_button_up {
2394 my ($self, $ev, $x, $y) = @_;
2395
2396 $self->emit ("activate")
2397 if $x >= 0 && $x < $self->{w}
2398 && $y >= 0 && $y < $self->{h};
2399
2400 1
2401}
2402
2403sub _draw {
2404 my ($self) = @_;
2405
2406 glEnable GL_TEXTURE_2D;
2407 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2408 glColor 0, 0, 0, 1;
2409
2410 my $tex = $tex[$GRAB == $self];
2411 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2412
2413 glDisable GL_TEXTURE_2D;
2414
2415 $self->SUPER::_draw;
2416}
2417
2418#############################################################################
2419
2357package CFPlus::UI::Button; 2420package CFPlus::UI::Button;
2358 2421
2359our @ISA = CFPlus::UI::Label::; 2422our @ISA = CFPlus::UI::Label::;
2360 2423
2361use CFPlus::OpenGL; 2424use CFPlus::OpenGL;
2465sub _draw { 2528sub _draw {
2466 my ($self) = @_; 2529 my ($self) = @_;
2467 2530
2468 $self->SUPER::_draw; 2531 $self->SUPER::_draw;
2469 2532
2470 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; 2533 glTranslate $self->{padding_x}, $self->{padding_y}, 0;
2471 2534
2472 my ($w, $h) = @$self{qw(w h)}; 2535 my ($w, $h) = @$self{qw(w h)};
2473 2536
2474 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; 2537 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2475 2538
2495sub new { 2558sub new {
2496 my $class = shift; 2559 my $class = shift;
2497 2560
2498 my $self = $class->SUPER::new ( 2561 my $self = $class->SUPER::new (
2499 can_events => 0, 2562 can_events => 0,
2563 scale => 1,
2500 @_, 2564 @_,
2501 ); 2565 );
2502 2566
2503 $self->{path} || $self->{tex} 2567 $self->{path} || $self->{tex}
2504 or Carp::croak "'path' or 'tex' attributes required"; 2568 or Carp::croak "'path' or 'tex' attributes required";
2529} 2593}
2530 2594
2531sub size_request { 2595sub size_request {
2532 my ($self) = @_; 2596 my ($self) = @_;
2533 2597
2534 ($self->{tex}{w}, $self->{tex}{h}) 2598 (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale})
2535} 2599}
2536 2600
2537sub _draw { 2601sub _draw {
2538 my ($self) = @_; 2602 my ($self) = @_;
2539 2603
2549 } 2613 }
2550 2614
2551 glEnable GL_TEXTURE_2D; 2615 glEnable GL_TEXTURE_2D;
2552 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2616 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2553 2617
2554 $tex->draw_quad (0, 0, $w, $h); 2618 $tex->draw_quad_alpha (0, 0, $w, $h);
2555 2619
2556 glDisable GL_TEXTURE_2D; 2620 glDisable GL_TEXTURE_2D;
2557} 2621}
2558 2622
2559############################################################################# 2623#############################################################################
2578 align => 0, 2642 align => 0,
2579 valign => 0, 2643 valign => 0,
2580 can_events => 1, 2644 can_events => 1,
2581 @_ 2645 @_
2582 ); 2646 );
2647}
2648
2649sub invoke_button_down {
2650 my ($self, $ev, $x, $y) = @_;
2651
2652 1
2583} 2653}
2584 2654
2585sub invoke_button_up { 2655sub invoke_button_up {
2586 my ($self, $ev, $x, $y) = @_; 2656 my ($self, $ev, $x, $y) = @_;
2587 2657
2727 glDisable GL_TEXTURE_2D; 2797 glDisable GL_TEXTURE_2D;
2728} 2798}
2729 2799
2730############################################################################# 2800#############################################################################
2731 2801
2802package CFPlus::UI::Progress;
2803
2804our @ISA = CFPlus::UI::Label::;
2805
2806use CFPlus::OpenGL;
2807
2808sub new {
2809 my ($class, %arg) = @_;
2810
2811 my $self = $class->SUPER::new (
2812 fg => [1, 1, 1],
2813 bg => [0, 0, 1, 0.2],
2814 bar => [0.7, 0.5, 0.1, 0.8],
2815 outline => [0.4, 0.3, 0],
2816 fontsize => 0.9,
2817 valign => 0,
2818 align => 0,
2819 can_events => 1,
2820 ellipsise => 1,
2821 label => "%d%%",
2822 %arg,
2823 );
2824
2825 $self->set_value ($arg{value} || -1);
2826
2827 $self
2828}
2829
2830sub set_label {
2831 my ($self, $label) = @_;
2832
2833 return if $self->{label} eq $label;
2834 $self->{label} = $label;
2835
2836 $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value});
2837}
2838
2839sub set_value {
2840 my ($self, $value) = @_;
2841
2842 if ($self->{value} ne $value) {
2843 $self->{value} = $value;
2844
2845 if ($value < 0) {
2846 $self->set_text ("-");
2847 } else {
2848 $self->set_text (sprintf $self->{label}, $value * 100);
2849 }
2850
2851 $self->update;
2852 }
2853}
2854
2855sub _draw {
2856 my ($self) = @_;
2857
2858 glEnable GL_BLEND;
2859 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2860
2861 if ($self->{value} >= 0) {
2862 my $s = int 2 + ($self->{w} - 4) * $self->{value};
2863
2864 glColor_premultiply @{$self->{bar}};
2865 glRect 2, 2, $s, $self->{h} - 2;
2866 glColor_premultiply @{$self->{bg}};
2867 glRect $s, 2, $self->{w} - 2, $self->{h} - 2;
2868 }
2869
2870 glColor_premultiply @{$self->{outline}};
2871 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2872
2873 glDisable GL_BLEND;
2874
2875 {
2876 local $self->{bg}; # do not draw background
2877 $self->SUPER::_draw;
2878 }
2879}
2880
2881#############################################################################
2882
2883package CFPlus::UI::ExperienceProgress;
2884
2885our @ISA = CFPlus::UI::Progress::;
2886
2887sub new {
2888 my ($class, %arg) = @_;
2889
2890 my $self = $class->SUPER::new (
2891 tooltip => sub {
2892 my ($self) = @_;
2893
2894 sprintf "level %d\n%s points\n%s next level\n%s to go",
2895 $self->{lvl},
2896 ::formsep ($self->{exp}),
2897 ::formsep ($self->{nxt}),
2898 ::formsep ($self->{nxt} - $self->{exp}),
2899 },
2900 %arg
2901 );
2902
2903 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2904 if $::CONN;
2905
2906 $self
2907}
2908
2909sub DESTROY {
2910 my ($self) = @_;
2911
2912 delete $::CONN->{on_exp_update}{$self+0}
2913 if $::CONN;
2914
2915 $self->SUPER::DESTROY;
2916}
2917
2918sub set_value {
2919 my ($self, $lvl, $exp) = @_;
2920
2921 $self->{lvl} = $lvl;
2922 $self->{exp} = $exp;
2923
2924 my $v = -1;
2925
2926 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2927 my $l0 = $table->[$lvl - 1];
2928 my $l1 = $table->[$lvl];
2929
2930 $self->{nxt} = $l1;
2931
2932 $v = ($exp - $l0) / ($l1 - $l0);
2933 }
2934
2935 $self->SUPER::set_value ($v);
2936}
2937
2938#############################################################################
2939
2732package CFPlus::UI::Gauge; 2940package CFPlus::UI::Gauge;
2733 2941
2734our @ISA = CFPlus::UI::VBox::; 2942our @ISA = CFPlus::UI::VBox::;
2735 2943
2736sub new { 2944sub new {
2861 3069
2862 $self->SUPER::invoke_button_down ($ev, $x, $y); 3070 $self->SUPER::invoke_button_down ($ev, $x, $y);
2863 3071
2864 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 3072 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2865 3073
2866 $self->invoke_mouse_motion ($ev, $x, $y) 3074 $self->invoke_mouse_motion ($ev, $x, $y);
3075
3076 1
2867} 3077}
2868 3078
2869sub invoke_mouse_motion { 3079sub invoke_mouse_motion {
2870 my ($self, $ev, $x, $y) = @_; 3080 my ($self, $ev, $x, $y) = @_;
2871 3081
2891 3101
2892 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; 3102 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2;
2893 3103
2894 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); 3104 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
2895 3105
2896 ! ! $delta 3106 1
2897} 3107}
2898 3108
2899sub update { 3109sub update {
2900 my ($self) = @_; 3110 my ($self) = @_;
2901 3111
3032} 3242}
3033 3243
3034sub size_request { 3244sub size_request {
3035 my ($self) = @_; 3245 my ($self) = @_;
3036 3246
3037 my ($empty, $slider) = @{ $self->{children} }; 3247 my ($empty, $slider) = $self->visible_children;
3038 3248
3039 local $self->{children} = [$empty, $slider]; 3249 local $self->{children} = [$empty, $slider];
3040 $self->SUPER::size_request 3250 $self->SUPER::size_request
3041} 3251}
3042 3252
3231 3441
3232 if ($y0 < $y + $h && $y < $y1) { 3442 if ($y0 < $y + $h && $y < $y1) {
3233 my $layout = $self->get_layout ($para); 3443 my $layout = $self->get_layout ($para);
3234 3444
3235 $layout->render ($para->{indent}, $y - $y0); 3445 $layout->render ($para->{indent}, $y - $y0);
3446 $layout->draw;
3236 3447
3237 if (my @w = @{ $para->{widget} }) { 3448 if (my @w = @{ $para->{widget} }) {
3238 my @s = $layout->get_shapes; 3449 my @s = $layout->get_shapes;
3239 3450
3240 for (@w) { 3451 for (@w) {
3362} 3573}
3363 3574
3364sub set_tooltip_from { 3575sub set_tooltip_from {
3365 my ($self, $widget) = @_; 3576 my ($self, $widget) = @_;
3366 3577
3367 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3368 if $widget->{tooltip} =~ /^#(.*)$/;
3369
3370 my $tooltip = $widget->{tooltip}; 3578 my $tip = $widget->{tooltip};
3579 $tip = $tip->($widget) if "CODE" eq ref $tip;
3580
3581 $tip = CFPlus::Pod::section_label tooltip => $1
3582 if $tip =~ /^#(.*)$/;
3371 3583
3372 if ($ENV{CFPLUS_DEBUG} & 2) { 3584 if ($ENV{CFPLUS_DEBUG} & 2) {
3373 $tooltip .= "\n\n" . (ref $widget) . "\n" 3585 $tip .= "\n\n" . (ref $widget) . "\n"
3374 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3586 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3375 . "req $widget->{req_w} $widget->{req_h}\n" 3587 . "req $widget->{req_w} $widget->{req_h}\n"
3376 . "visible $widget->{visible}"; 3588 . "visible $widget->{visible}";
3377 } 3589 }
3378 3590
3379 $tooltip =~ s/^\n+//; 3591 $tip =~ s/^\n+//;
3380 $tooltip =~ s/\n+$//; 3592 $tip =~ s/\n+$//;
3381 3593
3382 $self->add (new CFPlus::UI::Label 3594 $self->add (new CFPlus::UI::Label
3383 markup => $tooltip, 3595 markup => $tip,
3384 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3596 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3385 fontsize => 0.8, 3597 fontsize => 0.8,
3386 style => 1, # FLAG_INVERSE 3598 style => 1, # FLAG_INVERSE
3387 ellipsise => 0, 3599 ellipsise => 0,
3388 font => ($widget->{tooltip_font} || $::FONT_PROP), 3600 font => ($widget->{tooltip_font} || $::FONT_PROP),
3426} 3638}
3427 3639
3428sub _draw { 3640sub _draw {
3429 my ($self) = @_; 3641 my ($self) = @_;
3430 3642
3431 glTranslate 0.375, 0.375;
3432
3433 my ($w, $h) = @$self{qw(w h)}; 3643 my ($w, $h) = @$self{qw(w h)};
3434 3644
3435 glColor 1, 0.8, 0.4; 3645 glColor 1, 0.8, 0.4;
3436 glBegin GL_QUADS; 3646 glRect 0, 0, $w, $h;
3437 glVertex 0 , 0;
3438 glVertex 0 , $h;
3439 glVertex $w, $h;
3440 glVertex $w, 0;
3441 glEnd;
3442 3647
3443 glColor 0, 0, 0; 3648 glColor 0, 0, 0;
3444 glBegin GL_LINE_LOOP; 3649 glRect_lineloop .5, .5, $w + .5, $h + .5;
3445 glVertex 0 , 0;
3446 glVertex 0 , $h;
3447 glVertex $w, $h;
3448 glVertex $w, 0;
3449 glEnd;
3450 3650
3451 glTranslate 2 - 0.375, 2 - 0.375; 3651 glTranslate 2, 2;
3452 3652
3453 $self->SUPER::_draw; 3653 $self->SUPER::_draw;
3454} 3654}
3455 3655
3456############################################################################# 3656#############################################################################
3474 3674
3475 if ($self->{anim} && $self->{animspeed}) { 3675 if ($self->{anim} && $self->{animspeed}) {
3476 CFPlus::weaken (my $widget = $self); 3676 CFPlus::weaken (my $widget = $self);
3477 3677
3478 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3678 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3479 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; 3679 $widget->{anim_start} = $self->{animspeed} * int EV::now / $self->{animspeed};
3480 $self->{timer} = Event->timer ( 3680 $self->{timer} = EV::timer_ns 0, 0, sub {
3481 parked => 1,
3482 cb => sub {
3483 return unless $::CONN && $widget; 3681 return unless $::CONN;
3484 3682
3683 my $w = $widget
3684 or return;
3685
3485 ++$widget->{frame}; 3686 ++$w->{frame};
3486 $widget->update_face; 3687 $w->update_face;
3688
3689 # somehow, $widget can go away
3487 $widget->update; 3690 $w->update;
3488
3489 $widget->update_timer; 3691 $w->update_timer;
3490 },
3491 ); 3692 };
3492 3693
3493 $self->update_face; 3694 $self->update_face;
3494 $self->update_timer; 3695 $self->update_timer;
3495 } 3696 }
3496 3697
3501 my ($self) = @_; 3702 my ($self) = @_;
3502 3703
3503 return unless $self->{timer}; 3704 return unless $self->{timer};
3504 3705
3505 if ($self->{visible}) { 3706 if ($self->{visible}) {
3506 $self->{timer}->at ( 3707 $self->{timer}->set (
3507 $self->{anim_start} 3708 $self->{anim_start}
3508 + $self->{animspeed} 3709 + $self->{animspeed}
3509 * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed} 3710 * int 1.5 + (EV::now - $self->{anim_start}) / $self->{animspeed}
3510 ); 3711 );
3511 $self->{timer}->start; 3712 $self->{timer}->start;
3512 } else { 3713 } else {
3513 $self->{timer}->stop; 3714 $self->{timer}->stop;
3514 } 3715 }
3515} 3716}
3516 3717
3517sub update_face { 3718sub update_face {
3518 my ($self) = @_; 3719 my ($self) = @_;
3519 3720
3520 return unless $::CONN;
3521
3522 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3523 if ($anim && @$anim) {
3524 delete $self->{wait_face};
3525 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3526 }
3527 }
3528}
3529
3530sub size_request {
3531 my ($self) = @_;
3532
3533 if ($::CONN) { 3721 if ($::CONN) {
3534 if (my $faceid = $::CONN->{faceid}[$self->{face}]) { 3722 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3535 if (my $tex = $::CONN->{texture}[$faceid]) { 3723 if ($anim && @$anim) {
3536 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); 3724 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3537 } else { 3725 delete $self->{face_change_cb};
3538 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { 3726
3539 $self->realloc; 3727 if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) {
3728 unless ($tex->{name} || $tex->{loading}) {
3729 $tex->upload (sub { $self->reconfigure });
3730 }
3540 }); 3731 }
3541 } 3732 }
3542 } 3733 }
3543 } 3734 }
3735}
3736
3737sub size_request {
3738 my ($self) = @_;
3739
3740 if ($::CONN) {
3741 if (my $faceid = $::CONN->{face}[$self->{face}]{id}) {
3742 if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) {
3743 if ($tex->{name}) {
3744 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3745 } elsif (!$tex->{loading}) {
3746 $tex->upload (sub { $self->reconfigure });
3747 }
3748 }
3749
3750 $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure });
3751 }
3752 }
3544 3753
3545 ($self->{size_w} || 8, $self->{size_h} || 8) 3754 ($self->{size_w} || 8, $self->{size_h} || 8)
3546} 3755}
3547 3756
3548sub update { 3757sub update {
3562} 3771}
3563 3772
3564sub _draw { 3773sub _draw {
3565 my ($self) = @_; 3774 my ($self) = @_;
3566 3775
3567 return unless $::CONN;
3568
3569 $self->SUPER::_draw; 3776 $self->SUPER::_draw;
3570 3777
3571 my $faceid = $::CONN->{faceid}[$self->{face}] 3778 if (my $tex = $self->{tex}) {
3572 or return;
3573
3574 my $tex = $::CONN->{texture}[$faceid];
3575
3576 if ($tex) {
3577 glEnable GL_TEXTURE_2D; 3779 glEnable GL_TEXTURE_2D;
3578 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 3780 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
3579 glColor 0, 0, 0, 1; 3781 glColor 0, 0, 0, 1;
3580 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 3782 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
3581 glDisable GL_TEXTURE_2D; 3783 glDisable GL_TEXTURE_2D;
3633 children => [ 3835 children => [
3634 (new CFPlus::UI::Label markup => $left, expand => 1), 3836 (new CFPlus::UI::Label markup => $left, expand => 1),
3635 (new CFPlus::UI::Label markup => $right, align => +1), 3837 (new CFPlus::UI::Label markup => $right, align => +1),
3636 ], 3838 ],
3637 ; 3839 ;
3638 3840
3639 } else { 3841 } else {
3640 $widget = new CFPlus::UI::Label 3842 $widget = new CFPlus::UI::Label
3641 can_hover => 1, 3843 can_hover => 1,
3642 can_events => 1, 3844 can_events => 1,
3643 markup => $widget, 3845 markup => $widget,
3768 3970
3769############################################################################# 3971#############################################################################
3770 3972
3771package CFPlus::UI::Notebook; 3973package CFPlus::UI::Notebook;
3772 3974
3975use CFPlus::OpenGL;
3976
3773our @ISA = CFPlus::UI::VBox::; 3977our @ISA = CFPlus::UI::VBox::;
3774 3978
3775sub new { 3979sub new {
3776 my $class = shift; 3980 my $class = shift;
3777 3981
3778 my $self = $class->SUPER::new ( 3982 my $self = $class->SUPER::new (
3779 buttonbar => (new CFPlus::UI::Buttonbar), 3983 buttonbar => (new CFPlus::UI::Buttonbar),
3780 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3984 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3985 active_outline => [.7, .7, 0.2],
3781 # filter => # will be put between multiplexer and $self 3986 # filter => # will be put between multiplexer and $self
3782 @_, 3987 @_,
3783 ); 3988 );
3784 3989
3785 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3990 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3786 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); 3991 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3787 3992
3993 {
3994 Scalar::Util::weaken (my $wself = $self);
3995
3996 $self->{multiplexer}->connect (c_add => sub {
3997 my ($mplex, $widgets) = @_;
3998
3999 for my $child (@$widgets) {
4000 Scalar::Util::weaken $child;
4001 $child->{c_tab_} ||= do {
4002 my $tab =
4003 (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base")
4004 ? $child->{c_tab}
4005 : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1];
4006
4007 $tab->connect (activate => sub {
4008 $wself->set_current_page ($child);
4009 });
4010
4011 $tab
4012 };
4013
4014 $self->{buttonbar}->add ($child->{c_tab_});
4015 }
4016 });
4017
4018 $self->{multiplexer}->connect (c_remove => sub {
4019 my ($mplex, $widgets) = @_;
4020
4021 for my $child (@$widgets) {
4022 $wself->{buttonbar}->remove ($child->{c_tab_});
4023 }
4024 });
4025 }
4026
3788 $self 4027 $self
3789} 4028}
3790 4029
3791sub add { 4030sub add {
4031 my ($self, @widgets) = @_;
4032
4033 $self->{multiplexer}->add (@widgets)
4034}
4035
4036sub remove {
4037 my ($self, @widgets) = @_;
4038
4039 $self->{multiplexer}->remove (@widgets)
4040}
4041
4042sub pages {
4043 my ($self) = @_;
4044 $self->{multiplexer}->children
4045}
4046
4047sub add_tab {
3792 my ($self, $title, $widget, $tooltip) = @_; 4048 my ($self, $title, $widget, $tooltip) = @_;
3793 4049
3794 CFPlus::weaken $self; 4050 $title = [$title, $tooltip] unless ref $title;
4051 $widget->{c_tab} = $title;
3795 4052
3796 $self->{buttonbar}->add (new CFPlus::UI::Button
3797 markup => $title,
3798 tooltip => $tooltip,
3799 on_activate => sub { $self->set_current_page ($widget) },
3800 );
3801
3802 $self->{multiplexer}->add ($widget); 4053 $self->add ($widget);
3803} 4054}
3804 4055
3805sub get_current_page { 4056sub get_current_page {
3806 my ($self) = @_; 4057 my ($self) = @_;
3807 4058
3811sub set_current_page { 4062sub set_current_page {
3812 my ($self, $page) = @_; 4063 my ($self, $page) = @_;
3813 4064
3814 $self->{multiplexer}->set_current_page ($page); 4065 $self->{multiplexer}->set_current_page ($page);
3815 $self->emit (page_changed => $self->{multiplexer}{current}); 4066 $self->emit (page_changed => $self->{multiplexer}{current});
4067}
4068
4069sub _draw {
4070 my ($self) = @_;
4071
4072 $self->SUPER::_draw ();
4073
4074 if (my $cur = $self->{multiplexer}{current}) {
4075 if ($cur = $cur->{c_tab_}) {
4076 glTranslate $self->{buttonbar}{x} + $cur->{x},
4077 $self->{buttonbar}{y} + $cur->{y};
4078 glLineWidth 3;
4079 #glEnable GL_BLEND;
4080 #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
4081 glColor @{$self->{active_outline}};
4082 glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5;
4083 glLineWidth 1;
4084 #glDisable GL_BLEND;
4085 }
4086 }
3816} 4087}
3817 4088
3818############################################################################# 4089#############################################################################
3819 4090
3820package CFPlus::UI::Selector; 4091package CFPlus::UI::Selector;
3852} 4123}
3853 4124
3854sub _set_value { 4125sub _set_value {
3855 my ($self, $value) = @_; 4126 my ($self, $value) = @_;
3856 4127
3857 my ($item) = grep $_->[0] eq $value, @{ $self->{options} } 4128 my ($item) = grep $_->[0] eq $value, @{ $self->{options} };
4129 $item ||= $self->{options}[0]
3858 or return; 4130 or return;
3859 4131
3860 $self->{value} = $item->[0]; 4132 $self->{value} = $item->[0];
3861 $self->set_markup ("$item->[1] ⇓"); 4133 $self->set_markup ("$item->[1] ⇓");
3862 $self->set_tooltip ($item->[2]); 4134# $self->set_tooltip ($item->[2]);
3863} 4135}
3864 4136
3865sub set_value { 4137sub set_value {
3866 my ($self, $value) = @_; 4138 my ($self, $value) = @_;
3867 4139
3868 return unless $self->{value} ne $value; 4140 return unless $self->{value} ne $value;
3869 4141
3870 $self->_set_value ($value); 4142 $self->_set_value ($value);
3871 $self->emit (changed => $value); 4143 $self->emit (changed => $value);
4144}
4145
4146sub set_options {
4147 my ($self, $options) = @_;
4148
4149 $self->{options} = $options;
4150 $self->_set_value ($self->{value});
3872} 4151}
3873 4152
3874############################################################################# 4153#############################################################################
3875 4154
3876package CFPlus::UI::Statusbox; 4155package CFPlus::UI::Statusbox;
3885 @_, 4164 @_,
3886 ); 4165 );
3887 4166
3888 CFPlus::weaken (my $this = $self); 4167 CFPlus::weaken (my $this = $self);
3889 4168
3890 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 4169 $self->{timer} = EV::timer 1, 1, sub { $this->reorder };
3891 4170
3892 $self 4171 $self
3893} 4172}
3894 4173
3895sub reorder { 4174sub reorder {
3903 4182
3904 while (my ($k, $v) = each %{ $self->{item} }) { 4183 while (my ($k, $v) = each %{ $self->{item} }) {
3905 delete $self->{item}{$k} if $v->{timeout} < $NOW; 4184 delete $self->{item}{$k} if $v->{timeout} < $NOW;
3906 } 4185 }
3907 4186
4187 $self->{timer}->set (1, 1);
4188
3908 my @widgets; 4189 my @widgets;
3909 4190
3910 my @items = sort { 4191 my @items = sort {
3911 $a->{pri} <=> $b->{pri} 4192 $a->{pri} <=> $b->{pri}
3912 or $b->{id} <=> $a->{id} 4193 or $b->{id} <=> $a->{id}
3913 } values %{ $self->{item} }; 4194 } values %{ $self->{item} };
3914
3915 $self->{timer}->interval (1);
3916 4195
3917 my $count = 10 + 1; 4196 my $count = 10 + 1;
3918 for my $item (@items) { 4197 for my $item (@items) {
3919 last unless --$count; 4198 last unless --$count;
3920 4199
3944 if ((my $diff = $item->{timeout} - $NOW) < 2) { 4223 if ((my $diff = $item->{timeout} - $NOW) < 2) {
3945 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; 4224 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2;
3946 $label->update; 4225 $label->update;
3947 $label->set_max_size (undef, $label->{req_h} * $diff) 4226 $label->set_max_size (undef, $label->{req_h} * $diff)
3948 if $diff < 1; 4227 if $diff < 1;
3949 $self->{timer}->interval (1/30); 4228 $self->{timer}->set (1/30, 1/30);
3950 } else { 4229 } else {
3951 $label->{fg}[3] = $item->{fg}[3] || 1; 4230 $label->{fg}[3] = $item->{fg}[3] || 1;
3952 } 4231 }
3953 4232
3954 push @widgets, $label; 4233 push @widgets, $label;
4090} 4369}
4091 4370
4092sub update { 4371sub update {
4093 my ($self) = @_; 4372 my ($self) = @_;
4094 4373
4095 $::WANT_REFRESH++; 4374 $::WANT_REFRESH->start;
4096} 4375}
4097 4376
4098sub add { 4377sub add {
4099 my ($self, @children) = @_; 4378 my ($self, @children) = @_;
4100 4379
4137 while ($self->{refresh_hook}) { 4416 while ($self->{refresh_hook}) {
4138 $_->() 4417 $_->()
4139 for values %{delete $self->{refresh_hook}}; 4418 for values %{delete $self->{refresh_hook}};
4140 } 4419 }
4141 4420
4142 if ($self->{realloc}) { 4421 while ($self->{realloc}) {
4143 my %queue; 4422 my %queue;
4144 my @queue; 4423 my @queue;
4145 my $widget; 4424 my $widget;
4146 4425
4147 outer: 4426 outer:
4194 } 4473 }
4195 } 4474 }
4196 4475
4197 delete $self->{realloc}{$widget+0}; 4476 delete $self->{realloc}{$widget+0};
4198 } 4477 }
4199 }
4200 4478
4201 while (my $size_alloc = delete $self->{size_alloc}) { 4479 while (my $size_alloc = delete $self->{size_alloc}) {
4202 my @queue = sort { $b->{visible} <=> $a->{visible} } 4480 my @queue = sort { $a->{visible} <=> $b->{visible} }
4203 values %$size_alloc; 4481 values %$size_alloc;
4204 4482
4205 while () { 4483 while () {
4206 my $widget = pop @queue || last; 4484 my $widget = pop @queue || last;
4207 4485
4208 my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; 4486 my ($w, $h) = @$widget{qw(alloc_w alloc_h)};
4209 4487
4210 $w = 0 if $w < 0;
4211 $h = 0 if $h < 0;
4212
4213 $w = max $widget->{min_w}, $w; 4488 $w = max $widget->{min_w}, $w;
4214 $h = max $widget->{min_h}, $h; 4489 $h = max $widget->{min_h}, $h;
4215 4490
4216# $w = min $self->{w} - $widget->{x}, $w if $self->{w}; 4491# $w = min $self->{w} - $widget->{x}, $w if $self->{w};
4217# $h = min $self->{h} - $widget->{y}, $h if $self->{h}; 4492# $h = min $self->{h} - $widget->{y}, $h if $self->{h};
4218 4493
4219 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4494 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4220 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4495 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4221 4496
4222 $w = int $w + 0.5; 4497 $w = int $w + 0.5;
4223 $h = int $h + 0.5; 4498 $h = int $h + 0.5;
4224 4499
4225 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { 4500 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) {
4226 $widget->{old_w} = $widget->{w}; 4501 $widget->{old_w} = $widget->{w};
4227 $widget->{old_h} = $widget->{h}; 4502 $widget->{old_h} = $widget->{h};
4228 4503
4229 $widget->{w} = $w; 4504 $widget->{w} = $w;
4230 $widget->{h} = $h; 4505 $widget->{h} = $h;
4231 4506
4232 $widget->emit (size_allocate => $w, $h); 4507 $widget->emit (size_allocate => $w, $h);
4508 }
4233 } 4509 }
4234 } 4510 }
4235 } 4511 }
4236 4512
4237 while ($self->{post_alloc_hook}) { 4513 while ($self->{post_alloc_hook}) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines