Results 1 to 7 of 7

Thread: Non-rectangular buttons

  1. #1

    Default Non-rectangular buttons

    Hi. I just thought of a feature idea.

    ClanLib has collision support which can detect whether a point is contained within an arbitrarily shaped object, and it can get the object outlines from images.

    ClanLib also supports GUI push buttons which seem to support images.

    Maybe CL_PushButton could be given an option to render completely as an image and ignore clicks that occur in the transparent areas of that image?

  2. #2

    Default

    Hm... I just had another idea of how I can do this in my project without having to mess with ClanLib.

    i.e.

    Code:
    class PushButtonLimited : public CL_PushButton
    {
        PushButtonLimited(parent, CL_CollisionOutline ClicksDontWorkOutsideOfThis);
        on_process_message();
    }
    
    PushButtonLimited : CL_PushButton()
    {
        membervar_old_callback = func_process_message();
        func_process_message.set(this, &PushButtonLimited::on_process_message());
    }
    
    PushButtonLimited::on_process_message()
    {
        if (inside outline)
        {
            membervar_old_callback.invoke()
        }
        // Otherwise, no dice!
    }
    Maybe that could be made generic with a template as well.

  3. #3

    Default

    Maybe someone should add a get_outline and set_outline in CL_GUIComponent, and change CL_GUIComponent::get_component_at(point) to only return points within the component outlines

    They'd still be able to draw outside of those bounds, but as far as mouse clicks are concerned the component would end where the outline ends.

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

    Default

    Interesting idea.

    Hopefully it can be implemented as an example.

    I thought the GUI component could pass down mouse clicks to the parent, so you can ignore "invalid presses". But I am not sure.

  5. #5

    Default

    That would be a good way to solve this sort of problem as well, but from what I can tell by reading the code, even if a click isn't consumed by a message handler that's just the end of it. It looks up the component by the mouse position, and returns that, then sends that component the click.

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

    Default

    Also:

    ClanLib has collision support which can detect whether a point is contained within an arbitrarily shaped object, and it can get the object outlines from images.
    I think it would be easier, not using ClanLib's collision.

    Instead, have your own push button contain the CL_PixelBuffer of the image.
    (i.e. CL_PixelBuffer pixelbuffer("myimage.png"); CL_Image image(gc, pixelbuffer));

    Next translate the mouse coordinates into the x,y position inside the pixelbuffer.

    Then use the following code:
    Code:
     CL_Colorf color = pixelbuffer.get_pixel(xpos, ypos);
     if (color.a < 0.2f)  // (You may need to adjust this alpha threshold)
     {
       ignore_mouse_press
     }
     else
     {
       button_was_pressed
      }

  7. #7

    Default

    Ah! Good advice, thanks

Similar Threads

  1. Problems with user defined push buttons
    By MaxMustermann in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 06-21-2010, 01:42 PM
  2. Buttons fonts in ClanLib 1.0.0
    By Veitikka in forum Official ClanLib SDK Forums
    Replies: 12
    Last Post: 01-06-2010, 04:09 PM
  3. GUIs, Buttons, and the like...
    By Methius in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 03-28-2008, 07:50 PM
  4. Dynamically generate GUI buttons,labels and stuff
    By d_oilen in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 11-22-2006, 09:21 AM

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
  •