src/video/bwindow/SDL_bwindow.cc
author Nathan Heisey <nathanheisey@gmail.com>
Mon, 25 Jul 2011 16:46:55 +0000
changeset 5925 262ce29aabf6
parent 5922 efd1498efdff
child 5932 cd08863bcb49
permissions -rw-r--r--
Variable name/debugging output changes
     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 	BRect bounds(
    42         window->x,
    43         window->y,
    44         window->x + window->w - 1,	//BeWindows have an off-by-one px w/h thing
    45         window->y + window->h - 1
    46     );
    47 
    48     SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds);
    49     if(bwin == NULL)
    50     	return ENOMEM;
    51 
    52     window->driverdata = bwin;
    53     int32 winID = _GetBeApp()->GetID(window);
    54     bwin->SetID(winID);
    55     return 0;
    56 }
    57 
    58 int BE_CreateWindow(_THIS, SDL_Window *window) {
    59 	if(_InitWindow(_this, window) == ENOMEM)
    60 		return ENOMEM;
    61 	
    62 	/* Start window loop */
    63     _ToBeWin(window)->Show();
    64     return 0;
    65 }
    66 
    67 int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) {
    68 
    69 	SDL_BWin *otherBWin = (SDL_BWin*)data;
    70 	if(!otherBWin->LockLooper())
    71 		return -1;
    72 	
    73 	/* Create the new window and initialize its members */
    74 	window->x = (int)otherBWin->Frame().left;
    75 	window->y = (int)otherBWin->Frame().top;
    76 	window->w = (int)otherBWin->Frame().Width();
    77 	window->h = (int)otherBWin->Frame().Height();
    78 	
    79 	/* If we are out of memory, return the error code */
    80 	if(_InitWindow(_this, window) == ENOMEM)
    81 		return ENOMEM;
    82 	
    83 	/* TODO: Add any other SDL-supported window attributes here */
    84     _ToBeWin(window)->SetTitle(otherBWin->Title());
    85     
    86     /* Start window loop and unlock the other window */
    87     _ToBeWin(window)->Show();
    88     
    89     otherBWin->UnlockLooper();
    90     return 0;
    91 }
    92 
    93 void BE_SetWindowTitle(_THIS, SDL_Window * window) {
    94 	BMessage msg(BWIN_SET_TITLE);
    95 	msg.AddString("window-title", window->title);
    96 	_ToBeWin(window)->PostMessage(&msg);
    97 }
    98 
    99 void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) {
   100 	/* FIXME: Icons not supported by BeOs/Haiku */
   101 }
   102 
   103 void BE_SetWindowPosition(_THIS, SDL_Window * window) {
   104 	BMessage msg(BWIN_MOVE_WINDOW);
   105 	msg.AddInt32("window-x", window->x);
   106 	msg.AddInt32("window-y", window->y);
   107 	_ToBeWin(window)->PostMessage(&msg);
   108 }
   109 
   110 void BE_SetWindowSize(_THIS, SDL_Window * window) {
   111 	BMessage msg(BWIN_RESIZE_WINDOW);
   112 	msg.AddInt32("window-w", window->w - 1);
   113 	msg.AddInt32("window-h", window->h - 1);
   114 	_ToBeWin(window)->PostMessage(&msg);
   115 }
   116 
   117 void BE_ShowWindow(_THIS, SDL_Window * window) {
   118 	BMessage msg(BWIN_SHOW_WINDOW);
   119 	_ToBeWin(window)->PostMessage(&msg);
   120 }
   121 
   122 void BE_HideWindow(_THIS, SDL_Window * window) {
   123 	BMessage msg(BWIN_HIDE_WINDOW);
   124 	_ToBeWin(window)->PostMessage(&msg);
   125 }
   126 
   127 void BE_RaiseWindow(_THIS, SDL_Window * window) {
   128 	BMessage msg(BWIN_SHOW_WINDOW);	/* Activate this window and move to front */
   129 	_ToBeWin(window)->PostMessage(&msg);
   130 }
   131 
   132 void BE_MaximizeWindow(_THIS, SDL_Window * window) {
   133 	BMessage msg(BWIN_MAXIMIZE_WINDOW);
   134 	_ToBeWin(window)->PostMessage(&msg);
   135 }
   136 
   137 void BE_MinimizeWindow(_THIS, SDL_Window * window) {
   138 	BMessage msg(BWIN_MINIMIZE_WINDOW);
   139 	_ToBeWin(window)->PostMessage(&msg);
   140 }
   141 
   142 void BE_RestoreWindow(_THIS, SDL_Window * window) {
   143 	BMessage msg(BWIN_RESTORE_WINDOW);
   144 	_ToBeWin(window)->PostMessage(&msg);
   145 }
   146 
   147 void BE_SetWindowFullscreen(_THIS, SDL_Window * window,
   148 		SDL_VideoDisplay * display, SDL_bool fullscreen) {
   149 	/* Haiku tracks all video display information */
   150 	BMessage msg(BWIN_FULLSCREEN);
   151 	msg.AddBool("fullscreen", fullscreen);
   152 	_ToBeWin(window)->PostMessage(&msg);
   153 	
   154 }
   155 
   156 int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
   157 	/* FIXME: Not BeOs/Haiku supported */
   158 }
   159 
   160 int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
   161 	/* FIXME: Not BeOs/Haiku supported */
   162 }
   163 
   164 
   165 void BE_SetWindowGrab(_THIS, SDL_Window * window) {
   166 	/* TODO: Implement this! */
   167 }
   168 
   169 void BE_DestroyWindow(_THIS, SDL_Window * window) {
   170 	_ToBeWin(window)->LockLooper();	/* This MUST be locked */
   171 	_GetBeApp()->ClearID(_ToBeWin(window));
   172 	_ToBeWin(window)->Quit();
   173 	window->driverdata = NULL;
   174 }
   175 
   176 SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
   177                                     struct SDL_SysWMinfo *info) {
   178 	/* FIXME: What is the point of this? What information should be included? */
   179 }
   180 
   181 
   182 
   183 
   184  
   185 #ifdef __cplusplus
   186 }
   187 #endif
   188