Esempio n. 1
0
static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) {

    GRect bounds = layer_get_bounds(cell_layer);

    if (data_nb_stop_times > 0) {

        int r = cell_index->row;

        GRect frame_line        = GRect(0, 0, 26, TIMES_CELL_HEIGHT);
        GRect frame_destination = GRect(30, 0, bounds.size.w - 55, TIMES_CELL_HEIGHT);
        GRect frame_time        = GRect(bounds.size.w - 25, 0, 25, TIMES_CELL_HEIGHT);

        graphics_draw_text(ctx, data_stop_times[r].line, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), frame_line, GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);

        graphics_draw_line(ctx, GPoint(27, 0), GPoint(27, TIMES_CELL_HEIGHT));

        graphics_draw_text(ctx, data_stop_times[r].direction, fonts_get_system_font(FONT_KEY_GOTHIC_18), frame_destination, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);

        graphics_draw_text(ctx, data_stop_times[r].time, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), frame_time, GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);

    } else if (data_nb_stop_times == -1) {
        graphics_draw_text(ctx, "Loading...", fonts_get_system_font(FONT_KEY_GOTHIC_18), bounds, GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
    } else if (data_nb_stop_times == -2) {
        graphics_draw_text(ctx, "No bus.", fonts_get_system_font(FONT_KEY_GOTHIC_18), bounds, GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
    }

}
Esempio n. 2
0
static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) {
  TimeSlot *ts = &schedule.slots[cell_index->section];
  #ifndef PBL_COLOR
  graphics_context_set_text_color(ctx, ROW_FG_COLOR);
  graphics_context_set_fill_color(ctx, ROW_BG_COLOR);
  #endif
  if (ts->is_common) {
      graphics_draw_text(ctx, ts->title, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD),
              layer_get_bounds(cell_layer), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
  } else {
      GRect title_bounds = layer_get_bounds(cell_layer);
      title_bounds.origin.x += 30;
      title_bounds.size.w -= 30;
      title_bounds.origin.y += 3;
      title_bounds.size.h -= 3;
      GRect icon_bounds = layer_get_bounds(cell_layer);
      icon_bounds.size.w = 24;
      icon_bounds.size.h = 28;
      Session *s = &(ts->sessions[cell_index->row]); 
      graphics_draw_text(ctx, s->title, fonts_get_system_font(FONT_KEY_GOTHIC_14), title_bounds,
              GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
      char *room_number_str = "0";
      snprintf(room_number_str, 2, "%d", s->room);

      #ifdef PBL_COLOR
      GFont room_font = fonts_get_system_font(FONT_KEY_LECO_26_BOLD_NUMBERS_AM_PM);
      graphics_context_set_text_color(ctx, ROOM_NUMBER_COLOR);
      #else
      GFont room_font = fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK);
      #endif
      graphics_draw_text(ctx, room_number_str, room_font, icon_bounds, GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
  }
}
Esempio n. 3
0
void WeekNumber_draw(GContext* ctx, int yPosition) {
  graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);

  // note that it draws "above" the y position to correct for
  // the vertical padding
  graphics_draw_text(ctx,
                     wordForWeek[globalSettings.languageId],
                     smSidebarFont,
                     GRect(-4 + SidebarWidgets_xOffset, yPosition - 4, 38, 20),
                     GTextOverflowModeFill,
                     GTextAlignmentCenter,
                     NULL);

  if(!globalSettings.useLargeFonts) {
    graphics_draw_text(ctx,
                       currentWeekNum,
                       mdSidebarFont,
                       GRect(0 + SidebarWidgets_xOffset, yPosition + 9, 30, 20),
                       GTextOverflowModeFill,
                       GTextAlignmentCenter,
                       NULL);
  } else {
    graphics_draw_text(ctx,
                       currentWeekNum,
                       lgSidebarFont,
                       GRect(0 + SidebarWidgets_xOffset, yPosition + 6, 30, 20),
                       GTextOverflowModeFill,
                       GTextAlignmentCenter,
                       NULL);
  }
}
static void text_layer_update_callback(Layer *me, GContext *ctx) {
	const GRect frame = layer_get_frame(me);
	graphics_context_set_fill_color(ctx, GColorWhite);
	char str[32];
	
	// draw current weight
	snprintf(str, sizeof(str), "%dg", weight);
	graphics_draw_text(ctx, str, font_medium, frame, GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);

	str[0] = 0;
	if (is_measuring()) {
		// while measuring, draw frequency and amplitude
		Measurement m = calibrations[calibrations_count];
		floatStr(str, m.freq, 2);
		int len = strlen(str);
		str[len++] = '\n';
		floatStr(str + len, m.amp, 2);
	} else if (calibrations_count > 0) {
		// when not measuring draw next calibrated weight for selection
		// calibration values are not sorted by weight
		int16_t dw, minDw = -1, w = 0;
		for (int i = 0; i < calibrations_count; i++) {
			dw = (int16_t) calibrations[i].weight - (int16_t) weight;
			if (minDw >= 0 && (dw < 0 || dw >= minDw))
				continue;
			minDw = dw;
			w = (int16_t) calibrations[i].weight;
		}
		snprintf(str, sizeof(str), "next\n%dg", w);
	}
	graphics_draw_text(ctx, str, font_tiny, GRect(0, frame.size.h - 30, frame.size.w, 30), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
}
static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) {
  /*#ifdef PBL_COLOR    
    graphics_context_set_fill_color(ctx, GColorPastelYellow);
    graphics_fill_rect(ctx, GRect(0, 0, 144, 44), 0, GCornerNone);
  #endif*/

  #ifdef PBL_SDK_2
    graphics_context_set_text_color(ctx, GColorBlack);
  #endif
  
  GRect row_title_rect = GRect(5, -6, bounds.size.w-10, 28);
  GRect row_subtitle_rect = GRect(5, 21, bounds.size.w-10, 18);
  
  char reward_string[128];
  
  switch (cell_index->row) {
    case 0:
      graphics_draw_text(ctx, "Easy", fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD), row_title_rect, GTextOverflowModeFill, GTextAlignmentCenter, NULL);    
      snprintf(reward_string, sizeof(reward_string), "Reward: %ld", (long)get_car_score()*REWARD_COEFFICIENT_EASY);
      break;
    case 1:
      graphics_draw_text(ctx, "Medium", fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD), row_title_rect, GTextOverflowModeFill, GTextAlignmentCenter, NULL);
      snprintf(reward_string, sizeof(reward_string), "Reward: %ld", (long)get_car_score()*REWARD_COEFFICIENT_MEDIUM);
      break;
    case 2:
      graphics_draw_text(ctx, "Hard", fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD), row_title_rect, GTextOverflowModeFill, GTextAlignmentCenter, NULL);
      snprintf(reward_string, sizeof(reward_string), "Reward: %ld", (long)get_car_score()*REWARD_COEFFICIENT_HARD);
      break;
  }
  
  graphics_draw_text(ctx, reward_string, fonts_get_system_font(FONT_KEY_GOTHIC_18), row_subtitle_rect, GTextOverflowModeFill, GTextAlignmentCenter, NULL);
}
Esempio n. 6
0
void BatteryMeter_draw(GContext* ctx, int yPosition) {

  BatteryChargeState chargeState = battery_state_service_peek();

  graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);

  char batteryString[6];
  int batteryPositionY = yPosition - 5; // correct for vertical empty space on battery icon

  if (batteryImage) {
    gdraw_command_image_recolor(batteryImage, globalSettings.iconFillColor, globalSettings.iconStrokeColor);
    gdraw_command_image_draw(ctx, batteryImage, GPoint(3 + SidebarWidgets_xOffset, batteryPositionY));
  }

  if(chargeState.is_charging) {
    if(batteryChargeImage) {
      // the charge "bolt" icon uses inverted colors
      gdraw_command_image_recolor(batteryChargeImage, globalSettings.iconStrokeColor, globalSettings.iconFillColor);
      gdraw_command_image_draw(ctx, batteryChargeImage, GPoint(3 + SidebarWidgets_xOffset, batteryPositionY));
    }
  } else {

    int width = roundf(18 * chargeState.charge_percent / 100.0f);

    graphics_context_set_fill_color(ctx, globalSettings.iconStrokeColor);

    if(chargeState.charge_percent <= 20) {
      graphics_context_set_fill_color(ctx, GColorRed);
    }

    graphics_fill_rect(ctx, GRect(6 + SidebarWidgets_xOffset, 8 + batteryPositionY, width, 8), 0, GCornerNone);
  }

  // never show battery % while charging, because of this issue:
  // https://github.com/freakified/TimeStylePebble/issues/11
  if(globalSettings.showBatteryPct && !chargeState.is_charging) {
    if(!globalSettings.useLargeFonts) {
      snprintf(batteryString, sizeof(batteryString), "%d%%", chargeState.charge_percent);

      graphics_draw_text(ctx,
                         batteryString,
                         batteryFont,
                         GRect(-4 + SidebarWidgets_xOffset, 18 + batteryPositionY, 38, 20),
                         GTextOverflowModeFill,
                         GTextAlignmentCenter,
                         NULL);
    } else {
      snprintf(batteryString, sizeof(batteryString), "%d", chargeState.charge_percent);

      graphics_draw_text(ctx,
                         batteryString,
                         batteryFont,
                         GRect(-4 + SidebarWidgets_xOffset, 14 + batteryPositionY, 38, 20),
                         GTextOverflowModeFill,
                         GTextAlignmentCenter,
                         NULL);
    }
  }
}
void graphics_draw_wtext(GContext* ctx, int pos, char* time, char* temp) {
  int start = 29*pos;
  
  GFont custom_font_3 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCKY_11));
  //GFont custom_font_4 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCKY_08));
  graphics_context_set_text_color(ctx, GColorBlack);
  graphics_draw_text(ctx, temp, custom_font_3, GRect(start+2, 124, 29, 15), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
  graphics_draw_text(ctx, time, custom_font_3, GRect(start+2, 140, 29, 15), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
}
Esempio n. 8
0
static void render(Layer *layer, GContext* ctx) 
{
    graphics_context_set_text_color(ctx, GColorWhite);

    GPoint txtPoint = mBigHour ? mTextPoint : mTextPointAlt;
    graphics_draw_text(ctx, mDayText, mFont, GRect(txtPoint.x, txtPoint.y, SCREEN_W2, SCREEN_H), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
    graphics_draw_text(ctx, mWeatherText, mFont, GRect(txtPoint.x, txtPoint.y+TEXT_SIZE+TEXT_OFFSET, SCREEN_W2, SCREEN_H), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
    graphics_draw_text(ctx, mBatteryText, mFont, GRect(txtPoint.x, txtPoint.y+TEXT_SIZE*2+TEXT_OFFSET*2, SCREEN_W2, SCREEN_H), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
}
Esempio n. 9
0
void DrawStringS(int x, int y, int r, int g, int b, char *str)
{
	uint32_t color = 0;

	color = graphics_make_color(r, g, b, 0xff);
    graphics_set_color(0x00000000, 0x00000000);
	graphics_draw_text(__dc, x+1, y+1, str);
	graphics_set_color(color, 0x00000000);
	graphics_draw_text(__dc, x, y, str);
}
Esempio n. 10
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
	  );
	}
}
Esempio n. 11
0
void CurrentWeather_draw(GContext* ctx, int yPosition) {
  graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);

  if (Weather_currentWeatherIcon) {
    gdraw_command_image_recolor(Weather_currentWeatherIcon, globalSettings.iconFillColor, globalSettings.iconStrokeColor);

    gdraw_command_image_draw(ctx, Weather_currentWeatherIcon, GPoint(3 + SidebarWidgets_xOffset, yPosition));
  }

  // draw weather data only if it has been set
  if(Weather_weatherInfo.currentTemp != INT32_MIN) {

    int currentTemp = Weather_weatherInfo.currentTemp;

    if(!globalSettings.useMetric) {
      currentTemp = roundf(currentTemp * 1.8f + 32);
    }

    char tempString[8];

    // in large font mode, omit the degree symbol and move the text
    if(!globalSettings.useLargeFonts) {
      snprintf(tempString, sizeof(tempString), " %d°", currentTemp);

      graphics_draw_text(ctx,
                         tempString,
                         currentSidebarFont,
                         GRect(-5 + SidebarWidgets_xOffset, yPosition + 24, 38, 20),
                         GTextOverflowModeFill,
                         GTextAlignmentCenter,
                         NULL);
    } else {
      snprintf(tempString, sizeof(tempString), " %d", currentTemp);

      graphics_draw_text(ctx,
                         tempString,
                         currentSidebarFont,
                         GRect(-5 + SidebarWidgets_xOffset, yPosition + 20, 35, 20),
                         GTextOverflowModeFill,
                         GTextAlignmentCenter,
                         NULL);
    }
  } else {
    // if the weather data isn't set, draw a loading indication
    graphics_draw_text(ctx,
                       "...",
                       currentSidebarFont,
                       GRect(-5 + SidebarWidgets_xOffset, yPosition, 38, 20),
                       GTextOverflowModeFill,
                       GTextAlignmentCenter,
                       NULL);
  }
}
static void icon_layer_update_callback(Layer *me, GContext *ctx) {
	const GRect frame = layer_get_frame(me);
	graphics_context_set_fill_color(ctx, GColorWhite);
	// up
	graphics_draw_text(ctx, icon_plus, font_symbols, GRect(0, 0, frame.size.w, 30), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
	// select
	const char *cText = icon_clock;
	if (is_measuring())
		cText = icon_stop;
	graphics_draw_text(ctx, cText, font_symbols, GRect(0, frame.size.h / 2 - 18, frame.size.w, 30), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
	// down
	graphics_draw_text(ctx, icon_minus, font_symbols, GRect(0, frame.size.h - 30, frame.size.w, 30), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
}
Esempio n. 13
0
static void main_menu_draw_row(GContext *ctx, const Layer *cell_layer, MenuIndex *cell_index, void *menu_ctx) {
	struct menu_data_cell *data_cell;

	data_cell = &data_cells[cell_index->row];

	graphics_context_set_text_color(ctx, GColorBlack);
	graphics_draw_text(ctx, data_cell->title, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(7, -3, 130, 30),
			GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
	graphics_draw_text(ctx, data_cell->subtitle, fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(7, 23, 120, 30),
			GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
	graphics_draw_text(ctx, "\U0001F605", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(90, 5, 50, 50),
			GTextOverflowModeTrailingEllipsis, GTextAlignmentRight, NULL);
}
Esempio n. 14
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
}
Esempio n. 15
0
void textOutline(GContext *ctx, const char *text, const GFont font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, GTextAttributes *text_attributes, const GColor fg, const GColor bg){
	int w = box.size.w;
	int h = box.size.h;
	int x = box.origin.x;
	int y = box.origin.y;
	graphics_context_set_text_color(ctx, bg);
	graphics_draw_text(ctx, text, font, GRect(x+1,y,w,h), overflow_mode, alignment, text_attributes);
	graphics_draw_text(ctx, text, font, GRect(x-1,y,w,h), overflow_mode, alignment, text_attributes);
	graphics_draw_text(ctx, text, font, GRect(x,y+1,w,h), overflow_mode, alignment, text_attributes);
	graphics_draw_text(ctx, text, font, GRect(x,y-1,w,h), overflow_mode, alignment, text_attributes);
	
	graphics_context_set_text_color(ctx, fg);
	graphics_draw_text(ctx, text, font, box, overflow_mode, alignment, text_attributes);
}
Esempio n. 16
0
void draw_face_layer(Layer* l, GContext* ctx)
{
	GColor foreground_color = gcolor_legible_over(s_background_color);
	GRect bounds = layer_get_frame(l);
	GPoint center = GPoint(bounds.size.w / 2, bounds.size.h / 2);
	int height = bounds.size.h - 2;
	int width = bounds.size.w - 2;

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

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

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

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

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

		GPoint pt = GPoint(x + center.x, y + center.y);
		graphics_fill_circle(ctx, pt, 2);
	}
}
Esempio n. 17
0
static void main_menu_header(GContext *ctx, const Layer *cell_layer, uint16_t section_index, void *menu_ctx) {
	graphics_context_set_fill_color(ctx, GColorBlack);
	graphics_context_set_text_color(ctx, GColorWhite);
	graphics_fill_rect(ctx, layer_get_bounds(cell_layer), 0, GCornersAll);
	graphics_draw_text(ctx, "[Restrooms]", fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD),
			layer_get_bounds(cell_layer), GTextOverflowModeFill, GTextAlignmentCenter, NULL);
}
static void cb_draw_row(GContext *g_ctx, const Layer *l_cell, MenuIndex *i_cell, void *ctx) {
  ActionMenu *menu = ctx;
  GRect bounds = layer_get_bounds(l_cell);

  if(menu_layer_get_selected_index(menu->menulayer).row == i_cell->row) {
    graphics_context_set_fill_color(g_ctx, GColorWhite);
    graphics_fill_rect(g_ctx, bounds, 0, GCornerNone);
  }

  bounds.origin.x += 4;
  bounds.size.w -= 2*4;

  graphics_context_set_fill_color(g_ctx, GColorBlack);
  graphics_fill_rect(g_ctx, bounds, 4, GCornersAll);

  bounds.size.w -= 2*4;
  bounds.origin.x += 4;

  bounds.origin.y += 4;
  bounds.size.h -= 2*4;

  graphics_draw_text(g_ctx,
    menu->current_level->items[i_cell->row]->label,
    fonts_get_system_font(ACTION_MENU_FONT),
    bounds,
    GTextOverflowModeWordWrap,
    GTextAlignmentLeft,
    0);

  if(menu->current_level->items[i_cell->row]->child && menu_layer_get_selected_index(menu->menulayer).row == i_cell->row) {
    if(menu->arrow_image == NULL){
      menu->arrow_image = gbitmap_create_with_data(ARROW_IMAGE_DATA);
    }
    graphics_draw_bitmap_in_rect(g_ctx, menu->arrow_image, (GRect){.origin={116, bounds.origin.y + (bounds.size.h - 4) / 2},.size={7,5}});
Esempio n. 19
0
static void menu_draw_header_callback(GContext* ctx, const Layer *cell_layer, uint16_t section_index, void *data) {
  // Draw title text in the section header
	graphics_context_set_fill_color(ctx, GColorWhite);
	graphics_fill_rect(ctx, layer_get_frame(cell_layer), 1, GCornersAll);
	graphics_context_set_text_color(ctx, GColorBlack);
	graphics_draw_text(ctx, "OTAKU", fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD), layer_get_frame(cell_layer), GTextOverflowModeFill, GTextAlignmentCenter, NULL);
}
Esempio n. 20
0
static void menu_draw_row_callback_aplite(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) {
    GBitmap* image = getImage(_latestSource[cell_index->row]);
    if (image != NULL) {
        GRect bounds = GRect(5, 8, 48, 48);
        graphics_draw_bitmap_in_rect(ctx, image, bounds);
    }

    if (selectedMenuCell == cell_index->row) {
        graphics_context_set_text_color(ctx, GColorWhite);
    } else {
        graphics_context_set_text_color(ctx, GColorBlack);
    }
    graphics_draw_text(ctx, _latestSource[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(59, 8, 90, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
    graphics_draw_text(ctx, _latestCategory[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(59, 37, 90, 10), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
    graphics_draw_text(ctx, _latest[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(5, 59, 136, row_height(cell_index)), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);
}
static void prv_draw_text(Layer *layer, GContext *ctx) {
  SelectionLayerData *data = layer_get_data(layer);
  for (int i = 0, current_x_offset = 0; i < data->num_cells; i++) {
    if (data->callbacks.get_cell_text) {
      char *text = data->callbacks.get_cell_text(i, data->context);
      if (text) {
        int height = layer_get_bounds(layer).size.h;
        if (data->selected_cell_idx == i) {
          height += prv_get_pixels_for_bump_settle(data->bump_settle_anim_progress);
        }
        int y_offset = prv_get_y_offset_which_vertically_centers_font(data->font, height);

        if (data->selected_cell_idx == i && data->bump_is_upwards) {
          y_offset -= prv_get_pixels_for_bump_settle(data->bump_settle_anim_progress);
        }

        if (data->selected_cell_idx == i) {
          int delta = (data->bump_text_anim_progress * prv_get_font_top_padding(data->font)) / 100;
          if (data->bump_is_upwards) {
            delta *= -1;
          }
          y_offset += delta;
        }

        GRect rect = GRect(current_x_offset, y_offset, data->cell_widths[i], height);
        graphics_draw_text(ctx, text, data->font, rect, GTextOverflowModeFill, GTextAlignmentCenter, NULL);
      }
    }

    current_x_offset += data->cell_widths[i] + data->cell_padding;
  }
}
Esempio n. 22
0
// Draws a date window with the specified text contents.  Usually this is
// something like a numeric date or the weekday name.
void draw_window(Layer *me, GContext *ctx, const char *text, struct FontPlacement *font_placement, 
		 GFont *font, bool invert, bool opaque_layer) {
  GRect box = date_window_box;

  unsigned int draw_mode = invert ^ config.draw_mode;
  draw_date_window_background(ctx, draw_mode, draw_mode, opaque_layer);

  graphics_context_set_text_color(ctx, draw_mode_table[draw_mode].colors[1]);

  box.origin.y += font_placement->vshift;

  // The Pebble text routines seem to be a bit too conservative when
  // deciding whether a given bit of text will fit within its assigned
  // box, meaning the text is likely to be trimmed even if it would
  // have fit.  We avoid this problem by cheating and expanding the
  // box a bit wider and taller than we actually intend it to be.
  box.origin.x -= 4;
  box.size.w += 8;
  box.size.h += 4;

  if ((*font) == NULL) {
    (*font) = safe_load_custom_font(font_placement->resource_id);
  }

  graphics_draw_text(ctx, text, (*font), box,
                     GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter,
                     NULL);
}
// Draw the lizard by calling from the layer redraw proc
void draw_lizard(GContext* ctx) {
  GPath *lizard_path = gpath_create(&lizard_points);
  GPath *bug_path = gpath_create(&bug_points);

  //gpath_rotate_to(lizard_path, TRIG_MAX_ANGLE / 360 * 20);
  gpath_move_to(lizard_path, GPoint(10, 0));
    
  graphics_context_set_fill_color(ctx, GColorGreen);
  gpath_draw_filled(ctx, lizard_path);
  graphics_context_set_stroke_color(ctx, GColorBlack);
  gpath_draw_outline(ctx, lizard_path);
  graphics_context_set_fill_color(ctx, GColorBlack);
  gpath_draw_filled(ctx, bug_path);
    
  GPoint center = {
      .x = 41,
      .y = 59
  };
  graphics_fill_circle(ctx, center, 3);
  graphics_draw_circle(ctx, center, 8);
  graphics_draw_line(ctx, GPoint(6, 73), GPoint(16, 72));
    
  graphics_context_set_text_color(ctx, GColorRed);
  graphics_draw_text(ctx,
	    		"Lizzy",
	    		fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD),
	    		GRect(0,120,144,140),
	    		GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
    
}

// Only need to draw the lizard
static void drawing_layer_update_callback(Layer *me, GContext *ctx) { 
    draw_lizard(ctx);
}
Esempio n. 24
0
static void minute_display_layer_update_callback(Layer *layer, GContext* ctx) {

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

  unsigned int angle = t->tm_min * 6;

  GRect bounds = layer_get_bounds(layer);
  GRect min_rect;
  GPoint center = grect_center_point(&bounds);
  
  GPoint min_center; // center of the minute circle
  min_center.x = sin_lookup((TRIG_MAX_ANGLE / 360) * angle)*54/TRIG_MAX_RATIO + center.x;
  min_center.y = -cos_lookup((TRIG_MAX_ANGLE / 360) * angle)*54/TRIG_MAX_RATIO + center.y;
  graphics_context_set_fill_color(ctx, FOREGROUND_COLOR);
  graphics_context_set_stroke_color(ctx, FOREGROUND_COLOR);
  graphics_fill_circle(ctx, min_center, 17);
  
  strftime(min_text,sizeof(hour_text),"%M",t);

  min_rect.origin.x = min_center.x - 15;
  min_rect.origin.y = min_center.y - 18;
  min_rect.size.w = 30;
  min_rect.size.h = 15;
  graphics_context_set_text_color(ctx,BACKGROUND_COLOR);
  graphics_draw_text(ctx,min_text,fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD),min_rect,GTextOverflowModeWordWrap,GTextAlignmentCenter,NULL);
}
Esempio n. 25
0
static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) {
  	switch (cell_index->section) {
    	default:
			switch (cell_index->row) {
			  	case 0:
				  	menu_cell_basic_draw(ctx, cell_layer, _("Checkin"), NULL, NULL);
				  	break;
			  	case 1:
					menu_cell_basic_draw(ctx, cell_layer, _("Share"), NULL, NULL);
					GRect bounds = layer_get_bounds(cell_layer);
					char* alligators = ">>";
					GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD);
					graphics_draw_text(ctx, alligators, font,
									   GRect(bounds.size.w - PBL_IF_ROUND_ELSE(45, 35),
											 (bounds.size.h/2) - 18,
											 30, bounds.size.h),
									   GTextOverflowModeWordWrap, 
									   GTextAlignmentRight, 
									   NULL);
					break;
			  	case 2: 
				  	menu_cell_basic_draw(ctx, cell_layer, _("Private Checkin"), NULL, NULL);
				  	break;
			}
			break;
	}
}
// This is a layer update callback where compositing will take place
static void layer_update_callback(Layer *layer, GContext* ctx) {
  GRect bounds = layer_get_frame(layer);

  // Display the name of the current compositing operation
  graphics_context_set_text_color(ctx, GColorBlack);
  graphics_draw_text(ctx,
    gcompops[current_gcompop].name,
    fonts_get_system_font(FONT_KEY_GOTHIC_18),
    bounds,
    GTextOverflowModeTrailingEllipsis,
    GTextAlignmentCenter,
    NULL);

  // Draw the large circle the image will composite with
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_circle(ctx, GPoint(bounds.size.w/2, bounds.size.h+110), 180);

  // Use the image size to help center the image
  GRect destination = image->bounds;

  // Center horizontally using the window frame size
  destination.origin.x = (bounds.size.w-destination.size.w)/2;
  destination.origin.y = 50;

  // Set the current compositing operation
  // This will only cause bitmaps to composite
  graphics_context_set_compositing_mode(ctx, gcompops[current_gcompop].op);

  // Draw the bitmap; it will use current compositing operation set
  graphics_draw_bitmap_in_rect(ctx, image, destination);
}
void update_display(struct Layer *layer, GContext *ctx) {
    
    // Load the font
    GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD);
    // Set the color
    graphics_context_set_text_color(ctx, GColorBlack);
    
    // Determine a reduced bounding box
    GRect layer_bounds = layer_get_bounds(window_get_root_layer(window));
    GRect bounds = GRect(layer_bounds.origin.x+5, layer_bounds.origin.y+5,
                         layer_bounds.size.w-10, layer_bounds.size.h-10);

    // Clear the window
    graphics_context_set_fill_color(ctx, GColorWhite);
    graphics_fill_rect(ctx, layer_bounds, 0, GCornerNone);

    // Draw the text
    if (stats_display) {
        snprintf(madlibstr, 50, "nouns: %d\nverbs: %d\nadjectives: %d\nadverbs: %d", 
                                nouns, verbs, adjectives, adverbs);
    } 
    graphics_draw_text(ctx, madlibstr, font, bounds, GTextOverflowModeWordWrap, 
                                                     GTextAlignmentCenter, NULL);

}
Esempio n. 28
0
void Steps_draw(GContext* ctx, int yPosition) {

  if(stepsImage) {
    gdraw_command_image_recolor(stepsImage, globalSettings.iconFillColor, globalSettings.iconStrokeColor);
    gdraw_command_image_draw(ctx, stepsImage, GPoint(3 + SidebarWidgets_xOffset, yPosition - 7));
  }

  char steps_text[8];

  if(globalSettings.healthUseDistance) {
    int meters = (int)health_service_sum_today(HealthMetricWalkedDistanceMeters);

    // format distance string
    if(globalSettings.useMetric) {
      if(meters < 1000) {
        snprintf(steps_text, sizeof(steps_text), "%im", meters);
      } else {
        meters /= 1000; // convert to km
        snprintf(steps_text, sizeof(steps_text), "%ikm", meters);
      }
    } else {
      int miles_tenths = meters * 10 / 1609 % 10;
      int miles_whole  = (int)roundf(meters / 1609.0f);

      if(miles_whole > 0) {
        snprintf(steps_text, sizeof(steps_text), "%imi", miles_whole);
      } else {
        snprintf(steps_text, sizeof(steps_text), "%c%imi", globalSettings.decimalSeparator, miles_tenths);
      }
    }
  } else {
    int steps = (int)health_service_sum_today(HealthMetricStepCount);

    // format step string
    if(steps < 1000) {
      snprintf(steps_text, sizeof(steps_text), "%i", steps);
    } else {
      int steps_thousands = steps / 1000;
      int steps_hundreds  = steps / 100 % 10;

      if (steps < 10000) {
        snprintf(steps_text, sizeof(steps_text), "%i%c%ik", steps_thousands, globalSettings.decimalSeparator, steps_hundreds);
      } else {
        snprintf(steps_text, sizeof(steps_text), "%ik", steps_thousands);
      }
    }
  }


  graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);

  graphics_draw_text(ctx,
                     steps_text,
                     mdSidebarFont,
                     GRect(-2 + SidebarWidgets_xOffset, yPosition + 13, 34, 20),
                     GTextOverflowModeFill,
                     GTextAlignmentCenter,
                     NULL);
}
Esempio n. 29
0
void mainMenu_draw_row(GContext *ctx, const Layer *cell_layer,
                       MenuIndex *cell_index, void *callback_context){
    graphics_context_set_text_color(ctx, GColorBlack);
    // graphics_context_set_fill_color(ctx, GColorWhite);
    graphics_draw_text(ctx, stops+32*cell_index->row,
                       fonts_get_system_font(FONT_KEY_GOTHIC_14),
                       GRect(0,0,layer_get_frame(cell_layer).size.w,layer_get_frame(cell_layer).size.h-15),
                       GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
    graphics_draw_text(ctx, distances+32*cell_index->row,
                       fonts_get_system_font(FONT_KEY_GOTHIC_14),
                       GRect(0,15,layer_get_frame(cell_layer).size.w,layer_get_frame(cell_layer).size.h-15),
                       GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
    // Just saying layer_get_frame(cell_layer) for the 4th argument
    // doesn't work. Probably because the GContext is relative to the
    // cell already, but the cell_layer.frame is relative to the
    // menulayer or the screen or something.
}
Esempio n. 30
0
void Sleep_draw(GContext* ctx, int yPosition) {
  if(sleepImage) {
    gdraw_command_image_recolor(sleepImage, globalSettings.iconFillColor, globalSettings.iconStrokeColor);
    gdraw_command_image_draw(ctx, sleepImage, GPoint(3 + SidebarWidgets_xOffset, yPosition - 7));
  }

  // get sleep in seconds
  int sleep_seconds;

  if(globalSettings.healthUseRestfulSleep) {
    sleep_seconds = (int)health_service_sum_today(HealthMetricSleepSeconds);
  } else {
    sleep_seconds = (int)health_service_sum_today(HealthMetricSleepRestfulSeconds);
  }

  // convert to hours/minutes
  int sleep_minutes = sleep_seconds / 60;
  int sleep_hours   = sleep_minutes / 60;

  // find minutes remainder
  sleep_minutes %= 60;

  char sleep_text[4];

  snprintf(sleep_text, sizeof(sleep_text), "%ih", sleep_hours);

  graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);
  graphics_draw_text(ctx,
                     sleep_text,
                     mdSidebarFont,
                     GRect(-2 + SidebarWidgets_xOffset, yPosition + 14, 34, 20),
                     GTextOverflowModeFill,
                     GTextAlignmentCenter,
                     NULL);

  snprintf(sleep_text, sizeof(sleep_text), "%im", sleep_minutes);

  graphics_draw_text(ctx,
                     sleep_text,
                     smSidebarFont,
                     GRect(-2 + SidebarWidgets_xOffset, yPosition + 30, 34, 20),
                     GTextOverflowModeFill,
                     GTextAlignmentCenter,
                     NULL);

}