Fixed bug #360 SDL-1.2
authorSam Lantinga
Sat, 07 Jul 2007 19:20:28 +0000
branchSDL-1.2
changeset 40124e29535b821b
parent 4011 f5794774970d
child 4013 5804139bdf0b
Fixed bug #360

Fixed fullscreen video modes and improved the mouse grab code.
src/video/bwindow/SDL_BView.h
src/video/bwindow/SDL_BWin.h
src/video/bwindow/SDL_sysevents.cc
src/video/bwindow/SDL_sysmouse.cc
src/video/bwindow/SDL_sysvideo.cc
src/video/bwindow/SDL_sysyuv.cc
     1.1 --- a/src/video/bwindow/SDL_BView.h	Fri Jul 06 13:39:03 2007 +0000
     1.2 +++ b/src/video/bwindow/SDL_BView.h	Sat Jul 07 19:20:28 2007 +0000
     1.3 @@ -37,12 +37,26 @@
     1.4  		BView(frame, "SDL View", B_FOLLOW_ALL_SIDES,
     1.5  					(B_WILL_DRAW|B_FRAME_EVENTS)) {
     1.6  		image = NULL;
     1.7 +		xoff = yoff = 0;
     1.8  		SetViewColor(0,0,0,0);
     1.9  		SetHighColor(0,0,0,0);
    1.10  	}
    1.11  	virtual ~SDL_BView() {
    1.12  		SetBitmap(NULL);
    1.13  	}
    1.14 +	/* Set drawing offsets for fullscreen mode */
    1.15 +	virtual void SetXYOffset(int x, int y) {
    1.16 +		xoff = x;
    1.17 +		yoff = y;
    1.18 +	}
    1.19 +	virtual void GetXYOffset(int &x, int &y) {
    1.20 +		x = xoff;
    1.21 +		y = yoff;
    1.22 +	}
    1.23 +	virtual void GetXYOffset(float &x, float &y) {
    1.24 +		x = (float)xoff;
    1.25 +		y = (float)yoff;
    1.26 +	}
    1.27  	/* The view changed size. If it means we're in fullscreen, we
    1.28  	 * draw a nice black box in the entire view to get black borders.
    1.29  	 */
    1.30 @@ -52,14 +66,14 @@
    1.31  		bounds.right = width;
    1.32  		bounds.bottom = height;
    1.33  		/* Fill the entire view with black */ 
    1.34 -//		FillRect(bounds, B_SOLID_HIGH);
    1.35 +		FillRect(bounds, B_SOLID_HIGH);
    1.36  		/* And if there's an image, redraw it. */
    1.37  		if( image ) {
    1.38  			bounds = image->Bounds();
    1.39  			Draw(bounds);
    1.40  		}
    1.41  	}
    1.42 -
    1.43 +	
    1.44  	/* Drawing portion of this complete breakfast. :) */
    1.45  	virtual void SetBitmap(BBitmap *bitmap) {
    1.46  		if ( image ) {
    1.47 @@ -69,17 +83,34 @@
    1.48  	}
    1.49  	virtual void Draw(BRect updateRect) {
    1.50  		if ( image ) {
    1.51 -			DrawBitmap(image, updateRect, updateRect);
    1.52 +			if(xoff || yoff) {	
    1.53 +				BRect dest;
    1.54 +				dest.top    = updateRect.top + yoff;
    1.55 +				dest.left   = updateRect.left + xoff;
    1.56 +				dest.bottom = updateRect.bottom + yoff;
    1.57 +				dest.right  = updateRect.right + xoff;
    1.58 +				DrawBitmap(image, updateRect, dest);
    1.59 +			} else {
    1.60 +				DrawBitmap(image, updateRect, updateRect);
    1.61 +			}
    1.62  		}
    1.63  	}
    1.64  	virtual void DrawAsync(BRect updateRect) {
    1.65 -		if ( image ) {
    1.66 +		if(xoff || yoff) {	
    1.67 +			BRect dest;
    1.68 +			dest.top    = updateRect.top + yoff;
    1.69 +			dest.left   = updateRect.left + xoff;
    1.70 +			dest.bottom = updateRect.bottom + yoff;
    1.71 +			dest.right  = updateRect.right + xoff;;
    1.72 +			DrawBitmapAsync(image, updateRect, dest);
    1.73 +		} else {
    1.74  			DrawBitmapAsync(image, updateRect, updateRect);
    1.75  		}
    1.76  	}
    1.77  
    1.78  private:
    1.79  	BBitmap *image;
    1.80 +	int xoff, yoff;
    1.81  };
    1.82  
    1.83  #endif /* _SDL_BView_h */
     2.1 --- a/src/video/bwindow/SDL_BWin.h	Fri Jul 06 13:39:03 2007 +0000
     2.2 +++ b/src/video/bwindow/SDL_BWin.h	Sat Jul 07 19:20:28 2007 +0000
     2.3 @@ -149,6 +149,34 @@
     2.4  	virtual void SetBitmap(BBitmap *bitmap) {
     2.5  		SDL_View->SetBitmap(bitmap);
     2.6  	}
     2.7 +	virtual void SetXYOffset(int x, int y) {
     2.8 +#if SDL_VIDEO_OPENGL
     2.9 +		if ( the_view == SDL_GLView ) {
    2.10 +			return;
    2.11 +		}
    2.12 +#endif
    2.13 +		SDL_View->SetXYOffset(x, y);
    2.14 +	}
    2.15 +	virtual void GetXYOffset(int &x, int &y) {
    2.16 +#if SDL_VIDEO_OPENGL
    2.17 +		if ( the_view == SDL_GLView ) {
    2.18 +			x = 0;
    2.19 +			y = 0;
    2.20 +			return;
    2.21 +		}
    2.22 +#endif
    2.23 +		SDL_View->GetXYOffset(x, y);
    2.24 +	}
    2.25 +	virtual void GetXYOffset(float &x, float &y) {
    2.26 +#if SDL_VIDEO_OPENGL
    2.27 +		if ( the_view == SDL_GLView ) {
    2.28 +			x = 0.0f;
    2.29 +			y = 0.0f;
    2.30 +			return;
    2.31 +		}
    2.32 +#endif
    2.33 +		SDL_View->GetXYOffset(x, y);
    2.34 +	}
    2.35  	virtual bool BeginDraw(void) {
    2.36  		return(Lock());
    2.37  	}
     3.1 --- a/src/video/bwindow/SDL_sysevents.cc	Fri Jul 06 13:39:03 2007 +0000
     3.2 +++ b/src/video/bwindow/SDL_sysevents.cc	Sat Jul 07 19:20:28 2007 +0000
     3.3 @@ -166,62 +166,61 @@
     3.4  			BPoint where;
     3.5  			int32 transit;
     3.6  			if (msg->FindPoint("where", &where) == B_OK && msg->FindInt32("be:transit", &transit) == B_OK) {
     3.7 +				int x, y;
     3.8  
     3.9 -//BeSman: I need another method for cursor catching !!!
    3.10 -if(view->input_grab != SDL_GRAB_OFF)
    3.11 -{			
    3.12 -			BPoint center;
    3.13 -			center.x = (SDL_VideoSurface->w/2);
    3.14 -			center.y = (SDL_VideoSurface->h/2);
    3.15 -			BPoint delta = where - center;
    3.16 -if(delta.x > center.x)
    3.17 -SDL_WarpMouse((int)center.x*2,(int)where.y);
    3.18 -
    3.19 -if(delta.x < -center.x)
    3.20 -SDL_WarpMouse(0,(int)where.y);
    3.21 -
    3.22 -if(delta.y > center.y)
    3.23 -SDL_WarpMouse((int)where.x,(int)center.y*2);
    3.24 +				GetXYOffset(x, y);
    3.25 +				x = (int)where.x - x;
    3.26 +				y = (int)where.y - y;
    3.27  
    3.28 -if(delta.y < -center.y)
    3.29 -SDL_WarpMouse((int)where.x,0);
    3.30 -
    3.31 -
    3.32 -if((delta.x-1 < -center.x)&&(delta.y-1 < -center.y))
    3.33 -SDL_WarpMouse(1,1);
    3.34 -
    3.35 -if((delta.x-1 < -center.x)&&(delta.y+1 > center.y))
    3.36 -SDL_WarpMouse(1,(int)center.y*2-1);
    3.37 -
    3.38 -if((delta.x+1 > center.x)&&(delta.y-1 < -center.y))
    3.39 -SDL_WarpMouse((int)center.x*2-1,1);
    3.40 -
    3.41 -if((delta.x+1 > center.x)&&(delta.y+1 > center.y))
    3.42 -SDL_WarpMouse((int)center.x*2-1,(int)center.y*2-1);				
    3.43 -
    3.44 -}
    3.45 +				//BeSman: I need another method for cursor catching !!!
    3.46 +				if (view->input_grab != SDL_GRAB_OFF)
    3.47 +				{
    3.48 +					bool clipped = false;
    3.49 +					if ( x < 0 ) {
    3.50 +						x = 0;
    3.51 +						clipped = true;
    3.52 +					} else if ( x >= SDL_VideoSurface->w ) {
    3.53 +						x = (SDL_VideoSurface->w-1);
    3.54 +						clipped = true;
    3.55 +					}
    3.56 +					if ( y < 0 ) {
    3.57 +						y = 0;
    3.58 +						clipped = true;
    3.59 +					} else if ( y >= SDL_VideoSurface->h ) {
    3.60 +						y = (SDL_VideoSurface->h-1);
    3.61 +						clipped = true;
    3.62 +					}
    3.63 +					if ( clipped ) {
    3.64 +						BPoint edge;
    3.65 +						GetXYOffset(edge.x, edge.y);
    3.66 +						edge.x += x;
    3.67 +						edge.y += y;
    3.68 +						ConvertToScreen(&edge);
    3.69 +						set_mouse_position((int)edge.x, (int)edge.y);
    3.70 +					}
    3.71 +					transit = B_INSIDE_VIEW;
    3.72 +				}
    3.73  				if (transit == B_EXITED_VIEW) {
    3.74  					if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
    3.75  						SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
    3.76 -				//		be_app->SetCursor(B_HAND_CURSOR);
    3.77 +						be_app->SetCursor(B_HAND_CURSOR);
    3.78  					}
    3.79  				} else {
    3.80 -		
    3.81 -					int x, y;
    3.82 -					if ( ! (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
    3.83 +					if ( !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
    3.84  						SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
    3.85  						SDL_SetCursor(NULL);
    3.86  					}
    3.87 -					x = (int)where.x;
    3.88 -					y = (int)where.y;
    3.89  
    3.90  					if ( mouse_relative ) {
    3.91 -						BPoint center;
    3.92 -						center.x = (SDL_VideoSurface->w/2);
    3.93 -						center.y = (SDL_VideoSurface->h/2);
    3.94 -						x -= (int)center.x;
    3.95 -						y -= (int)center.y;
    3.96 +						int half_w = (SDL_VideoSurface->w/2);
    3.97 +						int half_h = (SDL_VideoSurface->h/2);
    3.98 +						x -= half_w;
    3.99 +						y -= half_h;
   3.100  						if ( x || y ) {
   3.101 +							BPoint center;
   3.102 +							GetXYOffset(center.x, center.y);
   3.103 +							center.x += half_w;
   3.104 +							center.y += half_h;
   3.105  							ConvertToScreen(&center);
   3.106  							set_mouse_position((int)center.x, (int)center.y);
   3.107  							SDL_PrivateMouseMotion(0, 1, x, y);
     4.1 --- a/src/video/bwindow/SDL_sysmouse.cc	Fri Jul 06 13:39:03 2007 +0000
     4.2 +++ b/src/video/bwindow/SDL_sysmouse.cc	Sat Jul 07 19:20:28 2007 +0000
     4.3 @@ -128,15 +128,14 @@
     4.4  /* Implementation by Christian Bauer <cbauer@student.physik.uni-mainz.de> */
     4.5  void BE_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
     4.6  {
     4.7 -	if (_this->screen && (_this->screen->flags & SDL_FULLSCREEN)) {
     4.8 -		SDL_PrivateMouseMotion(0, 0, x, y);
     4.9 -	} else {
    4.10 -		BPoint pt(x, y);
    4.11 -		SDL_Win->Lock();
    4.12 -		SDL_Win->ConvertToScreen(&pt);
    4.13 -		SDL_Win->Unlock();
    4.14 -		set_mouse_position((int32)pt.x, (int32)pt.y);
    4.15 -	}
    4.16 +	BPoint pt;
    4.17 +	SDL_Win->GetXYOffset(pt.x, pt.y);
    4.18 +	pt.x += x;
    4.19 +	pt.y += y;
    4.20 +	SDL_Win->Lock();
    4.21 +	SDL_Win->ConvertToScreen(&pt);
    4.22 +	SDL_Win->Unlock();
    4.23 +	set_mouse_position((int32)pt.x, (int32)pt.y);
    4.24  }
    4.25  
    4.26  /* Check to see if we need to enter or leave mouse relative mode */
     5.1 --- a/src/video/bwindow/SDL_sysvideo.cc	Fri Jul 06 13:39:03 2007 +0000
     5.2 +++ b/src/video/bwindow/SDL_sysvideo.cc	Sat Jul 07 19:20:28 2007 +0000
     5.3 @@ -366,9 +366,8 @@
     5.4  		--i;	/* We went too far */
     5.5  	}
     5.6  
     5.7 -/*  BeSman::We dont want to use a Desktop resolution */
     5.8 -//	width = modes[i]->w;
     5.9 -//	height = modes[i]->h;      
    5.10 +	width = modes[i]->w;
    5.11 +	height = modes[i]->h;      
    5.12  
    5.13  	bscreen.GetModeList(&dmodes, &nmodes);
    5.14  	for ( i = 0; i < nmodes; ++i ) {
    5.15 @@ -455,6 +454,12 @@
    5.16  		cx = (bounds.IntegerWidth() - width)/2;
    5.17  		cy = (bounds.IntegerHeight() - height)/2;
    5.18  
    5.19 +		if ( fullscreen ) {
    5.20 +			/* Set offset for drawing */
    5.21 +			SDL_Win->SetXYOffset(cx, cy);
    5.22 +		} else {
    5.23 +			SDL_Win->SetXYOffset(0, 0);
    5.24 +		}
    5.25  		if ( ! needs_unlock || was_fullscreen ) {
    5.26  			/* Center the window the first time */
    5.27  			SDL_Win->MoveTo(cx, cy);
     6.1 --- a/src/video/bwindow/SDL_sysyuv.cc	Fri Jul 06 13:39:03 2007 +0000
     6.2 +++ b/src/video/bwindow/SDL_sysyuv.cc	Sat Jul 07 19:20:28 2007 +0000
     6.3 @@ -274,7 +274,13 @@
     6.4          return 0;
     6.5      }
     6.6      BView * bview = overlay->hwdata->bview;
     6.7 -    bview->MoveTo(dst->x,dst->y);
     6.8 +    if (SDL_Win->IsFullScreen()) {
     6.9 +    	int left,top;
    6.10 +    	SDL_Win->GetXYOffset(left,top);
    6.11 +	    bview->MoveTo(left+dst->x,top+dst->y);
    6.12 +    } else {
    6.13 +	    bview->MoveTo(dst->x,dst->y);
    6.14 +    }
    6.15      bview->ResizeTo(dst->w,dst->h);
    6.16      bview->Flush();
    6.17  	if (overlay->hwdata->first_display) {