Uncoupled planet location selection from pMenuState and MENU_STATE

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3319 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-11-18 12:55:10 +00:00
parent fcb537e47f
commit 4a7f6c22f8
+45 -46
View File
@@ -51,6 +51,9 @@ extern FRAME SpaceJunkFrame;
CONTEXT ScanContext; CONTEXT ScanContext;
static POINT planetLoc; static POINT planetLoc;
static RECT cursorRect;
static FRAME eraseFrame;
void void
RepairBackRect (RECT *pRect) RepairBackRect (RECT *pRect)
@@ -496,56 +499,54 @@ PrintCoarseScan3DO (void)
} }
static void static void
initPlanetLocationImage (MENU_STATE *pMS) initPlanetLocationImage (void)
{ {
EXTENT size; EXTENT size;
FRAME cursorFrame;
// Get the cursor image // Get the cursor image
pMS->flash_frame0 = SetAbsFrameIndex (MiscDataFrame, FLASH_INDEX); cursorFrame = SetAbsFrameIndex (MiscDataFrame, FLASH_INDEX);
size.width = GetFrameWidth (pMS->flash_frame0); size.width = GetFrameWidth (cursorFrame);
size.height = GetFrameHeight (pMS->flash_frame0); size.height = GetFrameHeight (cursorFrame);
pMS->flash_rect0.extent = size; cursorRect.extent = size;
pMS->flash_frame1 = CaptureDrawable (CreateDrawable ( eraseFrame = CaptureDrawable (CreateDrawable (
WANT_PIXMAP | MAPPED_TO_DISPLAY, WANT_PIXMAP | MAPPED_TO_DISPLAY,
size.width, size.height, 1)); size.width, size.height, 1));
// copy the hotspot // copy the hotspot
SetFrameHot (pMS->flash_frame1, GetFrameHot (pMS->flash_frame0)); SetFrameHot (eraseFrame, GetFrameHot (cursorFrame));
} }
static void static void
savePlanetLocationImage (MENU_STATE *pMS) savePlanetLocationImage (void)
{ {
RECT r; RECT r;
HOT_SPOT hs = GetFrameHot (pMS->flash_frame1); HOT_SPOT hs = GetFrameHot (eraseFrame);
// Remember what we saved
pMS->flash_rect1.corner = pMS->flash_rect0.corner;
GetContextClipRect (&r); GetContextClipRect (&r);
r.corner.x += pMS->flash_rect1.corner.x - hs.x; r.corner.x += cursorRect.corner.x - hs.x;
r.corner.y += pMS->flash_rect1.corner.y - hs.y; r.corner.y += cursorRect.corner.y - hs.y;
r.extent = pMS->flash_rect0.extent; r.extent = cursorRect.extent;
LoadDisplayPixmap (&r, pMS->flash_frame1); LoadDisplayPixmap (&r, eraseFrame);
} }
static void static void
restorePlanetLocationImage (MENU_STATE *pMS) restorePlanetLocationImage (void)
{ {
STAMP s; STAMP s;
s.origin = pMS->flash_rect1.corner; s.origin = cursorRect.corner;
s.frame = pMS->flash_frame1; // saved image s.frame = eraseFrame; // saved image
DrawStamp (&s); DrawStamp (&s);
} }
static void static void
drawPlanetCursor (MENU_STATE *pMS, BOOLEAN filled) drawPlanetCursor (BOOLEAN filled)
{ {
STAMP s; STAMP s;
s.origin = pMS->flash_rect0.corner; s.origin = cursorRect.corner;
s.frame = pMS->flash_frame0; s.frame = SetAbsFrameIndex (MiscDataFrame, FLASH_INDEX);
if (filled) if (filled)
DrawFilledStamp (&s); DrawFilledStamp (&s);
else else
@@ -553,28 +554,26 @@ drawPlanetCursor (MENU_STATE *pMS, BOOLEAN filled)
} }
void void
setPlanetCursorLoc (MENU_STATE *pMS, POINT new_pt) setPlanetCursorLoc (POINT new_pt)
{ {
new_pt.x >>= MAG_SHIFT; new_pt.x >>= MAG_SHIFT;
new_pt.y >>= MAG_SHIFT; new_pt.y >>= MAG_SHIFT;
pMS->flash_rect0.corner = new_pt; cursorRect.corner = new_pt;
} }
static void static void
setPlanetLoc (MENU_STATE *pMS, POINT new_pt) setPlanetLoc (POINT new_pt)
{ {
planetLoc = new_pt; planetLoc = new_pt;
// Set the new flash location
setPlanetCursorLoc (pMS, new_pt);
SetContext (ScanContext); SetContext (ScanContext);
restorePlanetLocationImage (pMS); restorePlanetLocationImage ();
savePlanetLocationImage (pMS); setPlanetCursorLoc (new_pt);
savePlanetLocationImage ();
} }
static void static void
flashPlanetLocation (MENU_STATE *pMS) flashPlanetLocation (void)
{ {
#define FLASH_FRAME_DELAY (ONE_SECOND / 16) #define FLASH_FRAME_DELAY (ONE_SECOND / 16)
static BYTE c = 0x00; static BYTE c = 0x00;
@@ -584,8 +583,8 @@ flashPlanetLocation (MENU_STATE *pMS)
BOOLEAN locChanged; BOOLEAN locChanged;
TimeCount Now = GetTimeCounter (); TimeCount Now = GetTimeCounter ();
locChanged = prevPt.x != pMS->flash_rect0.corner.x locChanged = prevPt.x != cursorRect.corner.x
|| prevPt.y != pMS->flash_rect0.corner.y; || prevPt.y != cursorRect.corner.y;
if (!locChanged && Now < NextTime) if (!locChanged && Now < NextTime)
return; // nothing to do return; // nothing to do
@@ -594,7 +593,7 @@ flashPlanetLocation (MENU_STATE *pMS)
{ // Reset the flashing cycle { // Reset the flashing cycle
c = 0x00; c = 0x00;
val = -2; val = -2;
prevPt = pMS->flash_rect0.corner; prevPt = cursorRect.corner;
NextTime = Now + FLASH_FRAME_DELAY; NextTime = Now + FLASH_FRAME_DELAY;
} }
@@ -612,7 +611,7 @@ flashPlanetLocation (MENU_STATE *pMS)
SetContext (ScanContext); SetContext (ScanContext);
SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (c, c, c), c)); SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (c, c, c), c));
drawPlanetCursor (pMS, TRUE); drawPlanetCursor (TRUE);
} }
void void
@@ -627,9 +626,8 @@ RedrawSurfaceScan (const POINT *newLoc)
DrawScannedObjects (TRUE); DrawScannedObjects (TRUE);
if (newLoc) if (newLoc)
{ {
// TODO: Give scan its own STATE struct and pScanState (if needed) setPlanetLoc (*newLoc);
setPlanetLoc (pMenuState, *newLoc); drawPlanetCursor (FALSE);
drawPlanetCursor (pMenuState, FALSE);
} }
UnbatchGraphics (); UnbatchGraphics ();
@@ -663,8 +661,8 @@ PickPlanetSide (MENU_STATE *pMS)
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
SetContext (ScanContext); SetContext (ScanContext);
// Set the current flash location // Set the current flash location
setPlanetCursorLoc (pMS, planetLoc); setPlanetCursorLoc (planetLoc);
savePlanetLocationImage (pMS); savePlanetLocationImage ();
SetFlashRect (NULL); SetFlashRect (NULL);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
@@ -685,7 +683,7 @@ PickPlanetSide (MENU_STATE *pMS)
if (!select) if (!select)
{ // Bailing out { // Bailing out
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
restorePlanetLocationImage (pMS); restorePlanetLocationImage ();
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
} }
else else
@@ -702,7 +700,7 @@ PickPlanetSide (MENU_STATE *pMS)
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
DeltaSISGauges (0, -(SIZE)fuel_required, 0); DeltaSISGauges (0, -(SIZE)fuel_required, 0);
SetContext (ScanContext); SetContext (ScanContext);
drawPlanetCursor (pMS, FALSE); drawPlanetCursor (FALSE);
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
PlanetSide (planetLoc); PlanetSide (planetLoc);
@@ -798,10 +796,10 @@ ExitPlanetSide:
if (new_pt.x != planetLoc.x if (new_pt.x != planetLoc.x
|| new_pt.y != planetLoc.y) || new_pt.y != planetLoc.y)
{ {
setPlanetLoc (pMS, new_pt); setPlanetLoc (new_pt);
} }
flashPlanetLocation (pMS); flashPlanetLocation ();
UnbatchGraphics (); UnbatchGraphics ();
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);
@@ -1188,7 +1186,7 @@ ScanSystem (void)
ScanContext = CreateContext ("ScanContext"); ScanContext = CreateContext ("ScanContext");
SetContext (ScanContext); SetContext (ScanContext);
initPlanetLocationImage (&MenuState); initPlanetLocationImage ();
SetContextFGFrame (Screen); SetContextFGFrame (Screen);
r.corner.x = (SIS_ORG_X + SIS_SCREEN_WIDTH) - MAP_WIDTH; r.corner.x = (SIS_ORG_X + SIS_SCREEN_WIDTH) - MAP_WIDTH;
@@ -1216,7 +1214,8 @@ ScanSystem (void)
{ {
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
SetContext (SpaceContext); SetContext (SpaceContext);
DestroyDrawable (ReleaseDrawable (MenuState.flash_frame1)); DestroyDrawable (ReleaseDrawable (eraseFrame));
eraseFrame = NULL;
DestroyContext (ScanContext); DestroyContext (ScanContext);
ScanContext = NULL; ScanContext = NULL;
UnlockMutex (GraphicsLock); UnlockMutex (GraphicsLock);