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

Last change on this file since 655 was 655, checked in by Sam Hocevar, 12 years ago

imlib: refactor a few image methods so that they use vec2i.

  • Property svn:keywords set to Id
File size: 5.1 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
63protected:
64    Jwindow *owner;
65
66public :
67    ifield();
68    int x, y;
69
70    int id;
71    ifield *next;
72    virtual void set_owner(Jwindow *owner);
73    virtual void move(int newx, int newy) { x = newx; y = newy; }
74    virtual void area(int &x1, int &y1, int &x2, int &y2) = 0;
75    virtual void draw_first(image *screen) = 0;
76    virtual void draw(int active, image *screen) = 0;
77    virtual void handle_event(Event &ev, image *screen, InputManager *im) = 0;
78    virtual int selectable() { return 1; }
79    virtual void remap(Filter *f) { (void)f; }
80    virtual char *read() = 0;
81    virtual ifield *find(int search_id) { if (id==search_id) return this; else return NULL; }
82    virtual ifield *unlink(int id) { (void)id; return NULL; }
83    virtual ~ifield();
84} ;
85
86class Jwindow
87{
88    friend class InputManager;
89
90public:
91    Jwindow *next;
92    int x, y, l, h, backg;
93    InputManager *inm;
94    void *local_info;  // pointer to info block for local system (may support windows)
95
96    Jwindow(char const *name = NULL);
97    Jwindow(int X, int Y, int L, int H, ifield *f, char const *name = NULL);
98    ~Jwindow();
99
100    virtual void redraw();
101    void resize(int L, int H);
102    void clear(int color = 0) { m_surf->Bar(vec2i(x1(), y1()),
103                                            vec2i(x2(), y2()), color); }
104    void show() { _hidden = false; }
105    void hide() { _hidden = true; }
106    bool is_hidden() { return _hidden; }
107    void freeze() { _moveable = false; }
108    void thaw() { _moveable = true; }
109    bool is_moveable() { return _moveable; }
110    int x1() { return _x1; }
111    int y1() { return _y1; }
112    int x2() { return _x2; }
113    int y2() { return _y2; }
114    void clip_in() { m_surf->SetClip(x1(), y1(), x2() + 1, y2() + 1); }
115    void clip_out() { m_surf->SetClip(0, 0, l, h); }
116    char *read(int id) { return inm->get(id)->read(); }
117    void local_close();
118
119    static int left_border();
120    static int right_border();
121    static int top_border();
122    static int bottom_border();
123
124    image *m_surf;
125
126protected:
127    Jwindow *owner;
128    int _x1, _y1, _x2, _y2;
129
130private:
131    char *_name;
132    bool _hidden;
133    bool _moveable;
134
135    void reconfigure();
136};
137
138class WindowManager : public EventHandler
139{
140    friend class Jwindow;
141
142protected:
143    void add_window(Jwindow *);
144    void remove_window(Jwindow *);
145
146public:
147    WindowManager(image *, palette *, int hi, int med, int low, JCFont *);
148    ~WindowManager();
149
150    Jwindow *m_first, *m_grab;
151    image *mouse_pic, *mouse_save;
152    int hi, med, low, bk; // bright, medium, dark and black colors
153    int key_state[512];
154    enum { inputing, dragging } state;
155    int drag_mousex, drag_mousey, frame_suppress;
156    Jwindow *drag_window;
157    JCFont *fnt, *wframe_fnt;
158
159    Jwindow *new_window(int x, int y, int l, int h,
160                        ifield *fields = NULL, char const *Name = NULL);
161
162    void set_frame_font(JCFont *fnt) { wframe_fnt = fnt; }
163    JCFont *frame_font() { return wframe_fnt; }
164    void close_window(Jwindow *j);
165    void resize_window(Jwindow *j, int l, int h);
166    void move_window(Jwindow *j, int x, int y);
167    void get_event(Event &ev);
168    void flush_screen();
169    int bright_color() { return hi; }
170    int medium_color() { return med; }
171    int dark_color() { return low; }
172    int black() { return bk; }
173    void set_colors(int Hi, int Med, int Low) { hi=Hi; med=Med; low=Low; }
174    JCFont *font() { return fnt; }
175
176    int key_pressed(int x) { return key_state[x]; }
177    void hide_windows();
178    void show_windows();
179    void hide_window(Jwindow *j);
180    void show_window(Jwindow *j);
181    void set_frame_suppress(int x) { frame_suppress=x; }
182    void grab_focus(Jwindow *j);
183    void release_focus();
184    int window_in_area(int x1, int y1, int x2, int y2); // true if a window lies in this area
185
186private:
187    palette *m_pal;
188    image *m_surf;
189};
190
191#endif
192
193
Note: See TracBrowser for help on using the repository browser.