source: abuse/branches/lol/src/imlib/window.h @ 729

Last change on this file since 729 was 729, checked in by Sam Hocevar, 8 years ago

build: sync with newer Lol Engine changes.

  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2013 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#ifndef __JWIN__
12#define __JWIN__
13
14#include <stdarg.h>
15
16#include "imlib/video.h"
17#include "imlib/image.h"
18#include "imlib/event.h"
19#include "imlib/filter.h"
20#include "imlib/fonts.h"
21
22class WindowManager;
23class InputManager;
24class AWindow;
25
26extern int frame_top();
27extern int frame_bottom();
28extern int frame_left();
29extern int frame_right();
30
31void set_frame_size(int x);
32
33class AWidget
34{
35    friend class AWindow;
36    friend class InputManager;
37
38public:
39    AWidget();
40    AWidget(ivec2 pos, int id);
41    virtual ~AWidget();
42
43    virtual void set_owner(AWindow *owner);
44    virtual void Move(ivec2 pos) { m_pos = pos; }
45    virtual ibox2 GetArea() = 0;
46    virtual void draw_first(AImage *screen) = 0;
47    virtual void Draw(int active, AImage *screen) = 0;
48    virtual void handle_event(Event &ev, AImage *screen, InputManager *im) = 0;
49    virtual int selectable() { return 1; }
50    virtual void remap(Filter *f) { (void)f; }
51    virtual char const *read() = 0;
52    virtual AWidget *find(int search_id) { if (m_id == search_id) return this; else return nullptr; }
53    virtual AWidget *unlink(int id) { (void)id; return nullptr; }
54
55    ivec2 m_pos;
56    int m_id;
57
58protected:
59    AWindow *m_owner;
60};
61
62class AWidgetList : public array<AWidget *>
63{
64};
65
66class InputManager
67{
68    friend class AWindow;
69
70public:
71    InputManager(AImage *screen, AWidgetList const &fields = AWidgetList());
72    InputManager(AWindow *owner, AWidgetList const &fields = AWidgetList());
73    ~InputManager();
74
75    void handle_event(Event &ev, AWindow *j);
76    AWidget *get(int id);
77    void redraw();
78    void Add(AWidgetList const &fields);
79    void remap(Filter *f);
80    AWidget *unlink(int id); // unlink ID from list and return field pointer
81    void clear_current();
82    void grab_focus(AWidget *i);
83    void release_focus();
84    void allow_no_selections();
85
86private:
87    AImage *m_surf;
88    AWidgetList m_fields;
89    int m_active, m_grab;
90    AWindow *m_cur, *m_owner;
91    int no_selections_allowed;
92};
93
94class AWindow
95{
96    friend class InputManager;
97
98public:
99    AWindow *next;
100    int backg;
101    InputManager *inm;
102    void *local_info;  // pointer to info block for local system (may support windows)
103
104    AWindow(String const &name = "");
105    AWindow(ivec2 pos, ivec2 size,
106            String const &name = "",
107            AWidgetList const &widgets = AWidgetList());
108    ~AWindow();
109
110    virtual void redraw();
111    void Resize(ivec2 size);
112    void clear(int color = 0) { m_surf->Bar(ivec2(x1(), y1()),
113                                            ivec2(x2(), y2()), color); }
114    void show() { _hidden = false; }
115    void hide() { _hidden = true; }
116    bool is_hidden() { return _hidden; }
117    void freeze() { _moveable = false; }
118    void thaw() { _moveable = true; }
119    bool is_moveable() { return _moveable; }
120    int x1() { return _x1; }
121    int y1() { return _y1; }
122    int x2() { return _x2; }
123    int y2() { return _y2; }
124    char const *read(int id) { return inm->get(id)->read(); }
125    void local_close();
126
127    static int left_border();
128    static int right_border();
129    static int top_border();
130    static int bottom_border();
131
132    ivec2 m_pos, m_size;
133    AImage *m_surf;
134
135protected:
136    AWindow *m_owner;
137    int _x1, _y1, _x2, _y2;
138
139private:
140    char *_name;
141    bool _hidden;
142    bool _moveable;
143
144    void reconfigure();
145};
146
147class WindowManager : public EventHandler
148{
149    friend class AWindow;
150
151protected:
152    void add_window(AWindow *);
153    void remove_window(AWindow *);
154
155public:
156    WindowManager(AImage *, Palette *, int hi, int med, int low, JCFont *);
157    ~WindowManager();
158
159    AWindow *m_first, *m_grab;
160    AImage *mouse_pic, *mouse_save;
161    int hi, med, low, bk; // bright, medium, dark and black colors
162    int key_state[512];
163    enum { inputing, dragging } state;
164    int drag_mousex, drag_mousey, frame_suppress;
165    AWindow *drag_window;
166    JCFont *fnt, *wframe_fnt;
167
168    AWindow *CreateWindow(ivec2 pos, ivec2 size,
169                          String const &name = "",
170                          AWidgetList const &widgets = AWidgetList());
171
172    JCFont *frame_font() { return wframe_fnt; }
173    void close_window(AWindow *j);
174    void resize_window(AWindow *j, int l, int h);
175    void move_window(AWindow *j, int x, int y);
176    void get_event(Event &ev);
177    void flush_screen();
178    int bright_color() { return hi; }
179    int medium_color() { return med; }
180    int dark_color() { return low; }
181    int black() { return bk; }
182    void set_colors(int Hi, int Med, int Low) { hi=Hi; med=Med; low=Low; }
183    JCFont *font() { return fnt; }
184
185    int key_pressed(int x) { return key_state[x]; }
186    void hide_windows();
187    void show_windows();
188    void hide_window(AWindow *j);
189    void show_window(AWindow *j);
190    void grab_focus(AWindow *j);
191    void release_focus();
192
193private:
194    Palette *m_pal;
195    AImage *m_surf;
196};
197
198#endif
199
200
Note: See TracBrowser for help on using the repository browser.