Print Page | Close Window

DPI issues with PNG icons and XTP 20.1

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
Printed Date: 04 July 2022 at 6:07am
Software Version: Web Wiz Forums 12.04 -

Topic: DPI issues with PNG icons and XTP 20.1
Posted By: Fredrik
Subject: DPI issues with PNG icons and XTP 20.1
Date Posted: 21 September 2021 at 9:10am

Has anyone gotten their application look OK using bitmap icons in the ribbon using XTP 20.1? With DPI image scaling enabled I don't get any 'large' icons (Paste button should have been a large icon -  xtpButtonIconAndCaptionBelow - but here displayed as xtpButtonIconAndCaption regardless of width of the application and reduction mode). 

Using the RibbonExample I have not found the combination to make the icons look good (well, as good as the can being stretched from 32px version). I have 250% scaling on my screen

Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0

Posted By: astoyan
Date Posted: 27 September 2021 at 9:53pm
Try to add this line at some place before any UI is created:


The behavior of bitmap scaling has changed by default in version 20.1, that line enables it globally.

Posted By: Fredrik
Date Posted: 28 September 2021 at 3:51am
Hi, thanks for the reply.

I tried the solution but still no improvements - no icons are shown with style xtpButtonIconAndCaptionBelow by default.

I add ribbon icons as 
xtpControlButton. Previously they were rendered xtpButtonIconAndCaptionBelow if there was room enough (if the application was wide enough)

If I specify 
xtpButtonIconAndCaptionBelow style, then they are displayed in that way, but no longer collapse in a good way. Also with this style they icon become larger than previously.

Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0

Posted By: rdhd
Date Posted: 11 November 2021 at 10:51am
We do our own scaling using WIC (Windows Imaging Component) which does a pretty good job. WIC has now added cubic filtering too. We load our 16x16 and 32x32 icons into the image manager. Then I examine the system DPI and if > 100 (might be 125), we take each glyph and run it through WIC to scale it and then give it to the image manager too. I have a 4k monitor as part of my 3 monitor desktop config and use it as primary and set to 200%. So, I am always scaling our 32x32 icons to 64x64 and so far we have not found a reason to create a set of 64x64 icons. At some point, even WIC will fail to produce images that are good enough but so far we have had no complaints. Now, when will I get that 8k monitor so I can find out how it works scaling 32x32 to 128x128? Rats. Boss says "Not anytime soon."

Historically, WIC, if driven properly, has worked better than any GDI scaling even when one enables halftone filtering. It isn't too hard to use. Our display guy has some template wrappers around WIC that make the calls I use one liners.

Posted By: Fredrik
Date Posted: 11 November 2021 at 7:15pm
Thanks for your tip with WIC - I will check it out!

However, I don't think it will solve my problems for now. We have a show stopper problem with 19.3 and the property grid control. Looks like it has been fixed in 20/20 but then I have another show stopper easily reproduced with RibbonMDISample: just modify CMainFrame::LoadIcons() to always call LoadRasterIcons() and nothing more: I want the ribbon icons have the style icon and caption below - the default style when there is enough room. I hope there is an easy fix, since it looks like I am the only one complaining about this? 

Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0

Posted By: maureencurtis
Date Posted: 26 November 2021 at 7:45am
I initially had everything right and convenient.

Posted By: rdhd
Date Posted: 26 November 2021 at 3:51pm
I usually find the painting code and step thru it when I have an icon or other issue. You can also add code to get the icon size and/or the icon set and see what sizes are available. Also, we don't rely on defaults as they change over time so when we want a large icon and caption below we explicitly set the style for icon and caption below on any control we want it on.. Not at work so I'm not able to run the sample I have (has the same look when I set raster icons as your image) and debug the CJ code right now. I think I find some API like "drawcontrolparent". Usually takes me a few searches before I recognize the code and set a BP that trips.

Posted By: Fredrik
Date Posted: 27 November 2021 at 5:08pm
... ok.. so I have 250% scaling on my primary monitor, and I am not using XAML icons...

In CXTPRibbonGroup::OnBeforeCalcSize(CDC* pDC), GetRibbonBar()->GetLargeIconSize(FALSE/*bAutoSize*/); is called with FALSE indicating we want the size of large icons not adjusted for DPI. However, this function returns CSize(80, 80)  (= 32 * 2.5) for me which is not what is wanted since the return value should not have been scaled for DPI. 

Looking at CSize CXTPCommandBar::GetLargeIconSize(BOOL bAutoSize) we see that if m_pOptions->szIcons is empty, the return value will be 2 * XTPSystemMetrics()->GetSmallIconSize() regardless the value of bAutoSize.

Back to CXTPRibbonGroup::OnBeforeCalcSize we see that pControl->GetImageManager()->IsPrimaryImageExists will return false because an icon with the size {80, 80} does not exists in the icon set. And then, when IsPrimaryImageExists returns false the next statement pControl->m_buttonRibbonStyle will be set to xtpButtonIconAndCaption instead of xtpButtonIconAndCaptionBelow since it thinks that no image should be drawn. (But later in the code an image will be drawn anyway.)

If I modify GetLargeIconSize to the following it seems like it works. 

CSize CXTPCommandBar::GetLargeIconSize(BOOL bAutoSize) const
CSize sz = m_szIcons != CSize(0) ? m_szIcons : (pCommandBars->m_pOptions->szIcons != CSize(0)
                         ? pCommandBars->m_pOptions->szIcons
                         : bAutoSize ? XTPSystemMetrics()->GetSmallIconSize() // <--
                                     : XTP_UNDPI(XTPSystemMetrics()->GetSmallIconSize())); // <--



Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0

Posted By: dbrookes
Date Posted: 20 December 2021 at 1:11am
Can anyone confirm if this has been fixed in the 20.2 release? I'm too lazy to download it :)

Posted By: Fredrik
Date Posted: 20 December 2021 at 7:28pm
No, it is not fixed in the 20.2 release.

Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0

Posted By: Fredrik
Date Posted: 24 April 2022 at 5:05pm
... and it is not fixed in the 20.3 release.

Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0

Print Page | Close Window

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