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.162 by root, Mon Apr 24 06:05:35 2006 UTC vs.
Revision 1.171 by root, Mon Apr 24 11:54:26 2006 UTC

39 delete $TOOLTIP->{owner}; 39 delete $TOOLTIP->{owner};
40} 40}
41 41
42# class methods for events 42# class methods for events
43sub feed_sdl_key_down_event { 43sub feed_sdl_key_down_event {
44 $FOCUS->key_down ($_[0]) if $FOCUS; 44 $FOCUS->emit (key_down => $_[0]) || $FOCUS->key_down ($_[0])
45 if $FOCUS;
45} 46}
46 47
47sub feed_sdl_key_up_event { 48sub feed_sdl_key_up_event {
48 $FOCUS->key_up ($_[0]) if $FOCUS; 49 $FOCUS->emit (key_up => $_[0]) || $FOCUS->key_up ($_[0])
50 if $FOCUS;
49} 51}
50 52
51sub feed_sdl_button_down_event { 53sub feed_sdl_button_down_event {
52 my ($ev) = @_; 54 my ($ev) = @_;
53 my ($x, $y) = ($ev->{x}, $ev->{y}); 55 my ($x, $y) = ($ev->{x}, $ev->{y});
61 check_tooltip; 63 check_tooltip;
62 } 64 }
63 65
64 $BUTTON_STATE |= 1 << ($ev->{button} - 1); 66 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
65 67
66 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; 68 if ($GRAB) {
69 ($x, $y) = $GRAB->coord2local ($x, $y);
70 $GRAB->emit (button_down => $ev, $x, $y) || $GRAB->button_down ($ev, $x, $y);
71 }
67} 72}
68 73
69sub feed_sdl_button_up_event { 74sub feed_sdl_button_up_event {
70 my ($ev) = @_; 75 my ($ev) = @_;
71 my ($x, $y) = ($ev->{x}, $ev->{y}); 76 my ($x, $y) = ($ev->{x}, $ev->{y});
72 77
73 my $widget = $GRAB || $ROOT->find_widget ($x, $y); 78 my $widget = $GRAB || $ROOT->find_widget ($x, $y);
74 79
75 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); 80 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1));
76 81
77 $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; 82 if ($GRAB) {
83 ($x, $y) = $GRAB->coord2local ($x, $y);
84 $GRAB->emit (button_up => $ev, $x, $y) || $GRAB->button_up ($ev, $x, $y);
85 }
78 86
79 if (!$BUTTON_STATE) { 87 if (!$BUTTON_STATE) {
80 my $grab = $GRAB; undef $GRAB; 88 my $grab = $GRAB; undef $GRAB;
81 $grab->update if $grab; 89 $grab->update if $grab;
82 $GRAB->update if $GRAB; 90 $GRAB->update if $GRAB;
98 $HOVER->update if $HOVER && $HOVER->{can_hover}; 106 $HOVER->update if $HOVER && $HOVER->{can_hover};
99 107
100 check_tooltip; 108 check_tooltip;
101 } 109 }
102 110
103 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; 111 if ($HOVER) {
112 ($x, $y) = $HOVER->coord2local ($x, $y);
113 $HOVER->emit (mouse_motion => $ev, $x, $y) || $HOVER->mouse_motion ($ev, $x, $y);
114 }
104} 115}
105 116
106# convert position array to integers 117# convert position array to integers
107sub harmonize { 118sub harmonize {
108 my ($vals) = @_; 119 my ($vals) = @_;
126 137
127sub new { 138sub new {
128 my $class = shift; 139 my $class = shift;
129 140
130 my $self = bless { 141 my $self = bless {
131 x => 0, 142 x => 0,
132 y => 0, 143 y => 0,
133 z => 0, 144 z => 0,
134 can_events => 1, 145 can_events => 1,
135 @_ 146 @_
136 }, $class; 147 }, $class;
137 148
138 for (keys %$self) { 149 for (keys %$self) {
160} 171}
161 172
162sub hide { 173sub hide {
163 my ($self) = @_; 174 my ($self) = @_;
164 175
165 return unless $self->{parent}; 176 undef $GRAB if $GRAB == $self;
177 undef $HOVER if $HOVER == $self;
166 178
167 $self->{parent}->remove ($self); 179 $self->{parent}->remove ($self)
180 if $self->{parent};
168} 181}
169 182
170sub move { 183sub move {
171 my ($self, $x, $y, $z) = @_; 184 my ($self, $x, $y, $z) = @_;
172 185
233} 246}
234 247
235# return top left coordinates 248# return top left coordinates
236sub _topleft { 249sub _topleft {
237 my ($self, $x, $y) = @_; 250 my ($self, $x, $y) = @_;
251
252 $self->{parent}
253 or Carp::confess "no parent widget in _topleft\n";#d#
238 254
239 $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); 255 $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y});
240} 256}
241 257
242# translate global coordinates to local coordinate system 258# translate global coordinates to local coordinate system
402} 418}
403 419
404sub emit { 420sub emit {
405 my ($self, $signal, @args) = @_; 421 my ($self, $signal, @args) = @_;
406 422
407 for my $cb (@{$self->{signal_cb}{$signal} || []}) { 423 List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}
408 $cb->($self, @args);
409 }
410} 424}
411 425
412sub DESTROY { 426sub DESTROY {
413 my ($self) = @_; 427 my ($self) = @_;
414 428
481sub new { 495sub new {
482 my ($class, %arg) = @_; 496 my ($class, %arg) = @_;
483 497
484 my $children = delete $arg{children} || []; 498 my $children = delete $arg{children} || [];
485 499
486 my $self = $class->SUPER::new (children => [], can_events => 0, %arg); 500 my $self = $class->SUPER::new (
501 children => [],
502 can_events => 0,
503 %arg,
504 );
487 $self->add ($_) for @$children; 505 $self->add ($_) for @$children;
488 506
489 $self 507 $self
490} 508}
491 509
506 524
507sub remove { 525sub remove {
508 my ($self, $child) = @_; 526 my ($self, $child) = @_;
509 527
510 delete $child->{parent}; 528 delete $child->{parent};
529 $child->hide;
511 530
512 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 531 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
513 532
514 $self->check_size; 533 $self->check_size;
515 $self->update; 534 $self->update;
516} 535}
517 536
518sub clear { 537sub clear {
519 my ($self) = @_; 538 my ($self) = @_;
520 539
521 delete $_->{parent} 540 my $children = delete $self->{children};
522 for @{ delete $self->{children} };
523
524 $self->{children} = []; 541 $self->{children} = [];
542
543 for (@$children) {
544 delete $_->{parent};
545 $_->hide;
546 }
525} 547}
526 548
527sub find_widget { 549sub find_widget {
528 my ($self, $x, $y) = @_; 550 my ($self, $x, $y) = @_;
529 551
733 my $class = shift; 755 my $class = shift;
734 756
735 # TODO: user_x, user_y, overwrite moveto? 757 # TODO: user_x, user_y, overwrite moveto?
736 758
737 my $self = $class->SUPER::new ( 759 my $self = $class->SUPER::new (
738 bg => [1, 1, 1, 1], 760 bg => [1, 1, 1, 1],
739 border_bg => [1, 1, 1, 1], 761 border_bg => [1, 1, 1, 1],
740 border => 0.8, 762 border => 0.8,
741 can_events => 1, 763 can_events => 1,
742 @_ 764 @_
743 ); 765 );
744 766
745 $self->{title} &&= new CFClient::UI::Label 767 $self->{title} &&= new CFClient::UI::Label
897 919
898# TODO: move to container class maybe? send childs a signal on removal? 920# TODO: move to container class maybe? send childs a signal on removal?
899sub clear { 921sub clear {
900 my ($self) = @_; 922 my ($self) = @_;
901 923
902 delete $self->{children}; 924 my $children = delete $self->{children};
925
926 for (grep $_, map @$_, grep $_, @$children) {
927 delete $_->{parent};
928 $_->hide;
929 }
930
903 $self->update; 931 $self->update;
904} 932}
905 933
906sub get_wh { 934sub get_wh {
907 my ($self) = @_; 935 my ($self) = @_;
1130 1158
1131sub new { 1159sub new {
1132 my ($class, %arg) = @_; 1160 my ($class, %arg) = @_;
1133 1161
1134 my $self = $class->SUPER::new ( 1162 my $self = $class->SUPER::new (
1135 fg => [1, 1, 1], 1163 fg => [1, 1, 1],
1136 #font => default_font 1164 #font => default_font
1137 fontsize => 1, 1165 fontsize => 1,
1138 text => "", 1166 text => "",
1139 align => -1, 1167 align => -1,
1140 valign => -1, 1168 valign => -1,
1141 padding => 2, 1169 padding => 2,
1142 layout => new CFClient::Layout, 1170 layout => new CFClient::Layout,
1143 can_events => 0, 1171 can_events => 0,
1144 %arg 1172 %arg
1145 ); 1173 );
1146 1174
1147 if (exists $self->{template}) { 1175 if (exists $self->{template}) {
1271 1299
1272sub new { 1300sub new {
1273 my $class = shift; 1301 my $class = shift;
1274 1302
1275 $class->SUPER::new ( 1303 $class->SUPER::new (
1276 fg => [1, 1, 1], 1304 fg => [1, 1, 1],
1277 bg => [0, 0, 0, 0.2], 1305 bg => [0, 0, 0, 0.2],
1278 active_bg => [1, 1, 1, 0.5], 1306 active_bg => [1, 1, 1, 0.5],
1279 active_fg => [0, 0, 0], 1307 active_fg => [0, 0, 0],
1280 can_hover => 1, 1308 can_hover => 1,
1281 can_focus => 1, 1309 can_focus => 1,
1282 valign => 0, 1310 valign => 0,
1283 can_events => 1, 1311 can_events => 1,
1284 @_ 1312 @_
1285 ) 1313 )
1286} 1314}
1287 1315
1441 my ($self, $ev) = @_; 1469 my ($self, $ev) = @_;
1442 1470
1443 my $sym = $ev->{sym}; 1471 my $sym = $ev->{sym};
1444 1472
1445 if ($sym == 13) { 1473 if ($sym == 13) {
1474 unshift @{$self->{history}},
1475 my $txt = $self->get_text;
1476 $self->{history_pointer} = -1;
1477 $self->{history_saveback} = '';
1446 $self->emit (activate => $self->get_text); 1478 $self->emit (activate => $txt);
1447 $self->update; 1479 $self->update;
1480
1481 } elsif ($sym == CFClient::SDLK_UP) {
1482 if ($self->{history_pointer} < 0) {
1483 $self->{history_saveback} = $self->get_text;
1484 }
1485 if (@{$self->{history} || []} > 0) {
1486 $self->{history_pointer}++;
1487 if ($self->{history_pointer} >= @{$self->{history} || []}) {
1488 $self->{history_pointer} = @{$self->{history} || []} - 1;
1489 }
1490 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1491 }
1492
1493 } elsif ($sym == CFClient::SDLK_DOWN) {
1494 $self->{history_pointer}--;
1495 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1496
1497 if ($self->{history_pointer} >= 0) {
1498 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1499 } else {
1500 $self->set_text ($self->{history_saveback});
1501 }
1448 1502
1449 } else { 1503 } else {
1450 $self->SUPER::key_down ($ev); 1504 $self->SUPER::key_down ($ev);
1451 } 1505 }
1452 1506
1466 1520
1467sub new { 1521sub new {
1468 my $class = shift; 1522 my $class = shift;
1469 1523
1470 $class->SUPER::new ( 1524 $class->SUPER::new (
1471 padding => 4, 1525 padding => 4,
1472 fg => [1, 1, 1], 1526 fg => [1, 1, 1],
1473 bg => [1, 1, 1, 0.2], 1527 bg => [1, 1, 1, 0.2],
1474 active_fg => [0, 0, 1], 1528 active_fg => [0, 0, 1],
1475 can_hover => 1, 1529 can_hover => 1,
1476 align => 0, 1530 align => 0,
1477 valign => 0, 1531 valign => 0,
1478 can_events => 1, 1532 can_events => 1,
1479 @_ 1533 @_
1480 ) 1534 )
1481} 1535}
1482 1536
1773 1827
1774sub new { 1828sub new {
1775 my ($class, %arg) = @_; 1829 my ($class, %arg) = @_;
1776 1830
1777 my $self = $class->SUPER::new ( 1831 my $self = $class->SUPER::new (
1778 tooltip => $arg{type}, 1832 tooltip => $arg{type},
1833 can_hover => 1,
1779 can_events => 1, 1834 can_events => 1,
1780 can_hover => 1,
1781 %arg, 1835 %arg,
1782 ); 1836 );
1783 1837
1784 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); 1838 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1785 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 1839 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1957 2011
1958sub new { 2012sub new {
1959 my $class = shift; 2013 my $class = shift;
1960 2014
1961 my $self = $class->SUPER::new ( 2015 my $self = $class->SUPER::new (
1962 fontsize => 1, 2016 fontsize => 1,
2017 can_events => 0,
1963 #font => default_font 2018 #font => default_font
1964 @_, 2019 @_,
1965 2020
1966 layout => (new CFClient::Layout), 2021 layout => (new CFClient::Layout),
1967 par => [], 2022 par => [],
1968 height => 0, 2023 height => 0,
1969 children => [ 2024 children => [
1970 (new CFClient::UI::Empty expand => 1), 2025 (new CFClient::UI::Empty expand => 1),
1971 (new CFClient::UI::Slider vertical => 1), 2026 (new CFClient::UI::Slider vertical => 1),
1972 ], 2027 ],
1973 ); 2028 );
1974 2029
2159 2214
2160sub new { 2215sub new {
2161 my $class = shift; 2216 my $class = shift;
2162 2217
2163 my $self = $class->SUPER::new ( 2218 my $self = $class->SUPER::new (
2164 state => 0, 2219 state => 0,
2165 connect_activate => \&toggle_flopper, 2220 connect_activate => \&toggle_flopper,
2166 can_events => 1,
2167 @_ 2221 @_
2168 ); 2222 );
2169 2223
2170 if ($self->{state}) { 2224 if ($self->{state}) {
2171 $self->{state} = 0; 2225 $self->{state} = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines