src/video/cocoa/SDL_cocoavideo.m
author Sam Lantinga <slouken@libsdl.org>
Sat, 29 Jul 2006 21:51:00 +0000
changeset 1956 ba0d62354872
parent 1952 420716272158
child 1959 25d6537feea4
permissions -rw-r--r--
Simplified driver window creation code.
Implemented several Cocoa window functions
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #include "SDL_cocoavideo.h"
    25 
    26 /* Initialization/Query functions */
    27 static int Cocoa_VideoInit(_THIS);
    28 static void Cocoa_VideoQuit(_THIS);
    29 
    30 /* Cocoa driver bootstrap functions */
    31 
    32 static int
    33 Cocoa_Available(void)
    34 {
    35     return (1);
    36 }
    37 
    38 static void
    39 Cocoa_DeleteDevice(SDL_VideoDevice * device)
    40 {
    41     SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
    42 
    43     SDL_free(device->driverdata);
    44     SDL_free(device);
    45 }
    46 
    47 static SDL_VideoDevice *
    48 Cocoa_CreateDevice(int devindex)
    49 {
    50     SDL_VideoDevice *device;
    51     SDL_VideoData *data;
    52 
    53     Cocoa_RegisterApp();
    54 
    55     /* Initialize all variables that we clean on shutdown */
    56     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    57     if (device) {
    58         data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
    59     }
    60     if (!device || !data) {
    61         SDL_OutOfMemory();
    62         if (device) {
    63             SDL_free(device);
    64         }
    65         return NULL;
    66     }
    67     device->driverdata = data;
    68 
    69     /* Set the function pointers */
    70     device->VideoInit = Cocoa_VideoInit;
    71     device->VideoQuit = Cocoa_VideoQuit;
    72     device->GetDisplayModes = Cocoa_GetDisplayModes;
    73     device->SetDisplayMode = Cocoa_SetDisplayMode;
    74     device->PumpEvents = Cocoa_PumpEvents;
    75 
    76     device->CreateWindow = Cocoa_CreateWindow;
    77     device->CreateWindowFrom = Cocoa_CreateWindowFrom;
    78     device->SetWindowTitle = Cocoa_SetWindowTitle;
    79     device->SetWindowPosition = Cocoa_SetWindowPosition;
    80     device->SetWindowSize = Cocoa_SetWindowSize;
    81     device->ShowWindow = Cocoa_ShowWindow;
    82     device->HideWindow = Cocoa_HideWindow;
    83     device->RaiseWindow = Cocoa_RaiseWindow;
    84     device->MaximizeWindow = Cocoa_MaximizeWindow;
    85     device->MinimizeWindow = Cocoa_MinimizeWindow;
    86     device->RestoreWindow = Cocoa_RestoreWindow;
    87     device->SetWindowGrab = Cocoa_SetWindowGrab;
    88     device->DestroyWindow = Cocoa_DestroyWindow;
    89     device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
    90 #ifdef SDL_VIDEO_OPENGL_CGL
    91     device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
    92     device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
    93     device->GL_CreateContext = Cocoa_GL_CreateContext;
    94     device->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
    95     device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
    96     device->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
    97     device->GL_SwapWindow = Cocoa_GL_SwapWindow;
    98     device->GL_DeleteContext = Cocoa_GL_DeleteContext;
    99 #endif
   100 
   101     device->free = Cocoa_DeleteDevice;
   102 
   103     return device;
   104 }
   105 
   106 VideoBootStrap COCOA_bootstrap = {
   107     "cocoa", "SDL Cocoa video driver",
   108     Cocoa_Available, Cocoa_CreateDevice
   109 };
   110 
   111 
   112 int
   113 Cocoa_VideoInit(_THIS)
   114 {
   115     Cocoa_InitModes(_this);
   116     Cocoa_InitKeyboard(_this);
   117     Cocoa_InitMouse(_this);
   118     return 0;
   119 }
   120 
   121 void
   122 Cocoa_VideoQuit(_THIS)
   123 {
   124     Cocoa_QuitModes(_this);
   125     Cocoa_QuitKeyboard(_this);
   126     Cocoa_QuitMouse(_this);
   127 }
   128 
   129 /* vim: set ts=4 sw=4 expandtab: */