Migrate flash-rect task to new drawing modes
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3478 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -404,6 +404,7 @@ extern FRAME SetRelFrameIndex (FRAME Frame, SIZE FrameOffs);
|
|||||||
extern FRAME SetEquFrameIndex (FRAME DstFrame, FRAME SrcFrame);
|
extern FRAME SetEquFrameIndex (FRAME DstFrame, FRAME SrcFrame);
|
||||||
extern FRAME IncFrameIndex (FRAME Frame);
|
extern FRAME IncFrameIndex (FRAME Frame);
|
||||||
extern FRAME DecFrameIndex (FRAME Frame);
|
extern FRAME DecFrameIndex (FRAME Frame);
|
||||||
|
extern DRAWABLE CloneFrame (FRAME Frame);
|
||||||
extern DRAWABLE RotateFrame (FRAME Frame, int angle_deg);
|
extern DRAWABLE RotateFrame (FRAME Frame, int angle_deg);
|
||||||
extern DRAWABLE RescaleFrame (FRAME, int width, int height);
|
extern DRAWABLE RescaleFrame (FRAME, int width, int height);
|
||||||
// This pair works for both paletted and trucolor frames
|
// This pair works for both paletted and trucolor frames
|
||||||
|
|||||||
@@ -296,19 +296,12 @@ GetFramePixel (FRAME frame, POINT pixelPt)
|
|||||||
pixelPt.x, pixelPt.y);
|
pixelPt.x, pixelPt.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new DRAWABLE of specified size and scales the passed
|
static FRAME
|
||||||
// frame onto it. The aspect ratio is not preserved.
|
makeMatchingFrame (FRAME frame, int width, int height)
|
||||||
DRAWABLE
|
|
||||||
RescaleFrame (FRAME frame, int width, int height)
|
|
||||||
{
|
{
|
||||||
DRAWABLE drawable;
|
DRAWABLE drawable;
|
||||||
FRAME newFrame;
|
FRAME newFrame;
|
||||||
CREATE_FLAGS flags;
|
CREATE_FLAGS flags;
|
||||||
TFB_Image *img;
|
|
||||||
TFB_Canvas src, dst;
|
|
||||||
|
|
||||||
if (!frame)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
flags = GetFrameParentDrawable (frame)->Flags;
|
flags = GetFrameParentDrawable (frame)->Flags;
|
||||||
drawable = CreateDrawable (flags, width, height, 1);
|
drawable = CreateDrawable (flags, width, height, 1);
|
||||||
@@ -321,6 +314,61 @@ RescaleFrame (FRAME frame, int width, int height)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return newFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creates an new DRAWABLE mostly identical to specified FRAME
|
||||||
|
DRAWABLE
|
||||||
|
CloneFrame (FRAME frame)
|
||||||
|
{
|
||||||
|
FRAME newFrame;
|
||||||
|
TFB_Image *img;
|
||||||
|
TFB_Canvas src, dst;
|
||||||
|
RECT r;
|
||||||
|
|
||||||
|
if (!frame)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
GetFrameRect (frame, &r);
|
||||||
|
r.corner.x = 0;
|
||||||
|
r.corner.y = 0;
|
||||||
|
|
||||||
|
newFrame = makeMatchingFrame (frame, r.extent.width, r.extent.height);
|
||||||
|
if (!newFrame)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// copy the hot-spot
|
||||||
|
newFrame->HotSpot = frame->HotSpot;
|
||||||
|
|
||||||
|
img = frame->image;
|
||||||
|
LockMutex (img->mutex);
|
||||||
|
|
||||||
|
// copy the pixels
|
||||||
|
src = img->NormalImg;
|
||||||
|
dst = newFrame->image->NormalImg;
|
||||||
|
TFB_DrawCanvas_CopyRect (src, &r, dst, MAKE_POINT (0, 0));
|
||||||
|
|
||||||
|
UnlockMutex (img->mutex);
|
||||||
|
|
||||||
|
return ReleaseDrawable (newFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creates a new DRAWABLE of specified size and scales the passed
|
||||||
|
// frame onto it. The aspect ratio is not preserved.
|
||||||
|
DRAWABLE
|
||||||
|
RescaleFrame (FRAME frame, int width, int height)
|
||||||
|
{
|
||||||
|
FRAME newFrame;
|
||||||
|
TFB_Image *img;
|
||||||
|
TFB_Canvas src, dst;
|
||||||
|
|
||||||
|
if (!frame)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
newFrame = makeMatchingFrame (frame, width, height);
|
||||||
|
if (!newFrame)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
// scale the hot-spot
|
// scale the hot-spot
|
||||||
newFrame->HotSpot.x = frame->HotSpot.x * width / frame->Bounds.width;
|
newFrame->HotSpot.x = frame->HotSpot.x * width / frame->Bounds.width;
|
||||||
newFrame->HotSpot.y = frame->HotSpot.y * height / frame->Bounds.height;
|
newFrame->HotSpot.y = frame->HotSpot.y * height / frame->Bounds.height;
|
||||||
@@ -334,9 +382,7 @@ RescaleFrame (FRAME frame, int width, int height)
|
|||||||
|
|
||||||
UnlockMutex (img->mutex);
|
UnlockMutex (img->mutex);
|
||||||
|
|
||||||
ReleaseDrawable (newFrame);
|
return ReleaseDrawable (newFrame);
|
||||||
|
|
||||||
return drawable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
|
|||||||
+29
-24
@@ -1583,10 +1583,6 @@ static FRAME flash_screen_frame = 0;
|
|||||||
// The original contents of the flash rectangle.
|
// The original contents of the flash rectangle.
|
||||||
static int flash_changed;
|
static int flash_changed;
|
||||||
Mutex flash_mutex = 0;
|
Mutex flash_mutex = 0;
|
||||||
// XXX: these are currently defined in libs/graphics/sdl/3do_getbody.c
|
|
||||||
// they should be sorted out and cleaned up at some point
|
|
||||||
extern void arith_frame_blit (FRAME srcFrame, const RECT *rsrc,
|
|
||||||
FRAME dstFrame, const RECT *rdst, int num, int denom);
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
flash_rect_func (void *data)
|
flash_rect_func (void *data)
|
||||||
@@ -1620,21 +1616,14 @@ flash_rect_func (void *data)
|
|||||||
LockMutex (flash_mutex);
|
LockMutex (flash_mutex);
|
||||||
if (flash_changed)
|
if (flash_changed)
|
||||||
{
|
{
|
||||||
RECT screen_rect;
|
|
||||||
cached_rect = flash_rect;
|
cached_rect = flash_rect;
|
||||||
if (cached_screen_frame)
|
if (cached_screen_frame)
|
||||||
DestroyDrawable (ReleaseDrawable (cached_screen_frame));
|
DestroyDrawable (ReleaseDrawable (cached_screen_frame));
|
||||||
flash_changed = 0;
|
flash_changed = 0;
|
||||||
// Wait for the flash_screen_frame to get initialized
|
// Wait for the flash_screen_frame to get initialized
|
||||||
FlushGraphics ();
|
FlushGraphics ();
|
||||||
GetFrameRect (flash_screen_frame, &screen_rect);
|
cached_screen_frame = CaptureDrawable (
|
||||||
cached_screen_frame = CaptureDrawable (CreateDrawable (
|
CloneFrame (flash_screen_frame));
|
||||||
WANT_PIXMAP, screen_rect.extent.width,
|
|
||||||
screen_rect.extent.height, 1));
|
|
||||||
screen_rect.corner.x = 0;
|
|
||||||
screen_rect.corner.y = 0;
|
|
||||||
arith_frame_blit (flash_screen_frame, &screen_rect,
|
|
||||||
cached_screen_frame, NULL, 0, 0);
|
|
||||||
UnlockMutex (flash_mutex);
|
UnlockMutex (flash_mutex);
|
||||||
|
|
||||||
// Clear the cache.
|
// Clear the cache.
|
||||||
@@ -1652,6 +1641,7 @@ flash_rect_func (void *data)
|
|||||||
if (cached_rect.extent.width)
|
if (cached_rect.extent.width)
|
||||||
{
|
{
|
||||||
STAMP *pStamp;
|
STAMP *pStamp;
|
||||||
|
|
||||||
#define MIN_STRENGTH 4
|
#define MIN_STRENGTH 4
|
||||||
#define MAX_STRENGTH 6
|
#define MAX_STRENGTH 6
|
||||||
strength += 2;
|
strength += 2;
|
||||||
@@ -1661,22 +1651,36 @@ flash_rect_func (void *data)
|
|||||||
pStamp = &cached_stamp[strength - MIN_STRENGTH];
|
pStamp = &cached_stamp[strength - MIN_STRENGTH];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RECT tmp_rect = cached_rect;
|
|
||||||
pStamp = &cached_stamp[strength - MIN_STRENGTH];
|
pStamp = &cached_stamp[strength - MIN_STRENGTH];
|
||||||
cached[strength - MIN_STRENGTH] = true;
|
cached[strength - MIN_STRENGTH] = true;
|
||||||
pStamp->frame = CaptureDrawable (CreateDrawable (WANT_PIXMAP,
|
pStamp->frame = CaptureDrawable (
|
||||||
cached_rect.extent.width, cached_rect.extent.height,
|
CloneFrame (cached_screen_frame));
|
||||||
1));
|
|
||||||
pStamp->origin.x = 0;
|
pStamp->origin.x = 0;
|
||||||
pStamp->origin.y = 0;
|
pStamp->origin.y = 0;
|
||||||
tmp_rect.corner.x = 0;
|
|
||||||
tmp_rect.corner.y = 0;
|
|
||||||
|
|
||||||
arith_frame_blit (cached_screen_frame, &tmp_rect,
|
|
||||||
pStamp->frame, &tmp_rect, 4, 4);
|
|
||||||
if (strength != 4)
|
if (strength != 4)
|
||||||
arith_frame_blit (cached_screen_frame, &tmp_rect,
|
{ // brighten the frame with an additive
|
||||||
pStamp->frame, &tmp_rect, strength, 4);
|
DrawMode oldMode;
|
||||||
|
STAMP s;
|
||||||
|
int factor;
|
||||||
|
|
||||||
|
s.origin.x = 0;
|
||||||
|
s.origin.y = 0;
|
||||||
|
s.frame = cached_screen_frame;
|
||||||
|
|
||||||
|
factor = (strength - MIN_STRENGTH) * DRAW_FACTOR_1 / 4;
|
||||||
|
|
||||||
|
LockMutex (GraphicsLock);
|
||||||
|
OldContext = SetContext (OffScreenContext);
|
||||||
|
SetContextFGFrame (pStamp->frame);
|
||||||
|
SetContextClipRect (NULL);
|
||||||
|
oldMode = SetContextDrawMode (MAKE_DRAW_MODE (
|
||||||
|
DRAW_ADDITIVE, factor));
|
||||||
|
DrawStamp (&s);
|
||||||
|
SetContextDrawMode (oldMode);
|
||||||
|
SetContext (OldContext);
|
||||||
|
UnlockMutex (GraphicsLock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LockMutex (GraphicsLock);
|
LockMutex (GraphicsLock);
|
||||||
@@ -1685,7 +1689,8 @@ flash_rect_func (void *data)
|
|||||||
// flash changed_can't be modified while GraphicSem is held
|
// flash changed_can't be modified while GraphicSem is held
|
||||||
if (!flash_changed)
|
if (!flash_changed)
|
||||||
DrawStamp (pStamp);
|
DrawStamp (pStamp);
|
||||||
SetContextClipRect (NULL); // this will flush whatever
|
// XXX: Shouldn't we save and restore the original cliprect?
|
||||||
|
SetContextClipRect (NULL);
|
||||||
SetContext (OldContext);
|
SetContext (OldContext);
|
||||||
UnlockMutex (GraphicsLock);
|
UnlockMutex (GraphicsLock);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user