Migrate context debugging graphics to new drawing modes

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3480 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-12-27 10:32:16 +00:00
parent 8d6dcb5568
commit 80f101bc9e
+9 -63
View File
@@ -1662,59 +1662,6 @@ hsvaToRgba (double hue, double sat, double val, BYTE alpha)
return BUILD_COLOR_RGBA (0, 0, 0, alpha); return BUILD_COLOR_RGBA (0, 0, 0, alpha);
} }
// Workaround. DrawFilledRectangle() doesn't handle transparency.
// We use a temporary frame to achieve the same thing.
static void
DrawFilledRectangleTransparent (RECT *rect, BYTE alpha)
{
extern void arith_frame_blit (FRAME srcFrame, const RECT *rsrc,
FRAME dstFrame, const RECT *rdst, int num, int denom);
RECT absRect;
FRAME orgRectFrame;
Color fillColor;
// Create a rectangle from 'rect', but with (0, 0) as origin.
absRect.corner.x = 0;
absRect.corner.y = 0;
absRect.extent = rect->extent;
// Create a new temporary FRAME to store the contents of the original
// rectangle in.
orgRectFrame = CaptureDrawable (CreateDrawable (
WANT_PIXMAP, rect->extent.width, rect->extent.height, 1));
// Copy the original rectangle, faded.
arith_frame_blit (GetContextFGFrame (), rect, orgRectFrame, &absRect,
255 - alpha, 255);
// Apply the transparency to the colour.
fillColor = GetContextForeGroundColor ();
fillColor.r = (fillColor.r * alpha + 127) / 255;
fillColor.g = (fillColor.g * alpha + 127) / 255;
fillColor.b = (fillColor.b * alpha + 127) / 255;
// Fill the frame with fillColor
{
Color oldFgColor = SetContextForeGroundColor (fillColor);
DrawFilledRectangle (rect);
SetContextForeGroundColor (oldFgColor);
FlushGraphics ();
// Not really necessary for the Context for which this
// function is called, but if this function is ever used
// to draw directly to the screen, this will be needed
// to make sure the rectangle is drawn before the
// arith_frame_blit() call, which is immediate.
}
// Blend in the original rectangle.
arith_frame_blit (orgRectFrame, &absRect, GetContextFGFrame (), rect,
1, -1);
// Destroy the temporary frame
DestroyDrawable (ReleaseDrawable (orgRectFrame));
}
// Returns true iff this context has a visible FRAME. // Returns true iff this context has a visible FRAME.
static bool static bool
isContextVisible (CONTEXT context) isContextVisible (CONTEXT context)
@@ -1758,6 +1705,7 @@ drawContext (CONTEXT context, double hue /* no pun intended */)
FRAME drawFrame; FRAME drawFrame;
CONTEXT oldContext; CONTEXT oldContext;
FONT oldFont; FONT oldFont;
DrawMode oldMode;
Color oldFgCol; Color oldFgCol;
Color rectCol; Color rectCol;
Color lineCol; Color lineCol;
@@ -1769,8 +1717,8 @@ drawContext (CONTEXT context, double hue /* no pun intended */)
POINT p1, p2, p3, p4; POINT p1, p2, p3, p4;
drawFrame = GetContextFGFrame (); drawFrame = GetContextFGFrame ();
rectCol = hsvaToRgba (hue, 1.0, 0.5, 127); rectCol = hsvaToRgba (hue, 1.0, 0.5, 100);
lineCol = hsvaToRgba (hue, 1.0, 1.0, 0); lineCol = hsvaToRgba (hue, 1.0, 1.0, 90);
textCol = lineCol; textCol = lineCol;
// Save the original context. // Save the original context.
@@ -1791,7 +1739,7 @@ drawContext (CONTEXT context, double hue /* no pun intended */)
p4.y = rect.corner.y + rect.extent.height - 1; p4.y = rect.corner.y + rect.extent.height - 1;
oldFgCol = SetContextForeGroundColor (rectCol); oldFgCol = SetContextForeGroundColor (rectCol);
DrawFilledRectangleTransparent (&rect, 63); DrawFilledRectangle (&rect);
SetContextForeGroundColor (lineCol); SetContextForeGroundColor (lineCol);
line.first = p1; line.second = p2; DrawLine (&line); line.first = p1; line.second = p2; DrawLine (&line);
@@ -1805,12 +1753,15 @@ drawContext (CONTEXT context, double hue /* no pun intended */)
oldFont = SetContextFont (TinyFont); oldFont = SetContextFont (TinyFont);
SetContextForeGroundColor (textCol); SetContextForeGroundColor (textCol);
// Text prim does not yet support alpha via Color.a
oldMode = SetContextDrawMode (MAKE_DRAW_MODE (DRAW_ALPHA, textCol.a));
text.baseline.x = (p1.x + (p2.x + 1)) / 2; text.baseline.x = (p1.x + (p2.x + 1)) / 2;
text.baseline.y = p1.y + 8; text.baseline.y = p1.y + 8;
text.pStr = GetContextName (context); text.pStr = GetContextName (context);
text.align = ALIGN_CENTER; text.align = ALIGN_CENTER;
text.CharCount = (COUNT) ~0; text.CharCount = (COUNT) ~0;
font_DrawText (&text); font_DrawText (&text);
(void) SetContextDrawMode (oldMode);
(void) SetContextForeGroundColor (oldFgCol); (void) SetContextForeGroundColor (oldFgCol);
(void) SetContextFont (oldFont); (void) SetContextFont (oldFont);
@@ -1891,8 +1842,6 @@ putScreen (FRAME savedFrame) {
void void
debugContexts (void) debugContexts (void)
{ {
extern void arith_frame_blit (FRAME srcFrame, const RECT *rsrc,
FRAME dstFrame, const RECT *rdst, int num, int denom);
static volatile bool inDebugContexts = false; static volatile bool inDebugContexts = false;
// Prevent this function from being called from within itself. // Prevent this function from being called from within itself.
@@ -1927,14 +1876,11 @@ debugContexts (void)
// Create a new frame to draw on. // Create a new frame to draw on.
debugDrawContext = CreateContext ("debugDrawContext"); debugDrawContext = CreateContext ("debugDrawContext");
debugDrawFrame = CaptureDrawable (CreateDrawable ( // New work frame is a copy of the original.
WANT_PIXMAP /*| WANT_ALPHA*/, ScreenWidth, ScreenHeight, 1)); debugDrawFrame = CaptureDrawable (CloneFrame (savedScreen));
orgContext = SetContext (debugDrawContext); orgContext = SetContext (debugDrawContext);
SetContextFGFrame (debugDrawFrame); SetContextFGFrame (debugDrawFrame);
// Fill the new frame with a copy of the original.
arith_frame_blit (savedScreen, NULL, debugDrawFrame, NULL, 1, 1);
hueIncrement = 360.0 / contextCount; hueIncrement = 360.0 / contextCount;
//LockMutex (GraphicsLock); //LockMutex (GraphicsLock);