Change GetContextClipRect() semantics so that a valid rect is always filled in; added some gfx predicate functions, not used everywhere yet

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3406 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-12-08 20:58:18 +00:00
parent 5976a133dd
commit 4ad67018fa
13 changed files with 71 additions and 58 deletions
+29
View File
@@ -164,6 +164,33 @@ typedef struct line
POINT first, second;
} LINE;
static inline bool
pointsEqual (POINT p1, POINT p2)
{
return p1.x == p2.x && p1.y == p2.y;
}
static inline bool
extentsEqual (EXTENT e1, EXTENT e2)
{
return e1.width == e2.width && e1.height == e2.height;
}
static inline bool
rectsEqual (RECT r1, RECT r2)
{
return pointsEqual (r1.corner, r2.corner)
&& extentsEqual (r1.extent, r2.extent);
}
static inline bool
pointWithinRect (RECT r, POINT p)
{
return p.x >= r.corner.x && p.y >= r.corner.y
&& p.x < r.corner.x + r.extent.width
&& p.y < r.corner.y + r.extent.height;
}
typedef enum
{
ALIGN_LEFT,
@@ -248,6 +275,8 @@ extern FRAME GetContextFGFrame (void);
// Context cliprect defines the drawing bounds. Additionally, all
// drawing positions (x,y) are relative to the cliprect corner.
extern BOOLEAN SetContextClipRect (RECT *pRect);
// The returned rect is always filled in. If the context cliprect
// is undefined, the returned rect has foreground frame dimensions.
extern BOOLEAN GetContextClipRect (RECT *pRect);
extern TIME_VALUE DrawablesIntersect (INTERSECT_CONTROL *pControl0,
+1 -1
View File
@@ -19,7 +19,7 @@
#include "gfxintrn.h"
INTERSECT_CODE
_clip_line (RECT *pClipRect, BRESENHAM_LINE *pLine)
_clip_line (const RECT *pClipRect, BRESENHAM_LINE *pLine)
{
COORD p;
COORD x0, y0, xmin, ymin, xmax, ymax;
+29 -3
View File
@@ -199,6 +199,15 @@ GetContextBackGroundColor (void)
return _get_context_bg_color ();
}
// Returns a rect based at 0,0 and the size of context foreground frame
static inline RECT
_get_context_fg_rect (void)
{
RECT r = { {0, 0}, {0, 0} };
r.extent = GetFrameBounds (_CurFramePtr);
return r;
}
BOOLEAN
SetContextClipRect (RECT *lpRect)
{
@@ -206,11 +215,22 @@ SetContextClipRect (RECT *lpRect)
return (FALSE);
if (lpRect)
_pCurContext->ClipRect = *lpRect;
{
if (rectsEqual (*lpRect, _get_context_fg_rect ()))
{ // Cliprect is undefined to mirror GetContextClipRect()
_pCurContext->ClipRect.extent.width = 0;
}
else
{ // We have a cliprect
_pCurContext->ClipRect = *lpRect;
}
}
else
{ // Set cliprect as undefined
_pCurContext->ClipRect.extent.width = 0;
}
return (TRUE);
return TRUE;
}
BOOLEAN
@@ -220,7 +240,13 @@ GetContextClipRect (RECT *lpRect)
return (FALSE);
*lpRect = _pCurContext->ClipRect;
return (lpRect->extent.width != 0);
if (!_pCurContext->ClipRect.extent.width)
{ // Though the cliprect is undefined, drawing will be clipped
// to the extent of the foreground frame
*lpRect = _get_context_fg_rect ();
}
return (_pCurContext->ClipRect.extent.width != 0);
}
+1 -2
View File
@@ -172,8 +172,7 @@ GetFrameRect (FRAME FramePtr, RECT *pRect)
{
pRect->corner.x = -FramePtr->HotSpot.x;
pRect->corner.y = -FramePtr->HotSpot.y;
pRect->extent.width = GetFrameWidth (FramePtr);
pRect->extent.height = GetFrameHeight (FramePtr);
pRect->extent = GetFrameBounds (FramePtr);
return (TRUE);
}
+2 -1
View File
@@ -80,7 +80,8 @@ typedef struct
extern DRAWABLE _request_drawable (COUNT NumFrames, DRAWABLE_TYPE
DrawableType, CREATE_FLAGS flags, SIZE width, SIZE height);
extern INTERSECT_CODE _clip_line (RECT *pClipRect, BRESENHAM_LINE *pLine);
extern INTERSECT_CODE _clip_line (const RECT *pClipRect,
BRESENHAM_LINE *pLine);
extern void *_GetCelData (uio_Stream *fp, DWORD length);
extern BOOLEAN _ReleaseCelData (void *handle);
-1
View File
@@ -105,7 +105,6 @@ DrawBatch (PRIMITIVE *lpBasePrim, PRIM_LINKS PrimLinks,
if (GraphicsSystemActive () && GetContextValidRect (&ValidRect, &origin))
{
COUNT CurIndex;
PRIM_LINKS OldLinks;
PRIMITIVE *lpPrim;
BatchGraphics ();
+1 -9
View File
@@ -206,14 +206,6 @@ TFB_DrawCommandQueue_Clear ()
UnlockRecursiveMutex (DCQ_Mutex);
}
static inline int
rects_equal (RECT *r1, RECT *r2)
{
return r1->corner.x == r2->corner.x && r1->corner.y == r2->corner.y
&& r1->extent.width == r2->extent.width
&& r1->extent.height == r2->extent.height;
}
void
TFB_EnqueueDrawCommand (TFB_DrawCommand* DrawCommand)
{
@@ -229,7 +221,7 @@ TFB_EnqueueDrawCommand (TFB_DrawCommand* DrawCommand)
// Set the clipping region.
// We allow drawing with no current context set, so the whole screen
if ((_pCurContext && !rects_equal (&scissor_rect, &_pCurContext->ClipRect))
if ((_pCurContext && !rectsEqual (scissor_rect, _pCurContext->ClipRect))
|| (!_pCurContext && scissor_rect.extent.width != 0))
{
// Enqueue command to set the glScissor spec
+1 -5
View File
@@ -232,11 +232,7 @@ TFB_PlayVideo (VIDEO_REF vid, uint32 x, uint32 y)
// calculate the frame-source and screen-destination rects
GetContextClipRect (&scrn_r);
if (scrn_r.extent.width <= 0 || scrn_r.extent.height <= 0)
{ // bad or empty rect
scrn_r = vid_r;
}
else if (!BoxIntersect(&scrn_r, &vid_r, &scrn_r))
if (!BoxIntersect(&scrn_r, &vid_r, &scrn_r))
return false; // drawing outside visible
sr = dr;
+4 -7
View File
@@ -36,9 +36,9 @@ DoShipSpin (COUNT index, MUSIC_REF hMusic)
#ifdef WANT_SHIP_SPINS
char vnbuf[32];
BYTE clut_buf[1];
RECT old_r, r;
RECT old_r;
LoadIntoExtraScreen (0);
LoadIntoExtraScreen (NULL);
#if 0
/* This is cut out right now but should be part of the 3DO side */
clut_buf[0] = FadeAllToBlack;
@@ -60,11 +60,8 @@ DoShipSpin (COUNT index, MUSIC_REF hMusic)
FlushColorXForms ();
GetContextClipRect (&old_r);
r.corner.x = r.corner.y = 0;
r.extent.width = SCREEN_WIDTH;
r.extent.height = SCREEN_HEIGHT;
SetContextClipRect (&r);
DrawFromExtraScreen (0);
SetContextClipRect (NULL);
DrawFromExtraScreen (NULL);
SetContextClipRect (&old_r);
if (hMusic)
-6
View File
@@ -62,12 +62,6 @@ ConfirmSaveLoad (STAMP *MsgStamp)
SetContextFont (StarConFont);
GetContextClipRect (&clip_r);
if (clip_r.extent.width == 0)
{
clip_r.corner.x = clip_r.corner.y = 0;
clip_r.extent.width = SCREEN_WIDTH;
clip_r.extent.height = SCREEN_HEIGHT;
}
t.baseline.x = clip_r.extent.width >> 1;
t.baseline.y = (clip_r.extent.height >> 1) + 3;
+2 -10
View File
@@ -729,14 +729,6 @@ DrawOrbit (PLANET_DESC *planet, int sizeNumer, int dyNumer, int denom)
DrawOval (&r, 1);
}
static inline bool
pointWithinRect (RECT *r, POINT p)
{
return p.x >= r->corner.x && p.y >= r->corner.y
&& p.x < r->corner.x + r->extent.width
&& p.y < r->corner.y + r->extent.height;
}
static SIZE
FindRadius (POINT shipLoc, SIZE fromRadius)
{
@@ -755,7 +747,7 @@ FindRadius (POINT shipLoc, SIZE fromRadius)
DISPLAY_FACTOR, DISPLAY_FACTOR >> 2, fromRadius);
displayLoc = locationToDisplay (shipLoc, fromRadius);
} while (pointWithinRect (&scaleRect, displayLoc));
} while (pointWithinRect (scaleRect, displayLoc));
return fromRadius;
}
@@ -981,7 +973,7 @@ CheckShipLocation (SIZE *newRadius)
}
if (!playerInInnerSystem ()
&& pointWithinRect (&scaleRect, GLOBAL (ShipStamp.origin)))
&& pointWithinRect (scaleRect, GLOBAL (ShipStamp.origin)))
{ // Outer zoom-in transition
*newRadius = FindRadius (GLOBAL (ip_location), radius);
return TRUE;
+1 -5
View File
@@ -1764,11 +1764,7 @@ SetFlashRect (RECT *pRect)
LockMutex (flash_mutex);
flash_rect = flash_rect1;
if (old_r.extent.width
&& (old_r.extent.width != flash_rect.extent.width
|| old_r.extent.height != flash_rect.extent.height
|| old_r.corner.x != flash_rect.corner.x
|| old_r.corner.y != flash_rect.corner.y))
if (old_r.extent.width && !rectsEqual (old_r, flash_rect))
{
// We had a flash rectangle, and now a different one is set.
if (flash_screen_frame)
-8
View File
@@ -1782,14 +1782,6 @@ drawContext (CONTEXT context, double hue /* no pun intended */)
// Switch back the old context; we're going to draw in it.
(void) SetContext (oldContext);
if (!haveClippingRect)
{
rect.corner.x = 0;
rect.corner.y = 0;
rect.extent.width = ScreenWidth;
rect.extent.height = ScreenHeight;
}
p1 = rect.corner;
p2.x = rect.corner.x + rect.extent.width - 1;
p2.y = rect.corner.y;