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.256 by root, Tue May 30 01:42:16 2006 UTC vs.
Revision 1.258 by root, Tue May 30 02:55:45 2006 UTC

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
36sub set_layout { 38sub set_layout {
37 my ($layout) = @_; 39 my ($layout) = @_;
40
38 $LAYOUT = $layout; 41 $LAYOUT = $layout;
39} 42}
40 43
41sub check_tooltip { 44sub 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
464sub set_parent { 469sub 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
472sub connect { 476sub connect {
473 my ($self, $signal, $cb) = @_; 477 my ($self, $signal, $cb) = @_;
1026 1030
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 is_toplevel => 1,
1032 can_events => 1, 1035 can_events => 1,
1036 min_w => 16,
1037 min_h => 16,
1033 @_ 1038 @_
1034 ); 1039 );
1035 1040
1036 $self->{title} &&= new CFClient::UI::Label 1041 $self->{title} &&= new CFClient::UI::Label
1037 align => 0, 1042 align => 0,
1421 ellipsise => 3, # end 1426 ellipsise => 3, # end
1422 layout => (new CFClient::Layout), 1427 layout => (new CFClient::Layout),
1423 fontsize => 1, 1428 fontsize => 1,
1424 align => -1, 1429 align => -1,
1425 valign => -1, 1430 valign => -1,
1426 padding => 2, 1431 padding_x => 2,
1432 padding_y => 2,
1427 can_events => 0, 1433 can_events => 0,
1428 %arg 1434 %arg
1429 ); 1435 );
1430 1436
1431 if (exists $self->{template}) { 1437 if (exists $self->{template}) {
1507 1513
1508 $w = List::Util::max $w, $w2; 1514 $w = List::Util::max $w, $w2;
1509 $h = List::Util::max $h, $h2; 1515 $h = List::Util::max $h, $h2;
1510 } 1516 }
1511 1517
1512 ( 1518 ($w, $h)
1513 $w + $self->{padding} * 2,
1514 $h + $self->{padding} * 2,
1515 )
1516} 1519}
1517 1520
1518sub size_allocate { 1521sub size_allocate {
1519 my ($self, $w, $h, $changed) = @_; 1522 my ($self, $w, $h, $changed) = @_;
1520 1523
1544 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1547 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1545 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1548 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1546 1549
1547 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1550 my $tex = new_from_layout CFClient::Texture $self->{layout};
1548 1551
1549 $self->{ox} = int ($self->{align} < 0 ? $self->{padding} 1552 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x}
1550 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1553 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x}
1551 : ($self->{w} - $tex->{w}) * 0.5); 1554 : ($self->{w} - $tex->{w}) * 0.5);
1552 1555
1553 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding} 1556 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
1554 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1557 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y}
1555 : ($self->{h} - $tex->{h}) * 0.5); 1558 : ($self->{h} - $tex->{h}) * 0.5);
1556 1559
1557 $tex 1560 $tex
1558 }; 1561 };
1559 1562
1798 1801
1799sub new { 1802sub new {
1800 my $class = shift; 1803 my $class = shift;
1801 1804
1802 $class->SUPER::new ( 1805 $class->SUPER::new (
1803 padding => 4, 1806 padding_x => 4,
1807 padding_y => 4,
1804 fg => [1, 1, 1], 1808 fg => [1, 1, 1],
1805 active_fg => [0, 0, 1], 1809 active_fg => [0, 0, 1],
1806 can_hover => 1, 1810 can_hover => 1,
1807 align => 0, 1811 align => 0,
1808 valign => 0, 1812 valign => 0,
1855 1859
1856sub new { 1860sub new {
1857 my $class = shift; 1861 my $class = shift;
1858 1862
1859 $class->SUPER::new ( 1863 $class->SUPER::new (
1860 padding => 2, 1864 padding_x => 2,
1865 padding_y => 2,
1861 fg => [1, 1, 1], 1866 fg => [1, 1, 1],
1862 active_fg => [1, 1, 0], 1867 active_fg => [1, 1, 0],
1863 bg => [0, 0, 0, 0.2], 1868 bg => [0, 0, 0, 0.2],
1864 active_bg => [1, 1, 1, 0.5], 1869 active_bg => [1, 1, 1, 0.5],
1865 state => 0, 1870 state => 0,
1869} 1874}
1870 1875
1871sub size_request { 1876sub size_request {
1872 my ($self) = @_; 1877 my ($self) = @_;
1873 1878
1874 ($self->{padding} * 2 + 6) x 2 1879 (6) x 2
1875} 1880}
1876 1881
1877sub button_down { 1882sub button_down {
1878 my ($self, $ev, $x, $y) = @_; 1883 my ($self, $ev, $x, $y) = @_;
1879 1884
1880 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} 1885 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
1881 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { 1886 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
1882 $self->{state} = !$self->{state}; 1887 $self->{state} = !$self->{state};
1883 $self->_emit (changed => $self->{state}); 1888 $self->_emit (changed => $self->{state});
1884 } 1889 }
1885} 1890}
1886 1891
1887sub _draw { 1892sub _draw {
1888 my ($self) = @_; 1893 my ($self) = @_;
1889 1894
1890 $self->SUPER::_draw; 1895 $self->SUPER::_draw;
1891 1896
1892 glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; 1897 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0;
1893 1898
1894 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;
1895 1902
1896 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1903 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1897 1904
1898 my $tex = $self->{state} ? $tex[1] : $tex[0]; 1905 my $tex = $self->{state} ? $tex[1] : $tex[0];
1899 1906
2164 fg => [1, 1, 1], 2171 fg => [1, 1, 1],
2165 active_fg => [0, 0, 0], 2172 active_fg => [0, 0, 0],
2166 bg => [0, 0, 0, 0.2], 2173 bg => [0, 0, 0, 0.2],
2167 active_bg => [1, 1, 1, 0.5], 2174 active_bg => [1, 1, 1, 0.5],
2168 range => [0, 0, 100, 10, 0], 2175 range => [0, 0, 100, 10, 0],
2169 req_w => $::WIDTH / 80, 2176 min_w => $::WIDTH / 80,
2170 req_h => $::WIDTH / 80, 2177 min_h => $::WIDTH / 80,
2171 vertical => 0, 2178 vertical => 0,
2172 can_hover => 1, 2179 can_hover => 1,
2173 inner_pad => 0.02, 2180 inner_pad => 0.02,
2174 @_ 2181 @_
2175 ); 2182 );
2215} 2222}
2216 2223
2217sub size_request { 2224sub size_request {
2218 my ($self) = @_; 2225 my ($self) = @_;
2219 2226
2220 my $w = $self->{req_w}; 2227 ($self->{req_w}, $self->{req_h})
2221 my $h = $self->{req_h};
2222
2223 $self->{vertical} ? ($h, $w) : ($w, $h)
2224} 2228}
2225 2229
2226sub button_down { 2230sub button_down {
2227 my ($self, $ev, $x, $y) = @_; 2231 my ($self, $ev, $x, $y) = @_;
2228 2232
2858 # maybe save $GRAB? must be careful about events... 2862 # maybe save $GRAB? must be careful about events...
2859 $GRAB = $self; 2863 $GRAB = $self;
2860 $self->{button} = $ev->{button}; 2864 $self->{button} = $ev->{button};
2861 2865
2862 $self->show; 2866 $self->show;
2863 $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);
2864} 2868}
2865 2869
2866sub mouse_motion { 2870sub mouse_motion {
2867 my ($self, $ev, $x, $y) = @_; 2871 my ($self, $ev, $x, $y) = @_;
2868 2872
3141 3145
3142 my $widget = pop @queue || last; 3146 my $widget = pop @queue || last;
3143 3147
3144 $widget->{visible} or last; # do not resize invisible widgets 3148 $widget->{visible} or last; # do not resize invisible widgets
3145 3149
3150 my ($w, $h) = $widget->size_request;
3151
3152 $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2;
3153 $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2;
3154
3146 my ($w, $h) = exists $widget->{force_w} && exists $widget->{force_h} 3155 $w = $widget->{force_w} if exists $widget->{force_w};
3147 ? @$widget{qw(force_w force_h)} 3156 $h = $widget->{force_h} if exists $widget->{force_h};
3148 : $widget->size_request;
3149
3150 my $min_size = $widget->{is_toplevel} ? 16 : 0;
3151
3152 $w = $min_size if $w < $min_size;
3153 $h = $min_size if $h < $min_size;
3154 3157
3155 $widget->{req_w} = $w; 3158 $widget->{req_w} = $w;
3156 $widget->{req_h} = $h; 3159 $widget->{req_h} = $h;
3157 3160
3158 $self->{size_alloc}{$widget} = [$widget, undef, undef]; 3161 $self->{size_alloc}{$widget} = [$widget, undef, undef];
3159 3162
3160 push @queue, $widget->{parent} 3163 push @queue, $widget->{parent}
3161 if $widget->{parent}; 3164 if ($self->{w} != $w || $self->{h} != $h) && $widget->{parent};
3162 } 3165 }
3163 } 3166 }
3164 3167
3165 while (my $size_alloc = delete $self->{size_alloc}) { 3168 while (my $size_alloc = delete $self->{size_alloc}) {
3166 my @queue = sort $b->[0]{visible} <=> $a->[0]{visible}, 3169 my @queue = sort $b->[0]{visible} <=> $a->[0]{visible},

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines