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

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

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

  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 2001 Anthony Kruize <trandor@labyrinth.net.au>
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This program is free software; you can redistribute it and/or modify
7 *  it under the terms of the GNU General Public License as published by
8 *  the Free Software Foundation; either version 2 of the License, or
9 *  (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with this program; if not, write to the Free Software Foundation,
18 *  Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 */
20
21#if defined HAVE_CONFIG_H
22#   include "config.h"
23#endif
24
25#include "common.h"
26
27#include "event.h"
28#include "video.h"
29#include "filter.h"
30
31//
32// Constructor
33//
34EventHandler::EventHandler(image *screen, palette *pal)
35{
36    CHECK(screen && pal);
37    m_pending = 0;
38
39    m_screen = screen;
40
41    // Mouse stuff
42    uint8_t mouse_sprite[]=
43    {
44        0, 2, 0, 0, 0, 0, 0, 0,
45        2, 1, 2, 0, 0, 0, 0, 0,
46        2, 1, 1, 2, 0, 0, 0, 0,
47        2, 1, 1, 1, 2, 0, 0, 0,
48        2, 1, 1, 1, 1, 2, 0, 0,
49        2, 1, 1, 1, 1, 1, 2, 0,
50        0, 2, 1, 1, 2, 2, 0, 0,
51        0, 0, 2, 1, 1, 2, 0, 0,
52        0, 0, 2, 1, 1, 2, 0, 0,
53        0, 0, 0, 2, 2, 0, 0, 0
54    };
55
56    Filter f;
57    f.Set(1, pal->brightest(1));
58    f.Set(2, pal->darkest(1));
59    image *im = new image(ivec2(8, 10), mouse_sprite);
60    f.Apply(im);
61
62    m_sprite = new Sprite(screen, im, ivec2(100, 100));
63    m_pos = screen->Size() / 2;
64    m_center = ivec2(0, 0);
65    m_button = 0;
66
67    // Platform-specific stuff
68    SysInit();
69}
70
71//
72// Destructor
73//
74EventHandler::~EventHandler()
75{
76    ;
77}
78
79void EventHandler::Get(Event &ev)
80{
81    // Sleep until there are events available
82    while(!m_pending)
83    {
84        Timer tmp;
85        IsPending();
86
87        if (!m_pending)
88            tmp.WaitMs(1);
89    }
90
91    // Return first queued event if applicable
92    Event *ep = (Event *)m_events.first();
93    if(ep)
94    {
95        ev = *ep;
96        m_events.unlink(ep);
97        delete ep;
98        m_pending = m_events.first() != NULL;
99        return;
100    }
101
102    // Return an event from the platform-specific system
103    SysEvent(ev);
104}
105
106//
107// flush_screen()
108// Redraw the screen
109//
110void EventHandler::flush_screen()
111{
112    update_dirty(main_screen);
113}
114
Note: See TracBrowser for help on using the repository browser.