added guiDrawSlider()
This commit is contained in:
parent
894770e596
commit
4df715dd46
2 changed files with 30 additions and 8 deletions
30
gui.c
30
gui.c
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
static struct guiNode_t *firstGUI = NULL;
|
static struct guiNode_t *firstGUI = NULL;
|
||||||
uint16_t x, y; // global touchpad coordinates
|
uint16_t x, y; // global touchpad coordinates
|
||||||
uint16_t value_old; // needed for slider
|
uint16_t percent, value_old; // needed for slider
|
||||||
|
|
||||||
static uint8_t addElement(struct guiNode_t *newNode) {
|
static uint8_t addElement(struct guiNode_t *newNode) {
|
||||||
struct guiNode_t *new;
|
struct guiNode_t *new;
|
||||||
|
@ -90,13 +90,32 @@ static inline void buttonUpdate(struct guiNode_t *node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void sliderUpdate(struct guiNode_t *node) {
|
static inline void sliderUpdate(struct guiNode_t *node) {
|
||||||
(void)node;
|
uint16_t value, length;
|
||||||
|
|
||||||
uint16_t percent = 0, value = 0;
|
if(node->orientation == horizontal)
|
||||||
|
length = node->x1 - node->x0;
|
||||||
|
else if(node->orientation == vertical)
|
||||||
|
length = node->y1 - node->y0;
|
||||||
|
|
||||||
percent = *(node->state);
|
if(node->mode == modePassive) {
|
||||||
|
percent = *(node->state);
|
||||||
|
} else if(node->mode == modeActive) {
|
||||||
|
if(x >= node->x0 && x <= node->x1 && y >= node->y0 && y <= node->y1) {
|
||||||
|
if(node->orientation == horizontal) {
|
||||||
|
percent = (((x - node->x0) * 100) / length);
|
||||||
|
} else if(node->orientation == vertical) {
|
||||||
|
percent = (((y - node->y0) * 100) / length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*(node->state) = percent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// a bit of safety here
|
||||||
if(percent > 100)
|
if(percent > 100)
|
||||||
percent = 100;
|
percent = 100;
|
||||||
|
if(percent < 0)
|
||||||
|
percent = 0;
|
||||||
|
|
||||||
if(node->orientation == horizontal) {
|
if(node->orientation == horizontal) {
|
||||||
value = ((((node->x1)-(node->x0)) * percent) / 100);
|
value = ((((node->x1)-(node->x0)) * percent) / 100);
|
||||||
|
@ -203,7 +222,7 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value) {
|
uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t orientation, uint8_t mode, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value) {
|
||||||
struct guiNode_t *newNode;
|
struct guiNode_t *newNode;
|
||||||
|
|
||||||
newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
|
newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
|
||||||
|
@ -216,6 +235,7 @@ uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_
|
||||||
newNode->y0 = y0;
|
newNode->y0 = y0;
|
||||||
newNode->x1 = x1;
|
newNode->x1 = x1;
|
||||||
newNode->y1 = y1;
|
newNode->y1 = y1;
|
||||||
|
newNode->mode = mode;
|
||||||
newNode->bkColor = bkColor;
|
newNode->bkColor = bkColor;
|
||||||
newNode->valueColor = valueColor;
|
newNode->valueColor = valueColor;
|
||||||
newNode->state = value;
|
newNode->state = value;
|
||||||
|
|
4
gui.h
4
gui.h
|
@ -20,6 +20,7 @@ struct guiNode_t {
|
||||||
uint16_t bkColor;
|
uint16_t bkColor;
|
||||||
uint16_t valueColor;
|
uint16_t valueColor;
|
||||||
uint8_t orientation;
|
uint8_t orientation;
|
||||||
|
uint8_t mode;
|
||||||
uint8_t *active;
|
uint8_t *active;
|
||||||
uint8_t *state;
|
uint8_t *state;
|
||||||
char *label;
|
char *label;
|
||||||
|
@ -33,6 +34,7 @@ extern "C" {
|
||||||
enum {button, slider, wheel, keymatrix};
|
enum {button, slider, wheel, keymatrix};
|
||||||
enum {horizontal, vertical};
|
enum {horizontal, vertical};
|
||||||
enum {inactive, active};
|
enum {inactive, active};
|
||||||
|
enum {modePassive, modeActive};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Description: creates the GUI thread
|
* Description: creates the GUI thread
|
||||||
|
@ -77,7 +79,7 @@ uint8_t guiDeleteElement(char *label);
|
||||||
*/
|
*/
|
||||||
uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, font_t font, uint16_t fontColor, uint16_t buttonColor, uint16_t shadow, char *label, uint8_t *active, uint8_t *state);
|
uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, font_t font, uint16_t fontColor, uint16_t buttonColor, uint16_t shadow, char *label, uint8_t *active, uint8_t *state);
|
||||||
|
|
||||||
uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value);
|
uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t orientation, uint8_t mode, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value);
|
||||||
|
|
||||||
uint8_t guiDrawWheel(uint16_t x0, uint16_t y0, uint16_t radius1, uint16_t radius2, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value);
|
uint8_t guiDrawWheel(uint16_t x0, uint16_t y0, uint16_t radius1, uint16_t radius2, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue