Repository navigation
Expand file tree
/
Copy pathinter.h
More file actions
342 lines (318 loc) · 8.47 KB
/
Copy pathinter.h
File metadata and controls
342 lines (318 loc) · 8.47 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/* -*- Mode: C++; c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil -*-
*
* Quadra, an action puzzle game
* Copyright (C) 1998-2000 Ludus Design
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HEADER_INTER
#define HEADER_INTER
#include <set>
#include <stdint.h>
#include <vector>
#include "SDL.h"
#include "error.h"
#include "types.h"
#include "video.h"
#include "bitmap.h"
#include "sprite.h"
class Zone;
class Inter;
class Inter {
Zone* in;
int first_zone;
static int last_mouse_x, last_mouse_y;
static bool kb_visible;
int kb_x, kb_y, kb_anim;
bool kb_active;
int double_click_delay;
Zone *double_clicked_first;
std::set<SDL_Scancode> kb_keys;
Zone *kb_focus;
Zone *kb_find_upmost();
Zone *kb_find_downmost();
Zone *kb_find_down();
Zone *kb_find_up();
Zone *kb_find_left();
Zone *kb_find_right();
Zone *kb_find_closest();
Zone *kb_find_next();
Zone *kb_find_prev();
void kb_draw_focus();
void de_tag(Zone *z);
void tag(Zone *z);
bool kb_check_key(SDL_Keycode i) const;
public:
Font* font;
bool del_font;
std::vector<Zone*> zone;
Zone* focus;
Zone* clicked, *double_clicked;
Inter();
Inter(Inter *in);
void set_font(Font* f1, bool del=true); // del=true if we must delete 'font'
int nzone() const {
return zone.size();
}
void add(Zone* zon, bool back=false) {
if(back)
zone.insert(zone.begin(), zon);
else
zone.push_back(zon);
}
void remove(int i);
void remove(Zone *z);
Zone* do_frame();
void dirt_all();
void draw_zone();
void flush();
virtual ~Inter();
void process();
void select_zone(Zone *z, int quel); // selects a zone (gives focus and/or click)
bool is_kb_visible() const {
return kb_visible;
}
void kb_deactivate();
void kb_reactivate();
// The parameter of these two methods should be SDL_Scancode, but would
// require changing the config struct, which is (sadly) a problem.
void kb_alloc_key(int i);
void kb_free_key(int i);
};
class Zone {
public:
Zone* child,* parent;
int enabled;
int dirty, focusable;
int x, y, w, h;
bool kb_focusable, stay_on_top;
Inter* inter;
Zone(Inter* in=NULL, int px=0, int py=0, int pw=0, int ph=0);
virtual ~Zone();
virtual void disable() {
if(enabled == 0)
video->need_paint = 2; // to ensure that this zone will disappear
enabled--;
}
virtual void enable() {
enabled++;
}
virtual void dirt() {
dirty = 2;
}
virtual void draw() { } //called when the zone is dirty
virtual int in() const;
virtual void leaved();
virtual void entered();
virtual void waiting();
virtual void clicked(int quel);
virtual void double_clicked();
virtual void process() { }
virtual void lost_focus(int cancel) { }
void set_child(Zone* chil);
};
class Zone_sprite: public Zone {
Sprite *sp;
public:
Zone_sprite(Inter *in, const ResName& nam, int px = -1, int py = -1);
virtual ~Zone_sprite();
virtual void draw();
};
class Zone_bitmap: public Zone {
bool del_bit;
public:
Bitmap* bit_, *bit2_, *actual;
Zone_bitmap(Inter* in, Bitmap* bit, int px, int py, Bitmap* bit2=NULL);
Zone_bitmap(Inter* in, Bitmap* bit, int px, int py, bool del);
virtual ~Zone_bitmap();
virtual void draw() {
actual->draw(video->vb, x, y);
}
virtual void leaved() {
if(bit2_) {
actual = bit_;
dirt();
}
Zone::leaved();
}
virtual void entered() {
if(bit2_) {
actual = bit2_;
dirt();
}
Zone::entered();
}
};
class Zone_watch_int: public Zone {
public:
int *val, last_val;
Zone_watch_int(Inter* in, int *pval, int px=0, int py=0, int pw=0, int ph=0):
Zone(in, px, py, pw, ph) {
val = pval;
set_val(pval);
}
virtual void process();
void set_val(int *pv);
};
class Zone_state: public Zone_watch_int {
public:
int nstate;
Zone_state(Inter* in, int *pval, int px, int py, int pw=0, int ph=0, int pnstate=1);
virtual void clicked(int quel);
};
class Zone_state_bit: public Zone_state {
Bitmap *state[3];
public:
Zone_state_bit(Inter* in, const ResName& b1, int *pval, int px, int py, const ResName* b2=NULL, const ResName* b3=NULL);
virtual ~Zone_state_bit() {
for(int i=0; i < nstate; i++)
delete state[i];
}
virtual void draw() {
state[last_val]->draw(video->vb, x, y);
}
};
class Zone_text: public Zone {
friend class Zone_text_select;
protected:
Font *font;
bool lock_size;
int text_x;
public:
char st[256];
Zone_text(Inter* in, const char* s, int px, int py);
Zone_text(Font *f2, Inter* in, const char* s, int px, int py);
Zone_text(Font *f2, Inter* in, const char* s, int py);
Zone_text(Inter* in, const char* s, int px, int py, int pw);
Zone_text(Inter* in, const char* s, int py);
virtual void set_text(const char* s);
virtual void set_font(Font* f);
virtual void draw();
};
class Zone_text_select: public Zone_text {
protected:
Font* font2;
Font* actual;
public:
Zone_text_select(Inter* in, Font* f, const char* s, int px, int py);
Zone_text_select(Inter* in, Font* f, const char* s, int px, int py, int pw);
virtual void draw();
virtual void leaved();
virtual void entered();
virtual void set_font(Font* f);
};
class Zone_text_button: public Zone_text_select {
protected:
Bitmap *bit;
bool high;
void set_bit(Bitmap *fond);
public:
Zone_text_button(Inter* in, Bitmap* fond, Font* f, const char* s, int px, int py);
Zone_text_button(Inter* in, Bitmap* fond, Font* f, const char* s, int py);
Zone_text_button(Inter* in, Bitmap* fond, Font* f, const char* s, int px, int py, int pw);
virtual ~Zone_text_button();
virtual void draw();
virtual void leaved();
virtual void entered();
virtual void set_text(const char* s);
};
class Zone_clear: public Zone {
int color;
public:
Zone_clear(Inter* in, int px=0, int py=0, int pw=video->width, int ph=video->height, int c=0);
virtual void draw();
};
class Zone_panel: public Zone {
protected:
bool draw_frame;
public:
Video_bitmap* pan;
bool high;
Zone_panel(Inter* in, int px, int py, int pw, int ph);
virtual ~Zone_panel() {
delete pan;
}
virtual void draw();
void resize();
};
class Zone_state_text: public Zone_state {
Zone_panel pan;
public:
const char* state[256];
Font* fonts[256];
Zone_state_text(Inter* in, int *pval, int px, int py, int pw=50, int ph=20);
void add_string(const char* s, Font *f=NULL);
virtual void draw();
virtual void leaved();
virtual void entered();
};
class Zone_text_input: public Zone_panel {
protected:
char st[1024];
char* val;
int focus, curpos, actual_len, maxlen, panx, maxwidth;
void input_char(const uint8_t c);
void check_clipboard();
Font *font_selected;
int select_start;
uint8_t curcolor;
bool first_click;
void set_mouse_curpos();
bool cut_selection();
public:
Zone_text_input(Inter* in, const Palette& pal, char* s, int mlen, int px, int py, int pw, int mwidth = -1);
virtual ~Zone_text_input();
virtual void clicked(int quel);
virtual void lost_focus(int cancel);
void set_val(char* s);
virtual void draw();
virtual void process();
virtual void leaved();
virtual void entered();
virtual void waiting();
};
class Zone_input_numeric: public Zone_text_input {
char temp_st[64];
int var_min, var_max, *num_var;
public:
Zone_input_numeric(Inter* in, int *pvar, int ncar, int pmin, int pmax, const Palette &pal, int px, int py, int pw);
void lost_focus(int cancel);
};
class Zone_text_field: public Zone_panel {
protected:
char st[256];
int val;
int *var;
Font *font;
public:
Zone_text_field(Inter* in, int* s, int px, int py, int pw, Font *f2=NULL, bool frame=true);
Zone_text_field(Inter* in, const char* s, int px, int py, int pw, Font *f2=NULL, bool frame=false);
void set_val(int* s);
void set_val(const char* s);
virtual void draw();
virtual void process();
};
class Zone_text_numeric: public Zone_text_field {
public:
Zone_text_numeric(Inter* in, int* s, int px, int py, int pw):
Zone_text_field(in, s, px, py, pw) {
draw_frame = false;
}
Zone_text_numeric(Font *f2, Inter* in, int* s, int px, int py, int pw):
Zone_text_field(in, s, px, py, pw, f2) {
draw_frame = false;
}
};
#endif