diff --git a/Decorations.cpp b/Decorations.cpp index a8762e1..61c9261 100644 --- a/Decorations.cpp +++ b/Decorations.cpp @@ -27,8 +27,8 @@ Frame::Frame(CornerType corner, BorderType border, ShadowType shadow) : Node(), frames[2] = new Mesh("mesh/border_large_round.ply"); frames[3] = new Mesh("mesh/border_large_top.ply"); } - static LineSquare *sharpframethin = new LineSquare( 3 ); - static LineSquare *sharpframelarge = new LineSquare( 5 ); + static LineSquare *sharpframethin = new LineSquare( 4.f ); + static LineSquare *sharpframelarge = new LineSquare( 6.f ); if (corner == SHARP) { if (border == LARGE) @@ -116,7 +116,7 @@ void Frame::draw(glm::mat4 modelview, glm::mat4 projection) // top (scaled) if(square_) { - square_->shader()->color = color; + square_->setColor(color); square_->draw( ctm, projection); } diff --git a/ImGuiToolkit.cpp b/ImGuiToolkit.cpp index 71831ed..5d8501c 100644 --- a/ImGuiToolkit.cpp +++ b/ImGuiToolkit.cpp @@ -921,7 +921,7 @@ void ImGuiToolkit::ShowStats(bool *p_open, int* p_corner, bool *p_timer) ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background - if (ImGui::Begin("Metrics", NULL, (corner != -1 ? ImGuiWindowFlags_NoMove : 0) | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav)) + if (ImGui::Begin("Metrics", NULL, (corner != -1 ? ImGuiWindowFlags_NoMove : 0) | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav)) { int mode = (*p_timer) ? 1 : 0; ImGui::SetNextItemWidth(220); diff --git a/Primitives.cpp b/Primitives.cpp index b7f7848..469a659 100644 --- a/Primitives.cpp +++ b/Primitives.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #define GLM_ENABLE_EXPERIMENTAL @@ -224,6 +225,204 @@ void Points::accept(Visitor& v) v.visit(*this); } + + +HLine::HLine(float linewidth): Primitive(new Shader), width(linewidth) +{ + // 1 3 + // +-------+ ^ + // / | / | \ | + // +-----+ => 0 + | / | + 5 | linewidth + // -1 1 \ | / | / | + // +-------+ v + // 2 4 + // + points_ = std::vector { glm::vec3( -1.f, 0.f, 0.f ), + glm::vec3( -0.999f, 0.001f, 0.f ), + glm::vec3( -0.999f, -0.001f, 0.f ), + glm::vec3( 0.999f, 0.001f, 0.f ), + glm::vec3( 0.999f, -0.001f, 0.f ), + glm::vec3( 1.f, 0.f, 0.f ) }; + colors_ = std::vector { glm::vec4( 1.f, 1.f, 1.f , 1.f ), glm::vec4( 1.f, 1.f, 1.f, 1.f ), + glm::vec4( 1.f, 1.f, 1.f, 1.f ), glm::vec4( 1.f, 1.f, 1.f, 1.f ), + glm::vec4( 1.f, 1.f, 1.f, 1.f ), glm::vec4( 1.f, 1.f, 1.f, 1.f ) }; + indices_ = std::vector { 0, 1, 2, 3, 4, 5 }; + drawMode_ = GL_TRIANGLE_STRIP; + + // default scale + scale_.y = width; + + //default color + color = glm::vec4( 1.f, 1.f, 1.f, 1.f); +} + +HLine::~HLine() +{ + // do NOT delete vao_ (unique) + vao_ = 0; +} + +void HLine::init() +{ + // use static unique vertex array object + static uint unique_vao_ = 0; + static uint unique_drawCount = 0; + if (unique_vao_) { + // 1. only init Node (not the primitive vao) + Node::init(); + // 2. use the global vertex array object + vao_ = unique_vao_; + drawCount_ = unique_drawCount; + // compute AxisAlignedBoundingBox + bbox_.extend(points_); + // arrays of vertices are not needed anymore + points_.clear(); + colors_.clear(); + texCoords_.clear(); + indices_.clear(); + } + else { + // 1. init the Primitive (only once) + Primitive::init(); + // 2. remember global vertex array object + unique_vao_ = vao_; + unique_drawCount = drawCount_; + // 3. unique_vao_ will NOT be deleted + } + +} + +void HLine::draw(glm::mat4 modelview, glm::mat4 projection) +{ + // extract pure scaling from modelview (without rotation) + 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) ); + 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); + + // Change transform to use linewidth independently of scale in Y (vertical) + scale_.y = (float) width / vec.y; + update(0); + + // change color + shader_->color = color; + + Primitive::draw(modelview, projection); +} + +VLine::VLine(float linewidth): Primitive(new Shader), width(linewidth) +{ + points_ = std::vector { glm::vec3( 0.f, -1.f, 0.f ), + glm::vec3( 0.001f, -0.999f, 0.f ), + glm::vec3( -0.001f, -0.999f, 0.f ), + glm::vec3( 0.001f, 0.999f, 0.f ), + glm::vec3( -0.001f, 0.999f, 0.f ), + glm::vec3( 0.f, 1.f, 0.f )}; + colors_ = std::vector { glm::vec4( 1.f, 1.f, 1.f , 1.f ), glm::vec4( 1.f, 1.f, 1.f, 1.f ), + glm::vec4( 1.f, 1.f, 1.f, 1.f ), glm::vec4( 1.f, 1.f, 1.f, 1.f ), + glm::vec4( 1.f, 1.f, 1.f, 1.f ), glm::vec4( 1.f, 1.f, 1.f, 1.f ) }; + indices_ = std::vector { 0, 1, 2, 3, 4, 5 }; + drawMode_ = GL_TRIANGLE_STRIP; + + // default scale + scale_.x = width; + + // default color + color = glm::vec4( 1.f, 1.f, 1.f, 1.f); +} + +VLine::~VLine() +{ + // do NOT delete vao_ (unique) + vao_ = 0; +} + +void VLine::init() +{ + // use static unique vertex array object + static uint unique_vao_ = 0; + static uint unique_drawCount = 0; + if (unique_vao_) { + // 1. only init Node (not the primitive vao) + Node::init(); + // 2. use the global vertex array object + vao_ = unique_vao_; + drawCount_ = unique_drawCount; + // compute AxisAlignedBoundingBox + bbox_.extend(points_); + // arrays of vertices are not needed anymore + points_.clear(); + colors_.clear(); + texCoords_.clear(); + indices_.clear(); + } + else { + // 1. init the Primitive (only once) + Primitive::init(); + // 2. remember global vertex array object + unique_vao_ = vao_; + unique_drawCount = drawCount_; + // 3. unique_vao_ will NOT be deleted + } + +} + +void VLine::draw(glm::mat4 modelview, glm::mat4 projection) +{ + // extract pure scaling from modelview (without rotation) + 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) ); + 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); + + // Change transform to use linewidth independently of scale in X (horizontal) + scale_.x = width / vec.x; + update(0); + + // change color + shader_->color = color; + + Primitive::draw(modelview, projection); +} + +LineSquare::LineSquare(float linewidth) : Group() +{ + top_ = new HLine(linewidth); + top_->translation_ = glm::vec3(0.f, 1.f, 0.f); + attach(top_); + bottom_ = new HLine(linewidth); + bottom_->translation_ = glm::vec3(0.f, -1.f, 0.f); + attach(bottom_); + left_ = new VLine(linewidth); + left_->translation_ = glm::vec3(-1.f, 0.f, 0.f); + attach(left_); + right_ = new VLine(linewidth); + right_->translation_ = glm::vec3(1.f, 0.f, 0.f); + attach(right_); +} + + +void LineSquare::setLineWidth(float v) +{ + top_->width = v; + bottom_->width = v; + left_->width = v; + right_->width = v; +} + +void LineSquare::setColor(glm::vec4 c) +{ + top_->color = c; + bottom_->color = c; + left_->color = c; + right_->color = c; +} + + LineStrip::LineStrip(std::vector points, std::vector colors, uint linewidth) : Primitive(new Shader), linewidth_(linewidth) { for(size_t i = 0; i < points.size(); ++i) @@ -263,64 +462,6 @@ void LineStrip::accept(Visitor& v) } - -static const std::vector square_points { - glm::vec3( -1.f, -1.f, 0.f ), glm::vec3( -1.f, 1.f, 0.f ), - glm::vec3( 1.f, 1.f, 0.f ), glm::vec3( 1.f, -1.f, 0.f ), - glm::vec3( -1.f, -1.f, 0.f ) -}; - -static const std::vector square_colors { - glm::vec4( 1.f, 1.f, 1.f, 1.f ), glm::vec4( 1.f, 1.f, 1.f, 1.f ), - glm::vec4( 1.f, 1.f, 1.f, 1.f ), glm::vec4( 1.f, 1.f, 1.f, 1.f ), - glm::vec4( 1.f, 1.f, 1.f, 1.f ) -}; - -LineSquare::LineSquare(uint linewidth) : LineStrip(square_points, square_colors, linewidth) -{ -} - -void LineSquare::init() -{ - // use static unique vertex array object - static uint unique_vao_ = 0; - static uint unique_drawCount = 0; - if (unique_vao_) { - // 1. only init Node (not the primitive vao) - Node::init(); - // 2. use the global vertex array object - vao_ = unique_vao_; - drawCount_ = unique_drawCount; - // compute AxisAlignedBoundingBox - bbox_.extend(points_); - // arrays of vertices are not needed anymore - points_.clear(); - colors_.clear(); - texCoords_.clear(); - indices_.clear(); - } - else { - // 1. init the Primitive (only once) - Primitive::init(); - // 2. remember global vertex array object - unique_vao_ = vao_; - unique_drawCount = drawCount_; - } -} - -void LineSquare::accept(Visitor& v) -{ - Primitive::accept(v); - v.visit(*this); -} - -LineSquare::~LineSquare() -{ - // do NOT delete vao_ (unique) - vao_ = 0; -} - - LineCircle::LineCircle(uint linewidth) : LineStrip(std::vector(), std::vector(), linewidth) { static int N = 72; diff --git a/Primitives.h b/Primitives.h index 33023bc..10410ef 100644 --- a/Primitives.h +++ b/Primitives.h @@ -124,6 +124,52 @@ public: }; +class HLine : public Primitive { + +public: + + HLine(float width = 1.f); + virtual ~HLine(); + + void init () override; + void draw(glm::mat4 modelview, glm::mat4 projection) override; + + glm::vec4 color; + float width; +}; + +class VLine : public Primitive { + +public: + + VLine(float width = 1.f); + virtual ~VLine(); + + void init () override; + void draw(glm::mat4 modelview, glm::mat4 projection) override; + + glm::vec4 color; + float width; +}; + +/** + * @brief The LineSquare class is a group of 4 lines (width & height = 1.0) + */ +class LineSquare : public Group { + + HLine *top_, *bottom_; + VLine *left_, *right_; + +public: + LineSquare(float linewidth = 1.f); + + void setLineWidth(float v); + inline float lineWidth() const { return top_->width; } + + void setColor(glm::vec4 c); + inline glm::vec4 color() const { return top_->color; } +}; + /** * @brief The LineStrip class is a Primitive to draw lines */ @@ -145,21 +191,6 @@ public: }; -/** - * @brief The LineSquare class is a square LineStrip (width & height = 1.0) - */ -class LineSquare : public LineStrip { - -public: - LineSquare(uint linewidth = 1); - - void init() override; - void accept(Visitor& v) override; - - virtual ~LineSquare(); -}; - - /** * @brief The LineCircle class is a circular LineStrip (diameter = 1.0) */ diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 88e944b..65f3c6d 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -1452,16 +1452,25 @@ int UserInterface::RenderViewNavigator(int *shift) // 4 subtitles (text centered in column) ImGui::NextColumn(); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ImGui::GetColumnWidth() - ImGui::CalcTextSize("Mixing").x) * 0.5f - ImGui::GetStyle().ItemSpacing.x); + + ImGuiToolkit::PushFont(Settings::application.current_view == 1 ? ImGuiToolkit::FONT_BOLD : ImGuiToolkit::FONT_DEFAULT); ImGui::Text("Mixing"); + ImGui::PopFont(); ImGui::NextColumn(); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ImGui::GetColumnWidth() - ImGui::CalcTextSize("Geometry").x) * 0.5f - ImGui::GetStyle().ItemSpacing.x); + ImGuiToolkit::PushFont(Settings::application.current_view == 2 ? ImGuiToolkit::FONT_BOLD : ImGuiToolkit::FONT_DEFAULT); ImGui::Text("Geometry"); + ImGui::PopFont(); ImGui::NextColumn(); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ImGui::GetColumnWidth() - ImGui::CalcTextSize("Layers").x) * 0.5f - ImGui::GetStyle().ItemSpacing.x); + ImGuiToolkit::PushFont(Settings::application.current_view == 3 ? ImGuiToolkit::FONT_BOLD : ImGuiToolkit::FONT_DEFAULT); ImGui::Text("Layers"); + ImGui::PopFont(); ImGui::NextColumn(); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ImGui::GetColumnWidth() - ImGui::CalcTextSize("Texturing").x) * 0.5f - ImGui::GetStyle().ItemSpacing.x); + ImGuiToolkit::PushFont(Settings::application.current_view == 4 ? ImGuiToolkit::FONT_BOLD : ImGuiToolkit::FONT_DEFAULT); ImGui::Text("Texturing"); + ImGui::PopFont(); ImGui::Columns(1); ImGui::PopStyleVar();