From 7b85239093587c5cfa57c6bf846b89a0e6db358e Mon Sep 17 00:00:00 2001 From: tetektoza Date: Sun, 31 Aug 2025 21:36:24 +0200 Subject: [PATCH] Sketcher: Use different colors for touch/window selection (#23261) * Sketcher: Use different colors for touch/window selection As the title says. I think it was missing, so currently right to left motion makes the box selection in Sketcher green with dashed lines, whereas motion from left to right makes it blue with solid lines. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/Mod/Sketcher/Gui/CMakeLists.txt | 1 + src/Mod/Sketcher/Gui/StyleParameters.h | 40 +++++++++++++++++++++ src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 18 ++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/Mod/Sketcher/Gui/StyleParameters.h diff --git a/src/Mod/Sketcher/Gui/CMakeLists.txt b/src/Mod/Sketcher/Gui/CMakeLists.txt index 33a71b2bca..f5a3d0dd37 100644 --- a/src/Mod/Sketcher/Gui/CMakeLists.txt +++ b/src/Mod/Sketcher/Gui/CMakeLists.txt @@ -154,6 +154,7 @@ SET(SketcherGui_SRCS SketcherRegularPolygonDialog.cpp SnapManager.cpp SnapManager.h + StyleParameters.h TaskDlgEditSketch.cpp TaskDlgEditSketch.h ViewProviderPython.cpp diff --git a/src/Mod/Sketcher/Gui/StyleParameters.h b/src/Mod/Sketcher/Gui/StyleParameters.h new file mode 100644 index 0000000000..4bc217cd52 --- /dev/null +++ b/src/Mod/Sketcher/Gui/StyleParameters.h @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/**************************************************************************** + * * + * Copyright (c) 2025 The FreeCAD Project Association AISBL * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ + +#ifndef SKETCHER_STYLEPARAMETERS_H +#define SKETCHER_STYLEPARAMETERS_H + +#include + +namespace SketcherGui::StyleParameters +{ +// rubberband selection colors +DEFINE_STYLE_PARAMETER( + SketcherRubberbandTouchSelectionColor, + Base::Color(0.0F, 1.0F, 0.0F, 1.0F)); // green for touch selection (right to left) +DEFINE_STYLE_PARAMETER( + SketcherRubberbandWindowSelectionColor, + Base::Color(0.0F, 0.4F, 1.0F, 1.0F)); // blue for window selection (left to right) +} // namespace SketcherGui::StyleParameters + +#endif // SKETCHER_STYLEPARAMETERS_H diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index f3e66b30d7..2441e8c8f3 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -45,6 +45,7 @@ #include #include +#include #include #include #include @@ -70,6 +71,7 @@ #include "EditDatumDialog.h" #include "EditModeCoinManager.h" #include "SnapManager.h" +#include "StyleParameters.h" #include "TaskDlgEditSketch.h" #include "TaskSketcherValidation.h" #include "Utils.h" @@ -1509,6 +1511,22 @@ bool ViewProviderSketch::mouseMove(const SbVec2s& cursorPos, Gui::View3DInventor // (#0003130) qreal dpr = viewer->getGLWidget()->devicePixelRatioF(); DoubleClick::newCursorPos = cursorPos; + + // depending on selection direction (touch selection (right to left) or window selection (left to right)) + // set the appropriate color and line style using theme design tokens + bool isRightToLeft = DoubleClick::prvCursorPos.getValue()[0] > DoubleClick::newCursorPos.getValue()[0]; + + auto* styleParameterManager = Base::provideService(); + + // try to get colors from theme tokens + auto touchColorValue = styleParameterManager->resolve(StyleParameters::SketcherRubberbandTouchSelectionColor).asValue(); + auto windowColorValue = styleParameterManager->resolve(StyleParameters::SketcherRubberbandWindowSelectionColor).asValue(); + + auto color = isRightToLeft ? touchColorValue : windowColorValue; + + rubberband->setColor(color.r, color.g, color.b, color.a); + rubberband->setLineStipple(isRightToLeft); // dashed for touch, solid for window + rubberband->setCoords( DoubleClick::prvCursorPos.getValue()[0], viewer->getGLWidget()->height() * dpr - DoubleClick::prvCursorPos.getValue()[1],