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 | image *screen; |
---|
30 | ifield *first,*active,*grab; |
---|
31 | window_manager *wm; |
---|
32 | jwindow *cur; |
---|
33 | int no_selections_allowed; |
---|
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 | ~input_manager(); |
---|
48 | } ; |
---|
49 | |
---|
50 | class ifield |
---|
51 | { |
---|
52 | public : |
---|
53 | int x,y; |
---|
54 | |
---|
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 | public : |
---|
80 | jwindow_properties property; |
---|
81 | jwindow *next; |
---|
82 | char *name; |
---|
83 | int x,y,l,h,backg; |
---|
84 | image *screen; |
---|
85 | input_manager *inm; |
---|
86 | void *local_info; // pointer to info block for local system (may support windows) |
---|
87 | jwindow(int X, int Y, int L, int H, window_manager *wm, ifield *fields, char *Name=NULL); |
---|
88 | void redraw(int hi, int med, int low, JCFont *fnt); |
---|
89 | void resize(int L, int H); |
---|
90 | void clear(int color=0) { screen->bar(x1(),y1(),x2(),y2(),color); } |
---|
91 | int x1() { return WINDOW_FRAME_LEFT; } |
---|
92 | int y1() { return WINDOW_FRAME_TOP; } |
---|
93 | int x2() { return l-WINDOW_FRAME_RIGHT-1; } |
---|
94 | int y2() { return h-WINDOW_FRAME_BOTTOM-1; } |
---|
95 | void clip_in() { screen->set_clip(x1(),y1(),x2(),y2()); } |
---|
96 | void clip_out() { screen->set_clip(0,0,l-1,h-1); } |
---|
97 | char *read(int id) { return inm->get(id)->read(); } |
---|
98 | void local_close(); |
---|
99 | void set_moveability(int x); |
---|
100 | ~jwindow() { local_close(); delete screen; delete inm; jfree(name); } |
---|
101 | } ; |
---|
102 | |
---|
103 | class window_manager |
---|
104 | { |
---|
105 | public : |
---|
106 | event_handler *eh; |
---|
107 | jwindow *first,*grab; |
---|
108 | image *screen,*mouse_pic,*mouse_save; |
---|
109 | palette *pal; |
---|
110 | int hi,med,low,bk; // bright, medium, dark and black colors |
---|
111 | int key_state[512]; |
---|
112 | enum { inputing,dragging } state; |
---|
113 | int drag_mousex, drag_mousey,frame_suppress; |
---|
114 | jwindow *drag_window; |
---|
115 | JCFont *fnt,*wframe_fnt; |
---|
116 | |
---|
117 | window_manager(image *Screen, palette *Pal, int Hi, int Med, int Low, JCFont *Font); |
---|
118 | |
---|
119 | jwindow *new_window(int x, int y, int l, int h, ifield *fields=NULL, char *Name=NULL); |
---|
120 | void set_frame_font(JCFont *fnt) { wframe_fnt=fnt; } |
---|
121 | JCFont *frame_font() { return wframe_fnt; } |
---|
122 | void close_window(jwindow *j); |
---|
123 | void resize_window(jwindow *j, int l, int h); |
---|
124 | void move_window(jwindow *j, int x, int y); |
---|
125 | void get_event(event &ev); |
---|
126 | void push_event(event *ev) { eh->push_event(ev); } |
---|
127 | int event_waiting() { return eh->event_waiting(); } |
---|
128 | void flush_screen(); |
---|
129 | int bright_color() { return hi; } |
---|
130 | int medium_color() { return med; } |
---|
131 | int dark_color() { return low; } |
---|
132 | int black() { return bk; } |
---|
133 | void set_colors(int Hi, int Med, int Low) { hi=Hi; med=Med; low=Low; } |
---|
134 | JCFont *font() { return fnt; } |
---|
135 | int has_mouse() { return eh->has_mouse(); } |
---|
136 | void mouse_status(int &x, int &y, int &button) {eh->mouse_status(x,y,button); } |
---|
137 | void set_mouse_shape(image *im, int centerx, int centery) |
---|
138 | { eh->set_mouse_shape(im,centerx,centery); } |
---|
139 | |
---|
140 | void set_mouse_position(int mx, int my) |
---|
141 | { eh->set_mouse_position(mx,my); } |
---|
142 | |
---|
143 | int key_pressed(int x) { return key_state[x]; } |
---|
144 | ~window_manager() { delete eh; while (first) close_window(first); } |
---|
145 | void hide_windows(); |
---|
146 | void show_windows(); |
---|
147 | void hide_window(jwindow *j); |
---|
148 | void show_window(jwindow *j); |
---|
149 | void set_frame_suppress(int x) { frame_suppress=x; } |
---|
150 | void grab_focus(jwindow *j); |
---|
151 | void release_focus(); |
---|
152 | int window_in_area(int x1, int y1, int x2, int y2); // true if a window lies in this area |
---|
153 | } ; |
---|
154 | |
---|
155 | #endif |
---|
156 | |
---|
157 | |
---|