From 11c2f634f312ae45281a1ae90dcaf4fa46d03e79 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 9 Aug 2019 17:53:34 +0200 Subject: [PATCH] examples/tetris: better font initialization --- examples/tetris/tetris.v | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/tetris/tetris.v b/examples/tetris/tetris.v index 172b68d8af..901922bc67 100644 --- a/examples/tetris/tetris.v +++ b/examples/tetris/tetris.v @@ -21,6 +21,14 @@ const ( TimerPeriod = 250 // ms ) +const ( + text_cfg = gx.TextCfg{ + align:gx.ALIGN_LEFT + size:12 + color:gx.rgb(0, 0, 170) + } +) + const ( // Tetros' 4 possible states are encoded in binaries BTetros = [ @@ -105,8 +113,7 @@ struct Game { gg *gg.GG // ft context for font drawing ft *freetype.Context - // gx text config for font drawing - tcfg *gx.TextCfg + font_loaded bool } fn main() { @@ -121,7 +128,6 @@ fn main() { window_user_ptr: game }) ft: 0 - tcfg: 0 } game.gg.window.set_user_ptr(game) // TODO remove this when `window_user_ptr:` works game.init_game() @@ -135,14 +141,7 @@ fn main() { use_ortho: true font_size: 18 }, 1) - if game.ft != 0 { - // if font loaded, define default font color etc.. - game.tcfg = &gx.TextCfg{ - align:gx.ALIGN_LEFT - size:12 - color:gx.rgb(0, 0, 170) - } - } + game.font_loaded = (game.ft != 0 ) for { gg.clear(gx.White) game.draw_scene() @@ -309,8 +308,8 @@ fn (g &Game) draw_field() { } fn (g &Game) draw_score() { - if g.tcfg != 0 { - g.ft.draw_text(1, 2, 'score: ' + g.score.str(), g.tcfg) + if g.font_loaded { + g.ft.draw_text(1, 2, 'score: ' + g.score.str(), text_cfg) } }