From 1d87c3facd92fe58713537dbf2e901d976adeef0 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 2 Feb 2021 14:19:57 -0800 Subject: [PATCH] snapshot: tile dragging works, timers don't --- xwords4/wasm/main.c | 25 +++++++++++++++---------- xwords4/wasm/wasmdraw.c | 29 +++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/xwords4/wasm/main.c b/xwords4/wasm/main.c index 3b3e82a92..a5a1f4a13 100644 --- a/xwords4/wasm/main.c +++ b/xwords4/wasm/main.c @@ -30,8 +30,8 @@ #define WINDOW_WIDTH 400 #define WINDOW_HEIGHT 600 -#define BDWIDTH 330 -#define BDHEIGHT 330 +#define BDWIDTH 400 +#define BDHEIGHT 400 static void initGlobals( Globals* globals ) @@ -115,12 +115,12 @@ void main_set_timer( Globals* globals, XWTimerReason why, XP_U16 when, XWTimerProc proc, void* closure ) { - TimerState* timer = &globals->timers[why]; - timer->proc = proc; - timer->closure = closure; + /* TimerState* timer = &globals->timers[why]; */ + /* timer->proc = proc; */ + /* timer->closure = closure; */ - time_t now = getCurMS(); - timer->when = now + (1000 * when); + /* time_t now = getCurMS(); */ + /* timer->when = now + (1000 * when); */ } static void @@ -128,21 +128,26 @@ checkForEvent( Globals* globals ) { XP_Bool handled; XP_Bool draw = XP_FALSE; + BoardCtxt* board = globals->game.board; + SDL_Event event; if ( SDL_PollEvent(&event) ) { switch ( event.type ) { case SDL_MOUSEBUTTONDOWN: draw = event.button.button == SDL_BUTTON_LEFT - && board_handlePenDown( globals->game.board, NULL, + && board_handlePenDown( board, NULL, event.button.x, event.button.y, &handled ); break; case SDL_MOUSEBUTTONUP: draw = event.button.button == SDL_BUTTON_LEFT - && board_handlePenUp( globals->game.board, NULL, + && board_handlePenUp( board, NULL, event.button.x, event.button.y ); break; - // SDL_MouseButtonEvent + case SDL_MOUSEMOTION: + draw = board_handlePenMove( board, NULL, + event.motion.x, event.motion.y ); + break; default: break; } diff --git a/xwords4/wasm/wasmdraw.c b/xwords4/wasm/wasmdraw.c index 41898ea56..0e0d85767 100644 --- a/xwords4/wasm/wasmdraw.c +++ b/xwords4/wasm/wasmdraw.c @@ -84,7 +84,7 @@ frameRect( WasmDrawCtx* wdctx, const XP_Rect* rect ) { SDL_Rect sdlr; rectXPToSDL( &sdlr, rect ); - // SDL_SetRenderDrawColor( wdctx->renderer, COLOR_BLACK, 255 ); + SDL_SetRenderDrawColor( wdctx->renderer, COLOR_BLACK, 255 ); SDL_RenderDrawRect( wdctx->renderer, &sdlr ); } @@ -118,7 +118,8 @@ textInRect( WasmDrawCtx* wdctx, const XP_UCHAR* text, const XP_Rect* rect, SDL_QueryTexture( texture, NULL, NULL, &width, &height ); XP_LOGFF( "have w: %d; h: %d; got w: %d; h: %d", tmpR.width, tmpR.height, width, height ); - tmpR.width = width; + tmpR.width = XP_MIN( width, tmpR.width ); + tmpR.height = XP_MIN( height, tmpR.height ); SDL_Rect sdlr; rectXPToSDL( &sdlr, &tmpR ); @@ -127,13 +128,27 @@ textInRect( WasmDrawCtx* wdctx, const XP_UCHAR* text, const XP_Rect* rect, } static void -drawTile( WasmDrawCtx* wdctx, const XP_UCHAR* face, XP_U16 val, +drawTile( WasmDrawCtx* wdctx, const XP_UCHAR* face, int val, int owner, const XP_Rect* rect ) { clearRect( wdctx, rect ); - // setPlayerColor( wdctx, owner ); frameRect( wdctx, rect ); - textInRect( wdctx, face, rect, &sPlayerColors[owner] ); + + XP_Rect tmp = *rect; + tmp.width = 3 * tmp.width / 4; + tmp.height = 3 * tmp.height / 4; + textInRect( wdctx, face, &tmp, &sPlayerColors[owner] ); + + if ( 0 <= val ) { + XP_Rect tmp = *rect; + tmp.width = tmp.width / 4; + tmp.left += tmp.width * 3; + tmp.height = tmp.height / 4; + tmp.top += tmp.height * 3; + XP_UCHAR buf[4]; + XP_SNPRINTF( buf, VSIZE(buf), "%d", val ); + textInRect( wdctx, buf, &tmp, &sPlayerColors[owner] ); + } } static void @@ -256,7 +271,9 @@ wasm_draw_score_drawPlayer( DrawCtx* dctx, XWEnv xwe, { XP_LOGFF( "(playerNum: %d)", dsi->playerNum ); WasmDrawCtx* wdctx = (WasmDrawCtx*)dctx; - textInRect( wdctx, dsi->name, rInner, &sPlayerColors[dsi->playerNum] ); + XP_UCHAR buf[32]; + XP_SNPRINTF( buf, VSIZE(buf), "%s: %d", dsi->name, dsi->totalScore ); + textInRect( wdctx, buf, rInner, &sPlayerColors[dsi->playerNum] ); } static void