Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sigui = Simple Includable GUI  (Read 5790 times)

0 Members and 2 Guests are viewing this topic.

DoctorJ

  • Newbie
  • *
  • Posts: 21
    • View Profile
sigui = Simple Includable GUI
« on: February 28, 2011, 09:09:53 pm »
sigui is a GUI for SFML 1.6 currently in alpha development. It consists of a c++ source file and header file which are simply included in your project. Interaction is via callback functions (or simple polling.)


Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sigui = Simple Includable GUI
« Reply #1 on: February 28, 2011, 10:18:42 pm »
Sounds interesting... :)

Do you already have more informations, for example how the code might look on user-side?
And is everything implemented in SFML, or do you use OS-specific functions?
How about configurability/layouts?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

DoctorJ

  • Newbie
  • *
  • Posts: 21
    • View Profile
sigui = Simple Includable GUI
« Reply #2 on: March 01, 2011, 04:34:32 am »
Its all SFML - no OS specific code. Originally, the drawing was all done as opengl code, but most of it is now done with SFML graphic calls, and should be completely converted before release. The naming conventions and exact function naming, etc is still subject to change. The idea, of course, is to make things easy to use. Currently, in addition to including the files in your project's development environment (I use Code::Blocks most of the time), 4 lines of code are needed to enable it.

// 1) access the header file:
#include "sigui.hpp"

...

sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Test"); // eg.

// 2) after creating the renderwindow and before declaring any gui components, initialize the gui system:
   GUIinitialize(&App);

...

 while (App.GetEvent(Event))
{
// 3) at the beginning of the event handler:
   if (GUIprocessEvent(Event)) continue;

...

// 4) after drawing your scene and before issuing the App.Display():
GUIdraw();


---------------------------------------------------

After step 2, you will need to declare all of the gui components. These are placed on "Forms" with the SFML renderwindow being a default form named "GUImain". A Form can be created with:

GUIform Form1(100, 50, 500, 300, "First Form"); // left, top, width, height

// a menu added with:
GUImenuBar Menu1(&Form1, "Files, Edit, View, Options, Help, Exit");

// callback function specified:
Menu1.MenuItemOnClick(5, &getoutahere); // respond to "Exit"

There are different ways to create the components, just some quick examples are shown. Form and component colors can be changed and images can be applied. Overall, it is still an "old-school" rectangle based GUI.

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
sigui = Simple Includable GUI
« Reply #3 on: March 03, 2011, 06:11:30 am »
Looks pretty awesome, do you have a download link so we could help test it out?
John Carmack can Divide by zer0.

DoctorJ

  • Newbie
  • *
  • Posts: 21
    • View Profile
sigui = Simple Includable GUI
« Reply #4 on: March 03, 2011, 08:44:11 am »
Its available at http://sourceforge.net/projects/sigui/
But there is no documentation yet. I consider it not quite ready for beta testing. Though I am settling on the current component set for the initial version. I need to finish up some details on the menu items and the tree-view component. Then a little more basic testing and it will be "beta-time" (serious testing and revision of the interface for ease of use).

If you are adventurous enough to try it out already, I can certainly give you some guidance on usage.

Just promise not to freak out when you see my sloppy code  :oops:

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
sigui = Simple Includable GUI
« Reply #5 on: March 04, 2011, 01:01:18 am »
Im feeling adventures, so any guidance you can offer would be appreciated, I'll just take a gander at the header file and your example above until then!
John Carmack can Divide by zer0.

DoctorJ

  • Newbie
  • *
  • Posts: 21
    • View Profile
sigui = Simple Includable GUI
« Reply #6 on: March 04, 2011, 07:23:28 am »
well, since you're feeling adventurous... :twisted: ... lets jump right to using function calls.

place this before the main statement

Code: [Select]
// GUI invoked functions
void CloseGUIform(GUIwidget *pWidget)  // close the form
{
    // find parent form
    while (pWidget->parent != NULL) pWidget = pWidget->parent;  // find uber parent
    if (pWidget->thisType == tguiForm) static_cast<GUIform*>(pWidget)->close(); // if uber parent was a form (it should be!), close it
}

void getoutahere(GUIwidget *pWidget)  // close the program
{
         // find parent form
    while (pWidget->parent != NULL) pWidget = pWidget->parent;  // find uber parent
    if (pWidget->thisType == tguiForm) static_cast<GUIform*>(pWidget)->parentApp->Close(); // close the application.
}

put this after GUIinitialize
Code: [Select]
   GUIform ExitDialog(App.GetWidth()/2-210, App.GetHeight()/2-100, 440, 200); // create 420x200 dialog in middle of screen
    ExitDialog.showTitleBar = false; // no need for resizing, moving or closing this dialog
    ExitDialog.bevelInner = bsDown;   // makes it a little more decorative
    GUIlabel exitText(&ExitDialog, 20, 30, "Changes unsaved, please confirm Exit (without saving).");
    GUIbutton exitCancelBtn(&ExitDialog, 100, 100, "Cancel");
    GUIbutton exitConfirmBtn(&ExitDialog, 240, 100, "Exit");
    exitConfirmBtn.OnClick = &getoutahere;
    exitCancelBtn.OnClick = &CloseGUIform;
    exitCancelBtn.toggle = false;
    exitConfirmBtn.toggle = false;

and put this in the event handler
Code: [Select]
           if (Event.Type == sf::Event::KeyPressed)
            {
                if (Event.Key.Code == sf::Key::Escape) // Escape key : exit
                {
                        ExitDialog.show();
                }
            }

Now when you press the escape key, the "confirm exit without saving dialog" will pop up.

:? I see that I need to change buttons so that "toggle" is false by default, since that is the typical behavior desired.

While this is bit complicated for a first taste, it does show how little you need to have in the game loop if you use function calls.

Still adventurous? Add the lines
Code: [Select]
   exitConfirmBtn.faceColor = sf::Color(sf::Color::Red);
    exitCancelBtn.faceColor = sf::Color(sf::Color::Green);
    exitConfirmBtn.useParentColors = false;
    exitCancelBtn.useParentColors = false;

to add color clues to the user!

CJ_COIMBRA

  • Full Member
  • ***
  • Posts: 112
    • ICQ Messenger - 13077864
    • View Profile
    • http://www.cjcoimbra.com
    • Email
Availability
« Reply #7 on: June 09, 2011, 09:54:49 pm »
Great work!

When do you think it will be ready for some use?
I could really use that on my ongoing project!
CJ

 

anything