2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "SDL_config.h"
30 #include <InterfaceKit.h>
31 #include <be/game/DirectWindow.h>
33 #include <be/opengl/GLView.h>
35 #include <support/UTF8.h>
37 #include "../../main/beos/SDL_BeApp.h"
38 #include "SDL_events.h"
39 #include "SDL_BView.h"
42 #include "../../events/SDL_events_c.h"
44 extern int mouse_relative;
47 class SDL_BWin : public BDirectWindow
50 SDL_BWin(BRect bounds) :
51 BDirectWindow(bounds, "Untitled", B_TITLED_WINDOW, 0) {
60 inhibit_resize = false;
67 if ( the_view == SDL_GLView ) {
68 SDL_GLView->UnlockGL();
71 RemoveChild(the_view);
86 /* Override the Show() method so we can tell when we've been shown */
87 virtual void Show(void) {
91 virtual bool Shown(void) {
94 /* If called, the next resize event will not be forwarded to SDL. */
95 virtual void InhibitResize(void) {
98 /* Handle resizing of the window */
99 virtual void FrameResized(float width, float height) {
101 inhibit_resize = false;
103 SDL_PrivateResize((int)width, (int)height);
105 virtual int CreateView(Uint32 flags, Uint32 gl_flags) {
110 if ( flags & SDL_OPENGL ) {
112 if ( SDL_GLView == NULL ) {
113 SDL_GLView = new BGLView(Bounds(), "SDL GLView",
114 B_FOLLOW_ALL_SIDES, (B_WILL_DRAW|B_FRAME_EVENTS),
116 SDL_GLView->EnableDirectMode(true);
118 if ( the_view != SDL_GLView ) {
120 RemoveChild(the_view);
122 AddChild(SDL_GLView);
123 SDL_GLView->LockGL();
124 the_view = SDL_GLView;
127 SDL_SetError("OpenGL support not enabled");
131 if ( SDL_View == NULL ) {
132 SDL_View = new SDL_BView(Bounds());
134 if ( the_view != SDL_View ) {
137 if ( the_view == SDL_GLView ) {
138 SDL_GLView->UnlockGL();
141 RemoveChild(the_view);
150 virtual void SetBitmap(BBitmap *bitmap) {
151 SDL_View->SetBitmap(bitmap);
153 virtual void SetXYOffset(int x, int y) {
155 if ( the_view == SDL_GLView ) {
159 SDL_View->SetXYOffset(x, y);
161 virtual void GetXYOffset(int &x, int &y) {
163 if ( the_view == SDL_GLView ) {
169 SDL_View->GetXYOffset(x, y);
171 virtual void GetXYOffset(float &x, float &y) {
173 if ( the_view == SDL_GLView ) {
179 SDL_View->GetXYOffset(x, y);
181 virtual bool BeginDraw(void) {
184 virtual void DrawAsync(BRect updateRect) {
185 SDL_View->DrawAsync(updateRect);
187 virtual void EndDraw(void) {
192 virtual void SwapBuffers(void) {
193 SDL_GLView->UnlockGL();
194 SDL_GLView->LockGL();
195 SDL_GLView->SwapBuffers();
198 virtual BView *View(void) {
202 /* Hook functions -- overridden */
203 virtual void Minimize(bool minimize) {
204 /* This is only called when mimimized, not when restored */
205 //SDL_PrivateAppActive(minimize, SDL_APPACTIVE);
206 BWindow::Minimize(minimize);
208 virtual void WindowActivated(bool active) {
209 SDL_PrivateAppActive(active, SDL_APPINPUTFOCUS);
211 virtual bool QuitRequested(void) {
212 if ( SDL_BeAppActive > 0 ) {
214 /* We don't ever actually close the window here because
215 the application should respond to the quit request,
216 or ignore it as desired.
220 return(true); /* Close the app window */
222 virtual void Quit() {
225 BDirectWindow::Quit();
228 virtual int16 Translate2Unicode(const char *buf) {
229 int32 state, srclen, dstlen;
230 unsigned char destbuf[2];
233 if ((uchar)buf[0] > 127) {
235 srclen = SDL_strlen(buf);
236 dstlen = sizeof(destbuf);
237 convert_from_utf8(B_UNICODE_CONVERSION, buf, &srclen, (char *)destbuf, &dstlen, &state);
238 unicode = destbuf[0];
240 unicode |= destbuf[1];
244 /* For some reason function keys map to control characters */
245 # define CTRL(X) ((X)-'@')
255 if ( ! (SDL_GetModState() & KMOD_CTRL) )
258 /* Keyboard input maps newline to carriage return */
269 virtual void DispatchMessage(BMessage *msg, BHandler *target);
271 virtual void DirectConnected(direct_buffer_info *info);
284 #endif /* _SDL_BWin_h */