Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - DPI awareness for icons in Ribbon
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

DPI awareness for icons in Ribbon

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

Joined: 22 November 2004
Location: Austria
Status: Offline
Points: 76
Post Options Post Options   Thanks (0) Thanks(0)   Quote sbinder Quote  Post ReplyReply Direct Link To This Post Topic: DPI awareness for icons in Ribbon
    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.

Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Answer Answer
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 08 November 2016 at 11:53am
Hello,

Final size of icons depend on type of commandBar, style of button, options of CommandBar.
CSize CXTPPaintManager::GetIconSize(CXTPControl* pButton)
{
    XTPButtonStyle buttonStyle = pButton->GetStyle();

    CSize szIcon = buttonStyle == xtpButtonIconAndCaptionBelow
        && pButton->GetParent()->GetType() != xtpBarTypePopup ?
        pButton->GetParent()->GetLargeIconSize(m_bAutoResizeIcons) : pButton->GetIconSize();

    return szIcon;
}

CSize CXTPCommandBar::GetLargeIconSize(BOOL bAutoSize) const
{
    CXTPCommandBars* pCommandBars = GetCommandBars();

    if (!pCommandBars)
        return m_szIcons != CSize(0) ? CSize(2 * m_szIcons.cx, 2 * m_szIcons.cy) : CSize(32, 32);

    CSize sz = m_szIcons != CSize(0) ? m_szIcons: (pCommandBars->m_pOptions->szIcons != CSize(0) ?
        pCommandBars->m_pOptions->szIcons : CSize(16, 16));
        
    if (m_szButtons == CSize(0))
    {
        sz = bAutoSize ? GetAutoIconSize(TRUE) : 
            (pCommandBars->m_pOptions->szLargeIcons != CSize(0) ?
            pCommandBars->m_pOptions->szLargeIcons : CSize(sz.cx * 2, sz.cy * 2));
    }

    return sz;
}

CXTPControl::GetIconSize()  > CXTPRibbonBar::GetIconSize()  > CXTPCommandBar::GetAutoIconSize() > CXTPPaintManager::GetAutoIconSize()

CSize CXTPCommandBar::GetIconSize() const
{
    if (m_szIcons != CSize(0))
        return m_szIcons;

    CXTPCommandBars* pCommandBars = GetCommandBars();

    if (!pCommandBars)
        return CSize(16, 16);

    CXTPCommandBarsOptions* pOptions = pCommandBars->GetCommandBarsOptions();

    if (GetType() == xtpBarTypePopup)
    {
        return pOptions->szPopupIcons != CSize(0) ? pOptions->szPopupIcons :GetAutoIconSize(FALSE);
    }

    CSize sz = pOptions->szIcons != CSize(0) ? pOptions->szIcons : GetAutoIconSize(FALSE);

    if (pOptions->bLargeIcons && m_szButtons == CSize(0))
    {
        sz = pOptions->szLargeIcons != CSize(0) ? pOptions->szLargeIcons:GetAutoIconSize(TRUE);
    }

    return sz;
}

CSize CXTPPaintManager::GetAutoIconSize(BOOL bLarge) const
{
    if (m_bAutoResizeIcons)
    {
        int nHeight = GetControlHeight() - XTP_DPI_Y(4);
        if (bLarge) nHeight = nHeight * 2;

        nHeight = max(XTP_DPI_Y(2), nHeight / 8);

        return CSize(nHeight * 8, nHeight * 8);
    }

    return bLarge ? CSize(32, 32) : CSize(16, 16);
}

int CXTPPaintManager::GetControlHeight() const
{
    return max(XTP_COMMANDBAR_MIN_CONTROL_HEIGHT, m_nEditHeight);   // max(18, m_nEditHeight)
}
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:
CSize CXTPPaintManager::GetStretchIconSize(CXTPImageManagerIcon* pImage, CSize szIcon)
{
    if (!pImage)
        return szIcon;

    if (pImage->GetWidth()==0 || pImage->GetHeight()==0)
        return szIcon;

    int nHeight = XTP_DPI_Y(pImage->GetHeight()) * szIcon.cx / XTP_DPI_X(pImage->GetWidth());

    if (nHeight <= szIcon.cy + 1)
        return CSize(szIcon.cx, nHeight);

    int nWidth = szIcon.cy * XTP_DPI_X(pImage->GetWidth()) / XTP_DPI_Y(pImage->GetHeight());

    return CSize(nWidth, szIcon.cy);
}

Then size of icon can be scaled to system DPI coefficient if you call pOptions->SetDPIScallingOptions( __ , TRUE).
szIcon = (!bDPIIconsScallingEnabled) ? szStretchIcon :
    CSize(XTP_DPI_X(szStretchIcon.cx), XTP_DPI_Y(szStretchIcon.cy));

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.

void CMainFrame::OnOptionsStyle(UINT nStyle)
{
    ....
    LoadIcons();
    ....
    GetCommandBars()->GetPaintManager()->m_bAutoResizeIcons = TRUE;
    GetCommandBars()->GetCommandBarsOptions()->SetDPIScallingOptions(TRUE, FALSE);
    ....
}

void CMainFrame::LoadIcons()
{
  UINT uins[] = {  
     ID_EDIT_UNDO,0,0,0,0,ID_EDIT_PASTE,0,0,0,0 // 0
    ,ID_EDIT_COPY,0,0,0,0,ID_EDIT_SELECT,0,0,0,0 // 1
    ,ID_EDIT_REPLACE,0,0,0,ID_EDIT_FIND,0,0,0,0,0 // 2
    ,ID_EDIT_GOTO,0,0,0,0,0,0,0,0,0 // 3
    ,ID_FILE_NEW,0,0,0,0,0,0,0,0,0 // 4
    ,ID_FILE_PRINT,0,0,0,0,0,0,0,0,0 // 5
    ,ID_FILE_CLOSE,0,0,0,0,0,0,0,0,0 // 6
    ,ID_APP_ABOUT,0,0,0,0,0,0,0,0,0 // 7
    ,ID_VIEW_FULLSCREEN,0,0,0,0,0,0,0,0,0 // 8
    ,ID_WINDOW_ARRANGE,0,0,0,0,0,0,0,0,0 // 9
    ,ID_WINDOW_TILE_HORZ,0,0,0,0,0,0,0,0,0 // 10
    ,ID_WINDOW_CASCADE,0,0,0,0,0,ID_EDIT_CUT,0,0,0 // 11    
    ,ID_WINDOW_SWITCH,0,0,0,0,0,0,0,0,0 // 12
    ,ID_WINDOW_NEW,0,0,0,0,0,0,0,0,0 // 13
    ,ID_VIEW_NORMAL,0,0,0,0,0,0,0,0,0 // 14
    ,ID_FORMAT_PAINTER,0,0,0,0,0,0,0,0,0 // 15
    ,ID_FILE_PRINT_PREVIEW,0,0,0,0,0,0,0,0,0 // 16
    ,ID_FILE_SAVE,0,0,0,0,0,0,0,0,0 // 17
    ,ID_FILE_OPEN,0,0,0,0,0 // 18
  };
  
  CXTPCommandBars* pCommandBars = GetCommandBars();
  CXTPCommandBarsOptions* pOptions = pCommandBars->GetCommandBarsOptions();

  pCommandBars->GetImageManager()->RemoveAll();

  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_12, uins, _countof(uins), CSize(12, 12));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_16, uins, _countof(uins), CSize(16, 16));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_20, uins, _countof(uins), CSize(20, 20));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_24, uins, _countof(uins), CSize(24, 24));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_32, uins, _countof(uins), CSize(32, 32));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_40, uins, _countof(uins), CSize(40, 40));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_48, uins, _countof(uins), CSize(48, 48));

  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_52, uins, _countof(uins), CSize(52, 52));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_56, uins, _countof(uins), CSize(56, 56));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_64, uins, _countof(uins), CSize(64, 64));
}


Regards,
 Oleksandr Lebed
Back to Top
markr View Drop Down
Senior Member
Senior Member


Joined: 01 August 2004
Status: Offline
Points: 443
Post Options Post Options   Thanks (0) Thanks(0)   Quote markr Quote  Post ReplyReply Direct Link To This Post Posted: 18 August 2016 at 12:26pm
It seems super bizarre to me that this still hasn't been addressed.  Ouch

Guys, please check how BCGSoft handles this stuff. Their ribbon bar and button icons scale smoothly to whatever DPI is being used.

- Mark R.
Back to Top
sbinder View Drop Down
Groupie
Groupie
Avatar

Joined: 22 November 2004
Location: Austria
Status: Offline
Points: 76
Post Options Post Options   Thanks (0) Thanks(0)   Quote sbinder Quote  Post ReplyReply Direct Link To This Post Posted: 19 August 2016 at 3:21am
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... 
Back to Top
Marco1 View Drop Down
Senior Member
Senior Member


Joined: 16 January 2004
Location: Germany
Status: Offline
Points: 251
Post Options Post Options   Thanks (0) Thanks(0)   Quote Marco1 Quote  Post ReplyReply Direct Link To This Post Posted: 19 August 2016 at 5:20am
Originally posted by sbinder sbinder wrote:

Only reason that i still use Codejock is that it would be hard and time consuming job to exchange it.

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.

Back to Top
sbinder View Drop Down
Groupie
Groupie
Avatar

Joined: 22 November 2004
Location: Austria
Status: Offline
Points: 76
Post Options Post Options   Thanks (0) Thanks(0)   Quote sbinder Quote  Post ReplyReply Direct Link To This Post Posted: 22 August 2016 at 3:56am
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
Back to Top
markr View Drop Down
Senior Member
Senior Member


Joined: 01 August 2004
Status: Offline
Points: 443
Post Options Post Options   Thanks (0) Thanks(0)   Quote markr Quote  Post ReplyReply Direct Link To This Post Posted: 22 August 2016 at 11:11am
Originally posted by sbinder sbinder wrote:

It would need at least half a year to exchange codejock, therefore i currently have to deal with the problems.

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.

Originally posted by sbinder sbinder wrote:

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.

Would you mind sharing more information about how you did this?

- Mark R.
Back to Top
sbinder View Drop Down
Groupie
Groupie
Avatar

Joined: 22 November 2004
Location: Austria
Status: Offline
Points: 76
Post Options Post Options   Thanks (0) Thanks(0)   Quote sbinder Quote  Post ReplyReply Direct Link To This Post Posted: 23 August 2016 at 3:15am
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

extern AFX_EXT_API CSize calcDPIIconSize(CSize sz, bool bSquare/*=true*/, bool bLimitSquare32/*=true*/, bool bChooseBigger/*=false*/)
{
//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...
Back to Top
HTS10 View Drop Down
Newbie
Newbie


Joined: 16 September 2010
Status: Offline
Points: 8
Post Options Post Options   Thanks (1) Thanks(1)   Quote HTS10 Quote  Post ReplyReply Direct Link To This Post Posted: 24 August 2016 at 12:23am
I had the same problem. You need to set pCommandBars->GetCommandBarsOptions()->szLargeIcons size and after that, ribbon does not scale the icons.
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Answer Answer
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 08 November 2016 at 11:53am
Hello,

Final size of icons depend on type of commandBar, style of button, options of CommandBar.
CSize CXTPPaintManager::GetIconSize(CXTPControl* pButton)
{
    XTPButtonStyle buttonStyle = pButton->GetStyle();

    CSize szIcon = buttonStyle == xtpButtonIconAndCaptionBelow
        && pButton->GetParent()->GetType() != xtpBarTypePopup ?
        pButton->GetParent()->GetLargeIconSize(m_bAutoResizeIcons) : pButton->GetIconSize();

    return szIcon;
}

CSize CXTPCommandBar::GetLargeIconSize(BOOL bAutoSize) const
{
    CXTPCommandBars* pCommandBars = GetCommandBars();

    if (!pCommandBars)
        return m_szIcons != CSize(0) ? CSize(2 * m_szIcons.cx, 2 * m_szIcons.cy) : CSize(32, 32);

    CSize sz = m_szIcons != CSize(0) ? m_szIcons: (pCommandBars->m_pOptions->szIcons != CSize(0) ?
        pCommandBars->m_pOptions->szIcons : CSize(16, 16));
        
    if (m_szButtons == CSize(0))
    {
        sz = bAutoSize ? GetAutoIconSize(TRUE) : 
            (pCommandBars->m_pOptions->szLargeIcons != CSize(0) ?
            pCommandBars->m_pOptions->szLargeIcons : CSize(sz.cx * 2, sz.cy * 2));
    }

    return sz;
}

CXTPControl::GetIconSize()  > CXTPRibbonBar::GetIconSize()  > CXTPCommandBar::GetAutoIconSize() > CXTPPaintManager::GetAutoIconSize()

CSize CXTPCommandBar::GetIconSize() const
{
    if (m_szIcons != CSize(0))
        return m_szIcons;

    CXTPCommandBars* pCommandBars = GetCommandBars();

    if (!pCommandBars)
        return CSize(16, 16);

    CXTPCommandBarsOptions* pOptions = pCommandBars->GetCommandBarsOptions();

    if (GetType() == xtpBarTypePopup)
    {
        return pOptions->szPopupIcons != CSize(0) ? pOptions->szPopupIcons :GetAutoIconSize(FALSE);
    }

    CSize sz = pOptions->szIcons != CSize(0) ? pOptions->szIcons : GetAutoIconSize(FALSE);

    if (pOptions->bLargeIcons && m_szButtons == CSize(0))
    {
        sz = pOptions->szLargeIcons != CSize(0) ? pOptions->szLargeIcons:GetAutoIconSize(TRUE);
    }

    return sz;
}

CSize CXTPPaintManager::GetAutoIconSize(BOOL bLarge) const
{
    if (m_bAutoResizeIcons)
    {
        int nHeight = GetControlHeight() - XTP_DPI_Y(4);
        if (bLarge) nHeight = nHeight * 2;

        nHeight = max(XTP_DPI_Y(2), nHeight / 8);

        return CSize(nHeight * 8, nHeight * 8);
    }

    return bLarge ? CSize(32, 32) : CSize(16, 16);
}

int CXTPPaintManager::GetControlHeight() const
{
    return max(XTP_COMMANDBAR_MIN_CONTROL_HEIGHT, m_nEditHeight);   // max(18, m_nEditHeight)
}
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:
CSize CXTPPaintManager::GetStretchIconSize(CXTPImageManagerIcon* pImage, CSize szIcon)
{
    if (!pImage)
        return szIcon;

    if (pImage->GetWidth()==0 || pImage->GetHeight()==0)
        return szIcon;

    int nHeight = XTP_DPI_Y(pImage->GetHeight()) * szIcon.cx / XTP_DPI_X(pImage->GetWidth());

    if (nHeight <= szIcon.cy + 1)
        return CSize(szIcon.cx, nHeight);

    int nWidth = szIcon.cy * XTP_DPI_X(pImage->GetWidth()) / XTP_DPI_Y(pImage->GetHeight());

    return CSize(nWidth, szIcon.cy);
}

Then size of icon can be scaled to system DPI coefficient if you call pOptions->SetDPIScallingOptions( __ , TRUE).
szIcon = (!bDPIIconsScallingEnabled) ? szStretchIcon :
    CSize(XTP_DPI_X(szStretchIcon.cx), XTP_DPI_Y(szStretchIcon.cy));

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.

void CMainFrame::OnOptionsStyle(UINT nStyle)
{
    ....
    LoadIcons();
    ....
    GetCommandBars()->GetPaintManager()->m_bAutoResizeIcons = TRUE;
    GetCommandBars()->GetCommandBarsOptions()->SetDPIScallingOptions(TRUE, FALSE);
    ....
}

void CMainFrame::LoadIcons()
{
  UINT uins[] = {  
     ID_EDIT_UNDO,0,0,0,0,ID_EDIT_PASTE,0,0,0,0 // 0
    ,ID_EDIT_COPY,0,0,0,0,ID_EDIT_SELECT,0,0,0,0 // 1
    ,ID_EDIT_REPLACE,0,0,0,ID_EDIT_FIND,0,0,0,0,0 // 2
    ,ID_EDIT_GOTO,0,0,0,0,0,0,0,0,0 // 3
    ,ID_FILE_NEW,0,0,0,0,0,0,0,0,0 // 4
    ,ID_FILE_PRINT,0,0,0,0,0,0,0,0,0 // 5
    ,ID_FILE_CLOSE,0,0,0,0,0,0,0,0,0 // 6
    ,ID_APP_ABOUT,0,0,0,0,0,0,0,0,0 // 7
    ,ID_VIEW_FULLSCREEN,0,0,0,0,0,0,0,0,0 // 8
    ,ID_WINDOW_ARRANGE,0,0,0,0,0,0,0,0,0 // 9
    ,ID_WINDOW_TILE_HORZ,0,0,0,0,0,0,0,0,0 // 10
    ,ID_WINDOW_CASCADE,0,0,0,0,0,ID_EDIT_CUT,0,0,0 // 11    
    ,ID_WINDOW_SWITCH,0,0,0,0,0,0,0,0,0 // 12
    ,ID_WINDOW_NEW,0,0,0,0,0,0,0,0,0 // 13
    ,ID_VIEW_NORMAL,0,0,0,0,0,0,0,0,0 // 14
    ,ID_FORMAT_PAINTER,0,0,0,0,0,0,0,0,0 // 15
    ,ID_FILE_PRINT_PREVIEW,0,0,0,0,0,0,0,0,0 // 16
    ,ID_FILE_SAVE,0,0,0,0,0,0,0,0,0 // 17
    ,ID_FILE_OPEN,0,0,0,0,0 // 18
  };
  
  CXTPCommandBars* pCommandBars = GetCommandBars();
  CXTPCommandBarsOptions* pOptions = pCommandBars->GetCommandBarsOptions();

  pCommandBars->GetImageManager()->RemoveAll();

  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_12, uins, _countof(uins), CSize(12, 12));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_16, uins, _countof(uins), CSize(16, 16));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_20, uins, _countof(uins), CSize(20, 20));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_24, uins, _countof(uins), CSize(24, 24));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_32, uins, _countof(uins), CSize(32, 32));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_40, uins, _countof(uins), CSize(40, 40));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_48, uins, _countof(uins), CSize(48, 48));

  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_52, uins, _countof(uins), CSize(52, 52));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_56, uins, _countof(uins), CSize(56, 56));
  pCommandBars->GetImageManager()->SetIcons(IDB_PNG_TEST_64, uins, _countof(uins), CSize(64, 64));
}


Regards,
 Oleksandr Lebed
Back to Top
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 668
Post Options Post Options   Thanks (0) Thanks(0)   Quote cpede Quote  Post ReplyReply Direct Link To This Post Posted: 08 November 2016 at 3:18pm
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++)
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 08 November 2016 at 3:22pm
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
Back to Top
markr View Drop Down
Senior Member
Senior Member


Joined: 01 August 2004
Status: Offline
Points: 443
Post Options Post Options   Thanks (0) Thanks(0)   Quote markr Quote  Post ReplyReply Direct Link To This Post Posted: 06 December 2016 at 11:17am
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.
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 06 December 2016 at 11:25am
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 Unhappy
Back to Top
markr View Drop Down
Senior Member
Senior Member


Joined: 01 August 2004
Status: Offline
Points: 443
Post Options Post Options   Thanks (0) Thanks(0)   Quote markr Quote  Post ReplyReply Direct Link To This Post Posted: 07 December 2016 at 1:32pm
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:

m_pCommandBars = (CXTPCommandBars*)CXTPCommandBars::CreateObject();
m_pCommandBars->GetPaintManager()->m_bAutoResizeIcons = TRUE;
m_pCommandBars->GetCommandBarsOptions()->SetDPIScallingOptions(TRUE, FALSE);
m_pCommandBars->SetSite(this);

And the toolbar icons are set:

VERIFY(XTPImageManager()->SetIcons(IDB_PNG_SEARCH_32, nIDs, ARRAYSIZE(nIDs), CSize(32, 32)));
VERIFY(XTPImageManager()->SetIcons(IDB_PNG_SEARCH_40, nIDs, ARRAYSIZE(nIDs), CSize(40, 40)));
VERIFY(XTPImageManager()->SetIcons(IDB_PNG_SEARCH_48, nIDs, ARRAYSIZE(nIDs), CSize(48, 48)));

The results of this test:
  1. Set display to 100% (normal) scaling, and the toolbar shows the 32x32 icons [expected]
  2. Set display to 125% scaling, and the toolbar shows the 40x40 icons [expected]
  3. Set display to 150% scaling, and toolbar display seems to be incorrect. The resulting images are slightly malformed.
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.
Back to Top
markr View Drop Down
Senior Member
Senior Member


Joined: 01 August 2004
Status: Offline
Points: 443
Post Options Post Options   Thanks (0) Thanks(0)   Quote markr Quote  Post ReplyReply Direct Link To This Post Posted: 12 January 2017 at 11:46am
Any thoughts on this? Am I doing something wrong?

- Mark R.
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2017 at 4:23pm
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
Back to Top
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 668
Post Options Post Options   Thanks (0) Thanks(0)   Quote cpede Quote  Post ReplyReply Direct Link To This Post Posted: 14 January 2017 at 1:30pm
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++)
Back to Top
markr View Drop Down
Senior Member
Senior Member


Joined: 01 August 2004
Status: Offline
Points: 443
Post Options Post Options   Thanks (0) Thanks(0)   Quote markr Quote  Post ReplyReply Direct Link To This Post Posted: 04 May 2017 at 1:11pm
> 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.
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 09 June 2017 at 5:41am
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
CSize CXTPPaintManager::GetIconSize(CXTPControl* pButton)
{
    XTPButtonStyle buttonStyle = pButton->GetStyle();

    CSize szIcon = buttonStyle == xtpButtonIconAndCaptionBelow
        && pButton->GetParent()->GetType() != xtpBarTypePopup ?
        pButton->GetParent()->GetLargeIconSize(/**/ m_bAutoResizeIcons /*/ TRUE /**/) : pButton->GetIconSize();

    return szIcon;
}


Regards,
 Oleksandr Lebed
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: 12 June 2017 at 4:49am
... 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
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 12 June 2017 at 4:05pm
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
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 17 June 2017 at 3:34pm
Originally posted by markr markr wrote:

> 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.
Hello,

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
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.219 seconds.