updated Cdrom and Event and SDL pods,
[sdlgit/SDL_perl.git] / test / testmenu.pl
CommitLineData
8fde61e3 1#!/usr/bin/env perl
2
3use SDL;
4use SDL::App;
5use SDL::Surface;
6use SDL::Rect;
7use SDL::Event;
8
9my $menu = new SDL::Surface -name => 'data/menu.png';
10
11my $app = new SDL::App -w => $menu->width(), -h => $menu->height(), -resizeable => 1;
12
13my $hilight = new SDL::Surface -name => 'data/highlight.png';
14
15my %menu = (
16 'start' => [ 115, 30, 160, 40 ],
17 'help' => [ 120, 100, 120, 40 ],
18 'giveup' => [ 120, 230, 120, 40 ],
19 'spawnserver' => [ 115, 170, 165, 40 ],
20 'credits' => [ 115, 285, 160, 40 ],
21);
22
23my $needblit;
24sub drawMenu {
25 my ($a,$dx,$dy,$no,$hi,%m) = @_;
26 for (keys %m) {
27 my ($x,$y,$w,$h) = @{$m{$_}};
28 next unless $dx >= $x && $dx <= $x+$w
29 && $dy >= $y && $dy <= $y+$h;
30 unless ($needblit) {
31 my $rect = new SDL::Rect -w => $w, -h => $h,
32 -x => $x, -y => $y;
33 $hi->blit($rect,$a,$rect);
34 $needblit = 1;
35 }
36 return $_;
37 }
38 $no->blit(NULL,$a,NULL) if $needblit;
39 $needblit = 0;
40 return 0;
41}
42
43sub help {
44 print STDERR <<USAGE;
45This should print a help message
46
47USAGE
48
49}
50
51sub credits {
52 print STDERR <<CREDITS;
53David J. Goehrig
54
55CREDITS
56
57}
58
59sub spawnserver {
60 print STDERR <<SPAWN;
61Spawinging new server...
62
63SPAWN
64
65}
66
67sub start {
68 print STDERR <<START;
69This should start the game
70
71START
72
73}
74
75sub giveup {
76 print STDERR <<GIVEUP;
77Giving up
78
79GIVEUP
80
81 exit(0);
82}
83
84my %events = (
85 SDL_MOUSEMOTION() => sub {
86 my ($e) = @_;
87 drawMenu($app,
88 $e->motion_x(),
89 $e->motion_y(),
90 $menu,
91 $hilight,
92 %menu);
93 },
94 SDL_MOUSEBUTTONUP() => sub {
95 my ($e) = @_;
96 my $routine = drawMenu($app,
97 $e->motion_x(),
98 $e->motion_y(),
99 $menu,
100 $hilight,
101 %menu);
102 &{$routine} if ($routine);
103 },
104 SDL_QUIT() => sub { exit(0); },
105 SDL_KEYDOWN() => sub {
106 my ($e) = @_;
107 exit(0) if ($e->key_sym() == SDLK_ESCAPE);
108 },
109);
110
111$menu->blit(NULL,$app,NULL);
112$app->sync();
113$app->loop(\%events);
114
115