Fixes the Blue Comm Screen problem (hopefully, once and for all); drawing subtitles to off-screen context instead of doing screen grabs

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1877 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2005-09-27 03:40:35 +00:00
parent b2eed518ed
commit 040ef1fd9b
2 changed files with 35 additions and 27 deletions
+34 -27
View File
@@ -127,7 +127,9 @@ static int subtitle_state = DONE_SUBTITLE;
static Mutex subtitle_mutex; static Mutex subtitle_mutex;
static const UNICODE * volatile last_subtitle; static const UNICODE * volatile last_subtitle;
static TFB_Image *subtitle_cache;
CONTEXT TextCacheContext;
FRAME TextCacheFrame;
/* _count_lines - sees how many lines a given input string would take to /* _count_lines - sees how many lines a given input string would take to
* display given the line wrapping information * display given the line wrapping information
@@ -167,28 +169,29 @@ add_text (int status, PTEXT pTextIn)
int num_lines = 0; int num_lines = 0;
static COORD last_baseline; static COORD last_baseline;
BOOLEAN eol; BOOLEAN eol;
CONTEXT OldContext;
BatchGraphics (); BatchGraphics ();
maxchars = (COUNT)~0; maxchars = (COUNT)~0;
if (status == 1) if (status == 1)
{ {
RECT r;
GetContextClipRect (&r);
if (last_subtitle == pTextIn->pStr) if (last_subtitle == pTextIn->pStr)
{ {
// draws cached subtitle // draws cached subtitle
TFB_DrawScreen_Image (subtitle_cache, r.corner.x, r.corner.y, 0, 0, TFB_SCREEN_MAIN); STAMP s;
s.origin.x = s.origin.y = 0;
s.frame = TextCacheFrame;
DrawStamp (&s);
UnbatchGraphics (); UnbatchGraphics ();
return last_baseline; return last_baseline;
} }
else else
{ {
// saves background to extra screen // draw to subtitle cache; prepare first
TFB_DrawScreen_Copy (&r, TFB_SCREEN_MAIN, TFB_SCREEN_EXTRA); OldContext = SetContext (TextCacheContext);
// fills screen with transparent color ClearDrawable ();
TFB_DrawScreen_Rect (&r, 0, 0, 128, TFB_SCREEN_MAIN);
last_subtitle = pTextIn->pStr; last_subtitle = pTextIn->pStr;
} }
@@ -303,16 +306,13 @@ add_text (int status, PTEXT pTextIn)
if (status == 1) if (status == 1)
{ {
RECT r; STAMP s;
GetContextClipRect (&r);
// copies subtitle to cache // we were drawing to cache -- flush to screen
TFB_DrawScreen_CopyToImage (subtitle_cache, &r, TFB_SCREEN_MAIN); SetContext (OldContext);
// restores background s.origin.x = s.origin.y = 0;
TFB_DrawScreen_Copy (&r, TFB_SCREEN_EXTRA, TFB_SCREEN_MAIN); s.frame = TextCacheFrame;
// draws cached subtitle DrawStamp (&s);
TFB_DrawScreen_Image (subtitle_cache, r.corner.x, r.corner.y, 0, 0,
TFB_SCREEN_MAIN);
last_baseline = pText->baseline.y; last_baseline = pText->baseline.y;
} }
@@ -548,15 +548,8 @@ xform_complete (void)
void void
init_communication (void) init_communication (void)
{ {
TFB_Canvas canvas;
subtitle_mutex = CreateMutex ("Subtitle Lock", SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO); subtitle_mutex = CreateMutex ("Subtitle Lock", SYNC_CLASS_TOPLEVEL | SYNC_CLASS_VIDEO);
init_xform_control (); init_xform_control ();
canvas = TFB_DrawCanvas_New_TrueColor (SIS_SCREEN_WIDTH,
SIS_SCREEN_HEIGHT - SLIDER_Y - SLIDER_HEIGHT + 2, FALSE);
subtitle_cache = TFB_DrawImage_New (canvas);
TFB_DrawCanvas_SetTransparentColor (subtitle_cache->NormalImg, 0, 0, 128, TRUE);
} }
void void
@@ -564,8 +557,6 @@ uninit_communication (void)
{ {
DestroyMutex (subtitle_mutex); DestroyMutex (subtitle_mutex);
uninit_xform_control (); uninit_xform_control ();
TFB_DrawImage_Delete (subtitle_cache);
subtitle_cache = NULL;
} }
static volatile BOOLEAN ColorChange; static volatile BOOLEAN ColorChange;
@@ -1968,6 +1959,7 @@ HailAlien (void)
ENCOUNTER_STATE ES; ENCOUNTER_STATE ES;
FONT PlayerFont, OldFont; FONT PlayerFont, OldFont;
MUSIC_REF SongRef = 0; MUSIC_REF SongRef = 0;
COLOR TextBack;
pCurInputState = &ES; pCurInputState = &ES;
memset (pCurInputState, 0, sizeof (*pCurInputState)); memset (pCurInputState, 0, sizeof (*pCurInputState));
@@ -1998,6 +1990,18 @@ HailAlien (void)
LoadStringTableInstance ((RESOURCE)CommData.ConversationPhrases) LoadStringTableInstance ((RESOURCE)CommData.ConversationPhrases)
); );
// init subtitle cache context
TextCacheContext = CaptureContext (CreateContext ());
TextCacheFrame = CaptureDrawable (CreateDrawable (WANT_PIXMAP | WANT_MASK,
SIS_SCREEN_WIDTH, SIS_SCREEN_HEIGHT - SLIDER_Y - SLIDER_HEIGHT + 2,
1));
SetContext (TextCacheContext);
SetContextFGFrame (TextCacheFrame);
TextBack = BUILD_COLOR (MAKE_RGB15 (0, 0, 0x10), 1);
SetContextBackGroundColor (TextBack);
ClearDrawable ();
SetFrameTransparentColor (TextCacheFrame, TextBack);
ES.phrase_buf_index = 1; ES.phrase_buf_index = 1;
ES.phrase_buf[0] = '\0'; ES.phrase_buf[0] = '\0';
@@ -2071,6 +2075,9 @@ HailAlien (void)
DestroyFont (ReleaseFont (CommData.AlienFont)); DestroyFont (ReleaseFont (CommData.AlienFont));
DestroyDrawable (ReleaseDrawable (CommData.AlienFrame)); DestroyDrawable (ReleaseDrawable (CommData.AlienFrame));
DestroyContext (ReleaseContext (TextCacheContext));
DestroyDrawable (ReleaseDrawable (TextCacheFrame));
SetContext (SpaceContext); SetContext (SpaceContext);
SetContextFont (OldFont); SetContextFont (OldFont);
DestroyFont (ReleaseFont (PlayerFont)); DestroyFont (ReleaseFont (PlayerFont));
+1
View File
@@ -246,6 +246,7 @@ 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 RotateFrame (FRAME Frame, COUNT angle); extern DRAWABLE RotateFrame (FRAME Frame, COUNT angle);
extern void SetFrameTransparentColor (FRAME Frame, COLOR c32k);
extern FRAME CaptureDrawable (DRAWABLE Drawable); extern FRAME CaptureDrawable (DRAWABLE Drawable);
extern DRAWABLE ReleaseDrawable (FRAME Frame); extern DRAWABLE ReleaseDrawable (FRAME Frame);