-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgui.h
180 lines (153 loc) · 5 KB
/
gui.h
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#ifndef GUI_H
#define GUI_H
#include <pthread.h>
#include <AL/al.h>
#include <AL/alut.h>
#include "types.h"
#include "path.h"
#include "random.h"
#include "tower.h"
#include "enemy.h"
#include "player.h"
#include "io_bitmap.h"
#include "game_event.h"
// GUI's version of game state
typedef struct str_gstate_t {
u64b_t time; // Current time
player_t player; // Current player
enemy_t *enemies; // Array of enemies
u32b_t nenemies; // Number of enemies
u32b_t senemies; // Size of enemy array
path_t *path; // Path the enemies follow
u64b_t wave; // Enemy wave number
rnd_t random; // Random number generator state
io_bitmap_t terrain; // Heightmap for the floor / terrain
} gstate_t;
// GUI's internal (non-"game") state
typedef struct str_guistate_t {
u32b_t mouse_item_ndx; // Current item "held" by the mouse
vector3_t hand_pos; // Last position of mouse / hand
vector3_t enemy_hit_pos; // Where the enemy hit the player
vector3_t enemy_hit_color; // Color of the enemy who hit
} guistate_t;
////////////////////////////////////////////////////////////
// For GUI and widget files
////////////////////////////////////////////////////////////
#ifdef GUI_WIDGET
#include <X11/Xlib.h>
#include <GL/glx.h>
#include <GL/gl.h>
// Mouse button codes
#define MOUSE_LEFT 1
#define MOUSE_MIDDLE 2
#define MOUSE_RIGHT 3
#define MOUSE_UP 4
#define MOUSE_DOWN 5
// key and keycode
// These are probably machine + OS/xwindows specific
#define BACKSPACE 8 // Key
#define ESCAPE 27
#define ENTER 13
#define PAGEUP 99 // Keycode
#define PAGEDOWN 105
#define UP 98
#define DOWN 104
#define LEFT 100
#define RIGHT 102
#define F1 67
#define F2 68
#define F3 69
#define F4 70
#define F5 71
#define F6 72
#define F7 73
#define F8 74
#define F9 75
#define F10 76
#define F11 95
#define F12 96
// Defines a min/max distance the cursor needs to be away from an object
// to select it
#define MIN_SELECT_DIST 10.0
#define MAX_SELECT_DIST 100.0
#define ISCLOSE(d) ((d) <= MIN_SELECT_DIST ? 1:0)
#define ISFAR(d) ((d) <= MAX_SELECT_DIST ? 1:0)
// Holds what is needed to manage an opengl enabled window
typedef struct {
Display *dpy;
int screen;
Window win;
GLXContext ctx;
XSetWindowAttributes attr;
int x, y;
unsigned int width, height;
unsigned int pwidth, pheight;
unsigned int depth;
GLuint font;
int id;
} glwindow_t;
// Widget types and callbacks
typedef struct st_widget widget_t;
typedef void (*cbktick_t) (widget_t *w);
typedef void (*cbkdraw_t) (widget_t *w);
typedef void (*cbkkeypress_t) (widget_t *w, char key, unsigned int keycode);
typedef void (*cbkmousedown_t) (widget_t *w, int x, int y, int b);
typedef void (*cbkmouseup_t) (widget_t *w, int x, int y, int b);
typedef void (*cbkmousemove_t) (widget_t *w, int x, int y);
struct st_widget {
glwindow_t *glw; // Window information
float x; // x-pos
float y; // y-pos
float w; // width
float h; // height
cbkdraw_t draw; //
cbkkeypress_t keypress; //
cbkmousedown_t mousedown; // Event callbacks
cbkmouseup_t mouseup; //
cbkmousemove_t mousemove; //
cbktick_t tick; //
int update; // Update request flag
void *wd; // Custom widget data
};
#endif
////////////////////////////////////////////////////////////
// For files other than gui.c
////////////////////////////////////////////////////////////
#ifndef GUI_C
#ifdef CHROMO_CRAFT_C
// These are intended for the simulation to start/update the gui
extern int StartGUI(char *version, gstate_t *s);
extern void UpdateGuiState(gstate_t *s);
#endif // !GUI_WIDGET
// These are intended for use by widgets / gui subcomponents
#ifdef GUI_WIDGET
extern guistate_t GuiState;
extern gstate_t *Stateg,*Statec,*Statep;
extern pthread_mutex_t StateLock;
extern void printGLf(GLuint font, const char *fmt, ...);
extern u32b_t LoadTexture(char *fn);
extern void ViewPort3D(int x, int y, int w, int h);
extern void ViewPort2D(glwindow_t *glw);
extern void Cyan();
extern void Yellow();
extern void Red();
extern void Purple();
extern void Blue();
extern void White();
extern void Green();
extern void Black();
extern float ScaleX(widget_t *w, const float x);
extern float ScaleY(widget_t *w, const float y);
extern void GuiExit();
#define NUM_SOURCES 5
#define NUM_BUFFERS 5
extern ALuint al_buffers[NUM_BUFFERS];
extern ALuint al_sources[NUM_SOURCES];
#define AL_MUSIC al_sources[0]
#define AL_FIRE al_sources[1]
#define AL_KILL al_sources[2]
#define AL_TRIUMPH al_sources[3]
#define AL_FAILURE al_sources[4]
#endif // GUI_WIDGET
#endif // !GUI_C
#endif // !GUI_H