SDL  2.0
SDL_bvideo.cc
Go to the documentation of this file.
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 {
56  /*SDL_VideoData *data;*/
57 
58  /* Initialize all variables that we clean on shutdown */
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 
128  "haiku", "Haiku graphics",
129  HAIKU_CreateDevice
130 };
131 
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 
166 {
167  /* Initialize the Be Application for appserver interaction */
168  if (SDL_InitBeApp() < 0) {
169  return -1;
170  }
171 
172  /* Initialize video modes */
174 
175  /* Init the keymap */
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 
191 {
192 
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: */
int SDL_InitBeApp(void)
void SDL_QuitBeApp(void)
#define _THIS
char * HAIKU_GetClipboardText(_THIS)
int HAIKU_SetClipboardText(_THIS, const char *text)
SDL_bool HAIKU_HasClipboardText(_THIS)
void HAIKU_PumpEvents(_THIS)
int HAIKU_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
int HAIKU_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
void HAIKU_DestroyWindowFramebuffer(_THIS, SDL_Window *window)
void HAIKU_InitOSKeymap(void)
int HAIKU_QuitModes(_THIS)
int HAIKU_InitModes(_THIS)
void HAIKU_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
int HAIKU_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
int HAIKU_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
void HAIKU_DeleteDevice(_THIS)
void HAIKU_VideoQuit(_THIS)
int HAIKU_VideoInit(_THIS)
void HAIKU_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
SDL_bool HAIKU_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
void HAIKU_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
void HAIKU_ShowWindow(_THIS, SDL_Window *window)
void HAIKU_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
int HAIKU_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
void HAIKU_SetWindowSize(_THIS, SDL_Window *window)
int HAIKU_CreateWindow(_THIS, SDL_Window *window)
void HAIKU_RestoreWindow(_THIS, SDL_Window *window)
int HAIKU_GetWindowGammaRamp(_THIS, SDL_Window *window, Uint16 *ramp)
int HAIKU_SetWindowGammaRamp(_THIS, SDL_Window *window, const Uint16 *ramp)
void HAIKU_HideWindow(_THIS, SDL_Window *window)
void HAIKU_SetWindowPosition(_THIS, SDL_Window *window)
void HAIKU_DestroyWindow(_THIS, SDL_Window *window)
void HAIKU_RaiseWindow(_THIS, SDL_Window *window)
void HAIKU_SetWindowTitle(_THIS, SDL_Window *window)
void HAIKU_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
void HAIKU_MaximizeWindow(_THIS, SDL_Window *window)
void HAIKU_MinimizeWindow(_THIS, SDL_Window *window)
void HAIKU_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
#define SDL_SetError
#define SDL_free
#define SDL_calloc
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:175
VideoBootStrap HAIKU_bootstrap
static SDL_VideoDevice * _this
Definition: SDL_video.c:126
#define NULL
Definition: begin_code.h:163
static SDL_AudioDeviceID device
Definition: loopwave.c:37
SDL_Cursor * cur_cursor
Definition: SDL_mouse_c.h:105
int(* ShowCursor)(SDL_Cursor *cursor)
Definition: SDL_mouse_c.h:52
SDL_Window * focus
Definition: SDL_mouse_c.h:77
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:104