mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-14 19:51:04 +00:00
83 lines
3.5 KiB
C++
83 lines
3.5 KiB
C++
#include "bars.h"
|
|
|
|
void bar_draw_horizontal(int start_x, int start_y, int width, int height, int value, int max_value, uint color, char fill_outline, UTFT *display)
|
|
{
|
|
display->setColor(color);
|
|
int bar_width = (int)(((float)value / (float)max_value) * (float)width);
|
|
if (fill_outline)
|
|
{
|
|
display->drawRect(start_x, start_y, start_x + width, start_y + height);
|
|
}
|
|
display->fillRect(start_x, start_y, start_x + bar_width, start_y + height);
|
|
}
|
|
|
|
void bar_draw_horizontal(int start_x, int start_y, int width, int height, int value, int max_value, byte r, byte g, byte b, char fill_outline, UTFT *display)
|
|
{
|
|
display->setColor(r,g,b);
|
|
int bar_width = (int)(((float)value / (float)max_value) * (float)width);
|
|
if (fill_outline)
|
|
{
|
|
display->drawRect(start_x, start_y, start_x + width, start_y + height);
|
|
}
|
|
display->fillRect(start_x, start_y, start_x + bar_width, start_y + height);
|
|
}
|
|
|
|
void bar_draw_vertical(int start_x, int start_y, int width, int height, int value, int max_value, uint color, char fill_outline, UTFT *display)
|
|
{
|
|
display->setColor(color);
|
|
int bar_height = (int)(((float)value / (float)max_value) * (float)height);
|
|
if (fill_outline)
|
|
{
|
|
display->drawRect(start_x, start_y, start_x + width, start_y + height);
|
|
}
|
|
display->fillRect(start_x, (start_y + height) - bar_height, start_x + width, start_y + height);
|
|
}
|
|
|
|
void bar_draw_vertical(int start_x, int start_y, int width, int height, int value, int max_value, byte r, byte g, byte b, char fill_outline, UTFT *display)
|
|
{
|
|
display->setColor(r,g,b);
|
|
int bar_height = (int)(((float)value / (float)max_value) * (float)height);
|
|
if (fill_outline)
|
|
{
|
|
display->drawRect(start_x, start_y, start_x + width, start_y + height);
|
|
}
|
|
display->fillRect(start_x, (start_y + height) - bar_height, start_x + width, start_y + height);
|
|
}
|
|
|
|
void bar_clear_part_horizontal(int start_x, int start_y, int width, int height, int value_from, int max_value, char clear_color, char clear_outline, UTFT *display)
|
|
{
|
|
display->setColor(clear_color);
|
|
if (!clear_outline)
|
|
{
|
|
/**
|
|
* If we want to clear the outline, the part we need to clear becomes 1px smaller on each side.
|
|
* (that's not part of the bar to be filled, the "empty space" inside the bar)
|
|
* Because the start_y gets incremented, the end of the bar on the y side would be 2px too big.
|
|
* That's why we need to decrement the height by 2.
|
|
*/
|
|
start_y++;
|
|
height -= 2;
|
|
width--;
|
|
}
|
|
int bar_width = (int)((float)value_from / (float)max_value * width);
|
|
display->fillRect(start_x + bar_width, start_y, start_x + width, start_y + height);
|
|
}
|
|
|
|
void bar_clear_part_vertical(int start_x, int start_y, int width, int height, int value_from, int max_value, char clear_color, char clear_outline, UTFT *display)
|
|
{
|
|
display->setColor(clear_color);
|
|
if (!clear_outline)
|
|
{
|
|
/**
|
|
* If we want to clear the outline, the part we need to clear becomes 1px smaller on each side.
|
|
* (that's not part of the bar to be filled, the "empty space" inside the bar)
|
|
* Because the start_x gets incremented, the end of the bar on the x side would be 2px too big.
|
|
* That's why we need to decrement the width by 2.
|
|
*/
|
|
start_x++;
|
|
start_y++;
|
|
width-= 2;
|
|
}
|
|
int bar_height = (int)((float)value_from / (float)max_value * height);
|
|
display->fillRect(start_x, start_y, start_x + width, start_y + bar_height);
|
|
} |