Results 1 to 11 of 11

Thread: ClanLib 2.3.4 questions

  1. #1
    Lesser Knight
    Join Date
    Jun 2007
    Location
    Finland
    Posts
    44

    Default ClanLib 2.3.4 questions

    I'm porting my game from ClanLib 1 to ClanLib 2.3.4. For starters I have a few questions about the buttons, and I'm sure that more is on the way.

    What is the best or easiest way to set the textures and font for individual buttons? I don't want all my buttons to use the same theme. With ClanLib 1 I was doing it using CL_Button_Silver:

    button = new CL_Button();
    CL_Button_Silver *button_style = (CL_PushButton_Silver *)button->get_style();
    button_style->set_surface_up(surfaceUp);
    button_style->set_surface_down(surfaceDown);
    button_style->set_surface_highlighted(surfaceHL);
    button_style->set_font(font);

    Button->has_mouse_over() doesn't exist anymore, what should be used instead? I want to show some text when the mouse cursor is hovering above the button.


    Thanks for making a great lib.

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Since clanGUI was totally rewritten in Clanlib 2, the approach for doing this is quite different. All styling of GUI components is now done using CSS. You might have noticed it in the default theme - a theme.css file and a bunch of component css files. ClanLib CSS is built upon the normal HTML CSS selectors, so if you know that syntax, it should be pretty familiar and similar.

    For instance, if I want to have a specific style for a button, I could create a css like this:
    Code:
    button.custom
    {
    	bg-image-sizing-left:5;
    	bg-image-sizing-right:5;
    	bg-image-sizing-top:6;
    	bg-image-sizing-bottom:6;
    	bg-image-sizing:default;
    	text-color:white;
    }
    
    button.custom
    {
    	bg-image:ButtonNormal2; 
    }
    
    button.custom:defaulted
    {
    	bg-image:ButtonDefaulted2; 
    }
    
    button.custom:hot
    {
    	bg-image:ButtonHot2; 
    }
    
    button.custom:pressed
    {
    	bg-image:ButtonPressed2; 
    }
    
    button.custom:disabled
    {
    	bg-image:ButtonDisabled2; 
    	text-color:#444444;
    }
    ButtonNormal2, ButtonHot2 etc refers to an image in my resources.xml file:

    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <resources>
      <image name="ButtonNormal2">
        <image file="button_normal.png" />
      </image>
      <image name="ButtonHot2">
        <image file="button_hot.png" />
      </image>
    Notice the button.custom in the css ! The custom part is a css class selector. It means this css rule is only applied to buttons which has a class of "custom".

    In code this is how I create a button using this:

    CL_PushButton button(window);
    button.set_class_name("custom");
    button.set_geometry(rect);
    button.set_text("Custom Button");

    You can create as many classes you want.

    If you are familiar with CSS, you can also use ID selectors. The difference between a class and an id is that ids are unique to one component, while classes are used by many components.

    The CSS syntax for ids are

    Code:
    CSS: button#mycustomid { .. }
    Code: button.set_id_name("mycustomid");
    I've created a small example in the 2.4 branch of ClanLib that demonstrates this - it is called GUITexturedButtons. It is not available for ClanLib 2.3 as it relies on a 2.4 feature where you can load several gui themes and merge them. You can easily work around that in 2.3 by copying the default theme into your project and modify that instead of overriding it like I do in my example.

    Unfortunately, we don't have a complete documentation for which css properties every component has. We have some limited docs at http://clanlib.org/wiki/MainDocs:Standard_Components, at least it shows some of the basic components. The section called Available CSS Properties are properties that are available to all components, and is probably the most useful. PushButton is also documented, so if you want to change the font, you have the following options:

    Button text-color color black

    Button font-weight int or [normal, bold, bolder, light, lighter] normal
    Button font-size int -11
    Button font-style [none, italic] none
    Button font-family string Tahoma

    Button align [left, center, right, justify] left
    Button vertical-align [top, center, bottom] center


    A real example from the DiceWars game:

    Code:
    	text-color: white;
    
    	font-weight: bold;
    	font-size: 21;
    	font-family: VeraBd;
    DiceWars used a custom truetype font, so it needs to be registered in the system:

    Code:
    	CL_Font_System::register_font("Resources\\bitstream_vera_sans\\VeraBd.ttf", "VeraBd");

  3. #3
    Lesser Knight
    Join Date
    Jun 2007
    Location
    Finland
    Posts
    44

    Default

    Have I understood right, that if I want to use the GUI components I have to create my game window as CL_Window, instead of CL_DisplayWindow? In that case the flip() and CL_KeepAlive::process() functions are not used when rendering?

  4. #4
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    No, you don't neccesarily need to use CL_Window, you can use CL_DisplayWindow, and initialize the GUIManager with it (http://clanlib.org/docs/clanlib-2.3/...0f2a8755f24a4c)

    But if you are talking about your main loop, there are several ways to do "run the gui", but I'm not an expert on this field.

    Make sure you read the section bottom section at http://clanlib.org/wiki/MainDocs:GUI...play_Rendering. Basically it recommends you loose control to the gui and just hook into events created by it.

    But if you want to run your own loop, that is also possible - I think the GUIDirect example does this. (Maybe Rombust can answer this in more detail?)

  5. #5
    Lesser Knight
    Join Date
    Jun 2007
    Location
    Finland
    Posts
    44

    Default

    Quote Originally Posted by sphair View Post
    Make sure you read the section bottom section at http://clanlib.org/wiki/MainDocs:GUI...play_Rendering. Basically it recommends you loose control to the gui and just hook into events created by it.
    That's exactly what made me thinking that I should use CL_Window, and I should put my update&draw to the render callback function. However, I'd like to avoid that if possible.

  6. #6
    Lesser Knight
    Join Date
    Jun 2007
    Location
    Finland
    Posts
    44

    Default

    So I got my main loop running with CL_DisplayWindow & the GUI. I've updated my game to use the 2.3.4 API (Whew, that was some serious work!), but there are still some teething issues left.

    When I hide buttons with button->set_visible(false), the button is still drawn on every frame. It cannot be clicked, so that's ok, but I can see the button. Any ideas why? Below you can see my main loop.


    display = new CL_DisplayWindow( *displayDesc );
    gc = display->get_gc();
    wm = new CL_GUIWindowManagerTexture( *display );
    guimanager = new CL_GUIManager( *wm, GUITheme );
    rootWindow = new RootWindow( guimanager, displayDesc->get_size() );

    CL_PushButton *button1 = new CL_PushButton( rootWindow );
    ....

    while( !quit )
    {
    gc.clear( CL_Colorf::black );

    wm->process();
    wm->draw_windows(gc);
    display->flip(1);
    CL_KeepAlive::process();
    }


    Just in case, RootWindow:

    RootWindow::RootWindow(CL_GUIManager *gui, const CL_Rect &gui_position) : CL_GUIComponent(gui, CL_GUITopLevelDescription("GUI", gui_position, true))
    {
    }

  7. #7
    Peasant
    Join Date
    Aug 2011
    Location
    Helsinki, Finland, Finland
    Posts
    9

    Default

    Terve
    If you are using a .css style try changing the image for disabled buttons to transparent. That may work

  8. #8
    Lesser Knight
    Join Date
    Jun 2007
    Location
    Finland
    Posts
    44

    Default

    Moikkelis. I haven't tried the transparent image yet, but one way to fix this is to set_constant_repaint(true) for the buttons or RootWindow. It seems to have some effect on the performance though...

  9. #9
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Sounds weird that it still shows. I am using set_visible myself in my projects and they work fine.

    If you could create a minimal example with a visual studio project that demonstrates this effect, its easier for us to test it.

  10. #10
    Lesser Knight
    Join Date
    Jun 2007
    Location
    Finland
    Posts
    44

    Default

    Quote Originally Posted by sphair View Post
    Sounds weird that it still shows. I am using set_visible myself in my projects and they work fine.

    If you could create a minimal example with a visual studio project that demonstrates this effect, its easier for us to test it.
    I'll see if I can do that.

    Regarding the performance, I think that 2.3.4 is somewhat slower than 1.0. I found a thread here saying that 0.8.3->2.3.3 upgrade reduced the frame rate about 1/3, and in my case it's almost the same, especially when there are a lot of .png sprites on screen.

  11. #11
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Performance of CL_Sprites should now be similar. ClanLib 2.3.4 release contained: "Fix the OpenGL "allow_vertex_array_without_buffer_object" detection code by using the CL_OpenGLWindowDescription instead of the reported OpenGL version. This increases ClanGL speed on certain GPUs"

    There were some issues in the early 2.x series that have now been fixed.

    Although I cannot comment on the speed of clanGUI, I have not had much experience of it (ClanLib 2.3 and ClanLib 0.8)

    The "debug" builds of ClanLib can be a bit slow, unless the "compile debug with optimisations" setting is used in configure.exe. The precompiled libraries enable this setting.

    Note, CL_Image's are faster than CL_Sprites.
    Last edited by rombust; 03-15-2012 at 09:17 AM. Reason: add extra info

Similar Threads

  1. 2 questions when start using Clanlib GUI moudule
    By westpointer in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 05-26-2010, 12:44 PM
  2. ClanLib 0.9 GUI Questions
    By rombust in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 02-10-2009, 01:17 PM
  3. Questions
    By in forum Dink Smallwood HD
    Replies: 1
    Last Post: 12-20-2005, 09:54 PM
  4. few questions :D
    By virtual_lady in forum Dink Smallwood HD
    Replies: 3
    Last Post: 07-10-2005, 07:02 AM
  5. please,please,few questions
    By ladyblue in forum Dink Smallwood HD
    Replies: 2
    Last Post: 07-11-2004, 03:32 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •