static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) {
    
    graphics_context_set_text_color(ctx, GColorBlack);
  
    if (cell_index->section == 0) {
        graphics_draw_text(ctx, "Y Combinator", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(5, -4, 139, 98), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        graphics_draw_text(ctx, "320 Pioneer Way\nMountain View\nCA 94041", fonts_get_system_font(FONT_KEY_GOTHIC_18), GRect(5, 20, 139, 78), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        graphics_draw_text(ctx, "*****@*****.**", fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(5, 76, 139, 22), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
    } else if (cell_index->section == 1) {
        float text_height = graphics_text_layout_get_content_size(thursday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, 0, 100, 44), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft).h;
        graphics_draw_text(ctx, thursday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, (44 / 2) - (text_height / 2) - 3, 100, text_height), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        graphics_draw_text(ctx, thursday_times[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(100, 10, 41, 20), GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
    } else if (cell_index->section == 2) {
        float text_height = graphics_text_layout_get_content_size(friday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, 0, 100, 44), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft).h;
        graphics_draw_text(ctx, friday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, (44 / 2) - (text_height / 2) - 3, 100, text_height), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        graphics_draw_text(ctx, friday_times[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(100, 10, 41, 20), GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
    } else if (cell_index->section == 3) {
        float text_height = graphics_text_layout_get_content_size(saturday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, 0, 100, 44), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft).h;
        graphics_draw_text(ctx, saturday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, (44 / 2) - (text_height / 2) - 3, 100, text_height), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        graphics_draw_text(ctx, saturday_times[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(100, 10, 41, 20), GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
    } else if (cell_index->section == 4) {
        float text_height = graphics_text_layout_get_content_size(sunday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, 0, 100, 44), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft).h;
        graphics_draw_text(ctx, sunday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, (44 / 2) - (text_height / 2) - 3, 100, text_height), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        graphics_draw_text(ctx, sunday_times[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(100, 10, 41, 20), GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
    }
}
Пример #2
0
void update_title_and_info(void) {
    GRect layerSize = GRect(0, 0, c_viewportWidth, c_viewportHeight);
    
    const char* text = g_holomesh->string_table.ptr[g_holomesh->info.craft_name_string].str.ptr;
    create_symbol_text(g_craft_name_lower, sizeof(g_craft_name_lower), text);
    
    APP_LOG(APP_LOG_LEVEL_DEBUG, "'%s' -> '%s'", text, g_craft_name_lower);
    
    GSize textSize = graphics_text_layout_get_content_size(
        text,
        g_font_sw,
        layerSize,
        0,
        GTextAlignmentLeft);
    
    GRect textRect = { GPoint(0, 0), textSize };
    layer_set_bounds((Layer*) textLayer, textRect);
    layer_set_bounds((Layer*) textLayerSym, textRect);
    
    text_layer_set_text(textLayer, text);
    text_layer_set_text(textLayerSym, g_craft_name_lower);

    GRect currentFrame = layer_get_bounds((Layer*) infoTextLayer);
    currentFrame.origin.y = textRect.origin.y + textRect.size.h / 2;
    layer_set_bounds((Layer*) infoTextLayer, currentFrame);

    set_new_stat_text();
}
Пример #3
0
static int16_t menuGetCellHeight(struct MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context) {

  if (cell_index->row >= activeListCount)
    return 10;

  GRect menu_bounds = layer_get_bounds(menu_layer_get_layer(menu_layer));

  // Subtract off 20px for checkbox
  if (activeList[cell_index->row].status == STATUS_BOUGHT) {
    menu_bounds.origin.x += 20;
    menu_bounds.size.w -= 20;
  }

  GSize sz = graphics_text_layout_get_content_size(activeList[cell_index->row].name,
						   font, menu_bounds,
						   GTextOverflowModeTrailingEllipsis,
						   GTextAlignmentLeft);

  // Leave some space around the menu item and truncate text if needed
  if (sz.h >= (menu_bounds.size.h - 40)) {
    sz.h = menu_bounds.size.h - 40;
  }
  // And ensure there is enough space for the checkbox at minimum
  else if (sz.h < 10) {
    // We add another 10 below...
    sz.h = 10;
  }

  // sz seems to leave 10 px on the top of letters but not enough space
  // for letters that are below the baseline.  So we add 10 balance this out.
  return sz.h + 10;
}
Пример #4
0
static void draw_strikethrough_on_item(GContext* ctx, Layer* cell_layer, TodoListItem* item) {
  graphics_context_set_compositing_mode(ctx, GCompOpClear);
  graphics_context_set_stroke_color(ctx, GColorBlack);
  graphics_context_set_fill_color(ctx, GColorBlack);

  GRect cell_bounds = layer_get_frame(cell_layer);

  static const int menu_cell_margin = 5;
  GSize text_cell_size = cell_bounds.size;
  text_cell_size.w -= 2 * menu_cell_margin;

  GRect text_cell_rect;
  text_cell_rect.origin = GPointZero;
  text_cell_rect.size = text_cell_size;

  GSize max_used_size = graphics_text_layout_get_content_size(item->text,
      fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), text_cell_rect,
      GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft);

  GRect strike_through;
  strike_through.origin = cell_bounds.origin;
  strike_through.origin.x += menu_cell_margin;
  strike_through.origin.y += cell_bounds.size.h / 2;
  strike_through.size = (GSize) { max_used_size.w, 2 };

  // Stretch the strikethrough to be slightly wider than the text
  static const int pixel_nudge = 2;
  strike_through.origin.x -= pixel_nudge;
  strike_through.size.w += 2 * pixel_nudge;

  graphics_fill_rect(ctx, strike_through, 0, GCornerNone);
}
Пример #5
0
static void main_window_load(Window *window) {
	//get root layer of window
	Layer *window_layer = window_get_root_layer(window);

	//get window dimensions
	GRect bounds = layer_get_bounds(window_layer);

	//add drawing layers
	s_clock_layer_outer = layer_create(GRect(EDGE, EDGE, bounds.size.w - (EDGE * 2), bounds.size.h - (EDGE * 2)));
	layer_set_update_proc(s_clock_layer_outer, draw_clock_layer_outer);
	layer_add_child(window_layer, s_clock_layer_outer);

	s_clock_layer_center = layer_create(GRect(EDGE, EDGE, bounds.size.w - (EDGE * 2), bounds.size.h - (EDGE * 2)));
	layer_set_update_proc(s_clock_layer_center, draw_clock_layer_center);
	layer_add_child(window_layer, s_clock_layer_center);

	s_clock_layer_inner = layer_create(GRect(EDGE, EDGE, bounds.size.w - (EDGE * 2), bounds.size.h - (EDGE * 2)));
	layer_set_update_proc(s_clock_layer_inner, draw_clock_layer_inner);
	layer_add_child(window_layer, s_clock_layer_inner);

	//init text time layer
	GSize max_size = graphics_text_layout_get_content_size(
		"00:00",
		fonts_get_system_font(FONT_KEY_GOTHIC_14),
		GRect(0, 0, bounds.size.w, bounds.size.h),
		GTextOverflowModeTrailingEllipsis,
		GTextAlignmentCenter
	);
	s_text_time = text_layer_create(GRect(
		(bounds.size.w / 2) - (max_size.w / 2),
		(bounds.size.h / 2) - (max_size.h / 2),
		max_size.w,
		max_size.h)
	);
	text_layer_set_background_color(s_text_time, GColorClear);
	text_layer_set_text_color(s_text_time, GColorBlack);
	text_layer_set_font(s_text_time, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	text_layer_set_text_alignment(s_text_time, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(s_text_time));
	toggle_text_time();

	//init inverter layer
	s_layer_invert = inverter_layer_create(GRect(0, 0, bounds.size.w, bounds.size.h));
	layer_add_child(window_layer, inverter_layer_get_layer(s_layer_invert));
	invert_face();

	//store clock layer bounds
	s_clock_bounds = layer_get_bounds(s_clock_layer_outer);
	s_clock_center = grect_center_point(&s_clock_bounds);

	//init hand paths
	s_hand_path_outer = gpath_create(&OUTER_HAND_POINTS);
	gpath_move_to(s_hand_path_outer, s_clock_center);

	s_hand_path_center = gpath_create(&CENTER_HAND_POINTS);
	gpath_move_to(s_hand_path_center, s_clock_center);

	s_hand_path_inner = gpath_create(&INNER_HAND_POINTS);
	gpath_move_to(s_hand_path_inner, s_clock_center);
}
Пример #6
0
static void update_loading_layer(Layer* layer, GContext* ctx) {
  LoadingData* data = (LoadingData*)layer_get_data(layer);
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_context_set_text_color(ctx, GColorWhite);
  graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
  GSize text_size = graphics_text_layout_get_content_size(data->message, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD), GRect(8, 0, 144 - 16, 150), GTextOverflowModeWordWrap, GTextAlignmentCenter);
  GRect text_pos = GRect(8, 75 - (text_size.h / 2) - 4, 144 - 16, text_size.h);
  graphics_draw_text(ctx, data->message, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD), text_pos, GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
}
Пример #7
0
static void draw_hour(Layer *this_layer, GContext *ctx, int offset, int tz_offset, int y, const char *font, int font_height) {
  GRect bounds = layer_get_bounds(this_layer);
  
  // min_per_pixel is scaled 10x to get more precision without having
  // to go to floating point
  int16_t min_per_pixel = (10*bounds.size.w)/100;
  
  time_t otime = cur_time+3600*(offset); 
  struct tm *tick_time = localtime(&otime);

  GRect frame = GRect(0+6*offset*min_per_pixel-(min_per_pixel*tick_time->tm_min)/10, y-font_height/2, 
                      bounds.size.w, font_height + 2);
  

  static char s_buffer[3];
  strftime(s_buffer, sizeof(s_buffer), clock_is_24h_style() ?
                                          "%H" : "%I", tick_time);
  
//    APP_LOG(APP_LOG_LEVEL_INFO, "%d: m: %d frame: %d y: %d %s", offset, min_per_pixel, frame.origin.x, frame.origin.y, s_buffer);
                                            
  graphics_draw_text(ctx, 
    s_buffer,
    fonts_get_system_font(font),
    frame,
    GTextOverflowModeTrailingEllipsis,
    GTextAlignmentCenter,
    NULL
  );
    
  if (offset == 0 && tz_offset != 0) {	  
	  GSize size = graphics_text_layout_get_content_size(s_buffer,
		fonts_get_system_font(font),
		frame,
		GTextOverflowModeTrailingEllipsis,
		GTextAlignmentCenter
	  );
  
	  frame.origin.x += size.w/2 + 10;
	  frame.origin.y += font_height - 18;
  
	  otime = cur_time+3600*(tz_offset+offset); 
	  tick_time = localtime(&otime);
	  strftime(s_buffer, sizeof(s_buffer), clock_is_24h_style() ?
											  "%H" : "%I", tick_time);
  
	  graphics_draw_text(ctx, 
		s_buffer,
		fonts_get_system_font(FONT_KEY_GOTHIC_18),
		frame,
		GTextOverflowModeTrailingEllipsis,
		GTextAlignmentCenter,
		NULL
	  );
	}
}
Пример #8
0
void menu_cell_draw_job(GContext* ctx, const Layer *cell_layer, const uint8_t index) {
  GRect bounds = layer_get_frame(cell_layer);
  
  // http://newscentral.exsees.com/item/ac0cacd0083161de2ffe8161eb40fa51-15e3726b28defcbc9eb59ade232b5de3
  #ifdef PBL_SDK_3
  graphics_context_set_compositing_mode(ctx, GCompOpSet); // transparency
  #else
  graphics_context_set_text_color(ctx, GColorBlack);
  #endif
  
  #ifdef PBL_ROUND
  uint8_t name_width=graphics_text_layout_get_content_size(jobs[index].Name, FONT_GOTHIC_24_BOLD, GRect(4+ROUND_MARGIN, -4, bounds.size.w-8-16-2*ROUND_MARGIN, 4+18), GTextOverflowModeFill, GTextAlignmentLeft).w;
  uint8_t num_width =graphics_text_layout_get_content_size(jobs_get_job_count_as_text(index), FONT_GOTHIC_18, GRect(4+ROUND_MARGIN, 2, bounds.size.w-8-2*ROUND_MARGIN, 14), GTextOverflowModeFill, GTextAlignmentRight).w;
  uint8_t total_width=name_width+num_width+12;
  graphics_draw_text(ctx, jobs[index].Name, FONT_GOTHIC_24_BOLD, GRect((bounds.size.w-total_width)/2, -4, name_width, 4+18), GTextOverflowModeFill, GTextAlignmentLeft, NULL);
  graphics_draw_text(ctx, jobs_get_job_count_as_text(index), FONT_GOTHIC_18, GRect((bounds.size.w-total_width)/2, 0, total_width, 14), GTextOverflowModeFill, GTextAlignmentRight, NULL);
  #else
  graphics_draw_text(ctx, jobs[index].Name, FONT_GOTHIC_24_BOLD, GRect(4+ROUND_MARGIN, -4, bounds.size.w-8-16-2*ROUND_MARGIN, 4+18), GTextOverflowModeFill, GTextAlignmentLeft, NULL);
  graphics_draw_text(ctx, jobs_get_job_count_as_text(index), FONT_GOTHIC_18, GRect(4+ROUND_MARGIN, 0, bounds.size.w-8-2*ROUND_MARGIN, 14), GTextOverflowModeFill, GTextAlignmentRight, NULL);
  #endif
  
  char* stickers=jobs[index].Stickers; // always returns a zero padded string
  if (*stickers) {
    while (*(stickers+EMOJI_CHILD_COLS)) stickers+=EMOJI_CHILD_COLS;
    #ifdef PBL_ROUND
    uint8_t n=0;
    while (stickers[n]) n++;
    #endif
    
    uint8_t cell = (bounds.size.w-2*ROUND_MARGIN) / EMOJI_CHILD_COLS;
    uint8_t marg = (cell - EMOJI_WIDTH)/2+1+PBL_IF_ROUND_ELSE(ROUND_MARGIN+(EMOJI_CHILD_COLS-n)*cell/2, 0);
    uint8_t i=0;
    while (*stickers) {
      uint8_t emoji=*stickers-1;
      graphics_draw_bitmap_in_rect(ctx, EMOJI_INDEX(emoji, PBL_IF_SDK_3_APLITE_ELSE(menu_cell_layer_is_highlighted(cell_layer), 0)), GRect(marg+cell*(i++),23, EMOJI_WIDTH, EMOJI_HEIGHT));
      stickers++;
    }
  } else {
    graphics_draw_text(ctx, "PRESS to add sticker", FONT_GOTHIC_14, GRect(4, 20, bounds.size.w-8, 16), GTextOverflowModeFill, GTextAlignmentCenter, NULL);
    if (!job_menu_visible()) graphics_draw_text(ctx, "HOLD to edit", FONT_GOTHIC_14, GRect(4, 36, bounds.size.w-8, 16), GTextOverflowModeFill, GTextAlignmentCenter, NULL);
  }
}
Пример #9
0
void resize_layers()
{
	int current_height = MIN_CARD_HEIGHT + 4 + graphics_text_layout_get_content_size(text_strings[current%CACHE_SIZE],
																				 fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD),GRect(0,0,142,168),GTextOverflowModeWordWrap, GTextAlignmentLeft).h;
	int previous_height = MIN_CARD_HEIGHT + 4 + graphics_text_layout_get_content_size(text_strings[previous%CACHE_SIZE],
																				  fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD),GRect(0,0,142,168),GTextOverflowModeWordWrap, GTextAlignmentLeft).h;
	if(current_height > MAX_CARD_HEIGHT)
		current_height = MAX_CARD_HEIGHT;
	
	if(previous_height > MAX_CARD_HEIGHT)
		previous_height = MAX_CARD_HEIGHT;
	
	int back_A_pos = layer_get_frame(back_layer_A).origin.y;
	int back_B_pos = layer_get_frame(back_layer_B).origin.y;
	int card_A_pos = layer_get_frame(card_layer_A).origin.y;
	int card_B_pos = layer_get_frame(card_layer_B).origin.y;
	
	
	if(current % 2 == 0)//if even
	{
		layer_set_frame(back_layer_A, GRect(0,back_A_pos,144,144));				//0
		layer_set_frame(back_layer_B, GRect(0,back_B_pos,144,144));				//144
		layer_set_frame(card_layer_A, GRect(0,card_A_pos,144,current_height));	//168-current
		layer_set_frame(card_layer_B, GRect(0,card_B_pos,144,previous_height));	//168+168-previous
	}
	else
	{
		layer_set_frame(back_layer_A, GRect(0,back_A_pos,144,144));				//144
		layer_set_frame(back_layer_B, GRect(0,back_B_pos,144,144));				//0
		layer_set_frame(card_layer_A, GRect(0,card_A_pos,144,previous_height));	//168+168-previous
		layer_set_frame(card_layer_B, GRect(0,card_B_pos,144,current_height));	//168-current
	}
	
	if(watchface_visible)
	{
		layer_set_frame(watchface_layer, GRect(0,0,144,168));
		layer_set_frame(card_layer_A, GRect(0,168-MIN_CARD_HEIGHT,144,current_height));
	}
	else
		layer_set_frame(watchface_layer, GRect(0,-168,144,168));
}
Пример #10
0
void thread_window_appear(Window *window)
{
	thread_offset = 0;
	thread_offset_reset = false;

	text_size = graphics_text_layout_get_content_size(GetThreadTitle(GetSelectedThreadID()), GetFont(), GRect(0, 0, 1024, THREAD_WINDOW_HEIGHT), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft);

	if(text_size.w > window_frame.size.w)
	{
		init_timer(app_timer_register(600, thread_scroll_timer_callback, NULL));
	}
}
Пример #11
0
static int16_t cb_get_cell_height(MenuLayer *ml, MenuIndex *i_cell, void *ctx) {
  ActionMenu *menu = ctx;

  GSize size = 
    graphics_text_layout_get_content_size( 
      menu->current_level->items[i_cell->row]->label, 
      fonts_get_system_font(ACTION_MENU_FONT), 
      GRect(0,0,144 - MENU_LAYER_OFFSET - 16,168), 
      GTextOverflowModeWordWrap, GTextAlignmentLeft);

  return size.h + 8 + 8;
}
Пример #12
0
static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) {

    graphics_context_set_text_color(ctx, GColorBlack);

    if (cell_index->section == 0) {
        graphics_draw_text(ctx, "Revolution UC", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(5, -4, 139, 98), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        graphics_draw_text(ctx, "Rhodes Hall 801", fonts_get_system_font(FONT_KEY_GOTHIC_18), GRect(5, 20, 139, 78), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        graphics_draw_text(ctx, "*****@*****.**", fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(5, 76, 139, 22), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
    } else if (cell_index->section == 2) {
        float text_height = graphics_text_layout_get_content_size(friday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, 0, 100, 44), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft).h;
        graphics_draw_text(ctx, friday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, (44 / 2) - (text_height / 2) - 3, 100, text_height), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        graphics_draw_text(ctx, friday_times[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(100, 10, 41, 20), GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
    } else if (cell_index->section == 3) {
        float text_height = graphics_text_layout_get_content_size(saturday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, 0, 100, 44), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft).h;
        graphics_draw_text(ctx, saturday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, (44 / 2) - (text_height / 2) - 3, 100, text_height), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        graphics_draw_text(ctx, saturday_times[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(100, 10, 41, 20), GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
    } else if (cell_index->section == 4) {
        float text_height = graphics_text_layout_get_content_size(sunday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, 0, 100, 44), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft).h;
        graphics_draw_text(ctx, sunday_events[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(3, (44 / 2) - (text_height / 2) - 3, 100, text_height), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        graphics_draw_text(ctx, sunday_times[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(100, 10, 41, 20), GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
    }
}
Пример #13
0
static void update_back(GContext* ctx, int image_no)
{
	//if same odd/even, selection = current, else selection = previous
	int selection = (image_no % 2 == current % 2)? current : previous;
	int card_height = MIN_CARD_HEIGHT + 4 + graphics_text_layout_get_content_size(text_strings[selection%CACHE_SIZE],
																				 fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD),GRect(0,0,142,168),GTextOverflowModeWordWrap, GTextAlignmentLeft).h;
	if(card_height > MAX_CARD_HEIGHT)
		card_height = MAX_CARD_HEIGHT;
	
	int image_pos = 0-(card_height / 4);
	
	graphics_draw_bitmap_in_rect(ctx, &back_bitmaps[image_no],GRect(0,image_pos,144,144));
}
/*
 * Draws textual feedback about the currently used update procedure.
 *
 * Y-coordinate is determined by s_time_feedback_y which is updated by update_animation().
 *
 */
static void draw_method_feedback(GContext *ctx, char *method_text) {
  GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_18);
  graphics_context_set_fill_color(ctx, GColorBlack);

  struct GRect text_bounds = {.size = s_window_size};
  text_bounds.size.h = (int16_t)(graphics_text_layout_get_content_size(method_text, font, text_bounds,
      GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter).h + 5); // space for descender
  text_bounds.origin.y = (int16_t)(s_time_feedback_y % (s_window_size.h - text_bounds.size.h));

  graphics_fill_rect(ctx, text_bounds, 0, GCornerNone);
  graphics_draw_text(ctx, method_text, font, text_bounds,
      GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
}
Пример #15
0
static void text_layer_update(Layer *layer, GContext *ctx) {
  char text[50];  //Buffer to hold text

  #if(PBL_COLOR)
    if(!grayscale)
      snprintf(text, sizeof(text), "%cr:%d\n%cg:%d\n%cb:%d", cursor==0 ?'>':' ', color[red], cursor==1?'>':' ', color[green], cursor==2?'>':' ', color[blue]);
    else 
  #endif
      snprintf(text, sizeof(text), "%d", color[gray]);
  
  
  GRect bounds = layer_get_bounds(layer);
  GFont font = fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK);
  GSize text_size = graphics_text_layout_get_content_size(text, font, bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft); // Get how big the text is
  
  #if(PBL_COLOR)
    // Set up text box
    if (text_size.w<111) text_size.w = 111;  // Stop text from boppin' around
    GRect text_rect = GRect((bounds.size.w - text_size.w)/2, (bounds.size.h - text_size.h)/2, text_size.w, text_size.h);
  
    // Set Replacement Color
    // Making sure text color isn't anywhere else within the rect (to prevent accidental replacements)
    GColor replace = (color[red]>127 || color[green]>127 || color[blue]>127) ? GColorOxfordBlue : GColorCeleste;
      
    // Write Text in the "Color To Be Replaced"
    graphics_context_set_text_color(ctx, replace);
    graphics_draw_text(ctx, text, font, text_rect, GTextOverflowModeTrailingEllipsis, grayscale ? GTextAlignmentCenter : GTextAlignmentLeft, NULL);

    // Replace the color the text was drawn in (limiting to the text_rect region)
    if(!grayscale)
      replace_color_in_rect_with_dithered(ctx, text_rect, replace, 128+color[red], 128+color[green], 128+color[blue]);
    else
      replace_color_in_rect_with_dithered(ctx, text_rect, replace, 128+color[gray], 128+color[gray], 128+color[gray]);
  #else
    // Set up text box
    text_size.h += 10; text_size.w += 10;    // Add some nice padding on B&W
    GRect text_rect = GRect((bounds.size.w - text_size.w)/2, (bounds.size.h - text_size.h)/2, text_size.w, text_size.h);

    // So, since there's only 2 colors on B&W, replacement color looks kinda bad.  Adding a solid background
    graphics_context_set_fill_color(ctx, GColorBlack);  // Text Background Color
    graphics_fill_rect(ctx, text_rect, 0, GCornerNone); // Draw Background Rectangle
  
    // Write Text in the "Color To Be Replaced" (GColorWhite on this B&W example)
    graphics_context_set_text_color(ctx, GColorWhite);
    graphics_draw_text(ctx, text, font, text_rect, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);

    // Replace the color (GColorWhite for example) the text was drawn in. Restricted to the text_rect region.
    replace_color_in_rect_with_dithered(ctx, text_rect, GColorWhite, 64+color[gray], 64+color[gray], 64+color[gray]);
  #endif
}
Пример #16
0
static void centerTextLayer(const char *text) {
	GSize size;
	static GRect newFrame;
	static Layer *layer = NULL;

	if (layer == NULL) {
		layer = text_layer_get_layer(textLayer);
		newFrame = textFrame;
	}

	size = graphics_text_layout_get_content_size(text, font, textFrame, GTextOverflowModeWordWrap, GTextAlignmentCenter);
	newFrame.origin.y = 84-size.h/2;
	layer_set_frame(text_layer_get_layer(textLayer), newFrame);
	text_layer_set_text(textLayer, text);
}
Пример #17
0
static void draw_box(Layer *layer, GContext *ctx, GColor border_color, GColor back_color, GColor text_color, char *text) {
  GRect bounds = layer_get_bounds(layer);
  graphics_context_set_fill_color(ctx, back_color);
  graphics_fill_rect(ctx, layer_get_bounds(layer), PBL_IF_RECT_ELSE(8, 0), GCornersAll);
  IF_3(graphics_context_set_stroke_width(ctx, 3)); 
  graphics_context_set_stroke_color(ctx, border_color);
  graphics_draw_round_rect(ctx, layer_get_bounds(layer), PBL_IF_RECT_ELSE(8, 0));
  graphics_context_set_text_color(ctx, text_color);
  GSize text_size = graphics_text_layout_get_content_size(text, s_res_gothic_18_bold, 
                                                          GRect(5, 5, bounds.size.w-10, bounds.size.h-2), 
                                                          GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter);
  graphics_draw_text(ctx, text, s_res_gothic_18_bold, 
                     GRect(5, ((bounds.size.h-text_size.h)/2)-4, bounds.size.w-10, text_size.h), 
                     GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
}
Пример #18
0
static void draw_info(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);
  graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorPictonBlue, GColorBlack));
  graphics_fill_rect(ctx, layer_get_bounds(layer), 8, GCornersAll);
  IF_B(graphics_context_set_stroke_width(ctx, 3)); 
  graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorBlueMoon, GColorWhite));
  graphics_draw_round_rect(ctx, layer_get_bounds(layer), 8);
  graphics_context_set_text_color(ctx, COLOR_FALLBACK(GColorBlack, GColorWhite));
  GSize text_size = graphics_text_layout_get_content_size(s_info, s_res_gothic_18_bold, 
                                                          GRect(5, 5, bounds.size.w-10, bounds.size.h-10), 
                                                          GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter);
  graphics_draw_text(ctx, s_info, s_res_gothic_18_bold, 
                     GRect(5, ((bounds.size.h-text_size.h)/2)-4, bounds.size.w-10, text_size.h), 
                     GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
}
Пример #19
0
void menu_cell_draw_other(GContext* ctx, const Layer *cell_layer, const char *title, GBitmap ** icon) {
  GRect bounds = layer_get_frame(cell_layer);
  
  #ifndef PBL_SDK_3
  graphics_context_set_text_color(ctx, GColorBlack);
  #endif
  
  graphics_draw_text(ctx, title, FONT_GOTHIC_24_BOLD, GRect(MENU_ICON_SPACE, -4, bounds.size.w-MENU_ICON_SPACE, 4+18), GTextOverflowModeFill, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft), NULL);
  #ifdef PBL_ROUND
  uint8_t text_width=graphics_text_layout_get_content_size(title, FONT_GOTHIC_24_BOLD, GRect(MENU_ICON_SPACE, -4, bounds.size.w-MENU_ICON_SPACE, 4+18), GTextOverflowModeFill, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft)).w;  
  if (icon) graphics_draw_bitmap_in_rect(ctx, icon[PBL_IF_SDK_3_ELSE(menu_cell_layer_is_highlighted(cell_layer), 0)], GRect((bounds.size.w-text_width)/2-16-6,(bounds.size.h-16)/2, 16, 16));
  #else
  if (icon) graphics_draw_bitmap_in_rect(ctx, icon[PBL_IF_SDK_3_ELSE(menu_cell_layer_is_highlighted(cell_layer), 0)], GRect(6,(bounds.size.h-16)/2, 16, 16));
  #endif
}
Пример #20
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  Tuple *tuple = dict_find(iterator, 0);
  if (!tuple) {
    APP_LOG(APP_LOG_LEVEL_ERROR, "The tuple was missing!");
    return;
  }
  s_speaking_enabled = true;
  APP_LOG(APP_LOG_LEVEL_INFO, "Got message: %s", tuple->value->cstring);
  snprintf(s_defn_buffer, sizeof(s_defn_buffer), "%s", tuple->value->cstring);
  //where the word and def show up
  
  GSize size = graphics_text_layout_get_content_size(s_defn_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD),
                                        GRect(0, 0, 134, 1000), GTextOverflowModeWordWrap, GTextAlignmentCenter);
  layer_set_frame((Layer *)s_def_layer, GRect(5, 40, 134, size.h));
  scroll_layer_set_content_size(s_scroll_layer, GSize(144, 50 + size.h));
  text_layer_set_text(s_word_layer, s_last_text_buffer); 
  text_layer_set_text(s_def_layer, s_defn_buffer);
  window_stack_push(s_def_window, true);
}
Пример #21
0
void note_data_received(DictionaryIterator* iterator){
  
  Tuple *t = dict_read_first(iterator);

  // For all items
  while(t != NULL) {
    // Which key was received?
    
      APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d ", (int)t->key);
    
  
    // Look for next item
    t = dict_read_next(iterator);
  }
  uint16_t location = dict_find(iterator, 1)->value->uint16;
  uint16_t segmentLength = dict_find(iterator, 2)->value->uint16;
  memcpy((void *) &fullNote[location], dict_find(iterator, 4)->value->cstring, segmentLength);
  GSize maxSize = graphics_text_layout_get_content_size(fullNote, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD),
                                                        GRect(0, 0, 144, 1000), GTextOverflowModeWordWrap, GTextAlignmentLeft);
  if (maxSize.h < 168 - 16)
    maxSize.h = 168 - 16;

  text_layer_set_size(fullNoteText, maxSize);
  scroll_layer_set_content_size(scroller, maxSize);


  text_layer_set_text(fullNoteText, fullNote);

  if (segmentLength == 75){
    DictionaryIterator *iterator;
    app_message_outbox_begin(&iterator);
    
    dict_write_uint8(iterator, 0, 3);
    dict_write_uint16(iterator, 1, location + 75);
    
    app_message_outbox_send();
    
    app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
    app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
  }

}
Пример #22
0
void set_new_stat_text(void) {
    const holomesh_tag_t* tag = &g_holomesh->tags.ptr[
        (++g_current_stat) % g_holomesh->tags.size
    ];

    const char* stat = g_holomesh->string_table.ptr[tag->name_string].str.ptr;

    GRect currentFrame = layer_get_bounds(text_layer_get_layer(infoTextLayer));

    currentFrame.size = GSize(c_viewportWidth, c_viewportHeight);
    currentFrame.size = graphics_text_layout_get_content_size(
        stat,
        g_font_info,
        currentFrame,
        0,
        GTextAlignmentLeft);
    
    layer_set_bounds(text_layer_get_layer(infoTextLayer), currentFrame);
    text_layer_set_text(infoTextLayer, stat);
}
Пример #23
0
static void update_card(GContext* ctx, int card_no)
{
	int title_height = graphics_text_layout_get_content_size(title_strings[card_no],fonts_get_system_font(FONT_KEY_GOTHIC_18),GRect(0,0,142-54,168),GTextOverflowModeWordWrap, GTextAlignmentLeft).h;
	
	//card
	graphics_context_set_fill_color(ctx, GColorWhite);
	if(title_height > 18)
		graphics_fill_rect(ctx, GRect(0, 12, 144, 168), 0, GCornerNone);
	else
		graphics_fill_rect(ctx, GRect(0, 26, 144, 168), 0, GCornerNone);
	
	//icon box
	graphics_context_set_stroke_color(ctx, GColorWhite);
	graphics_draw_round_rect(ctx,GRect(144-54, 0, 54, 54),3);		
	graphics_context_set_fill_color(ctx, GColorBlack);
	graphics_fill_rect(ctx, GRect(144-53, 1, 52, 52), 3, GCornersAll);
	
	//icon
	graphics_draw_bitmap_in_rect(ctx, &icon_bitmaps[card_no],GRect(144-51,3,48,48));
	
	//text
	graphics_context_set_text_color(ctx, GColorBlack);	
	if(title_height > 18)
		graphics_draw_text(ctx, 
						   title_strings[card_no],  
						   fonts_get_system_font(FONT_KEY_GOTHIC_18),
						   GRect( 2, 12, 142-54, 20),
						   GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
	else
		graphics_draw_text(ctx, 
					   title_strings[card_no],  
					   fonts_get_system_font(FONT_KEY_GOTHIC_18),
					   GRect( 2, 26, 142-54, 20),
					   GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
	
	graphics_draw_text(ctx, 
					   text_strings[card_no],  
					   fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD),
					   GRect( 2, MIN_CARD_HEIGHT - 7, 142, 60),
					   (expanded_visible)?GTextOverflowModeWordWrap:GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
}
Пример #24
0
static void draw_load_screen(Layer* layer, GContext* ctx) {

    GRect bounds = layer_get_bounds(layer);
    graphics_context_set_text_color(ctx, GColorBlack);
    graphics_context_set_fill_color(ctx, GColorWhite);
    graphics_fill_rect(ctx, bounds, 0, GCornerNone);

    const char* text = "kangaete imasu";
    GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD);
    GRect box = layer_get_bounds(layer);
    GTextOverflowMode overflow = GTextOverflowModeWordWrap;
    GTextAlignment alignment = GTextAlignmentCenter;

    GSize size = graphics_text_layout_get_content_size(
        text, font, box, overflow, alignment);
    box.origin.y = (box.size.h - size.h) / 2;

    graphics_draw_text(ctx, text, font, box, overflow, alignment, NULL);
    if (s_result_text[0]) {
        box.origin.y += size.h;
        graphics_draw_text(ctx, s_result_text, font, box, overflow, alignment, NULL);
    }
}
Пример #25
0
void update_date_display(struct tm* tick_time) {
//    strftime(g_date_str, sizeof(g_date_str), "%A\n%x", tick_time);
    strftime(g_date_str, sizeof(g_date_str), "%a %b %d", tick_time);
    for (char* c = g_date_str; *c; ++c) {
        if (*c >= 'a' && *c <= 'z') *c += 'A' - 'a';
    }
    
    GRect layerSize = GRect(0, 0, c_viewportWidth, c_viewportHeight);

    GSize dateSize = graphics_text_layout_get_content_size(
        g_date_str,
        g_font_info,
        layerSize,
        0,
        GTextAlignmentLeft);
    
    layerSize.origin.x = c_viewportWidth - dateSize.w - DT_EDGE_PAD;
    layerSize.origin.y = c_viewportHeight - dateSize.h;
    layerSize.size = dateSize;
    
    text_layer_set_text(dateLayer, g_date_str);
    layer_set_frame((Layer*) dateLayer, layerSize);
}
Пример #26
0
static void draw_onoff(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);
  GColor border_color;
  GColor fill_color;
#ifdef PBL_COLOR
  switch (s_onoff_mode) {
    case MODE_OFF:
      border_color = GColorRed;
      fill_color = GColorMelon;
      break;
    case MODE_ON:
      border_color = GColorJaegerGreen;
      fill_color = GColorMintGreen;
      break;
    case MODE_ACTIVE:
      border_color = GColorChromeYellow;
      fill_color = GColorPastelYellow;
      break;
  }
#else
  border_color = GColorWhite;
  fill_color = GColorBlack;
#endif
  graphics_context_set_fill_color(ctx, fill_color);
  graphics_fill_rect(ctx, layer_get_bounds(layer), 8, GCornersAll);
  IF_B(graphics_context_set_stroke_width(ctx, 3)); 
  graphics_context_set_stroke_color(ctx, border_color);
  graphics_draw_round_rect(ctx, layer_get_bounds(layer), 8);
  graphics_context_set_text_color(ctx, COLOR_FALLBACK(GColorBlack, GColorWhite));
  GSize text_size = graphics_text_layout_get_content_size(s_onoff_text, s_res_gothic_18_bold, 
                                                          GRect(5, 5, bounds.size.w-10, bounds.size.h-10), 
                                                          GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter);
  graphics_draw_text(ctx, s_onoff_text, s_res_gothic_18_bold, 
                     GRect(5, ((bounds.size.h-text_size.h)/2)-4, bounds.size.w-10, text_size.h), 
                     GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
}
Пример #27
0
static void update_proc(Layer *layer, GContext *ctx) {
  // Custom drawing happens here!
	GRect bounds = layer_get_bounds(layer);
	
	graphics_context_set_fill_color(ctx, GColorBlack);
	graphics_fill_rect(ctx, bounds, 0, 0);
	
	if(center){
		return;
	}
	
	BatteryChargeState state = battery_state_service_peek();
	
	char batteryT[5];
	snprintf(batteryT, sizeof(batteryT), "%d%%", state.charge_percent);
	
	GSize size1 = graphics_text_layout_get_content_size(batteryT, fonts_get_system_font(FONT_KEY_GOTHIC_24),
																											bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentRight);
	
	GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_18);
	
	#ifdef PBL_COLOR
		graphics_context_set_text_color(ctx, state.charge_percent>20 ? GColorGreen : GColorRed);
	#else
		graphics_context_set_fill_color(ctx, GColorWhite);
	#endif
	
	graphics_draw_text(ctx, batteryT, font,
										 GRect(bounds.size.w - BATT_PADING - size1.w, bounds.size.h/2-size1.h/2, size1.w, size1.h),
										 GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
	
	#ifdef PBL_COLOR
		graphics_context_set_fill_color(ctx, connection_service_peek_pebble_app_connection() ? GColorGreen : GColorRed);
	#else
		graphics_context_set_fill_color(ctx, connection_service_peek_pebble_app_connection() ? GColorWhite : GColorBlack);
	#endif
	
	graphics_fill_circle(ctx,
											 GPoint(bounds.size.w - CONNECTED_CIR_PADING - CONNECTED_CIR_RADIUS * PBL_IF_ROUND_ELSE(3, 1),
															PBL_IF_RECT_ELSE(CONNECTED_CIR_PADING + CONNECTED_CIR_RADIUS,
																							 bounds.size.h/2-size1.h/2-CONNECTED_CIR_RADIUS-CONNECTED_CIR_PADING)),
											 CONNECTED_CIR_RADIUS);
	
	
	HealthValue steps = health_service_sum_today(HealthMetricStepCount);
	
	char steps_string[10];
	if(steps >= 1000){
		snprintf(steps_string, sizeof(steps_string), "%d.%dK", (int)steps/1000, (int)((float)(steps-(steps/1000)*1000)/100));
	}else{
		snprintf(steps_string, sizeof(steps_string), "%d", (int)steps);
	}
	
	
	GSize size2 = graphics_text_layout_get_content_size(steps_string, fonts_get_system_font(FONT_KEY_GOTHIC_24),
																											bounds, GTextOverflowModeTrailingEllipsis, GTextAlignmentRight);
	
	graphics_context_set_text_color(ctx, GColorGreen);
	graphics_draw_text(ctx, steps_string, font,
										 GRect(bounds.size.w - HEALTH_PADING * PBL_IF_ROUND_ELSE(3, 1) - size2.w,
													 PBL_IF_RECT_ELSE(bounds.size.h-size2.h-HEALTH_PADING, bounds.size.h/2+HEALTH_PADING),
													 size2.w, size2.h),
										 GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
	
	
}
Пример #28
0
// @private Called to redraw the layer
static void OutputTextLabel_Redraw(struct Layer* layer, GContext* ctx) {
	
	// Get class container
	OutputTextLabel* label = layer_get_data(layer);
	
	// Get window bounds
	GRect bounds = layer_get_bounds(layer);
	
	// Clear the view area
	graphics_context_set_fill_color(ctx, GColorBlack);
	graphics_fill_rect(ctx, bounds, 0, 0);
	
	// Check if got text
	if (strlen(label->text) == 0)
		return;
	
	// Check if can use giant font
	if (label->giantFont) {
		
		// Get bounds of text
		GSize textSize = graphics_text_layout_get_content_size(label->text, label->giantFont, bounds, GTextOverflowModeWordWrap, GTextAlignmentCenter);
		if (textSize.h < bounds.size.h) {
			
			// We can use the large font, draw it!
			graphics_context_set_stroke_color(ctx, GColorWhite);
			graphics_draw_text(ctx, label->text, label->giantFont, GRect(0, bounds.size.h / 2 - textSize.h / 2, bounds.size.w, bounds.size.h), GTextOverflowModeWordWrap, GTextAlignmentCenter, 0);
			return;
			
		}
		
	}
	
	// Check if can use large font
	if (label->largeFont) {
		
		// Get bounds of text
		GSize textSize = graphics_text_layout_get_content_size(label->text, label->largeFont, bounds, GTextOverflowModeWordWrap, GTextAlignmentCenter);
		if (textSize.h < bounds.size.h) {
			
			// We can use the large font, draw it!
			graphics_context_set_stroke_color(ctx, GColorWhite);
			graphics_draw_text(ctx, label->text, label->largeFont, GRect(0, bounds.size.h / 2 - textSize.h / 2, bounds.size.w, bounds.size.h), GTextOverflowModeWordWrap, GTextAlignmentCenter, 0);
			return;
			
		}
		
	}
	
	// Check if can use medium font
	if (label->mediumFont) {
		
		// Get bounds of text
		GSize textSize = graphics_text_layout_get_content_size(label->text, label->mediumFont, bounds, GTextOverflowModeWordWrap, GTextAlignmentCenter);
		if (textSize.h < bounds.size.h) {
			
			// We can use the large font, draw it!
			graphics_context_set_stroke_color(ctx, GColorWhite);
			graphics_draw_text(ctx, label->text, label->mediumFont, GRect(0, bounds.size.h / 2 - textSize.h / 2, bounds.size.w, bounds.size.h), GTextOverflowModeWordWrap, GTextAlignmentCenter, 0);
			return;
			
		}
		
	}
	
	// Check if can use small font
	if (label->smallFont) {
		
		// Get bounds of text
		GSize textSize = graphics_text_layout_get_content_size(label->text, label->smallFont, bounds, GTextOverflowModeWordWrap, GTextAlignmentCenter);
		
		// Draw it no matter the size
		graphics_context_set_stroke_color(ctx, GColorWhite);
		graphics_draw_text(ctx, label->text, label->smallFont, GRect(0, MAX(bounds.size.h / 2 - textSize.h / 2, 0), bounds.size.w, bounds.size.h), GTextOverflowModeWordWrap, GTextAlignmentCenter, 0);
		return;
		
	}
	
}
Пример #29
0
static void my_face_draw(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);

  // Draw a white filled circle a radius of half the layer height
  graphics_context_set_fill_color(ctx, GColorWhite);
  const int16_t half_h = bounds.size.h / 2;
  
  graphics_draw_circle (ctx, GPoint(half_h, half_h), 90);
  
  
  
  
  graphics_context_set_stroke_width(ctx, 2);
  graphics_context_set_text_color(ctx, GColorBlack);
  
  GPoint center = grect_center_point(&bounds);                   
                                     
  for(int i=0; i<12; i++) {
    int angle = i * 30;
  
    static char buf[] = "000";    /* <-- implicit NUL-terminator at the end here */
    snprintf(buf, sizeof(buf), "%02d", i==0?12:i);
    int ascender = 8;
    GPoint text_point = gpoint_from_polar(grect_crop(bounds, 50), GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(angle));
    GRect text_rect = GRect(text_point.x - 24, text_point.y - 24, 48, 48);

    GSize size = graphics_text_layout_get_content_size(buf,
                                                       fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD),
                                                       text_rect, GTextOverflowModeWordWrap, GTextAlignmentLeft);
      
    ///graphics_draw_bitmap_in_rect(ctx, image, layer_get_bounds(layer));
    
    text_rect.size = size;
    text_rect.size.h -= ascender;
    text_rect.origin = GPoint(text_point.x - size.w/2, text_point.y -size.h/2);
    
    graphics_draw_text(ctx, buf,
                       fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD),
                       grect_inset(text_rect, GEdgeInsets4(-8, 0, 0, 0)),
                       GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
 

    //graphics_draw_rect(ctx, text_rect);
    // Draw hour
    
   graphics_context_set_stroke_color(ctx, GColorBlack);
    graphics_context_set_stroke_width(ctx, 2);
    graphics_draw_line(ctx,
                       gpoint_from_polar(grect_crop(bounds, 30), GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(angle)),
                       gpoint_from_polar(bounds, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(angle)));    
    
    angle += 15;
    // Draw half hour
    
   graphics_context_set_stroke_color(ctx, GColorDarkGray);
    graphics_context_set_stroke_width(ctx, 2);
    graphics_draw_line(ctx,
                       gpoint_from_polar(grect_crop(bounds, 10), GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(angle)),
                       gpoint_from_polar(bounds, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(angle)));
    
    
    angle += 7.5;
    // Draw quarter hours
    
   graphics_context_set_stroke_color(ctx, GColorDarkGray);
    graphics_context_set_stroke_width(ctx, 2);
    graphics_draw_line(ctx,
                       gpoint_from_polar(grect_crop(bounds, 10), GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(angle)),
                       gpoint_from_polar(bounds, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(angle)));
    angle -= 15;
    graphics_draw_line(ctx,
                       gpoint_from_polar(grect_crop(bounds, 10), GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(angle)),
                       gpoint_from_polar(bounds, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(angle)));
  } 

  
}
Пример #30
0
//-----------------------------------------------------------------------------------------------------------------------
static void face_update_proc(Layer *layer, GContext *ctx) 
{
	GRect bounds = layer_get_bounds(layer);
	GPoint center = grect_center_point(&bounds), clock_center = GPoint(200, 200);
	
	//Draw Mask
#if defined(PBL_RECT)
	if (CfgData.circle)
		graphics_draw_bitmap_in_rect(ctx, bmp_mask, bounds);
#endif		
	
	graphics_context_set_stroke_color(ctx, CfgData.circle || CfgData.inv ? GColorBlack : GColorWhite);
	graphics_context_set_text_color(ctx, CfgData.circle || CfgData.inv ? GColorBlack : GColorWhite);
	graphics_context_set_fill_color(ctx, CfgData.circle || CfgData.inv ? GColorBlack : GColorWhite);
	
	//TRIG_MAX_ANGLE * t->tm_sec / 60
	int32_t angle = (TRIG_MAX_ANGLE * (((aktHH % 12) * 60) + (aktMM / 1))) / (12 * 60), 
		sinl = sin_lookup(angle), cosl = cos_lookup(angle);
	int16_t radV = 144, radD = 175, radT = 135;
	
	GPoint sub_center, ptLin, ptDot;
	sub_center.x = (int16_t)(sinl * (int32_t)radV / TRIG_MAX_RATIO) + clock_center.x;
	sub_center.y = (int16_t)(-cosl * (int32_t)radV / TRIG_MAX_RATIO) + clock_center.y;

	GRect sub_rect = {
		.origin = GPoint(sub_center.x - bounds.size.w / 2, sub_center.y - bounds.size.h / 2),
		.size = bounds.size
	};

	for (int32_t i = 1; i<=72; i++)
	{
		int32_t angleC = TRIG_MAX_ANGLE * i / 72,
			sinC = sin_lookup(angleC), cosC = cos_lookup(angleC);
		
		ptLin.x = (int16_t)(sinC * (int32_t)(radD) / TRIG_MAX_RATIO) + clock_center.x - sub_rect.origin.x;
		ptLin.y = (int16_t)(-cosC * (int32_t)(radD) / TRIG_MAX_RATIO) + clock_center.y - sub_rect.origin.y;

		if (ptLin.x > -40 && ptLin.x < bounds.size.w+40 && ptLin.y > -40 && ptLin.y < bounds.size.h+40)
		{
			if ((i % 6) == 0)
			{
				gpath_move_to(hour_path, ptLin);
				gpath_rotate_to(hour_path, angleC);
				gpath_draw_filled(ctx, hour_path);
				
				int16_t nHrPnt = i/6;
				if (clock_is_24h_style())
					if ((aktHH > 9 && aktHH < 21 && nHrPnt > 0 && nHrPnt < 6) ||
						(((aktHH > 15 && aktHH <= 23) || (aktHH >= 0 && aktHH < 3)) && nHrPnt >= 6  && nHrPnt <= 12))
						nHrPnt += 12;
				
				snprintf(hhBuffer, sizeof(hhBuffer), "%d", nHrPnt);
				GSize txtSize = graphics_text_layout_get_content_size(hhBuffer, 
					fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD), 
					bounds, GTextOverflowModeWordWrap, GTextAlignmentCenter);

				ptDot.x = (int16_t)(sinC * (int32_t)radT / TRIG_MAX_RATIO) + clock_center.x - sub_rect.origin.x;
				ptDot.y = (int16_t)(-cosC * (int32_t)radT / TRIG_MAX_RATIO) + clock_center.y - sub_rect.origin.y;

				graphics_draw_text(ctx, hhBuffer, 
					fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD), 
					GRect(ptDot.x-txtSize.w/2, ptDot.y-txtSize.h/2, txtSize.w, txtSize.h), 
					GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
			}
			else if ((i % 3) == 0)
			{
				gpath_move_to(mins_path, ptLin);
				gpath_rotate_to(mins_path, angleC);
				gpath_draw_filled(ctx, mins_path);
			}
			else
			{
				gpath_move_to(secs_path, ptLin);
				gpath_rotate_to(secs_path, angleC);
				gpath_draw_filled(ctx, secs_path);
			}
		}
	}

	//Draw Hand Path
	ptLin.x = (int16_t)(sinl * (int32_t)(radV+111) / TRIG_MAX_RATIO) + clock_center.x - sub_rect.origin.x;
	ptLin.y = (int16_t)(-cosl * (int32_t)(radV+111) / TRIG_MAX_RATIO) + clock_center.y - sub_rect.origin.y;
	
#ifdef PBL_COLOR
	graphics_context_set_fill_color(ctx, GColorOrange);
#else
	graphics_context_set_fill_color(ctx, CfgData.circle || CfgData.inv ? GColorBlack : GColorWhite);
#endif

	gpath_move_to(hand_path, ptLin);
	gpath_rotate_to(hand_path, angle);
	gpath_draw_filled(ctx, hand_path);

	//Only if no Mask...
	if (!CfgData.circle) 
	{
		graphics_context_set_stroke_color(ctx, CfgData.inv ? GColorWhite : GColorBlack);
		gpath_draw_outline(ctx, hand_path);
	}
	
	//Draw Separator Lines
	graphics_context_set_stroke_color(ctx, CfgData.inv ? GColorBlack : GColorWhite);
#if defined(PBL_RECT)
	if (CfgData.sep && !CfgData.circle)
		graphics_draw_line(ctx, GPoint(10, bounds.size.h-1), GPoint(bounds.size.w-10, bounds.size.h-1));
#elif defined(PBL_ROUND)
	//Radio & Battery
	graphics_context_set_fill_color(ctx, CfgData.inv ? GColorWhite : GColorBlack);
	if (CfgData.smart)
	{	
		graphics_fill_radial(ctx, GRect(-20, center.y-20, 40, 40), GOvalScaleModeFitCircle, 20, DEG_TO_TRIGANGLE(5), DEG_TO_TRIGANGLE(175));
		graphics_fill_radial(ctx, GRect(bounds.size.w-20, center.y-20, 40, 40), GOvalScaleModeFitCircle, 20, DEG_TO_TRIGANGLE(185), DEG_TO_TRIGANGLE(355));
		if (CfgData.sep)
		{
			graphics_draw_arc(ctx, GRect(-20, center.y-20, 40, 40), GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(5), DEG_TO_TRIGANGLE(175));
			graphics_draw_arc(ctx, GRect(bounds.size.w-20, center.y-20, 40, 40), GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(190), DEG_TO_TRIGANGLE(350));
		}
	}

	//DateTime
	if (!CfgData.fsm)
	{
		graphics_fill_radial(ctx, GRect(center.x-100, bounds.size.h-n_bottom_margin-5, 200, 200), GOvalScaleModeFitCircle, n_bottom_margin+5, DEG_TO_TRIGANGLE(275), DEG_TO_TRIGANGLE(445));
		graphics_draw_text(ctx, ddmmyyyyBuffer, digitS, GRect(0, bounds.size.h-n_bottom_margin-5, bounds.size.w, n_bottom_margin), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
		if (CfgData.sep)
			graphics_draw_arc(ctx, GRect(center.x-100, bounds.size.h-n_bottom_margin-5, 200, 200), GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(275), DEG_TO_TRIGANGLE(445));
	}
#endif
}
//-----------------------------------------------------------------------------------------------------------------------
static void handle_tick(struct tm *tick_time, TimeUnits units_changed) 
{
	if (b_initialized)
	{
		aktHH = tick_time->tm_hour;
		aktMM = tick_time->tm_min;
		layer_mark_dirty(face_layer);
	}
	
#if defined(PBL_RECT)
	strftime(ddmmyyyyBuffer, sizeof(ddmmyyyyBuffer), 
		//true ? "%a %d.%b" :
		CfgData.datefmt == 1 ? "%d-%m-%Y" : 
		CfgData.datefmt == 2 ? "%d/%m/%Y" : 
		CfgData.datefmt == 3 ? "%m/%d/%Y" : 
		CfgData.datefmt == 4 ? "%Y-%m-%d" :  
		CfgData.datefmt == 5 ? "%d.%m.%y" : 
		CfgData.datefmt == 6 ? "%d-%m-%y" : 
		CfgData.datefmt == 7 ? "%d/%m/%y" : 
		CfgData.datefmt == 8 ? "%m/%d/%y" : 
		CfgData.datefmt == 9 ? "%y-%m-%d" : 
		CfgData.datefmt == 10 ? "%a %d.%m." : 
		CfgData.datefmt == 11 ? "%a %d.%b" : "%d.%m.%Y", tick_time);
#elif defined(PBL_ROUND)
	strftime(ddmmyyyyBuffer, sizeof(ddmmyyyyBuffer), 
		//true ? "%a %d." :
		CfgData.datefmt == 1 ? "%d-%m" : 
		CfgData.datefmt == 2 ? "%d/%m" : 
		CfgData.datefmt == 3 ? "%m/%d" : 
		CfgData.datefmt == 4 ? "%m-%d" :  
		CfgData.datefmt == 5 ? "%d.%m" : 
		CfgData.datefmt == 6 ? "%d-%m" : 
		CfgData.datefmt == 7 ? "%d/%m" : 
		CfgData.datefmt == 8 ? "%m/%d" : 
		CfgData.datefmt == 9 ? "%m-%d" : 
		CfgData.datefmt == 10 ? "%a %d." : 
		CfgData.datefmt == 11 ? "%a %d." : "%d.%m", tick_time);
#endif
	/*
	snprintf(ddmmyyyyBuffer, sizeof(ddmmyyyyBuffer), 
		CfgData.datefmt == 1 ? "%d-%d-%d" : 
		CfgData.datefmt == 2 ? "%d/%d/%d" : 
		CfgData.datefmt == 3 ? "%d/%d/%d" : 
		CfgData.datefmt == 4 ? "%d-%d-%d" : "%d.%d.%d", 88, 88, 8888);
	*/
	//strcpy(ddmmyyyyBuffer, "00000");
	
	text_layer_set_text(date_layer, ddmmyyyyBuffer);
	
	//Hourly vibrate
	if (CfgData.vibr && tick_time->tm_min == 0)
		vibes_enqueue_custom_pattern(vibe_pat_hr); 	
}
//-----------------------------------------------------------------------------------------------------------------------
static void timerCallback(void *data) 
{
	if ((int)data == TIMER_ANIM_FACE && !b_initialized)
	{
		time_t temp = time(NULL);
		struct tm *t = localtime(&temp);
		if ((aktHH % 12) != (t->tm_hour % 12) || aktMM != t->tm_min)
		{
			int16_t nStep = (aktHH % 12) != (t->tm_hour % 12) ? 5 : 1;
			if ((t->tm_hour % 12) < 6)
			{
				//Initial Value? Set correct initial
				if (aktHH == 0 && aktMM == 0)
				{
					aktHH = t->tm_hour >= 12 ? 12 : 0;
					aktMM = 0;
				}

				if (aktMM < 60-nStep)
					aktMM += nStep;
				else
				{
					aktMM = 0;
					aktHH++;
				}
			}
			else
			{
				//Initial Value? Set correct initial
				if (aktHH == 0 && aktMM == 0)
				{
					aktHH = t->tm_hour > 12 ? 23 : 11;
					aktMM = 60;
				}
				
				if (aktMM > nStep)
					aktMM -= nStep;
				else
				{
					aktMM = 60;
					aktHH--;
				}
				
				//Little workaround if time is close to the 12 o'clock
				if ((aktHH % 12) == (t->tm_hour % 12) && aktMM < t->tm_min)
					aktMM = t->tm_min;
			}

			layer_mark_dirty(face_layer);
			timer_face = app_timer_register(TIMER_ANIM_FACE_MS, timerCallback, (void*)TIMER_ANIM_FACE);
		}
		else
			b_initialized = true;
	}
	else if ((int)data == TIMER_ANIM_BATT && b_charging)
	{
		int nImage = 10 - (aktBattAnim / 10);
		
		bitmap_layer_set_bitmap(battery_layer, NULL);
		gbitmap_destroy(bmp_batt);
		bmp_batt = gbitmap_create_as_sub_bitmap(batteryAll, GRect(10*nImage, 0, 10, 20));
		bitmap_layer_set_bitmap(battery_layer, bmp_batt);

		aktBattAnim += 10;
		if (aktBattAnim > 100)
			aktBattAnim = aktBatt;
		timer_batt = app_timer_register(TIMER_ANIM_BATT_MS, timerCallback, (void*)TIMER_ANIM_BATT);
	}
}
//-----------------------------------------------------------------------------------------------------------------------
void battery_state_service_handler(BatteryChargeState charge_state) 
{
	int nImage = 0;
	aktBatt = charge_state.charge_percent;
	
	if (charge_state.is_charging)
	{
		if (!b_charging)
		{
			nImage = 10;
			b_charging = true;
			aktBattAnim = aktBatt;
			timer_batt = app_timer_register(TIMER_ANIM_BATT_MS, timerCallback, (void*)TIMER_ANIM_BATT);
		}
	}
	else
	{
		nImage = 10 - (aktBatt / 10);
		b_charging = false;
	}
	
	bmp_batt = gbitmap_create_as_sub_bitmap(batteryAll, GRect(10*nImage, 0, 10, 20));
	bitmap_layer_set_bitmap(battery_layer, bmp_batt);
}