aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTectu <joel@unormal.org>2012-07-09 20:45:02 +0200
committerTectu <joel@unormal.org>2012-07-09 20:45:02 +0200
commit4df715dd4600ddd05afe579ff742fbb331710cbc (patch)
tree12af8da333acab48f1ec8c634bbe926a600c354e
parent894770e5961c2e356313f9e70a8ea63b763bf9c5 (diff)
downloaduGFX-4df715dd4600ddd05afe579ff742fbb331710cbc.tar.gz
uGFX-4df715dd4600ddd05afe579ff742fbb331710cbc.tar.bz2
uGFX-4df715dd4600ddd05afe579ff742fbb331710cbc.zip
added guiDrawSlider()
-rw-r--r--gui.c34
-rw-r--r--gui.h4
2 files changed, 30 insertions, 8 deletions
diff --git a/gui.c b/gui.c
index 36db6c7c..0dce1c77 100644
--- a/gui.c
+++ b/gui.c
@@ -2,7 +2,7 @@
static struct guiNode_t *firstGUI = NULL;
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) {
struct guiNode_t *new;
@@ -90,14 +90,33 @@ static inline void buttonUpdate(struct guiNode_t *node) {
}
static inline void sliderUpdate(struct guiNode_t *node) {
- (void)node;
+ uint16_t value, length;
+
+ if(node->orientation == horizontal)
+ length = node->x1 - node->x0;
+ else if(node->orientation == vertical)
+ length = node->y1 - node->y0;
+
+ 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);
+ }
+ }
- uint16_t percent = 0, value = 0;
+ *(node->state) = percent;
+ }
- percent = *(node->state);
+ // a bit of safety here
if(percent > 100)
- percent = 100;
-
+ percent = 100;
+ if(percent < 0)
+ percent = 0;
+
if(node->orientation == horizontal) {
value = ((((node->x1)-(node->x0)) * percent) / 100);
if(value_old > value || value == 0)
@@ -203,7 +222,7 @@ uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *
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;
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->x1 = x1;
newNode->y1 = y1;
+ newNode->mode = mode;
newNode->bkColor = bkColor;
newNode->valueColor = valueColor;
newNode->state = value;
diff --git a/gui.h b/gui.h
index 49b8241f..e1606e45 100644
--- a/gui.h
+++ b/gui.h
@@ -20,6 +20,7 @@ struct guiNode_t {
uint16_t bkColor;
uint16_t valueColor;
uint8_t orientation;
+ uint8_t mode;
uint8_t *active;
uint8_t *state;
char *label;
@@ -33,6 +34,7 @@ extern "C" {
enum {button, slider, wheel, keymatrix};
enum {horizontal, vertical};
enum {inactive, active};
+enum {modePassive, modeActive};
/*
* 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 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);