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>
This commit is contained in:
tetektoza
2025-08-31 21:36:24 +02:00
committed by GitHub
parent f502aad3b8
commit 7b85239093
3 changed files with 59 additions and 0 deletions

View File

@@ -154,6 +154,7 @@ SET(SketcherGui_SRCS
SketcherRegularPolygonDialog.cpp
SnapManager.cpp
SnapManager.h
StyleParameters.h
TaskDlgEditSketch.cpp
TaskDlgEditSketch.h
ViewProviderPython.cpp

View File

@@ -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 *
* <https://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#ifndef SKETCHER_STYLEPARAMETERS_H
#define SKETCHER_STYLEPARAMETERS_H
#include <Gui/StyleParameters/ParameterManager.h>
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

View File

@@ -45,6 +45,7 @@
#include <fmt/format.h>
#include <Base/Console.h>
#include <Base/ServiceProvider.h>
#include <Base/Vector3D.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
@@ -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<Gui::StyleParameters::ParameterManager>();
// try to get colors from theme tokens
auto touchColorValue = styleParameterManager->resolve(StyleParameters::SketcherRubberbandTouchSelectionColor).asValue<Base::Color>();
auto windowColorValue = styleParameterManager->resolve(StyleParameters::SketcherRubberbandWindowSelectionColor).asValue<Base::Color>();
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],