From 99bfad20b3c3171831da0a06aecf61692ac1ea71 Mon Sep 17 00:00:00 2001 From: Timo Schrader Date: Mon, 5 Jun 2023 18:20:17 +0200 Subject: [PATCH] (feature): Began implementing radius scaling for rounded borders. --- src/Window.cpp | 63 +++++++++++++++++++++++++++--------- src/config/ConfigManager.cpp | 4 +++ src/render/OpenGL.cpp | 7 ++-- src/render/Shader.hpp | 5 ++- 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/Window.cpp b/src/Window.cpp index ce3ee967..2cb123b2 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -523,29 +523,60 @@ void CWindow::updateDynamicRules() { // it is assumed that the point is within the real window box (m_vRealPosition, m_vRealSize) // otherwise behaviour is undefined bool CWindow::isInCurvedCorner(double x, double y) { - static auto* const ROUNDING = &g_pConfigManager->getConfigValuePtr("decoration:rounding")->intValue; + const uint8_t TOP_LEFT = 0; + const uint8_t TOP_RIGHT = 1; + const uint8_t BOTTOM_LEFT = 2; + const uint8_t BOTTOM_RIGHT = 3; + + + static auto* const ROUNDING = &g_pConfigManager->getConfigValuePtr("decoration:rounding")->intValue; + + static auto* const ROUNGING_SCALING_TOP_LEFT = &g_pConfigManager->getConfigValuePtr("decoration:rounding_scaling_top_left")->floatValue; + static auto* const ROUNGING_SCALING_TOP_RIGHT = &g_pConfigManager->getConfigValuePtr("decoration:rounding_scaling_top_left")->floatValue; + static auto* const ROUNGING_SCALING_BOTTOM_LEFT = &g_pConfigManager->getConfigValuePtr("decoration:rounding_scaling_top_left")->floatValue; + static auto* const ROUNGING_SCALING_BOTTOM_RIGHT = &g_pConfigManager->getConfigValuePtr("decoration:rounding_scaling_top_left")->floatValue; + static auto* const BORDERSIZE = &g_pConfigManager->getConfigValuePtr("general:border_size")->intValue; - if (BORDERSIZE >= ROUNDING || ROUNDING == 0) - return false; + static double const ROUNDING_INDEXED[4] = { + *ROUNDING * *ROUNGING_SCALING_TOP_LEFT, + *ROUNDING * *ROUNGING_SCALING_TOP_RIGHT, + *ROUNDING * *ROUNGING_SCALING_BOTTOM_LEFT, + *ROUNDING * *ROUNGING_SCALING_BOTTOM_RIGHT + }; - // (x0, y0), (x0, y1), ... are the center point of rounding at each corner - double x0 = m_vRealPosition.vec().x + *ROUNDING; - double y0 = m_vRealPosition.vec().y + *ROUNDING; - double x1 = m_vRealPosition.vec().x + m_vRealSize.vec().x - *ROUNDING; - double y1 = m_vRealPosition.vec().y + m_vRealSize.vec().y - *ROUNDING; + double roundingCenterCoords[8] = { + m_vRealPosition.vec().x + ROUNDING_INDEXED[TOP_LEFT], + m_vRealPosition.vec().x + m_vRealSize.vec().x - ROUNDING_INDEXED[TOP_RIGHT], + m_vRealPosition.vec().x + ROUNDING_INDEXED[BOTTOM_LEFT], + m_vRealPosition.vec().x + m_vRealSize.vec().x - ROUNDING_INDEXED[BOTTOM_RIGHT], + m_vRealPosition.vec().y + ROUNDING_INDEXED[TOP_LEFT], + m_vRealPosition.vec().y + ROUNDING_INDEXED[TOP_RIGHT], + m_vRealPosition.vec().y + m_vRealSize.vec().y + ROUNDING_INDEXED[BOTTOM_LEFT], + m_vRealPosition.vec().y + m_vRealSize.vec().y + ROUNDING_INDEXED[BOTTOM_RIGHT] + }; - if (x < x0 && y < y0) { - return Vector2D{x0, y0}.distance(Vector2D{x, y}) > (double)*ROUNDING; + Vector2D roundingCenter[4] = { + Vector2D(roundingCenterCoords[TOP_LEFT], roundingCenterCoords[TOP_LEFT+4]), + Vector2D(roundingCenterCoords[TOP_RIGHT], roundingCenterCoords[TOP_RIGHT+4]), + Vector2D(roundingCenterCoords[BOTTOM_RIGHT], roundingCenterCoords[BOTTOM_RIGHT+4]), + Vector2D(roundingCenterCoords[BOTTOM_LEFT], roundingCenterCoords[BOTTOM_LEFT+4]), + }; + + if (x < roundingCenter[TOP_LEFT].x && y < roundingCenter[TOP_LEFT].y) { + return roundingCenter->distance(Vector2D(x,y)) > ROUNDING_INDEXED[TOP_LEFT]; } - if (x > x1 && y < y0) { - return Vector2D{x1, y0}.distance(Vector2D{x, y}) > (double)*ROUNDING; + + if (x > roundingCenter[TOP_RIGHT].x && y < roundingCenter[TOP_RIGHT].y) { + return roundingCenter->distance(Vector2D(x,y)) > ROUNDING_INDEXED[TOP_RIGHT]; } - if (x < x0 && y > y1) { - return Vector2D{x0, y1}.distance(Vector2D{x, y}) > (double)*ROUNDING; + + if (x < roundingCenter[BOTTOM_LEFT].x && y > roundingCenter[BOTTOM_LEFT].y) { + return roundingCenter->distance(Vector2D(x,y)) > ROUNDING_INDEXED[BOTTOM_LEFT]; } - if (x > x1 && y > y1) { - return Vector2D{x1, y1}.distance(Vector2D{x, y}) > (double)*ROUNDING; + + if (x > roundingCenter[BOTTOM_RIGHT].x && y > roundingCenter[BOTTOM_RIGHT].y) { + return roundingCenter->distance(Vector2D(x,y)) > ROUNDING_INDEXED[BOTTOM_RIGHT]; } return false; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 99e7d99b..d2c01b77 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -110,6 +110,10 @@ void CConfigManager::setDefaultVars() { configValues["debug:manual_crash"].intValue = 0; configValues["decoration:rounding"].intValue = 0; + configValues["decoration:rounding_scaling_top_left"].floatValue = 1.0; + configValues["decoration:rounding_scaling_top_right"].floatValue = 1.0; + configValues["decoration:rounding_scaling_bottom_right"].floatValue = 1.0; + configValues["decoration:rounding_scaling_bottom_left"].floatValue = 1.0; configValues["decoration:blur"].intValue = 1; configValues["decoration:blur_size"].intValue = 8; configValues["decoration:blur_passes"].intValue = 1; diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index e47f5119..261f71e0 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -1052,7 +1052,7 @@ void pushVert2D(float x, float y, float* arr, int& counter, wlr_box* box) { counter++; } -void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CGradientValueData& grad, int round, int borderSize, float a) { +void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CGradientValueData& grad, int round_top_left, int round_top_right, int round_bottom_left, int round_bottom_right, int borderSize, float a) { RASSERT((box->width > 0 && box->height > 0), "Tried to render rect with width/height < 0!"); RASSERT(m_RenderData.pMonitor, "Tried to render rect without begin()!"); @@ -1079,7 +1079,10 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CGradientValueData& grad, box->width += 2 * scaledBorderSize; box->height += 2 * scaledBorderSize; - round += round == 0 ? 0 : scaledBorderSize; + round_top_left += round_top_left == 0 ? 0 : scaledBorderSize; + round_top_right += round_top_right == 0 ? 0 : scaledBorderSize; + round_bottom_left += round_bottom_left == 0 ? 0 : scaledBorderSize; + round_bottom_right += round_bottom_right == 0 ? 0 : scaledBorderSize; float matrix[9]; wlr_matrix_project_box(matrix, box, wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform), 0, diff --git a/src/render/Shader.hpp b/src/render/Shader.hpp index 04bf9259..01945999 100644 --- a/src/render/Shader.hpp +++ b/src/render/Shader.hpp @@ -21,7 +21,10 @@ class CShader { GLint bottomRight; GLint fullSize; GLint fullSizeUntransformed; - GLint radius; + GLint radius_top_left; + GLint radius_top_right; + GLint radius_bottom_left; + GLint radius_bottom_tight; GLint primitiveMultisample; GLint thick;