… | |
… | |
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; |
… | |
… | |
87 | |
87 | |
88 | package CFClient::UI::Base; |
88 | package CFClient::UI::Base; |
89 | |
89 | |
90 | use strict; |
90 | use strict; |
91 | |
91 | |
92 | use SDL::OpenGL; |
92 | use CFClient::OpenGL; |
93 | |
93 | |
94 | sub new { |
94 | sub new { |
95 | my $class = shift; |
95 | my $class = shift; |
96 | |
96 | |
97 | my $self = bless { |
97 | my $self = bless { |
… | |
… | |
324 | package CFClient::UI::DrawBG; |
324 | package CFClient::UI::DrawBG; |
325 | |
325 | |
326 | our @ISA = CFClient::UI::Base::; |
326 | our @ISA = CFClient::UI::Base::; |
327 | |
327 | |
328 | use strict; |
328 | use strict; |
329 | use SDL::OpenGL; |
329 | use CFClient::OpenGL; |
330 | |
330 | |
331 | sub new { |
331 | sub new { |
332 | my $class = shift; |
332 | my $class = shift; |
333 | |
333 | |
334 | # range [value, low, high, page] |
334 | # range [value, low, high, page] |
… | |
… | |
482 | |
482 | |
483 | package CFClient::UI::Window; |
483 | package CFClient::UI::Window; |
484 | |
484 | |
485 | our @ISA = CFClient::UI::Bin::; |
485 | our @ISA = CFClient::UI::Bin::; |
486 | |
486 | |
487 | use SDL::OpenGL; |
487 | use CFClient::OpenGL; |
488 | |
488 | |
489 | sub new { |
489 | sub new { |
490 | my ($class, %arg) = @_; |
490 | my ($class, %arg) = @_; |
491 | |
491 | |
492 | my $self = $class->SUPER::new (%arg); |
492 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
565 | |
565 | |
566 | package CFClient::UI::Frame; |
566 | package CFClient::UI::Frame; |
567 | |
567 | |
568 | our @ISA = CFClient::UI::Bin::; |
568 | our @ISA = CFClient::UI::Bin::; |
569 | |
569 | |
570 | use SDL::OpenGL; |
570 | use CFClient::OpenGL; |
571 | |
571 | |
572 | sub size_request { |
572 | sub size_request { |
573 | my ($self) = @_; |
573 | my ($self) = @_; |
574 | my $chld = $self->child |
574 | my $chld = $self->child |
575 | or return (0, 0); |
575 | or return (0, 0); |
… | |
… | |
607 | |
607 | |
608 | package CFClient::UI::FancyFrame; |
608 | package CFClient::UI::FancyFrame; |
609 | |
609 | |
610 | our @ISA = CFClient::UI::Bin::; |
610 | our @ISA = CFClient::UI::Bin::; |
611 | |
611 | |
612 | use SDL::OpenGL; |
612 | use CFClient::OpenGL; |
613 | |
613 | |
614 | my @tex = |
614 | my @tex = |
615 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
615 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
616 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
616 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
617 | |
617 | |
… | |
… | |
748 | |
748 | |
749 | our @ISA = CFClient::UI::Base::; |
749 | our @ISA = CFClient::UI::Base::; |
750 | |
750 | |
751 | use List::Util qw(max sum); |
751 | use List::Util qw(max sum); |
752 | |
752 | |
753 | use SDL::OpenGL; |
753 | use CFClient::OpenGL; |
754 | |
754 | |
755 | sub new { |
755 | sub new { |
756 | my $class = shift; |
756 | my $class = shift; |
757 | |
757 | |
758 | $class->SUPER::new ( |
758 | $class->SUPER::new ( |
… | |
… | |
999 | |
999 | |
1000 | package CFClient::UI::Label; |
1000 | package CFClient::UI::Label; |
1001 | |
1001 | |
1002 | our @ISA = CFClient::UI::Base::; |
1002 | our @ISA = CFClient::UI::Base::; |
1003 | |
1003 | |
1004 | use SDL::OpenGL; |
1004 | use CFClient::OpenGL; |
1005 | |
1005 | |
1006 | sub new { |
1006 | sub new { |
1007 | my ($class, %arg) = @_; |
1007 | my ($class, %arg) = @_; |
1008 | |
1008 | |
1009 | my $self = $class->SUPER::new ( |
1009 | my $self = $class->SUPER::new ( |
… | |
… | |
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; |
1116 | use CFClient::OpenGL; |
1117 | use SDL::OpenGL; |
|
|
1118 | |
1117 | |
1119 | sub new { |
1118 | sub new { |
1120 | my $class = shift; |
1119 | my $class = shift; |
1121 | |
1120 | |
1122 | $class->SUPER::new ( |
1121 | $class->SUPER::new ( |
… | |
… | |
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; |
1283 | use CFClient::OpenGL; |
1286 | 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; |
1306 | use CFClient::OpenGL; |
1310 | 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); |
1315 | |
1311 | |
… | |
… | |
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; |
1369 | use CFClient::OpenGL; |
1374 | use SDL::OpenGL; |
|
|
1375 | |
1370 | |
1376 | sub new { |
1371 | sub new { |
1377 | my $class = shift; |
1372 | my $class = shift; |
1378 | |
1373 | |
1379 | $class->SUPER::new ( |
1374 | $class->SUPER::new ( |
… | |
… | |
1429 | |
1424 | |
1430 | package CFClient::UI::VGauge; |
1425 | package CFClient::UI::VGauge; |
1431 | |
1426 | |
1432 | our @ISA = CFClient::UI::Base::; |
1427 | our @ISA = CFClient::UI::Base::; |
1433 | |
1428 | |
1434 | use SDL::OpenGL; |
1429 | use CFClient::OpenGL; |
1435 | |
1430 | |
1436 | my %tex = ( |
1431 | my %tex = ( |
1437 | food => [ |
1432 | food => [ |
1438 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1433 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1439 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
1434 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
… | |
… | |
1536 | |
1531 | |
1537 | package CFClient::UI::Slider; |
1532 | package CFClient::UI::Slider; |
1538 | |
1533 | |
1539 | use strict; |
1534 | use strict; |
1540 | |
1535 | |
1541 | use SDL::OpenGL; |
1536 | use CFClient::OpenGL; |
1542 | |
1537 | |
1543 | our @ISA = CFClient::UI::DrawBG::; |
1538 | our @ISA = CFClient::UI::DrawBG::; |
1544 | |
1539 | |
1545 | my @tex = |
1540 | my @tex = |
1546 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1541 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1671 | |
1666 | |
1672 | package CFClient::UI::TextView; |
1667 | package CFClient::UI::TextView; |
1673 | |
1668 | |
1674 | our @ISA = CFClient::UI::HBox::; |
1669 | our @ISA = CFClient::UI::HBox::; |
1675 | |
1670 | |
1676 | use SDL::OpenGL; |
1671 | use CFClient::OpenGL; |
1677 | |
1672 | |
1678 | sub new { |
1673 | sub new { |
1679 | my $class = shift; |
1674 | my $class = shift; |
1680 | |
1675 | |
1681 | my $self = $class->SUPER::new ( |
1676 | my $self = $class->SUPER::new ( |
… | |
… | |
1827 | |
1822 | |
1828 | ############################################################################# |
1823 | ############################################################################# |
1829 | |
1824 | |
1830 | package CFClient::UI::Animator; |
1825 | package CFClient::UI::Animator; |
1831 | |
1826 | |
1832 | use SDL::OpenGL; |
1827 | use CFClient::OpenGL; |
1833 | |
1828 | |
1834 | our @ISA = CFClient::UI::Bin::; |
1829 | our @ISA = CFClient::UI::Bin::; |
1835 | |
1830 | |
1836 | sub moveto { |
1831 | sub moveto { |
1837 | my ($self, $x, $y) = @_; |
1832 | my ($self, $x, $y) = @_; |
… | |
… | |
1910 | |
1905 | |
1911 | package CFClient::UI::Root; |
1906 | package CFClient::UI::Root; |
1912 | |
1907 | |
1913 | our @ISA = CFClient::UI::Container::; |
1908 | our @ISA = CFClient::UI::Container::; |
1914 | |
1909 | |
1915 | use SDL::OpenGL; |
1910 | use CFClient::OpenGL; |
1916 | |
1911 | |
1917 | sub check_size { |
1912 | sub check_size { |
1918 | my ($self) = @_; |
1913 | my ($self) = @_; |
1919 | |
1914 | |
1920 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
1915 | $self->configure (0, 0, $::WITH, $::HEIGHT); |