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