Skip to content

Commit

Permalink
NaviCube - tweaks and new parameters
Browse files Browse the repository at this point in the history
By default navigation cube text now has more weight and CS axes are slightly shifted. A few additional parameters have been added, for being able to customize navigation cube offset, colors, font and visibility of CS. Parameters are consolidated under NaviCube group. Customization front-end, making use of this new parameters, will be added to CubeMenu module in the following days:

https://forum.freecadweb.org/viewtopic.php?f=34&t=43338
  • Loading branch information
triplus authored and yorikvanhavre committed Mar 24, 2020
1 parent 0a1312e commit 2241d0d
Showing 1 changed file with 98 additions and 61 deletions.
159 changes: 98 additions & 61 deletions src/Gui/NaviCube.cpp
Expand Up @@ -245,6 +245,7 @@ class NaviCubeImplementation {
int m_CubeWidgetPosY = 0;
int m_PrevWidth = 0;
int m_PrevHeight = 0;
QColor m_TextColor;
QColor m_HiliteColor;
QColor m_ButtonColor;
QColor m_FrontFaceColor;
Expand Down Expand Up @@ -275,7 +276,6 @@ class NaviCubeImplementation {

NaviCube::NaviCube(Gui::View3DInventorViewer* viewer) {
m_NaviCubeImplementation = new NaviCubeImplementation(viewer);

}

NaviCube::~NaviCube() {
Expand Down Expand Up @@ -305,17 +305,37 @@ void NaviCube::setCorner(Corner c) {
}

NaviCubeImplementation::NaviCubeImplementation(
Gui::View3DInventorViewer* viewer) {
Gui::View3DInventorViewer* viewer) {
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/NaviCube");
m_View3DInventorViewer = viewer;

m_TextColor = QColor(0,0,0,255);
if (hGrp->GetUnsigned("TextColor")) {
m_TextColor.setRgba(hGrp->GetUnsigned("TextColor"));
}

m_FrontFaceColor = QColor(255,255,255,128);
if (hGrp->GetUnsigned("FrontColor")) {
m_FrontFaceColor.setRgba(hGrp->GetUnsigned("FrontColor"));
}

m_BackFaceColor = QColor(226,233,239,128);
m_HiliteColor = QColor(170,226,247);
m_ButtonColor = QColor(226,233,239,128);
m_PickingFramebuffer = NULL;
if (hGrp->GetUnsigned("BackColor")) {
m_BackFaceColor.setRgba(hGrp->GetUnsigned("BackColor"));
}

m_HiliteColor = QColor(170,226,255);
if (hGrp->GetUnsigned("HiliteColor")) {
m_HiliteColor.setRgba(hGrp->GetUnsigned("HiliteColor"));
}

m_CubeWidgetSize = (App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("View")->GetInt("NaviWidgetSize", 132));
m_ButtonColor = QColor(226,233,239,128);
if (hGrp->GetUnsigned("ButtonColor")) {
m_ButtonColor.setRgba(hGrp->GetUnsigned("ButtonColor"));
}

m_PickingFramebuffer = NULL;
m_CubeWidgetSize = (hGrp->GetInt("CubeSize", 132));
m_Menu = createNaviCubeMenu();
}

Expand Down Expand Up @@ -372,10 +392,25 @@ GLuint NaviCubeImplementation::createCubeFaceTex(QtGLWidget* gl, float gap, floa
paint.begin(&image);

if (text) {
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/NaviCube");
paint.setPen(Qt::white);
QFont sansFont(str("Helvetica"), 0.18 * texSize);
sansFont.setStretch(App::GetApplication().GetUserParameter().GetGroup("BaseApp")
->GetGroup("Preferences")->GetGroup("View")->GetInt("NaviFontStretch", 62));
QString fontString = QString::fromUtf8((hGrp->GetASCII("FontString")).c_str());
if (fontString.isEmpty()) {
// Improving readability
sansFont.setWeight(hGrp->GetInt("FontWeight", 87));
sansFont.setStretch(hGrp->GetInt("FontStretch", 62));
}
else {
sansFont.fromString(fontString);
}
// Override fromString
if (hGrp->GetInt("FontWeight") > 0) {
sansFont.setWeight(hGrp->GetInt("FontWeight"));
}
if (hGrp->GetInt("FontStretch") > 0) {
sansFont.setStretch(hGrp->GetInt("FontStretch"));
}
paint.setFont(sansFont);
paint.drawText(QRect(0, 0, texSize, texSize), Qt::AlignCenter,qApp->translate("Gui::NaviCube",text));
}
Expand Down Expand Up @@ -616,7 +651,7 @@ void NaviCubeImplementation::addFace(const Vector3f& x, const Vector3f& z, int f
m_Textures[frontTex],
pickId,
m_Textures[pickTex],
Qt::black,
m_TextColor,
2);
m_Faces.push_back(ft);

Expand Down Expand Up @@ -680,18 +715,13 @@ void NaviCubeImplementation::initNaviCube(QtGLWidget* gl) {

if (labels.size() != 6) {
labels.clear();
labels.push_back(App::GetApplication().GetUserParameter().GetGroup("BaseApp")
->GetGroup("Preferences")->GetGroup("View")->GetASCII("NaviTextFront", "FRONT"));
labels.push_back(App::GetApplication().GetUserParameter().GetGroup("BaseApp")
->GetGroup("Preferences")->GetGroup("View")->GetASCII("NaviTextRear", "REAR"));
labels.push_back(App::GetApplication().GetUserParameter().GetGroup("BaseApp")
->GetGroup("Preferences")->GetGroup("View")->GetASCII("NaviTextTop", "TOP"));
labels.push_back(App::GetApplication().GetUserParameter().GetGroup("BaseApp")
->GetGroup("Preferences")->GetGroup("View")->GetASCII("NaviTextBottom", "BOTTOM"));
labels.push_back(App::GetApplication().GetUserParameter().GetGroup("BaseApp")
->GetGroup("Preferences")->GetGroup("View")->GetASCII("NaviTextRight", "RIGHT"));
labels.push_back(App::GetApplication().GetUserParameter().GetGroup("BaseApp")
->GetGroup("Preferences")->GetGroup("View")->GetASCII("NaviTextLeft", "LEFT"));
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/NaviCube");
labels.push_back(hGrp->GetASCII("TextFront", "FRONT"));
labels.push_back(hGrp->GetASCII("TextRear", "REAR"));
labels.push_back(hGrp->GetASCII("TextTop", "TOP"));
labels.push_back(hGrp->GetASCII("TextBottom", "BOTTOM"));
labels.push_back(hGrp->GetASCII("TextRight", "RIGHT"));
labels.push_back(hGrp->GetASCII("TextLeft", "LEFT"));
}

float gap = 0.12f;
Expand Down Expand Up @@ -801,27 +831,30 @@ void NaviCubeImplementation::handleResize() {
if ((m_PrevWidth > 0) && (m_PrevHeight > 0)) {
// maintain position relative to closest edge
if (m_CubeWidgetPosX > m_PrevWidth / 2)
m_CubeWidgetPosX = view[0] - (m_PrevWidth -m_CubeWidgetPosX);
m_CubeWidgetPosX = view[0] - (m_PrevWidth - m_CubeWidgetPosX);
if (m_CubeWidgetPosY > m_PrevHeight / 2)
m_CubeWidgetPosY = view[1] - (m_PrevHeight - m_CubeWidgetPosY);
}
else { // initial position
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/NaviCube");
int m_CubeWidgetOffsetX = hGrp->GetInt("OffsetX", 0);
int m_CubeWidgetOffsetY = hGrp->GetInt("OffsetY", 0);
switch (m_Corner) {
case NaviCube::TopLeftCorner:
m_CubeWidgetPosX = m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosY = view[1] - m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosX = m_CubeWidgetSize*1.1 / 2 + m_CubeWidgetOffsetX;
m_CubeWidgetPosY = view[1] - m_CubeWidgetSize*1.1 / 2 - m_CubeWidgetOffsetY;
break;
case NaviCube::TopRightCorner:
m_CubeWidgetPosX = view[0] - m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosY = view[1] - m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosX = view[0] - m_CubeWidgetSize*1.1 / 2 - m_CubeWidgetOffsetX;
m_CubeWidgetPosY = view[1] - m_CubeWidgetSize*1.1 / 2 - m_CubeWidgetOffsetY;
break;
case NaviCube::BottomLeftCorner:
m_CubeWidgetPosX = m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosY = m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosX = m_CubeWidgetSize*1.1 / 2 + m_CubeWidgetOffsetX;
m_CubeWidgetPosY = m_CubeWidgetSize*1.1 / 2 + m_CubeWidgetOffsetY;
break;
case NaviCube::BottomRightCorner:
m_CubeWidgetPosX = view[0] - m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosY = m_CubeWidgetSize*1.1 / 2;
m_CubeWidgetPosX = view[0] - m_CubeWidgetSize*1.1 / 2 - m_CubeWidgetOffsetX;
m_CubeWidgetPosY = m_CubeWidgetSize*1.1 / 2 + m_CubeWidgetOffsetY;
break;
}
}
Expand Down Expand Up @@ -932,37 +965,41 @@ void NaviCubeImplementation::drawNaviCube(bool pickMode) {

if (!pickMode) {
// Draw the axes
glDisable(GL_TEXTURE_2D);
float a=1.1f;

static GLubyte xbmp[] = { 0x11,0x11,0x0a,0x04,0x0a,0x11,0x11 };
glColor3f(1, 0, 0);
glBegin(GL_LINES);
glVertex3f(-1 , -1, -1);
glVertex3f(+1 , -1, -1);
glEnd();
glRasterPos3d(a, -a, -a);
glBitmap(8, 7, 0, 0, 0, 0, xbmp);

static GLubyte ybmp[] = { 0x04,0x04,0x04,0x04,0x0a,0x11,0x11 };
glColor3f(0, 1, 0);
glBegin(GL_LINES);
glVertex3f(-1 , -1, -1);
glVertex3f(-1 , +1, -1);
glEnd();
glRasterPos3d( -a, a, -a);
glBitmap(8, 7, 0, 0, 0, 0, ybmp);

static GLubyte zbmp[] = { 0x1f,0x10,0x08,0x04,0x02,0x01,0x1f };
glColor3f(0, 0, 1);
glBegin(GL_LINES);
glVertex3f(-1 , -1, -1);
glVertex3f(-1 , -1, +1);
glEnd();
glRasterPos3d( -a, -a, a);
glBitmap(8, 7, 0, 0, 0, 0, zbmp);
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/NaviCube");
bool ShowCS = hGrp->GetBool("ShowCS", 1);
if (ShowCS) {
glDisable(GL_TEXTURE_2D);
float a=1.1f;

static GLubyte xbmp[] = { 0x11,0x11,0x0a,0x04,0x0a,0x11,0x11 };
glColor3f(1, 0, 0);
glBegin(GL_LINES);
glVertex3f(-1.1 , -1.1, -1.1);
glVertex3f(+0.5 , -1.1, -1.1);
glEnd();
glRasterPos3d(a, -a, -a);
glBitmap(8, 7, 0, 0, 0, 0, xbmp);

static GLubyte ybmp[] = { 0x04,0x04,0x04,0x04,0x0a,0x11,0x11 };
glColor3f(0, 1, 0);
glBegin(GL_LINES);
glVertex3f(-1.1 , -1.1, -1.1);
glVertex3f(-1.1 , +0.5, -1.1);
glEnd();
glRasterPos3d( -a, a, -a);
glBitmap(8, 7, 0, 0, 0, 0, ybmp);

static GLubyte zbmp[] = { 0x1f,0x10,0x08,0x04,0x02,0x01,0x1f };
glColor3f(0, 0, 1);
glBegin(GL_LINES);
glVertex3f(-1.1 , -1.1, -1.1);
glVertex3f(-1.1 , -1.1, +0.5);
glEnd();
glRasterPos3d( -a, -a, a);
glBitmap(8, 7, 0, 0, 0, 0, zbmp);

glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
}
}

// Draw the cube faces
Expand Down

0 comments on commit 2241d0d

Please sign in to comment.