Skip to content

Commit c8b54ce

Browse files
authored
Experimental basic SVG support (#64)
1 parent 163b608 commit c8b54ce

File tree

22 files changed

+3460
-113
lines changed

22 files changed

+3460
-113
lines changed

examples/graphics/data/svg/tiger.svg

Lines changed: 725 additions & 0 deletions
Loading
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
==============================================================================
3+
4+
This file is part of the YUP library.
5+
Copyright (c) 2025 - [email protected]
6+
7+
YUP is an open source library subject to open-source licensing.
8+
9+
The code included in this file is provided under the terms of the ISC license
10+
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
11+
to use, copy, modify, and/or distribute this software for any purpose with or
12+
without fee is hereby granted provided that the above copyright notice and
13+
this permission notice appear in all copies.
14+
15+
YUP IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
16+
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
17+
DISCLAIMED.
18+
19+
==============================================================================
20+
*/
21+
22+
#pragma once
23+
24+
namespace yup
25+
{
26+
27+
class SvgDemo : public yup::Component
28+
{
29+
public:
30+
SvgDemo()
31+
{
32+
updateListOfSvgFiles();
33+
34+
parseSvgFile (currentSvgFileIndex);
35+
}
36+
37+
void resized() override
38+
{
39+
//drawable.setBounds (getLocalBounds());
40+
}
41+
42+
void mouseDown (const yup::MouseEvent& event) override
43+
{
44+
++currentSvgFileIndex;
45+
46+
parseSvgFile (currentSvgFileIndex);
47+
}
48+
49+
void paint (Graphics& g) override
50+
{
51+
g.setFillColor (findColor (yup::DocumentWindow::Style::backgroundColorId).value_or (yup::Colors::dimgray));
52+
g.fillAll();
53+
54+
drawable.paint (g, getLocalBounds());
55+
}
56+
57+
private:
58+
void updateListOfSvgFiles()
59+
{
60+
yup::File riveBasePath = yup::File (__FILE__)
61+
.getParentDirectory()
62+
.getParentDirectory()
63+
.getParentDirectory();
64+
65+
auto files = riveBasePath.getChildFile ("data/svg").findChildFiles (yup::File::findFiles, false, "*.svg");
66+
if (files.isEmpty())
67+
return;
68+
69+
for (const auto& svgFile : files)
70+
svgFiles.add (svgFile);
71+
}
72+
73+
void parseSvgFile (int index)
74+
{
75+
if (svgFiles.isEmpty())
76+
return;
77+
78+
if (index < 0)
79+
index = svgFiles.size() - 1;
80+
81+
if (index >= svgFiles.size())
82+
index = 0;
83+
84+
currentSvgFileIndex = index;
85+
86+
YUP_DBG ("Showing " << svgFiles[currentSvgFileIndex].getFullPathName());
87+
88+
drawable.clear();
89+
drawable.parseSVG (svgFiles[currentSvgFileIndex]);
90+
91+
repaint();
92+
}
93+
94+
yup::Drawable drawable;
95+
Array<yup::File> svgFiles;
96+
int currentSvgFileIndex = 0;
97+
};
98+
99+
} // namespace yup

examples/graphics/source/examples/VariableFonts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class VariableFontsExample : public yup::Component
128128
g.setFillColor (findColor (yup::DocumentWindow::Style::backgroundColorId).value_or (yup::Colors::dimgray));
129129
g.fillAll();
130130

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

134134
if (feather > 0.0f)

examples/graphics/source/main.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "examples/Paths.h"
4141
#include "examples/PopupMenu.h"
4242
#include "examples/TextEditor.h"
43+
#include "examples/Svg.h"
4344
#include "examples/VariableFonts.h"
4445
#include "examples/Widgets.h"
4546

@@ -222,6 +223,19 @@ class CustomWindow
222223
addChildComponent (components.getLast());
223224
}
224225

226+
{
227+
auto button = std::make_unique<yup::TextButton> ("SVG");
228+
button->onClick = [this, number = counter++]
229+
{
230+
selectComponent (number);
231+
};
232+
addAndMakeVisible (button.get());
233+
buttons.add (std::move (button));
234+
235+
components.add (std::make_unique<yup::SvgDemo>());
236+
addChildComponent (components.getLast());
237+
}
238+
225239
selectComponent (0);
226240

227241
startTimerHz (10);

0 commit comments

Comments
 (0)