src/video/windows/SDL_windowsvideo.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 02 Mar 2013 20:44:16 -0800
changeset 6950 1ddb72193079
parent 6885 700f1b25f77f
child 7037 3fedf1f25b94
permissions -rw-r--r--
Added a mouse ID to the mouse events, which set to the special value SDL_TOUCH_MOUSEID for mouse events simulated by touch input.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 #include "SDL_config.h"
    22 
    23 #if SDL_VIDEO_DRIVER_WINDOWS
    24 
    25 #include "SDL_main.h"
    26 #include "SDL_video.h"
    27 #include "SDL_mouse.h"
    28 #include "../SDL_sysvideo.h"
    29 #include "../SDL_pixels_c.h"
    30 
    31 #include "SDL_windowsvideo.h"
    32 #include "SDL_windowsframebuffer.h"
    33 #include "SDL_windowsshape.h"
    34 
    35 /* Initialization/Query functions */
    36 static int WIN_VideoInit(_THIS);
    37 static void WIN_VideoQuit(_THIS);
    38 
    39 
    40 /* Windows driver bootstrap functions */
    41 
    42 static int
    43 WIN_Available(void)
    44 {
    45     return (1);
    46 }
    47 
    48 static void
    49 WIN_DeleteDevice(SDL_VideoDevice * device)
    50 {
    51     SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
    52 
    53     SDL_UnregisterApp();
    54 	if (data->userDLL) {
    55 		SDL_UnloadObject(data->userDLL);
    56 	}
    57 
    58     SDL_free(device->driverdata);
    59     SDL_free(device);
    60 }
    61 
    62 static SDL_VideoDevice *
    63 WIN_CreateDevice(int devindex)
    64 {
    65     SDL_VideoDevice *device;
    66     SDL_VideoData *data;
    67 
    68     SDL_RegisterApp(NULL, 0, NULL);
    69 
    70     /* Initialize all variables that we clean on shutdown */
    71     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    72     if (device) {
    73         data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
    74     } else {
    75         data = NULL;
    76     }
    77     if (!data) {
    78         SDL_OutOfMemory();
    79         if (device) {
    80             SDL_free(device);
    81         }
    82         return NULL;
    83     }
    84     device->driverdata = data;
    85 
    86 	data->userDLL = SDL_LoadObject("USER32.DLL");
    87 	if (data->userDLL) {
    88 		data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle");
    89 		data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo");
    90 		data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow");
    91 	}
    92 
    93     /* Set the function pointers */
    94     device->VideoInit = WIN_VideoInit;
    95     device->VideoQuit = WIN_VideoQuit;
    96     device->GetDisplayBounds = WIN_GetDisplayBounds;
    97     device->GetDisplayModes = WIN_GetDisplayModes;
    98     device->SetDisplayMode = WIN_SetDisplayMode;
    99     device->PumpEvents = WIN_PumpEvents;
   100 
   101 #undef CreateWindow
   102     device->CreateWindow = WIN_CreateWindow;
   103     device->CreateWindowFrom = WIN_CreateWindowFrom;
   104     device->SetWindowTitle = WIN_SetWindowTitle;
   105     device->SetWindowIcon = WIN_SetWindowIcon;
   106     device->SetWindowPosition = WIN_SetWindowPosition;
   107     device->SetWindowSize = WIN_SetWindowSize;
   108     device->ShowWindow = WIN_ShowWindow;
   109     device->HideWindow = WIN_HideWindow;
   110     device->RaiseWindow = WIN_RaiseWindow;
   111     device->MaximizeWindow = WIN_MaximizeWindow;
   112     device->MinimizeWindow = WIN_MinimizeWindow;
   113     device->RestoreWindow = WIN_RestoreWindow;
   114     device->SetWindowBordered = WIN_SetWindowBordered;
   115     device->SetWindowFullscreen = WIN_SetWindowFullscreen;
   116     device->SetWindowGammaRamp = WIN_SetWindowGammaRamp;
   117     device->GetWindowGammaRamp = WIN_GetWindowGammaRamp;
   118     device->SetWindowGrab = WIN_SetWindowGrab;
   119     device->DestroyWindow = WIN_DestroyWindow;
   120     device->GetWindowWMInfo = WIN_GetWindowWMInfo;
   121     device->CreateWindowFramebuffer = WIN_CreateWindowFramebuffer;
   122     device->UpdateWindowFramebuffer = WIN_UpdateWindowFramebuffer;
   123     device->DestroyWindowFramebuffer = WIN_DestroyWindowFramebuffer;
   124     
   125     device->shape_driver.CreateShaper = Win32_CreateShaper;
   126     device->shape_driver.SetWindowShape = Win32_SetWindowShape;
   127     device->shape_driver.ResizeWindowShape = Win32_ResizeWindowShape;
   128     
   129 #if SDL_VIDEO_OPENGL_WGL
   130     device->GL_LoadLibrary = WIN_GL_LoadLibrary;
   131     device->GL_GetProcAddress = WIN_GL_GetProcAddress;
   132     device->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
   133     device->GL_CreateContext = WIN_GL_CreateContext;
   134     device->GL_MakeCurrent = WIN_GL_MakeCurrent;
   135     device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
   136     device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
   137     device->GL_SwapWindow = WIN_GL_SwapWindow;
   138     device->GL_DeleteContext = WIN_GL_DeleteContext;
   139 #endif
   140     device->StartTextInput = WIN_StartTextInput;
   141     device->StopTextInput = WIN_StopTextInput;
   142     device->SetTextInputRect = WIN_SetTextInputRect;
   143 
   144     device->SetClipboardText = WIN_SetClipboardText;
   145     device->GetClipboardText = WIN_GetClipboardText;
   146     device->HasClipboardText = WIN_HasClipboardText;
   147 
   148     device->free = WIN_DeleteDevice;
   149 
   150     return device;
   151 }
   152 
   153 VideoBootStrap WINDOWS_bootstrap = {
   154     "windows", "SDL Windows video driver", WIN_Available, WIN_CreateDevice
   155 };
   156 
   157 int
   158 WIN_VideoInit(_THIS)
   159 {
   160     if (WIN_InitModes(_this) < 0) {
   161         return -1;
   162     }
   163 
   164     WIN_InitKeyboard(_this);
   165     WIN_InitMouse(_this);
   166 
   167     return 0;
   168 }
   169 
   170 void
   171 WIN_VideoQuit(_THIS)
   172 {
   173     WIN_QuitModes(_this);
   174     WIN_QuitKeyboard(_this);
   175     WIN_QuitMouse(_this);
   176 }
   177 
   178 #endif /* SDL_VIDEO_DRIVER_WINDOWS */
   179 
   180 /* vim: set ts=4 sw=4 expandtab: */