Jump to content
  • entries
    4
  • comments
    2
  • views
    4,007

Basic GUI Creation


GorzenDev

2,370 views

 Share

Bare with me im not a very good story teller :D .
I will not be focusing on basic leadwerks usage and assume the reader knows a thing or 2 about leadwerks.

So lets start with the basics,
Create a window and context.

bool App::Start()
{
	window = Leadwerks::Window::Create("GUI Tutorial", 0, 0, 1024, 768);
	context = Leadwerks::Context::Create(window);
  
  	return true;
}

bool App::Loop()
{
	if (window->Closed() || window->KeyHit(Key::Escape)) return false;

	return true;
}

Now i personally like to use classes for my GUI so thats what we are gonna do.
Create a new class called "UI_Interface".

UI_Interface.h

#pragma once

#include "Leadwerks.h"

//Forward declare
class App;

using namespace Leadwerks;

class UI_Interface
{
private:
	App* app = NULL;
	//
	GUI* gui = NULL;
public:
	UI_Interface();
	UI_Interface(App* pApp);
	~UI_Interface();

	void Process();
	bool ProcessEvent(Event event);
};

UI_Interface.cpp

#include "UI_Interface.h"

//Forward declares
#include "App.h"

UI_Interface::UI_Interface() {}

UI_Interface::UI_Interface(App* pApp)
{

}

UI_Interface::~UI_Interface()
{
}

void UI_Interface::Process()
{
	while (EventQueue::Peek())
	{
		Event event = EventQueue::Wait();
		ProcessEvent(event);
	}
}

bool UI_Interface::ProcessEvent(Event event)
{
	if (event.id == Event::WidgetSelect)
	{

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

	}
	//
	return false;
}

now that we have a interface class lets first make sure it is created and called in your main function or app.

App.h

#pragma once

#include "Leadwerks.h"
#include "UI_Interface.h"

#undef GetFileType

using namespace Leadwerks;

class App
{
public:
	Leadwerks::Window* window;
	Context* context;
	World* world;
	Camera* camera;

	UI_Interface* ui_Interface = NULL;

	App();
	virtual ~App();

    bool Start();
    bool Loop();
};

App.cpp

#include "App.h"

using namespace Leadwerks;

App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}

App::~App() { delete ui_Interface; delete world; delete window; }

bool App::Start()
{
	window = Leadwerks::Window::Create("GUI Tutorial", 0, 0, 1024, 768);
	context = Leadwerks::Context::Create(window);

	//create GUI
	ui_Interface = new UI_Interface(this);

	return true;
}

bool App::Loop()
{
	if (window->Closed() || window->KeyHit(Key::Escape))
	{
		return false;
	}

	context->SetColor(0.0, 0.0, 0.0);
	context->Clear();

	//
	ui_Interface->Process();

	//
	Time::Update();

	//
	//world->Update();

	//
	//world->Render();

	//
	context->Sync();

	return true;
}


Now lets create the GUI in the UI_Interface class.

UI_Interface::UI_Interface(App* pApp)
{
	app = pApp;
	//
	//create gui
	gui = GUI::Create(app->context);
	float guiScale = gui->GetScale();
	gui->GetBase()->SetScript("Scripts/GUI/Panel.lua");
  	//make the base gui invisible if you want
	//gui->GetBase()->SetObject("backgroundcolor", new Vec4(0, 0, 0, 0));
}


This will result in a window with a panel as background.
Next blog entry we will be focusing on adding widgets to the GUI.



 

  • Like 2
  • Thanks 2
 Share

1 Comment


Recommended Comments

thank's, i have been doing some trials... without much success trying to get events and objetcts from cpp created lua side... i will read and try what you posted here... 

and

but... no one answer... seems to be a black hole on this topic

hope your blog bring to me some light at the end of the tunnel  :)

Juan

 

Link to comment
Guest
Add a comment...

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

×
×
  • Create New...