Esempio n. 1
0
  GRect minuteFrame = (GRect) {
    .origin = {
      paddingLeft,
      top
    },
    .size = {
      bounds.size.w - paddingLeft /* width */,
      3 * 42  /* height */
    }
  };
  minuteLayer = text_layer_create(minuteFrame);
  text_layer_set_text_color(minuteLayer, GColorWhite);
  text_layer_set_background_color(minuteLayer, GColorClear);
  text_layer_set_text_alignment(minuteLayer, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft));
  GFont bitham = fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT);
  text_layer_set_font(minuteLayer, bitham);

  GRect hourFrame = (GRect) {
    .origin = {
      paddingLeft,
      top + (2 * 42)
    },
    .size = {
      bounds.size.w - paddingLeft /* width */,
      42 + 10 /* height */
    }
  };
  hourLayer = text_layer_create(hourFrame);
  text_layer_set_text_color(hourLayer, GColorWhite);
  text_layer_set_background_color(hourLayer, GColorClear);
static void prv_window_load(Window *window) {
  GoalStarNumberWindow *number_window = window_get_user_data(window);
  if (!number_window) {
    return;
  }

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

  number_window->checkmark_icon = gbitmap_create_with_resource(RESOURCE_ID_CHECKMARK);
  number_window->up_icon = gbitmap_create_with_resource(RESOURCE_ID_UP);
  number_window->down_icon = gbitmap_create_with_resource(RESOURCE_ID_DOWN);

  const GTextAlignment text_layer_alignment = GTextAlignmentRight;
  const GTextOverflowMode text_layer_overflow_mode = GTextOverflowModeTrailingEllipsis;

  const GFont label_text_font = fonts_get_system_font(FONT_KEY_GOTHIC_14);
  const int16_t label_text_font_height = 14;

  const int16_t value_text_max_font_height = 36;

  const int16_t horizontal_padding = 5;
  GRect text_container_frame = grect_inset(window_root_layer_bounds,
                                           GEdgeInsets(0, ACTION_BAR_WIDTH + horizontal_padding,
                                                       0, horizontal_padding));
  text_container_frame.size.h = label_text_font_height + value_text_max_font_height;
  grect_align(&text_container_frame, &window_root_layer_bounds, GAlignLeft, true /* clip */);
  text_container_frame.origin.y -= gbitmap_get_bounds(number_window->checkmark_icon).size.h / 2;

  GRect label_text_layer_frame = (GRect) {
    .size = GSize(text_container_frame.size.w, label_text_font_height),
  };
  grect_align(&label_text_layer_frame, &text_container_frame, GAlignTop, true /* clip */);
  number_window->label_text_layer = text_layer_create(label_text_layer_frame);
  TextLayer *label_text_layer = number_window->label_text_layer;
  text_layer_set_text(label_text_layer, number_window->label);
  text_layer_set_text_color(label_text_layer, GColorBlack);
  text_layer_set_background_color(label_text_layer, GColorClear);
  text_layer_set_font(label_text_layer, label_text_font);
  text_layer_set_overflow_mode(label_text_layer, text_layer_overflow_mode);
  text_layer_set_text_alignment(label_text_layer, text_layer_alignment);
  layer_add_child(window_root_layer, text_layer_get_layer(label_text_layer));

  GRect value_text_layer_frame = (GRect) {
    .size = GSize(text_container_frame.size.w, value_text_max_font_height),
  };
  grect_align(&value_text_layer_frame, &text_container_frame, GAlignBottom, true /* clip */);
  number_window->value_text_layer = text_layer_create(value_text_layer_frame);
  TextLayer *value_text_layer = number_window->value_text_layer;
  prv_update_value_text_layer(number_window);
  text_layer_set_text_color(value_text_layer, GColorBlack);
  text_layer_set_background_color(value_text_layer, GColorClear);
  text_layer_set_overflow_mode(value_text_layer, text_layer_overflow_mode);
  text_layer_set_text_alignment(value_text_layer, text_layer_alignment);
  layer_add_child(window_root_layer, text_layer_get_layer(value_text_layer));

  number_window->action_bar_layer = action_bar_layer_create();
  ActionBarLayer *action_bar_layer = number_window->action_bar_layer;
  action_bar_layer_set_click_config_provider(action_bar_layer, prv_click_config_provider);
  action_bar_layer_set_context(action_bar_layer, number_window);
  action_bar_layer_set_icon(action_bar_layer, BUTTON_ID_SELECT, number_window->checkmark_icon);
  action_bar_layer_set_icon(action_bar_layer, BUTTON_ID_UP, number_window->up_icon);
  action_bar_layer_set_icon(action_bar_layer, BUTTON_ID_DOWN, number_window->down_icon);
  action_bar_layer_add_to_window(action_bar_layer, window);
}

static void prv_window_unload(Window *window) {
  GoalStarNumberWindow *number_window = window_get_user_data(window);
  if (number_window) {
    text_layer_destroy(number_window->label_text_layer);
    text_layer_destroy(number_window->value_text_layer);
    action_bar_layer_destroy(number_window->action_bar_layer);
    gbitmap_destroy(number_window->checkmark_icon);
    gbitmap_destroy(number_window->up_icon);
    gbitmap_destroy(number_window->down_icon);
  }
}

static void prv_goal_star_number_window_init(GoalStarNumberWindow *number_window, const char *label,
                                             GoalStarNumberWindowCallbacks callbacks,
                                             void *callback_context) {
  if (!number_window) {
    return;
  }

  *number_window = (GoalStarNumberWindow) {
    .label = label,
    .value = 0,
    .min = GOAL_STAR_NUMBER_WINDOW_MIN,
    .max = GOAL_STAR_NUMBER_WINDOW_MAX,
    .step_size = 1,
    .callbacks = callbacks,
    .callback_context = callback_context,
  };

  number_window->window = window_create();
  Window *window = number_window->window;
  window_set_window_handlers(window, (WindowHandlers) {
    .load = prv_window_load,
    .unload = prv_window_unload,
  });
  window_set_background_color(window, GColorLightGray);
  window_set_user_data(window, number_window);
}

GoalStarNumberWindow *goal_star_number_window_create(const char *label,
                                                     GoalStarNumberWindowCallbacks callbacks,
                                                     void *callback_context) {
  GoalStarNumberWindow *number_window = calloc(1, sizeof(*number_window));
  prv_goal_star_number_window_init(number_window, label, callbacks, callback_context);
  return number_window;
}
Esempio n. 3
0
void menu_draw_option(GContext* ctx, char* option, char* value) {
  graphics_context_set_text_color(ctx, GColorBlack);
  graphics_draw_text(ctx, option, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(4, 0, 136, 28), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
  graphics_draw_text(ctx, value, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(4, 5, 136, 20), GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
}
Esempio n. 4
0
static void window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);


	icon_layer = bitmap_layer_create(GRect(82, 0, 61, 61));

	layer_add_child(window_layer, bitmap_layer_get_layer(icon_layer));

	bg_layer = text_layer_create(GRect(0, 0, 83, 40));
	text_layer_set_text_color(bg_layer, GColorBlack);
	text_layer_set_background_color(bg_layer, GColorClear);
	text_layer_set_font(bg_layer, fonts_get_system_font(FONT_KEY_BITHAM_34_MEDIUM_NUMBERS));
	text_layer_set_text_alignment(bg_layer, GTextAlignmentLeft);
	layer_add_child(window_layer, text_layer_get_layer(bg_layer));




	readtime_layer = text_layer_create(GRect(0, 40, 144, 22));
	text_layer_set_text_color(readtime_layer, GColorBlack);
	text_layer_set_background_color(readtime_layer, GColorClear);
	text_layer_set_font(readtime_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
	text_layer_set_text_alignment(readtime_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(readtime_layer));

	name_layer = text_layer_create(GRect(0, 62, 144, 22));
	text_layer_set_text_color(name_layer, GColorBlack);
	text_layer_set_background_color(name_layer, GColorWhite);
	text_layer_set_font(name_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
	text_layer_set_text_alignment(name_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(name_layer));
	//text_layer_set_text(name_layer, "Phone\45 |NAME| Change");



	

	bg_2_layer = text_layer_create(GRect(0, 84, 144, 40));
	text_layer_set_text_color(bg_2_layer, GColorBlack);
	text_layer_set_background_color(bg_2_layer, GColorWhite);
	text_layer_set_font(bg_2_layer, fonts_get_system_font(FONT_KEY_BITHAM_34_MEDIUM_NUMBERS));
	text_layer_set_text_alignment(bg_2_layer, GTextAlignmentLeft);
	layer_add_child(window_layer, text_layer_get_layer(bg_2_layer));
	//Date
	icon_2_layer = bitmap_layer_create(GRect(82, 84, 61, 61));

	layer_add_child(window_layer, bitmap_layer_get_layer(icon_2_layer));
	


	readtime_2_layer = text_layer_create(GRect(0, 124, 144, 22));
	text_layer_set_text_color(readtime_2_layer, GColorBlack);
	text_layer_set_background_color(readtime_2_layer, GColorClear);
	text_layer_set_font(readtime_2_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
	text_layer_set_text_alignment(readtime_2_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(readtime_2_layer));

	name_2_layer = text_layer_create(GRect(0, 146, 144, 22));
	text_layer_set_text_color(name_2_layer, GColorBlack);
	text_layer_set_background_color(name_2_layer, GColorWhite);
	text_layer_set_font(name_2_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
	text_layer_set_text_alignment(name_2_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(name_2_layer));
	//text_layer_set_text(name_2_layer, "\45 Name Change");



	//draw_date();

	Tuplet initial_values[] = {
		TupletInteger(CGM_ICON_KEY, (uint8_t)4),
		TupletInteger(CGM_ICON_2_KEY, (uint8_t)4),
		TupletCString(CGM_BG_KEY, ""),
		TupletCString(CGM_READTIME_KEY, "Loading..."),
		TupletInteger(CGM_ALERT_KEY, 0),
		TupletCString(CGM_BG_2, ""),
		TupletCString(CGM_DELTA_KEY, "Welcome to NS"),
		TupletCString(CGM_DELTA_2_KEY, "#wearenotwaiting"),
		TupletCString(CGM_READTIME_2_KEY, "Loading...")
	};

	app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL);

	timer = app_timer_register(1000, timer_callback, NULL);
}
Esempio n. 5
0
static void window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_bounds(window_layer);
	
	// load action bar images
	image_refresh = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_REFRESH);
  image_start = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_START);
  image_pause = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PAUSE);
  image_exit = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_EXIT);
	
	// Initialize the action bar:
	action_bar = action_bar_layer_create();
	action_bar_layer_add_to_window(action_bar, window);
	action_bar_layer_set_click_config_provider(action_bar,click_config_provider);
	action_bar_layer_set_icon(action_bar, BUTTON_ID_UP, image_start);
	action_bar_layer_set_icon(action_bar, BUTTON_ID_SELECT, image_refresh);
	action_bar_layer_set_icon(action_bar, BUTTON_ID_DOWN, image_exit);
	
	// background layer
	bg_layer = layer_create(GRect(1, 3, (bounds.size.w - 22), bounds.size.h));
	layer_set_update_proc(bg_layer, bg_layer_draw);
	layer_add_child(window_layer, bg_layer);
	
	// time remaining
	GRect bg_bounds = layer_get_bounds(bg_layer);
	time_remaining_label = text_layer_create(GRect(0, 0, bg_bounds.size.w, 25));
	text_layer_set_text(time_remaining_label, "time remaining:");
	text_layer_set_text_color(time_remaining_label, GColorWhite);
	text_layer_set_background_color(time_remaining_label, GColorClear);
	text_layer_set_font(time_remaining_label, fonts_get_system_font(FONT_KEY_GOTHIC_18));
	text_layer_set_text_alignment(time_remaining_label, GTextAlignmentCenter);
	layer_add_child(bg_layer, text_layer_get_layer(time_remaining_label));
	
	time_remaining_counter = text_layer_create(GRect(0, 20, bg_bounds.size.w, 60));
	text_layer_set_text(time_remaining_counter, "??:??");
	text_layer_set_text_color(time_remaining_counter, GColorWhite);
	text_layer_set_background_color(time_remaining_counter, GColorClear);
	text_layer_set_font(time_remaining_counter, fonts_get_system_font(FONT_KEY_BITHAM_42_MEDIUM_NUMBERS));
	text_layer_set_text_alignment(time_remaining_counter, GTextAlignmentCenter);
	layer_add_child(bg_layer, text_layer_get_layer(time_remaining_counter));
	
	// filename
	filename_label = text_layer_create(GRect(3, 78, (bg_bounds.size.w -4), 30));
	text_layer_set_overflow_mode(filename_label, GTextOverflowModeWordWrap);
	text_layer_set_text(filename_label, "loading...");
	text_layer_set_text_color(filename_label, GColorBlack);
	text_layer_set_background_color(filename_label, GColorClear);
	text_layer_set_font(filename_label, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	text_layer_set_text_alignment(filename_label, GTextAlignmentLeft);
	layer_add_child(bg_layer, text_layer_get_layer(filename_label));
	
	// status
	status_label = text_layer_create(GRect(3, 122, (bg_bounds.size.w -4), 25));
	text_layer_set_text(status_label, "loading...");
	text_layer_set_text_color(status_label, GColorWhite);
	text_layer_set_background_color(status_label, GColorClear);
	text_layer_set_font(status_label, fonts_get_system_font(FONT_KEY_GOTHIC_18));
	text_layer_set_text_alignment(status_label, GTextAlignmentLeft);
	layer_add_child(bg_layer, text_layer_get_layer(status_label));
	
	// start timer to auto-update
	tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
}
Esempio n. 6
0
static void main_window_load(Window *window) {
  GRect bounds = layer_get_bounds(window_get_root_layer(window));
  
  action_bar = action_bar_layer_create();
  action_bar_layer_set_click_config_provider(action_bar, click_config_provider);
#ifdef PBL_COLOR
  action_bar_layer_set_icon_animated(action_bar,BUTTON_ID_UP,gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_CROSS_INV),true);
  action_bar_layer_set_icon_animated(action_bar,BUTTON_ID_DOWN,gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_ZZ_INV),true);
#else
  action_bar_layer_set_icon(action_bar,BUTTON_ID_UP,gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_CROSS));
  action_bar_layer_set_icon(action_bar,BUTTON_ID_DOWN,gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_ZZ));
#endif
  action_bar_layer_add_to_window(action_bar,window);
  
  // Create output TextLayer
  s_output_layer = text_layer_create(GRect(0, bounds.size.h/2-21-(clock_is_24h_style()?0:21), bounds.size.w-ACTION_BAR_WIDTH, bounds.size.h));
  text_layer_set_text_alignment(s_output_layer, GTextAlignmentCenter);
  text_layer_set_font(s_output_layer,fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
  //snprintf(output_text, sizeof(output_text), "00:00");
  text_layer_set_text(s_output_layer, output_text);
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_output_layer));
  
  //snprintf(output_text, sizeof(output_text), "00:00");
  if(alarm_has_description(s_alarm))
  {
    // Create Description
    s_description_layer = text_layer_create(GRect(0, 6, bounds.size.w-ACTION_BAR_WIDTH, 36));
    text_layer_set_text_alignment(s_description_layer, GTextAlignmentCenter);
    text_layer_set_font(s_description_layer,fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
    text_layer_set_text(s_description_layer, s_alarm->description);
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_description_layer));
  }
  else
  {
    // Create Bitmap
    s_bitmap_layer = bitmap_layer_create(GRect(0,10,bounds.size.w-ACTION_BAR_WIDTH, bounds.size.h));
    s_logo = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_LOGO);
    bitmap_layer_set_bitmap(s_bitmap_layer,s_logo);
    bitmap_layer_set_alignment(s_bitmap_layer,GAlignTop);
    layer_add_child(window_get_root_layer(window),bitmap_layer_get_layer(s_bitmap_layer));
  }
#ifdef PBL_SDK_2
  s_inverter_layer = inverter_layer_create(GRect(0,0,bounds.size.w,bounds.size.h));
  layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(s_inverter_layer));
#endif
  s_vibration_pattern = load_persistent_storage_int(VIBRATION_PATTERN_KEY,0);
  s_vibration_duration = load_persistent_storage_int(VIBRATION_DURATION_KEY, 2);
  s_auto_snooze = load_persistent_storage_bool(AUTO_SNOOZE_KEY, true);
  do_vibrate();
  // switch off vibration after x minutes
  switch (s_vibration_duration) {
    case 0:
      s_vibration_duration = 30;
      break;
    case 1:
    s_vibration_duration = 60;
    break;
    case 2:
    s_vibration_duration = 120;
    break;
    case 3:
    s_vibration_duration = 300;
    break;
    default:
    break;
  }
  cancel_vibe_timer = app_timer_register(1000*s_vibration_duration,cancel_vibe_timer_callback,NULL);
  
  // test snoozing with the accelerometer
  /*if(s_flip_to_snooze)
  {
    accel_tap_service_subscribe(&accel_tap_handler);
  }*/
}
Esempio n. 7
0
static void init_settings() {
    
    screen_is_inverted = false;
    screen_ox = 144;
    screen_oy = 168;
    
    canvas_is_circle = false;
    canvas_justified = false;
    canvas_corner_radius = 0;
    canvas_corner_mask = GCornersAll;
    canvas_border_px = 1;
    canvas_fill_px = 0;
    canvas_layer_crop_px = canvas_fill_px;

    canvas_count_ox = 4;
    canvas_count_oy = 4;

    canvas_spacing_ox = 1;
    canvas_spacing_oy = 1;

    canvas_rectangle_ox = get_canvas_size(screen_ox,canvas_count_ox,canvas_spacing_ox);
    canvas_rectangle_oy = get_canvas_size(screen_oy,canvas_count_oy,canvas_spacing_oy);
    if (!canvas_justified) {
      if (canvas_rectangle_oy > canvas_rectangle_ox) {
        canvas_rectangle_oy = canvas_rectangle_ox;
        } else {
        canvas_rectangle_ox = canvas_rectangle_oy;
      } 
    }

    canvas_border_ox = get_canvas_border(screen_ox,canvas_count_ox,canvas_spacing_ox);
    canvas_border_oy = get_canvas_border(screen_oy,canvas_count_oy,canvas_spacing_oy);

    canvas_circle_diameter = (canvas_rectangle_ox < canvas_rectangle_oy) ? \
                              canvas_rectangle_ox : canvas_rectangle_oy;
    
    canvas_circle_radius = (canvas_circle_diameter - 1) / 2;
    
    hours_1stdigit_row = 0;
    hours_2nddigit_row = 1;
    minutes_1stdigit_row = 2;
    minutes_2nddigit_row = 3;
    seconds_1stdigit_row = 4;
    seconds_2nddigit_row = 5;

    default_digit_max_cols = 4;
    hours_1stdigit_max_cols = 4;
    minutes_1stdigit_max_cols = 4;
    seconds_1stdigit_max_cols = 4;

    refreshed_minutes_ago = 0;

    if (canvas_count_ox <= 4) {
        canvas_font_text = fonts_get_system_font(FONT_KEY_GOTHIC_14);
        canvas_font_digits = fonts_load_custom_font( \
                             resource_get_handle(RESOURCE_ID_FONT_DIGITALDREAM_NARROW_18));
        canvas_font_icons = fonts_load_custom_font( \
                             resource_get_handle(RESOURCE_ID_FONT_WEATHERICONS_REGULAR_18));

        canvas_font_text_height_px = 18;
        canvas_font_digits_height_px = 24;
        canvas_font_icons_height_px = 24;
      } else {
        canvas_font_text = fonts_get_system_font(FONT_KEY_GOTHIC_14);
        canvas_font_digits = fonts_get_system_font(FONT_KEY_GOTHIC_14);
        canvas_font_icons = fonts_get_system_font(FONT_KEY_GOTHIC_14);
        canvas_font_text_height_px = 18;
        canvas_font_digits_height_px = 18;
        canvas_font_icons_height_px = 18;
    }
}
Esempio n. 8
0
void chrono_digital_window_load_handler(struct Window *window) {
  app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "chrono digital loads");

  GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);


#ifdef PBL_SDK_3
  Layer *chrono_digital_window_layer = window_get_root_layer(chrono_digital_window);
  chrono_status_bar_layer = status_bar_layer_create();
  if (chrono_status_bar_layer == NULL) {
    trigger_memory_panic(__LINE__);
    return;
  }    
  layer_add_child(chrono_digital_window_layer, status_bar_layer_get_layer(chrono_status_bar_layer));
  
  chrono_digital_contents_layer = layer_create(GRect((SCREEN_WIDTH - DIGITAL_LAYER_WIDTH) / 2, STATUS_BAR_LAYER_HEIGHT, DIGITAL_LAYER_WIDTH, SCREEN_HEIGHT - STATUS_BAR_LAYER_HEIGHT));
  if (chrono_digital_contents_layer == NULL) {
    trigger_memory_panic(__LINE__);
    return;
  }    
  layer_add_child(chrono_digital_window_layer, chrono_digital_contents_layer);

#else  // PBL_SDK_3
  // On SDK 2.0 and before, we don't create a separate contents layer;
  // we just use the root layer.
  Layer *chrono_digital_contents_layer = window_get_root_layer(chrono_digital_window);
  
#endif  // PBL_SDK_3

  chrono_digital_current_layer = text_layer_create(GRect(25, LAP_HEIGHT * CHRONO_MAX_LAPS, 94, LAP_HEIGHT));
  if (chrono_digital_current_layer == NULL) {
    trigger_memory_panic(__LINE__);
    return;
  }    
  int i;
  for (i = 0; i < CHRONO_MAX_LAPS; ++i) {
    chrono_digital_laps_layer[i] = text_layer_create(GRect(25, LAP_HEIGHT * i, 94, LAP_HEIGHT));
    if (chrono_digital_laps_layer[i] == NULL) {
      trigger_memory_panic(__LINE__);
      return;
    }    

    text_layer_set_text(chrono_digital_laps_layer[i], chrono_laps_buffer[i]);
    text_layer_set_text_color(chrono_digital_laps_layer[i], GColorBlack);
    text_layer_set_text_alignment(chrono_digital_laps_layer[i], GTextAlignmentRight);
    text_layer_set_overflow_mode(chrono_digital_laps_layer[i], GTextOverflowModeFill);
    text_layer_set_font(chrono_digital_laps_layer[i], font);
    layer_add_child(chrono_digital_contents_layer, (Layer *)chrono_digital_laps_layer[i]);
  }

  text_layer_set_text(chrono_digital_current_layer, chrono_current_buffer);
  text_layer_set_text_color(chrono_digital_current_layer, GColorBlack);
  text_layer_set_text_alignment(chrono_digital_current_layer, GTextAlignmentRight);
  text_layer_set_overflow_mode(chrono_digital_current_layer, GTextOverflowModeFill);
  text_layer_set_font(chrono_digital_current_layer, font);
  layer_add_child(chrono_digital_contents_layer, (Layer *)chrono_digital_current_layer);

  chrono_digital_line_layer = layer_create(GRect(0, LAP_HEIGHT * CHRONO_MAX_LAPS + 1, SCREEN_WIDTH, 1));
  if (chrono_digital_line_layer == NULL) {
    trigger_memory_panic(__LINE__);
    return;
  }    
  layer_set_update_proc(chrono_digital_line_layer, &chrono_digital_line_layer_update_callback);
  layer_add_child(chrono_digital_contents_layer, (Layer *)chrono_digital_line_layer);
}
Esempio n. 9
0
void handle_init(void) {
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);

  Layer *window_layer = window_get_root_layer(window);

  // Setup weather bar
  Layer *weather_holder = layer_create(GRect(0, 0, 144, 50));
  layer_add_child(window_layer, weather_holder);

  icon_layer = bitmap_layer_create(GRect(0, 0, 40, 40));
  layer_add_child(weather_holder, bitmap_layer_get_layer(icon_layer));

  temp_layer = text_layer_create(GRect(40, 3, 144 - 40, 28));
  text_layer_set_text_color(temp_layer, GColorWhite);
  text_layer_set_background_color(temp_layer, GColorClear);
  text_layer_set_font(temp_layer,
      fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text_alignment(temp_layer, GTextAlignmentRight);
  layer_add_child(weather_holder, text_layer_get_layer(temp_layer));

  // Initialize date & time text
  Layer *date_holder = layer_create(GRect(0, 52, 144, 94));
  layer_add_child(window_layer, date_holder);

  ResHandle roboto_21 = resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21);
  text_day_layer = text_layer_create(GRect(8, 0, 144-8, 25));
  text_layer_set_text_color(text_day_layer, GColorWhite);
  text_layer_set_background_color(text_day_layer, GColorClear);
  text_layer_set_font(text_day_layer, fonts_load_custom_font(roboto_21));
  layer_add_child(date_holder, text_layer_get_layer(text_day_layer));

  text_date_layer = text_layer_create(GRect(8, 21, 144-8, 25));
  text_layer_set_text_color(text_date_layer, GColorWhite);
  text_layer_set_background_color(text_date_layer, GColorClear);
  text_layer_set_font(text_date_layer, fonts_load_custom_font(roboto_21));
  layer_add_child(date_holder, text_layer_get_layer(text_date_layer));

  line_layer = layer_create(GRect(8, 51, 144-16, 2));
  layer_set_update_proc(line_layer, line_layer_update_callback);
  layer_add_child(date_holder, line_layer);

  ResHandle roboto_49 = resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49);
  text_time_layer = text_layer_create(GRect(7, 45, 144-7, 49));
  text_layer_set_text_color(text_time_layer, GColorWhite);
  text_layer_set_background_color(text_time_layer, GColorClear);
  text_layer_set_font(text_time_layer, fonts_load_custom_font(roboto_49));
  layer_add_child(date_holder, text_layer_get_layer(text_time_layer));

  // Setup messaging
  const int inbound_size = 64;
  const int outbound_size = 64;
  app_message_open(inbound_size, outbound_size);

  Tuplet initial_values[] = {
    TupletInteger(WEATHER_ICON_KEY, (uint8_t) 13),
    TupletCString(WEATHER_TEMPERATURE_KEY, ""),
    TupletInteger(INVERT_COLOR_KEY, persist_read_bool(INVERT_COLOR_KEY)),
  };

  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values,
                ARRAY_LENGTH(initial_values), sync_tuple_changed_callback,
                NULL, NULL);

  // FIXME testing code
  battery_text_layer = text_layer_create(GRect(0, 168 - 18, 144, 168));
  text_layer_set_text_color(battery_text_layer, GColorWhite);
  text_layer_set_background_color(battery_text_layer, GColorClear);
  text_layer_set_font(battery_text_layer,
                      fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(battery_text_layer, GTextAlignmentRight);
  layer_add_child(window_layer, text_layer_get_layer(battery_text_layer));

  // Subscribe to notifications
  bluetooth_connection_service_subscribe(bluetooth_connection_changed);
  tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
  battery_state_service_subscribe(update_battery_state);

  // Update the battery on launch
  update_battery_state(battery_state_service_peek());

  // TODO: Update display here to avoid blank display on launch?
}
Esempio n. 10
0
static void main_window_load(Window *window) {
	//Create background bitmap, then set to created BitmapLayer
  s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_DEDSEC_LOGO);
  s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168));
  bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer));
	
	//Create BT bitmap, then set to created BitmapLayer
  s_bluetooth_bitmap = gbitmap_create_with_resource(RESOURCE_ID_SIGNAL);
  s_bluetooth_layer = bitmap_layer_create(GRect(0, 144, 20, 20));  
  bitmap_layer_set_bitmap(s_bluetooth_layer, s_bluetooth_bitmap);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bluetooth_layer));
	
	//Create Battery bitmap, then set to created BitmapLayer
  s_battery_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_CHARGING);
  s_battery_layer = bitmap_layer_create(GRect(122, 123, 22, 18));
	bitmap_layer_set_bitmap(s_battery_layer, s_battery_bitmap);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_battery_layer));
		
	// Create time TextLayer
  s_hour_layer = text_layer_create(GRect(0, -5, 60, 84));
  text_layer_set_background_color(s_hour_layer, GColorClear);
  text_layer_set_text_color(s_hour_layer, GColorWhite);
  text_layer_set_text(s_hour_layer, "00");

  s_minute_layer = text_layer_create(GRect(0, 55, 60, 84));
  text_layer_set_background_color(s_minute_layer, GColorClear);
  text_layer_set_text_color(s_minute_layer, GColorWhite);
  text_layer_set_text(s_minute_layer, "00");
  
  	//Create GFont
  	s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_WATCHDOGS_SUBSET_58));

  	//Apply to TextLayer
  	text_layer_set_font(s_hour_layer, s_time_font);
  	text_layer_set_text_alignment(s_hour_layer, GTextAlignmentCenter);
	
	  text_layer_set_font(s_minute_layer, s_time_font);
  	text_layer_set_text_alignment(s_minute_layer, GTextAlignmentCenter);

  	// Add it as a child layer to the Window's root layer
  	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_hour_layer));
	  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_minute_layer));
	
	//Create date text layer
	s_date_layer = text_layer_create(GRect(0, 150, 144, 18));
  text_layer_set_background_color(s_date_layer, GColorClear);
  text_layer_set_text_color(s_date_layer, GColorWhite);
  text_layer_set_text(s_date_layer, "MON_01_01_2001");
	text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight);
	text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));
    	
	//Create connection background layer
	s_connection_bg_layer = text_layer_create(GRect(0, 123, 122, 18));	
	#ifdef PBL_COLOR
	  text_layer_set_background_color(s_connection_bg_layer, GColorTiffanyBlue);
	#else
	  text_layer_set_background_color(s_connection_bg_layer, GColorClear);
	#endif
  text_layer_set_text_color(s_connection_bg_layer, GColorWhite);
  text_layer_set_text(s_connection_bg_layer, CONNECTION_TEXT);
	text_layer_set_font(s_connection_bg_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_connection_bg_layer));
	
	//Create connection text layer
	s_connection_layer = text_layer_create(GRect(0, 123, 122, 18));
  text_layer_set_text(s_connection_layer, CONNECTION_TEXT);
  s_connection_bar_color = GColorWhite;
  layer_set_update_proc((Layer*) s_connection_layer, text_update_proc);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_connection_layer));
	
	//Create hacking text layer
	s_hacking_layer = text_layer_create(GRect(0, 137, 144, 18));
  text_layer_set_background_color(s_hacking_layer, GColorClear);
  text_layer_set_text_color(s_hacking_layer, GColorWhite);
  text_layer_set_text(s_hacking_layer, "_hacking is our weapon");
	text_layer_set_text_alignment(s_hacking_layer, GTextAlignmentRight);	
	text_layer_set_font(s_hacking_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_hacking_layer));
	
	// Make sure the time is displayed from the start
  update_time();
	
	// Show current connection state
  bt_handler(bluetooth_connection_service_peek());
	
	// Show current battery state
  battery_handler(battery_state_service_peek());
}
Esempio n. 11
0
static void main_window_load(Window *window) {
    // Get information about the window needed for drawing text 'n shit
    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_bounds(window_layer);

    /* Bitmap layer for displaying the background */

    // Create GBitmap
    s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND);

    // Create BitmapLayer to display the GBitmap
    s_background_layer = bitmap_layer_create(bounds);

    // Add bitmap to the layer and add the layer to the window as a child
    bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);
    layer_add_child(window_layer, bitmap_layer_get_layer(s_background_layer));

    /* Text layer for displaying the time */

    // Create TextLayer
    s_time_layer = text_layer_create(
        GRect(0, 53, bounds.size.w, 50));

    // Set layout options
    text_layer_set_background_color(s_time_layer, GColorRed);
    text_layer_set_text_color(s_time_layer, GColorYellow);
    text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_LECO_42_NUMBERS));
    text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);

    // Add child
    layer_add_child(window_layer, text_layer_get_layer(s_time_layer));

    /* Text layer for displaying the current date */

    // Create TextLayer
    s_date_layer = text_layer_create(GRect(-10, 105, bounds.size.w, 20));

    // Set layout options
    text_layer_set_background_color(s_date_layer, GColorRed);
    text_layer_set_text_color(s_date_layer, GColorYellow);
    text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_LECO_20_BOLD_NUMBERS));
    text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight);

    // Add child
    layer_add_child(window_layer, text_layer_get_layer(s_date_layer));

    /* Text Layer for displaying battery info */

    // Create TextLayer
    s_battery_info_layer = text_layer_create(GRect(-10, 10, bounds.size.w, 20));

    // Set layout options
    text_layer_set_background_color(s_battery_info_layer, GColorRed);
    text_layer_set_text_color(s_battery_info_layer, GColorYellow);
    text_layer_set_font(s_battery_info_layer, fonts_get_system_font(FONT_KEY_LECO_20_BOLD_NUMBERS));
    text_layer_set_text_alignment(s_battery_info_layer, GTextAlignmentRight);

    // Add child
    layer_add_child(window_layer, text_layer_get_layer(s_battery_info_layer));

    // Get first value
    BatteryChargeState charge = battery_state_service_peek();
    static char charge_percent_char[] = "00000000000";
    snprintf(charge_percent_char, sizeof(charge_percent_char), "%d", charge.charge_percent);
    text_layer_set_text(s_battery_info_layer, charge_percent_char);

    /* Text Layer for displaying steps counted by Pebble Health */

    // Create TextLayer
    s_step_count_layer = text_layer_create(GRect(-10, 30, bounds.size.w, 20));

    // Set layout options
    text_layer_set_background_color(s_step_count_layer, GColorRed);
    text_layer_set_text_color(s_step_count_layer, GColorYellow);
    text_layer_set_font(s_step_count_layer, fonts_get_system_font(FONT_KEY_LECO_20_BOLD_NUMBERS));
    text_layer_set_text_alignment(s_step_count_layer, GTextAlignmentRight);

    // Add child
    layer_add_child(window_layer, text_layer_get_layer(s_step_count_layer));

    // Get first value
    update_step_counter();
}
Esempio n. 12
0
static void text_update_proc(Layer* layer, GContext* ctx) {
  graphics_context_set_fill_color(ctx, s_connection_bar_color);
  graphics_fill_rect(ctx, GRect(0, 0, 144, 18), 0, GCornerNone);
  graphics_context_set_text_color(ctx, GColorBlack);
  graphics_draw_text(ctx, CONNECTION_TEXT, fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(0,0,144,18), GTextOverflowModeFill, GTextAlignmentLeft, NULL);
}
Esempio n. 13
0
void handle_init(AppContextRef ctx) {
  (void)ctx;
  g_ctx = ctx;
  
  window_init(&window, "Golf Dashboard");
  window_stack_push(&window, true /* Animated */);
  
  GFont defaultfont = fonts_get_system_font(FONT_KEY_GOTHIC_14);
  
  layer_init(&holepar, GRect(0, 0, 144 /* width */, 40 /* height */));
  holepar.update_proc = &holepar_layer_callback;
  layer_add_child(&window.layer, &holepar);
  
  text_layer_init(&holepar_hole, GRect(0, 0, 72, 17));
  text_layer_set_background_color(&holepar_hole, GColorClear);
  text_layer_set_text_color(&holepar_hole, GColorBlack);
  text_layer_set_text(&holepar_hole, "Hole");
  text_layer_set_text_alignment(&holepar_hole, GTextAlignmentCenter);
  layer_add_child(&holepar, &holepar_hole.layer);
  
  GFont holeparfont = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);
  text_layer_init(&holepar_hole_num, GRect(0, 10, 60, 30));
  text_layer_set_background_color(&holepar_hole_num, GColorClear);
  text_layer_set_text_color(&holepar_hole_num, GColorBlack);
  text_layer_set_font(&holepar_hole_num,holeparfont);
  text_layer_set_text(&holepar_hole_num, "");
  text_layer_set_text_alignment(&holepar_hole_num, GTextAlignmentCenter);
  layer_add_child(&holepar, &holepar_hole_num.layer);
    
  text_layer_init(&holepar_par, GRect(72, 0, 72, 17));
  text_layer_set_background_color(&holepar_par, GColorClear);
  text_layer_set_text_color(&holepar_par, GColorBlack);
  text_layer_set_text(&holepar_par, "Par");
  text_layer_set_text_alignment(&holepar_par, GTextAlignmentCenter);
  layer_add_child(&holepar, &holepar_par.layer);
  
//  GFont holeparfont = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);
  text_layer_init(&holepar_par_num, GRect(75, 10, 60, 30));
  text_layer_set_background_color(&holepar_par_num, GColorClear);
  text_layer_set_text_color(&holepar_par_num, GColorBlack);
  text_layer_set_font(&holepar_par_num,holeparfont);
  text_layer_set_text(&holepar_par_num, "0");
  text_layer_set_text_alignment(&holepar_par_num, GTextAlignmentCenter);
  layer_add_child(&holepar, &holepar_par_num.layer);
  
  text_layer_init(&roundtime, GRect(0, 40, 144 /* width */, 15 /* height */));
  text_layer_set_background_color(&roundtime, GColorBlack);
  text_layer_set_text_color(&roundtime, GColorWhite);
  text_layer_set_font(&roundtime, defaultfont);
  text_layer_set_text(&roundtime, "Round Time:      ");
  text_layer_set_text_alignment(&roundtime, GTextAlignmentCenter);
  layer_add_child(&window.layer, &roundtime.layer);
  
  GFont yrdfont = fonts_get_system_font(FONT_KEY_GOTHAM_42_MEDIUM_NUMBERS);
  text_layer_init(&distance, GRect(0, 55, 144 /* width */, 50 /* height */));
  text_layer_set_background_color(&distance, GColorBlack);
  text_layer_set_text_color(&distance, GColorWhite);
// Placeholder for Sports SDK
  text_layer_set_text(&distance, "000");
  text_layer_set_font(&distance, yrdfont);
  text_layer_set_text_alignment(&distance, GTextAlignmentCenter);
  layer_add_child(&window.layer, &distance.layer);
  
 
  mini_snprintf(s_shots_hole, 25, "Shots: %d", thishole);
  text_layer_init(&shots_hole, GRect(0, 105, 72 /* width */, 15 /* height */));
  text_layer_set_background_color(&shots_hole, GColorBlack);
  text_layer_set_text_color(&shots_hole, GColorWhite);
  text_layer_set_font(&shots_hole, defaultfont);
  text_layer_set_text(&shots_hole, s_shots_hole);
  text_layer_set_text_alignment(&shots_hole, GTextAlignmentLeft);
  layer_add_child(&window.layer, &shots_hole.layer);
  
  mini_snprintf(s_shots_total, 25, "Total: %d", totalshots);
  text_layer_init(&shots_total, GRect(72, 105, 72 /* width */, 15 /* height */));
  text_layer_set_background_color(&shots_total, GColorBlack);
  text_layer_set_text_color(&shots_total, GColorWhite);
  text_layer_set_font(&shots_total, defaultfont);
  text_layer_set_text(&shots_total, s_shots_total);
  text_layer_set_text_alignment(&shots_total, GTextAlignmentRight);
  layer_add_child(&window.layer, &shots_total.layer);
  
  GFont clubfont = fonts_get_system_font(FONT_KEY_GOTHIC_24);
  text_layer_init(&club, GRect(0, 120, 144 /* width */, 168-120-16 /* height */));
  text_layer_set_background_color(&club, GColorWhite);
  text_layer_set_text_color(&club, GColorBlack);
  text_layer_set_font(&club, clubfont);
  text_layer_set_text(&club, club_menu[club_menu_index]);
  text_layer_set_text_alignment(&club, GTextAlignmentCenter);
  layer_add_child(&window.layer, &club.layer);
 
  window_set_click_config_provider(&window, (ClickConfigProvider) click_config_provider);
  
}
	// Bind the menu layer's click config provider to the window for interactivity
	menu_layer_set_click_config_onto_window(&groupLayer, &groupWindow);
	
	// Add it to the window for display
	layer_add_child(&groupWindow.layer, menu_layer_get_layer(&groupLayer));
	
	//DEVICE LAYER
	action_bar_layer_init(&deviceLayer);
	
	action_bar_layer_set_click_config_provider(&deviceLayer, device_click_config_provider);
	
	// Add it to the window for display
	action_bar_layer_add_to_window(&deviceLayer, &deviceWindow);
	
	text_layer_init(&deviceNameLayer, GRect(0, 30, 124, 150));
	text_layer_set_font(&deviceNameLayer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
	text_layer_set_overflow_mode(&deviceNameLayer, GTextOverflowModeWordWrap);
	
	layer_insert_above_sibling((Layer *)&deviceNameLayer, (Layer *)&deviceLayer);
	
	ResHandle config_file = resource_get_handle(RESOURCE_ID_CONFIG_FILE);
	size_t config_size = resource_size(config_file);
	resource_load(config_file, (uint8_t*) &config, config_size);
	
	currentWindow = WINDOW_HOME;
	
	http_set_app_id(HTTP_APP_ID);
	
	HTTPCallbacks callbacks = {
		.success = &handle_http_success,
		.failure = &handle_http_failure
/**
 * Window load handler function
 */
static void mainWindowLoad(Window *w)
{
  init_hardware_icons();
  
  // Get information about the root window
  Layer *windowLayer = window_get_root_layer(w);
  GRect bounds = layer_get_bounds(windowLayer);
  
  // Set sleepy time flag
  time_t temp_time = time(NULL);
  struct tm *cur_time = localtime(&temp_time); 
  s_is_sleepy_time = (cur_time->tm_hour <= SLEEPY_TIME_END_HOUR && cur_time->tm_hour >= SLEEPY_TIME_START_HOUR);
  
  //////////////////////////////////////////
  // Battery
  
  GRect bat_icon_bounds = get_battery_icon_bounds();
  
  // Create BitmapLayer to display the GBitmap
  s_powerIconLayer = bitmap_layer_create(GRect(bounds.size.w - (bat_icon_bounds.size.w + 2),
                                               0, bat_icon_bounds.size.w, bat_icon_bounds.size.h));

  // set background colout and compositing mode 
  bitmap_layer_set_background_color(s_powerIconLayer, POWER_ICON_BACK_COLOR);
  bitmap_layer_set_compositing_mode(s_powerIconLayer, GCompOpSet);
  
  update_power_status(battery_state_service_peek());
  
  // add the bitmap layer to the window
  layer_add_child(windowLayer, bitmap_layer_get_layer(s_powerIconLayer));
  
  //////////////////////////////////////////
  // BT connection

  GRect bt_icon_bounds = get_bt_icon_bounds();
  
  // Create BitmapLayer to display the GBitmap
  s_btIconLayer = bitmap_layer_create(GRect(bounds.size.w - (bat_icon_bounds.size.w + bt_icon_bounds.size.w + 4), 4, bt_icon_bounds.size.w, bt_icon_bounds.size.h));

  // set background colout and compositing mode 
  bitmap_layer_set_background_color(s_btIconLayer, BT_ICON_BACK_COLOR);
  bitmap_layer_set_compositing_mode(s_btIconLayer, GCompOpSet);
  
  update_bt_status(connection_service_peek_pebble_app_connection());
  
  // add the bitmap layer to the window
  layer_add_child(windowLayer, bitmap_layer_get_layer(s_btIconLayer));
  
  ////////////////////////////////////
  // Create the time text layers
  
  // time accuracy text layer
  s_timeAccText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(-2, -6), 94, 28));
  
  // Improve the layout to be more like a watchface
  text_layer_set_background_color(s_timeAccText, TIME_TEXT_BACK_COLOR);
  text_layer_set_text_color(s_timeAccText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY));
  
  //s_timeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FFF_TUSJ_42));
  GFont timeFont = fonts_get_system_font(FONT_KEY_GOTHIC_24);
  
  text_layer_set_font(s_timeAccText, timeFont);
  text_layer_set_text_alignment(s_timeAccText, GTextAlignmentLeft);

  // Add it as a child layer to the Window's root layer
  layer_add_child(windowLayer, text_layer_get_layer(s_timeAccText));
    
  // time text layer
  s_timeText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(20, 16), bounds.size.w-4, 100));
  
  // Improve the layout to be more like a watchface
  text_layer_set_background_color(s_timeText, TIME_TEXT_BACK_COLOR);
  text_layer_set_text_color(s_timeText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY));

  update_timeish(s_timeText,s_timeAccText);
  
  //s_timeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FFF_TUSJ_42));
  timeFont = fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK);
  
  text_layer_set_font(s_timeText, timeFont);
  text_layer_set_text_alignment(s_timeText, GTextAlignmentLeft);

  // Add it as a child layer to the Window's root layer
  layer_add_child(windowLayer, text_layer_get_layer(s_timeText));
  
  ///////////////////////////////////
  // Create the date text layer
  s_dateText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(128, 122), bounds.size.w-4, 16));
  
   // Improve the layout to be more like a watchface
  text_layer_set_background_color(s_dateText, TIME_TEXT_BACK_COLOR);
  text_layer_set_text_color(s_dateText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY));

  update_date(s_dateText);
  
  //s_dateFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FFF_TUSJ_24));
  GFont dateFont = fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD);
  
  text_layer_set_font(s_dateText, dateFont);
  text_layer_set_text_alignment(s_dateText, GTextAlignmentLeft);

  // Add it as a child layer to the Window's root layer
  layer_add_child(windowLayer, text_layer_get_layer(s_dateText));
  
  //////////////////////////////////
  // Create the weather text layer
  s_weatherText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(112, 108), bounds.size.w-4, 18));
  
   // Improve the layout to be more like a watchface
  text_layer_set_background_color(s_weatherText, TIME_TEXT_BACK_COLOR);

  update_weather((Tuple *)NULL,(Tuple *)NULL, (Tuple *)NULL);
  
  GFont weatherFont = fonts_get_system_font(FONT_KEY_GOTHIC_14);
  
  text_layer_set_font(s_weatherText, weatherFont);
  text_layer_set_text_alignment(s_weatherText, GTextAlignmentLeft);
  
  // Set weather text colour
  set_weather_text_colour();

  // Add it as a child layer to the Window's root layer
  layer_add_child(windowLayer, text_layer_get_layer(s_weatherText));
  
  //////////////////////////////////
  // Create the news text layer
  s_newsText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(142, 136), bounds.size.w-4, 30));
  
   // Improve the layout to be more like a watchface
  text_layer_set_background_color(s_newsText, TIME_TEXT_BACK_COLOR);
  text_layer_set_text_color(s_newsText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY));

  display_news_weather();
  
  text_layer_set_font(s_newsText, weatherFont);
  text_layer_set_text_alignment(s_newsText, GTextAlignmentLeft);

  // Add it as a child layer to the Window's root layer
  layer_add_child(windowLayer, text_layer_get_layer(s_newsText));
  
}
Esempio n. 16
0
static void main_window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_frame(window_layer);

	// 時刻領域(数値時計)
	s_time_layer = text_layer_create(GRect(0, 0, bounds.size.w, 34));
	text_layer_set_text_color      (s_time_layer, GColorWhite);
	text_layer_set_background_color(s_time_layer, GColorClear);
	text_layer_set_font            (s_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
	text_layer_set_text_alignment  (s_time_layer, GTextAlignmentCenter);

	// 時刻領域(元素記号時計)
	s_time_element_layer = text_layer_create(GRect(0, 22, bounds.size.w, 34));
	text_layer_set_text_color      (s_time_element_layer, GColorWhite);
	text_layer_set_background_color(s_time_element_layer, GColorClear);
	text_layer_set_font            (s_time_element_layer, fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD));
	text_layer_set_text_alignment  (s_time_element_layer, GTextAlignmentCenter);

	// 日付領域(元素記号)
	s_date_element_layer = text_layer_create(GRect(0, 55, bounds.size.w, 34));
	text_layer_set_text_color      (s_date_element_layer, GColorWhite);
	text_layer_set_background_color(s_date_element_layer, GColorClear);
	text_layer_set_font            (s_date_element_layer, fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD));
	text_layer_set_text_alignment  (s_date_element_layer, GTextAlignmentCenter);

	// 日付領域(数値)
	s_date_layer = text_layer_create(GRect(0, 80, bounds.size.w, 34));
	text_layer_set_text_color      (s_date_layer, GColorWhite);
	text_layer_set_background_color(s_date_layer, GColorClear);
	text_layer_set_font            (s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
	text_layer_set_text_alignment  (s_date_layer, GTextAlignmentCenter);

  // 初期値の表示	
	text_layer_set_text(s_time_layer, "01:23:45");
	text_layer_set_text(s_time_element_layer, "H:V:Rh");
	text_layer_set_text(s_date_layer, "2015/03/21");
	text_layer_set_text(s_date_element_layer, "CaP/Li/Sc");
	
	// 母艦との接続状態の表示
	s_connection_layer = text_layer_create(GRect(0, 110, bounds.size.w, 34));
	text_layer_set_text_color(s_connection_layer, GColorWhite);
	text_layer_set_background_color(s_connection_layer, GColorClear);
	text_layer_set_font(s_connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
	text_layer_set_text_alignment(s_connection_layer, GTextAlignmentCenter);
	handle_bluetooth(bluetooth_connection_service_peek());

	// 充電状態の表示
	s_battery_layer = text_layer_create(GRect(0, 130, bounds.size.w, 34));
	text_layer_set_text_color(s_battery_layer, GColorWhite);
	text_layer_set_background_color(s_battery_layer, GColorClear);
	text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
	text_layer_set_text_alignment(s_battery_layer, GTextAlignmentCenter);
	text_layer_set_text(s_battery_layer, "100% charged");

	// Ensures time is displayed immediately (will break if NULL tick event accessed).
	// (This is why it's a good idea to have a separate routine to do the update itself.)
	time_t now = time(NULL);
	struct tm *current_time = localtime(&now);
	handle_second_tick(current_time, SECOND_UNIT);

	tick_timer_service_subscribe(SECOND_UNIT, handle_second_tick);
	battery_state_service_subscribe(handle_battery);
	bluetooth_connection_service_subscribe(handle_bluetooth);

	layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_time_element_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_date_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_date_element_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_connection_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_battery_layer));
}
Esempio n. 17
0
  text_layer_set_background_color(&text_time_layer, GColorClear);
  layer_set_frame(&text_time_layer.layer, GRect(0, 112, 143, 168-112));
  text_layer_set_font(&text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49)));
  text_layer_set_text_alignment	(&text_time_layer,GTextAlignmentCenter);
  layer_add_child(&window.layer, &text_time_layer.layer);

  // Line
  layer_init(&line_layer, window.layer.frame);
  line_layer.update_proc = &line_layer_update_callback;
  layer_add_child(&window.layer, &line_layer);
 
  // Event title
  text_layer_init(&text_event_title_layer, GRect(0, 18, window.layer.bounds.size.w, 21));
  text_layer_set_text_color(&text_event_title_layer, GColorWhite);
  text_layer_set_background_color(&text_event_title_layer, GColorClear);
  text_layer_set_font(&text_event_title_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  layer_add_child(&window.layer, &text_event_title_layer.layer);

  // Date 
  text_layer_init(&text_event_start_date_layer, GRect(0, 36, window.layer.bounds.size.w, 21));
  text_layer_set_text_color(&text_event_start_date_layer, GColorWhite);
  text_layer_set_background_color(&text_event_start_date_layer, GColorClear);
  text_layer_set_font(&text_event_start_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  layer_add_child(&window.layer, &text_event_start_date_layer.layer);

  // Location
  text_layer_init(&text_event_location_layer, GRect(0, 54, window.layer.bounds.size.w, 21));
  text_layer_set_text_color(&text_event_location_layer, GColorWhite);
  text_layer_set_background_color(&text_event_location_layer, GColorClear);
  text_layer_set_font(&text_event_location_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  layer_add_child(&window.layer, &text_event_location_layer.layer);
Esempio n. 18
0
static void layer_update_callback(Layer *me, GContext* ctx) {

  // preparations
  GRect bounds = layer_get_bounds(me);
  uint16_t width = bounds.size.w;
  uint16_t height = bounds.size.h;
  uint16_t stride = (bounds.size.w + 31) / 32 * 32;
  uint16_t max = (height - 1) * stride + width;
  uint16_t shake = stride - width;
  uint16_t shake_stride = shake * stride;

  // handle shake
  if (do_shake) {
    do_shake = false;
    light_enable_interaction();
    for (uint16_t i = 0, j = rand(); i < NUM_FLAKES; i++, j+=31) {
      for (uint16_t k = 0; k < 2; k++, j+=31) {
        uint16_t next = flakes[i] + j % (max * 2) - max;
        if (next < max && next % stride < width && get_pixel(ctx, next) == GColorBlack) {
          flakes[i] = next;
          break;
        }
      }
    }
    last_time = 0;
  }

  // update time text
  time_t t = time(NULL);
  if (t / UPDATE_S > last_time) {
    last_time = t / UPDATE_S;
    char time_text[6];
    clock_copy_time_string(time_text, sizeof(time_text));

    graphics_context_set_fill_color(ctx, GColorBlack);
    graphics_fill_rect(ctx, bounds, 0, GCornerNone);

    GRect rect = (GRect) {{0, 60}, {width, 50}};
    GFont font = fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD);
    graphics_draw_text(ctx, time_text, font, rect, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);

    graphics_context_set_stroke_color(ctx, GColorWhite);
    for (uint16_t i = 0, j = rand(); i < NUM_FLAKES; i++) {
      if (get_pixel(ctx, flakes[i]) == GColorBlack) {
        graphics_draw_pixel(ctx, GPoint(flakes[i] % stride, flakes[i] / stride));
      } else {
        for (uint16_t k = 0; k < 8; k++, j++) {
          uint16_t next = flakes[i] + (j % 9 / 3 - 1) * shake_stride + (j % 3 - 1) * shake;
          if (next < max && next % stride < width && get_pixel(ctx, next) == GColorBlack) {
            flakes[i] = next;
            graphics_draw_pixel(ctx, GPoint(flakes[i] % stride, flakes[i] / stride));
            break;
          }
        }
      }
    }
  }

  // apply physics
  AccelData accel = {.x = 0, .y = 0, .z = 0};
  accel_service_peek(&accel);
  uint16_t absx = accel.x < 0 ? -accel.x : accel.x;
  uint16_t absy = accel.y < 0 ? -accel.y : accel.y;
  uint16_t span = (absx + absy + 10) * SPEED;

  for (uint16_t i = 0, j = rand(), k = rand(), l = rand(); i < span; i++, j++, k++, l++) {
    uint16_t index = j % NUM_FLAKES;
    uint16_t next = flakes[index];

    int16_t sideway = k % 3 == 0 ? l % 5 - 2 : 0;
    int16_t accx = accel.x + accel.y * sideway;
    int16_t accy = accel.y - accel.x * sideway;
    absx = accx < 0 ? -accx : accx;
    absy = accy < 0 ? -accy : accy;

    if (absx > absy || k % absy < absx) {
      if (accx > 0) {
        next++;
      } else {
        next--;
      }
    }
    if (absy > absx || l % absx < absy) {
      if (accy > 0) {
        next -= stride;
      } else {
        next += stride;
      }
    }
    if (next < max && next % stride < width && get_pixel(ctx, next) == GColorBlack) {
      graphics_context_set_stroke_color(ctx, GColorBlack);
      graphics_draw_pixel(ctx, GPoint(flakes[index] % stride, flakes[index] / stride));
      graphics_context_set_stroke_color(ctx, GColorWhite);
      graphics_draw_pixel(ctx, GPoint(next % stride, next / stride));
      flakes[index] = next;
    }
  }

  if (!timer) timer = app_timer_register(UPDATE_MS, timer_callback, NULL);
}

static void handle_accel(AccelData *accel_data, uint32_t num_samples) {
  // or else I will crash
}

static void accel_tap_handler(AccelAxisType axis, int32_t direction) {
  do_shake = true;
}

static void root_update_callback(Layer *me, GContext* ctx) {
  // hack to prevent screen cleaning
}

static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  layer_set_update_proc(window_layer, root_update_callback);
  GRect bounds = layer_get_bounds(window_layer);

  layer = layer_create(bounds);
  layer_set_update_proc(layer, layer_update_callback);
  layer_add_child(window_layer, layer);

  uint16_t width = bounds.size.w;
  uint16_t height = bounds.size.h;
  uint16_t stride = (bounds.size.w + 31) / 32 * 32;
  for (uint16_t i = 0; i < NUM_FLAKES; i++) {
    flakes[i] = rand() % height * stride + rand() % width;
  }
}
Esempio n. 19
0
static void draw_direction(GContext *ctx, GPoint *center, int32_t degrees, const char *text) {

  int32_t angle = TRIG_MAX_ANGLE * degrees / 360;
  GPoint point = {
    .y = ((int16_t)(-cos_lookup(angle) * (int32_t)BEZEL_RADIUS / TRIG_MAX_RATIO) + center->y),
    .x = ((int16_t)(sin_lookup(angle) * (int32_t)BEZEL_RADIUS / TRIG_MAX_RATIO) + center->x),
  };

  gpath_move_to(square_path, point);
  gpath_rotate_to(square_path, angle);
  gpath_draw_filled(ctx, square_path);

  graphics_draw_text(
    ctx, text,
    fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD),
    GRect(point.x - 12, point.y - 16, 24, 24),
    GTextOverflowModeWordWrap,
    GTextAlignmentCenter,
    NULL);
}

static void heading_update_proc(Layer *layer, GContext *ctx) {
  snprintf(heading_angle_buffer, sizeof(heading_angle_buffer), "%d°", heading_angle);
  text_layer_set_text(heading_angle_label, heading_angle_buffer);
  switch (status) {
    case STATUS_SUCCESS:
      text_layer_set_text(status_layer, "");
      if (heading_angle < 23) {
        text_layer_set_text(heading_text_label, "N");
      } else if (heading_angle < 68) {
        text_layer_set_text(heading_text_label, "NE");
      } else if (heading_angle < 113) {
        text_layer_set_text(heading_text_label, "E");
      } else if (heading_angle < 158) {
        text_layer_set_text(heading_text_label, "SE");
      } else if (heading_angle < 203) {
        text_layer_set_text(heading_text_label, "S");
      } else if (heading_angle < 248) {
        text_layer_set_text(heading_text_label, "SW");
      } else if (heading_angle < 293) {
        text_layer_set_text(heading_text_label, "W");
      } else if (heading_angle < 338) {
        text_layer_set_text(heading_text_label, "NW");
      } else {
        text_layer_set_text(heading_text_label, "N");
      }
      break;
    case STATUS_PERMISSION_DENIED:
      text_layer_set_text(status_layer, "Permission\nDenied");
      text_layer_set_text(heading_text_label, "");
      text_layer_set_text(heading_angle_label, "");
      break;
    case STATUS_POSITION_UNAVAILABLE:
      text_layer_set_text(status_layer, "Heading\nUnavailable");
      text_layer_set_text(heading_text_label, "");
      text_layer_set_text(heading_angle_label, "");
      break;
    case STATUS_TIMEOUT:
      text_layer_set_text(status_layer, "Timed\nOut");
      text_layer_set_text(heading_text_label, "");
      text_layer_set_text(heading_angle_label, "");
      break;
    case STATUS_NOT_MOVING:
      text_layer_set_text(status_layer, "Not\nMoving");
      text_layer_set_text(heading_text_label, "");
      text_layer_set_text(heading_angle_label, "");
      break;
    case STATUS_WAITING:
      text_layer_set_text(status_layer, "Waiting for\nHeading");
      text_layer_set_text(heading_text_label, "");
      text_layer_set_text(heading_angle_label, "");
      break;
  }
}
Esempio n. 20
0
/*
 * Here we draw what each header is
 */
static void menu_draw_header_callback(GContext* ctx, const Layer *cell_layer, uint16_t section_index, void *data) {
  graphics_context_set_text_color(ctx, MENU_HEAD_COLOR);
  graphics_draw_text(ctx, date_text, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD), GRect(0, -2, 144, 32), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
}
Esempio n. 21
0
void init_text_layer(TextLayer *text_layer){
  text_layer_set_background_color(text_layer, GColorBlack);
  text_layer_set_text_color(text_layer, GColorWhite);
  text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
  text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
}
Esempio n. 22
0
static void init(void) {
  memset(&time_digits_layers, 0, sizeof(time_digits_layers));
  memset(&time_digits_images, 0, sizeof(time_digits_images));
  memset(&date_digits_layers, 0, sizeof(date_digits_layers));
  memset(&date_digits_images, 0, sizeof(date_digits_images));
  memset(&battery_percent_layers, 0, sizeof(battery_percent_layers));
  memset(&battery_percent_image, 0, sizeof(battery_percent_image));

/* canceled settings
  const int inbound_size = 64;
  const int outbound_size = 64;
  app_message_open(inbound_size, outbound_size);  
*/
  
  window = window_create();
  if (window == NULL) {
      //APP_LOG(APP_LOG_LEVEL_DEBUG, "OOM: couldn't allocate window");
      return;
  }
  window_stack_push(window, true /* Animated */);
  window_layer = window_get_root_layer(window);
  
//  loadPersistentSettings();
	
  background_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND);
  background_layer = bitmap_layer_create(layer_get_frame(window_layer));
  bitmap_layer_set_bitmap(background_layer, background_image);
  layer_add_child(window_layer, bitmap_layer_get_layer(background_layer));
  
  separator_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SEPARATOR);
  GRect frame = (GRect) {
    .origin = { .x = 69, .y = 91 },
    .size = separator_image->bounds.size
  };
  separator_layer = bitmap_layer_create(frame);
  bitmap_layer_set_bitmap(separator_layer, separator_image);
  layer_add_child(window_layer, bitmap_layer_get_layer(separator_layer));   

  /*
  meter_bar_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_METER_BAR);
  GRect frame2 = (GRect) {
    .origin = { .x = 17, .y = 43 },
    .size = meter_bar_image->bounds.size
  };
  meter_bar_layer = bitmap_layer_create(frame2);
  bitmap_layer_set_bitmap(meter_bar_layer, meter_bar_image);
  layer_add_child(window_layer, bitmap_layer_get_layer(meter_bar_layer));  
*/
  
  bluetooth_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH);
  GRect frame3 = (GRect) {
    .origin = { .x = 37, .y = 43 },
    .size = bluetooth_image->bounds.size
  };
  bluetooth_layer = bitmap_layer_create(frame3);
  bitmap_layer_set_bitmap(bluetooth_layer, bluetooth_image);
  layer_add_child(window_layer, bitmap_layer_get_layer(bluetooth_layer));
  
  battery_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY);
  GRect frame4 = (GRect) {
    .origin = { .x = 111, .y = 43 },
    .size = battery_image->bounds.size
  };
  battery_layer = bitmap_layer_create(frame4);
  battery_image_layer = bitmap_layer_create(frame4);
  bitmap_layer_set_bitmap(battery_image_layer, battery_image);
  layer_set_update_proc(bitmap_layer_get_layer(battery_layer), battery_layer_update_callback);
  
  layer_add_child(window_layer, bitmap_layer_get_layer(battery_image_layer));
  layer_add_child(window_layer, bitmap_layer_get_layer(battery_layer));
  
	 //week status layer (ShaBP)
  week_layer = text_layer_create(GRect(55, 38, 27, 14));
  text_layer_set_text_color(week_layer, GColorBlack);
	text_layer_set_text_alignment(week_layer, GTextAlignmentLeft);
  text_layer_set_background_color(week_layer, GColorClear);
  text_layer_set_font(week_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	layer_add_child(window_layer, text_layer_get_layer(week_layer));
  
  // steps layer (ShaBP)
  steps_layer = text_layer_create(GRect(20, 0, 48, 18));
  text_layer_set_text_color(steps_layer, GColorWhite);
	text_layer_set_text_alignment(steps_layer, GTextAlignmentLeft);
  text_layer_set_background_color(steps_layer, GColorClear);
  text_layer_set_font(steps_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
	layer_add_child(window_layer, text_layer_get_layer(steps_layer));
  layer_set_hidden(text_layer_get_layer(steps_layer), true);
  
  steps_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_STEPS);
  steps_image_layer = bitmap_layer_create(GRect(9, 4, 9, 14));
  bitmap_layer_set_bitmap(steps_image_layer, steps_image);
  layer_add_child(window_layer, bitmap_layer_get_layer(steps_image_layer));
  layer_set_hidden(bitmap_layer_get_layer(steps_image_layer), true);
  
  // Goal percentage layer (ShaBP)
/*
  goal_percent_layer = layer_create(GRect(12, 50, 120, 1));
  layer_set_update_proc(goal_percent_layer, goal_percent_layer_update_callback);
  layer_add_child(window_get_root_layer(window), goal_percent_layer);
*/
  // steps goal layer (ShaBP)
  goal_layer = text_layer_create(GRect(66, 0, 34, 18));
  text_layer_set_text_color(goal_layer, GColorWhite);
	text_layer_set_text_alignment(goal_layer, GTextAlignmentRight);
  text_layer_set_background_color(goal_layer, GColorClear);
  text_layer_set_font(goal_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
	layer_add_child(window_layer, text_layer_get_layer(goal_layer));
  layer_set_hidden(text_layer_get_layer(goal_layer), true);
  
  goal_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_GOAL);
  GRect frame_goal = (GRect) {
    .origin = { .x = 103, .y = 8 },
    .size = goal_image->bounds.size
  };
  goal_image_layer = bitmap_layer_create(frame_goal);
  goal_fill_image_layer = bitmap_layer_create(frame_goal);
  bitmap_layer_set_bitmap(goal_image_layer, goal_image);
  layer_set_update_proc(bitmap_layer_get_layer(goal_fill_image_layer), goal_image_layer_update_callback);
  layer_set_hidden(bitmap_layer_get_layer(goal_image_layer), true);
  
  layer_add_child(window_layer, bitmap_layer_get_layer(goal_image_layer));
  layer_add_child(window_layer, bitmap_layer_get_layer(goal_fill_image_layer));

  //time format
  GRect frame5 = (GRect) {
    .origin = { .x = 12, .y = 68 },
    .size = {.w = 19, .h = 8}
  };
Esempio n. 23
0
static void main_window_load(Window *window) {
    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_bounds(window_layer);
    s_sizew = PBL_IF_ROUND_ELSE(130, bounds.size.w);
    s_time_layer = text_layer_create(
            GRect(0, 0, bounds.size.w, PBL_IF_ROUND_ELSE(75, 80)));
    text_layer_set_background_color(s_time_layer, GColorClear);
    //text_layer_set_text_color(s_time_layer, GColorWhite);
    text_layer_set_text(s_time_layer, "00:00");
    text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
    // Create Fonts
    s_time_font = fonts_load_custom_font(resource_get_handle(PBL_IF_ROUND_ELSE(RESOURCE_ID_FONT_DIN_40, RESOURCE_ID_FONT_DIN_40)));
    s_people_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIN_BOLD_25));
    s_dinsmall_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIN_20));
    s_weather_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_METEOCONS_35));
    s_batt_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIN_15));

    text_layer_set_font(s_time_layer, s_time_font);
    // Add it as a child layer to the Window's root layer
    layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
    // Create date TextLayer
    s_date_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(68, 55), bounds.size.w, 30));
    //text_layer_set_text_color(s_date_layer, GColorWhite);
    text_layer_set_background_color(s_date_layer, GColorClear);
    text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
    text_layer_set_font(s_date_layer, s_people_font);
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));
    //create People Layer
    s_people_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(25, 0), 138, bounds.size.w, block_height));
    text_layer_set_background_color(s_people_layer, GColorClear);
    text_layer_set_text_alignment(s_people_layer, GTextAlignmentCenter);
    text_layer_set_text_color(s_people_layer, text);
    text_layer_set_text(s_people_layer, "");
    text_layer_set_font(s_people_layer, s_people_font);
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_people_layer));
    if (ppl_total != 0) {
        create_ppl();
    }
    //Create Weather Layer. Makes stuff easier.
    s_weather_layer = text_layer_create(GRect(0,PBL_IF_ROUND_ELSE(80, 70), bounds.size.w, 65));
    text_layer_set_background_color(s_weather_layer, GColorClear);
    text_layer_set_text_color(s_weather_layer, text);
    text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter);
    text_layer_set_text(s_weather_layer, "");
    text_layer_set_font(s_weather_layer, s_people_font);
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer));
    //create temperature Layer
    s_temp_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(25, 10), 18, 50, 30));
    text_layer_set_background_color(s_temp_layer, GColorClear);
    //text_layer_set_text_color(s_temp_layer, GColorWhite);
    text_layer_set_text_alignment(s_temp_layer, GTextAlignmentLeft);
    text_layer_set_text(s_temp_layer, temp_buffer);
    text_layer_set_font(s_temp_layer, s_people_font);
    layer_add_child(text_layer_get_layer(s_weather_layer), text_layer_get_layer(s_temp_layer));
    //create conditions Layer
    s_cond_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(65, 47), 16, 50, 50));
    text_layer_set_background_color(s_cond_layer, GColorClear);
    //text_layer_set_text_color(s_cond_layer, GColorWhite);
    text_layer_set_text_alignment(s_cond_layer, GTextAlignmentCenter);
    text_layer_set_text(s_cond_layer, s_cond);
    text_layer_set_font(s_cond_layer, s_weather_font);
    layer_add_child(text_layer_get_layer(s_weather_layer), text_layer_get_layer(s_cond_layer));
    //create high/low temp Layer
    s_hilo_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(115, 93), 12, 50, 60));
    text_layer_set_background_color(s_hilo_layer, GColorClear);
    //text_layer_set_text_color(s_hilo_layer, GColorWhite);
    text_layer_set_text_alignment(s_hilo_layer, GTextAlignmentCenter);
    text_layer_set_text(s_hilo_layer, hilo_buffer);
    text_layer_set_font(s_hilo_layer, s_dinsmall_font);
    layer_add_child(text_layer_get_layer(s_weather_layer), text_layer_get_layer(s_hilo_layer));
    //create battery Layer
    s_batt_layer = text_layer_create(GRect(53, 5, 40, 20));
    text_layer_set_background_color(s_batt_layer, GColorClear);
    //text_layer_set_text_color(s_batt_layer, GColorWhite);
    text_layer_set_text_alignment(s_batt_layer, GTextAlignmentCenter);
    text_layer_set_text(s_batt_layer, "");
    text_layer_set_font(s_batt_layer, s_batt_font);
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_batt_layer));
    //create shit Layer
    s_shit_layer = text_layer_create(
            GRect(0, 90, bounds.size.w, 30));
    text_layer_set_background_color(s_shit_layer, GColorClear);
    //text_layer_set_text_color(s_shit_layer, GColorWhite);
    text_layer_set_text_alignment(s_shit_layer, GTextAlignmentCenter);
    text_layer_set_text(s_shit_layer, s_shit);
    text_layer_set_font(s_shit_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_shit_layer));

    set_colors();
}
void window_load(Window *window) {
    persist_read_string(1, saved_passcode, 50);
    
    Layer *window_layer = window_get_root_layer(window);
    
    number_0 = number_layer_init(GRect(124, 0, 20, 15), "0");
    layer_add_child(window_layer, text_layer_get_layer(number_0));
    
    number_1 = number_layer_init(GRect(124, 15, 20, 15), "1");
    layer_add_child(window_layer, text_layer_get_layer(number_1));
    
    number_2 = number_layer_init(GRect(124, 30, 20, 15), "2");
    layer_add_child(window_layer, text_layer_get_layer(number_2));
    
    number_3 = number_layer_init(GRect(124, 45, 20, 15), "3");
    layer_add_child(window_layer, text_layer_get_layer(number_3));
    
    number_4 = number_layer_init(GRect(124, 60, 20, 15), "4");
    layer_add_child(window_layer, text_layer_get_layer(number_4));
    
    number_5 = number_layer_init(GRect(124, 75, 20, 15), "5");
    layer_add_child(window_layer, text_layer_get_layer(number_5));
    
    number_6 = number_layer_init(GRect(124, 90, 20, 15), "6");
    layer_add_child(window_layer, text_layer_get_layer(number_6));
    
    number_7 = number_layer_init(GRect(124, 105, 20, 15), "7");
    layer_add_child(window_layer, text_layer_get_layer(number_7));
    
    number_8 = number_layer_init(GRect(124, 120, 20, 15), "8");
    layer_add_child(window_layer, text_layer_get_layer(number_8));
    
    number_9 = number_layer_init(GRect(124, 135, 20, 17), "9");
    layer_add_child(window_layer, text_layer_get_layer(number_9));
    
    status_text_layer = text_layer_create(GRect(0, 90, 124, 40));
    text_layer_set_text_color(status_text_layer, GColorBlack);
    text_layer_set_font(status_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
    text_layer_set_text_alignment(status_text_layer, GTextAlignmentCenter);
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(status_text_layer));
    
    selected_number = 0;
    cursor_position = 0;
    
    circle_layer = layer_create(GRect(0, 20, 144, 100));
    layer_set_update_proc(circle_layer, circle_proc);
    layer_add_child(window_layer, circle_layer);
    
    update_bar();
    
    window_set_click_config_provider(window, (ClickConfigProvider) config_provider);
    
    line = gbitmap_create_with_resource(RESOURCE_ID_LINE);
    
    line_layer = bitmap_layer_create(GRect(122, 0, 2, 168));
    bitmap_layer_set_alignment(line_layer, GAlignCenter);
    layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(line_layer));
    
    bitmap_layer_set_bitmap(line_layer, line);
    
    theme = inverter_layer_create(GRect(0, 0, 144, 168));
    layer_add_child(window_layer, inverter_layer_get_layer(theme));
    layer_set_hidden(inverter_layer_get_layer(theme), theme_public);
}
Esempio n. 25
0
static void window_load(Window *window) {
  
  set_color_data();
  
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  APP_LOG(APP_LOG_LEVEL_DEBUG, "---- window_load ----");

  // Config
 //if (persist_read_bool(KEY_CONNECTION_LOST_VIBE)) {
    s_connection_lost_vibe = persist_read_bool(KEY_CONNECTION_LOST_VIBE);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "s_connection_lost_vibe %d", s_connection_lost_vibe);
 /// }
 //if (persist_read_bool(KEY_SHOW_SECONDS_HAND)) {
    s_show_seconds_hand = persist_read_bool(KEY_SHOW_SECONDS_HAND);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "s_show_seconds_hand %d", s_show_seconds_hand);
 // }
 //if (persist_read_bool(KEY_COLOR_REVERSE)) {
    s_color_reverse = persist_read_bool(KEY_COLOR_REVERSE);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "s_color_reverse %d", s_color_reverse);
    set_color_data();
  //}
  
  

  
  s_simple_bg_layer = layer_create(bounds);
  layer_set_update_proc(s_simple_bg_layer, bg_update_proc);
  layer_add_child(window_layer, s_simple_bg_layer);

  s_date_layer = layer_create(bounds);
  layer_set_update_proc(s_date_layer, date_update_proc);
  layer_add_child(window_layer, s_date_layer);

  //s_day_label = text_layer_create(PBL_IF_ROUND_ELSE(
  //  GRect(63, 114, 27, 20),
  //  GRect(46, 114, 27, 20)));
  s_day_label = text_layer_create(
    GRect((int)(bounds.size.w / 2) + 20, bounds.size.h -98, 27,20));
  text_layer_set_text(s_day_label, s_day_buffer);
  text_layer_set_background_color(s_day_label, s_backColor);
  text_layer_set_text_color(s_day_label, s_textColor);
  text_layer_set_font(s_day_label, fonts_get_system_font(FONT_KEY_GOTHIC_18));

  layer_add_child(s_date_layer, text_layer_get_layer(s_day_label));

  //s_num_label = text_layer_create(PBL_IF_ROUND_ELSE(
  //  GRect(90, 114, 18, 20),
  //  GRect(73, 114, 18, 20)));
  s_num_label = text_layer_create(GRect((int)(bounds.size.w / 2) + 47, bounds.size.h -98, 18,20));
  text_layer_set_text(s_num_label, s_num_buffer);
  text_layer_set_background_color(s_num_label, s_backColor);
  text_layer_set_text_color(s_num_label, s_textColor);
  text_layer_set_font(s_num_label, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  
  // BT OK/NG
  s_connection_layer = text_layer_create(GRect((int)(bounds.size.w / 2) - 27,114, 20, 20));
  text_layer_set_text_color(s_connection_layer, s_textColor);
  text_layer_set_background_color(s_connection_layer, GColorClear);
  text_layer_set_font(s_connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(s_connection_layer, GTextAlignmentLeft);
  handle_bluetooth(connection_service_peek_pebble_app_connection());

  // Battery
  s_battery_layer = text_layer_create(GRect((int)(bounds.size.w / 2) , 114,40,20));
  text_layer_set_text_color(s_battery_layer, s_textColor);
  text_layer_set_background_color(s_battery_layer, GColorClear);
  text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(s_battery_layer, GTextAlignmentLeft);
  text_layer_set_text(s_battery_layer, "100%");

  battery_state_service_subscribe(handle_battery);

  connection_service_subscribe((ConnectionHandlers) {
    .pebble_app_connection_handler = handle_bluetooth
  });
Esempio n. 26
0
void update_cb(Layer* layer, GContext* ctx) {
    
  if(title) {
    if( score > best_score) {
      best_score = score;
      persist_write_int(42, best_score);
    }
    score = 0;

    graphics_context_set_text_color(ctx, GColorBlack);
    graphics_draw_text(ctx, "Tiny Bird", fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK), (GRect) {.origin = {0,0}, .size = {144, 40}}, GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
    graphics_draw_bitmap_in_rect(ctx, pos_20_deg, (GRect) {.origin = {10, 50}, .size = {30, 19}});


    graphics_draw_text(ctx, "PRESS UP", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), (GRect) {.origin = {0,95}, .size = {144, 40}}, GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
  
    graphics_draw_bitmap_in_rect(ctx, ground, (GRect) {.origin = {0, 158}, .size = {170, 10}});
    if(best_score > 0) {
      snprintf(best_score_str, 20, "Best: %i", best_score);
    graphics_draw_text(ctx, best_score_str, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), (GRect) {.origin = {0,125}, .size = {144, 40}}, GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
    }
  } else {

    if(int_v < -6){
      graphics_draw_bitmap_in_rect(ctx, pos_20_deg, (GRect) {.origin = {10, y}, .size = {30, 19}});
    }
    else if(int_v < 0) {
      graphics_draw_bitmap_in_rect(ctx, pos_10_deg, (GRect) {.origin = {10, y}, .size = {30, 19}});
     }
    else if(int_v < 6) {
Esempio n. 27
0
void init() {
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);

  text_date_layer = text_layer_create(GRect(8, 94, 144-8, 168-94));
  text_layer_set_text_color(text_date_layer, GColorWhite);
  text_layer_set_background_color(text_date_layer, GColorClear);
  text_layer_set_font(text_date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21)));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_date_layer));

  text_time_layer = text_layer_create(GRect(7, 112, 144-7, 168-112));
  text_layer_set_text_color(text_time_layer, GColorWhite);
  text_layer_set_background_color(text_time_layer, GColorClear);
  text_layer_set_font(text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49)));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_time_layer));

  line_layer = layer_create(layer_get_bounds(window_get_root_layer(window)));
  layer_set_update_proc(line_layer, line_layer_update_callback);
  layer_add_child(window_get_root_layer(window), line_layer);

  tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);

  // TODO: Update display here to avoid blank display on launch?

  text_event_title_layer = text_layer_create(GRect(5, 18, layer_get_bounds(window_get_root_layer(window)).size.w - 10, 21));
  text_layer_set_text_color(text_event_title_layer, GColorWhite);
  text_layer_set_background_color(text_event_title_layer, GColorClear);
  text_layer_set_font(text_event_title_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_event_title_layer));

  text_event_start_date_layer = text_layer_create(GRect(5, 36, layer_get_bounds(window_get_root_layer(window)).size.w - 10, 21));
  text_layer_set_text_color(text_event_start_date_layer, GColorWhite);
  text_layer_set_background_color(text_event_start_date_layer, GColorClear);
  text_layer_set_font(text_event_start_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_event_start_date_layer));

  text_event_location_layer = text_layer_create(GRect(5, 54, layer_get_bounds(window_get_root_layer(window)).size.w - 10, 21));
  text_layer_set_text_color(text_event_location_layer, GColorWhite);
  text_layer_set_background_color(text_event_location_layer, GColorClear);
  text_layer_set_font(text_event_location_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_event_location_layer));

  icon_battery = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_ICON);

  GRect frame;
  frame.origin.x = layer_get_bounds(window_get_root_layer(window)).size.w - 66;
  frame.origin.y = 6;
  frame.size.w = 59;
  frame.size.h = 12;

  battery_layer = layer_create(frame);
  layer_set_update_proc(battery_layer, battery_layer_update_callback);
  layer_add_child(window_get_root_layer(window), battery_layer);

  battery_status.state = 0;
  battery_status.level = -1;

  app_message_open(124, 256);
  app_message_register_inbox_received(received_message);

  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  if (!iter) return;
  dict_write_int8(iter, REQUEST_CALENDAR_KEY, 0);
  uint8_t clock_style = clock_is_24h_style() ? CLOCK_STYLE_24H : CLOCK_STYLE_12H;
  dict_write_uint8(iter, CLOCK_STYLE_KEY, clock_style);
  app_message_outbox_send();

  app_timer_register(1000, &handle_timer, NULL);
}
Esempio n. 28
0
static void main_window_load(Window *window) {

  Layer *window_layer = window_get_root_layer(window);
  GRect window_bounds = layer_get_bounds(window_layer);


  title_layer = text_layer_create(
    GRect(0, 0,window_bounds.size.w, window_bounds.size.h));
  text_layer_set_text_alignment(title_layer, GTextAlignmentCenter);
  text_layer_set_text(title_layer, "FloodWatch");
  text_layer_set_text_color(title_layer, GColorBlack);
  text_layer_set_background_color(title_layer, GColorClear);
  text_layer_set_font(title_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
  layer_add_child(window_layer, text_layer_get_layer(title_layer));

  region_layer = text_layer_create(
    GRect(0, 20,window_bounds.size.w, window_bounds.size.h));
  text_layer_set_text_alignment(region_layer, GTextAlignmentCenter);
  text_layer_set_text(region_layer, "Jakarta - Timur");
  text_layer_set_text_color(region_layer, GColorWhite);
  text_layer_set_background_color(region_layer, GColorClear);
  text_layer_set_font(region_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
  layer_add_child(window_layer, text_layer_get_layer(region_layer));


  s_scroll_layer = scroll_layer_create(window_bounds);
 scroll_layer_set_click_config_onto_window(s_scroll_layer, window);
 scroll_layer_set_shadow_hidden(s_scroll_layer, true);
 layer_add_child(window_layer, scroll_layer_get_layer(s_scroll_layer));

 // Get the ContentIndicator from the ScrollLayer
 s_indicator = scroll_layer_get_content_indicator(s_scroll_layer);

 // Create two Layers to draw the arrows
 s_indicator_up_layer = layer_create(GRect(window_bounds.origin.x, window_bounds.origin.y,
                                     window_bounds.size.w, STATUS_BAR_LAYER_HEIGHT));
 s_indicator_down_layer = layer_create(GRect(0, window_bounds.size.h - STATUS_BAR_LAYER_HEIGHT,
                                       window_bounds.size.w, STATUS_BAR_LAYER_HEIGHT));
 layer_add_child(window_layer, s_indicator_up_layer);
 layer_add_child(window_layer, s_indicator_down_layer);

 // Configure the properties of each indicator
 const ContentIndicatorConfig up_config = (ContentIndicatorConfig) {
   .layer = s_indicator_up_layer,
   .times_out = false,
   .alignment = GAlignCenter,
   .colors = {
     .foreground = GColorBlack,
     .background = GColorLightGray
   }
 };
 content_indicator_configure_direction(s_indicator, ContentIndicatorDirectionUp,
                                       &up_config);

 const ContentIndicatorConfig down_config = (ContentIndicatorConfig) {
   .layer = s_indicator_down_layer,
   .times_out = false,
   .alignment = GAlignCenter,
   .colors = {
     .foreground = GColorBlack,
     .background = GColorLightGray
   }
 };
 content_indicator_configure_direction(s_indicator, ContentIndicatorDirectionDown,
                                       &down_config);

 reports_layer = text_layer_create(GRect(0, 50, window_bounds.size.w, 2000));
 text_layer_set_text(reports_layer, reports);
 text_layer_set_text_alignment(reports_layer, GTextAlignmentCenter);
 text_layer_set_font(reports_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
 text_layer_set_text_color(region_layer, GColorBlack);
 text_layer_set_background_color(region_layer, GColorClear);
 scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(reports_layer));

 GSize text_size = text_layer_get_content_size(reports_layer);
 layer_set_frame(text_layer_get_layer(reports_layer),
                 GRect(0, 50, window_bounds.size.w, text_size.h));
 scroll_layer_set_content_size(s_scroll_layer, text_size);
}
Esempio n. 29
0
static void prv_draw_menu_row(GContext *ctx, const Layer *cell_layer, MenuIndex *cell_index, void *menu) {
  char time_buf[17];
  char minutes_buf[6];
  char zone_buf[7];
  TrainStop stop;
  
  TrainTime *time = &s_times[cell_index->row];
  
  stop_get(time->stop, &stop);
  snprintf(zone_buf, sizeof(zone_buf), "Zone %d", stop.zone);
  train_time_format_minutes(time->time, sizeof(minutes_buf), minutes_buf);
  int16_t time_diff = time->time - s_times[s_index].time;
  if(time_diff > 0) {
    snprintf(time_buf, sizeof(time_buf), "%s (%d min)", minutes_buf, time_diff);
  } else {
    strncpy(time_buf, minutes_buf, sizeof(time_buf));
  }
  
  menu_hack_set_colours(ctx, menu, cell_index);
  
  graphics_fill_rect(ctx, layer_get_bounds(cell_layer), 0, GCornerNone);
  
  graphics_draw_text(ctx, stop.name, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(13, -7, 131, 29), GTextOverflowModeFill, GTextAlignmentLeft, NULL);
  graphics_draw_text(ctx, zone_buf, fonts_get_system_font(FONT_KEY_GOTHIC_18), GRect(14, 16, 129, 20), GTextOverflowModeFill, GTextAlignmentLeft, NULL);
  graphics_draw_text(ctx, time_buf, fonts_get_system_font(FONT_KEY_GOTHIC_18), GRect(14, 16, 129, 20), GTextOverflowModeFill, GTextAlignmentRight, NULL);
  
  // Draw in map thing in the left margin.
  const bool is_start = (cell_index->row == 0);
  const bool is_end = (cell_index->row == s_time_count - 1);
  graphics_context_set_fill_color(ctx, COLOUR_ROUTE_FILLED);
  graphics_context_set_stroke_color(ctx, COLOUR_ROUTE_OUTLINE);
  if(time->sequence < s_sequence) { // Empty section because the train has already gone past here.
    int16_t top = -1;
    int16_t bottom = 41;
    // Avoid drawing past either end.
    if(is_start) {
      top = 20;
    } else if(is_end) {
      bottom = 20;
    }
    graphics_context_set_fill_color(ctx, COLOUR_ROUTE_EMPTY);
    graphics_fill_rect(ctx, GRect(3, top, 7, bottom - top), 0, GCornerNone);
    graphics_draw_rect(ctx, GRect(3, top, 7, bottom - top));
    graphics_fill_circle(ctx, GPoint(6, 20), 6); // Fill white and draw black outline to avoid intersecting tracks.
    graphics_draw_circle(ctx, GPoint(6, 20), 6);
  } else if(time->sequence > s_sequence) { // Filled section; we haven't gone here yet.
    GRect rect = GRect(3, -1, 7, 41);
    // Avoid drawing past either end.
    if(is_end) {
      rect.size.h = 21;
    } else if(is_start) {
      rect.size.h = 21;
      rect.origin.y = 20;
    }
    graphics_fill_rect(ctx, rect, 0, GCornerNone);
    graphics_fill_circle(ctx, GPoint(6, 20), 6);
  } else { // Half-filled; we're here, and heading in one direction.
           // Which direction we fill depends on which direction we're going in.
    if(!is_start) {
      if(s_trip.direction == TrainDirectionSouthbound) {
        graphics_context_set_fill_color(ctx, COLOUR_ROUTE_EMPTY);
      } else {
        graphics_context_set_fill_color(ctx, COLOUR_ROUTE_FILLED);
      }
      graphics_fill_rect(ctx, GRect(3, -1, 7, 21), 0, GCornerNone);
      graphics_draw_rect(ctx, GRect(3, -1, 7, 21));
    }
    if(!is_end) {
      if(s_trip.direction == TrainDirectionSouthbound) {
        graphics_context_set_fill_color(ctx, COLOUR_ROUTE_FILLED);
      } else {
        graphics_context_set_fill_color(ctx, COLOUR_ROUTE_EMPTY);
      }
      graphics_fill_rect(ctx, GRect(3, 20, 7, 21), 0, GCornerNone);
      graphics_draw_rect(ctx, GRect(3, -1, 7, 21));
    }
    graphics_context_set_fill_color(ctx, COLOUR_ROUTE_FILLED);
    graphics_fill_circle(ctx, GPoint(6, 20), 6);
    graphics_draw_circle(ctx, GPoint(6, 20), 6);
  }
}
Esempio n. 30
0
static void window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_bounds(window_layer);
		int offset = !b_show_numbers * 10;

	s_simple_bg_layer = layer_create(bounds);
	layer_set_update_proc(s_simple_bg_layer, bg_update_proc);
	layer_add_child(window_layer, s_simple_bg_layer);

	window_set_background_color(window, gcolor_background);

#ifdef PBL_RECT
  date_layer_right = text_layer_create(GRect(
    (bounds.size.w - DATE_LAYER_HORIZONTAL_OFFSET),
    (bounds.size.h/2 - DATE_LAYER_VERTICAL_OFFSET), 
    DATE_LAYER_HORIZONTAL_OFFSET,
    60));

  date_layer_left = text_layer_create(GRect(
    0,
    (bounds.size.h/2 - DATE_LAYER_VERTICAL_OFFSET),
    DATE_LAYER_HORIZONTAL_OFFSET + offset,
    60));
  
  date_layer_bottom = text_layer_create(GRect(
    0,
    (bounds.size.h - DATE_LAYER_BOTTOM_OFFSET),
    bounds.size.w,
    DATE_LAYER_BOTTOM_OFFSET));
#else
  date_layer_right = text_layer_create(GRect(
    (bounds.size.w - DATE_LAYER_HORIZONTAL_OFFSET),
    (bounds.size.h/2 - DATE_LAYER_VERTICAL_OFFSET), 
    DATE_LAYER_HORIZONTAL_OFFSET,
    60));

  date_layer_left = text_layer_create(GRect(
    0,
    (bounds.size.h/2 - DATE_LAYER_VERTICAL_OFFSET),
    DATE_LAYER_HORIZONTAL_OFFSET + (offset * 4),
    60));
  
  date_layer_bottom = text_layer_create(GRect(
    0,
    (bounds.size.h - DATE_LAYER_BOTTOM_OFFSET),
    bounds.size.w,
    DATE_LAYER_BOTTOM_OFFSET + (offset * 2)));
 #endif
 
  text_layer_set_background_color(date_layer_right, GColorClear);
  text_layer_set_text_color(date_layer_right, gcolor_numbers);
  text_layer_set_text_alignment(date_layer_right, GTextAlignmentCenter);
  text_layer_set_font(date_layer_right, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  
  text_layer_set_background_color(date_layer_left, GColorClear);
  text_layer_set_text_color(date_layer_left, gcolor_numbers);
  text_layer_set_text_alignment(date_layer_left, GTextAlignmentCenter);
  text_layer_set_font(date_layer_left, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  
  text_layer_set_background_color(date_layer_bottom, GColorClear);
  text_layer_set_text_color(date_layer_bottom, gcolor_numbers);
  text_layer_set_text_alignment(date_layer_bottom, GTextAlignmentCenter);
  text_layer_set_font(date_layer_bottom, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
 update_date();
 layer_add_child(window_layer, text_layer_get_layer(date_layer_right));
  layer_add_child(window_layer, text_layer_get_layer(date_layer_left));
  layer_add_child(window_layer, text_layer_get_layer(date_layer_bottom));

	s_hands_layer = layer_create(bounds);
	layer_set_update_proc(s_hands_layer, hands_update_proc);
	layer_add_child(window_layer, s_hands_layer);

	load_persisted_values();
}