Commits

Trammell Hudson committed 8c6b7d8

Framework in place; need to work on highlight

Comments (0)

Files changed (3)

words/src/Makefile

+APP := words
+
+SRCS += words.c
+
+FONTS := \
+	fonts/Andale.ttf:16 \
+
+include ../../Makefile.pebble

words/src/fonts/Andale.ttf

+/Library/Fonts/Andale Mono.ttf

words/src/words.c

+/** \file
+ * Word clock, like the qlock2
+ */
+#include <pebble_os.h>
+#include <pebble_app.h>
+#include <pebble_fonts.h>
+
+PBL_APP_INFO(
+	"Wordsquare",
+	"hudson",
+	1, // Version
+	INVALID_RESOURCE,
+	APP_INFO_WATCH_FACE
+);
+
+#define ROWS 10
+#define COLS 11
+#define FONT_H 16
+#define FONT_W 10
+
+typedef struct
+{
+	int row;
+	int col;
+	char text[8];
+} word_t;
+
+static const word_t words[] = {
+	{  0, 0, "IT" },
+	{  5, 0, "ONE" },
+	{  6, 8, "TWO" },
+	{  5, 6, "THREE" },
+	{  6, 0, "FOUR" },
+	{  6, 4, "FIVE" }, // hour
+	{  5, 3, "SIX" },
+	{  8, 0, "SEVEN" },
+	{  7, 0, "EIGHT" },
+	{  4, 7, "NINE" },
+	{  9, 0, "TEN" }, // hour
+	{  7, 5, "ELEVEN" },
+	{  8, 5, "TWELVE" },
+	{  3, 5, "TEN" }, // minute
+	{  1, 2, "QUARTER" },
+	{  3, 0, "HALF" },
+	{  2, 0, "TWENTY" },
+	{  2, 6, "FIVE" }, // minute
+	{  4, 0, "PAST" },
+	{  3, 9, "TO" },
+	{  9, 5, "OCLOCK" },
+	{  0, 3, "IS" },
+	{  0, 2, "L" },
+	{  0, 5, "AATIME" },
+	{  1, 0, "A" },
+	{  1, 1, "T" },
+	{  1, 9, "TH" },
+	{  2, 10, "X" },
+	{  3, 4, "B" },
+	{  3, 8, "F" },
+	{  4, 4, "ERU" },
+	{  9, 3, "SE" },
+};
+
+#define WORD_COUNT ((sizeof(words) / sizeof(*words)))
+
+static Window window;
+static TextLayer layers[WORD_COUNT];
+
+
+/** Called once per minute */
+static void
+handle_tick(
+	AppContextRef ctx,
+	PebbleTickEvent * const event
+)
+{
+	(void) ctx;
+	const PblTm * const ptm = event->tick_time;
+
+	int hour = ptm->tm_hour;
+	int min = ptm->tm_min;
+
+
+/*
+	string_format_time(
+		time_buffer,
+		sizeof(time_buffer),
+		"%H:%M",
+		event->tick_time
+	);
+
+	text_layer_set_text(&ampm_layer, ampm_text);
+	text_layer_set_text(&hour_layer, hour_text);
+	text_layer_set_text(&rel_layer, rel_text);
+	text_layer_set_text(&min_layer, min_text);
+*/
+}
+
+
+static void
+text_layer(
+	TextLayer * layer,
+	int row,
+	int col,
+	const char * text,
+	int font
+)
+{
+	GRect frame = GRect(
+		col*FONT_W + 15,
+		row*FONT_H,
+		strlen(text)*(FONT_W+1),
+		FONT_H+2
+	);
+	text_layer_init(layer, frame);
+	text_layer_set_text(layer, text);
+	text_layer_set_text_color(layer, GColorWhite);
+	text_layer_set_background_color(layer, GColorClear);
+	text_layer_set_font(layer, fonts_load_custom_font(resource_get_handle(font)));
+
+	layer_add_child(&window.layer, &layer->layer);
+}
+
+
+static void
+handle_init(
+	AppContextRef ctx
+)
+{
+	(void) ctx;
+
+	window_init(&window, "Main");
+	window_stack_push(&window, true);
+	window_set_background_color(&window, GColorBlack);
+
+	resource_init_current_app(&RESOURCES);
+
+	for (unsigned i = 0 ; i < WORD_COUNT ; i++)
+	{
+		const word_t * const w = &words[i];
+		text_layer(
+			&layers[i],
+			w->row,
+			w->col,
+			w->text,
+			RESOURCE_ID_FONT_ANDALE_16
+		);
+	}
+}
+
+
+void
+pbl_main(
+	void * const params
+)
+{
+	PebbleAppHandlers handlers = {
+		.init_handler	= &handle_init,
+		.tick_info	= {
+			.tick_handler = &handle_tick,
+			.tick_units = MINUTE_UNIT,
+		},
+	};
+
+	app_event_loop(params, &handlers);
+}