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

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

imlib: merge JCMouse into EventHandler?.

  • Property svn:keywords set to Id
File size: 2.3 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
31class Jwindow;
32
33class Event : public linked_node
34{
35public:
36    Event()
37    {
38        type = EV_SPURIOUS;
39    }
40
41    Event(int id, char *data)
42    {
43        type = EV_MESSAGE;
44        message.id = id;
45        message.data = data;
46    }
47
48    int type;
49    vec2i mouse_move;
50    int mouse_button, key;
51
52    struct { char alt, ctrl, shift; } key_special;
53    struct { int x1, y1, x2, y2; void *start; } redraw;
54
55    Jwindow *window;      // NULL is root
56    vec2i window_position;
57    struct { int id; char *data; } message;
58};
59
60class EventHandler
61{
62public:
63    EventHandler(image *screen, palette *pal);
64    ~EventHandler();
65
66    void Push(Event *ev)
67    {
68        m_events.add_end(ev);
69    }
70
71    void SysInit();
72    void SysWarpMouse(vec2i pos);
73
74  int IsPending();
75  void Get(Event &ev);
76  void add_redraw(int X1, int Y1, int X2, int Y2, void *Start);
77  void flush_screen();
78
79  int has_mouse() { return 1; }
80  void set_mouse_shape(image *im, int centerx, int centery)
81  {
82    m_sprite->change_visual(im);
83    m_center = vec2i(-centerx, -centery);
84  }
85  void set_mouse_position(int mx, int my)
86  {
87    m_pos = vec2i(Min(mx, m_screen->Size().x - 1),
88                  Min(my, m_screen->Size().y - 1));
89    SysWarpMouse(m_pos);
90  }
91
92private:
93    int get_key_flags();
94
95    linked_list m_events;
96    int m_pending, last_keystat, last_key;
97    sprite_controller sc;
98
99    image *m_screen;
100
101protected:
102    /* Mouse information */
103    sprite *m_sprite;
104    vec2i m_pos, m_lastpos, m_center;
105    int m_button, m_lastbutton;
106};
107
108#endif
109
Note: See TracBrowser for help on using the repository browser.