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

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