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.135 by root, Wed Apr 19 06:21:07 2006 UTC vs.
Revision 1.139 by root, Wed Apr 19 23:55:58 2006 UTC

21 $FOCUS->key_up ($_[0]) if $FOCUS; 21 $FOCUS->key_up ($_[0]) if $FOCUS;
22} 22}
23 23
24sub feed_sdl_button_down_event { 24sub 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
40sub feed_sdl_button_up_event { 40sub 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
57sub feed_sdl_motion_event { 57sub 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
88package CFClient::UI::Base; 88package CFClient::UI::Base;
89 89
90use strict; 90use strict;
91 91
92use SDL::OpenGL; 92use CFClient::OpenGL;
93 93
94sub new { 94sub new {
95 my $class = shift; 95 my $class = shift;
96 96
97 my $self = bless { 97 my $self = bless {
324package CFClient::UI::DrawBG; 324package CFClient::UI::DrawBG;
325 325
326our @ISA = CFClient::UI::Base::; 326our @ISA = CFClient::UI::Base::;
327 327
328use strict; 328use strict;
329use SDL::OpenGL; 329use CFClient::OpenGL;
330 330
331sub new { 331sub 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
483package CFClient::UI::Window; 483package CFClient::UI::Window;
484 484
485our @ISA = CFClient::UI::Bin::; 485our @ISA = CFClient::UI::Bin::;
486 486
487use SDL::OpenGL; 487use CFClient::OpenGL;
488 488
489sub new { 489sub 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
566package CFClient::UI::Frame; 566package CFClient::UI::Frame;
567 567
568our @ISA = CFClient::UI::Bin::; 568our @ISA = CFClient::UI::Bin::;
569 569
570use SDL::OpenGL; 570use CFClient::OpenGL;
571 571
572sub size_request { 572sub 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
608package CFClient::UI::FancyFrame; 608package CFClient::UI::FancyFrame;
609 609
610our @ISA = CFClient::UI::Bin::; 610our @ISA = CFClient::UI::Bin::;
611 611
612use SDL::OpenGL; 612use CFClient::OpenGL;
613 613
614my @tex = 614my @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
660 my $border = $self->border; 660 my $border = $self->border;
661 661
662 if ($x < $self->{w} && $x >= $self->{w} - $border 662 if ($x < $self->{w} && $x >= $self->{w} - $border
663 && $y < $self->{h} && $y >= $self->{h} - $border) { 663 && $y < $self->{h} && $y >= $self->{h} - $border) {
664 664
665 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 665 my ($ox, $oy) = ($ev->{x}, $ev->{y});
666 my ($bw, $bh) = ($self->{w}, $self->{h}); 666 my ($bw, $bh) = ($self->{w}, $self->{h});
667 667
668 $self->{motion} = sub { 668 $self->{motion} = sub {
669 my ($ev, $x, $y) = @_; 669 my ($ev, $x, $y) = @_;
670 670
671 ($x, $y) = ($ev->motion_x, $ev->motion_y); 671 ($x, $y) = ($ev->{x}, $ev->{y});
672 672
673 $self->{user_w} = $bw + $x - $ox; 673 $self->{user_w} = $bw + $x - $ox;
674 $self->{user_h} = $bh + $y - $oy; 674 $self->{user_h} = $bh + $y - $oy;
675 $self->check_size; 675 $self->check_size;
676 }; 676 };
677 677
678 } elsif ($x >= 0 && $x < $self->{w} 678 } elsif ($x >= 0 && $x < $self->{w}
679 && $y >= 0 && $y < $border) { 679 && $y >= 0 && $y < $border) {
680 680
681 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 681 my ($ox, $oy) = ($ev->{x}, $ev->{y});
682 my ($bx, $by) = ($self->{x}, $self->{y}); 682 my ($bx, $by) = ($self->{x}, $self->{y});
683 683
684 $self->{motion} = sub { 684 $self->{motion} = sub {
685 my ($ev, $x, $y) = @_; 685 my ($ev, $x, $y) = @_;
686 686
687 ($x, $y) = ($ev->motion_x, $ev->motion_y); 687 ($x, $y) = ($ev->{x}, $ev->{y});
688 688
689 $self->move ($bx + $x - $ox, $by + $y - $oy); 689 $self->move ($bx + $x - $ox, $by + $y - $oy);
690 $self->update; 690 $self->update;
691 }; 691 };
692 } 692 }
748 748
749our @ISA = CFClient::UI::Base::; 749our @ISA = CFClient::UI::Base::;
750 750
751use List::Util qw(max sum); 751use List::Util qw(max sum);
752 752
753use SDL::OpenGL; 753use CFClient::OpenGL;
754 754
755sub new { 755sub new {
756 my $class = shift; 756 my $class = shift;
757 757
758 $class->SUPER::new ( 758 $class->SUPER::new (
999 999
1000package CFClient::UI::Label; 1000package CFClient::UI::Label;
1001 1001
1002our @ISA = CFClient::UI::Base::; 1002our @ISA = CFClient::UI::Base::;
1003 1003
1004use SDL::OpenGL; 1004use CFClient::OpenGL;
1005 1005
1006sub new { 1006sub 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
1112package CFClient::UI::EntryBase; 1112package CFClient::UI::EntryBase;
1113 1113
1114our @ISA = CFClient::UI::Label::; 1114our @ISA = CFClient::UI::Label::;
1115 1115
1116use SDL; 1116use CFClient::OpenGL;
1117use SDL::OpenGL;
1118 1117
1119sub new { 1118sub new {
1120 my $class = shift; 1119 my $class = shift;
1121 1120
1122 $class->SUPER::new ( 1121 $class->SUPER::new (
1176} 1175}
1177 1176
1178sub key_down { 1177sub 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
1281package CFClient::UI::Entry; 1279package CFClient::UI::Entry;
1282 1280
1283our @ISA = CFClient::UI::EntryBase::; 1281our @ISA = CFClient::UI::EntryBase::;
1284 1282
1285use SDL; 1283use CFClient::OpenGL;
1286use SDL::OpenGL;
1287 1284
1288sub key_down { 1285sub 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
1305package CFClient::UI::Button; 1302package CFClient::UI::Button;
1306 1303
1307our @ISA = CFClient::UI::Label::; 1304our @ISA = CFClient::UI::Label::;
1308 1305
1309use SDL; 1306use CFClient::OpenGL;
1310use SDL::OpenGL;
1311 1307
1312my @tex = 1308my @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
1369my @tex = 1365my @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
1373use SDL; 1369use CFClient::OpenGL;
1374use SDL::OpenGL;
1375 1370
1376sub new { 1371sub new {
1377 my $class = shift; 1372 my $class = shift;
1378 1373
1379 $class->SUPER::new ( 1374 $class->SUPER::new (
1429 1424
1430package CFClient::UI::VGauge; 1425package CFClient::UI::VGauge;
1431 1426
1432our @ISA = CFClient::UI::Base::; 1427our @ISA = CFClient::UI::Base::;
1433 1428
1434use SDL::OpenGL; 1429use CFClient::OpenGL;
1435 1430
1436my %tex = ( 1431my %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
1537package CFClient::UI::Slider; 1532package CFClient::UI::Slider;
1538 1533
1539use strict; 1534use strict;
1540 1535
1541use SDL::OpenGL; 1536use CFClient::OpenGL;
1542 1537
1543our @ISA = CFClient::UI::DrawBG::; 1538our @ISA = CFClient::UI::DrawBG::;
1544 1539
1545my @tex = 1540my @tex =
1546 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1541 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1671 1666
1672package CFClient::UI::TextView; 1667package CFClient::UI::TextView;
1673 1668
1674our @ISA = CFClient::UI::HBox::; 1669our @ISA = CFClient::UI::HBox::;
1675 1670
1676use SDL::OpenGL; 1671use CFClient::OpenGL;
1677 1672
1678sub new { 1673sub 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
1830package CFClient::UI::Animator; 1825package CFClient::UI::Animator;
1831 1826
1832use SDL::OpenGL; 1827use CFClient::OpenGL;
1833 1828
1834our @ISA = CFClient::UI::Bin::; 1829our @ISA = CFClient::UI::Bin::;
1835 1830
1836sub moveto { 1831sub moveto {
1837 my ($self, $x, $y) = @_; 1832 my ($self, $x, $y) = @_;
1910 1905
1911package CFClient::UI::Root; 1906package CFClient::UI::Root;
1912 1907
1913our @ISA = CFClient::UI::Container::; 1908our @ISA = CFClient::UI::Container::;
1914 1909
1915use SDL::OpenGL; 1910use CFClient::OpenGL;
1916 1911
1917sub check_size { 1912sub check_size {
1918 my ($self) = @_; 1913 my ($self) = @_;
1919 1914
1920 $self->configure (0, 0, $::WITH, $::HEIGHT); 1915 $self->configure (0, 0, $::WITH, $::HEIGHT);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines