pass vScale and hScale into draw_boardBegin so platform can use same

size font for all cells regardless of size; fix scrolling to pass
actual sum of the disappearing rows' heights.
This commit is contained in:
eehouse 2010-04-08 04:14:55 +00:00
parent 5922d8c96a
commit a87ecf5638
5 changed files with 36 additions and 12 deletions

View file

@ -1,6 +1,6 @@
/* -*-mode: C; fill-column: 78; compile-command: "cd ../linux && make MEMDEBUG=TRUE"; -*- */
/*
* Copyright 1997 - 2009 by Eric House (xwords@eehouse.org). All rights
* Copyright 1997 - 2010 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* This program is free software; you can redistribute it and/or
@ -234,6 +234,7 @@ drawBoard( BoardCtxt* board )
if ( board->needsDrawing
&& draw_boardBegin( board->draw,
&board->boardBounds,
board->boardHScale, board->boardVScale,
dfsFor( board, OBJ_BOARD ) ) ) {
XP_Bool allDrawn = XP_TRUE;
@ -509,6 +510,22 @@ drawDragTileIf( BoardCtxt* board )
} /* drawDragTileIf */
#endif
static XP_S16
sumRowHeights( const BoardCtxt* board, XP_U16 row1, XP_U16 row2 )
{
XP_S16 sign = row1 > row2 ? -1 : 1;
XP_S16 result, ii;
if ( sign < 0 ) {
XP_U16 tmp = row1;
row1 = row2;
row2 = tmp;
}
for ( result = 0, ii = row1; ii < row2; ++ii ) {
result += board->rowHeights[ii];
}
return result * sign;
}
static void
scrollIfCan( BoardCtxt* board )
{
@ -525,9 +542,8 @@ scrollIfCan( BoardCtxt* board )
}
#endif
invalSelTradeWindow( board );
dist = (board->yOffset - board->prevYScrollOffset)
* board->boardVScale;
dist = sumRowHeights( board, board->prevYScrollOffset, board->yOffset );
scrolled = draw_vertScrollBoard( board->draw, &scrollR, dist,
dfsFor( board, OBJ_BOARD ) );

View file

@ -1,6 +1,7 @@
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
/*
* Copyright 1997 - 2007 by Eric House (xwords@eehouse.org). All rights reserved.
* Copyright 1997 - 2010 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -115,6 +116,7 @@ typedef struct DrawCtxVTable {
XP_Bool DRAW_VTABLE_NAME(boardBegin) ( DrawCtx* dctx,
const XP_Rect* rect,
XP_U16 hScale, XP_U16 vScale,
DrawFocusState dfs );
void DRAW_VTABLE_NAME(objFinished)( DrawCtx* dctx, BoardObjectType typ,
const XP_Rect* rect,
@ -249,7 +251,8 @@ struct DrawCtx {
#define draw_destroyCtxt(dc) CALL_DRAW_NAME0(destroyCtxt, dc)
#define draw_dictChanged( dc, d ) CALL_DRAW_NAME1(dictChanged, (dc), (d))
#define draw_boardBegin( dc,r,f ) CALL_DRAW_NAME2(boardBegin, dc, r,f)
#define draw_boardBegin( dc,r,h,v,f ) CALL_DRAW_NAME4(boardBegin, (dc),\
(r),(h),(v),(f))
#define draw_objFinished( dc, t, r, d ) CALL_DRAW_NAME3(objFinished, (dc), (t), (r), (d))
#define draw_trayBegin( dc, r, o, f ) CALL_DRAW_NAME3(trayBegin,dc, r, o, f)
#define draw_vertScrollBoard( dc, r, d, f ) \

View file

@ -94,6 +94,7 @@ curses_draw_dictChanged( DrawCtx* XP_UNUSED(p_dctx),
static XP_Bool
curses_draw_boardBegin( DrawCtx* XP_UNUSED(p_dctx),
const XP_Rect* XP_UNUSED(rect),
XP_U16 XP_UNUSED(width), XP_U16 XP_UNUSED(height),
DrawFocusState XP_UNUSED(dfs) )
{
return XP_TRUE;

View file

@ -318,10 +318,13 @@ gtk_draw_dictChanged( DrawCtx* XP_UNUSED(p_dctx),
static XP_Bool
gtk_draw_boardBegin( DrawCtx* p_dctx, const XP_Rect* rect,
XP_U16 width, XP_U16 height,
DrawFocusState XP_UNUSED(dfs) )
{
GdkRectangle gdkrect;
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
dctx->cellWidth = width;
dctx->cellHeight = height;
gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
@ -346,9 +349,6 @@ static XP_Bool
gtk_draw_vertScrollBoard( DrawCtx* p_dctx, XP_Rect* rect,
XP_S16 dist, DrawFocusState XP_UNUSED(dfs) )
{
/* Turn this on to mimic what palm does, but need to figure out some gtk
analog to copybits for it to actually work. */
#if 1
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
XP_Bool down = dist <= 0;
gint ysrc, ydest;
@ -376,11 +376,12 @@ gtk_draw_vertScrollBoard( DrawCtx* p_dctx, XP_Rect* rect,
rect->top += rect->height - dist;
}
rect->height = dist;
#endif
XP_LOGF( "%s=>(%d,%d,%d,%d)", __func__, rect->left, rect->top,
rect->width, rect->height );
return XP_TRUE;
}
static void
drawHintBorders( GtkDrawCtx* dctx, const XP_Rect* rect, HintAtts hintAtts)
{
@ -465,7 +466,7 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter,
}
}
if ( (flags & CELL_ISSTAR) != 0 ) {
draw_string_at( dctx, NULL, "*", rect->height, rect,
draw_string_at( dctx, NULL, "*", dctx->cellHeight, rect,
XP_GTK_JUST_CENTER, &dctx->black, NULL );
}
} else if ( !!bitmaps && !!bitmaps->bmps[0] ) {
@ -488,7 +489,7 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter,
}
foreground = highlight? &dctx->white : &dctx->playerColors[owner];
draw_string_at( dctx, NULL, letter, rectInset.height-2, &rectInset,
draw_string_at( dctx, NULL, letter, dctx->cellHeight, &rectInset,
XP_GTK_JUST_CENTER, foreground, cursor );
if ( isBlank ) {

View file

@ -67,6 +67,9 @@ typedef struct GtkDrawCtx {
} scoreCache[MAX_NUM_PLAYERS];
XP_U16 trayOwner;
XP_U16 cellWidth;
XP_U16 cellHeight;
XP_Bool scoreIsVertical;
} GtkDrawCtx;