Hot Door CORE Forum

Full Version: Adding SVG resources
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'd like to using SVG resources in my project, but I cannot get them to work. There's no example to follow, so I'm adapting the technique for PNGI images.

in IDtoFile:

29001.svg imgCompass-01.svg
29011.svg imgCompassDark-01.svg

in ResourceIDs.rh:

#define AT_compass1_SVG_RSRC_ID 29001
#define AT_compass1_SVG_RSRC_NAME "imgCompass-01"
#define AT_compass1_SVG_RSRC_FILE "imgCompass-01.svg"

#define AT_compass1_DARK_SVG_RSRC_ID 29011
#define AT_compass1_DARK_SVG_RSRC_NAME "imgCompassDark-01"
#define AT_compass1_DARK_SVG_RSRC_FILE "imgCompassDark-01.svg"

in Resources.r:

read 'SVG' (AT_compass1_SVG_RSRC_ID, AT_compass1_SVG_RSRC_NAME)  AT_compass1_SVG_RSRC_FILE;
read 'SVG' (AT_compass1_DARK_SVG_RSRC_ID, AT_compass1_DARK_SVG_RSRC_NAME)  AT_compass1_DARK_SVG_RSRC_FILE;

in Resources.rc:

AT_compass1_SVG_RSRC_ID SVG AT_compass1_SVG_RSRC_FILE
AT_compass1_DARK_SVG_RSRC_ID SVG AT_compass1_DARK_SVG_RSRC_FILE

In my main cpp file:

hdi::core::Label labl = hdi::core::Label(hdi::core::Rect(20,36,26,24),hdi::core::SVGWithRolloverIDs(
    AT_compass1_SVG_RSRC_ID,
    AT_compass1_DARK_SVG_RSRC_ID));
this->myDlg.addWidget(labl);

The SVG images are exported from Illustrator 2020, size 26x24 px, using the default export settings. No image appears in Illustrator 2020 on either Mac or Windows. What am I doing wrong?
Partial success: On Mac, in Xcode, Project > Build Phases > Run Script, add these lines:

mkdir "$INSTALL_DIR/$FULL_PRODUCT_NAME/Contents/Resources/svg" 2> /dev/null
cp "$PROJECT_DIR/../../../Images/"*.png "$INSTALL_DIR/$FULL_PRODUCT_NAME/Contents/Resources/png/"

I can't find anything in the Windows Visual Studio project that specifies any resource types. Any suggestions here would be very much appreciated!
On both Mac and Windows, the resource type name for PNG images is "PNGI"; similarly, for SVG images it's "SVG_"

Try using that in your *.r and *.rc files

It's worth noting that we found some limitations in SVG rendering at this time, so you might want to retain your PNG images just in case you need to fallback. We will likely look for another SVG rendering solution in the future that hopefully does not have the same limitations.

Before you ask, I don't remember all the limitations off the top of my head, but one was that rendering SVGs very early in the startup process didn't work very well. I would advise setting them as late as possible in your plugin (post)startup cycle, for now at least.
Thanks, Garrett, that worked! I had a hunch it was that 3-character descriptor.

Under Windows it displays the normal image but does not change to the rollover image. Works fine on Mac, though. The resources are loaded into a dialog box toward the end of postStartup. In the meantime I just set backgroundRollover to true for Windows, which highlights the image bounds, but at least it confirms that it senses the cursor. If I make more progress on it, I'll post it here.
I noticed that the announcement for CORE 0.7.5 includes "Label rollover image fixes" but perhaps that had nothing to do with SVG rollovers. I'm still having trouble with SVG rollover images showing up in labels under Windows. They're defined in the usual places (.rh, .r, .rc) and first added to a panel late in post-startup. Is there another approach I can take, or is this a continuing issue with SVG?

I sure do like working with SVG images, having one image for all sizes and being able to create them entirely in Illustrator.
A panel includes some labels with SVG images (no rollovers) that work well for me on Mac and Windows, but some Windows users see these images as white rectangles. Is there anything users or I could do to make these images show?
I'm still working on SVG images for plugins, this time specifically for panel dock icons. I found that when exporting SVG from Illustrator (File > Export for Screens), the art shows as black silhouettes only. I need to go to the gear icon for Format Settings, choose SVG from the list, and change the Styling to "Inline Style." That works for Mac, but In AI 2023 for Windows, panels won't even show, and if they were docked, they disappear from the dock.

I found that the .cpp file needs to explicitly #include "hdicoreSVGIDs.h" even though it copies and runs without doing so.

I define the panel dock images this way in declaring the panel:

hdi::core::SVGWithRolloverIDs(INSP_INSPECTORICON_SVG_RSRC_ID, INSP_INSPECTORICON_DARK_SVG_RSRC_ID)

and this way in the .rc file:

INSP_INSPECTORICON_SVG_RSRC_ID SVG_ INSP_INSPECTORICON_SVG_RSRC_FILE
INSP_INSPECTORICON_SVG_RSRC_NAME SVG_ INSP_INSPECTORICON_SVG_RSRC_FILE
INSP_INSPECTORICON_DARK_SVG_RSRC_ID SVG_ INSP_INSPECTORICON_DARK_SVG_RSRC_FILE
INSP_INSPECTORICON_DARK_SVG_RSRC_NAME SVG_ INSP_INSPECTORICON_DARK_SVG_RSRC_FILE

This works great for Mac, but the panel won't appear in Windows. I changed the panel declaration's SVGWithRolloverIDs to include all four IDs (light/dark plus repeating them for rollovers), but the panel still won't even show in Windows.

Any suggestions would be very much appreciated.