From 54e34af3ecbb0f1c79132c223424c60728ece828 Mon Sep 17 00:00:00 2001 From: Stefan Berggren Date: Sun, 18 Dec 2016 19:55:56 +0100 Subject: [PATCH 1/3] Store 't' package and display last 10 on screen. --- src/main.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 6b0df08..529cb64 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "tiny_obj_loader.h" #include "optional.hpp" #include "matrix.h" @@ -267,6 +268,12 @@ class Konstructs: public nanogui::Screen { } + int n = 0; + for (auto it=text_list.cbegin(); it != text_list.cend(); ++it, n++) { + if (n < (int)text_list.size() - 10) continue; + os << *it << std::endl; + } + glActiveTexture(GL_TEXTURE0); nvgFontBlur(mNVGContext, 0.8f); nvgFontSize(mNVGContext, 20.0f); @@ -490,6 +497,9 @@ class Konstructs: public nanogui::Screen { case 'T': handle_time(packet->to_string()); break; + case 't': + handle_text(packet->to_string()); + break; default: cout << "UNKNOWN: " << packet->type << endl; break; @@ -627,6 +637,14 @@ class Konstructs: public nanogui::Screen { glfwSetTime((double)time_value); } + void handle_text(const string &str) { + if(sscanf(str.c_str(), ",%4096[^,]", text_recive_buffer) != 1) { + throw std::runtime_error(str); + } + + text_list.push_back(string(text_recive_buffer)); + } + float time_of_day() { if (day_length <= 0) { return 0.5; @@ -762,6 +780,8 @@ class Konstructs: public nanogui::Screen { uint32_t max_faces; double frame_time; uint32_t click_delay; + char text_recive_buffer[4096]; + std::list text_list; }; #ifdef WIN32 From 970cdbe14a84ac06899bc1b6840bbf6d5a4015fb Mon Sep 17 00:00:00 2001 From: Stefan Berggren Date: Sun, 18 Dec 2016 20:04:28 +0100 Subject: [PATCH 2/3] Display selected hud slot. This is a placeholder. --- src/main.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 529cb64..6fc63aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -231,6 +231,7 @@ class Konstructs: public nanogui::Screen { hud_shader.render(mSize.x(), mSize.y(), mx, my, hud, blocks); update_radius(); print_top_text(); + print_hud_descr_text(hud.get_selection()); } else if(!menu_state) { show_menu(2, client.get_error_message()); } @@ -280,6 +281,21 @@ class Konstructs: public nanogui::Screen { nvgTextBox(mNVGContext, 10, 20, width - 10, os.str().c_str(), NULL); } + void print_hud_descr_text(int selection) { + int width, height; + glfwGetFramebufferSize(mGLFWWindow, &width, &height); + + ostringstream os; + os << "Selected slot " << selection << std::endl; + + glActiveTexture(GL_TEXTURE0); + + nvgFontBlur(mNVGContext, 0.8f); + nvgFontSize(mNVGContext, ((float)height * 0.03)); + nvgTextAlign(mNVGContext, 2); + nvgTextBox(mNVGContext, 10, height - (height * 0.08), width - 10, os.str().c_str(), NULL); + } + int translate_button(int button) { switch(button) { case GLFW_MOUSE_BUTTON_1: From 9f6717a3ff18342c9bb85bdf1f0fbb2a45b57478 Mon Sep 17 00:00:00 2001 From: Stefan Berggren Date: Sun, 18 Dec 2016 21:12:05 +0100 Subject: [PATCH 3/3] Make the formatter happy. --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 6fc63aa..30b53a4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -271,7 +271,9 @@ class Konstructs: public nanogui::Screen { int n = 0; for (auto it=text_list.cbegin(); it != text_list.cend(); ++it, n++) { - if (n < (int)text_list.size() - 10) continue; + if (n < (int)text_list.size() - 10) { + continue; + } os << *it << std::endl; }