computerscare: no my code is not released yet the entire code is below
qno: no i don’t override draw() - the examples i saw just had confusing settings for the various positioning parameters, and even looking at their SVG assets didn’t help me to understand it better
Constructor:
setBackgroundSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/components/slider-45mm-bg.svg")));
setHandleSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/components/slider-knob-black-red.svg")));
setTravel(45.0);
the method to set the travel:
void setTravel(float travel) {
travel = mm2px(travel);
math::Vec margin = math::Vec(handle->box.size).mult(0.5);
float handleX = -margin.x + (background->box.size.x * 0.5);
float handleY = margin.y;
float trackOffset = (background->box.size.y - travel) * 0.5;
maxHandlePos = math::Vec(handleX, trackOffset - handleY);
minHandlePos = math::Vec(handleX, trackOffset - handleY + travel);
box.size = background->box.size.plus(margin.mult(2));
}
I’m trying to make this so I can just have it work with whatever SVG background and handle are provided. The only manual setting is the track length, but I might even try to make that depend on the background SVG length. I just can’t seem to get things centered properly when also trying to increase the box.size to allow the margin area for the mouse interacting with the handle. It only works when the box size is not changed by my own code… but then you have to click only above the background track image to adjust the slider. (boo
)