src/video/bwindow/SDL_bwindow.cc
author Nathan Heisey <nathanheisey@gmail.com>
Wed, 17 Aug 2011 13:31:18 +0000
changeset 5937 74870d003e32
parent 5932 cd08863bcb49
child 5938 b85b6326c498
permissions -rw-r--r--
Fixed some problems with switching to/from fullscreen
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2011 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_config.h"
    22 #include "../SDL_sysvideo.h"
    23 
    24 #include "SDL_BWin.h"
    25 #include <new>
    26 
    27 /* Define a path to window's BWIN data */
    28 #ifdef __cplusplus
    29 extern "C" {
    30 #endif
    31 
    32 static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
    33 	return ((SDL_BWin*)(window->driverdata));
    34 }
    35 
    36 static inline SDL_BApp *_GetBeApp() {
    37 	return ((SDL_BApp*)be_app);
    38 }
    39 
    40 int _InitWindow(_THIS, SDL_Window *window) {
    41 	uint32 flags = 0;
    42 	BRect bounds(
    43         window->x,
    44         window->y,
    45         window->x + window->w - 1,	//BeWindows have an off-by-one px w/h thing
    46         window->y + window->h - 1
    47     );
    48     
    49     if(window->flags & SDL_WINDOW_FULLSCREEN) {
    50     }
    51     if(window->flags & SDL_WINDOW_OPENGL) {
    52     }
    53     if(!(window->flags & SDL_WINDOW_RESIZABLE)) {
    54     	flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE;
    55     }
    56     if(window->flags & SDL_WINDOW_BORDERLESS) {
    57     }
    58 
    59     SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, flags);
    60     if(bwin == NULL)
    61     	return ENOMEM;
    62 
    63     window->driverdata = bwin;
    64     int32 winID = _GetBeApp()->GetID(window);
    65     bwin->SetID(winID);
    66 
    67     return 0;
    68 }
    69 
    70 int BE_CreateWindow(_THIS, SDL_Window *window) {
    71 	if(_InitWindow(_this, window) == ENOMEM)
    72 		return ENOMEM;
    73 	
    74 	printf("Flags = 0x%x\n", window->flags);
    75 	/* Start window loop */
    76     _ToBeWin(window)->Show();
    77     return 0;
    78 }
    79 
    80 int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) {
    81 
    82 	SDL_BWin *otherBWin = (SDL_BWin*)data;
    83 	if(!otherBWin->LockLooper())
    84 		return -1;
    85 	
    86 	/* Create the new window and initialize its members */
    87 	window->x = (int)otherBWin->Frame().left;
    88 	window->y = (int)otherBWin->Frame().top;
    89 	window->w = (int)otherBWin->Frame().Width();
    90 	window->h = (int)otherBWin->Frame().Height();
    91 	
    92 	/* Set SDL flags */
    93 	if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) {
    94 		window->flags |= SDL_WINDOW_RESIZABLE;
    95 	}
    96 	
    97 	/* If we are out of memory, return the error code */
    98 	if(_InitWindow(_this, window) == ENOMEM)
    99 		return ENOMEM;
   100 	
   101 	/* TODO: Add any other SDL-supported window attributes here */
   102     _ToBeWin(window)->SetTitle(otherBWin->Title());
   103     
   104     /* Start window loop and unlock the other window */
   105     _ToBeWin(window)->Show();
   106     
   107     otherBWin->UnlockLooper();
   108     return 0;
   109 }
   110 
   111 void BE_SetWindowTitle(_THIS, SDL_Window * window) {
   112 	BMessage msg(BWIN_SET_TITLE);
   113 	msg.AddString("window-title", window->title);
   114 	_ToBeWin(window)->PostMessage(&msg);
   115 }
   116 
   117 void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) {
   118 	/* FIXME: Icons not supported by BeOs/Haiku */
   119 }
   120 
   121 void BE_SetWindowPosition(_THIS, SDL_Window * window) {
   122 	BMessage msg(BWIN_MOVE_WINDOW);
   123 	msg.AddInt32("window-x", window->x);
   124 	msg.AddInt32("window-y", window->y);
   125 	_ToBeWin(window)->PostMessage(&msg);
   126 }
   127 
   128 void BE_SetWindowSize(_THIS, SDL_Window * window) {
   129 	BMessage msg(BWIN_RESIZE_WINDOW);
   130 	msg.AddInt32("window-w", window->w - 1);
   131 	msg.AddInt32("window-h", window->h - 1);
   132 	_ToBeWin(window)->PostMessage(&msg);
   133 }
   134 
   135 void BE_ShowWindow(_THIS, SDL_Window * window) {
   136 	BMessage msg(BWIN_SHOW_WINDOW);
   137 	_ToBeWin(window)->PostMessage(&msg);
   138 }
   139 
   140 void BE_HideWindow(_THIS, SDL_Window * window) {
   141 	BMessage msg(BWIN_HIDE_WINDOW);
   142 	_ToBeWin(window)->PostMessage(&msg);
   143 }
   144 
   145 void BE_RaiseWindow(_THIS, SDL_Window * window) {
   146 	BMessage msg(BWIN_SHOW_WINDOW);	/* Activate this window and move to front */
   147 	_ToBeWin(window)->PostMessage(&msg);
   148 }
   149 
   150 void BE_MaximizeWindow(_THIS, SDL_Window * window) {
   151 	BMessage msg(BWIN_MAXIMIZE_WINDOW);
   152 	_ToBeWin(window)->PostMessage(&msg);
   153 }
   154 
   155 void BE_MinimizeWindow(_THIS, SDL_Window * window) {
   156 	BMessage msg(BWIN_MINIMIZE_WINDOW);
   157 	_ToBeWin(window)->PostMessage(&msg);
   158 }
   159 
   160 void BE_RestoreWindow(_THIS, SDL_Window * window) {
   161 	BMessage msg(BWIN_RESTORE_WINDOW);
   162 	_ToBeWin(window)->PostMessage(&msg);
   163 }
   164 
   165 void BE_SetWindowFullscreen(_THIS, SDL_Window * window,
   166 		SDL_VideoDisplay * display, SDL_bool fullscreen) {
   167 	/* Haiku tracks all video display information */
   168 	BMessage msg(BWIN_FULLSCREEN);
   169 	msg.AddBool("fullscreen", fullscreen);
   170 	_ToBeWin(window)->PostMessage(&msg);
   171 	
   172 }
   173 
   174 int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
   175 	/* FIXME: Not BeOs/Haiku supported */
   176 }
   177 
   178 int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
   179 	/* FIXME: Not BeOs/Haiku supported */
   180 }
   181 
   182 
   183 void BE_SetWindowGrab(_THIS, SDL_Window * window) {
   184 	/* TODO: Implement this! */
   185 }
   186 
   187 void BE_DestroyWindow(_THIS, SDL_Window * window) {
   188 	_ToBeWin(window)->LockLooper();	/* This MUST be locked */
   189 	_GetBeApp()->ClearID(_ToBeWin(window));
   190 	_ToBeWin(window)->Quit();
   191 	window->driverdata = NULL;
   192 }
   193 
   194 SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
   195                                     struct SDL_SysWMinfo *info) {
   196 	/* FIXME: What is the point of this? What information should be included? */
   197 }
   198 
   199 
   200 
   201 
   202  
   203 #ifdef __cplusplus
   204 }
   205 #endif
   206