mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-28 16:20:50 +00:00
Add she::EventQueue to she::Display to get events from she library
This commit is contained in:
parent
aa27c0d68a
commit
be6b98995e
@ -9,8 +9,9 @@
|
|||||||
|
|
||||||
namespace she {
|
namespace she {
|
||||||
|
|
||||||
class Surface;
|
class EventQueue;
|
||||||
class NotDisposableSurface;
|
class NotDisposableSurface;
|
||||||
|
class Surface;
|
||||||
|
|
||||||
// A display or window to show graphics.
|
// A display or window to show graphics.
|
||||||
class Display {
|
class Display {
|
||||||
@ -43,6 +44,8 @@ namespace she {
|
|||||||
virtual void maximize() = 0;
|
virtual void maximize() = 0;
|
||||||
virtual bool isMaximized() const = 0;
|
virtual bool isMaximized() const = 0;
|
||||||
|
|
||||||
|
virtual EventQueue* getEventQueue() = 0;
|
||||||
|
|
||||||
// Returns the HWND on Windows.
|
// Returns the HWND on Windows.
|
||||||
virtual void* nativeHandle() = 0;
|
virtual void* nativeHandle() = 0;
|
||||||
};
|
};
|
||||||
|
29
src/she/event.h
Normal file
29
src/she/event.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// SHE library
|
||||||
|
// Copyright (C) 2012-2014 David Capello
|
||||||
|
//
|
||||||
|
// This source file is ditributed under a BSD-like license, please
|
||||||
|
// read LICENSE.txt for more information.
|
||||||
|
|
||||||
|
#ifndef SHE_EVENT_H_INCLUDED
|
||||||
|
#define SHE_EVENT_H_INCLUDED
|
||||||
|
|
||||||
|
namespace she {
|
||||||
|
|
||||||
|
class Event {
|
||||||
|
public:
|
||||||
|
enum Type {
|
||||||
|
None,
|
||||||
|
};
|
||||||
|
|
||||||
|
Event() : m_type(None) { }
|
||||||
|
|
||||||
|
int type() const { return m_type; }
|
||||||
|
void setType(Type type) { m_type = type; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Type m_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace she
|
||||||
|
|
||||||
|
#endif
|
@ -4,15 +4,18 @@
|
|||||||
// This source file is ditributed under a BSD-like license, please
|
// This source file is ditributed under a BSD-like license, please
|
||||||
// read LICENSE.txt for more information.
|
// read LICENSE.txt for more information.
|
||||||
|
|
||||||
#ifndef SHE_EVENT_LOOP_H_INCLUDED
|
#ifndef SHE_EVENT_QUEUE_H_INCLUDED
|
||||||
#define SHE_EVENT_LOOP_H_INCLUDED
|
#define SHE_EVENT_QUEUE_H_INCLUDED
|
||||||
|
|
||||||
namespace she {
|
namespace she {
|
||||||
|
|
||||||
class EventLoop {
|
class Event;
|
||||||
|
|
||||||
|
class EventQueue {
|
||||||
public:
|
public:
|
||||||
virtual ~EventLoop() { }
|
virtual ~EventQueue() { }
|
||||||
virtual void dispose() = 0;
|
virtual void dispose() = 0;
|
||||||
|
virtual void getEvent(Event& ev) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace she
|
} // namespace she
|
@ -8,7 +8,8 @@
|
|||||||
#define SHE_H_INCLUDED
|
#define SHE_H_INCLUDED
|
||||||
|
|
||||||
#include "she/display.h"
|
#include "she/display.h"
|
||||||
#include "she/event_loop.h"
|
#include "she/event.h"
|
||||||
|
#include "she/event_queue.h"
|
||||||
#include "she/locked_surface.h"
|
#include "she/locked_surface.h"
|
||||||
#include "she/scoped_handle.h"
|
#include "she/scoped_handle.h"
|
||||||
#include "she/scoped_surface_lock.h"
|
#include "she/scoped_surface_lock.h"
|
||||||
|
@ -12,12 +12,21 @@
|
|||||||
|
|
||||||
#include <allegro.h>
|
#include <allegro.h>
|
||||||
#include <allegro/internal/aintern.h>
|
#include <allegro/internal/aintern.h>
|
||||||
#ifdef ALLEGRO_WINDOWS
|
|
||||||
|
#ifdef WIN32
|
||||||
#include <winalleg.h>
|
#include <winalleg.h>
|
||||||
|
|
||||||
|
#if defined STRICT || defined __GNUC__
|
||||||
|
typedef WNDPROC wndproc_t;
|
||||||
|
#else
|
||||||
|
typedef FARPROC wndproc_t;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "loadpng.h"
|
#include "loadpng.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#define DISPLAY_FLAG_FULL_REFRESH 1
|
#define DISPLAY_FLAG_FULL_REFRESH 1
|
||||||
#define DISPLAY_FLAG_WINDOW_RESIZE 2
|
#define DISPLAY_FLAG_WINDOW_RESIZE 2
|
||||||
@ -125,6 +134,60 @@ private:
|
|||||||
DestroyFlag m_destroy;
|
DestroyFlag m_destroy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Alleg4EventQueue : public EventQueue {
|
||||||
|
public:
|
||||||
|
Alleg4EventQueue() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispose() {
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void getEvent(Event& event) {
|
||||||
|
if (m_events.size() > 0) {
|
||||||
|
event = m_events[0];
|
||||||
|
m_events.erase(m_events.begin());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
event.setType(Event::None);
|
||||||
|
}
|
||||||
|
|
||||||
|
void queueEvent(const Event& event) {
|
||||||
|
m_events.push_back(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Event> m_events;
|
||||||
|
};
|
||||||
|
|
||||||
|
#if WIN32
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
Display* g_display = NULL;
|
||||||
|
wndproc_t base_wndproc = NULL;
|
||||||
|
|
||||||
|
static LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
// switch (msg) {
|
||||||
|
// }
|
||||||
|
return ::CallWindowProc(base_wndproc, hwnd, msg, wparam, lparam);
|
||||||
|
}
|
||||||
|
|
||||||
|
void subclass_hwnd(HWND hwnd)
|
||||||
|
{
|
||||||
|
base_wndproc = (wndproc_t)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)wndproc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void unsubclass_hwnd(HWND hwnd)
|
||||||
|
{
|
||||||
|
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)base_wndproc);
|
||||||
|
base_wndproc = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
class Alleg4Display : public Display {
|
class Alleg4Display : public Display {
|
||||||
public:
|
public:
|
||||||
Alleg4Display(int width, int height, int scale)
|
Alleg4Display(int width, int height, int scale)
|
||||||
@ -150,6 +213,8 @@ public:
|
|||||||
|
|
||||||
setScale(scale);
|
setScale(scale);
|
||||||
|
|
||||||
|
m_queue = new Alleg4EventQueue();
|
||||||
|
|
||||||
// Add a hook to display-switch so when the user returns to the
|
// Add a hook to display-switch so when the user returns to the
|
||||||
// screen it's completelly refreshed/redrawn.
|
// screen it's completelly refreshed/redrawn.
|
||||||
LOCK_VARIABLE(display_flags);
|
LOCK_VARIABLE(display_flags);
|
||||||
@ -160,9 +225,19 @@ public:
|
|||||||
// Setup the handler for window-resize events
|
// Setup the handler for window-resize events
|
||||||
set_resize_callback(resize_callback);
|
set_resize_callback(resize_callback);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if WIN32
|
||||||
|
subclass_hwnd((HWND)nativeHandle());
|
||||||
|
#endif WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
~Alleg4Display() {
|
~Alleg4Display() {
|
||||||
|
delete m_queue;
|
||||||
|
|
||||||
|
#if WIN32
|
||||||
|
unsubclass_hwnd((HWND)nativeHandle());
|
||||||
|
#endif WIN32
|
||||||
|
|
||||||
m_surface->dispose();
|
m_surface->dispose();
|
||||||
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
|
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
@ -246,6 +321,10 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EventQueue* getEventQueue() {
|
||||||
|
return m_queue;
|
||||||
|
}
|
||||||
|
|
||||||
void* nativeHandle() {
|
void* nativeHandle() {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
return reinterpret_cast<void*>(win_get_window());
|
return reinterpret_cast<void*>(win_get_window());
|
||||||
@ -257,16 +336,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
Surface* m_surface;
|
Surface* m_surface;
|
||||||
int m_scale;
|
int m_scale;
|
||||||
};
|
Alleg4EventQueue* m_queue;
|
||||||
|
|
||||||
class Alleg4EventLoop : public EventLoop {
|
|
||||||
public:
|
|
||||||
Alleg4EventLoop() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void dispose() {
|
|
||||||
delete this;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Alleg4System : public System {
|
class Alleg4System : public System {
|
||||||
@ -307,10 +377,6 @@ public:
|
|||||||
Alleg4Surface::AutoDestroy);
|
Alleg4Surface::AutoDestroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventLoop* createEventLoop() {
|
|
||||||
return new Alleg4EventLoop();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static System* g_instance;
|
static System* g_instance;
|
||||||
|
@ -30,7 +30,6 @@ namespace she {
|
|||||||
virtual Display* createDisplay(int width, int height, int scale) = 0;
|
virtual Display* createDisplay(int width, int height, int scale) = 0;
|
||||||
virtual Surface* createSurface(int width, int height) = 0;
|
virtual Surface* createSurface(int width, int height) = 0;
|
||||||
virtual Surface* createSurfaceFromNativeHandle(void* nativeHandle) = 0;
|
virtual Surface* createSurfaceFromNativeHandle(void* nativeHandle) = 0;
|
||||||
virtual EventLoop* createEventLoop() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
System* CreateSystem();
|
System* CreateSystem();
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
|
|
||||||
#include "ui/manager.h"
|
#include "ui/manager.h"
|
||||||
|
|
||||||
|
#include "she/display.h"
|
||||||
|
#include "she/event.h"
|
||||||
|
#include "she/event_queue.h"
|
||||||
#include "ui/intern.h"
|
#include "ui/intern.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
@ -106,6 +109,8 @@ static void allegro_window_close_hook()
|
|||||||
|
|
||||||
Manager::Manager()
|
Manager::Manager()
|
||||||
: Widget(kManagerWidget)
|
: Widget(kManagerWidget)
|
||||||
|
, m_display(NULL)
|
||||||
|
, m_eventQueue(NULL)
|
||||||
{
|
{
|
||||||
if (!m_defaultManager) {
|
if (!m_defaultManager) {
|
||||||
// Hook the window close message
|
// Hook the window close message
|
||||||
@ -173,6 +178,12 @@ Manager::~Manager()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Manager::setDisplay(she::Display* display)
|
||||||
|
{
|
||||||
|
m_display = display;
|
||||||
|
m_eventQueue = m_display->getEventQueue();
|
||||||
|
}
|
||||||
|
|
||||||
void Manager::run()
|
void Manager::run()
|
||||||
{
|
{
|
||||||
MessageLoop loop(this);
|
MessageLoop loop(this);
|
||||||
@ -442,6 +453,18 @@ bool Manager::generateMessages()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Events from "she" layer.
|
||||||
|
she::Event sheEvent;
|
||||||
|
for (;;) {
|
||||||
|
m_eventQueue->getEvent(sheEvent);
|
||||||
|
if (sheEvent.type() == she::Event::None)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// switch (sheEvent.type()) {
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
// Generate messages for timers
|
// Generate messages for timers
|
||||||
Timer::pollTimers();
|
Timer::pollTimers();
|
||||||
|
|
||||||
|
@ -12,7 +12,10 @@
|
|||||||
#include "ui/mouse_buttons.h"
|
#include "ui/mouse_buttons.h"
|
||||||
#include "ui/widget.h"
|
#include "ui/widget.h"
|
||||||
|
|
||||||
namespace she { class Display; }
|
namespace she {
|
||||||
|
class Display;
|
||||||
|
class EventQueue;
|
||||||
|
}
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
@ -31,7 +34,7 @@ namespace ui {
|
|||||||
~Manager();
|
~Manager();
|
||||||
|
|
||||||
she::Display* getDisplay() { return m_display; }
|
she::Display* getDisplay() { return m_display; }
|
||||||
void setDisplay(she::Display* display) { m_display = display; }
|
void setDisplay(she::Display* display);
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
@ -99,6 +102,7 @@ namespace ui {
|
|||||||
|
|
||||||
WidgetsList m_garbage;
|
WidgetsList m_garbage;
|
||||||
she::Display* m_display;
|
she::Display* m_display;
|
||||||
|
she::EventQueue* m_eventQueue;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ui
|
} // namespace ui
|
||||||
|
Loading…
x
Reference in New Issue
Block a user