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: 235
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: 303
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: 235
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: 886
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: 235
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: 886
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: 235
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
dbrookes View Drop Down
Groupie
Groupie


Joined: 30 August 2019
Location: Australia
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote dbrookes Quote  Post ReplyReply Direct Link To This Post 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 :)
Back to Top
Fredrik View Drop Down
Senior Member
Senior Member


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


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


Joined: 22 June 2005
Status: Offline
Points: 235
Post Options Post Options   Thanks (0) Thanks(0)   Quote Fredrik Quote  Post ReplyReply Direct Link To This Post Posted: 03 November 2022 at 7:49pm
... and it is not fixed in the 22.0 release.
Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0
Back to Top
Fredrik View Drop Down
Senior Member
Senior Member


Joined: 22 June 2005
Status: Offline
Points: 235
Post Options Post Options   Thanks (0) Thanks(0)   Quote Fredrik Quote  Post ReplyReply Direct Link To This Post Posted: 09 May 2024 at 4:03pm
... and it is not fixed in the v24.0.0 (Beta 1) release.
Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0
Back to Top
agontarenko View Drop Down
Admin Group
Admin Group


Joined: 25 March 2016
Status: Offline
Points: 289
Post Options Post Options   Thanks (1) Thanks(1)   Quote agontarenko Quote  Post ReplyReply Direct Link To This Post Posted: 16 May 2024 at 4:28am
Hello,

I've checked RibbonMDISample and found that not all images are scaled when "Enable DPI Icons Scaling" option enabled.

I changed next function
void CMainFrame::OnDpiIconsScaling()
I added line, that discribed by my collegue in this forum thread
XTPDpiHelper()->EnableDpiBitmapScaling();
after all images are scaled as expected.

So, I problem with DPI scaling png images was solved.

Regards,
Artem Gontarenko

Back to Top
Fredrik View Drop Down
Senior Member
Senior Member


Joined: 22 June 2005
Status: Offline
Points: 235
Post Options Post Options   Thanks (0) Thanks(0)   Quote Fredrik Quote  Post ReplyReply Direct Link To This Post Posted: 16 May 2024 at 9:31am
But notice on your screenshot that the layout is wrong. The icons are displayed using style (xtpButtonIconAndCaption) even though there is plenty of space and they are added as

pGroupFile->Add(xtpControlButton, ID_FILE_NEW);
pGroupFile->Add(xtpControlButton, ID_FILE_OPEN);
pGroupFile->Add(xtpControlButton, ID_FILE_CLOSE);

When you use SVG icons the style becomes 
xtpButtonIconAndCaptionBelow.

Compare with this screenshot: this is how I want the layout but it is no longer possible after 19.3. (Here I have applied the workaround I posted couple of years ago).





Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0
Back to Top
Fredrik View Drop Down
Senior Member
Senior Member


Joined: 22 June 2005
Status: Offline
Points: 235
Post Options Post Options   Thanks (0) Thanks(0)   Quote Fredrik Quote  Post ReplyReply Direct Link To This Post Posted: 16 May 2024 at 9:41am
Artem -if you look in my post from Posted: 2021 November 12 at 1:15am an 2021 November 27 at 11:08pm - after the 19.3 release it is no longer possible to have a large icon with the caption below if you use PNG images for the ribbon. 
Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0
Back to Top
agontarenko View Drop Down
Admin Group
Admin Group


Joined: 25 March 2016
Status: Offline
Points: 289
Post Options Post Options   Thanks (0) Thanks(0)   Quote agontarenko Quote  Post ReplyReply Direct Link To This Post Posted: 22 May 2024 at 4:07am
Hello,

I found, that Ribbon button size changed by depends from PNG image size.
So if you use different DPIs, you should be add PNG for each DPI.
For example: PNG icon 16x16 will be used with 100%DPI and PNG icon 32x32 will be used with  200%DPI etc.

See please MultiLangRibbon as example.

And you can to use XAML/SVG icons to exclude DPI scale problems.

Regargs,
Artem Gontarenko
Back to Top
Fredrik View Drop Down
Senior Member
Senior Member


Joined: 22 June 2005
Status: Offline
Points: 235
Post Options Post Options   Thanks (0) Thanks(0)   Quote Fredrik Quote  Post ReplyReply Direct Link To This Post Posted: 23 May 2024 at 4:28am
I think you missed the point again.

I can't use XAML/SVG icons basically because then someone has to generate them for me and that is not happening. 

Using the MDI Ribbon Look at the difference between the Office 2016 theme and Office 2007 theme. In the Office 2007 theme the New, Open, Close button are stacked ontop of each other even though there is space, and even though if I would change the code to below. This is a regression since XTP 19.3. 


pView->AddCommand(ID_FILE_SAVE)->SetStyle(xtpButtonIconAndCaptionBelow);
pView->AddCommand(ID_FILE_OPEN)->SetStyle(xtpButtonIconAndCaptionBelow);
pView->AddCommand(ID_FILE_PRINT_SETUP)->SetStyle(xtpButtonIconAndCaptionBelow);
pView->AddCommand(ID_FILE_PRINT_PREVIEW)->SetStyle(xtpButtonIconAndCaptionBelow);
pView->AddCommand(ID_FILE_PRINT)->SetStyle(xtpButtonIconAndCaptionBelow);
pView->AddCommand(ID_APP_EXIT)->SetStyle(xtpButtonIconAndCaptionBelow);

The buttons above are not adhering to xtpButtonIconAndCaptionBelow style. 

I am using 2013 theme myself, but same thing there. 





Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0
Back to Top
agontarenko View Drop Down
Admin Group
Admin Group


Joined: 25 March 2016
Status: Offline
Points: 289
Post Options Post Options   Thanks (0) Thanks(0)   Quote agontarenko Quote  Post ReplyReply Direct Link To This Post Posted: 29 May 2024 at 3:46am
Hello,

CXTPCommandBarsOptions has two variables:
    CSize szIcons;        // Size of the normal icons.
    CSize szLargeIcons; // Size of the large icons.

By default it 0.
You need to change them and icon size will be obtained from CXTPCommandBarsOptions in
CXTPCommandBar::GetLargeIconSize function.
So icon size will be same as PNG icon size.




Regards,
Artem Gontarenko
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.156 seconds.