/* draw the bar and the percentage following it */ void draw_window() { std::string bat_percent_string; int bat_percent; int pair_n; bat_percent_string = get_bat_percent(); bat_percent = std::stoi(bat_percent_string); erase(); draw_battery(bat_percent); printw(bat_percent_string.c_str()); addch('%'); if (!battery_charging) // add a full block of red color that scrolls down from the last full bar // to the first full bar, if the battery is discharging { for (int i = full_bars - 2; i >= 0; i--) { pair_n = (bat_percent == 100 ? cyan : red); // if the battery is full, the block that scrolls down is // cyan. Otherwise it is red erase(); draw_battery(bat_percent); printw(bat_percent_string.c_str()); addch('%'); mvdelch(0,i); attron(COLOR_PAIR(pair_n)); add_wchar(block_solid); attroff(COLOR_PAIR(pair_n)); refresh(); usleep(sleep_time / full_bars - 1); } } else // blink the last full bar and one over if the battery is charging { for (int i = 0; i < 10; i++) { int color = (i % 2 == 0 ? white : cyan); int last_bar = full_bars; if (last_bar >= bars - 1) { last_bar --; } erase(); draw_battery(bat_percent); printw(bat_percent_string.c_str()); addch('%'); mvdelch(0, last_bar); attron(COLOR_PAIR(color)); add_wchar(block_solid); attroff(COLOR_PAIR(color)); refresh(); usleep(sleep_time / 10); } } }
static void update_canvas(Layer *this_layer, GContext *ctx) { graphics_context_set_fill_color(ctx, GColorFromHEX(colors[selected_color])); graphics_fill_rect(ctx, GRect(0, 0, box_width, 168), 0, GCornerNone); // Show battery low indicator below 25 % if (battery_level < 25) { draw_battery(ctx, GColorFromHEX(0xFF0000)); } }
static void main_layer_update_proc(Layer *layer, GContext *ctx) { draw_time(layer, ctx); if (show_battery) { draw_battery(layer, ctx); } if (show_timeline) { draw_timeline(layer, ctx); } }