Permalink
Browse files

Generate mouse/key events from polling in she module instead of ui mo…

…dule
  • Loading branch information...
dacap committed Sep 3, 2014
1 parent bd3fcd3 commit c5a568cd15c7b9e4d83af297153819bac1157388
@@ -27,11 +27,8 @@
#include "ui/system.h"
#include "ui/theme.h"
#include <allegro.h>
#if defined ALLEGRO_WINDOWS && defined DEBUGMODE
#include <winalleg.h>
#include <windows.h>
#include <psapi.h>
#endif
@@ -55,10 +52,6 @@ RefreshCommand::RefreshCommand()
void RefreshCommand::onExecute(Context* context)
{
ui::jmouse_hide();
clear_to_color(screen, makecol(0, 0, 0));
ui::jmouse_show();
// Reload skin
{
skin::SkinTheme* theme = (skin::SkinTheme*)ui::CurrentTheme::get();
View
@@ -2,8 +2,12 @@
# Copyright (C) 2012-2014 David Capello
set(SHE_SOURCES
alleg4/clock.cpp
alleg4/close_button.cpp
alleg4/fontbmp.cpp
alleg4/she_alleg4.cpp)
alleg4/key_poller.cpp
alleg4/mouse_poller.cpp
alleg4/she.cpp)
if(APPLE)
if(NOT USE_SHARED_ALLEGRO4)
View
@@ -0,0 +1,43 @@
// SHE library
// Copyright (C) 2012-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <allegro.h>
static volatile int clock_var = 0; // Global timer.
static void clock_inc()
{
++clock_var;
}
END_OF_STATIC_FUNCTION(clock_inc);
namespace she {
void clock_init()
{
// Install timer related stuff
LOCK_VARIABLE(clock_var);
LOCK_FUNCTION(clock_inc);
install_int_ex(clock_inc, BPS_TO_TIMER(1000));
}
void clock_exit()
{
remove_int(clock_inc);
}
int clock_value()
{
return clock_var;
}
} // namespace she
View
@@ -0,0 +1,18 @@
// SHE library
// Copyright (C) 2012-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef SHE_ALLEG4_CLOCK_H_INCLUDED
#define SHE_ALLEG4_CLOCK_H_INCLUDED
#pragma once
namespace she {
void clock_init();
void clock_exit();
} // namespace she
#endif
@@ -0,0 +1,57 @@
// SHE library
// Copyright (C) 2012-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "she/alleg4/internals.h"
#include "she/event.h"
#include <allegro.h>
namespace {
enum {
STAGE_NORMAL,
STAGE_WANT_CLOSE,
};
// variable to handle the external close button in some Windows enviroments
int want_close_stage;
// hooks the close-button in some platform with window support
void allegro_window_close_hook()
{
if (want_close_stage == STAGE_NORMAL)
want_close_stage = STAGE_WANT_CLOSE;
}
}
namespace she {
void close_button_init()
{
// Hook the window close message
want_close_stage = STAGE_NORMAL;
set_close_button_callback(allegro_window_close_hook);
}
void close_button_generate_events()
{
// Generate Close message when the user press close button on the system window.
if (want_close_stage == STAGE_WANT_CLOSE) {
want_close_stage = STAGE_NORMAL;
Event ev;
ev.setType(Event::CloseDisplay);
ev.setDisplay(unique_display);
queue_event(ev);
}
}
} // namespace she
@@ -0,0 +1,18 @@
// SHE library
// Copyright (C) 2012-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef SHE_ALLEG4_CLOSE_BUTTON_H_INCLUDED
#define SHE_ALLEG4_CLOSE_BUTTON_H_INCLUDED
#pragma once
namespace she {
void close_button_init();
void close_button_generate_events();
} // namespace she
#endif
File renamed without changes.
@@ -13,9 +13,9 @@
#include "config.h"
#endif
#include "she/alleg4/alleg4_font.h"
#include "she/alleg4/font.h"
#include "she/alleg4/alleg4_surface.h"
#include "she/alleg4/surface.h"
#include "she/display.h"
#include "she/system.h"
@@ -10,8 +10,11 @@
namespace she {
class Display;
class Event;
extern Display* unique_display;
void queue_event(const Event& ev);
} // namespace she
@@ -0,0 +1,93 @@
// SHE library
// Copyright (C) 2012-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "she/alleg4/internals.h"
#include "she/she.h"
#include <allegro.h>
namespace {
static char old_readed_key[KEY_MAX]; // keyboard status of previous poll
static unsigned key_repeated[KEY_MAX];
}
namespace she {
void key_poller_init()
{
// Reset keyboard
for (int c=0; c<KEY_MAX; c++) {
old_readed_key[c] = 0;
key_repeated[c] = 0;
}
}
void key_poller_generate_events()
{
Event ev;
// Poll keyboard
poll_keyboard();
// Generate kKeyDownMessage messages.
int c;
while (keypressed()) {
int scancode;
int unicode_char = ureadkey(&scancode);
int repeat = 0;
{
c = scancode;
if (c >= 0 && c < KEY_MAX) {
old_readed_key[c] = key[c];
repeat = key_repeated[c]++;
}
}
ev.setType(Event::KeyDown);
ev.setScancode(static_cast<KeyScancode>(scancode));
ev.setUnicodeChar(unicode_char);
ev.setRepeat(repeat);
queue_event(ev);
}
for (int c=0; c<KEY_MAX; c++) {
if (old_readed_key[c] != key[c]) {
KeyScancode scancode = static_cast<KeyScancode>(c);
// Generate kKeyUpMessage messages (old key state is activated,
// the new one is deactivated).
if (old_readed_key[c]) {
ev.setType(Event::KeyUp);
ev.setScancode(scancode);
ev.setUnicodeChar(::scancode_to_ascii(scancode));
ev.setRepeat(0);
queue_event(ev);
old_readed_key[c] = key[c];
key_repeated[c] = 0;
}
// Generate kKeyDownMessage messages for modifiers
else if (c >= kKeyFirstModifierScancode) {
ev.setType(Event::KeyDown);
ev.setScancode(scancode);
ev.setUnicodeChar(::scancode_to_ascii(scancode));
ev.setRepeat(key_repeated[c]++);
queue_event(ev);
old_readed_key[c] = key[c];
}
}
}
}
} // namespace she
@@ -0,0 +1,18 @@
// SHE library
// Copyright (C) 2012-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef SHE_ALLEG4_KEY_POLLER_H_INCLUDED
#define SHE_ALLEG4_KEY_POLLER_H_INCLUDED
#pragma once
namespace she {
void key_poller_init();
void key_poller_generate_events();
} // namespace she
#endif
Oops, something went wrong.

0 comments on commit c5a568c

Please sign in to comment.