Move TFB_BoundingBox out of SDL domain
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3464 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
uqm_SUBDIRS="sdl"
|
||||
uqm_CFILES="boxint.c clipline.c cmap.c context.c drawable.c filegfx.c
|
||||
dcqueue.c
|
||||
bbox.c dcqueue.c
|
||||
font.c frame.c gfx_common.c intersec.c loaddisp.c
|
||||
pixmap.c resgfx.c tfb_draw.c tfb_prim.c widgets.c"
|
||||
|
||||
@@ -15,30 +15,53 @@
|
||||
*/
|
||||
|
||||
#include "port.h"
|
||||
#include SDL_INCLUDE(SDL.h)
|
||||
#include "bbox.h"
|
||||
#include "libs/graphics/bbox.h"
|
||||
|
||||
TFB_BoundingBox TFB_BBox;
|
||||
int maxWidth;
|
||||
int maxHeight;
|
||||
|
||||
void
|
||||
TFB_BBox_Init (int width, int height)
|
||||
{
|
||||
maxWidth = width;
|
||||
maxHeight = height;
|
||||
TFB_BBox.clip.extent.width = width;
|
||||
TFB_BBox.clip.extent.height = height;
|
||||
}
|
||||
|
||||
void
|
||||
TFB_BBox_Reset (void)
|
||||
{
|
||||
TFB_BBox.valid = 0;
|
||||
TFB_BBox.clip.corner.x = 0;
|
||||
TFB_BBox.clip.corner.y = 0;
|
||||
TFB_BBox.clip.extent.width = ScreenWidth;
|
||||
TFB_BBox.clip.extent.height = ScreenHeight;
|
||||
}
|
||||
|
||||
void
|
||||
TFB_BBox_GetClipRect (TFB_Canvas c)
|
||||
TFB_BBox_SetClipRect (const RECT *r)
|
||||
{
|
||||
SDL_Rect r;
|
||||
SDL_GetClipRect ((SDL_Surface *)c, &r);
|
||||
TFB_BBox.clip.corner.x = r.x;
|
||||
TFB_BBox.clip.corner.y = r.y;
|
||||
TFB_BBox.clip.extent.width = r.w;
|
||||
TFB_BBox.clip.extent.height = r.h;
|
||||
if (!r)
|
||||
{ /* No clipping -- full rect */
|
||||
TFB_BBox.clip.corner.x = 0;
|
||||
TFB_BBox.clip.corner.y = 0;
|
||||
TFB_BBox.clip.extent.width = maxWidth;
|
||||
TFB_BBox.clip.extent.height = maxHeight;
|
||||
return;
|
||||
}
|
||||
|
||||
TFB_BBox.clip = *r;
|
||||
|
||||
/* Make sure the cliprect is sane */
|
||||
if (TFB_BBox.clip.corner.x < 0)
|
||||
TFB_BBox.clip.corner.x = 0;
|
||||
|
||||
if (TFB_BBox.clip.corner.y < 0)
|
||||
TFB_BBox.clip.corner.y = 0;
|
||||
|
||||
if (TFB_BBox.clip.corner.x + TFB_BBox.clip.extent.width > maxWidth)
|
||||
TFB_BBox.clip.extent.width = maxWidth - TFB_BBox.clip.corner.x;
|
||||
|
||||
if (TFB_BBox.clip.corner.y + TFB_BBox.clip.extent.height > maxHeight)
|
||||
TFB_BBox.clip.extent.height = maxHeight - TFB_BBox.clip.corner.y;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -49,22 +72,6 @@ TFB_BBox_RegisterPoint (int x, int y)
|
||||
int x2 = TFB_BBox.clip.corner.x + TFB_BBox.clip.extent.width - 1;
|
||||
int y2 = TFB_BBox.clip.corner.y + TFB_BBox.clip.extent.height - 1;
|
||||
|
||||
/* Make sure the cliprect is sane */
|
||||
|
||||
if (x1 < 0) x1 = TFB_BBox.clip.corner.x = 0;
|
||||
if (y1 < 0) y1 = TFB_BBox.clip.corner.y = 0;
|
||||
if (x2 >= ScreenWidth)
|
||||
{
|
||||
TFB_BBox.clip.extent.width = ScreenWidth - x1;
|
||||
x2 = ScreenWidth - 1;
|
||||
}
|
||||
if (y2 >= ScreenHeight)
|
||||
{
|
||||
TFB_BBox.clip.extent.height = ScreenHeight - y1;
|
||||
y2 = ScreenHeight - 1;
|
||||
}
|
||||
|
||||
|
||||
/* Constrain coordinates */
|
||||
if (x < x1) x = x1;
|
||||
if (x >= x2) x = x2;
|
||||
@@ -105,16 +112,22 @@ TFB_BBox_RegisterPoint (int x, int y)
|
||||
}
|
||||
|
||||
void
|
||||
TFB_BBox_RegisterRect (RECT *r)
|
||||
TFB_BBox_RegisterRect (const RECT *r)
|
||||
{
|
||||
/* RECT will still register as a corner point of the cliprect even
|
||||
* if it does not intersect with the cliprect at all. This is not
|
||||
* a problem, as more is not less. */
|
||||
TFB_BBox_RegisterPoint (r->corner.x, r->corner.y);
|
||||
TFB_BBox_RegisterPoint (r->corner.x + r->extent.width, r->corner.y + r->extent.height);
|
||||
TFB_BBox_RegisterPoint (r->corner.x + r->extent.width - 1,
|
||||
r->corner.y + r->extent.height - 1);
|
||||
}
|
||||
|
||||
void
|
||||
TFB_BBox_RegisterCanvas (TFB_Canvas c, int x, int y)
|
||||
{
|
||||
SDL_Surface *s = (SDL_Surface *)c;
|
||||
TFB_BBox_RegisterPoint (x, y);
|
||||
TFB_BBox_RegisterPoint (x + s->w, y + s->h);
|
||||
RECT r;
|
||||
r.corner.x = x;
|
||||
r.corner.y = y;
|
||||
TFB_DrawCanvas_GetExtent (c, &r.extent);
|
||||
TFB_BBox_RegisterRect (&r);
|
||||
}
|
||||
@@ -14,12 +14,11 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef BBOX_H_INCL__
|
||||
#define BBOX_H_INCL__
|
||||
|
||||
#include "libs/gfxlib.h"
|
||||
#include "libs/graphics/tfb_draw.h"
|
||||
#include "libs/graphics/gfx_common.h"
|
||||
|
||||
#ifndef _BBOX_H_
|
||||
#define _BBOX_H_
|
||||
|
||||
/* Bounding Box operations. These operations are NOT synchronized.
|
||||
* However, they should only be accessed by TFB_FlushGraphics and
|
||||
@@ -37,10 +36,11 @@ typedef struct {
|
||||
extern TFB_BoundingBox TFB_BBox;
|
||||
|
||||
void TFB_BBox_RegisterPoint (int x, int y);
|
||||
void TFB_BBox_RegisterRect (RECT *r);
|
||||
void TFB_BBox_RegisterRect (const RECT *r);
|
||||
void TFB_BBox_RegisterCanvas (TFB_Canvas c, int x, int y);
|
||||
|
||||
void TFB_BBox_Init (int width, int height);
|
||||
void TFB_BBox_Reset (void);
|
||||
void TFB_BBox_GetClipRect (TFB_Canvas c);
|
||||
void TFB_BBox_SetClipRect (const RECT *r);
|
||||
|
||||
#endif
|
||||
#endif /* BBOX_H_INCL__ */
|
||||
@@ -231,10 +231,7 @@ TFB_EnqueueDrawCommand (TFB_DrawCommand* DrawCommand)
|
||||
if (scissor_rect.extent.width)
|
||||
{
|
||||
DC.Type = TFB_DRAWCOMMANDTYPE_SCISSORENABLE;
|
||||
DC.data.scissor.x = scissor_rect.corner.x;
|
||||
DC.data.scissor.y = scissor_rect.corner.y;
|
||||
DC.data.scissor.w = scissor_rect.extent.width;
|
||||
DC.data.scissor.h = scissor_rect.extent.height;
|
||||
DC.data.scissor.rect = scissor_rect;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -100,7 +100,7 @@ typedef struct tfb_dc_copyimg
|
||||
|
||||
typedef struct tfb_dc_scissor
|
||||
{
|
||||
int x, y, w, h;
|
||||
RECT rect;
|
||||
} TFB_DrawCommand_Scissor;
|
||||
|
||||
typedef struct tfb_dc_setmip
|
||||
|
||||
@@ -4,4 +4,4 @@ uqm_CFILES="3do_blt.c 3do_funcs.c 3do_getbody.c opengl.c
|
||||
scalers.c 2xscalers.c
|
||||
2xscalers_mmx.c 2xscalers_sse.c 2xscalers_3dnow.c
|
||||
nearest2x.c bilinear2x.c biadv2x.c triscan2x.c hq2x.c
|
||||
canvas.c bbox.c sdluio.c rotozoom.c"
|
||||
canvas.c sdluio.c rotozoom.c"
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#if defined (GFXMODULE_SDL) && defined (HAVE_OPENGL)
|
||||
|
||||
#include "libs/graphics/sdl/opengl.h"
|
||||
#include "bbox.h"
|
||||
#include "libs/graphics/bbox.h"
|
||||
#include "scalers.h"
|
||||
#include "options.h"
|
||||
#include "libs/log.h"
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#ifdef GFXMODULE_SDL
|
||||
|
||||
#include "pure.h"
|
||||
#include "bbox.h"
|
||||
#include "libs/graphics/bbox.h"
|
||||
#include "scalers.h"
|
||||
#include "libs/log.h"
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "libs/graphics/cmap.h"
|
||||
#include "libs/input/sdl/input.h"
|
||||
// for ProcessInputEvent()
|
||||
#include "bbox.h"
|
||||
#include "libs/graphics/bbox.h"
|
||||
#include "port.h"
|
||||
#include "libs/uio.h"
|
||||
#include "libs/log.h"
|
||||
@@ -174,6 +174,7 @@ TFB_InitGraphics (int driver, int flags, int width, int height)
|
||||
Init_DrawCommandQueue ();
|
||||
|
||||
TFB_DrawCanvas_Initialize ();
|
||||
TFB_BBox_Init (ScreenWidth, ScreenHeight);
|
||||
|
||||
RenderingCond = CreateCondVar ("DCQ empty",
|
||||
SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO);
|
||||
@@ -660,7 +661,6 @@ TFB_FlushGraphics (void) // Only call from main thread!!
|
||||
}
|
||||
|
||||
TFB_BBox_Reset ();
|
||||
TFB_BBox_GetClipRect (SDL_Screens[0]);
|
||||
|
||||
done = FALSE;
|
||||
while (!done)
|
||||
@@ -794,19 +794,17 @@ TFB_FlushGraphics (void) // Only call from main thread!!
|
||||
case TFB_DRAWCOMMANDTYPE_SCISSORENABLE:
|
||||
{
|
||||
SDL_Rect r;
|
||||
r.x = TFB_BBox.clip.corner.x = DC.data.scissor.x;
|
||||
r.y = TFB_BBox.clip.corner.y = DC.data.scissor.y;
|
||||
r.w = TFB_BBox.clip.extent.width = DC.data.scissor.w;
|
||||
r.h = TFB_BBox.clip.extent.height = DC.data.scissor.h;
|
||||
r.x = DC.data.scissor.rect.corner.x;
|
||||
r.y = DC.data.scissor.rect.corner.y;
|
||||
r.w = DC.data.scissor.rect.extent.width;
|
||||
r.h = DC.data.scissor.rect.extent.height;
|
||||
SDL_SetClipRect (SDL_Screens[0], &r);
|
||||
TFB_BBox_SetClipRect (&DC.data.scissor.rect);
|
||||
break;
|
||||
}
|
||||
case TFB_DRAWCOMMANDTYPE_SCISSORDISABLE:
|
||||
SDL_SetClipRect (SDL_Screens[0], NULL);
|
||||
TFB_BBox.clip.corner.x = 0;
|
||||
TFB_BBox.clip.corner.y = 0;
|
||||
TFB_BBox.clip.extent.width = ScreenWidth;
|
||||
TFB_BBox.clip.extent.height = ScreenHeight;
|
||||
TFB_BBox_SetClipRect (NULL);
|
||||
break;
|
||||
case TFB_DRAWCOMMANDTYPE_COPYTOIMAGE:
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user