-
Notifications
You must be signed in to change notification settings - Fork 4
/
display.hpp
151 lines (139 loc) · 4.3 KB
/
display.hpp
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
** sdl.hh
** Login : <mouret@asuncion.lip6.fr>
** Started on Mon Jan 14 16:42:14 2008 Jean-Baptiste MOURET
** $Id$
**
** Copyright (C) 2008 Jean-Baptiste MOURET
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SDL_HH_
# define SDL_HH_
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <valarray>
#include <stdio.h>
#include <unistd.h>
#ifdef USE_SDL
#include <SDL.h>
#endif
#include "map.hpp"
#include "robot.hpp"
#include <boost/shared_ptr.hpp>
namespace fastsim {
class Display {
public:
#ifdef USE_SDL
Display(const boost::shared_ptr<Map>& m, const Robot& r);
~Display() {
SDL_FreeSurface(_map_bmp);
SDL_FreeSurface(_screen);
SDL_Quit();
}
void update();
void update_map() {
_blit_map();
}
int save_BMP(const char *file) {
return SDL_SaveBMP(_screen,file);
}
#else
Display(const boost::shared_ptr<Map>& m, const Robot& r) : _map(m), _robot(r) {}
~Display() {}
void update() {}
void update_map() {}
int save_BMP(const char *file) { assert(0); }
#endif
protected:
const boost::shared_ptr<Map>& _map;
const Robot& _robot;
#ifdef USE_SDL
void _events();
void _bb_to_sdl(const Robot::BoundingBox& bb,
SDL_Rect *r) {
r->x = (Sint16) _map->real_to_pixel(bb.x);
r->y = (Sint16) _map->real_to_pixel(bb.y);
r->w = (Sint16) _map->real_to_pixel(bb.w);
r->h = (Sint16) _map->real_to_pixel(bb.h);
}
void _quit() {
SDL_Quit();
exit(0);
}
void _put_pixel(SDL_Surface* surf,
Uint32 color, unsigned x, unsigned y) {
if (x >= surf->w || x < 0 || y >= surf->h || y < 0)
return;
Uint32 *bufp = (Uint32*)surf->pixels + y * surf->pitch / 4 + x;
*bufp = color;
}
void _put_pixel(SDL_Surface* surf,
unsigned x, unsigned y,
Uint8 r, Uint8 g, Uint8 b) {
_put_pixel(surf, SDL_MapRGB(surf->format, r, g, b), x, y);
}
void _blit_map();
// used by _circle
void _circle_points(SDL_Surface* surf,
int cx, int cy, int x, int y, Uint32 color);
void _circle(SDL_Surface* surf,
int x_center, int y_center, int radius,
Uint8 r, Uint8 g, Uint8 b) {
_circle(surf, x_center, y_center, radius, SDL_MapRGB(surf->format, r, g, b));
}
void _circle(SDL_Surface* surf,
int x_center, int y_center, int radius,
Uint32 color);
//
void _disc(SDL_Surface* surf,
int x_center, int y_center, int radius,
Uint8 r, Uint8 g, Uint8 b) {
_disc(surf, x_center, y_center, radius, SDL_MapRGB(surf->format, r, g, b));
}
void _disc(SDL_Surface* surf,
int x_center, int y_center, int radius,
Uint32 color);
//
void _line(SDL_Surface* surf, int x0, int y0, int x1, int y1,
Uint8 r, Uint8 g, Uint8 b) {
_line(surf, x0, y0, x1, y1, SDL_MapRGB(surf->format, r, g, b));
}
void _line(SDL_Surface* surf, int x0, int y0, int x1, int y1,
Uint32 color);
void _try_pixel(bool& res,
SDL_Surface* surf,
Uint32 color,
int x, int y);
//
Uint32 _color_from_id(SDL_Surface* surf, int id);
// disp sensor values
void _disp_bb();
void _disp_goals();
void _disp_switches();
void _disp_radars();
void _disp_bumpers();
void _disp_lasers();
void _disp_light_sensors();
void _disp_camera();
//
int _w, _h;
SDL_Surface* _screen, *_map_bmp;
SDL_Rect _prev_bb;
#endif
};
}
#endif /* !SDL_HH_ */