Commits

Trammell Hudson  committed 029f35b

display the fonts

  • Participants
  • Parent commits bd7a17a

Comments (0)

Files changed (4)

File Makefile.pebble

 -include $(TOP)/Makefile.config
 
 # If Makefile.config does not define these, use defaults paths.
-PEBBLE_HOME ?= $(HOME)/build/pebble/pebble-sdk-release-001/sdk
+#PEBBLE_HOME ?= $(HOME)/build/pebble/pebble-sdk-release-001/sdk
+PEBBLE_HOME ?= $(HOME)/build/pebble/v1.1/Pebble/sdk
 ARM_GCC_PATH ?= $(HOME)/arm-cs-tools/bin
 
 GCC_PREFIX := $(ARM_GCC_PATH)/arm-none-eabi-

File sample/images/menu_icon.png

Added
New image

File sample/src/Makefile

+#
+# Show the builtin fonts
+#
+
+APP := fonts
+
+SRCS += sample.c
+
+FONTS := \
+
+IMAGES := \
+	images/menu_icon.png \
+
+include ../../Makefile.pebble

File sample/src/sample.c

+/** \file
+ * Display all the built in fonts
+ *
+ */
+#include "pebble_os.h"
+#include "pebble_app.h"
+#include "pebble_fonts.h"
+#include "pebble_th.h"
+
+#define UUID { 0xE6, 0x87, 0x18, 0x07, 0x0E, 0x8A, 0x4F, 0xC2, 0xB6, 0xFF, 0x0E, 0x66, 0xA9, 0xC1, 0x7E, 0xA9 }
+
+PBL_APP_INFO(
+	UUID,
+	"Font Sample",
+	"hudson",
+	1, 0, // Version
+	RESOURCE_ID_IMAGE_MENU_ICON,
+	APP_INFO_WATCH_FACE
+);
+
+
+static Window window;
+static Layer layer;
+static PblTm now;
+
+static void
+draw_text(
+        GContext * ctx,
+	int x,
+	int y,
+	const char * font,
+	const char * buf
+)
+{
+	graphics_text_draw(ctx,
+		buf,
+		fonts_get_system_font(font),
+		GRect(x, y, PEBBLE_SCREEN_WIDTH, 80),
+		GTextOverflowModeTrailingEllipsis,
+		GTextAlignmentCenter,
+		NULL
+	);
+}
+
+
+static void
+layer_update(
+        Layer * const me,
+        GContext * ctx
+)
+{
+	char buf[32];
+	string_format_time(
+		buf,
+		sizeof(buf),
+		"%H:%M:%S",
+		&now
+	);
+
+	int y = 0;
+/*
+	layer.frame.origin.y -= 4;
+	if (layer.frame.origin.y < -(512 - PEBBLE_SCREEN_HEIGHT))
+		layer.frame.origin.y = 0;
+*/
+
+	draw_text(ctx, 0, y, FONT_KEY_GOTHIC_14, buf);
+	y += 14;
+
+/*
+	draw_text(ctx, 0, y, FONT_KEY_GOTHIC_14_BOLD, buf);
+	y += 14;
+*/
+
+	draw_text(ctx, 0, y, FONT_KEY_GOTHIC_18, buf);
+	y += 18;
+
+/*
+	draw_text(ctx, 0, y, FONT_KEY_GOTHIC_18_BOLD, buf);
+	y += 18;
+*/
+
+	draw_text(ctx, 0, y, FONT_KEY_GOTHIC_24, buf);
+	y += 24;
+
+/*
+	draw_text(ctx, 0, y, FONT_KEY_GOTHIC_24_BOLD, buf);
+	y += 24;
+*/
+
+	draw_text(ctx, 0, y, FONT_KEY_GOTHIC_28, buf);
+	y += 28;
+
+/*
+	draw_text(ctx, 0, y, FONT_KEY_GOTHIC_28_BOLD, buf);
+	y += 28;
+
+	draw_text(ctx, 0, y, FONT_KEY_GOTHAM_18_LIGHT_SUBSET, buf);
+	y += 18;
+*/
+
+	draw_text(ctx, 0, y, FONT_KEY_GOTHAM_30_BLACK, buf);
+	y += 30;
+
+/*
+	draw_text(ctx, 0, y, FONT_KEY_GOTHAM_34_LIGHT_SUBSET, buf);
+	y += 34;
+*/
+
+	draw_text(ctx, 0, y, FONT_KEY_GOTHAM_42_LIGHT, buf);
+	y += 42;
+
+	draw_text(ctx, 0, y, FONT_KEY_GOTHAM_42_BOLD, buf);
+	y += 42;
+
+	draw_text(ctx, 0, y, FONT_KEY_DROID_SERIF_28_BOLD, buf);
+	y += 28;
+
+}
+
+
+/** Called once per minute */
+static void
+handle_tick(
+	AppContextRef ctx,
+	PebbleTickEvent * const event
+)
+{
+	(void) ctx;
+
+	now = *event->tick_time;
+	layer_mark_dirty(&layer);
+}
+
+
+static void
+handle_init(
+	AppContextRef ctx
+)
+{
+	(void) ctx;
+	get_time(&now);
+
+	window_init(&window, "Main");
+	window_stack_push(&window, true);
+	window_set_background_color(&window, GColorBlack);
+
+	resource_init_current_app(&RESOURCES);
+
+	layer_init(
+		&layer,
+		GRect(0, 0, PEBBLE_SCREEN_WIDTH, 512)
+	);
+
+	layer.update_proc = layer_update;
+	layer_add_child(&window.layer, &layer);
+	layer_mark_dirty(&layer);
+}
+
+
+static void
+handle_deinit(
+	AppContextRef ctx
+)
+{
+	(void) ctx;
+}
+
+
+void
+pbl_main(
+	void * const params
+)
+{
+	PebbleAppHandlers handlers = {
+		.init_handler	= &handle_init,
+		.deinit_handler = &handle_deinit,
+		.tick_info	= {
+			.tick_handler = &handle_tick,
+			.tick_units = SECOND_UNIT,
+		},
+	};
+
+	app_event_loop(params, &handlers);
+}