//============================================================================== void Path::applyTransform (const AffineTransform& transform) noexcept { bounds.reset(); bool firstPoint = true; float* d = data.elements; float* const end = d + numElements; while (d < end) { const float type = *d++; if (type == moveMarker) { transform.transformPoint (d[0], d[1]); if (firstPoint) { firstPoint = false; bounds.reset (d[0], d[1]); } else { bounds.extend (d[0], d[1]); } d += 2; } else if (type == lineMarker) { transform.transformPoint (d[0], d[1]); bounds.extend (d[0], d[1]); d += 2; } else if (type == quadMarker) { transform.transformPoints (d[0], d[1], d[2], d[3]); bounds.extend (d[0], d[1], d[2], d[3]); d += 4; } else if (type == cubicMarker) { transform.transformPoints (d[0], d[1], d[2], d[3], d[4], d[5]); bounds.extend (d[0], d[1], d[2], d[3]); bounds.extend (d[4], d[5]); d += 6; } } }
void Path::addPath (const Path& other, const AffineTransform& transformToApply) { size_t i = 0; const float* const d = other.data.elements; while (i < other.numElements) { const float type = d [i++]; if (type == closeSubPathMarker) { closeSubPath(); } else { float x = d[i++]; float y = d[i++]; transformToApply.transformPoint (x, y); if (type == moveMarker) { startNewSubPath (x, y); } else if (type == lineMarker) { lineTo (x, y); } else if (type == quadMarker) { float x2 = d [i++]; float y2 = d [i++]; transformToApply.transformPoint (x2, y2); quadraticTo (x, y, x2, y2); } else if (type == cubicMarker) { float x2 = d [i++]; float y2 = d [i++]; float x3 = d [i++]; float y3 = d [i++]; transformToApply.transformPoints (x2, y2, x3, y3); cubicTo (x, y, x2, y2, x3, y3); } else { // something's gone wrong with the element list! jassertfalse; } } } }
void drawRotarySlider (Graphics& g, int x, int y, int width, int height, float sliderPos, float rotaryStartAngle, float rotaryEndAngle, Slider& slider) override { const float diameter = jmin (width, height) - 4.0f; const float radius = (diameter / 2.0f) * std::cos (float_Pi / 4.0f); const float centreX = x + width * 0.5f; const float centreY = y + height * 0.5f; const float rx = centreX - radius; const float ry = centreY - radius; const float rw = radius * 2.0f; const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle); const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled(); const Colour baseColour (slider.isEnabled() ? slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 0.8f : 1.0f) : Colour (0x80808080)); Rectangle<float> r (rx, ry, rw, rw); AffineTransform t (AffineTransform::rotation (angle, r.getCentreX(), r.getCentreY())); float x1 = r.getTopLeft().getX(), y1 = r.getTopLeft().getY(), x2 = r.getBottomLeft().getX(), y2 = r.getBottomLeft().getY(); t.transformPoints (x1, y1, x2, y2); g.setGradientFill (ColourGradient (baseColour, x1, y1, baseColour.darker (0.1f), x2, y2, false)); Path knob; knob.addRectangle (r); g.fillPath (knob, t); Path needle; Rectangle<float> r2 (r * 0.1f); needle.addRectangle (r2.withPosition (Point<float> (r.getCentreX() - (r2.getWidth() / 2.0f), r.getY()))); g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId)); g.fillPath (needle, AffineTransform::rotation (angle, r.getCentreX(), r.getCentreY())); }