SDL2 Forms

I am currently working on SDL2 forms interface.

The global idea is to create interface module that will be handling SDL events.
To hide mouse click on button logic and so on.

All you have to do is to create form, create button and attach a function to that button on corresponding event that you want to use it.

I didn’t found any similar systems so I decided to create it for my project.
Currently I done

Form
Button
Label
Edit

Indeed my code is not ideal.
So I am thinking to share it with the community so other people who will find it usefull to them too will be able to modify and improve it.

Example:

Code:

//=====ON CREATE
GCP_Controller *Interface = new GCP_Controller(sdlRenderer,SCREEN_WIDTH,SCREEN_HEIGHT);
Interface->setFont(font_path.str()); // *.ttf path
GCP_Form MainInterfaceForm = Interface->createForm(sdlRenderer); // main interface form
//=====GUI INIT
GCP_Button
bLoad = new GCP_Button();
bLoad->setCaption(“Button”);
bLoad->setWidthHeight(19,18);
bLoad->setPosition(100,200);
bLoad->iType = GCP_BUTTON_ROUNDRECT;
bLoad->setOnMouseLeftClick(this ,&MainClass::function); //attach function ‘function’ of MainClass (this) to button on MouseClick
MainInterfaceForm ->addComponent(bLoad);

//=====MAIN WHILE
SDL_RenderClear(sdlRenderer);
while( SDL_PollEvent( &event ) )
{
Interface->handleEvents(event); //handle interface events
if( event.type == SDL_QUIT )
return -1;
}
draw(); //Draw program logic
Interface->draw(); //Draw Interface
SDL_RenderPresent(sdlRenderer);
//================

I have written a fully-featured Button API, as part of SDLU, the SDL Utility library [http://bitbucket.org/sdlu/sdlu]. The API supports button callbacks on press or on mouse hover via event watchers, complete customization in its appearence and much more. Have a look at ‘src/button/SDLU_button.c’ for my implementation, it should be good to get you started and give you some ideas :slight_smile:

– Aggelos KolaitisOn Sep 16, 2013, at 12:59 PM, “Wins_Vefa” wrote:

I am currently working on SDL2 forms interface.

The global idea is to create interface module that will be handling SDL events.
To hide mouse click on button logic and so on.

All you have to do is to create form, create button and attach a function to that button on corresponding event that you want to use it.

I didn’t found any similar systems so I decided to create it for my project.
Currently I done

Form
Button
Label
Edit

Indeed my code is not ideal.
So I am thinking to share it with the community so other people who will find it usefull to them too will be able to modify and improve it.

Example:

Code:

//=====ON CREATE
GCP_Controller *Interface = new GCP_Controller(sdlRenderer,SCREEN_WIDTH,SCREEN_HEIGHT);
Interface->setFont(font_path.str()); // *.ttf path
GCP_Form MainInterfaceForm = Interface->createForm(sdlRenderer); // main interface form
//=====GUI INIT
GCP_Button
bLoad = new GCP_Button();
bLoad->setCaption(“Button”);
bLoad->setWidthHeight(19,18);
bLoad->setPosition(100,200);
bLoad->iType = GCP_BUTTON_ROUNDRECT;
bLoad->setOnMouseLeftClick(this ,&MainClass::function); //attach function ‘function’ of MainClass (this) to button on MouseClick
MainInterfaceForm ->addComponent(bLoad);

//=====MAIN WHILE
SDL_RenderClear(sdlRenderer);
while( SDL_PollEvent( &event ) )
{
Interface->handleEvents(event); //handle interface events
if( event.type == SDL_QUIT )
return -1;
}
draw(); //Draw program logic
Interface->draw(); //Draw Interface
SDL_RenderPresent(sdlRenderer);
//================


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Looks fancy.
Do you have screenshots or example programm?

Yup! You can look at test/testbutton.cOn Sep 16, 2013, at 11:35 PM, “Wins_Vefa” wrote:

Looks fancy.
Do you have screenshots or example programm?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org