#include "graphics.h" #include "display.h" void DisplayTest(pixel_t color) { for (uint16_t h = 0; h < DISPLAY_HEIGHT; h++) { for (uint16_t w = 0; w < DISPLAY_WIDTH; w++) { next_framebuffer[(h * DISPLAY_WIDTH) + w] = color; } } } void DrawBox(uint32_t topleft_x_loc, uint32_t topleft_y_loc, uint32_t width, uint32_t height, pixel_t color) { for (uint32_t y = topleft_y_loc; y < (topleft_y_loc + height); y++) { for (uint32_t x = topleft_x_loc; x < (topleft_x_loc + width); x++) { if (x < DISPLAY_WIDTH && y < DISPLAY_HEIGHT) { next_framebuffer[(y * DISPLAY_WIDTH) + x] = color; } } } } void draw_toggle_switch(volatile pixel_t *const framebuffer, const toggle_switch_t *const toggle_switch) { const uint16_t x_loc = toggle_switch->x; const uint16_t y_loc = toggle_switch->y; const uint16_t width = toggle_switch->width ? toggle_switch->width : 50; const uint16_t height = toggle_switch->height ? toggle_switch->height : 20; const pixel_t on_color = toggle_switch->on_color ? toggle_switch->on_color : MAKE_PIXEL(0, 255, 0); const pixel_t off_color = toggle_switch->off_color ? toggle_switch->off_color : MAKE_PIXEL(160, 20, 20); const bool value = toggle_switch->value; DrawBox(x_loc, y_loc, width, height, value ? on_color : off_color); if (value) { const uint16_t inner_switchbox_width = height - (toggle_switch->inner_padding_pixels * 2); const uint16_t inner_switchbox_x_loc = x_loc + width - toggle_switch->inner_padding_pixels - inner_switchbox_width; const uint16_t inner_switchbox_y_loc = y_loc + toggle_switch->inner_padding_pixels; DrawBox(inner_switchbox_x_loc, inner_switchbox_y_loc, inner_switchbox_width, inner_switchbox_width, MAKE_PIXEL(255, 255, 255)); } else { const uint16_t inner_switchbox_width = height - (toggle_switch->inner_padding_pixels * 2); const uint16_t inner_switchbox_x_loc = x_loc + toggle_switch->inner_padding_pixels; const uint16_t inner_switchbox_y_loc = y_loc + toggle_switch->inner_padding_pixels; DrawBox(inner_switchbox_x_loc, inner_switchbox_y_loc, inner_switchbox_width, inner_switchbox_width, MAKE_PIXEL(255, 255, 255)); } }