StOneDOes Posted October 14, 2017 Share Posted October 14, 2017 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? Quote Link to comment Share on other sites More sharing options...
gamecreator Posted October 14, 2017 Share Posted October 14, 2017 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. 1 Quote Link to comment Share on other sites More sharing options...
StOneDOes Posted October 14, 2017 Author Share Posted October 14, 2017 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? Quote Link to comment Share on other sites More sharing options...
Josh Posted October 14, 2017 Share Posted October 14, 2017 Create your GUI on the context, not the window. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
StOneDOes Posted October 14, 2017 Author Share Posted October 14, 2017 13 hours ago, Josh said: Create your GUI on the context, not the window. Yep, thanks for this one. But any advice to offer on my idea of event handling? Or perhaps is there another way? Quote Link to comment Share on other sites More sharing options...
StOneDOes Posted November 10, 2017 Author Share Posted November 10, 2017 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. Quote Link to comment Share on other sites More sharing options...
GorzenDev Posted November 12, 2017 Share Posted November 12, 2017 as far as i know that is the only way. Quote Link to comment Share on other sites More sharing options...
StOneDOes Posted November 13, 2017 Author Share Posted November 13, 2017 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. Quote Link to comment Share on other sites More sharing options...
GorzenDev Posted November 13, 2017 Share Posted November 13, 2017 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. Quote Link to comment Share on other sites More sharing options...
StOneDOes Posted November 18, 2017 Author Share Posted November 18, 2017 Seems to get a bit more difficult for trying to hook the mouse hover event for a button. It can clearly be done with lua but I can't see an event for this in event.h. Have you managed to come up with anything for this? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.