Skip to content

Commit

Permalink
Begin implementation of HoverStates (#1757)
Browse files Browse the repository at this point in the history
Begin implementation of HoverStates. This change

1. Plubms through hover state API on the skin engine
2. Implements a default hover state
3. Makes CHSwitch2 an accurate client of that
4. Adds bad hover graphics for filter and waveshaper switches

Committing here so designers can start using this feature on the
switches while we code up other elements.

Addresses #1752
  • Loading branch information
baconpaul authored Apr 26, 2020
1 parent 6235667 commit 441bb00
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 45 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ It's what the primary Mac developers use day to day. The simplest approach is to
./build-osx.sh
```

`build-osx.sh` will give you better output if you first `gem install xcpretty`, the xcodebuild formatter,
and you have your gem environment running. If that doesn't work don't worry - you can still build.

this command will build, but not install, the VST3 and AU components. It has a variety of options which
are documented in the `./build-osx.sh --help` screen but a few key ones are:

Expand Down
19 changes: 17 additions & 2 deletions build-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ NC=`tput init`

prerequisite_check()
{

if [ ! -f vst3sdk/LICENSE.txt ]; then
echo
echo ${RED}ERROR: You have not gotten the submodules required to build Surge. Run the following command to get them.${NC}
Expand All @@ -100,10 +101,17 @@ prerequisite_check()
echo
echo ${RED}ERROR: You do not have cmake on your path${NC}
echo
echo Please install cmake. "brew install cmake" or visit https://cmake.org
echo Please install cmake. "brew install cmake" or visit https://cmake.org
echo
exit 1
fi

if [ ! $(which xcpretty) ]; then
echo
echo ${GREEN}You will get better output if you `brew install xcpretty`${NC}
echo
fi

}


Expand All @@ -124,7 +132,14 @@ run_cmake_build()
# Don't let TEE eat my return status
mkdir -p build
cmake -GXcode -Bbuild
xcodebuild build -configuration Release -project build/Surge.xcodeproj -target ${target}

if [ $(which xcpretty) ]; then
set -o pipefail && xcodebuild build -configuration Release -project build/Surge.xcodeproj -target ${target} | xcpretty
else
xcodebuild build -configuration Release -project build/Surge.xcodeproj -target ${target}
fi



build_suc=$?

Expand Down
23 changes: 23 additions & 0 deletions resources/data/skins/default.surge-skin/SVG/hover00108.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions resources/data/skins/default.surge-skin/SVG/hover00120.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/data/skins/default.surge-skin/skin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<surge-skin name="Surge Default Skin" author="Surge Synth Team" authorURL="https://surge-synth-team.org/">
<!-- This skin exists to make sure we can fall back on defaults with no assets and an empty XML. The defaults are built into the DLL -->
<globals>
<defaultimage directory="SVG/"/>
</globals>
<component-classes>
</component-classes>
Expand Down
43 changes: 43 additions & 0 deletions src/common/gui/CHSwitch2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//-------------------------------------------------------------------------------------------------------
#include "CHSwitch2.h"
#include <vt_dsp/basic_dsp.h>
#include "CScalableBitmap.h"

using namespace VSTGUI;

Expand All @@ -14,6 +15,20 @@ void CHSwitch2::draw(CDrawContext* dc)
CPoint where(0, heightOfOneImage *
(long)(imgoffset + ((value * (float)(rows * columns - 1) + 0.5f))));
getBackground()->draw(dc, getViewSize(), where, 0xff);

if( ! lookedForHover && skin.get() )
{
lookedForHover = true;
hoverBmp = skin->hoverBitmapOverlayForBackgroundBitmap( skinControl, dynamic_cast<CScalableBitmap*>( getBackground() ), associatedBitmapStore );
}

if( hoverBmp && doingHover )
{
CPoint hwhere(0, heightOfOneImage *
(long)(imgoffset + ((hoverValue * (float)(rows * columns - 1) + 0.5f))));

hoverBmp->draw(dc, getViewSize(), hwhere, 0xff);
}
}
setDirty(false);
}
Expand Down Expand Up @@ -105,6 +120,34 @@ CMouseEventResult CHSwitch2::onMouseMoved(CPoint& where, const CButtonState& but

return kMouseEventHandled;
}

if( doingHover )
{
auto mouseableArea = getMouseableArea();
double coefX, coefY;
coefX = (double)mouseableArea.getWidth() / (double)columns;
coefY = (double)mouseableArea.getHeight() / (double)rows;

int y = (int)((where.y - mouseableArea.top) / coefY);
int x = (int)((where.x - mouseableArea.left) / coefX);

x = limit_range(x, 0, columns - 1);
y = limit_range(y, 0, rows - 1);

if (columns * rows > 1)
{
float nhoverValue = (float)(x + y * columns) / (float)(columns * rows - 1);

nhoverValue = limit_range( nhoverValue, 0.f, 1.f );

if( nhoverValue != hoverValue )
{
hoverValue = nhoverValue;
invalid();
}
}
}

return kMouseEventNotHandled;
}
bool CHSwitch2::onWheel(const CPoint& where, const float& distance, const CButtonState& buttons)
Expand Down
11 changes: 10 additions & 1 deletion src/common/gui/CHSwitch2.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
//-------------------------------------------------------------------------------------------------------
#pragma once
#include "vstcontrols.h"
#include "SkinSupport.h"

class CHSwitch2 : public VSTGUI::CHorizontalSwitch
class CHSwitch2 : public VSTGUI::CHorizontalSwitch, public Surge::UI::SkinConsumingComponnt
{
public:
CHSwitch2(const VSTGUI::CRect& size,
Expand Down Expand Up @@ -35,6 +36,11 @@ class CHSwitch2 : public VSTGUI::CHorizontalSwitch
bool dragable;
bool usesMouseWheel;

bool lookedForHover = false;
CScalableBitmap *hoverBmp = nullptr;
bool doingHover = false;
float hoverValue = 0.0f;

virtual void draw(VSTGUI::CDrawContext* dc) override;
virtual VSTGUI::CMouseEventResult
onMouseDown(VSTGUI::CPoint& where,
Expand All @@ -49,10 +55,13 @@ class CHSwitch2 : public VSTGUI::CHorizontalSwitch

virtual VSTGUI::CMouseEventResult onMouseEntered (VSTGUI::CPoint& where, const VSTGUI::CButtonState& buttons) override {
getFrame()->setCursor( VSTGUI::kCursorHand );
doingHover = true;
return VSTGUI::kMouseEventHandled;
}
virtual VSTGUI::CMouseEventResult onMouseExited (VSTGUI::CPoint& where, const VSTGUI::CButtonState& buttons) override {
getFrame()->setCursor( VSTGUI::kCursorDefault );
doingHover = false;
invalid();
return VSTGUI::kMouseEventHandled;
}

Expand Down
3 changes: 2 additions & 1 deletion src/common/gui/CScalableBitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class CScalableBitmap : public VSTGUI::CBitmap
extraScaleFactor = a;
}

int resourceID;

private:
struct CPointCompare
{
Expand All @@ -66,7 +68,6 @@ class CScalableBitmap : public VSTGUI::CBitmap

int lastSeenZoom, bestFitScaleGroup;
int extraScaleFactor;
int resourceID;
std::string fname;

VSTGUI::CFrame* frame;
Expand Down
3 changes: 2 additions & 1 deletion src/common/gui/CSwitchControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
//-------------------------------------------------------------------------------------------------------
#pragma once
#include "vstcontrols.h"
#include "SkinSupport.h"

class CSwitchControl : public VSTGUI::CControl
class CSwitchControl : public VSTGUI::CControl, public Surge::UI::SkinConsumingComponnt
{
public:
CSwitchControl(const VSTGUI::CRect& size, VSTGUI::IControlListener* listener, long tag, VSTGUI::CBitmap* background);
Expand Down
32 changes: 32 additions & 0 deletions src/common/gui/SkinSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "UserInteractions.h"
#include "UserDefaults.h"
#include "UIInstrumentation.h"
#include "CScalableBitmap.h"

#if LINUX
#include <experimental/filesystem>
Expand All @@ -27,6 +28,9 @@ namespace Surge
{
namespace UI
{

const std::string Skin::defaultImageIDPrefix = "DEFAULT/";

SkinDB& Surge::UI::SkinDB::get(SurgeStorage* s)
{
static SkinDB instance(s);
Expand Down Expand Up @@ -384,6 +388,11 @@ void Skin::reloadSkin(std::shared_ptr<SurgeBitmaps> bitmapStore)
int idx = std::atoi(d.path().generic_string().c_str() + pos + 3);
bitmapStore->loadBitmapByPathForID(d.path().generic_string(), idx);
}
else
{
std::string id = defaultImageIDPrefix + d.path().filename().generic_string();
bitmapStore->loadBitmapByPathForStringID(d.path().generic_string(), id);
}
}
}
}
Expand Down Expand Up @@ -591,5 +600,28 @@ CScalableBitmap *Skin::backgroundBitmapForControl( Skin::Control::ptr_t c, std::
return bmp;
}

CScalableBitmap *Skin::hoverBitmapOverlayForBackgroundBitmap( Skin::Control::ptr_t c, CScalableBitmap *b, std::shared_ptr<SurgeBitmaps> bitmapStore )
{
if( ! bitmapStore.get() )
{
return nullptr;
}
if( c.get() )
{
std::cout << "should ask control if it has an opinoin" << std::endl;
}
if( ! b )
{
return nullptr;
}
std::ostringstream sid;
sid << defaultImageIDPrefix << "hover" << std::setw(5) << std::setfill('0') << b->resourceID << ".svg";
auto bmp = bitmapStore->getBitmapByStringID( sid.str() );
if( bmp )
return bmp;

return nullptr;
}

} // namespace UI
} // namespace Surge
13 changes: 12 additions & 1 deletion src/common/gui/SkinSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ class Skin
}

CScalableBitmap *backgroundBitmapForControl( Skin::Control::ptr_t c, std::shared_ptr<SurgeBitmaps> bitmapStore );
CScalableBitmap *hoverBitmapOverlayForBackgroundBitmap( Skin::Control::ptr_t c, CScalableBitmap *b, std::shared_ptr<SurgeBitmaps> bitmapStore );

static const std::string defaultImageIDPrefix;

private:
static std::atomic<int> instances;
Expand Down Expand Up @@ -253,8 +256,16 @@ class SkinConsumingComponnt {
virtual ~SkinConsumingComponnt() {
}
virtual void setSkin( Skin::ptr_t s ) { skin = s; }
virtual void setSkin( Skin::ptr_t s, std::shared_ptr<SurgeBitmaps> b ) {
skin = s;
associatedBitmapStore = b;
}
virtual void setAssociatedSkinControl( Skin::Control::ptr_t c ) { skinControl = c; };
virtual void setAssociatedBitmapStore( std::shared_ptr<SurgeBitmaps> b ) { associatedBitmapStore = b; }
protected:
Skin::ptr_t skin;
Skin::ptr_t skin = nullptr;
Skin::Control::ptr_t skinControl = nullptr;
std::shared_ptr<SurgeBitmaps> associatedBitmapStore = nullptr;
};
}
}
Loading

0 comments on commit 441bb00

Please sign in to comment.