mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
Pick largest possible bitmap; fix inconsistency between cedict's idea
of bitmap format and cedraw's: rows are padded to 8-bit boundary, not necessarily 16-bit.
This commit is contained in:
parent
70371d12f5
commit
ff89bee6e8
1 changed files with 37 additions and 26 deletions
|
@ -125,7 +125,7 @@ struct CEDrawCtx {
|
||||||
|
|
||||||
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,
|
||||||
XP_Bool center, XP_Bool stretch );
|
XP_Bool stretch );
|
||||||
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 );
|
||||||
|
|
||||||
|
@ -654,18 +654,14 @@ checkBMCache( CEDrawCtx* dctx, HDC hdc, const XP_UCHAR* letters,
|
||||||
|
|
||||||
if ( !bm ) {
|
if ( !bm ) {
|
||||||
const CEBitmapInfo* info = (const CEBitmapInfo*)(bitmaps->bmps[index]);
|
const CEBitmapInfo* info = (const CEBitmapInfo*)(bitmaps->bmps[index]);
|
||||||
XP_U16 nCols, nRows, row, col, rowBytes;
|
XP_U16 row, col;
|
||||||
COLORREF black = dctx->globals->appPrefs.colors[CE_BLACK_COLOR];
|
COLORREF black = dctx->globals->appPrefs.colors[CE_BLACK_COLOR];
|
||||||
COLORREF white = dctx->globals->appPrefs.colors[CE_WHITE_COLOR];
|
COLORREF white = dctx->globals->appPrefs.colors[CE_WHITE_COLOR];
|
||||||
HDC tmpDC;
|
HDC tmpDC;
|
||||||
XP_U8* bits = info->bits;
|
XP_U8* bits = info->bits;
|
||||||
|
XP_U16 nCols = info->nCols;
|
||||||
nCols = info->nCols;
|
XP_U16 nRows = info->nRows;
|
||||||
nRows = info->nRows;
|
XP_U16 rowBytes = (info->nCols + 7) / 8; /* rows are 8-bit padded */
|
||||||
rowBytes = (info->nCols + 7) / 8;
|
|
||||||
while ( (rowBytes % 2) != 0 ) {
|
|
||||||
++rowBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
bm = CreateBitmap( info->nCols, info->nRows, 1, 1, NULL );
|
bm = CreateBitmap( info->nCols, info->nRows, 1, 1, NULL );
|
||||||
tmpDC = CreateCompatibleDC( hdc );
|
tmpDC = CreateCompatibleDC( hdc );
|
||||||
|
@ -704,12 +700,34 @@ checkBMCache( CEDrawCtx* dctx, HDC hdc, const XP_UCHAR* letters,
|
||||||
static void
|
static void
|
||||||
makeAndDrawBitmap( CEDrawCtx* dctx, HDC hdc, const RECT* bnds,
|
makeAndDrawBitmap( CEDrawCtx* dctx, HDC hdc, const RECT* bnds,
|
||||||
const XP_UCHAR* letters, const XP_Bitmaps* bitmaps,
|
const XP_UCHAR* letters, const XP_Bitmaps* bitmaps,
|
||||||
XP_U16 index, XP_Bool center )
|
XP_Bool center )
|
||||||
{
|
{
|
||||||
XP_Bool cached;
|
XP_Bool cached;
|
||||||
|
XP_U16 index;
|
||||||
|
RECT lrt = *bnds;
|
||||||
|
|
||||||
|
SIZE size;
|
||||||
|
GetTextExtentPoint32( hdc, L"M", 1, &size );
|
||||||
|
|
||||||
|
if ( center ) {
|
||||||
|
lrt.left += ((lrt.right - lrt.left) - size.cx) / 2;
|
||||||
|
lrt.top += ((lrt.bottom - lrt.top) - size.cx) / 2;
|
||||||
|
}
|
||||||
|
lrt.right = lrt.left + size.cx;
|
||||||
|
lrt.bottom = lrt.top + size.cx;
|
||||||
|
|
||||||
|
for ( index = bitmaps->nBitmaps - 1; ; --index ) {
|
||||||
|
const CEBitmapInfo* info = (const CEBitmapInfo*)(bitmaps->bmps[index]);
|
||||||
|
if ( index == 0 ) {
|
||||||
|
break;
|
||||||
|
} else if ( info->nCols <= size.cx && info->nRows <= size.cx ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HBITMAP bm = checkBMCache( dctx, hdc, letters, index, bitmaps, &cached );
|
HBITMAP bm = checkBMCache( dctx, hdc, letters, index, bitmaps, &cached );
|
||||||
|
|
||||||
ceDrawBitmapInRect( hdc, bnds, bm, center, XP_TRUE );
|
ceDrawBitmapInRect( hdc, &lrt, bm, XP_TRUE );
|
||||||
|
|
||||||
if ( !cached ) {
|
if ( !cached ) {
|
||||||
DeleteObject( bm );
|
DeleteObject( bm );
|
||||||
|
@ -1014,7 +1032,7 @@ DRAW_FUNC_NAME(drawCell)( DrawCtx* p_dctx, const XP_Rect* xprect,
|
||||||
ceSetTextColor( hdc, dctx, foreColorIndx );
|
ceSetTextColor( hdc, dctx, foreColorIndx );
|
||||||
|
|
||||||
if ( !isDragSrc && !!bitmaps ) {
|
if ( !isDragSrc && !!bitmaps ) {
|
||||||
makeAndDrawBitmap( dctx, hdc, &rt, letters, bitmaps, 0, XP_TRUE );
|
makeAndDrawBitmap( dctx, hdc, &rt, letters, bitmaps, XP_TRUE );
|
||||||
} else if ( !isDragSrc && !!letters && (letters[0] != '\0') ) {
|
} else if ( !isDragSrc && !!letters && (letters[0] != '\0') ) {
|
||||||
wchar_t widebuf[4];
|
wchar_t widebuf[4];
|
||||||
|
|
||||||
|
@ -1024,7 +1042,7 @@ DRAW_FUNC_NAME(drawCell)( DrawCtx* p_dctx, const XP_Rect* xprect,
|
||||||
xprect->top+2, xprect->width, DT_CENTER );
|
xprect->top+2, xprect->width, DT_CENTER );
|
||||||
} else if ( (flags&CELL_ISSTAR) != 0 ) {
|
} else if ( (flags&CELL_ISSTAR) != 0 ) {
|
||||||
ceSetTextColor( hdc, dctx, CE_BLACK_COLOR );
|
ceSetTextColor( hdc, dctx, CE_BLACK_COLOR );
|
||||||
ceDrawBitmapInRect( hdc, &textRect, dctx->origin, XP_TRUE, XP_FALSE );
|
ceDrawBitmapInRect( hdc, &textRect, dctx->origin, XP_FALSE );
|
||||||
}
|
}
|
||||||
|
|
||||||
ceDrawHintBorders( dctx, xprect, hintAtts );
|
ceDrawHintBorders( dctx, xprect, hintAtts );
|
||||||
|
@ -1160,7 +1178,7 @@ drawDrawTileGuts( DrawCtx* p_dctx, const XP_Rect* xprect,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !!bitmaps ) {
|
if ( !!bitmaps ) {
|
||||||
makeAndDrawBitmap( dctx, hdc, &rt, letters, bitmaps, 1,
|
makeAndDrawBitmap( dctx, hdc, &rt, letters, bitmaps,
|
||||||
valHidden );
|
valHidden );
|
||||||
} else if ( !!letters ) {
|
} else if ( !!letters ) {
|
||||||
ceDrawTextClipped( hdc, widebuf, -1, XP_TRUE, fce,
|
ceDrawTextClipped( hdc, widebuf, -1, XP_TRUE, fce,
|
||||||
|
@ -1258,7 +1276,7 @@ ceClearToBkground( CEDrawCtx* dctx, const XP_Rect* rect )
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
ceDrawBitmapInRect( HDC hdc, const RECT* rect, HBITMAP bitmap,
|
ceDrawBitmapInRect( HDC hdc, const RECT* rect, HBITMAP bitmap,
|
||||||
XP_Bool center, XP_Bool stretch )
|
XP_Bool stretch )
|
||||||
{
|
{
|
||||||
BITMAP bmp;
|
BITMAP bmp;
|
||||||
int nBytes;
|
int nBytes;
|
||||||
|
@ -1275,12 +1293,7 @@ ceDrawBitmapInRect( HDC hdc, const RECT* rect, HBITMAP bitmap,
|
||||||
XP_U16 height = rect->bottom - top;
|
XP_U16 height = rect->bottom - top;
|
||||||
HDC tmpDC;
|
HDC tmpDC;
|
||||||
|
|
||||||
if ( stretch ) {
|
if ( !stretch ) {
|
||||||
/* Target rect size is based on width of M in the current font */
|
|
||||||
SIZE size;
|
|
||||||
GetTextExtentPoint32( hdc, L"M", 1, &size );
|
|
||||||
width = height = size.cx; /* make it square */
|
|
||||||
} else {
|
|
||||||
/* Find dimensions that'll fit multiplying an integral number of
|
/* Find dimensions that'll fit multiplying an integral number of
|
||||||
times */
|
times */
|
||||||
XP_U16 factor = XP_MIN( width/bmp.bmWidth, height/bmp.bmHeight );
|
XP_U16 factor = XP_MIN( width/bmp.bmWidth, height/bmp.bmHeight );
|
||||||
|
@ -1299,10 +1312,8 @@ ceDrawBitmapInRect( HDC hdc, const RECT* rect, HBITMAP bitmap,
|
||||||
|
|
||||||
(void)IntersectClipRect( tmpDC, left, top, rect->right, rect->bottom );
|
(void)IntersectClipRect( tmpDC, left, top, rect->right, rect->bottom );
|
||||||
|
|
||||||
if ( center ) {
|
left += ((rect->right - left) - width) / 2;
|
||||||
left += ((rect->right - left) - width) / 2;
|
top += ((rect->bottom - top) - height) / 2;
|
||||||
top += ((rect->bottom - top) - height) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
StretchBlt( hdc, left, top, width, height,
|
StretchBlt( hdc, left, top, width, height,
|
||||||
tmpDC, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY );
|
tmpDC, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY );
|
||||||
|
@ -1348,7 +1359,7 @@ DRAW_FUNC_NAME(drawBoardArrow)( DrawCtx* p_dctx, const XP_Rect* xprect,
|
||||||
ceSetBkColor( hdc, dctx, bkIndex );
|
ceSetBkColor( hdc, dctx, bkIndex );
|
||||||
ceSetTextColor( hdc, dctx, CE_BLACK_COLOR );
|
ceSetTextColor( hdc, dctx, CE_BLACK_COLOR );
|
||||||
|
|
||||||
ceDrawBitmapInRect( hdc, &rt, cursor, XP_TRUE, XP_FALSE );
|
ceDrawBitmapInRect( hdc, &rt, cursor, XP_FALSE );
|
||||||
|
|
||||||
ceDrawHintBorders( dctx, xprect, hintAtts );
|
ceDrawHintBorders( dctx, xprect, hintAtts );
|
||||||
} /* ce_draw_drawBoardArrow */
|
} /* ce_draw_drawBoardArrow */
|
||||||
|
|
Loading…
Reference in a new issue