示例#1
0
文件: main.c 项目: musl/DataFace
/*:
 * Handle window loading.
 */
static void load_cb(Window *window) {

	// Right Margin
	static int m = 4;
	// Font Size
	static int s = 31;
	// First Row Offset
	static int o = 0;
	// Row Top Padding
	static int p = 2;

	// Screen Size
	static int w = 144;
	static int h = 168;

	// Load resources we'll have to destroy later.
	s_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TARGA_MS_31));

	// NO DESCENDERS FOR YOU
#define make_row(x) text_layer_create(GRect(m, (x - 1) * (s + p) + o, w, s))

	// Window Background
	//
	s_bg_layer = bitmap_layer_create(GRect(0, 0, w, h));
	bitmap_layer_set_background_color(s_bg_layer, GColorBlack);
	layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bg_layer));

	s_cldr_layer = make_row(1);
	text_layer_set_background_color(s_cldr_layer, GColorClear);
	text_layer_set_text_color(s_cldr_layer, theme_tertiary);
	text_layer_set_font(s_cldr_layer, s_font);
	text_layer_set_text_alignment(s_cldr_layer, GTextAlignmentLeft);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_cldr_layer));

	s_date_layer = make_row(2);
	text_layer_set_background_color(s_date_layer, GColorClear);
	text_layer_set_text_color(s_date_layer, theme_secondary);
	text_layer_set_font(s_date_layer, s_font);
	text_layer_set_text_alignment(s_date_layer, GTextAlignmentLeft);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));

	s_time_layer = make_row(3);
	text_layer_set_background_color(s_time_layer, GColorClear);
	text_layer_set_text_color(s_time_layer, theme_primary);
	text_layer_set_font(s_time_layer, s_font);
	text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));

	s_wthr_layer = make_row(4);
	text_layer_set_background_color(s_wthr_layer, GColorClear);
	text_layer_set_text_color(s_wthr_layer, theme_info);
	text_layer_set_font(s_wthr_layer, s_font);
	text_layer_set_text_alignment(s_wthr_layer, GTextAlignmentLeft);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_wthr_layer));

	s_blth_layer = make_row(5);
	text_layer_set_background_color(s_blth_layer, GColorClear);
	text_layer_set_text_color(s_blth_layer, theme_tertiary);
	text_layer_set_font(s_blth_layer, s_font);
	text_layer_set_text_alignment(s_blth_layer, GTextAlignmentLeft);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_blth_layer));

	s_batt_layer = make_row(5);
	text_layer_set_background_color(s_batt_layer, GColorClear);
	text_layer_set_text_color(s_batt_layer, theme_tertiary);
	text_layer_set_font(s_batt_layer, s_font);
	text_layer_set_text_alignment(s_batt_layer, GTextAlignmentLeft);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_batt_layer));

#undef make_row

}
示例#2
0
void handle_init(AppContextRef ctx) {
  (void)ctx;

  window_init(&window, "Brains Watch");
  window_stack_push(&window, true);

  resource_init_current_app(&APP_RESOURCES);

//    rotbmp_pair_init_container(RESOURCE_ID_IMAGE_PANDA_WHITE, RESOURCE_ID_IMAGE_PANDA_BLACK, &bitmap_container);


  // Set up a layer for the static watch face background
  bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container);
  layer_add_child(&window.layer, &background_image_container.layer.layer);


dice = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_VISITOR_16));

  text_layer_init(&date_layer, GRect(53, 105, 40, 40));
  text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter);
  text_layer_set_text_color(&date_layer, GColorWhite);
  text_layer_set_background_color(&date_layer, GColorClear);
  text_layer_set_font(&date_layer, dice);
  layer_add_child(&window.layer, &date_layer.layer);

 PblTm ti;
 get_time(&ti);
  
 string_format_time(date_text, sizeof(date_text), "%d", &ti);
 text_layer_set_text(&date_layer, date_text);




  // Set up a layer for the hour hand
  rotbmp_init_container(RESOURCE_ID_IMAGE_HOUR_HAND, &hour_hand_image_container);

    //  hour_hand_image_container.layer.compositing_mode = GCompOpClear;

  rot_bitmap_set_src_ic(&hour_hand_image_container.layer, GPoint(3, 42));

  layer_add_child(&window.layer, &hour_hand_image_container.layer.layer);


  // Set up a layer for the minute hand
  rotbmp_init_container(RESOURCE_ID_IMAGE_MINUTE_HAND, &minute_hand_image_container);

 // minute_hand_image_container.layer.compositing_mode = GCompOpClear;

  rot_bitmap_set_src_ic(&minute_hand_image_container.layer, GPoint(3, 58));

  layer_add_child(&window.layer, &minute_hand_image_container.layer.layer);






  update_hand_positions();


  // Setup the black and white circle in the centre of the watch face
  // (We use a bitmap rather than just drawing it because it means not having
  // to stuff around with working out the circle center etc.)
  rotbmp_pair_init_container(RESOURCE_ID_IMAGE_CENTER_CIRCLE_WHITE, RESOURCE_ID_IMAGE_CENTER_CIRCLE_BLACK,
			     &center_circle_image_container);

  // TODO: Do this properly with a GRect().
  // (144 = screen width, 168 = screen height)
  center_circle_image_container.layer.layer.frame.origin.x = (144/2) - (center_circle_image_container.layer.layer.frame.size.w/2);
  center_circle_image_container.layer.layer.frame.origin.y = (168/2) - (center_circle_image_container.layer.layer.frame.size.h/2);


  layer_add_child(&window.layer, &center_circle_image_container.layer.layer);

  layer_init(&second_display_layer, window.layer.frame);
  second_display_layer.update_proc = &second_display_layer_update_callback;
  layer_add_child(&window.layer, &second_display_layer);

}
/**
 * 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));
  
}
void window_load(Window *window) {
    persist_read_string(1, saved_passcode, 50);
    
    Layer *window_layer = window_get_root_layer(window);
    
    number_0 = number_layer_init(GRect(124, 0, 20, 15), "0");
    layer_add_child(window_layer, text_layer_get_layer(number_0));
    
    number_1 = number_layer_init(GRect(124, 15, 20, 15), "1");
    layer_add_child(window_layer, text_layer_get_layer(number_1));
    
    number_2 = number_layer_init(GRect(124, 30, 20, 15), "2");
    layer_add_child(window_layer, text_layer_get_layer(number_2));
    
    number_3 = number_layer_init(GRect(124, 45, 20, 15), "3");
    layer_add_child(window_layer, text_layer_get_layer(number_3));
    
    number_4 = number_layer_init(GRect(124, 60, 20, 15), "4");
    layer_add_child(window_layer, text_layer_get_layer(number_4));
    
    number_5 = number_layer_init(GRect(124, 75, 20, 15), "5");
    layer_add_child(window_layer, text_layer_get_layer(number_5));
    
    number_6 = number_layer_init(GRect(124, 90, 20, 15), "6");
    layer_add_child(window_layer, text_layer_get_layer(number_6));
    
    number_7 = number_layer_init(GRect(124, 105, 20, 15), "7");
    layer_add_child(window_layer, text_layer_get_layer(number_7));
    
    number_8 = number_layer_init(GRect(124, 120, 20, 15), "8");
    layer_add_child(window_layer, text_layer_get_layer(number_8));
    
    number_9 = number_layer_init(GRect(124, 135, 20, 17), "9");
    layer_add_child(window_layer, text_layer_get_layer(number_9));
    
    status_text_layer = text_layer_create(GRect(0, 90, 124, 40));
    text_layer_set_text_color(status_text_layer, GColorBlack);
    text_layer_set_font(status_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
    text_layer_set_text_alignment(status_text_layer, GTextAlignmentCenter);
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(status_text_layer));
    
    selected_number = 0;
    cursor_position = 0;
    
    circle_layer = layer_create(GRect(0, 20, 144, 100));
    layer_set_update_proc(circle_layer, circle_proc);
    layer_add_child(window_layer, circle_layer);
    
    update_bar();
    
    window_set_click_config_provider(window, (ClickConfigProvider) config_provider);
    
    line = gbitmap_create_with_resource(RESOURCE_ID_LINE);
    
    line_layer = bitmap_layer_create(GRect(122, 0, 2, 168));
    bitmap_layer_set_alignment(line_layer, GAlignCenter);
    layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(line_layer));
    
    bitmap_layer_set_bitmap(line_layer, line);
    
    theme = inverter_layer_create(GRect(0, 0, 144, 168));
    layer_add_child(window_layer, inverter_layer_get_layer(theme));
    layer_set_hidden(inverter_layer_get_layer(theme), theme_public);
}
示例#5
0
static void improve_text_layer(TextLayer *the_text_layer, GFont font) {
  text_layer_set_font(the_text_layer, font);
  text_layer_set_text_alignment(the_text_layer, GTextAlignmentCenter);
}
示例#6
0
static void handle_init(AppContextRef ctx) {
	(void)ctx;

	window_init(&s_data.window, "MichaPoe words #1");
	window_stack_push(&s_data.window, true);
	resource_init_current_app(&WF_WOERTER_2);

	// resolution: 144 × 168

	// Fonts
	GFont font_gross = fonts_load_custom_font(resource_get_handle(DATEFONTBIG));
	GFont font_mittel = fonts_load_custom_font(resource_get_handle(DATEFONTMIDDLE));
	GFont font_klein = fonts_load_custom_font(resource_get_handle(DATEFONTSMALL));

	GFont font_minute = font_mittel;
	GFont font_qualifier = font_klein;
	GFont font_hour = font_gross;
	GFont font_daytime = font_klein;

	// init layers
	layer_init(&s_data.simple_bg_layer, s_data.window.layer.frame);
	s_data.simple_bg_layer.update_proc = &bg_update_proc;
	layer_add_child(&s_data.window.layer, &s_data.simple_bg_layer);

	// init date layer -> a plain parent layer to create a date update proc
	layer_init(&s_data.date_layer, s_data.window.layer.frame);
	s_data.date_layer.update_proc = &date_update_proc;
	layer_add_child(&s_data.window.layer, &s_data.date_layer);

	// calc top of frames
	int16_t top = TOPSPACE;
	s_data.minute_label_top = top;
	s_data.qualifier_label_top = top += TEXTLAYER_MINUTE_VSPACE + FONT_MINUTE_SIZE;
	s_data.hourqualifier_label_top = top += TEXTLAYER_QUALIFIER_VSPACE + FONT_QUALIFIER_SIZE;
	s_data.hour_label_top = top += TEXTLAYER_QUALIFIER_VSPACE + FONT_QUALIFIER_SIZE;
	s_data.daytime_label_top = top += TEXTLAYER_HOUR_VSPACE + FONT_HOUR_SIZE;
	top += TEXTLAYER_DAYTIME_VSPACE + FONT_DAYTIME_SIZE;
	int16_t move_down = (168 - top) / 2;
	s_data.minute_label_top += move_down;
	s_data.qualifier_label_top += move_down;
	s_data.hourqualifier_label_top += move_down;
	s_data.hour_label_top += move_down;
	s_data.daytime_label_top += move_down;

	// init minute
	text_layer_init(&s_data.minute_label, GRect(LEFTSPACE, s_data.minute_label_top, TEXTLAYERWIDTH, FONT_MINUTE_SIZE + TEXTLAYER_MINUTE_VSPACE));
	text_layer_set_text(&s_data.minute_label, s_data.minute_buffer);
	text_layer_set_background_color(&s_data.minute_label, GColorBlack);
	text_layer_set_text_color(&s_data.minute_label, GColorWhite);
	text_layer_set_font(&s_data.minute_label, font_minute);
	layer_add_child(&s_data.date_layer, &s_data.minute_label.layer);

	// init qualifier
	text_layer_init(&s_data.qualifier_label, GRect(LEFTSPACE, s_data.qualifier_label_top, TEXTLAYERWIDTH, FONT_QUALIFIER_SIZE + TEXTLAYER_QUALIFIER_VSPACE));
	text_layer_set_text(&s_data.qualifier_label, s_data.qualifier_buffer);
	text_layer_set_background_color(&s_data.qualifier_label, GColorBlack);
	text_layer_set_text_color(&s_data.qualifier_label, GColorWhite);
	text_layer_set_font(&s_data.qualifier_label, font_qualifier);
	layer_add_child(&s_data.date_layer, &s_data.qualifier_label.layer);

	// init hourqualifier
	text_layer_init(&s_data.hourqualifier_label, GRect(LEFTSPACE, s_data.hourqualifier_label_top, TEXTLAYERWIDTH, FONT_QUALIFIER_SIZE + TEXTLAYER_QUALIFIER_VSPACE));
	text_layer_set_text(&s_data.hourqualifier_label, s_data.hourqualifier_buffer);
	text_layer_set_background_color(&s_data.hourqualifier_label, GColorBlack);
	text_layer_set_text_color(&s_data.hourqualifier_label, GColorWhite);
	text_layer_set_font(&s_data.hourqualifier_label, font_qualifier);
	layer_add_child(&s_data.date_layer, &s_data.hourqualifier_label.layer);

	// init hour
	text_layer_init(&s_data.hour_label, GRect(LEFTSPACE, s_data.hour_label_top, TEXTLAYERWIDTH, FONT_HOUR_SIZE + TEXTLAYER_HOUR_VSPACE));
	text_layer_set_text(&s_data.hour_label, s_data.hour_buffer);
	text_layer_set_background_color(&s_data.hour_label, GColorBlack);
	text_layer_set_text_color(&s_data.hour_label, GColorWhite);
	text_layer_set_font(&s_data.hour_label, font_hour);
	layer_add_child(&s_data.date_layer, &s_data.hour_label.layer);

	// init daytime
	text_layer_init(&s_data.daytime_label, GRect(LEFTSPACE, s_data.daytime_label_top, TEXTLAYERWIDTH, FONT_DAYTIME_SIZE + TEXTLAYER_DAYTIME_VSPACE));
	text_layer_set_text(&s_data.daytime_label, s_data.daytime_buffer);
	text_layer_set_background_color(&s_data.daytime_label, GColorBlack);
	text_layer_set_text_color(&s_data.daytime_label, GColorWhite);
	text_layer_set_font(&s_data.daytime_label, font_daytime);
	layer_add_child(&s_data.date_layer, &s_data.daytime_label.layer);
}
示例#7
0
文件: bit_face.c 项目: ollien/BitFace
static void init(void) {
	window = window_create();
	window_stack_push(window, true);
	window_set_background_color(window, GColorBlack);
	Layer *root_layer = window_get_root_layer(window);
	GRect frame = layer_get_frame(root_layer);

	// Init fonts and images
	font			=	fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_16));
	font_tiny		=	fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_10));
	battery_outline	=	gbitmap_create_with_resource(RESOURCE_ID_BATTERY_OUTLINE);
	battery_charge	=	gbitmap_create_with_resource(RESOURCE_ID_BATTERY_CHARGE);

	// Init layer for display
	display_layer = layer_create(frame);
	layer_set_update_proc(display_layer, &display_layer_update_callback);
	layer_add_child(root_layer, display_layer);

	// Init layer for text
	date_layer = text_layer_create(frame);
	layer_set_frame(text_layer_get_layer(date_layer), GRect(0, 130, 144, 168-130));
	layer_set_bounds(text_layer_get_layer(date_layer), GRect(0, 0, 144, 168-130));
	text_layer_set_text_alignment(date_layer, GTextAlignmentCenter);
	text_layer_set_font(date_layer, font);
	layer_add_child(root_layer, text_layer_get_layer(date_layer));

	// Init layer for battery image
	battery_layer = bitmap_layer_create(frame);
	bitmap_layer_set_background_color(battery_layer, GColorClear);
	layer_set_frame(bitmap_layer_get_layer(battery_layer), GRect(4, 134, 30, 20));
	layer_set_bounds(bitmap_layer_get_layer(battery_layer), GRect(0, 0, 30, 20));
	bitmap_layer_set_bitmap(battery_layer, battery_outline);
	layer_add_child(root_layer, bitmap_layer_get_layer(battery_layer));

	// Init layer for charge image
	charge_layer = bitmap_layer_create(frame);
	bitmap_layer_set_background_color(charge_layer, GColorClear);
	layer_set_frame(bitmap_layer_get_layer(charge_layer), GRect(8, 136, 20, 16));
	layer_set_bounds(bitmap_layer_get_layer(charge_layer), GRect(0, 0, 20, 16));
	bitmap_layer_set_bitmap(charge_layer, battery_charge);
	layer_add_child(root_layer, bitmap_layer_get_layer(charge_layer));

	// Init battery fill layer
	battfill_layer = inverter_layer_create(frame);
	layer_set_frame(inverter_layer_get_layer(battfill_layer), GRect(8, 136, 0, 16));
	layer_add_child(root_layer, inverter_layer_get_layer(battfill_layer));

	// Init layer for battery percentage
	percent_layer = text_layer_create(frame);
	layer_set_frame(text_layer_get_layer(percent_layer), GRect(4, 154, 30, 14));
	layer_set_bounds(text_layer_get_layer(percent_layer), GRect(0, 0, 30, 14));
	text_layer_set_text_alignment(percent_layer, GTextAlignmentCenter);
	text_layer_set_font(percent_layer, font_tiny);
	layer_add_child(root_layer, text_layer_get_layer(percent_layer));

	battery_state_service_subscribe(set_battery);
	set_battery(battery_state_service_peek());
	show_battery();

	tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick);
}
示例#8
0
void handle_init(AppContextRef ctx) {
  (void)ctx;
  g_ctx = ctx;
  
  window_init(&window, "Golf Dashboard");
  window_stack_push(&window, true /* Animated */);
  
  GFont defaultfont = fonts_get_system_font(FONT_KEY_GOTHIC_14);
  
  layer_init(&holepar, GRect(0, 0, 144 /* width */, 40 /* height */));
  holepar.update_proc = &holepar_layer_callback;
  layer_add_child(&window.layer, &holepar);
  
  text_layer_init(&holepar_hole, GRect(0, 0, 72, 17));
  text_layer_set_background_color(&holepar_hole, GColorClear);
  text_layer_set_text_color(&holepar_hole, GColorBlack);
  text_layer_set_text(&holepar_hole, "Hole");
  text_layer_set_text_alignment(&holepar_hole, GTextAlignmentCenter);
  layer_add_child(&holepar, &holepar_hole.layer);
  
  GFont holeparfont = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);
  text_layer_init(&holepar_hole_num, GRect(0, 10, 60, 30));
  text_layer_set_background_color(&holepar_hole_num, GColorClear);
  text_layer_set_text_color(&holepar_hole_num, GColorBlack);
  text_layer_set_font(&holepar_hole_num,holeparfont);
  text_layer_set_text(&holepar_hole_num, "");
  text_layer_set_text_alignment(&holepar_hole_num, GTextAlignmentCenter);
  layer_add_child(&holepar, &holepar_hole_num.layer);
    
  text_layer_init(&holepar_par, GRect(72, 0, 72, 17));
  text_layer_set_background_color(&holepar_par, GColorClear);
  text_layer_set_text_color(&holepar_par, GColorBlack);
  text_layer_set_text(&holepar_par, "Par");
  text_layer_set_text_alignment(&holepar_par, GTextAlignmentCenter);
  layer_add_child(&holepar, &holepar_par.layer);
  
//  GFont holeparfont = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);
  text_layer_init(&holepar_par_num, GRect(75, 10, 60, 30));
  text_layer_set_background_color(&holepar_par_num, GColorClear);
  text_layer_set_text_color(&holepar_par_num, GColorBlack);
  text_layer_set_font(&holepar_par_num,holeparfont);
  text_layer_set_text(&holepar_par_num, "0");
  text_layer_set_text_alignment(&holepar_par_num, GTextAlignmentCenter);
  layer_add_child(&holepar, &holepar_par_num.layer);
  
  text_layer_init(&roundtime, GRect(0, 40, 144 /* width */, 15 /* height */));
  text_layer_set_background_color(&roundtime, GColorBlack);
  text_layer_set_text_color(&roundtime, GColorWhite);
  text_layer_set_font(&roundtime, defaultfont);
  text_layer_set_text(&roundtime, "Round Time:      ");
  text_layer_set_text_alignment(&roundtime, GTextAlignmentCenter);
  layer_add_child(&window.layer, &roundtime.layer);
  
  GFont yrdfont = fonts_get_system_font(FONT_KEY_GOTHAM_42_MEDIUM_NUMBERS);
  text_layer_init(&distance, GRect(0, 55, 144 /* width */, 50 /* height */));
  text_layer_set_background_color(&distance, GColorBlack);
  text_layer_set_text_color(&distance, GColorWhite);
// Placeholder for Sports SDK
  text_layer_set_text(&distance, "000");
  text_layer_set_font(&distance, yrdfont);
  text_layer_set_text_alignment(&distance, GTextAlignmentCenter);
  layer_add_child(&window.layer, &distance.layer);
  
 
  mini_snprintf(s_shots_hole, 25, "Shots: %d", thishole);
  text_layer_init(&shots_hole, GRect(0, 105, 72 /* width */, 15 /* height */));
  text_layer_set_background_color(&shots_hole, GColorBlack);
  text_layer_set_text_color(&shots_hole, GColorWhite);
  text_layer_set_font(&shots_hole, defaultfont);
  text_layer_set_text(&shots_hole, s_shots_hole);
  text_layer_set_text_alignment(&shots_hole, GTextAlignmentLeft);
  layer_add_child(&window.layer, &shots_hole.layer);
  
  mini_snprintf(s_shots_total, 25, "Total: %d", totalshots);
  text_layer_init(&shots_total, GRect(72, 105, 72 /* width */, 15 /* height */));
  text_layer_set_background_color(&shots_total, GColorBlack);
  text_layer_set_text_color(&shots_total, GColorWhite);
  text_layer_set_font(&shots_total, defaultfont);
  text_layer_set_text(&shots_total, s_shots_total);
  text_layer_set_text_alignment(&shots_total, GTextAlignmentRight);
  layer_add_child(&window.layer, &shots_total.layer);
  
  GFont clubfont = fonts_get_system_font(FONT_KEY_GOTHIC_24);
  text_layer_init(&club, GRect(0, 120, 144 /* width */, 168-120-16 /* height */));
  text_layer_set_background_color(&club, GColorWhite);
  text_layer_set_text_color(&club, GColorBlack);
  text_layer_set_font(&club, clubfont);
  text_layer_set_text(&club, club_menu[club_menu_index]);
  text_layer_set_text_alignment(&club, GTextAlignmentCenter);
  layer_add_child(&window.layer, &club.layer);
 
  window_set_click_config_provider(&window, (ClickConfigProvider) click_config_provider);
  
}
示例#9
0
static void main_window_load(Window *window) {
	//Create background bitmap, then set to created BitmapLayer
  s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_DEDSEC_LOGO);
  s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168));
  bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer));
	
	//Create BT bitmap, then set to created BitmapLayer
  s_bluetooth_bitmap = gbitmap_create_with_resource(RESOURCE_ID_SIGNAL);
  s_bluetooth_layer = bitmap_layer_create(GRect(0, 144, 20, 20));  
  bitmap_layer_set_bitmap(s_bluetooth_layer, s_bluetooth_bitmap);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bluetooth_layer));
	
	//Create Battery bitmap, then set to created BitmapLayer
  s_battery_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_CHARGING);
  s_battery_layer = bitmap_layer_create(GRect(122, 123, 22, 18));
	bitmap_layer_set_bitmap(s_battery_layer, s_battery_bitmap);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_battery_layer));
		
	// Create time TextLayer
  s_hour_layer = text_layer_create(GRect(0, -5, 60, 84));
  text_layer_set_background_color(s_hour_layer, GColorClear);
  text_layer_set_text_color(s_hour_layer, GColorWhite);
  text_layer_set_text(s_hour_layer, "00");

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

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

  	// Add it as a child layer to the Window's root layer
  	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_hour_layer));
	  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_minute_layer));
	
	//Create date text layer
	s_date_layer = text_layer_create(GRect(0, 150, 144, 18));
  text_layer_set_background_color(s_date_layer, GColorClear);
  text_layer_set_text_color(s_date_layer, GColorWhite);
  text_layer_set_text(s_date_layer, "MON_01_01_2001");
	text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight);
	text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));
    	
	//Create connection background layer
	s_connection_bg_layer = text_layer_create(GRect(0, 123, 122, 18));	
	#ifdef PBL_COLOR
	  text_layer_set_background_color(s_connection_bg_layer, GColorTiffanyBlue);
	#else
	  text_layer_set_background_color(s_connection_bg_layer, GColorClear);
	#endif
  text_layer_set_text_color(s_connection_bg_layer, GColorWhite);
  text_layer_set_text(s_connection_bg_layer, CONNECTION_TEXT);
	text_layer_set_font(s_connection_bg_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_connection_bg_layer));
	
	//Create connection text layer
	s_connection_layer = text_layer_create(GRect(0, 123, 122, 18));
  text_layer_set_text(s_connection_layer, CONNECTION_TEXT);
  s_connection_bar_color = GColorWhite;
  layer_set_update_proc((Layer*) s_connection_layer, text_update_proc);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_connection_layer));
	
	//Create hacking text layer
	s_hacking_layer = text_layer_create(GRect(0, 137, 144, 18));
  text_layer_set_background_color(s_hacking_layer, GColorClear);
  text_layer_set_text_color(s_hacking_layer, GColorWhite);
  text_layer_set_text(s_hacking_layer, "_hacking is our weapon");
	text_layer_set_text_alignment(s_hacking_layer, GTextAlignmentRight);	
	text_layer_set_font(s_hacking_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_hacking_layer));
	
	// Make sure the time is displayed from the start
  update_time();
	
	// Show current connection state
  bt_handler(bluetooth_connection_service_peek());
	
	// Show current battery state
  battery_handler(battery_state_service_peek());
}
示例#10
0
文件: main.c 项目: turnervink/CUTOFF
static void main_window_load(Window *window) {
  
  window_set_background_color(s_my_window, GColorBlack);

  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);

  bluetooth_connection_service_subscribe(bluetooth_handler);

  s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_LIGHT_72));

  s_minute_layer = text_layer_create(GRect(15, 56, 144, 80));
  text_layer_set_text(s_minute_layer, "");
  text_layer_set_text_alignment(s_minute_layer, GTextAlignmentCenter);
  text_layer_set_font(s_minute_layer, s_time_font);
  text_layer_set_background_color(s_minute_layer, GColorClear);

  s_hour_layer = text_layer_create(GRect(-23, 19, 154, 61));
  text_layer_set_font(s_hour_layer, s_time_font);
  text_layer_set_text(s_hour_layer, "");
  text_layer_set_text_alignment(s_hour_layer, GTextAlignmentCenter);
  text_layer_set_background_color(s_hour_layer, GColorBlack);
  
  date_layer = text_layer_create(GRect(0, 0, 144, 20));
  text_layer_set_font(date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  text_layer_set_text_alignment(date_layer, GTextAlignmentCenter);
  text_layer_set_background_color(date_layer, GColorBlack);
  text_layer_set_text_color(date_layer, GColorWhite);
 
  s_line_layer = layer_create(GRect(0 , 0, 144, 168));
  layer_set_update_proc(s_line_layer, s_layer_update_proc);
  
  #ifdef PBL_BW
  s_inv_layer = inverter_layer_create(GRect(0, 0, 144, 168));

    text_layer_set_text_color(s_minute_layer , GColorWhite);
    text_layer_set_text_color(s_hour_layer , GColorWhite);
  #else 
    text_layer_set_text_color(s_minute_layer , GColorSpringBud);
    text_layer_set_text_color(s_hour_layer , GColorGreen);
    
    #endif
  
      
  
  layer_add_child(window_get_root_layer(s_my_window), text_layer_get_layer(s_minute_layer));
  layer_add_child(window_get_root_layer(s_my_window), text_layer_get_layer(s_hour_layer));
  layer_add_child(window_get_root_layer(s_my_window), s_line_layer);
  layer_add_child(window_get_root_layer(s_my_window), text_layer_get_layer(date_layer));
  #ifdef PBL_BW
  layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(s_inv_layer));
  #endif  
       
  if(persist_exists(KEY_INVERT_FACE)){
      invert_face = persist_read_int(KEY_INVERT_FACE);
    APP_LOG(APP_LOG_LEVEL_INFO, "Read Invert");
    }
  
   if(persist_exists(KEY_BLUETOOTH_VIBRATION)){
    bluetooth_vibration = persist_read_int(KEY_BLUETOOTH_VIBRATION);
    APP_LOG(APP_LOG_LEVEL_INFO,"Bluetooth read");
   }
  if(persist_exists(KEY_SHOW_DATE)){
    show_date = persist_read_int(KEY_SHOW_DATE);
    APP_LOG(APP_LOG_LEVEL_INFO, "Read Date");
  }
      

update_time();
update_layers();
    
  struct tm *t;
  time_t temp;
  temp = time(NULL);
  t = localtime(&temp);
  
  tick_handler(t, MINUTE_UNIT);
  
  
  
 
}
示例#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();
}
示例#12
0
void handle_init(AppContextRef ctx) {
  (void)ctx;
	
  window_init(&window, "KP Sun-Moon-Clock");
  window_stack_push(&window, true /* Animated */);
  window_set_background_color(&window, GColorWhite);

  resource_init_current_app(&APP_RESOURCES);
  font_moon = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MOON_PHASES_SUBSET_30));
  layer_init(&graphics_sun_layer, window.layer.frame);
  graphics_sun_layer.update_proc = &graphics_sun_layer_update_callback;
  layer_add_child(&window.layer, &graphics_sun_layer);

  rotbmp_pair_init_container(RESOURCE_ID_IMAGE_WATCHFACE_WHITE, RESOURCE_ID_IMAGE_WATCHFACE_BLACK, &watchface_container);
  layer_add_child(&graphics_sun_layer, &watchface_container.layer.layer);
  rotbmp_pair_layer_set_angle(&watchface_container.layer, 1);
  watchface_container.layer.layer.frame.origin.x = (144/2) - (watchface_container.layer.layer.frame.size.w/2);
  watchface_container.layer.layer.frame.origin.y = (168/2) - (watchface_container.layer.layer.frame.size.h/2);

  text_layer_init(&text_time_layer, window.layer.frame);
  text_layer_set_text_color(&text_time_layer, GColorBlack);
  text_layer_set_background_color(&text_time_layer, GColorClear);
  layer_set_frame(&text_time_layer.layer, GRect(0, 35, 144, 30));
  text_layer_set_font(&text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_30)));
  layer_add_child(&window.layer, &text_time_layer.layer);

  rotbmp_pair_init_container(RESOURCE_ID_IMAGE_HOUR_WHITE, RESOURCE_ID_IMAGE_HOUR_BLACK, &bitmap_container);
  rotbmp_pair_layer_set_src_ic(&bitmap_container.layer, GPoint(9,56));
  layer_add_child(&window.layer, &bitmap_container.layer.layer);

  text_layer_init(&moonLayer, GRect(0, 100, 144 /* width */, 168-115 /* height */));
  text_layer_set_text_color(&moonLayer, GColorWhite);
  text_layer_set_background_color(&moonLayer, GColorClear);
  text_layer_set_font(&moonLayer, font_moon);
  text_layer_set_text_alignment(&moonLayer, GTextAlignmentCenter);

  handle_day(ctx, NULL);
	
  layer_add_child(&window.layer, &moonLayer.layer);
	
PblTm t;
  get_time(&t);
  rotbmp_pair_layer_set_angle(&bitmap_container.layer, TRIG_MAX_ANGLE * get24HourAngle(t.tm_hour, t.tm_min));
  bitmap_container.layer.layer.frame.origin.x = (144/2) - (bitmap_container.layer.layer.frame.size.w/2);
  bitmap_container.layer.layer.frame.origin.y = (168/2) - (bitmap_container.layer.layer.frame.size.h/2);

  //Day of Week text
  text_layer_init(&dow_layer, GRect(0, 0, 144, 127+26));
  text_layer_set_text_color(&dow_layer, GColorWhite);
  text_layer_set_background_color(&dow_layer, GColorClear);
  text_layer_set_font(&dow_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_text_alignment(&dow_layer, GTextAlignmentLeft);
  text_layer_set_text(&dow_layer, "xxx");
  layer_add_child(&window.layer, &dow_layer.layer);

  //Day of the Month text
  text_layer_init(&dom_layer, GRect(0, 10, 144, 137+26));
  text_layer_set_text_color(&dom_layer, GColorWhite);
  text_layer_set_background_color(&dom_layer, GColorClear);
  text_layer_set_font(&dom_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
  text_layer_set_text_alignment(&dom_layer, GTextAlignmentLeft);
  text_layer_set_text(&dom_layer, "00");
  layer_add_child(&window.layer, &dom_layer.layer);
	
  //Month Text
  text_layer_init(&mon_layer, GRect(0, 0, 144, 127+26));
  text_layer_set_text_color(&mon_layer, GColorWhite);
  text_layer_set_background_color(&mon_layer, GColorClear);
  text_layer_set_font(&mon_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_text_alignment(&mon_layer, GTextAlignmentRight);
  text_layer_set_text(&mon_layer, "xxx");
  layer_add_child(&window.layer, &mon_layer.layer);

  //Year Number text
  text_layer_init(&yon_layer, GRect(0, 10, 144, 137+26));
  text_layer_set_text_color(&yon_layer, GColorWhite);
  text_layer_set_background_color(&yon_layer, GColorClear);
  text_layer_set_font(&yon_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
  text_layer_set_text_alignment(&yon_layer, GTextAlignmentRight);
  text_layer_set_text(&yon_layer, "00");
  layer_add_child(&window.layer, &yon_layer.layer); 	

  //Sunrise Text 
  text_layer_init(&text_sunrise_layer, window.layer.frame);
  text_layer_set_text_color(&text_sunrise_layer, GColorWhite);
  text_layer_set_background_color(&text_sunrise_layer, GColorClear);
  layer_set_frame(&text_sunrise_layer.layer, GRect(0, 145, 144, 30));
  text_layer_set_font(&text_sunrise_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  layer_add_child(&window.layer, &text_sunrise_layer.layer);

 //Sunset Text
  text_layer_init(&text_sunset_layer, window.layer.frame);
  text_layer_set_text_color(&text_sunset_layer, GColorWhite);
  text_layer_set_background_color(&text_sunset_layer, GColorClear);
  layer_set_frame(&text_sunset_layer.layer, GRect(0, 145, 144, 30));
  text_layer_set_font(&text_sunset_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  layer_add_child(&window.layer, &text_sunset_layer.layer); 

  http_set_app_id(55122370);

  http_register_callbacks((HTTPCallbacks){
    .time=have_time,
    .location=have_location
  }, (void*)ctx);
示例#13
0
static void show_text(char *message, GColor fg_color, GColor bg_color) {
  text_layer_set_text_color(s_output_layer, fg_color);
  text_layer_set_background_color(s_output_layer, bg_color);
  text_layer_set_font(s_output_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text(s_output_layer, message);
}
示例#14
0
文件: main.c 项目: volco/getitdone
void handle_init(void) {
    my_window = window_create();
    window_set_background_color(my_window, GColorBlack);
    line_layer = layer_create(GRect(0, 0, 144, 168));
    layer_set_update_proc(line_layer, draw_line);
    time_layer = text_layer_create(GRect(90, 20, 144, 32));
    text_layer_set_background_color(time_layer, GColorBlack);

#if defined(PBL_ROUND)
    text_done = text_layer_create(GRect(33,99,144,48));
    text_get = text_layer_create(GRect(33, 44, 144, 32));
    text_shit = text_layer_create(GRect(33,74,144,32));

    text_emoji = text_layer_create(GRect(15,44,50,50));
#elif defined(PBL_RECT)
    text_done = text_layer_create(GRect(22,95,144,48));
    text_get = text_layer_create(GRect(22, 40, 144, 32));
    text_shit = text_layer_create(GRect(22,70,144,32));

    text_emoji = text_layer_create(GRect(2,40,50,50));
#endif
    text_layer_set_background_color(text_emoji, GColorBlack);
    text_layer_set_text_color(text_emoji, GColorWhite);
    text_layer_set_text(text_emoji, "\U0001F603");
    s_custom_font_bold = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_BOLD_48));
    text_layer_set_font(text_done, s_custom_font_bold);
    text_layer_set_background_color(text_done, GColorBlack);

#if defined(PBL_COLOR)
    text_layer_set_text_color(text_done, GColorRed);
    text_layer_set_text(text_done, "DONE.");
#elif defined(PBL_BW)
    text_layer_set_text_color(text_done, GColorWhite);
    text_layer_set_text(text_done, "DONE.");
#endif

    s_custom_font_24 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_32));
    text_layer_set_font(text_get, s_custom_font_24);
    text_layer_set_background_color(text_get, GColorBlack);
    text_layer_set_text_color(text_get, GColorWhite);
    text_layer_set_text(text_get, "Get");
    text_layer_set_font(text_shit, s_custom_font_24);
    text_layer_set_background_color(text_shit, GColorBlack);
    text_layer_set_text_color(text_shit, GColorWhite);
    text_layer_set_text(text_shit, "Shit");



    s_custom_font_bold = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_18));
    text_layer_set_font(time_layer, s_custom_font_bold);
    text_layer_set_text_color(time_layer, GColorWhite);
    text_layer_set_text(time_layer, "00:00");

    //draw_line(ctx);

    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(text_done));
    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(text_emoji));
    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(text_shit));
    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(text_get));
    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(time_layer));
    layer_add_child(window_get_root_layer(my_window), line_layer);
    window_stack_push(my_window, true);

    tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
}
示例#15
0
文件: modern.c 项目: 7bp/pebble
void handle_init(AppContextRef ctx) {
  (void)ctx;

  window_init(&window, "Modern Watch");
  window_stack_push(&window, true /* Animated */);
  resource_init_current_app(&APP_RESOURCES);

#if DISPLAY_LOGO && DISPLAY_DATE_ANALOG
  bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND_LOGO_DATEBOX, &background_image_container);
#elif DISPLAY_LOGO
  bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND_LOGO, &background_image_container);
#elif DISPLAY_DATE_ANALOG
  bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND_DATEBOX, &background_image_container);
#else
  bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container);
#endif
  layer_add_child(&window.layer, &background_image_container.layer.layer);

#if DISPLAY_DATE_ANALOG
  date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ORBITRON_MEDIUM_12));
  text_layer_init(&date_layer, GRect(116, 77, 20, 20));
  text_layer_set_text_color(&date_layer, GColorBlack);
#elif DISPLAY_DATE_DIGITAL || DISPLAY_DATE_DIGITAL_DAY
  date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIGITALDREAM_NARROW_12));
  text_layer_init(&date_layer, GRect(27, 40, 90, 30));
  text_layer_set_text_color(&date_layer, GColorWhite);
#endif
#if DISPLAY_DATE_ANALOG || DISPLAY_DATE_DIGITAL || DISPLAY_DATE_DIGITAL_DAY
  text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter);
  text_layer_set_background_color(&date_layer, GColorClear);
  text_layer_set_font(&date_layer, date_font);
  layer_add_child(&window.layer, &date_layer.layer);

  draw_date();
#endif
  layer_init(&hour_display_layer, window.layer.frame);
  hour_display_layer.update_proc = &hour_display_layer_update_callback;
  layer_add_child(&window.layer, &hour_display_layer);

  gpath_init(&hour_hand_outline_path, &HOUR_HAND_OUTLINE_PATH_POINTS);
  gpath_move_to(&hour_hand_outline_path, grect_center_point(&hour_display_layer.frame));
  gpath_init(&hour_hand_path, &HOUR_HAND_PATH_POINTS);
  gpath_move_to(&hour_hand_path, grect_center_point(&hour_display_layer.frame));

  layer_init(&minute_display_layer, window.layer.frame);
  minute_display_layer.update_proc = &minute_display_layer_update_callback;
  layer_add_child(&window.layer, &minute_display_layer);

  gpath_init(&minute_hand_outline_path, &MINUTE_HAND_OUTLINE_PATH_POINTS);
  gpath_move_to(&minute_hand_outline_path, grect_center_point(&minute_display_layer.frame));
  gpath_init(&minute_hand_path, &MINUTE_HAND_PATH_POINTS);
  gpath_move_to(&minute_hand_path, grect_center_point(&minute_display_layer.frame));

  layer_init(&center_display_layer, window.layer.frame);
  center_display_layer.update_proc = &center_display_layer_update_callback;
  layer_add_child(&window.layer, &center_display_layer);
#if DISPLAY_SECONDS
  layer_init(&second_display_layer, window.layer.frame);
  second_display_layer.update_proc = &second_display_layer_update_callback;
  layer_add_child(&window.layer, &second_display_layer);
#endif
}
示例#16
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();
}
示例#17
0
static void main_window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_frame(window_layer);

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

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

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

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

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

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

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

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

	layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_time_element_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_date_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_date_element_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_connection_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_battery_layer));
}
示例#18
0
void handle_init(AppContextRef ctx)
{
    PblTm tm;
    PebbleTickEvent t;
    ResHandle res_d;
    ResHandle res_t;
    GFont font_date;
    GFont font_time;

    window_init(&window, "AccuInfo");
    window_stack_push(&window, true /* Animated */);
    window_set_background_color(&window, BG_COLOR);

    resource_init_current_app(&APP_RESOURCES);

    res_d = resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21);
    res_t = resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_41);
    font_date = fonts_load_custom_font(res_d);
    font_time = fonts_load_custom_font(res_t);

    text_layer_init(&day_layer, window.layer.frame);
    text_layer_set_text_color(&day_layer, FG_COLOR);
    text_layer_set_background_color(&day_layer, GColorClear);
    text_layer_set_text_alignment(&day_layer, GTextAlignmentCenter);
    text_layer_set_font(&day_layer, font_date);
    layer_set_frame(&day_layer.layer, GRect(1, 2, 144-1, 168-2));
    layer_add_child(&window.layer, &day_layer.layer);

    text_layer_init(&time_layer, window.layer.frame);
    text_layer_set_text_color(&time_layer, FG_COLOR);
    text_layer_set_background_color(&time_layer, GColorClear);
    layer_set_frame(&time_layer.layer, GRect(1, 48, 144-1, 168-48));
    text_layer_set_font(&time_layer, font_time);
    layer_add_child(&window.layer, &time_layer.layer);

    text_layer_init(&secs_layer, window.layer.frame);
    text_layer_set_text_color(&secs_layer, FG_COLOR);
    text_layer_set_background_color(&secs_layer, GColorClear);
    layer_set_frame(&secs_layer.layer, GRect(112, 46, 144-112, 168-46));
    text_layer_set_font(&secs_layer, font_date);
    layer_add_child(&window.layer, &secs_layer.layer);

    text_layer_init(&ampm_layer, window.layer.frame);
    text_layer_set_text_color(&ampm_layer, FG_COLOR);
    text_layer_set_background_color(&ampm_layer, GColorClear);
    layer_set_frame(&ampm_layer.layer, GRect(112, 74, 144-112, 168-74));
    text_layer_set_font(&ampm_layer, font_date);
    layer_add_child(&window.layer, &ampm_layer.layer);

    text_layer_init(&date_layer, window.layer.frame);
    text_layer_set_text_color(&date_layer, FG_COLOR);
    text_layer_set_background_color(&date_layer, GColorClear);
    text_layer_set_font(&date_layer, font_date);
    text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter);
    layer_set_frame(&date_layer.layer, GRect(1, 118, 144-1, 168-118));
    layer_add_child(&window.layer, &date_layer.layer);

    text_layer_init(&year_layer, window.layer.frame);
    text_layer_set_text_color(&year_layer, FG_COLOR);
    text_layer_set_background_color(&year_layer, GColorClear);
    text_layer_set_font(&year_layer, font_date);
    text_layer_set_text_alignment(&year_layer, GTextAlignmentCenter);
    layer_set_frame(&year_layer.layer, GRect(0, 142, 144, 168-142));
    layer_add_child(&window.layer, &year_layer.layer);

    layer_init(&line_layer, window.layer.frame);
    line_layer.update_proc = &line_layer_update_callback;
    layer_add_child(&window.layer, &line_layer);

    get_time(&tm);
    t.tick_time = &tm;
    t.units_changed = SECOND_UNIT | MINUTE_UNIT | HOUR_UNIT | DAY_UNIT;

    handle_second_tick(ctx, &t);
}
示例#19
0
static void main_window_load(Window *window) {
  printf("main_window_load function");
  //Create GBitmap, then set to created BitmapLayer
  s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND);
  s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168));
  bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer));
  
  // Create time TextLayer
  s_time_layer = text_layer_create(GRect(5, 52, 139, 50));
  text_layer_set_background_color(s_time_layer, GColorClear);
  text_layer_set_text_color(s_time_layer, GColorBlack);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
  text_layer_set_text(s_time_layer, "00:00");
  
  // Create temperature Layer
  s_weather_layer = text_layer_create(GRect(0, 130, 144, 25));
  text_layer_set_background_color(s_weather_layer, GColorClear);
  text_layer_set_text_color(s_weather_layer, GColorWhite);
  text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter);
  text_layer_set_text(s_weather_layer, "Loading...");
  
  // Create date TextLayer
  s_date_layer = text_layer_create(GRect(0, 115, 144, 30));
  text_layer_set_text_color(s_date_layer, GColorWhite);
  text_layer_set_background_color(s_date_layer, GColorClear);
  text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
  text_layer_set_text(s_date_layer, "Date Load...");
  
  //Create GFont
  s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_48));
  text_layer_set_font(s_time_layer, s_time_font);
  s_weather_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_20));
  text_layer_set_font(s_weather_layer, s_weather_font);
  s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_15));
  text_layer_set_font(s_date_layer, s_date_font);

  
  // Create the Bluetooth icon GBitmap
  s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON);
  // Create the BitmapLayer to display the GBitmap
  s_bt_icon_layer = bitmap_layer_create(GRect(59, 12, 30, 30));
  bitmap_layer_set_bitmap(s_bt_icon_layer, s_bt_icon_bitmap);
  
  // Show the correct state of the BT connection from the start
  bluetooth_callback(connection_service_peek_pebble_app_connection());
  
  // Add it as a child layer to the Window's root layer
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bt_icon_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);
  
  // Make sure the time is displayed from the start
  update_time();
}
void copying_text_layer_set_font(CopyingTextLayer *copying_text_layer, GFont font) {
  text_layer_set_font(copying_text_layer->text_layer, font);
}
示例#21
0
文件: main.c 项目: ShaBP/91DubPro
static void init(void) {
  memset(&time_digits_layers, 0, sizeof(time_digits_layers));
  memset(&time_digits_images, 0, sizeof(time_digits_images));
  memset(&date_digits_layers, 0, sizeof(date_digits_layers));
  memset(&date_digits_images, 0, sizeof(date_digits_images));
  memset(&battery_percent_layers, 0, sizeof(battery_percent_layers));
  memset(&battery_percent_image, 0, sizeof(battery_percent_image));

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

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

  //time format
  GRect frame5 = (GRect) {
    .origin = { .x = 12, .y = 68 },
    .size = {.w = 19, .h = 8}
  };
static void set_text_layer_big_font(TextLayer* layer){
	GFont s_font;
	s_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SCORE_FONT_34));
	text_layer_set_font(layer, s_font);
}
示例#23
0
文件: polar_clock.c 项目: Japh/pebble
void handle_init(AppContextRef ctx) {
  (void)ctx;

  window_init(&window, "Polar Clock watch");
  window_stack_push(&window, true);
  window_set_background_color(&window, GColorBlack);

  resource_init_current_app(&APP_RESOURCES);

  // Init the layer for the minute display
  layer_init(&minute_display_layer, window.layer.frame);
  minute_display_layer.update_proc = &minute_display_layer_update_callback;
  layer_add_child(&window.layer, &minute_display_layer);

  // Init the minute segment path
  gpath_init(&minute_segment_path, &MINUTE_SEGMENT_PATH_POINTS);
  gpath_move_to(&minute_segment_path, grect_center_point(&minute_display_layer.frame));

  // Init the layer for the hour display
  layer_init(&hour_display_layer, window.layer.frame);
  hour_display_layer.update_proc = &hour_display_layer_update_callback;
  layer_add_child(&window.layer, &hour_display_layer);

  // Init the hour segment path
  gpath_init(&hour_segment_path, &HOUR_SEGMENT_PATH_POINTS);
  gpath_move_to(&hour_segment_path, grect_center_point(&hour_display_layer.frame));

  #if SHOW_SECONDS

  // Init the layer for the second display
  layer_init(&second_display_layer, window.layer.frame);
  second_display_layer.update_proc = &second_display_layer_update_callback;
  layer_add_child(&window.layer, &second_display_layer);

  // Init the second segment path
  gpath_init(&second_segment_path, &SECOND_SEGMENT_PATH_POINTS);
  gpath_move_to(&second_segment_path, grect_center_point(&second_display_layer.frame));
  
  #endif

  #if SHOW_TEXT_TIME

  text_layer_init(&text_time_layer, window.layer.frame);
  text_layer_set_text_color(&text_time_layer, GColorWhite);
  text_layer_set_background_color(&text_time_layer, GColorClear);

  #if SHOW_TEXT_DATE
  layer_set_frame(&text_time_layer.layer, GRect(47, 57, 144-47, 168-57));
  #else
  layer_set_frame(&text_time_layer.layer, GRect(47, 70, 144-47, 168-70));
  #endif

  text_layer_set_font(&text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21)));
  layer_add_child(&window.layer, &text_time_layer.layer);

  #endif

  #if SHOW_TEXT_DATE

  text_layer_init(&text_date_layer, window.layer.frame);
  text_layer_set_text_color(&text_date_layer, GColorWhite);
  text_layer_set_background_color(&text_date_layer, GColorClear);
  layer_set_frame(&text_date_layer.layer, GRect(44, 80, 144-44, 168-80));
  text_layer_set_font(&text_date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21)));
  layer_add_child(&window.layer, &text_date_layer.layer);

  #endif

}
示例#24
0
void chrono_digital_window_load_handler(struct Window *window) {
  app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "chrono digital loads");

  GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);


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

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

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

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

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

  chrono_digital_line_layer = layer_create(GRect(0, LAP_HEIGHT * CHRONO_MAX_LAPS + 1, SCREEN_WIDTH, 1));
  if (chrono_digital_line_layer == NULL) {
    trigger_memory_panic(__LINE__);
    return;
  }    
  layer_set_update_proc(chrono_digital_line_layer, &chrono_digital_line_layer_update_callback);
  layer_add_child(chrono_digital_contents_layer, (Layer *)chrono_digital_line_layer);
}
示例#25
0
文件: main.c 项目: eisea/SimpleTime
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();
}
示例#26
0
文件: WA1OUI.c 项目: DHKaplan/WA1OUI
//********************************** Handle Init **************************
void handle_init(void) {

  if (quiet_time_is_active()) {
     QuietTimeColor = GColorYellow;
     }
     else
     {  
     QuietTimeColor = GColorRed;
     }
  
  GColor BGCOLOR   = COLOR_FALLBACK(GColorDukeBlue, GColorBlack);
  BGColorHold = BGCOLOR;

  GColor TEXTCOLOR = COLOR_FALLBACK(GColorWhite, GColorWhite);
  TextColorHold = TEXTCOLOR;

  window = window_create();
  window_set_background_color(window, BGCOLOR);
  window_stack_push(window, true /* Animated */);

  fontHelvNewLight20 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELV_NEW_LIGHT_20));
  fontRobotoCondensed20  = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_20));
  fontRobotoCondensed21  = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21));
  fontRobotoBoldSubset37 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_37));
  fontRobotoBoldSubset49 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49));

  Layer *window_layer = window_get_root_layer(window);

  // Register callbacks
  app_message_register_inbox_received(inbox_received_callback);
  app_message_register_inbox_dropped(inbox_dropped_callback);
  app_message_register_outbox_failed(outbox_failed_callback);
  app_message_register_outbox_sent(outbox_sent_callback);

  // Open AppMessage
  app_message_open(128, 128);

  //degrees
  text_degrees_layer = text_layer_create(GRect(30, 1, 60, 200));
  text_layer_set_text_alignment(text_degrees_layer, GTextAlignmentCenter);
  text_layer_set_text(text_degrees_layer, degreesstr);
  text_layer_set_font(text_degrees_layer, fontRobotoCondensed20);
  text_layer_set_background_color(text_degrees_layer, BGCOLOR);
  text_layer_set_text_color(text_degrees_layer, TEXTCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_degrees_layer));

  //degrees inside
  text_degrees_inside_layer = text_layer_create(GRect(85, 2, 55, 26));
  text_layer_set_text_alignment(text_degrees_inside_layer, GTextAlignmentRight);
  text_layer_set_text(text_degrees_inside_layer, degreesstr);
  text_layer_set_font(text_degrees_inside_layer, fontRobotoCondensed20);
  text_layer_set_background_color(text_degrees_inside_layer, BGCOLOR);
  text_layer_set_text_color(text_degrees_inside_layer, TEXTCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_degrees_inside_layer));


  // WA1OUI
  text_wa1oui_layer = text_layer_create(GRect(1,25, 144, 148));
  text_layer_set_text_alignment(text_wa1oui_layer, GTextAlignmentCenter);
  text_layer_set_text(text_wa1oui_layer, "WA1OUI");
  text_layer_set_font(text_wa1oui_layer, fontRobotoBoldSubset37);
  text_layer_set_text_color(text_wa1oui_layer, TEXTCOLOR);
  text_layer_set_background_color(text_wa1oui_layer, BGCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_wa1oui_layer));


  // Dayname
  text_dayname_layer = text_layer_create(GRect(1, 65, 35, 168-65));
  text_layer_set_text_alignment(text_dayname_layer, GTextAlignmentLeft);
  text_layer_set_font(text_dayname_layer, fontRobotoCondensed20);
  text_layer_set_text_color(text_dayname_layer, TEXTCOLOR);
  text_layer_set_background_color(text_dayname_layer, BGCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_dayname_layer));
  
  
  // wind
  text_wind_layer = text_layer_create(GRect(37, 65, 60, 168-65));
  text_layer_set_text_alignment(text_wind_layer, GTextAlignmentCenter);
  text_layer_set_font(text_wind_layer, fontRobotoCondensed20);
  text_layer_set_text_color(text_wind_layer, TEXTCOLOR);
  text_layer_set_background_color(text_wind_layer, BGCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_wind_layer));
  
  // Rain
  text_rain_layer = text_layer_create(GRect(95, 65, 49, 168-65));
  text_layer_set_text_alignment(text_rain_layer, GTextAlignmentRight);
  text_layer_set_font(text_rain_layer, fontRobotoCondensed21);
  text_layer_set_text_color(text_rain_layer, TEXTCOLOR);
  text_layer_set_background_color(text_rain_layer, BGCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_rain_layer));
  

  // Date
  text_date_layer = text_layer_create(GRect(8, 88, 144-8, 168-88));
  text_layer_set_text_alignment(text_date_layer, GTextAlignmentCenter);
  text_layer_set_font(text_date_layer, fontRobotoCondensed21);
  text_layer_set_text_color(text_date_layer, TEXTCOLOR);
  text_layer_set_background_color(text_date_layer, BGCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_date_layer));


  // Time of Day
  text_time_layer = text_layer_create(GRect(7, 116, 144-7, 168-116));
  text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter);
  text_layer_set_font(text_time_layer, fontRobotoBoldSubset49);
  text_layer_set_text_color(text_time_layer, TEXTCOLOR);
  text_layer_set_background_color(text_time_layer, BGCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_time_layer));

  // Red Line
  GRect red_line_frame = GRect(10, 28, 124, 2);
  RedLineLayer = layer_create(red_line_frame);
  layer_set_update_proc(RedLineLayer, red_line_layer_update_callback);
  layer_add_child(window_layer, RedLineLayer);

  // Battery Line
  GRect line_frame = GRect(22, 118, 104, 6);
  LineLayer = layer_create(line_frame);
  layer_set_update_proc(LineLayer, line_layer_update_callback);
  layer_add_child(window_layer, LineLayer);

  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);

  //Bluetooth Logo Setup area
  GRect BTArea = GRect(1, 5, 20, 20);
  BTLayer1 = layer_create(BTArea);

  layer_add_child(window_layer, BTLayer1);

  layer_set_update_proc(BTLayer1, BTLine_update_callback);

  bluetooth_connection_service_subscribe(&handle_bluetooth);

 
  handle_bluetooth(bluetooth_connection_service_peek());
  handle_battery(battery_state_service_peek());

  //app focus service subscribe
  app_focus_service_subscribe(&handle_appfocus);
  
  // Ensures time is displayed immediately (will break if NULL tick event accessed).
  // (This is why it's a good idea to have a separate routine to do the update itself.)
  time_t now = time(NULL);
  struct tm *current_time = localtime(&now);
  handle_tick(current_time, SECOND_UNIT);
}
示例#27
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);
}
示例#28
0
void handle_init(void) {
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);

  Layer *window_layer = window_get_root_layer(window);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  // TODO: Update display here to avoid blank display on launch?
}
示例#29
0
static void initialise_ui(void) {
  s_window = window_create();
  window_set_background_color(s_window, GColorBlack);
  #ifndef PBL_SDK_3
    window_set_fullscreen(s_window, 0);
  #endif
  
  s_res_content_regular_12 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_content_regular_12));
  s_res_content_regular_24 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_content_regular_24));
  s_res_left_led = gbitmap_create_with_resource(RESOURCE_ID_Left_LED);
  s_res_send_button = gbitmap_create_with_resource(RESOURCE_ID_Send_Button);
  s_res_right_led = gbitmap_create_with_resource(RESOURCE_ID_Right_LED);
  s_res_content_regular_16 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_content_regular_16));
  // s_time_layer
  s_time_layer = text_layer_create(GRect(0, 0, 144, 18));
  text_layer_set_background_color(s_time_layer, GColorClear);
  text_layer_set_text_color(s_time_layer, GColorWhite);
  text_layer_set_text(s_time_layer, "00:00");
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
  text_layer_set_font(s_time_layer, s_res_content_regular_12);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_time_layer);
  
  // s_xy_values_layer
  s_xy_values_layer = text_layer_create(GRect(13, 66, 99, 36));
  text_layer_set_background_color(s_xy_values_layer, GColorClear);
  text_layer_set_text_color(s_xy_values_layer, GColorWhite);
  text_layer_set_text(s_xy_values_layer, "000 000");
  text_layer_set_text_alignment(s_xy_values_layer, GTextAlignmentCenter);
  text_layer_set_font(s_xy_values_layer, s_res_content_regular_24);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_xy_values_layer);
  
  // s_actionbarlayer_1
  s_actionbarlayer_1 = action_bar_layer_create();
  action_bar_layer_add_to_window(s_actionbarlayer_1, s_window);
  action_bar_layer_set_background_color(s_actionbarlayer_1, GColorBlack);
  action_bar_layer_set_icon(s_actionbarlayer_1, BUTTON_ID_UP, s_res_left_led);
  action_bar_layer_set_icon(s_actionbarlayer_1, BUTTON_ID_SELECT, s_res_send_button);
  action_bar_layer_set_icon(s_actionbarlayer_1, BUTTON_ID_DOWN, s_res_right_led);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_actionbarlayer_1);
  
  // s_left_stop
  s_left_stop = bitmap_layer_create(GRect(40, 53, 15, 15));
  bitmap_layer_set_bitmap(s_left_stop, s_res_left_led);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_left_stop);
  
  // s_right_stop
  s_right_stop = bitmap_layer_create(GRect(70, 53, 15, 15));
  bitmap_layer_set_bitmap(s_right_stop, s_res_right_led);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_right_stop);
  
  // s_transmitting
  s_transmitting = bitmap_layer_create(GRect(55, 105, 15, 15));
  bitmap_layer_set_bitmap(s_transmitting, s_res_send_button);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_transmitting);
  
  // s_delay_text
  s_delay_text = text_layer_create(GRect(73, 98, 30, 30));
  text_layer_set_background_color(s_delay_text, GColorClear);
  text_layer_set_text_color(s_delay_text, GColorWhite);
  text_layer_set_text(s_delay_text, "0");
  text_layer_set_font(s_delay_text, s_res_content_regular_16);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_delay_text);
}
示例#30
0
/* Initialize the application.
*/
void handle_init(AppContextRef ctx)
{
    PblTm tm;
    PebbleTickEvent t;
    ResHandle res_d;
    ResHandle res_h;
//    ResHandle res_m;
	ResHandle res_u;

    window_init(&window, "Antonio");
    window_stack_push(&window, true /* Animated */);
    window_set_background_color(&window, GColorBlack);

    resource_init_current_app(&APP_RESOURCES);

    res_d = resource_get_handle(RESOURCE_ID_FUTURA_18);
    res_h = resource_get_handle(RESOURCE_ID_FUTURA_CONDENSED_53);
	res_u = resource_get_handle(RESOURCE_ID_FUTURA_12);

    font_date = fonts_load_custom_font(res_d);
    font_hour = fonts_load_custom_font(res_h);
    font_minute = fonts_load_custom_font(res_h);
    font_updated = fonts_load_custom_font(res_u);

    time_layer_init(&time_layer, window.layer.frame);
    time_layer_set_text_color(&time_layer, GColorWhite);
    time_layer_set_background_color(&time_layer, GColorClear);
    time_layer_set_fonts(&time_layer, font_hour, font_minute);
    layer_set_frame(&time_layer.layer, TIME_FRAME);
    layer_add_child(&window.layer, &time_layer.layer);

    text_layer_init(&date_layer, window.layer.frame);
    text_layer_set_text_color(&date_layer, GColorWhite);
    text_layer_set_background_color(&date_layer, GColorClear);
    text_layer_set_font(&date_layer, font_date);
    text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter);
    layer_set_frame(&date_layer.layer, DATE_FRAME);
    layer_add_child(&window.layer, &date_layer.layer);

	// Add weather layer
	weather_layer_init(&weather_layer, GPoint(0, 90));
	layer_add_child(&window.layer, &weather_layer.layer);
	
	// Add updated layer
    text_layer_init(&updated_layer, window.layer.frame);
    text_layer_set_text_color(&updated_layer, GColorBlack);
    text_layer_set_background_color(&updated_layer, GColorClear);
    text_layer_set_font(&updated_layer, font_updated);
    text_layer_set_text_alignment(&updated_layer, GTextAlignmentLeft);
    layer_set_frame(&updated_layer.layer, UPDATED_FRAME);
    layer_add_child(&window.layer, &updated_layer.layer);

	// Add hi/low layer
    text_layer_init(&minmax_layer, window.layer.frame);
    text_layer_set_text_color(&minmax_layer, GColorBlack);
    text_layer_set_background_color(&minmax_layer, GColorClear);
    text_layer_set_font(&minmax_layer, font_updated);
    text_layer_set_text_alignment(&minmax_layer, GTextAlignmentLeft);
    layer_set_frame(&minmax_layer.layer, MINMAX_FRAME);
    layer_add_child(&window.layer, &minmax_layer.layer);

	
	
	http_register_callbacks((HTTPCallbacks){.failure=failed,.success=success,.reconnect=reconnect,.location=location}, (void*)ctx);