Example #1
0
static void window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	ui.bounds = layer_get_bounds(window_layer);
	
	ui.top_text = text_layer_create((GRect) { .origin = { 0, 0 }, .size = { ui.bounds.size.w, 32 } });
Example #2
0
static void anim_update2_proc(Layer *layer, GContext *ctx) {
  APP_LOG(APP_LOG_LEVEL_INFO, "Paint BOX2");
  int x = layer_get_bounds(layer).size.w / 2 ;
  graphics_context_set_fill_color(ctx, GColorLightGray);
  graphics_fill_circle(ctx, GPoint(x,x) ,x -1);
}
Example #3
0
static void bt_update_proc(Layer *layer, GContext *ctx) {
  graphics_context_set_fill_color(ctx, data_get_color(AppKeyBackgroundColor));
  graphics_fill_rect(ctx, layer_get_bounds(layer), 0 , GCornerNone);
}
Example #4
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);
  }*/
}
Example #5
0
static void hands_update_proc(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);
  GPoint center = grect_center_point(&bounds);
  graphics_draw_circle(ctx, center, bounds.size.w / 2);
  
  int16_t second_hand_length = bounds.size.w / 3;

  time_t now = time(NULL);
  struct tm *t = localtime(&now);
  int32_t second_angle = TRIG_MAX_ANGLE * t->tm_sec / 60;
  GPoint second_hand = {
    .x = (int16_t)(sin_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.x,
    .y = (int16_t)(-cos_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.y,
  };

  gpath_rotate_to(s_second_arrow, second_angle);
  graphics_context_set_stroke_color(ctx, GColorBlack);
  graphics_context_set_stroke_width(ctx, 1);
  graphics_draw_circle(ctx, second_hand, 5);
  // second hand
  //graphics_context_set_stroke_color(ctx, GColorBlack);
  //graphics_draw_line(ctx, second_hand, center);

  // minute/hour hand
  //graphics_context_set_fill_color(ctx, GColorBlack);
  //graphics_context_set_stroke_color(ctx, GColorBlack);
  int16_t minute_hand_length = bounds.size.w / 3;
  int32_t minute_angle = TRIG_MAX_ANGLE * t->tm_min / 60;
  GPoint minute_hand = {
    .x = (int16_t)(sin_lookup(minute_angle) * (int32_t)minute_hand_length / TRIG_MAX_RATIO) + center.x,
    .y = (int16_t)(-cos_lookup(minute_angle) * (int32_t)minute_hand_length / TRIG_MAX_RATIO) + center.y,
  };
  
  gpath_rotate_to(s_minute_arrow, minute_angle);
  //gpath_draw_filled(ctx, s_minute_arrow);
  //gpath_draw_outline(ctx, s_minute_arrow);
  graphics_context_set_stroke_color(ctx, GColorBlack);
  //graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_context_set_stroke_width(ctx, 1);
  graphics_draw_circle(ctx, minute_hand, 15);
  //graphics_context_set_fill_color(ctx, GColorWhite);
  //graphics_fill_circle(ctx, minute_hand, 8);

  int16_t hour_hand_length = bounds.size.w / 3;
  int32_t hour_angle = (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6);
  GPoint hour_hand = {
    .x = (int16_t)(sin_lookup(hour_angle) * (int32_t)hour_hand_length / TRIG_MAX_RATIO) + center.x,
    .y = (int16_t)(-cos_lookup(hour_angle) * (int32_t)hour_hand_length / TRIG_MAX_RATIO) + center.y,
  };
  gpath_rotate_to(s_hour_arrow, hour_angle);
  //gpath_draw_filled(ctx, s_hour_arrow);
  //gpath_draw_outline(ctx, s_hour_arrow);
  graphics_context_set_stroke_color(ctx, GColorBlack);
  graphics_context_set_stroke_width(ctx, 1);
  graphics_draw_circle(ctx, hour_hand, 8);
  
  // dot in the middle
  graphics_context_set_fill_color(ctx, GColorBlack);
  //graphics_fill_rect(ctx, GRect(bounds.size.w / 2 - 1, bounds.size.h / 2 - 1, 3, 3), 0, GCornerNone);
  graphics_fill_circle(ctx, center, 3);
}
  
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);
  
  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_hands_layer = layer_create(bounds);
  layer_set_update_proc(s_hands_layer, hands_update_proc);
  layer_add_child(window_layer, s_hands_layer);

}

static void window_unload(Window *window) {

  layer_destroy(s_hands_layer);
}
  
static void init() {
  window = window_create();
  window_set_window_handlers(window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload,
  });
/**
 * 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));
  
}
static void window_load(Window *window) {

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

  current_slide_text_layer = text_layer_create((GRect) { .origin = { 0, 0 }, .size = { bounds.size.w, 50 } });
Example #8
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();
}
Example #9
0
//BT Logo Callback;
void BTLine_update_callback(Layer *BTLayer1, GContext* BT1ctx) {

       GPoint BTLinePointStart;
       GPoint BTLinePointEnd;

       graphics_context_set_stroke_color(BT1ctx, TextColorHold);

      if (BTConnected == 0) {

        #ifdef PBL_COLOR
            graphics_context_set_stroke_color(BT1ctx, GColorRed);
            graphics_context_set_fill_color(BT1ctx, GColorWhite);
            graphics_fill_rect(BT1ctx, layer_get_bounds(BTLayer1), 0, GCornerNone);
        #else
            graphics_context_set_stroke_color(BT1ctx, GColorBlack);
            graphics_context_set_fill_color(BT1ctx, GColorWhite);
            graphics_fill_rect(BT1ctx, layer_get_bounds(BTLayer1), 0, GCornerNone);
        #endif

        // "X"" Line 1
        BTLinePointStart.x = 1;
        BTLinePointStart.y = 1;

        BTLinePointEnd.x = 20;
        BTLinePointEnd.y = 20;
        graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd);

        // "X"" Line 2
        BTLinePointStart.x = 1;
        BTLinePointStart.y = 20;

        BTLinePointEnd.x = 20;
        BTLinePointEnd.y = 1;
        graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd);
      }
      else
      {
       //Line 1
       BTLinePointStart.x = 10;
       BTLinePointStart.y = 1;

       BTLinePointEnd.x = 10;
       BTLinePointEnd.y = 20;
       graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd);

       //Line 2
       BTLinePointStart.x = 10;
       BTLinePointStart.y = 1;

       BTLinePointEnd.x = 16;
       BTLinePointEnd.y = 5;
       graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd);

       //Line 3
       BTLinePointStart.x = 4;
       BTLinePointStart.y = 5;

       BTLinePointEnd.x = 16;
       BTLinePointEnd.y = 16;
       graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd);

       //Line 4
       BTLinePointStart.x = 4;
       BTLinePointStart.y = 16;

       BTLinePointEnd.x = 16;
       BTLinePointEnd.y = 5;
       graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd);

       //Line 5
       BTLinePointStart.x = 10;
       BTLinePointStart.y = 20;

       BTLinePointEnd.x = 16;
       BTLinePointEnd.y = 16;
       graphics_draw_line(BT1ctx, BTLinePointStart, BTLinePointEnd);
      }
}
Example #10
0
static void hands_update_proc(Layer *layer, GContext *ctx) {
	GRect bounds = layer_get_bounds(layer);
	GPoint center = grect_center_point(&bounds);
	int16_t second_hand_length = bounds.size.w / 2 - 5;
	int16_t second_hand_tail_length = 15;

	time_t now = time(NULL);
	struct tm *t = localtime(&now);
	int32_t second_angle = TRIG_MAX_ANGLE * t->tm_sec / 60;
	int32_t second_angle_tail = TRIG_MAX_ANGLE * (t->tm_sec + 30) / 60;

	GPoint second_hand = {
		.x = (int16_t)(sin_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.x,
		.y = (int16_t)(-cos_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.y,
	};
	GPoint second_hand_tail = {
		.x = (int16_t)(sin_lookup(second_angle_tail) * (int32_t)second_hand_tail_length / TRIG_MAX_RATIO) + center.x,
		.y = (int16_t)(-cos_lookup(second_angle_tail) * (int32_t)second_hand_tail_length / TRIG_MAX_RATIO) + center.y,
	};

	// temperature
	if (b_show_temperature) {
		graphics_context_set_text_color(ctx, gcolor_numbers);
		int offset = !b_show_numbers * 10;
#ifdef PBL_RECT
		graphics_draw_text(ctx, s_temp_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(27 - offset, 75, 40 + offset, 14), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
#else
		graphics_draw_text(ctx, s_temp_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_18), GRect(40 - offset, 78, 40 + offset, 14), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
#endif
	}

	// minute hand
	graphics_context_set_fill_color(ctx, gcolor_minute_hand);
	gpath_rotate_to(s_minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60);
	gpath_draw_filled(ctx, s_minute_arrow);

	// hour hand
	graphics_context_set_fill_color(ctx, gcolor_hour_hand);
	gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6));
	gpath_draw_filled(ctx, s_hour_arrow);

	// second hand
	if (b_show_second_hand) {
		graphics_context_set_stroke_color(ctx, gcolor_second_hand);
		graphics_draw_line(ctx, second_hand, center);
		graphics_draw_line(ctx, second_hand_tail, center);
	}

	// dot in the middle
	graphics_context_set_fill_color(ctx, gcolor_second_hand);
	graphics_fill_circle(ctx, GPoint(bounds.size.w / 2, bounds.size.h / 2), 4);
}

static void update_date(void){
  time_t now = time(NULL);
  struct tm *t = localtime(&now);
  
  //corrects for 24h time
  int hour = (t->tm_hour < 13) ? t->tm_hour : t->tm_hour - 12;
  
  static char date_buffer[16];
  
  //strategically put the date where the hands are not covering
  if((t->tm_min < 7 || t->tm_min > 23) && (hour < 1 || hour >= 5)){
    strftime(date_buffer, sizeof(date_buffer), "%a\n%d", t);
    text_layer_set_text(date_layer_right, date_buffer);
    text_layer_set_text(date_layer_left, "\0");
    text_layer_set_text(date_layer_bottom, "\0"); 
  }
  else if((t->tm_min < 37 || t->tm_min > 53) && (hour < 7 || hour > 11)){
    strftime(date_buffer, sizeof(date_buffer), "%a\n%d", t);
    text_layer_set_text(date_layer_left, date_buffer);
    text_layer_set_text(date_layer_right, "\0");
    text_layer_set_text(date_layer_bottom, "\0");
  }
  else{
    strftime(date_buffer, sizeof(date_buffer), "%a %d", t);
    text_layer_set_text(date_layer_bottom, date_buffer);
    text_layer_set_text(date_layer_right, "\0");
    text_layer_set_text(date_layer_left, "\0");
  }
}

static void handle_second_tick(struct tm *tick_time, TimeUnits units_changed) {
	layer_mark_dirty(window_get_root_layer(window));
  update_date();
}
Example #11
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();
}
Example #12
0
static void bg_update_proc(Layer *layer, GContext *ctx) {
	GRect bounds = layer_get_bounds(layer);
	GRect frame = grect_inset(bounds, GEdgeInsets(4 * INSET));
	GRect inner_hour_frame = grect_inset(bounds, GEdgeInsets((4 * INSET) + 8));
	GRect inner_minute_frame = grect_inset(bounds, GEdgeInsets((4 * INSET) + 6));
	
	graphics_context_set_stroke_color(ctx, gcolor_hour_marks);
	graphics_context_set_stroke_width(ctx, 3);

	// Hours marks
	for(int i = 0; i < 12; i++) {
		int hour_angle = get_angle_for_hour(i);
		GPoint p0 = gpoint_from_polar(frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(hour_angle));
		GPoint p1 = gpoint_from_polar(inner_hour_frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(hour_angle));
		graphics_draw_line(ctx, p0, p1);
	}
	
	// Minute Marks
	graphics_context_set_stroke_color(ctx, gcolor_minute_marks);
	graphics_context_set_stroke_width(ctx, 1);
	for(int i = 0; i < 60; i++) {
		if (i % 5) {
			int minute_angle = get_angle_for_minute(i);
			GPoint p0 = gpoint_from_polar(frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(minute_angle));
			GPoint p1 = gpoint_from_polar(inner_minute_frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(minute_angle));
			graphics_draw_line(ctx, p0, p1);
		}
	}
	
	// numbers
	if (b_show_numbers) {
		graphics_context_set_text_color(ctx, gcolor_numbers);
		
#ifdef PBL_RECT
		graphics_draw_text(ctx, "12", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(63, 18, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
		graphics_draw_text(ctx, "1", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(85, 23, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
		graphics_draw_text(ctx, "2", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(104, 43, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
		graphics_draw_text(ctx, "3", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(112, 68, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
		graphics_draw_text(ctx, "4", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(104, 93, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
		graphics_draw_text(ctx, "5", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(85, 110, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
		graphics_draw_text(ctx, "6", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(62, 118, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
		graphics_draw_text(ctx, "7", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(39, 110, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
		graphics_draw_text(ctx, "8", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(20, 93, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
		graphics_draw_text(ctx, "9", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(14, 68, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
		graphics_draw_text(ctx, "10", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(20, 43, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
		graphics_draw_text(ctx, "11", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(39, 23, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
#else
		graphics_draw_text(ctx, "12", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(80, 10, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
		graphics_draw_text(ctx, "1", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(107, 20, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
		graphics_draw_text(ctx, "2", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(130, 43, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
		graphics_draw_text(ctx, "3", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(140, 74, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
		graphics_draw_text(ctx, "4", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(130, 106, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
		graphics_draw_text(ctx, "5", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(107, 126, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
		graphics_draw_text(ctx, "6", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(81, 136, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
		graphics_draw_text(ctx, "7", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(53, 124, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
		graphics_draw_text(ctx, "8", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(29, 106, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
		graphics_draw_text(ctx, "9", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(20, 74, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
		graphics_draw_text(ctx, "10", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(28, 42, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
		graphics_draw_text(ctx, "11", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(50, 22, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
#endif
	}
}
Example #13
0
// @private Called to redraw the layer
static void OutputTextLabel_Redraw(struct Layer* layer, GContext* ctx) {
	
	// Get class container
	OutputTextLabel* label = layer_get_data(layer);
	
	// Get window bounds
	GRect bounds = layer_get_bounds(layer);
	
	// Clear the view area
	graphics_context_set_fill_color(ctx, GColorBlack);
	graphics_fill_rect(ctx, bounds, 0, 0);
	
	// Check if got text
	if (strlen(label->text) == 0)
		return;
	
	// Check if can use giant font
	if (label->giantFont) {
		
		// Get bounds of text
		GSize textSize = graphics_text_layout_get_content_size(label->text, label->giantFont, bounds, GTextOverflowModeWordWrap, GTextAlignmentCenter);
		if (textSize.h < bounds.size.h) {
			
			// We can use the large font, draw it!
			graphics_context_set_stroke_color(ctx, GColorWhite);
			graphics_draw_text(ctx, label->text, label->giantFont, GRect(0, bounds.size.h / 2 - textSize.h / 2, bounds.size.w, bounds.size.h), GTextOverflowModeWordWrap, GTextAlignmentCenter, 0);
			return;
			
		}
		
	}
	
	// Check if can use large font
	if (label->largeFont) {
		
		// Get bounds of text
		GSize textSize = graphics_text_layout_get_content_size(label->text, label->largeFont, bounds, GTextOverflowModeWordWrap, GTextAlignmentCenter);
		if (textSize.h < bounds.size.h) {
			
			// We can use the large font, draw it!
			graphics_context_set_stroke_color(ctx, GColorWhite);
			graphics_draw_text(ctx, label->text, label->largeFont, GRect(0, bounds.size.h / 2 - textSize.h / 2, bounds.size.w, bounds.size.h), GTextOverflowModeWordWrap, GTextAlignmentCenter, 0);
			return;
			
		}
		
	}
	
	// Check if can use medium font
	if (label->mediumFont) {
		
		// Get bounds of text
		GSize textSize = graphics_text_layout_get_content_size(label->text, label->mediumFont, bounds, GTextOverflowModeWordWrap, GTextAlignmentCenter);
		if (textSize.h < bounds.size.h) {
			
			// We can use the large font, draw it!
			graphics_context_set_stroke_color(ctx, GColorWhite);
			graphics_draw_text(ctx, label->text, label->mediumFont, GRect(0, bounds.size.h / 2 - textSize.h / 2, bounds.size.w, bounds.size.h), GTextOverflowModeWordWrap, GTextAlignmentCenter, 0);
			return;
			
		}
		
	}
	
	// Check if can use small font
	if (label->smallFont) {
		
		// Get bounds of text
		GSize textSize = graphics_text_layout_get_content_size(label->text, label->smallFont, bounds, GTextOverflowModeWordWrap, GTextAlignmentCenter);
		
		// Draw it no matter the size
		graphics_context_set_stroke_color(ctx, GColorWhite);
		graphics_draw_text(ctx, label->text, label->smallFont, GRect(0, MAX(bounds.size.h / 2 - textSize.h / 2, 0), bounds.size.w, bounds.size.h), GTextOverflowModeWordWrap, GTextAlignmentCenter, 0);
		return;
		
	}
	
}
static void window_load(Window *window) {
  
  // Load the bitmap asset
  // resource_init_current_app must be called before all asset loading.
  menu_icons[0] = gbitmap_create_with_resource(RESOURCE_ID_HAPPY);
  menu_icons[1] = gbitmap_create_with_resource(RESOURCE_ID_SAD);
  menu_icons[2] = gbitmap_create_with_resource(RESOURCE_ID_STRESSED);
  menu_icons[3] = gbitmap_create_with_resource(RESOURCE_ID_CALM);
  
  // ******** Menu Items ********
  // First menu item.
  first_menu_items[0] = (SimpleMenuItem) {
    .icon = menu_icons[0],
    .title = "Happy",
    .subtitle = "Sweet!",
    .callback = menu_select_callback,
  };
  
  // Second menu item.
  first_menu_items[1] = (SimpleMenuItem) {
    .icon = menu_icons[1],
    .title = "Sad",
    .subtitle = "Cheer Up!",
    .callback = menu_select_callback,
  };
  
  // Third menu item.
  first_menu_items[2] = (SimpleMenuItem) {
    .icon = menu_icons[2],
    .title = "Stressed",
    .subtitle = "Take a chill pill!",
    .callback = menu_select_callback,
  };

  // Fourth menu item.
  first_menu_items[3] = (SimpleMenuItem){
    .icon = menu_icons[3],
    .title = "Calm",
    .subtitle = "Like a felon!",
    .callback = menu_select_callback,
  };
  
  // ******** SECTIONS ********
  menu_sections[0] = (SimpleMenuSection) {
    .num_items = NUM_FIRST_MENU_ITEM,
    .items = first_menu_items,
  };
  
  // Required: gets the root layer. ( base layer )
  Layer *window_layer = window_get_root_layer(window);
  
  // Required: Gets the dimensions of the whole pebble screen.
  GRect bounds = layer_get_bounds(window_layer);

  // initialize the menu.
  simple_menu_layer = simple_menu_layer_create(bounds, window, menu_sections, NUM_MENU_SECTIONS, NULL);
  
  // Required: add the window for display
  layer_add_child(window_layer, simple_menu_layer_get_layer(simple_menu_layer));
}

/************************************************************/
/* window_unload                                            */
/*                                                          */
/* Handles all the clean up before destroying the window.   */
/************************************************************/
static void window_unload(Window *window) {
  simple_menu_layer_destroy(simple_menu_layer);
  
  // Destroy the images
  for(int i = 0; i < NUM_MENU_ICONS; i++){
    gbitmap_destroy(menu_icons[i]);
  }
}

/************************************************************/
/* init                                                     */
/*                                                          */
/* Creates the window, sets the click_config_provider, sets */
/* the window handlers, and pushes the window onto the  top */
/* of the stack so it is visible.                           */
/************************************************************/
static void init(void) {
  
  // Required: Creates the window. Needed to display everything.
  window = window_create();
  
  // Required. Sets the hanldlers for the window. window_load for when the user enters the watchapp and
  // window_unload, for when the user leave the watch app.
  window_set_window_handlers(window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload,
  });
  
  // Setup the messaging handlers.
  app_message_register_outbox_sent(out_sent_handler);
  app_message_register_outbox_failed(out_failed_handler);
  const uint32_t inbound_size = 10;
  const uint32_t outbound_size = 64;
  app_message_open(inbound_size, outbound_size);
  
  
  // Vibrate to let the user know.
  vibes_short_pulse();
  
  // Required: Will push the window to the top of the stack and therefore making it visible.
  const bool animated = true;
  window_stack_push(window, animated);
}

/************************************************************/
/* deinit                                                   */
/*                                                          */
/* Destroys the window and performs all of the necessary    */
/* clean up.                                                */
/************************************************************/
static void deinit(void) {
  window_destroy(window);
}
Example #15
0
void draw_marine_layer(Layer *layer, GContext *ctx) {
  int next_x = 0;
  int next_y = 5 - ceil(anim_data.current_battery_state.charge_percent / 20.0);
  
  next_y = next_y > MAX_SPRITE_Y ? MAX_SPRITE_Y : next_y; 
  
  bool destroy_new_sprite = false;
  GBitmap* new_sprite = NULL;
  
  if (!anim_data.current_battery_state.is_charging && !anim_data.current_battery_state.is_plugged) {
      switch (anim_data.current_x) {
        case 2:
          next_x = 1;
          break;
        case 1:
          switch (anim_data.previous_x) {
            case 2:
             next_x = 0;
             break;
            case 0:
             next_x = 2;
             break;
            case 1:
             next_x = 0;
             break;
            default:
              return;
          }
          break;
       case 0:
        next_x = 1;
        break;
       default:
        return;
     }
      
     anim_data.previous_x = anim_data.current_x;
     anim_data.current_x = next_x;
     
     new_sprite  = get_sprite_by_index(marine_spritesheet, next_x, next_y);
     
     if (!new_sprite) {
       APP_LOG(APP_LOG_LEVEL_ERROR, "Error getting new sprite! x:%d y:%d", next_x, next_y);
       return;
     }
     
     destroy_new_sprite = true; 
  } else {
    new_sprite = marine_charging;
  }
   
#ifdef PBL_PLATFORM_BASALT
   GRect image_size = gbitmap_get_bounds(new_sprite);
#else 
   GRect image_size = new_sprite->bounds;
#endif  
  
  GRect bounds = layer_get_bounds(layer);
  
  grect_align(&image_size, &bounds, GAlignCenter, true);

  graphics_context_set_compositing_mode(ctx, GCompOpAssign);
  graphics_draw_bitmap_in_rect(ctx, new_sprite, image_size);
  
  if (destroy_new_sprite) {
    gbitmap_destroy(new_sprite);
  }
}
Example #16
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;
  }
}
Example #17
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);
}
Example #18
0
static void bg_update_proc(Layer *layer, GContext *ctx) {
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
}
static void init_location_search(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  label_layer = text_layer_create((GRect) { .origin = { 0, 90 }, .size = { bounds.size.w, 100 } });
Example #20
0
/*Update Drawing Handler*/
static void hands_update_proc(Layer *layer, GContext *ctx) {
  
   graphics_context_set_antialiased(ctx, true);
 
  int16_t scale = _12HScaleFactor*60; 
  if ( clock_is_24h_style() ) {
    scale = _24HScaleFactor*60;
  }

  
  GRect bounds = layer_get_bounds(layer);
  GPoint center = grect_center_point(&bounds);
  
  GPoint secondHand;
  GPoint hourHand1, hourHand2;
  
  time_t now = time(NULL);
  struct tm* t = localtime(&now); 

  int16_t ms = time_ms(NULL, NULL);
  
  const int16_t second_hand_length = PBL_IF_ROUND_ELSE((bounds.size.w / 2) - 19, (bounds.size.w / 2) - 2);
  const int16_t hour_tick_length = PBL_IF_ROUND_ELSE((bounds.size.w / 2) - 28, bounds.size.w / 2);
  //const int16_t hour_hand_length = PBL_IF_ROUND_ELSE((bounds.size.w / 2) - 60, bounds.size.w / 2);
  
  calculate_pointer_end((t->tm_sec*100)+ms/10, second_hand_length, &center, &secondHand, 60*100, 0);    
 
// minute/hour hand
  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_context_set_stroke_color(ctx, GColorBlack);
  gpath_rotate_to(s_minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60);
  gpath_draw_filled(ctx, s_minute_arrow);
  gpath_draw_outline(ctx, s_minute_arrow);
  //graphics_draw_line(ctx, minuteHand, center);
    
  graphics_context_set_stroke_color(ctx, GColorWhite);
  //gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6));
  gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (t->tm_hour*60+t->tm_min ))/ scale);
  gpath_draw_filled(ctx, s_hour_arrow);
  gpath_draw_outline(ctx, s_hour_arrow);

  // draw hour lines
  int hours = clock_is_24h_style() ? _24HScaleFactor : _12HScaleFactor;
  for (int h = 0; h < hours; h++) {
    calculate_pointer_end(h, hour_tick_length, &center, &hourHand1, hours, 0);
    if (h % 3 == 0) {
      calculate_pointer_end(h, hour_tick_length-11, &center, &hourHand2, hours, 0);
    } else {
      calculate_pointer_end(h, hour_tick_length-7, &center, &hourHand2, hours, 0);
    }
    
    graphics_context_set_fill_color(ctx, GColorWhite);
    graphics_context_set_stroke_color(ctx, GColorWhite);
    graphics_draw_line(ctx, hourHand1, hourHand2);
  }

  // draw second ticks 
  for (int i = 0; i < t->tm_sec; i++) {
    calculate_pointer_end(i, second_hand_length, &center, &secondHand, 60, 0);
    graphics_context_set_fill_color(ctx, GColorWhite);
    graphics_fill_rect(ctx, GRect(secondHand.x, secondHand.y, 3, 3), 0, GCornerNone);
  }
  
  // dot in the middle
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, GRect(bounds.size.w / 2 - 1, bounds.size.h / 2 - 1, 3, 3), 0, GCornerNone);
}
Example #21
0
  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);

  // Battery
  GRect frame;
  frame.origin.x = layer_get_bounds(&window.layer).size.w - 31;
  frame.origin.y = 6;
  frame.size.w = 24;
  frame.size.h = 12;

  layer_init(&battery_layer, frame);
  battery_layer.update_proc = &battery_layer_update_callback;
  layer_add_child(&window.layer, &battery_layer);

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

  // Bluetooth 	
  GRect frameb;
  frameb.origin.x = layer_get_bounds(&window.layer).size.w - 50;
  frameb.origin.y = 6;
Example #22
0
static void draw_astro(Layer *layer, GContext *ctx) {
  if (astro_initialized) {
      // draw dawn & dusk lines (background)
      GRect bounds = layer_get_bounds(layer);
      const GPoint center = grect_center_point(&bounds);
      GPathInfo horizon_info = {
        .num_points = 5,
        .points = (GPoint []) {{bounds.origin.x, center.y - (bounds.size.w * sin_lookup(sunrise_angle) / (2 * cos_lookup(sunrise_angle)))},
                               {center.x, center.y},
                               {bounds.size.w, center.y - (bounds.size.w * sin_lookup(sunset_angle) / (2 * cos_lookup(sunset_angle)))},
                               {bounds.size.w, bounds.size.h},
                               {bounds.origin.x, bounds.size.h}
                              }
      };
      GPath *horizon = NULL;
      horizon = gpath_create(&horizon_info);
      graphics_context_set_fill_color(ctx, GColorBlack);
      graphics_context_set_stroke_color(ctx, GColorBlack);
      gpath_draw_filled(ctx, horizon);
      gpath_draw_outline(ctx, horizon);

      // draw sun and moon rays
      graphics_draw_ray(ctx, layer, center, sun_angle, SUN_THICKNESS, SUN_STROKE, SUN_FILL);
      graphics_draw_ray(ctx, layer, center, moon_angle, MOON_THICKNESS, MOON_STROKE, MOON_FILL);

      // draw planets
      GPath *venus = NULL;
      GPath *mars = NULL;
      graphics_context_set_fill_color(ctx, GColorWhite);
      graphics_context_set_stroke_color(ctx, GColorBlack);
      venus = gpath_create(&VENUS_PATH_INFO);
      gpath_move_to(venus, GPoint(center.x + VENUS_RADIUS * cos_lookup(venus_angle) / TRIG_MAX_RATIO,
                                  center.y + VENUS_RADIUS * sin_lookup(venus_angle) / TRIG_MAX_RATIO));
      gpath_draw_filled(ctx, venus);
      gpath_draw_outline(ctx, venus);
      mars = gpath_create(&VENUS_PATH_INFO);
      gpath_move_to(mars, GPoint(center.x + MARS_RADIUS * cos_lookup(mars_angle) / TRIG_MAX_RATIO,
                                  center.y + MARS_RADIUS * sin_lookup(mars_angle) / TRIG_MAX_RATIO));
      gpath_rotate_to(mars, TRIG_MAX_ANGLE / 2);
      gpath_draw_filled(ctx, mars);
      gpath_draw_outline(ctx, mars);

      GRect jupiter = GRect(center.x + JUPITER_RADIUS * cos_lookup(jupiter_angle) / TRIG_MAX_RATIO,
                            center.y + JUPITER_RADIUS * sin_lookup(jupiter_angle) / TRIG_MAX_RATIO,
                            JUPITER_SIZE * 2,
                            JUPITER_SIZE * 2);
      graphics_fill_rect(ctx, jupiter, 0, 0);
      graphics_draw_rect(ctx, jupiter);
  }
}

static void draw_time(Layer *layer, GContext *ctx) {
  // draw the time in an analog clock at the center
  GRect bounds = layer_get_bounds(layer);
  const GPoint center = grect_center_point(&bounds);

  time_t now = time(NULL);
  struct tm *t = localtime(&now);
  int secondMarkers = t->tm_sec / 2;
  int i;

  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_fill_circle(ctx, center, HMS_RADIUS);
  graphics_context_set_fill_color(ctx, GColorBlack);
  // draw the seconds
  if (secondMarkers % 30 != 0) {
    if (secondMarkers <= 15) {
      for (i=1; i<=secondMarkers; i++) {
        int angle = i * 4;
        GPoint marker = GPoint(center.x + SECOND_RADIUS * sin_lookup(angle * angle_180 / 30) / TRIG_MAX_RATIO, center.y - SECOND_RADIUS * cos_lookup(angle * angle_180 / 30) / TRIG_MAX_RATIO);
        graphics_fill_circle(ctx, marker, SECOND_THICKNESS);
      }
    } else {
      for (i=(secondMarkers % 15 + 1); i<=15; i++) {
        int angle = i * 4;
        GPoint marker = GPoint(center.x + SECOND_RADIUS * sin_lookup(angle * angle_180 / 30) / TRIG_MAX_RATIO, center.y - SECOND_RADIUS * cos_lookup(angle * angle_180 / 30) / TRIG_MAX_RATIO);
        graphics_fill_circle(ctx, marker, SECOND_THICKNESS);
      }
    }
  }
  // draw hour hand
  graphics_draw_arc_cw(ctx, center, HOUR_RADIUS, HOUR_THICKNESS, -angle_90, ((t->tm_hour * angle_180 / 6) - angle_90), GColorBlack);

  // draw minute hand
  graphics_draw_arc_cw(ctx, center, MINUTE_RADIUS, MINUTE_THICKNESS, -angle_90, ((t->tm_min * angle_180 / 30) - angle_90), GColorBlack);
}
Example #23
0
static void pad_update_proc(Layer *this_layer, GContext *ctx) 
  {
  //Background
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, layer_get_bounds(s_pad_layer), 0, GCornerNone);
	pos += (spd*.7);
  //Paddle bounds
	if(pos <= 0)
    {
		pos = 0;
	  }
	else if(pos >= 105)
    {
		pos = 105;
	  }
  //Paddle
  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_fill_rect(ctx, GRect(10, pos , 7, 45), 0, GCornerNone);
	//Ball bounce off right
	if(bpos.x >= 130)
    {
		bspd.x = bspd.x * -1;
		score += 1;
		//Score
	  static char sco[32];
	  snprintf(sco, sizeof(sco), "Score %i", score);
    text_layer_set_text(s_scr, sco);
	  }
  //Ball bounce off top or bot
	if(bpos.y <= 5 || bpos.y >= 140)
    {
		bspd.y = bspd.y * -1;
	  }
  //Change in speed
	if(bpos.x >= 16 && bpos.x < 20)
    {
		if(abs(bpos.y + 5 - (pos+23)) < 23)
      {
			if(abs(bpos.y - pos - 11) <12)
        {
				if(bspd.y < 10)
          {
          bspd.y += 1;
          }
				else
          {
          bspd.y = 10;
          }
			  }
			else if(abs(bpos.y - pos + 11) < 12)
        {
				if(bspd.y > -10)
          {
          bspd.y -= 1;
          }
				else
          {
          bspd.y = -10;
          }
			  }
			bspd.x *= -1;
		  }
			if(bpos.x <= 5)
      {
			bspd.x = bspd.x * -1;
			bpos.x += bspd.x;
			
			layer_mark_dirty(s_pad_layer);
			score -= 1;
			
	    static char sco[32];
	    snprintf(sco, sizeof(sco), "Score %i", score);
      text_layer_set_text(s_scr, sco);
		  }
	  }
/*  if(bpos.x < 5)      //Suppose to vibrate
    {
    vibes_short_pulse();
    }*/
  //Change in HighScore
	bpos.x += bspd.x;
	bpos.y += bspd.y;
  //The ball
	graphics_fill_rect(ctx, GRect(bpos.x, bpos.y, 10, 10), 0, GCornerNone);
}
Example #24
0
static void line_layer_update_callback(Layer *layer, GContext* ctx) {
  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
}
Example #25
0
static void anim_update_proc(Layer *layer, GContext *ctx) {
  int x = layer_get_bounds(layer).size.w / 2 ;
  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_fill_circle(ctx, GPoint(x,x) ,x -1);
  //layer_mark_dirty(s_box2_layer);
}
Example #26
0
static void icon_update_proc(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);
  GRect bitmap_bounds = gbitmap_get_bounds(immergo_bitmap);
  graphics_context_set_compositing_mode(ctx, GCompOpSet);
  graphics_draw_bitmap_in_rect(ctx, immergo_bitmap, (GRect){.origin = bounds.origin, .size = bitmap_bounds.size});
Example #27
0
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  text_layer = text_layer_create((GRect) { .origin = { 0, 72 }, .size = { bounds.size.w, 20 } });
Example #28
0
static void main_window_load(Window *window) {
  // Get information about the Window
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  

  APP_LOG(APP_LOG_LEVEL_INFO, "Main window loading");
  
  APP_LOG(APP_LOG_LEVEL_INFO, "battery time");

  s_battery_layer = layer_create(GRect(PBL_IF_ROUND_ELSE(0, 20), PBL_IF_ROUND_ELSE(0, 154), PBL_IF_ROUND_ELSE(180, 104), PBL_IF_ROUND_ELSE(180, 2)));
  s_weather_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(117, 120), bounds.size.w, 55));
  s_time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(52, 46), bounds.size.w, 80));
  s_date_layer = PBL_IF_BW_ELSE(text_layer_create(GRect(1, 2, bounds.size.w, 50)), text_layer_create(GRect(PBL_IF_ROUND_ELSE(42, 1), PBL_IF_ROUND_ELSE(15, 1), PBL_IF_ROUND_ELSE(97, 65), 55)));
  s_bt_icon_layer = PBL_IF_BW_ELSE(layer_create(GRect(60, 115, 30, 30)), layer_create(GRect(PBL_IF_ROUND_ELSE(75, 62), PBL_IF_ROUND_ELSE(135, 8), 30, 30)));
  
  
  int textcolor = persist_read_int(MESSAGE_KEY_TextColor);
  int background = persist_read_int(MESSAGE_KEY_BackgroundColor);
  GColor bg_color = GColorFromHEX(background);
  GColor text_color = GColorFromHEX(textcolor);
  window_set_background_color(s_main_window, bg_color);
  APP_LOG(APP_LOG_LEVEL_INFO, "Text Color is: %d", textcolor);
  APP_LOG(APP_LOG_LEVEL_INFO, "Background Color is: %d", background);
  
  
  // Battery Layer
  layer_set_update_proc(s_battery_layer, battery_update_proc);

  // Add Battery Layer to Window
  layer_add_child(window_get_root_layer(window), s_battery_layer);
  
  

  
  APP_LOG(APP_LOG_LEVEL_INFO, "reading key: celsius");
  
  if (persist_read_bool(MESSAGE_KEY_Celsius)) {
    celsius = persist_read_int(MESSAGE_KEY_Celsius);
  }
  
  /*
  APP_LOG(APP_LOG_LEVEL_INFO, "reading key: customLocation");
  if (persist_read_string(KEY_CUSTOM_LOCATION)) {
    customLocation = persist_read_string(KEY_CUSTOM_LOCATION);
  }*/
  
  APP_LOG(APP_LOG_LEVEL_INFO, "weather time");
  
  
  
  // Weather Layer
  text_layer_set_background_color(s_weather_layer, GColorClear);
  text_layer_set_text_color(s_weather_layer, text_color);
  //text_layer_set_text_color(s_weather_layer, GColorBlack);
  text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter);
  PBL_IF_BW_ELSE(text_layer_set_text(s_weather_layer, ""), text_layer_set_text(s_weather_layer, "Loading..."));
  s_weather_font = PBL_IF_ROUND_ELSE(fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_17)), fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_20)));
  text_layer_set_font(s_weather_layer, s_weather_font);
  
  // Add Weather Layer to Window
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer));

  APP_LOG(APP_LOG_LEVEL_INFO, "time layer");
  
 
  
  
  // Time Layer
  s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_53));
  text_layer_set_font(s_time_layer, s_time_font);
  text_layer_set_background_color(s_time_layer, GColorClear);
  text_layer_set_text_color(s_time_layer, text_color);
  
  APP_LOG(APP_LOG_LEVEL_INFO, "reading key: invert");

  APP_LOG(APP_LOG_LEVEL_INFO, "reading key: 24h");
  

  
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);

  // Add Time Layer to Window
  layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
  
  APP_LOG(APP_LOG_LEVEL_INFO, "date time");

  // Date Layer
  s_date_font = PBL_IF_BW_ELSE(fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_20)), fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_17)));
	text_layer_set_text_color(s_date_layer, text_color);
  //text_layer_set_text_color(s_date_layer, GColorBlack);
  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_date_font);

  APP_LOG(APP_LOG_LEVEL_INFO, "updating time");
  
  
  // Add Date Layer to Window
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));
  
  
  // Create the Bluetooth icon GBitmap
  APP_LOG(APP_LOG_LEVEL_INFO, "Reading Bluetooth color: %d", persist_read_bool(MESSAGE_KEY_Bluetooth));
  if (persist_read_int(MESSAGE_KEY_Bluetooth) == 102) {
    s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON);
  } else {
    s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON_BLACK);
  }
  // Create the BitmapLayer to display the GBitmap
  s_bt_icon_layer = PBL_IF_BW_ELSE(layer_create(GRect(60, 115, 30, 30)), layer_create(GRect(PBL_IF_ROUND_ELSE(75, 62), PBL_IF_ROUND_ELSE(135, 8), 30, 30)));
  layer_set_update_proc(s_bt_icon_layer, layer_update_proc);
  //bitmap_layer_set_bitmap(s_bt_icon_layer, s_bt_icon_bitmap);
  layer_add_child(window_layer, s_bt_icon_layer);
  
  APP_LOG(APP_LOG_LEVEL_INFO, "steps time");

  // Steps Layer
  
  // subscribe to health events
  int goal_num = persist_read_int(MESSAGE_KEY_Step_Goal);
  int steps = persist_read_int(MESSAGE_KEY_Goal_Color);
  GColor steps_color = GColorFromHEX(steps);
  s_num_label = text_layer_create(GRect(PBL_IF_ROUND_ELSE(67, 90), PBL_IF_ROUND_ELSE(37, 1), 50, 45));
  text_layer_set_background_color(s_num_label, GColorClear);
  text_layer_set_text_color(s_num_label, text_color);
  int s_step_count = (int)health_service_sum_today(HealthMetricStepCount);
  if (goal_num == 0 || s_step_count < goal_num) {
    int textcolor = persist_read_int(MESSAGE_KEY_TextColor);
    GColor text_color = GColorFromHEX(textcolor);
    text_layer_set_text_color(s_num_label, text_color);
  }
  else {
    text_layer_set_text_color(s_num_label, steps_color);
  }
  //text_layer_set_text_color(s_num_label, GColorBlack);
  text_layer_set_text_alignment(s_num_label, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentRight));
  text_layer_set_font(s_num_label, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_17)));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_num_label));
  
  if(health_service_events_subscribe(health_handler, NULL)) {
    // force initial steps display
    health_handler(HealthEventMovementUpdate, NULL);
  } else {
    APP_LOG(APP_LOG_LEVEL_ERROR, "Health not available!");
  }
  
 
	
  
  // Show the correct state of the BT connection from the start
  bluetooth_callback(connection_service_peek_pebble_app_connection());


  APP_LOG(APP_LOG_LEVEL_INFO, "Main window loaded");
  
  update_time();
}
Example #29
0
    window = window_create();
    window_set_window_handlers(window, (WindowHandlers) {
        .load = window_load,
            .unload = window_unload,
    });
    window_stack_push(window, true);

    s_day_buffer[0] = '\0';
    s_num_buffer[0] = '\0';

    // init hand paths
    s_minute_arrow = gpath_create(&MINUTE_HAND_POINTS);
    s_hour_arrow = gpath_create(&HOUR_HAND_POINTS);

    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_bounds(window_layer);
    GPoint center = grect_center_point(&bounds);
    gpath_move_to(s_minute_arrow, center);
    gpath_move_to(s_hour_arrow, center);

    for (int i = 0; i < NUM_CLOCK_TICKS; ++i) {
        s_tick_paths[i] = gpath_create(&ANALOG_BG_POINTS[i]);
    }
    Star[0] = gpath_create(&FillGray);
    Star[1] = gpath_create(&FillBlack);
    Star[2] = gpath_create(&FillWhite);
    Star[3] = gpath_create(&FillCenter);
    for (int i = 0; i < 6; ++i){
        HiLites[i] = gpath_create(&HiLitePts[i]);
    }
Example #30
0
static void main_window_load(Window *window) {
  // Get information about the Window
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  // Create the TextLayer with specific bounds GRect(0, PBL_IF_ROUND_ELSE(58, 52), bounds.size.w, 50));
  s_time_layer = text_layer_create(
      GRect(0, PBL_IF_ROUND_ELSE(10, 10), bounds.size.w, 50));

  // Improve the layout to be more like a watchface
  text_layer_set_background_color(s_time_layer, textBackgroundColour);
  text_layer_set_text_color(s_time_layer, textColour);
  text_layer_set_text(s_time_layer, "00:00");
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
  text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT ));

  // 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(10, 70), bounds.size.w, 50));
  
  //GColorBlack
text_layer_set_background_color(s_date_layer, textBackgroundColour);
  text_layer_set_text_color(s_date_layer, textColour);
  text_layer_set_text(s_date_layer, "dd:mm:yyyy");
text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
  text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));

// Add it as a child layer to the Window's root layer
  layer_add_child(window_layer, text_layer_get_layer(s_date_layer));
  
  // Create temperature Layer
  s_weather_layer = text_layer_create(
      GRect(0, PBL_IF_ROUND_ELSE(125, 130), bounds.size.w, 30));

  // Style the text
  text_layer_set_background_color(s_weather_layer, textBackgroundColour);
  text_layer_set_text_color(s_weather_layer, textColour);
  text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter);
  text_layer_set_text(s_weather_layer, "hold on boss...");
  text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT ));
  
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer));
  
  // Sun Layer 
  s_sun_layer = text_layer_create(
      GRect(0, PBL_IF_ROUND_ELSE(95, 95), bounds.size.w, 25));
  text_layer_set_background_color(s_sun_layer, textBackgroundColour);
  text_layer_set_text_color(s_sun_layer, textColour);
  text_layer_set_text_alignment(s_sun_layer, GTextAlignmentCenter);
  text_layer_set_text(s_sun_layer, "<><><><><><>");
  text_layer_set_font(s_sun_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_sun_layer));
  
  // Create battery meter Layer
s_battery_layer = layer_create(GRect(14, 54, 115, 2));
layer_set_update_proc(s_battery_layer, battery_update_proc);
  
  // Add to Window
layer_add_child(window_get_root_layer(window), s_battery_layer);
  
}