… | |
… | |
26 | |
26 | |
27 | $win->{x} = ($_->{x} + $_->{w} * 0.5) / $::WIDTH if $_->{x} =~ /^[0-9.]+$/; |
27 | $win->{x} = ($_->{x} + $_->{w} * 0.5) / $::WIDTH if $_->{x} =~ /^[0-9.]+$/; |
28 | $win->{y} = ($_->{y} + $_->{h} * 0.5) / $::HEIGHT if $_->{y} =~ /^[0-9.]+$/; |
28 | $win->{y} = ($_->{y} + $_->{h} * 0.5) / $::HEIGHT if $_->{y} =~ /^[0-9.]+$/; |
29 | $win->{w} = $_->{w} / $::WIDTH if defined $_->{w}; |
29 | $win->{w} = $_->{w} / $::WIDTH if defined $_->{w}; |
30 | $win->{h} = $_->{h} / $::HEIGHT if defined $_->{h}; |
30 | $win->{h} = $_->{h} / $::HEIGHT if defined $_->{h}; |
|
|
31 | |
|
|
32 | $win->{show} = $_->{visible} && $_->{is_toplevel}; |
31 | } |
33 | } |
32 | |
34 | |
33 | $layout |
35 | $layout |
34 | } |
36 | } |
35 | |
37 | |
36 | sub set_layout { |
38 | sub set_layout { |
37 | my ($layout) = @_; |
39 | my ($layout) = @_; |
|
|
40 | |
38 | $LAYOUT = $layout; |
41 | $LAYOUT = $layout; |
39 | } |
42 | } |
40 | |
43 | |
41 | sub check_tooltip { |
44 | sub check_tooltip { |
42 | if (!$GRAB) { |
45 | if (!$GRAB) { |
… | |
… | |
207 | h => undef, |
210 | h => undef, |
208 | can_events => 1, |
211 | can_events => 1, |
209 | @_ |
212 | @_ |
210 | }, $class; |
213 | }, $class; |
211 | |
214 | |
|
|
215 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
|
|
216 | |
|
|
217 | for (keys %$self) { |
|
|
218 | if (/^on_(.*)$/) { |
|
|
219 | $self->connect ($1 => delete $self->{$_}); |
|
|
220 | } |
|
|
221 | } |
|
|
222 | |
212 | if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { |
223 | if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { |
213 | $self->{x} = $layout->{x} * $CFClient::UI::ROOT->{w} if exists $layout->{x}; |
224 | $self->{x} = $layout->{x} * $CFClient::UI::ROOT->{w} if exists $layout->{x}; |
214 | $self->{y} = $layout->{y} * $CFClient::UI::ROOT->{h} if exists $layout->{y}; |
225 | $self->{y} = $layout->{y} * $CFClient::UI::ROOT->{h} if exists $layout->{y}; |
215 | $self->{force_w} = $layout->{w} * $CFClient::UI::ROOT->{w} if exists $layout->{w}; |
226 | $self->{force_w} = $layout->{w} * $CFClient::UI::ROOT->{w} if exists $layout->{w}; |
216 | $self->{force_h} = $layout->{h} * $CFClient::UI::ROOT->{h} if exists $layout->{h}; |
227 | $self->{force_h} = $layout->{h} * $CFClient::UI::ROOT->{h} if exists $layout->{h}; |
217 | |
228 | |
218 | $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; |
229 | $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; |
219 | $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; |
230 | $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; |
220 | } |
|
|
221 | |
231 | |
222 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
232 | $self->show if $layout->{show}; |
223 | |
|
|
224 | for (keys %$self) { |
|
|
225 | if (/^on_(.*)$/) { |
|
|
226 | $self->connect ($1 => delete $self->{$_}); |
|
|
227 | } |
|
|
228 | } |
233 | } |
229 | |
234 | |
230 | $self |
235 | $self |
231 | } |
236 | } |
232 | |
237 | |
… | |
… | |
463 | |
468 | |
464 | sub set_parent { |
469 | sub set_parent { |
465 | my ($self, $parent) = @_; |
470 | my ($self, $parent) = @_; |
466 | |
471 | |
467 | Scalar::Util::weaken ($self->{parent} = $parent); |
472 | Scalar::Util::weaken ($self->{parent} = $parent); |
468 | |
|
|
469 | $self->set_visible if $parent->{visible}; |
473 | $self->set_visible if $parent->{visible}; |
470 | } |
474 | } |
471 | |
475 | |
472 | sub connect { |
476 | sub connect { |
473 | my ($self, $signal, $cb) = @_; |
477 | my ($self, $signal, $cb) = @_; |
… | |
… | |
1027 | my $self = $class->SUPER::new ( |
1031 | my $self = $class->SUPER::new ( |
1028 | bg => [1, 1, 1, 1], |
1032 | bg => [1, 1, 1, 1], |
1029 | border_bg => [1, 1, 1, 1], |
1033 | border_bg => [1, 1, 1, 1], |
1030 | border => 0.6, |
1034 | border => 0.6, |
1031 | can_events => 1, |
1035 | can_events => 1, |
|
|
1036 | min_w => 16, |
|
|
1037 | min_h => 16, |
1032 | @_ |
1038 | @_ |
1033 | ); |
1039 | ); |
1034 | |
1040 | |
1035 | $self->{title} &&= new CFClient::UI::Label |
1041 | $self->{title} &&= new CFClient::UI::Label |
1036 | align => 0, |
1042 | align => 0, |
… | |
… | |
1420 | ellipsise => 3, # end |
1426 | ellipsise => 3, # end |
1421 | layout => (new CFClient::Layout), |
1427 | layout => (new CFClient::Layout), |
1422 | fontsize => 1, |
1428 | fontsize => 1, |
1423 | align => -1, |
1429 | align => -1, |
1424 | valign => -1, |
1430 | valign => -1, |
1425 | padding => 2, |
1431 | padding_x => 2, |
|
|
1432 | padding_y => 2, |
1426 | can_events => 0, |
1433 | can_events => 0, |
1427 | %arg |
1434 | %arg |
1428 | ); |
1435 | ); |
1429 | |
1436 | |
1430 | if (exists $self->{template}) { |
1437 | if (exists $self->{template}) { |
… | |
… | |
1506 | |
1513 | |
1507 | $w = List::Util::max $w, $w2; |
1514 | $w = List::Util::max $w, $w2; |
1508 | $h = List::Util::max $h, $h2; |
1515 | $h = List::Util::max $h, $h2; |
1509 | } |
1516 | } |
1510 | |
1517 | |
1511 | ( |
1518 | ($w, $h) |
1512 | $w + $self->{padding} * 2, |
|
|
1513 | $h + $self->{padding} * 2, |
|
|
1514 | ) |
|
|
1515 | } |
1519 | } |
1516 | |
1520 | |
1517 | sub size_allocate { |
1521 | sub size_allocate { |
1518 | my ($self, $w, $h, $changed) = @_; |
1522 | my ($self, $w, $h, $changed) = @_; |
1519 | |
1523 | |
… | |
… | |
1543 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1547 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1544 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1548 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1545 | |
1549 | |
1546 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1550 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1547 | |
1551 | |
1548 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding} |
1552 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} |
1549 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1553 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} |
1550 | : ($self->{w} - $tex->{w}) * 0.5); |
1554 | : ($self->{w} - $tex->{w}) * 0.5); |
1551 | |
1555 | |
1552 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding} |
1556 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
1553 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1557 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} |
1554 | : ($self->{h} - $tex->{h}) * 0.5); |
1558 | : ($self->{h} - $tex->{h}) * 0.5); |
1555 | |
1559 | |
1556 | $tex |
1560 | $tex |
1557 | }; |
1561 | }; |
1558 | |
1562 | |
… | |
… | |
1797 | |
1801 | |
1798 | sub new { |
1802 | sub new { |
1799 | my $class = shift; |
1803 | my $class = shift; |
1800 | |
1804 | |
1801 | $class->SUPER::new ( |
1805 | $class->SUPER::new ( |
1802 | padding => 4, |
1806 | padding_x => 4, |
|
|
1807 | padding_y => 4, |
1803 | fg => [1, 1, 1], |
1808 | fg => [1, 1, 1], |
1804 | active_fg => [0, 0, 1], |
1809 | active_fg => [0, 0, 1], |
1805 | can_hover => 1, |
1810 | can_hover => 1, |
1806 | align => 0, |
1811 | align => 0, |
1807 | valign => 0, |
1812 | valign => 0, |
… | |
… | |
1854 | |
1859 | |
1855 | sub new { |
1860 | sub new { |
1856 | my $class = shift; |
1861 | my $class = shift; |
1857 | |
1862 | |
1858 | $class->SUPER::new ( |
1863 | $class->SUPER::new ( |
1859 | padding => 2, |
1864 | padding_x => 2, |
|
|
1865 | padding_y => 2, |
1860 | fg => [1, 1, 1], |
1866 | fg => [1, 1, 1], |
1861 | active_fg => [1, 1, 0], |
1867 | active_fg => [1, 1, 0], |
1862 | bg => [0, 0, 0, 0.2], |
1868 | bg => [0, 0, 0, 0.2], |
1863 | active_bg => [1, 1, 1, 0.5], |
1869 | active_bg => [1, 1, 1, 0.5], |
1864 | state => 0, |
1870 | state => 0, |
… | |
… | |
1868 | } |
1874 | } |
1869 | |
1875 | |
1870 | sub size_request { |
1876 | sub size_request { |
1871 | my ($self) = @_; |
1877 | my ($self) = @_; |
1872 | |
1878 | |
1873 | ($self->{padding} * 2 + 6) x 2 |
1879 | (6) x 2 |
1874 | } |
1880 | } |
1875 | |
1881 | |
1876 | sub button_down { |
1882 | sub button_down { |
1877 | my ($self, $ev, $x, $y) = @_; |
1883 | my ($self, $ev, $x, $y) = @_; |
1878 | |
1884 | |
1879 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1885 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
1880 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1886 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
1881 | $self->{state} = !$self->{state}; |
1887 | $self->{state} = !$self->{state}; |
1882 | $self->_emit (changed => $self->{state}); |
1888 | $self->_emit (changed => $self->{state}); |
1883 | } |
1889 | } |
1884 | } |
1890 | } |
1885 | |
1891 | |
1886 | sub _draw { |
1892 | sub _draw { |
1887 | my ($self) = @_; |
1893 | my ($self) = @_; |
1888 | |
1894 | |
1889 | $self->SUPER::_draw; |
1895 | $self->SUPER::_draw; |
1890 | |
1896 | |
1891 | glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; |
1897 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
1892 | |
1898 | |
1893 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1899 | my ($w, $h) = @$self{qw(w h)}; |
|
|
1900 | |
|
|
1901 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
1894 | |
1902 | |
1895 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1903 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1896 | |
1904 | |
1897 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
1905 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
1898 | |
1906 | |
… | |
… | |
2854 | # maybe save $GRAB? must be careful about events... |
2862 | # maybe save $GRAB? must be careful about events... |
2855 | $GRAB = $self; |
2863 | $GRAB = $self; |
2856 | $self->{button} = $ev->{button}; |
2864 | $self->{button} = $ev->{button}; |
2857 | |
2865 | |
2858 | $self->show; |
2866 | $self->show; |
2859 | $self->move ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); |
2867 | $self->move_abs ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); |
2860 | } |
2868 | } |
2861 | |
2869 | |
2862 | sub mouse_motion { |
2870 | sub mouse_motion { |
2863 | my ($self, $ev, $x, $y) = @_; |
2871 | my ($self, $ev, $x, $y) = @_; |
2864 | |
2872 | |
… | |
… | |
3139 | |
3147 | |
3140 | $widget->{visible} or last; # do not resize invisible widgets |
3148 | $widget->{visible} or last; # do not resize invisible widgets |
3141 | |
3149 | |
3142 | my ($w, $h) = $widget->size_request; |
3150 | my ($w, $h) = $widget->size_request; |
3143 | |
3151 | |
3144 | my $min_size = $widget->{is_toplevel} ? 16 : 0; |
|
|
3145 | |
|
|
3146 | $w = List::Util::max $widget->{min_w} || $widget->{is_toplevel} * 16, $w; |
3152 | $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
3147 | $h = List::Util::max $widget->{min_h} || $widget->{is_toplevel} * 16, $h; |
3153 | $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
3148 | |
3154 | |
3149 | $w = $widget->{force_w} if exists $widget->{force_w}; |
3155 | $w = $widget->{force_w} if exists $widget->{force_w}; |
3150 | $h = $widget->{force_h} if exists $widget->{force_h}; |
3156 | $h = $widget->{force_h} if exists $widget->{force_h}; |
3151 | |
3157 | |
3152 | $widget->{req_w} = $w; |
3158 | $widget->{req_w} = $w; |