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

	s_layer = layer_create(layer_get_bounds(window_get_root_layer(window)));
	layer_add_child(window_get_root_layer(window), s_layer);
	layer_set_update_proc(s_layer, draw_watchface);

	s_time_layer = text_layer_create(GRect(0, 0, 24, 24));
	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);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));

	if (persist_read_int(KEY_BACKGROUND_COLOR)) {
		background_color = GColorFromHEX(persist_read_int(KEY_BACKGROUND_COLOR));
		window_set_background_color(window, GColorFromHEX(persist_read_int(KEY_BACKGROUND_COLOR)));
	} else {
		background_color = GColorWhite;
	}

	setup_blocks();

	if (persist_read_int(KEY_DEGREEOPTION)) {
		degreeOption = persist_read_int(KEY_DEGREEOPTION);
	} else {
		degreeOption = 0;
	}

	s_weather_layer = text_layer_create(GRect(0,152, 144, 14));
	text_layer_set_font(s_weather_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	text_layer_set_background_color(s_weather_layer, GColorClear);
	text_layer_set_text_color(s_weather_layer, gcolor_legible_over(background_color));
	text_layer_set_text_alignment(s_weather_layer, GTextAlignmentRight);
	text_layer_set_text(s_weather_layer, "Loading...");
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer));

	s_bluetooth_icon_layer = layer_create(GRect(0,0,30,30));
	layer_set_update_proc(s_bluetooth_icon_layer, bluetooth_update_proc);
	bluetooth_path = gpath_create(&BLUETOOTH_INFO);
	layer_add_child(window_get_root_layer(window), s_bluetooth_icon_layer);

	//show the correct state of the bluetooth connection from the start
#ifdef PBL_SDK_2
	bluetooth_callback(bluetooth_connection_service_peek());
#elif PBL_SDK_3
	bluetooth_callback(connection_service_peek_pebble_app_connection());
#endif

	s_date_layer = text_layer_create(GRect(0,0,144,14));
	text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	text_layer_set_text_color(s_date_layer, gcolor_legible_over(background_color));
	text_layer_set_background_color(s_date_layer, GColorClear);
	text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));

}
static void bluetooth_update_proc(Layer *layer, GContext *ctx) {
    if (!s_bluetooth_connected) {
        graphics_context_set_stroke_width(ctx, 3);
        graphics_context_set_stroke_color(ctx, gcolor_legible_over(background_color));
        gpath_draw_outline(ctx, bluetooth_path);
    }
}
Exemplo n.º 3
0
static void set_background_and_text_color(int color){
  GColor background_color = GColorFromHEX(color);
  text_layer_set_background_color(upper_text_layer, background_color);
  window_set_background_color(s_main_window, background_color);
  text_layer_set_text_color(battery_text, gcolor_legible_over(background_color));
  
}
Exemplo n.º 4
0
void draw_hand_layer(Layer* l, GContext* ctx)
{
	GColor foreground_color = gcolor_legible_over(s_background_color);
	GRect bounds = layer_get_frame(l);
	GPoint center = GPoint(bounds.size.w / 2, bounds.size.h / 2);

	graphics_context_set_antialiased(ctx, true);

	graphics_context_set_stroke_color(ctx, foreground_color);
	graphics_context_set_fill_color(ctx, foreground_color);
	graphics_context_set_stroke_width(ctx, 3);

	time_t ts = time(NULL);
	struct tm* now = localtime(&ts);

	GRect reduced_bounds = bounds;
	int arc_offset = PBL_IF_ROUND_ELSE(24, 18);
	reduced_bounds.origin.x += arc_offset;
	reduced_bounds.origin.y += arc_offset;
	reduced_bounds.size.w -= (arc_offset << 1);
	reduced_bounds.size.h -= (arc_offset << 1);

	// initially, angle is relative to top (wrong)
	int angle = TRIG_MAX_ANGLE * (now->tm_hour * 60 + now->tm_min) / 1440;
	// make 0 at the bottom
	angle = (angle + TRIG_MAX_ANGLE / 2) % TRIG_MAX_ANGLE;

	graphics_context_set_fill_color(ctx, s_complementary_color);

	int hand_length = MIN(reduced_bounds.size.h, reduced_bounds.size.w) / 2;
	int radial_inset = ((hand_length - 20) * inset_pct) / 100;

	if (angle < TRIG_MAX_ANGLE / 2) {
		// first draw the bottom half
		graphics_fill_radial(ctx, reduced_bounds, GOvalScaleModeFitCircle, radial_inset, TRIG_MAX_ANGLE / 2, TRIG_MAX_ANGLE);
		graphics_draw_arc(ctx, reduced_bounds, GOvalScaleModeFitCircle, TRIG_MAX_ANGLE / 2, TRIG_MAX_ANGLE);
		// then the rest
		graphics_fill_radial(ctx, reduced_bounds, GOvalScaleModeFitCircle, radial_inset, 0, angle);
		graphics_draw_arc(ctx, reduced_bounds, GOvalScaleModeFitCircle, 0, angle);
	} else {
		graphics_fill_radial(ctx, reduced_bounds, GOvalScaleModeFitCircle, radial_inset, TRIG_MAX_ANGLE / 2, angle);
		graphics_draw_arc(ctx, reduced_bounds, GOvalScaleModeFitCircle, TRIG_MAX_ANGLE / 2, angle);
	}

	graphics_context_set_stroke_width(ctx, 2);

	GPoint hand_end;
	hand_end.y = (-cos_lookup(angle) * hand_length / TRIG_MAX_RATIO) + center.y;
	hand_end.x = (sin_lookup(angle) * hand_length / TRIG_MAX_RATIO) + center.x;

	graphics_draw_line(ctx, center, hand_end);

	GPoint sm_end = GPoint(center.x, center.y + hand_length);
	GPoint sm_start = GPoint(center.x, sm_end.y - radial_inset);

	graphics_draw_line(ctx, sm_start, sm_end);
}
Exemplo n.º 5
0
static void battery_update_proc(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);

  // Find the width of the bar
  float percent = ((float)s_battery_level / 100.0F);
  int width = (int)(float)(percent * bounds.size.w);

  // Draw the background
  
  GColor bgcolor = GColorFromHEX(persist_read_int(MESSAGE_KEY_BackgroundColor));
  GColor batterycolor;
  
  //graphics_context_set_fill_color(ctx, GColorClear);
  //graphics_fill_rect(ctx, bounds, 0, GCornerNone);

  // Draw the bar
  int g = (255 * percent);
  int r = (255 * (1 - percent));
  int b = 0;
  int rgb = createRGB(r, g, b);

  if (s_battery_level == 100) {
    r = 85;
    g = 255;
  }
  if (s_battery_level == 50) {
    rgb = 0xFFAA00;
  }
  int x = persist_read_int(MESSAGE_KEY_Battery);
  APP_LOG(APP_LOG_LEVEL_INFO, "Battery Preference: %d", x);
  if (persist_read_int(MESSAGE_KEY_Battery) != 102) {
    APP_LOG(APP_LOG_LEVEL_INFO, "RGB");
    batterycolor = GColorFromHEX(rgb);
  } else {
    batterycolor = gcolor_legible_over(bgcolor);
  }

  PBL_IF_BW_ELSE(graphics_context_set_fill_color(ctx, batterycolor), graphics_context_set_fill_color(ctx, batterycolor));
  //APP_LOG(APP_LOG_LEVEL_INFO, GColorFromHEX(rgb));
  
  /*
  if (s_battery_level <= 20) {
    graphics_context_set_fill_color(ctx, PBL_IF_BW_ELSE(GColorBlack, GColorRed));
  } else if (s_battery_level == 100) {
    graphics_context_set_fill_color(ctx, PBL_IF_BW_ELSE(GColorBlack, GColorBrightGreen));
  }
  */
  
  GRect frame = grect_inset(bounds, GEdgeInsets(10));
  
  //graphics_context_set_fill_color(ctx, GColorBlack);
  
  PBL_IF_ROUND_ELSE(graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, 5,
                       DEG_TO_TRIGANGLE(125+((1-percent)*110)), DEG_TO_TRIGANGLE(235)), 
                    graphics_fill_rect(ctx, GRect(0, 0, width, bounds.size.h), 0, GCornerNone));
  
}
Exemplo n.º 6
0
static void action_performed_callback(ActionMenu *action_menu, const ActionMenuItem *action, void *context) {
  // An action was selected, determine which one
  s_color = *(GColor*)action_menu_item_get_action_data(action);

  // Update background color
  window_set_background_color(s_main_window, s_color);

  // Update legible foreground color
  s_visible_color = gcolor_legible_over(s_color);
  text_layer_set_text_color(s_label_layer, s_visible_color);
}
static void update_time(struct tm * tick_time) {
    s_hour = tick_time->tm_hour;
    s_min = tick_time->tm_min;
    s_sec = tick_time->tm_sec;

    //update the date using localized format
    text_layer_set_text_color(s_date_layer, gcolor_legible_over(background_color));
    static char date_buffer[20];
    strftime(date_buffer, sizeof(date_buffer), "%x", tick_time);
    text_layer_set_text(s_date_layer, date_buffer);

    layer_mark_dirty(s_layer);
}
Exemplo n.º 8
0
void draw_face_layer(Layer* l, GContext* ctx)
{
	GColor foreground_color = gcolor_legible_over(s_background_color);
	GRect bounds = layer_get_frame(l);
	GPoint center = GPoint(bounds.size.w / 2, bounds.size.h / 2);
	int height = bounds.size.h - 2;
	int width = bounds.size.w - 2;

	graphics_context_set_stroke_color(ctx, foreground_color);
	graphics_context_set_fill_color(ctx, s_complementary_color);
	graphics_context_set_text_color(ctx, foreground_color);

	graphics_draw_circle(ctx, center, 6);
	graphics_fill_circle(ctx, center, 5);

	// draw 4 ticks
	GRect zero_box;
	zero_box.size.w = 30;
	zero_box.size.h = 12;
	zero_box.origin.x = width / 2 - 12;
	zero_box.origin.y = height - 20;
	graphics_draw_text(ctx, "0", s_time_font, zero_box, GTextOverflowModeFill, GTextAlignmentCenter, NULL);
	zero_box.origin.y = height / 2 - 12;
	zero_box.origin.x = 2;
	graphics_draw_text(ctx, "6", s_time_font, zero_box, GTextOverflowModeFill, GTextAlignmentLeft, NULL);
	zero_box.origin.x = width / 2 - 10;
	zero_box.origin.y = 0;
	graphics_draw_text(ctx, "12", s_time_font, zero_box, GTextOverflowModeFill, GTextAlignmentCenter, NULL);
	zero_box.origin.y = height / 2 - 10;
	zero_box.origin.x = width - 30;
	graphics_draw_text(ctx, "18", s_time_font, zero_box, GTextOverflowModeFill, GTextAlignmentRight, NULL);

	graphics_context_set_fill_color(ctx, s_complementary_color);
	int circle_inset = PBL_IF_ROUND_ELSE(6, 2);
	int circle_radius = MIN(width / 2 - circle_inset, height / 2 - circle_inset);
	for (int i = 0; i < 24; ++i) {
		if (i % 6 == 0) {
			continue;
		}
		int angle = i * TRIG_MAX_ANGLE / 24;

		int y = (-cos_lookup(angle) * circle_radius / TRIG_MAX_RATIO);
		int x = (sin_lookup(angle) * circle_radius / TRIG_MAX_RATIO);

		GPoint pt = GPoint(x + center.x, y + center.y);
		graphics_fill_circle(ctx, pt, 2);
	}
}
Exemplo n.º 9
0
static void setColors(int color, bool invert){
  GColor fgcolor = GColorWhite;
  GColor bgcolor = GColorBlack;
  GColor tmp;
#ifdef PBL_COLOR
  fgcolor = GColorFromHEX(color);
  bgcolor = gcolor_legible_over(fgcolor);
#endif
  if (invert){
    tmp = bgcolor;
    bgcolor = fgcolor;
    fgcolor = tmp;
  }
  window_set_background_color(window_time, bgcolor);
  text_layer_set_background_color(time_layer, bgcolor);
  text_layer_set_text_color(time_layer, fgcolor);
}
static void update_time(struct tm *tick_time) {
	s_hour = tick_time->tm_hour;
	s_min = tick_time->tm_min;
	s_sec = tick_time->tm_sec;

	static char buffer[] = "00";

	//update minutes
	strftime(buffer, sizeof("00"), "%M", tick_time);
	text_layer_set_text(s_time_layer, buffer);

	//update date
	text_layer_set_text_color(s_date_layer, gcolor_legible_over(background_color));
	static char date_buffer[20];
	strftime(date_buffer, sizeof(date_buffer), "%x", tick_time);
	text_layer_set_text(s_date_layer, date_buffer);

	layer_mark_dirty(s_layer);
}
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
	APP_LOG(APP_LOG_LEVEL_DEBUG, "inbox received handler");
	Tuple *background_color_t = dict_find(iter, KEY_BACKGROUND_COLOR);
	Tuple *one_t = dict_find(iter, KEY_BLOCK_ONE_COLOR);
	Tuple *two_t = dict_find(iter, KEY_BLOCK_TWO_COLOR);
	Tuple *three_t = dict_find(iter, KEY_BLOCK_THREE_COLOR);
	Tuple *four_t = dict_find(iter, KEY_BLOCK_FOUR_COLOR);
	Tuple *five_t = dict_find(iter, KEY_BLOCK_FIVE_COLOR);
	Tuple *six_t = dict_find(iter, KEY_BLOCK_SIX_COLOR);
	Tuple *seven_t = dict_find(iter, KEY_BLOCK_SEVEN_COLOR);
	Tuple *eight_t = dict_find(iter, KEY_BLOCK_EIGHT_COLOR);
	Tuple *nine_t = dict_find(iter, KEY_BLOCK_NINE_COLOR);
	Tuple *ten_t = dict_find(iter, KEY_BLOCK_TEN_COLOR);
	Tuple *eleven_t = dict_find(iter, KEY_BLOCK_ELEVEN_COLOR);
	Tuple *twelve_t = dict_find(iter, KEY_BLOCK_TWELVE_COLOR);

	Tuple *temp_t = dict_find(iter, KEY_TEMPERATURE);
	Tuple *conditions_t = dict_find(iter, KEY_CONDITIONS);

	Tuple *degreeOption_t = dict_find(iter, KEY_DEGREEOPTION);

	//Store incoming information
	static char temperature_buffer[8];
	static char conditions_buffer[32];
	static char weather_layer_buffer[42];

	if (degreeOption_t) {
		degreeOption = degreeOption_t->value->uint32;
		APP_LOG(APP_LOG_LEVEL_DEBUG, "degree Option : %d", degreeOption);
		persist_write_int(KEY_DEGREEOPTION, degreeOption);
	}

	if (temp_t) {
		int kelvin = (int) temp_t->value->int32;
		if (degreeOption == 0) {
			//celsius
			int celsius = kelvin - 273.15;
			snprintf(temperature_buffer, sizeof(temperature_buffer), "%d\u00B0", (int) celsius);
			APP_LOG(APP_LOG_LEVEL_DEBUG, "Degree option is Celsius: %d", degreeOption);
		} else {
			//fahrenheit
			int fahrenheit = (kelvin - 273.15) * 1.8 + 32;
			snprintf(temperature_buffer, sizeof(temperature_buffer), "%d\u00B0", (int) fahrenheit);
			APP_LOG(APP_LOG_LEVEL_DEBUG, "Degree option is Fahrenheit: %d", degreeOption);
		}
	}

	if (conditions_t) {
		snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", conditions_t->value->cstring);
	}

	if (conditions_t && temp_t) {
		snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s, %s", temperature_buffer, conditions_buffer);
		text_layer_set_text_color(s_weather_layer, gcolor_legible_over(background_color));
		text_layer_set_text(s_weather_layer, weather_layer_buffer);
	}

	if (background_color_t) {
		int bc = background_color_t->value->int32;
		if (bc == 0) { //quick fix so that black colour persists
			bc++;
		}
		persist_write_int(KEY_BACKGROUND_COLOR, bc);
		background_color = GColorFromHEX(bc);
		window_set_background_color(window, background_color);
		APP_LOG(APP_LOG_LEVEL_DEBUG, "background color %d", bc);
	}

	if (one_t) {
		int c = one_t->value->int32;
		if (c == 0) { //quick fix so that black colour persists
			c++;
		}
		persist_write_int(KEY_BLOCK_ONE_COLOR, c);
		blockOneColor = GColorFromHEX(c);
	}

	if (two_t) {
		int c = two_t->value->int32;
		if (c == 0) { //quick fix so that black colour persists
			c++;
		}
		persist_write_int(KEY_BLOCK_TWO_COLOR, c);
		blockTwoColor = GColorFromHEX(c);
	}

	if (three_t) {
		int c = three_t->value->int32;
		if (c == 0) { //quick fix so that black colour persists
			c++;
		}
		persist_write_int(KEY_BLOCK_THREE_COLOR, c);
		blockThreeColor = GColorFromHEX(c);
	}

	if (four_t) { 
		int c = four_t->value->int32;
		if (c == 0) { //quick fix so that black colour persists
			c++;
		}
		persist_write_int(KEY_BLOCK_FOUR_COLOR, c);
		blockFourColor = GColorFromHEX(c);
	}

	if (five_t) {
		int c = five_t->value->int32;
		if (c == 0) { //quick fix so that black colour persists
			c++;
		}
		persist_write_int(KEY_BLOCK_FIVE_COLOR, c);
		blockFiveColor = GColorFromHEX(c);
	}

	if (six_t) { 
		int c = six_t->value->int32;
		if (c == 0) { //quick fix so that black colour persists
			c++;
		}
		persist_write_int(KEY_BLOCK_SIX_COLOR, c);
		blockSixColor = GColorFromHEX(c);
	}

	if (seven_t) {
		int c = seven_t->value->int32;
		if (c == 0) { //quick fix so that black colour persists
			c++;
		}
		persist_write_int(KEY_BLOCK_SEVEN_COLOR, c);
		blockSevenColor = GColorFromHEX(c);
	}

	if (eight_t) {
		int c = eight_t->value->int32;
		if (c == 0) { //quick fix so that black colour persists
			c++;
		}
		persist_write_int(KEY_BLOCK_EIGHT_COLOR, c);
		blockEightColor = GColorFromHEX(c);
	}

	if (nine_t) {
		int c = nine_t->value->int32;
		if (c == 0) { //quick fix so that black colour persists
			c++;
		}
		persist_write_int(KEY_BLOCK_NINE_COLOR, c);
		blockNineColor = GColorFromHEX(c);
		APP_LOG(APP_LOG_LEVEL_DEBUG, "nine color %d", c);
	}

	if (ten_t) {
		int c = ten_t->value->int32;
		if (c == 0) { //quick fix so that black colour persists
			c++;
		}
		persist_write_int(KEY_BLOCK_TEN_COLOR, c);
		blockTenColor = GColorFromHEX(c);
		APP_LOG(APP_LOG_LEVEL_DEBUG, "ten color %d", c);
	}

	if (eleven_t) {
		int c = eleven_t->value->int32;
		if (c == 0) { //quick fix so that black colour persists
			c++;
		}
		persist_write_int(KEY_BLOCK_ELEVEN_COLOR, c);
		blockElevenColor = GColorFromHEX(c);
		APP_LOG(APP_LOG_LEVEL_DEBUG, "eleven color %d", c);
	}

	if (twelve_t) {
		int c = twelve_t->value->int32;
		if (c == 0) { //quick fix so that black colour persists
			c++;
		}
		persist_write_int(KEY_BLOCK_TWELVE_COLOR, c);
		blockTwelveColor = GColorFromHEX(c);
	}

	time_t start_time = time(NULL);
	update_time(localtime(&start_time));
}
Exemplo n.º 12
0
static void charge_layer_update_callback(Layer *layer, GContext *ctx) {
  BatteryChargeState batChargeState = battery_state_service_peek();
  GColor charge_color = GColorClear;

  // Select color for battery charge
  if (batChargeState.charge_percent >= 60) {
    charge_color = GColorGreen;
  } else if (batChargeState.charge_percent >= 25) {
    charge_color = GColorChromeYellow;
  } else {
    charge_color = GColorRed;
  }

  // Fill the battery frame
  graphics_context_set_fill_color(ctx, GColorBlack);
  gpath_draw_filled(ctx, s_bat_frame_path_ptr);

  // Draw battery charge
  graphics_context_set_fill_color(ctx, charge_color);
  int h = (100 - batChargeState.charge_percent) / 5 + 1;
  graphics_fill_rect(ctx, GRect(3, h, 8, 21 - h), 0, GCornerNone);

  // Clear overwritten part (outside of battery)
  graphics_context_set_stroke_color(ctx, GColorClear);
  graphics_draw_pixel(ctx, GPoint(3, 1));
  graphics_draw_pixel(ctx, GPoint(10, 1));

  // Stroke the battery frame
  graphics_context_set_stroke_color(ctx, (conf.fiboDisplay == FiboDispZoomed) ? s_legibleColor : gcolor_legible_over(conf.backgroundColor));
  gpath_draw_outline(ctx, s_bat_frame_path_ptr);

  graphics_context_set_compositing_mode(ctx, GCompOpSet);
  if (batChargeState.is_charging) {
    // Draw charging icon
    graphics_draw_bitmap_in_rect(ctx, s_charging_image, gbitmap_get_bounds(s_charging_image));
  } else if (batChargeState.is_plugged) {
    // Draw plugged icon
    graphics_draw_bitmap_in_rect(ctx, s_plugged_image, gbitmap_get_bounds(s_plugged_image));
  }
}
Exemplo n.º 13
0
static void set_layer1_color_and_text(int color_layer){
  GColor square_color = GColorFromHEX(color_layer);
  text_layer_set_background_color(lower_text_layer, square_color);
  text_layer_set_text_color(weekday_text, gcolor_legible_over(square_color));
  
}
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "inbox received handler");
    Tuple *top_bar_color_t = dict_find(iter, KEY_TOP_BAR_COLOR);
    Tuple *middle_bar_color_t = dict_find(iter, KEY_MIDDLE_BAR_COLOR);
    Tuple *bottom_bar_color_t = dict_find(iter, KEY_BOTTOM_BAR_COLOR);
    Tuple *background_color_t = dict_find(iter, KEY_BACKGROUND_COLOR);

    Tuple *temp_t = dict_find(iter, KEY_TEMPERATURE);
    Tuple *conditions_t = dict_find(iter, KEY_CONDITIONS);

    Tuple *degreeOption_t = dict_find(iter, KEY_DEGREEOPTION);

    //Store incoming information
    static char temperature_buffer[8];
    static char conditions_buffer[32];
    static char weather_layer_buffer[42];

    if (degreeOption_t) {
        degreeOption = degreeOption_t->value->uint32;
        APP_LOG(APP_LOG_LEVEL_DEBUG, "degree Option : %d", degreeOption);
        persist_write_int(KEY_DEGREEOPTION, degreeOption);
    }

    if (temp_t) {
        int kelvin = (int) temp_t->value->int32;
        if (degreeOption == 0) {
            //celsius
            int celsius = kelvin - 273.15;
            snprintf(temperature_buffer, sizeof(temperature_buffer), "%d\u00B0", (int) celsius);
            APP_LOG(APP_LOG_LEVEL_DEBUG, "Degree option is Celsius: %d", degreeOption);
        } else {
            //fahrenheit
            int fahrenheit = (kelvin - 273.15) * 1.8 + 32;
            snprintf(temperature_buffer, sizeof(temperature_buffer), "%d\u00B0", (int) fahrenheit);
            APP_LOG(APP_LOG_LEVEL_DEBUG, "Degree option is Fahrenheit: %d", degreeOption);
        }
    }

    if (conditions_t) {
        snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", conditions_t->value->cstring);
    }

    if (conditions_t && temp_t) {
        snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s, %s", temperature_buffer, conditions_buffer);
        text_layer_set_text_color(s_weather_layer, gcolor_legible_over(background_color));
        text_layer_set_text(s_weather_layer, weather_layer_buffer);
    }

    if (top_bar_color_t) {
        int top_bar_color = top_bar_color_t->value->int32;
        if (top_bar_color == 0) { //quick fix so that black colour persists
            top_bar_color++;
        }

        persist_write_int(KEY_TOP_BAR_COLOR, top_bar_color);

        //set_background_and_text_color(background_color);
        s_top_bar_color = GColorFromHEX(top_bar_color);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "top bar color:  %d", top_bar_color);
    }

    if (middle_bar_color_t) {
        int middle_bar_color = middle_bar_color_t->value->int32;
        if (middle_bar_color == 0) { //quick fix so that black colour persists
            middle_bar_color++;
        }

        persist_write_int(KEY_MIDDLE_BAR_COLOR, middle_bar_color);

        s_middle_bar_color = GColorFromHEX(middle_bar_color);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "middle bar color:  %d", middle_bar_color);
    }

    if (bottom_bar_color_t) {
        int bottom_bar_color = bottom_bar_color_t->value->int32;
        if (bottom_bar_color == 0) { //quick fix so that black colour persists
            bottom_bar_color++;
        }

        persist_write_int(KEY_BOTTOM_BAR_COLOR, bottom_bar_color);

        s_bottom_bar_color = GColorFromHEX(bottom_bar_color);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "bottom bar color:  %d", bottom_bar_color);
    }

    if (background_color_t) {
        int background_color = background_color_t->value->int32;
        if (background_color == 0) { //quick fix so that black colour persists
            background_color++;
        }

        persist_write_int(KEY_BACKGROUND_COLOR, background_color);

        APP_LOG(APP_LOG_LEVEL_DEBUG, "background color: %d", background_color);

        set_background_and_text_color(background_color);
    }

    time_t start_time = time(NULL);
    update_time(localtime(&start_time));

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

    s_layer = layer_create(layer_get_bounds(window_get_root_layer(window)));
    layer_add_child(window_get_root_layer(window), s_layer);
    layer_set_update_proc(s_layer, draw_watchface);

    uint16_t vert_padding = (bounds.size.h - ((NUM_BARS - 1)*PADDING) - (NUM_BARS*HEIGHT)) / 2;
    uint16_t width = bounds.size.w - (2 * PADDING); //this is 120 on basalt

    //create the unary ticks image
    s_unary_ticks_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_UNARY_TICKS);
    s_unary_ticks_layer = bitmap_layer_create(GRect(PADDING,vert_padding,width + 1,HEIGHT));
    bitmap_layer_set_background_color(s_unary_ticks_layer, GColorClear);
    bitmap_layer_set_bitmap(s_unary_ticks_layer, s_unary_ticks_bitmap);
    bitmap_layer_set_compositing_mode(s_unary_ticks_layer, GCompOpSet);
    layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_unary_ticks_layer));

    //create the ternary ticks image and layer for minutes
    s_ternary_ticks_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_TERNARY_TICKS);
    s_ternary_ticks_layer_minutes = bitmap_layer_create(GRect(PADDING, vert_padding + PADDING + HEIGHT, width + 1, HEIGHT));
    bitmap_layer_set_background_color(s_ternary_ticks_layer_minutes, GColorClear);
    bitmap_layer_set_bitmap(s_ternary_ticks_layer_minutes, s_ternary_ticks_bitmap);
    bitmap_layer_set_compositing_mode(s_ternary_ticks_layer_minutes, GCompOpSet);
    layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_ternary_ticks_layer_minutes));

    //create the ternary ticks layer for seconds
    s_ternary_ticks_layer_seconds = bitmap_layer_create(GRect(PADDING, vert_padding + (2*PADDING) + (2*HEIGHT), width + 1, HEIGHT));
    bitmap_layer_set_background_color(s_ternary_ticks_layer_seconds, GColorClear);
    bitmap_layer_set_bitmap(s_ternary_ticks_layer_seconds, s_ternary_ticks_bitmap);
    bitmap_layer_set_compositing_mode(s_ternary_ticks_layer_seconds, GCompOpSet);
    layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_ternary_ticks_layer_seconds));

    if (persist_read_int(KEY_TOP_BAR_COLOR)) {
        s_top_bar_color = GColorFromHEX(persist_read_int(KEY_TOP_BAR_COLOR));
        ///	set_background_and_text_color(background_color);
    } else {
        s_top_bar_color = GColorRed;
    }

    if (persist_read_int(KEY_MIDDLE_BAR_COLOR)) {
        s_middle_bar_color = GColorFromHEX(persist_read_int(KEY_MIDDLE_BAR_COLOR));
    } else {
        s_middle_bar_color = GColorGreen;
    }

    if (persist_read_int(KEY_BOTTOM_BAR_COLOR)) {
        s_bottom_bar_color = GColorFromHEX(persist_read_int(KEY_BOTTOM_BAR_COLOR));
    } else {
        s_bottom_bar_color = GColorBlue;
    }

    if (persist_read_int(KEY_BACKGROUND_COLOR)) {
        set_background_and_text_color(persist_read_int(KEY_BACKGROUND_COLOR));
    } else {
        set_background_and_text_color(0xFFFFFF);
    }

    if (persist_read_int(KEY_DEGREEOPTION)) {
        degreeOption = persist_read_int(KEY_DEGREEOPTION);
    } else {
        degreeOption = 0;
    }

    s_weather_layer = text_layer_create(GRect(0,152, 144, 14));
    text_layer_set_font(s_weather_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
    text_layer_set_background_color(s_weather_layer, GColorClear);
    text_layer_set_text_color(s_weather_layer, gcolor_legible_over(background_color));
    text_layer_set_text_alignment(s_weather_layer, GTextAlignmentRight);
    text_layer_set_text(s_weather_layer, "Loading...");
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer));

    s_bluetooth_icon_layer = layer_create(GRect(0,0,30,30));
    layer_set_update_proc(s_bluetooth_icon_layer, bluetooth_update_proc);
    bluetooth_path = gpath_create(&BLUETOOTH_INFO);
    layer_add_child(window_get_root_layer(window), s_bluetooth_icon_layer);

    //show the correct state of the bluetooth connection from the start
#ifdef PBL_SDK_2
    bluetooth_callback(bluetooth_connection_service_peek());
#elif PBL_SDK_3
    bluetooth_callback(connection_service_peek_pebble_app_connection());
#endif

    s_date_layer = text_layer_create(GRect(0,0,144,14));
    text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
    text_layer_set_text_color(s_date_layer, gcolor_legible_over(background_color));
    text_layer_set_background_color(s_date_layer, GColorClear);
    text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight);
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));

}
static void draw_watchface(Layer *layer, GContext *ctx) {

	uint8_t cur_hour = s_hour % 12;
	if (cur_hour == 0) {
		cur_hour = 12;
	}

	GRect f = layer_get_frame((Layer *) s_time_layer);
	int shift = 5;
	switch (cur_hour) {
		case 12:
			f.origin.x = 60;
			f.origin.y = 16 - shift;
			text_layer_set_text_color(s_time_layer, gcolor_legible_over(blockTwelveColor));
			break;
		case 1:
			f.origin.x = 80;
			f.origin.y = 40 - shift;
			text_layer_set_text_color(s_time_layer, gcolor_legible_over(blockOneColor));
			break;
		case 2:
			f.origin.x = 104;
			f.origin.y = 48 - shift;
			text_layer_set_text_color(s_time_layer, gcolor_legible_over(blockTwoColor));
			break;
		case 3:
			f.origin.x = 112;
			f.origin.y = 72 - shift;
			text_layer_set_text_color(s_time_layer, gcolor_legible_over(blockThreeColor));
			break;
		case 4:
			f.origin.x = 104;
			f.origin.y = 96 - shift;
			text_layer_set_text_color(s_time_layer, gcolor_legible_over(blockFourColor));
			break;
		case 5:
			f.origin.x = 80;
			f.origin.y = 104 - shift;
			text_layer_set_text_color(s_time_layer, gcolor_legible_over(blockFiveColor));
			break;
		case 6:
			f.origin.x = 60;
			f.origin.y = 128 - shift;
			text_layer_set_text_color(s_time_layer, gcolor_legible_over(blockSixColor));
			break;
		case 7:
			f.origin.x = 40;
			f.origin.y = 104 - shift;
			text_layer_set_text_color(s_time_layer, gcolor_legible_over(blockSevenColor));
			break;
		case 8:
			f.origin.x = 16;
			f.origin.y = 96 - shift;
			text_layer_set_text_color(s_time_layer, gcolor_legible_over(blockEightColor));
			break;
		case 9:
			f.origin.x = 8;
			f.origin.y = 72 - shift;
			text_layer_set_text_color(s_time_layer, gcolor_legible_over(blockNineColor));
			break;
		case 10:
			f.origin.x = 16;
			f.origin.y = 48 - shift;
			text_layer_set_text_color(s_time_layer, gcolor_legible_over(blockTenColor));
			break;
		case 11:
			f.origin.x = 40;
			f.origin.y = 40 - shift;
			text_layer_set_text_color(s_time_layer, gcolor_legible_over(blockElevenColor));
			break;
		default :
			APP_LOG(APP_LOG_LEVEL_DEBUG, "invalid hour: %d", cur_hour);
	}

	layer_set_frame((Layer *) s_time_layer, f);

	switch (cur_hour) {
		case 11:
			graphics_context_set_fill_color(ctx, blockElevenColor);
			graphics_fill_rect(ctx, eleven, 0 , 0);
		case 10:
			graphics_context_set_fill_color(ctx, blockTenColor);
			graphics_fill_rect(ctx, ten, 0 , 0);
		case 9:
			graphics_context_set_fill_color(ctx, blockNineColor);
			graphics_fill_rect(ctx, nine, 0 , 0);
		case 8:
			graphics_context_set_fill_color(ctx, blockEightColor);
			graphics_fill_rect(ctx, eight, 0 , 0);
		case 7:
			graphics_context_set_fill_color(ctx, blockSevenColor);
			graphics_fill_rect(ctx, seven, 0 , 0);
		case 6:
			graphics_context_set_fill_color(ctx, blockSixColor);
			graphics_fill_rect(ctx, six, 0 , 0);
		case 5:
			graphics_context_set_fill_color(ctx, blockFiveColor);
			graphics_fill_rect(ctx, five, 0 , 0);
		case 4:
			graphics_context_set_fill_color(ctx, blockFourColor);
			graphics_fill_rect(ctx, four, 0 , 0);
		case 3:
			graphics_context_set_fill_color(ctx, blockThreeColor);
			graphics_fill_rect(ctx, three, 0 , 0);
		case 2:
			graphics_context_set_fill_color(ctx, blockTwoColor);
			graphics_fill_rect(ctx, two, 0, 0);
		case 1:
			graphics_context_set_fill_color(ctx, blockOneColor);
			graphics_fill_rect(ctx, one, 0, 0);
		case 12:
			graphics_context_set_fill_color(ctx, blockTwelveColor);
			graphics_fill_rect(ctx, twelve, 0 , 0);
			break;
		default :
			APP_LOG(APP_LOG_LEVEL_DEBUG, "invalid hour: %d", cur_hour);
	}

	//draw the blocks
	graphics_context_set_stroke_color(ctx, gcolor_legible_over(background_color));
	graphics_context_set_stroke_width(ctx, 3);

	graphics_draw_rect(ctx, one);
	graphics_draw_rect(ctx, two);
	graphics_draw_rect(ctx, three);
	graphics_draw_rect(ctx, four);
	graphics_draw_rect(ctx, five);
	graphics_draw_rect(ctx, six);
	graphics_draw_rect(ctx, seven);
	graphics_draw_rect(ctx, eight);
	graphics_draw_rect(ctx, nine);
	graphics_draw_rect(ctx, ten);
	graphics_draw_rect(ctx, eleven);
	graphics_draw_rect(ctx, twelve);

}
Exemplo n.º 17
0
static void fibo_layer_update_callback(Layer *layer, GContext *ctx) {
  GColor fill_color[4]; // None, Hour, Minute, Hr+Min
  static int8_t h, m, fc1L, fc1R, fc2, fc3, fc5;

  fill_color[0] = conf.noneColor;
  fill_color[1] = conf.hourColor;
  fill_color[2] = conf.minuteColor;
  fill_color[3] = conf.hourMinuteColor;

  /* Only get new random combination on time change */
  if (h != s_curr_hour) {
    h = s_curr_hour;
    m = s_curr_min / 5; // Divide by five since only values from 1-12 can be displayed
    fc1L = fc1R = fc2 = fc3 = fc5 = 0;
    get_fibo_colors(h, m, &fc1L, &fc1R, &fc2, &fc3, &fc5);
  } else if (m != s_curr_min / 5) {
    m = s_curr_min / 5; // Divide by five since only values from 1-12 can be displayed
    fc1L = fc1R = fc2 = fc3 = fc5 = 0;
    get_fibo_colors(h, m, &fc1L, &fc1R, &fc2, &fc3, &fc5);
  }
    
#if ACTIVATE_COLOR_LOOP
{
  static int8_t cnt = 0;
  fc5 = cnt;
  cnt = (cnt == 3) ? 0 : cnt + 1;
}
#endif
  
  // Draw the time boxes
  graphics_context_set_fill_color(ctx, fill_color[fc3]);
  graphics_fill_rect(ctx, fibo[conf.fiboDisplay].s_3x3_square, 0, GCornerNone);
  graphics_context_set_fill_color(ctx, fill_color[fc2]);
  graphics_fill_rect(ctx, fibo[conf.fiboDisplay].s_2x2_square, 0, GCornerNone);
  graphics_context_set_fill_color(ctx, fill_color[fc1L]);
  graphics_fill_rect(ctx, fibo[conf.fiboDisplay].s_1x1L_square, 0, GCornerNone);
  graphics_context_set_fill_color(ctx, fill_color[fc1R]);
  graphics_fill_rect(ctx, fibo[conf.fiboDisplay].s_1x1R_square, 0, GCornerNone);
  graphics_context_set_fill_color(ctx, fill_color[fc5]);
  
  s_legibleColor = gcolor_legible_over(fill_color[fc5]); // Also used for battery frame
  
  text_layer_set_text_color(s_time_layer, conf.legibleText ? s_legibleColor: conf.timeColor);
  text_layer_set_text_color(s_date_layer, conf.legibleText ? s_legibleColor: conf.timeColor);
  text_layer_set_text_color(s_week_layer, conf.legibleText ? s_legibleColor: conf.timeColor);
  graphics_fill_rect(ctx, fibo[conf.fiboDisplay].s_5x5_square, 0, GCornerNone);

  // Draw the grid
  graphics_context_set_stroke_color(ctx, conf.gridColor);
  graphics_context_set_stroke_width(ctx, 3);
  graphics_draw_rect(ctx, fibo[conf.fiboDisplay].s_3x3_square);
  graphics_draw_rect(ctx, fibo[conf.fiboDisplay].s_2x2_square);
  graphics_draw_rect(ctx, fibo[conf.fiboDisplay].s_1x1L_square);
  graphics_draw_rect(ctx, fibo[conf.fiboDisplay].s_1x1R_square);
  graphics_draw_rect(ctx, fibo[conf.fiboDisplay].s_5x5_square);

  // Draw the grid dots
  graphics_context_set_stroke_color(ctx, conf.dotColor);
  for (int16_t y = fibo[conf.fiboDisplay].s_outline.origin.y + 2;
       y <= fibo[conf.fiboDisplay].s_outline.origin.y + fibo[conf.fiboDisplay].s_outline.size.h;
       y += fibo[conf.fiboDisplay].s_1x1L_square.size.h - 1) {
    for (int16_t x = fibo[conf.fiboDisplay].s_outline.origin.x + 2;
         x <= fibo[conf.fiboDisplay].s_outline.origin.x + fibo[conf.fiboDisplay].s_outline.size.w;
         x += fibo[conf.fiboDisplay].s_1x1L_square.size.w - 1) {
      graphics_draw_pixel(ctx, GPoint(x, y));
    }
  }

  // Draw the outline
  graphics_context_set_stroke_color(ctx, conf.outlineColor);
  graphics_context_set_stroke_width(ctx, 1);
  graphics_draw_rect(ctx, fibo[conf.fiboDisplay].s_outline);
}