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

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

imlib: remove unused code and tag unused method arguments.

  • Property svn:keywords set to Id
File size: 5.0 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(x1(), y1(), x2(), y2(), color); }
103    void show() { _hidden = false; }
104    void hide() { _hidden = true; }
105    bool is_hidden() { return _hidden; }
106    void freeze() { _moveable = false; }
107    void thaw() { _moveable = true; }
108    bool is_moveable() { return _moveable; }
109    int x1() { return _x1; }
110    int y1() { return _y1; }
111    int x2() { return _x2; }
112    int y2() { return _y2; }
113    void clip_in() { m_surf->SetClip(x1(), y1(), x2() + 1, y2() + 1); }
114    void clip_out() { m_surf->SetClip(0, 0, l, h); }
115    char *read(int id) { return inm->get(id)->read(); }
116    void local_close();
117
118    static int left_border();
119    static int right_border();
120    static int top_border();
121    static int bottom_border();
122
123    image *m_surf;
124
125protected:
126    Jwindow *owner;
127    int _x1, _y1, _x2, _y2;
128
129private:
130    char *_name;
131    bool _hidden;
132    bool _moveable;
133
134    void reconfigure();
135};
136
137class WindowManager : public EventHandler
138{
139    friend class Jwindow;
140
141protected:
142    void add_window(Jwindow *);
143    void remove_window(Jwindow *);
144
145public:
146    WindowManager(image *, palette *, int hi, int med, int low, JCFont *);
147    ~WindowManager();
148
149    Jwindow *m_first, *m_grab;
150    image *mouse_pic, *mouse_save;
151    int hi, med, low, bk; // bright, medium, dark and black colors
152    int key_state[512];
153    enum { inputing, dragging } state;
154    int drag_mousex, drag_mousey, frame_suppress;
155    Jwindow *drag_window;
156    JCFont *fnt, *wframe_fnt;
157
158    Jwindow *new_window(int x, int y, int l, int h,
159                        ifield *fields = NULL, char const *Name = NULL);
160
161    void set_frame_font(JCFont *fnt) { wframe_fnt = fnt; }
162    JCFont *frame_font() { return wframe_fnt; }
163    void close_window(Jwindow *j);
164    void resize_window(Jwindow *j, int l, int h);
165    void move_window(Jwindow *j, int x, int y);
166    void get_event(Event &ev);
167    void flush_screen();
168    int bright_color() { return hi; }
169    int medium_color() { return med; }
170    int dark_color() { return low; }
171    int black() { return bk; }
172    void set_colors(int Hi, int Med, int Low) { hi=Hi; med=Med; low=Low; }
173    JCFont *font() { return fnt; }
174
175    int key_pressed(int x) { return key_state[x]; }
176    void hide_windows();
177    void show_windows();
178    void hide_window(Jwindow *j);
179    void show_window(Jwindow *j);
180    void set_frame_suppress(int x) { frame_suppress=x; }
181    void grab_focus(Jwindow *j);
182    void release_focus();
183    int window_in_area(int x1, int y1, int x2, int y2); // true if a window lies in this area
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.