DPI awareness for icons in Ribbon |
Post Reply |
Author | ||||
sbinder
Groupie Joined: 22 November 2004 Location: Austria Status: Offline Points: 76 |
Post Options
Thanks(0)
Posted: 03 June 2016 at 6:03am |
|||
When I enable DPI awareness for my ribbon (SetDPIScallingOptions(TRUE, TRUE)) I get a horrible result once my DPI settings are up to 100%. 125% Icon sizes: Same problem with controls I posted months ago! http://forum.codejock.com/forum_posts.asp?TID=22965&title=dpi-cxtpbutton I can't use version 17 because of the problem with the controls. There is no way to disable DPI-awareness for buttons. |
||||
olebed
Admin Group Joined: 01 July 2014 Location: Ukraine Status: Offline Points: 841 |
Answer Post Options Thanks(0) |
|||
Hello,
Final size of icons depend on type of commandBar, style of button, options of CommandBar.
So if you set CXTPCommandBar::m_szIcons with CXTPCommandBar::SetIconSize() to some value (except CSize(0)) then this size will be used as size of normal icons and m_szIcons*2 for large icons. If you don't set CXTPCommandBar::m_szIcons then pOptions->szIcons and pOptions->szLargeIcons will be used. If pOptions->szIcons and pOptions->szLargeIcons are CSize(0) then CommandBars will use auto size (CXTPPaintManager::GetAutoIconSize). Default sizes of icon is 16x16 and 32x32. But if you set to TRUE CXTPPaintManager::m_bAutoResizeIcons then icon size will be depend on height of control which use icon ( GetControlHeight() ) and size will be multiple 8 (8x8, 16x16, 24, 32, 40, 48, 56, 64,...). So you can create icons for all these sizes to be sure in nice icons. Also value of m_nEditHeight in CXTPPaintManager::GetControlHeight() depend on system font (e.g. different in Win7 and Win8 even on the same DPI). Next is choosing of icon from iconSet in CXTPImageManagerIconSet::GetIcon(UINT nWidth, BOOL bScaled). This method returns icon which has the less difference between their size and calculated/presetted size (calls which described above). The best case is to have icon with the same size as nWidth. In other case returned icon can be bigger or smaller then needed size. In this case icon will be drawn in calculated size (not original) and will be scaled and blurred. If icon isn't square then it can be stretched with next code:
But scaled icons looks very bad and now best way is to have iconset for many sizes (8x8, 16x16, 24, 32, 40, 48, 56, 64,...) without DPI scalling. Here below is code which I used for testing icons scaling in Samples\Ribbon\RibbonMDISample\MainFrm.cpp to load icons with many different sizes.
Regards, Oleksandr Lebed
|
||||
markr
Senior Member Joined: 01 August 2004 Status: Offline Points: 443 |
Post Options
Thanks(0)
|
|||
It seems super bizarre to me that this still hasn't been addressed.
Guys, please check how BCGSoft handles this stuff. Their ribbon bar and button icons scale smoothly to whatever DPI is being used.
- Mark R.
|
||||
sbinder
Groupie Joined: 22 November 2004 Location: Austria Status: Offline Points: 76 |
Post Options
Thanks(0)
|
|||
Only reason that i still use Codejock is that it would be hard and time consuming job to exchange it.
When i bought it 11 years ago, release cycles where fast, and Bugs got fixed in time. Now i got confirmed bugs in the ticket system that are open for years...
|
||||
Marco1
Senior Member Joined: 16 January 2004 Location: Germany Status: Offline Points: 251 |
Post Options
Thanks(0)
|
|||
What's the alternative? We are using the Outlook Calendar view as main part of our app and apart from all the actual problems it's very cool. We evaluated the one of BCGSoft and this is still far away froms CJs. |
||||
sbinder
Groupie Joined: 22 November 2004 Location: Austria Status: Offline Points: 76 |
Post Options
Thanks(0)
|
|||
I have not really evaluated any alternatives yet.
It would need at least half a year to exchange codejock, therefore i currently have to deal with the problems. My concern is that the support is not working like it was in the past. DPI Awareness was a feature we where long waiting for, then there is a essential bug like this one, and i got no answer on a support ticket, no changes where made in the updates 17.1 and 17.2 So after 3 month with no reply, we worked around the issue, with checking the dpi on our own, and supply the right icon sizes explicitly
|
||||
markr
Senior Member Joined: 01 August 2004 Status: Offline Points: 443 |
Post Options
Thanks(0)
|
|||
To be clear, I am not advocating that you move away from CodeJock. I don't know anything about your product(s) and XTP does a lot of things right (markup support in particular is super useful). However, I would like to point out that CodeJock can be used in conjunction with other commercial MFC libraries. With a little planning and effort, it's possible to leverage the strengths of each of them without re-writing all the UI components of your app(s) at once.
Would you mind sharing more information about how you did this? - Mark R.
|
||||
sbinder
Groupie Joined: 22 November 2004 Location: Austria Status: Offline Points: 76 |
Post Options
Thanks(0)
|
|||
wrote a simple function (could be extended, but ok for my current needs), that calculates the best fitting icon size. then using this size explicitly when setting an icon. (for command bars i disabled pCommandBars->GetPaintManager()->m_bAutoResizeIcons { //if(bLimitSquare32 && sz.cx > 32) return sz; double x = (double)sz.cx*gdDPIProzX; double y = (double)sz.cy*gdDPIProzY; if(!bSquare) return CSize((int)x, (int)y); if(bChooseBigger) { if(!bLimitSquare32 && x > 48) return CSize(64,64); if(!bLimitSquare32 && x > 40) return CSize(48,48); if(!bLimitSquare32 && x > 32) return CSize(40,40); if(x > 24) return CSize(32,32); if(x > 20) return CSize(24,24); if(x > 16) return CSize(20,20); return sz; } if(!bLimitSquare32 && x >= 64) return CSize(64,64); if(!bLimitSquare32 && x >= 48) return CSize(48,48); if(!bLimitSquare32 && x >= 40) return CSize(40,40); if(x >= 32) return CSize(32,32); if(x >= 24) return CSize(24,24); if(x >= 20) return CSize(20,20); if(x >= 16) return CSize(16,16); return sz; } and yes. i like the features of toolkit! i also dont have a problem when there are some bugs, only thing i dont like is writing support tickets without getting replies...
|
||||
HTS10
Newbie Joined: 16 September 2010 Status: Offline Points: 8 |
Post Options
Thanks(1)
|
|||
I had the same problem. You need to set pCommandBars->GetCommandBarsOptions()->szLargeIcons size and after that, ribbon does not scale the icons.
|
||||
olebed
Admin Group Joined: 01 July 2014 Location: Ukraine Status: Offline Points: 841 |
Answer Post Options Thanks(0) |
|||
Hello,
Final size of icons depend on type of commandBar, style of button, options of CommandBar.
So if you set CXTPCommandBar::m_szIcons with CXTPCommandBar::SetIconSize() to some value (except CSize(0)) then this size will be used as size of normal icons and m_szIcons*2 for large icons. If you don't set CXTPCommandBar::m_szIcons then pOptions->szIcons and pOptions->szLargeIcons will be used. If pOptions->szIcons and pOptions->szLargeIcons are CSize(0) then CommandBars will use auto size (CXTPPaintManager::GetAutoIconSize). Default sizes of icon is 16x16 and 32x32. But if you set to TRUE CXTPPaintManager::m_bAutoResizeIcons then icon size will be depend on height of control which use icon ( GetControlHeight() ) and size will be multiple 8 (8x8, 16x16, 24, 32, 40, 48, 56, 64,...). So you can create icons for all these sizes to be sure in nice icons. Also value of m_nEditHeight in CXTPPaintManager::GetControlHeight() depend on system font (e.g. different in Win7 and Win8 even on the same DPI). Next is choosing of icon from iconSet in CXTPImageManagerIconSet::GetIcon(UINT nWidth, BOOL bScaled). This method returns icon which has the less difference between their size and calculated/presetted size (calls which described above). The best case is to have icon with the same size as nWidth. In other case returned icon can be bigger or smaller then needed size. In this case icon will be drawn in calculated size (not original) and will be scaled and blurred. If icon isn't square then it can be stretched with next code:
But scaled icons looks very bad and now best way is to have iconset for many sizes (8x8, 16x16, 24, 32, 40, 48, 56, 64,...) without DPI scalling. Here below is code which I used for testing icons scaling in Samples\Ribbon\RibbonMDISample\MainFrm.cpp to load icons with many different sizes.
Regards, Oleksandr Lebed
|
||||
cpede
Senior Member Joined: 13 August 2004 Location: Denmark Status: Offline Points: 668 |
Post Options
Thanks(0)
|
|||
Thanks for the description.
But how do I prevent resizing of the icon image on e.g. a XTPButton on high DPI? And do I have to figure out the correct icon image size based on the DPI and set that for the XTPButton, or can the icon image automatically be selected from an image list ? -cpede
|
||||
Product: Xtreme ToolkitPro (24.0.0)
Platform: Windows 10 (x64) Language: Visual Studio 2017 (C++) |
||||
olebed
Admin Group Joined: 01 July 2014 Location: Ukraine Status: Offline Points: 841 |
Post Options
Thanks(0)
|
|||
Hello cpede,
That description is only for CommandBars (toolbars, menuBars, Ribbon and so on). Vlad (Vladimir) are working on dpi scaling in XTPButton. I think we improve it for next release. Regards, Lebed Oleksandr |
||||
markr
Senior Member Joined: 01 August 2004 Status: Offline Points: 443 |
Post Options
Thanks(0)
|
|||
Hello Lebed,
Thanks very much for this information. > But scaled icons looks very bad and now best way is to have iconset for many sizes (8x8, 16x16, 24, 32, 40, 48, 56, 64,...) without DPI scalling. Could you please create a sample application that illustrates the best practices you describe? Or perhaps one already exists? Regards, Mark R.
|
||||
olebed
Admin Group Joined: 01 July 2014 Location: Ukraine Status: Offline Points: 841 |
Post Options
Thanks(0)
|
|||
Hello Mark,
I did this with test icon set. For RibbonSample I need set of nice Office icons for all sizes. I will try to do this because sample really is not looking very good now |
||||
markr
Senior Member Joined: 01 August 2004 Status: Offline Points: 443 |
Post Options
Thanks(0)
|
|||
Hello Lebed,
I've been running some tests based on the information you provided above, and I'm not quite getting the results I expect. For my test, I took one application toolbar which normally has icon sizes of 32x32 and attempted to add support for 125% and 150% DPI scaling. So I created two new icon sets - one for 125% scaling (40x40) and another for 150% scaling (48x48). The command bars are created within a dialog window:
And the toolbar icons are set:
The results of this test:
Here's how the 48x48 icons appear in my toolbar (notice how they are jagged): Am I doing something incorrectly, or are my operating assumptions somehow incorrect? Thanks again for your time on this. - Mark R.
|
||||
markr
Senior Member Joined: 01 August 2004 Status: Offline Points: 443 |
Post Options
Thanks(0)
|
|||
Any thoughts on this? Am I doing something wrong?
- Mark R.
|
||||
olebed
Admin Group Joined: 01 July 2014 Location: Ukraine Status: Offline Points: 841 |
Post Options
Thanks(0)
|
|||
Hello Mark,
In your case algorithm needs 56x56 icons and take nearest exist 48x48 then scale they to 56x56. You can see what exactly size is needed in method CXTPPaintManager::GetAutoIconSize. On my virtual test machine Win7 with 125 % DPI GetControlHeight() returns 29, then int nHeight = GetControlHeight() - XTP_DPI_Y(4); // 29 - 5 = 24 then for small icons we get 24x24 and for large 48x48 100%: 23 - XTP_DPI_Y(4) -> 23 - 4 = 19 -> 16x16 and 32x32 120%: 27 - XTP_DPI_Y(4) -> 27 - 5 = 22 -> 16x16 and 40x40 125%: 29 - XTP_DPI_Y(4) -> 29 - 5 = 24 -> 24x24 and 48x48 135%: 31 - XTP_DPI_Y(4) -> 31 - 5 = 26 -> 24x24 and 48x48 150%: 35 - XTP_DPI_Y(4) -> 35 - 6 = 29 -> 24x24 and 56x56 175%: 41 - XTP_DPI_Y(4) -> 41 - 7 = 34 -> 32x32 and 64x64 200%: 47 - XTP_DPI_Y(4) -> 47 - 8 = 39 -> 32x32 and 72x72
Regards, Oleksandr Lebed |
||||
cpede
Senior Member Joined: 13 August 2004 Location: Denmark Status: Offline Points: 668 |
Post Options
Thanks(0)
|
|||
But, can't we get the closest icon size in the resources, without scaling it?
-cpede
|
||||
Product: Xtreme ToolkitPro (24.0.0)
Platform: Windows 10 (x64) Language: Visual Studio 2017 (C++) |
||||
markr
Senior Member Joined: 01 August 2004 Status: Offline Points: 443 |
Post Options
Thanks(0)
|
|||
> But, can't we get the closest icon size in the resources, without scaling it?
That's what I'd like to know as well. Scaling will almost always result in a lower quality experience when compared to simply choosing the closest fit (without scaling). - Mark R.
|
||||
olebed
Admin Group Joined: 01 July 2014 Location: Ukraine Status: Offline Points: 841 |
Post Options
Thanks(0)
|
|||
Hello,
Fix for icon's scaling for Ribbon's buttons with style xtpButtonIconAndCaptionBelow and when set some value for pCommandBars->m_pOptions->szLargeIcons in Source\CommandBars\XTPPaintManager.cpp
Regards, Oleksandr Lebed |
||||
Fredrik
Senior Member Joined: 22 June 2005 Status: Offline Points: 235 |
Post Options
Thanks(0)
|
|||
... this is the result of calling SetDPIScallingOptions(TRUE, TRUE) and using m_bAutoResizeIcons = TRUE: Thought they would be independent of each other? The reason I tried was just to see whether it is possible to get auto resized icons in backstage in v18 - it seems to be broken - or at least the behaviour has changed between 17 and 18.
|
||||
Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0
|
||||
olebed
Admin Group Joined: 01 July 2014 Location: Ukraine Status: Offline Points: 841 |
Post Options
Thanks(0)
|
|||
Hello Frederik,
Logic of option 'm_bAutoResizeIcons == TRUE' - calculate best size of normal and large icons for current font size (Size of Ribbon depend on font size). Also current font depend on current DPI so m_bAutoResizeIcons also gives resizing for HighDPI. That is why I think IsDPIIconsScallingEnabled is redundant. Also using these two options (TRUE) together give awful result. But there are cases where customers don't want use many icon sets for different DPI and they need this icon's scaling. So I'm going to change appointment of IsDPIIconsScallingEnabled(pButton) - allow any icon scaling only if it is TRUE else - will be used only original size of icons, except icon is bigger than button/control. Now I fix using IsDPIIconsScallingEnabled() in CXTPPaintManager::DrawControlToolBarParent /*case as on your screenshot*/ and going to add it in other places (drawing Combobox, Edit control, some themes (CXTPCommandBarsOffice2000Theme, CXTPCommandBarsOfficeXPTheme) Regards, Oleksandr Lebed |
||||
olebed
Admin Group Joined: 01 July 2014 Location: Ukraine Status: Offline Points: 841 |
Post Options
Thanks(0)
|
|||
The scaling of Ribbon icons have been fixed. Also some samples updated. Fix will be available soon in next release. As I wrote icons will be scaled only if option IsDPIIconsScallingEnabled() is TRUE or size of icon is bigger than button. Regards, Oleksandr Lebed |
||||
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |