commit 4259beb36997a9d5c9c9f266e89d9e548adb08b3 Author: dyedgreen Date: Sun Jun 19 16:37:07 2016 +0200 Initial commit 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 0000000..caf6101 Binary files /dev/null and b/resources/images/car_black.png differ diff --git a/resources/images/car_white.png b/resources/images/car_white.png new file mode 100644 index 0000000..dd9b8fe Binary files /dev/null and b/resources/images/car_white.png differ diff --git a/resources/images/train_black.png b/resources/images/train_black.png new file mode 100644 index 0000000..2b2e1eb Binary files /dev/null and b/resources/images/train_black.png differ diff --git a/resources/images/train_white.png b/resources/images/train_white.png new file mode 100644 index 0000000..d55155d Binary files /dev/null and b/resources/images/train_white.png differ 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')