Update GWIN demos
This commit is contained in:
parent
8681e85ba6
commit
ba264ef1ad
5 changed files with 304 additions and 195 deletions
demos/modules
|
@ -28,7 +28,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
#include "chprintf.h"
|
|
||||||
|
|
||||||
static GConsoleObject gc;
|
static GConsoleObject gc;
|
||||||
static GButtonObject gNext;
|
static GButtonObject gNext;
|
||||||
|
@ -39,15 +38,15 @@ static GListener gl;
|
||||||
* GINPUT Touch Driver Calibrator. *
|
* GINPUT Touch Driver Calibrator. *
|
||||||
*------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------*/
|
||||||
int main(void) {
|
int main(void) {
|
||||||
GSourceHandle gs, gsNext, gsPrev;
|
GSourceHandle gs;
|
||||||
GEvent *pe;
|
GEvent *pe;
|
||||||
GEventMouse *pem;
|
GEventMouse *pem;
|
||||||
GEventGWinButton *peb;
|
GEventGWinButton *peb;
|
||||||
coord_t swidth, sheight;
|
coord_t swidth, sheight;
|
||||||
GHandle ghc, ghNext, ghPrev;
|
GHandle ghc, ghNext, ghPrev;
|
||||||
BaseSequentialStream *gp;
|
|
||||||
GEventType deviceType;
|
GEventType deviceType;
|
||||||
font_t font;
|
font_t font;
|
||||||
|
GWidgetInit wi;
|
||||||
|
|
||||||
gfxInit(); // Initialize the display
|
gfxInit(); // Initialize the display
|
||||||
|
|
||||||
|
@ -58,12 +57,13 @@ int main(void) {
|
||||||
|
|
||||||
// Create our title
|
// Create our title
|
||||||
font = gdispOpenFont("UI2");
|
font = gdispOpenFont("UI2");
|
||||||
|
gwinSetDefaultFont(font);
|
||||||
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Red, White, justifyLeft);
|
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Red, White, justifyLeft);
|
||||||
|
|
||||||
// Create our main display window
|
// Create our main display window
|
||||||
ghc = gwinCreateConsole(&gc, 0, 20, swidth, sheight-20, font);
|
wi.g.show = TRUE; wi.g.x = 0; wi.g.y = 20; wi.g.width = swidth; wi.g.height = sheight-20;
|
||||||
|
ghc = gwinConsoleCreate(&gc, &wi.g);
|
||||||
gwinClear(ghc);
|
gwinClear(ghc);
|
||||||
gp = gwinGetConsoleStream(ghc);
|
|
||||||
|
|
||||||
// Initialize the mouse in our special no calibration mode.
|
// Initialize the mouse in our special no calibration mode.
|
||||||
geventListenerInit(&gl);
|
geventListenerInit(&gl);
|
||||||
|
@ -77,22 +77,22 @@ int main(void) {
|
||||||
StepDeviceType:
|
StepDeviceType:
|
||||||
gwinClear(ghc);
|
gwinClear(ghc);
|
||||||
gwinSetColor(ghc, Yellow);
|
gwinSetColor(ghc, Yellow);
|
||||||
chprintf(gp, "\n1. DEVICE TYPE\n\n");
|
gwinPrintf(ghc, "\n1. DEVICE TYPE\n\n");
|
||||||
|
|
||||||
pem = (GEventMouse *)&gl.event;
|
pem = (GEventMouse *)&gl.event;
|
||||||
ginputGetMouseStatus(0, pem);
|
ginputGetMouseStatus(0, pem);
|
||||||
deviceType = pem->type;
|
deviceType = pem->type;
|
||||||
|
|
||||||
gwinSetColor(ghc, White);
|
gwinSetColor(ghc, White);
|
||||||
chprintf(gp, "This is detected as a %s device\n\n",
|
gwinPrintf(ghc, "This is detected as a %s device\n\n",
|
||||||
deviceType == GEVENT_MOUSE ? "MOUSE" : (pem->type == GEVENT_TOUCH ? "TOUCH" : "UNKNOWN"));
|
deviceType == GEVENT_MOUSE ? "MOUSE" : (pem->type == GEVENT_TOUCH ? "TOUCH" : "UNKNOWN"));
|
||||||
|
|
||||||
if (ghNext)
|
if (ghNext)
|
||||||
chprintf(gp, "Press Next or Back to continue.\n");
|
gwinPrintf(ghc, "Press Next or Back to continue.\n");
|
||||||
else if (deviceType == GEVENT_MOUSE)
|
else if (deviceType == GEVENT_MOUSE)
|
||||||
chprintf(gp, "Click the mouse button to move on to the next test.\n");
|
gwinPrintf(ghc, "Click the mouse button to move on to the next test.\n");
|
||||||
else
|
else
|
||||||
chprintf(gp, "Press and release your finger to move on to the next test.\n");
|
gwinPrintf(ghc, "Press and release your finger to move on to the next test.\n");
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
pe = geventEventWait(&gl, TIME_INFINITE);
|
pe = geventEventWait(&gl, TIME_INFINITE);
|
||||||
|
@ -117,23 +117,23 @@ StepDeviceType:
|
||||||
StepRawJitter:
|
StepRawJitter:
|
||||||
gwinClear(ghc);
|
gwinClear(ghc);
|
||||||
gwinSetColor(ghc, Yellow);
|
gwinSetColor(ghc, Yellow);
|
||||||
chprintf(gp, "\n2. GINPUT_MOUSE_READ_CYCLES\n\n");
|
gwinPrintf(ghc, "\n2. GINPUT_MOUSE_READ_CYCLES\n\n");
|
||||||
|
|
||||||
gwinSetColor(ghc, White);
|
gwinSetColor(ghc, White);
|
||||||
if (deviceType == GEVENT_MOUSE)
|
if (deviceType == GEVENT_MOUSE)
|
||||||
chprintf(gp, "Press and hold the mouse button.\n\n");
|
gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
|
||||||
else
|
else
|
||||||
chprintf(gp, "Press and hold on the surface.\n\n");
|
gwinPrintf(ghc, "Press and hold on the surface.\n\n");
|
||||||
chprintf(gp, "Numbers will display in this window.\n"
|
gwinPrintf(ghc, "Numbers will display in this window.\n"
|
||||||
"Ensure that values don't jump around very much when your finger is stationary.\n\n"
|
"Ensure that values don't jump around very much when your finger is stationary.\n\n"
|
||||||
"Increasing GINPUT_MOUSE_READ_CYCLES helps reduce jitter but increases CPU usage.\n\n");
|
"Increasing GINPUT_MOUSE_READ_CYCLES helps reduce jitter but increases CPU usage.\n\n");
|
||||||
|
|
||||||
if (ghNext)
|
if (ghNext)
|
||||||
chprintf(gp, "Press Next or Back to continue.\n");
|
gwinPrintf(ghc, "Press Next or Back to continue.\n");
|
||||||
else if (deviceType == GEVENT_MOUSE)
|
else if (deviceType == GEVENT_MOUSE)
|
||||||
chprintf(gp, "Release the mouse button to move on to the next test.\n");
|
gwinPrintf(ghc, "Release the mouse button to move on to the next test.\n");
|
||||||
else
|
else
|
||||||
chprintf(gp, "Release your finger to move on to the next test.\n");
|
gwinPrintf(ghc, "Release your finger to move on to the next test.\n");
|
||||||
|
|
||||||
// For this test turn on ALL mouse movement events
|
// For this test turn on ALL mouse movement events
|
||||||
geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER);
|
geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER);
|
||||||
|
@ -150,7 +150,7 @@ StepRawJitter:
|
||||||
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) {
|
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) {
|
||||||
pem = (GEventMouse *)pe;
|
pem = (GEventMouse *)pe;
|
||||||
if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
|
if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
|
||||||
chprintf(gp, "%u:%u\n", pem->x, pem->y);
|
gwinPrintf(ghc, "%u:%u\n", pem->x, pem->y);
|
||||||
if (!ghNext && (pem->meta & GMETA_MOUSE_UP))
|
if (!ghNext && (pem->meta & GMETA_MOUSE_UP))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -166,19 +166,19 @@ StepRawJitter:
|
||||||
StepCalibrate:
|
StepCalibrate:
|
||||||
gwinClear(ghc);
|
gwinClear(ghc);
|
||||||
gwinSetColor(ghc, Yellow);
|
gwinSetColor(ghc, Yellow);
|
||||||
chprintf(gp, "\n3. GINPUT_MOUSE_CALIBRATION_ERROR\n\n");
|
gwinPrintf(ghc, "\n3. GINPUT_MOUSE_CALIBRATION_ERROR\n\n");
|
||||||
gwinSetColor(ghc, Gray);
|
gwinSetColor(ghc, Gray);
|
||||||
chprintf(gp, "Ensure GINPUT_MOUSE_NEED_CALIBRATION = TRUE and GINPUT_MOUSE_CALIBRATION_ERROR is >= 0\n\n");
|
gwinPrintf(ghc, "Ensure GINPUT_MOUSE_NEED_CALIBRATION = TRUE and GINPUT_MOUSE_CALIBRATION_ERROR is >= 0\n\n");
|
||||||
gwinSetColor(ghc, White);
|
gwinSetColor(ghc, White);
|
||||||
chprintf(gp, "You will be presented with a number of points to touch.\nPress them in turn.\n\n"
|
gwinPrintf(ghc, "You will be presented with a number of points to touch.\nPress them in turn.\n\n"
|
||||||
"If the calibration repeatedly fails, increase GINPUT_MOUSE_CALIBRATION_ERROR and try again.\n\n");
|
"If the calibration repeatedly fails, increase GINPUT_MOUSE_CALIBRATION_ERROR and try again.\n\n");
|
||||||
|
|
||||||
if (ghNext)
|
if (ghNext)
|
||||||
chprintf(gp, "Press Next to start the calibration.\n");
|
gwinPrintf(ghc, "Press Next to start the calibration.\n");
|
||||||
else if (deviceType == GEVENT_MOUSE)
|
else if (deviceType == GEVENT_MOUSE)
|
||||||
chprintf(gp, "Click the mouse button to start the calibration.\n");
|
gwinPrintf(ghc, "Click the mouse button to start the calibration.\n");
|
||||||
else
|
else
|
||||||
chprintf(gp, "Press and release your finger to start the calibration.\n");
|
gwinPrintf(ghc, "Press and release your finger to start the calibration.\n");
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
pe = geventEventWait(&gl, TIME_INFINITE);
|
pe = geventEventWait(&gl, TIME_INFINITE);
|
||||||
|
@ -201,37 +201,21 @@ StepCalibrate:
|
||||||
|
|
||||||
/* From now on we can use Next and Previous Buttons */
|
/* From now on we can use Next and Previous Buttons */
|
||||||
if (!ghNext) {
|
if (!ghNext) {
|
||||||
|
gwinAttachMouse(0);
|
||||||
|
gwinAttachListener(&gl);
|
||||||
|
|
||||||
ghNext = gwinCreateButton(&gNext, swidth-50, 0, 50, 20, font, GBTN_NORMAL);
|
wi.customDraw = 0; wi.customParam = 0; wi.customStyle = 0;
|
||||||
gwinSetButtonText(ghNext, "Next", FALSE);
|
wi.g.show = TRUE; wi.g.x = swidth-50; wi.g.y = 0; wi.g.width = 50; wi.g.height = 20;
|
||||||
gsNext = gwinGetButtonSource(ghNext);
|
wi.text = "Next"; ghNext = gwinButtonCreate(&gNext, &wi);
|
||||||
geventAttachSource(&gl, gsNext, 0);
|
|
||||||
gwinAttachButtonMouse(ghNext, 0);
|
|
||||||
|
|
||||||
ghPrev = gwinCreateButton(&gPrev, swidth-100, 0, 50, 20, font, GBTN_NORMAL);
|
wi.g.show = TRUE; wi.g.x = swidth-100;
|
||||||
gwinSetButtonText(ghPrev, "Back", FALSE);
|
wi.text = "Back"; ghPrev = gwinButtonCreate(&gPrev, &wi);
|
||||||
gsPrev = gwinGetButtonSource(ghPrev);
|
|
||||||
geventAttachSource(&gl, gsPrev, 0);
|
|
||||||
gwinAttachButtonMouse(ghPrev, 0);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
{
|
|
||||||
// Attach a couple of hardware toggle buttons to our Next and Back buttons as well.
|
|
||||||
// We can always use the mouse to trigger the buttons if you don't want to use hardware toggles.
|
|
||||||
// This code depends on your hardware. Turn it on only if you have
|
|
||||||
// defined a board definition for your toggle driver. Then change
|
|
||||||
// the next two lines to be correct for your hardware. The values
|
|
||||||
// below are correct for the Win32 toggle driver.
|
|
||||||
gwinAttachButtonToggle(ghNext, GINPUT_TOGGLE_MOMENTARY1);
|
|
||||||
gwinAttachButtonToggle(ghPrev, GINPUT_TOGGLE_MOMENTARY2);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calibration used the whole screen - re-establish our title
|
// Calibration used the whole screen - re-establish our title
|
||||||
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Green, White, justifyLeft);
|
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Green, White, justifyLeft);
|
||||||
gwinButtonDraw(ghNext);
|
gwinRedraw(ghNext);
|
||||||
gwinButtonDraw(ghPrev);
|
gwinRedraw(ghPrev);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test: Mouse movement jitter
|
* Test: Mouse movement jitter
|
||||||
|
@ -240,18 +224,18 @@ StepCalibrate:
|
||||||
StepJitter:
|
StepJitter:
|
||||||
gwinClear(ghc);
|
gwinClear(ghc);
|
||||||
gwinSetColor(ghc, Yellow);
|
gwinSetColor(ghc, Yellow);
|
||||||
chprintf(gp, "\n4. GINPUT_MOUSE_MOVE_JITTER\n\n");
|
gwinPrintf(ghc, "\n4. GINPUT_MOUSE_MOVE_JITTER\n\n");
|
||||||
|
|
||||||
gwinSetColor(ghc, White);
|
gwinSetColor(ghc, White);
|
||||||
if (deviceType == GEVENT_MOUSE)
|
if (deviceType == GEVENT_MOUSE)
|
||||||
chprintf(gp, "Press and hold the mouse button and move around as if to draw.\n\n");
|
gwinPrintf(ghc, "Press and hold the mouse button and move around as if to draw.\n\n");
|
||||||
else
|
else
|
||||||
chprintf(gp, "Press firmly on the surface and move around as if to draw.\n\n");
|
gwinPrintf(ghc, "Press firmly on the surface and move around as if to draw.\n\n");
|
||||||
|
|
||||||
chprintf(gp, "Dots will display in this window. Ensure that when you stop moving your finger that "
|
gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your finger that "
|
||||||
"new dots stop displaying.\nNew dots should only display when your finger is moving.\n\n"
|
"new dots stop displaying.\nNew dots should only display when your finger is moving.\n\n"
|
||||||
"Adjust GINPUT_MOUSE_MOVE_JITTER to the smallest value that this reliably works for.\n\n");
|
"Adjust GINPUT_MOUSE_MOVE_JITTER to the smallest value that this reliably works for.\n\n");
|
||||||
chprintf(gp, "Press Next or Back to continue.\n\n");
|
gwinPrintf(ghc, "Press Next or Back to continue.\n\n");
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
pe = geventEventWait(&gl, TIME_INFINITE);
|
pe = geventEventWait(&gl, TIME_INFINITE);
|
||||||
|
@ -265,7 +249,7 @@ StepJitter:
|
||||||
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) {
|
if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) {
|
||||||
pem = (GEventMouse *)pe;
|
pem = (GEventMouse *)pe;
|
||||||
if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
|
if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
|
||||||
chprintf(gp, ".");
|
gwinPrintf(ghc, ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,16 +260,16 @@ StepJitter:
|
||||||
StepPolling:
|
StepPolling:
|
||||||
gwinClear(ghc);
|
gwinClear(ghc);
|
||||||
gwinSetColor(ghc, Yellow);
|
gwinSetColor(ghc, Yellow);
|
||||||
chprintf(gp, "\n5. GINPUT_MOUSE_POLL_PERIOD\n\n");
|
gwinPrintf(ghc, "\n5. GINPUT_MOUSE_POLL_PERIOD\n\n");
|
||||||
|
|
||||||
gwinSetColor(ghc, White);
|
gwinSetColor(ghc, White);
|
||||||
chprintf(gp, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n");
|
gwinPrintf(ghc, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n");
|
||||||
chprintf(gp, "A green line will follow your finger.\n"
|
gwinPrintf(ghc, "A green line will follow your finger.\n"
|
||||||
"Adjust GINPUT_MOUSE_POLL_PERIOD to the highest value that provides a line without "
|
"Adjust GINPUT_MOUSE_POLL_PERIOD to the highest value that provides a line without "
|
||||||
"gaps that are too big.\nDecreasing the value increases CPU usage.\n"
|
"gaps that are too big.\nDecreasing the value increases CPU usage.\n"
|
||||||
"About 25 (millisecs) normally produces good results."
|
"About 25 (millisecs) normally produces good results."
|
||||||
"This test can be ignored for interrupt driven drivers.\n\n");
|
"This test can be ignored for interrupt driven drivers.\n\n");
|
||||||
chprintf(gp, "Press Next or Back to continue.\n\n");
|
gwinPrintf(ghc, "Press Next or Back to continue.\n\n");
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
pe = geventEventWait(&gl, TIME_INFINITE);
|
pe = geventEventWait(&gl, TIME_INFINITE);
|
||||||
|
@ -310,18 +294,18 @@ StepPolling:
|
||||||
StepClickJitter:
|
StepClickJitter:
|
||||||
gwinClear(ghc);
|
gwinClear(ghc);
|
||||||
gwinSetColor(ghc, Yellow);
|
gwinSetColor(ghc, Yellow);
|
||||||
chprintf(gp, "\n6. GINPUT_MOUSE_MAX_CLICK_JITTER\n\n");
|
gwinPrintf(ghc, "\n6. GINPUT_MOUSE_MAX_CLICK_JITTER\n\n");
|
||||||
|
|
||||||
gwinSetColor(ghc, White);
|
gwinSetColor(ghc, White);
|
||||||
chprintf(gp, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n");
|
gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n");
|
||||||
chprintf(gp, "For a mouse click with the left and right buttons.\n\n");
|
gwinPrintf(ghc, "For a mouse click with the left and right buttons.\n\n");
|
||||||
chprintf(gp, "Dots will display in this window. A yellow dash is a left (or short) click. "
|
gwinPrintf(ghc, "Dots will display in this window. A yellow dash is a left (or short) click. "
|
||||||
"A red x is a right (or long) click.\n\n"
|
"A red x is a right (or long) click.\n\n"
|
||||||
"Adjust GINPUT_MOUSE_CLICK_JITTER to the smallest value that this reliably works for.\n"
|
"Adjust GINPUT_MOUSE_CLICK_JITTER to the smallest value that this reliably works for.\n"
|
||||||
"Adjust GINPUT_MOUSE_CLICK_TIME to adjust distinguishing short vs long presses.\n"
|
"Adjust GINPUT_MOUSE_CLICK_TIME to adjust distinguishing short vs long presses.\n"
|
||||||
"TIME_INFINITE means there are no long presses (although a right mouse button will still work).\n\n"
|
"TIME_INFINITE means there are no long presses (although a right mouse button will still work).\n\n"
|
||||||
"Note: moving your finger (mouse) during a click cancels it.\n\n");
|
"Note: moving your finger (mouse) during a click cancels it.\n\n");
|
||||||
chprintf(gp, "This is the last test but you can press Next or Back to continue.\n\n");
|
gwinPrintf(ghc, "This is the last test but you can press Next or Back to continue.\n\n");
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
pe = geventEventWait(&gl, TIME_INFINITE);
|
pe = geventEventWait(&gl, TIME_INFINITE);
|
||||||
|
@ -336,11 +320,11 @@ StepClickJitter:
|
||||||
pem = (GEventMouse *)pe;
|
pem = (GEventMouse *)pe;
|
||||||
if ((pem->meta & GMETA_MOUSE_CLICK)) {
|
if ((pem->meta & GMETA_MOUSE_CLICK)) {
|
||||||
gwinSetColor(ghc, Yellow);
|
gwinSetColor(ghc, Yellow);
|
||||||
chprintf(gp, "-");
|
gwinPrintf(ghc, "-");
|
||||||
}
|
}
|
||||||
if ((pem->meta & GMETA_MOUSE_CXTCLICK)) {
|
if ((pem->meta & GMETA_MOUSE_CXTCLICK)) {
|
||||||
gwinSetColor(ghc, Red);
|
gwinSetColor(ghc, Red);
|
||||||
chprintf(gp, "x");
|
gwinPrintf(ghc, "x");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,14 @@ int main(void) {
|
||||||
gdispClear(Lime);
|
gdispClear(Lime);
|
||||||
|
|
||||||
/* Create two windows */
|
/* Create two windows */
|
||||||
GW1 = gwinCreateWindow(NULL, 20, 10, 200, 150);
|
{
|
||||||
GW2 = gwinCreateWindow(NULL, 50, 190, 150, 100);
|
GWindowInit wi;
|
||||||
|
|
||||||
|
wi.show = TRUE; wi.x = 20; wi.y = 10; wi.width = 200; wi.height = 150;
|
||||||
|
GW1 = gwinWindowCreate(NULL, &wi);
|
||||||
|
wi.show = TRUE; wi.x = 50; wi.y = 190; wi.width = 150; wi.height = 100;
|
||||||
|
GW2 = gwinWindowCreate(NULL, &wi);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set fore- and background colors for both windows */
|
/* Set fore- and background colors for both windows */
|
||||||
gwinSetColor(GW1, Black);
|
gwinSetColor(GW1, Black);
|
||||||
|
@ -53,9 +59,9 @@ int main(void) {
|
||||||
gwinClear(GW1);
|
gwinClear(GW1);
|
||||||
gwinClear(GW2);
|
gwinClear(GW2);
|
||||||
|
|
||||||
gwinDrawLine (GW1, 5, 30, 150, 110);
|
gwinDrawLine(GW1, 5, 30, 150, 110);
|
||||||
for(i=5, j=0; i < 200 && j < 150; i+=3, j+=i/20)
|
for(i=5, j=0; i < 200 && j < 150; i+=3, j+=i/20)
|
||||||
gwinDrawPixel (GW1, i, j);
|
gwinDrawPixel(GW1, i, j);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Draw two filled circles at the same coordinate
|
* Draw two filled circles at the same coordinate
|
||||||
|
|
|
@ -28,27 +28,37 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
#include "chprintf.h"
|
|
||||||
|
|
||||||
/* The handles for our three consoles */
|
/* The handles for our three consoles */
|
||||||
GHandle GW1, GW2, GW3;
|
GHandle GW1, GW2, GW3;
|
||||||
|
|
||||||
/* The streams for our three consoles */
|
|
||||||
BaseSequentialStream *S1, *S2, *S3;
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
font_t font1, font2;
|
font_t font1, font2;
|
||||||
|
|
||||||
/* initialize and clear the display */
|
/* initialize and clear the display */
|
||||||
gfxInit();
|
gfxInit();
|
||||||
font1 = gdispOpenFont("UI2 Double");
|
|
||||||
font2 = gdispOpenFont("Small");
|
|
||||||
|
|
||||||
/* create the three console windows and set a font for each */
|
/* Set some fonts */
|
||||||
GW1 = gwinCreateConsole(NULL, 0, 0, gdispGetWidth(), gdispGetHeight()/2, font1);
|
font1 = gdispOpenFont("Small");
|
||||||
GW2 = gwinCreateConsole(NULL, 0, gdispGetHeight()/2, gdispGetWidth()/2, gdispGetHeight(), font2);
|
font2 = gdispOpenFont("UI2 Double");
|
||||||
GW3 = gwinCreateConsole(NULL, gdispGetWidth()/2, gdispGetHeight()/2, gdispGetWidth(), gdispGetHeight(), font2);
|
gwinSetDefaultFont(font1);
|
||||||
|
|
||||||
|
/* create the three console windows */
|
||||||
|
{
|
||||||
|
GWindowInit wi;
|
||||||
|
|
||||||
|
wi.show = TRUE;
|
||||||
|
wi.x = 0; wi.y = 0; wi.width = gdispGetWidth(); wi.height = gdispGetHeight()/2;
|
||||||
|
GW1 = gwinConsoleCreate(NULL, &wi);
|
||||||
|
wi.y = gdispGetHeight()/2; wi.width = gdispGetWidth()/2; wi.height = gdispGetHeight();
|
||||||
|
GW2 = gwinConsoleCreate(NULL, &wi);
|
||||||
|
wi.x = gdispGetWidth()/2; wi.height = gdispGetHeight();
|
||||||
|
GW3 = gwinConsoleCreate(NULL, &wi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use a special font for GW1 */
|
||||||
|
gwinSetFont(GW1, font2);
|
||||||
|
|
||||||
/* Set the fore- and background colors for each console */
|
/* Set the fore- and background colors for each console */
|
||||||
gwinSetColor(GW1, Green);
|
gwinSetColor(GW1, Green);
|
||||||
|
@ -63,24 +73,19 @@ int main(void) {
|
||||||
gwinClear(GW2);
|
gwinClear(GW2);
|
||||||
gwinClear(GW3);
|
gwinClear(GW3);
|
||||||
|
|
||||||
/* receive the stream pointers of each console */
|
|
||||||
S1 = gwinGetConsoleStream(GW1);
|
|
||||||
S2 = gwinGetConsoleStream(GW2);
|
|
||||||
S3 = gwinGetConsoleStream(GW3);
|
|
||||||
|
|
||||||
/* Output some data on the first console */
|
/* Output some data on the first console */
|
||||||
for(i = 0; i < 10; i++) {
|
for(i = 0; i < 10; i++) {
|
||||||
chprintf(S1, "Hello ChibiOS/GFX!\r\n");
|
gwinPrintf(GW1, "Hello ChibiOS/GFX!\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Output some data on the second console */
|
/* Output some data on the second console */
|
||||||
for(i = 0; i < 16; i++) {
|
for(i = 0; i < 16; i++) {
|
||||||
chprintf(S2, "Message Nr.: %d\r\n", i+1);
|
gwinPrintf(GW2, "Message Nr.: %d\r\n", i+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Output some data on the third console */
|
/* Output some data on the third console */
|
||||||
for(i = 0; i < 18; i++) {
|
for(i = 0; i < 18; i++) {
|
||||||
chprintf(S3, "Message Nr.: %d\r\n", i+1);
|
gwinPrintf(GW3, "Message Nr.: %d\r\n", i+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while(TRUE) {
|
while(TRUE) {
|
||||||
|
|
|
@ -28,20 +28,59 @@
|
||||||
|
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This demo demonstrates many of the GWIN widgets.
|
||||||
|
* On the "Radio" tab try playing with the color radio buttons.
|
||||||
|
* On the "Checkbox" tab try playing with the "Disable All" checkbox.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Our custom yellow style */
|
||||||
|
static const GWidgetStyle YellowWidgetStyle = {
|
||||||
|
Yellow, // window background
|
||||||
|
|
||||||
|
// enabled color set
|
||||||
|
{
|
||||||
|
HTML2COLOR(0x0000FF), // text
|
||||||
|
HTML2COLOR(0x404040), // edge
|
||||||
|
HTML2COLOR(0xE0E0E0), // fill
|
||||||
|
HTML2COLOR(0xE0E0E0), // progress - inactive area
|
||||||
|
},
|
||||||
|
|
||||||
|
// disabled color set
|
||||||
|
{
|
||||||
|
HTML2COLOR(0xC0C0C0), // text
|
||||||
|
HTML2COLOR(0x808080), // edge
|
||||||
|
HTML2COLOR(0xE0E0E0), // fill
|
||||||
|
HTML2COLOR(0xC0E0C0), // progress - active area
|
||||||
|
},
|
||||||
|
|
||||||
|
// pressed color set
|
||||||
|
{
|
||||||
|
HTML2COLOR(0xFF00FF), // text
|
||||||
|
HTML2COLOR(0x404040), // edge
|
||||||
|
HTML2COLOR(0x808080), // fill
|
||||||
|
HTML2COLOR(0x00E000), // progress - active area
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/* The variables we need */
|
||||||
static GListener gl;
|
static GListener gl;
|
||||||
static GHandle ghConsole;
|
static GHandle ghConsole;
|
||||||
static GHandle ghTabButtons, ghTabSliders, ghTabCheckboxes, ghTabLabels, ghTabRadios, ghTabImages;
|
static GHandle ghTabButtons, ghTabSliders, ghTabCheckboxes, ghTabLabels, ghTabRadios, ghTabImages;
|
||||||
static GHandle ghButton1, ghButton2, ghButton3, ghButton4;
|
static GHandle ghButton1, ghButton2, ghButton3, ghButton4;
|
||||||
static GHandle ghSlider1, ghSlider2, ghSlider3, ghSlider4;
|
static GHandle ghSlider1, ghSlider2, ghSlider3, ghSlider4;
|
||||||
static GHandle ghCheckbox1, ghCheckbox2;
|
static GHandle ghCheckbox1, ghCheckbox2, ghCheckDisableAll;
|
||||||
static GHandle ghLabel1;
|
static GHandle ghLabel1;
|
||||||
static GHandle ghRadio1, ghRadio2;
|
static GHandle ghRadio1, ghRadio2;
|
||||||
|
static GHandle ghRadioBlack, ghRadioWhite, ghRadioYellow;
|
||||||
//static GHandle ghImage1;
|
//static GHandle ghImage1;
|
||||||
|
|
||||||
|
/* Some useful macros */
|
||||||
#define ScrWidth gdispGetWidth()
|
#define ScrWidth gdispGetWidth()
|
||||||
#define ScrHeight gdispGetHeight()
|
#define ScrHeight gdispGetHeight()
|
||||||
|
|
||||||
#define TAB_HEIGHT 30
|
#define TAB_HEIGHT 30
|
||||||
|
#define LABEL_HEIGHT 40
|
||||||
#define BUTTON_WIDTH 50
|
#define BUTTON_WIDTH 50
|
||||||
#define BUTTON_HEIGHT 30
|
#define BUTTON_HEIGHT 30
|
||||||
#define SLIDER_WIDTH 20
|
#define SLIDER_WIDTH 20
|
||||||
|
@ -49,16 +88,126 @@ static GHandle ghRadio1, ghRadio2;
|
||||||
#define CHECKBOX_HEIGHT 20
|
#define CHECKBOX_HEIGHT 20
|
||||||
#define RADIO_WIDTH 50
|
#define RADIO_WIDTH 50
|
||||||
#define RADIO_HEIGHT 20
|
#define RADIO_HEIGHT 20
|
||||||
|
#define COLOR_WIDTH 80
|
||||||
|
#define DISABLEALL_WIDTH 100
|
||||||
#define GROUP_TABS 0
|
#define GROUP_TABS 0
|
||||||
#define GROUP_R1R2 1
|
#define GROUP_YESNO 1
|
||||||
|
#define GROUP_COLORS 2
|
||||||
|
|
||||||
static GHandle createTab(GWidgetInit *pwi) {
|
/**
|
||||||
GHandle gh;
|
* Create all the widgets.
|
||||||
|
* With the exception of the Tabs they are all created invisible.
|
||||||
|
*/
|
||||||
|
static void createWidgets(void) {
|
||||||
|
GWidgetInit wi;
|
||||||
|
|
||||||
gh = gwinCreateRadio(NULL, pwi, GROUP_TABS);
|
wi.customDraw = 0; wi.customParam = 0; wi.customStyle = 0;
|
||||||
gwinSetCustomDraw(gh, gwinRadioDraw_Tab, 0);
|
|
||||||
gwinSetVisible(gh, TRUE);
|
// Create the Tabs
|
||||||
return gh;
|
wi.g.show = TRUE; wi.customDraw = gwinRadioDraw_Tab;
|
||||||
|
wi.g.width = ScrWidth/6; wi.g.height = TAB_HEIGHT; wi.g.y = 0;
|
||||||
|
wi.g.x = 0*wi.g.width; wi.text = "Buttons"; ghTabButtons = gwinRadioCreate(NULL, &wi, GROUP_TABS);
|
||||||
|
wi.g.x = 1*wi.g.width; wi.text = "Sliders"; ghTabSliders = gwinRadioCreate(NULL, &wi, GROUP_TABS);
|
||||||
|
wi.g.x = 2*wi.g.width; wi.text = "Checkbox"; ghTabCheckboxes = gwinRadioCreate(NULL, &wi, GROUP_TABS);
|
||||||
|
wi.g.x = 3*wi.g.width; wi.text = "Radios"; ghTabRadios = gwinRadioCreate(NULL, &wi, GROUP_TABS);
|
||||||
|
wi.g.x = 4*wi.g.width; wi.text = "Labels"; ghTabLabels = gwinRadioCreate(NULL, &wi, GROUP_TABS);
|
||||||
|
wi.g.x = 5*wi.g.width; wi.text = "Images"; ghTabImages = gwinRadioCreate(NULL, &wi, GROUP_TABS);
|
||||||
|
|
||||||
|
// Buttons
|
||||||
|
wi.g.show = FALSE; wi.customDraw = 0;
|
||||||
|
wi.g.width = BUTTON_WIDTH; wi.g.height = BUTTON_HEIGHT; wi.g.y = TAB_HEIGHT+5;
|
||||||
|
wi.g.x = 0+0*(BUTTON_WIDTH+1); wi.text = "B1"; ghButton1 = gwinButtonCreate(NULL, &wi);
|
||||||
|
wi.g.x = 0+1*(BUTTON_WIDTH+1); wi.text = "B2"; ghButton2 = gwinButtonCreate(NULL, &wi);
|
||||||
|
wi.g.x = 0+2*(BUTTON_WIDTH+1); wi.text = "B3"; ghButton3 = gwinButtonCreate(NULL, &wi);
|
||||||
|
wi.g.x = 0+3*(BUTTON_WIDTH+1); wi.text = "B4"; ghButton4 = gwinButtonCreate(NULL, &wi);
|
||||||
|
|
||||||
|
// Horizontal Sliders
|
||||||
|
wi.g.width = ScrWidth/2-2; wi.g.height = SLIDER_WIDTH; wi.g.x = ScrWidth/2+1;
|
||||||
|
wi.g.y = ScrHeight/2-2*(SLIDER_WIDTH+1); wi.text = "S1"; ghSlider1 = gwinSliderCreate(NULL, &wi);
|
||||||
|
wi.g.y = ScrHeight/2-1*(SLIDER_WIDTH+1); wi.text = "S2"; ghSlider2 = gwinSliderCreate(NULL, &wi);
|
||||||
|
|
||||||
|
// Vertical Sliders
|
||||||
|
wi.g.width = SLIDER_WIDTH; wi.g.height = ScrHeight/2-2; wi.g.y = ScrHeight/2+1;
|
||||||
|
wi.g.x = 0+0*(SLIDER_WIDTH+1); wi.text = "S3"; ghSlider3 = gwinSliderCreate(NULL, &wi);
|
||||||
|
wi.g.x = 0+1*(SLIDER_WIDTH+1); wi.text = "S4"; ghSlider4 = gwinSliderCreate(NULL, &wi);
|
||||||
|
|
||||||
|
// Checkboxes - for the 2nd checkbox we apply special drawing before making it visible
|
||||||
|
wi.g.width = CHECKBOX_WIDTH; wi.g.height = CHECKBOX_HEIGHT; wi.g.x = 0;
|
||||||
|
wi.g.y = TAB_HEIGHT+5+0*(CHECKBOX_HEIGHT+1); wi.text = "C1"; ghCheckbox1 = gwinCheckboxCreate(NULL, &wi);
|
||||||
|
wi.customDraw = gwinCheckboxDraw_CheckOnRight;
|
||||||
|
wi.g.y = TAB_HEIGHT+5+1*(CHECKBOX_HEIGHT+1); wi.text = "C2"; ghCheckbox2 = gwinCheckboxCreate(NULL, &wi);
|
||||||
|
wi.customDraw = 0; wi.g.width = DISABLEALL_WIDTH;
|
||||||
|
wi.g.y = TAB_HEIGHT+5+2*(CHECKBOX_HEIGHT+1); wi.text = "Disable All"; ghCheckDisableAll = gwinCheckboxCreate(NULL, &wi);
|
||||||
|
|
||||||
|
// Labels
|
||||||
|
wi.g.width = 0; wi.g.height = LABEL_HEIGHT; // dynamic width, fixed height
|
||||||
|
wi.g.y = TAB_HEIGHT+5+2*(CHECKBOX_HEIGHT+1); wi.text = "Label"; ghLabel1 = gwinLabelCreate(NULL, &wi);
|
||||||
|
|
||||||
|
// Radio Buttons
|
||||||
|
wi.g.width = RADIO_WIDTH; wi.g.height = RADIO_HEIGHT; wi.g.y = TAB_HEIGHT+5;
|
||||||
|
wi.g.x = 0*wi.g.width; wi.text = "Yes"; ghRadio1 = gwinRadioCreate(NULL, &wi, GROUP_YESNO);
|
||||||
|
wi.g.x = 1*wi.g.width; wi.text = "No"; ghRadio2 = gwinRadioCreate(NULL, &wi, GROUP_YESNO);
|
||||||
|
wi.g.width = COLOR_WIDTH; wi.g.y += RADIO_HEIGHT+5;
|
||||||
|
wi.g.x = 0*wi.g.width; wi.text = "Black"; ghRadioBlack = gwinRadioCreate(NULL, &wi, GROUP_COLORS);
|
||||||
|
wi.g.x = 1*wi.g.width; wi.text = "White"; ghRadioWhite = gwinRadioCreate(NULL, &wi, GROUP_COLORS);
|
||||||
|
wi.g.x = 2*wi.g.width; wi.text = "Yellow"; ghRadioYellow = gwinRadioCreate(NULL, &wi, GROUP_COLORS);
|
||||||
|
gwinRadioPress(ghRadioWhite);
|
||||||
|
|
||||||
|
// Console - we apply some special colors before making it visible
|
||||||
|
wi.g.width = ScrWidth/2-1; wi.g.height = ScrHeight/2-1;
|
||||||
|
wi.g.x = ScrWidth/2+1; wi.g.y = ScrHeight/2+1;
|
||||||
|
ghConsole = gwinConsoleCreate(NULL, &wi.g);
|
||||||
|
gwinSetColor(ghConsole, Yellow);
|
||||||
|
gwinSetBgColor(ghConsole, Black);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the visibility of widgets based on which tab is selected.
|
||||||
|
*/
|
||||||
|
static void setTab(GHandle tab) {
|
||||||
|
/* Make sure everything is invisible first */
|
||||||
|
gwinSetVisible(ghButton1, FALSE); gwinSetVisible(ghButton2, FALSE);
|
||||||
|
gwinSetVisible(ghButton3, FALSE); gwinSetVisible(ghButton4, FALSE);
|
||||||
|
gwinSetVisible(ghSlider1, FALSE); gwinSetVisible(ghSlider2, FALSE);
|
||||||
|
gwinSetVisible(ghSlider3, FALSE); gwinSetVisible(ghSlider4, FALSE);
|
||||||
|
gwinSetVisible(ghCheckbox1, FALSE); gwinSetVisible(ghCheckbox2, FALSE); gwinSetVisible(ghCheckDisableAll, FALSE);
|
||||||
|
gwinSetVisible(ghLabel1, FALSE);
|
||||||
|
gwinSetVisible(ghRadio1, FALSE); gwinSetVisible(ghRadio2, FALSE);
|
||||||
|
gwinSetVisible(ghRadioWhite, FALSE);gwinSetVisible(ghRadioBlack, FALSE);gwinSetVisible(ghRadioYellow, FALSE);
|
||||||
|
//gwinSetVisible(ghImage1, FALSE);
|
||||||
|
|
||||||
|
/* Turn on widgets depending on the tab selected */
|
||||||
|
if (tab == ghTabButtons) {
|
||||||
|
gwinSetVisible(ghButton1, TRUE); gwinSetVisible(ghButton2, TRUE);
|
||||||
|
gwinSetVisible(ghButton3, TRUE); gwinSetVisible(ghButton4, TRUE);
|
||||||
|
} else if (tab == ghTabSliders) {
|
||||||
|
gwinSetVisible(ghSlider1, TRUE); gwinSetVisible(ghSlider2, TRUE);
|
||||||
|
gwinSetVisible(ghSlider3, TRUE); gwinSetVisible(ghSlider4, TRUE);
|
||||||
|
} else if (tab == ghTabCheckboxes) {
|
||||||
|
gwinSetVisible(ghCheckbox1, TRUE); gwinSetVisible(ghCheckbox2, TRUE); gwinSetVisible(ghCheckDisableAll, TRUE);
|
||||||
|
} else if (tab == ghTabLabels) {
|
||||||
|
gwinSetVisible(ghLabel1, TRUE);
|
||||||
|
} else if (tab == ghTabRadios) {
|
||||||
|
gwinSetVisible(ghRadio1, TRUE); gwinSetVisible(ghRadio2, TRUE);
|
||||||
|
gwinSetVisible(ghRadioWhite, TRUE); gwinSetVisible(ghRadioBlack, TRUE); gwinSetVisible(ghRadioYellow, TRUE);
|
||||||
|
} else if (tab == ghTabImages) {
|
||||||
|
//gwinSetVisible(ghImage1, TRUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the enabled state of every widget (except the tabs etc)
|
||||||
|
*/
|
||||||
|
static void setEnabled(bool_t ena) {
|
||||||
|
gwinSetEnabled(ghButton1, ena); gwinSetEnabled(ghButton2, ena);
|
||||||
|
gwinSetEnabled(ghButton3, ena); gwinSetEnabled(ghButton4, ena);
|
||||||
|
gwinSetEnabled(ghSlider1, ena); gwinSetEnabled(ghSlider2, ena);
|
||||||
|
gwinSetEnabled(ghSlider3, ena); gwinSetEnabled(ghSlider4, ena);
|
||||||
|
gwinSetEnabled(ghCheckbox1, ena); gwinSetEnabled(ghCheckbox2, ena); //gwinSetEnabled(ghCheckDisableAll, TRUE);
|
||||||
|
gwinSetEnabled(ghLabel1, ena);
|
||||||
|
gwinSetEnabled(ghRadio1, ena); gwinSetEnabled(ghRadio2, ena);
|
||||||
|
gwinSetEnabled(ghRadioWhite, ena); gwinSetEnabled(ghRadioBlack, ena); gwinSetEnabled(ghRadioYellow, ena);
|
||||||
|
//gwinSetEnabled(ghImage1, ena);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
@ -66,16 +215,11 @@ int main(void) {
|
||||||
|
|
||||||
// Initialize the display
|
// Initialize the display
|
||||||
gfxInit();
|
gfxInit();
|
||||||
gdispClear(White);
|
|
||||||
|
|
||||||
// Set the widget defaults
|
// Set the widget defaults
|
||||||
gwinSetDefaultFont(gdispOpenFont("UI2"));
|
gwinSetDefaultFont(gdispOpenFont("UI2"));
|
||||||
gwinSetDefaultColor(Black);
|
gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
|
||||||
gwinSetDefaultBgColor(White);
|
gdispClear(White);
|
||||||
|
|
||||||
// We want to listen for widget events
|
|
||||||
geventListenerInit(&gl);
|
|
||||||
gwinAttachListener(&gl);
|
|
||||||
|
|
||||||
// Connect the mouse
|
// Connect the mouse
|
||||||
#if GINPUT_NEED_MOUSE
|
#if GINPUT_NEED_MOUSE
|
||||||
|
@ -83,59 +227,9 @@ int main(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create the gwin windows/widgets
|
// Create the gwin windows/widgets
|
||||||
{
|
createWidgets();
|
||||||
GWidgetInit wi;
|
|
||||||
|
|
||||||
// Create the Tabs
|
// Assign toggles and dials to specific buttons & sliders etc.
|
||||||
wi.g.show = FALSE; wi.g.width = ScrWidth/6; wi.g.height = TAB_HEIGHT; wi.g.y = 0;
|
|
||||||
wi.g.x = 0*wi.g.width; wi.text = "Buttons"; ghTabButtons = createTab(&wi);
|
|
||||||
wi.g.x = 1*wi.g.width; wi.text = "Sliders"; ghTabSliders = createTab(&wi);
|
|
||||||
wi.g.x = 2*wi.g.width; wi.text = "Checkbox"; ghTabCheckboxes = createTab(&wi);
|
|
||||||
wi.g.x = 3*wi.g.width; wi.text = "Labels"; ghTabLabels = createTab(&wi);
|
|
||||||
wi.g.x = 4*wi.g.width; wi.text = "Radios"; ghTabRadios = createTab(&wi);
|
|
||||||
wi.g.x = 5*wi.g.width; wi.text = "Images"; ghTabImages = createTab(&wi);
|
|
||||||
|
|
||||||
// Buttons
|
|
||||||
wi.g.width = BUTTON_WIDTH; wi.g.height = BUTTON_HEIGHT; wi.g.y = TAB_HEIGHT+5;
|
|
||||||
wi.g.x = 0+0*(BUTTON_WIDTH+1); wi.text = "B1"; ghButton1 = gwinCreateButton(NULL, &wi);
|
|
||||||
wi.g.x = 0+1*(BUTTON_WIDTH+1); wi.text = "B2"; ghButton2 = gwinCreateButton(NULL, &wi);
|
|
||||||
wi.g.x = 0+2*(BUTTON_WIDTH+1); wi.text = "B3"; ghButton3 = gwinCreateButton(NULL, &wi);
|
|
||||||
wi.g.x = 0+3*(BUTTON_WIDTH+1); wi.text = "B4"; ghButton4 = gwinCreateButton(NULL, &wi);
|
|
||||||
|
|
||||||
// Horizontal Sliders
|
|
||||||
wi.g.width = ScrWidth/2-2; wi.g.height = SLIDER_WIDTH; wi.g.x = ScrWidth/2+1;
|
|
||||||
wi.g.y = ScrHeight/2-2*(SLIDER_WIDTH+1); wi.text = "S1"; ghSlider1 = gwinCreateSlider(NULL, &wi);
|
|
||||||
wi.g.y = ScrHeight/2-1*(SLIDER_WIDTH+1); wi.text = "S2"; ghSlider2 = gwinCreateSlider(NULL, &wi);
|
|
||||||
|
|
||||||
// Vertical Sliders
|
|
||||||
wi.g.width = SLIDER_WIDTH; wi.g.height = ScrHeight/2-2; wi.g.y = ScrHeight/2+1;
|
|
||||||
wi.g.x = 0+0*(SLIDER_WIDTH+1); wi.text = "S3"; ghSlider3 = gwinCreateSlider(NULL, &wi);
|
|
||||||
wi.g.x = 0+1*(SLIDER_WIDTH+1); wi.text = "S4"; ghSlider4 = gwinCreateSlider(NULL, &wi);
|
|
||||||
|
|
||||||
// Checkboxes - for the 2nd checkbox we apply special drawing before making it visible
|
|
||||||
wi.g.width = CHECKBOX_WIDTH; wi.g.height = CHECKBOX_HEIGHT; wi.g.x = 0;
|
|
||||||
wi.g.y = TAB_HEIGHT+5+0*(CHECKBOX_HEIGHT+1); wi.text = "C1"; ghCheckbox1 = gwinCreateCheckbox(NULL, &wi);
|
|
||||||
wi.g.y = TAB_HEIGHT+5+1*(CHECKBOX_HEIGHT+1); wi.text = "C2"; ghCheckbox2 = gwinCreateCheckbox(NULL, &wi);
|
|
||||||
gwinSetCustomDraw(ghCheckbox2, gwinCheckboxDraw_CheckOnRight, 0);
|
|
||||||
|
|
||||||
// Labels
|
|
||||||
wi.g.width = 0; // dynamic width
|
|
||||||
wi.g.y = TAB_HEIGHT+5+2*(CHECKBOX_HEIGHT+1); wi.text = "L1"; ghLabel1 = gwinLabelCreate(NULL, &wi);
|
|
||||||
|
|
||||||
// Radio Buttons
|
|
||||||
wi.g.width = RADIO_WIDTH; wi.g.height = RADIO_HEIGHT; wi.g.y = TAB_HEIGHT+5;
|
|
||||||
wi.g.x = 0*wi.g.width; wi.text = "Yes"; ghRadio1 = gwinCreateRadio(NULL, &wi, GROUP_R1R2);
|
|
||||||
wi.g.x = 1*wi.g.width; wi.text = "No"; ghRadio2 = gwinCreateRadio(NULL, &wi, GROUP_R1R2);
|
|
||||||
|
|
||||||
// Console - we apply some special colors before making it visible
|
|
||||||
wi.g.width = ScrWidth/2-1; wi.g.height = ScrHeight/2-1;
|
|
||||||
wi.g.x = ScrWidth/2+1; wi.g.y = ScrHeight/2+1;
|
|
||||||
ghConsole = gwinCreateConsole(NULL, &wi.g);
|
|
||||||
gwinSetColor(ghConsole, Yellow);
|
|
||||||
gwinSetBgColor(ghConsole, Black);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assign toggles and dials to the buttons & sliders etc.
|
|
||||||
#if GINPUT_NEED_TOGGLE
|
#if GINPUT_NEED_TOGGLE
|
||||||
gwinAttachToggle(ghButton1, 0, 0);
|
gwinAttachToggle(ghButton1, 0, 0);
|
||||||
gwinAttachToggle(ghButton2, 0, 1);
|
gwinAttachToggle(ghButton2, 0, 1);
|
||||||
|
@ -149,8 +243,12 @@ int main(void) {
|
||||||
gwinSetVisible(ghConsole, TRUE);
|
gwinSetVisible(ghConsole, TRUE);
|
||||||
gwinClear(ghConsole);
|
gwinClear(ghConsole);
|
||||||
|
|
||||||
// Press the Buttons Tab
|
// We want to listen for widget events
|
||||||
gwinPressRadio(ghTabButtons);
|
geventListenerInit(&gl);
|
||||||
|
gwinAttachListener(&gl);
|
||||||
|
|
||||||
|
// Press the Tab we want visible
|
||||||
|
gwinRadioPress(ghTabButtons);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
// Get an Event
|
// Get an Event
|
||||||
|
@ -160,54 +258,68 @@ int main(void) {
|
||||||
case GEVENT_GWIN_BUTTON:
|
case GEVENT_GWIN_BUTTON:
|
||||||
gwinPrintf(ghConsole, "Button %s\n", gwinGetText(((GEventGWinButton *)pe)->button));
|
gwinPrintf(ghConsole, "Button %s\n", gwinGetText(((GEventGWinButton *)pe)->button));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GEVENT_GWIN_SLIDER:
|
case GEVENT_GWIN_SLIDER:
|
||||||
gwinPrintf(ghConsole, "Slider %s=%d\n", gwinGetText(((GEventGWinSlider *)pe)->slider), ((GEventGWinSlider *)pe)->position);
|
gwinPrintf(ghConsole, "Slider %s=%d\n", gwinGetText(((GEventGWinSlider *)pe)->slider), ((GEventGWinSlider *)pe)->position);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GEVENT_GWIN_CHECKBOX:
|
case GEVENT_GWIN_CHECKBOX:
|
||||||
gwinPrintf(ghConsole, "Checkbox %s=%s\n", gwinGetText(((GEventGWinCheckbox *)pe)->checkbox), ((GEventGWinCheckbox *)pe)->isChecked ? "Checked" : "UnChecked");
|
gwinPrintf(ghConsole, "Checkbox %s=%s\n", gwinGetText(((GEventGWinCheckbox *)pe)->checkbox), ((GEventGWinCheckbox *)pe)->isChecked ? "Checked" : "UnChecked");
|
||||||
|
|
||||||
|
// If it is the Disable All checkbox then do that.
|
||||||
|
if (((GEventGWinCheckbox *)pe)->checkbox == ghCheckDisableAll) {
|
||||||
|
gwinPrintf(ghConsole, "%s All\n", ((GEventGWinCheckbox *)pe)->isChecked ? "Disable" : "Enable");
|
||||||
|
setEnabled(!((GEventGWinCheckbox *)pe)->isChecked);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GEVENT_GWIN_RADIO:
|
case GEVENT_GWIN_RADIO:
|
||||||
gwinPrintf(ghConsole, "Radio Group %u=%s\n", ((GEventGWinRadio *)pe)->group, gwinGetText(((GEventGWinRadio *)pe)->radio));
|
gwinPrintf(ghConsole, "Radio Group %u=%s\n", ((GEventGWinRadio *)pe)->group, gwinGetText(((GEventGWinRadio *)pe)->radio));
|
||||||
|
|
||||||
// Is this the tab radio's
|
switch(((GEventGWinRadio *)pe)->group) {
|
||||||
if (((GEventGWinRadio *)pe)->group == GROUP_TABS) {
|
case GROUP_TABS:
|
||||||
|
|
||||||
// Do some special animation for Label1
|
|
||||||
if (((GEventGWinRadio *)pe)->radio == ghTabLabels) {
|
|
||||||
gwinSetBgColor(ghLabel1, gwinGetDefaultBgColor());
|
|
||||||
gwinSetColor(ghLabel1, gwinGetDefaultColor());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set control visibility depending on the tab selected
|
// Set control visibility depending on the tab selected
|
||||||
gwinSetVisible(ghButton1, ((GEventGWinRadio *)pe)->radio == ghTabButtons);
|
setTab(((GEventGWinRadio *)pe)->radio);
|
||||||
gwinSetVisible(ghButton2, ((GEventGWinRadio *)pe)->radio == ghTabButtons);
|
|
||||||
gwinSetVisible(ghButton3, ((GEventGWinRadio *)pe)->radio == ghTabButtons);
|
|
||||||
gwinSetVisible(ghButton4, ((GEventGWinRadio *)pe)->radio == ghTabButtons);
|
|
||||||
gwinSetVisible(ghSlider1, ((GEventGWinRadio *)pe)->radio == ghTabSliders);
|
|
||||||
gwinSetVisible(ghSlider2, ((GEventGWinRadio *)pe)->radio == ghTabSliders);
|
|
||||||
gwinSetVisible(ghSlider3, ((GEventGWinRadio *)pe)->radio == ghTabSliders);
|
|
||||||
gwinSetVisible(ghSlider4, ((GEventGWinRadio *)pe)->radio == ghTabSliders);
|
|
||||||
gwinSetVisible(ghCheckbox1, ((GEventGWinRadio *)pe)->radio == ghTabCheckboxes);
|
|
||||||
gwinSetVisible(ghCheckbox2, ((GEventGWinRadio *)pe)->radio == ghTabCheckboxes);
|
|
||||||
gwinSetVisible(ghLabel1, ((GEventGWinRadio *)pe)->radio == ghTabLabels);
|
|
||||||
gwinSetVisible(ghRadio1, ((GEventGWinRadio *)pe)->radio == ghTabRadios);
|
|
||||||
gwinSetVisible(ghRadio2, ((GEventGWinRadio *)pe)->radio == ghTabRadios);
|
|
||||||
//gwinSetVisible(ghImage1, ((GEventGWinRadio *)pe)->radio == ghTabImages);
|
|
||||||
|
|
||||||
// Do some special animation for Label1
|
// Do some special animation for Label1 to demonstrate auto width sizing
|
||||||
if (((GEventGWinRadio *)pe)->radio == ghTabLabels) {
|
if (((GEventGWinRadio *)pe)->radio == ghTabLabels) {
|
||||||
|
gwinPrintf(ghConsole, "Change Label Text\n");
|
||||||
gfxSleepMilliseconds(1000);
|
gfxSleepMilliseconds(1000);
|
||||||
gwinSetBgColor(ghLabel1, Blue);
|
|
||||||
gwinSetColor(ghLabel1, Yellow);
|
|
||||||
gwinSetText(ghLabel1, "Very Big Label", FALSE);
|
gwinSetText(ghLabel1, "Very Big Label", FALSE);
|
||||||
|
|
||||||
gfxSleepMilliseconds(1000);
|
gfxSleepMilliseconds(1000);
|
||||||
gwinSetBgColor(ghLabel1, Yellow);
|
gwinSetText(ghLabel1, "Label", FALSE);
|
||||||
gwinSetColor(ghLabel1, Red);
|
|
||||||
gwinSetText(ghLabel1, "L1", FALSE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GROUP_COLORS:
|
||||||
|
{
|
||||||
|
const GWidgetStyle *pstyle;
|
||||||
|
|
||||||
|
gwinPrintf(ghConsole, "Change Color Scheme\n");
|
||||||
|
|
||||||
|
if (((GEventGWinRadio *)pe)->radio == ghRadioYellow)
|
||||||
|
pstyle = &YellowWidgetStyle;
|
||||||
|
else if (((GEventGWinRadio *)pe)->radio == ghRadioBlack)
|
||||||
|
pstyle = &BlackWidgetStyle;
|
||||||
|
else
|
||||||
|
pstyle = &WhiteWidgetStyle;
|
||||||
|
|
||||||
|
// Clear the screen to the new color - we avoid the console area as it can't redraw itself
|
||||||
|
#if GDISP_NEED_CLIP
|
||||||
|
gdispUnsetClip();
|
||||||
|
#endif
|
||||||
|
gdispFillArea(0, 0, ScrWidth, ScrHeight/2, pstyle->background);
|
||||||
|
gdispFillArea(0, ScrHeight/2, ScrWidth/2, ScrHeight/2, pstyle->background);
|
||||||
|
|
||||||
|
// Update the style on all controls
|
||||||
|
gwinSetDefaultStyle(pstyle, TRUE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
gwinPrintf(ghConsole, "Unknown %d\n", pe->type);
|
gwinPrintf(ghConsole, "Unknown %d\n", pe->type);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
This demo supports input from both a mouse/touch and/or a dial input.
|
This demo supports input from both a mouse/touch, toggles and/or a dial input.
|
||||||
If your platform does not support one or the other, turn it off in
|
If your platform does not support one or the other, turn it off in
|
||||||
gfxconf.h
|
gfxconf.h
|
||||||
|
|
||||||
Note that you will need to include the drivers into your project
|
Note that you will need to include the drivers into your project
|
||||||
makefile for whichever inputs you decide to use.
|
makefile for whichever inputs you decide to use.
|
||||||
|
|
||||||
|
For some fun have a play with the "colors" radio group and the "Disable All" checkbox.
|
||||||
|
|
Loading…
Add table
Reference in a new issue