Skip to content

Commit

Permalink
- Scripting API: added viewport
Browse files Browse the repository at this point in the history
- implemented #24
  • Loading branch information
christoph-hart committed Jun 8, 2017
1 parent 6a195a2 commit 7f9d1bb
Show file tree
Hide file tree
Showing 10 changed files with 1,904 additions and 1,720 deletions.
51 changes: 51 additions & 0 deletions hi_scripting/scripting/api/ScriptComponentWrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,57 @@ void ScriptCreatedComponentWrappers::ModulatorMeterWrapper::updateComponent()
dynamic_cast<SettableTooltipClient*>(component.get())->setTooltip(GET_SCRIPT_PROPERTY(tooltip));
}


class DummyComponent: public Component
{
public:

DummyComponent()
{
setSize(4000, 4000);
}

void paint(Graphics& g)
{
g.setGradientFill(ColourGradient(Colours::white.withAlpha(0.2f), 0.0f, 0.0f, Colours::black.withAlpha(0.2f), getWidth(), getHeight(), false));

g.fillAll();
g.setColour(Colours::white.withAlpha(0.6f));
g.drawRect(getLocalBounds(), 1.0f);

}
};

ScriptCreatedComponentWrappers::ViewportWrapper::ViewportWrapper(ScriptContentComponent* content, ScriptingApi::Content::ScriptedViewport* viewport, int index):
ScriptCreatedComponentWrapper(content, index)
{
Viewport* vp = new Viewport();

vp->setName(viewport->name.toString());

vp->setViewedComponent(new DummyComponent(), true);

component = vp;
}


ScriptCreatedComponentWrappers::ViewportWrapper::~ViewportWrapper()
{

}

void ScriptCreatedComponentWrappers::ViewportWrapper::updateComponent()
{
auto vp = dynamic_cast<Viewport*>(component.get());

auto vpc = dynamic_cast<ScriptingApi::Content::ScriptedViewport*>(getScriptComponent());

vp->setScrollBarThickness(vpc->getScriptObjectProperty(ScriptingApi::Content::ScriptedViewport::Properties::scrollbarThickness));

vp->setColour(ScrollBar::ColourIds::thumbColourId, GET_OBJECT_COLOUR(itemColour));

}

ScriptCreatedComponentWrappers::PlotterWrapper::PlotterWrapper(ScriptContentComponent *content, ScriptingApi::Content::ScriptedPlotter *p, int index):
ScriptCreatedComponentWrapper(content, index)
{
Expand Down
14 changes: 14 additions & 0 deletions hi_scripting/scripting/api/ScriptComponentWrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,20 @@ class ScriptCreatedComponentWrappers
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PanelWrapper)
};


class ViewportWrapper : public ScriptCreatedComponentWrapper
{
public:

ViewportWrapper(ScriptContentComponent* content, ScriptingApi::Content::ScriptedViewport* viewport, int index);

~ViewportWrapper();

void updateComponent() override;


};

class SliderPackWrapper : public ScriptCreatedComponentWrapper,
public SliderPack::Listener
{
Expand Down
27 changes: 27 additions & 0 deletions hi_scripting/scripting/api/ScriptingApiContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,25 @@ void ScriptingApi::Content::ScriptPanel::AsyncControlCallbackSender::handleAsync
}


ScriptCreatedComponentWrapper * ScriptingApi::Content::ScriptedViewport::createComponentWrapper(ScriptContentComponent *content, int index)
{
return new ScriptCreatedComponentWrappers::ViewportWrapper(content, this, index);
}

ScriptingApi::Content::ScriptedViewport::ScriptedViewport(ProcessorWithScriptingContent* base, Content* parentContent, Identifier viewportName, int x, int y, int width, int height):
ScriptComponent(base, parentContent, viewportName, x, y, width, height)
{
deactivatedProperties.add(getIdFor(ScriptComponent::Properties::macroControl));

propertyIds.add("scrollBarThickness"); ADD_AS_SLIDER_TYPE(0, 40, 1);
propertyIds.add("autoHide"); ADD_TO_TYPE_SELECTOR(SelectorTypes::ToggleSelector);


setDefaultValue(scrollbarThickness, 16.0);
setDefaultValue(autoHide, true);
}


struct ScriptingApi::Content::ScriptedPlotter::Wrapper
{
API_VOID_METHOD_WRAPPER_2(ScriptedPlotter, addModulatorToPlotter);
Expand Down Expand Up @@ -2518,6 +2537,7 @@ colour(Colour(0xff777777))
setMethod("addImage", Wrapper::addImage);
setMethod("addModulatorMeter", Wrapper::addModulatorMeter);
setMethod("addPlotter", Wrapper::addPlotter);
setMethod("addViewport", Wrapper::addScriptedViewport);
setMethod("addPanel", Wrapper::addPanel);
setMethod("addAudioWaveform", Wrapper::addAudioWaveform);
setMethod("addSliderPack", Wrapper::addSliderPack);
Expand Down Expand Up @@ -2636,6 +2656,13 @@ ScriptingApi::Content::ScriptLabel * ScriptingApi::Content::addLabel(Identifier
return addComponent<ScriptLabel>(labelName, x, y, 100, 50);
};


ScriptingApi::Content::ScriptedViewport* ScriptingApi::Content::addScriptedViewport(Identifier viewportName, int x, int y)
{
return addComponent<ScriptedViewport>(viewportName, x, y, 200, 100);
}


ScriptingApi::Content::ScriptTable * ScriptingApi::Content::addTable(Identifier labelName, int x, int y)
{
return addComponent<ScriptTable>(labelName, x, y, 100, 50);
Expand Down
22 changes: 22 additions & 0 deletions hi_scripting/scripting/api/ScriptingApiContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,25 @@ class ScriptingApi::Content : public ScriptingObject,
// ========================================================================================================
};

struct ScriptedViewport : public ScriptComponent
{
public:

enum Properties
{
scrollbarThickness = ScriptComponent::numProperties,
autoHide,
numProperties
};

ScriptedViewport(ProcessorWithScriptingContent* base, Content* parentContent, Identifier viewportName, int x, int y, int width, int height);

virtual Identifier getObjectName() const override { return "ScriptedViewport"; }
ScriptCreatedComponentWrapper *createComponentWrapper(ScriptContentComponent *content, int index) override;


};


struct ScriptedPlotter : public ScriptComponent
{
Expand Down Expand Up @@ -956,6 +975,9 @@ class ScriptingApi::Content : public ScriptingObject,
/** Adds a slider pack. */
ScriptSliderPack *addSliderPack(Identifier sliderPackName, int x, int y);

/** Adds a viewport. */
ScriptedViewport* addScriptedViewport(Identifier viewportName, int x, int y);

/** Restore the widget from a JSON object. */
void setPropertiesFromJSON(const Identifier &name, const var &jsonData);

Expand Down
20 changes: 20 additions & 0 deletions hi_scripting/scripting/api/ScriptingApiWrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct ScriptingApi::Content::Wrapper
static var addTable(const var::NativeFunctionArgs& args);
static var addImage(const var::NativeFunctionArgs& args);
static var addModulatorMeter(const var::NativeFunctionArgs& args);
static var addScriptedViewport(const var::NativeFunctionArgs& args);
static var addPlotter(const var::NativeFunctionArgs& args);
static var addModulatorToPlotter(const var::NativeFunctionArgs& args);
static var addPanel(const var::NativeFunctionArgs& args);
Expand Down Expand Up @@ -253,6 +254,25 @@ var ScriptingApi::Content::Wrapper::addPlotter (const var::NativeFunctionArgs& a
};


var ScriptingApi::Content::Wrapper::addScriptedViewport(const var::NativeFunctionArgs& args)
{
if (ScriptingApi::Content* thisObject = GET_OBJECT(Content))
{
if (args.numArguments == 1)
{
return thisObject->addScriptedViewport(Identifier(args.arguments[0]), 0, 0);
}

CHECK_ARGUMENTS("addScriptedViewport()", 3);

return thisObject->addScriptedViewport(Identifier(args.arguments[0]), args.arguments[1], args.arguments[2]);
}

return var::undefined();
}



var ScriptingApi::Content::Wrapper::addPanel (const var::NativeFunctionArgs& args)
{
if (ScriptingApi::Content* thisObject = GET_OBJECT(Content))
Expand Down
Loading

0 comments on commit 7f9d1bb

Please sign in to comment.