src/video/bwindow/SDL_BView.h

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

FUNCTIONS

This source file includes following functions.
  1. SDL_BView
  2. SetXYOffset
  3. FrameResized
  4. SetBitmap
  5. Draw
  6. DrawAsync

   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_BView.h,v 1.2.2.5 2001/02/10 07:20:05 hercules Exp $";
  26 #endif
  27 
  28 /* This is the event handling and graphics update portion of SDL_BWin */
  29 
  30 extern "C" {
  31 #include "SDL_events_c.h"
  32 };
  33 
  34 class SDL_BView : public BView
     /* [<][>][^][v][top][bottom][index][help] */
  35 {
  36 public:
  37         SDL_BView(BRect frame) : 
  38                 BView(frame, "SDL View", B_FOLLOW_ALL_SIDES,
  39                                         (B_WILL_DRAW|B_FRAME_EVENTS)) {
  40                 image = NULL;
  41                 xoff = yoff = 0;
  42                 SetViewColor(0,0,0,0);
  43                 SetHighColor(0,0,0,0);
  44         }
  45         virtual ~SDL_BView() {
  46                 SetBitmap(NULL);
  47         }
  48         /* Set drawing offsets for fullscreen mode */
  49         virtual void SetXYOffset(int x, int y) {
     /* [<][>][^][v][top][bottom][index][help] */
  50                 xoff = x;
  51                 yoff = y;
  52         }
  53         /* The view changed size. If it means we're in fullscreen, we
  54          * draw a nice black box in the entire view to get black borders.
  55          */
  56         virtual void FrameResized(float width, float height) {
     /* [<][>][^][v][top][bottom][index][help] */
  57                 BRect bounds;
  58                 bounds.top = bounds.left = 0;
  59                 bounds.right = width;
  60                 bounds.bottom = height;
  61                 /* Fill the entire view with black */ 
  62                 FillRect(bounds, B_SOLID_HIGH);
  63                 /* And if there's an image, redraw it. */
  64                 if( image ) {
  65                         bounds = image->Bounds();
  66                         Draw(bounds);
  67                 }
  68         }
  69         
  70         /* Drawing portion of this complete breakfast. :) */
  71         virtual void SetBitmap(BBitmap *bitmap) {
     /* [<][>][^][v][top][bottom][index][help] */
  72                 if ( image ) {
  73                         delete image;
  74                 }
  75                 image = bitmap;
  76         }
  77         virtual void Draw(BRect updateRect) {
     /* [<][>][^][v][top][bottom][index][help] */
  78                 if ( image ) {
  79                         if(xoff || yoff) {      
  80                                 BRect dest;
  81                                 dest.top    = updateRect.top + yoff;
  82                                 dest.left   = updateRect.left + xoff;
  83                                 dest.bottom = updateRect.bottom + yoff;
  84                                 dest.right  = updateRect.right + xoff;;
  85                                 DrawBitmap(image, updateRect, dest);
  86                         } else {
  87                                 DrawBitmap(image, updateRect, updateRect);
  88                         }
  89                 }
  90         }
  91         virtual void DrawAsync(BRect updateRect) {
     /* [<][>][^][v][top][bottom][index][help] */
  92                 if(xoff || yoff) {      
  93                         BRect dest;
  94                         dest.top    = updateRect.top + yoff;
  95                         dest.left   = updateRect.left + xoff;
  96                         dest.bottom = updateRect.bottom + yoff;
  97                         dest.right  = updateRect.right + xoff;;
  98                         DrawBitmapAsync(image, updateRect, dest);
  99                 } else {
 100                         DrawBitmapAsync(image, updateRect, updateRect);
 101                 }
 102         }
 103 
 104 private:
 105         BBitmap *image;
 106         int xoff, yoff;
 107 };

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