From 939fc2e5dbe7bfbba38c4cd6eb81a1cf9e2c6c5a Mon Sep 17 00:00:00 2001 From: avolkov Date: Tue, 8 Dec 2009 21:50:16 +0000 Subject: [PATCH] Better context drawing origin semantics; also chaser fix for foreground frame hotspot left broken in r3401 git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3407 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/libs/gfxlib.h | 9 +++++++++ sc2/src/libs/graphics/context.c | 6 ++++++ sc2/src/uqm/melee.c | 8 +++++--- sc2/src/uqm/planets/plangen.c | 6 +++--- sc2/src/uqm/planets/pstarmap.c | 8 +++++--- sc2/src/uqm/setup.c | 2 +- sc2/src/uqm/shipstat.c | 18 +++++++++--------- sc2/src/uqm/util.c | 6 +++--- 8 files changed, 41 insertions(+), 22 deletions(-) diff --git a/sc2/src/libs/gfxlib.h b/sc2/src/libs/gfxlib.h index d34696bde..3f1161d70 100644 --- a/sc2/src/libs/gfxlib.h +++ b/sc2/src/libs/gfxlib.h @@ -164,6 +164,13 @@ typedef struct line POINT first, second; } LINE; +static inline POINT +MAKE_POINT (COORD x, COORD y) +{ + POINT pt = {x, y}; + return pt; +} + static inline bool pointsEqual (POINT p1, POINT p2) { @@ -278,6 +285,8 @@ 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); +// The actual origin will be orgOffset + context ClipRect.corner +extern POINT SetContextOrigin (POINT orgOffset); extern TIME_VALUE DrawablesIntersect (INTERSECT_CONTROL *pControl0, INTERSECT_CONTROL *pControl1, TIME_VALUE max_time_val); diff --git a/sc2/src/libs/graphics/context.c b/sc2/src/libs/graphics/context.c index afd37cedd..2f5204984 100644 --- a/sc2/src/libs/graphics/context.c +++ b/sc2/src/libs/graphics/context.c @@ -249,6 +249,12 @@ GetContextClipRect (RECT *lpRect) return (_pCurContext->ClipRect.extent.width != 0); } +POINT +SetContextOrigin (POINT orgOffset) +{ + // XXX: This is a hack, kind of. But that's what the original did. + return SetFrameHot (_CurFramePtr, orgOffset); +} FRAME SetContextFontEffect (FRAME EffectFrame) diff --git a/sc2/src/uqm/melee.c b/sc2/src/uqm/melee.c index 30c94aa03..50bc8c3a9 100644 --- a/sc2/src/uqm/melee.c +++ b/sc2/src/uqm/melee.c @@ -363,6 +363,7 @@ RepairMeleeFrame (RECT *pRect) RECT r; CONTEXT OldContext; RECT OldRect; + POINT oldOrigin; r.corner.x = pRect->corner.x + SAFE_X; r.corner.y = pRect->corner.y + SAFE_Y; @@ -376,8 +377,9 @@ RepairMeleeFrame (RECT *pRect) OldContext = SetContext (SpaceContext); GetContextClipRect (&OldRect); SetContextClipRect (&r); - SetFrameHot (Screen, - MAKE_HOT_SPOT (r.corner.x - SAFE_X, r.corner.y - SAFE_Y)); + // Offset the origin so that we draw the correct gfx in the cliprect + oldOrigin = SetContextOrigin (MAKE_POINT (-r.corner.x + SAFE_X, + -r.corner.y + SAFE_Y)); BatchGraphics (); DrawMeleeIcon (0); /* Entire melee screen */ @@ -413,7 +415,7 @@ RepairMeleeFrame (RECT *pRect) DrawPickFrame (pMeleeState); UnbatchGraphics (); - SetFrameHot (Screen, MAKE_HOT_SPOT (0, 0)); + SetContextOrigin (oldOrigin); SetContextClipRect (&OldRect); SetContext (OldContext); } diff --git a/sc2/src/uqm/planets/plangen.c b/sc2/src/uqm/planets/plangen.c index e6b0a7939..fbeb37dba 100644 --- a/sc2/src/uqm/planets/plangen.c +++ b/sc2/src/uqm/planets/plangen.c @@ -128,10 +128,10 @@ RenderTopography (FRAME DstFrame, BYTE *pTopoData, int w, int h) BYTE *pSrc; BYTE *xlat_tab; BYTE *cbase; - HOT_SPOT OldHot; + POINT oldOrigin; RECT ClipRect; - OldHot = SetFrameHot (DstFrame, MAKE_HOT_SPOT (0, 0)); + oldOrigin = SetContextOrigin (MAKE_POINT (0, 0)); GetContextClipRect (&ClipRect); SetContextClipRect (NULL); @@ -201,7 +201,7 @@ RenderTopography (FRAME DstFrame, BYTE *pTopoData, int w, int h) } SetContextClipRect (&ClipRect); - SetFrameHot (DstFrame, OldHot); + SetContextOrigin (oldOrigin); } SetContextFGFrame (OldFrame); diff --git a/sc2/src/uqm/planets/pstarmap.c b/sc2/src/uqm/planets/pstarmap.c index d514deb61..7fa3e80b8 100644 --- a/sc2/src/uqm/planets/pstarmap.c +++ b/sc2/src/uqm/planets/pstarmap.c @@ -287,6 +287,7 @@ DrawStarMap (COUNT race_update, RECT *pClipRect) COUNT which_space; long diameter; RECT r, old_r; + POINT oldOrigin; STAMP s; FRAME star_frame; STAR_DESC *SDPtr; @@ -312,8 +313,9 @@ DrawStarMap (COUNT race_update, RECT *pClipRect) SetContextClipRect (pClipRect); pClipRect->corner.x -= old_r.corner.x; pClipRect->corner.y -= old_r.corner.y; - SetFrameHot (Screen, - MAKE_HOT_SPOT (pClipRect->corner.x, pClipRect->corner.y)); + // Offset the origin so that we draw the correct gfx in the cliprect + oldOrigin = SetContextOrigin (MAKE_POINT (-pClipRect->corner.x, + -pClipRect->corner.y)); } if (transition_pending) @@ -548,7 +550,7 @@ printf ("%s\n", buf); if (pClipRect) { SetContextClipRect (&old_r); - SetFrameHot (Screen, MAKE_HOT_SPOT (0, 0)); + SetContextOrigin (oldOrigin); } if (race_update == 0) diff --git a/sc2/src/uqm/setup.c b/sc2/src/uqm/setup.c index 814bd025f..ea725177f 100644 --- a/sc2/src/uqm/setup.c +++ b/sc2/src/uqm/setup.c @@ -107,7 +107,7 @@ LoadKernel (int argc, char *argv[]) SetContext (ScreenContext); SetContextFGFrame (Screen); - SetFrameHot (Screen, MAKE_HOT_SPOT (0, 0)); + SetContextOrigin (MAKE_POINT (0, 0)); hResIndex = (RESOURCE_INDEX) InitResourceSystem (); if (hResIndex == 0) diff --git a/sc2/src/uqm/shipstat.c b/sc2/src/uqm/shipstat.c index f1383aa68..3a28dc28d 100644 --- a/sc2/src/uqm/shipstat.c +++ b/sc2/src/uqm/shipstat.c @@ -139,6 +139,8 @@ InitShipStatus (SHIP_INFO *SIPtr, STARSHIP *StarShipPtr, RECT *pClipRect) COORD y = 0; // default, for Melee menu STAMP Stamp; CONTEXT OldContext; + RECT oldClipRect; + POINT oldOrigin; if (StarShipPtr) // set during battle { @@ -149,14 +151,16 @@ InitShipStatus (SHIP_INFO *SIPtr, STARSHIP *StarShipPtr, RECT *pClipRect) OldContext = SetContext (StatusContext); if (pClipRect) { - GetContextClipRect (&r); + GetContextClipRect (&oldClipRect); + r = oldClipRect; r.corner.x += pClipRect->corner.x; r.corner.y += (pClipRect->corner.y & ~1); r.extent = pClipRect->extent; r.extent.height += pClipRect->corner.y & 1; SetContextClipRect (&r); - SetFrameHot (Screen, MAKE_HOT_SPOT ( - pClipRect->corner.x, (pClipRect->corner.y & ~1))); + // Offset the origin so that we draw into the cliprect + oldOrigin = SetContextOrigin (MAKE_POINT (-pClipRect->corner.x, + -(pClipRect->corner.y & ~1))); } BatchGraphics (); @@ -291,12 +295,8 @@ InitShipStatus (SHIP_INFO *SIPtr, STARSHIP *StarShipPtr, RECT *pClipRect) if (pClipRect) { - SetFrameHot (Screen, MAKE_HOT_SPOT (0, 0)); - r.corner.x = SPACE_WIDTH + SAFE_X; - r.corner.y = SAFE_Y; - r.extent.width = STATUS_WIDTH; - r.extent.height = STATUS_HEIGHT; - SetContextClipRect (&r); + SetContextOrigin (oldOrigin); + SetContextClipRect (&oldClipRect); } SetContext (OldContext); diff --git a/sc2/src/uqm/util.c b/sc2/src/uqm/util.c index bad7739bb..0bbc87e67 100644 --- a/sc2/src/uqm/util.c +++ b/sc2/src/uqm/util.c @@ -144,7 +144,7 @@ PauseGame (void) STAMP s; CONTEXT OldContext; FRAME F; - HOT_SPOT OldHot; + POINT oldOrigin; RECT OldRect; if (ActivityFrame == 0 @@ -159,7 +159,7 @@ PauseGame (void) LockMutex (GraphicsLock); OldContext = SetContext (ScreenContext); - OldHot = SetFrameHot (Screen, MAKE_HOT_SPOT (0, 0)); + oldOrigin = SetContextOrigin (MAKE_POINT (0, 0)); GetContextClipRect (&OldRect); SetContextClipRect (NULL); @@ -204,7 +204,7 @@ PauseGame (void) ClearSystemRect (); SetContextClipRect (&OldRect); - SetFrameHot (Screen, OldHot); + SetContextOrigin (oldOrigin); SetContext (OldContext); WaitForNoInput (ONE_SECOND / 4, TRUE);