Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
725 changes: 725 additions & 0 deletions examples/graphics/data/svg/tiger.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions examples/graphics/source/examples/Svg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
==============================================================================

This file is part of the YUP library.
Copyright (c) 2025 - [email protected]

YUP is an open source library subject to open-source licensing.

The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
to use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.

YUP IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.

==============================================================================
*/

#pragma once

namespace yup
{

class SvgDemo : public yup::Component
{
public:
SvgDemo()
{
updateListOfSvgFiles();

parseSvgFile (currentSvgFileIndex);
}

void resized() override
{
//drawable.setBounds (getLocalBounds());
}

void mouseDown (const yup::MouseEvent& event) override
{
++currentSvgFileIndex;

parseSvgFile (currentSvgFileIndex);
}

void paint (Graphics& g) override
{
g.setFillColor (findColor (yup::DocumentWindow::Style::backgroundColorId).value_or (yup::Colors::dimgray));
g.fillAll();

drawable.paint (g, getLocalBounds());
}

private:
void updateListOfSvgFiles()
{
yup::File riveBasePath = yup::File (__FILE__)
.getParentDirectory()
.getParentDirectory()
.getParentDirectory();

auto files = riveBasePath.getChildFile ("data/svg").findChildFiles (yup::File::findFiles, false, "*.svg");
if (files.isEmpty())
return;

for (const auto& svgFile : files)
svgFiles.add (svgFile);
}

void parseSvgFile (int index)
{
if (svgFiles.isEmpty())
return;

if (index < 0)
index = svgFiles.size() - 1;

if (index >= svgFiles.size())
index = 0;

currentSvgFileIndex = index;

YUP_DBG ("Showing " << svgFiles[currentSvgFileIndex].getFullPathName());

drawable.clear();
drawable.parseSVG (svgFiles[currentSvgFileIndex]);

repaint();
}

yup::Drawable drawable;
Array<yup::File> svgFiles;
int currentSvgFileIndex = 0;
};

} // namespace yup
2 changes: 1 addition & 1 deletion examples/graphics/source/examples/VariableFonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class VariableFontsExample : public yup::Component
g.setFillColor (findColor (yup::DocumentWindow::Style::backgroundColorId).value_or (yup::Colors::dimgray));
g.fillAll();

g.setTransform (yup::AffineTransform::rotation (
g.addTransform (yup::AffineTransform::rotation (
yup::degreesToRadians (-rotation), getLocalBounds().getCenterX(), 100.0f));

if (feather > 0.0f)
Expand Down
14 changes: 14 additions & 0 deletions examples/graphics/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "examples/Paths.h"
#include "examples/PopupMenu.h"
#include "examples/TextEditor.h"
#include "examples/Svg.h"
#include "examples/VariableFonts.h"
#include "examples/Widgets.h"

Expand Down Expand Up @@ -222,6 +223,19 @@ class CustomWindow
addChildComponent (components.getLast());
}

{
auto button = std::make_unique<yup::TextButton> ("SVG");
button->onClick = [this, number = counter++]
{
selectComponent (number);
};
addAndMakeVisible (button.get());
buttons.add (std::move (button));

components.add (std::make_unique<yup::SvgDemo>());
addChildComponent (components.getLast());
}

selectComponent (0);

startTimerHz (10);
Expand Down
Loading
Loading