source: abuse/trunk/src/imlib/include/jwindow.hpp @ 28

Last change on this file since 28 was 17, checked in by Sam Hocevar, 18 years ago
  • absolute shitloads of 64 bit fixes.
File size: 4.7 KB
Line 
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
10class ifield;
11class window_manager;
12class jwindow;
13
14int frame_top();
15int frame_bottom();
16int frame_left();
17int frame_right();
18
19void 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
27class input_manager
28{
29  image *screen;
30  ifield *first,*active,*grab;
31  window_manager *wm;
32  jwindow *cur;
33  int no_selections_allowed;
34public :
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
50class ifield
51{
52public :
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
69struct jwindow_properties
70{
71  uint8_t moveable,
72          hidden;
73} ;
74
75
76class jwindow
77{
78public :
79  jwindow_properties property;
80  jwindow *next;
81  char *name;
82  int x,y,l,h,backg;
83  image *screen;
84  input_manager *inm;
85  void *local_info;     // pointer to info block for local system (may support windows)
86  jwindow(int X, int Y, int L, int H, window_manager *wm, ifield *fields, char *Name=NULL);
87  void redraw(int hi, int med, int low, JCFont *fnt);
88  void resize(int L, int H);
89  void clear(int color=0) { screen->bar(x1(),y1(),x2(),y2(),color); }
90  int x1() { return WINDOW_FRAME_LEFT; }
91  int y1() { return WINDOW_FRAME_TOP; }
92  int x2() { return l-WINDOW_FRAME_RIGHT-1; }
93  int y2() { return h-WINDOW_FRAME_BOTTOM-1; }
94  void clip_in() { screen->set_clip(x1(),y1(),x2(),y2()); }
95  void clip_out() { screen->set_clip(0,0,l-1,h-1); }
96  char *read(int id) { return inm->get(id)->read(); } 
97  void local_close();
98  void set_moveability(int x);
99  ~jwindow() { local_close(); delete screen; delete inm; jfree(name); }
100} ;
101
102class window_manager
103{
104public :
105  event_handler *eh;
106  jwindow *first,*grab;
107  image *screen,*mouse_pic,*mouse_save;
108  palette *pal;
109  int hi,med,low,bk;                            // bright, medium, dark and black colors
110  int key_state[512];
111  enum { inputing,dragging } state;
112  int drag_mousex, drag_mousey,frame_suppress;
113  jwindow *drag_window;
114  JCFont *fnt,*wframe_fnt;
115
116  window_manager(image *Screen, palette *Pal, int Hi, int Med, int Low, JCFont *Font);
117
118  jwindow *new_window(int x, int y, int l, int h, ifield *fields=NULL, char *Name=NULL);
119  void set_frame_font(JCFont *fnt) { wframe_fnt=fnt; }
120  JCFont *frame_font() { return wframe_fnt; }
121  void close_window(jwindow *j);
122  void resize_window(jwindow *j, int l, int h);
123  void move_window(jwindow *j, int x, int y);
124  void get_event(event &ev);
125  void push_event(event *ev) { eh->push_event(ev); }
126  int event_waiting() { return eh->event_waiting(); }
127  void flush_screen();
128  int bright_color() { return hi; }
129  int medium_color() { return med; }
130  int dark_color() { return low; }
131  int black() { return bk; }
132  void set_colors(int Hi, int Med, int Low) { hi=Hi; med=Med; low=Low; }
133  JCFont *font() { return fnt; }
134  int has_mouse() { return eh->has_mouse(); }
135  void mouse_status(int &x, int &y, int &button) {eh->mouse_status(x,y,button); }             
136  void set_mouse_shape(image *im, int centerx, int centery)
137  { eh->set_mouse_shape(im,centerx,centery); }
138
139  void set_mouse_position(int mx, int my)
140  { eh->set_mouse_position(mx,my); }
141
142  int key_pressed(int x) { return key_state[x]; }
143  ~window_manager() { delete eh; while (first) close_window(first); }
144  void hide_windows();
145  void show_windows();
146  void hide_window(jwindow *j);
147  void show_window(jwindow *j);
148  void set_frame_suppress(int x) { frame_suppress=x; }
149  void grab_focus(jwindow *j);
150  void release_focus();
151  int window_in_area(int x1, int y1, int x2, int y2); // true if a window lies in this area
152} ;
153
154#endif
155
156
Note: See TracBrowser for help on using the repository browser.