Gui: Add ability to set coordinate system axis letter color

Fixes: #12172
This commit is contained in:
Kacper Donat
2024-01-28 17:55:56 +01:00
committed by Adrián Insaurralde Avalos
parent 913a5dd60f
commit e40131d4b8
6 changed files with 103 additions and 18 deletions

View File

@@ -16,8 +16,8 @@ namespace Gui {
#define XPM_WIDTH (21)
#define XPM_HEIGHT (27)
#define XPM_BYTES_PER_PIXEL (4) /* 2:RGB16, 3:RGB, 4:RGBA */
#define XPM_PIXEL_DATA ((unsigned char*) XPM_pixel_data)
static const unsigned char XPM_pixel_data[21 * 27 * 4 + 1] =
#define XPM_PIXEL_MASK ((unsigned char*) ::XPM_pixel_mask)
static const unsigned char XPM_pixel_mask[21 * 27 * 4 + 1] =
("\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
@@ -89,8 +89,8 @@ static const unsigned char XPM_pixel_data[21 * 27 * 4 + 1] =
#define YPM_WIDTH (21)
#define YPM_HEIGHT (27)
#define YPM_BYTES_PER_PIXEL (4) /* 2:RGB16, 3:RGB, 4:RGBA */
#define YPM_PIXEL_DATA ((unsigned char*) YPM_pixel_data)
static const unsigned char YPM_pixel_data[21 * 27 * 4 + 1] =
#define YPM_PIXEL_MASK ((unsigned char*) ::YPM_pixel_mask)
static const unsigned char YPM_pixel_mask[21 * 27 * 4 + 1] =
("\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
@@ -161,8 +161,8 @@ static const unsigned char YPM_pixel_data[21 * 27 * 4 + 1] =
#define ZPM_WIDTH (21)
#define ZPM_HEIGHT (27)
#define ZPM_BYTES_PER_PIXEL (4) /* 2:RGB16, 3:RGB, 4:RGBA */
#define ZPM_PIXEL_DATA ((unsigned char*) ZPM_pixel_data)
static const unsigned char ZPM_pixel_data[21 * 27 * 4 + 1] =
#define ZPM_PIXEL_MASK ((unsigned char*) ::ZPM_pixel_mask)
static const unsigned char ZPM_pixel_mask[21 * 27 * 4 + 1] =
("\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"

View File

@@ -24,8 +24,8 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayoutCoord">
<item>
<layout class="QGridLayout" name="gridLayoutCoord">
<item row="0" column="0">
<widget class="Gui::PrefCheckBox" name="CheckBox_CornerCoordSystem">
<property name="toolTip">
<string>Main coordinate system will always be shown in
@@ -45,7 +45,7 @@ lower right corner within opened files</string>
</property>
</widget>
</item>
<item>
<item row="0" column="1">
<spacer name="horizontalSpacerCoord">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -57,7 +57,7 @@ lower right corner within opened files</string>
</property>
</spacer>
</item>
<item>
<item row="0" column="2">
<widget class="QLabel" name="labelCoordSize">
<property name="text">
<string>Relative size : </string>
@@ -67,7 +67,7 @@ lower right corner within opened files</string>
</property>
</widget>
</item>
<item>
<item row="0" column="3">
<widget class="Gui::PrefSpinBox" name="SpinBox_CornerCoordSystemSize">
<property name="toolTip">
<string>Size of main coordinate system representation
@@ -93,6 +93,33 @@ in the corner -- in % of height/width of viewport</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="axisLetterColorLabel">
<property name="text">
<string>Letter color:</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="Gui::PrefColorButton" name="axisLetterColor">
<property name="toolTip">
<string>Axis letter color</string>
</property>
<property name="color" stdset="0">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>AxisLetterColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -542,7 +569,7 @@ bounding box size of the 3D object that is currently displayed.</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="0" column="1">
<widget class="Gui::PrefRadioButton" name="radioOrthographic">
<property name="toolTip">
<string>Objects will be projected in orthographic projection</string>
@@ -561,7 +588,7 @@ bounding box size of the 3D object that is currently displayed.</string>
</property>
</widget>
</item>
</layout>
</layout>
</widget>
</item>
<item>
@@ -678,5 +705,11 @@ bounding box size of the 3D object that is currently displayed.</string>
<receiver>SpinBox_CornerCoordSystemSize</receiver>
<slot>setEnabled(bool)</slot>
</connection>
<connection>
<sender>CheckBox_CornerCoordSystem</sender>
<signal>toggled(bool)</signal>
<receiver>axisLetterColor</receiver>
<slot>setEnabled(bool)</slot>
</connection>
</connections>
</ui>

View File

@@ -85,6 +85,7 @@ void DlgSettings3DViewImp::saveSettings()
ui->FloatSpinBox_EyeDistance->onSave();
ui->checkBoxBacklight->onSave();
ui->backlightColor->onSave();
ui->axisLetterColor->onSave();
ui->sliderIntensity->onSave();
ui->radioPerspective->onSave();
ui->radioOrthographic->onSave();
@@ -101,6 +102,7 @@ void DlgSettings3DViewImp::loadSettings()
ui->FloatSpinBox_EyeDistance->onRestore();
ui->checkBoxBacklight->onRestore();
ui->backlightColor->onRestore();
ui->axisLetterColor->onRestore();
ui->sliderIntensity->onRestore();
ui->radioPerspective->onRestore();
ui->radioOrthographic->onRestore();

View File

@@ -92,7 +92,6 @@
#include "View3DInventorViewer.h"
#include "Application.h"
#include "CornerCrossLetters.h"
#include "Document.h"
#include "GLPainter.h"
#include "MainWindow.h"
@@ -3427,6 +3426,40 @@ void View3DInventorViewer::setViewing(bool enable)
inherited::setViewing(enable);
}
unsigned char View3DInventorViewer::XPM_pixel_data[XPM_WIDTH * XPM_HEIGHT * XPM_BYTES_PER_PIXEL + 1] = {};
unsigned char View3DInventorViewer::YPM_pixel_data[YPM_WIDTH * YPM_HEIGHT * YPM_BYTES_PER_PIXEL + 1] = {};
unsigned char View3DInventorViewer::ZPM_pixel_data[ZPM_WIDTH * ZPM_HEIGHT * ZPM_BYTES_PER_PIXEL + 1] = {};
void View3DInventorViewer::setAxisLetterColor(const SbColor& color)
{
unsigned packed = color.getPackedValue();
auto recolor =
[&](const unsigned char* mask,
unsigned char* data,
unsigned width,
unsigned height,
unsigned bitdepth) {
for (unsigned y = 0; y < height; y++) {
for (unsigned x = 0; x < width; x++) {
unsigned offset = (y * width + x) * bitdepth;
const unsigned char* src = &mask[offset];
unsigned char* dst = &data[offset];
dst[0] = (packed >> 24) & 0xFF; // RR - from color
dst[1] = (packed >> 16) & 0xFF; // GG - from color
dst[2] = (packed >> 8) & 0xFF; // BB - from color
dst[3] = src[3]; // AA - from mask
}
}
};
recolor(XPM_PIXEL_MASK, XPM_pixel_data, XPM_WIDTH, XPM_HEIGHT, XPM_BYTES_PER_PIXEL);
recolor(YPM_PIXEL_MASK, YPM_pixel_data, YPM_WIDTH, YPM_HEIGHT, YPM_BYTES_PER_PIXEL);
recolor(ZPM_PIXEL_MASK, ZPM_pixel_data, ZPM_WIDTH, ZPM_HEIGHT, ZPM_BYTES_PER_PIXEL);
}
void View3DInventorViewer::drawAxisCross()
{
// NOLINTBEGIN
@@ -3584,11 +3617,11 @@ void View3DInventorViewer::drawAxisCross()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPixelZoom((float)axiscrossSize / 30, (float)axiscrossSize / 30); // 30 = 3 (character pixmap ratio) * 10 (default axiscrossSize)
glRasterPos2d(xpos[0], xpos[1]);
glDrawPixels(XPM_WIDTH, XPM_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, XPM_PIXEL_DATA);
glDrawPixels(XPM_WIDTH, XPM_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, XPM_pixel_data);
glRasterPos2d(ypos[0], ypos[1]);
glDrawPixels(YPM_WIDTH, YPM_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, YPM_PIXEL_DATA);
glDrawPixels(YPM_WIDTH, YPM_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, YPM_pixel_data);
glRasterPos2d(zpos[0], zpos[1]);
glDrawPixels(ZPM_WIDTH, ZPM_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, ZPM_PIXEL_DATA);
glDrawPixels(ZPM_WIDTH, ZPM_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, ZPM_pixel_data);
glPixelStorei(GL_UNPACK_ALIGNMENT, unpack);
glPopMatrix();

View File

@@ -41,6 +41,8 @@
#include "Namespace.h"
#include "Selection.h"
#include "CornerCrossLetters.h"
#include "View3DInventorSelection.h"
#include "Quarter/SoQTQuarterAdaptor.h"
@@ -414,6 +416,7 @@ public:
const SbColor& midColor);
void setNavigationType(Base::Type);
void setAxisLetterColor(const SbColor& color);
void setAxisCross(bool on);
bool hasAxisCross();
@@ -536,7 +539,11 @@ private:
ViewerEventFilter* viewerEventFilter;
PyObject *_viewerPy;
PyObject* _viewerPy;
static unsigned char XPM_pixel_data[YPM_WIDTH * YPM_HEIGHT * YPM_BYTES_PER_PIXEL + 1];
static unsigned char YPM_pixel_data[YPM_WIDTH * YPM_HEIGHT * YPM_BYTES_PER_PIXEL + 1];
static unsigned char ZPM_pixel_data[ZPM_WIDTH * ZPM_HEIGHT * ZPM_BYTES_PER_PIXEL + 1];
// friends
friend class NavigationStyle;

View File

@@ -73,6 +73,7 @@ void View3DSettings::applySettings()
OnChange(*hGrp,"EyeDistance");
OnChange(*hGrp,"CornerCoordSystem");
OnChange(*hGrp,"CornerCoordSystemSize");
OnChange(*hGrp,"AxisLetterColor");
OnChange(*hGrp,"ShowAxisCross");
OnChange(*hGrp,"UseNavigationAnimations");
OnChange(*hGrp,"UseSpinningAnimations");
@@ -290,6 +291,15 @@ void View3DSettings::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M
_viewer->setFeedbackSize(rGrp.GetInt("CornerCoordSystemSize", 10));
}
}
else if (strcmp(Reason,"AxisLetterColor") == 0) {
unsigned long backlight = rGrp.GetUnsigned("AxisLetterColor", 0x00000000); // default color (black)
float transparency;
SbColor color;
color.setPackedValue((uint32_t)backlight, transparency);
for (auto _viewer : _viewers) {
_viewer->setAxisLetterColor(color);
}
}
else if (strcmp(Reason,"ShowAxisCross") == 0) {
for (auto _viewer : _viewers) {
_viewer->setAxisCross(rGrp.GetBool("ShowAxisCross", false));