From 4259beb36997a9d5c9c9f266e89d9e548adb08b3 Mon Sep 17 00:00:00 2001 From: dyedgreen Date: Sun, 19 Jun 2016 16:37:07 +0200 Subject: [PATCH] Initial commit --- .gitignore | 10 ++ package.json | 28 +++++ resources/images/car_black.png | Bin 0 -> 187 bytes resources/images/car_white.png | Bin 0 -> 200 bytes resources/images/train_black.png | Bin 0 -> 251 bytes resources/images/train_white.png | Bin 0 -> 251 bytes src/pebble-directions.c | 17 +++ src/select_window.c | 186 +++++++++++++++++++++++++++++++ src/select_window.h | 10 ++ wscript | 50 +++++++++ 10 files changed, 301 insertions(+) create mode 100644 .gitignore create mode 100644 package.json create mode 100644 resources/images/car_black.png create mode 100644 resources/images/car_white.png create mode 100644 resources/images/train_black.png create mode 100644 resources/images/train_white.png create mode 100644 src/pebble-directions.c create mode 100644 src/select_window.c create mode 100644 src/select_window.h create mode 100644 wscript diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f69d3d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Ignore build generated files +build/ +dist/ +dist.zip + +# Ignore waf lock file +.lock-waf* + +# Ignore installed node modules +node_modules/ diff --git a/package.json b/package.json new file mode 100644 index 0000000..69ad1bc --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "pebble-directions", + "author": "Dyedgreen", + "version": "1.0.0", + "keywords": ["pebble-app"], + "private": true, + "dependencies": {}, + "pebble": { + "displayName": "Directions", + "uuid": "36f93ce6-8a6d-4518-989d-31a7b0458e37", + "sdkVersion": "3", + "enableMultiJS": true, + "targetPlatforms": [ + "aplite", + "basalt", + "chalk" + ], + "watchapp": { + "watchface": false + }, + "messageKeys": [ + "dummy" + ], + "resources": { + "media": [] + } + } +} diff --git a/resources/images/car_black.png b/resources/images/car_black.png new file mode 100644 index 0000000000000000000000000000000000000000..caf6101b4c8bf1181a6132df734921acb83cfa9f GIT binary patch literal 187 zcmeAS@N?(olHy`uVBq!ia0vp^{2!lvI6-xoDQ2& zC30Ibagl@6lkg!lvI6<_o-U3d z8lqPx#Bwzl@HCr$O|b4v|0)x=Ozo9I>T3H3-K~k!^)qK`{@s6O&4ZXw&iKwNO~&7O zuAHpaVJvvvW&DljihrCGpFrN)w2C|5bPi5=e(G9{d3`7Gvz$W?cB+Sx*m;w0DC*7y`;W$dLiz>uPXW8eo zl_*K+k2uM$MYsk;r{8dFSxRTg@4~C_5D@()92Q9Z2AgM1HzWOL)a9sP5=O^H2j=)iobzq7V}jJ9#A+o^k^1M_KBV<-*|Et=0AJLkN@ekjuDyWvs_Z|tz8 zn{n?u<8!dDIlGPu=?)=HGgZ+|S`3saaIWWhtCj$Tg002ovPDHLkV1k0| BYmfi{ literal 0 HcmV?d00001 diff --git a/resources/images/train_white.png b/resources/images/train_white.png new file mode 100644 index 0000000000000000000000000000000000000000..d55155d0c5135043b1a1a0aa07b1b99212459d7c GIT binary patch literal 251 zcmeAS@N?(olHy`uVBq!ia0vp^{2!lvI6;=JY5_^ zG(^`<>gGLUz~jPfz2$Ssq;r!RXE5Gqd?$Qw>Bgy(LKbvPjtw09N~Xc_R_(o?0*h}IMWiV<24pPJ&woq^2~I3Bz9C*$Mt+=m#o({#_vbM z#LMzT_4(c({dZodEm8L40)YozA+CARv_dWi8<>t0` zn%l1S_=Pc6=`izYztZd|_B>#kQFfc#y~&){>7zT}jMEQ+u4nLc^>bP0l+XkK<>X@~ literal 0 HcmV?d00001 diff --git a/src/pebble-directions.c b/src/pebble-directions.c new file mode 100644 index 0000000..15a0403 --- /dev/null +++ b/src/pebble-directions.c @@ -0,0 +1,17 @@ +#include +#include + +static void init(void) { + // Open the transit mode window + select_window_push(); +} + +static void deinit(void) { + +} + +int main(void) { + init(); + app_event_loop(); + deinit(); +} diff --git a/src/select_window.c b/src/select_window.c new file mode 100644 index 0000000..3eec6a6 --- /dev/null +++ b/src/select_window.c @@ -0,0 +1,186 @@ +#include +#include "select_window.h" + +#define COLOR_FIRST COLOR_CAR + +// The main window +static Window *window; + +static MenuLayer *transit_mode_menu; + +// Transit mode icons +static GBitmap *icon_car; +static GBitmap *icon_car_black; +static GBitmap *icon_bike; +static GBitmap *icon_bike_black; +static GBitmap *icon_train; +static GBitmap *icon_train_black; +static GBitmap *icon_walking; +static GBitmap *icon_walking_black; + +// Callback for number of rows +static uint16_t get_num_rows_callback(MenuLayer *menu_layer, uint16_t section_index, void *context) { + return NUM_TRANSIT_METHODS; +} + +// Draw menu cell callback +static void draw_row_callback(GContext *ctx, const Layer *cell_layer, MenuIndex *cell_index, void *context) { + // Is the current cell highlighted? + bool highlighted = menu_cell_layer_is_highlighted(cell_layer); + // Determine what row to draw + switch (cell_index->row) { + // Driving / Car + case 0: + if (highlighted) { + menu_cell_basic_draw(ctx, cell_layer, "Driving", NULL, NULL); + } else { + menu_cell_basic_draw(ctx, cell_layer, "Driving", NULL, NULL); + } + break; + // Riding the bike + case 1: + if (highlighted) { + menu_cell_basic_draw(ctx, cell_layer, "Cycling", NULL, NULL); + } else { + menu_cell_basic_draw(ctx, cell_layer, "Cycling", NULL, NULL); + } + break; + // Going by train / public transit + case 2: + if (highlighted) { + menu_cell_basic_draw(ctx, cell_layer, "Transit", NULL, NULL); + } else { + menu_cell_basic_draw(ctx, cell_layer, "Transit", NULL, NULL); + } + break; + // Walking + case 3: + if (highlighted) { + menu_cell_basic_draw(ctx, cell_layer, "Walking", NULL, NULL); + } else { + menu_cell_basic_draw(ctx, cell_layer, "Walking", NULL, NULL); + } + break; + } +} + +static void selection_will_change_callback(struct MenuLayer *menu_layer, MenuIndex *new_index, MenuIndex old_index, void *context) { + // Change the highlight color + #ifdef PBL_COLOR + switch (new_index->row) { + // Driving / Car + case 0: + menu_layer_set_highlight_colors(transit_mode_menu, COLOR_CAR, GColorWhite); + break; + // Riding the bike + case 1: + menu_layer_set_highlight_colors(transit_mode_menu, COLOR_BIKE, GColorWhite); + break; + // Going by train / public transit + case 2: + menu_layer_set_highlight_colors(transit_mode_menu, COLOR_TRAIN, GColorWhite); + break; + // Walking + case 3: + menu_layer_set_highlight_colors(transit_mode_menu, COLOR_WALKING, GColorWhite); + break; + } + #endif +} + +// Select cell callback +static void select_cell_callback(struct MenuLayer *menu_layer, MenuIndex *cell_index, void *context) { + // Tell which action to perform TODO: Transfer this info to the js part! + switch (cell_index->row) { + // Driving / Car + case 0: + printf("Car\n"); + break; + // Riding the bike + case 1: + printf("Bike\n"); + break; + // Going by train / public transit + case 2: + printf("Train\n"); + break; + // Walking + case 3: + printf("Walking\n"); + break; + } + // Open the speak stuff... +} + +// Window unload handler +static void window_unload() { + // Destroy the menu layer + menu_layer_destroy(transit_mode_menu); + + // Destroy all images + gbitmap_destroy(icon_car); + gbitmap_destroy(icon_car_black); + gbitmap_destroy(icon_bike); + gbitmap_destroy(icon_bike_black); + gbitmap_destroy(icon_train); + gbitmap_destroy(icon_train_black); + gbitmap_destroy(icon_walking); + gbitmap_destroy(icon_walking_black); + + // Destroy the window + window_destroy(window); + window = NULL; +} + +// Window load stuff +static void window_load() { + Layer *window_layer = window_get_root_layer(window); + GRect bounds = layer_get_bounds(window_layer); + + // Create the menu layer + transit_mode_menu = menu_layer_create(bounds); + // Set the click event handles to the correct window + menu_layer_set_click_config_onto_window(transit_mode_menu, window); + // If color, set the starting highlighted color + #ifdef PBL_COLOR + menu_layer_set_highlight_colors(transit_mode_menu, COLOR_FIRST, GColorWhite); + #endif + + // Define menu callbacks + menu_layer_set_callbacks(transit_mode_menu, NULL, (MenuLayerCallbacks) { + .get_num_rows = get_num_rows_callback, + .draw_row = draw_row_callback, + .select_click = select_cell_callback, + .selection_will_change = selection_will_change_callback, + }); + + // Add the menu layer to the window + layer_add_child(window_layer, menu_layer_get_layer(transit_mode_menu)); + + // Load the icon images + /*icon_car = gbitmap_create_with_resource(RESOURCE_ID_ICON_CAR_WHITE); + icon_car_black = gbitmap_create_with_resource(RESOURCE_ID_ICON_CAR_BLACK); + icon_bike = gbitmap_create_with_resource(RESOURCE_ID_ICON_CAR_WHITE); + icon_bike_black = gbitmap_create_with_resource(RESOURCE_ID_ICON_CAR_BLACK); + icon_train = gbitmap_create_with_resource(RESOURCE_ID_ICON_TRAIN_WHITE); + icon_train_black = gbitmap_create_with_resource(RESOURCE_ID_ICON_TRAIN_BLACK); + icon_walking = gbitmap_create_with_resource(RESOURCE_ID_ICON_CAR_WHITE); + icon_walking_black = gbitmap_create_with_resource(RESOURCE_ID_ICON_CAR_BLACK);*/ +} + +// Push the window to the window stack +void select_window_push() { + if (!window) { + // Create the window + window = window_create(); + + // Initialise the window event handlers + window_set_window_handlers(window, (WindowHandlers) { + .load = window_load, + .unload = window_unload, + }); + } + + // Push window to screen + window_stack_push(window, true); +} diff --git a/src/select_window.h b/src/select_window.h new file mode 100644 index 0000000..e33b39b --- /dev/null +++ b/src/select_window.h @@ -0,0 +1,10 @@ +#pragma once +#include + +#define NUM_TRANSIT_METHODS 4 +#define COLOR_CAR GColorPictonBlue +#define COLOR_BIKE GColorTiffanyBlue +#define COLOR_TRAIN GColorSunsetOrange +#define COLOR_WALKING GColorChromeYellow + +void select_window_push(); diff --git a/wscript b/wscript new file mode 100644 index 0000000..e721ba8 --- /dev/null +++ b/wscript @@ -0,0 +1,50 @@ +# +# This file is the default set of rules to compile a Pebble application. +# +# Feel free to customize this to your needs. +# +import os.path + +top = '.' +out = 'build' + + +def options(ctx): + ctx.load('pebble_sdk') + + +def configure(ctx): + """ + This method is used to configure your build. ctx.load(`pebble_sdk`) automatically configures + a build for each valid platform in `targetPlatforms`. Platform-specific configuration: add your + change after calling ctx.load('pebble_sdk') and make sure to set the correct environment first. + Universal configuration: add your change prior to calling ctx.load('pebble_sdk'). + """ + ctx.load('pebble_sdk') + + +def build(ctx): + ctx.load('pebble_sdk') + + build_worker = os.path.exists('worker_src') + binaries = [] + + cached_env = ctx.env + for platform in ctx.env.TARGET_PLATFORMS: + ctx.env = ctx.all_envs[platform] + ctx.set_group(ctx.env.PLATFORM_NAME) + app_elf = '{}/pebble-app.elf'.format(ctx.env.BUILD_DIR) + ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'), target=app_elf) + + if build_worker: + worker_elf = '{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR) + binaries.append({'platform': platform, 'app_elf': app_elf, 'worker_elf': worker_elf}) + ctx.pbl_worker(source=ctx.path.ant_glob('worker_src/**/*.c'), target=worker_elf) + else: + binaries.append({'platform': platform, 'app_elf': app_elf}) + ctx.env = cached_env + + ctx.set_group('bundle') + ctx.pbl_bundle(binaries=binaries, + js=ctx.path.ant_glob(['src/js/**/*.js', 'src/js/**/*.json']), + js_entry_file='src/js/app.js')