|
| 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 |
0 commit comments