Jump to content

Difficulty drawing Widgets


StOneDOes
 Share

Recommended Posts

Hi guys,

I'm trying to get the hang of drawing a GUI but falling rather short on actually getting anything to draw correctly. Right now I can create a button, but it only renders for a single frame when i hover the mouse over it and un-hover. So this leads me to believe that I need to perhaps render it every frame?

Here's a test example:

#include <Leadwerks.h>
using namespace Leadwerks;

int main( int argc,const char *argv[] )
{
    Window *window = Window::Create( "Some game", 100, 100, 400, 400, Window::Titlebar );
    Context *context = Context::Create( window );

    GUI *gui = GUI::Create( window );
    Widget *button = Widget::Create( "Some Button", 100, 100, 100, 100, gui->GetBase(), "Scripts/GUI/Button.lua" );

    button->Enable();
    button->Show();

    while( !window->Closed() )
    {
        //button->Draw( 100, 100, 100, 100 );
        context->Sync( true, 60.f );
    }

    context->Release();
    window->Release();

    return 0;

}

Now, if I uncomment the Draw function I get an exception thrown on the following line.

Thanks in advance for any help.

 

EDIT:

Just found this useful thread: https://www.leadwerks.com/community/topic/16487-understanding-new-gui-widgets/

 

Would calling Button::Redraw() every frame be the right way to go about this?

And while I'm here, is there also a way to hook the event of button press in c++ or does it have to be done with lua?

Link to comment
Share on other sites

1 hour ago, gamecreator said:

As far as I can tell, none of the widget or GUI commands have C++ examples, which is a little disappointing.  I tried to get it working here but it was buggy at the time: https://www.leadwerks.com/community/topic/16418-gui-commands-meant-to-be-cumulative/
Not sure if Josh ever fixed it or if I was even using it right.

Cool, thanks for this ... I realised that GUI::Create() has 2 other overloads earlier, but I'm not sure why I didn't try using context instead of the window. Using context instead seems to solve my problem (also Enable() and Show() are not necessary - from my example). Now I'll try some event research and see if I can get some stuff working.

EDIT:

Cool, and it works:

if( EventQueue::Peek() )
    {
        Event event = EventQueue::Wait();

        if( event.id == Event::WidgetAction )
        {
            //do stuff here
        }
    }

And then from here, I can edit Widget.h to store a function pointer which I can assign when creating the widget, and then call from it from inside the above, like so:

Object *source = event.source;

Widget *widget = dynamic_cast<Widget*>( source );
widget->function();

Thoughts on this?

Link to comment
Share on other sites

  • 3 weeks later...

Sorry to bump this but I really was hoping to get some advice here. Is there any current setup in C++ for some type of event handling with widget's other than what I've tried already? I was hoping for a better way, but also when compiling in Release Mode assigning a function pointer as a member variable to a Widget causes break points.

Link to comment
Share on other sites

22 hours ago, GorzenDev said:

as far as i know that is the only way.

 

Hmm okay, but do you have any idea as to why it may be causing break points when I compile and run in release mode (At exactly when I assign the function pointer to the widget)? Because strangely enough it only happens *most* of the time ... sometimes it can run just fine, but runs fine every time in debug mode.

Link to comment
Share on other sites

6 hours ago, St0nedas said:

Hmm okay, but do you have any idea as to why it may be causing break points when I compile and run in release mode (At exactly when I assign the function pointer to the widget)? Because strangely enough it only happens *most* of the time ... sometimes it can run just fine, but runs fine every time in debug mode.

i am not sure to be honest i have never tried assigning a function pointer to a widget.
i usually just check event.source against a widget pointer and call a specific class function corresponding to that widget.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...