void MLDrawing::resizeWidget(const MLRect& b, const int u) { // adapt vrect to juce rect Component* pC = getComponent(); if(pC) { MLRect bb = b + mPixelOffset; if (bb.height() == 0) bb.setHeight(1); if (bb.width() == 0) bb.setWidth(1); // adapt vrect to juce rect Rectangle<int> c(bb.left(), bb.top(), bb.width(), bb.height()); pC->setBounds(c); } // iterate over points int size = mGridPoints.size(); for(int i = 0; i<size; ++i) { mTransformedPoints[i] = mGridPoints[i]*u; //debug() << "pt. " << i << ":" << mTransformedPoints[i] << " "; } //debug() << "\n"; }
void MLDebugDisplay::resizeWidget(const MLRect& b, const int) { Component* pC = getComponent(); if(pC) { // adapt vrect to juce rect Rectangle<int> c(b.left(), b.top(), b.width(), b.height()); pC->setBounds(c); mpComp->setBounds(0, 0, b.width(), b.height()); } }
void SoundplaneZoneView::renderZones() { if (!mpModel) return; const ScopedLock lock(*(mpModel->getZoneLock())); const std::vector<ZonePtr>& zoneList = mpModel->getZones(); int viewW = getBackingLayerWidth(); int viewH = getBackingLayerHeight(); int viewScale = getRenderingScale(); // float viewAspect = (float)viewW / (float)viewH; int gridWidth = 30; // Soundplane A TODO get from tracker int gridHeight = 5; int lineWidth = viewW / 200; int thinLineWidth = viewW / 400; // int margin = lineWidth*2; // put origin in lower left. MLGL::orthoView2(viewW, viewH); MLRange xRange(0, gridWidth, 1, viewW); MLRange yRange(0, gridHeight, 1, viewH); Vec4 lineColor; Vec4 darkBlue(0.3f, 0.3f, 0.5f, 1.f); Vec4 gray(0.6f, 0.6f, 0.6f, 1.f); Vec4 lightGray(0.9f, 0.9f, 0.9f, 1.f); Vec4 blue2(0.1f, 0.1f, 0.5f, 1.f); float smallDotSize = xRange(1.f); // float strokeWidth = viewW / 100; std::vector<ZonePtr>::const_iterator it; for(it = zoneList.begin(); it != zoneList.end(); ++it) { const Zone& zone = **it; int t = zone.getType(); MLRect zr = zone.getBounds(); const char * name = zone.getName().c_str(); int offset = zone.getOffset(); // affine transforms TODO for better syntax: MLRect zrd = zr.xform(gridToView); MLRect zoneRectInView(xRange.convert(zr.x()), yRange.convert(zr.y()), xRange.convert(zr.width()), yRange.convert(zr.height())); zoneRectInView.shrink(lineWidth); // color idx = type + port offset. Vec4 zoneStroke(MLGL::getIndicatorColor(t + offset)); Vec4 zoneFill(zoneStroke); zoneFill[3] = 0.1f; Vec4 activeFill(zoneStroke); activeFill[3] = 0.25f; Vec4 dotFill(zoneStroke); dotFill[3] = 0.5f; // draw box common to all kinds of zones glColor4fv(&zoneFill[0]); MLGL::fillRect(zoneRectInView); glColor4fv(&zoneStroke[0]); glLineWidth(lineWidth); MLGL::strokeRect(zoneRectInView, 2.0f*viewScale); glLineWidth(1); // draw name // all these rect calculations read upside-down here because view origin is at bottom MLGL::drawTextAt(zoneRectInView.left() + lineWidth, zoneRectInView.top() + lineWidth, 0.f, 0.1f, viewScale, name); // draw any zone-specific things float x, y; int toggle; switch(t) { case kNoteRow: for(int i = 0; i < kSoundplaneMaxTouches; ++i) { const ZoneTouch& uTouch = zone.getTouch(i); const ZoneTouch& touch = zone.touchToKeyPos(uTouch); if(touch.isActive()) { glColor4fv(&dotFill[0]); float dx = xRange(touch.pos.x()); float dy = yRange(touch.pos.y()); float dz = touch.pos.z(); MLGL::drawDot(Vec2(dx, dy), dz*smallDotSize); } } break; case kControllerX: x = xRange(zone.getXKeyPos()); glColor4fv(&zoneStroke[0]); glLineWidth(thinLineWidth); MLGL::strokeRect(MLRect(x, zoneRectInView.top(), 0., zoneRectInView.height()), viewScale); glColor4fv(&activeFill[0]); MLGL::fillRect(MLRect(zoneRectInView.left(), zoneRectInView.top(), x - zoneRectInView.left(), zoneRectInView.height())); break; case kControllerY: y = yRange(zone.getYKeyPos()); glColor4fv(&zoneStroke[0]); glLineWidth(thinLineWidth); MLGL::strokeRect(MLRect(zoneRectInView.left(), y, zoneRectInView.width(), 0.), viewScale); glColor4fv(&activeFill[0]); MLGL::fillRect(MLRect(zoneRectInView.left(), zoneRectInView.top(), zoneRectInView.width(), y - zoneRectInView.top())); break; case kControllerXY: x = xRange(zone.getXKeyPos()); y = yRange(zone.getYKeyPos()); glColor4fv(&zoneStroke[0]); glLineWidth(thinLineWidth); // cross-hairs centered on dot MLGL::strokeRect(MLRect(x, zoneRectInView.top(), 0., zoneRectInView.height()), viewScale); MLGL::strokeRect(MLRect(zoneRectInView.left(), y, zoneRectInView.width(), 0.), viewScale); glColor4fv(&dotFill[0]); MLGL::drawDot(Vec2(x, y), smallDotSize*0.25f); break; case kControllerZ: y = yRange(zone.mYRange(zone.getValue(0))); // look at z value over y range glColor4fv(&zoneStroke[0]); glLineWidth(thinLineWidth); MLGL::strokeRect(MLRect(zoneRectInView.left(), y, zoneRectInView.width(), 0.), viewScale); glColor4fv(&activeFill[0]); MLGL::fillRect(MLRect(zoneRectInView.left(), zoneRectInView.top(), zoneRectInView.width(), y - zoneRectInView.top())); break; case kToggle: toggle = zone.getToggleValue(); glColor4fv(&zoneStroke[0]); glLineWidth(thinLineWidth); if(toggle) { MLRect toggleFill = zoneRectInView; Vec2 zoneCenter = zoneRectInView.getCenter(); glColor4fv(&activeFill[0]); MLGL::fillRect(zoneRectInView); glColor4fv(&dotFill[0]); MLGL::drawDot(zoneCenter, smallDotSize*0.25f); } break; } } }
void MLMultiSlider::mouseDrag(const MouseEvent& e) { MLRect r = mPos.getLocalOutline(); float w = r.width(); float h = r.height(); int mx = ml::clamp(e.x, (int)r.left() + 1, (int)(r.left() + w)); int my = ml::clamp(e.y, (int)r.top() + 1, (int)(r.top() + h)); int dials = getNumSliders(); int s = getSliderUnderPoint(Vec2(mx, my)); if (isEnabled()) { if (ml::within(s, 0, dials)) { const int mousePos = mVertical ? my : mx; float val; MLRange posRange; if (mVertical) { posRange.set(h, 1); } else { posRange.set(1, w); } posRange.convertTo(mRange); val = posRange(mousePos); // if dial changed in drag, interpolate, setting dials in between if((mCurrDragSlider >= 0) && (mCurrDragSlider != s)) { int span = (s - mCurrDragSlider); int dir = sign(span); float mix, mixedval; int startDrag = mCurrDragSlider + dir; int endDrag = s + dir; for(int i=startDrag; i != endDrag; i += dir) { mix = fabs(float(i - startDrag)/float(span)); mixedval = lerp(mCurrDragValue, val, mix); // finish old drag and switch to dragging new dial if (i != mCurrDragSlider) { mCurrDragSlider = i; } sendSliderAction(snapValue (mixedval, false), i); } } else if (mCurrDragSlider == s) // set current drag dial { sendSliderAction(snapValue (val, false), s); } if (s != mSliderUnderMouse) { mSliderUnderMouse = s; repaint(); } mCurrDragSlider = s; mCurrDragValue = val; } } }