src/video/haiku/SDL_bwindow.cc
author Sam Lantinga <slouken@libsdl.org>
Mon, 24 Sep 2018 11:49:25 -0700
changeset 12201 8bdc4d340419
parent 12082 09999a0e8f9a
child 12503 806492103856
permissions -rw-r--r--
Fixed whitespace
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) {
slouken@12201
    35
    return ((SDL_BWin*)(window->driverdata));
nathanheisey@5918
    36
}
nathanheisey@5918
    37
slouken@7860
    38
static SDL_INLINE SDL_BApp *_GetBeApp() {
slouken@12201
    39
    return ((SDL_BApp*)be_app);
nathanheisey@5918
    40
}
nathanheisey@5918
    41
nathanheisey@5940
    42
static int _InitWindow(_THIS, SDL_Window *window) {
slouken@12201
    43
    uint32 flags = 0;
slouken@12201
    44
    window_look look = B_TITLED_WINDOW_LOOK;
icculus@6421
    45
slouken@12201
    46
    BRect bounds(
nathanheisey@5918
    47
        window->x,
nathanheisey@5918
    48
        window->y,
slouken@12201
    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) {
slouken@12201
    54
        /* TODO: Add support for this flag */
slouken@12201
    55
        printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__);
nathanheisey@5932
    56
    }
nathanheisey@5932
    57
    if(window->flags & SDL_WINDOW_OPENGL) {
slouken@12201
    58
        /* TODO: Add support for this flag */
nathanheisey@5932
    59
    }
nathanheisey@5932
    60
    if(!(window->flags & SDL_WINDOW_RESIZABLE)) {
slouken@12201
    61
        flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE;
nathanheisey@5932
    62
    }
nathanheisey@5932
    63
    if(window->flags & SDL_WINDOW_BORDERLESS) {
slouken@12201
    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
icculus@12082
    78
int HAIKU_CreateWindow(_THIS, SDL_Window *window) {
philipp@11123
    79
    if (_InitWindow(_this, window) < 0) {
philipp@11123
    80
        return -1;
philipp@11123
    81
    }
slouken@12201
    82
    
slouken@12201
    83
    /* Start window loop */
nathanheisey@5918
    84
    _ToBeWin(window)->Show();
nathanheisey@5918
    85
    return 0;
nathanheisey@5918
    86
}
nathanheisey@5918
    87
icculus@12082
    88
int HAIKU_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) {
nathanheisey@5918
    89
slouken@12201
    90
    SDL_BWin *otherBWin = (SDL_BWin*)data;
slouken@12201
    91
    if(!otherBWin->LockLooper())
slouken@12201
    92
        return -1;
slouken@12201
    93
    
slouken@12201
    94
    /* Create the new window and initialize its members */
slouken@12201
    95
    window->x = (int)otherBWin->Frame().left;
slouken@12201
    96
    window->y = (int)otherBWin->Frame().top;
slouken@12201
    97
    window->w = (int)otherBWin->Frame().Width();
slouken@12201
    98
    window->h = (int)otherBWin->Frame().Height();
slouken@12201
    99
    
slouken@12201
   100
    /* Set SDL flags */
slouken@12201
   101
    if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) {
slouken@12201
   102
        window->flags |= SDL_WINDOW_RESIZABLE;
slouken@12201
   103
    }
slouken@12201
   104
    
slouken@12201
   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
    }
slouken@12201
   109
    
slouken@12201
   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
icculus@12082
   120
void HAIKU_SetWindowTitle(_THIS, SDL_Window * window) {
slouken@12201
   121
    BMessage msg(BWIN_SET_TITLE);
slouken@12201
   122
    msg.AddString("window-title", window->title);
slouken@12201
   123
    _ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   124
}
nathanheisey@5918
   125
icculus@12082
   126
void HAIKU_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) {
slouken@12201
   127
    /* FIXME: Icons not supported by Haiku */
nathanheisey@5918
   128
}
nathanheisey@5918
   129
icculus@12082
   130
void HAIKU_SetWindowPosition(_THIS, SDL_Window * window) {
slouken@12201
   131
    BMessage msg(BWIN_MOVE_WINDOW);
slouken@12201
   132
    msg.AddInt32("window-x", window->x);
slouken@12201
   133
    msg.AddInt32("window-y", window->y);
slouken@12201
   134
    _ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   135
}
nathanheisey@5918
   136
icculus@12082
   137
void HAIKU_SetWindowSize(_THIS, SDL_Window * window) {
slouken@12201
   138
    BMessage msg(BWIN_RESIZE_WINDOW);
slouken@12201
   139
    msg.AddInt32("window-w", window->w - 1);
slouken@12201
   140
    msg.AddInt32("window-h", window->h - 1);
slouken@12201
   141
    _ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   142
}
nathanheisey@5918
   143
icculus@12082
   144
void HAIKU_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered) {
slouken@12201
   145
    BMessage msg(BWIN_SET_BORDERED);
slouken@12201
   146
    msg.AddBool("window-border", bordered != SDL_FALSE);
slouken@12201
   147
    _ToBeWin(window)->PostMessage(&msg);
icculus@6422
   148
}
icculus@6422
   149
icculus@12082
   150
void HAIKU_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable) {
slouken@12201
   151
    BMessage msg(BWIN_SET_RESIZABLE);
slouken@12201
   152
    msg.AddBool("window-resizable", resizable != SDL_FALSE);
slouken@12201
   153
    _ToBeWin(window)->PostMessage(&msg);
icculus@10385
   154
}
icculus@10385
   155
icculus@12082
   156
void HAIKU_ShowWindow(_THIS, SDL_Window * window) {
slouken@12201
   157
    BMessage msg(BWIN_SHOW_WINDOW);
slouken@12201
   158
    _ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   159
}
nathanheisey@5918
   160
icculus@12082
   161
void HAIKU_HideWindow(_THIS, SDL_Window * window) {
slouken@12201
   162
    BMessage msg(BWIN_HIDE_WINDOW);
slouken@12201
   163
    _ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   164
}
nathanheisey@5918
   165
icculus@12082
   166
void HAIKU_RaiseWindow(_THIS, SDL_Window * window) {
slouken@12201
   167
    BMessage msg(BWIN_SHOW_WINDOW);    /* Activate this window and move to front */
slouken@12201
   168
    _ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   169
}
nathanheisey@5918
   170
icculus@12082
   171
void HAIKU_MaximizeWindow(_THIS, SDL_Window * window) {
slouken@12201
   172
    BMessage msg(BWIN_MAXIMIZE_WINDOW);
slouken@12201
   173
    _ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   174
}
nathanheisey@5918
   175
icculus@12082
   176
void HAIKU_MinimizeWindow(_THIS, SDL_Window * window) {
slouken@12201
   177
    BMessage msg(BWIN_MINIMIZE_WINDOW);
slouken@12201
   178
    _ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   179
}
nathanheisey@5918
   180
icculus@12082
   181
void HAIKU_RestoreWindow(_THIS, SDL_Window * window) {
slouken@12201
   182
    BMessage msg(BWIN_RESTORE_WINDOW);
slouken@12201
   183
    _ToBeWin(window)->PostMessage(&msg);
nathanheisey@5918
   184
}
nathanheisey@5918
   185
icculus@12082
   186
void HAIKU_SetWindowFullscreen(_THIS, SDL_Window * window,
slouken@12201
   187
        SDL_VideoDisplay * display, SDL_bool fullscreen) {
slouken@12201
   188
    /* Haiku tracks all video display information */
slouken@12201
   189
    BMessage msg(BWIN_FULLSCREEN);
slouken@12201
   190
    msg.AddBool("fullscreen", fullscreen);
slouken@12201
   191
    _ToBeWin(window)->PostMessage(&msg);
slouken@12201
   192
    
nathanheisey@5918
   193
}
nathanheisey@5918
   194
icculus@12082
   195
int HAIKU_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
slouken@12201
   196
    /* FIXME: Not Haiku supported */
slouken@12201
   197
    return -1;
nathanheisey@5918
   198
}
nathanheisey@5918
   199
icculus@12082
   200
int HAIKU_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
slouken@12201
   201
    /* FIXME: Not Haiku supported */
slouken@12201
   202
    return -1;
nathanheisey@5918
   203
}
nathanheisey@5918
   204
nathanheisey@5918
   205
icculus@12082
   206
void HAIKU_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed) {
slouken@12201
   207
    /* TODO: Implement this! */
nathanheisey@5918
   208
}
nathanheisey@5918
   209
icculus@12082
   210
void HAIKU_DestroyWindow(_THIS, SDL_Window * window) {
slouken@12201
   211
    _ToBeWin(window)->LockLooper();    /* This MUST be locked */
slouken@12201
   212
    _GetBeApp()->ClearID(_ToBeWin(window));
slouken@12201
   213
    _ToBeWin(window)->Quit();
slouken@12201
   214
    window->driverdata = NULL;
nathanheisey@5918
   215
}
nathanheisey@5918
   216
icculus@12082
   217
SDL_bool HAIKU_GetWindowWMInfo(_THIS, SDL_Window * window,
nathanheisey@5918
   218
                                    struct SDL_SysWMinfo *info) {
slouken@12201
   219
    /* FIXME: What is the point of this? What information should be included? */
slouken@12201
   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: */