This is a custom control that shows red or green.
struct control_data { // declare some data that you want to have associated with your control. CDATA color; _32 last_buttons; // used to track when a click happens }; EasyRegisterControl( WIDE( "simple" ), sizeof( struct ball_timer_data ) ); // define the function called when a new 'simple' control is created. static int OnCreateCommon( WIDE( "simple" ) )( PSI_CONTROL pc ) { MyValidatedControlData( struct control_data*, my_data, pc ); if( my_data ) { // assign a color to start my_data->color = BASE_COLOR_RED; return 1; } return 0; } // define a method to draw the control static int OnDrawCommon( WIDE( "simple" ) )( PSI_CONTROL pc ) { MyValidatedControlData( struct control_data*, my_data, pc ); if( my_data ) { Image image = GetControlSufrace( pc ); BlatColor( image, my_data->color ); return 1; // return that the draw happened. } return 0; // return no draw - prevents update. } // define a handler when the simple control is clicked. static int OnMouseCommon( WIDE( "simple" ) )( PSI_CONTROL pc, S_32 x, S_32 y, _32 b ) {
MyValidatedControlData( struct control_data*, my_data, pc ); // this checks to see if any mouse button goes down if( MAKE_NEWBUTTON( b, my_data->last_buttons ) ) { if( my_data->color == BASE_COLOR_RED ) my_data->color = BASE_COLOR_GREEN; else my_data->color = BASE_COLOR_RED; // tell the control to update. SmudgeCommon( pc ); } // save this button state as the prior button state for future checks my_data->last_buttons = b;
}