GColor color_inverted(GColor source) { GColor inverted = source; if(gcolor_equal(source, GColorBlack)) inverted= GColorWhite; if(gcolor_equal(source, GColorWhite)) inverted= GColorBlack; #ifdef PBL_COLOR if(!gcolor_equal(source, GColorClear)) //GColorClear should not change inverted.argb= source.argb ^ 0b00111111; #endif return inverted; }
void Settings_updateDynamicSettings() { globalSettings.disableWeather = true; globalSettings.updateScreenEverySecond = false; globalSettings.enableAutoBatteryWidget = true; for(int i = 0; i < 3; i++) { // if there are any weather widgets, enable weather checking // if(globalSettings.widgets[i] == WEATHER_CURRENT || // globalSettings.widgets[i] == WEATHER_FORECAST_TODAY) { if(globalSettings.widgets[i] == WEATHER_CURRENT) { globalSettings.disableWeather = false; } // if any widget is "seconds", we'll need to update the sidebar every second if(globalSettings.widgets[i] == SECONDS) { globalSettings.updateScreenEverySecond = true; } // if any widget is "battery", disable the automatic battery indication if(globalSettings.widgets[i] == BATTERY_METER) { globalSettings.enableAutoBatteryWidget = false; } } // temp: if the sidebar is black, use inverted colors for icons if(gcolor_equal(globalSettings.sidebarColor, GColorBlack)) { globalSettings.iconFillColor = GColorBlack; globalSettings.iconStrokeColor = globalSettings.sidebarTextColor; // exciting } else { globalSettings.iconFillColor = GColorWhite; globalSettings.iconStrokeColor = GColorBlack; } }
void set_bitmap_pixel_color(GBitmap *bitmap, GBitmapFormat bitmap_format, int y, int x, GColor color) { GRect bounds = gbitmap_get_bounds(bitmap); if (y < 0 || y >= bounds.size.h) { //APP_LOG(APP_LOG_LEVEL_WARNING, "Setting offscreen pixel at (%u, %u) to %x", x, y, color.argb); return; } GBitmapDataRowInfo row = gbitmap_get_data_row_info(bitmap, y); if ((x >= row.min_x) && (x <= row.max_x)) { switch(bitmap_format) { case GBitmapFormat1Bit : row.data[x / 8] ^= (-(gcolor_equal(color, GColorWhite)? 1 : 0) ^ row.data[x / 8]) & (1 << (x % 8)); break; case GBitmapFormat1BitPalette : //TODO break; case GBitmapFormat2BitPalette : //TODO break; case GBitmapFormat4BitPalette : //TODO break; case GBitmapFormat8BitCircular : case GBitmapFormat8Bit : row.data[x] = color.argb; } } }
void Settings_updateDynamicSettings() { globalSettings.disableWeather = true; globalSettings.updateScreenEverySecond = false; for(int i = 0; i < 3; i++) { // if there are any weather widgets, enable weather checking if(globalSettings.widgets[i] == WEATHER_CURRENT || globalSettings.widgets[i] == WEATHER_FORECAST_TODAY) { globalSettings.disableWeather = false; } // if any widget is "seconds", we'll need to update the sidebar every second if(globalSettings.widgets[i] == SECONDS) { globalSettings.updateScreenEverySecond = true; } } // temp: if the sidebar is black, use inverted colors for icons if(gcolor_equal(globalSettings.sidebarColor, GColorBlack)) { globalSettings.iconFillColor = GColorBlack; globalSettings.iconStrokeColor = GColorWhite; } else { globalSettings.iconFillColor = GColorWhite; globalSettings.iconStrokeColor = GColorBlack; } }
static bool gcolor_is_dark(GColor color) { #if defined(PBL_BW) return gcolor_equal(color, GColorBlack); #elif defined(PBL_COLOR) return color.r < 2 && color.g < 2 && color.b < 2; #endif }
DashboardLayer* dashboard_layer_create(GRect frame, GColor bgColor){ DashboardLayer* dashboard_layer = malloc(sizeof(DashboardLayer)); dashboard_layer->bgColor = bgColor; dashboard_layer->fgColor = gcolor_equal(bgColor,GColorBlack) ? GColorWhite : GColorBlack; #ifdef PBL_SDK_3 dashboard_layer->main_font = fonts_get_system_font(FONT_KEY_LECO_36_BOLD_NUMBERS); #else dashboard_layer->main_font = fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT); #endif resetDisplay(dashboard_layer); // s_background dashboard_layer->s_background = layer_create_with_data(frame, sizeof(DashboardLayer*)); layer_set_update_proc(dashboard_layer->s_background, cb_background_draw); memcpy(layer_get_data(dashboard_layer->s_background), &dashboard_layer, sizeof(DashboardLayer*)); // s_name dashboard_layer->s_name = text_layer_create(GRect(0, 4, 144, 20)); text_layer_set_background_color(dashboard_layer->s_name, GColorClear); text_layer_set_font(dashboard_layer->s_name, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_text_color(dashboard_layer->s_name, dashboard_layer->fgColor); text_layer_set_text(dashboard_layer->s_name, dashboard_layer->text_name); text_layer_set_text_alignment(dashboard_layer->s_name, GTextAlignmentCenter); layer_add_child(dashboard_layer->s_background, text_layer_get_layer(dashboard_layer->s_name)); // s_main #ifdef PBL_SDK_3 dashboard_layer->s_main = text_layer_create(GRect(0, 19, 144, 45)); #else dashboard_layer->s_main = text_layer_create(GRect(0, 15, 144, 45)); #endif text_layer_set_font(dashboard_layer->s_main, dashboard_layer->main_font); text_layer_set_background_color(dashboard_layer->s_main, GColorClear); text_layer_set_text_color(dashboard_layer->s_main, dashboard_layer->fgColor); text_layer_set_text(dashboard_layer->s_main, dashboard_layer->text_main); text_layer_set_text_alignment(dashboard_layer->s_main, GTextAlignmentCenter); layer_add_child(dashboard_layer->s_background, text_layer_get_layer(dashboard_layer->s_main)); // s_subtitle dashboard_layer->s_subtitle = text_layer_create(GRect(0, 60, 144, 27)); text_layer_set_background_color(dashboard_layer->s_subtitle, GColorClear); text_layer_set_text_color(dashboard_layer->s_subtitle, dashboard_layer->fgColor); text_layer_set_text(dashboard_layer->s_subtitle, dashboard_layer->text_subtitle); text_layer_set_text_alignment(dashboard_layer->s_subtitle, GTextAlignmentCenter); text_layer_set_font(dashboard_layer->s_subtitle, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); layer_add_child(dashboard_layer->s_background, text_layer_get_layer(dashboard_layer->s_subtitle)); // s_graph_layer dashboard_layer->s_graph_layer = graph_layer_create(GRect(3, 80, 144 - 6, 168 - 80), dashboard_layer->fgColor); layer_add_child(dashboard_layer->s_background, graph_layer_get_layer(dashboard_layer->s_graph_layer)); return dashboard_layer; }
void graphics_draw_cloud(GContext * ctx, int pos, int isFront, GColor color, weather next) { int start = 29*pos; if (isFront == 0) { graphics_context_set_fill_color(ctx, GColorBlack); graphics_context_set_stroke_color(ctx, GColorBlack); graphics_fill_circle(ctx, GPoint(start + 7, 102+y_off), 6); graphics_fill_circle(ctx, GPoint(start + 14, 99+y_off), 7); graphics_fill_circle(ctx, GPoint(start + 22, 103+y_off), 5); graphics_draw_line(ctx, GPoint(start + 7, 107+y_off), GPoint(start + 18, 107+y_off)); graphics_draw_line(ctx, GPoint(start + 7, 108+y_off), GPoint(start + 18, 108+y_off)); if (next == cloudy || next == rainy || next == tstorm) { graphics_fill_circle(ctx, GPoint(start + 30, 101+y_off), 7); graphics_draw_line(ctx, GPoint(start + 13, 107+y_off), GPoint(start + 32, 107+y_off)); graphics_draw_line(ctx, GPoint(start + 13, 108+y_off), GPoint(start + 32, 108+y_off)); } } else { graphics_context_set_fill_color(ctx, color); graphics_fill_circle(ctx, GPoint(start + 7, 102+y_off), 4); graphics_fill_circle(ctx, GPoint(start + 14, 99+y_off), 5); graphics_fill_circle(ctx, GPoint(start + 22, 103+y_off), 3); graphics_fill_rect(ctx, GRect(start + 7, 101+y_off, 16, 6), 0, GCornerNone); GColor nextColor = GColorClear; if (next == cloudy) { nextColor = GColorWhite; } else if (next == rainy || next == tstorm) { nextColor = GColorDarkGray; } if (!gcolor_equal(nextColor, GColorClear)) { if (!gcolor_equal(color, nextColor)) { graphics_context_set_fill_color(ctx, GColorLightGray); } graphics_fill_circle(ctx, GPoint(start + 30, 101+y_off), 5); graphics_fill_circle(ctx, GPoint(start + 32, 103+y_off), 3); graphics_fill_circle(ctx, GPoint(start + 26, 103+y_off), 3); graphics_context_set_fill_color(ctx, color); graphics_fill_circle(ctx, GPoint(start + 23, 103+y_off), 3); } } }
static void set_pixel_color(GBitmapDataRowInfo info, GPoint point, GColor color) { #if defined(PBL_COLOR) // Write the pixel's byte color memset(&info.data[point.x], color.argb, 1); #elif defined(PBL_BW) // Find the correct byte, then set the appropriate bit uint8_t byte = point.x / 8; uint8_t bit = point.x % 8; byte_set_bit(&info.data[byte], bit, gcolor_equal(color, GColorWhite) ? 1 : 0); #endif }
static void draw_row_callback(GContext *ctx, Layer *cell_layer, MenuIndex *idx, void *context) { GRect bounds = layer_get_bounds(cell_layer); #if defined(PBL_ROUND) // get info of pixel row in the middle of menu row GBitmap *fb = graphics_capture_frame_buffer(ctx); GPoint sc_coord = layer_convert_point_to_screen(cell_layer, GPoint(0, bounds.size.h/2)); GBitmapDataRowInfo info = gbitmap_get_data_row_info(fb, sc_coord.y); graphics_release_frame_buffer(ctx, fb); // adapt bounds for round displays bounds.origin.x = info.min_x + PADDING; bounds.size.w = info.max_x - info.min_x - PADDING; #endif GRect frame = GRect( bounds.origin.x + ICON_SIZE + 3*PADDING, 0, bounds.size.w - 2*ICON_SIZE - PADDING, bounds.size.h/2 ); // draw direction // expand frame width if countdown on the right is small if(deps_items[idx->row].countdown > 0 && deps_items[idx->row].countdown < 10) { frame.size.w += 10; } graphics_draw_text(ctx, deps_items[idx->row].direction, fonts_get_system_font(FONT_KEY_GOTHIC_14), frame, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); // draw time of scheduled departure plus delay frame.origin.y += 12; graphics_draw_text(ctx, deps_items[idx->row].time, fonts_get_system_font(FONT_KEY_GOTHIC_18), frame, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); // draw time until real time departure frame.origin.x = bounds.origin.x + bounds.size.w - ICON_SIZE - PADDING; frame.origin.y = 0; frame.size.w = ICON_SIZE; frame.size.h = ICON_SIZE; if(deps_items[idx->row].countdown == 0) { // draw icon if departure is imminent char* icon_number; if (strcmp(deps_items[idx->row].icon, "bus") == 0) { icon_number = "1"; } else if (strcmp(deps_items[idx->row].icon, "tram") == 0) { icon_number = "2"; } else if (strcmp(deps_items[idx->row].icon, "train") == 0) { icon_number = "3"; } else if (strcmp(deps_items[idx->row].icon, "boat") == 0) { icon_number = "4"; } else if (strcmp(deps_items[idx->row].icon, "funicular") == 0) { icon_number = "5"; } else if (strcmp(deps_items[idx->row].icon, "cable_car") == 0) { icon_number = "6"; } else { icon_number = ""; } frame.origin.x = bounds.origin.x + bounds.size.w - ICON_SIZE; frame.origin.y = 0; frame.size.w = ICON_SIZE+2; frame.size.h = ICON_SIZE; graphics_draw_text(ctx, icon_number, s_icons, frame, GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); } else { static char s_buff[16]; if(deps_items[idx->row].countdown > 60) { strncpy(s_buff, ">1h", 16); } else if(deps_items[idx->row].countdown > 0) { snprintf(s_buff, sizeof(s_buff), "%d'", deps_items[idx->row].countdown); } graphics_draw_text(ctx, s_buff, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), frame, GTextOverflowModeFill, GTextAlignmentRight, NULL); } // draw line icon with colors frame.origin.x = bounds.origin.x + PADDING; frame.origin.y = (bounds.size.h / 2) - (ICON_SIZE / 2); frame.size.w = ICON_SIZE; frame.size.h = ICON_SIZE; GColor color_bg; // correct some coloring switch(deps_items[idx->row].color_bg) { case 9090335 : color_bg = GColorSpringBud; break; case 12703135 : color_bg = GColorInchworm; break; default : color_bg = GColorFromHEX(deps_items[idx->row].color_bg); } GColor color_fg = GColorFromHEX(deps_items[idx->row].color_fg); graphics_context_set_fill_color(ctx, COLOR_FALLBACK(color_bg, GColorClear)); graphics_fill_rect(ctx, frame, 3, GCornersAll); if(!gcolor_equal(color_bg, GColorWhite) || menu_cell_layer_is_highlighted(cell_layer)) { graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorWhite, GColorClear)); } graphics_draw_round_rect(ctx, frame, 3); graphics_context_set_text_color(ctx, COLOR_FALLBACK(color_fg, GColorBlack)); char * name = deps_items[idx->row].name; GFont font; if(strlen(name) == 1) { frame.origin.x += 1; frame.origin.y += 3; /*font = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);*/ font = s_helvetic_bold; } else if(strlen(name) == 2) { // correct position if 2nd digit is "1" if (strstr(name+1, "1") != NULL) { frame.origin.x += 2; } frame.origin.y += 3; /*font = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);*/ font = s_helvetic_bold; /*if(strlen(name) == 1) { frame.origin.x += 1; }*/ } else if(strlen(name) == 3){ frame.origin.y += 3; font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD); } else { frame.origin.y += 6; font = fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD); } graphics_draw_text(ctx, name, font, frame, GTextOverflowModeFill, GTextAlignmentCenter, NULL); }