Skip to content

Commit

Permalink
Merge pull request #137 from Musicoll/dev/master
Browse files Browse the repository at this point in the history
Dev/master
  • Loading branch information
eliottparis authored Jun 1, 2018
2 parents 6c719fb + 8735852 commit d978c87
Show file tree
Hide file tree
Showing 39 changed files with 523 additions and 305 deletions.
4 changes: 2 additions & 2 deletions Client/Source/KiwiApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
namespace ProjectInfo
{
const char* const projectName = "Kiwi";
const char* const versionString = "v1.0.0";
const int versionNumber = 0x100;
const char* const versionString = "v1.0.1";
const int versionNumber = 0x101;
}

namespace kiwi
Expand Down
1 change: 0 additions & 1 deletion Client/Source/KiwiApp_General/KiwiApp_CommandIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ namespace kiwi

newBox = 0xf30300, ///< Add a new "box" to the patcher.
newMessage = 0xf30301, ///< Add a new "message" object box to the patcher.
newFlonum = 0xf30302, ///< Add a new "flonum" object box to the patcher.
newNumber = 0xf30303, ///< Add a new "number" object box to the patcher.
newComment = 0xf30304, ///< Add a new "comment" object box to the patcher.
newBang = 0xf30305, ///< Add a new "button" object box to the patcher.
Expand Down
19 changes: 10 additions & 9 deletions Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_BangView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ namespace kiwi {
return std::make_unique<BangView>(model);
}

BangView::BangView(model::Object & model):
ObjectView(model),
m_signal(model.getSignal<>(model::Bang::Signal::TriggerBang)),
m_connection(m_signal.connect(std::bind(&BangView::signalTriggered, this))),
m_active(false),
m_mouse_down(false)
{
}
BangView::BangView(model::Object & model)
: ObjectView(model)
, m_trigger_signal(model.getSignal<>(model::Bang::Signal::TriggerBang))
, m_flash_signal(model.getSignal<>(model::Bang::Signal::FlashBang))
, m_trigger_connection(m_trigger_signal.connect(std::bind(&BangView::signalTriggered, this)))
, m_flash_connection(m_flash_signal.connect(std::bind(&BangView::signalTriggered, this)))
, m_active(false)
, m_mouse_down(false)
{}

BangView::~BangView()
{
Expand Down Expand Up @@ -81,7 +82,7 @@ namespace kiwi {
m_mouse_down = true;
repaint();

m_signal();
m_trigger_signal();
}

void BangView::mouseUp(juce::MouseEvent const& e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ namespace kiwi {
private: // members

//! @todo Put border into ObjectView.
flip::Signal<>& m_signal;
flip::SignalConnection m_connection;
flip::Signal<>& m_trigger_signal;
flip::Signal<>& m_flash_signal;
flip::SignalConnection m_trigger_connection;
flip::SignalConnection m_flash_connection;
bool m_active;
bool m_mouse_down;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,22 @@ namespace kiwi {
return std::make_unique<NumberTildeView>(object_model);
}

NumberTildeView::NumberTildeView(model::Object & object_model) :
NumberViewBase(object_model)
NumberTildeView::NumberTildeView(model::Object & object_model)
: NumberViewBase(object_model)
{
setEditable(false);
setIconColour(findColour(ObjectView::ColourIds::Active));
setInterceptsMouseClicks(false, false);
}

void NumberTildeView::drawIcon (juce::Graphics& g) const
{
g.setColour (findColour (ObjectView::ColourIds::Active));

g.setFont(22.f);
g.drawFittedText("~", getLocalBounds().withWidth(getHeight()).withX(2),
juce::Justification::centredLeft, 1);
}

void NumberTildeView::parameterChanged(std::string const& name, tool::Parameter const& param)
{
if (name == "value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace kiwi {

private: // methods

void drawIcon (juce::Graphics& g) const override;

//! @brief Called when the displayed number has just changed.
void displayNumberChanged(double new_number) override final;

Expand Down
141 changes: 97 additions & 44 deletions Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,31 @@ namespace kiwi {
return std::make_unique<NumberView>(object_model);
}

NumberView::NumberView(model::Object & object_model) :
NumberViewBase(object_model),
m_output_message(object_model.getSignal<>(model::Message::Signal::outputMessage)),
m_sensitivity(1),
m_mouse_info()
NumberView::NumberView(model::Object & object_model)
: NumberViewBase(object_model)
, m_output_message(object_model.getSignal<>(model::Message::Signal::outputMessage))
{
setIconColour(findColour(ObjectView::ColourIds::Outline));
setInterceptsMouseClicks(true, true);
}

NumberView::~NumberView()
{}

void NumberView::drawIcon (juce::Graphics& g) const
{
g.setColour(findColour(ObjectView::ColourIds::Outline));

const juce::Rectangle<int> icon_bounds = getLocalBounds()
.withWidth(m_indent - 4).withHeight(getHeight() - 8).translated(2, 4);

juce::Path corner;

corner.addTriangle(icon_bounds.getTopLeft().toFloat(),
icon_bounds.getTopRight().toFloat()
+ juce::Point<float>(0, (icon_bounds.getHeight() / 2.)),
icon_bounds.getBottomLeft().toFloat());

g.fillPath(corner);
}

void NumberView::mouseDoubleClick(juce::MouseEvent const& e)
Expand All @@ -63,60 +76,100 @@ namespace kiwi {
{
e.source.enableUnboundedMouseMovement(true, true);

m_mouse_info.m_mouse_down_value = getDisplayNumber();
m_mouse_info.m_mouse_down_y = e.y;
m_last_drag_pos = e.position;
m_drag_value = m_value;

auto const& label = getLabel();
const auto textArea = label.getBorderSize().subtractedFrom(label.getBounds());

if (e.mods.isAltDown())
juce::GlyphArrangement glyphs;
glyphs.addFittedText (label.getFont(), label.getText(),
textArea.getX(), 0., textArea.getWidth(), getHeight(),
juce::Justification::centredLeft, 1,
label.getMinimumHorizontalScale());

double decimal_x = getWidth();
for(int i = 0; i < glyphs.getNumGlyphs(); ++i)
{
m_mouse_info.m_is_alt_down = true;
m_mouse_info.m_alt_down_value = getDisplayNumber();
m_mouse_info.m_alt_down_y = e.y;
auto const& glyph = glyphs.getGlyph(i);
if(glyph.getCharacter() == '.')
{
decimal_x = glyph.getRight();
}
}

const bool is_dragging_decimal = e.x > decimal_x;

m_decimal_drag = is_dragging_decimal ? 6 : 0;

if(is_dragging_decimal)
{
juce::GlyphArrangement decimals_glyph;
static const juce::String decimals_str("000000");

decimals_glyph.addFittedText (label.getFont(), decimals_str,
decimal_x, 0, getWidth(), getHeight(),
juce::Justification::centredLeft, 1,
label.getMinimumHorizontalScale());

for(int i = 0; i < decimals_glyph.getNumGlyphs(); ++i)
{
auto const& glyph = decimals_glyph.getGlyph(i);
if(e.x <= glyph.getRight())
{
m_decimal_drag = i+1;
break;
}
}
}
}

void NumberView::mouseDrag(juce::MouseEvent const& e)
{
if (e.getDistanceFromDragStartY() != 0)
setMouseCursor(juce::MouseCursor::NoCursor);
updateMouseCursor();

if (e.mouseWasDraggedSinceMouseDown())
{
double new_value = 0;

if (!m_mouse_info.m_is_alt_down && e.mods.isAltDown())
{
m_mouse_info.m_is_alt_down = true;
m_mouse_info.m_alt_down_value = getDisplayNumber();
m_mouse_info.m_alt_down_y = e.y;
}
else if(m_mouse_info.m_is_alt_down && !e.mods.isAltDown())
{
m_mouse_info.m_mouse_down_value = getDisplayNumber();
m_mouse_info.m_mouse_down_y = e.y;
m_mouse_info.m_is_alt_down = false;
m_mouse_info.m_is_alt_down = 0;
m_mouse_info.m_alt_down_y = 0;
}
const int decimal = m_decimal_drag + e.mods.isShiftDown();
const double increment = (decimal == 0) ? 1. : (1. / std::pow(10., decimal));
const double delta_y = e.y - m_last_drag_pos.y;
m_last_drag_pos = e.position;

if (e.mods.isAltDown())
{
new_value = m_mouse_info.m_alt_down_value - (m_sensitivity * (e.y - m_mouse_info.m_alt_down_y)) / 100.;
}
else
m_drag_value += increment * -delta_y;

if(m_drag_value != m_value)
{
new_value = m_mouse_info.m_mouse_down_value - m_sensitivity * (e.y - m_mouse_info.m_mouse_down_y);
// truncate value and set

double new_value = m_drag_value;

if(decimal > 0)
{
const int sign = (new_value > 0) ? 1 : -1;
unsigned int ui_temp = (new_value * std::pow(10, decimal)) * sign;
new_value = (((double)ui_temp)/std::pow(10, decimal) * sign);
}
else
{
new_value = static_cast<int64_t>(new_value);
}

setParameter("value",
tool::Parameter(tool::Parameter::Type::Float, {new_value}));
m_output_message();
repaint();
}

setParameter("value", tool::Parameter(tool::Parameter::Type::Float, {new_value}));
m_output_message();
repaint();
}
}

void NumberView::mouseUp(juce::MouseEvent const& e)
{
m_mouse_info.m_mouse_down_value = 0;
m_mouse_info.m_mouse_down_y = 0;
m_mouse_info.m_is_alt_down = false;
m_mouse_info.m_alt_down_value = 0;
m_mouse_info.m_alt_down_y = 0;
setMouseCursor(juce::MouseCursor::NormalCursor);
updateMouseCursor();

juce::Desktop::getInstance()
.getMainMouseSource().setScreenPosition(e.getMouseDownScreenPosition().toFloat());
}

void NumberView::parameterChanged(std::string const& name, tool::Parameter const& param)
Expand Down
20 changes: 6 additions & 14 deletions Client/Source/KiwiApp_Patcher/KiwiApp_Objects/KiwiApp_NumberView.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ namespace kiwi {
//! @brief The view of any textual kiwi object.
class NumberView : public NumberViewBase
{
private: // members

struct MouseInfo
{
double m_mouse_down_value = 0;
int m_mouse_down_y = 0;
bool m_is_alt_down = false;
double m_alt_down_value = 0;
int m_alt_down_y = 0;
};

public: // methods

// @brief The declaration method.
Expand All @@ -61,6 +50,8 @@ namespace kiwi {

private: // methods

void drawIcon (juce::Graphics& g) const override;

//! @brief Stores the initial value before draging.
void mouseDown(juce::MouseEvent const& e) override final;

Expand All @@ -81,9 +72,10 @@ namespace kiwi {

private: // members

flip::Signal<> & m_output_message;
int m_sensitivity;
MouseInfo m_mouse_info;
flip::Signal<>& m_output_message;
int m_decimal_drag = 0;
juce::Point<float> m_last_drag_pos {};
double m_drag_value = 0;

private: // deleted methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ namespace kiwi {
// NUMBER VIEW BASE //
// ================================================================================ //

NumberViewBase::NumberViewBase(model::Object & object_model) :
EditableObjectView(object_model),
m_value(0),
m_indent(9),
m_icon_colour(findColour (ObjectView::ColourIds::Outline))
NumberViewBase::NumberViewBase(model::Object & object_model)
: EditableObjectView(object_model)
, m_value(0)
, m_indent(9)
{
juce::Label & label = getLabel();

Expand Down Expand Up @@ -65,18 +64,12 @@ namespace kiwi {
g.setColour (findColour (ObjectView::ColourIds::Outline));

drawOutline(g);

juce::Path corner;

g.setColour(m_icon_colour);

juce::Rectangle<int> triangle_bounds = getLocalBounds().withWidth(m_indent - 4).withHeight(getHeight() - 8).translated(2, 4);

corner.addTriangle(triangle_bounds.getTopLeft().toFloat(),
triangle_bounds.getTopRight().toFloat() + juce::Point<float>(0, (triangle_bounds.getHeight() / 2.)),
triangle_bounds.getBottomLeft().toFloat());

g.fillPath(corner);
drawIcon(g);
}

void NumberViewBase::drawIcon (juce::Graphics& g) const
{
// nothing by default
}

void NumberViewBase::resized()
Expand All @@ -86,11 +79,6 @@ namespace kiwi {
getLabel().setBounds(label_bounds);
}

void NumberViewBase::setIconColour(juce::Colour colour)
{
m_icon_colour = colour;
}

double NumberViewBase::getDisplayNumber() const
{
return m_value;
Expand All @@ -101,15 +89,15 @@ namespace kiwi {
m_value = number;

juce::String display_value(std::to_string(m_value));

display_value = display_value.trimCharactersAtEnd("0");

getLabel().setText(display_value, juce::NotificationType::dontSendNotification);
}

void NumberViewBase::textChanged()
{
m_value = getLabel().getText().getFloatValue();
m_value = getLabel().getText().getDoubleValue();

displayNumberChanged(m_value);
}
Expand Down
Loading

0 comments on commit d978c87

Please sign in to comment.