sdl

FORK: Simple Directmedia Layer
git clone https://git.neptards.moe/neptards/sdl.git
Log | Files | Refs

SDL_bvideo.cc (6437B)


      1 /*
      2   Simple DirectMedia Layer
      3   Copyright (C) 1997-2020 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_internal.h"
     22 #include "../../main/haiku/SDL_BApp.h"
     23 
     24 #if SDL_VIDEO_DRIVER_HAIKU
     25 
     26 
     27 #ifdef __cplusplus
     28 extern "C" {
     29 #endif
     30 
     31 #include "SDL_bkeyboard.h"
     32 #include "SDL_bwindow.h"
     33 #include "SDL_bclipboard.h"
     34 #include "SDL_bvideo.h"
     35 #include "SDL_bopengl.h"
     36 #include "SDL_bmodes.h"
     37 #include "SDL_bframebuffer.h"
     38 #include "SDL_bevents.h"
     39 
     40 #include <Url.h>
     41 
     42 /* FIXME: Undefined functions */
     43 //    #define HAIKU_PumpEvents NULL
     44     #define HAIKU_StartTextInput NULL
     45     #define HAIKU_StopTextInput NULL
     46     #define HAIKU_SetTextInputRect NULL
     47 
     48 //    #define HAIKU_DeleteDevice NULL
     49 
     50 /* End undefined functions */
     51 
     52 static SDL_VideoDevice *
     53 HAIKU_CreateDevice(int devindex)
     54 {
     55     SDL_VideoDevice *device;
     56     /*SDL_VideoData *data;*/
     57 
     58     /* Initialize all variables that we clean on shutdown */
     59     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
     60 
     61     device->driverdata = NULL; /* FIXME: Is this the cause of some of the
     62                                   SDL_Quit() errors? */
     63 
     64 /* TODO: Figure out if any initialization needs to go here */
     65 
     66     /* Set the function pointers */
     67     device->VideoInit = HAIKU_VideoInit;
     68     device->VideoQuit = HAIKU_VideoQuit;
     69     device->GetDisplayBounds = HAIKU_GetDisplayBounds;
     70     device->GetDisplayModes = HAIKU_GetDisplayModes;
     71     device->SetDisplayMode = HAIKU_SetDisplayMode;
     72     device->PumpEvents = HAIKU_PumpEvents;
     73 
     74     device->CreateSDLWindow = HAIKU_CreateWindow;
     75     device->CreateSDLWindowFrom = HAIKU_CreateWindowFrom;
     76     device->SetWindowTitle = HAIKU_SetWindowTitle;
     77     device->SetWindowIcon = HAIKU_SetWindowIcon;
     78     device->SetWindowPosition = HAIKU_SetWindowPosition;
     79     device->SetWindowSize = HAIKU_SetWindowSize;
     80     device->ShowWindow = HAIKU_ShowWindow;
     81     device->HideWindow = HAIKU_HideWindow;
     82     device->RaiseWindow = HAIKU_RaiseWindow;
     83     device->MaximizeWindow = HAIKU_MaximizeWindow;
     84     device->MinimizeWindow = HAIKU_MinimizeWindow;
     85     device->RestoreWindow = HAIKU_RestoreWindow;
     86     device->SetWindowBordered = HAIKU_SetWindowBordered;
     87     device->SetWindowResizable = HAIKU_SetWindowResizable;
     88     device->SetWindowFullscreen = HAIKU_SetWindowFullscreen;
     89     device->SetWindowGammaRamp = HAIKU_SetWindowGammaRamp;
     90     device->GetWindowGammaRamp = HAIKU_GetWindowGammaRamp;
     91     device->SetWindowGrab = HAIKU_SetWindowGrab;
     92     device->DestroyWindow = HAIKU_DestroyWindow;
     93     device->GetWindowWMInfo = HAIKU_GetWindowWMInfo;
     94     device->CreateWindowFramebuffer = HAIKU_CreateWindowFramebuffer;
     95     device->UpdateWindowFramebuffer = HAIKU_UpdateWindowFramebuffer;
     96     device->DestroyWindowFramebuffer = HAIKU_DestroyWindowFramebuffer;
     97     
     98     device->shape_driver.CreateShaper = NULL;
     99     device->shape_driver.SetWindowShape = NULL;
    100     device->shape_driver.ResizeWindowShape = NULL;
    101 
    102 #if SDL_VIDEO_OPENGL
    103     device->GL_LoadLibrary = HAIKU_GL_LoadLibrary;
    104     device->GL_GetProcAddress = HAIKU_GL_GetProcAddress;
    105     device->GL_UnloadLibrary = HAIKU_GL_UnloadLibrary;
    106     device->GL_CreateContext = HAIKU_GL_CreateContext;
    107     device->GL_MakeCurrent = HAIKU_GL_MakeCurrent;
    108     device->GL_SetSwapInterval = HAIKU_GL_SetSwapInterval;
    109     device->GL_GetSwapInterval = HAIKU_GL_GetSwapInterval;
    110     device->GL_SwapWindow = HAIKU_GL_SwapWindow;
    111     device->GL_DeleteContext = HAIKU_GL_DeleteContext;
    112 #endif
    113 
    114     device->StartTextInput = HAIKU_StartTextInput;
    115     device->StopTextInput = HAIKU_StopTextInput;
    116     device->SetTextInputRect = HAIKU_SetTextInputRect;
    117 
    118     device->SetClipboardText = HAIKU_SetClipboardText;
    119     device->GetClipboardText = HAIKU_GetClipboardText;
    120     device->HasClipboardText = HAIKU_HasClipboardText;
    121 
    122     device->free = HAIKU_DeleteDevice;
    123 
    124     return device;
    125 }
    126 
    127 VideoBootStrap HAIKU_bootstrap = {
    128     "haiku", "Haiku graphics",
    129     HAIKU_CreateDevice
    130 };
    131 
    132 void HAIKU_DeleteDevice(SDL_VideoDevice * device)
    133 {
    134     SDL_free(device->driverdata);
    135     SDL_free(device);
    136 }
    137 
    138 static int HAIKU_ShowCursor(SDL_Cursor *cur)
    139 {
    140 	SDL_Mouse *mouse = SDL_GetMouse();
    141 	int show;
    142 	if (!mouse)
    143 		return 0;
    144 	show = (cur || !mouse->focus);
    145 	if (show) {
    146 		if (be_app->IsCursorHidden())
    147 			be_app->ShowCursor();
    148 	} else {
    149 		if (!be_app->IsCursorHidden())
    150 			be_app->HideCursor();
    151 	}
    152 	return 0;
    153 }
    154 
    155 static void HAIKU_MouseInit(_THIS)
    156 {
    157 	SDL_Mouse *mouse = SDL_GetMouse();
    158 	if (!mouse)
    159 		return;
    160 	mouse->ShowCursor = HAIKU_ShowCursor;
    161 	mouse->cur_cursor = (SDL_Cursor*)0x1;
    162 	mouse->def_cursor = (SDL_Cursor*)0x2;
    163 }
    164 
    165 int HAIKU_VideoInit(_THIS)
    166 {
    167     /* Initialize the Be Application for appserver interaction */
    168     if (SDL_InitBeApp() < 0) {
    169         return -1;
    170     }
    171     
    172     /* Initialize video modes */
    173     HAIKU_InitModes(_this);
    174 
    175     /* Init the keymap */
    176     HAIKU_InitOSKeymap();
    177 
    178     HAIKU_MouseInit(_this);
    179 
    180 #if SDL_VIDEO_OPENGL
    181         /* testgl application doesn't load library, just tries to load symbols */
    182         /* is it correct? if so we have to load library here */
    183     HAIKU_GL_LoadLibrary(_this, NULL);
    184 #endif
    185 
    186     /* We're done! */
    187     return (0);
    188 }
    189 
    190 void HAIKU_VideoQuit(_THIS)
    191 {
    192 
    193     HAIKU_QuitModes(_this);
    194 
    195     SDL_QuitBeApp();
    196 }
    197 
    198 // just sticking this function in here so it's in a C++ source file.
    199 extern "C" { int HAIKU_OpenURL(const char *url); }
    200 int HAIKU_OpenURL(const char *url)
    201 {
    202     BUrl burl(url);
    203     const status_t rc = burl.OpenWithPreferredApplication(false);
    204     return (rc == B_NO_ERROR) ? 0 : SDL_SetError("URL open failed (err=%d)", (int) rc);
    205 }
    206 
    207 #ifdef __cplusplus
    208 }
    209 #endif
    210 
    211 #endif /* SDL_VIDEO_DRIVER_HAIKU */
    212 
    213 /* vi: set ts=4 sw=4 expandtab: */