… | |
… | |
21 | $FOCUS->key_up ($_[0]) if $FOCUS; |
21 | $FOCUS->key_up ($_[0]) if $FOCUS; |
22 | } |
22 | } |
23 | |
23 | |
24 | sub feed_sdl_button_down_event { |
24 | sub feed_sdl_button_down_event { |
25 | my ($ev) = @_; |
25 | my ($ev) = @_; |
26 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
26 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
27 | |
27 | |
28 | if (!$BUTTON_STATE) { |
28 | if (!$BUTTON_STATE) { |
29 | my $widget = $ROOT->find_widget ($x, $y); |
29 | my $widget = $ROOT->find_widget ($x, $y); |
30 | |
30 | |
31 | $GRAB = $widget; |
31 | $GRAB = $widget; |
32 | $GRAB->update if $GRAB; |
32 | $GRAB->update if $GRAB; |
33 | } |
33 | } |
34 | |
34 | |
35 | $BUTTON_STATE |= 1 << ($ev->button - 1); |
35 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
36 | |
36 | |
37 | $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
37 | $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
38 | } |
38 | } |
39 | |
39 | |
40 | sub feed_sdl_button_up_event { |
40 | sub feed_sdl_button_up_event { |
41 | my ($ev) = @_; |
41 | my ($ev) = @_; |
42 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
42 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
43 | |
43 | |
44 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
44 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
45 | |
45 | |
46 | $BUTTON_STATE &= ~(1 << ($ev->button - 1)); |
46 | $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); |
47 | |
47 | |
48 | $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
48 | $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
49 | |
49 | |
50 | if (!$BUTTON_STATE) { |
50 | if (!$BUTTON_STATE) { |
51 | my $grab = $GRAB; undef $GRAB; |
51 | my $grab = $GRAB; undef $GRAB; |
… | |
… | |
54 | } |
54 | } |
55 | } |
55 | } |
56 | |
56 | |
57 | sub feed_sdl_motion_event { |
57 | sub feed_sdl_motion_event { |
58 | my ($ev) = @_; |
58 | my ($ev) = @_; |
59 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
59 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
60 | |
60 | |
61 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
61 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
62 | |
62 | |
63 | if ($widget != $HOVER) { |
63 | if ($widget != $HOVER) { |
64 | my $hover = $HOVER; $HOVER = $widget; |
64 | my $hover = $HOVER; $HOVER = $widget; |
… | |
… | |
1111 | |
1111 | |
1112 | package CFClient::UI::EntryBase; |
1112 | package CFClient::UI::EntryBase; |
1113 | |
1113 | |
1114 | our @ISA = CFClient::UI::Label::; |
1114 | our @ISA = CFClient::UI::Label::; |
1115 | |
1115 | |
1116 | use SDL; |
|
|
1117 | use SDL::OpenGL; |
1116 | use SDL::OpenGL; |
1118 | |
1117 | |
1119 | sub new { |
1118 | sub new { |
1120 | my $class = shift; |
1119 | my $class = shift; |
1121 | |
1120 | |
… | |
… | |
1176 | } |
1175 | } |
1177 | |
1176 | |
1178 | sub key_down { |
1177 | sub key_down { |
1179 | my ($self, $ev) = @_; |
1178 | my ($self, $ev) = @_; |
1180 | |
1179 | |
1181 | my $mod = $ev->key_mod; |
1180 | my $mod = $ev->{mod}; |
1182 | my $sym = $ev->key_sym; |
1181 | my $sym = $ev->{sym}; |
1183 | |
|
|
1184 | my $uni = $ev->key_unicode; |
1182 | my $uni = $ev->{unicode}; |
1185 | |
1183 | |
1186 | my $text = $self->get_text; |
1184 | my $text = $self->get_text; |
1187 | |
1185 | |
1188 | if ($sym == SDLK_BACKSPACE) { |
1186 | if ($sym == 8) { |
1189 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1187 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1190 | } elsif ($sym == SDLK_DELETE) { |
1188 | } elsif ($sym == 127) { |
1191 | substr $text, $self->{cursor}, 1, ""; |
1189 | substr $text, $self->{cursor}, 1, ""; |
1192 | } elsif ($sym == SDLK_LEFT) { |
1190 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1193 | --$self->{cursor} if $self->{cursor}; |
1191 | --$self->{cursor} if $self->{cursor}; |
1194 | } elsif ($sym == SDLK_RIGHT) { |
1192 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1195 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1193 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1196 | } elsif ($sym == SDLK_HOME) { |
1194 | } elsif ($sym == CFClient::SDLK_HOME) { |
1197 | $self->{cursor} = 0; |
1195 | $self->{cursor} = 0; |
1198 | } elsif ($sym == SDLK_END) { |
1196 | } elsif ($sym == CFClient::SDLK_END) { |
1199 | $self->{cursor} = length $text; |
1197 | $self->{cursor} = length $text; |
1200 | } elsif ($sym == SDLK_ESCAPE) { |
1198 | } elsif ($sym == 27) { |
1201 | $self->emit ('escape'); |
1199 | $self->emit ('escape'); |
1202 | } elsif ($uni) { |
1200 | } elsif ($uni) { |
1203 | substr $text, $self->{cursor}++, 0, chr $uni; |
1201 | substr $text, $self->{cursor}++, 0, chr $uni; |
1204 | } |
1202 | } |
1205 | |
1203 | |
… | |
… | |
1280 | |
1278 | |
1281 | package CFClient::UI::Entry; |
1279 | package CFClient::UI::Entry; |
1282 | |
1280 | |
1283 | our @ISA = CFClient::UI::EntryBase::; |
1281 | our @ISA = CFClient::UI::EntryBase::; |
1284 | |
1282 | |
1285 | use SDL; |
|
|
1286 | use SDL::OpenGL; |
1283 | use SDL::OpenGL; |
1287 | |
1284 | |
1288 | sub key_down { |
1285 | sub key_down { |
1289 | my ($self, $ev) = @_; |
1286 | my ($self, $ev) = @_; |
1290 | |
1287 | |
1291 | my $sym = $ev->key_sym; |
1288 | my $sym = $ev->{sym}; |
1292 | |
1289 | |
1293 | if ($sym == SDLK_RETURN) { |
1290 | if ($sym == 13) { |
1294 | $self->emit (activate => $self->get_text); |
1291 | $self->emit (activate => $self->get_text); |
1295 | $self->update; |
1292 | $self->update; |
1296 | |
1293 | |
1297 | } else { |
1294 | } else { |
1298 | $self->SUPER::key_down ($ev); |
1295 | $self->SUPER::key_down ($ev); |
… | |
… | |
1304 | |
1301 | |
1305 | package CFClient::UI::Button; |
1302 | package CFClient::UI::Button; |
1306 | |
1303 | |
1307 | our @ISA = CFClient::UI::Label::; |
1304 | our @ISA = CFClient::UI::Label::; |
1308 | |
1305 | |
1309 | use SDL; |
|
|
1310 | use SDL::OpenGL; |
1306 | use SDL::OpenGL; |
1311 | |
1307 | |
1312 | my @tex = |
1308 | my @tex = |
1313 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1309 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1314 | qw(b1_button_active.png); |
1310 | qw(b1_button_active.png); |
… | |
… | |
1368 | |
1364 | |
1369 | my @tex = |
1365 | my @tex = |
1370 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1366 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1371 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1367 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1372 | |
1368 | |
1373 | use SDL; |
|
|
1374 | use SDL::OpenGL; |
1369 | use SDL::OpenGL; |
1375 | |
1370 | |
1376 | sub new { |
1371 | sub new { |
1377 | my $class = shift; |
1372 | my $class = shift; |
1378 | |
1373 | |