Commits

Trammell Hudson committed 665f799

Rotating world map

Comments (0)

Files changed (5)

worldmap/src/Makefile

+APP := worldmap
+
+SRCS += worldmap.c
+
+FONTS := \
+	fonts/SourceCodePro-Black.otf:18 \
+
+IMAGES := \
+	images/map.png:white \
+	images/map.png:black \
+	images/menu_icon.png \
+
+include ../../Makefile.pebble

worldmap/src/fonts/SourceCodePro-Black.otf

+../../../words/src/fonts/SourceCodePro-Black.otf

worldmap/src/images/map.png

Added
New image

worldmap/src/images/menu_icon.png

Added
New image

worldmap/src/worldmap.c

+/** \file
+ * World map clock
+ */
+#include <pebble_os.h>
+#include <pebble_app.h>
+#include <pebble_fonts.h>
+
+PBL_APP_INFO(
+	"World map",
+	"hudson",
+	1, // Version
+	RESOURCE_ID_IMAGE_MENU_ICON,
+	APP_INFO_WATCH_FACE
+);
+
+static Window window;
+
+static RotBmpPairContainer map_container;
+
+static char time_text[8];
+static TextLayer time_layer;
+static const int gmt_offset = -5; // hours from GMT
+
+/** Called once per minute */
+static void
+handle_tick(
+	AppContextRef ctx,
+	PebbleTickEvent * const event
+)
+{
+	(void) ctx;
+	const PblTm * const ptm = event->tick_time;
+
+	string_format_time(
+		time_text,
+		sizeof(time_text),
+		"%H:%M",
+		ptm
+	);
+
+	text_layer_set_text(&time_layer, time_text);
+
+	// Adjust hour by GMT offset and reverse angle
+	// Also note that this image is rotated with GMT 
+	// is 180 degrees out from where it should be
+	// (world rotates "backwards" relative to the sun)
+	
+	const int32_t angle = 0
+		- TRIG_MAX_ANGLE/2
+		+ (TRIG_MAX_ANGLE * gmt_offset) / 24
+		- (TRIG_MAX_ANGLE * (ptm->tm_hour + gmt_offset)) / 24
+		- (TRIG_MAX_ANGLE * ptm->tm_min) / (60 * 24)
+		;
+/*
+	const int32_t angle = 0
+		+ (TRIG_MAX_ANGLE * ptm->tm_sec) / 60;
+*/
+
+	rotbmp_pair_layer_set_angle(&map_container.layer, angle);
+	layer_mark_dirty(&map_container.layer.layer);
+}
+
+
+static void
+text_layer(
+	TextLayer * layer,
+	GRect frame,
+	int font
+)
+{
+	text_layer_init(layer, frame);
+	text_layer_set_text(layer, "");
+	text_layer_set_text_color(layer, GColorBlack);
+	text_layer_set_background_color(layer, GColorWhite);
+	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, false);
+	window_set_background_color(&window, GColorBlack);
+
+	resource_init_current_app(&RESOURCES);
+
+	// This doesn't need the transparency, but there is no
+	// rotbmp that isn't a pair?
+	rotbmp_pair_init_container(
+		RESOURCE_ID_IMAGE_MAP_WHITE,
+		RESOURCE_ID_IMAGE_MAP_BLACK,
+		&map_container
+	);
+
+	//map_container.layer.compositing_mode = GCompOpAssignInverted;
+	//map_container.layer.compositing_mode = GCompOpAssign;
+
+	rotbmp_pair_layer_set_src_ic(&map_container.layer, GPoint(100,100));
+
+	// No dest_ic routines?
+	map_container.layer.white_layer.dest_ic = GPoint(144/2, 168/2);
+	map_container.layer.black_layer.dest_ic = GPoint(144/2, 168/2);
+
+	layer_add_child(&window.layer, &map_container.layer.layer);
+
+	text_layer(
+		&time_layer,
+		GRect(0, 150, 60, 30),
+		RESOURCE_ID_FONT_SOURCECODEPRO_BLACK_18
+	);
+}
+
+
+static void
+handle_deinit(
+	AppContextRef ctx
+)
+{
+	rotbmp_pair_deinit_container(&map_container);
+}
+
+
+void
+pbl_main(
+	void * const params
+)
+{
+	PebbleAppHandlers handlers = {
+		.init_handler	= handle_init,
+		.deinit_handler	= handle_deinit,
+		.tick_info	= {
+			.tick_handler = handle_tick,
+			.tick_units = MINUTE_UNIT,
+			//.tick_units = SECOND_UNIT,
+		},
+	};
+
+	app_event_loop(params, &handlers);
+}