File: testmenu.pl

package info (click to toggle)
sdlperl 1.20.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,804 kB
  • ctags: 2,169
  • sloc: perl: 7,397; ansic: 232; makefile: 72; sh: 1
file content (115 lines) | stat: -rwxr-xr-x 1,826 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env perl

use SDL;
use SDL::App;
use SDL::Surface;
use SDL::Rect;
use SDL::Event;

my $menu = new SDL::Surface -name => 'data/menu.png';

my $app = new SDL::App -w => $menu->width(), -h => $menu->height(), -resizeable => 1;

my $hilight = new SDL::Surface -name => 'data/highlight.png';

my %menu = (
	'start' => [ 115, 30, 160, 40 ],
	'help' => [ 120, 100, 120, 40 ],
	'giveup' => [ 120, 230, 120, 40 ],
	'spawnserver' => [ 115, 170, 165, 40 ], 
	'credits' => [ 115, 285, 160, 40 ],
);

my $needblit;
sub drawMenu {
	my ($a,$dx,$dy,$no,$hi,%m) = @_;
	for (keys %m) {
		my ($x,$y,$w,$h) = @{$m{$_}};
		next unless $dx >= $x && $dx <= $x+$w
			 && $dy >= $y && $dy <= $y+$h;
		unless ($needblit) {
			my $rect = new SDL::Rect -w => $w, -h => $h, 
					 -x => $x, -y => $y;
			$hi->blit($rect,$a,$rect);
			$needblit = 1;
		}
		return $_;
	}
	$no->blit(NULL,$a,NULL) if $needblit;
	$needblit = 0;
	return 0;
}

sub help {
	print STDERR <<USAGE;
This should print a help message

USAGE

}

sub credits {
	print STDERR <<CREDITS;
David J. Goehrig

CREDITS

}

sub spawnserver {
	print STDERR <<SPAWN;
Spawinging new server...

SPAWN

}

sub start  {
	print STDERR <<START;
This should start the game

START

}

sub giveup {
	print STDERR <<GIVEUP;
Giving up

GIVEUP

	exit(0);
}

my %events = (
	SDL_MOUSEMOTION() =>  sub {
		my ($e) = @_;
		drawMenu($app,
			 $e->motion_x(),
			 $e->motion_y(),
			 $menu,
			 $hilight,
			 %menu);
	},
	SDL_MOUSEBUTTONUP() => sub {
		my ($e) = @_;
		my $routine = drawMenu($app,
			 $e->motion_x(),
			 $e->motion_y(),
			 $menu,
			 $hilight,
			 %menu);
		&{$routine} if ($routine);
	},
	SDL_QUIT() => sub { exit(0); },
	SDL_KEYDOWN() => sub { 
		my ($e) = @_;
		exit(0) if ($e->key_sym() == SDLK_ESCAPE);
	},
);

$menu->blit(NULL,$app,NULL);
$app->sync();
$app->loop(\%events);