src/video/bwindow/SDL_bwindow.cc
changeset 5918 2063df37190b
child 5921 4cec9ba57dfb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/bwindow/SDL_bwindow.cc	Wed Jul 13 09:29:43 2011 +0000
     1.3 @@ -0,0 +1,203 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +#include "SDL_config.h"
    1.25 +#include "../SDL_sysvideo.h"
    1.26 +
    1.27 +#include "SDL_BWin.h"
    1.28 +#include <new>
    1.29 +
    1.30 +/* Define a path to window's BWIN data */
    1.31 +#ifdef __cplusplus
    1.32 +extern "C" {
    1.33 +#endif
    1.34 +
    1.35 +static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
    1.36 +	return ((SDL_BWin*)(window->driverdata));
    1.37 +}
    1.38 +
    1.39 +static inline SDL_BApp *_GetBeApp() {
    1.40 +	return ((SDL_BApp*)be_app);
    1.41 +}
    1.42 +
    1.43 +int _InitWindow(_THIS, SDL_Window *window) {
    1.44 +	BRect bounds(
    1.45 +        window->x,
    1.46 +        window->y,
    1.47 +        window->x + window->w - 1,	//BeWindows have an off-by-one px w/h thing
    1.48 +        window->y + window->h - 1
    1.49 +    );
    1.50 +    
    1.51 +    SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds);
    1.52 +    if(bwin == NULL)
    1.53 +    	return ENOMEM;
    1.54 +    
    1.55 +    window->driverdata = bwin;
    1.56 +    int32 winID = _GetBeApp()->GetID(window);
    1.57 +    bwin->SetID(winID);
    1.58 +    return 0;
    1.59 +}
    1.60 +
    1.61 +int BE_CreateWindow(_THIS, SDL_Window *window) {
    1.62 +	if(_InitWindow(_this, window) == ENOMEM)
    1.63 +		return ENOMEM;
    1.64 +	
    1.65 +	/* Start window loop */
    1.66 +    _ToBeWin(window)->Show();
    1.67 +    return 0;
    1.68 +}
    1.69 +
    1.70 +int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) {
    1.71 +
    1.72 +	SDL_BWin *otherBWin = (SDL_BWin*)data;
    1.73 +	if(!otherBWin->LockLooper())
    1.74 +		return -1;
    1.75 +	
    1.76 +	/* Create the new window and initialize its members */
    1.77 +	window->x = (int)otherBWin->Frame().left;
    1.78 +	window->y = (int)otherBWin->Frame().top;
    1.79 +	window->w = (int)otherBWin->Frame().Width();
    1.80 +	window->h = (int)otherBWin->Frame().Height();
    1.81 +	
    1.82 +	/* If we are out of memory, return the error code */
    1.83 +	if(_InitWindow(_this, window) == ENOMEM)
    1.84 +		return ENOMEM;
    1.85 +	
    1.86 +	/* TODO: Add any other SDL-supported window attributes here */
    1.87 +    _ToBeWin(window)->SetTitle(otherBWin->Title());
    1.88 +    
    1.89 +    /* Start window loop and unlock the other window */
    1.90 +    _ToBeWin(window)->Show();
    1.91 +    
    1.92 +    otherBWin->UnlockLooper();
    1.93 +    return 0;
    1.94 +}
    1.95 +
    1.96 +void BE_SetWindowTitle(_THIS, SDL_Window * window) {
    1.97 +	BMessage msg(BWIN_SET_TITLE);
    1.98 +	msg.AddString("window-title", window->title);
    1.99 +	_ToBeWin(window)->PostMessage(&msg);
   1.100 +}
   1.101 +
   1.102 +void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) {
   1.103 +	/* FIXME: Icons not supported by BeOs/Haiku */
   1.104 +}
   1.105 +
   1.106 +void BE_SetWindowPosition(_THIS, SDL_Window * window) {
   1.107 +	BMessage msg(BWIN_MOVE_WINDOW);
   1.108 +	msg.AddInt32("window-x", window->x);
   1.109 +	msg.AddInt32("window-y", window->y);
   1.110 +	_ToBeWin(window)->PostMessage(&msg);
   1.111 +}
   1.112 +
   1.113 +void BE_SetWindowSize(_THIS, SDL_Window * window) {
   1.114 +	BMessage msg(BWIN_RESIZE_WINDOW);
   1.115 +	msg.AddInt32("window-w", window->w - 1);
   1.116 +	msg.AddInt32("window-h", window->h - 1);
   1.117 +	_ToBeWin(window)->PostMessage(&msg);
   1.118 +}
   1.119 +
   1.120 +void BE_ShowWindow(_THIS, SDL_Window * window) {
   1.121 +	BMessage msg(BWIN_SHOW_WINDOW);
   1.122 +	_ToBeWin(window)->PostMessage(&msg);
   1.123 +}
   1.124 +
   1.125 +void BE_HideWindow(_THIS, SDL_Window * window) {
   1.126 +	BMessage msg(BWIN_HIDE_WINDOW);
   1.127 +	_ToBeWin(window)->PostMessage(&msg);
   1.128 +}
   1.129 +
   1.130 +void BE_RaiseWindow(_THIS, SDL_Window * window) {
   1.131 +	BMessage msg(BWIN_SHOW_WINDOW);	/* Activate this window and move to front */
   1.132 +	_ToBeWin(window)->PostMessage(&msg);
   1.133 +}
   1.134 +
   1.135 +void BE_MaximizeWindow(_THIS, SDL_Window * window) {
   1.136 +	BMessage msg(BWIN_MAXIMIZE_WINDOW);
   1.137 +	_ToBeWin(window)->PostMessage(&msg);
   1.138 +}
   1.139 +
   1.140 +void BE_MinimizeWindow(_THIS, SDL_Window * window) {
   1.141 +	BMessage msg(BWIN_MINIMIZE_WINDOW);
   1.142 +	_ToBeWin(window)->PostMessage(&msg);
   1.143 +}
   1.144 +
   1.145 +void BE_RestoreWindow(_THIS, SDL_Window * window) {
   1.146 +	BMessage msg(BWIN_RESTORE_WINDOW);
   1.147 +	_ToBeWin(window)->PostMessage(&msg);
   1.148 +}
   1.149 +
   1.150 +void BE_SetWindowFullscreen(_THIS, SDL_Window * window,
   1.151 +		SDL_VideoDisplay * display, SDL_bool fullscreen) {
   1.152 +	/* Haiku tracks all video display information */
   1.153 +	BMessage msg(BWIN_FULLSCREEN);
   1.154 +	msg.AddBool("fullscreen", fullscreen);
   1.155 +	_ToBeWin(window)->PostMessage(&msg);
   1.156 +	
   1.157 +}
   1.158 +
   1.159 +int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
   1.160 +	/* FIXME: Not BeOs/Haiku supported */
   1.161 +}
   1.162 +
   1.163 +int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
   1.164 +	/* FIXME: Not BeOs/Haiku supported */
   1.165 +}
   1.166 +
   1.167 +
   1.168 +void BE_SetWindowGrab(_THIS, SDL_Window * window) {
   1.169 +	/* TODO: Implement this! */
   1.170 +}
   1.171 +
   1.172 +void BE_DestroyWindow(_THIS, SDL_Window * window) {
   1.173 +	_ToBeWin(window)->LockLooper();	/* This MUST be locked */
   1.174 +	_GetBeApp()->ClearID(_ToBeWin(window));
   1.175 +	_ToBeWin(window)->Quit();
   1.176 +	window->driverdata = NULL;
   1.177 +}
   1.178 +
   1.179 +SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
   1.180 +                                    struct SDL_SysWMinfo *info) {
   1.181 +	/* FIXME: What is the point of this? What information should be included? */
   1.182 +}
   1.183 +
   1.184 +
   1.185 +extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
   1.186 +                                       Uint32 * format,
   1.187 +                                       void ** pixels, int *pitch) {
   1.188 +	/* FIXME: Not BeOs/Haiku supported */
   1.189 +	return -1;
   1.190 +}
   1.191 +
   1.192 +extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
   1.193 +                                       SDL_Rect * rects, int numrects) {
   1.194 +	/* FIXME: Not BeOs/Haiku supported */
   1.195 +	return -1;
   1.196 +}
   1.197 +
   1.198 +extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) {
   1.199 +	/* FIXME: Not BeOs/Haiku supported */
   1.200 +}
   1.201 +
   1.202 + 
   1.203 +#ifdef __cplusplus
   1.204 +}
   1.205 +#endif
   1.206 +