This example shows how to use selection lists. It presents a strange, moving list of options to select the color of the background and a normal, rectangular section list to control the movement of the first. It also adds a button to end the execution of the program.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define SCRW 800
#define SCRH 600
#define RAD 250.0
#define SPEED 0.005
void setPos(double angle);
int setCol(int op);
int contrast(int c);
char *modeText[3] = {"Rotate counterclockwise", "Stop rotation", "Rotate clockwise"};
char *colorText[6] = {"Red", "Magenta", "Blue", "Yellow", "Green", "Cyan"};
int colors[6] = {MGS_CRED, MGS_CMAGENTA, MGS_CBLUE, MGS_CYELLOW, MGS_CGREEN, MGS_CCYAN};
int hexa[12];
int main() {
int scr, sc, sc2, btn;
int op, op2 = 0, oldop2 = 1, col, col2;
double a = 0.0, v = SPEED;
sc =
mrmSelectionInit(scr, 200, 75, 3, modeText, 1, MWG_SCUNIQUE | MWG_SCROUND | 10);
sc2 =
mrmSelectionInit(scr, 0, 0, 6, colorText, 0, MWG_SCMULTI | MWG_SCSYMBOL |
'V');
btn =
mrmButtonInit(scr, 80, 40, NULL,
"Exit", MGS_CGREY, 0x202020, MGS_CBLACK);
setPos(a);
a = a + v;
v = (1 - op) * SPEED;
if (op2 != oldop2) {
oldop2 = op2;
col = setCol(op2);
col2 = contrast(col);
}
}
exit(EXIT_SUCCESS);
}
void setPos(double angle)
{
int i;
for (i = 0; i < 6; i++) {
hexa[2 * i] = SCRW / 2 - 50 + RAD * cos(angle + i * 2.0 * M_PI / 6.0);
hexa[2 * i + 1] = SCRH / 2 - RAD * sin(angle + i * 2.0 * M_PI / 6.0);
}
}
int setCol(int op)
{
int i, msc = 1, resR = 0, resG = 0, resB = 0;
for (i = 0; i < 6; i++) {
if (op & msc) {
resR += colors[i] & 0x7F;
resG += (colors[i] >> 8) & 0x7F;
resB += (colors[i] >> 16) & 0x7F;
}
msc = msc << 1;
}
resR = resR & 0xFF;
resG = resG & 0xFF;
resB = resB & 0xFF;
}
int contrast(int c)
{
int r, g, b;
r = ((c & 0xFF) + 0x80) & 0xFF;
g = (((c >> 8)& 0xFF) + 0x80) & 0xFF;
b = (((c >> 16)& 0xFF) + 0x80) & 0xFF;
}