From 1da25307e5b9680f092ab2ff1cba98844f5418ee Mon Sep 17 00:00:00 2001 From: ehouse Date: Sun, 20 Sep 2009 18:45:25 +0000 Subject: [PATCH] Display relay state on board, horizontal scoreboard mode only for now. --- xwords4/linux/gtkdraw.c | 21 ++++++++++++++++++++- xwords4/linux/gtkdraw.h | 4 +++- xwords4/linux/gtkmain.c | 21 +++++++++++++++++++-- xwords4/linux/gtkmain.h | 6 ++++++ xwords4/linux/main.h | 2 ++ 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/xwords4/linux/gtkdraw.c b/xwords4/linux/gtkdraw.c index 308ece5fc..2d437bc0b 100644 --- a/xwords4/linux/gtkdraw.c +++ b/xwords4/linux/gtkdraw.c @@ -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 */ diff --git a/xwords4/linux/gtkdraw.h b/xwords4/linux/gtkdraw.h index 08499adcf..26b3de603 100644 --- a/xwords4/linux/gtkdraw.h +++ b/xwords4/linux/gtkdraw.h @@ -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 diff --git a/xwords4/linux/gtkmain.c b/xwords4/linux/gtkmain.c index 6e23d2b5e..f4ad09db9 100644 --- a/xwords4/linux/gtkmain.c +++ b/xwords4/linux/gtkmain.c @@ -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)], */ diff --git a/xwords4/linux/gtkmain.h b/xwords4/linux/gtkmain.h index e53bd9859..63a814a51 100644 --- a/xwords4/linux/gtkmain.h +++ b/xwords4/linux/gtkmain.h @@ -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 diff --git a/xwords4/linux/main.h b/xwords4/linux/main.h index c12414d0c..2ebaf700f 100644 --- a/xwords4/linux/main.h +++ b/xwords4/linux/main.h @@ -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;