#include "game_drawing.h" // Include its own header #include "ssd1306.h" // For _ssd1306_pixel and SSD1306_t definition /** * @brief Draws a filled rectangle on the OLED display buffer. * * @param dev Pointer to the SSD1306 device structure. * @param x1 X-coordinate of the top-left corner. * @param y1 Y-coordinate of the top-left corner. * @param x2 X-coordinate of the bottom-right corner. * @param y2 Y-coordinate of the bottom-right corner. * @param color True for white, false for black. */ void draw_filled_rect(SSD1306_t *dev, int x1, int y1, int x2, int y2, bool color) { if (x1 > x2) { int t = x1; x1 = x2; x2 = t; } if (y1 > y2) { int t = y1; y1 = y2; y2 = t; } x1 = (x1 < 0) ? 0 : x1; y1 = (y1 < 0) ? 0 : y1; x2 = (x2 >= dev->_width) ? dev->_width - 1 : x2; y2 = (y2 >= dev->_height) ? dev->_height - 1 : y2; for (int y = y1; y <= y2; y++) { for (int x = x1; x <= x2; x++) { _ssd1306_pixel(dev, x, y, color); } } } /** * @brief Draws an outline rectangle on the OLED display buffer. * * @param dev Pointer to the SSD1306 device structure. * @param x1 X-coordinate of the top-left corner. * @param y1 Y-coordinate of the top-left corner. * @param x2 X-coordinate of the bottom-right corner. * @param y2 Y-coordinate of the bottom-right corner. * @param color True for white, false for black. */ void draw_rectangle_outline(SSD1306_t *dev, int x1, int y1, int x2, int y2, bool color) { // Ensure coordinates are ordered correctly if (x1 > x2) { int t = x1; x1 = x2; x2 = t; } if (y1 > y2) { int t = y1; y1 = y2; y2 = t; } // Draw top line for (int x = x1; x <= x2; x++) { _ssd1306_pixel(dev, x, y1, color); } // Draw bottom line for (int x = x1; x <= x2; x++) { _ssd1306_pixel(dev, x, y2, color); } // Draw left line for (int y = y1; y <= y2; y++) { _ssd1306_pixel(dev, x1, y, color); } // Draw right line for (int y = y1; y <= y2; y++) { _ssd1306_pixel(dev, x2, y, color); } }