[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 |
---|
[555] | 7 | * domain software, no warranty is made or implied by Crack dot Com, by |
---|
| 8 | * Jonathan Clark, or by Sam Hocevar. |
---|
[56] | 9 | */ |
---|
| 10 | |
---|
[2] | 11 | #ifndef __JWIN__ |
---|
| 12 | #define __JWIN__ |
---|
[643] | 13 | |
---|
[481] | 14 | #include "video.h" |
---|
| 15 | #include "image.h" |
---|
| 16 | #include "event.h" |
---|
| 17 | #include "filter.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 | { |
---|
[644] | 33 | friend class Jwindow; |
---|
[109] | 34 | |
---|
[644] | 35 | public: |
---|
| 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); |
---|
[649] | 45 | ifield *unlink(int id); // unlink ID from list and return field pointer |
---|
[644] | 46 | void clear_current(); |
---|
| 47 | void grab_focus(ifield *i); |
---|
| 48 | void release_focus(); |
---|
| 49 | void allow_no_selections(); |
---|
| 50 | |
---|
[109] | 51 | private: |
---|
[644] | 52 | image *m_surf; |
---|
[649] | 53 | ifield *m_first, *m_active, *m_grab; |
---|
| 54 | Jwindow *m_cur, *m_owner; |
---|
[644] | 55 | int no_selections_allowed; |
---|
| 56 | }; |
---|
[109] | 57 | |
---|
[2] | 58 | class ifield |
---|
| 59 | { |
---|
[120] | 60 | friend class Jwindow; |
---|
| 61 | friend class InputManager; |
---|
[109] | 62 | |
---|
[2] | 63 | public : |
---|
[109] | 64 | ifield(); |
---|
[659] | 65 | virtual ~ifield(); |
---|
[2] | 66 | |
---|
[120] | 67 | virtual void set_owner(Jwindow *owner); |
---|
[682] | 68 | virtual void Move(ivec2 pos) { m_pos = pos; } |
---|
[109] | 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; |
---|
[643] | 72 | virtual void handle_event(Event &ev, image *screen, InputManager *im) = 0; |
---|
[109] | 73 | virtual int selectable() { return 1; } |
---|
[653] | 74 | virtual void remap(Filter *f) { (void)f; } |
---|
[109] | 75 | virtual char *read() = 0; |
---|
| 76 | virtual ifield *find(int search_id) { if (id==search_id) return this; else return NULL; } |
---|
[653] | 77 | virtual ifield *unlink(int id) { (void)id; return NULL; } |
---|
[2] | 78 | |
---|
[682] | 79 | ivec2 m_pos; |
---|
[659] | 80 | int id; |
---|
| 81 | ifield *next; |
---|
| 82 | |
---|
| 83 | protected: |
---|
| 84 | Jwindow *owner; |
---|
| 85 | }; |
---|
| 86 | |
---|
[120] | 87 | class Jwindow |
---|
[2] | 88 | { |
---|
[120] | 89 | friend class InputManager; |
---|
[109] | 90 | |
---|
| 91 | public: |
---|
[120] | 92 | Jwindow *next; |
---|
[671] | 93 | int backg; |
---|
[120] | 94 | InputManager *inm; |
---|
[109] | 95 | void *local_info; // pointer to info block for local system (may support windows) |
---|
[111] | 96 | |
---|
[120] | 97 | Jwindow(char const *name = NULL); |
---|
[682] | 98 | Jwindow(ivec2 pos, ivec2 size, ifield *f, char const *name = NULL); |
---|
[120] | 99 | ~Jwindow(); |
---|
[111] | 100 | |
---|
[117] | 101 | virtual void redraw(); |
---|
[682] | 102 | void Resize(ivec2 size); |
---|
| 103 | void clear(int color = 0) { m_surf->Bar(ivec2(x1(), y1()), |
---|
| 104 | ivec2(x2(), y2()), color); } |
---|
[111] | 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; } |
---|
[682] | 115 | void clip_in() { m_surf->SetClip(ivec2(x1(), y1()), ivec2(x2() + 1, y2() + 1)); } |
---|
| 116 | void clip_out() { m_surf->SetClip(ivec2(0), m_size); } |
---|
[124] | 117 | char *read(int id) { return inm->get(id)->read(); } |
---|
[109] | 118 | void local_close(); |
---|
[2] | 119 | |
---|
[111] | 120 | static int left_border(); |
---|
| 121 | static int right_border(); |
---|
| 122 | static int top_border(); |
---|
| 123 | static int bottom_border(); |
---|
[644] | 124 | |
---|
[682] | 125 | ivec2 m_pos, m_size; |
---|
[644] | 126 | image *m_surf; |
---|
| 127 | |
---|
| 128 | protected: |
---|
| 129 | Jwindow *owner; |
---|
| 130 | int _x1, _y1, _x2, _y2; |
---|
| 131 | |
---|
| 132 | private: |
---|
| 133 | char *_name; |
---|
| 134 | bool _hidden; |
---|
| 135 | bool _moveable; |
---|
| 136 | |
---|
| 137 | void reconfigure(); |
---|
[111] | 138 | }; |
---|
| 139 | |
---|
[643] | 140 | class WindowManager : public EventHandler |
---|
[2] | 141 | { |
---|
[120] | 142 | friend class Jwindow; |
---|
[109] | 143 | |
---|
[111] | 144 | protected: |
---|
[120] | 145 | void add_window(Jwindow *); |
---|
| 146 | void remove_window(Jwindow *); |
---|
[111] | 147 | |
---|
[109] | 148 | public: |
---|
[643] | 149 | WindowManager(image *, palette *, int hi, int med, int low, JCFont *); |
---|
| 150 | ~WindowManager(); |
---|
| 151 | |
---|
[649] | 152 | Jwindow *m_first, *m_grab; |
---|
[643] | 153 | image *mouse_pic, *mouse_save; |
---|
[111] | 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; |
---|
[120] | 158 | Jwindow *drag_window; |
---|
[111] | 159 | JCFont *fnt, *wframe_fnt; |
---|
[2] | 160 | |
---|
[682] | 161 | Jwindow *CreateWindow(ivec2 pos, ivec2 size, |
---|
[671] | 162 | ifield *fields = NULL, char const *Name = NULL); |
---|
[2] | 163 | |
---|
[111] | 164 | JCFont *frame_font() { return wframe_fnt; } |
---|
[120] | 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); |
---|
[643] | 168 | void get_event(Event &ev); |
---|
[111] | 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; } |
---|
[2] | 176 | |
---|
[111] | 177 | int key_pressed(int x) { return key_state[x]; } |
---|
| 178 | void hide_windows(); |
---|
| 179 | void show_windows(); |
---|
[120] | 180 | void hide_window(Jwindow *j); |
---|
| 181 | void show_window(Jwindow *j); |
---|
| 182 | void grab_focus(Jwindow *j); |
---|
[111] | 183 | void release_focus(); |
---|
[643] | 184 | |
---|
| 185 | private: |
---|
| 186 | palette *m_pal; |
---|
[644] | 187 | image *m_surf; |
---|
[111] | 188 | }; |
---|
| 189 | |
---|
[2] | 190 | #endif |
---|
| 191 | |
---|
| 192 | |
---|