mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-16 04:31:04 +00:00
add possibility to clear bars
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "bars.h"
|
||||
|
||||
void draw_bar_horizontal(int start_x, int start_y, int width, int height, int value, int max_value, uint color, char fill_outline, UTFT *display)
|
||||
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 * width);
|
||||
@@ -11,7 +11,7 @@ void draw_bar_horizontal(int start_x, int start_y, int width, int height, int va
|
||||
display->fillRect(start_x, start_y, start_x + bar_width, start_y + height);
|
||||
}
|
||||
|
||||
void draw_bar_vertical(int start_x, int start_y, int width, int height, int value, int max_value, uint color, char fill_outline, UTFT *display)
|
||||
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 * height);
|
||||
@@ -20,4 +20,42 @@ void draw_bar_vertical(int start_x, int start_y, int width, int height, int valu
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user