Exemple #1
0
	void OnDeviceButtonFloat(gainput::DeviceId deviceId, gainput::DeviceButtonId deviceButton, float oldValue, float newValue)
	{
		const gainput::InputDevice* device = manager.GetDevice(deviceId);
		char buttonName[64] = "";
		device->GetButtonName(deviceButton, buttonName, 64);
		SFW_LOG("Device %d (%s%d) float button (%d/%s) changed: %f -> %f\n", deviceId, device->GetTypeName(), device->GetIndex(), deviceButton, buttonName, oldValue, newValue);
	}
Exemple #2
0
	void OnDeviceButtonBool(gainput::DeviceId deviceId, gainput::DeviceButtonId deviceButton, bool oldValue, bool newValue)
	{
		const gainput::InputDevice* device = manager.GetDevice(deviceId);
		char buttonName[64] = "";
		device->GetButtonName(deviceButton, buttonName, 64);
		SFW_LOG("Device %d (%s%d) bool button (%d/%s) changed: %d -> %d\n", deviceId, device->GetTypeName(), device->GetIndex(), deviceButton, buttonName, oldValue, newValue);
	}
void SfwOpenWindow(const char* title)
{
	static int attributeListDbl[] = {      GLX_RGBA,      GLX_DOUBLEBUFFER, /*In case single buffering is not supported*/      GLX_RED_SIZE,   1,      GLX_GREEN_SIZE, 1,      GLX_BLUE_SIZE,  1,
		None };

	xDisplay = XOpenDisplay(0);
	if (xDisplay == 0)
	{
		SFW_LOG("Cannot connect to X server.\n");
		return;
	}

	Window root = DefaultRootWindow(xDisplay);

	XVisualInfo* vi = glXChooseVisual(xDisplay, DefaultScreen(xDisplay), attributeListDbl);
	assert(vi);

	glxContext = glXCreateContext(xDisplay, vi, 0, GL_TRUE);

	Colormap cmap = XCreateColormap(xDisplay, root,                   vi->visual, AllocNone);

	XSetWindowAttributes swa;
	swa.colormap = cmap;
	swa.event_mask = ExposureMask
		| KeyPressMask | KeyReleaseMask
		| PointerMotionMask | ButtonPressMask | ButtonReleaseMask;

	xWindow = XCreateWindow(
			xDisplay, root,
			0, 0, width, height, 0,
			CopyFromParent, InputOutput,
			CopyFromParent, CWEventMask,
			&swa
			);

	glXMakeCurrent(xDisplay, xWindow, glxContext);

	XSetWindowAttributes xattr;
	xattr.override_redirect = False;
	XChangeWindowAttributes(xDisplay, xWindow, CWOverrideRedirect, &xattr);

	XMapWindow(xDisplay, xWindow);
	XStoreName(xDisplay, xWindow, title);

	Atom wmDelete=XInternAtom(xDisplay, "WM_DELETE_WINDOW", True);
	XSetWMProtocols(xDisplay, xWindow, &wmDelete, 1);

	XFree(vi);
}
Exemple #4
0
void SampleMain()
{
	SfwOpenWindow("Gainput: Listener sample");

	gainput::InputManager manager;

	manager.CreateDevice<gainput::InputDeviceKeyboard>(gainput::InputDevice::DV_RAW);
	const gainput::DeviceId keyboardId = manager.CreateDevice<gainput::InputDeviceKeyboard>();
	manager.CreateDevice<gainput::InputDeviceMouse>(gainput::InputDevice::DV_RAW);
	const gainput::DeviceId mouseId = manager.CreateDevice<gainput::InputDeviceMouse>();
	manager.CreateDevice<gainput::InputDevicePad>();
	manager.CreateDevice<gainput::InputDevicePad>();
	manager.CreateDevice<gainput::InputDeviceTouch>();

#if defined(GAINPUT_PLATFORM_LINUX) || defined(GAINPUT_PLATFORM_WIN)
	manager.SetDisplaySize(SfwGetWidth(), SfwGetHeight());
#endif

	SfwSetInputManager(&manager);

	gainput::InputMap map(manager, "testmap");

	map.MapBool(ButtonToggleListener, keyboardId, gainput::KeyF1);
	map.MapBool(ButtonToggleMapListener, keyboardId, gainput::KeyF2);
	map.MapBool(ButtonConfirm, mouseId, gainput::MouseButtonLeft);
	map.MapFloat(ButtonMouseX, mouseId, gainput::MouseAxisX);

	MyDeviceButtonListener myDeviceButtonListener(manager);
	MyUserButtonListener myUserButtonListener;
	gainput::ListenerId myDeviceButtonListenerId = manager.AddListener(&myDeviceButtonListener);
	gainput::ListenerId myUserButtonListenerId = map.AddListener(&myUserButtonListener);

	bool doExit = false;

	while (!SfwIsDone() && !doExit)
	{
		manager.Update();

#if defined(GAINPUT_PLATFORM_LINUX)
		XEvent event;
		while (XPending(SfwGetXDisplay()))
		{
			XNextEvent(SfwGetXDisplay(), &event);
			manager.HandleEvent(event);
			if (event.type == DestroyNotify || event.type == ClientMessage)
			{
				doExit = true;
			}
		}
#elif defined(GAINPUT_PLATFORM_WIN)
		MSG msg;
		while (PeekMessage(&msg, SfwGetHWnd(),  0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
			manager.HandleMessage(msg);
		}
#endif

		SfwUpdate();

		if (map.GetBoolWasDown(ButtonToggleListener))
		{
			if (myDeviceButtonListenerId != gainput::ListenerId(-1))
			{
				manager.RemoveListener(myDeviceButtonListenerId);
				myDeviceButtonListenerId = gainput::ListenerId(-1);
				SFW_LOG("Device button listener disabled.\n");
			}
			else
			{
				myDeviceButtonListenerId = manager.AddListener(&myDeviceButtonListener);
				SFW_LOG("Device button listener enabled.\n");
			}
		}

		if (map.GetBoolWasDown(ButtonToggleMapListener))
		{
			if (myUserButtonListenerId != gainput::ListenerId(-1))
			{
				map.RemoveListener(myUserButtonListenerId);
				myUserButtonListenerId = gainput::ListenerId(-1);
				SFW_LOG("User button listener disabled.\n");
			}
			else
			{
				myUserButtonListenerId = map.AddListener(&myUserButtonListener);
				SFW_LOG("User button listener enabled.\n");
			}
		}
	}

	SfwCloseWindow();
}
Exemple #5
0
	void OnUserButtonFloat(gainput::UserButtonId userButton, float oldValue, float newValue)
	{
		SFW_LOG("User float button %d changed: %f -> %f\n", userButton, oldValue, newValue);
	}
Exemple #6
0
	void OnUserButtonBool(gainput::UserButtonId userButton, bool oldValue, bool newValue)
	{
		SFW_LOG("User bool button %d changed: %d -> %d\n", userButton, oldValue, newValue);
	}
void SampleMain()
{
	SfwOpenWindow("Gainput: Gesture sample");

	gainput::TrackingAllocator allocator(gainput::GetDefaultAllocator());

	gainput::InputManager manager(true, allocator);

	const gainput::DeviceId keyboardId = manager.CreateDevice<gainput::InputDeviceKeyboard>();
	const gainput::DeviceId mouseId = manager.CreateDevice<gainput::InputDeviceMouse>();

	gainput::InputDeviceTouch* touchDevice = manager.CreateAndGetDevice<gainput::InputDeviceTouch>();
	GAINPUT_ASSERT(touchDevice);
	gainput::DeviceId touchId = touchDevice->GetDeviceId();

#if defined(GAINPUT_PLATFORM_LINUX) || defined(GAINPUT_PLATFORM_WIN)
	manager.SetDisplaySize(SfwGetWidth(), SfwGetHeight());
#endif

	SfwSetInputManager(&manager);

	gainput::InputMap map(manager, "testmap", allocator);

	map.MapBool(ButtonConfirm, mouseId, gainput::MouseButtonLeft);

	gainput::DoubleClickGesture* dcg = manager.CreateAndGetDevice<gainput::DoubleClickGesture>();
	GAINPUT_ASSERT(dcg);
	dcg->Initialize(mouseId, gainput::MouseButtonLeft,
			mouseId, gainput::MouseAxisX, 0.01f,
			mouseId, gainput::MouseAxisY, 0.01f,
			500);
	map.MapBool(ButtonConfirmDouble, dcg->GetDeviceId(), gainput::DoubleClickTriggered);

	gainput::SimultaneouslyDownGesture* sdg = manager.CreateAndGetDevice<gainput::SimultaneouslyDownGesture>();
	GAINPUT_ASSERT(sdg);
	sdg->AddButton(mouseId, gainput::MouseButtonLeft);
	sdg->AddButton(keyboardId, gainput::KeyShiftL);
	map.MapBool(ButtonConfirmExtra, sdg->GetDeviceId(), gainput::SimultaneouslyDownTriggered);

	MultiTouchEmulator* mte = manager.CreateAndGetDevice<MultiTouchEmulator>();
	mte->Initialize(sdg->GetDeviceId(), gainput::SimultaneouslyDownTriggered,
			mouseId, gainput::MouseAxisX,
			mouseId, gainput::MouseAxisY,
			mouseId, gainput::MouseButtonLeft,
			mouseId, gainput::MouseAxisX,
			mouseId, gainput::MouseAxisY);

	if (!touchDevice->IsAvailable() || touchDevice->GetVariant() == gainput::InputDevice::DV_NULL)
	{
		touchId = mte->GetDeviceId();
	}

	gainput::HoldGesture* hg = manager.CreateAndGetDevice<gainput::HoldGesture>();
	GAINPUT_ASSERT(hg);
	hg->Initialize(touchId, gainput::Touch0Down,
			touchId, gainput::Touch0X, 0.1f,
			touchId, gainput::Touch0Y, 0.1f,
			true,
			800);
	map.MapBool(ButtonHoldGesture, hg->GetDeviceId(), gainput::HoldTriggered);

	gainput::TapGesture* tg = manager.CreateAndGetDevice<gainput::TapGesture>();
	GAINPUT_ASSERT(tg);
	tg->Initialize(touchId, gainput::Touch0Down,
			500);
	map.MapBool(ButtonTapGesture, tg->GetDeviceId(), gainput::TapTriggered);
	
	gainput::PinchGesture* pg = manager.CreateAndGetDevice<gainput::PinchGesture>();
	GAINPUT_ASSERT(pg);
	pg->Initialize(touchId, gainput::Touch0Down,
			touchId, gainput::Touch0X,
			touchId, gainput::Touch0Y,
			touchId, gainput::Touch1Down,
			touchId, gainput::Touch1X,
			touchId, gainput::Touch1Y);
	map.MapBool(ButtonPinching, pg->GetDeviceId(), gainput::PinchTriggered);
	map.MapFloat(ButtonPinchScale, pg->GetDeviceId(), gainput::PinchScale);

	gainput::RotateGesture* rg = manager.CreateAndGetDevice<gainput::RotateGesture>();
	GAINPUT_ASSERT(rg);
	rg->Initialize(touchId, gainput::Touch0Down,
			touchId, gainput::Touch0X,
			touchId, gainput::Touch0Y,
			touchId, gainput::Touch1Down,
			touchId, gainput::Touch1X,
			touchId, gainput::Touch1Y);
	map.MapBool(ButtonRotating, rg->GetDeviceId(), gainput::RotateTriggered);
	map.MapFloat(ButtonRotateAngle, rg->GetDeviceId(), gainput::RotateAngle);

	bool doExit = false;

	while (!SfwIsDone() && !doExit)
	{
		manager.Update();

#if defined(GAINPUT_PLATFORM_LINUX)
		XEvent event;
		while (XPending(SfwGetXDisplay()))
		{
			XNextEvent(SfwGetXDisplay(), &event);
			manager.HandleEvent(event);
			if (event.type == DestroyNotify || event.type == ClientMessage)
			{
				doExit = true;
			}
		}
#elif defined(GAINPUT_PLATFORM_WIN)
		MSG msg;
		while (PeekMessage(&msg, SfwGetHWnd(),  0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
			manager.HandleMessage(msg);
		}
#endif

		SfwUpdate();

		if (map.GetBoolWasDown(ButtonConfirm))
		{
			SFW_LOG("Confirmed!\n");
			SFW_LOG("Memory: %u allocs, %u deallocs, %u used bytes\n", static_cast<unsigned>(allocator.GetAllocateCount()), static_cast<unsigned>(allocator.GetDeallocateCount()), static_cast<unsigned>(allocator.GetAllocatedMemory()));
		}

		if (map.GetBoolWasDown(ButtonConfirmDouble))
		{
			SFW_LOG("Confirmed doubly!\n");
		}

		if (map.GetBoolWasDown(ButtonConfirmExtra))
		{
			SFW_LOG("Confirmed alternatively!\n");
		}

		if (map.GetBool(ButtonHoldGesture))
		{
			SFW_LOG("Hold triggered!\n");
		}

		if (map.GetBoolWasDown(ButtonTapGesture))
		{
			SFW_LOG("Tapped!\n");
		}

		if (map.GetBool(ButtonPinching))
		{
			SFW_LOG("Pinching: %f\n", map.GetFloat(ButtonPinchScale));
		}

		if (map.GetBool(ButtonRotating))
		{
			SFW_LOG("Rotation angle: %f\n", map.GetFloat(ButtonRotateAngle));
		}
	}

	SfwCloseWindow();
}