I am trying to make a GUI to choose whether it is auton or skills.
this is what i have so far. (came from the guide from a few years back
//vex::smartdrive drive = smartdrive(leftSide, rightSide, GPS1, 180, 0, 0, inches, true);
int autonomousSelection = -1;//storage for auton selcetion
vex::competition Competition;
typedef struct _button{
int xpos;
int ypos;
int width;
int height;
bool state;
vex::color offColor;
vex::color onColor;
const char *label;
} button;
//button definitions for each software button
button buttons[] = {
{ 30, 30, 60, 60, false, 0xE00000, 0x0000E0, "Is this a skills run?" },
{ 150, 150, 60, 60, false, 0x404040, 0xC0C0C0, "5-" },
};
void displayButtonControls( int index, bool pressed );
int findButton( int16_t xpos, int16_t ypos ) {
int nButtons = sizeof(buttons) / sizeof(button);
for( int index=0;index < nButtons;index++) {
button *pButton = &buttons[ index ];
if( xpos < pButton->xpos || xpos > (pButton->xpos + pButton->width) )
continue;
if( ypos < pButton->ypos || ypos > (pButton->ypos + pButton->height) )
continue;
return(index);
}
return (-1);
}
void initButtons() {
int nButtons = sizeof(buttons) / sizeof(button);
for( int index=0;index < nButtons;index++) {
buttons[index].state = false;
}
}
void userTouchCallbackPressed() {
int index;
int xpos = Brain.Screen.xPosition();
int ypos = Brain.Screen.yPosition();
if( (index = findButton( xpos, ypos )) >= 0 ) {
displayButtonControls( index, true );
}
}
void userTouchCallbackReleased() {
int index;
int xpos = Brain.Screen.xPosition();
int ypos = Brain.Screen.yPosition();
if( (index = findButton( xpos, ypos )) >= 0 ) {
// clear all buttons to false, ie. unselected
// initButtons();
// now set this one as true
if( buttons[index].state == true) {
buttons[index].state = false; }
else {
buttons[index].state = true;}
// save as auton selection
autonomousSelection = index;
displayButtonControls( index, false );
}
}
void displayButtonControls( int index, bool pressed ) {
vex::color c;
Brain.Screen.setPenColor( vex::color(0xe0e0e0) );
for(int i=0;i<sizeof(buttons)/sizeof(button);i++) {
if( buttons[i].state )
c = buttons[i].onColor;
else
c = buttons[i].offColor;
Brain.Screen.setFillColor( c );
// button fill
if( i == index && pressed == true ) {
Brain.Screen.drawRectangle( buttons[i].xpos, buttons[i].ypos, buttons[i].width, buttons[i].height, c );
}
else
Brain.Screen.drawRectangle( buttons[i].xpos, buttons[i].ypos, buttons[i].width, buttons[i].height );
// outline
Brain.Screen.drawRectangle( buttons[i].xpos, buttons[i].ypos, buttons[i].width, buttons[i].height, vex::color::transparent );
// draw label
if( buttons[i].label != NULL )
Brain.Screen.printAt( buttons[i].xpos + 8, buttons[i].ypos + buttons[i].height - 8, buttons[i].label );
}
}
void autonomous() {
bool skills = buttons[1].state;
if (skills == 0){
//auton
} else{
//auton again
//rest of skills run
}