Display relay state on board, horizontal scoreboard mode only for now.

This commit is contained in:
ehouse 2009-09-20 18:45:25 +00:00
parent a5556469ef
commit 1da25307e5
5 changed files with 50 additions and 4 deletions

View file

@ -73,7 +73,7 @@ gtkFillRect( GtkDrawCtx* dctx, const XP_Rect* rect, const GdkColor* color )
}
static void
gtkEraseRect( GtkDrawCtx* dctx, const XP_Rect* rect )
gtkEraseRect( const GtkDrawCtx* dctx, const XP_Rect* rect )
{
gdk_draw_rectangle( DRAW_WHAT(dctx),
dctx->drawing_area->style->white_gc,
@ -1141,5 +1141,24 @@ gtkDrawCtxtMake( GtkWidget* drawing_area, GtkAppGlobals* globals )
return (DrawCtx*)dctx;
} /* gtkDrawCtxtMake */
void
draw_gtk_status( GtkDrawCtx* dctx, char ch )
{
GtkAppGlobals* globals = dctx->globals;
XP_Rect rect = {
.left = globals->netStatLeft,
.top = globals->netStatTop,
.width = GTK_NETSTAT_WIDTH,
.height = GTK_HOR_SCORE_HEIGHT
};
gtkEraseRect( dctx, &rect );
const XP_UCHAR str[2] = { ch, '\0' };
draw_string_at( dctx, NULL, str, GTKMIN_W_HT,
&rect, XP_GTK_JUST_CENTER,
&dctx->black, NULL );
}
#endif /* PLATFORM_GTK */

View file

@ -1,4 +1,4 @@
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make debug"; -*- */
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
/*
* Copyright 1997 - 2000 by Eric House (xwords@eehouse.org). All rights reserved.
*
@ -24,4 +24,6 @@
DrawCtx* gtkDrawCtxtMake( GtkWidget *widget, GtkAppGlobals* globals );
void draw_gtk_status( GtkDrawCtx* draw, char ch );
#endif

View file

@ -292,9 +292,13 @@ key_release_event( GtkWidget* XP_UNUSED(widget), GdkEventKey* event,
#endif
static void
relay_status_gtk( void* XP_UNUSED(closure), CommsRelayState state )
relay_status_gtk( void* closure, CommsRelayState state )
{
XP_LOGF( "%s got status: %s", __func__, CommsRelayState2Str(state) );
GtkAppGlobals* globals = (GtkAppGlobals*)closure;
globals->cGlobals.state = state;
globals->stateChar = 'A' + COMMS_RELAYSTATE_ALLCONNECTED - state;
draw_gtk_status( globals->draw, globals->stateChar );
}
static void
@ -436,6 +440,7 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
gint hscale, vscale;
gint trayTop;
gint boardTop = 0;
XP_U16 netStatWidth = 0;
if ( globals->draw == NULL ) {
createOrLoadObjects( globals );
@ -469,6 +474,10 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
board_setShowColors( globals->cGlobals.game.board, XP_TRUE );
globals->gridOn = XP_TRUE;
if ( !!globals->cGlobals.game.comms ) {
netStatWidth = GTK_NETSTAT_WIDTH;
}
timerTop = GTK_TIMER_TOP;
if ( globals->cGlobals.params->verticalScore ) {
timerLeft = GTK_BOARD_LEFT + (hscale*GTK_NUM_COLS) + 1;
@ -480,7 +489,8 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
XP_FALSE );
} else {
timerLeft = GTK_BOARD_LEFT + (hscale*GTK_NUM_COLS) - GTK_TIMER_WIDTH;
timerLeft = GTK_BOARD_LEFT + (hscale*GTK_NUM_COLS)
- GTK_TIMER_WIDTH - netStatWidth;
board_setScoreboardLoc( globals->cGlobals.game.board,
GTK_BOARD_LEFT, GTK_HOR_SCORE_TOP,
timerLeft-GTK_BOARD_LEFT,
@ -489,6 +499,12 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
}
/* Still pending: do this for the vertical score case */
if ( globals->cGlobals.game.comms ) {
globals->netStatLeft = timerLeft + GTK_TIMER_WIDTH;
globals->netStatTop = 0;
}
board_setTimerLoc( globals->cGlobals.game.board, timerLeft, timerTop,
GTK_TIMER_WIDTH, GTK_HOR_SCORE_HEIGHT );
@ -524,6 +540,7 @@ expose_event( GtkWidget* XP_UNUSED(widget),
board_invalAll( globals->cGlobals.game.board );
board_draw( globals->cGlobals.game.board );
draw_gtk_status( globals->draw, globals->stateChar );
/* gdk_draw_pixmap( widget->window, */
/* widget->style->fg_gc[GTK_WIDGET_STATE (widget)], */

View file

@ -92,6 +92,11 @@ typedef struct GtkAppGlobals {
guint timerSources[NUM_TIMERS_PLUS_ONE - 1];
#ifndef XWFEATURE_STANDALONE_ONLY
XP_U16 netStatLeft, netStatTop;
XP_UCHAR stateChar;
#endif
CommonPrefs cp;
XP_Bool gridOn;
@ -128,6 +133,7 @@ int gtkmain( LaunchParams* params, int argc, char *argv[] );
#define GTK_VERT_SCORE_HEIGHT ((MIN_SCALE*MAX_COLS) - GTK_TIMER_HEIGHT - \
GTK_TIMER_PAD)
#define GTK_TIMER_WIDTH 40
#define GTK_NETSTAT_WIDTH 20
#define GTK_TIMER_TOP GTK_HOR_SCORE_TOP
#define GTK_HOR_SCORE_WIDTH ((GTK_MIN_SCALE*MAX_COLS)-GTK_TIMER_PAD)
#define GTK_VERT_SCORE_WIDTH 40

View file

@ -135,6 +135,8 @@ struct CommonGlobals {
SocketChangedFunc socketChanged;
void* socketChangedClosure;
CommsRelayState state;
/* Allow listener sockets to be installed in either gtk or ncurses'
* polling mechanism.*/
AddAcceptorFunc addAcceptor;