Added Checkbox support
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "touch.h"
|
#include "touch.h"
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
|
#include "checkbox.h"
|
||||||
#include "pixy.h"
|
#include "pixy.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -43,8 +44,11 @@ void buttonCB(void* button) {
|
|||||||
printf("button pressed\n");
|
printf("button pressed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHECKBOX_STRUCT c1;
|
||||||
|
|
||||||
|
void checkboxCB(void *checkbox, bool checked) {
|
||||||
|
printf("Checkbox %s\n",(checked?"checked":"unchecked"));
|
||||||
|
}
|
||||||
|
|
||||||
void app_init() {
|
void app_init() {
|
||||||
system_init();
|
system_init();
|
||||||
@@ -73,8 +77,8 @@ void app_init() {
|
|||||||
tft_draw_rectangle(30,30,100,60,BLUE);
|
tft_draw_rectangle(30,30,100,60,BLUE);
|
||||||
tft_print_line(30, 30, RED, BLUE, 0, "Hallo");*/
|
tft_print_line(30, 30, RED, BLUE, 0, "Hallo");*/
|
||||||
|
|
||||||
//b_alarm_ok
|
//button test
|
||||||
b1.base.x1=25; //Start X of Button
|
b1.base.x1=25; //Start X of Button
|
||||||
b1.base.y1=45; //Start Y of Button
|
b1.base.y1=45; //Start Y of Button
|
||||||
b1.base.x2=AUTO; //b1.base.x1+160; //Auto Calculate X2 with String Width
|
b1.base.x2=AUTO; //b1.base.x1+160; //Auto Calculate X2 with String Width
|
||||||
b1.base.y2=AUTO; //Auto Calculate Y2 with String Height
|
b1.base.y2=AUTO; //Auto Calculate Y2 with String Height
|
||||||
@@ -85,6 +89,16 @@ void app_init() {
|
|||||||
b1.callback=buttonCB; //Call b1_cb as Callback
|
b1.callback=buttonCB; //Call b1_cb as Callback
|
||||||
gui_button_add(&b1); //Register Button (and run the callback from now on)
|
gui_button_add(&b1); //Register Button (and run the callback from now on)
|
||||||
|
|
||||||
|
//Checkbox test
|
||||||
|
c1.base.x1=220;
|
||||||
|
c1.base.y1=45;
|
||||||
|
c1.base.x2=c1.base.x1+16;
|
||||||
|
c1.base.y2=c1.base.y1+16;
|
||||||
|
c1.fgcolor = GREEN;
|
||||||
|
c1.checked = true;
|
||||||
|
c1.callback = checkboxCB;
|
||||||
|
gui_checkbox_add(&c1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -97,7 +111,8 @@ int pixy_frame_test();
|
|||||||
void app_process() {
|
void app_process() {
|
||||||
|
|
||||||
system_process(); //Let the system handle it's pending events
|
system_process(); //Let the system handle it's pending events
|
||||||
gui_button_redraw(&b1);
|
//gui_button_redraw(&b1);
|
||||||
|
///gui_checkbox_redraw(&c1);
|
||||||
|
|
||||||
//Note: The only way to detect that pixy has been disconnected is if a command fails. There's no pixy_is_connected method yet :'(
|
//Note: The only way to detect that pixy has been disconnected is if a command fails. There's no pixy_is_connected method yet :'(
|
||||||
|
|
||||||
|
|||||||
88
common/gui/checkbox.c
Normal file
88
common/gui/checkbox.c
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include "tft.h"
|
||||||
|
#include "touch.h"
|
||||||
|
#include "checkbox.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define BRIGHTNESS_VAL 2 //How much the Brightness is in/decreased for checkbox shadows (3 -> Add 1/3 off Full Value)
|
||||||
|
#define ACTIVE_COLOR RGB(251,208,123)
|
||||||
|
#define BORDER_COLOR RGB(29,82,129)
|
||||||
|
#define BACKGROUND_COLOR WHITE
|
||||||
|
|
||||||
|
void checkboxes_cb(void* touchArea, TOUCH_ACTION triggeredAction)
|
||||||
|
{
|
||||||
|
TOUCH_AREA_STRUCT * area = (TOUCH_AREA_STRUCT*)touchArea;
|
||||||
|
CHECKBOX_STRUCT* checkbox = (CHECKBOX_STRUCT*)touchArea;
|
||||||
|
switch(triggeredAction)
|
||||||
|
{
|
||||||
|
case PEN_DOWN:
|
||||||
|
area->hookedActions=PEN_UP|PEN_LEAVE;
|
||||||
|
tft_draw_rectangle(checkbox->base.x1+1,checkbox->base.y1+1,checkbox->base.x2-1,checkbox->base.y2-1,ACTIVE_COLOR);
|
||||||
|
tft_draw_rectangle(checkbox->base.x1+2,checkbox->base.y1+2,checkbox->base.x2-2,checkbox->base.y2-2,ACTIVE_COLOR);
|
||||||
|
break;
|
||||||
|
case PEN_UP:
|
||||||
|
checkbox->checked=!checkbox->checked;
|
||||||
|
gui_checkbox_update(checkbox);
|
||||||
|
if(checkbox->callback!=NULL)
|
||||||
|
checkbox->callback(checkbox,checkbox->checked);
|
||||||
|
case PEN_LEAVE:
|
||||||
|
area->hookedActions=PEN_DOWN;
|
||||||
|
tft_draw_rectangle(checkbox->base.x1+1,checkbox->base.y1+1,checkbox->base.x2-1,checkbox->base.y2-1,BACKGROUND_COLOR);
|
||||||
|
tft_draw_rectangle(checkbox->base.x1+2,checkbox->base.y1+2,checkbox->base.x2-2,checkbox->base.y2-2,BACKGROUND_COLOR);
|
||||||
|
break;
|
||||||
|
default:break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gui_checkbox_add(CHECKBOX_STRUCT* checkbox)
|
||||||
|
{
|
||||||
|
if(touch_have_empty(1))
|
||||||
|
{
|
||||||
|
unsigned char size=0;
|
||||||
|
checkbox->base.hookedActions=PEN_DOWN;
|
||||||
|
checkbox->base.callback = checkboxes_cb;
|
||||||
|
if(checkbox->base.x2>checkbox->base.x1)
|
||||||
|
size = checkbox->base.x2 - checkbox->base.x1;
|
||||||
|
if(checkbox->base.y2>checkbox->base.y1)
|
||||||
|
{
|
||||||
|
if((checkbox->base.y2 - checkbox->base.y1)>size)
|
||||||
|
size = checkbox->base.y2 - checkbox->base.y1;
|
||||||
|
}
|
||||||
|
if((size&0x01))
|
||||||
|
size++;
|
||||||
|
checkbox->base.x2 = checkbox->base.x1 + size;
|
||||||
|
checkbox->base.y2 = checkbox->base.y1 + size;
|
||||||
|
gui_checkbox_redraw(checkbox);
|
||||||
|
return touch_register_area(&checkbox->base);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_checkbox_redraw(CHECKBOX_STRUCT* checkbox)
|
||||||
|
{
|
||||||
|
tft_fill_rectangle(checkbox->base.x1+1,checkbox->base.y1+1,checkbox->base.x2-1,checkbox->base.y2-1,BACKGROUND_COLOR);
|
||||||
|
tft_draw_rectangle(checkbox->base.x1,checkbox->base.y1,checkbox->base.x2,checkbox->base.y2,BORDER_COLOR);
|
||||||
|
if(checkbox->checked)
|
||||||
|
gui_checkbox_update(checkbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_checkbox_remove(CHECKBOX_STRUCT* checkbox)
|
||||||
|
{
|
||||||
|
touch_unregister_area((TOUCH_AREA_STRUCT*)checkbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_checkbox_update(CHECKBOX_STRUCT* checkbox)
|
||||||
|
{
|
||||||
|
unsigned int c = (checkbox->checked)? checkbox->fgcolor:BACKGROUND_COLOR;
|
||||||
|
unsigned int xcent = checkbox->base.x1+(checkbox->base.x2-checkbox->base.x1)*6/14;
|
||||||
|
unsigned int yleft = checkbox->base.y2 - (xcent- checkbox->base.x1) - 1 ;
|
||||||
|
unsigned int yright = checkbox->base.y2 - (checkbox->base.x2 - xcent) - 1 ;
|
||||||
|
unsigned int ybot = checkbox->base.y2 - 4;
|
||||||
|
tft_draw_line(checkbox->base.x1+3,yleft-1,xcent,ybot -1,c);
|
||||||
|
tft_draw_line(checkbox->base.x1+3,yleft,xcent,ybot ,c);
|
||||||
|
tft_draw_line(checkbox->base.x1+3,yleft+1,xcent,ybot + 1,c);
|
||||||
|
xcent++;
|
||||||
|
ybot--;
|
||||||
|
tft_draw_line(xcent,ybot-1,checkbox->base.x2-3,yright-1,c);
|
||||||
|
tft_draw_line(xcent,ybot,checkbox->base.x2-3,yright+0,c);
|
||||||
|
tft_draw_line(xcent,ybot+1,checkbox->base.x2-3,yright+1,c);
|
||||||
|
}
|
||||||
15
common/gui/checkbox.h
Normal file
15
common/gui/checkbox.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
typedef void (*CHECKBOX_CALLBACK)(void *checkbox, bool checked); //!< Function pointer used...
|
||||||
|
typedef struct {
|
||||||
|
TOUCH_AREA_STRUCT base;
|
||||||
|
uint16_t fgcolor;
|
||||||
|
bool checked;
|
||||||
|
CHECKBOX_CALLBACK callback; //Callback
|
||||||
|
} CHECKBOX_STRUCT;
|
||||||
|
|
||||||
|
|
||||||
|
bool gui_checkbox_add(CHECKBOX_STRUCT* checkbox);
|
||||||
|
void gui_checkbox_remove(CHECKBOX_STRUCT* checkbox);
|
||||||
|
void gui_checkbox_update(CHECKBOX_STRUCT* checkbox);
|
||||||
|
void gui_checkbox_redraw(CHECKBOX_STRUCT* checkbox);
|
||||||
|
#define CHECKBOX_WIN_FG_COLOR RGB(32,161,34)
|
||||||
Reference in New Issue
Block a user