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