2014-05-10 11:26:13 +00:00
|
|
|
#include "gfx.h"
|
2015-11-27 00:16:40 +00:00
|
|
|
#include <stdlib.h>
|
2014-05-10 11:26:13 +00:00
|
|
|
|
|
|
|
static GListener gl;
|
|
|
|
static GHandle ghFrame1;
|
2014-05-30 01:56:51 +00:00
|
|
|
static GHandle ghSliderR, ghSliderG, ghSliderB;
|
|
|
|
static GHandle ghButton1, ghButton2, ghButton3;
|
|
|
|
static GHandle ghWindow1;
|
2014-05-10 11:26:13 +00:00
|
|
|
|
2014-05-30 01:56:51 +00:00
|
|
|
static void _updateColor(void) {
|
2018-11-03 00:51:23 +00:00
|
|
|
gU32 color;
|
2014-05-30 01:56:51 +00:00
|
|
|
|
2014-05-30 02:46:40 +00:00
|
|
|
color = (unsigned)gwinSliderGetPosition(ghSliderR) << 16;
|
|
|
|
color |= (unsigned)gwinSliderGetPosition(ghSliderG) << 8;
|
|
|
|
color |= (unsigned)gwinSliderGetPosition(ghSliderB) << 0;
|
2014-05-30 01:56:51 +00:00
|
|
|
|
|
|
|
gwinSetBgColor(ghWindow1, HTML2COLOR(color));
|
|
|
|
gwinClear(ghWindow1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _createWidgets(void) {
|
2014-05-10 11:26:13 +00:00
|
|
|
GWidgetInit wi;
|
|
|
|
|
|
|
|
// Apply some default values for GWIN
|
|
|
|
gwinWidgetClearInit(&wi);
|
2018-06-23 03:02:07 +00:00
|
|
|
wi.g.show = gTrue;
|
2014-05-10 11:26:13 +00:00
|
|
|
|
2014-08-16 12:49:15 +00:00
|
|
|
// Create a surprise label behind the frame window
|
|
|
|
wi.g.width = 100;
|
|
|
|
wi.g.height = 20;
|
|
|
|
wi.g.y = 100;
|
|
|
|
wi.g.x = 150;
|
|
|
|
wi.text = "Surprise!";
|
2015-11-06 23:39:08 +00:00
|
|
|
gwinLabelCreate(0, &wi);
|
2014-08-16 12:49:15 +00:00
|
|
|
|
2014-09-26 06:30:53 +00:00
|
|
|
// Apply the frame parameters
|
2014-05-30 01:56:51 +00:00
|
|
|
wi.g.width = 300;
|
|
|
|
wi.g.height = 200;
|
2014-05-10 11:26:13 +00:00
|
|
|
wi.g.y = 10;
|
|
|
|
wi.g.x = 10;
|
2014-05-30 01:56:51 +00:00
|
|
|
wi.text = "Colorpicker";
|
2014-05-10 11:26:13 +00:00
|
|
|
ghFrame1 = gwinFrameCreate(0, &wi, GWIN_FRAME_BORDER | GWIN_FRAME_CLOSE_BTN | GWIN_FRAME_MINMAX_BTN);
|
2014-05-30 01:56:51 +00:00
|
|
|
|
|
|
|
// Apply the button parameters
|
|
|
|
wi.g.width = 60;
|
|
|
|
wi.g.height = 20;
|
|
|
|
wi.g.x = 10;
|
|
|
|
wi.g.y = 10;
|
|
|
|
wi.text = "Random";
|
|
|
|
wi.g.parent = ghFrame1;
|
|
|
|
ghButton1 = gwinButtonCreate(0, &wi);
|
|
|
|
|
|
|
|
// Apply the slider parameters
|
|
|
|
wi.g.width = 200;
|
|
|
|
wi.g.height = 20;
|
|
|
|
wi.g.x = 80;
|
|
|
|
wi.g.y += 0;
|
|
|
|
wi.text = "Red";
|
|
|
|
wi.g.parent = ghFrame1;
|
|
|
|
ghSliderR = gwinSliderCreate(0, &wi);
|
|
|
|
gwinSliderSetRange(ghSliderR, 0, 255);
|
|
|
|
gwinSliderSetPosition(ghSliderR, 180);
|
|
|
|
|
|
|
|
// Apply the button parameters
|
|
|
|
wi.g.width = 60;
|
|
|
|
wi.g.height = 20;
|
|
|
|
wi.g.x = 10;
|
|
|
|
wi.g.y += 25;
|
|
|
|
wi.text = "Random";
|
|
|
|
wi.g.parent = ghFrame1;
|
|
|
|
ghButton2 = gwinButtonCreate(0, &wi);
|
|
|
|
|
|
|
|
// Apply the slider parameters
|
|
|
|
wi.g.width = 200;
|
|
|
|
wi.g.height = 20;
|
|
|
|
wi.g.x = 80;
|
|
|
|
wi.g.y += 0;
|
|
|
|
wi.text = "Green";
|
|
|
|
wi.g.parent = ghFrame1;
|
|
|
|
ghSliderG = gwinSliderCreate(0, &wi);
|
|
|
|
gwinSliderSetRange(ghSliderG, 0, 255);
|
|
|
|
gwinSliderSetPosition(ghSliderG, 60);
|
|
|
|
|
|
|
|
// Apply the button parameters
|
|
|
|
wi.g.width = 60;
|
|
|
|
wi.g.height = 20;
|
|
|
|
wi.g.x = 10;
|
|
|
|
wi.g.y += 25;
|
|
|
|
wi.text = "Random";
|
|
|
|
wi.g.parent = ghFrame1;
|
|
|
|
ghButton3 = gwinButtonCreate(0, &wi);
|
|
|
|
|
|
|
|
// Apply the slider parameters
|
|
|
|
wi.g.width = 200;
|
|
|
|
wi.g.height = 20;
|
|
|
|
wi.g.x = 80;
|
|
|
|
wi.g.y += 0;
|
|
|
|
wi.text = "Blue";
|
|
|
|
wi.g.parent = ghFrame1;
|
|
|
|
ghSliderB = gwinSliderCreate(0, &wi);
|
|
|
|
gwinSliderSetRange(ghSliderB, 0, 255);
|
|
|
|
gwinSliderSetPosition(ghSliderB, 235);
|
|
|
|
|
|
|
|
// Color Preview
|
|
|
|
wi.g.width = 270;
|
|
|
|
wi.g.height = 65;
|
|
|
|
wi.g.x = 10;
|
|
|
|
wi.g.y = 90;
|
|
|
|
ghWindow1 = gwinWindowCreate(0, &wi.g);
|
2014-09-26 06:30:53 +00:00
|
|
|
|
2014-05-30 01:56:51 +00:00
|
|
|
_updateColor();
|
2014-05-10 11:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
2014-05-30 01:56:51 +00:00
|
|
|
GEvent* pe;
|
|
|
|
|
2014-05-10 11:26:13 +00:00
|
|
|
// Initialize the display
|
|
|
|
gfxInit();
|
|
|
|
|
|
|
|
// Set the widget defaults
|
|
|
|
gwinSetDefaultFont(gdispOpenFont("*"));
|
2018-06-23 03:02:07 +00:00
|
|
|
gwinSetDefaultStyle(&WhiteWidgetStyle, gFalse);
|
2018-03-10 10:36:12 +00:00
|
|
|
gdispClear(GFX_WHITE);
|
2014-05-10 11:26:13 +00:00
|
|
|
|
|
|
|
// create the widget
|
2014-05-30 01:56:51 +00:00
|
|
|
_createWidgets();
|
2014-05-10 11:26:13 +00:00
|
|
|
|
|
|
|
// We want to listen for widget events
|
|
|
|
geventListenerInit(&gl);
|
|
|
|
gwinAttachListener(&gl);
|
|
|
|
|
|
|
|
while(1) {
|
2014-05-30 01:56:51 +00:00
|
|
|
// Get an Event
|
2018-07-08 05:15:15 +00:00
|
|
|
pe = geventEventWait(&gl, gDelayForever);
|
2014-05-30 01:56:51 +00:00
|
|
|
|
|
|
|
switch(pe->type) {
|
|
|
|
case GEVENT_GWIN_SLIDER:
|
2014-08-20 02:18:27 +00:00
|
|
|
if (((GEventGWinSlider *)pe)->gwin == ghSliderR || \
|
|
|
|
ghSliderG || \
|
|
|
|
ghSliderB ) {
|
2014-05-30 01:56:51 +00:00
|
|
|
_updateColor();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEVENT_GWIN_BUTTON:
|
2014-08-20 02:18:27 +00:00
|
|
|
if (((GEventGWinButton *)pe)->gwin == ghButton1) {
|
2014-05-30 01:56:51 +00:00
|
|
|
gwinSliderSetPosition(ghSliderR, rand() % 256);
|
2014-08-20 02:18:27 +00:00
|
|
|
} else if (((GEventGWinButton *)pe)->gwin == ghButton2) {
|
2014-05-30 01:56:51 +00:00
|
|
|
gwinSliderSetPosition(ghSliderG, rand() % 256);
|
2014-08-20 02:18:27 +00:00
|
|
|
} else if (((GEventGWinButton *)pe)->gwin == ghButton3) {
|
2014-05-30 01:56:51 +00:00
|
|
|
gwinSliderSetPosition(ghSliderB, rand() % 256);
|
|
|
|
}
|
|
|
|
|
|
|
|
_updateColor();
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-05-10 11:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|