Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - DPI issues with PNG icons and XTP 20.1
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

DPI issues with PNG icons and XTP 20.1

 Post Reply Post Reply
Author
Message
Fredrik View Drop Down
Senior Member
Senior Member


Joined: 22 June 2005
Status: Offline
Points: 203
Post Options Post Options   Thanks (0) Thanks(0)   Quote Fredrik Quote  Post ReplyReply Direct Link To This Post Topic: DPI issues with PNG icons and XTP 20.1
    Posted: 21 September 2021 at 9:10am
Hi, 

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
Back to Top
astoyan View Drop Down
Admin Group
Admin Group
Avatar

Joined: 24 August 2013
Status: Offline
Points: 241
Post Options Post Options   Thanks (0) Thanks(0)   Quote astoyan Quote  Post ReplyReply Direct Link To This Post Posted: 27 September 2021 at 9:53pm
Try to add this line at some place before any UI is created:

XTPDpiHelper()->EnableDpiBitmapScaling();

The behavior of bitmap scaling has changed by default in version 20.1, that line enables it globally.
Back to Top
Fredrik View Drop Down
Senior Member
Senior Member


Joined: 22 June 2005
Status: Offline
Points: 203
Post Options Post Options   Thanks (0) Thanks(0)   Quote Fredrik Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 761
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Fredrik View Drop Down
Senior Member
Senior Member


Joined: 22 June 2005
Status: Offline
Points: 203
Post Options Post Options   Thanks (0) Thanks(0)   Quote Fredrik Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
maureencurtis View Drop Down
Newbie
Newbie
Avatar

Joined: 26 November 2021
Location: USA/Chicago
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote maureencurtis Quote  Post ReplyReply Direct Link To This Post Posted: 26 November 2021 at 7:45am
I initially had everything right and convenient
Back to Top
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 761
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Fredrik View Drop Down
Senior Member
Senior Member


Joined: 22 June 2005
Status: Offline
Points: 203
Post Options Post Options   Thanks (0) Thanks(0)   Quote Fredrik Quote  Post ReplyReply Direct Link To This Post 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
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.063 seconds.