source: abuse/trunk/src/imlib/jwindow.h @ 671

Last change on this file since 671 was 671, checked in by Sam Hocevar, 8 years ago

imlib: convert some Jwindow members to vec2i.

  • Property svn:keywords set to Id
File size: 4.9 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#ifndef __JWIN__
12#define __JWIN__
13
14#include "video.h"
15#include "image.h"
16#include "event.h"
17#include "filter.h"
18#include "fonts.h"
19
20class ifield;
21class WindowManager;
22class Jwindow;
23
24extern int frame_top();
25extern int frame_bottom();
26extern int frame_left();
27extern int frame_right();
28
29void set_frame_size(int x);
30
31class InputManager
32{
33    friend class Jwindow;
34
35public:
36    InputManager(image *screen, ifield *first);
37    InputManager(Jwindow *owner, ifield *first);
38    ~InputManager();
39
40    void handle_event(Event &ev, Jwindow *j);
41    ifield *get(int id);
42    void redraw();
43    void add(ifield *i);
44    void remap(Filter *f);
45    ifield *unlink(int id); // unlink ID from list and return field pointer
46    void clear_current();
47    void grab_focus(ifield *i);
48    void release_focus();
49    void allow_no_selections();
50
51private:
52    image *m_surf;
53    ifield *m_first, *m_active, *m_grab;
54    Jwindow *m_cur, *m_owner;
55    int no_selections_allowed;
56};
57
58class ifield
59{
60    friend class Jwindow;
61    friend class InputManager;
62
63public :
64    ifield();
65    virtual ~ifield();
66
67    virtual void set_owner(Jwindow *owner);
68    virtual void Move(vec2i pos) { m_pos = pos; }
69    virtual void area(int &x1, int &y1, int &x2, int &y2) = 0;
70    virtual void draw_first(image *screen) = 0;
71    virtual void draw(int active, image *screen) = 0;
72    virtual void handle_event(Event &ev, image *screen, InputManager *im) = 0;
73    virtual int selectable() { return 1; }
74    virtual void remap(Filter *f) { (void)f; }
75    virtual char *read() = 0;
76    virtual ifield *find(int search_id) { if (id==search_id) return this; else return NULL; }
77    virtual ifield *unlink(int id) { (void)id; return NULL; }
78
79    vec2i m_pos;
80    int id;
81    ifield *next;
82
83protected:
84    Jwindow *owner;
85};
86
87class Jwindow
88{
89    friend class InputManager;
90
91public:
92    Jwindow *next;
93    int backg;
94    InputManager *inm;
95    void *local_info;  // pointer to info block for local system (may support windows)
96
97    Jwindow(char const *name = NULL);
98    Jwindow(vec2i pos, vec2i size, ifield *f, char const *name = NULL);
99    ~Jwindow();
100
101    virtual void redraw();
102    void Resize(vec2i size);
103    void clear(int color = 0) { m_surf->Bar(vec2i(x1(), y1()),
104                                            vec2i(x2(), y2()), color); }
105    void show() { _hidden = false; }
106    void hide() { _hidden = true; }
107    bool is_hidden() { return _hidden; }
108    void freeze() { _moveable = false; }
109    void thaw() { _moveable = true; }
110    bool is_moveable() { return _moveable; }
111    int x1() { return _x1; }
112    int y1() { return _y1; }
113    int x2() { return _x2; }
114    int y2() { return _y2; }
115    void clip_in() { m_surf->SetClip(vec2i(x1(), y1()), vec2i(x2() + 1, y2() + 1)); }
116    void clip_out() { m_surf->SetClip(vec2i(0), m_size); }
117    char *read(int id) { return inm->get(id)->read(); }
118    void local_close();
119
120    static int left_border();
121    static int right_border();
122    static int top_border();
123    static int bottom_border();
124
125    vec2i m_pos, m_size;
126    image *m_surf;
127
128protected:
129    Jwindow *owner;
130    int _x1, _y1, _x2, _y2;
131
132private:
133    char *_name;
134    bool _hidden;
135    bool _moveable;
136
137    void reconfigure();
138};
139
140class WindowManager : public EventHandler
141{
142    friend class Jwindow;
143
144protected:
145    void add_window(Jwindow *);
146    void remove_window(Jwindow *);
147
148public:
149    WindowManager(image *, palette *, int hi, int med, int low, JCFont *);
150    ~WindowManager();
151
152    Jwindow *m_first, *m_grab;
153    image *mouse_pic, *mouse_save;
154    int hi, med, low, bk; // bright, medium, dark and black colors
155    int key_state[512];
156    enum { inputing, dragging } state;
157    int drag_mousex, drag_mousey, frame_suppress;
158    Jwindow *drag_window;
159    JCFont *fnt, *wframe_fnt;
160
161    Jwindow *CreateWindow(vec2i pos, vec2i size,
162                          ifield *fields = NULL, char const *Name = NULL);
163
164    JCFont *frame_font() { return wframe_fnt; }
165    void close_window(Jwindow *j);
166    void resize_window(Jwindow *j, int l, int h);
167    void move_window(Jwindow *j, int x, int y);
168    void get_event(Event &ev);
169    void flush_screen();
170    int bright_color() { return hi; }
171    int medium_color() { return med; }
172    int dark_color() { return low; }
173    int black() { return bk; }
174    void set_colors(int Hi, int Med, int Low) { hi=Hi; med=Med; low=Low; }
175    JCFont *font() { return fnt; }
176
177    int key_pressed(int x) { return key_state[x]; }
178    void hide_windows();
179    void show_windows();
180    void hide_window(Jwindow *j);
181    void show_window(Jwindow *j);
182    void grab_focus(Jwindow *j);
183    void release_focus();
184
185private:
186    palette *m_pal;
187    image *m_surf;
188};
189
190#endif
191
192
Note: See TracBrowser for help on using the repository browser.