User Tools

Site Tools


c_screen_tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
c_screen_tutorial [2017/05/04 19:12]
curtisb created
c_screen_tutorial [2019/01/21 16:34] (current)
Line 1: Line 1:
 ====== Screen Tutorial ====== ====== Screen Tutorial ======
  
-GestureWorks can be setup to run in two different modes. Screen mode is the simplest, in this mode touch points from the screen are sent to GestureWorks and gestures are sent back. There is no association with a specific gesture and a specific object. For example if you wanted a fullscreen pan or rotation this mode sets it up easily.+GestureWorks can be setup to run in two different modes. Screen mode is the simplest. In this mode touch points from the screen are sent to GestureWorks and gestures are sent back. There is no association with a specific gesture and a specific object. For example if you wanted a fullscreen pan or rotation this mode sets it up easily.
  
-Full code for this sample is at GestureWorks\C++\gestureworks-demo-screen\+Full code for this sample is in the GestureWorks install ​at GestureWorks\C++\gestureworks-demo-screen\.
  
 **1 - Include the header “GestureWorks2.h” and link to the appropriate C++ dll library.** GestureWorks is built with Visual Studio and includes 32 and 64 bit dlls for debug and release. **1 - Include the header “GestureWorks2.h” and link to the appropriate C++ dll library.** GestureWorks is built with Visual Studio and includes 32 and 64 bit dlls for debug and release.
Line 28: Line 28:
  GetPointerInfo(GET_POINTERID_WPARAM(wParam),​ &pi);  GetPointerInfo(GET_POINTERID_WPARAM(wParam),​ &pi);
  
- addEvent(gesture_works,​ pi.pointerId,​ GW_TOUCHADDED,​ (float)pi.ptPixelLocation.x,​ (float)pi.ptPixelLocation.y);​+ addTouchEvent(gesture_works,​ pi.pointerId,​ GW_TOUCHADDED,​ (float)pi.ptPixelLocation.x,​ (float)pi.ptPixelLocation.y);​
  
  break;  break;
Line 37: Line 37:
  GetPointerInfo(GET_POINTERID_WPARAM(wParam),​ &pi);  GetPointerInfo(GET_POINTERID_WPARAM(wParam),​ &pi);
  
- addEvent(gesture_works,​ pi.pointerId,​ GW_TOUCHREMOVED,​ (float)pi.ptPixelLocation.x,​ (float)pi.ptPixelLocation.y);​+ addTouchEvent(gesture_works,​ pi.pointerId,​ GW_TOUCHREMOVED,​ (float)pi.ptPixelLocation.x,​ (float)pi.ptPixelLocation.y);​
  
  break;  break;
Line 46: Line 46:
  GetPointerInfo(GET_POINTERID_WPARAM(wParam),​ &pi);  GetPointerInfo(GET_POINTERID_WPARAM(wParam),​ &pi);
  
- addEvent(gesture_works,​ pi.pointerId,​ GW_TOUCHUPDATE,​ (float)pi.ptPixelLocation.x,​ (float)pi.ptPixelLocation.y);​+ addTouchEvent(gesture_works,​ pi.pointerId,​ GW_TOUCHUPDATE,​ (float)pi.ptPixelLocation.x,​ (float)pi.ptPixelLocation.y);​
  
  break;  break;
Line 87: Line 87:
  destroyGestureWorks(gesture_works);​  destroyGestureWorks(gesture_works);​
 </​code>​ </​code>​
-The final code is at GestureWorks2\Samples\C++\gestureworks-demo-screen\src\main.cpp+ 
 +** Final Code ** 
 +The final code is at GestureWorks2\Samples\C++\gestureworks-demo-screen\src\main.cpp. Here is the complete code: 
 +<​code>​ 
 +#include <​Windows.h>​ 
 +#include <​iostream>​ 
 +#include "​render.h"​ 
 + 
 +// 1 - Link library, header 
 +#include "​GestureWorks2.h"​ 
 + 
 +// 2 - Declare GestureWorks 
 +static GestureWorks *gesture_works = nullptr; 
 + 
 +// Some variables to display our test image 
 +static int s_window_width,​ s_window_height;​ 
 +static float s_image_x, s_image_y;​ 
 +static float s_image_rotation;​ 
 +static float s_image_scale;​ 
 + 
 +HWND CreateAdjustedWindow(char *windowTitle,​ WNDPROC wndProc, bool windowed = false, int width = CW_USEDEFAULT,​ int height = CW_USEDEFAULT,​ int x = CW_USEDEFAULT,​ int y = CW_USEDEFAULT) 
 +
 + WNDCLASSEXA wc; 
 + ZeroMemory(&​wc,​ sizeof(wc));​ 
 + wc.style = CS_OWNDC; 
 + wc.cbSize = sizeof(WNDCLASSEX);​ 
 + wc.lpfnWndProc = wndProc; 
 + wc.hInstance = GetModuleHandle(0);​ 
 + wc.hCursor = LoadCursor(NULL,​ IDC_ARROW);​ 
 + wc.lpszClassName = windowTitle;​ 
 + RegisterClassExA(&​wc);​ 
 + 
 + RECT windowRect;​ 
 + DWORD style; 
 + if (windowed) 
 +
 + style = WS_OVERLAPPED;​ 
 + windowRect = { 0, 0, width, height }; 
 + AdjustWindowRectEx(&​windowRect,​ style, FALSE, 0); 
 +
 + else 
 +
 + style = WS_POPUPWINDOW ^ WS_BORDER;​ 
 + HWND desktop = GetDesktopWindow();​ 
 + GetWindowRect(desktop,​ &​windowRect);​ 
 + x = 0; 
 + y = 0; 
 +
 + 
 + width = windowRect.right - windowRect.left;​ 
 + height = windowRect.bottom - windowRect.top;​ 
 + HWND hWnd = CreateWindowExA(0,​ wc.lpszClassName,​ windowTitle,​ style, x, y, width, height, NULL, NULL, wc.hInstance,​ NULL); 
 + ShowWindow(hWnd,​ SW_NORMAL);​ 
 + s_window_width = width; 
 + s_window_height = height; 
 + 
 + // 3 - Initialize GestureWorks 
 + gesture_works = initializeGestureWorksScreenGestures(width,​ height); 
 + 
 + return hWnd; 
 +
 + 
 +void PumpEvents() 
 +
 + MSG msg; 
 + while (PeekMessageA(&​msg,​ NULL, 0, 0, 1) > 0) 
 +
 + TranslateMessage(&​msg);​ 
 + DispatchMessage(&​msg);​ 
 +
 +
 + 
 +static bool g_running = true; 
 +// 4 - Pass input to GestureWorks 
 +static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
 +
 + switch (uMsg) 
 +
 + case WM_POINTERDOWN:​ 
 +
 + POINTER_INFO pi; 
 + GetPointerInfo(GET_POINTERID_WPARAM(wParam),​ &pi); 
 + 
 + addTouchEvent(gesture_works,​ pi.pointerId,​ GW_TOUCHADDED,​ (float)pi.ptPixelLocation.x,​ (float)pi.ptPixelLocation.y);​ 
 + 
 + break; 
 +
 + case WM_POINTERUP:​ 
 +
 + POINTER_INFO pi; 
 + GetPointerInfo(GET_POINTERID_WPARAM(wParam),​ &pi); 
 + 
 + addTouchEvent(gesture_works,​ pi.pointerId,​ GW_TOUCHREMOVED,​ (float)pi.ptPixelLocation.x,​ (float)pi.ptPixelLocation.y);​ 
 + 
 + break; 
 +
 + case WM_POINTERUPDATE:​ 
 +
 + POINTER_INFO pi; 
 + GetPointerInfo(GET_POINTERID_WPARAM(wParam),​ &pi); 
 + 
 + addTouchEvent(gesture_works,​ pi.pointerId,​ GW_TOUCHUPDATE,​ (float)pi.ptPixelLocation.x,​ (float)pi.ptPixelLocation.y);​ 
 + 
 + break; 
 +
 + 
 + case WM_CREATE:​ 
 + Re_Init(hWnd);​ 
 + break; 
 + case WM_DESTROY:​ 
 + // 7 - Destroy GestureWorks 
 + destroyGestureWorks(gesture_works);​ 
 + g_running = false; 
 + break; 
 + case WM_KEYDOWN:​ 
 + if (wParam == VK_ESCAPE) 
 + g_running = false; 
 + break; 
 + case WM_SIZE: 
 + Re_SizeToClientArea();​ 
 + break; 
 +
 + return DefWindowProc(hWnd,​ uMsg, wParam, lParam); 
 +
 + 
 +int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,​ LPSTR lpCmdLine, int nCmdShow) 
 +
 + HWND hWnd = CreateAdjustedWindow("​GestureWorks Demo", WndProc, false); 
 + 
 + RECT clientRect;​ 
 + GetClientRect(hWnd,​ &​clientRect);​ 
 + 
 + Re_Image *testImage = Re_LoadImage(L"​GestureWorks.png"​);​ 
 + 
 + float screenCenterX = clientRect.right / 2.0f; 
 + float screenCenterY = clientRect.bottom / 2.0f; 
 + s_image_x = clientRect.right / 2.0f - testImage->​width / 2.0f; 
 + s_image_y = clientRect.bottom / 2.0f - testImage->​height / 2.0f; 
 + s_image_rotation = 0.0f; 
 + s_image_scale = 1.0f; 
 + 
 + float angle = 0; 
 + while (g_running) 
 +
 + PumpEvents();​ 
 + 
 + Re_ClearScreen(0.52f,​ 0.80f, 0.98f, 0); 
 + 
 + Re_BeginDraw();​ 
 + Re_Identity();​ 
 + 
 + // 5 - Update frame 
 + updateScreenFrame(gesture_works);​ 
 + 
 + // 6 - Read gestures 
 + GestureInfo *gesture_info;​ 
 + const int gesture_count = getGestureEvents(gesture_works,​ &​gesture_info);​ 
 + for (int i = 0; i != gesture_count;​ ++i) 
 +
 + GestureInfo event = gesture_info[i];​ 
 + 
 + if (strcmp("​drag",​ event.gesture_type) == 0) 
 +
 + s_image_x += event.getValue("​drag_dx"​) * s_window_width;​ 
 + s_image_y += event.getValue("​drag_dy"​) * s_window_height;​ 
 + 
 +
 + else if (strcmp("​rotate",​ event.gesture_type) == 0) 
 +
 + s_image_rotation += event.getValue("​rotate_dtheta"​);​ 
 +
 + else if (strcmp("​scale",​ event.gesture_type) == 0) 
 +
 + s_image_scale += event.getValue("​scale_dsx"​) * s_window_width;​ 
 +
 +
 + 
 + Re_Scale(s_image_scale,​ s_image_scale,​ s_image_x + testImage->​width / 2.0f, s_image_y + testImage->​height / 2.0f); 
 + Re_Rotate(s_image_rotation,​ s_image_x + testImage->​width / 2.0f, s_image_y + testImage->​height / 2.0f); 
 + Re_DrawImage(testImage,​ s_image_x, s_image_y);​ 
 + 
 + Re_EndDraw();​ 
 + 
 + // waits for vsync 
 + Re_PresentBackBuffer();​ 
 +
 + 
 + Re_ReleaseImage(testImage);​ 
 + Re_Cleanup();​ 
 +
 + 
 +</​code>​
  
c_screen_tutorial.1493925179.txt.gz · Last modified: 2019/01/21 16:35 (external edit)