PageRenderTime 36ms CodeModel.GetById 14ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 1ms

/project/jni/sdl-1.3/src/video/bwindow/SDL_bwindow.cc

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