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