src/video/bwindow/SDL_bwindow.cc
author Nathan Heisey <nathanheisey@gmail.com>
Wed, 20 Jul 2011 19:25:38 +0000
changeset 5921 4cec9ba57dfb
parent 5918 2063df37190b
child 5922 efd1498efdff
permissions -rw-r--r--
Framebuffer support in progress.
nathanheisey@5918
     1
/*
nathanheisey@5918
     2
  Simple DirectMedia Layer
nathanheisey@5918
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
nathanheisey@5918
     4
nathanheisey@5918
     5
  This software is provided 'as-is', without any express or implied
nathanheisey@5918
     6
  warranty.  In no event will the authors be held liable for any damages
nathanheisey@5918
     7
  arising from the use of this software.
nathanheisey@5918
     8
nathanheisey@5918
     9
  Permission is granted to anyone to use this software for any purpose,
nathanheisey@5918
    10
  including commercial applications, and to alter it and redistribute it
nathanheisey@5918
    11
  freely, subject to the following restrictions:
nathanheisey@5918
    12
nathanheisey@5918
    13
  1. The origin of this software must not be misrepresented; you must not
nathanheisey@5918
    14
     claim that you wrote the original software. If you use this software
nathanheisey@5918
    15
     in a product, an acknowledgment in the product documentation would be
nathanheisey@5918
    16
     appreciated but is not required.
nathanheisey@5918
    17
  2. Altered source versions must be plainly marked as such, and must not be
nathanheisey@5918
    18
     misrepresented as being the original software.
nathanheisey@5918
    19
  3. This notice may not be removed or altered from any source distribution.
nathanheisey@5918
    20
*/
nathanheisey@5918
    21
#include "SDL_config.h"
nathanheisey@5918
    22
#include "../SDL_sysvideo.h"
nathanheisey@5918
    23
nathanheisey@5918
    24
#include "SDL_BWin.h"
nathanheisey@5918
    25
#include <new>
nathanheisey@5918
    26
nathanheisey@5918
    27
/* Define a path to window's BWIN data */
nathanheisey@5918
    28
#ifdef __cplusplus
nathanheisey@5918
    29
extern "C" {
nathanheisey@5918
    30
#endif
nathanheisey@5918
    31
nathanheisey@5918
    32
static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
nathanheisey@5918
    33
	return ((SDL_BWin*)(window->driverdata));
nathanheisey@5918
    34
}
nathanheisey@5918
    35
nathanheisey@5918
    36
static inline SDL_BApp *_GetBeApp() {
nathanheisey@5918
    37
	return ((SDL_BApp*)be_app);
nathanheisey@5918
    38
}
nathanheisey@5918
    39
nathanheisey@5921
    40
int _InitWindow(_THIS, SDL_Window *window) {printf("SDL_bwindow.cc: 40\n");
nathanheisey@5918
    41
	BRect bounds(
nathanheisey@5918
    42
        window->x,
nathanheisey@5918
    43
        window->y,
nathanheisey@5918
    44
        window->x + window->w - 1,	//BeWindows have an off-by-one px w/h thing
nathanheisey@5918
    45
        window->y + window->h - 1
nathanheisey@5918
    46
    );
nathanheisey@5921
    47
printf("SDL_bwindow.cc: 30\n");
nathanheisey@5918
    48
    SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds);
nathanheisey@5918
    49
    if(bwin == NULL)
nathanheisey@5918
    50
    	return ENOMEM;
nathanheisey@5921
    51
printf("SDL_bwindow.cc: 51\n");
nathanheisey@5918
    52
    window->driverdata = bwin;
nathanheisey@5918
    53
    int32 winID = _GetBeApp()->GetID(window);
nathanheisey@5918
    54
    bwin->SetID(winID);
nathanheisey@5918
    55
    return 0;
nathanheisey@5918
    56
}
nathanheisey@5918
    57
nathanheisey@5921
    58
int BE_CreateWindow(_THIS, SDL_Window *window) {printf("SDL_bwindow.cc: 58\n");
nathanheisey@5918
    59
	if(_InitWindow(_this, window) == ENOMEM)
nathanheisey@5918
    60
		return ENOMEM;
nathanheisey@5918
    61
	
nathanheisey@5918
    62
	/* Start window loop */
nathanheisey@5918
    63
    _ToBeWin(window)->Show();
nathanheisey@5918
    64
    return 0;
nathanheisey@5918
    65
}
nathanheisey@5918
    66
nathanheisey@5918
    67
int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) {
nathanheisey@5918
    68
nathanheisey@5918
    69
	SDL_BWin *otherBWin = (SDL_BWin*)data;
nathanheisey@5918
    70
	if(!otherBWin->LockLooper())
nathanheisey@5918
    71
		return -1;
nathanheisey@5918
    72
	
nathanheisey@5918
    73
	/* Create the new window and initialize its members */
nathanheisey@5918
    74
	window->x = (int)otherBWin->Frame().left;
nathanheisey@5918
    75
	window->y = (int)otherBWin->Frame().top;
nathanheisey@5918
    76
	window->w = (int)otherBWin->Frame().Width();
nathanheisey@5918
    77
	window->h = (int)otherBWin->Frame().Height();
nathanheisey@5918
    78
	
nathanheisey@5918
    79
	/* If we are out of memory, return the error code */
nathanheisey@5918
    80
	if(_InitWindow(_this, window) == ENOMEM)
nathanheisey@5918
    81
		return ENOMEM;
nathanheisey@5918
    82
	
nathanheisey@5918
    83
	/* TODO: Add any other SDL-supported window attributes here */
nathanheisey@5918
    84
    _ToBeWin(window)->SetTitle(otherBWin->Title());
nathanheisey@5918
    85
    
nathanheisey@5918
    86
    /* Start window loop and unlock the other window */
nathanheisey@5918
    87
    _ToBeWin(window)->Show();
nathanheisey@5918
    88
    
nathanheisey@5918
    89
    otherBWin->UnlockLooper();
nathanheisey@5918
    90
    return 0;
nathanheisey@5918
    91
}
nathanheisey@5918
    92
nathanheisey@5918
    93
void BE_SetWindowTitle(_THIS, SDL_Window * window) {
nathanheisey@5918
    94
	BMessage msg(BWIN_SET_TITLE);
nathanheisey@5918
    95
	msg.AddString("window-title", window->title);
nathanheisey@5918
    96
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
    97
}
nathanheisey@5918
    98
nathanheisey@5918
    99
void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) {
nathanheisey@5918
   100
	/* FIXME: Icons not supported by BeOs/Haiku */
nathanheisey@5918
   101
}
nathanheisey@5918
   102
nathanheisey@5918
   103
void BE_SetWindowPosition(_THIS, SDL_Window * window) {
nathanheisey@5918
   104
	BMessage msg(BWIN_MOVE_WINDOW);
nathanheisey@5918
   105
	msg.AddInt32("window-x", window->x);
nathanheisey@5918
   106
	msg.AddInt32("window-y", window->y);
nathanheisey@5918
   107
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   108
}
nathanheisey@5918
   109
nathanheisey@5918
   110
void BE_SetWindowSize(_THIS, SDL_Window * window) {
nathanheisey@5918
   111
	BMessage msg(BWIN_RESIZE_WINDOW);
nathanheisey@5918
   112
	msg.AddInt32("window-w", window->w - 1);
nathanheisey@5918
   113
	msg.AddInt32("window-h", window->h - 1);
nathanheisey@5918
   114
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   115
}
nathanheisey@5918
   116
nathanheisey@5918
   117
void BE_ShowWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   118
	BMessage msg(BWIN_SHOW_WINDOW);
nathanheisey@5918
   119
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   120
}
nathanheisey@5918
   121
nathanheisey@5918
   122
void BE_HideWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   123
	BMessage msg(BWIN_HIDE_WINDOW);
nathanheisey@5918
   124
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   125
}
nathanheisey@5918
   126
nathanheisey@5918
   127
void BE_RaiseWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   128
	BMessage msg(BWIN_SHOW_WINDOW);	/* Activate this window and move to front */
nathanheisey@5918
   129
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   130
}
nathanheisey@5918
   131
nathanheisey@5918
   132
void BE_MaximizeWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   133
	BMessage msg(BWIN_MAXIMIZE_WINDOW);
nathanheisey@5918
   134
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   135
}
nathanheisey@5918
   136
nathanheisey@5918
   137
void BE_MinimizeWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   138
	BMessage msg(BWIN_MINIMIZE_WINDOW);
nathanheisey@5918
   139
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   140
}
nathanheisey@5918
   141
nathanheisey@5918
   142
void BE_RestoreWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   143
	BMessage msg(BWIN_RESTORE_WINDOW);
nathanheisey@5918
   144
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   145
}
nathanheisey@5918
   146
nathanheisey@5918
   147
void BE_SetWindowFullscreen(_THIS, SDL_Window * window,
nathanheisey@5918
   148
		SDL_VideoDisplay * display, SDL_bool fullscreen) {
nathanheisey@5918
   149
	/* Haiku tracks all video display information */
nathanheisey@5918
   150
	BMessage msg(BWIN_FULLSCREEN);
nathanheisey@5918
   151
	msg.AddBool("fullscreen", fullscreen);
nathanheisey@5918
   152
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   153
	
nathanheisey@5918
   154
}
nathanheisey@5918
   155
nathanheisey@5918
   156
int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
nathanheisey@5918
   157
	/* FIXME: Not BeOs/Haiku supported */
nathanheisey@5918
   158
}
nathanheisey@5918
   159
nathanheisey@5918
   160
int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
nathanheisey@5918
   161
	/* FIXME: Not BeOs/Haiku supported */
nathanheisey@5918
   162
}
nathanheisey@5918
   163
nathanheisey@5918
   164
nathanheisey@5918
   165
void BE_SetWindowGrab(_THIS, SDL_Window * window) {
nathanheisey@5918
   166
	/* TODO: Implement this! */
nathanheisey@5918
   167
}
nathanheisey@5918
   168
nathanheisey@5918
   169
void BE_DestroyWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   170
	_ToBeWin(window)->LockLooper();	/* This MUST be locked */
nathanheisey@5918
   171
	_GetBeApp()->ClearID(_ToBeWin(window));
nathanheisey@5918
   172
	_ToBeWin(window)->Quit();
nathanheisey@5918
   173
	window->driverdata = NULL;
nathanheisey@5918
   174
}
nathanheisey@5918
   175
nathanheisey@5918
   176
SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
nathanheisey@5918
   177
                                    struct SDL_SysWMinfo *info) {
nathanheisey@5918
   178
	/* FIXME: What is the point of this? What information should be included? */
nathanheisey@5918
   179
}
nathanheisey@5918
   180
nathanheisey@5918
   181
nathanheisey@5921
   182
nathanheisey@5921
   183
int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
nathanheisey@5918
   184
                                       Uint32 * format,
nathanheisey@5918
   185
                                       void ** pixels, int *pitch) {
nathanheisey@5921
   186
	/* pitch = width of screen, in bytes */
nathanheisey@5921
   187
	BScreen bscreen;
nathanheisey@5921
   188
	*pitch = (bscreen->Frame().right - bscreen->Frame().left + 1) *	/*screen w*/
nathanheisey@5921
   189
			 SDL_BYTESPERPIXEL(*format);
nathanheisey@5921
   190
nathanheisey@5921
   191
	/* FIXME: FINISH! */
nathanheisey@5918
   192
	return -1;
nathanheisey@5918
   193
}
nathanheisey@5918
   194
nathanheisey@5921
   195
int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
nathanheisey@5918
   196
                                       SDL_Rect * rects, int numrects) {
nathanheisey@5921
   197
	
nathanheisey@5918
   198
	return -1;
nathanheisey@5918
   199
}
nathanheisey@5918
   200
nathanheisey@5921
   201
void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) {
nathanheisey@5921
   202
	/* FIXME: FINISH! */
nathanheisey@5918
   203
}
nathanheisey@5918
   204
nathanheisey@5918
   205
 
nathanheisey@5918
   206
#ifdef __cplusplus
nathanheisey@5918
   207
}
nathanheisey@5918
   208
#endif
nathanheisey@5918
   209