2013-01-18 10:38:13 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
|
|
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ENTRY_PRIVATE_H__
|
|
|
|
#define __ENTRY_PRIVATE_H__
|
|
|
|
|
2013-01-17 10:44:51 +04:00
|
|
|
#include <bx/spscqueue.h>
|
|
|
|
|
|
|
|
#include "entry.h"
|
2013-01-18 10:38:13 +04:00
|
|
|
|
2013-08-15 08:08:46 +04:00
|
|
|
#ifndef ENTRY_CONFIG_USE_SDL
|
|
|
|
# define ENTRY_CONFIG_USE_SDL BX_PLATFORM_OSX
|
|
|
|
#endif // ENTRY_CONFIG_USE_SDL
|
|
|
|
|
|
|
|
#ifndef ENTRY_CONFIG_USE_NATIVE
|
|
|
|
# define ENTRY_CONFIG_USE_NATIVE !ENTRY_CONFIG_USE_SDL
|
|
|
|
#endif // ENTRY_CONFIG_USE_NATIVE
|
|
|
|
|
|
|
|
#if !defined(ENTRY_DEFAULT_WIDTH) && !defined(ENTRY_DEFAULT_HEIGHT)
|
|
|
|
# define ENTRY_DEFAULT_WIDTH 1280
|
|
|
|
# define ENTRY_DEFAULT_HEIGHT 720
|
|
|
|
#elif !defined(ENTRY_DEFAULT_WIDTH) || !defined(ENTRY_DEFAULT_HEIGHT)
|
|
|
|
# error "Both ENTRY_DEFAULT_WIDTH and ENTRY_DEFAULT_HEIGHT must be defined."
|
|
|
|
#endif // ENTRY_DEFAULT_WIDTH
|
|
|
|
|
2013-01-18 10:38:13 +04:00
|
|
|
namespace entry
|
|
|
|
{
|
2013-08-08 08:45:56 +04:00
|
|
|
int main(int _argc, char** _argv);
|
|
|
|
|
|
|
|
struct Event
|
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
Exit,
|
|
|
|
Key,
|
|
|
|
Mouse,
|
|
|
|
Size,
|
|
|
|
};
|
|
|
|
|
|
|
|
Event::Enum m_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct KeyEvent : public Event
|
|
|
|
{
|
|
|
|
Key::Enum m_key;
|
|
|
|
uint8_t m_modifiers;
|
|
|
|
bool m_down;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MouseEvent : public Event
|
|
|
|
{
|
|
|
|
int32_t m_mx;
|
|
|
|
int32_t m_my;
|
|
|
|
MouseButton::Enum m_button;
|
|
|
|
bool m_down;
|
|
|
|
bool m_move;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SizeEvent : public Event
|
|
|
|
{
|
|
|
|
uint32_t m_width;
|
|
|
|
uint32_t m_height;
|
|
|
|
};
|
|
|
|
|
|
|
|
const Event* poll();
|
|
|
|
void release(const Event* _event);
|
|
|
|
|
|
|
|
void setWindowSize(uint32_t _width, uint32_t _height);
|
|
|
|
void toggleWindowFrame();
|
|
|
|
void setMouseLock(bool _lock);
|
|
|
|
|
2013-01-17 10:44:51 +04:00
|
|
|
class EventQueue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void postExitEvent()
|
|
|
|
{
|
|
|
|
Event* ev = new Event;
|
|
|
|
ev->m_type = Event::Exit;
|
|
|
|
m_queue.push(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void postKeyEvent(Key::Enum _key, uint8_t _modifiers, bool _down)
|
|
|
|
{
|
|
|
|
KeyEvent* ev = new KeyEvent;
|
|
|
|
ev->m_type = Event::Key;
|
|
|
|
ev->m_key = _key;
|
|
|
|
ev->m_modifiers = _modifiers;
|
|
|
|
ev->m_down = _down;
|
|
|
|
m_queue.push(ev);
|
|
|
|
}
|
|
|
|
|
2013-01-18 11:22:38 +04:00
|
|
|
void postMouseEvent(int32_t _mx, int32_t _my)
|
|
|
|
{
|
|
|
|
MouseEvent* ev = new MouseEvent;
|
|
|
|
ev->m_type = Event::Mouse;
|
|
|
|
ev->m_mx = _mx;
|
|
|
|
ev->m_my = _my;
|
|
|
|
ev->m_button = MouseButton::None;
|
|
|
|
ev->m_down = false;
|
|
|
|
ev->m_move = true;
|
|
|
|
m_queue.push(ev);
|
|
|
|
}
|
|
|
|
|
2013-01-17 10:44:51 +04:00
|
|
|
void postMouseEvent(int32_t _mx, int32_t _my, MouseButton::Enum _button, bool _down)
|
|
|
|
{
|
|
|
|
MouseEvent* ev = new MouseEvent;
|
|
|
|
ev->m_type = Event::Mouse;
|
|
|
|
ev->m_mx = _mx;
|
|
|
|
ev->m_my = _my;
|
|
|
|
ev->m_button = _button;
|
|
|
|
ev->m_down = _down;
|
2013-01-18 11:22:38 +04:00
|
|
|
ev->m_move = false;
|
2013-01-17 10:44:51 +04:00
|
|
|
m_queue.push(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void postSizeEvent(uint32_t _width, uint32_t _height)
|
|
|
|
{
|
|
|
|
SizeEvent* ev = new SizeEvent;
|
|
|
|
ev->m_type = Event::Size;
|
|
|
|
ev->m_width = _width;
|
|
|
|
ev->m_height = _height;
|
|
|
|
m_queue.push(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Event* poll()
|
|
|
|
{
|
|
|
|
return m_queue.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void release(const Event* _event) const
|
|
|
|
{
|
|
|
|
delete _event;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bx::SpScUnboundedQueue<Event> m_queue;
|
|
|
|
};
|
2013-01-18 10:38:13 +04:00
|
|
|
|
|
|
|
} // namespace entry
|
|
|
|
|
|
|
|
#endif // __ENTRY_PRIVATE_H__
|