Code Reference - main.c

Defines

IMG_DIR
LEXICA_EXT
LEXICA_DIR
ALPHA_EXT
ALPHA_DIR
HANDY_USE_UNSTABLE_API
GDK_DISABLE_DEPRECATED
GTK_DISABLE_DEPRECATED
OPT(T)
ROOT
ROUND(x)

Typedefs

typedef struct config_t config_t

Record of all configuration data.

typedef struct letter_t letter_t
typedef struct lang_t lang_t
typedef struct root_t root_t

Functions

void free_board(square_t ***board, int n)

Free the board array.

static void free_config(config_t **config)

Free the config data.

static void free_lang(lang_t **lang)

Free the lexicon/alphabet data.

static void shutdown(GtkApplication *app ATTR_UNUSED, gpointer root)

Callback function ran when program ends - free everything.

static void quit_app(GSimpleAction *action ATTR_UNUSED, GVariant *parameter ATTR_UNUSED, gpointer app)

Ran when the ‘quit’ action is triggered, ends the main loop.

static void clear_board(square_t **board, int n)

Clear/initialise the board - run before a new game starts.

static gboolean get_file(const char *filename, char **buf, gsize *buflen)

Reads a file stored in DATADIR into a string.

static void draw_tile(cairo_t *cr, const char *letter, const char *lang, int x, int y, const config_t *config)

Render the tile image for the given letter.

static void draw_text_in_square(GtkWidget *widget, cairo_t *cr, const char *text, const PangoFontDescription *font, int x, int y, const config_t *config)

Render the text given, in the centre of the board square at the coordinates given.

static gboolean draw_board_elements(GtkWidget *widget, cairo_t *cr, gpointer root)

Draw elements within the board: gridlines, coloured squares, and labels.

static GtkWidget *draw_board(root_t *root)

Calculate the dimensions of the whole board, and tiles.

static gchar **list_langs(void)

List available languages by searching the lexica directory.

static gchar **list_modes_for_lang(const gchar *lang)

List available game modes for the given language.

static gchar **load_lexicon(const gchar *lang, const gchar *lang_var, gint *w_num)

Load the given lexicon into an array of strings.

static letter_t *load_alphabet(const gchar *lang, const gchar *mode, gint *l_num)

Load the given alphabet into an array of letter_t.

static root_t *setup_root(void)

Create the initial root structure that gets passed everywhere.

static void show_prefs(GSimpleAction *action ATTR_UNUSED, GVariant *parameter ATTR_UNUSED, gpointer root)

A preference dialog, for the user to set the config.

static void show_about(GSimpleAction *action ATTR_UNUSED, GVariant *parameter ATTR_UNUSED, gpointer root)

A small ‘About’ dialog, with a description, license information and links.

static void setup_window(GtkApplication *app, gpointer root)

Set up thw window and draw the graphics.

static void setup_app(GtkApplication * app, gpointer root ATTR_UNUSED)

Set up the GtkApplication, create the app menu and the keyboard shortcuts.

int main(int argc, char **argv)

Main entry point: initialise libhandy, declare the GtkApplication, attach the callbacks and run the main loop.

struct config_t

Record of all configuration data.

Public Members

gint square_num

Number of squares in a row/column.

gint border_size

Thickness of border within and around the board, in pixels.

gint board_width

Overall width of board, in pixels.

gint tile_width

Width of each tile, in pixels.

double margin

Margin around the board, as a proportion of window size.

GdkRGBA font_colour
GdkRGBA border_colour
GdkRGBA *sq_colour
gchar *lang

Current language used for word list.

gchar *lang_var

Current language variant, if applicable.

gchar *mode

Current mode, i.e. rule set.

struct letter_t

Public Members

gchar *label
gint64 freq
gint64 score
struct lang_t

Public Members

gchar **words
gint w_num
letter_t *letters
gint l_num
struct root_t

Public Members

GtkWidget *window
square_t **board
config_t *config
lang_t *lang