From 5d6370eafbb943f25ce87b6d2f09d57f65a803fb Mon Sep 17 00:00:00 2001 From: malloc Date: Tue, 4 Sep 2018 16:31:11 -0500 Subject: [PATCH] im hearing jewish voices and i like it --- protocol.md | 2 +- src/client/ui/font.cpp | 26 ++++++++++++++++++++++++-- src/client/ui/font.hpp | 7 ++++--- src/client/ui/texture.cpp | 2 ++ src/client/ui/texture.hpp | 18 ++++++++++++++++++ 5 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 src/client/ui/texture.cpp create mode 100644 src/client/ui/texture.hpp diff --git a/protocol.md b/protocol.md index f911cf1..e20ea1e 100644 --- a/protocol.md +++ b/protocol.md @@ -51,7 +51,7 @@ TODO: populate To keep track of the status of multiple servers from a centralized point that the client may query, each server must be able to communicate with a "master" server that will record and dispense information regarding all servers to clients. All servers that report to the master server will hereby be refered to as "slave" servers. -Communication between master and slave servers will be done over a UDP connection on a port that is defined by the master server's configuration. The protocol used for this communication is identical to the protocol defined for standard client/server communication; however, the [_Packet IDs_](#TODO) are defined differently. +Communication between master and slave servers will be done over a TCP connection on a port that is defined by the master server's configuration. The protocol used for this communication is identical to the protocol defined for standard client/server communication; however, the [_Packet IDs_](#TODO) are defined differently. Communication between the master server and clients will be done over a WebSocket connection on a port that is defined by the master server's configuration. The protocol used for this communication is identical to the protocol defined for standard client/server communication; however, the [_Packet IDs_](#TODO) are defined differently. diff --git a/src/client/ui/font.cpp b/src/client/ui/font.cpp index 6a8f33d..22073c4 100644 --- a/src/client/ui/font.cpp +++ b/src/client/ui/font.cpp @@ -194,7 +194,6 @@ void sosc::ui::Font::UnbindBitmap() const { void sosc::ui::Font::Unload() { glDeleteTextures(1, &this->texture); - this->loaded = false; } @@ -274,6 +273,29 @@ void sosc::ui::Text::SetWrapWidth(uint32_t w) { this->Redraw(); } +uint32_t sosc::ui::Text::GetHeight() const { + return this->GetLineCount() * this->font_size; +} + +uint32_t sosc::ui::Text::GetLineCount() const { + if(this->wrap_width == 0) + return 1; + else { + uint32_t count = 1, topleft_x = 0; + for(const auto c : this->text) { + auto width = (uint32_t)((*this->font)[c].width * this->font_size); + + if(topleft_x + width > this->wrap_width) { + ++count; + topleft_x = 0; + } + + topleft_x += width; + } + return count; + } +} + void sosc::ui::Text::Render() { auto shdr = _font_ctx.shader; @@ -317,7 +339,7 @@ void sosc::ui::Text::Redraw() { delete[]this->tex_coords; this->tex_coords = new float[this->vertex_count * 2]; - uint32_t line_width = 0, top_x = 0, top_y = 0; + uint32_t top_x = 0, top_y = 0; for(int i = 0; i < this->text.length(); ++i) { auto glyph = (*this->font)[this->text[i]]; uint32_t width = (uint32_t)(this->font_size * glyph.width), diff --git a/src/client/ui/font.hpp b/src/client/ui/font.hpp index e73969a..e02228d 100644 --- a/src/client/ui/font.hpp +++ b/src/client/ui/font.hpp @@ -6,13 +6,11 @@ #include #include #include -#define GLM_ENABLE_EXPERIMENTAL -#include #include #include #include -#include +#include "ui/texture.hpp" #include "shaders/_shader.hpp" namespace sosc { @@ -96,6 +94,9 @@ public: void SetPosition(uint32_t x, uint32_t y); void SetWrapWidth(uint32_t w); + uint32_t GetHeight() const; + uint32_t GetLineCount() const; + void Render(); void Destroy(); diff --git a/src/client/ui/texture.cpp b/src/client/ui/texture.cpp new file mode 100644 index 0000000..32d5def --- /dev/null +++ b/src/client/ui/texture.cpp @@ -0,0 +1,2 @@ +#include "texture.hpp" + diff --git a/src/client/ui/texture.hpp b/src/client/ui/texture.hpp new file mode 100644 index 0000000..6d88aab --- /dev/null +++ b/src/client/ui/texture.hpp @@ -0,0 +1,18 @@ +#ifndef SOSC_UI_TEXTURE_H +#define SOSC_UI_TEXTURE_H + +#include +#include + + +namespace sosc { +namespace ui { +class Texture { +public: + +private: + +}; +}} + +#endif