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

data around everywhere thing I had going on before
master
MitchellHansen 7 years ago
parent a6e18bbb54
commit 3ff6fb0b14

@ -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:
/**

@ -4,8 +4,9 @@
#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;

@ -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
};

@ -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;
};

@ -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);

@ -145,40 +145,23 @@ bool Application::game_loop() {
fps.frame(delta_time);
fps.draw();
Gui::do_render();
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar;
bool window_show = true;
ImGui::Begin("Camera", &window_show, window_flags);
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginMenu("Menu"))
{
ImGui::Button("asdoifjasodif");
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
ImGui::Columns(2);
ImGui::Text("Camera Inclination");
ImGui::Text("Camera Azimuth");
ImGui::Text("Camera Pos_X");
ImGui::Text("Camera Poz_Y");
ImGui::Text("Camera Poz_Z");
ImGui::NextColumn();
sf::Vector2f dir = camera->get_direction();
sf::Vector3f pos = camera->get_position();
ImGui::Text("%f", dir.x);
ImGui::Text("%f", dir.y);
ImGui::Text("%f", pos.x);
ImGui::Text("%f", pos.y);
ImGui::Text("%f", pos.z);
ImGui::NextColumn();
ImGui::Begin("Window");
ImGui::InputText("filename", screenshot_buf, 128);
if (ImGui::Button("Take Screen shot")) {
@ -197,9 +180,6 @@ bool Application::game_loop() {
ImGui::NextColumn();
if (ImGui::Button("Recompile kernel")) {
while (!raycaster->debug_quick_recompile());
}
if (ImGui::Button("Pause")) {
paused = !paused;
@ -210,35 +190,8 @@ bool Application::game_loop() {
Logger::log("Unpausing", Logger::LogLevel::INFO);
}
ImGui::End();
ImGui::Begin("Lights");
if (ImGui::SliderFloat4("Color", light_color, 0, 1)) {
sf::Vector4f light(light_color[0], light_color[1], light_color[2], light_color[3]);
light_handle->set_rgbi(light);
}
if (ImGui::SliderFloat("Camera Speed", &camera_speed, 0, 4)) {
camera->setSpeed(camera_speed);
}
if (ImGui::SliderFloat3("Position", light_pos, 0, MAP_X)) {
sf::Vector3f light(light_pos[0], light_pos[1], light_pos[2]);
light_handle->set_position(light);
}
if (ImGui::CollapsingHeader("Window options"))
{
if (ImGui::TreeNode("Style"))
{
ImGui::ShowStyleEditor();
ImGui::TreePop();
}
}
ImGui::End();
ImGui::Begin("Controller debugger");

@ -335,6 +335,25 @@ bool CLCaster::debug_quick_recompile() {
}
void CLCaster::render_gui() {
ImGui::Begin("CLCaster");
if (ImGui::Button("Recompile Kernel")) {
while (!debug_quick_recompile()) {
std::cin.get();
};
}
ImGui::End();
}
void CLCaster::update_gui() {
rendering = true;
}
bool CLCaster::aquire_hardware() {
Logger::log("Acquiring OpenCL Hardware", Logger::LogLevel::INFO);

@ -197,6 +197,39 @@ void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Even
}
void Camera::render_gui() {
ImGui::Begin("Camera");
ImGui::Columns(2);
ImGui::Text("Camera Inclination");
ImGui::Text("Camera Azimuth");
ImGui::Text("Camera Pos_X");
ImGui::Text("Camera Poz_Y");
ImGui::Text("Camera Poz_Z");
ImGui::NextColumn();
ImGui::Text("%f", direction.x);
ImGui::Text("%f", direction.y);
ImGui::Text("%f", position.x);
ImGui::Text("%f", position.y);
ImGui::Text("%f", position.z);
ImGui::Separator();
ImGui::Columns(1);
ImGui::SliderFloat("Camera Speed", &default_impulse, 0, 4);
ImGui::End();
}
void Camera::update_gui() {
rendering = true;
}
void Camera::look_at_center() {
direction = CartToNormalizedSphere(sf::Vector3f(60, 60, 35) - position);

@ -0,0 +1,4 @@
#include "Gui.h"
std::mutex Gui::container_lock;
std::list<Gui*> Gui::renderable_container;

@ -1,8 +1,10 @@
#include "Input.h"
#pragma once
#include "Input.h"
#include <iostream>
#include <memory>
#include "imgui/imgui-SFML.h"
#include "Logger.h"
#include "LightHandle.h"
#include "imgui/imgui-SFML.h"
Input::Input() :
@ -119,6 +121,67 @@ void Input::dispatch_events() {
}
void Input::render_gui() {
ImGui::Begin("Input Debugger");
ImDrawList* draw_list = ImGui::GetWindowDrawList();
static ImVec4 col = ImVec4(1.0f, 0.0f, 1.0f, 1.0f);
const ImVec2 p = ImGui::GetCursorScreenPos();
const ImU32 col32 = ImColor(col);
std::vector<float> axis_values = {
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::X) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::Y) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::U) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::R) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::Z) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::V) / 2
};
ImGui::Columns(3, "Axis's"); // 4-ways, with border
ImGui::Separator();
ImGui::Text("X Y"); ImGui::NextColumn();
ImGui::Text("U R"); ImGui::NextColumn();
ImGui::Text("Z V"); ImGui::NextColumn();
ImGui::Separator();
for (int i = 0; i < 3; i++) {
float offset = ImGui::GetColumnWidth(i);
draw_list->AddLine(ImVec2(p.x + 0 + offset * i, p.y + 50), ImVec2(p.x + 100 + offset * i, p.y + 50), col32, 1.0);
draw_list->AddLine(ImVec2(p.x + 50 + offset * i, p.y + 0), ImVec2(p.x + 50 + offset * i, p.y + 100), col32, 1.0);
draw_list->AddCircleFilled(ImVec2(p.x + axis_values[2 * i] + 50 + offset * i, p.y + axis_values[2 * i + 1] + 50), 6, col32, 32);
ImGui::Dummy(ImVec2(100, 100));
ImGui::NextColumn();
}
ImGui::Text("Pressed Keyboard Keys");
ImGui::Separator();
ImGui::Columns(6);
for (auto i : held_keys) {
ImGui::Text(key_strings.at(i).c_str());
ImGui::NextColumn();
}
ImGui::Separator();
ImGui::End();
}
void Input::update_gui() {
rendering = true;
}
void Input::transpose_sf_events(std::list<sf::Event> sf_event_queue) {
@ -229,3 +292,108 @@ void Input::transpose_sf_events(std::list<sf::Event> sf_event_queue) {
}
}
const std::vector<std::string> Input::key_strings = {
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
"Num0",
"Num1",
"Num2",
"Num3",
"Num4",
"Num5",
"Num6",
"Num7",
"Num8",
"Num9",
"Escape",
"LControl",
"LShift",
"LAlt",
"LSystem",
"RControl",
"RShift",
"RAlt",
"RSystem",
"Menu",
"LBracket",
"RBracket",
"SemiColon",
"Comma",
"Period",
"Quote",
"Slash",
"BackSlash",
"Tilde",
"Equal",
"Dash",
"Space",
"Return",
"BackSpace",
"Tab",
"PageUp",
"PageDown",
"End",
"Home",
"Insert",
"Delete",
"Add",
"Subtract",
"Multiply",
"Divide",
"Left",
"Right",
"Up",
"Down",
"Numpad0",
"Numpad1",
"Numpad2",
"Numpad3",
"Numpad4",
"Numpad5",
"Numpad6",
"Numpad7",
"Numpad8",
"Numpad9",
"F1" ,
"F2" ,
"F3" ,
"F4" ,
"F5" ,
"F6" ,
"F7" ,
"F8" ,
"F9" ,
"F10",
"F11",
"F12",
"F13",
"F14",
"F15",
"Pause"
};

@ -95,3 +95,20 @@ void LightHandle::update(double delta_time) {
}
void LightHandle::render_gui() {
ImGui::Begin("Lights");
// Well I'm noooot reaallly supposed to do this. But I've been doing with the caster for
// a wile with no problems....
ImGui::SliderFloat4("Color", reinterpret_cast<float*>(&data_reference->rgbi), 0, 1);
ImGui::SliderFloat3("Position", reinterpret_cast<float*>(&data_reference->position), 0, 256);
ImGui::Separator();
ImGui::End();
}
void LightHandle::update_gui() {
rendering = true;
}

Loading…
Cancel
Save