mirror of
https://github.com/Threnklyn/pebble-directions.git
synced 2026-05-18 12:53:27 +02:00
Initial commit
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
# Ignore build generated files
|
||||
build/
|
||||
dist/
|
||||
dist.zip
|
||||
|
||||
# Ignore waf lock file
|
||||
.lock-waf*
|
||||
|
||||
# Ignore installed node modules
|
||||
node_modules/
|
||||
@@ -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": []
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 187 B |
Binary file not shown.
|
After Width: | Height: | Size: 200 B |
Binary file not shown.
|
After Width: | Height: | Size: 251 B |
Binary file not shown.
|
After Width: | Height: | Size: 251 B |
@@ -0,0 +1,17 @@
|
||||
#include <pebble.h>
|
||||
#include <select_window.h>
|
||||
|
||||
static void init(void) {
|
||||
// Open the transit mode window
|
||||
select_window_push();
|
||||
}
|
||||
|
||||
static void deinit(void) {
|
||||
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
init();
|
||||
app_event_loop();
|
||||
deinit();
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
#include <pebble.h>
|
||||
#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);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <pebble.h>
|
||||
|
||||
#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();
|
||||
@@ -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')
|
||||
Reference in New Issue
Block a user