This example shows how to use the Color Picker to and two slider bars to select color and size of a matrix of rectangles on screen. It also adds a button to end the execution of the program.
#include <stdio.h>
#include <stdlib.h>
#define SCRW 800
#define SCRH 500
#define SIZE 48
#define GAP 2
#define FREE 50
int main() {
int scr, cp, slh, slv, btn;
int col, width, height, nh, nv;
int i, j;
char buffer[100];
if ((scr =
mgsCreateScreen(SCRW, SCRH,
"Selecting colors", MGS_CBLACK, NULL)) < 0)
exit(EXIT_FAILURE);
if ((cp =
mrmCPInit(0x808080, MGS_CWHITE)) < 0)
exit(EXIT_FAILURE);
slh =
mrmSliderInit(scr, MWG_SLHORIZONTAL, 25, SCRW - 50, 0.0, SIZE, MGS_CGREY, MGS_CRED, 0x000080, 0x202020);
slv =
mrmSliderInit(scr, MWG_SLVERTICAL, 25, SCRH - 50, 0.0, SIZE, MGS_CGREY, MGS_CRED, 0x000080, 0x202020);
btn =
mrmButtonInit(scr, 80, 40, NULL,
"Exit", MGS_CGREY, 0x202020, MGS_CBLACK);
nh = 1 + (SCRW - SIZE - GAP - 50) / (SIZE + GAP);
nv = 1 + (SCRH - SIZE - GAP - 50 - FREE) / (SIZE + GAP);
sprintf(buffer, "Width: %d - Height: %d", width, height);
for(i = 0; i < nh; i++)
for(j = 0; j < nv; j++)
mgsRectangle(scr, i * (SIZE + GAP) + 40, j * (SIZE + GAP) + 40, i * (SIZE + GAP) + 40 + width, j * (SIZE + GAP) + 40 + height, col);
mgsPutsAligned(scr, MGS_THCENTER | MGS_TVCENTER, 0, SCRH - FREE - 30, SCRW, SCRH, buffer);
}
exit(EXIT_SUCCESS);
}