… | |
… | |
96 | |
96 | |
97 | my $self = bless { |
97 | my $self = bless { |
98 | x => 0, |
98 | x => 0, |
99 | y => 0, |
99 | y => 0, |
100 | z => 0, |
100 | z => 0, |
|
|
101 | can_events => 1, |
101 | @_ |
102 | @_ |
102 | }, $class; |
103 | }, $class; |
103 | |
104 | |
104 | for (keys %$self) { |
105 | for (keys %$self) { |
105 | if (/^connect_(.*)$/) { |
106 | if (/^connect_(.*)$/) { |
… | |
… | |
278 | } |
279 | } |
279 | |
280 | |
280 | sub find_widget { |
281 | sub find_widget { |
281 | my ($self, $x, $y) = @_; |
282 | my ($self, $x, $y) = @_; |
282 | |
283 | |
|
|
284 | return () unless $self->{can_events}; |
|
|
285 | |
283 | return $self |
286 | return $self |
284 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
287 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
285 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
288 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
286 | |
289 | |
287 | () |
290 | () |
… | |
… | |
294 | } |
297 | } |
295 | |
298 | |
296 | sub check_size { |
299 | sub check_size { |
297 | my ($self) = @_; |
300 | my ($self) = @_; |
298 | |
301 | |
|
|
302 | return unless $self->{parent}; |
|
|
303 | |
299 | my ($w, $h) = $self->size_request; |
304 | my ($w, $h) = $self->size_request; |
300 | |
305 | |
301 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
306 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
302 | $self->{req_w} = $w; |
307 | $self->{req_w} = $w; |
303 | $self->{req_h} = $h; |
308 | $self->{req_h} = $h; |
304 | |
309 | |
305 | $self->{parent}->check_size |
310 | $self->{parent}->check_size; |
306 | if $self->{parent}; |
|
|
307 | } |
311 | } |
308 | } |
312 | } |
309 | |
313 | |
310 | sub update { |
314 | sub update { |
311 | my ($self) = @_; |
315 | my ($self) = @_; |
… | |
… | |
378 | |
382 | |
379 | package CFClient::UI::Empty; |
383 | package CFClient::UI::Empty; |
380 | |
384 | |
381 | our @ISA = CFClient::UI::Base::; |
385 | our @ISA = CFClient::UI::Base::; |
382 | |
386 | |
|
|
387 | sub new { |
|
|
388 | my ($class, %arg) = @_; |
|
|
389 | $class->SUPER::new (can_events => 0, %arg); |
|
|
390 | } |
|
|
391 | |
383 | sub size_request { |
392 | sub size_request { |
384 | (0, 0) |
393 | (0, 0) |
385 | } |
394 | } |
386 | |
395 | |
387 | sub draw { } |
396 | sub draw { } |
… | |
… | |
395 | sub new { |
404 | sub new { |
396 | my ($class, %arg) = @_; |
405 | my ($class, %arg) = @_; |
397 | |
406 | |
398 | my $children = delete $arg{children} || []; |
407 | my $children = delete $arg{children} || []; |
399 | |
408 | |
400 | my $self = $class->SUPER::new (children => [], %arg); |
409 | my $self = $class->SUPER::new (children => [], can_events => 0, %arg); |
401 | $self->add ($_) for @$children; |
410 | $self->add ($_) for @$children; |
402 | |
411 | |
403 | $self |
412 | $self |
404 | } |
413 | } |
405 | |
414 | |
… | |
… | |
561 | sub new { die } |
570 | sub new { die } |
562 | |
571 | |
563 | sub size_request { |
572 | sub size_request { |
564 | my ($self) = @_; |
573 | my ($self) = @_; |
565 | |
574 | |
566 | @$self{qw(child_w child_h)} = $self->child->size_request; |
575 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
567 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
576 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
568 | |
577 | |
569 | @$self{qw(child_w child_h)} |
578 | @$self{qw(child_w child_h)} |
570 | } |
579 | } |
571 | |
580 | |
… | |
… | |
659 | |
668 | |
660 | my $self = $class->SUPER::new ( |
669 | my $self = $class->SUPER::new ( |
661 | bg => [1, 1, 1, 1], |
670 | bg => [1, 1, 1, 1], |
662 | border_bg => [1, 1, 1, 1], |
671 | border_bg => [1, 1, 1, 1], |
663 | border => 0.8, |
672 | border => 0.8, |
|
|
673 | can_events => 1, |
664 | @_ |
674 | @_ |
665 | ); |
675 | ); |
666 | |
676 | |
667 | $self->{title} &&= new CFClient::UI::Label |
677 | $self->{title} &&= new CFClient::UI::Label |
668 | align => 0, |
678 | align => 0, |
… | |
… | |
837 | or next; |
847 | or next; |
838 | |
848 | |
839 | for my $x (0 .. $#$row) { |
849 | for my $x (0 .. $#$row) { |
840 | my $widget = $row->[$x] |
850 | my $widget = $row->[$x] |
841 | or next; |
851 | or next; |
842 | my ($w, $h) = $widget->size_request; |
852 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
843 | |
853 | |
844 | $w[$x] = max $w[$x], $w; |
854 | $w[$x] = max $w[$x], $w; |
845 | $h[$y] = max $h[$y], $h; |
855 | $h[$y] = max $h[$y], $h; |
846 | } |
856 | } |
847 | } |
857 | } |
… | |
… | |
952 | |
962 | |
953 | ($h, $w) = ($w, $h); |
963 | ($h, $w) = ($w, $h); |
954 | |
964 | |
955 | my $children = $self->{children}; |
965 | my $children = $self->{children}; |
956 | |
966 | |
957 | my @h = map +($_->size_request)[0], @$children; |
967 | my @h = map $_->{req_w}, @$children; |
958 | |
968 | |
959 | my $req_h = List::Util::sum @h; |
969 | my $req_h = List::Util::sum @h; |
960 | |
970 | |
961 | if ($req_h > $h) { |
971 | if ($req_h > $h) { |
962 | # ah well, not enough space |
972 | # ah well, not enough space |
… | |
… | |
1010 | sub size_allocate { |
1020 | sub size_allocate { |
1011 | my ($self, $w, $h) = @_; |
1021 | my ($self, $w, $h) = @_; |
1012 | |
1022 | |
1013 | my $children = $self->{children}; |
1023 | my $children = $self->{children}; |
1014 | |
1024 | |
1015 | my @h = map +($_->size_request)[1], @$children; |
1025 | my @h = map $_->{req_h}, @$children; |
1016 | |
1026 | |
1017 | my $req_h = List::Util::sum @h; |
1027 | my $req_h = List::Util::sum @h; |
1018 | |
1028 | |
1019 | if ($req_h > $h) { |
1029 | if ($req_h > $h) { |
1020 | # ah well, not enough space |
1030 | # ah well, not enough space |
… | |
… | |
1061 | text => "", |
1071 | text => "", |
1062 | align => -1, |
1072 | align => -1, |
1063 | valign => -1, |
1073 | valign => -1, |
1064 | padding => 2, |
1074 | padding => 2, |
1065 | layout => new CFClient::Layout, |
1075 | layout => new CFClient::Layout, |
|
|
1076 | can_events => 0, |
1066 | %arg |
1077 | %arg |
1067 | ); |
1078 | ); |
1068 | |
1079 | |
1069 | if (exists $self->{template}) { |
1080 | if (exists $self->{template}) { |
1070 | my $layout = new CFClient::Layout; |
1081 | my $layout = new CFClient::Layout; |
… | |
… | |
1092 | my ($self, $text) = @_; |
1103 | my ($self, $text) = @_; |
1093 | |
1104 | |
1094 | $self->{layout}->set_text ($text); |
1105 | $self->{layout}->set_text ($text); |
1095 | |
1106 | |
1096 | delete $self->{texture}; |
1107 | delete $self->{texture}; |
|
|
1108 | $self->check_size; |
1097 | $self->update; |
1109 | $self->update; |
1098 | } |
1110 | } |
1099 | |
1111 | |
1100 | sub set_markup { |
1112 | sub set_markup { |
1101 | my ($self, $markup) = @_; |
1113 | my ($self, $markup) = @_; |
1102 | |
1114 | |
1103 | $self->{layout}->set_markup ($markup); |
1115 | $self->{layout}->set_markup ($markup); |
1104 | |
1116 | |
1105 | delete $self->{texture}; |
1117 | delete $self->{texture}; |
|
|
1118 | $self->check_size; |
1106 | $self->update; |
1119 | $self->update; |
1107 | } |
1120 | } |
1108 | |
1121 | |
1109 | sub size_request { |
1122 | sub size_request { |
1110 | my ($self) = @_; |
1123 | my ($self) = @_; |
… | |
… | |
1193 | active_bg => [1, 1, 1, 0.5], |
1206 | active_bg => [1, 1, 1, 0.5], |
1194 | active_fg => [0, 0, 0], |
1207 | active_fg => [0, 0, 0], |
1195 | can_hover => 1, |
1208 | can_hover => 1, |
1196 | can_focus => 1, |
1209 | can_focus => 1, |
1197 | valign => 0, |
1210 | valign => 0, |
|
|
1211 | can_events => 1, |
1198 | @_ |
1212 | @_ |
1199 | ) |
1213 | ) |
1200 | } |
1214 | } |
1201 | |
1215 | |
1202 | sub _set_text { |
1216 | sub _set_text { |
… | |
… | |
1230 | } |
1244 | } |
1231 | |
1245 | |
1232 | sub size_allocate { |
1246 | sub size_allocate { |
1233 | my ($self, $w, $h) = @_; |
1247 | my ($self, $w, $h) = @_; |
1234 | |
1248 | |
1235 | $self->_set_text ($self->{text}); |
1249 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1236 | } |
1250 | } |
1237 | |
1251 | |
1238 | sub set_text { |
1252 | sub set_text { |
1239 | my ($self, $text) = @_; |
1253 | my ($self, $text) = @_; |
1240 | |
1254 | |
… | |
… | |
1387 | bg => [1, 1, 1, 0.2], |
1401 | bg => [1, 1, 1, 0.2], |
1388 | active_fg => [0, 0, 1], |
1402 | active_fg => [0, 0, 1], |
1389 | can_hover => 1, |
1403 | can_hover => 1, |
1390 | align => 0, |
1404 | align => 0, |
1391 | valign => 0, |
1405 | valign => 0, |
|
|
1406 | can_events => 1, |
1392 | @_ |
1407 | @_ |
1393 | ) |
1408 | ) |
1394 | } |
1409 | } |
1395 | |
1410 | |
1396 | sub button_up { |
1411 | sub button_up { |
… | |
… | |
1501 | our %loaded_images; |
1516 | our %loaded_images; |
1502 | |
1517 | |
1503 | sub new { |
1518 | sub new { |
1504 | my $class = shift; |
1519 | my $class = shift; |
1505 | |
1520 | |
1506 | my $self = $class->SUPER::new (@_); |
1521 | my $self = $class->SUPER::new (can_events => 0, @_); |
1507 | |
1522 | |
1508 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
1523 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
1509 | |
1524 | |
1510 | $loaded_images{$self->{image}} ||= |
1525 | $loaded_images{$self->{image}} ||= |
1511 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
1526 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
… | |
… | |
1676 | |
1691 | |
1677 | my $self = $class->SUPER::new ( |
1692 | my $self = $class->SUPER::new ( |
1678 | @_, |
1693 | @_, |
1679 | ); |
1694 | ); |
1680 | |
1695 | |
1681 | $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
1696 | $self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"; |
|
|
1697 | $self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"; |
|
|
1698 | $self->add ($self->{value}); |
1682 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
1699 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
1683 | $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
1700 | $self->add ($self->{max}); |
1684 | |
1701 | |
1685 | $self |
1702 | $self |
|
|
1703 | } |
|
|
1704 | |
|
|
1705 | sub size_request { |
|
|
1706 | my ($self) = @_; |
|
|
1707 | (($self->{max}->size_request)[0], 0) |
1686 | } |
1708 | } |
1687 | |
1709 | |
1688 | sub set_fontsize { |
1710 | sub set_fontsize { |
1689 | my ($self, $fsize) = @_; |
1711 | my ($self, $fsize) = @_; |
1690 | |
1712 | |
… | |
… | |
2054 | my $class = shift; |
2076 | my $class = shift; |
2055 | |
2077 | |
2056 | my $self = $class->SUPER::new ( |
2078 | my $self = $class->SUPER::new ( |
2057 | state => 0, |
2079 | state => 0, |
2058 | connect_activate => \&toggle_flopper, |
2080 | connect_activate => \&toggle_flopper, |
|
|
2081 | can_events => 1, |
2059 | @_ |
2082 | @_ |
2060 | ); |
2083 | ); |
2061 | |
2084 | |
2062 | if ($self->{state}) { |
2085 | if ($self->{state}) { |
2063 | $self->{state} = 0; |
2086 | $self->{state} = 0; |
… | |
… | |
2092 | use CFClient::OpenGL; |
2115 | use CFClient::OpenGL; |
2093 | |
2116 | |
2094 | sub check_size { |
2117 | sub check_size { |
2095 | my ($self) = @_; |
2118 | my ($self) = @_; |
2096 | |
2119 | |
2097 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2120 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
2098 | } |
2121 | } |
2099 | |
2122 | |
2100 | sub size_request { |
2123 | sub size_request { |
2101 | ($::WIDTH, $::HEIGHT) |
2124 | ($::WIDTH, $::HEIGHT) |
2102 | } |
2125 | } |
… | |
… | |
2104 | sub configure { |
2127 | sub configure { |
2105 | my ($self, $x, $y, $w, $h) = @_; |
2128 | my ($self, $x, $y, $w, $h) = @_; |
2106 | |
2129 | |
2107 | $self->SUPER::configure ($x, $y, $w, $h); |
2130 | $self->SUPER::configure ($x, $y, $w, $h); |
2108 | |
2131 | |
2109 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
|
|
2110 | for @{$self->{children}}; |
2132 | for my $child (@{$self->{children}}) { |
|
|
2133 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
|
|
2134 | |
|
|
2135 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
|
|
2136 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
|
|
2137 | $child->configure ($X, $Y, $W,$H); |
|
|
2138 | } |
2111 | } |
2139 | } |
2112 | |
2140 | |
2113 | sub _topleft { |
2141 | sub _topleft { |
2114 | my ($self, $x, $y) = @_; |
2142 | my ($self, $x, $y) = @_; |
2115 | |
2143 | |