[56] | 1 | /* |
---|
| 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
[494] | 4 | * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
[56] | 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 | |
---|
[2] | 11 | #ifndef __JWIN__ |
---|
| 12 | #define __JWIN__ |
---|
[481] | 13 | #include "video.h" |
---|
| 14 | #include "image.h" |
---|
| 15 | #include "event.h" |
---|
| 16 | #include "filter.h" |
---|
| 17 | #include "event.h" |
---|
| 18 | #include "fonts.h" |
---|
[2] | 19 | |
---|
| 20 | class ifield; |
---|
[120] | 21 | class WindowManager; |
---|
| 22 | class Jwindow; |
---|
[2] | 23 | |
---|
[111] | 24 | extern int frame_top(); |
---|
| 25 | extern int frame_bottom(); |
---|
| 26 | extern int frame_left(); |
---|
| 27 | extern int frame_right(); |
---|
[2] | 28 | |
---|
| 29 | void set_frame_size(int x); |
---|
| 30 | |
---|
[120] | 31 | class InputManager |
---|
[2] | 32 | { |
---|
[120] | 33 | friend class Jwindow; |
---|
[109] | 34 | |
---|
| 35 | private: |
---|
[2] | 36 | image *screen; |
---|
[109] | 37 | ifield *first, *active, *grab; |
---|
[120] | 38 | Jwindow *cur, *owner; |
---|
[2] | 39 | int no_selections_allowed; |
---|
[109] | 40 | |
---|
| 41 | public: |
---|
[120] | 42 | InputManager(image *Screen, ifield *First); |
---|
| 43 | InputManager(Jwindow *owner, ifield *First); |
---|
| 44 | void handle_event(event &ev, Jwindow *j); |
---|
[2] | 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 | void clear_current(); |
---|
| 51 | void grab_focus(ifield *i); |
---|
| 52 | void release_focus(); |
---|
| 53 | void allow_no_selections(); |
---|
[124] | 54 | ~InputManager(); |
---|
[2] | 55 | } ; |
---|
| 56 | |
---|
| 57 | class ifield |
---|
| 58 | { |
---|
[120] | 59 | friend class Jwindow; |
---|
| 60 | friend class InputManager; |
---|
[109] | 61 | |
---|
| 62 | protected: |
---|
[120] | 63 | Jwindow *owner; |
---|
[109] | 64 | |
---|
[2] | 65 | public : |
---|
[109] | 66 | ifield(); |
---|
| 67 | int x, y; |
---|
[2] | 68 | |
---|
[109] | 69 | int id; |
---|
| 70 | ifield *next; |
---|
[120] | 71 | virtual void set_owner(Jwindow *owner); |
---|
[109] | 72 | virtual void move(int newx, int newy) { x = newx; y = newy; } |
---|
| 73 | virtual void area(int &x1, int &y1, int &x2, int &y2) = 0; |
---|
| 74 | virtual void draw_first(image *screen) = 0; |
---|
| 75 | virtual void draw(int active, image *screen) = 0; |
---|
[120] | 76 | virtual void handle_event(event &ev, image *screen, InputManager *im) = 0; |
---|
[109] | 77 | virtual int selectable() { return 1; } |
---|
| 78 | virtual void remap(filter *f) { ; } |
---|
| 79 | virtual char *read() = 0; |
---|
| 80 | virtual ifield *find(int search_id) { if (id==search_id) return this; else return NULL; } |
---|
[124] | 81 | virtual ifield *unlink(int id) { return NULL; } |
---|
[109] | 82 | virtual ~ifield(); |
---|
[2] | 83 | } ; |
---|
| 84 | |
---|
[120] | 85 | class Jwindow |
---|
[2] | 86 | { |
---|
[120] | 87 | friend class InputManager; |
---|
[109] | 88 | |
---|
| 89 | private: |
---|
[111] | 90 | char *_name; |
---|
| 91 | bool _hidden; |
---|
| 92 | bool _moveable; |
---|
[109] | 93 | |
---|
[111] | 94 | void reconfigure(); |
---|
| 95 | |
---|
[109] | 96 | protected: |
---|
[120] | 97 | Jwindow *owner; |
---|
[111] | 98 | int _x1, _y1, _x2, _y2; |
---|
[109] | 99 | |
---|
| 100 | public: |
---|
[120] | 101 | Jwindow *next; |
---|
[109] | 102 | int x, y, l, h, backg; |
---|
| 103 | image *screen; |
---|
[120] | 104 | InputManager *inm; |
---|
[109] | 105 | void *local_info; // pointer to info block for local system (may support windows) |
---|
[111] | 106 | |
---|
[120] | 107 | Jwindow(char const *name = NULL); |
---|
| 108 | Jwindow(int X, int Y, int L, int H, ifield *f, char const *name = NULL); |
---|
| 109 | ~Jwindow(); |
---|
[111] | 110 | |
---|
[117] | 111 | virtual void redraw(); |
---|
[109] | 112 | void resize(int L, int H); |
---|
| 113 | void clear(int color = 0) { screen->bar(x1(), y1(), x2(), y2(), color); } |
---|
[111] | 114 | void show() { _hidden = false; } |
---|
| 115 | void hide() { _hidden = true; } |
---|
| 116 | bool is_hidden() { return _hidden; } |
---|
| 117 | void freeze() { _moveable = false; } |
---|
| 118 | void thaw() { _moveable = true; } |
---|
| 119 | bool is_moveable() { return _moveable; } |
---|
| 120 | int x1() { return _x1; } |
---|
| 121 | int y1() { return _y1; } |
---|
| 122 | int x2() { return _x2; } |
---|
| 123 | int y2() { return _y2; } |
---|
[518] | 124 | void clip_in() { screen->SetClip(x1(), y1(), x2() + 1, y2() + 1); } |
---|
| 125 | void clip_out() { screen->SetClip(0, 0, l, h); } |
---|
[124] | 126 | char *read(int id) { return inm->get(id)->read(); } |
---|
[109] | 127 | void local_close(); |
---|
[2] | 128 | |
---|
[111] | 129 | static int left_border(); |
---|
| 130 | static int right_border(); |
---|
| 131 | static int top_border(); |
---|
| 132 | static int bottom_border(); |
---|
| 133 | }; |
---|
| 134 | |
---|
[120] | 135 | class WindowManager |
---|
[2] | 136 | { |
---|
[120] | 137 | friend class Jwindow; |
---|
[109] | 138 | |
---|
[111] | 139 | protected: |
---|
[120] | 140 | void add_window(Jwindow *); |
---|
| 141 | void remove_window(Jwindow *); |
---|
[111] | 142 | |
---|
[109] | 143 | public: |
---|
[111] | 144 | event_handler *eh; |
---|
[120] | 145 | Jwindow *first, *grab; |
---|
[111] | 146 | image *screen, *mouse_pic, *mouse_save; |
---|
| 147 | palette *pal; |
---|
| 148 | int hi, med, low, bk; // bright, medium, dark and black colors |
---|
| 149 | int key_state[512]; |
---|
| 150 | enum { inputing, dragging } state; |
---|
| 151 | int drag_mousex, drag_mousey, frame_suppress; |
---|
[120] | 152 | Jwindow *drag_window; |
---|
[111] | 153 | JCFont *fnt, *wframe_fnt; |
---|
[2] | 154 | |
---|
[124] | 155 | WindowManager(image *, palette *, int hi, int med, int low, JCFont *); |
---|
[120] | 156 | ~WindowManager(); |
---|
[2] | 157 | |
---|
[120] | 158 | Jwindow *new_window(int x, int y, int l, int h, |
---|
[111] | 159 | ifield *fields = NULL, char const *Name = NULL); |
---|
[2] | 160 | |
---|
[111] | 161 | void set_frame_font(JCFont *fnt) { wframe_fnt = fnt; } |
---|
| 162 | JCFont *frame_font() { return wframe_fnt; } |
---|
[120] | 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); |
---|
[111] | 166 | void get_event(event &ev); |
---|
| 167 | void push_event(event *ev) { eh->push_event(ev); } |
---|
| 168 | int event_waiting() { return eh->event_waiting(); } |
---|
| 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 | int has_mouse() { return eh->has_mouse(); } |
---|
[494] | 177 | void mouse_status(int &x, int &y, int &button) { eh->mouse_status(x,y,button); } |
---|
[124] | 178 | void set_mouse_shape(image *im, int centerx, int centery) |
---|
[111] | 179 | { eh->set_mouse_shape(im,centerx,centery); } |
---|
[2] | 180 | |
---|
[111] | 181 | void set_mouse_position(int mx, int my) |
---|
| 182 | { eh->set_mouse_position(mx,my); } |
---|
[2] | 183 | |
---|
[111] | 184 | int key_pressed(int x) { return key_state[x]; } |
---|
| 185 | void hide_windows(); |
---|
| 186 | void show_windows(); |
---|
[120] | 187 | void hide_window(Jwindow *j); |
---|
| 188 | void show_window(Jwindow *j); |
---|
[111] | 189 | void set_frame_suppress(int x) { frame_suppress=x; } |
---|
[120] | 190 | void grab_focus(Jwindow *j); |
---|
[111] | 191 | void release_focus(); |
---|
| 192 | int window_in_area(int x1, int y1, int x2, int y2); // true if a window lies in this area |
---|
| 193 | }; |
---|
| 194 | |
---|
[2] | 195 | #endif |
---|
| 196 | |
---|
| 197 | |
---|