19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Lesser General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2.1 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lesser General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Lesser General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free Software 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef _SDL_BWin_h 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define _SDL_BWin_h 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h" 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdio.h> 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <AppKit.h> 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <InterfaceKit.h> 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <be/game/DirectWindow.h> 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_opengl.h" 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <be/opengl/GLView.h> 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <support/UTF8.h> 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../main/beos/SDL_BeApp.h" 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_events.h" 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_BView.h" 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern "C" { 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h" 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern int mouse_relative; 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallclass SDL_BWin : public BDirectWindow 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallpublic: 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_BWin(BRect bounds) : 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall BDirectWindow(bounds, "Untitled", B_TITLED_WINDOW, 0) { 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall last_buttons = 0; 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall the_view = NULL; 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GLView = NULL; 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_View = NULL; 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Unlock(); 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall shown = false; 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall inhibit_resize = false; 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual ~SDL_BWin() { 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lock(); 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( the_view ) { 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( the_view == SDL_GLView ) { 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GLView->UnlockGL(); 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall RemoveChild(the_view); 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall the_view = NULL; 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Unlock(); 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_GLView ) { 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall delete SDL_GLView; 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_View ) { 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall delete SDL_View; 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Override the Show() method so we can tell when we've been shown */ 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void Show(void) { 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall BWindow::Show(); 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall shown = true; 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual bool Shown(void) { 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return (shown); 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If called, the next resize event will not be forwarded to SDL. */ 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void InhibitResize(void) { 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall inhibit_resize=true; 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Handle resizing of the window */ 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void FrameResized(float width, float height) { 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(inhibit_resize) 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall inhibit_resize = false; 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateResize((int)width, (int)height); 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual int CreateView(Uint32 flags, Uint32 gl_flags) { 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int retval; 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall retval = 0; 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lock(); 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( flags & SDL_OPENGL ) { 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_GLView == NULL ) { 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GLView = new BGLView(Bounds(), "SDL GLView", 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall B_FOLLOW_ALL_SIDES, (B_WILL_DRAW|B_FRAME_EVENTS), 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall gl_flags|BGL_DOUBLE); 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GLView->EnableDirectMode(true); 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( the_view != SDL_GLView ) { 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( the_view ) { 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall RemoveChild(the_view); 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall AddChild(SDL_GLView); 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GLView->LockGL(); 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall the_view = SDL_GLView; 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("OpenGL support not enabled"); 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall retval = -1; 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_View == NULL ) { 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_View = new SDL_BView(Bounds()); 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( the_view != SDL_View ) { 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( the_view ) { 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall RemoveChild(the_view); 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall AddChild(SDL_View); 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall the_view = SDL_View; 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( the_view == SDL_GLView ) { 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GLView->UnlockGL(); 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Unlock(); 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(retval); 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void SetBitmap(BBitmap *bitmap) { 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_View->SetBitmap(bitmap); 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void SetXYOffset(int x, int y) { 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( the_view == SDL_GLView ) { 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_View->SetXYOffset(x, y); 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void GetXYOffset(int &x, int &y) { 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( the_view == SDL_GLView ) { 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = 0; 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = 0; 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_View->GetXYOffset(x, y); 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void GetXYOffset(float &x, float &y) { 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( the_view == SDL_GLView ) { 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall x = 0.0f; 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall y = 0.0f; 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_View->GetXYOffset(x, y); 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual bool BeginDraw(void) { 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(Lock()); 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void DrawAsync(BRect updateRect) { 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_View->DrawAsync(updateRect); 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void EndDraw(void) { 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_View->Sync(); 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Unlock(); 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void SwapBuffers(void) { 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GLView->UnlockGL(); 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GLView->SwapBuffers(); 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GLView->LockGL(); 1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual BView *View(void) { 2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(the_view); 2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Hook functions -- overridden */ 2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void Minimize(bool minimize) { 2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* This is only called when mimimized, not when restored */ 2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall //SDL_PrivateAppActive(minimize, SDL_APPACTIVE); 2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall BWindow::Minimize(minimize); 2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void WindowActivated(bool active) { 2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateAppActive(active, SDL_APPINPUTFOCUS); 2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual bool QuitRequested(void) { 2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_BeAppActive > 0 ) { 2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateQuit(); 2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We don't ever actually close the window here because 2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall the application should respond to the quit request, 2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall or ignore it as desired. 2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_GLView != NULL ) { 2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_GLView->EnableDirectMode(false); 2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(false); 2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(true); /* Close the app window */ 2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void Quit() { 2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (!IsLocked()) 2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lock(); 2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall BDirectWindow::Quit(); 2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual int16 Translate2Unicode(const char *buf) { 2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int32 state, srclen, dstlen; 2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char destbuf[2]; 2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint16 unicode = 0; 2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ((uchar)buf[0] > 127) { 2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall state = 0; 2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall srclen = SDL_strlen(buf); 2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dstlen = sizeof(destbuf); 2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall convert_from_utf8(B_UNICODE_CONVERSION, buf, &srclen, (char *)destbuf, &dstlen, &state); 2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unicode = destbuf[0]; 2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unicode <<= 8; 2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unicode |= destbuf[1]; 2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unicode = buf[0]; 2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* For some reason function keys map to control characters */ 2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define CTRL(X) ((X)-'@') 2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch (unicode) { 2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case CTRL('A'): 2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case CTRL('B'): 2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case CTRL('C'): 2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case CTRL('D'): 2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case CTRL('E'): 2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case CTRL('K'): 2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case CTRL('L'): 2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case CTRL('P'): 2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! (SDL_GetModState() & KMOD_CTRL) ) 2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unicode = 0; 2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Keyboard input maps newline to carriage return */ 2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case '\n': 2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unicode = '\r'; 2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: 2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return unicode; 2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void DispatchMessage(BMessage *msg, BHandler *target); 2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall virtual void DirectConnected(direct_buffer_info *info); 2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallprivate: 2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if SDL_VIDEO_OPENGL 2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall BGLView *SDL_GLView; 2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_BView *SDL_View; 2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall BView *the_view; 2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool shown; 2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool inhibit_resize; 2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int32 last_buttons; 2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* _SDL_BWin_h */ 291