mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-03 23:04:08 +01:00
first cut at supporting landscape mode by moving scoreboard to left edge of screen from top.
This commit is contained in:
parent
14c973354b
commit
58f4b08623
4 changed files with 260 additions and 162 deletions
|
@ -32,6 +32,9 @@
|
||||||
#define CE_TIMER_WIDTH 35
|
#define CE_TIMER_WIDTH 35
|
||||||
#define CE_SCORE_WIDTH (4 * 51)
|
#define CE_SCORE_WIDTH (4 * 51)
|
||||||
|
|
||||||
|
#define CE_TIMER_HT_HORIZ CE_SCORE_HEIGHT
|
||||||
|
#define CE_TIMER_HT_VERT CE_SCORE_WIDTH
|
||||||
|
|
||||||
#if 1 /* Palm-like case */
|
#if 1 /* Palm-like case */
|
||||||
|
|
||||||
#define CE_SCORE_TOP 0
|
#define CE_SCORE_TOP 0
|
||||||
|
|
213
wince/cedraw.c
213
wince/cedraw.c
|
@ -37,6 +37,9 @@
|
||||||
#define DRAW_FUNC_NAME(nam) ce_draw_ ## nam
|
#define DRAW_FUNC_NAME(nam) ce_draw_ ## nam
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define CE_MINI_V_PADDING 6
|
||||||
|
#define CE_INTERLINE_SPACE 0
|
||||||
|
|
||||||
static void ceClearToBkground( CEDrawCtx* dctx, const XP_Rect* rect );
|
static void ceClearToBkground( CEDrawCtx* dctx, const XP_Rect* rect );
|
||||||
static void ceDrawBitmapInRect( HDC hdc, const RECT* r, HBITMAP bitmap );
|
static void ceDrawBitmapInRect( HDC hdc, const RECT* r, HBITMAP bitmap );
|
||||||
|
|
||||||
|
@ -107,6 +110,73 @@ makeAndDrawBitmap( CEDrawCtx* dctx, HDC hdc, const RECT* bnds, XP_Bool center,
|
||||||
#endif
|
#endif
|
||||||
} /* makeAndDrawBitmap */
|
} /* makeAndDrawBitmap */
|
||||||
|
|
||||||
|
static void
|
||||||
|
measureText( CEDrawCtx* dctx, const XP_UCHAR* str,
|
||||||
|
XP_U16* widthP, XP_U16* heightP )
|
||||||
|
{
|
||||||
|
HDC hdc = GetDC(dctx->mainWin);//globals->hdc;
|
||||||
|
XP_U16 height, maxWidth;
|
||||||
|
|
||||||
|
for ( height = CE_MINI_V_PADDING, maxWidth = 0; ; ) {
|
||||||
|
wchar_t widebuf[64];
|
||||||
|
XP_UCHAR* nextStr = strstr( str, XP_CR );
|
||||||
|
XP_U16 len = nextStr==NULL? strlen(str): nextStr - str;
|
||||||
|
SIZE size;
|
||||||
|
|
||||||
|
XP_ASSERT( nextStr != str );
|
||||||
|
|
||||||
|
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, len,
|
||||||
|
widebuf, sizeof(widebuf)/sizeof(widebuf[0]) );
|
||||||
|
widebuf[len] = 0;
|
||||||
|
GetTextExtentPoint32( hdc, widebuf, wcslen(widebuf), &size );
|
||||||
|
|
||||||
|
maxWidth = (XP_U16)XP_MAX( maxWidth, size.cx );
|
||||||
|
height += size.cy + CE_INTERLINE_SPACE;
|
||||||
|
dctx->miniLineHt = (XP_U16)size.cy;
|
||||||
|
|
||||||
|
if ( nextStr == NULL ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
str = nextStr + XP_STRLEN(XP_CR); /* skip '\n' */
|
||||||
|
}
|
||||||
|
|
||||||
|
*widthP = maxWidth + 8;
|
||||||
|
*heightP = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
drawLines( CEDrawCtx* dctx, HDC hdc, const XP_UCHAR* text, const RECT* rp,
|
||||||
|
int flags )
|
||||||
|
{
|
||||||
|
wchar_t widebuf[128];
|
||||||
|
RECT textRt = *rp;
|
||||||
|
|
||||||
|
for ( ; ; ) { /* draw up to the '\n' each time */
|
||||||
|
XP_UCHAR* nextStr = strstr( text, XP_CR );
|
||||||
|
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, flags );
|
||||||
|
|
||||||
|
if ( nextStr == NULL ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
textRt.top = textRt.bottom + CE_INTERLINE_SPACE;
|
||||||
|
text = nextStr + XP_STRLEN(XP_CR);
|
||||||
|
}
|
||||||
|
} /* drawLines */
|
||||||
|
|
||||||
DLSTATIC XP_Bool
|
DLSTATIC XP_Bool
|
||||||
DRAW_FUNC_NAME(boardBegin)( DrawCtx* p_dctx, const DictionaryCtxt* dict,
|
DRAW_FUNC_NAME(boardBegin)( DrawCtx* p_dctx, const DictionaryCtxt* dict,
|
||||||
const XP_Rect* rect, XP_Bool hasfocus )
|
const XP_Rect* rect, XP_Bool hasfocus )
|
||||||
|
@ -278,6 +348,7 @@ DRAW_FUNC_NAME(invertCell)( DrawCtx* p_dctx, const XP_Rect* rect )
|
||||||
} /* ce_draw_invertCell */
|
} /* ce_draw_invertCell */
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
#if 0
|
||||||
static char*
|
static char*
|
||||||
logClipResult( int icrResult )
|
logClipResult( int icrResult )
|
||||||
{
|
{
|
||||||
|
@ -292,6 +363,7 @@ logClipResult( int icrResult )
|
||||||
return "unknown";
|
return "unknown";
|
||||||
} /* logClipResult */
|
} /* logClipResult */
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
DLSTATIC XP_Bool
|
DLSTATIC XP_Bool
|
||||||
DRAW_FUNC_NAME(trayBegin)( DrawCtx* p_dctx, const XP_Rect* rect, XP_U16 owner,
|
DRAW_FUNC_NAME(trayBegin)( DrawCtx* p_dctx, const XP_Rect* rect, XP_U16 owner,
|
||||||
|
@ -496,20 +568,24 @@ DRAW_FUNC_NAME(scoreBegin)( DrawCtx* p_dctx, const XP_Rect* rect,
|
||||||
HDC hdc = globals->hdc;
|
HDC hdc = globals->hdc;
|
||||||
SetBkColor( hdc, dctx->globals->appPrefs.colors[BKG_COLOR] );
|
SetBkColor( hdc, dctx->globals->appPrefs.colors[BKG_COLOR] );
|
||||||
|
|
||||||
|
dctx->scoreIsVertical = rect->height > rect->width;
|
||||||
|
|
||||||
ceClearToBkground( (CEDrawCtx*)p_dctx, rect );
|
ceClearToBkground( (CEDrawCtx*)p_dctx, rect );
|
||||||
} /* ce_draw_scoreBegin */
|
} /* ce_draw_scoreBegin */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
formatRemText( HDC hdc, wchar_t* buf, XP_S16 nTilesLeft, SIZE* size )
|
formatRemText( HDC hdc, XP_S16 nTilesLeft, XP_Bool isVertical, XP_UCHAR* buf )
|
||||||
{
|
{
|
||||||
wchar_t* format = L"Rem:%d";
|
|
||||||
|
|
||||||
if ( nTilesLeft <= 0 ) {
|
if ( nTilesLeft <= 0 ) {
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
size->cx = size->cy = 0;
|
|
||||||
} else {
|
} else {
|
||||||
swprintf( buf, format, nTilesLeft );
|
char* fmt;
|
||||||
GetTextExtentPoint32( hdc, buf, wcslen(buf), size );
|
if ( isVertical ) {
|
||||||
|
fmt = "Rem" XP_CR "%d";
|
||||||
|
} else {
|
||||||
|
fmt = "Rem:%d";
|
||||||
|
}
|
||||||
|
sprintf( buf, fmt, nTilesLeft );
|
||||||
}
|
}
|
||||||
} /* formatRemText */
|
} /* formatRemText */
|
||||||
|
|
||||||
|
@ -521,13 +597,10 @@ DRAW_FUNC_NAME(measureRemText)( DrawCtx* p_dctx, const XP_Rect* r,
|
||||||
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
|
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
|
||||||
CEAppGlobals* globals = dctx->globals;
|
CEAppGlobals* globals = dctx->globals;
|
||||||
HDC hdc = globals->hdc;
|
HDC hdc = globals->hdc;
|
||||||
wchar_t buf[16];
|
XP_UCHAR buf[16];
|
||||||
SIZE size;
|
|
||||||
|
|
||||||
formatRemText( hdc, buf, nTilesLeft, &size );
|
formatRemText( hdc, nTilesLeft, dctx->scoreIsVertical, buf );
|
||||||
|
measureText( dctx, buf, width, height );
|
||||||
*width = (XP_U16)size.cx + 1; /* 1: don't write up against edge */
|
|
||||||
*height = (XP_U16)size.cy;
|
|
||||||
} /* ce_draw_measureRemText */
|
} /* ce_draw_measureRemText */
|
||||||
|
|
||||||
DLSTATIC void
|
DLSTATIC void
|
||||||
|
@ -537,44 +610,45 @@ DRAW_FUNC_NAME(drawRemText)( DrawCtx* p_dctx, const XP_Rect* rInner,
|
||||||
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
|
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
|
||||||
CEAppGlobals* globals = dctx->globals;
|
CEAppGlobals* globals = dctx->globals;
|
||||||
HDC hdc = globals->hdc;
|
HDC hdc = globals->hdc;
|
||||||
wchar_t buf[16];
|
XP_UCHAR buf[16];
|
||||||
RECT rt;
|
RECT rt;
|
||||||
SIZE size;
|
|
||||||
|
|
||||||
formatRemText( hdc, buf, nTilesLeft, &size );
|
formatRemText( hdc, nTilesLeft, dctx->scoreIsVertical, buf );
|
||||||
|
|
||||||
XPRtoRECT( &rt, rInner );
|
XPRtoRECT( &rt, rInner );
|
||||||
++rt.left; /* 1: don't write up against edge */
|
++rt.left; /* 1: don't write up against edge */
|
||||||
DrawText( hdc, buf, -1, &rt, DT_SINGLELINE | DT_LEFT | DT_VCENTER);
|
drawLines( dctx, hdc, buf, &rt, DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_CENTER );
|
||||||
} /* ce_draw_drawRemText */
|
} /* ce_draw_drawRemText */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ceWidthAndText( HDC hdc, wchar_t* buf, const DrawScoreInfo* dsi,
|
ceWidthAndText( CEDrawCtx* dctx, HDC hdc, const DrawScoreInfo* dsi, XP_Bool isVertical,
|
||||||
XP_U16* widthP, XP_U16* heightP )
|
XP_UCHAR* buf, XP_U16* widthP, XP_U16* heightP )
|
||||||
{
|
{
|
||||||
XP_UCHAR borders[] = {'•', '\0'};
|
XP_UCHAR borders[] = {'•', '\0'};
|
||||||
XP_UCHAR tilesLeftTxt[8];
|
XP_UCHAR tilesLeftTxt[8];
|
||||||
XP_UCHAR tbuf[10]; /* *9999:7* is 8 chars */
|
|
||||||
SIZE size;
|
|
||||||
XP_U16 len;
|
|
||||||
|
|
||||||
if ( !dsi->isTurn ) {
|
if ( !dsi->isTurn ) {
|
||||||
borders[0] = '\0';
|
borders[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( isVertical ) {
|
||||||
|
sprintf( buf, "%d", dsi->score );
|
||||||
|
XP_LOGF( "%s: write %s", __FUNCTION__, buf );
|
||||||
|
if ( dsi->nTilesLeft >= 0 ) {
|
||||||
|
XP_UCHAR smallBuf[32];
|
||||||
|
sprintf( smallBuf, XP_CR "%s%d%s", borders, dsi->nTilesLeft, borders );
|
||||||
|
strcat( buf, smallBuf );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if ( dsi->nTilesLeft >= 0 ) {
|
if ( dsi->nTilesLeft >= 0 ) {
|
||||||
sprintf( tilesLeftTxt, ":%d", dsi->nTilesLeft );
|
sprintf( tilesLeftTxt, ":%d", dsi->nTilesLeft );
|
||||||
} else {
|
} else {
|
||||||
tilesLeftTxt[0] = '\0';
|
tilesLeftTxt[0] = '\0';
|
||||||
}
|
}
|
||||||
sprintf( tbuf, "%s%d%s%s", borders, dsi->score, tilesLeftTxt, borders );
|
sprintf( buf, "%s%d%s%s", borders, dsi->score, tilesLeftTxt, borders );
|
||||||
|
}
|
||||||
|
|
||||||
len = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, tbuf, -1,
|
measureText( dctx, buf, widthP, heightP );
|
||||||
buf, 10 );
|
|
||||||
|
|
||||||
GetTextExtentPoint32( hdc, buf, len, &size );
|
|
||||||
*widthP = (XP_U16)size.cx;
|
|
||||||
*heightP = (XP_U16)size.cy;
|
|
||||||
} /* ceWidthAndText */
|
} /* ceWidthAndText */
|
||||||
|
|
||||||
DLSTATIC void
|
DLSTATIC void
|
||||||
|
@ -585,7 +659,7 @@ DRAW_FUNC_NAME(measureScoreText)( DrawCtx* p_dctx, const XP_Rect* r,
|
||||||
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
|
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
|
||||||
CEAppGlobals* globals = dctx->globals;
|
CEAppGlobals* globals = dctx->globals;
|
||||||
HDC hdc = globals->hdc;
|
HDC hdc = globals->hdc;
|
||||||
wchar_t widebuf[10];
|
XP_UCHAR buf[16];
|
||||||
HFONT newFont;
|
HFONT newFont;
|
||||||
HFONT oldFont;
|
HFONT oldFont;
|
||||||
|
|
||||||
|
@ -596,7 +670,8 @@ DRAW_FUNC_NAME(measureScoreText)( DrawCtx* p_dctx, const XP_Rect* r,
|
||||||
}
|
}
|
||||||
oldFont = SelectObject( hdc, newFont );
|
oldFont = SelectObject( hdc, newFont );
|
||||||
|
|
||||||
ceWidthAndText( hdc, widebuf, dsi, widthP, heightP );
|
ceWidthAndText( dctx, hdc, dsi, dctx->scoreIsVertical,
|
||||||
|
buf, widthP, heightP );
|
||||||
|
|
||||||
SelectObject( hdc, oldFont );
|
SelectObject( hdc, oldFont );
|
||||||
} /* ce_draw_measureScoreText */
|
} /* ce_draw_measureScoreText */
|
||||||
|
@ -611,7 +686,7 @@ DRAW_FUNC_NAME(score_drawPlayer)( DrawCtx* p_dctx,
|
||||||
HDC hdc = globals->hdc;
|
HDC hdc = globals->hdc;
|
||||||
RECT rt;
|
RECT rt;
|
||||||
XP_U16 width, height;
|
XP_U16 width, height;
|
||||||
wchar_t scoreBuf[20];
|
XP_UCHAR scoreBuf[20];
|
||||||
HFONT newFont;
|
HFONT newFont;
|
||||||
HFONT oldFont;
|
HFONT oldFont;
|
||||||
|
|
||||||
|
@ -626,9 +701,10 @@ DRAW_FUNC_NAME(score_drawPlayer)( DrawCtx* p_dctx,
|
||||||
SetTextColor( hdc, dctx->globals->
|
SetTextColor( hdc, dctx->globals->
|
||||||
appPrefs.colors[getPlayerColor(dsi->playerNum)] );
|
appPrefs.colors[getPlayerColor(dsi->playerNum)] );
|
||||||
|
|
||||||
ceWidthAndText( hdc, scoreBuf, dsi, &width, &height );
|
ceWidthAndText( dctx, hdc, dsi, dctx->scoreIsVertical,
|
||||||
DrawText( hdc, scoreBuf, -1, &rt,
|
scoreBuf, &width, &height );
|
||||||
DT_SINGLELINE | DT_VCENTER | DT_CENTER );
|
|
||||||
|
drawLines( dctx, hdc, scoreBuf, &rt, DT_SINGLELINE | DT_VCENTER | DT_CENTER );
|
||||||
|
|
||||||
SelectObject( hdc, oldFont );
|
SelectObject( hdc, oldFont );
|
||||||
} /* ce_draw_score_drawPlayer */
|
} /* ce_draw_score_drawPlayer */
|
||||||
|
@ -680,7 +756,7 @@ DRAW_FUNC_NAME(drawTimer)( DrawCtx* p_dctx,
|
||||||
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
|
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
|
||||||
CEAppGlobals* globals = dctx->globals;
|
CEAppGlobals* globals = dctx->globals;
|
||||||
HDC hdc = globals->hdc;
|
HDC hdc = globals->hdc;
|
||||||
wchar_t widebuf[10];
|
XP_UCHAR buf[16];
|
||||||
XP_U16 mins, secs;
|
XP_U16 mins, secs;
|
||||||
RECT rt;
|
RECT rt;
|
||||||
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
||||||
|
@ -696,7 +772,9 @@ DRAW_FUNC_NAME(drawTimer)( DrawCtx* p_dctx,
|
||||||
mins = secondsLeft / 60;
|
mins = secondsLeft / 60;
|
||||||
secs = secondsLeft % 60;
|
secs = secondsLeft % 60;
|
||||||
|
|
||||||
swprintf( widebuf, L"%s%.1d:%.2d", isNegative? L"-": L"", mins, secs );
|
snprintf( buf, sizeof(buf),
|
||||||
|
dctx->scoreIsVertical? "%s%.1dm" XP_CR "%.2ds" : "%s%.1d:%.2d",
|
||||||
|
isNegative? "-": "", mins, secs );
|
||||||
|
|
||||||
if ( !globals->hdc ) {
|
if ( !globals->hdc ) {
|
||||||
InvalidateRect( dctx->mainWin, &rt, FALSE );
|
InvalidateRect( dctx->mainWin, &rt, FALSE );
|
||||||
|
@ -705,7 +783,7 @@ DRAW_FUNC_NAME(drawTimer)( DrawCtx* p_dctx,
|
||||||
|
|
||||||
SetTextColor( hdc, dctx->globals->appPrefs.colors[getPlayerColor(player)] );
|
SetTextColor( hdc, dctx->globals->appPrefs.colors[getPlayerColor(player)] );
|
||||||
ceClearToBkground( dctx, rInner );
|
ceClearToBkground( dctx, rInner );
|
||||||
DrawText( hdc, widebuf, -1, &rt, DT_SINGLELINE | DT_VCENTER | DT_RIGHT);
|
drawLines( dctx, hdc, buf, &rt, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
|
||||||
|
|
||||||
if ( !globals->hdc ) {
|
if ( !globals->hdc ) {
|
||||||
EndPaint( dctx->mainWin, &ps );
|
EndPaint( dctx->mainWin, &ps );
|
||||||
|
@ -735,44 +813,12 @@ DRAW_FUNC_NAME(getMiniWText)( DrawCtx* p_dctx, XWMiniTextType whichText )
|
||||||
return str;
|
return str;
|
||||||
} /* ce_draw_getMiniWText */
|
} /* ce_draw_getMiniWText */
|
||||||
|
|
||||||
#define CE_MINI_V_PADDING 6
|
|
||||||
#define CE_INTERLINE_SPACE 0
|
|
||||||
|
|
||||||
DLSTATIC void
|
DLSTATIC void
|
||||||
DRAW_FUNC_NAME(measureMiniWText)( DrawCtx* p_dctx, const XP_UCHAR* str,
|
DRAW_FUNC_NAME(measureMiniWText)( DrawCtx* p_dctx, const XP_UCHAR* str,
|
||||||
XP_U16* widthP, XP_U16* heightP )
|
XP_U16* widthP, XP_U16* heightP )
|
||||||
{
|
{
|
||||||
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
|
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
|
||||||
CEAppGlobals* globals = dctx->globals;
|
measureText( dctx, str, widthP, heightP );
|
||||||
HDC hdc = GetDC(dctx->mainWin);//globals->hdc;
|
|
||||||
XP_Bool lastLine = XP_FALSE;
|
|
||||||
XP_U16 height, maxWidth;
|
|
||||||
|
|
||||||
for ( height = CE_MINI_V_PADDING, maxWidth = 0; ; ) {
|
|
||||||
wchar_t widebuf[64];
|
|
||||||
XP_UCHAR* nextStr = strstr( str, XP_CR );
|
|
||||||
XP_U16 len = nextStr==NULL? strlen(str): nextStr - str;
|
|
||||||
SIZE size;
|
|
||||||
|
|
||||||
XP_ASSERT( nextStr != str );
|
|
||||||
|
|
||||||
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, len,
|
|
||||||
widebuf, sizeof(widebuf)/sizeof(widebuf[0]) );
|
|
||||||
widebuf[len] = 0;
|
|
||||||
GetTextExtentPoint32( hdc, widebuf, wcslen(widebuf), &size );
|
|
||||||
|
|
||||||
maxWidth = (XP_U16)XP_MAX( maxWidth, size.cx );
|
|
||||||
height += size.cy + CE_INTERLINE_SPACE;
|
|
||||||
dctx->miniLineHt = (XP_U16)size.cy;
|
|
||||||
|
|
||||||
if ( nextStr == NULL ) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
str = nextStr + XP_STRLEN(XP_CR); /* skip '\n' */
|
|
||||||
}
|
|
||||||
|
|
||||||
*widthP = maxWidth + 8;
|
|
||||||
*heightP = height;
|
|
||||||
} /* ce_draw_measureMiniWText */
|
} /* ce_draw_measureMiniWText */
|
||||||
|
|
||||||
DLSTATIC void
|
DLSTATIC void
|
||||||
|
@ -784,7 +830,6 @@ DRAW_FUNC_NAME(drawMiniWindow)( DrawCtx* p_dctx, const XP_UCHAR* text,
|
||||||
HDC hdc;
|
HDC hdc;
|
||||||
RECT rt, textRt;
|
RECT rt, textRt;
|
||||||
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
||||||
wchar_t widebuf[64];
|
|
||||||
|
|
||||||
XPRtoRECT( &rt, rect );
|
XPRtoRECT( &rt, rect );
|
||||||
|
|
||||||
|
@ -808,30 +853,7 @@ DRAW_FUNC_NAME(drawMiniWindow)( DrawCtx* p_dctx, const XP_UCHAR* text,
|
||||||
textRt.top += 2;
|
textRt.top += 2;
|
||||||
InsetRect( &textRt, 3, 0 );
|
InsetRect( &textRt, 3, 0 );
|
||||||
|
|
||||||
for ( ; ; ) { /* draw up to the '\n' each time */
|
drawLines( dctx, hdc, text, &textRt, DT_CENTER | DT_VCENTER );
|
||||||
XP_UCHAR* nextStr = strstr( text, XP_CR );
|
|
||||||
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 + CE_INTERLINE_SPACE;
|
|
||||||
text = nextStr + XP_STRLEN(XP_CR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !globals->hdc ) {
|
if ( !globals->hdc ) {
|
||||||
EndPaint( dctx->mainWin, &ps );
|
EndPaint( dctx->mainWin, &ps );
|
||||||
|
@ -922,7 +944,6 @@ ce_drawctxt_make( MPFORMAL HWND mainWin, CEAppGlobals* globals )
|
||||||
{
|
{
|
||||||
CEDrawCtx* dctx = (CEDrawCtx*)XP_MALLOC( mpool,
|
CEDrawCtx* dctx = (CEDrawCtx*)XP_MALLOC( mpool,
|
||||||
sizeof(*dctx) );
|
sizeof(*dctx) );
|
||||||
XP_U16 i;
|
|
||||||
|
|
||||||
#ifndef DRAW_LINK_DIRECT
|
#ifndef DRAW_LINK_DIRECT
|
||||||
dctx->vtable = (DrawCtxVTable*)XP_MALLOC( mpool, sizeof(*((dctx)->vtable)));
|
dctx->vtable = (DrawCtxVTable*)XP_MALLOC( mpool, sizeof(*((dctx)->vtable)));
|
||||||
|
|
187
wince/cemain.c
187
wince/cemain.c
|
@ -371,98 +371,171 @@ hideScroller( CEAppGlobals* globals )
|
||||||
#define MIN_CELL_HEIGHT 12
|
#define MIN_CELL_HEIGHT 12
|
||||||
#if defined TARGET_OS_WINCE
|
#if defined TARGET_OS_WINCE
|
||||||
# define MIN_TRAY_HEIGHT 20
|
# define MIN_TRAY_HEIGHT 20
|
||||||
|
# define CE_MIN_SCORE_WIDTH 20 /* for vertical score case */
|
||||||
#elif defined TARGET_OS_WIN32
|
#elif defined TARGET_OS_WIN32
|
||||||
# define MIN_TRAY_HEIGHT 40
|
# define MIN_TRAY_HEIGHT 40
|
||||||
|
# define CE_MIN_SCORE_WIDTH 34
|
||||||
#endif
|
#endif
|
||||||
#define TRAY_PADDING 1
|
#define TRAY_PADDING 1
|
||||||
|
|
||||||
typedef struct CEBoardParms {
|
typedef struct CEBoardParms {
|
||||||
XP_U16 boardHScale;
|
XP_U16 boardHScale;
|
||||||
XP_U16 boardVScale;
|
XP_U16 boardVScale;
|
||||||
|
XP_U16 boardTop;
|
||||||
XP_U16 trayTop;
|
XP_U16 trayTop;
|
||||||
XP_U16 trayVScale;
|
|
||||||
XP_U16 trayHScale;
|
XP_U16 trayHeight;
|
||||||
XP_U16 leftEdge;
|
XP_U16 trayWidth;
|
||||||
|
|
||||||
|
XP_U16 timerLeft, timerTop, timerWidth, timerHeight;
|
||||||
|
|
||||||
|
XP_U16 boardLeft, trayLeft;
|
||||||
XP_U16 scoreWidth;
|
XP_U16 scoreWidth;
|
||||||
XP_U16 scoreHeight;
|
XP_U16 scoreHeight;
|
||||||
XP_Bool needsScroller;
|
XP_Bool needsScroller;
|
||||||
|
XP_Bool horiz;
|
||||||
} CEBoardParms;
|
} CEBoardParms;
|
||||||
|
|
||||||
|
static XP_U16
|
||||||
|
sizeBoard( XP_U16* bdHeightP, /* INOUT */
|
||||||
|
XP_U16* nRowsP, /* INOUT: on OUT, gives nRowsVisible */
|
||||||
|
XP_U16* scrollWidthP )
|
||||||
|
{
|
||||||
|
/* given the initial max board height, figure how many rows are visible
|
||||||
|
and the adjusted heights of the board and tray. */
|
||||||
|
XP_U16 bdHeight = *bdHeightP;
|
||||||
|
XP_U16 nVisibleRows = *nRowsP;
|
||||||
|
XP_U16 vScale;
|
||||||
|
XP_U16 boardHtLimit;
|
||||||
|
|
||||||
|
*scrollWidthP = 0;
|
||||||
|
|
||||||
|
vScale = bdHeight / nVisibleRows;
|
||||||
|
if ( vScale < MIN_CELL_HEIGHT ) {
|
||||||
|
vScale = MIN_CELL_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now adjust tray height to make board height a multiple */
|
||||||
|
boardHtLimit = nVisibleRows * vScale;
|
||||||
|
while ( boardHtLimit > bdHeight ) {
|
||||||
|
boardHtLimit -= vScale;
|
||||||
|
--nVisibleRows;
|
||||||
|
*scrollWidthP = SCROLLBAR_WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
*bdHeightP = boardHtLimit;
|
||||||
|
*nRowsP = nVisibleRows;
|
||||||
|
return vScale;
|
||||||
|
} /* sizeBoard */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
figureBoardParms( CEAppGlobals* globals, XP_U16 nCols, CEBoardParms* bparms )
|
figureBoardParms( CEAppGlobals* globals, XP_U16 nRows, CEBoardParms* bparms )
|
||||||
{
|
{
|
||||||
RECT rc;
|
RECT rc;
|
||||||
XP_U16 width, height;
|
XP_U16 scrnWidth, scrnHeight;
|
||||||
XP_U16 trayVScale, leftEdge, scoreWidth;
|
XP_U16 trayVScale, boardLeft, scoreWidth, scoreHeight;
|
||||||
XP_U16 boardHt, boardWidth, visBoardHt, hScale, vScale, nHiddenRows;
|
XP_U16 boardHt, boardWidth, visBoardHt, hScale, vScale, nVisibleRows;
|
||||||
XP_U16 boardHtLimit, trayTop;
|
XP_U16 boardHtLimit, trayTop, boardTop;
|
||||||
XP_Bool needsScroller;
|
XP_Bool horiz;
|
||||||
|
XP_U16 trayWidth;
|
||||||
|
XP_U16 scrollWidth = 0;
|
||||||
|
|
||||||
GetClientRect( globals->hWnd, &rc );
|
GetClientRect( globals->hWnd, &rc );
|
||||||
boardWidth = width = (XP_U16)(rc.right - rc.left);
|
#if 1
|
||||||
height = (XP_U16)(rc.bottom - rc.top);
|
#ifndef _WIN32_WCE
|
||||||
|
{
|
||||||
|
int width = rc.right - rc.left;
|
||||||
|
int height = rc.bottom - rc.top;
|
||||||
|
if ( width > height ) {
|
||||||
|
width = (height * 3) / 4;
|
||||||
|
rc.right = rc.left + width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
boardHt = height - CE_SCORE_HEIGHT - MIN_TRAY_HEIGHT;
|
scrnWidth = (XP_U16)(rc.right - rc.left);
|
||||||
|
scrnHeight = (XP_U16)(rc.bottom - rc.top);
|
||||||
|
|
||||||
|
horiz = (scrnHeight - CE_SCORE_HEIGHT) >= (scrnWidth - CE_MIN_SCORE_WIDTH);
|
||||||
|
nVisibleRows = nRows;
|
||||||
|
|
||||||
|
if ( horiz ) {
|
||||||
|
scoreHeight = horiz? CE_SCORE_HEIGHT : 0;
|
||||||
|
}
|
||||||
|
boardTop = scoreHeight;
|
||||||
|
|
||||||
/* Try to make it fit without scrolling. But if necessary, reduce the
|
/* Try to make it fit without scrolling. But if necessary, reduce the
|
||||||
width for a scrollbar. */
|
width for a scrollbar. */
|
||||||
vScale = boardHt / nCols;
|
boardHt = scrnHeight - scoreHeight - MIN_TRAY_HEIGHT;
|
||||||
needsScroller = vScale < MIN_CELL_HEIGHT;
|
vScale = sizeBoard( &boardHt, &nVisibleRows, &scrollWidth );
|
||||||
if ( needsScroller ) {
|
|
||||||
vScale = MIN_CELL_HEIGHT;
|
|
||||||
boardWidth -= SCROLLBAR_WIDTH;
|
|
||||||
}
|
|
||||||
hScale = boardWidth / nCols;
|
|
||||||
|
|
||||||
/* Figure tray top. May overlap board. The tray's height must be at
|
boardWidth = scrnWidth - scrollWidth;
|
||||||
least the minimum, plus whatever fraction of a row is left when
|
if ( horiz ) {
|
||||||
visible board height is determined. */
|
scoreWidth = scrnWidth;
|
||||||
visBoardHt = vScale * nCols;
|
hScale = boardWidth / nRows;
|
||||||
nHiddenRows = 0;
|
/* center the board */
|
||||||
boardHtLimit = height - CE_SCORE_HEIGHT - MIN_TRAY_HEIGHT;
|
boardWidth += scrollWidth;
|
||||||
while ( visBoardHt > boardHtLimit ) {
|
boardLeft = (scrnWidth - boardWidth) / 2; /* center it all */
|
||||||
visBoardHt -= vScale;
|
} else {
|
||||||
++nHiddenRows;
|
/* move extra pixels into scoreboard */
|
||||||
|
hScale = (boardWidth - CE_MIN_SCORE_WIDTH) / nRows;
|
||||||
|
boardWidth = hScale * nRows;
|
||||||
|
scoreWidth = scrnWidth - boardWidth - scrollWidth;
|
||||||
|
boardLeft = scoreWidth;
|
||||||
}
|
}
|
||||||
trayTop = CE_SCORE_HEIGHT + visBoardHt + TRAY_PADDING;
|
trayWidth = boardWidth;
|
||||||
trayVScale = height - trayTop;
|
|
||||||
|
|
||||||
/* Center the board */
|
trayTop = boardHt + scoreHeight + TRAY_PADDING;
|
||||||
boardWidth = nCols * hScale;
|
trayVScale = scrnHeight - trayTop;
|
||||||
if ( needsScroller ) {
|
|
||||||
boardWidth += SCROLLBAR_WIDTH;
|
if ( !horiz ) {
|
||||||
|
scoreHeight = scrnHeight;
|
||||||
}
|
}
|
||||||
leftEdge = (width - boardWidth) / 2; /* center it all */
|
|
||||||
|
|
||||||
scoreWidth = width;
|
|
||||||
if ( globals->gameInfo.timerEnabled ) {
|
if ( globals->gameInfo.timerEnabled ) {
|
||||||
|
if ( horiz ) {
|
||||||
scoreWidth -= CE_TIMER_WIDTH;
|
scoreWidth -= CE_TIMER_WIDTH;
|
||||||
|
bparms->timerLeft = scoreWidth;
|
||||||
|
bparms->timerTop = 0;
|
||||||
|
bparms->timerWidth = CE_TIMER_WIDTH;
|
||||||
|
bparms->timerHeight = CE_SCORE_HEIGHT;
|
||||||
|
} else {
|
||||||
|
bparms->timerLeft = 0;
|
||||||
|
bparms->timerHeight = CE_SCORE_HEIGHT * 2;
|
||||||
|
bparms->timerTop = scrnHeight - bparms->timerHeight;
|
||||||
|
bparms->timerWidth = scoreWidth;
|
||||||
|
|
||||||
|
scoreHeight -= bparms->timerHeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bparms->boardHScale = hScale;
|
bparms->boardHScale = hScale;
|
||||||
bparms->boardVScale = vScale;
|
bparms->boardVScale = vScale;
|
||||||
|
bparms->boardTop = boardTop;
|
||||||
bparms->trayTop = trayTop;
|
bparms->trayTop = trayTop;
|
||||||
bparms->trayVScale = trayVScale;
|
bparms->trayHeight = trayVScale;
|
||||||
bparms->trayHScale = CE_TRAY_SCALEH; /* unchanged so far... */
|
bparms->trayWidth = trayWidth;
|
||||||
bparms->leftEdge = leftEdge;
|
bparms->boardLeft = boardLeft;
|
||||||
|
bparms->trayLeft = boardLeft;
|
||||||
bparms->scoreWidth = scoreWidth;
|
bparms->scoreWidth = scoreWidth;
|
||||||
bparms->scoreHeight = CE_SCORE_HEIGHT;
|
bparms->scoreHeight = scoreHeight;
|
||||||
|
bparms->horiz = horiz;
|
||||||
|
|
||||||
#ifdef CEFEATURE_CANSCROLL
|
#ifdef CEFEATURE_CANSCROLL
|
||||||
bparms->needsScroller = needsScroller;
|
bparms->needsScroller = nVisibleRows < nRows;
|
||||||
|
if ( bparms->needsScroller ) {
|
||||||
if ( needsScroller ) {
|
XP_U16 boardRight = boardLeft + (nRows * hScale);
|
||||||
XP_U16 boardRight = leftEdge + (nCols * hScale);
|
showScroller( globals, nRows - nVisibleRows,
|
||||||
showScroller( globals, nHiddenRows,
|
|
||||||
boardRight,
|
boardRight,
|
||||||
CE_SCORE_HEIGHT,
|
CE_SCORE_HEIGHT,
|
||||||
rc.right - boardRight, visBoardHt );
|
rc.right - boardRight, visBoardHt );
|
||||||
XP_LOGF( "NEEDING SCROLLBAR!!!!" );
|
XP_LOGF( "NEEDING SCROLLBAR!!!!" );
|
||||||
XP_LOGF( "%d rows hidden", nHiddenRows );
|
XP_LOGF( "%d rows hidden", nRows - nVisibleRows );
|
||||||
} else {
|
} else {
|
||||||
hideScroller( globals );
|
hideScroller( globals );
|
||||||
}
|
}
|
||||||
globals->nHiddenRows = nHiddenRows;
|
globals->nHiddenRows = nVisibleRows - nVisibleRows;
|
||||||
#endif
|
#endif
|
||||||
} /* figureBoardParms */
|
} /* figureBoardParms */
|
||||||
|
|
||||||
|
@ -479,26 +552,26 @@ cePositionBoard( CEAppGlobals* globals )
|
||||||
|
|
||||||
figureBoardParms( globals, nCols, &bparms );
|
figureBoardParms( globals, nCols, &bparms );
|
||||||
|
|
||||||
board_setTimerLoc( globals->game.board, CE_TIMER_LEFT,
|
if ( globals->gameInfo.timerEnabled ) {
|
||||||
CE_TIMER_TOP, CE_TIMER_WIDTH, CE_TIMER_HEIGHT );
|
board_setTimerLoc( globals->game.board, bparms.timerLeft,
|
||||||
|
bparms.timerTop, bparms.timerWidth,
|
||||||
|
bparms.timerHeight );
|
||||||
|
}
|
||||||
|
|
||||||
board_setPos( globals->game.board, bparms.leftEdge,
|
board_setPos( globals->game.board, bparms.boardLeft,
|
||||||
bparms.scoreHeight, XP_FALSE );
|
bparms.boardTop, XP_FALSE );
|
||||||
board_setScale( globals->game.board, bparms.boardHScale, bparms.boardVScale );
|
board_setScale( globals->game.board, bparms.boardHScale, bparms.boardVScale );
|
||||||
|
|
||||||
board_setScoreboardLoc( globals->game.board, CE_SCORE_LEFT,
|
board_setScoreboardLoc( globals->game.board, CE_SCORE_LEFT,
|
||||||
CE_SCORE_TOP, bparms.scoreWidth,
|
CE_SCORE_TOP, bparms.scoreWidth,
|
||||||
bparms.scoreHeight, XP_TRUE );
|
bparms.scoreHeight, bparms.horiz );
|
||||||
board_setShowColors( globals->game.board, globals->appPrefs.showColors );
|
board_setShowColors( globals->game.board, globals->appPrefs.showColors );
|
||||||
board_setYOffset( globals->game.board, 0 );
|
board_setYOffset( globals->game.board, 0 );
|
||||||
|
|
||||||
board_prefsChanged( globals->game.board, &globals->appPrefs.cp );
|
board_prefsChanged( globals->game.board, &globals->appPrefs.cp );
|
||||||
|
|
||||||
board_setTrayLoc( globals->game.board,
|
board_setTrayLoc( globals->game.board, bparms.trayLeft, bparms.trayTop,
|
||||||
CE_TRAY_LEFT_RH,
|
bparms.trayWidth, bparms.trayHeight, CE_DIVIDER_WIDTH );
|
||||||
bparms.trayTop,
|
|
||||||
bparms.trayHScale, bparms.trayVScale,
|
|
||||||
CE_DIVIDER_WIDTH );
|
|
||||||
|
|
||||||
server_prefsChanged( globals->game.server, &globals->appPrefs.cp );
|
server_prefsChanged( globals->game.server, &globals->appPrefs.cp );
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,7 @@ typedef struct CEDrawCtx {
|
||||||
|
|
||||||
XP_U16 trayOwner;
|
XP_U16 trayOwner;
|
||||||
XP_U16 miniLineHt;
|
XP_U16 miniLineHt;
|
||||||
|
XP_Bool scoreIsVertical;
|
||||||
|
|
||||||
MPSLOT
|
MPSLOT
|
||||||
} CEDrawCtx;
|
} CEDrawCtx;
|
||||||
|
|
Loading…
Reference in a new issue