mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-02 06:20:14 +01:00
inval font cache when new dict has different chars; use cell size as a
minimum font heigth for tray; darken default player 4 color for better contrast.
This commit is contained in:
parent
bbe8cceb6e
commit
0f3b206371
4 changed files with 87 additions and 35 deletions
|
@ -83,6 +83,7 @@ TARGET_OS_DEF = -DTARGET_OS_WIN32
|
||||||
CELIBS += -lws2_32
|
CELIBS += -lws2_32
|
||||||
|
|
||||||
CFLAGS += -DCANT_DO_CMDBAR -DDRAW_LINK_DIRECT -DXWFEATURE_TURNCHANGENOTIFY
|
CFLAGS += -DCANT_DO_CMDBAR -DDRAW_LINK_DIRECT -DXWFEATURE_TURNCHANGENOTIFY
|
||||||
|
# CFLAGS += -DFORCE_FONT="L\"Segoe Condensed\""
|
||||||
#CFLAGS += -DFORCE_HEIGHT=240 -DFORCE_WIDTH=320
|
#CFLAGS += -DFORCE_HEIGHT=240 -DFORCE_WIDTH=320
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -112,6 +112,29 @@ static void ceDrawBitmapInRect( HDC hdc, const RECT* r, HBITMAP bitmap );
|
||||||
static void ceClipToRect( HDC hdc, const RECT* rt );
|
static void ceClipToRect( HDC hdc, const RECT* rt );
|
||||||
static void ceClearFontCache( CEDrawCtx* dctx );
|
static void ceClearFontCache( CEDrawCtx* dctx );
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
const char*
|
||||||
|
RFI2Str( RFIndex rfi )
|
||||||
|
{
|
||||||
|
const char* str;
|
||||||
|
# define CASE_STR(c) case c: str = #c; break
|
||||||
|
switch( rfi ) {
|
||||||
|
CASE_STR( RFONTS_TRAY );
|
||||||
|
CASE_STR( RFONTS_TRAYVAL );
|
||||||
|
CASE_STR( RFONTS_CELL );
|
||||||
|
CASE_STR( RFONTS_REM );
|
||||||
|
CASE_STR( RFONTS_SCORE );
|
||||||
|
CASE_STR( RFONTS_SCORE_BOLD );
|
||||||
|
default:
|
||||||
|
str = "<unknown>";
|
||||||
|
}
|
||||||
|
# undef CASE_STR
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define RFI2Str( rfi ) ""
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
XPRtoRECT( RECT* rt, const XP_Rect* xprect )
|
XPRtoRECT( RECT* rt, const XP_Rect* xprect )
|
||||||
{
|
{
|
||||||
|
@ -453,9 +476,13 @@ ceFillFontInfo( const CEDrawCtx* dctx, LOGFONT* fontInfo,
|
||||||
/* } else { */
|
/* } else { */
|
||||||
/* fontInfo->lfWeight = FW_LIGHT; */
|
/* fontInfo->lfWeight = FW_LIGHT; */
|
||||||
/* } */
|
/* } */
|
||||||
|
wcscpy( fontInfo->lfFaceName,
|
||||||
wcscpy( fontInfo->lfFaceName, IS_SMARTPHONE(dctx->globals)?
|
#ifdef FORCE_FONT
|
||||||
L"Segoe Condensed" : L"Tahoma" );
|
FORCE_FONT
|
||||||
|
#else
|
||||||
|
IS_SMARTPHONE(dctx->globals)? L"Segoe Condensed" : L"Tahoma"
|
||||||
|
#endif
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -514,8 +541,9 @@ ceBestFitFont( CEDrawCtx* dctx, XP_U16 soughtHeight, RFIndex index,
|
||||||
fce->lfHeight = testSize;
|
fce->lfHeight = testSize;
|
||||||
fce->offset = top;
|
fce->offset = top;
|
||||||
fce->glyphHt = thisHeight;
|
fce->glyphHt = thisHeight;
|
||||||
XP_LOGF( "Found for %d: indexHt: %d; lfHeight: %d; glyphHt: %d",
|
XP_LOGF( "Found for %s: indexHt: %d; lfHeight: %d; glyphHt: %d",
|
||||||
index, fce->indexHt, fce->lfHeight, fce->glyphHt );
|
RFI2Str(index), fce->indexHt, fce->lfHeight,
|
||||||
|
fce->glyphHt );
|
||||||
|
|
||||||
XP_ASSERT( fce->lfHeight >= fce->indexHt );
|
XP_ASSERT( fce->lfHeight >= fce->indexHt );
|
||||||
XP_ASSERT( fce->indexHt >= fce->glyphHt );
|
XP_ASSERT( fce->indexHt >= fce->glyphHt );
|
||||||
|
@ -535,6 +563,8 @@ ceGetSizedFont( CEDrawCtx* dctx, XP_U16 height, RFIndex index )
|
||||||
FontCacheEntry* fce = &dctx->fcEntry[index];
|
FontCacheEntry* fce = &dctx->fcEntry[index];
|
||||||
if ( (0 != height) /* 0 means use what we have */
|
if ( (0 != height) /* 0 means use what we have */
|
||||||
&& fce->indexHt != height ) {
|
&& fce->indexHt != height ) {
|
||||||
|
XP_LOGF( "%s: no match for %s (have %d, want %d) so recalculating",
|
||||||
|
__func__, RFI2Str(index), fce->indexHt, height );
|
||||||
ceBestFitFont( dctx, height, index, fce );
|
ceBestFitFont( dctx, height, index, fce );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -614,10 +644,12 @@ drawTextLines( CEDrawCtx* dctx, HDC hdc, const XP_UCHAR* text, XP_S16 padding,
|
||||||
} /* drawTextLines */
|
} /* drawTextLines */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ceGetCharValHts( const XP_Rect* xprect, XP_U16* charHt, XP_U16* valHt )
|
ceGetCharValHts( const CEDrawCtx* dctx, const XP_Rect* xprect,
|
||||||
|
XP_U16* charHt, XP_U16* valHt )
|
||||||
{
|
{
|
||||||
XP_U16 visHt = xprect->height - TRAY_BORDER;
|
XP_U16 visHt = xprect->height - TRAY_BORDER;
|
||||||
XP_U16 visWidth = xprect->width - 5; /* ??? */
|
XP_U16 visWidth = xprect->width - 5; /* ??? */
|
||||||
|
XP_U16 minHt;
|
||||||
|
|
||||||
/* if tiles are wider than tall we can let them overlap vertically */
|
/* if tiles are wider than tall we can let them overlap vertically */
|
||||||
if ( visWidth > visHt ) {
|
if ( visWidth > visHt ) {
|
||||||
|
@ -628,13 +660,19 @@ ceGetCharValHts( const XP_Rect* xprect, XP_U16* charHt, XP_U16* valHt )
|
||||||
*charHt = (visHt * 4) / 5;
|
*charHt = (visHt * 4) / 5;
|
||||||
*valHt = visHt / 2;
|
*valHt = visHt / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
*valHt = visHt / 3;
|
*valHt = visHt / 3;
|
||||||
*charHt = visHt - *valHt;
|
*charHt = visHt - *valHt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
minHt = dctx->globals->cellHt - CELL_BORDER;
|
||||||
|
if ( *charHt < minHt ) {
|
||||||
|
*charHt = minHt;
|
||||||
|
}
|
||||||
/* XP_LOGF( "%s(width:%d, height:%d)=>char: %d, val:%d", __func__, */
|
/* XP_LOGF( "%s(width:%d, height:%d)=>char: %d, val:%d", __func__, */
|
||||||
/* xprect->width, xprect->height, *charHt, *valHt ); */
|
/* xprect->width, xprect->height, *charHt, *valHt ); */
|
||||||
}
|
} /* ceGetCharValHts */
|
||||||
|
|
||||||
DLSTATIC XP_Bool
|
DLSTATIC XP_Bool
|
||||||
DRAW_FUNC_NAME(boardBegin)( DrawCtx* p_dctx,
|
DRAW_FUNC_NAME(boardBegin)( DrawCtx* p_dctx,
|
||||||
|
@ -744,8 +782,8 @@ DRAW_FUNC_NAME(drawCell)( DrawCtx* p_dctx, const XP_Rect* xprect,
|
||||||
InsetRect( &rt, 1, 1 );
|
InsetRect( &rt, 1, 1 );
|
||||||
ceClipToRect( hdc, &rt );
|
ceClipToRect( hdc, &rt );
|
||||||
|
|
||||||
fce = ceGetSizedFont( dctx, XP_MIN(xprect->height-CELL_BORDER,xprect->width),
|
XP_ASSERT( xprect->height == globals->cellHt );
|
||||||
RFONTS_CELL );
|
fce = ceGetSizedFont( dctx, xprect->height - CELL_BORDER, RFONTS_CELL );
|
||||||
oldFont = SelectObject( hdc, fce->setFont );
|
oldFont = SelectObject( hdc, fce->setFont );
|
||||||
|
|
||||||
/* always init to silence compiler warning */
|
/* always init to silence compiler warning */
|
||||||
|
@ -907,7 +945,7 @@ drawDrawTileGuts( DrawCtx* p_dctx, const XP_Rect* xprect,
|
||||||
const FontCacheEntry* fce;
|
const FontCacheEntry* fce;
|
||||||
/* Dumb to calc these when only needed once.... */
|
/* Dumb to calc these when only needed once.... */
|
||||||
XP_U16 valHt, charHt;
|
XP_U16 valHt, charHt;
|
||||||
ceGetCharValHts( xprect, &charHt, &valHt );
|
ceGetCharValHts( dctx, xprect, &charHt, &valHt );
|
||||||
|
|
||||||
if ( !highlighted ) {
|
if ( !highlighted ) {
|
||||||
InsetRect( &rt, 1, 1 );
|
InsetRect( &rt, 1, 1 );
|
||||||
|
@ -1313,7 +1351,7 @@ DRAW_FUNC_NAME(score_pendingScore)( DrawCtx* p_dctx, const XP_Rect* xprect,
|
||||||
XP_U16 valHt;
|
XP_U16 valHt;
|
||||||
XP_U16 charHt;
|
XP_U16 charHt;
|
||||||
|
|
||||||
ceGetCharValHts( xprect, &charHt, &valHt );
|
ceGetCharValHts( dctx, xprect, &charHt, &valHt );
|
||||||
|
|
||||||
/* Little Pts first up top */
|
/* Little Pts first up top */
|
||||||
fce = ceGetSizedFont( dctx, valHt, RFONTS_TRAYVAL );
|
fce = ceGetSizedFont( dctx, valHt, RFONTS_TRAYVAL );
|
||||||
|
@ -1521,8 +1559,14 @@ DLSTATIC void
|
||||||
DRAW_FUNC_NAME(dictChanged)( DrawCtx* p_dctx, const DictionaryCtxt* dict )
|
DRAW_FUNC_NAME(dictChanged)( DrawCtx* p_dctx, const DictionaryCtxt* dict )
|
||||||
{
|
{
|
||||||
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
|
CEDrawCtx* dctx = (CEDrawCtx*)p_dctx;
|
||||||
/* May want to inval font cache if new dict has different tiles from
|
XP_ASSERT( !!dict );
|
||||||
old. Use dict_tilesAreSame(). */
|
|
||||||
|
/* If we don't yet have a dict, stick with the cache we have, which is
|
||||||
|
either empty or came from the saved game and likely belong with the
|
||||||
|
dict we're getting now. */
|
||||||
|
if ( !!dctx->dict && !dict_tilesAreSame( dctx->dict, dict ) ) {
|
||||||
|
ceClearFontCache( dctx );
|
||||||
|
}
|
||||||
dctx->dict = dict;
|
dctx->dict = dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1688,11 +1732,16 @@ ce_draw_toStream( const CEDrawCtx* dctx, XWStreamCtxt* stream )
|
||||||
stream_putU8( stream, N_RESIZE_FONTS );
|
stream_putU8( stream, N_RESIZE_FONTS );
|
||||||
for ( ii = 0; ii < N_RESIZE_FONTS; ++ii ) {
|
for ( ii = 0; ii < N_RESIZE_FONTS; ++ii ) {
|
||||||
const FontCacheEntry* fce = &dctx->fcEntry[ii];
|
const FontCacheEntry* fce = &dctx->fcEntry[ii];
|
||||||
|
XP_LOGF( "saving indexHt: %d, lfHeight: %d, offset: %d, glyphHt: %d "
|
||||||
|
"for %s", fce->indexHt, fce->lfHeight, fce->offset,
|
||||||
|
fce->glyphHt, RFI2Str(ii) );
|
||||||
stream_putU8( stream, fce->indexHt );
|
stream_putU8( stream, fce->indexHt );
|
||||||
|
if ( fce->indexHt > 0 ) {
|
||||||
stream_putU8( stream, fce->lfHeight );
|
stream_putU8( stream, fce->lfHeight );
|
||||||
stream_putU8( stream, fce->offset );
|
stream_putU8( stream, fce->offset );
|
||||||
stream_putU8( stream, fce->glyphHt );
|
stream_putU8( stream, fce->glyphHt );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#define DROP_CACHE
|
//#define DROP_CACHE
|
||||||
|
@ -1710,17 +1759,21 @@ ce_draw_fromStream( CEDrawCtx* dctx, XWStreamCtxt* stream )
|
||||||
FontCacheEntry fce;
|
FontCacheEntry fce;
|
||||||
|
|
||||||
fce.indexHt = (XP_U16)stream_getU8( stream );
|
fce.indexHt = (XP_U16)stream_getU8( stream );
|
||||||
|
if ( fce.indexHt > 0 ) {
|
||||||
fce.lfHeight = (XP_U16)stream_getU8( stream );
|
fce.lfHeight = (XP_U16)stream_getU8( stream );
|
||||||
fce.offset = (XP_U16)stream_getU8( stream );
|
fce.offset = (XP_U16)stream_getU8( stream );
|
||||||
fce.glyphHt = (XP_U16)stream_getU8( stream );
|
fce.glyphHt = (XP_U16)stream_getU8( stream );
|
||||||
|
|
||||||
/* We need to read from the file no matter how many entries, but only
|
/* We need to read from the file no matter how many entries, but
|
||||||
populate what we have room for -- in case N_RESIZE_FONTS was
|
only populate what we have room for -- in case N_RESIZE_FONTS
|
||||||
different when file written. */
|
was different when file written. */
|
||||||
#ifndef DROP_CACHE
|
#ifndef DROP_CACHE
|
||||||
if ( ii < N_RESIZE_FONTS ) {
|
if ( ii < N_RESIZE_FONTS ) {
|
||||||
LOGFONT fontInfo;
|
LOGFONT fontInfo;
|
||||||
/* XP_LOGF( "using height %d for index %d", fce.lfHeight, ii ); */
|
|
||||||
|
XP_LOGF( "read indexHt: %d, lfHeight: %d, offset: %d, "
|
||||||
|
"glyphHt: %d for %s", fce.indexHt, fce.lfHeight,
|
||||||
|
fce.offset, fce.glyphHt, RFI2Str(ii) );
|
||||||
ceFillFontInfo( dctx, &fontInfo, fce.lfHeight );
|
ceFillFontInfo( dctx, &fontInfo, fce.lfHeight );
|
||||||
fce.setFont = CreateFontIndirect( &fontInfo );
|
fce.setFont = CreateFontIndirect( &fontInfo );
|
||||||
XP_ASSERT( !!fce.setFont );
|
XP_ASSERT( !!fce.setFont );
|
||||||
|
@ -1729,4 +1782,5 @@ ce_draw_fromStream( CEDrawCtx* dctx, XWStreamCtxt* stream )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} /* ce_draw_fromStream */
|
} /* ce_draw_fromStream */
|
||||||
|
|
|
@ -2059,7 +2059,6 @@ ceCheckHandleFocusKey( CEAppGlobals* globals, WPARAM wParam, LPARAM lParam,
|
||||||
if ( isRepeat ) {
|
if ( isRepeat ) {
|
||||||
(void)checkFireLateKeyTimer( globals );
|
(void)checkFireLateKeyTimer( globals );
|
||||||
}
|
}
|
||||||
XP_LOGF( "%s: XP_RETURN_KEY", __func__ );
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Still need to produce these somehow */
|
/* Still need to produce these somehow */
|
||||||
|
@ -2112,7 +2111,6 @@ ceCheckHandleFocusKey( CEAppGlobals* globals, WPARAM wParam, LPARAM lParam,
|
||||||
}
|
}
|
||||||
index = (index + orderLen + incr) % orderLen;
|
index = (index + orderLen + incr) % orderLen;
|
||||||
}
|
}
|
||||||
XP_LOGF( "%s: calling board_focusChanged", __func__ );
|
|
||||||
draw = board_focusChanged( board, order[index], XP_TRUE );
|
draw = board_focusChanged( board, order[index], XP_TRUE );
|
||||||
|
|
||||||
if ( !!globals->scrollHandle ) {
|
if ( !!globals->scrollHandle ) {
|
||||||
|
@ -2210,7 +2208,6 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
* work around using WM_PAINT or WM_ERASEBKGND but no luck
|
* work around using WM_PAINT or WM_ERASEBKGND but no luck
|
||||||
* yet. */
|
* yet. */
|
||||||
case WM_CTLCOLORSCROLLBAR:
|
case WM_CTLCOLORSCROLLBAR:
|
||||||
XP_LOGF( "got WM_CTLCOLORSCROLLBAR" );
|
|
||||||
if ( (HWND)lParam == globals->scrollHandle ) {
|
if ( (HWND)lParam == globals->scrollHandle ) {
|
||||||
if ( globals->scrollerHasFocus ) {
|
if ( globals->scrollerHasFocus ) {
|
||||||
return (LRESULT)ce_draw_getFocusBrush( globals->draw );
|
return (LRESULT)ce_draw_getFocusBrush( globals->draw );
|
||||||
|
|
|
@ -885,7 +885,7 @@ BEGIN
|
||||||
0x00, 0x00, 0x00, /* player 1 */
|
0x00, 0x00, 0x00, /* player 1 */
|
||||||
0xFF, 0x00, 0x00,
|
0xFF, 0x00, 0x00,
|
||||||
0x00, 0x00, 0xFF,
|
0x00, 0x00, 0xFF,
|
||||||
0x00, 0xFF, 0x00,
|
0x00, 0x8F, 0x00, /* 8F: full-green contrasts badly with background */
|
||||||
0x00, 0x00, 0x00, /* black */
|
0x00, 0x00, 0x00, /* black */
|
||||||
0xFF, 0xFF, 0xFF /* white */
|
0xFF, 0xFF, 0xFF /* white */
|
||||||
END
|
END
|
||||||
|
|
Loading…
Reference in a new issue