Jump to content

how to implement a gui in cpp code?


Charrua
 Share

Recommended Posts

I started another thread (https://www.leadwerks.com/community/topic/16553-handling-widgets-created-cpp-side-and-lua-side/) because i started with a gui in lua and then has the need to create and handle some widgets in cpp code, i had some troubles and guessed that the problem was in a bad parameter usage/passage.

So I decided to make it work only in cpp code and i found that the test (event->source == butt1) never gets true, the same problem that i have when calling a method from lua passing the event peeked from the queue.

Relevant parts of my code:

/* globals */
GUI* gui;
Widget* butt1;

 

/* in App::Start */
gui = Leadwerks::GUI::Create(context);
butt1->Button("Quit",30,30,100,50,gui->GetBase());
/* function to process events */
bool App::ProcessEvent(Event* event){

    if (event->id == Event::WidgetAction) {
        System::Print("widget action!");
        if (event->source == butt1) {
            System::Print("butt1 pressed");
            butt1->Hide();
            return false;   //quit
        }
    }
    return true;
}


 

inside App::Loop

    while (EventQueue::Peek()){
        System::Print("event queue peek");
        Event event = EventQueue::Wait();
        if (ProcessEvent(&event)==false) return false;
    }

what am I doing wrong?

thanks in advance

Juan

Paren el mundo!, me quiero bajar.

Link to comment
Share on other sites

  • 11 months later...

at a first glanse i would say.


This:

butt1->Button("Quit",30,30,100,50,gui->GetBase());

Should be this:

butt1 = Widget::Button("Quit",30,30,100,50,gui->GetBase());


Also i advice to always add a panel script to your gui when you create one.
This neutralizes certain problems you could come across.

	gui = GUI::Create(context);
	gui->GetBase()->SetScript("Scripts/GUI/Panel.lua");
	gui->GetBase()->SetObject("background", new Vec4(0,0,0,0));

 

Link to comment
Share on other sites

thank's

I test the panel thing as GrozenDev suggested and works! but.. always a but i found other problem, not related with the gui itself.., it's related to latest beta, visual studio 2017.. don't know exactly ... will see

Paren el mundo!, me quiero bajar.

Link to comment
Share on other sites

  • 1 year later...

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...