source: abuse/trunk/src/imlib/jwindow.hpp @ 57

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