mirror of
https://github.com/glfw/glfw.git
synced 2025-10-05 06:06:36 +00:00
Add initial input support , fix bugs , refractor and implement some methods
Rotation also works now
This commit is contained in:
parent
1daf1401fb
commit
56816cd0ba
@ -30,9 +30,21 @@
|
||||
|
||||
extern int main();
|
||||
void handle_cmd(struct android_app* _app, int32_t cmd) {
|
||||
switch (cmd)
|
||||
case APP_CMD_INIT_WINDOW:
|
||||
switch (cmd) {
|
||||
case APP_CMD_INIT_WINDOW: {
|
||||
app = _app; // The window is being shown so the initialization is finished.
|
||||
break;
|
||||
}
|
||||
case APP_CMD_LOST_FOCUS: {
|
||||
break;
|
||||
}
|
||||
case APP_CMD_GAINED_FOCUS: {
|
||||
break;
|
||||
}
|
||||
case APP_CMD_TERM_WINDOW: {
|
||||
glfwDestroyWindow((GLFWwindow *) _glfw.windowListHead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Android Entry Point
|
||||
@ -45,20 +57,12 @@ void android_main(struct android_app *app) {
|
||||
int events;
|
||||
struct android_poll_source* source;
|
||||
|
||||
while ((ident=ALooper_pollAll(0, NULL, &events,(void**)&source)) >= 0) {
|
||||
|
||||
// Process this event.
|
||||
if (source != NULL) {
|
||||
// Process events
|
||||
while ((ident=ALooper_pollAll(0, NULL, &events,(void**)&source)) >= 0)
|
||||
if (source != NULL)
|
||||
source->process(app, source);
|
||||
}
|
||||
|
||||
// Check if we are exiting.
|
||||
if (app->destroyRequested != 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
|
@ -39,8 +39,8 @@
|
||||
#define _glfw_dlclose(handle) dlclose(handle)
|
||||
#define _glfw_dlsym(handle, name) dlsym(handle, name)
|
||||
|
||||
#define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->android.app->window)
|
||||
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowAndroid android
|
||||
#define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->android->window)
|
||||
#define _GLFW_PLATFORM_WINDOW_STATE struct android_app* android
|
||||
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE
|
||||
#define _GLFW_PLATFORM_MONITOR_STATE
|
||||
#define _GLFW_PLATFORM_CURSOR_STATE
|
||||
@ -50,13 +50,6 @@
|
||||
|
||||
struct android_app *app;
|
||||
|
||||
// Android-specific per-window data
|
||||
typedef struct _GLFWwindowAndroid
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
struct android_app *app;
|
||||
} _GLFWwindowAndroid;
|
||||
|
||||
typedef VkFlags VkAndroidSurfaceCreateFlagsKHR;
|
||||
|
||||
|
@ -26,8 +26,20 @@
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
#include <android_native_app_glue.h>
|
||||
#include <android/log.h>
|
||||
|
||||
float x,y;
|
||||
|
||||
static int32_t handle_input(struct android_app* app, AInputEvent* event)
|
||||
{
|
||||
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
|
||||
for (size_t i = 0; i < AMotionEvent_getPointerCount(event); ++i) {
|
||||
x = AMotionEvent_getX(event, i);
|
||||
y = AMotionEvent_getY(event, i);
|
||||
}
|
||||
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY)
|
||||
_glfwInputKey(_glfw.windowListHead, 0 , AKeyEvent_getKeyCode(event), GLFW_PRESS,0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
@ -38,33 +50,36 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
||||
const _GLFWctxconfig* ctxconfig,
|
||||
const _GLFWfbconfig* fbconfig)
|
||||
{
|
||||
window->android.app = app;
|
||||
window->android = app;
|
||||
window->android->onInputEvent = handle_input;
|
||||
|
||||
if (ctxconfig->client != GLFW_NO_API)
|
||||
{
|
||||
if ((ctxconfig->source == GLFW_NATIVE_CONTEXT_API) | (ctxconfig->source == GLFW_EGL_CONTEXT_API))
|
||||
{
|
||||
ANativeWindow_setBuffersGeometry(window->android->window, wndconfig->width, wndconfig->height, 0);
|
||||
|
||||
if (ctxconfig->client != GLFW_NO_API) {
|
||||
if ((ctxconfig->source == GLFW_NATIVE_CONTEXT_API) |
|
||||
(ctxconfig->source == GLFW_EGL_CONTEXT_API)) {
|
||||
if (!_glfwInitEGL())
|
||||
return GLFW_FALSE;
|
||||
if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API)
|
||||
{
|
||||
} else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API) {
|
||||
if (!_glfwInitOSMesa())
|
||||
return GLFW_FALSE;
|
||||
if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig))
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return GLFW_TRUE;
|
||||
}
|
||||
|
||||
|
||||
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
|
||||
{
|
||||
if (window->context.destroy)
|
||||
window->context.destroy(window);
|
||||
ANativeActivity_finish(window->android->activity);
|
||||
}
|
||||
|
||||
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
||||
@ -86,6 +101,7 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
|
||||
|
||||
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos)
|
||||
@ -94,22 +110,19 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos)
|
||||
|
||||
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
|
||||
{
|
||||
if (width)
|
||||
*width = window->android.width;
|
||||
if (height)
|
||||
*height = window->android.height;
|
||||
*height = ANativeWindow_getHeight(window->android->window);
|
||||
*width = ANativeWindow_getWidth(window->android->window);
|
||||
}
|
||||
|
||||
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
||||
{
|
||||
window->android.width = width;
|
||||
window->android.height = height;
|
||||
}
|
||||
|
||||
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
|
||||
int minwidth, int minheight,
|
||||
int maxwidth, int maxheight)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int n, int d)
|
||||
@ -118,10 +131,7 @@ void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int n, int d)
|
||||
|
||||
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height)
|
||||
{
|
||||
if (width)
|
||||
*width = window->android.width;
|
||||
if (height)
|
||||
*height = window->android.height;
|
||||
|
||||
}
|
||||
|
||||
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
|
||||
@ -197,10 +207,12 @@ int _glfwPlatformWindowVisible(_GLFWwindow* window)
|
||||
|
||||
void _glfwPlatformPollEvents(void)
|
||||
{
|
||||
_glfwInputCursorPos(_glfw.windowListHead, x ,y);
|
||||
}
|
||||
|
||||
void _glfwPlatformWaitEvents(void)
|
||||
{
|
||||
_glfwPlatformPollEvents();
|
||||
}
|
||||
|
||||
void _glfwPlatformWaitEventsTimeout(double timeout)
|
||||
@ -213,6 +225,8 @@ void _glfwPlatformPostEmptyEvent(void)
|
||||
|
||||
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
|
||||
{
|
||||
*xpos = x;
|
||||
*ypos = y;
|
||||
}
|
||||
|
||||
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
|
||||
@ -303,7 +317,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
|
||||
|
||||
memset(&sci, 0, sizeof(sci));
|
||||
sci.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
|
||||
sci.window = window->android.app->window;
|
||||
sci.window = window->android->window;
|
||||
|
||||
err = vkCreateAndroidSurfaceKHR(instance, &sci, allocator, surface);
|
||||
if (err)
|
||||
@ -324,5 +338,5 @@ GLFWAPI struct android_app * glfwGetAndroidApp(GLFWwindow* handle)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*)handle;
|
||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||
return window->android.app;
|
||||
return window->android;
|
||||
}
|
@ -590,6 +590,7 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle)
|
||||
_glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (previous)
|
||||
{
|
||||
if (!window || window->context.source != previous->context.source)
|
||||
|
Loading…
Reference in New Issue
Block a user