Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Disabling Vector
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Disabling Vector

 Post Reply Post Reply
Author
Message
navap View Drop Down
Groupie
Groupie
Avatar

Joined: 11 June 2019
Location: India
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote navap Quote  Post ReplyReply Direct Link To This Post Topic: Disabling Vector
    Posted: 17 September 2021 at 9:01am

I am trying to use xaml icons in command bar for my application.Previously I have used bitmap images for my ribbon bar , now I am trying to replace them with xaml icons. I have followed the codejock sample "CommandBarIcons" . I have following queries 

1. How do I disable this vector icon ? I have tried using below method , but I am not able to disable the icon. Is there any other call which I am missing ?
XTPImageManager()->SetVectorIcon(_T("RT_XAML"), IDR_XAML_ICON_DISABLED_SAVEALL, ID_FILE_SAVEALL, XTP_DPI_X(16), xtpImageDisabled);
2. Also is there any method which automatically disables the icon , like in bitmap image (which doesn't require any gray-image). 

Thanks,
Navap
Back to Top
astoyan View Drop Down
Admin Group
Admin Group
Avatar

Joined: 24 August 2013
Status: Online
Points: 241
Post Options Post Options   Thanks (1) Thanks(1)   Quote astoyan Quote  Post ReplyReply Direct Link To This Post Posted: 18 September 2021 at 9:43pm
Setting an icon with xtpImageDisabled only adds that image into the image collection and tells it that it's associated with a disabled state of a control where it will be used in, but it does not make it to use the disabled icon right away. Whenever a command bar button is in disabled state its paint manager will try to obtain and draw an xtpImageDisabled icon.

And there is no method to make a disabled icon automatically.
Back to Top
markr View Drop Down
Senior Member
Senior Member


Joined: 01 August 2004
Status: Offline
Points: 429
Post Options Post Options   Thanks (1) Thanks(1)   Quote markr Quote  Post ReplyReply Direct Link To This Post Posted: 19 September 2021 at 12:12am
My approach to solving this was to hack together some code that loads the XAML icon from resources and replaces any colors it uses with a light shade of gray. It is then stored in the image list for use by the "disabled" state.

Yeah, it's ugly - but preferable to creating and storing all the disabled vector variants separately.
Back to Top
navap View Drop Down
Groupie
Groupie
Avatar

Joined: 11 June 2019
Location: India
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote navap Quote  Post ReplyReply Direct Link To This Post Posted: 20 September 2021 at 8:54am
Thanks for the response . I am able to enable/disable the icon when command bar button state is changed . However my concern is that I have to maintain 4 sets of icons (normal-large, normal-small, disabled-large, disabled-small) if I have to go with vector icons, previously i.e. while using bmp icons it was only 2 sets of icons (large and small). 

I am trying to understand if there any better way to handle this. Loading file and changing its attributes programmatically is the best logic I could come across. 
Thanks,
Navap
Back to Top
dbrookes View Drop Down
Groupie
Groupie


Joined: 30 August 2019
Location: Australia
Status: Offline
Points: 58
Post Options Post Options   Thanks (0) Thanks(0)   Quote dbrookes Quote  Post ReplyReply Direct Link To This Post Posted: 20 September 2021 at 9:15pm
I do a similar thing to markr, except at pre-compile time. I have a powershell script that runs over the XAML XML and grayscales any colours to create disabled variants of icons.

All my icons are stored in a tar gz archive that I load and create vector icon handles at runtime. I don't store icons in a resource DLL.

I guess it depends how many icons your dealing with whats worth it for you. If you haven't got a large number of icons its probably fine to grab the XAML from your resource DLL and to generate disabled variants at runtime. 
Product: ToolkitPro v19.1.0
OS: Windows 10
Language: C++ (VS2019)
Back to Top
markr View Drop Down
Senior Member
Senior Member


Joined: 01 August 2004
Status: Offline
Points: 429
Post Options Post Options   Thanks (0) Thanks(0)   Quote markr Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2021 at 6:35pm
> If you haven't got a large number of icons its probably fine to grab the XAML...

More icons = better software Shocked
Back to Top
Pesci7 View Drop Down
Newbie
Newbie
Avatar

Joined: 27 January 2021
Location: Italy
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote Pesci7 Quote  Post ReplyReply Direct Link To This Post Posted: 29 September 2021 at 6:20am
Is it better lo load icons from an external file instead of from resources?

Actually I had to add a splash screen on startup because of initial icons loading.

Any advice?
Thanks
Product: Xtreme ToolkitPro (20.1.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2019 (C++)
Back to Top
dbrookes View Drop Down
Groupie
Groupie


Joined: 30 August 2019
Location: Australia
Status: Offline
Points: 58
Post Options Post Options   Thanks (0) Thanks(0)   Quote dbrookes Quote  Post ReplyReply Direct Link To This Post Posted: 06 October 2021 at 6:10am
There are benefits but also downsides. A benefit being avoiding have to add resource ids and so on for each icon, icon size and icon state. It is more work to setup loading from an external source. You have to map those to command ids at some point. We do have a resource DLL of course full of all the usual stuff, just not our icons. I doubt there is a big performance difference one way or the other. If I had to guess resources would be faster. Recently I found for this use case that .tar.gz is a fair bit faster than .zip with similar compression so switched to that.

As for vector icon loading it self. I too found that the performance of that can be a problem. We added around 4 seconds to our loading time when we moved to using vector icons. Not to mention around ~400mb more initial memory usage. We do have quite a lot of icons so are probably an outlier. Around 1200 icons total, each with a small and large, and with a normal and disabled state. So that makes around 5000 icon handles to load. Loading all that markup takes a lot of time.

You can save a little bit of time by minifying your XAML at pre-compile time but that'll only get you so far.

One thing I tested out was loading these on a worker thread but this stuff is just generally not thread safe. This is a bad idea.

Here is a patch someone might find interesting...

CXTPImageManagerVectorImageHandles actually already keep a copy of the XAML in their serialization data buffer. Piggy backing off of this we can delay building the markup UI element until we first try and draw the vector icon rather than immediately. If you have a ribbon like we do this means icons are built as they become visible when switching tabs. Building a tab worth of icons is quick enough its not noticeable. Similarly the disabled icon for things won't be built until they are needed. This took our loading time from 4 seconds to around 27ms and took our initial memory usage way down. That memory usage grows over time as icons are built on demand.

This delayed markup building idea can be used for markup list boxes as well by the way if you have a very large number of items to deal with. This only works for fixed height owner draw though since we can't measure the markup if it isn't built for variable height owner draw. The former is better for performance usually anyway.
Product: ToolkitPro v19.1.0
OS: Windows 10
Language: C++ (VS2019)
Back to Top
Pesci7 View Drop Down
Newbie
Newbie
Avatar

Joined: 27 January 2021
Location: Italy
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote Pesci7 Quote  Post ReplyReply Direct Link To This Post Posted: 06 October 2021 at 12:39pm
Should I change SetVectorIcon, SetVectorDisabledIcon, ... methods to call CreateDelayedMarkupHandle instead of CreateMarkupHandle to use this patch?


Product: Xtreme ToolkitPro (20.1.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2019 (C++)
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.031 seconds.