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

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

imlib: refactor dirty_rect clipping coordiantes so that the upper
bound is no longer inclusive. It will make things easier in the future.

  • Property svn:keywords set to Id
File size: 5.4 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 or
8 *  Jonathan Clark.
9 */
10
11#ifndef __JWIN__
12#define __JWIN__
13#include "video.h"
14#include "image.h"
15#include "event.h"
16#include "filter.h"
17#include "event.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
35private:
36  image *screen;
37  ifield *first, *active, *grab;
38  Jwindow *cur, *owner;
39  int no_selections_allowed;
40
41public:
42  InputManager(image *Screen, ifield *First);
43  InputManager(Jwindow *owner, ifield *First);
44  void handle_event(event &ev, Jwindow *j);
45  ifield *get(int id);
46  void redraw();
47  void add(ifield *i);
48  void remap(filter *f);
49  ifield *unlink(int id);     // unlinks ID from fields list and return the pointer to it
50  ifield *current() { return active; }
51  void clear_current();
52  void grab_focus(ifield *i);
53  void release_focus();
54  void allow_no_selections();
55  ~InputManager();
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) { ; }
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) { return NULL; }
83    virtual ~ifield();
84} ;
85
86class Jwindow
87{
88    friend class InputManager;
89
90private:
91    char *_name;
92    bool _hidden;
93    bool _moveable;
94
95    void reconfigure();
96
97protected:
98    Jwindow *owner;
99    int _x1, _y1, _x2, _y2;
100
101public:
102    Jwindow *next;
103    int x, y, l, h, backg;
104    image *screen;
105    InputManager *inm;
106    void *local_info;  // pointer to info block for local system (may support windows)
107
108    Jwindow(char const *name = NULL);
109    Jwindow(int X, int Y, int L, int H, ifield *f, char const *name = NULL);
110    ~Jwindow();
111
112    virtual void redraw();
113    void resize(int L, int H);
114    void clear(int color = 0) { screen->bar(x1(), y1(), x2(), y2(), color); }
115    void show() { _hidden = false; }
116    void hide() { _hidden = true; }
117    bool is_hidden() { return _hidden; }
118    void freeze() { _moveable = false; }
119    void thaw() { _moveable = true; }
120    bool is_moveable() { return _moveable; }
121    int x1() { return _x1; }
122    int y1() { return _y1; }
123    int x2() { return _x2; }
124    int y2() { return _y2; }
125    void clip_in() { screen->SetClip(x1(), y1(), x2() + 1, y2() + 1); }
126    void clip_out() { screen->SetClip(0, 0, l, h); }
127    char *read(int id) { return inm->get(id)->read(); }
128    void local_close();
129
130    static int left_border();
131    static int right_border();
132    static int top_border();
133    static int bottom_border();
134};
135
136class WindowManager
137{
138    friend class Jwindow;
139
140protected:
141    void add_window(Jwindow *);
142    void remove_window(Jwindow *);
143
144public:
145    event_handler *eh;
146    Jwindow *first, *grab;
147    image *screen, *mouse_pic, *mouse_save;
148    palette *pal;
149    int hi, med, low, bk; // bright, medium, dark and black colors
150    int key_state[512];
151    enum { inputing, dragging } state;
152    int drag_mousex, drag_mousey, frame_suppress;
153    Jwindow *drag_window;
154    JCFont *fnt, *wframe_fnt;
155
156    WindowManager(image *, palette *, int hi, int med, int low, JCFont *);
157    ~WindowManager();
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 push_event(event *ev) { eh->push_event(ev); }
169    int event_waiting() { return eh->event_waiting(); }
170    void flush_screen();
171    int bright_color() { return hi; }
172    int medium_color() { return med; }
173    int dark_color() { return low; }
174    int black() { return bk; }
175    void set_colors(int Hi, int Med, int Low) { hi=Hi; med=Med; low=Low; }
176    JCFont *font() { return fnt; }
177    int has_mouse() { return eh->has_mouse(); }
178    void mouse_status(int &x, int &y, int &button) { eh->mouse_status(x,y,button); }
179    void set_mouse_shape(image *im, int centerx, int centery)
180    { eh->set_mouse_shape(im,centerx,centery); }
181
182    void set_mouse_position(int mx, int my)
183    { eh->set_mouse_position(mx,my); }
184
185    int key_pressed(int x) { return key_state[x]; }
186    void hide_windows();
187    void show_windows();
188    void hide_window(Jwindow *j);
189    void show_window(Jwindow *j);
190    void set_frame_suppress(int x) { frame_suppress=x; }
191    void grab_focus(Jwindow *j);
192    void release_focus();
193    int window_in_area(int x1, int y1, int x2, int y2); // true if a window lies in this area
194};
195
196#endif
197
198
Note: See TracBrowser for help on using the repository browser.