diff --git a/Decorations.cpp b/Decorations.cpp index 8620672..792310f 100644 --- a/Decorations.cpp +++ b/Decorations.cpp @@ -547,11 +547,6 @@ Disk::Disk() : Node() color = glm::vec4( 1.f, 1.f, 1.f, 1.f); } -Disk::~Disk() -{ - -} - void Disk::draw(glm::mat4 modelview, glm::mat4 projection) { if ( !initialized() ) { @@ -577,77 +572,85 @@ void Disk::accept(Visitor& v) v.visit(*this); } +Surface *Glyph::font_ = nullptr; +Glyph::Glyph(int imgui_font_index) : Node(), character_(' '), font_index_(imgui_font_index), ar_(1.f) +{ + if (Glyph::font_ == nullptr) + Glyph::font_ = new Surface; -//FrameBuffer *textToFrameBuffer(const std::string &text, font_style type, uint h) -//{ -// FrameBuffer *fb = nullptr; + uvTransform_ = glm::identity(); + color = glm::vec4( 1.f, 1.f, 1.f, 1.f); +} -// uint w = 0; -// for (auto i = 0; i < text.size(); ++i) { -// const ImFontGlyph* glyph = fontmap[type]->FindGlyph( text[i] ); -// w += h * (uint) ceil( (glyph->X1 - glyph->X0) / (glyph->Y1 - glyph->Y0) ); -// } -// if (w > 0) { +void Glyph::draw(glm::mat4 modelview, glm::mat4 projection) +{ + if ( !initialized() ) { -// // create and fill a FrameBuffer with the ImGui Font texture (once) -// static uint framebufferFont_ = 0; -// static uint textureFont_ = 0; -// static int widthFont_ =0; -// static int heightFont_ =0; -// if (framebufferFont_ == 0) { -// glGenTextures(1, &textureFont_); -// glBindTexture(GL_TEXTURE_2D, textureFont_); -// unsigned char *pixels; -// int bpp = 0; -// ImGuiIO& io = ImGui::GetIO(); -// io.Fonts->GetTexDataAsRGBA32(&pixels, &widthFont_, &heightFont_, &bpp); -// glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA, widthFont_, heightFont_); -// glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, widthFont_, heightFont_, GL_BGRA, GL_UNSIGNED_BYTE, pixels); -// glBindTexture(GL_TEXTURE_2D, 0); -// glGenFramebuffers(1, &framebufferFont_); -// glBindFramebuffer(GL_FRAMEBUFFER, framebufferFont_); -// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureFont_, 0); -// } + if (!Glyph::font_->initialized()) { -// // create an empty FrameBuffer for the target glyphs -// fb = new FrameBuffer(w, h, true); + uint tex = (uint)(intptr_t)ImGui::GetIO().Fonts->TexID; + if ( tex > 0) { + Glyph::font_->init(); + font_->setTextureIndex(tex); + } + } -//// uint textureGlyphs_ = 0; -//// glGenTextures(1, &textureGlyphs_); -//// glBindTexture(GL_TEXTURE_2D, textureGlyphs_); -//// glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA, w, h); -//// glBindTexture(GL_TEXTURE_2D, 0); -//// uint framebufferGlyphs_ = 0; -//// glGenFramebuffers(1, &framebufferGlyphs_); -//// glBindFramebuffer(GL_FRAMEBUFFER, framebufferGlyphs_); -//// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureGlyphs_, 0); + if (Glyph::font_->initialized()) { + init(); + setChar(character_); + } + } -//// glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferGlyphs_); + if ( visible_ ) { + // set color + Glyph::font_->shader()->color = color; -// // blit glyphs from framebufferFont_ to framebuffer target -// glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferFont_); -// glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb->opengl_id() ); + // modify the shader iTransform to select UVs of the desired glyph + Glyph::font_->shader()->iTransform = uvTransform_; -// GLint write_x = 0; -// for (auto i = 0; i < text.size(); ++i) { -// const ImFontGlyph* glyph = fontmap[type]->FindGlyph( text[i] ); -// w = h * (uint) ceil( (glyph->X1 - glyph->X0) / (glyph->Y1 - glyph->Y0) ); + // rebuild a matrix with rotation (see handles) and translation from modelview + translation_ + // and define scale to be 1, 1 + glm::mat4 ctm; + glm::vec3 rot(0.f); + glm::vec4 vec = modelview * glm::vec4(1.f, 0.f, 0.f, 0.f); + rot.z = glm::orientedAngle( glm::vec3(1.f, 0.f, 0.f), glm::normalize(glm::vec3(vec)), glm::vec3(0.f, 0.f, 1.f) ); + // extract scaling + ctm = glm::rotate(glm::identity(), -rot.z, glm::vec3(0.f, 0.f, 1.f)) * modelview ; + vec = ctm * glm::vec4(1.f, 1.f, 0.f, 0.f); + glm::vec3 sca = glm::vec3(vec.y, vec.y, 1.f) * glm::vec3(scale_.y * ar_, scale_.y, 1.f); + // extract translation + glm::vec3 tran = glm::vec3(modelview[3][0], modelview[3][1], modelview[3][2]) ; + tran += translation_ * glm::vec3(vec); + // apply local rotation + rot.z += rotation_.z; + // generate matrix + ctm = GlmToolkit::transform(tran, rot, sca); -// GLint read_x0 = (GLint) ( glyph->U0 * (float) widthFont_ ); -// GLint read_y0 = (GLint) ( glyph->V0 * (float) heightFont_ ); -// GLint read_x1 = (GLint) ( glyph->U1 * (float) widthFont_ ); -// GLint read_y1 = (GLint) ( glyph->V1 * (float) heightFont_ ); -// glBlitFramebuffer(read_x0, read_y0, read_x1, read_y1, -// write_x, 0, w, h, GL_COLOR_BUFFER_BIT, GL_LINEAR); + Glyph::font_->draw( ctm, projection); + } +} -// write_x += w; -// } +void Glyph::setChar(char c) +{ + character_ = c; -// } - -// return fb; -//} + if (initialized()) { + // get from imgui the UVs of the given char + const ImGuiIO& io = ImGui::GetIO(); + ImFont* myfont = io.Fonts->Fonts[0]; + if (font_index_ > 0 && font_index_ < io.Fonts->Fonts.size() ) + myfont = io.Fonts->Fonts[font_index_]; + const ImFontGlyph* glyph = myfont->FindGlyph(character_); + // create a texture UV transform to get the UV coordinates of the glyph + const glm::vec3 uv_t = glm::vec3( glyph->U0, glyph->V0, 0.f); + const glm::vec3 uv_s = glm::vec3( glyph->U1 - glyph->U0, glyph->V1 - glyph->V0, 1.f); + const glm::vec3 uv_r = glm::vec3(0.f, 0.f, 0.f); + uvTransform_ = GlmToolkit::transform(uv_t, uv_r, uv_s); + // remember aspect ratio + ar_ = (glyph->X1 - glyph->X0) / (glyph->Y1 - glyph->Y0); + } +} diff --git a/Decorations.h b/Decorations.h index 74c8e7b..b31c75c 100644 --- a/Decorations.h +++ b/Decorations.h @@ -83,7 +83,6 @@ class Disk : public Node { public: Disk(); - ~Disk(); void draw (glm::mat4 modelview, glm::mat4 projection) override; void accept (Visitor& v) override; @@ -94,21 +93,25 @@ protected: static Mesh *disk_; }; -//class TextSurface : public Node -//{ -//public: -// TextSurface(); +class Glyph : public Node +{ +public: + Glyph(int imgui_font_index = 0); + void setChar(char c); -// void draw (glm::mat4 modelview, glm::mat4 projection) override; + void draw (glm::mat4 modelview, glm::mat4 projection) override; -// void setText(const std::string &t); -// glm::vec4 color; + glm::vec4 color; -//protected: +protected: -// std::string text_; + char character_; + int font_index_; + float ar_; + glm::mat4 uvTransform_; + static Surface *font_; -//}; +}; #endif // DECORATIONS_H diff --git a/Source.cpp b/Source.cpp index b05ed1e..0e55503 100644 --- a/Source.cpp +++ b/Source.cpp @@ -143,6 +143,16 @@ Source::Source(uint64_t id) : SourceCore(), id_(id), ready_(false), symbol_(null frames_[View::MIXING]->attach(frame); groups_[View::MIXING]->attach(frames_[View::MIXING]); + // Glyphs show letters from the intials, with Font index 4 (LARGE) + initial_0_ = new Glyph(4); + initial_0_->translation_ = glm::vec3(0.2f, 0.75f, 0.1f); + initial_0_->scale_.y = 0.15f; + groups_[View::MIXING]->attach(initial_0_); + initial_1_ = new Glyph(4); + initial_1_->translation_ = glm::vec3(0.45f, 0.75f, 0.1f); + initial_1_->scale_.y = 0.15f; + groups_[View::MIXING]->attach(initial_1_); + overlays_[View::MIXING] = new Group; overlays_[View::MIXING]->translation_.z = 0.1; overlays_[View::MIXING]->visible_ = false; @@ -226,6 +236,9 @@ Source::Source(uint64_t id) : SourceCore(), id_(id), ready_(false), symbol_(null frames_[View::LAYER]->attach(frame); groups_[View::LAYER]->attach(frames_[View::LAYER]); + groups_[View::LAYER]->attach(initial_0_); + groups_[View::LAYER]->attach(initial_1_); + overlays_[View::LAYER] = new Group; overlays_[View::LAYER]->translation_.z = 0.15; overlays_[View::LAYER]->visible_ = false; @@ -351,6 +364,9 @@ void Source::setName (const std::string &name) initials_[0] = std::toupper( name_.front(), std::locale("C") ); initials_[1] = std::toupper( name_.back(), std::locale("C") ); + + initial_0_->setChar(initials_[0]); + initial_1_->setChar(initials_[1]); } void Source::accept(Visitor& v) @@ -381,6 +397,10 @@ void Source::setMode(Source::Mode m) for (auto o = overlays_.begin(); o != overlays_.end(); ++o) (*o).second->visible_ = (current && !locked_); + // the opacity of the initials changes if current + initial_0_->color.w = current ? 1.0 : 0.7; + initial_1_->color.w = current ? 1.0 : 0.7; + // the lock icon locker_->setActive( locked_ ? 0 : 1); @@ -495,6 +515,10 @@ void Source::attach(FrameBuffer *renderbuffer) symbol_->translation_.x += 0.1f * (renderbuffer_->aspectRatio()-1.f); } + // hack to place the initials in the corner independently of aspect ratio + initial_0_->translation_.x -= renderbuffer_->aspectRatio(); + initial_1_->translation_.x -= renderbuffer_->aspectRatio(); + // add lock icon to views (displayed on front) groups_[View::LAYER]->attach( locker_ ); groups_[View::MIXING]->attach( locker_ ); diff --git a/Source.h b/Source.h index 853dcda..b226f02 100644 --- a/Source.h +++ b/Source.h @@ -35,6 +35,7 @@ class FrameBufferSurface; class Frame; class Handles; class Symbol; +class Glyph; class CloneSource; class MixingGroup; @@ -303,6 +304,7 @@ protected: Handles *lock_, *unlock_; Switch *locker_; Symbol *symbol_; + Glyph *initial_0_, *initial_1_; // update bool active_; diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 05b215f..16460e3 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -184,7 +184,7 @@ bool UserInterface::Init() ImGuiToolkit::SetFont(ImGuiToolkit::FONT_BOLD, "Roboto-Bold", int(base_font_size) ); ImGuiToolkit::SetFont(ImGuiToolkit::FONT_ITALIC, "Roboto-Italic", int(base_font_size) ); ImGuiToolkit::SetFont(ImGuiToolkit::FONT_MONO, "Hack-Regular", int(base_font_size) - 2); - ImGuiToolkit::SetFont(ImGuiToolkit::FONT_LARGE, "Hack-Regular", MIN(int(base_font_size * 1.5f), 50), 1 ); + ImGuiToolkit::SetFont(ImGuiToolkit::FONT_LARGE, "Hack-Regular", MIN(int(base_font_size * 1.5f), 50) ); // info // Log::Info("Monitor (%.1f,%.1f)", Rendering::manager().monitorWidth(), Rendering::manager().monitorHeight());