Ejemplo n.º 1
0
static void onAppCmd(struct android_app* app, int32_t cmd)
{
	if (!app)
	{
		return;
	}

	switch(cmd)
	{
		case APP_CMD_INIT_WINDOW:
			{
				int32_t orientation = AConfiguration_getOrientation (g_app->config);

				int32_t width;
				int32_t height;

				if (orientation == ACONFIGURATION_ORIENTATION_PORT)
				{
					width = ANativeWindow_getWidth(g_app->window);
					height = ANativeWindow_getHeight(g_app->window);
				}
				else
				{
					height = ANativeWindow_getWidth(g_app->window);
					width = ANativeWindow_getHeight(g_app->window);
				}

				if (width != g_width || height != g_height)
				{
					g_width = width;
					g_height = height;
				}

				g_nativeWindow = app->window;
			}
	        break;

	    case APP_CMD_TERM_WINDOW:
	    case APP_CMD_DESTROY:

	    	if (g_nativeWindow)
	    	{
		    	_glusWindowInternalClose();

		    	g_nativeWindow = 0;
	    	}

			g_width = -1;
			g_height = -1;

	    	app->destroyRequested = 1;

	    	break;
	}
}
Ejemplo n.º 2
0
GLUSvoid _glusOsPollEvents()
{
	int ident;
    int events;
    struct android_poll_source* androidPollSource;

    while ((ident = ALooper_pollAll( 0, NULL, &events, (void**)&androidPollSource)) >= 0)
    {
         if (androidPollSource != NULL)
         {
        	 androidPollSource->process(g_app, androidPollSource);
         }
    }

	int32_t orientation = AConfiguration_getOrientation (g_app->config);

	int32_t width;
	int32_t height;

	if (orientation == ACONFIGURATION_ORIENTATION_PORT)
	{
		width = ANativeWindow_getWidth(g_app->window);
		height = ANativeWindow_getHeight(g_app->window);
	}
	else
	{
		height = ANativeWindow_getWidth(g_app->window);
		width = ANativeWindow_getHeight(g_app->window);
	}

	if (width != g_width || height != g_height)
	{
		g_width = width;
		g_height = height;

		_glusWindowInternalReshape(g_width, g_height);
	}

    if (g_app->destroyRequested != 0 )
    {
    	_glusWindowInternalClose();
    }
}
Ejemplo n.º 3
0
GLUSvoid _glusOsPollEvents()
{
	if (g_keyFileDescriptor >= 0)
	{
		static GLUSboolean LEFT_CTRL = GLUS_FALSE;
		static GLUSboolean RIGHT_CTRL = GLUS_FALSE;

		struct input_event keyEvent;

		ssize_t numBytes;

		do
		{
			numBytes = read(g_keyFileDescriptor, &keyEvent, sizeof(struct input_event));

			if (numBytes > 0 && keyEvent.type == EV_KEY)
			{
				switch (keyEvent.value)
				{
					case 1:	// Pressed
					{
						// CTRL-C
						if (keyEvent.code == 46 && (LEFT_CTRL || RIGHT_CTRL))
						{
							_glusWindowInternalClose();

							return;
						}
						else
						{
							if (keyEvent.code == 29)
							{
								LEFT_CTRL = GLUS_TRUE;
							}
							else if (keyEvent.code == 97)
							{
								RIGHT_CTRL = GLUS_TRUE;
							}

							_glusWindowInternalKey(glusOsTranslateKey(keyEvent.code), GLFW_PRESS);
						}
					}
					break;

					case 0: // Released
					{
						if (keyEvent.code == 29)
						{
							LEFT_CTRL = GLUS_FALSE;
						}
						else if (keyEvent.code == 97)
						{
							RIGHT_CTRL = GLUS_FALSE;
						}

						_glusWindowInternalKey(glusOsTranslateKey(keyEvent.code), GLFW_RELEASE);
					}
					break;
				}
			}
		} while (numBytes > 0);
	}

	if (g_touchFileDescriptor >= 0)
	{
		struct input_event touchEvent;

		ssize_t numBytes;

		int pressed = -1;
		int moved = 0;

		do
		{
			numBytes = read(g_touchFileDescriptor, &touchEvent, sizeof(struct input_event));

			if (numBytes > 0)
			{
				if (touchEvent.type == EV_ABS)
				{
					if (touchEvent.code == 48)
					{
						if (touchEvent.value == 1 && !g_pressed)
						{
							pressed = 1;

							g_pressed = pressed;
						}
						else if (touchEvent.value == 0 && g_pressed)
						{
							pressed = 0;

							g_pressed = pressed;
						}
					}
					else if (touchEvent.code == 53)
					{
						g_currentX = g_displayWidth * touchEvent.value / ((1 << 15) - 1);

						moved = 1;
					}
					else if (touchEvent.code == 54)
					{
						g_currentY = g_displayHeight * touchEvent.value / ((1 << 15) - 1);

						moved = 1;
					}
				}
				else if (touchEvent.type == EV_SYN)
				{
					if (moved)
					{
						_glusWindowInternalMouseMove(g_currentX, g_currentY);
					}

					if (pressed == 1)
					{
						_glusWindowInternalMouse(GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS);
					}
					else if (pressed == 0)
					{
						_glusWindowInternalMouse(GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE);
					}

					pressed = -1;
					moved = 0;
				}
			}
		} while (numBytes > 0);
	}
}
Ejemplo n.º 4
0
GLUSvoid _glusOsPollEvents()
{
	if (g_keyFileDescriptor >= 0)
	{
		static GLUSboolean LEFT_CTRL = GLUS_FALSE;
		static GLUSboolean RIGHT_CTRL = GLUS_FALSE;

		struct input_event keyEvent;

		ssize_t numBytes;

		do
		{
			numBytes = read(g_keyFileDescriptor, &keyEvent, sizeof(struct input_event));

			if (numBytes > 0 && keyEvent.type == EV_KEY)
			{
				switch (keyEvent.value)
				{
					case 1:	// Pressed
					{
						// CTRL-C
						if (keyEvent.code == 46 && (LEFT_CTRL || RIGHT_CTRL))
						{
							_glusWindowInternalClose();

							return;
						}
						else
						{
							if (keyEvent.code == 29)
							{
								LEFT_CTRL = GLUS_TRUE;
							}
							else if (keyEvent.code == 97)
							{
								RIGHT_CTRL = GLUS_TRUE;
							}

							_glusWindowInternalKey(glusOsTranslateKey(keyEvent.code), GLFW_PRESS);
						}
					}
					break;

					case 0: // Released
					{
						if (keyEvent.code == 29)
						{
							LEFT_CTRL = GLUS_FALSE;
						}
						else if (keyEvent.code == 97)
						{
							RIGHT_CTRL = GLUS_FALSE;
						}

						_glusWindowInternalKey(glusOsTranslateKey(keyEvent.code), GLFW_RELEASE);
					}
					break;
				}
			}
		} while (numBytes > 0);
	}

	if (g_touchFileDescriptor >= 0)
	{
		struct input_event touchEvent;

		ssize_t numBytes;

		int submitPosition = 0;

		do
		{
			numBytes = read(g_touchFileDescriptor, &touchEvent, sizeof(struct input_event));

			if (numBytes > 0)
			{
				if (touchEvent.type == 1)
				{
					if (touchEvent.code == 330)
					{
						if (touchEvent.value == 1)
						{
							if (submitPosition)
							{
								_glusWindowInternalMouseMove(g_currentX, g_currentY);

								submitPosition = 0;
							}

							_glusWindowInternalMouse(GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS);
						}
						else if (touchEvent.value == 0)
						{
							_glusWindowInternalMouse(GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE);
						}
					}
				}
				else if (touchEvent.type == 3)
				{
					if (touchEvent.code == 53)
					{
						g_currentX = g_displayWidth * touchEvent.value / ((1 << 15) - 1);

						submitPosition = 1;
					}
					else if (touchEvent.code == 54)
					{
						g_currentY = g_displayHeight * touchEvent.value / ((1 << 15) - 1);

						submitPosition = 1;
					}
					else if ((touchEvent.code == 0 || touchEvent.code == 1) && submitPosition)
					{
						_glusWindowInternalMouseMove(g_currentX, g_currentY);

						submitPosition = 0;
					}
				}
			}
		} while (numBytes > 0);
	}


	if (g_powermateFileDescriptor >= 0)
	{
		struct input_event powermateEvent;

		ssize_t numBytes;

		do
		{
			numBytes = read(g_powermateFileDescriptor, &powermateEvent, sizeof(struct input_event));

			if (numBytes > 0)
			{
				if (powermateEvent.type == 1)
				{
					if (powermateEvent.code == 256)
					{
						if (powermateEvent.value == 1)
						{
							_glusWindowInternalMouse(GLFW_MOUSE_BUTTON_MIDDLE, GLFW_PRESS);
						}
						else if (powermateEvent.value == 0)
						{
							_glusWindowInternalMouse(GLFW_MOUSE_BUTTON_MIDDLE, GLFW_RELEASE);
						}
					}
				}
				else if (powermateEvent.type == 2)
				{
					if (powermateEvent.code == 7)
					{
						static int mouseWheel = 0;

						mouseWheel += powermateEvent.value;

						_glusWindowInternalMouseWheel(mouseWheel);
					}
				}
			}
		} while (numBytes > 0);
	}
}