mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-29 02:55:36 -05:00
WIP key/mouse support.
This commit is contained in:
parent
e764548220
commit
165e98c60b
3 changed files with 155 additions and 116 deletions
|
@ -48,11 +48,7 @@ namespace entry
|
||||||
int m_argc;
|
int m_argc;
|
||||||
char** m_argv;
|
char** m_argv;
|
||||||
|
|
||||||
static int32_t threadFunc(void* _userData)
|
static int32_t threadFunc(void* _userData);
|
||||||
{
|
|
||||||
MainThreadEntry* self = (MainThreadEntry*)_userData;
|
|
||||||
return _main_(self->m_argc, self->m_argv);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Context
|
struct Context
|
||||||
|
@ -142,22 +138,25 @@ namespace entry
|
||||||
XInitThreads();
|
XInitThreads();
|
||||||
m_display = XOpenDisplay(0);
|
m_display = XOpenDisplay(0);
|
||||||
|
|
||||||
XLockDisplay(m_display);
|
|
||||||
|
|
||||||
int32_t screen = DefaultScreen(m_display);
|
int32_t screen = DefaultScreen(m_display);
|
||||||
int32_t depth = DefaultDepth(m_display, screen);
|
int32_t depth = DefaultDepth(m_display, screen);
|
||||||
Visual* visual = DefaultVisual(m_display, screen);
|
Visual* visual = DefaultVisual(m_display, screen);
|
||||||
Window root = RootWindow(m_display, screen);
|
Window root = RootWindow(m_display, screen);
|
||||||
|
|
||||||
XSetWindowAttributes windowAttrs;
|
XSetWindowAttributes windowAttrs;
|
||||||
windowAttrs.colormap =
|
memset(&windowAttrs, 0, sizeof(windowAttrs) );
|
||||||
XCreateColormap(m_display
|
|
||||||
, root
|
|
||||||
, visual
|
|
||||||
, AllocNone
|
|
||||||
);
|
|
||||||
windowAttrs.background_pixmap = 0;
|
windowAttrs.background_pixmap = 0;
|
||||||
windowAttrs.border_pixel = 0;
|
windowAttrs.border_pixel = 0;
|
||||||
|
windowAttrs.event_mask = 0
|
||||||
|
| ButtonPressMask
|
||||||
|
| ButtonReleaseMask
|
||||||
|
| ExposureMask
|
||||||
|
| KeyPressMask
|
||||||
|
| KeyReleaseMask
|
||||||
|
| PointerMotionMask
|
||||||
|
| ResizeRedirectMask
|
||||||
|
| StructureNotifyMask
|
||||||
|
;
|
||||||
|
|
||||||
m_window = XCreateWindow(m_display
|
m_window = XCreateWindow(m_display
|
||||||
, root
|
, root
|
||||||
|
@ -165,30 +164,13 @@ namespace entry
|
||||||
, DEFAULT_WIDTH, DEFAULT_HEIGHT, 0, depth
|
, DEFAULT_WIDTH, DEFAULT_HEIGHT, 0, depth
|
||||||
, InputOutput
|
, InputOutput
|
||||||
, visual
|
, visual
|
||||||
, CWBorderPixel|CWColormap
|
, CWBorderPixel|CWEventMask
|
||||||
, &windowAttrs
|
, &windowAttrs
|
||||||
);
|
);
|
||||||
|
|
||||||
XMapRaised(m_display, m_window);
|
XMapWindow(m_display, m_window);
|
||||||
XFlush(m_display);
|
|
||||||
|
|
||||||
XStoreName(m_display, m_window, "BGFX");
|
XStoreName(m_display, m_window, "BGFX");
|
||||||
|
|
||||||
XSelectInput(m_display
|
|
||||||
, m_window
|
|
||||||
, ExposureMask
|
|
||||||
| KeyPressMask
|
|
||||||
| KeyReleaseMask
|
|
||||||
| PointerMotionMask
|
|
||||||
| ButtonPressMask
|
|
||||||
| ButtonReleaseMask
|
|
||||||
| StructureNotifyMask
|
|
||||||
);
|
|
||||||
|
|
||||||
XUnlockDisplay(m_display);
|
|
||||||
|
|
||||||
// XResizeWindow(s_display, s_window, _width, _height);
|
|
||||||
|
|
||||||
bgfx::x11SetDisplayWindow(m_display, m_window);
|
bgfx::x11SetDisplayWindow(m_display, m_window);
|
||||||
|
|
||||||
MainThreadEntry mte;
|
MainThreadEntry mte;
|
||||||
|
@ -214,12 +196,36 @@ namespace entry
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
break;
|
|
||||||
|
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
|
{
|
||||||
|
const XButtonEvent& button = event.xbutton;
|
||||||
|
MouseButton::Enum mb;
|
||||||
|
switch (button.button)
|
||||||
|
{
|
||||||
|
case Button1: mb = MouseButton::Left; break;
|
||||||
|
case Button2: mb = MouseButton::Middle; break;
|
||||||
|
case Button3: mb = MouseButton::Right; break;
|
||||||
|
default: mb = MouseButton::None; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MouseButton::None != mb)
|
||||||
|
{
|
||||||
|
m_eventQueue.postMouseEvent(button.x
|
||||||
|
, button.y
|
||||||
|
, mb
|
||||||
|
, event.type == ButtonPress
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
|
{
|
||||||
|
const XMotionEvent& motion = event.xmotion;
|
||||||
|
m_eventQueue.postMouseEvent(motion.x
|
||||||
|
, motion.y
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
|
@ -233,12 +239,22 @@ namespace entry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ResizeRequest:
|
||||||
|
{
|
||||||
|
const XResizeRequestEvent& resize = event.xresizerequest;
|
||||||
|
XResizeWindow(m_display, m_window, resize.width, resize.height);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thread.shutdown();
|
thread.shutdown();
|
||||||
|
|
||||||
|
XUnmapWindow(m_display, m_window);
|
||||||
|
XDestroyWindow(m_display, m_window);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,6 +267,14 @@ namespace entry
|
||||||
|
|
||||||
static Context s_ctx;
|
static Context s_ctx;
|
||||||
|
|
||||||
|
int32_t MainThreadEntry::threadFunc(void* _userData)
|
||||||
|
{
|
||||||
|
MainThreadEntry* self = (MainThreadEntry*)_userData;
|
||||||
|
int32_t result = _main_(self->m_argc, self->m_argv);
|
||||||
|
s_ctx.m_exit = true;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
const Event* poll()
|
const Event* poll()
|
||||||
{
|
{
|
||||||
return s_ctx.m_eventQueue.poll();
|
return s_ctx.m_eventQueue.poll();
|
||||||
|
@ -263,6 +287,15 @@ namespace entry
|
||||||
|
|
||||||
void setWindowSize(uint32_t _width, uint32_t _height)
|
void setWindowSize(uint32_t _width, uint32_t _height)
|
||||||
{
|
{
|
||||||
|
XResizeRequestEvent ev;
|
||||||
|
ev.type = ResizeRequest;
|
||||||
|
ev.serial = 0;
|
||||||
|
ev.send_event = true;
|
||||||
|
ev.display = s_ctx.m_display;
|
||||||
|
ev.window = s_ctx.m_window;
|
||||||
|
ev.width = (int)_width;
|
||||||
|
ev.height = (int)_height;
|
||||||
|
XSendEvent(s_ctx.m_display, s_ctx.m_window, false, ResizeRedirectMask, (XEvent*)&ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleWindowFrame()
|
void toggleWindowFrame()
|
||||||
|
|
|
@ -358,7 +358,7 @@ namespace entry
|
||||||
{
|
{
|
||||||
int32_t mx = GET_X_LPARAM(_lparam);
|
int32_t mx = GET_X_LPARAM(_lparam);
|
||||||
int32_t my = GET_Y_LPARAM(_lparam);
|
int32_t my = GET_Y_LPARAM(_lparam);
|
||||||
m_eventQueue.postMouseEvent(mx, my, MouseButton::Middle, _id == WM_LBUTTONDOWN);
|
m_eventQueue.postMouseEvent(mx, my, MouseButton::Left, _id == WM_LBUTTONDOWN);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -378,7 +378,7 @@ namespace entry
|
||||||
{
|
{
|
||||||
int32_t mx = GET_X_LPARAM(_lparam);
|
int32_t mx = GET_X_LPARAM(_lparam);
|
||||||
int32_t my = GET_Y_LPARAM(_lparam);
|
int32_t my = GET_Y_LPARAM(_lparam);
|
||||||
m_eventQueue.postMouseEvent(mx, my, MouseButton::Middle, _id == WM_RBUTTONDOWN);
|
m_eventQueue.postMouseEvent(mx, my, MouseButton::Right, _id == WM_RBUTTONDOWN);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,12 @@ inline bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug)
|
||||||
bgfx::setDebug(_debug);
|
bgfx::setDebug(_debug);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
else if (key->m_key == Key::F9 && key->m_down)
|
||||||
|
{
|
||||||
|
setWindowSize(640, 480);
|
||||||
|
_width = 640;
|
||||||
|
_height = 480;
|
||||||
|
}
|
||||||
else if (key->m_key == Key::F10 && key->m_down)
|
else if (key->m_key == Key::F10 && key->m_down)
|
||||||
{
|
{
|
||||||
setWindowSize(1280, 720);
|
setWindowSize(1280, 720);
|
||||||
|
|
Loading…
Reference in a new issue