Skip to content

Commit

Permalink
Add shift key behavior to Texture Coord editor for move/rotate/scale
Browse files Browse the repository at this point in the history
The main 3D view has alternate behavior for select, move, rotate,
and scale tools when shift key is held. The Texture Coord editor
only had it for select. Add alternate behavior for Texture Coord
move/rotate/scale when the shift key is held. It should be the
same as the main 3D view.
  • Loading branch information
zturtleman committed Apr 24, 2019
1 parent 65449c9 commit 99df34f
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 3 deletions.
8 changes: 5 additions & 3 deletions doc/html/olh_texturecoordwin.htm
Expand Up @@ -64,11 +64,13 @@ <h1>Texture Coordinates Window</h1>
the right mouse button. You can hold the shift key to make your selection
cumulative.</li>
<li>The <b>Move</b> button allows you
to move selected vertices.</li>
to move selected vertices. You can hold the shift key to only move in one dimension.</li>
<li>The <b>Rotate</b> button allows you
to rotate selected vertices.</li>
to rotate selected vertices. Right click sets the rotation point.
You can hold the shift key to rotate selected vertices in 15 degree increments.</li>
<li>The <b>Scale</b> button allows you
to scale the distance between selected vertices. Using the
to scale the distance between selected vertices. You can hold
the shift key to only scale in one dimension. Using the
<b>Scale Options</b> frame you can control whether you scale
from the center of the selected vertices or the far corner
and whether or not the 2D aspect ratio of the selection is
Expand Down
112 changes: 112 additions & 0 deletions src/depui/texwidget.cc
Expand Up @@ -894,6 +894,23 @@ int TextureWidget::addTriangle( int v1, int v2, int v3 )
return -1;
}

double TextureWidget::adjustToNearest( double angle )
{
double f = angle / PIOVER180; // Change to degrees
if ( f < 0.0 )
{
int n = (int) (f / 15.0 - 0.5);
f = n * 15.0;
}
else
{
int n = (int) (f / 15.0 + 0.5);
f = n * 15.0;
}
log_debug( "nearest angle is %f\n", f );
return f * PIOVER180;
}

void TextureWidget::mousePressEvent( QMouseEvent * e )
{
if ( m_interactive )
Expand Down Expand Up @@ -976,8 +993,12 @@ void TextureWidget::mousePressEvent( QMouseEvent * e )
m_drawBounding = true;
break;
case MouseMove:
m_allowX = true;
m_allowY = true;
break;
case MouseScale:
m_allowX = true;
m_allowY = true;
startScale(
(m_lastXPos / (double) this->width()) * (m_xMax - m_xMin) + m_xMin ,
(1.0 - (m_lastYPos / (double) this->height())) * (m_yMax - m_yMin) + m_yMin );
Expand Down Expand Up @@ -1023,6 +1044,11 @@ void TextureWidget::mousePressEvent( QMouseEvent * e )
}
}

if ( e->modifiers() & Qt::ShiftModifier )
{
angle = adjustToNearest( angle );
}

m_startAngle = angle;
}

Expand Down Expand Up @@ -1094,6 +1120,33 @@ void TextureWidget::mouseReleaseEvent( QMouseEvent * e )
emit updateSelectionDoneSignal();
break;
case MouseMove:
if ( e->modifiers() & Qt::ShiftModifier )
{
if ( m_allowX && m_allowY )
{
double ax = fabs( x - m_lastXPos );
double ay = fabs( y - m_lastYPos );

if ( ax > ay )
{
m_allowY = false;
}
if ( ay > ax )
{
m_allowX = false;
}
}
}

if ( !m_allowX )
{
x = m_lastXPos;
}
if ( !m_allowY )
{
y = m_lastYPos;
}

moveSelectedVertices(
((x - m_lastXPos) / (double) this->width()) * (m_xMax - m_xMin),
(-(y - m_lastYPos) / (double) this->height()) * (m_yMax - m_yMin) );
Expand Down Expand Up @@ -1187,6 +1240,33 @@ void TextureWidget::mouseMoveEvent( QMouseEvent * e )
(1.0 - (y / (double) this->height())) * m_zoom + m_yMin );
break;
case MouseMove:
if ( e->modifiers() & Qt::ShiftModifier )
{
if ( m_allowX && m_allowY )
{
double ax = fabs( x - m_lastXPos );
double ay = fabs( y - m_lastYPos );

if ( ax > ay )
{
m_allowY = false;
}
if ( ay > ax )
{
m_allowX = false;
}
}
}

if ( !m_allowX )
{
x = m_lastXPos;
}
if ( !m_allowY )
{
y = m_lastYPos;
}

moveSelectedVertices(
((x - m_lastXPos) / (double) this->width()) * m_zoom,
(-(y - m_lastYPos) / (double) this->height()) * m_zoom);
Expand Down Expand Up @@ -1226,12 +1306,44 @@ void TextureWidget::mouseMoveEvent( QMouseEvent * e )
}
}

if ( e->modifiers() & Qt::ShiftModifier )
{
angle = adjustToNearest( angle );
}

rotateSelectedVertices( angle - m_startAngle );

emit updateCoordinatesSignal();
}
break;
case MouseScale:
if ( e->modifiers() & Qt::ShiftModifier )
{
if ( m_allowX && m_allowY )
{
double ax = fabs( x - m_lastXPos );
double ay = fabs( y - m_lastYPos );

if ( ax > ay )
{
m_allowY = false;
}
if ( ay > ax )
{
m_allowX = false;
}
}
}

if ( !m_allowX )
{
x = m_lastXPos;
}
if ( !m_allowY )
{
y = m_lastYPos;
}

scaleSelectedVertices(
(x / (double) this->width()) * m_zoom + m_xMin,
(1.0 - (y / (double) this->height())) * m_zoom + m_yMin );
Expand Down
6 changes: 6 additions & 0 deletions src/depui/texwidget.h
Expand Up @@ -226,6 +226,8 @@ class TextureWidget : public QGLWidget
double distance( const double &, const double &, const double &, const double & );
double max( const double &, const double & );

double adjustToNearest( double angle );

void useLinesColor();
void useSelectionColor();

Expand Down Expand Up @@ -282,6 +284,10 @@ class TextureWidget : public QGLWidget
double m_yMin;
double m_yMax;

// For move and scale
bool m_allowX;
bool m_allowY;

// For select
double m_xSel1;
double m_ySel1;
Expand Down

0 comments on commit 99df34f

Please sign in to comment.