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

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

core: rename vec2i to ivec2 and update matrix.h from Lol Engine.

  • Property svn:keywords set to Id
File size: 2.1 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]5 *
6 *  This software was released into the Public Domain. As with most public
[555]7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
[56]9 */
10
[2]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
[673]17/* #define EV_REDRAW        16 UNUSED */
[124]18#define EV_SPURIOUS      32
[2]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
[669]28
[481]29#include "keys.h"
30#include "sprite.h"
[2]31
[120]32class Jwindow;
[2]33
[643]34class Event : public linked_node
[2]35{
[643]36public:
37    Event()
38    {
39        type = EV_SPURIOUS;
40    }
[2]41
[643]42    Event(int id, char *data)
43    {
44        type = EV_MESSAGE;
45        message.id = id;
46        message.data = data;
47    }
48
49    int type;
[682]50    ivec2 mouse_move;
[643]51    int mouse_button, key;
52
53    struct { char alt, ctrl, shift; } key_special;
54
55    Jwindow *window;      // NULL is root
[682]56    ivec2 window_position;
[643]57    struct { int id; char *data; } message;
58};
59
60class EventHandler
[2]61{
[643]62public:
63    EventHandler(image *screen, palette *pal);
64    ~EventHandler();
65
66    void Push(Event *ev)
67    {
68        m_events.add_end(ev);
69    }
70
[652]71    void SysInit();
[682]72    void SysWarpMouse(ivec2 pos);
[656]73    void SysEvent(Event &ev);
[652]74
[673]75    int IsPending();
76    void Get(Event &ev);
[652]77  void flush_screen();
78
79  int has_mouse() { return 1; }
[682]80    void SetMouseShape(image *im, ivec2 center)
[656]81    {
[669]82        m_sprite->SetVisual(im, 1);
[656]83        m_center = center;
84    }
[682]85    void SetMousePos(ivec2 pos)
[656]86    {
[682]87        m_pos = ivec2(Min(Max(pos.x, 0), m_screen->Size().x - 1),
[656]88                      Min(Max(pos.y, 0), m_screen->Size().y - 1));
89        SysWarpMouse(m_pos);
90    }
[643]91
92private:
93    linked_list m_events;
[656]94    int m_pending, last_key;
[652]95
96    image *m_screen;
97
98protected:
99    /* Mouse information */
[669]100    Sprite *m_sprite;
[682]101    ivec2 m_pos, m_center;
[656]102    int m_button;
[643]103};
104
[2]105#endif
106
Note: See TracBrowser for help on using the repository browser.