2008-02-02 17:56:20 +01:00
|
|
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */
|
2003-11-01 06:35:29 +01:00
|
|
|
/*
|
2008-02-02 17:56:20 +01:00
|
|
|
* Copyright 1997-2008 by Eric House (xwords@eehouse.org). All rights
|
|
|
|
* reserved.
|
2003-11-01 06:35:29 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef PLATFORM_NCURSES
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
2005-03-15 04:29:37 +01:00
|
|
|
#include <ctype.h>
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
#include "cursesmain.h"
|
|
|
|
#include "draw.h"
|
|
|
|
#include "board.h"
|
2006-11-05 17:54:18 +01:00
|
|
|
#include "dbgutil.h"
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2006-11-03 07:23:54 +01:00
|
|
|
typedef struct CursesDrawCtx {
|
|
|
|
DrawCtxVTable* vtable;
|
|
|
|
|
|
|
|
WINDOW* boardWin;
|
|
|
|
|
|
|
|
} CursesDrawCtx;
|
|
|
|
|
2006-09-19 05:35:26 +02:00
|
|
|
static void curses_draw_clearRect( DrawCtx* p_dctx, const XP_Rect* rectP );
|
2008-02-02 17:56:20 +01:00
|
|
|
static void getTops( const XP_Rect* rect, int* toptop, int* topbot );
|
2006-09-19 05:35:26 +02:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
drawRect( WINDOW* win, const XP_Rect* rect, char vert, char hor )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
wmove( win, rect->top-1, rect->left );
|
|
|
|
whline( win, hor, rect->width );
|
|
|
|
wmove( win, rect->top+rect->height, rect->left );
|
|
|
|
whline( win, hor, rect->width );
|
|
|
|
|
|
|
|
wmove( win, rect->top, rect->left-1 );
|
|
|
|
wvline( win, vert, rect->height );
|
|
|
|
wmove( win, rect->top, rect->left+rect->width );
|
|
|
|
wvline( win, vert, rect->height );
|
|
|
|
} /* drawRect */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
eraseRect( CursesDrawCtx* dctx, const XP_Rect* rect )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
int y, bottom = rect->top + rect->height;
|
|
|
|
for ( y = rect->top; y < bottom; ++y ) {
|
|
|
|
mvwhline( dctx->boardWin, y, rect->left, ' ', rect->width );
|
|
|
|
}
|
|
|
|
} /* eraseRect */
|
|
|
|
|
2006-11-03 07:23:54 +01:00
|
|
|
static void
|
|
|
|
cursesHiliteRect( WINDOW* window, const XP_Rect* rect )
|
|
|
|
{
|
|
|
|
int right, width, x, y;
|
|
|
|
width = rect->width;
|
|
|
|
right = width + rect->left;
|
|
|
|
wstandout( window );
|
|
|
|
for ( y = rect->top; y < rect->top + rect->height; ++y ) {
|
|
|
|
for ( x = rect->left; x < right; ++x ) {
|
|
|
|
chtype cht = mvwinch( window, y, x );
|
|
|
|
char ch = cht & A_CHARTEXT;
|
|
|
|
mvwaddch( window, y, x, ch );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wstandend( window );
|
|
|
|
}
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
curses_draw_destroyCtxt( DrawCtx* XP_UNUSED(p_dctx) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
// CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
|
|
|
} /* draw_setup */
|
|
|
|
|
2008-09-05 14:11:37 +02:00
|
|
|
static void
|
|
|
|
curses_draw_dictChanged( DrawCtx* XP_UNUSED(p_dctx),
|
|
|
|
const DictionaryCtxt* XP_UNUSED(dict) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-02-17 04:58:40 +01:00
|
|
|
static XP_Bool
|
2006-11-05 17:54:18 +01:00
|
|
|
curses_draw_boardBegin( DrawCtx* XP_UNUSED(p_dctx),
|
|
|
|
const XP_Rect* XP_UNUSED(rect),
|
2010-04-08 06:14:55 +02:00
|
|
|
XP_U16 XP_UNUSED(width), XP_U16 XP_UNUSED(height),
|
2006-11-05 17:54:18 +01:00
|
|
|
DrawFocusState XP_UNUSED(dfs) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2004-02-17 04:58:40 +01:00
|
|
|
return XP_TRUE;
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* draw_finish */
|
|
|
|
|
2004-06-27 06:35:20 +02:00
|
|
|
static XP_Bool
|
2006-11-05 17:54:18 +01:00
|
|
|
curses_draw_trayBegin( DrawCtx* XP_UNUSED(p_dctx),
|
|
|
|
const XP_Rect* XP_UNUSED(rect),
|
|
|
|
XP_U16 XP_UNUSED(owner),
|
|
|
|
DrawFocusState XP_UNUSED(dfs) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2004-06-27 06:35:20 +02:00
|
|
|
return XP_TRUE;
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* draw_finish */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
curses_draw_scoreBegin( DrawCtx* p_dctx, const XP_Rect* rect,
|
2006-11-05 17:54:18 +01:00
|
|
|
XP_U16 XP_UNUSED(numPlayers),
|
2009-11-19 03:26:38 +01:00
|
|
|
const XP_S16* const XP_UNUSED(scores),
|
|
|
|
XP_S16 XP_UNUSED(remCount),
|
2006-11-05 17:54:18 +01:00
|
|
|
DrawFocusState XP_UNUSED(dfs) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
2006-11-05 17:54:18 +01:00
|
|
|
eraseRect( dctx, rect );
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* curses_draw_scoreBegin */
|
|
|
|
|
|
|
|
static void
|
2008-02-02 17:56:20 +01:00
|
|
|
formatRemText( char* buf, int bufLen, XP_S16 nTilesLeft, int width )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2008-02-02 17:56:20 +01:00
|
|
|
snprintf( buf, bufLen, "Tiles left in pool: %.3d", nTilesLeft );
|
|
|
|
if ( strlen(buf)+1 >= width ) {
|
|
|
|
snprintf( buf, bufLen, "Rem: %.3d", nTilesLeft );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
} /* formatRemText */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
curses_draw_measureRemText( DrawCtx* XP_UNUSED(dctx),
|
2008-02-02 17:56:20 +01:00
|
|
|
const XP_Rect* r,
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_S16 nTilesLeft,
|
|
|
|
XP_U16* width, XP_U16* height )
|
|
|
|
{
|
|
|
|
char buf[32];
|
2008-02-02 17:56:20 +01:00
|
|
|
formatRemText( buf, sizeof(buf), nTilesLeft, r->width );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
*width = strlen(buf);
|
|
|
|
*height = 1;
|
|
|
|
} /* curses_draw_measureRemText */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
curses_draw_drawRemText( DrawCtx* p_dctx, const XP_Rect* rInner,
|
2008-10-24 11:07:30 +02:00
|
|
|
const XP_Rect* XP_UNUSED(rOuter), XP_S16 nTilesLeft,
|
|
|
|
XP_Bool focussed )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
|
|
|
char buf[32];
|
|
|
|
|
2008-02-02 17:56:20 +01:00
|
|
|
formatRemText( buf, sizeof(buf), nTilesLeft, rInner->width );
|
2003-11-01 06:35:29 +01:00
|
|
|
mvwprintw( dctx->boardWin, rInner->top, rInner->left, buf );
|
2008-10-24 11:07:30 +02:00
|
|
|
if ( focussed ) {
|
|
|
|
cursesHiliteRect( dctx->boardWin, rInner );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* curses_draw_drawRemText */
|
|
|
|
|
2008-02-02 17:56:20 +01:00
|
|
|
static int
|
2009-10-15 14:44:53 +02:00
|
|
|
fitIn( char* buf, int len, int* rem, const char* str )
|
2008-02-02 17:56:20 +01:00
|
|
|
{
|
|
|
|
int slen = strlen(str);
|
|
|
|
if ( !!rem && (*rem != 0) ) {
|
|
|
|
++len;
|
|
|
|
--*rem;
|
|
|
|
}
|
|
|
|
if ( slen > len ) {
|
|
|
|
slen = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy( buf, str, slen );
|
|
|
|
return len;
|
|
|
|
} /* fitIn */
|
2005-03-15 04:29:37 +01:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
2008-02-02 17:56:20 +01:00
|
|
|
formatScoreText( XP_UCHAR* out, int outLen, const DrawScoreInfo* dsi,
|
|
|
|
int width )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2008-02-02 17:56:20 +01:00
|
|
|
/* Long and short formats. We'll try long first. If it fits, cool.
|
|
|
|
Otherwise we use short. Either way, we fill the whole rect so it can
|
|
|
|
overwrite anything that was there before.*/
|
|
|
|
char tmp[width+1];
|
|
|
|
char buf[width+1];
|
|
|
|
int scoreWidth = 4;
|
|
|
|
|
|
|
|
XP_ASSERT( width < outLen );
|
|
|
|
|
|
|
|
XP_MEMSET( buf, ' ', width );
|
|
|
|
buf[width] = '\0';
|
|
|
|
|
|
|
|
/* Status/role chars at start */
|
|
|
|
if ( dsi->isTurn ) {
|
|
|
|
buf[0] = 'T';
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2008-02-02 17:56:20 +01:00
|
|
|
if ( dsi->selected ) {
|
|
|
|
buf[1] = 'S';
|
2005-03-15 04:29:37 +01:00
|
|
|
}
|
2008-02-02 17:56:20 +01:00
|
|
|
if ( dsi->isRobot) {
|
|
|
|
buf[2] = 'r';
|
2005-03-15 04:29:37 +01:00
|
|
|
}
|
|
|
|
|
2008-02-02 17:56:20 +01:00
|
|
|
/* Score always goes at end. Will overwrite status if width is really small */
|
|
|
|
snprintf( tmp, scoreWidth, "%.3d", dsi->totalScore );
|
|
|
|
memcpy( &buf[width-scoreWidth+1], tmp, scoreWidth-1 );
|
|
|
|
|
|
|
|
/* Now we want to fit name, rem tiles, last score, and last move, if
|
|
|
|
there's space. Allocate to each so they're in columns. */
|
|
|
|
|
|
|
|
width -= 8; /* status chars plus space; score plus space */
|
|
|
|
if ( width > 0 ) {
|
|
|
|
int pos = 4;
|
|
|
|
int nCols = 2;
|
|
|
|
int perCol = (width - ( nCols - 1)) / nCols; /* not counting spaces */
|
|
|
|
if ( perCol > 0 ) {
|
|
|
|
int rem = (width - ( nCols - 1)) % nCols;
|
|
|
|
|
|
|
|
pos += 1 + fitIn( &buf[pos], perCol, &rem, dsi->name );
|
|
|
|
|
|
|
|
XP_U16 len = sizeof(tmp);
|
|
|
|
if ( (*dsi->lsc)( dsi->lscClosure, dsi->playerNum, tmp, &len ) ) {
|
|
|
|
char* s = tmp;
|
|
|
|
if ( len > perCol ) {
|
|
|
|
/* We want to preserve the score first, then the first part of
|
|
|
|
word. That is, WORD:20 prints as W0:20, not WORD: or
|
|
|
|
RD:20 */
|
|
|
|
char* colon = strstr( tmp, ":" );
|
|
|
|
if ( colon ) {
|
|
|
|
s += len - perCol;
|
|
|
|
memmove( s, tmp, colon - tmp - (len - perCol) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pos += 1 + fitIn( &buf[pos], perCol, NULL, s );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fitIn( &buf[pos], width, NULL, dsi->name );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2008-02-02 17:56:20 +01:00
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-02-02 17:56:20 +01:00
|
|
|
snprintf( out, outLen, "%s", buf );
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* formatScoreText */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
curses_draw_measureScoreText( DrawCtx* XP_UNUSED(p_dctx),
|
2008-02-02 17:56:20 +01:00
|
|
|
const XP_Rect* r,
|
2006-02-18 07:39:40 +01:00
|
|
|
const DrawScoreInfo* dsi,
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16* width, XP_U16* height )
|
|
|
|
{
|
2006-02-18 07:39:40 +01:00
|
|
|
XP_UCHAR buf[100];
|
2008-02-02 17:56:20 +01:00
|
|
|
formatScoreText( buf, sizeof(buf), dsi, r->width );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
*width = strlen( buf );
|
2008-02-02 17:56:20 +01:00
|
|
|
XP_ASSERT( *width <= r->width );
|
2003-11-01 06:35:29 +01:00
|
|
|
*height = 1; /* one line per player */
|
|
|
|
} /* curses_draw_measureScoreText */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
curses_draw_score_pendingScore( DrawCtx* p_dctx, const XP_Rect* rect,
|
2006-11-12 15:51:47 +01:00
|
|
|
XP_S16 score, XP_U16 XP_UNUSED(playerNum),
|
|
|
|
CellFlags XP_UNUSED(flags) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
|
|
|
char buf[4];
|
|
|
|
|
|
|
|
if ( score >= 0 ) {
|
|
|
|
sprintf( buf, "%.3d", score );
|
|
|
|
} else {
|
|
|
|
strcpy( buf, "???" );
|
|
|
|
}
|
|
|
|
|
2008-02-02 17:56:20 +01:00
|
|
|
int toptop, topbot;
|
|
|
|
getTops( rect, &toptop, &topbot );
|
|
|
|
|
|
|
|
mvwprintw( dctx->boardWin, toptop, rect->left, "pt:" );
|
|
|
|
mvwprintw( dctx->boardWin, topbot, rect->left, "%s", buf );
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* curses_draw_score_pendingScore */
|
|
|
|
|
|
|
|
static void
|
2007-01-19 09:20:58 +01:00
|
|
|
curses_draw_objFinished( DrawCtx* p_dctx, BoardObjectType XP_UNUSED(typ),
|
|
|
|
const XP_Rect* XP_UNUSED(rect),
|
|
|
|
DrawFocusState XP_UNUSED(dfs) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
|
|
|
wrefresh( dctx->boardWin );
|
2006-11-05 17:54:18 +01:00
|
|
|
} /* curses_draw_objFinished */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
#define MY_PAIR 1
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
curses_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner,
|
|
|
|
const XP_Rect* rOuter, const DrawScoreInfo* dsi )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
|
|
|
char buf[100];
|
|
|
|
int y = rInner->top;
|
2006-09-19 05:35:26 +02:00
|
|
|
|
|
|
|
curses_draw_clearRect( p_dctx, rOuter );
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
/* print the name and turn/remoteness indicator */
|
2008-02-02 17:56:20 +01:00
|
|
|
formatScoreText( buf, sizeof(buf), dsi, rInner->width );
|
2003-11-01 06:35:29 +01:00
|
|
|
mvwprintw( dctx->boardWin, y, rOuter->left, buf );
|
2006-11-14 07:47:50 +01:00
|
|
|
|
|
|
|
if ( (dsi->flags&CELL_ISCURSOR) != 0 ) {
|
|
|
|
cursesHiliteRect( dctx->boardWin, rOuter );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* curses_draw_score_drawPlayer */
|
|
|
|
|
|
|
|
static XP_Bool
|
2006-02-18 07:39:40 +01:00
|
|
|
curses_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect,
|
2009-01-13 14:02:17 +01:00
|
|
|
const XP_UCHAR* letter,
|
|
|
|
const XP_Bitmaps* XP_UNUSED(bitmaps),
|
2006-08-16 15:44:44 +02:00
|
|
|
Tile XP_UNUSED(tile), XP_S16 XP_UNUSED(owner),
|
|
|
|
XWBonusType bonus, HintAtts XP_UNUSED(hintAtts),
|
2006-11-12 15:51:47 +01:00
|
|
|
CellFlags flags )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
2007-06-01 04:08:04 +02:00
|
|
|
XP_UCHAR loc[4] = { ' ', ' ', ' ', '\0' };
|
|
|
|
XP_ASSERT( rect->width < sizeof(loc) );
|
2008-05-26 02:27:48 +02:00
|
|
|
if ( !!letter ) {
|
|
|
|
XP_MEMCPY( loc, letter, strlen(letter) );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-02-02 18:21:57 +01:00
|
|
|
/* in case it's not 1x1 */
|
|
|
|
eraseRect( dctx, rect );
|
|
|
|
|
2008-05-26 02:27:48 +02:00
|
|
|
if ( (flags & (CELL_DRAGSRC|CELL_ISEMPTY)) != 0 ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
switch ( bonus ) {
|
|
|
|
case BONUS_DOUBLE_LETTER:
|
2006-02-18 07:39:40 +01:00
|
|
|
loc[0] = '+'; break;
|
2003-11-01 06:35:29 +01:00
|
|
|
case BONUS_DOUBLE_WORD:
|
2006-02-18 07:39:40 +01:00
|
|
|
loc[0] = '*'; break;
|
2003-11-01 06:35:29 +01:00
|
|
|
case BONUS_TRIPLE_LETTER:
|
2006-02-18 07:39:40 +01:00
|
|
|
loc[0] = '^'; break;
|
2003-11-01 06:35:29 +01:00
|
|
|
case BONUS_TRIPLE_WORD:
|
2006-02-18 07:39:40 +01:00
|
|
|
loc[0] = '#'; break;
|
2003-11-01 06:35:29 +01:00
|
|
|
default:
|
2006-02-18 07:39:40 +01:00
|
|
|
loc[0] = ' ';
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* switch */
|
|
|
|
}
|
|
|
|
|
2006-11-12 15:51:47 +01:00
|
|
|
if ( (flags&CELL_HIGHLIGHT) != 0 ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
wstandout( dctx->boardWin );
|
|
|
|
}
|
|
|
|
|
2007-06-01 04:08:04 +02:00
|
|
|
mvwaddnstr( dctx->boardWin, rect->top, rect->left,
|
|
|
|
loc, rect->width );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2006-11-12 15:51:47 +01:00
|
|
|
if ( (flags&CELL_HIGHLIGHT) != 0 ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
wstandend( dctx->boardWin );
|
|
|
|
}
|
|
|
|
|
2007-01-19 09:20:58 +01:00
|
|
|
if ( (flags&CELL_ISCURSOR) != 0 ) {
|
|
|
|
cursesHiliteRect( dctx->boardWin, rect );
|
|
|
|
}
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
return XP_TRUE;
|
|
|
|
} /* curses_draw_drawCell */
|
|
|
|
|
2008-02-02 17:56:20 +01:00
|
|
|
static void
|
|
|
|
getTops( const XP_Rect* rect, int* toptop, int* topbot )
|
|
|
|
{
|
|
|
|
int top = rect->top;
|
|
|
|
if ( rect->height >= 4 ) {
|
|
|
|
++top;
|
|
|
|
}
|
|
|
|
*toptop = top;
|
|
|
|
|
|
|
|
top = rect->top + rect->height - 1;
|
|
|
|
if ( rect->height >= 3 ) {
|
|
|
|
--top;
|
|
|
|
}
|
|
|
|
*topbot = top;
|
|
|
|
} /* getTops */
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
curses_stringInTile( CursesDrawCtx* dctx, const XP_Rect* rect,
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_UCHAR* letter, XP_UCHAR* val )
|
|
|
|
{
|
|
|
|
eraseRect( dctx, rect );
|
|
|
|
|
2008-02-02 17:56:20 +01:00
|
|
|
int toptop, topbot;
|
|
|
|
getTops( rect, &toptop, &topbot );
|
|
|
|
|
2006-11-12 16:39:10 +01:00
|
|
|
if ( !!letter ) {
|
2008-02-02 17:56:20 +01:00
|
|
|
mvwaddnstr( dctx->boardWin, toptop, rect->left+(rect->width/2),
|
2006-11-12 16:39:10 +01:00
|
|
|
letter, strlen(letter) );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
if ( !!val ) {
|
|
|
|
int len = strlen( val );
|
2008-02-02 17:56:20 +01:00
|
|
|
mvwaddnstr( dctx->boardWin, topbot, rect->left + rect->width - len,
|
|
|
|
val, len );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
} /* curses_stringInTile */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
curses_draw_drawTile( DrawCtx* p_dctx, const XP_Rect* rect,
|
2009-01-13 14:02:17 +01:00
|
|
|
const XP_UCHAR* textP, const XP_Bitmaps* XP_UNUSED(bitmaps),
|
2008-12-29 04:09:35 +01:00
|
|
|
XP_U16 val, CellFlags flags )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
char numbuf[5];
|
|
|
|
char letterbuf[5];
|
|
|
|
char* nump = NULL;
|
2006-11-12 16:39:10 +01:00
|
|
|
char* letterp = NULL;
|
2003-11-01 06:35:29 +01:00
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
|
|
|
|
2006-11-12 16:39:10 +01:00
|
|
|
if ( (flags&CELL_ISEMPTY) == 0 ) {
|
|
|
|
letterbuf[0] = !!textP? *textP: '_'; /* BLANK or bitmap */
|
|
|
|
letterbuf[1] = '\0';
|
2008-12-29 04:09:35 +01:00
|
|
|
if ( (flags&CELL_VALHIDDEN) == 0 ) {
|
2006-11-12 16:39:10 +01:00
|
|
|
sprintf( numbuf, "%.2d", val );
|
|
|
|
if ( numbuf[0] == '0' ) {
|
|
|
|
numbuf[0] = ' ';
|
|
|
|
}
|
|
|
|
nump = numbuf;
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2006-11-12 16:39:10 +01:00
|
|
|
letterp = letterbuf;
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2006-11-12 16:39:10 +01:00
|
|
|
curses_stringInTile( dctx, rect, letterp, nump );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2006-11-12 15:51:47 +01:00
|
|
|
if ( (flags&CELL_HIGHLIGHT) != 0 ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
mvwaddnstr( dctx->boardWin, rect->top+rect->height-1,
|
|
|
|
rect->left, "*-*", 3 );
|
|
|
|
}
|
2006-11-14 07:47:50 +01:00
|
|
|
|
|
|
|
if ( (flags&CELL_ISCURSOR) != 0 ) {
|
|
|
|
cursesHiliteRect( dctx->boardWin, rect );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* curses_draw_drawTile */
|
|
|
|
|
|
|
|
static void
|
2006-11-12 15:51:47 +01:00
|
|
|
curses_draw_drawTileBack( DrawCtx* p_dctx, const XP_Rect* rect,
|
2006-11-14 07:47:50 +01:00
|
|
|
CellFlags flags )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
|
|
|
curses_stringInTile( dctx, rect, "?", "?" );
|
2006-11-14 07:47:50 +01:00
|
|
|
if ( (flags&CELL_ISCURSOR) != 0 ) {
|
|
|
|
cursesHiliteRect( dctx->boardWin, rect );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* curses_draw_drawTileBack */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
curses_draw_drawTrayDivider( DrawCtx* p_dctx, const XP_Rect* rect,
|
2008-07-17 07:03:01 +02:00
|
|
|
CellFlags XP_UNUSED(flags) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
|
|
|
wmove( dctx->boardWin, rect->top, rect->left );
|
|
|
|
wvline( dctx->boardWin, '#', rect->height );
|
|
|
|
|
|
|
|
} /* curses_draw_drawTrayDivider */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
curses_draw_drawBoardArrow( DrawCtx* p_dctx, const XP_Rect* rect,
|
2006-08-16 15:44:44 +02:00
|
|
|
XWBonusType XP_UNUSED(cursorBonus),
|
2006-11-12 15:51:47 +01:00
|
|
|
XP_Bool vertical, HintAtts XP_UNUSED(hintAtts),
|
|
|
|
CellFlags XP_UNUSED(flags) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
|
|
|
#if 1
|
|
|
|
char ch = vertical?'|':'-';
|
|
|
|
mvwaddch( dctx->boardWin, rect->top, rect->left, ch );
|
|
|
|
#else
|
|
|
|
chtype curChar = mvwinch(dctx->boardWin, rect->top, rect->left );
|
|
|
|
wstandout( dctx->boardWin );
|
|
|
|
mvwaddch( dctx->boardWin, rect->top, rect->left, curChar);
|
|
|
|
wstandend( dctx->boardWin );
|
|
|
|
#endif
|
|
|
|
} /* curses_draw_drawBoardArrow */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
curses_draw_clearRect( DrawCtx* p_dctx, const XP_Rect* rectP )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
|
|
|
XP_Rect rect = *rectP;
|
|
|
|
|
|
|
|
eraseRect( dctx, &rect );
|
|
|
|
} /* curses_draw_clearRect */
|
|
|
|
|
2007-02-03 18:54:20 +01:00
|
|
|
static const XP_UCHAR*
|
2006-08-16 15:44:44 +02:00
|
|
|
curses_draw_getMiniWText( DrawCtx* XP_UNUSED(p_dctx),
|
|
|
|
XWMiniTextType XP_UNUSED(textHint) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
return "Trading...";
|
|
|
|
} /* curses_draw_getMiniWText */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
curses_draw_measureMiniWText( DrawCtx* XP_UNUSED(p_dctx), const XP_UCHAR* str,
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16* widthP, XP_U16* heightP )
|
|
|
|
{
|
|
|
|
*widthP = strlen(str) + 4;
|
|
|
|
*heightP = 3;
|
|
|
|
} /* curses_draw_measureMiniWText */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
curses_draw_drawMiniWindow( DrawCtx* p_dctx, const XP_UCHAR* text,
|
2006-08-16 15:44:44 +02:00
|
|
|
const XP_Rect* rect, void** XP_UNUSED(closure) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
|
|
|
XP_Rect smallerR;
|
|
|
|
|
2007-01-19 09:20:58 +01:00
|
|
|
XP_ASSERT(0); /* does this really get called? */
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
smallerR.top = rect->top + 1;
|
|
|
|
smallerR.left = rect->left + 1;
|
|
|
|
smallerR.width = rect->width - 2;
|
|
|
|
smallerR.height = rect->height - 2;
|
|
|
|
|
|
|
|
eraseRect( dctx, rect );
|
|
|
|
drawRect( dctx->boardWin, &smallerR, '|', '-' );
|
|
|
|
|
|
|
|
mvwprintw( dctx->boardWin, smallerR.top, smallerR.left, text,
|
|
|
|
strlen(text) );
|
|
|
|
} /* curses_draw_drawMiniWindow */
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static void
|
|
|
|
curses_draw_frameTray( DrawCtx* p_dctx, XP_Rect* rect )
|
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
|
|
|
box( dctx->boardWin, '*', '+');
|
|
|
|
} /* curses_draw_frameTray */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
draw_doNothing( DrawCtx* XP_UNUSED(dctx), ... )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
} /* draw_doNothing */
|
|
|
|
|
|
|
|
DrawCtx*
|
|
|
|
cursesDrawCtxtMake( WINDOW* boardWin )
|
|
|
|
{
|
|
|
|
CursesDrawCtx* dctx = malloc( sizeof(CursesDrawCtx) );
|
|
|
|
short i;
|
|
|
|
|
|
|
|
dctx->vtable = malloc( sizeof(*(((CursesDrawCtx*)dctx)->vtable)) );
|
|
|
|
|
|
|
|
for ( i = 0; i < sizeof(*dctx->vtable)/4; ++i ) {
|
|
|
|
((void**)(dctx->vtable))[i] = draw_doNothing;
|
|
|
|
}
|
|
|
|
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_destroyCtxt, curses );
|
2008-09-05 14:11:37 +02:00
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_dictChanged, curses );
|
2003-11-01 06:35:29 +01:00
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_boardBegin, curses );
|
2006-11-05 17:54:18 +01:00
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_objFinished, curses );
|
2003-11-01 06:35:29 +01:00
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_trayBegin, curses );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_scoreBegin, curses );
|
|
|
|
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_measureRemText, curses );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawRemText, curses );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_measureScoreText, curses );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_score_pendingScore, curses );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_score_drawPlayer, curses );
|
|
|
|
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawCell, curses );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawTile, curses );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawTileBack, curses );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawTrayDivider, curses );
|
|
|
|
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawBoardArrow, curses );
|
|
|
|
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_clearRect, curses );
|
|
|
|
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawMiniWindow, curses );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_getMiniWText, curses );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_measureMiniWText, curses );
|
|
|
|
|
|
|
|
dctx->boardWin = boardWin;
|
|
|
|
|
|
|
|
return (DrawCtx*)dctx;
|
|
|
|
} /* curses_drawctxt_init */
|
|
|
|
|
|
|
|
#endif /* PLATFORM_NCURSES */
|