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.140 by root, Thu Apr 20 04:20:52 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 {
148sub configure { 148sub configure {
149 my ($self, $x, $y, $w, $h) = @_; 149 my ($self, $x, $y, $w, $h) = @_;
150 150
151 $self->{x} = $x; 151 $self->{x} = $x;
152 $self->{y} = $y; 152 $self->{y} = $y;
153
154 if ($self->{aspect}) {
155 $w = List::Util::min $w, int $h * $self->{aspect};
156 $h = List::Util::min $h, int $w / $self->{aspect};
157 }
153 158
154 return unless $self->{w} != $w || $self->{h} != $h; 159 return unless $self->{w} != $w || $self->{h} != $h;
155 160
156 $self->{w} = $w; 161 $self->{w} = $w;
157 $self->{h} = $h; 162 $self->{h} = $h;
324package CFClient::UI::DrawBG; 329package CFClient::UI::DrawBG;
325 330
326our @ISA = CFClient::UI::Base::; 331our @ISA = CFClient::UI::Base::;
327 332
328use strict; 333use strict;
329use SDL::OpenGL; 334use CFClient::OpenGL;
330 335
331sub new { 336sub new {
332 my $class = shift; 337 my $class = shift;
333 338
334 # range [value, low, high, page] 339 # range [value, low, high, page]
482 487
483package CFClient::UI::Window; 488package CFClient::UI::Window;
484 489
485our @ISA = CFClient::UI::Bin::; 490our @ISA = CFClient::UI::Bin::;
486 491
487use SDL::OpenGL; 492use CFClient::OpenGL;
488 493
489sub new { 494sub new {
490 my ($class, %arg) = @_; 495 my ($class, %arg) = @_;
491 496
492 my $self = $class->SUPER::new (%arg); 497 my $self = $class->SUPER::new (%arg);
565 570
566package CFClient::UI::Frame; 571package CFClient::UI::Frame;
567 572
568our @ISA = CFClient::UI::Bin::; 573our @ISA = CFClient::UI::Bin::;
569 574
570use SDL::OpenGL; 575use CFClient::OpenGL;
571 576
572sub size_request { 577sub size_request {
573 my ($self) = @_; 578 my ($self) = @_;
574 my $chld = $self->child 579 my $chld = $self->child
575 or return (0, 0); 580 or return (0, 0);
607 612
608package CFClient::UI::FancyFrame; 613package CFClient::UI::FancyFrame;
609 614
610our @ISA = CFClient::UI::Bin::; 615our @ISA = CFClient::UI::Bin::;
611 616
612use SDL::OpenGL; 617use CFClient::OpenGL;
613 618
614my @tex = 619my @tex =
615 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 620 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); 621 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
617 622
660 my $border = $self->border; 665 my $border = $self->border;
661 666
662 if ($x < $self->{w} && $x >= $self->{w} - $border 667 if ($x < $self->{w} && $x >= $self->{w} - $border
663 && $y < $self->{h} && $y >= $self->{h} - $border) { 668 && $y < $self->{h} && $y >= $self->{h} - $border) {
664 669
665 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 670 my ($ox, $oy) = ($ev->{x}, $ev->{y});
666 my ($bw, $bh) = ($self->{w}, $self->{h}); 671 my ($bw, $bh) = ($self->{w}, $self->{h});
667 672
668 $self->{motion} = sub { 673 $self->{motion} = sub {
669 my ($ev, $x, $y) = @_; 674 my ($ev, $x, $y) = @_;
670 675
671 ($x, $y) = ($ev->motion_x, $ev->motion_y); 676 ($x, $y) = ($ev->{x}, $ev->{y});
672 677
673 $self->{user_w} = $bw + $x - $ox; 678 $self->{user_w} = $bw + $x - $ox;
674 $self->{user_h} = $bh + $y - $oy; 679 $self->{user_h} = $bh + $y - $oy;
675 $self->check_size; 680 $self->check_size;
676 }; 681 };
677 682
678 } elsif ($x >= 0 && $x < $self->{w} 683 } elsif ($x >= 0 && $x < $self->{w}
679 && $y >= 0 && $y < $border) { 684 && $y >= 0 && $y < $border) {
680 685
681 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 686 my ($ox, $oy) = ($ev->{x}, $ev->{y});
682 my ($bx, $by) = ($self->{x}, $self->{y}); 687 my ($bx, $by) = ($self->{x}, $self->{y});
683 688
684 $self->{motion} = sub { 689 $self->{motion} = sub {
685 my ($ev, $x, $y) = @_; 690 my ($ev, $x, $y) = @_;
686 691
687 ($x, $y) = ($ev->motion_x, $ev->motion_y); 692 ($x, $y) = ($ev->{x}, $ev->{y});
688 693
689 $self->move ($bx + $x - $ox, $by + $y - $oy); 694 $self->move ($bx + $x - $ox, $by + $y - $oy);
690 $self->update; 695 $self->update;
691 }; 696 };
692 } 697 }
748 753
749our @ISA = CFClient::UI::Base::; 754our @ISA = CFClient::UI::Base::;
750 755
751use List::Util qw(max sum); 756use List::Util qw(max sum);
752 757
753use SDL::OpenGL; 758use CFClient::OpenGL;
754 759
755sub new { 760sub new {
756 my $class = shift; 761 my $class = shift;
757 762
758 $class->SUPER::new ( 763 $class->SUPER::new (
999 1004
1000package CFClient::UI::Label; 1005package CFClient::UI::Label;
1001 1006
1002our @ISA = CFClient::UI::Base::; 1007our @ISA = CFClient::UI::Base::;
1003 1008
1004use SDL::OpenGL; 1009use CFClient::OpenGL;
1005 1010
1006sub new { 1011sub new {
1007 my ($class, %arg) = @_; 1012 my ($class, %arg) = @_;
1008 1013
1009 my $self = $class->SUPER::new ( 1014 my $self = $class->SUPER::new (
1111 1116
1112package CFClient::UI::EntryBase; 1117package CFClient::UI::EntryBase;
1113 1118
1114our @ISA = CFClient::UI::Label::; 1119our @ISA = CFClient::UI::Label::;
1115 1120
1116use SDL; 1121use CFClient::OpenGL;
1117use SDL::OpenGL;
1118 1122
1119sub new { 1123sub new {
1120 my $class = shift; 1124 my $class = shift;
1121 1125
1122 $class->SUPER::new ( 1126 $class->SUPER::new (
1176} 1180}
1177 1181
1178sub key_down { 1182sub key_down {
1179 my ($self, $ev) = @_; 1183 my ($self, $ev) = @_;
1180 1184
1181 my $mod = $ev->key_mod; 1185 my $mod = $ev->{mod};
1182 my $sym = $ev->key_sym; 1186 my $sym = $ev->{sym};
1183
1184 my $uni = $ev->key_unicode; 1187 my $uni = $ev->{unicode};
1185 1188
1186 my $text = $self->get_text; 1189 my $text = $self->get_text;
1187 1190
1188 if ($sym == SDLK_BACKSPACE) { 1191 if ($sym == 8) {
1189 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1192 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1190 } elsif ($sym == SDLK_DELETE) { 1193 } elsif ($sym == 127) {
1191 substr $text, $self->{cursor}, 1, ""; 1194 substr $text, $self->{cursor}, 1, "";
1192 } elsif ($sym == SDLK_LEFT) { 1195 } elsif ($sym == CFClient::SDLK_LEFT) {
1193 --$self->{cursor} if $self->{cursor}; 1196 --$self->{cursor} if $self->{cursor};
1194 } elsif ($sym == SDLK_RIGHT) { 1197 } elsif ($sym == CFClient::SDLK_RIGHT) {
1195 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1198 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1196 } elsif ($sym == SDLK_HOME) { 1199 } elsif ($sym == CFClient::SDLK_HOME) {
1197 $self->{cursor} = 0; 1200 $self->{cursor} = 0;
1198 } elsif ($sym == SDLK_END) { 1201 } elsif ($sym == CFClient::SDLK_END) {
1199 $self->{cursor} = length $text; 1202 $self->{cursor} = length $text;
1200 } elsif ($sym == SDLK_ESCAPE) { 1203 } elsif ($sym == 27) {
1201 $self->emit ('escape'); 1204 $self->emit ('escape');
1202 } elsif ($uni) { 1205 } elsif ($uni) {
1203 substr $text, $self->{cursor}++, 0, chr $uni; 1206 substr $text, $self->{cursor}++, 0, chr $uni;
1204 } 1207 }
1205 1208
1280 1283
1281package CFClient::UI::Entry; 1284package CFClient::UI::Entry;
1282 1285
1283our @ISA = CFClient::UI::EntryBase::; 1286our @ISA = CFClient::UI::EntryBase::;
1284 1287
1285use SDL; 1288use CFClient::OpenGL;
1286use SDL::OpenGL;
1287 1289
1288sub key_down { 1290sub key_down {
1289 my ($self, $ev) = @_; 1291 my ($self, $ev) = @_;
1290 1292
1291 my $sym = $ev->key_sym; 1293 my $sym = $ev->{sym};
1292 1294
1293 if ($sym == SDLK_RETURN) { 1295 if ($sym == 13) {
1294 $self->emit (activate => $self->get_text); 1296 $self->emit (activate => $self->get_text);
1295 $self->update; 1297 $self->update;
1296 1298
1297 } else { 1299 } else {
1298 $self->SUPER::key_down ($ev); 1300 $self->SUPER::key_down ($ev);
1304 1306
1305package CFClient::UI::Button; 1307package CFClient::UI::Button;
1306 1308
1307our @ISA = CFClient::UI::Label::; 1309our @ISA = CFClient::UI::Label::;
1308 1310
1309use SDL; 1311use CFClient::OpenGL;
1310use SDL::OpenGL;
1311 1312
1312my @tex = 1313my @tex =
1313 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1314 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1314 qw(b1_button_active.png); 1315 qw(b1_button_active.png);
1315 1316
1368 1369
1369my @tex = 1370my @tex =
1370 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1371 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1371 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1372 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1372 1373
1373use SDL; 1374use CFClient::OpenGL;
1374use SDL::OpenGL;
1375 1375
1376sub new { 1376sub new {
1377 my $class = shift; 1377 my $class = shift;
1378 1378
1379 $class->SUPER::new ( 1379 $class->SUPER::new (
1429 1429
1430package CFClient::UI::VGauge; 1430package CFClient::UI::VGauge;
1431 1431
1432our @ISA = CFClient::UI::Base::; 1432our @ISA = CFClient::UI::Base::;
1433 1433
1434use SDL::OpenGL; 1434use CFClient::OpenGL;
1435 1435
1436my %tex = ( 1436my %tex = (
1437 food => [ 1437 food => [
1438 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1438 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1439 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1439 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1454 1454
1455# eg. VGauge->new (gauge => 'food'), default gauge: food 1455# eg. VGauge->new (gauge => 'food'), default gauge: food
1456sub new { 1456sub new {
1457 my $class = shift; 1457 my $class = shift;
1458 1458
1459 my $self = $class->SUPER::new (gauge => 'food', @_); 1459 my $self = $class->SUPER::new (
1460 gauge => 'food',
1461 @_
1462 );
1463
1464 $self->{aspect} = $tex{$self->{gauge}}[0]{w} / $tex{$self->{gauge}}[0]{h};
1460 1465
1461 $self 1466 $self
1462} 1467}
1463 1468
1464sub size_request { 1469sub size_request {
1536 1541
1537package CFClient::UI::Slider; 1542package CFClient::UI::Slider;
1538 1543
1539use strict; 1544use strict;
1540 1545
1541use SDL::OpenGL; 1546use CFClient::OpenGL;
1542 1547
1543our @ISA = CFClient::UI::DrawBG::; 1548our @ISA = CFClient::UI::DrawBG::;
1544 1549
1545my @tex = 1550my @tex =
1546 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1551 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1671 1676
1672package CFClient::UI::TextView; 1677package CFClient::UI::TextView;
1673 1678
1674our @ISA = CFClient::UI::HBox::; 1679our @ISA = CFClient::UI::HBox::;
1675 1680
1676use SDL::OpenGL; 1681use CFClient::OpenGL;
1677 1682
1678sub new { 1683sub new {
1679 my $class = shift; 1684 my $class = shift;
1680 1685
1681 my $self = $class->SUPER::new ( 1686 my $self = $class->SUPER::new (
1827 1832
1828############################################################################# 1833#############################################################################
1829 1834
1830package CFClient::UI::Animator; 1835package CFClient::UI::Animator;
1831 1836
1832use SDL::OpenGL; 1837use CFClient::OpenGL;
1833 1838
1834our @ISA = CFClient::UI::Bin::; 1839our @ISA = CFClient::UI::Bin::;
1835 1840
1836sub moveto { 1841sub moveto {
1837 my ($self, $x, $y) = @_; 1842 my ($self, $x, $y) = @_;
1910 1915
1911package CFClient::UI::Root; 1916package CFClient::UI::Root;
1912 1917
1913our @ISA = CFClient::UI::Container::; 1918our @ISA = CFClient::UI::Container::;
1914 1919
1915use SDL::OpenGL; 1920use CFClient::OpenGL;
1916 1921
1917sub check_size { 1922sub check_size {
1918 my ($self) = @_; 1923 my ($self) = @_;
1919 1924
1920 $self->configure (0, 0, $::WITH, $::HEIGHT); 1925 $self->configure (0, 0, $::WITH, $::HEIGHT);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines