Skip to content

Commit

Permalink
MSEG more tweaks (#2890)
Browse files Browse the repository at this point in the history
Adjust MSEG curve deform/highlight colors
Add CNF tags for MSEG snaps
MSEG snap grid always draws, even if snap disabled
Dashed horizontal grid
Draw axes after grid
Flip Shift and Ctrl key modifiers for temporary snapping
  • Loading branch information
mkruselj authored Oct 17, 2020
1 parent 77d8f4f commit 2e3a66e
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 39 deletions.
2 changes: 2 additions & 0 deletions resources/data/skins/dark-mode.surge-skin/skin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@

<color id="msegeditor.background" value="#202020"/>
<color id="msegeditor.curve" value="modblue"/>
<color id="msegeditor.curve.deformed" value="#2E86FE80"/>
<color id="msegeditor.curve.highlight" value="#40ADFF"/>
<color id="msegeditor.panel" value="#2D2D2D"/>
<color id="msegeditor.panel.text" value="lightgray"/>
<color id="msegeditor.axis.text" value="lightgray"/>
Expand Down
9 changes: 5 additions & 4 deletions src/common/SkinColors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ namespace Colors
{
const Surge::Skin::Color Background("msegeditor.background", 17, 17, 17),
Curve("msegeditor.curve", 255, 255, 255),
DeformCurve("msegeditor.deformcurve", 120, 120, 120),
CurveUnderHighlight( "msegeditor.curve.highlight", 255, 90, 0, 128 ),
DeformCurve("msegeditor.curve.deformed", 128, 128, 128),
CurveHighlight("msegeditor.curve.highlight", 255, 144, 0),
Panel("msegeditor.panel", 205, 206, 212),
Text("msegeditor.panel.text", 0, 0, 0);

Expand All @@ -236,8 +236,9 @@ namespace Colors
}
namespace Grid
{
const Surge::Skin::Color Primary("msegeditor.grid.primary", 220, 220, 240),
Secondary("msegeditor.grid.secondary", 100, 100, 110);
const Surge::Skin::Color Primary("msegeditor.grid.primary", 255, 255, 255, 192),
SecondaryHorizontal("msegeditor.grid.secondary.horizontal", 255, 255, 255, 48),
SecondaryVertical("msegeditor.grid.secondary.vertical", 255, 255, 255, 96);
}
namespace Loop
{
Expand Down
4 changes: 2 additions & 2 deletions src/common/SkinColors.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace Colors

namespace MSEGEditor
{
extern const Surge::Skin::Color Background, Curve, DeformCurve, CurveUnderHighlight, Panel, Text;
extern const Surge::Skin::Color Background, Curve, DeformCurve, CurveHighlight, Panel, Text;

namespace Axis
{
Expand All @@ -176,7 +176,7 @@ namespace Colors
}
namespace Grid
{
extern const Surge::Skin::Color Primary, Secondary;
extern const Surge::Skin::Color Primary, SecondaryHorizontal, SecondaryVertical;
}
namespace Loop
{
Expand Down
2 changes: 2 additions & 0 deletions src/common/SurgeParamConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,6 @@ enum ctrl_mode
cm_noyes,
cm_temposync,
cm_int_menu,
cm_mseg_snap_h,
cm_mseg_snap_v,
};
23 changes: 17 additions & 6 deletions src/common/gui/CNumberField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ void CNumberField::setControlMode(int mode)
setIntMax(1);
setIntDefaultValue(0);
break;
case cm_mseg_snap_h:
case cm_mseg_snap_v:
setIntMin(1);
setIntMax(100);
if (mode == cm_mseg_snap_h)
setIntDefaultValue(10);
else
setIntDefaultValue(4);
break;
default:
setFloatMin(0.f);
setFloatMax(1.f);
Expand All @@ -257,18 +266,20 @@ void CNumberField::setValue(float val)
//------------------------------------------------------------------------
void CNumberField::draw(CDrawContext* pContext)
{
auto colorName = skin->propertyValue(skinControl, "text_color", Colors::NumberField::Text.name );
auto hoverColorName = skin->propertyValue(skinControl, "text_color.hover", Colors::NumberField::TextHover.name );
auto colorName = Colors::NumberField::Text.name;
auto hoverColorName = Colors::NumberField::TextHover.name;

if (skinControl)
{
colorName = skin->propertyValue(skinControl, "text_color", Colors::NumberField::Text.name);
hoverColorName = skin->propertyValue(skinControl, "text_color.hover", Colors::NumberField::TextHover.name );
}

auto fontColor = kRedCColor;
if( hovered )
{
fontColor = skin->getColor(hoverColorName );
}
else
{
fontColor = skin->getColor(colorName );
}

// cache this of course
if( ! triedToLoadBg )
Expand Down
79 changes: 52 additions & 27 deletions src/common/gui/MSEGEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "DebugHelpers.h"
#include "SkinColors.h"
#include "basic_dsp.h" // for limit_range
#include "CNumberField.h"
#include "CScalableBitmap.h"
#include "SurgeBitmaps.h"
#include "CHSwitch2.h"
Expand Down Expand Up @@ -405,7 +406,7 @@ struct MSEGCanvas : public CControl, public Surge::UI::SkinConsumingComponent {
inline void drawAxis( CDrawContext *dc ) {
auto haxisArea = getHAxisArea();
float maxt = drawDuration();
int skips = (ms->hSnap > 0 ? 1/ms->hSnap : 4 );
int skips = 1.f / ms->hSnapDefault;
auto tpx = timeToPx();

dc->setFont( displayFont );
Expand Down Expand Up @@ -434,7 +435,7 @@ struct MSEGCanvas : public CControl, public Surge::UI::SkinConsumingComponent {
dc->setFrameColor(skin->getColor(Colors::MSEGEditor::Axis::Line));
dc->drawLine( vaxisArea.getTopRight(), vaxisArea.getBottomRight() );
auto valpx = valToPx();
float step = (ms->vSnap > 0 ? ms->vSnap : 0.25 );
float step = ms->vSnapDefault;
for( float i=-1; i<=1.001 /* for things like "3" rounding*/; i += step )
{
float p = valpx( i );
Expand Down Expand Up @@ -539,53 +540,60 @@ struct MSEGCanvas : public CControl, public Surge::UI::SkinConsumingComponent {
dc->fillLinearGradient(fillpath, *cg, CPoint(0, 0), CPoint(0, valpx(-1)), false, &tfpath);
fillpath->forget();
cg->forget();

// Draw the axis here after the gradient fill
drawAxis(dc);

// draw horizontal grid
dc->setLineWidth(1);
int skips = (ms->hSnap > 0 ? 1.f / ms->hSnap : 4 );

// draw vertical grid
auto primaryGridColor = skin->getColor(Colors::MSEGEditor::Grid::Primary);
auto secondaryGridColor = skin->getColor(Colors::MSEGEditor::Grid::Secondary);
auto secondaryHGridColor = skin->getColor(Colors::MSEGEditor::Grid::SecondaryHorizontal);
auto secondaryVGridColor = skin->getColor(Colors::MSEGEditor::Grid::SecondaryVertical);

int skips = 1.f / ms->hSnapDefault;
for( int gi = 0; gi < maxt * skips + 1; ++gi )
{
float t = 1.0f * gi / skips;
float px = tpx( t );
if( gi % skips == 0 )
dc->setFrameColor( primaryGridColor );
else
dc->setFrameColor( secondaryGridColor );
dc->setFrameColor(secondaryVGridColor);
dc->drawLine( CPoint( px, drawArea.top ), CPoint( px, drawArea.bottom ) );
// std::cout << _D(t) << _D(px) << _D(pxt(px)) << std::endl;
}

skips = (ms->vSnap > 0 ? 1.f / ms->vSnap : 4 );
// draw vertical grid
// draw horizontal grid
skips = 1.f / ms->vSnapDefault;
for( int vi = 0; vi < 2 * skips + 1; vi ++ )
{
float v = valpx( 1.f * vi / skips - 1 );
if( vi % skips == 0 )
{
dc->setFrameColor( primaryGridColor );
dc->setLineStyle(kLineSolid);
}
else
dc->setFrameColor( secondaryGridColor );
{
dc->setFrameColor(secondaryHGridColor);
CCoord dashes[] = {2, 5};
dc->setLineStyle(CLineStyle(CLineStyle::kLineCapButt, CLineStyle::kLineJoinMiter, 0, 2, dashes));
}
dc->drawLine( CPoint( drawArea.left, v ), CPoint( drawArea.right, v ) );
}

// draw segment curve
dc->setLineWidth( 1.0 );
dc->setFrameColor( skin->getColor( Colors::MSEGEditor::DeformCurve));
dc->drawGraphicsPath( defpath, VSTGUI::CDrawContext::PathDrawMode::kPathStroked, &tfpath );
// Draw the axes here after the gradient fill and gridlines
drawAxis(dc);

dc->setLineWidth( 6 );
dc->setFrameColor(skin->getColor( Colors::MSEGEditor::CurveUnderHighlight) );
dc->drawGraphicsPath( highlightPath, VSTGUI::CDrawContext::PathDrawMode::kPathStroked, &tfpath );
// draw segment curve
dc->setLineWidth(1.0);
dc->setFrameColor(skin->getColor( Colors::MSEGEditor::DeformCurve));
dc->drawGraphicsPath(defpath, VSTGUI::CDrawContext::PathDrawMode::kPathStroked, &tfpath);

dc->setLineWidth(1.5);
dc->setFrameColor(skin->getColor(Colors::MSEGEditor::Curve));
dc->drawGraphicsPath( path, VSTGUI::CDrawContext::PathDrawMode::kPathStroked, &tfpath );
dc->drawGraphicsPath(path, VSTGUI::CDrawContext::PathDrawMode::kPathStroked, &tfpath);

//dc->setLineWidth(3.0);
dc->setFrameColor(skin->getColor( Colors::MSEGEditor::CurveHighlight) );
dc->drawGraphicsPath(highlightPath, VSTGUI::CDrawContext::PathDrawMode::kPathStroked, &tfpath);

path->forget();
defpath->forget();
Expand Down Expand Up @@ -703,8 +711,8 @@ struct MSEGCanvas : public CControl, public Surge::UI::SkinConsumingComponent {
/*
* Activate temporary snap
*/
bool s = buttons & kShift;
bool c = buttons & kControl;
bool c = buttons & kShift;
bool s = buttons & kControl;
if( s || c )
{
snapGuard = std::make_shared<SnapGuard>(ms, this);
Expand Down Expand Up @@ -983,6 +991,7 @@ void MSEGControlRegion::valueChanged( CControl *p )
{
// FIXME locales
auto fv = 1.f / (std::max( std::atoi( ((CTextEdit *)p)->getText() ), 1 ) ); // -1 to 1 remeber
//auto fv = 1.f / p->getValue(); // for CNF
ms->vSnapDefault = fv;
if( ms->vSnap > 0 )
ms->vSnap = ms->vSnapDefault;
Expand All @@ -991,7 +1000,8 @@ void MSEGControlRegion::valueChanged( CControl *p )
break;
case tag_horizontal_value:
{
auto fv = 1.f / ( std::max( std::atoi(((CTextEdit *)p)->getText()), 1 ) );
auto fv = 1.f / (std::max( std::atoi( ((CTextEdit *)p)->getText() ), 1 ) ); // -1 to 1 remeber
//auto fv = 1.f / p->getValue(); // for CNF
ms->hSnapDefault = fv;
if( ms->hSnap > 0 )
ms->hSnap = ms->hSnapDefault;
Expand Down Expand Up @@ -1091,8 +1101,14 @@ void MSEGControlRegion::rebuild()
hbut->setValue(ms->hSnap < 0.001 ? 0 : 1);

snprintf(svt, 255, "%d", (int)round(1.f / ms->hSnapDefault));
auto htxt = new CTextEdit(CRect(CPoint(xpos + 52 + margin, ypos), CPoint(editWidth, controlHeight)),
this, tag_horizontal_value, svt);

auto hsrect = CRect(CPoint(xpos + 52 + margin, ypos), CPoint(editWidth, controlHeight));
auto htxt = new CTextEdit(hsrect, this, tag_horizontal_value, svt);
//auto* htxt = new CNumberField(hsrect, this, tag_horizontal_value, nullptr /*, ref to storage?*/);
//htxt->setControlMode(cm_mseg_snap_h);
//htxt->setSkin(skin, associatedBitmapStore);
//htxt->setMouseableArea(hsrect);

#if WINDOWS
htxt->setTextInset(CPoint(3, 1));
#endif
Expand All @@ -1101,6 +1117,7 @@ void MSEGControlRegion::rebuild()
htxt->setFrameColor(skin->getColor(Colors::MSEGEditor::NumberField::Border));
htxt->setBackColor(skin->getColor(Colors::MSEGEditor::NumberField::Background));
htxt->setRoundRectRadius(CCoord(3.f));

addView(htxt);

xpos += segWidth;
Expand All @@ -1112,7 +1129,14 @@ void MSEGControlRegion::rebuild()
vbut->setValue( ms->vSnap < 0.001? 0 : 1 );

snprintf(svt, 255, "%d", (int)round( 1.f / ms->vSnapDefault));
auto vtxt = new CTextEdit(CRect(CPoint(xpos + 52 + margin , ypos), CPoint(editWidth, controlHeight)), this, tag_vertical_value, svt);

auto vsrect = CRect(CPoint(xpos + 52 + margin, ypos), CPoint(editWidth, controlHeight));
auto vtxt = new CTextEdit(vsrect, this, tag_vertical_value, svt);
// auto* vtxt = new CNumberField(vsrect, this, tag_vertical_value, nullptr /*, ref to storage?*/);
// vtxt->setControlMode(cm_mseg_snap_h);
// vtxt->setSkin(skin, associatedBitmapStore);
// vtxt->setMouseableArea(vsrect);

#if WINDOWS
vtxt->setTextInset(CPoint(3, 1));
#endif
Expand All @@ -1121,6 +1145,7 @@ void MSEGControlRegion::rebuild()
vtxt->setFrameColor(skin->getColor(Colors::MSEGEditor::NumberField::Border));
vtxt->setBackColor(skin->getColor(Colors::MSEGEditor::NumberField::Background));
vtxt->setRoundRectRadius(CCoord(3.f));

addView(vtxt);
}
}
Expand Down

0 comments on commit 2e3a66e

Please sign in to comment.