HISE Logo Forum
    • Categories
    • Register
    • Login

    Native SVG import?

    Scheduled Pinned Locked Moved Feature Requests
    figmasvgvectorpaint routinejuce
    16 Posts 6 Posters 1.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d.healeyD
      d.healey @Straticah
      last edited by

      @Straticah Yup

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      Christoph HartC 1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart @d.healey
        last edited by

        You can parse SVG images and draw them in JUCE (in fact the shiny scriptnode logo in the HISE workspace is a SVG), but I haven't added a wrapper for HiseScript yet. It will probably look like this to be consistent with the path handling:

        const var svg = Content.createSVG("sjdlfkjhsldfg8798275345");
        
        panel.setPaintRoutine(function(g)
        {
            g.drawSVG(svg, this.getLocalBounds(0));
        }
        

        Given that SVG is a XML file which is always annoying to use inside a Javascript-like context, we would have to wrap it in a Base64 String (I would add this to the Path converter window in HISE).

        d.healeyD StraticahS 2 Replies Last reply Reply Quote 5
        • d.healeyD
          d.healey @Christoph Hart
          last edited by

          @Christoph-Hart Excellent!

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          1 Reply Last reply Reply Quote 0
          • Dan KorneffD
            Dan Korneff
            last edited by

            That would be great!

            Dan Korneff - Producer / Mixer / Audio Nerd

            1 Reply Last reply Reply Quote 0
            • StraticahS
              Straticah @Christoph Hart
              last edited by

              @Christoph-Hart 🖤

              building user interfaces in HISE :)
              web: www.vst-design.com

              Christoph HartC 1 Reply Last reply Reply Quote 0
              • Christoph HartC
                Christoph Hart @Straticah
                last edited by

                Alright, here we go:

                460abcde-5160-4dc8-a096-1b258d256973-image.png

                1. Use the converter window (Tools -> Convert SVG to Path).
                2. Select "Base64 SVG" as output format (this is important, otherwise it will just extract the first shape from the SVG as monochromatic path)
                3. Drag a SVG file in the window.
                4. It should preview the file on the right. This is WYSIWYG: if the SVG is not shown correctly here, it will not be shown correctly later. There are a few known issues with the JUCE SVG parser, but it should work with most SVG images quite OK.
                5. Click on copy to clipboard, and paste the line in the onInit callback of your script (or whatever).
                6. Use the API to create a SVG object and render it on a Panel.

                Below is an example that shows all new API calls (they do not show up in the autocomplete yet because I'm not on Windows but I'll add this on Monday).

                With some tricks you can create SVG animations too by using the provided Graphics functions:

                Content.makeFrontInterface(600, 600);
                
                const var atom = "243.nT6K8CF9.zzA.HQSp7AXGQO9msCBhJy1H+SMHfvbQbEcQ+2dyntPJAvIbmX.DL.gppGBqWQIsVp8DKFr162FctP0i0NLnwubgFWZVLTVHC3bIAdqhcRa+.c1TeTnVl4.gg8pt0ZOAkaW6QTtURRPbt.Z+qHhR4+3+Y9ztTFaX3iAvPWztikIdS+ASpsx8ZwXiiDWbjZOZVv8iPbCgpp0ZUnfzYAiag68pTDfvZcZu9HODwPn5KPFf.mRTo0Atn.7GvH.epfHf4tEuaMyPlj.CLYAhfW1KvVQ.pG9DiBrfFaaa.lrDIfMHEgpFwlRQzHLq2d."
                
                const var svg = Content.createSVG(atom);
                
                const var Panel1 = Content.getComponent("Panel1");
                
                
                
                Panel1.setPaintRoutine(function(g)
                {
                	var center = [this.get("width") / 2, this.get("height")/2];
                	
                	// offset the center (the SVG is not perfectly centered)
                	center[1] += 9;
                
                	g.rotate(this.data.rotation, center);
                	g.drawSVG(svg, this.getLocalBounds(20), this.data.alpha);	
                });
                
                Panel1.setTimerCallback(function()
                {
                	this.data.rotation += 0.01;
                	this.repaint();
                	
                	this.data.alpha = Math.sin(this.data.rotation * 12.0) * 0.5 + 0.5;
                });
                
                Panel1.startTimer(30);
                
                HiseSnippet 1261.3ocsVstbZaDEVx1pSf1LSyL8APC+BJtxRXGa73IS4tgXrs3hwNjIS5hzJoMVrqrzBDbm7t1Gg9FzdVIrARHY53ogeHz41te62dtHyPlENJhEJImp+7.rj7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ozpetIGmMZSjvDx78gEbSlS1puQfYoSFOBGtKjF5OA+niPqn06uo706usZ6Wqj72UbjQaQI7KCvzuVSYoEI8vaW0pFvmhlhKzA9AYYbh.Bx0vSgILIsHSoTCGcKmED66hJEXnAO15yenApf0kHPaxmojbCH8wGGBUBWZ9iB+0nRwkFOp3OhJkTTrbnEsjzW1qFlRvrm3C0zqM5PLubgAfuWqesnmLMhvmu57z+2lm7eEhuPwjvs71LF2ZCXDtU9dfwESgetRcGQyjk.bGkF278YjqTROSWnRNj.4CJWLYbO3CQrvvtSgrDQ9t7VhLyDYcgrfA5go1wB+C7agQCgr7BiFOXTZLxJj8dqjpLwb9mEqAvDM9SbRobtPV0PJtxChSA5BIMF9ji2aYIN9+FTrr4XJ7DhY+mPLG7Dh4kOgXN7IDyQOgXJ9MiQ70dkm.ylSJG.El0iaGIKWmhfLq3rPo+EF5ALq.
                
                orangeO ? 2 Replies Last reply Reply Quote 4
                • orangeO
                  orange @Christoph Hart
                  last edited by

                  @Christoph-Hart Perfect, Thank you!!

                  develop Branch / XCode 13.1
                  macOS Monterey / M1 Max

                  1 Reply Last reply Reply Quote 1
                  • ?
                    A Former User @Christoph Hart
                    last edited by A Former User

                    @Christoph-Hart that's amazing thanks a lot <3

                    BTW if I understand correctly, we have only draw path option in the Hise SVG to Path converter.

                    Could you add also Fill Path and Close sub-path options too? Because in most cases just filling the path is the way to go especially for icons, personally I don't use draw path way too much.

                    If you add these options, I hope it will be available for this current .createSVG method too.

                    JJJJJ.jpg

                    d.healeyD 1 Reply Last reply Reply Quote 0
                    • d.healeyD
                      d.healey
                      last edited by

                      That was quick!

                      Libre Wave - Freedom respecting instruments and effects
                      My Patreon - HISE tutorials
                      YouTube Channel - Public HISE tutorials

                      1 Reply Last reply Reply Quote 0
                      • d.healeyD
                        d.healey @A Former User
                        last edited by

                        @Steve-Mohican said in Native SVG import?:

                        @Christoph-Hart that's amazing thanks a lot <3

                        BTW if I understand correctly, we have only draw path option in the Hise SVG to Path converter.

                        Could you add also Fill Path and Close sub-path options too? Because in most cases just filling the path is the way to go especially for icons, personally I don't use draw path way too much.

                        If you add these options, I hope it will be available for this current .createSVG method too.

                        You can do this from within HISE. Use the function g.fillPath() instead of g.drawPath()

                        Libre Wave - Freedom respecting instruments and effects
                        My Patreon - HISE tutorials
                        YouTube Channel - Public HISE tutorials

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        33

                        Online

                        1.7k

                        Users

                        11.7k

                        Topics

                        102.3k

                        Posts