void Oscilloscope::paint(Graphics& g) { static const DropShadow shadow(Colour(0xbb000000), 5, Point<int>(0, 0)); g.drawImageWithin(background_, 0, 0, getWidth(), getHeight(), RectanglePlacement()); shadow.drawForPath(g, wave_path_); g.setColour(Colour(0xff565656)); g.fillPath(wave_path_); g.setColour(Colour(0xffaaaaaa)); g.strokePath(wave_path_, PathStrokeType(1.0f, PathStrokeType::beveled, PathStrokeType::rounded)); }
void VideoComponent::resized() { Rectangle<int> r = getLocalBounds(); if (isVideoOpen() && ! r.isEmpty()) { Rectangle<int> nativeSize = getVideoNativeSize(); if (nativeSize.isEmpty()) { // if we've just opened the file and are still waiting for it to // figure out the size, start our timer.. if (! isTimerRunning()) startTimer (50); } else { r = RectanglePlacement (RectanglePlacement::centred).appliedTo (nativeSize, r); stopTimer(); } } else { stopTimer(); } pimpl->setBounds (r); }
void drawTickBox (Graphics& g, Component& component, float x, float y, float w, float h, bool ticked, bool isEnabled, bool /*isMouseOverButton*/, bool /*isButtonDown*/) override { const float boxSize = w * 0.7f; bool isDownOrDragging = component.isEnabled() && (component.isMouseOverOrDragging() || component.isMouseButtonDown()); const Colour colour (component.findColour (TextButton::buttonOnColourId).withMultipliedSaturation ((component.hasKeyboardFocus (false) || isDownOrDragging) ? 1.3f : 0.9f) .withMultipliedAlpha (component.isEnabled() ? 1.0f : 0.7f)); g.setColour (colour); Rectangle<float> r (x, y + (h - boxSize) * 0.5f, boxSize, boxSize); g.fillRect (r); if (ticked) { const Path tick (LookAndFeel_V4::getTickShape (6.0f)); g.setColour (isEnabled ? findColour (TextButton::buttonColourId) : Colours::grey); const AffineTransform trans (RectanglePlacement (RectanglePlacement::centred) .getTransformToFit (tick.getBounds(), r.reduced (r.getHeight() * 0.05f))); g.fillPath (tick, trans); } }
//============================================================================== void CtrlrGroup::paint (Graphics& g) { //[UserPrePaint] Add your own custom painting code here.. //[/UserPrePaint] //[UserPaint] Add your own custom painting code here.. Rectangle<int> r = getUsableRect(); gradientFromProperty(g, getBounds(), getObjectTree(), Ids::uiGroupOutlineGradientType, Ids::uiGroupOutlineColour1, Ids::uiGroupOutlineColour2); g.drawRoundedRectangle (r.toFloat().reduced((float)getProperty(Ids::uiGroupOutlineThickness)/2.0f), getProperty(Ids::uiGroupOutlineRoundAngle), getProperty(Ids::uiGroupOutlineThickness)); gradientFromProperty(g, getBounds(), getObjectTree(), Ids::uiGroupBackgroundGradientType, Ids::uiGroupBackgroundColour1, Ids::uiGroupBackgroundColour2); g.fillRoundedRectangle (r.toFloat().reduced((float)getProperty(Ids::uiGroupOutlineThickness)/2.0f), getProperty(Ids::uiGroupOutlineRoundAngle)); if (groupBackgroundImage.isValid()) { if ((int)getProperty (Ids::uiGroupBackgroundImageLayout) == 8192) { g.setTiledImageFill (groupBackgroundImage, 0, 0, (float)getProperty (Ids::uiGroupBackgroundImageAlpha)/255.0f); g.fillRect(r); } else { g.setColour (Colours::black.withAlpha ((float)getProperty (Ids::uiGroupBackgroundImageAlpha)/255.0f)); g.drawImageWithin (groupBackgroundImage, r.getX(), r.getY(), r.getWidth(), r.getHeight(), RectanglePlacement(getProperty (Ids::uiGroupBackgroundImageLayout))); } } //[/UserPaint] }
void paint (Graphics& g) { g.setColour (findColour (mainBackgroundColourId).contrasting (0.3f)); Rectangle<int> r (getLocalBounds()); g.setFont (15.0f); g.drawFittedText (getVersionInfo(), r.removeFromBottom (50), Justification::centredBottom, 3); logo->drawWithin (g, r.withTrimmedBottom (r.getHeight() / 4).toFloat(), RectanglePlacement (RectanglePlacement::centred), 1.0f); }
void CtrlrValueTreeEditorItem::paintItem (Graphics &g, int width, int height) { Image icon = provider.getIconForItem (treeToEdit); if (isSelected()) { drawSelectionRectangle (g,width,height); } g.setColour (Colours::black); AttributedString as = provider.getDisplayString(treeToEdit); as.setJustification (Justification (Justification::centredLeft)); as.draw (g, Rectangle <float> (24.0, 0.0, width - 24.0, height)); g.drawImageWithin (icon, 4, 0, 16, height, RectanglePlacement (RectanglePlacement::centred)); }
PathsDemo (ControllersComponent& cc, bool linear, bool radial) : GraphicsDemoBase (cc, String ("Paths") + (radial ? ": Radial Gradients" : (linear ? ": Linear Gradients" : ": Solid"))), useLinearGradient (linear), useRadialGradient (radial) { logoPath = MainAppWindow::getJUCELogoPath(); // rescale the logo path so that it's centred about the origin and has the right size. logoPath.applyTransform (RectanglePlacement (RectanglePlacement::centred) .getTransformToFit (logoPath.getBounds(), Rectangle<float> (-200.0f, -200.0f, 400.0f, 400.0f))); // Surround it with some other shapes.. logoPath.addStar (Point<float> (-300.0f, -50.0f), 7, 30.0f, 70.0f, 0.1f); logoPath.addStar (Point<float> (300.0f, 50.0f), 6, 40.0f, 70.0f, 0.1f); logoPath.addEllipse (-100.0f, 150.0f, 200.0f, 140.0f); logoPath.addRectangle (-100.0f, -280.0f, 200.0f, 140.0f); }
void drawCurrentImage (Graphics& g, Rectangle<int> area) { if (imageNeedsFlipping) { const ScopedLock sl (imageSwapLock); std::swap (loadingImage, activeImage); imageNeedsFlipping = false; } Rectangle<int> centred (RectanglePlacement (RectanglePlacement::centred) .appliedTo (Rectangle<int> (width, height), area)); RectangleList<int> borders (area); borders.subtract (centred); g.setColour (Colours::black); g.fillRectList (borders); g.drawImage (activeImage, centred.getX(), centred.getY(), centred.getWidth(), centred.getHeight(), 0, 0, width, height); }
//============================================================================== void MainContentComponent::selectionChanged() { const File selectedFile(mFileTree.getSelectedFile()); //> open selected file if (selectedFile.existsAsFile()) { //> the image cahce is a handly way to load images from files or directly from memory and //> will keep them hanging around for a few seconds in case they are requested elsewhere //> RectanglePlacement() default is centred mImgViewer.setImage(ImageCache::getFromFile(selectedFile), RectanglePlacement()); //> change title bar of window MainWindow *pMainWindow = MainWindow::getMainWindow(); if (pMainWindow != nullptr) { pMainWindow->setName(selectedFile.getFileName() + " - " + ProjectInfo::projectName); } } }
void WaveViewer::paint(juce::Graphics &g) { g.drawImageWithin(background_, 0, 0, getWidth(), getHeight(), RectanglePlacement()); if (wave_phase_) { if (phase_ >= 0.0 && phase_ < 1.0) { float x = phaseToX(phase_); g.setColour(Colour(0x33ffffff)); g.fillRect(x - 0.5f, 0.0f, 1.0f, (float)getHeight()); float y = PADDING + (getHeight() - 2 * PADDING) * (1.0f - amp_) / 2.0f; if (is_control_rate_) g.setColour(Colour(0xff00e676)); else g.setColour(Colour(0xff03a9f4)); g.fillEllipse(x - MARKER_WIDTH / 2.0f, y - MARKER_WIDTH / 2.0f, MARKER_WIDTH, MARKER_WIDTH); g.setColour(Colour(0xff000000)); g.fillEllipse(x - MARKER_WIDTH / 4.0f, y - MARKER_WIDTH / 4.0f, MARKER_WIDTH / 2.0f, MARKER_WIDTH / 2.0f); } } }
//============================================================================== Drawable* parseSVGElement (const XmlPath& xml) { if (! xml->hasTagNameIgnoringNamespace ("svg")) return nullptr; DrawableComposite* const drawable = new DrawableComposite(); setDrawableID (*drawable, xml); SVGState newState (*this); if (xml->hasAttribute ("transform")) newState.addTransform (xml); newState.elementX = getCoordLength (xml->getStringAttribute ("x", String (newState.elementX)), viewBoxW); newState.elementY = getCoordLength (xml->getStringAttribute ("y", String (newState.elementY)), viewBoxH); newState.width = getCoordLength (xml->getStringAttribute ("width", String (newState.width)), viewBoxW); newState.height = getCoordLength (xml->getStringAttribute ("height", String (newState.height)), viewBoxH); if (newState.width <= 0) newState.width = 100; if (newState.height <= 0) newState.height = 100; Point<float> viewboxXY; if (xml->hasAttribute ("viewBox")) { const String viewBoxAtt (xml->getStringAttribute ("viewBox")); String::CharPointerType viewParams (viewBoxAtt.getCharPointer()); Point<float> vwh; if (parseCoords (viewParams, viewboxXY, true) && parseCoords (viewParams, vwh, true) && vwh.x > 0 && vwh.y > 0) { newState.viewBoxW = vwh.x; newState.viewBoxH = vwh.y; int placementFlags = 0; const String aspect (xml->getStringAttribute ("preserveAspectRatio")); if (aspect.containsIgnoreCase ("none")) { placementFlags = RectanglePlacement::stretchToFit; } else { if (aspect.containsIgnoreCase ("slice")) placementFlags |= RectanglePlacement::fillDestination; if (aspect.containsIgnoreCase ("xMin")) placementFlags |= RectanglePlacement::xLeft; else if (aspect.containsIgnoreCase ("xMax")) placementFlags |= RectanglePlacement::xRight; else placementFlags |= RectanglePlacement::xMid; if (aspect.containsIgnoreCase ("yMin")) placementFlags |= RectanglePlacement::yTop; else if (aspect.containsIgnoreCase ("yMax")) placementFlags |= RectanglePlacement::yBottom; else placementFlags |= RectanglePlacement::yMid; } newState.transform = RectanglePlacement (placementFlags) .getTransformToFit (Rectangle<float> (viewboxXY.x, viewboxXY.y, vwh.x, vwh.y), Rectangle<float> (newState.width, newState.height)) .followedBy (newState.transform); } } else { if (viewBoxW == 0) newState.viewBoxW = newState.width; if (viewBoxH == 0) newState.viewBoxH = newState.height; } newState.parseSubElements (xml, *drawable); drawable->setContentArea (RelativeRectangle (RelativeCoordinate (viewboxXY.x), RelativeCoordinate (viewboxXY.x + newState.viewBoxW), RelativeCoordinate (viewboxXY.y), RelativeCoordinate (viewboxXY.y + newState.viewBoxH))); drawable->resetBoundingBoxToContentArea(); return drawable; }
void SplashScreen::paint (Graphics& g) { g.setOpacity (1.0f); g.drawImage (backgroundImage, getLocalBounds().toFloat(), RectanglePlacement (RectanglePlacement::fillDestination)); }
void ScoreImage::drawNote(Graphics* g, Note note) { int pitch = note.pitch; pitch += note.octave * 14; pitch = (pitch / 2); int move = pitch - 7; g->setColour(Colours::black); int ellipseY = scoreHeight / 2 - noteHeight / 2 * move - noteHeight / 2; if (note.duration / metrumBase >= 0.5) g->drawEllipse(actualPoint, ellipseY, 2 * noteHeight, noteHeight, 3); else g->fillEllipse(actualPoint, ellipseY, 2 * noteHeight, noteHeight); if ( move < -5 || move > 5) { g->drawHorizontalLine(ellipseY + noteHeight / 2, actualPoint - noteHeight / 4, actualPoint + 2 * noteHeight + noteHeight / 4); g->drawHorizontalLine(ellipseY + noteHeight / 2 - 1, actualPoint - noteHeight / 4, actualPoint + 2 * noteHeight + noteHeight / 4); g->drawHorizontalLine(ellipseY + noteHeight / 2 + 1, actualPoint - noteHeight / 4, actualPoint + 2 * noteHeight + noteHeight / 4); } // stem if (note.duration / metrumBase != 1) { if (move < 0) g->fillRect(actualPoint + 2 * noteHeight, ellipseY + noteHeight / 2 - 4 * noteHeight, 4, 4 * noteHeight); else g->fillRect(actualPoint, ellipseY + noteHeight / 2, 4, 4 * noteHeight); actualPoint += 4; } // flags if (note.duration / metrumBase < 0.25) { // 8 if (move >= 0) { g->drawImageTransformed(flagImage, AffineTransform::verticalFlip(flagImage.getHeight()).followedBy( AffineTransform::scale((float)flagImage.getWidth() / (noteHeight / 2) / 8, (float)flagImage.getHeight() / (noteHeight / 2) / 8).followedBy( AffineTransform::translation(actualPoint, ellipseY + 2 * noteHeight - noteHeight / 2)))); } else g->drawImageWithin(flagImage, actualPoint + 2 * noteHeight, ellipseY - 4 * noteHeight + noteHeight / 2, noteHeight / 2, 3 * noteHeight, RectanglePlacement(1 + 8 + 64 + 128)); // 16 if (note.duration / metrumBase < 0.125) { if (move >= 0) { g->drawImageTransformed(flagImage, AffineTransform::verticalFlip(flagImage.getHeight()).followedBy( AffineTransform::scale((float)flagImage.getWidth() / (noteHeight / 2) / 8, (float)flagImage.getHeight() / (noteHeight / 2) / 8).followedBy( AffineTransform::translation(actualPoint, ellipseY + noteHeight / 2)))); } else g->drawImageWithin(flagImage, actualPoint + 2 * noteHeight, ellipseY - 3 * noteHeight + noteHeight / 2, noteHeight / 2, 3 * noteHeight, RectanglePlacement(1 + 8 + 64 + 128)); } } actualPoint += 2 * noteHeight; actualPoint += 4 * 2 * noteHeight * note.duration; }
ScoreImage::ScoreImage(Array<ScorePart> scoreParts_) : score(scoreParts_), scoreHeight(1000), actualPosition(0), isRecording(false) { noteHeight = scoreHeight / 24; // key File violinImageFile = File(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory().getChildFile("images").getChildFile("klucz-wiolinowy.png")); Image violinImage = ImageCache::getFromFile(violinImageFile); keyImage = Image(Image::PixelFormat::RGB,200,1000,true); Graphics keyGraphics (keyImage); keyGraphics.fillAll(Colours::white); keyGraphics.setColour(Colours::black); keyGraphics.fillRect(0,scoreHeight / 2 - 1, 200, 3); keyGraphics.fillRect(0,scoreHeight / 2 - noteHeight - 1, 200, 3); keyGraphics.fillRect(0,scoreHeight / 2 + noteHeight - 1, 200, 3); keyGraphics.fillRect(0,scoreHeight / 2 - 2 * noteHeight - 1, 200, 3); keyGraphics.fillRect(0,scoreHeight / 2 + 2 * noteHeight - 1, 200, 3); keyGraphics.drawImageWithin(violinImage, 0, scoreHeight / 2 - 3.5 * noteHeight, 200, 7 * noteHeight, RectanglePlacement(4 + 32 + 128)); //score scoreWidth = 10000; scoreImage = Image(Image::PixelFormat::RGB,10000,1000,true); Graphics graphics (scoreImage); graphics.fillAll(Colours::white); // staff graphics.setColour(Colours::black); graphics.fillRect(0,scoreHeight / 2 - 1, scoreWidth, 3); graphics.fillRect(0,scoreHeight / 2 - noteHeight - 1, scoreWidth, 3); graphics.fillRect(0,scoreHeight / 2 + noteHeight - 1, scoreWidth, 3); graphics.fillRect(0,scoreHeight / 2 - 2 * noteHeight - 1, scoreWidth, 3); graphics.fillRect(0,scoreHeight / 2 + 2 * noteHeight - 1, scoreWidth, 3); actualPoint = 10; // metrum metrumValue = score[0].time.count; metrumBase= score[0].time.base; drawMetrum(&graphics); // notes File flagImageFile = File(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory().getChildFile("images").getChildFile("ogonek.png")); flagImage = ImageCache::getFromFile(flagImageFile); float count = 0; for (int i = 1; i < score[0].notes.size(); i++) { drawNote(&graphics, score[0].notes[i]); count += score[0].notes[i].duration; if (count >= metrumValue) { drawBarLine(&graphics); count = 0; } } startTimer (25); }
//============================================================================== void CtrlrXYSurface::paint (Graphics& g) { //[UserPrePaint] Add your own custom painting code here.. //[/UserPrePaint] //[UserPaint] Add your own custom painting code here.. gradientFromProperty (g, usableRectangle.getSmallestIntegerContainer(), getObjectTree(), Ids::uiXYSurfaceBgGradientType, Ids::uiXYSurfaceBackgroundColour1, Ids::uiXYSurfaceBackgroundColour2); g.fillRoundedRectangle ((float)usableRectangle.getTopLeft().getX(), (float)usableRectangle.getTopLeft().getY(), (float)usableRectangle.getWidth(), (float)usableRectangle.getHeight(), getProperty(Ids::uiXYSurfaceCornerSize)); gradientFromProperty (g, usableRectangle.getSmallestIntegerContainer(), getObjectTree(), Ids::uiXYSurfaceOutlineGradientType, Ids::uiXYSurfaceOutlineColour1, Ids::uiXYSurfaceOutlineColour2); g.drawRoundedRectangle ((float)usableRectangle.getX(), (float)usableRectangle.getY(), (float)usableRectangle.getWidth(), (float)usableRectangle.getHeight(), getProperty(Ids::uiXYSurfaceCornerSize), getProperty(Ids::uiXYSurfaceOutlineThickness)); const int snapSize = (int)getProperty (Ids::uiXYSurfaceGradientGrain, 8); Colour colour = VAR2COLOUR(getProperty(Ids::uiXYSurfaceGradientColour)); if (snapSize > 0) { Image backgroundFill(Image::ARGB, snapSize, snapSize, true); Graphics g1(backgroundFill); if (snapSize > 2) { g1.setColour (colour); g1.drawRect (0, 0, snapSize + 1, snapSize + 1); } g.setTiledImageFill (backgroundFill, 0, 0, 1.0f); g.fillRoundedRectangle ((float)usableRectangle.getX(), (float)usableRectangle.getY(), (float)usableRectangle.getWidth(), (float)usableRectangle.getHeight(), getProperty(Ids::uiXYSurfaceCornerSize)); } if (backgroundImage.isValid()) { if ((int)getProperty (Ids::uiXYSurfaceBgImageLayout) == 8192) { g.setTiledImageFill (backgroundImage, 0, 0, (float)getProperty (Ids::uiXYSurfaceBgImageAlpha)/255.0f); g.fillRect ((float)usableRectangle.getX(), (float)usableRectangle.getY(), (float)usableRectangle.getWidth(), (float)usableRectangle.getHeight()); } else { g.setColour (Colours::black.withAlpha ((float)getProperty (Ids::uiXYSurfaceBgImageAlpha)/255.0f)); g.drawImageWithin (backgroundImage, usableRectangle.getX(), usableRectangle.getX(), usableRectangle.getWidth(), usableRectangle.getHeight(), RectanglePlacement(getProperty (Ids::uiXYSurfaceBgImageLayout))); } } if (getProperty (Ids::uiXYSurfaceXTrackEnabled)) { const Point<int> c = surfaceModulator->getBounds().getCentre(); g.setColour (VAR2COLOUR(getProperty(Ids::uiXYSurfaceYTrackColour))); g.drawLine ((float)c.getX(), (float)usableRectangle.getY(), (float)c.getX(), (float)usableRectangle.getBottom(), getProperty(Ids::uiXYSurfaceYTrackThickness)); g.setColour (VAR2COLOUR(getProperty(Ids::uiXYSurfaceXTrackColour))); g.drawLine ((float)usableRectangle.getX(), (float)c.getY(), (float)usableRectangle.getWidth(), (float)c.getY(), getProperty(Ids::uiXYSurfaceXTrackThickness)); } if ((bool)getProperty(Ids::uiXYSurfaceInfoLabelVisible)) { // const int xScale = (int)getProperty(Ids::uiXYSurfaceMaxX); // const int yScale = (int)getProperty(Ids::uiXYSurfaceMaxY); const Point<int> c = surfaceModulator->getBounds().getCentre(); g.setColour (VAR2COLOUR(getProperty (Ids::uiXYSurfaceInfoLabelColour))); g.setFont (STR2FONT(getProperty(Ids::uiXYSurfaceInfoLabelFont))); g.drawText ("X="+String(getValueForPosition(c.getX(), true))+" Y="+String(getValueForPosition(c.getY(), false)), usableRectangle.getX() + 8, usableRectangle.getY() + 8, usableRectangle.getWidth()-16, usableRectangle.getHeight()-16, justificationFromProperty(getProperty (Ids::uiXYSurfaceInfoLabelLocation)), true); } //[/UserPaint] }
void Oscilloscope::paint(juce::Graphics &g) { g.fillAll (Colours::white); Path path; float xOffset = 21.f; float yOffset = 120.f; Rectangle<float> rect = logoPath.getBounds(); Rectangle<int> rect2 = getLocalBounds(); g.setColour (Colours::black); g.fillPath (logoPath, RectanglePlacement (RectanglePlacement::stretchToFit) .getTransformToFit (logoPath.getBounds(), getLocalBounds().toFloat())); // Horizontal zero line. path.addLineSegment(Line<float> (xOffset, yOffset, getLocalBounds().getWidth() - xOffset, yOffset), 1.); g.setColour (Colours::lightgrey); g.fillPath (path); float xIncrement = (getLocalBounds().getWidth() - 2 * xOffset) / (UIConstants::NUMBER_SCOPE_POINTS - 1); // Now iterate over points. int count = 0; float alpha = 0; for (auto& points : allPoints) { if ((currentPointsIndex - count + UIConstants::NUMBER_SCOPE_BUFFERS) % UIConstants::NUMBER_SCOPE_BUFFERS == 0) { // Current array is 'brightest' alpha = 1; } else { // Set older immediately to less than 0.5 alpha. alpha = 0.3 - ((currentPointsIndex - count + UIConstants::NUMBER_SCOPE_BUFFERS) % UIConstants::NUMBER_SCOPE_BUFFERS) * 0.03 ; } // g.setColour(Colour::fromFloatRGBA(0, 255 , 0, alpha)) ; g.setColour(scopeTraceColour.withAlpha(alpha)); path.clear(); float x = 0; path.startNewSubPath(xOffset, yOffset); for (auto& point : points) { // g.setPixel(x + xOffset, yOffset - 30 * point.x); // point.x in this case is the right value of the stereo pair. path.lineTo(x + xOffset, yOffset - 30 * point.x); x += xIncrement; } // path.closeSubPath(); g.strokePath (path, PathStrokeType (1.0f)); count++; } }