[49] | 1 | #ifndef __JWIN__ |
---|
| 2 | #define __JWIN__ |
---|
| 3 | #include "video.hpp" |
---|
| 4 | #include "image.hpp" |
---|
| 5 | #include "event.hpp" |
---|
| 6 | #include "filter.hpp" |
---|
| 7 | #include "event.hpp" |
---|
| 8 | #include "fonts.hpp" |
---|
| 9 | |
---|
| 10 | class ifield; |
---|
| 11 | class window_manager; |
---|
| 12 | class jwindow; |
---|
| 13 | |
---|
| 14 | int frame_top(); |
---|
| 15 | int frame_bottom(); |
---|
| 16 | int frame_left(); |
---|
| 17 | int frame_right(); |
---|
| 18 | |
---|
| 19 | void set_frame_size(int x); |
---|
| 20 | |
---|
| 21 | #define WINDOW_FRAME_TOP frame_top() |
---|
| 22 | #define WINDOW_FRAME_BOTTOM frame_bottom() |
---|
| 23 | #define WINDOW_FRAME_LEFT frame_left() |
---|
| 24 | #define WINDOW_FRAME_RIGHT frame_right() |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | class input_manager |
---|
| 28 | { |
---|
| 29 | ifield *first,*active,*grab; |
---|
| 30 | window_manager *wm; |
---|
| 31 | jwindow *cur; |
---|
| 32 | int no_selections_allowed; |
---|
| 33 | image *screen; |
---|
| 34 | public : |
---|
| 35 | input_manager(image *Screen, window_manager *WM, ifield *First); |
---|
| 36 | void handle_event(event &ev, jwindow *j, window_manager *wm); |
---|
| 37 | ifield *get(int id); |
---|
| 38 | void redraw(); |
---|
| 39 | void add(ifield *i); |
---|
| 40 | void remap(filter *f); |
---|
| 41 | ifield *unlink(int id); // unlinks ID from fields list and return the pointer to it |
---|
| 42 | ifield *current() { return active; } |
---|
| 43 | void clear_current(); |
---|
| 44 | void grab_focus(ifield *i); |
---|
| 45 | void release_focus(); |
---|
| 46 | void allow_no_selections(); |
---|
| 47 | void next_active(image *screen, window_manager *wm); |
---|
| 48 | ~input_manager(); |
---|
| 49 | } ; |
---|
| 50 | |
---|
| 51 | class ifield |
---|
| 52 | { |
---|
| 53 | public : |
---|
| 54 | int x,y; |
---|
| 55 | int id; |
---|
| 56 | ifield *next; |
---|
| 57 | virtual void area(int &x1, int &y1, int &x2, int &y2, window_manager *wm) = 0; |
---|
| 58 | virtual void draw_first(image *screen, window_manager *wm) = 0; |
---|
| 59 | virtual void draw(int active, image *screen, window_manager *wm) = 0; |
---|
| 60 | virtual void handle_event(event &ev, image *screen, window_manager *wm, input_manager *im) = 0; |
---|
| 61 | virtual int selectable() { return 1; } |
---|
| 62 | virtual void remap(filter *f) { ; } |
---|
| 63 | virtual char *read() = 0; |
---|
| 64 | virtual ifield *find(int search_id) { if (id==search_id) return this; else return NULL; } |
---|
| 65 | virtual ifield *unlink(int id) { return NULL; } |
---|
| 66 | virtual ~ifield(); |
---|
| 67 | } ; |
---|
| 68 | |
---|
| 69 | struct jwindow_properties |
---|
| 70 | { |
---|
| 71 | uchar moveable, |
---|
| 72 | hidden; |
---|
| 73 | |
---|
| 74 | } ; |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | class jwindow |
---|
| 78 | { |
---|
| 79 | |
---|
| 80 | public: |
---|
| 81 | image *screen; |
---|
| 82 | jwindow_properties property; |
---|
| 83 | jwindow *next; |
---|
| 84 | char *name; |
---|
| 85 | int x,y,l,h,backg; |
---|
| 86 | input_manager *inm; |
---|
| 87 | void *local_info; // pointer to info block for local system (may support windows) |
---|
| 88 | jwindow(int X, int Y, int L, int H, window_manager *wm, ifield *fields, char *Name=NULL); |
---|
| 89 | void redraw(int hi, int med, int low, JCFont *fnt); |
---|
| 90 | void resize(int L, int H); |
---|
| 91 | void clear(int color=0) { screen->bar(x1(),y1(),x2(),y2(),color); } |
---|
| 92 | int x1() { return WINDOW_FRAME_LEFT; } |
---|
| 93 | int y1() { return WINDOW_FRAME_TOP; } |
---|
| 94 | int x2() { return l-WINDOW_FRAME_RIGHT-1; } |
---|
| 95 | int y2() { return h-WINDOW_FRAME_BOTTOM-1; } |
---|
| 96 | void clip_in() { screen->set_clip(x1(),y1(),x2(),y2()); } |
---|
| 97 | void clip_out() { screen->set_clip(0,0,l-1,h-1); } |
---|
| 98 | char *read(int id) { return inm->get(id)->read(); } |
---|
| 99 | void local_close(); |
---|
| 100 | void set_moveability(int x); |
---|
| 101 | ~jwindow() { local_close(); delete screen; delete inm; jfree(name); } |
---|
| 102 | } ; |
---|
| 103 | |
---|
| 104 | class window_manager |
---|
| 105 | { |
---|
| 106 | public : |
---|
| 107 | event_handler *eh; |
---|
| 108 | jwindow *first,*grab; |
---|
| 109 | image *mouse_pic,*mouse_save; |
---|
| 110 | palette *pal; |
---|
| 111 | int hi,med,low,bk; // bright, medium, dark and black colors |
---|
| 112 | int key_state[512]; |
---|
| 113 | enum { inputing,dragging } state; |
---|
| 114 | int drag_mousex, drag_mousey,frame_suppress; |
---|
| 115 | jwindow *drag_window; |
---|
| 116 | JCFont *fnt,*wframe_fnt; |
---|
| 117 | |
---|
| 118 | window_manager(image *Screen, palette *Pal, int Hi, int Med, int Low, JCFont *Font); |
---|
| 119 | |
---|
| 120 | jwindow *new_window(int x, int y, int l, int h, ifield *fields=NULL, char *Name=NULL); |
---|
| 121 | void set_frame_font(JCFont *fnt) { wframe_fnt=fnt; } |
---|
| 122 | JCFont *frame_font() { return wframe_fnt; } |
---|
| 123 | void close_window(jwindow *j); |
---|
| 124 | void resize_window(jwindow *j, int l, int h); |
---|
| 125 | void move_window(jwindow *j, int x, int y); |
---|
| 126 | void get_event(event &ev); |
---|
| 127 | void push_event(event *ev) { eh->push_event(ev); } |
---|
| 128 | int event_waiting() { return eh->event_waiting(); } |
---|
| 129 | void flush_screen(); |
---|
| 130 | int bright_color() { return hi; } |
---|
| 131 | int medium_color() { return med; } |
---|
| 132 | int dark_color() { return low; } |
---|
| 133 | int black() { return bk; } |
---|
| 134 | void set_colors(int Hi, int Med, int Low) { hi=Hi; med=Med; low=Low; } |
---|
| 135 | JCFont *font() { return fnt; } |
---|
| 136 | int has_mouse() { return eh->has_mouse(); } |
---|
| 137 | void mouse_status(int &x, int &y, int &button) {eh->mouse_status(x,y,button); } |
---|
| 138 | void set_mouse_shape(image *im, int centerx, int centery) |
---|
| 139 | { eh->set_mouse_shape(im,centerx,centery); } |
---|
| 140 | |
---|
| 141 | void set_mouse_position(int mx, int my) |
---|
| 142 | { eh->set_mouse_position(mx,my); } |
---|
| 143 | |
---|
| 144 | int key_pressed(int x) { return key_state[x]; } |
---|
| 145 | ~window_manager() { delete eh; while (first) close_window(first); } |
---|
| 146 | void hide_windows(); |
---|
| 147 | void show_windows(); |
---|
| 148 | void hide_window(jwindow *j); |
---|
| 149 | void show_window(jwindow *j); |
---|
| 150 | void set_frame_suppress(int x) { frame_suppress=x; } |
---|
| 151 | void grab_focus(jwindow *j); |
---|
| 152 | void release_focus(); |
---|
| 153 | int window_in_area(int x1, int y1, int x2, int y2); // true if a window lies in this area |
---|
| 154 | } ; |
---|
| 155 | |
---|
| 156 | #endif |
---|
| 157 | |
---|
| 158 | |
---|