source: abuse/trunk/src/imlib/event.h @ 645

Last change on this file since 645 was 645, checked in by Sam Hocevar, 11 years ago

imlib: clean up EventHandler? and JCMouse.

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 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 __EVENT_HPP_
12#define __EVENT_HPP_
13#define EV_MOUSE_MOVE     1
14#define EV_MOUSE_BUTTON   2
15#define EV_KEY            4
16#define EV_KEY_SPECIAL    8
17#define EV_REDRAW        16
18#define EV_SPURIOUS      32
19#define EV_RESIZE        64
20#define EV_KEYRELEASE   128
21#define EV_CLOSE_WINDOW 256
22#define EV_DRAG_WINDOW  512
23#define EV_MESSAGE     1024
24
25#define LEFT_BUTTON    1
26#define RIGHT_BUTTON   2
27#define MIDDLE_BUTTON  4
28#include "keys.h"
29#include "sprite.h"
30#include "mouse.h"
31
32class Jwindow;
33
34class Event : public linked_node
35{
36public:
37    Event()
38    {
39        type = EV_SPURIOUS;
40    }
41
42    Event(int id, char *data)
43    {
44        type = EV_MESSAGE;
45        message.id = id;
46        message.data = data;
47    }
48
49    int type;
50    vec2i mouse_move;
51    int mouse_button, key;
52
53    struct { char alt, ctrl, shift; } key_special;
54    struct { int x1, y1, x2, y2; void *start; } redraw;
55
56    Jwindow *window;      // NULL is root
57    vec2i window_position;
58    struct { int id; char *data; } message;
59};
60
61class EventHandler
62{
63public:
64    EventHandler(image *screen, palette *pal);
65    ~EventHandler();
66
67    void Push(Event *ev)
68    {
69        m_events.add_end(ev);
70    }
71
72  JCMouse *mouse;
73  sprite *mouse_sprite() { return mouse->mouse_sprite(); }
74  int IsPending();
75  void Get(Event &ev);
76  void add_redraw(int X1, int Y1, int X2, int Y2, void *Start);
77  void mouse_status(int &x, int &y, int &button)
78  {
79    if (mouse)
80    {
81      x = mouse->x();
82      y = mouse->y();
83      button = mouse->button();
84    } else x = y = button = 0;
85  }
86  void flush_screen();
87  int has_mouse() { return mouse->exists(); }
88  void set_mouse_shape(image *im, int centerx, int centery) { mouse->set_shape(im, -centerx, -centery); }
89  void set_mouse_position(int mx, int my) { if (mouse) mouse->set_position(mx, my); }
90
91private:
92    int get_key_flags();
93
94    linked_list m_events;
95    int mhere, m_pending, last_keystat, last_key;
96    sprite_controller sc;
97};
98
99#endif
100
Note: See TracBrowser for help on using the repository browser.