Adding a method of rendering GUI's that avoid the whole throwing raw

data around everywhere thing I had going on before
This commit is contained in:
MitchellHansen
2017-09-27 23:36:20 -07:00
parent a6e18bbb54
commit 3ff6fb0b14
11 changed files with 343 additions and 59 deletions

View File

@@ -11,6 +11,7 @@
#include <unordered_map>
#include "Logger.h"
#include "map/Map.h"
#include "Gui.h"
#ifdef linux
#include <CL/cl.h>
@@ -86,7 +87,7 @@ struct device_info {
struct PackedData;
class CLCaster {
class CLCaster : private Gui {
public:
@@ -152,6 +153,11 @@ public:
void test_edit_viewport(int width, int height, float v_fov, float h_fov);
// ============= GUI ==============
virtual void render_gui() override;
virtual void update_gui() override;
// ================================
private:
/**

View File

@@ -1,11 +1,12 @@
#pragma once
#include <SFML/System/Vector3.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/System/Vector2.hpp>
#include "util.hpp"
#include "Pub_Sub.h"
#include <cmath>
#include "Gui.h"
class Camera : public VrEventSubscriber{
class Camera : public VrEventSubscriber, private Gui{
public:
enum DIRECTION { FORWARD, REARWARD, LEFT, RIGHT, UP, DOWN };
@@ -40,6 +41,10 @@ public:
void recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Event> event) override;
virtual void render_gui() override;
virtual void update_gui() override;
private:
float friction_coefficient = 0.1f;

66
include/Gui.h Normal file
View File

@@ -0,0 +1,66 @@
#pragma once
#include <mutex>
#include <Logger.h>
#include <list>
class Gui {
public:
Gui() {
container_lock.lock();
renderable_container.push_back(this);
container_lock.unlock();
};
virtual ~Gui() {
container_lock.lock();
renderable_container.remove(this);
container_lock.unlock();
};
virtual void render_gui() = 0;
virtual void update_gui() = 0;
// Instead of rendering nil, we can pass our render call if we would like
bool renderable() { return rendering; };
private:
// Whatever class that wants to call this must be a friend!!!
friend class Application;
static void do_render() {
for (auto i : renderable_container) {
i->update_gui();
if (i->renderable())
i->render_gui();
}
};
static std::mutex container_lock;
static std::list<Gui*> renderable_container;
protected:
bool rendering = false;
// Derived class will handle imgui calls
};

View File

@@ -4,9 +4,11 @@
#include "Event.hpp"
#include <memory>
#include "Pub_Sub.h"
#include "Gui.h"
#include <string>
class Input : public VrEventPublisher {
class Input : public VrEventPublisher, private Gui{
public:
Input();
@@ -21,6 +23,10 @@ public:
void handle_held_keys();
void dispatch_events();
virtual void render_gui() override;
virtual void update_gui() override;
private:
void transpose_sf_events(std::list<sf::Event> event_queue);
@@ -33,6 +39,8 @@ private:
private:
static const std::vector<std::string> key_strings;
std::list<std::unique_ptr<vr::Event>> event_queue;
};

View File

@@ -4,13 +4,14 @@
#include <memory>
#include "Pub_Sub.h"
#include "Vector4.hpp"
#include "Gui.h"
struct LightPrototype;
class LightController;
struct PackedData;
class LightHandle : public VrEventSubscriber{
class LightHandle : public VrEventSubscriber, private Gui{
public:
@@ -35,6 +36,10 @@ public:
void update(double delta_time);
virtual void render_gui() override;
virtual void update_gui() override;
private:
LightHandle(LightController *const light_controller, unsigned int light_id, LightPrototype light_prototype, PackedData *const data_reference);