make two-line miniWindows work

This commit is contained in:
ehouse 2004-02-28 05:25:21 +00:00
parent bef321eb6b
commit 1e8bc80851

View file

@ -625,6 +625,9 @@ ce_draw_drawTimer( DrawCtx* p_dctx, XP_Rect* rInner, XP_Rect* rOuter,
} }
} /* ce_draw_drawTimer */ } /* ce_draw_drawTimer */
/* #define LINE_BREAK XP_CR */
#define LINE_BREAK "\n"
static XP_UCHAR* static XP_UCHAR*
ce_draw_getMiniWText( DrawCtx* p_dctx, XWMiniTextType whichText ) ce_draw_getMiniWText( DrawCtx* p_dctx, XWMiniTextType whichText )
{ {
@ -640,7 +643,7 @@ ce_draw_getMiniWText( DrawCtx* p_dctx, XWMiniTextType whichText )
case BONUS_TRIPLE_WORD: case BONUS_TRIPLE_WORD:
str = "Triple word"; break; str = "Triple word"; break;
case INTRADE_MW_TEXT: case INTRADE_MW_TEXT:
str = "Trading tiles; tap 'D' when done"; break; str = "Trading tiles;" LINE_BREAK "select 'Turn done' when ready"; break;
default: default:
XP_ASSERT( XP_FALSE ); XP_ASSERT( XP_FALSE );
} }
@ -648,6 +651,7 @@ ce_draw_getMiniWText( DrawCtx* p_dctx, XWMiniTextType whichText )
return str; return str;
} /* ce_draw_getMiniWText */ } /* ce_draw_getMiniWText */
#define CE_MINI_V_PADDING 6
static void static void
ce_draw_measureMiniWText( DrawCtx* p_dctx, XP_UCHAR* str, ce_draw_measureMiniWText( DrawCtx* p_dctx, XP_UCHAR* str,
XP_U16* widthP, XP_U16* heightP ) XP_U16* widthP, XP_U16* heightP )
@ -655,16 +659,34 @@ ce_draw_measureMiniWText( DrawCtx* p_dctx, XP_UCHAR* str,
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx; CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
CEAppGlobals* globals = dctx->globals; CEAppGlobals* globals = dctx->globals;
HDC hdc = GetDC(dctx->mainWin);//globals->hdc; HDC hdc = GetDC(dctx->mainWin);//globals->hdc;
SIZE size; XP_Bool lastLine = XP_FALSE;
wchar_t widebuf[40]; XP_U16 height, maxWidth;
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, -1, for ( height = CE_MINI_V_PADDING, maxWidth = 0; ; ) {
widebuf, sizeof(widebuf)/sizeof(widebuf[0]) ); wchar_t widebuf[64];
XP_UCHAR* nextStr = strstr( str, LINE_BREAK );
GetTextExtentPoint32( hdc, widebuf, wcslen(widebuf), &size ); XP_U16 len = nextStr==NULL? strlen(str): nextStr - str;
SIZE size;
*widthP = size.cx + 12; XP_ASSERT( nextStr != str );
*heightP = size.cy + 4;
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, len,
widebuf, sizeof(widebuf)/sizeof(widebuf[0]) );
widebuf[len] = 0;
GetTextExtentPoint32( hdc, widebuf, wcslen(widebuf), &size );
maxWidth = XP_MAX( maxWidth, size.cx );
height += size.cy + 2;
dctx->miniLineHt = size.cy;
if ( nextStr == NULL ) {
break;
}
str = nextStr + XP_STRLEN(LINE_BREAK); /* skip '\n' */
}
*widthP = maxWidth + 8;
*heightP = height;
} /* ce_draw_measureMiniWText */ } /* ce_draw_measureMiniWText */
static void static void
@ -674,9 +696,9 @@ ce_draw_drawMiniWindow( DrawCtx* p_dctx, XP_UCHAR* text, XP_Rect* rect,
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx; CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
CEAppGlobals* globals = dctx->globals; CEAppGlobals* globals = dctx->globals;
HDC hdc; HDC hdc;
RECT rt; RECT rt, textRt;
PAINTSTRUCT ps; PAINTSTRUCT ps;
wchar_t widebuf[40]; wchar_t widebuf[64];
XPRtoRECT( &rt, rect ); XPRtoRECT( &rt, rect );
@ -689,14 +711,41 @@ ce_draw_drawMiniWindow( DrawCtx* p_dctx, XP_UCHAR* text, XP_Rect* rect,
ceClearToBkground( (CEDrawCtx*)p_dctx, rect ); ceClearToBkground( (CEDrawCtx*)p_dctx, rect );
SetBkColor( hdc, dctx->colors[BKG_COLOR] );
SetTextColor( hdc, dctx->colors[BLACK_COLOR] );
Rectangle( hdc, rt.left, rt.top, rt.right, rt.bottom ); Rectangle( hdc, rt.left, rt.top, rt.right, rt.bottom );
InsetRect( &rt, 1, 1 ); InsetRect( &rt, 1, 1 );
Rectangle( hdc, rt.left, rt.top, rt.right, rt.bottom ); Rectangle( hdc, rt.left, rt.top, rt.right, rt.bottom );
XP_MEMSET( widebuf, 0, sizeof(widebuf) ); textRt = rt;
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, text, -1, textRt.top += 2;
widebuf, sizeof(widebuf)/sizeof(widebuf[0]) ); InsetRect( &textRt, 3, 0 );
DrawText(hdc, widebuf, -1, &rt, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
for ( ; ; ) { /* draw up to the '\n' each time */
XP_UCHAR* nextStr = strstr( text, LINE_BREAK );
XP_U16 len;
if ( nextStr == NULL ) {
len = XP_STRLEN(text);
} else {
len = nextStr - text;
}
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, text, len,
widebuf, sizeof(widebuf)/sizeof(widebuf[0]) );
widebuf[len] = 0;
textRt.bottom = textRt.top + dctx->miniLineHt;
DrawText( hdc, widebuf, -1, &textRt, DT_CENTER | DT_VCENTER );
if ( nextStr == NULL ) {
break;
}
textRt.top = textRt.bottom + 2;
text = nextStr + XP_STRLEN(LINE_BREAK);
}
if ( !globals->hdc ) { if ( !globals->hdc ) {
EndPaint( dctx->mainWin, &ps ); EndPaint( dctx->mainWin, &ps );