vivante input handled

This commit is contained in:
Krylov Yaroslav 2019-06-20 16:39:09 +03:00
parent f33fb7ef58
commit c72dacafc5
3 changed files with 98 additions and 12 deletions

View File

@ -27,16 +27,32 @@
#include "internal.h"
void _glfwInitFbMonitor(void)
static void _glfwInitFbMonitor(void)
{
int width, height;
fbGetDisplayGeometry(_glfw.vivante.display, &width, &height);
_glfw.vivante.displayWidth = width;
_glfw.vivante.displayHeight = height;
_glfw.vivante.cursorXpos = width / 2;
_glfw.vivante.cursorYpos = height / 2;
_glfwInputMonitor(_glfwAllocMonitor("Display", width, height),
GLFW_CONNECTED,
_GLFW_INSERT_FIRST);
}
static void _glfwNotifyCursorPositionChanged(void)
{
if (_glfw.vivante.focusedWindow){
if (_glfwPlatformWindowHovered(_glfw.vivante.focusedWindow)){
double xpos, ypos;
_glfwPlatformGetCursorPos(_glfw.vivante.focusedWindow, &xpos, &ypos);
_glfwInputCursorPos(_glfw.vivante.focusedWindow, xpos, ypos);
}
}
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
@ -151,30 +167,52 @@ const char* _glfwPlatformGetVersionString(void)
void _glfwEvdevInputKey(int key, int scancode, int action, int mods)
{
printf("_glfwEvdevInputKey key = %i, scancode = %i, action = %i, mods = %i\n", key, scancode, action, mods);
if (_glfw.vivante.focusedWindow)
_glfwInputKey(_glfw.vivante.focusedWindow, key, scancode, action, mods);
}
void _glfwEvdevInputChar(unsigned int codepoint, int mods, GLFWbool plain)
{
printf("_glfwEvdevInputChar codepoint = %i, mods = %i, plain = %i\n", codepoint, mods, plain);
if (_glfw.vivante.focusedWindow)
_glfwInputChar(_glfw.vivante.focusedWindow, codepoint, mods, plain);
}
void _glfwEvdevInputScroll(double xoffset, double yoffset)
{
printf("_glfwEvdevInputScroll xoffset = %f, yoffset = %f\n", xoffset, yoffset);
if (_glfw.vivante.focusedWindow)
_glfwInputScroll(_glfw.vivante.focusedWindow, xoffset, yoffset);
}
void _glfwEvdevInputMouseClick(int button, int action, int mods)
{
printf("_glfwEvdevInputMouseClick button = %i, action = %i, mods = %i\n", button, action, mods);
if (_glfw.vivante.focusedWindow)
_glfwInputMouseClick(_glfw.vivante.focusedWindow, button, action, mods);
}
void _glfwVivanteSetCursorPos(double xpos, double ypos)
{
_glfw.vivante.cursorXpos = xpos;
_glfw.vivante.cursorYpos = ypos;
if( _glfw.vivante.cursorXpos < 0.0 )
_glfw.vivante.cursorXpos = 0.0;
if( _glfw.vivante.cursorXpos > _glfw.vivante.displayWidth )
_glfw.vivante.cursorXpos = _glfw.vivante.displayWidth;
if( _glfw.vivante.cursorYpos < 0.0 )
_glfw.vivante.cursorYpos = 0.0;
if( _glfw.vivante.cursorYpos > _glfw.vivante.displayHeight )
_glfw.vivante.cursorYpos = _glfw.vivante.displayHeight;
}
void _glfwEvdevInputCursorPos(double xpos, double ypos)
{
printf("_glfwEvdevInputCursorPos xpos = %f, ypos = %f\n", xpos, ypos);
_glfwVivanteSetCursorPos(xpos, ypos);
_glfwNotifyCursorPositionChanged();
}
void _glfwEvdevInputCursorMove(double xoffset, double yoffset)
{
printf("_glfwEvdevInputCursorMove xoffset = %f, yoffset = %f\n", xoffset, yoffset);
_glfwVivanteSetCursorPos(_glfw.vivante.cursorXpos + xoffset, _glfw.vivante.cursorYpos + yoffset);
_glfwNotifyCursorPositionChanged();
}

View File

@ -97,6 +97,11 @@ typedef struct _GLFWlibraryVivante
void* handle;
int displayWidth, displayHeight;
double cursorXpos, cursorYpos;
_GLFWwindow* focusedWindow;
char* clipboardString;
PFN_fbGetDisplay GetDisplay;
PFN_fbGetDisplayByIndex GetDisplayByIndex;
PFN_fbGetDisplayGeometry GetDisplayGeometry;
@ -108,3 +113,5 @@ typedef struct _GLFWlibraryVivante
PFN_fbDestroyWindow DestroyWindow;
} _GLFWlibraryVivante;
void _glfwVivanteSetCursorPos(double xpos, double ypos);

View File

@ -27,6 +27,7 @@
#include "internal.h"
#include <errno.h>
#include <stdlib.h>
// Wait for data to arrive using select
// TODO: because we get keyboard and mouse events via polling,
@ -162,6 +163,9 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
{
if (_glfwPlatformWindowFocused(window))
_glfw.vivante.focusedWindow = GLFW_FALSE;
if (window->context.destroy)
window->context.destroy(window);
@ -276,7 +280,21 @@ int _glfwPlatformWindowMaximized(_GLFWwindow* window)
int _glfwPlatformWindowHovered(_GLFWwindow* window)
{
double xpos = _glfw.vivante.cursorXpos;
double ypos = _glfw.vivante.cursorYpos;
xpos -= window->vivante.xpos;
ypos -= window->vivante.ypos;
if( xpos < 0.0 )
return GLFW_FALSE;
if( xpos > window->vivante.width )
return GLFW_FALSE;
if( ypos < 0.0 )
return GLFW_FALSE;
if( ypos > window->vivante.height )
return GLFW_FALSE;
return GLFW_TRUE;
}
int _glfwPlatformFramebufferTransparent(_GLFWwindow* window)
@ -333,11 +351,12 @@ void _glfwPlatformHideWindow(_GLFWwindow* window)
void _glfwPlatformFocusWindow(_GLFWwindow* window)
{
_glfw.vivante.focusedWindow = window;
}
int _glfwPlatformWindowFocused(_GLFWwindow* window)
{
return GLFW_FALSE;
return _glfw.vivante.focusedWindow == window;
}
int _glfwPlatformWindowIconified(_GLFWwindow* window)
@ -347,7 +366,7 @@ int _glfwPlatformWindowIconified(_GLFWwindow* window)
int _glfwPlatformWindowVisible(_GLFWwindow* window)
{
return GLFW_FALSE;
return GLFW_TRUE;
}
void _glfwPlatformPollEvents(void)
@ -374,10 +393,29 @@ void _glfwPlatformPostEmptyEvent(void)
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
{
double cursorXpos = _glfw.vivante.cursorXpos;
double cursorYpos = _glfw.vivante.cursorYpos;
cursorXpos -= window->vivante.xpos;
cursorYpos -= window->vivante.ypos;
if (xpos)
*xpos = cursorXpos;
if (ypos)
*ypos = cursorYpos;
}
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
{
if( x < 0.0 )
return;
if( x > window->vivante.width )
return;
if( y < 0.0 )
return;
if( y > window->vivante.height )
return;
_glfwVivanteSetCursorPos(x + window->vivante.xpos, y + window->vivante.ypos);
}
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
@ -406,11 +444,14 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
void _glfwPlatformSetClipboardString(const char* string)
{
if (_glfw.vivante.clipboardString)
free(_glfw.vivante.clipboardString);
_glfw.vivante.clipboardString = _glfw_strdup(string);
}
const char* _glfwPlatformGetClipboardString(void)
{
return NULL;
return _glfw.vivante.clipboardString;
}
const char* _glfwPlatformGetScancodeName(int scancode)