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

Last change on this file since 106 was 106, checked in by Sam Hocevar, 11 years ago
  • Rename the "eh" variable to "wm" because it's a window manager, not an event handler.
  • No longer pass the window manager to functions, there's only one.

Inspired by Win32 Abuse changelog for January 28, 2001:

  • Starting work on singleton code; will get rid of all

references to an arbitrary window_manager* because
there's only going to be one, and it's not ever
going to change.

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