src/video/haiku/SDL_bwindow.cc
author Sam Lantinga <slouken@libsdl.org>
Wed, 03 Jan 2018 10:03:25 -0800
changeset 11811 5d94cb6b24d3
parent 11123 93de4d56b1b8
child 12082 09999a0e8f9a
permissions -rw-r--r--
Updated copyright for 2018
nathanheisey@5918
     1
/*
nathanheisey@5918
     2
  Simple DirectMedia Layer
slouken@11811
     3
  Copyright (C) 1997-2018 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
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@6044
    22
icculus@7981
    23
#if SDL_VIDEO_DRIVER_HAIKU
nathanheisey@5918
    24
#include "../SDL_sysvideo.h"
nathanheisey@5918
    25
nathanheisey@5918
    26
#include "SDL_BWin.h"
nathanheisey@5918
    27
#include <new>
nathanheisey@5918
    28
nathanheisey@5918
    29
/* Define a path to window's BWIN data */
nathanheisey@5918
    30
#ifdef __cplusplus
nathanheisey@5918
    31
extern "C" {
nathanheisey@5918
    32
#endif
nathanheisey@5918
    33
slouken@7860
    34
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
nathanheisey@5918
    35
	return ((SDL_BWin*)(window->driverdata));
nathanheisey@5918
    36
}
nathanheisey@5918
    37
slouken@7860
    38
static SDL_INLINE SDL_BApp *_GetBeApp() {
nathanheisey@5918
    39
	return ((SDL_BApp*)be_app);
nathanheisey@5918
    40
}
nathanheisey@5918
    41
nathanheisey@5940
    42
static int _InitWindow(_THIS, SDL_Window *window) {
nathanheisey@5932
    43
	uint32 flags = 0;
philipp@11062
    44
	window_look look = B_TITLED_WINDOW_LOOK;
icculus@6421
    45
nathanheisey@5918
    46
	BRect bounds(
nathanheisey@5918
    47
        window->x,
nathanheisey@5918
    48
        window->y,
nathanheisey@5918
    49
        window->x + window->w - 1,	//BeWindows have an off-by-one px w/h thing
nathanheisey@5918
    50
        window->y + window->h - 1
nathanheisey@5918
    51
    );
nathanheisey@5932
    52
    
nathanheisey@5932
    53
    if(window->flags & SDL_WINDOW_FULLSCREEN) {
nathanheisey@5939
    54
    	/* TODO: Add support for this flag */
nathanheisey@5939
    55
    	printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__);
nathanheisey@5932
    56
    }
nathanheisey@5932
    57
    if(window->flags & SDL_WINDOW_OPENGL) {
nathanheisey@5939
    58
    	/* TODO: Add support for this flag */
nathanheisey@5932
    59
    }
nathanheisey@5932
    60
    if(!(window->flags & SDL_WINDOW_RESIZABLE)) {
nathanheisey@5937
    61
    	flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE;
nathanheisey@5932
    62
    }
nathanheisey@5932
    63
    if(window->flags & SDL_WINDOW_BORDERLESS) {
icculus@6421
    64
    	look = B_NO_BORDER_WINDOW_LOOK;
nathanheisey@5932
    65
    }
nathanheisey@5925
    66
icculus@6421
    67
    SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, look, flags);
nathanheisey@5918
    68
    if(bwin == NULL)
philipp@11123
    69
        return -1;
nathanheisey@5925
    70
nathanheisey@5918
    71
    window->driverdata = bwin;
nathanheisey@5918
    72
    int32 winID = _GetBeApp()->GetID(window);
nathanheisey@5918
    73
    bwin->SetID(winID);
nathanheisey@5932
    74
nathanheisey@5918
    75
    return 0;
nathanheisey@5918
    76
}
nathanheisey@5918
    77
nathanheisey@5925
    78
int BE_CreateWindow(_THIS, SDL_Window *window) {
philipp@11123
    79
    if (_InitWindow(_this, window) < 0) {
philipp@11123
    80
        return -1;
philipp@11123
    81
    }
nathanheisey@5918
    82
	
nathanheisey@5918
    83
	/* Start window loop */
nathanheisey@5918
    84
    _ToBeWin(window)->Show();
nathanheisey@5918
    85
    return 0;
nathanheisey@5918
    86
}
nathanheisey@5918
    87
nathanheisey@5918
    88
int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) {
nathanheisey@5918
    89
nathanheisey@5918
    90
	SDL_BWin *otherBWin = (SDL_BWin*)data;
nathanheisey@5918
    91
	if(!otherBWin->LockLooper())
nathanheisey@5918
    92
		return -1;
nathanheisey@5918
    93
	
nathanheisey@5918
    94
	/* Create the new window and initialize its members */
nathanheisey@5918
    95
	window->x = (int)otherBWin->Frame().left;
nathanheisey@5918
    96
	window->y = (int)otherBWin->Frame().top;
nathanheisey@5918
    97
	window->w = (int)otherBWin->Frame().Width();
nathanheisey@5918
    98
	window->h = (int)otherBWin->Frame().Height();
nathanheisey@5918
    99
	
nathanheisey@5932
   100
	/* Set SDL flags */
nathanheisey@5932
   101
	if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) {
nathanheisey@5932
   102
		window->flags |= SDL_WINDOW_RESIZABLE;
nathanheisey@5932
   103
	}
nathanheisey@5932
   104
	
nathanheisey@5918
   105
	/* If we are out of memory, return the error code */
philipp@11123
   106
    if (_InitWindow(_this, window) < 0) {
philipp@11123
   107
        return -1;
philipp@11123
   108
    }
nathanheisey@5918
   109
	
nathanheisey@5918
   110
	/* TODO: Add any other SDL-supported window attributes here */
nathanheisey@5918
   111
    _ToBeWin(window)->SetTitle(otherBWin->Title());
nathanheisey@5918
   112
    
nathanheisey@5918
   113
    /* Start window loop and unlock the other window */
nathanheisey@5918
   114
    _ToBeWin(window)->Show();
nathanheisey@5918
   115
    
nathanheisey@5918
   116
    otherBWin->UnlockLooper();
nathanheisey@5918
   117
    return 0;
nathanheisey@5918
   118
}
nathanheisey@5918
   119
nathanheisey@5918
   120
void BE_SetWindowTitle(_THIS, SDL_Window * window) {
nathanheisey@5918
   121
	BMessage msg(BWIN_SET_TITLE);
nathanheisey@5918
   122
	msg.AddString("window-title", window->title);
nathanheisey@5918
   123
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   124
}
nathanheisey@5918
   125
nathanheisey@5918
   126
void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) {
icculus@7981
   127
	/* FIXME: Icons not supported by Haiku */
nathanheisey@5918
   128
}
nathanheisey@5918
   129
nathanheisey@5918
   130
void BE_SetWindowPosition(_THIS, SDL_Window * window) {
nathanheisey@5918
   131
	BMessage msg(BWIN_MOVE_WINDOW);
nathanheisey@5918
   132
	msg.AddInt32("window-x", window->x);
nathanheisey@5918
   133
	msg.AddInt32("window-y", window->y);
nathanheisey@5918
   134
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   135
}
nathanheisey@5918
   136
nathanheisey@5918
   137
void BE_SetWindowSize(_THIS, SDL_Window * window) {
nathanheisey@5918
   138
	BMessage msg(BWIN_RESIZE_WINDOW);
nathanheisey@5918
   139
	msg.AddInt32("window-w", window->w - 1);
nathanheisey@5918
   140
	msg.AddInt32("window-h", window->h - 1);
nathanheisey@5918
   141
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   142
}
nathanheisey@5918
   143
icculus@6422
   144
void BE_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered) {
icculus@6422
   145
	BMessage msg(BWIN_SET_BORDERED);
icculus@6422
   146
	msg.AddBool("window-border", bordered != SDL_FALSE);
icculus@6422
   147
	_ToBeWin(window)->PostMessage(&msg);
icculus@6422
   148
}
icculus@6422
   149
icculus@10385
   150
void BE_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable) {
icculus@10385
   151
	BMessage msg(BWIN_SET_RESIZABLE);
icculus@10385
   152
	msg.AddBool("window-resizable", resizable != SDL_FALSE);
icculus@10385
   153
	_ToBeWin(window)->PostMessage(&msg);
icculus@10385
   154
}
icculus@10385
   155
nathanheisey@5918
   156
void BE_ShowWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   157
	BMessage msg(BWIN_SHOW_WINDOW);
nathanheisey@5918
   158
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   159
}
nathanheisey@5918
   160
nathanheisey@5918
   161
void BE_HideWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   162
	BMessage msg(BWIN_HIDE_WINDOW);
nathanheisey@5918
   163
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   164
}
nathanheisey@5918
   165
nathanheisey@5918
   166
void BE_RaiseWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   167
	BMessage msg(BWIN_SHOW_WINDOW);	/* Activate this window and move to front */
nathanheisey@5918
   168
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   169
}
nathanheisey@5918
   170
nathanheisey@5918
   171
void BE_MaximizeWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   172
	BMessage msg(BWIN_MAXIMIZE_WINDOW);
nathanheisey@5918
   173
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   174
}
nathanheisey@5918
   175
nathanheisey@5918
   176
void BE_MinimizeWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   177
	BMessage msg(BWIN_MINIMIZE_WINDOW);
nathanheisey@5918
   178
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   179
}
nathanheisey@5918
   180
nathanheisey@5918
   181
void BE_RestoreWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   182
	BMessage msg(BWIN_RESTORE_WINDOW);
nathanheisey@5918
   183
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   184
}
nathanheisey@5918
   185
nathanheisey@5918
   186
void BE_SetWindowFullscreen(_THIS, SDL_Window * window,
nathanheisey@5918
   187
		SDL_VideoDisplay * display, SDL_bool fullscreen) {
nathanheisey@5918
   188
	/* Haiku tracks all video display information */
nathanheisey@5918
   189
	BMessage msg(BWIN_FULLSCREEN);
nathanheisey@5918
   190
	msg.AddBool("fullscreen", fullscreen);
nathanheisey@5918
   191
	_ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   192
	
nathanheisey@5918
   193
}
nathanheisey@5918
   194
nathanheisey@5918
   195
int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
icculus@7981
   196
	/* FIXME: Not Haiku supported */
nathanheisey@5939
   197
	return -1;
nathanheisey@5918
   198
}
nathanheisey@5918
   199
nathanheisey@5918
   200
int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
icculus@7981
   201
	/* FIXME: Not Haiku supported */
nathanheisey@5939
   202
	return -1;
nathanheisey@5918
   203
}
nathanheisey@5918
   204
nathanheisey@5918
   205
slouken@6662
   206
void BE_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed) {
nathanheisey@5918
   207
	/* TODO: Implement this! */
nathanheisey@5918
   208
}
nathanheisey@5918
   209
nathanheisey@5918
   210
void BE_DestroyWindow(_THIS, SDL_Window * window) {
nathanheisey@5918
   211
	_ToBeWin(window)->LockLooper();	/* This MUST be locked */
nathanheisey@5918
   212
	_GetBeApp()->ClearID(_ToBeWin(window));
nathanheisey@5918
   213
	_ToBeWin(window)->Quit();
nathanheisey@5918
   214
	window->driverdata = NULL;
nathanheisey@5918
   215
}
nathanheisey@5918
   216
nathanheisey@5918
   217
SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
nathanheisey@5918
   218
                                    struct SDL_SysWMinfo *info) {
nathanheisey@5918
   219
	/* FIXME: What is the point of this? What information should be included? */
nathanheisey@5939
   220
	return SDL_FALSE;
nathanheisey@5918
   221
}
nathanheisey@5918
   222
nathanheisey@5918
   223
nathanheisey@5921
   224
nathanheisey@5918
   225
nathanheisey@5918
   226
 
nathanheisey@5918
   227
#ifdef __cplusplus
nathanheisey@5918
   228
}
nathanheisey@5918
   229
#endif
nathanheisey@5918
   230
icculus@7981
   231
#endif /* SDL_VIDEO_DRIVER_HAIKU */
slouken@10690
   232
slouken@10690
   233
/* vi: set ts=4 sw=4 expandtab: */