Created
April 21, 2013 11:17
-
-
Save cstrat/5429285 to your computer and use it in GitHub Desktop.
Squash Scorer Attempt ...
Trying to get text aligned...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pebble_os.h" | |
#include "pebble_app.h" | |
#include "pebble_fonts.h" | |
#define MY_UUID { 0x7E, 0xAE, 0xA1, 0x05, 0x71, 0xC3, 0x4E, 0x4F, 0xAF, 0xF8, 0x19, 0x40, 0x88, 0xEA, 0x4A, 0xA4 } | |
PBL_APP_INFO(MY_UUID, "Squash Scorer V3", "Chris Stratford", 1, 1, DEFAULT_MENU_ICON, APP_INFO_STANDARD_APP); | |
Window window; | |
TextLayer layer_p1_games; | |
TextLayer layer_p1_score; | |
TextLayer layer_p2_games; | |
TextLayer layer_p2_score; | |
static int p1_score; | |
static int p1_games; | |
static int p2_score; | |
static int p2_games; | |
void config_provider(ClickConfig **config, Window *window); | |
void handle_init(AppContextRef ctx) { | |
(void)ctx; | |
window_init(&window, "SQUASH - VERSION 3"); | |
window_stack_push(&window, true); | |
// Set Action List | |
window_set_click_config_provider(&window, (ClickConfigProvider) config_provider); | |
// Initialise Variables | |
p1_score = 0; | |
p2_score = 0; | |
p1_games = 0; | |
p2_games = 0; | |
// Set Text Layers | |
text_layer_init(&layer_p1_games, GRect(50, 10, 144, 30)); | |
text_layer_set_text_alignment(&layer_p1_games, GTextAlignmentLeft); | |
text_layer_set_text(&layer_p1_games, "P1: Zero"); | |
layer_add_child(&window.layer, &layer_p1_games.layer); | |
text_layer_init(&layer_p1_score, GRect(10, 10, 144, 30)); | |
text_layer_set_text_alignment(&layer_p1_score, GTextAlignmentRight); | |
text_layer_set_text(&layer_p1_score, "Zero"); | |
layer_add_child(&window.layer, &layer_p1_score.layer); | |
text_layer_init(&layer_p2_games, GRect(50, 100, 144, 30)); | |
text_layer_set_text_alignment(&layer_p2_games, GTextAlignmentLeft); | |
text_layer_set_text(&layer_p2_games, "P2: Zero"); | |
layer_add_child(&window.layer, &layer_p2_games.layer); | |
text_layer_init(&layer_p2_score, GRect(10, 100, 144, 30)); | |
text_layer_set_text_alignment(&layer_p2_score, GTextAlignmentRight); | |
text_layer_set_text(&layer_p2_score, "Zero"); | |
layer_add_child(&window.layer, &layer_p2_score.layer); | |
vibes_double_pulse(); | |
} | |
void pbl_main(void *params) { | |
PebbleAppHandlers handlers = { | |
.init_handler = &handle_init | |
}; | |
app_event_loop(params, &handlers); | |
} | |
void click_player1(ClickRecognizerRef recognizer, Window *window) { | |
text_layer_set_text(&layer_p1_games, "P1: Zero"); | |
text_layer_set_text(&layer_p2_games, "P1: Zero"); | |
text_layer_set_text(&layer_p1_score, "P1: Zero"); | |
text_layer_set_text(&layer_p2_score, "P1: Zero"); | |
} | |
void click_player2(ClickRecognizerRef recognizer, Window *window) { | |
text_layer_set_text(&layer_p1_games, "Schoolboy error"); | |
text_layer_set_text(&layer_p2_games, "Schoolboy error"); | |
text_layer_set_text(&layer_p1_score, "Schoolboy error"); | |
text_layer_set_text(&layer_p2_score, "Schoolboy error"); | |
} | |
void hold_player1(ClickRecognizerRef recognizer, Window *window) { | |
vibes_long_pulse(); | |
} | |
void hold_player2(ClickRecognizerRef recognizer, Window *window) { | |
vibes_long_pulse(); | |
} | |
void config_provider(ClickConfig **config, Window *window) { | |
config[BUTTON_ID_UP]->click.handler = (ClickHandler)click_player1; | |
config[BUTTON_ID_UP]->long_click.handler = (ClickHandler)hold_player1; | |
config[BUTTON_ID_UP]->long_click.delay_ms = 1000; | |
config[BUTTON_ID_DOWN]->click.handler = (ClickHandler)click_player2; | |
config[BUTTON_ID_DOWN]->long_click.handler = (ClickHandler)hold_player1; | |
config[BUTTON_ID_DOWN]->long_click.delay_ms = 1000; | |
//config[BUTTON_ID_RESET]->click.handler = (ClickHandler)reset_handler; | |
//config[BUTTON_ID_RESET]->long_click.handler = (ClickHandler)reset_handler; | |
//config[BUTTON_ID_RESET]->long_click.delay_ms = 1000; | |
(void)window; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment