Basic GUI Creation
Bare with me im not a very good story teller .
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.
- 2
- 2
1 Comment
Recommended Comments