Exemplo n.º 1
0
static void draw_box(Layer *layer, GContext *ctx, GColor border_color, GColor back_color, GColor text_color, char *text) {
  GRect bounds = layer_get_bounds(layer);
  graphics_context_set_fill_color(ctx, back_color);
  graphics_fill_rect(ctx, layer_get_bounds(layer), PBL_IF_RECT_ELSE(8, 0), GCornersAll);
  IF_3(graphics_context_set_stroke_width(ctx, 3)); 
  graphics_context_set_stroke_color(ctx, border_color);
  graphics_draw_round_rect(ctx, layer_get_bounds(layer), PBL_IF_RECT_ELSE(8, 0));
  graphics_context_set_text_color(ctx, text_color);
  GSize text_size = graphics_text_layout_get_content_size(text, s_res_gothic_18_bold, 
                                                          GRect(5, 5, bounds.size.w-10, bounds.size.h-2), 
                                                          GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter);
  graphics_draw_text(ctx, text, s_res_gothic_18_bold, 
                     GRect(5, ((bounds.size.h-text_size.h)/2)-4, bounds.size.w-10, text_size.h), 
                     GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
}
static void typicalIconLayerCreate(uint8_t layerNumber) {
	// A lot is assumed here, could be a source of problems
	s_checkIcons_layers[layerNumber] = bitmap_layer_create(GRect(0, CHECK_ICON_START + PBL_IF_RECT_ELSE(layerNumber, layerNumber + 1) * CHECK_ICON_HEIGHT, CHECK_ICON_HEIGHT, CHECK_ICON_HEIGHT));
	bitmap_layer_set_background_color(s_checkIcons_layers[layerNumber], GColorWhite);
	bitmap_layer_set_alignment(s_checkIcons_layers[layerNumber], GAlignCenter);
	scroll_layer_add_child(s_checklist_scroll, bitmap_layer_get_layer(s_checkIcons_layers[layerNumber]));		// Adds the root layer to the window
}
Exemplo n.º 3
0
//Loads main_window
static void main_window_load(Window *window) {
  // Here we load the bitmap assets
  s_menu_icons[0] = gbitmap_create_with_resource(RESOURCE_ID_VERYGOOD);
  s_menu_icons[1] = gbitmap_create_with_resource(RESOURCE_ID_GOOD);
  s_menu_icons[2] = gbitmap_create_with_resource(RESOURCE_ID_MED);
  s_menu_icons[3] = gbitmap_create_with_resource(RESOURCE_ID_BAD);
  s_menu_icons[4] = gbitmap_create_with_resource(RESOURCE_ID_VERYBAD);
  s_menu_icons[5] = gbitmap_create_with_resource(RESOURCE_ID_EXAMPLE1);


  // Now we prepare to initialize the menu layer
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);

  //if user presses BACK, the app exits
  window_set_click_config_provider(window, back_click_config_provider);

  // Create the menu layer
  s_menu_layer = menu_layer_create(bounds);
  menu_layer_set_callbacks(s_menu_layer, NULL, (MenuLayerCallbacks){
    .get_num_rows = menu_get_num_rows_callback,
    .get_header_height = PBL_IF_RECT_ELSE(menu_get_header_height_callback, NULL),
    .draw_header = PBL_IF_RECT_ELSE(menu_draw_header_callback, NULL),
    .draw_row = menu_draw_row_callback,
    .select_click = menu_select_callback,
    .get_cell_height = PBL_IF_ROUND_ELSE(get_cell_height_callback, NULL),
  });
Exemplo n.º 4
0
// Update the display elements
static void update_display()
{
	// Update platform settings
	platformSettings.grect_background_layer = PBL_IF_RECT_ELSE(GRect(0, 0, 144, 168),GRect(0, 0, 180, 180));
	
	if (userSettings.ThinLogo)
	{	
		platformSettings.grect_time_layer = PBL_IF_RECT_ELSE(GRect(24, 108, 97, 50),GRect(42, 125, 97, 50));
		platformSettings.grect_date_layer = PBL_IF_RECT_ELSE(GRect(74,147,67,50),GRect(73,111,67,50));
		platformSettings.grect_dayOfWeek_layer = PBL_IF_RECT_ELSE(GRect(74,132,67,50),GRect(73,96,67,50));
	}
	else
	{
		platformSettings.grect_time_layer = PBL_IF_RECT_ELSE(GRect(12, 63, 97, 50),GRect(12, 70, 97, 50));
		platformSettings.grect_date_layer = PBL_IF_RECT_ELSE(GRect(74,147,67,50),GRect(115,91,67,50));
		platformSettings.grect_dayOfWeek_layer = PBL_IF_RECT_ELSE(GRect(74,132,67,50),GRect(115,76,67,50));
	}
	
	layer_set_frame(bitmap_layer_get_layer(s_background_layer), platformSettings.grect_background_layer);
	layer_mark_dirty(bitmap_layer_get_layer(s_background_layer));
	
	layer_set_frame(text_layer_get_layer(s_time_layer), platformSettings.grect_time_layer);
	layer_mark_dirty(text_layer_get_layer(s_time_layer));
	
	layer_set_frame(text_layer_get_layer(s_date_layer), platformSettings.grect_date_layer);
	layer_mark_dirty(text_layer_get_layer(s_date_layer));
	
	layer_set_frame(text_layer_get_layer(s_dayOfWeek_layer), platformSettings.grect_dayOfWeek_layer);
	layer_mark_dirty(text_layer_get_layer(s_dayOfWeek_layer));
	
	
	
	// Toggle new/old logo
	if (userSettings.ThinLogo && userSettings.Lyrics)
	{
		bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap_thin);
		layer_set_hidden(text_layer_get_layer(s_lyrics_layer),false);
	}
	else if (userSettings.ThinLogo && !userSettings.Lyrics)
	{
		bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap_thin);
		layer_set_hidden(text_layer_get_layer(s_lyrics_layer),true);
	}
	else if (!userSettings.ThinLogo && userSettings.Lyrics)
	{
		bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);
		layer_set_hidden(text_layer_get_layer(s_lyrics_layer),false);
	}
	else
	{
		bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap_dithered);
		layer_set_hidden(text_layer_get_layer(s_lyrics_layer),true);
	}
	
	// Set color of text layers
    text_layer_set_text_color(s_time_layer, userSettings.TimeColor);
    text_layer_set_text_color(s_date_layer, userSettings.DateColor);
    text_layer_set_text_color(s_dayOfWeek_layer, userSettings.DayOfWeekColor);
    text_layer_set_text_color(s_lyrics_layer, userSettings.LyricsColor);
}
static void prv_window_load(Window *window) {
  GoalStarConfigurationWindowData *data = window_get_user_data(window);
  if (!data) {
    return;
  }

  Layer *window_root_layer = window_get_root_layer(window);
  const GRect window_root_layer_bounds = layer_get_bounds(window_root_layer);

  const GRect title_layer_frame = (GRect) {
#if PBL_RECT
    // Adjust for font cap offset
    .origin = GPoint(0, -2),
#endif
    .size = GSize(window_root_layer_bounds.size.w, STATUS_BAR_LAYER_HEIGHT),
  };
  data->title_layer = text_layer_create(title_layer_frame);
  TextLayer *title_layer = data->title_layer;
  text_layer_set_text_alignment(title_layer, GTextAlignmentCenter);
  text_layer_set_overflow_mode(title_layer, GTextOverflowModeTrailingEllipsis);
  text_layer_set_background_color(title_layer, GColorClear);
  text_layer_set_text_color(title_layer, GColorBlack);
  text_layer_set_font(title_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
  text_layer_set_text(title_layer, PBL_IF_RECT_ELSE("Goal Star Configuration", "Config"));
  layer_add_child(window_root_layer, text_layer_get_layer(title_layer));

  const GEdgeInsets menu_layer_insets = PBL_IF_RECT_ELSE(GEdgeInsets(STATUS_BAR_LAYER_HEIGHT, 0, 0),
                                                         GEdgeInsets(STATUS_BAR_LAYER_HEIGHT, 0));
  const GRect menu_layer_frame = grect_inset(window_root_layer_bounds, menu_layer_insets);
  data->menu_layer = menu_layer_create(menu_layer_frame);
  MenuLayer *menu_layer = data->menu_layer;
  menu_layer_set_callbacks(menu_layer, data, (MenuLayerCallbacks) {
    .get_num_rows = prv_menu_layer_get_num_rows_callback,
    .draw_row = prv_menu_layer_draw_row_callback,
#if PBL_ROUND
    .get_cell_height = prv_menu_layer_get_cell_height,
#endif
    .select_click = prv_menu_layer_select_callback,
  });
  menu_layer_set_normal_colors(menu_layer, GColorWhite, GColorBlack);
  menu_layer_set_highlight_colors(menu_layer, GColorCobaltBlue, GColorWhite);
  menu_layer_set_click_config_onto_window(menu_layer, window);
  layer_add_child(window_root_layer, menu_layer_get_layer(menu_layer));
}
Exemplo n.º 6
0
static void main_window_load (Window *window)
{
	Layer *window_layer = window_get_root_layer(window);
	
	// Set the lyrics layer setting...
	platformSettings.grect_lyrics_layer = PBL_IF_RECT_ELSE(GRect(0,0,144,65),layer_get_bounds(window_layer));
	
    s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_TOP_LOGO);
    s_background_bitmap_dithered = gbitmap_create_with_resource(RESOURCE_ID_TOP_LOGO_DITHER);
	s_background_bitmap_thin = gbitmap_create_with_resource(RESOURCE_ID_THIN_TOP_LOGO);
    s_background_layer = bitmap_layer_create(platformSettings.grect_background_layer);
    layer_add_child(window_layer, bitmap_layer_get_layer(s_background_layer));
    
    s_time_layer = text_layer_create(platformSettings.grect_time_layer);
    text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
    text_layer_set_background_color(s_time_layer, GColorClear);
    text_layer_set_font(s_time_layer,fonts_get_system_font(FONT_KEY_BITHAM_34_MEDIUM_NUMBERS));
    layer_add_child(window_layer,text_layer_get_layer(s_time_layer));
    
    s_date_layer = text_layer_create(platformSettings.grect_date_layer);
    text_layer_set_text_alignment(s_date_layer, PBL_IF_RECT_ELSE(GTextAlignmentRight,GTextAlignmentLeft));
    text_layer_set_background_color(s_date_layer, GColorClear);
    text_layer_set_font(s_date_layer,fonts_get_system_font(FONT_KEY_GOTHIC_18));
    layer_add_child(window_layer,text_layer_get_layer(s_date_layer));
    
    s_dayOfWeek_layer = text_layer_create(platformSettings.grect_dayOfWeek_layer);
    text_layer_set_text_alignment(s_dayOfWeek_layer, PBL_IF_RECT_ELSE(GTextAlignmentRight,GTextAlignmentLeft));
    text_layer_set_background_color(s_dayOfWeek_layer, GColorClear);
    text_layer_set_font(s_dayOfWeek_layer,fonts_get_system_font(FONT_KEY_GOTHIC_18));
    layer_add_child(window_layer,text_layer_get_layer(s_dayOfWeek_layer));

    s_lyrics_layer = text_layer_create(platformSettings.grect_lyrics_layer);
    text_layer_set_font(s_lyrics_layer,fonts_get_system_font(FONT_KEY_GOTHIC_14));
    text_layer_set_background_color(s_lyrics_layer, GColorClear);
    text_layer_set_text_alignment(s_lyrics_layer, GTextAlignmentCenter);
    layer_add_child(window_layer,text_layer_get_layer(s_lyrics_layer));
    text_layer_enable_screen_text_flow_and_paging(s_lyrics_layer, 1);
        
    // Load time when window is loaded
    time_t now = time(NULL); 
    tick_handler(localtime(&now),MINUTE_UNIT | DAY_UNIT);
	
	update_display();
}
static void version_window_appear() {
	s_version_layer = text_layer_create(PBL_IF_RECT_ELSE(GRect(0, 0, 144, 168), GRect(10, 20, 160, 160)));
	typicalTextLayerSetup(s_version_layer);
	text_layer_set_font(s_version_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
	text_layer_set_text_alignment(s_version_layer, GTextAlignmentCenter);
	static char verBuffer[128];
	snprintf(verBuffer, sizeof(verBuffer), "Welcome to v2.0\nBuild %d\nCheck changelog for what's new and please heart the watch app to support development.\nClick to continue", BUILD_NUMBER);
	text_layer_set_text(s_version_layer, verBuffer);
	layer_add_child(window_get_root_layer(s_version_window), text_layer_get_layer(s_version_layer));
}
Exemplo n.º 8
0
static void initialise_ui(void) {
  
  Layer *root_layer = NULL;
  GRect bounds; 
  s_window = window_create_fullscreen(&root_layer, &bounds);
  
  s_res_img_standby = gbitmap_create_with_resource(RESOURCE_ID_IMG_STANDBY);
  s_res_img_settings = gbitmap_create_with_resource(RESOURCE_ID_IMG_SETTINGS);
  s_res_roboto_bold_subset_49 = fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49);
  s_res_gothic_18_bold = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD);
  // action_layer
  action_layer = action_bar_layer_create();
  action_bar_layer_add_to_window(action_layer, s_window);
  action_bar_layer_set_background_color(action_layer, GColorWhite);
  action_bar_layer_set_icon(action_layer, BUTTON_ID_UP, s_res_img_standby);
  action_bar_layer_set_icon(action_layer, BUTTON_ID_DOWN, s_res_img_settings);
#ifdef PBL_RECT
  layer_set_frame(action_bar_layer_get_layer(action_layer), GRect(bounds.size.w-20, 0, 20, bounds.size.h));
  IF_3(layer_set_bounds(action_bar_layer_get_layer(action_layer), GRect(-6, 0, 31, bounds.size.h)));
  // Put Action Bar underneath other layers on rectangular Pebbles
  layer_add_child(root_layer, action_bar_layer_get_layer(action_layer));
#endif
  
  // clock_layer
  clock_layer = layer_create_with_proc(root_layer, draw_clock,
                                       GRect(0 - PBL_IF_RECT_ELSE(0, ACTION_BAR_WIDTH/2), (bounds.size.h/2)-32-PBL_IF_ROUND_ELSE(2, 0), bounds.size.w, 65));
  
  // onoff_layer
  onoff_layer = layer_create_with_proc(root_layer, draw_onoff,
                                      PBL_IF_RECT_ELSE(GRect(2, (bounds.size.h/2)-82, 119, 56),
                                                   GRect(-10, (bounds.size.h/2)-82, bounds.size.w+11, 56)));
  
  // info_layer
  info_layer = layer_create_with_proc(root_layer, draw_info,
                                     PBL_IF_RECT_ELSE(GRect(2, (bounds.size.h/2)+26, 119, 56),
                                                 GRect(-10, (bounds.size.h/2)+24, bounds.size.w+11, 56)));
  
#ifdef PBL_ROUND
  // Put Action Bar on top for Pebble Round
  layer_add_child(root_layer, (Layer *)action_layer);
#endif
}
Exemplo n.º 9
0
static void window_load(Window *window) {
  SprinklesAppData *data = window_get_user_data(window);

  Layer *root_layer = window_get_root_layer(window);
  const GRect root_layer_bounds = layer_get_bounds(root_layer);

  data->homer_bitmap = gbitmap_create_with_resource(RESOURCE_ID_HOMER);

  GRect homer_bitmap_layer_frame = root_layer_bounds;
  homer_bitmap_layer_frame.size = gbitmap_get_bounds(data->homer_bitmap).size;
  grect_align(&homer_bitmap_layer_frame, &root_layer_bounds, GAlignBottom, true /* clip */);

  data->homer_layer = bitmap_layer_create(homer_bitmap_layer_frame);
  bitmap_layer_set_bitmap(data->homer_layer, data->homer_bitmap);
  bitmap_layer_set_compositing_mode(data->homer_layer, GCompOpSet);
  layer_add_child(root_layer, bitmap_layer_get_layer(data->homer_layer));

  const int16_t date_layer_width = PBL_IF_RECT_ELSE(41, 58);
  const int16_t date_layer_height = 17;
  GRect date_layer_frame = (GRect) { .size = GSize(date_layer_width, date_layer_height) };
  grect_align(&date_layer_frame, &root_layer_bounds, GAlignRight, true /* clip */);
  data->date_layer = layer_create(date_layer_frame);
  layer_set_update_proc(data->date_layer, prv_date_layer_update_proc);
  layer_add_child(root_layer, data->date_layer);

  data->homer_eyes_layer = layer_create(homer_bitmap_layer_frame);
  layer_set_update_proc(data->homer_eyes_layer, prv_homer_eyes_layer_update_proc);
  layer_add_child(root_layer, data->homer_eyes_layer);

  data->donut_bitmap = gbitmap_create_with_resource(RESOURCE_ID_DONUT);

  data->hands_layer = layer_create(root_layer_bounds);
  layer_set_update_proc(data->hands_layer, prv_hands_layer_update_proc);
  layer_add_child(root_layer, data->hands_layer);

  const time_t current_time = time(NULL);
  struct tm *current_time_tm = localtime(&current_time);
  prv_tick_timer_service_handler(current_time_tm, SECOND_UNIT);
}

static void window_unload(Window *window) {
  SprinklesAppData *data = window_get_user_data(window);

  layer_destroy(data->hands_layer);
  layer_destroy(data->homer_eyes_layer);
  layer_destroy(data->date_layer);

  gbitmap_destroy(data->donut_bitmap);

  bitmap_layer_destroy(data->homer_layer);
  gbitmap_destroy(data->homer_bitmap);

  window_destroy(window);
}
Exemplo n.º 10
0
static void initialise_ui(void) {
  
  s_window = window_create();
  Layer *root_layer = window_get_root_layer(s_window);
  GRect bounds = layer_get_bounds(root_layer); 
  window_set_background_color(s_window, COLOR_FALLBACK(GColorBulgarianRose, GColorBlack)); 
  IF_2(window_set_fullscreen(s_window, false));
  
#ifdef PBL_ROUND
  int dev_layer_left = (bounds.size.w - DEV_LAYER_WIDTH)/2;
  int dev_layer_top = (bounds.size.h - DEV_LAYER_HEIGHT)/2;
#else
  int dev_layer_left = ((bounds.size.w - DEV_LAYER_WIDTH - ACTION_BAR_WIDTH)/2) + 4;
  int dev_layer_top = ((bounds.size.h - DEV_LAYER_HEIGHT - 14)/2) + IF_32(14, 0);
#endif
  
  s_rect_above = GRect(dev_layer_left, -(DEV_LAYER_HEIGHT+2), DEV_LAYER_WIDTH, DEV_LAYER_HEIGHT);
  s_rect_onscreen = GRect(dev_layer_left, dev_layer_top, DEV_LAYER_WIDTH, DEV_LAYER_HEIGHT);
  s_rect_below = GRect(dev_layer_left, bounds.size.h+2, DEV_LAYER_WIDTH, DEV_LAYER_HEIGHT);
  
  // s_devicecard_layer
  s_devicecard_layer = devicecard_layer_create(s_rect_onscreen);
  layer_add_child(root_layer, s_devicecard_layer->layer);
  
  // s_layer_spots
  s_layer_spots = layer_create(PBL_IF_RECT_ELSE(GRect((dev_layer_left/2)-SPOT_RADIUS, dev_layer_top, 
                                                (SPOT_RADIUS*2)+1 , DEV_LAYER_HEIGHT), bounds));
  layer_add_child(root_layer, (Layer *)s_layer_spots);
  
#ifndef PBL_SDK_2
  s_status_bar = status_bar_layer_create();
  status_bar_layer_set_colors(s_status_bar, COLOR_FALLBACK(GColorBulgarianRose, GColorBlack), GColorWhite);
  layer_add_child(root_layer, status_bar_layer_get_layer(s_status_bar));
#endif
  
  s_res_image_action_up = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_UP);
  s_res_image_action_set = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_SET);
  s_res_image_action_down = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_DOWN);
  
  // s_actionbar_main
  s_actionbar_main = action_bar_layer_create();
  action_bar_layer_add_to_window(s_actionbar_main, s_window);
  action_bar_layer_set_background_color(s_actionbar_main, GColorWhite);
  action_bar_layer_set_icon(s_actionbar_main, BUTTON_ID_UP, s_res_image_action_up);
  action_bar_layer_set_icon(s_actionbar_main, BUTTON_ID_SELECT, s_res_image_action_set);
  action_bar_layer_set_icon(s_actionbar_main, BUTTON_ID_DOWN, s_res_image_action_down);
#ifdef PBL_RECT
  layer_set_frame(action_bar_layer_get_layer(s_actionbar_main), GRect(bounds.size.w-20, 0, 20, bounds.size.h));
  IF_3(layer_set_bounds(action_bar_layer_get_layer(s_actionbar_main), GRect(-5, 0, 30, bounds.size.h)));
#endif
  layer_add_child(root_layer, (Layer *)s_actionbar_main);
}
Exemplo n.º 11
0
static void main_window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);
  const int inset = 8;

  // Create UI
  s_output_layer = text_layer_create(bounds);
  text_layer_set_text(s_output_layer, "Use SELECT to start/stop the background worker.");
  text_layer_set_text_alignment(s_output_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(s_output_layer));
#ifdef PBL_ROUND
  text_layer_enable_screen_text_flow_and_paging(s_output_layer, inset);
#endif

  s_ticks_layer = text_layer_create(GRect(PBL_IF_RECT_ELSE(5, 0), 135, bounds.size.w, 30));
  text_layer_set_text(s_ticks_layer, "No data yet.");
  text_layer_set_text_alignment(s_ticks_layer, PBL_IF_RECT_ELSE(GTextAlignmentLeft, 
                                                                GTextAlignmentCenter));
  layer_add_child(window_layer, text_layer_get_layer(s_ticks_layer));
#ifdef PBL_ROUND
  text_layer_enable_screen_text_flow_and_paging(s_ticks_layer, inset);
#endif
}
Exemplo n.º 12
0
static void main_menu_window_load(Window *window)
{
    // Now we prepare to initialize the menu layer
    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_frame(window_layer);

    // Create the menu layer
    g_menu_layer = menu_layer_create(bounds);
    menu_layer_set_callbacks(g_menu_layer, NULL, (MenuLayerCallbacks){
        .get_num_sections = main_menu_num_sections_get_cb,
        .get_num_rows = main_menu_num_rows_get_cb,
        .get_header_height = PBL_IF_RECT_ELSE(main_menu_header_height_get_cb, NULL),
        .draw_header = PBL_IF_RECT_ELSE(main_menu_header_draw_cb, NULL),
        .draw_row = main_menu_row_draw_cb,
        .select_click = main_menu_select_click_cb,
    });
Exemplo n.º 13
0
static void prv_layer_update_proc(Layer *layer, GContext *ctx) {
  GoalStarStatusBarLayer *status_bar_layer = (GoalStarStatusBarLayer *)layer;
  if (!status_bar_layer) {
    return;
  }

  char clock_text[10] = {0};
  clock_copy_time_string(clock_text, sizeof(clock_text));

  GFont font = fonts_get_system_font(PBL_IF_RECT_ELSE(FONT_KEY_GOTHIC_18_BOLD,
                                                      FONT_KEY_GOTHIC_24_BOLD));

  graphics_context_set_text_color(ctx, GColorBlack);
  graphics_draw_text(ctx, clock_text, font, layer_get_bounds(layer),
                     GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
}
Exemplo n.º 14
0
static void parseStringIntoArray(char *passedString, char a_delim[]) {
	char *tmp = passedString;
	//char a_delim[] = ",";
	// Find the number of delimiters
	int delimNum = 1;		// Increment from 1 for the trailing string
	while (*tmp) {
		if (*a_delim == *tmp) {
			delimNum++;
		}
		tmp++;
	}
	//dispVal(delimNum, "Number of unique strings:");
	if (delimNum > CHECKLIST_MAX_ITEMS) {
		delimNum = CHECKLIST_MAX_ITEMS;		// Reset the number of items to show only the maximum amount
	}
	numItems = delimNum;
	//APP_LOG(APP_LOG_LEVEL_INFO, "Parsing string, heap usage: %d", (int)heap_bytes_used());

	//checklistItems = iso_realloc(checklistItems, delimNum * sizeof(char*) * MAXIMUM_LIST_ITEM_SIZE);
	if (checklistItems == NULL) {
		APP_LOG(APP_LOG_LEVEL_ERROR, "The reallocation of memory for checklistItems failed, most probably a lack of available heap.");
	}		// Reallocate enough memory for the checklist item array, returns null if failed and will error out.
	//memset(checklistItems, 0, sizeof(checklistItems));		// Reset all bytes in checklist items array to zero value
	tmp = passedString;
	int i = 0;
	for (int j = 0; j < delimNum; j++) {
		i = 0;
		while (*a_delim != *tmp && *tmp) {
			memcpy(&checklistItems[j][i], tmp, sizeof(char*));		// The address of the checklist item array increments by row every maximum list size (in characters)
			i++;
			tmp++;
		}
		tmp++;		// Increment to get passed the delimiter that stopped the while loop
		checklistItems[j][i] = 0;
		//APP_LOG(APP_LOG_LEVEL_INFO, "%s", checklistItems[j]);
	}

	sizeOfContent = CHECK_ICON_START + ((numItems + PBL_IF_RECT_ELSE(0,2)) * CHECK_ICON_HEIGHT);        // Add two extra items when using a round face to create an infinite scroll
	scroll_layer_set_content_size(s_checklist_scroll, GSize(144, sizeOfContent));
}
Exemplo n.º 15
0
static void main_window_load(Window *window) {
  // Here we load the bitmap assets
  s_menu_icons[0] = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MENU_ICON_BIG_WATCH);
  s_menu_icons[1] = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MENU_ICON_SECTOR_WATCH);
  s_menu_icons[2] = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MENU_ICON_BINARY_WATCH);

  // And also load the background
  s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND_BRAINS);

  // Now we prepare to initialize the menu layer
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);

  // Create the menu layer
  s_menu_layer = menu_layer_create(bounds);
  menu_layer_set_callbacks(s_menu_layer, NULL, (MenuLayerCallbacks){
    .get_num_sections = menu_get_num_sections_callback,
    .get_num_rows = menu_get_num_rows_callback,
    .get_header_height = PBL_IF_RECT_ELSE(menu_get_header_height_callback, NULL),
    .draw_header = PBL_IF_RECT_ELSE(menu_draw_header_callback, NULL),
    .draw_row = menu_draw_row_callback,
    .select_click = menu_select_callback,
    .get_cell_height = PBL_IF_ROUND_ELSE(get_cell_height_callback, NULL),
  });
static void main_window_load(Window *window) {
  s_menu_icon_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MENU_ICON_1);

  // Although we already defined NUM_FIRST_MENU_ITEMS, you can define
  // an int as such to easily change the order of menu items later
  int num_a_items = 0;

  s_first_menu_items[num_a_items++] = (SimpleMenuItem) {
    .title = "First Item",
    .callback = menu_select_callback,
  };
  s_first_menu_items[num_a_items++] = (SimpleMenuItem) {
    .title = "Second Item",
    .subtitle = "Here's a subtitle",
    .callback = menu_select_callback,
  };
  s_first_menu_items[num_a_items++] = (SimpleMenuItem) {
    .title = "Third Item",
    .subtitle = PBL_IF_RECT_ELSE("This has an icon", "Item number three"),
    .callback = open_new_window,
    .icon = PBL_IF_RECT_ELSE(s_menu_icon_image, NULL),
  };

  s_second_menu_items[0] = (SimpleMenuItem) {
    .title = "Special Item",
    .callback = special_select_callback,
  };

  s_menu_sections[0] = (SimpleMenuSection) {
    .num_items = NUM_FIRST_MENU_ITEMS,
    .items = s_first_menu_items,
  };
  s_menu_sections[1] = (SimpleMenuSection) {
    .title = PBL_IF_RECT_ELSE("Yet Another Section", NULL),
    .num_items = NUM_SECOND_MENU_ITEMS,
    .items = s_second_menu_items,
  };

  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);

  s_simple_menu_layer = simple_menu_layer_create(bounds, window, s_menu_sections, NUM_MENU_SECTIONS, NULL);

  layer_add_child(window_layer, simple_menu_layer_get_layer(s_simple_menu_layer));
}

void main_window_unload(Window *window) {
  simple_menu_layer_destroy(s_simple_menu_layer);
  gbitmap_destroy(s_menu_icon_image);
}

static void init() {
  s_main_window = window_create();
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload,
  });
  window_stack_push(s_main_window, true);
}

static void deinit() {
  window_destroy(s_main_window);
}

int main(void) {
  init();
  app_event_loop();
  deinit();
}
  if (data) {
    // TODO replace with SDK NumberWindow once it gets updated to support larger numbers
    goal_star_number_window_destroy(data->number_window);
    menu_layer_destroy(data->menu_layer);
    text_layer_destroy(data->title_layer);
    window_destroy(data->window);
  }

  free(data);
}

void goal_star_configuration_window_push(void) {
  GoalStarConfigurationWindowData *data = calloc(1, sizeof(*data));
  if (!data) {
    return;
  }

  data->window = window_create();
  Window *window = data->window;

  window_set_window_handlers(window, (WindowHandlers) {
    .load = prv_window_load,
    .unload = prv_window_unload,
  });
  window_set_user_data(window, data);

  // The window push animation on rectangular displays looks a little weird with the ring
  const bool animated = PBL_IF_RECT_ELSE(false, true);
  window_stack_push(window, animated);
}
Exemplo n.º 18
0
static const int lineWidth = 3;

static void update_layer(struct Layer* layer, GContext* ctx) {
  if(!g_water_path) {
    GPathInfo pInf = (GPathInfo){ .num_points = MAX_WATER_PATH_POINTS };
    pInf.points = g_water_path_points;
    g_water_path = gpath_create(&pInf);
  }

  GRect bounds = layer_get_bounds(g_layer);

  int y=bounds.size.h;
  g_water_path_points[0] = (GPoint){ .x = 0 , .y = y + lineWidth };
  int ct = curMins();
  int ip = 1;
  const int futureMins = PBL_IF_RECT_ELSE(10, 30);
  const int numD = numDrinks();
  const int minsToPx = 1;
  for(int i=0 ; i<numD ; ++i) {
    const int dt = drinkTime(i);
    // as the display is roughly 150px width, using minutes 1:1 fits roughly 2 hours on screen
    const int x = bounds.size.w+(dt-ct-futureMins)*minsToPx;
    if(x<0) continue;
    y -= drinkVolume(i)/10;
    if(ip>=(MAX_WATER_PATH_POINTS-1)) continue; //FIXME: maybe better do this inverse ;)
    g_water_path_points[ip++] = (GPoint){ .x = x , .y = y };
  }
  for(;ip<(MAX_WATER_PATH_POINTS-1);++ip) {
    g_water_path_points[ip] = (GPoint){ .x = bounds.size.w + lineWidth , .y = y };
  }
  g_water_path_points[(MAX_WATER_PATH_POINTS-1)].x = bounds.size.w + lineWidth;
Exemplo n.º 19
0
static void update_proc(Layer *layer, GContext *ctx) {
  // Custom drawing happens here!
	GRect bounds = layer_get_bounds(layer);
	
	graphics_context_set_fill_color(ctx, GColorBlack);
	graphics_fill_rect(ctx, bounds, 0, 0);
	
	if(center){
		return;
	}
	
	BatteryChargeState state = battery_state_service_peek();
	
	char batteryT[5];
	snprintf(batteryT, sizeof(batteryT), "%d%%", state.charge_percent);
	
	GSize size1 = graphics_text_layout_get_content_size(batteryT, fonts_get_system_font(FONT_KEY_GOTHIC_24),
																											bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentRight);
	
	GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_18);
	
	#ifdef PBL_COLOR
		graphics_context_set_text_color(ctx, state.charge_percent>20 ? GColorGreen : GColorRed);
	#else
		graphics_context_set_fill_color(ctx, GColorWhite);
	#endif
	
	graphics_draw_text(ctx, batteryT, font,
										 GRect(bounds.size.w - BATT_PADING - size1.w, bounds.size.h/2-size1.h/2, size1.w, size1.h),
										 GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
	
	#ifdef PBL_COLOR
		graphics_context_set_fill_color(ctx, connection_service_peek_pebble_app_connection() ? GColorGreen : GColorRed);
	#else
		graphics_context_set_fill_color(ctx, connection_service_peek_pebble_app_connection() ? GColorWhite : GColorBlack);
	#endif
	
	graphics_fill_circle(ctx,
											 GPoint(bounds.size.w - CONNECTED_CIR_PADING - CONNECTED_CIR_RADIUS * PBL_IF_ROUND_ELSE(3, 1),
															PBL_IF_RECT_ELSE(CONNECTED_CIR_PADING + CONNECTED_CIR_RADIUS,
																							 bounds.size.h/2-size1.h/2-CONNECTED_CIR_RADIUS-CONNECTED_CIR_PADING)),
											 CONNECTED_CIR_RADIUS);
	
	
	HealthValue steps = health_service_sum_today(HealthMetricStepCount);
	
	char steps_string[10];
	if(steps >= 1000){
		snprintf(steps_string, sizeof(steps_string), "%d.%dK", (int)steps/1000, (int)((float)(steps-(steps/1000)*1000)/100));
	}else{
		snprintf(steps_string, sizeof(steps_string), "%d", (int)steps);
	}
	
	
	GSize size2 = graphics_text_layout_get_content_size(steps_string, fonts_get_system_font(FONT_KEY_GOTHIC_24),
																											bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentRight);
	
	graphics_context_set_text_color(ctx, GColorGreen);
	graphics_draw_text(ctx, steps_string, font,
										 GRect(bounds.size.w - HEALTH_PADING * PBL_IF_ROUND_ELSE(3, 1) - size2.w,
													 PBL_IF_RECT_ELSE(bounds.size.h-size2.h-HEALTH_PADING, bounds.size.h/2+HEALTH_PADING),
													 size2.w, size2.h),
										 GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
	
	
}