src/video/bwindow/SDL_BWin.h

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. SDL_BWin
  2. Show
  3. Shown
  4. InhibitResize
  5. FrameResized
  6. CreateView
  7. SetBitmap
  8. SetXYOffset
  9. BeginDraw
  10. DrawAsync
  11. EndDraw
  12. SwapBuffers
  13. View
  14. Minimize
  15. WindowActivated
  16. QuitRequested

   1 /*
   2     SDL - Simple DirectMedia Layer
   3     Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
   4 
   5     This library is free software; you can redistribute it and/or
   6     modify it under the terms of the GNU Library General Public
   7     License as published by the Free Software Foundation; either
   8     version 2 of the License, or (at your option) any later version.
   9 
  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     Library General Public License for more details.
  14 
  15     You should have received a copy of the GNU Library General Public
  16     License along with this library; if not, write to the Free
  17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18 
  19     Sam Lantinga
  20     slouken@devolution.com
  21 */
  22 
  23 #ifdef SAVE_RCSID
  24 static char rcsid =
  25  "@(#) $Id: SDL_BWin.h,v 1.2.2.7 2001/02/10 07:20:05 hercules Exp $";
  26 #endif
  27 
  28 #ifndef _SDL_BWin_h
  29 #define _SDL_BWin_h
  30 
  31 #include <stdio.h>
  32 #include <AppKit.h>
  33 #include <InterfaceKit.h>
  34 #include <be/game/DirectWindow.h>
  35 #ifdef HAVE_OPENGL
  36 #include <be/opengl/GLView.h>
  37 #endif
  38 
  39 #include "SDL_BeApp.h"
  40 #include "SDL_events.h"
  41 #include "SDL_BView.h"
  42 
  43 extern "C" {
  44 #include "SDL_events_c.h"
  45 };
  46 
  47 class SDL_BWin : public BDirectWindow
     /* [<][>][^][v][top][bottom][index][help] */
  48 {
  49 public:
  50         SDL_BWin(BRect bounds) :
  51                         BDirectWindow(bounds, "Untitled", B_TITLED_WINDOW, 0) {
  52                 the_view = NULL;
  53 #ifdef HAVE_OPENGL
  54                 SDL_GLView = NULL;
  55 #endif
  56                 SDL_View = NULL;
  57                 Unlock();
  58                 shown = false;
  59                 inhibit_resize = false;
  60         }
  61         virtual ~SDL_BWin() {
  62                 Lock();
  63                 if ( the_view ) {
  64 #ifdef HAVE_OPENGL
  65                         if ( the_view == SDL_GLView ) {
  66                                 SDL_GLView->UnlockGL();
  67                         }
  68 #endif
  69                         RemoveChild(the_view);
  70                         the_view = NULL;
  71                 }
  72                 Unlock();
  73 #ifdef HAVE_OPENGL
  74                 if ( SDL_GLView ) {
  75                         delete SDL_GLView;
  76                 }
  77 #endif
  78                 if ( SDL_View ) {
  79                         delete SDL_View;
  80                 }
  81         }
  82 
  83         /* Override the Show() method so we can tell when we've been shown */
  84         virtual void Show(void) {
     /* [<][>][^][v][top][bottom][index][help] */
  85                 BWindow::Show();
  86                 shown = true;
  87         }
  88         virtual bool Shown(void) {
     /* [<][>][^][v][top][bottom][index][help] */
  89                 return (shown);
  90         }
  91         /* If called, the next resize event will not be forwarded to SDL. */
  92         virtual void InhibitResize(void) {
     /* [<][>][^][v][top][bottom][index][help] */
  93                 inhibit_resize=true;
  94         }
  95         /* Handle resizing of the window */
  96         virtual void FrameResized(float width, float height) {
     /* [<][>][^][v][top][bottom][index][help] */
  97                 if(inhibit_resize)
  98                         inhibit_resize = false;
  99                 else 
 100                         SDL_PrivateResize((int)width, (int)height);
 101         }
 102         virtual int CreateView(Uint32 flags) {
     /* [<][>][^][v][top][bottom][index][help] */
 103                 int retval;
 104 
 105                 retval = 0;
 106                 Lock();
 107                 if ( flags & SDL_OPENGL ) {
 108 #ifdef HAVE_OPENGL
 109                         if ( SDL_GLView == NULL ) {
 110                                 /* FIXME: choose BGL type via user flags */
 111                                 SDL_GLView = new BGLView(Bounds(), "SDL GLView",
 112                                                 B_FOLLOW_ALL_SIDES,
 113                                                 (B_WILL_DRAW|B_FRAME_EVENTS),
 114                                                 (BGL_RGB|BGL_DOUBLE|BGL_DEPTH));
 115                         }
 116                         if ( the_view != SDL_GLView ) {
 117                                 if ( the_view ) {
 118                                         RemoveChild(the_view);
 119                                 }
 120                                 AddChild(SDL_GLView);
 121                                 SDL_GLView->LockGL();
 122                                 the_view = SDL_GLView;
 123                         }
 124 #else
 125                         SDL_SetError("OpenGL support not enabled");
 126                         retval = -1;
 127 #endif
 128                 } else {
 129                         if ( SDL_View == NULL ) {
 130                                 SDL_View = new SDL_BView(Bounds());
 131                         }
 132                         if ( the_view != SDL_View ) {
 133                                 if ( the_view ) {
 134 #ifdef HAVE_OPENGL
 135                                         if ( the_view == SDL_GLView ) {
 136                                                 SDL_GLView->UnlockGL();
 137                                         }
 138 #endif
 139                                         RemoveChild(the_view);
 140                                 }
 141                                 AddChild(SDL_View);
 142                                 the_view = SDL_View;
 143                         }
 144                 }
 145                 Unlock();
 146                 return(retval);
 147         }
 148         virtual void SetBitmap(BBitmap *bitmap) {
     /* [<][>][^][v][top][bottom][index][help] */
 149                 SDL_View->SetBitmap(bitmap);
 150         }
 151         virtual void SetXYOffset(int x, int y) {
     /* [<][>][^][v][top][bottom][index][help] */
 152 #ifdef HAVE_OPENGL
 153                 if ( the_view == SDL_GLView ) {
 154                         return;
 155                 }
 156 #endif
 157                 SDL_View->SetXYOffset(x, y);            
 158         }
 159         virtual bool BeginDraw(void) {
     /* [<][>][^][v][top][bottom][index][help] */
 160                 return(Lock());
 161         }
 162         virtual void DrawAsync(BRect updateRect) {
     /* [<][>][^][v][top][bottom][index][help] */
 163                 SDL_View->DrawAsync(updateRect);
 164         }
 165         virtual void EndDraw(void) {
     /* [<][>][^][v][top][bottom][index][help] */
 166                 SDL_View->Sync();
 167                 Unlock();
 168         }
 169 #ifdef HAVE_OPENGL
 170         virtual void SwapBuffers(void) {
     /* [<][>][^][v][top][bottom][index][help] */
 171                 SDL_GLView->UnlockGL();
 172                 SDL_GLView->LockGL();
 173                 SDL_GLView->SwapBuffers();
 174         }
 175 #endif
 176         virtual BView *View(void) {
     /* [<][>][^][v][top][bottom][index][help] */
 177                 return(the_view);
 178         }
 179 
 180         /* Hook functions -- overridden */
 181         virtual void Minimize(bool minimize) {
     /* [<][>][^][v][top][bottom][index][help] */
 182                 /* This is only called when mimimized, not when restored */
 183                 //SDL_PrivateAppActive(minimize, SDL_APPACTIVE);
 184                 BWindow::Minimize(minimize);
 185         }
 186         virtual void WindowActivated(bool active) {
     /* [<][>][^][v][top][bottom][index][help] */
 187                 SDL_PrivateAppActive(active, SDL_APPINPUTFOCUS);
 188         }
 189         virtual bool QuitRequested(void) {
     /* [<][>][^][v][top][bottom][index][help] */
 190                 if ( SDL_BeAppActive > 0 ) {
 191                         SDL_PrivateQuit();
 192                         /* We don't ever actually close the window here because
 193                            the application should respond to the quit request,
 194                            or ignore it as desired.
 195                          */
 196                         return(false);
 197                 }
 198                 return(true);   /* Close the app window */
 199         }
 200 
 201 private:
 202 #ifdef HAVE_OPENGL
 203         BGLView *SDL_GLView;
 204 #endif
 205         SDL_BView *SDL_View;
 206         BView *the_view;
 207 
 208         bool shown;
 209         bool inhibit_resize;
 210 };
 211 
 212 #endif /* _SDL_BWin_h */

/* [<][>][^][v][top][bottom][index][help] */