• R/O
  • SSH
  • HTTPS

tortoisesvn: Commit


Commit MetaInfo

Revision28200 (tree)
Time2018-04-21 21:27:37
Authorstefankueng

Log Message

use the improved DPIAware class from the sktoolslib.

Change Summary

Incremental Difference

--- trunk/src/Utils/DpiScale.h (revision 28199)
+++ trunk/src/Utils/DpiScale.h (revision 28200)
@@ -1,43 +0,0 @@
1-// TortoiseSVN - a Windows shell extension for easy version control
2-
3-// Copyright (C) 2017 - TortoiseSVN
4-
5-// This program is free software; you can redistribute it and/or
6-// modify it under the terms of the GNU General Public License
7-// as published by the Free Software Foundation; either version 2
8-// of the License, or (at your option) any later version.
9-
10-// This program is distributed in the hope that it will be useful,
11-// but WITHOUT ANY WARRANTY; without even the implied warranty of
12-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-// GNU General Public License for more details.
14-
15-// You should have received a copy of the GNU General Public License
16-// along with this program; if not, write to the Free Software Foundation,
17-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18-//
19-#pragma once
20-
21-class CDpiScale
22-{
23-public:
24- CDpiScale(HDC hdc)
25- {
26- m_cxScale = GetDeviceCaps(hdc, LOGPIXELSX);
27- m_cyScale = GetDeviceCaps(hdc, LOGPIXELSY);
28- }
29-
30- int ScaleX(int x) const
31- {
32- return MulDiv(x, m_cxScale, 96);
33- }
34-
35- int ScaleY(int y) const
36- {
37- return MulDiv(y, m_cyScale, 96);
38- }
39-
40-private:
41- int m_cxScale;
42- int m_cyScale;
43-};
--- trunk/src/Utils/DPIAware.h (revision 0)
+++ trunk/src/Utils/DPIAware.h (revision 28200)
@@ -0,0 +1,132 @@
1+// TortoiseSVN - a Windows shell extension for easy version control
2+
3+// Copyright (C) 2018 - TortoiseSVN
4+
5+// This program is free software; you can redistribute it and/or
6+// modify it under the terms of the GNU General Public License
7+// as published by the Free Software Foundation; either version 2
8+// of the License, or (at your option) any later version.
9+
10+// This program is distributed in the hope that it will be useful,
11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+// GNU General Public License for more details.
14+
15+// You should have received a copy of the GNU General Public License
16+// along with this program; if not, write to the Free Software Foundation,
17+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+//
19+class CDPIAware
20+{
21+private:
22+ CDPIAware() : m_fInitialized(false), m_dpiX(96), m_dpiY(96) {}
23+ ~CDPIAware() {}
24+public:
25+ static CDPIAware& Instance()
26+ {
27+ static CDPIAware instance;
28+ return instance;
29+ }
30+
31+ // Get screen DPI.
32+ int GetDPIX() { _Init(); return m_dpiX; }
33+ int GetDPIY() { _Init(); return m_dpiY; }
34+
35+ // Convert between raw pixels and relative pixels.
36+ int ScaleX(int x) { _Init(); return MulDiv(x, m_dpiX, 96); }
37+ int ScaleY(int y) { _Init(); return MulDiv(y, m_dpiY, 96); }
38+ float ScaleFactorX() { _Init(); return m_dpiX / 96.0f; }
39+ float ScaleFactorY() { _Init(); return m_dpiY / 96.0f; }
40+ int UnscaleX(int x) { _Init(); return MulDiv(x, 96, m_dpiX); }
41+ int UnscaleY(int y) { _Init(); return MulDiv(y, 96, m_dpiY); }
42+
43+ // Determine the screen dimensions in relative pixels.
44+ int ScaledScreenWidth() { return _ScaledSystemMetricX(SM_CXSCREEN); }
45+ int ScaledScreenHeight() { return _ScaledSystemMetricY(SM_CYSCREEN); }
46+
47+ // Scale rectangle from raw pixels to relative pixels.
48+ void ScaleRect(__inout RECT *pRect)
49+ {
50+ pRect->left = ScaleX(pRect->left);
51+ pRect->right = ScaleX(pRect->right);
52+ pRect->top = ScaleY(pRect->top);
53+ pRect->bottom = ScaleY(pRect->bottom);
54+ }
55+
56+ // Scale Point from raw pixels to relative pixels.
57+ void ScalePoint(__inout POINT *pPoint)
58+ {
59+ pPoint->x = ScaleX(pPoint->x);
60+ pPoint->y = ScaleY(pPoint->y);
61+ }
62+
63+ // Scale Size from raw pixels to relative pixels.
64+ void ScaleSize(__inout SIZE *pSize)
65+ {
66+ pSize->cx = ScaleX(pSize->cx);
67+ pSize->cy = ScaleY(pSize->cy);
68+ }
69+
70+ // Determine if screen resolution meets minimum requirements in relative pixels.
71+ bool IsResolutionAtLeast(int cxMin, int cyMin)
72+ {
73+ return (ScaledScreenWidth() >= cxMin) && (ScaledScreenHeight() >= cyMin);
74+ }
75+
76+ // Convert a point size (1/72 of an inch) to raw pixels.
77+ int PointsToPixels(int pt) { return MulDiv(pt, m_dpiY, 72); }
78+
79+ // Invalidate any cached metrics.
80+ void Invalidate() { m_fInitialized = false; }
81+
82+private:
83+
84+ // This function initializes the CDPIAware Class
85+ void _Init()
86+ {
87+ if (!m_fInitialized)
88+ {
89+ HDC hdc = GetDC(nullptr);
90+ if (hdc)
91+ {
92+ // Initialize the DPI member variable
93+ // This will correspond to the DPI setting
94+ // With all Windows OS's to date the X and Y DPI will be identical
95+ m_dpiX = GetDeviceCaps(hdc, LOGPIXELSX);
96+ m_dpiY = GetDeviceCaps(hdc, LOGPIXELSY);
97+ ReleaseDC(nullptr, hdc);
98+ }
99+ m_fInitialized = true;
100+ }
101+ }
102+
103+ // This returns a 96-DPI scaled-down equivalent value for nIndex
104+ // For example, the value 120 at 120 DPI setting gets scaled down to 96
105+ // X and Y versions are provided, though to date all Windows OS releases
106+ // have equal X and Y scale values
107+ int _ScaledSystemMetricX(int nIndex)
108+ {
109+ _Init();
110+ return MulDiv(GetSystemMetrics(nIndex), 96, m_dpiX);
111+ }
112+
113+ // This returns a 96-DPI scaled-down equivalent value for nIndex
114+ // For example, the value 120 at 120 DPI setting gets scaled down to 96
115+ // X and Y versions are provided, though to date all Windows OS releases
116+ // have equal X and Y scale values
117+ int _ScaledSystemMetricY(int nIndex)
118+ {
119+ _Init();
120+ return MulDiv(GetSystemMetrics(nIndex), 96, m_dpiY);
121+ }
122+
123+private:
124+
125+ // Member variable indicating whether the class has been initialized
126+ bool m_fInitialized;
127+
128+ // X and Y DPI values are provided, though to date all
129+ // Windows OS releases have equal X and Y scale values
130+ int m_dpiX;
131+ int m_dpiY;
132+};
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
--- trunk/src/TortoiseMerge/BaseView.cpp (revision 28199)
+++ trunk/src/TortoiseMerge/BaseView.cpp (revision 28200)
@@ -28,7 +28,7 @@
2828 #include "GotoLineDlg.h"
2929 #include "EncodingDlg.h"
3030 #include "EditorConfigWrapper.h"
31-#include "DpiScale.h"
31+#include "DPIAware.h"
3232
3333 // Note about lines:
3434 // We use three different kind of lines here:
@@ -1644,7 +1644,6 @@
16441644 }
16451645 else
16461646 {
1647- CDpiScale dpi(pDC->GetSafeHdc());
16481647 CPen pen(PS_SOLID, 0, m_WhiteSpaceFg);
16491648 CPen * oldpen = pDC->SelectObject(&pen);
16501649 int yMiddle = origin.y + rc.Height()/2;
@@ -1656,10 +1655,10 @@
16561655 {
16571656 // multiline
16581657 bMultiline = true;
1659- pDC->MoveTo(origin.x, yMiddle-dpi.ScaleY(2));
1660- pDC->LineTo(origin.x+GetCharWidth()-dpi.ScaleX(1), yMiddle-dpi.ScaleY(2));
1661- pDC->LineTo(origin.x+GetCharWidth()-dpi.ScaleX(1), yMiddle+dpi.ScaleY(2));
1662- pDC->LineTo(origin.x, yMiddle+dpi.ScaleY(2));
1658+ pDC->MoveTo(origin.x, yMiddle- CDPIAware::Instance().ScaleY(2));
1659+ pDC->LineTo(origin.x+GetCharWidth()-CDPIAware::Instance().ScaleX(1), yMiddle-CDPIAware::Instance().ScaleY(2));
1660+ pDC->LineTo(origin.x+GetCharWidth()-CDPIAware::Instance().ScaleX(1), yMiddle+CDPIAware::Instance().ScaleY(2));
1661+ pDC->LineTo(origin.x, yMiddle+ CDPIAware::Instance().ScaleY(2));
16631662 }
16641663 else if (GetLineLength(nLineIndex) == 0)
16651664 bMultiline = true;
@@ -1674,32 +1673,32 @@
16741673 case EOL_AUTOLINE:
16751674 case EOL_CRLF:
16761675 // arrow from top to middle+2, then left
1677- pDC->MoveTo(origin.x+GetCharWidth()-dpi.ScaleX(1), rc.top+dpi.ScaleY(1));
1678- pDC->LineTo(origin.x+GetCharWidth()-dpi.ScaleX(1), yMiddle);
1676+ pDC->MoveTo(origin.x+GetCharWidth()-CDPIAware::Instance().ScaleX(1), rc.top+ CDPIAware::Instance().ScaleY(1));
1677+ pDC->LineTo(origin.x+GetCharWidth()-CDPIAware::Instance().ScaleX(1), yMiddle);
16791678 case EOL_CR:
16801679 // arrow from right to left
1681- pDC->MoveTo(origin.x+GetCharWidth()-dpi.ScaleX(1), yMiddle);
1680+ pDC->MoveTo(origin.x+GetCharWidth()-CDPIAware::Instance().ScaleX(1), yMiddle);
16821681 pDC->LineTo(origin.x, yMiddle);
1683- pDC->LineTo(origin.x+dpi.ScaleX(4), yMiddle+dpi.ScaleY(4));
1682+ pDC->LineTo(origin.x+CDPIAware::Instance().ScaleX(4), yMiddle+CDPIAware::Instance().ScaleY(4));
16841683 pDC->MoveTo(origin.x, yMiddle);
1685- pDC->LineTo(origin.x+dpi.ScaleX(4), yMiddle-dpi.ScaleY(4));
1684+ pDC->LineTo(origin.x+CDPIAware::Instance().ScaleX(4), yMiddle-CDPIAware::Instance().ScaleY(4));
16861685 break;
16871686 case EOL_LFCR:
16881687 // from right-upper to left then down
1689- pDC->MoveTo(origin.x+GetCharWidth()-dpi.ScaleX(1), yMiddle-dpi.ScaleY(2));
1690- pDC->LineTo(xMiddle, yMiddle-dpi.ScaleY(2));
1691- pDC->LineTo(xMiddle, rc.bottom-dpi.ScaleY(1));
1692- pDC->LineTo(xMiddle+dpi.ScaleX(4), rc.bottom-dpi.ScaleY(5));
1693- pDC->MoveTo(xMiddle, rc.bottom-dpi.ScaleY(1));
1694- pDC->LineTo(xMiddle-dpi.ScaleX(4), rc.bottom-dpi.ScaleY(5));
1688+ pDC->MoveTo(origin.x+GetCharWidth()-CDPIAware::Instance().ScaleX(1), yMiddle-CDPIAware::Instance().ScaleY(2));
1689+ pDC->LineTo(xMiddle, yMiddle-CDPIAware::Instance().ScaleY(2));
1690+ pDC->LineTo(xMiddle, rc.bottom-CDPIAware::Instance().ScaleY(1));
1691+ pDC->LineTo(xMiddle+CDPIAware::Instance().ScaleX(4), rc.bottom-CDPIAware::Instance().ScaleY(5));
1692+ pDC->MoveTo(xMiddle, rc.bottom-CDPIAware::Instance().ScaleY(1));
1693+ pDC->LineTo(xMiddle-CDPIAware::Instance().ScaleX(4), rc.bottom-CDPIAware::Instance().ScaleY(5));
16951694 break;
16961695 case EOL_LF:
16971696 // arrow from top to bottom
16981697 pDC->MoveTo(xMiddle, rc.top);
1699- pDC->LineTo(xMiddle, rc.bottom-dpi.ScaleY(1));
1700- pDC->LineTo(xMiddle+dpi.ScaleX(4), rc.bottom-dpi.ScaleY(5));
1701- pDC->MoveTo(xMiddle, rc.bottom-dpi.ScaleY(1));
1702- pDC->LineTo(xMiddle-dpi.ScaleX(4), rc.bottom-dpi.ScaleY(5));
1698+ pDC->LineTo(xMiddle, rc.bottom-CDPIAware::Instance().ScaleY(1));
1699+ pDC->LineTo(xMiddle+CDPIAware::Instance().ScaleX(4), rc.bottom-CDPIAware::Instance().ScaleY(5));
1700+ pDC->MoveTo(xMiddle, rc.bottom-CDPIAware::Instance().ScaleY(1));
1701+ pDC->LineTo(xMiddle-CDPIAware::Instance().ScaleX(4), rc.bottom-CDPIAware::Instance().ScaleY(5));
17031702 break;
17041703 case EOL_FF: // Form Feed, U+000C
17051704 case EOL_NEL: // Next Line, U+0085
@@ -2054,7 +2053,6 @@
20542053 int y = rc.top + (rc.bottom-rc.top)/2;
20552054 xpos -= m_nOffsetChar * GetCharWidth();
20562055
2057- CDpiScale dpi(pDC->GetSafeHdc());
20582056 CPen pen(PS_SOLID, 0, m_WhiteSpaceFg);
20592057 while (*pszChars)
20602058 {
@@ -2072,11 +2070,11 @@
20722070 if ((xposreal > 0) || (nSpaces > 0))
20732071 {
20742072 CPen * oldPen = pDC->SelectObject(&pen);
2075- pDC->MoveTo(xposreal + rc.left + dpi.ScaleX(2), y);
2076- pDC->LineTo((xpos + nSpaces * GetCharWidth()) + rc.left - dpi.ScaleX(2), y);
2077- pDC->LineTo((xpos + nSpaces * GetCharWidth()) + rc.left - dpi.ScaleX(6), y - dpi.ScaleY(4));
2078- pDC->MoveTo((xpos + nSpaces * GetCharWidth()) + rc.left - dpi.ScaleX(2), y);
2079- pDC->LineTo((xpos + nSpaces * GetCharWidth()) + rc.left - dpi.ScaleX(6), y + dpi.ScaleY(4));
2073+ pDC->MoveTo(xposreal + rc.left + CDPIAware::Instance().ScaleX(2), y);
2074+ pDC->LineTo((xpos + nSpaces * GetCharWidth()) + rc.left - CDPIAware::Instance().ScaleX(2), y);
2075+ pDC->LineTo((xpos + nSpaces * GetCharWidth()) + rc.left - CDPIAware::Instance().ScaleX(6), y - CDPIAware::Instance().ScaleY(4));
2076+ pDC->MoveTo((xpos + nSpaces * GetCharWidth()) + rc.left - CDPIAware::Instance().ScaleX(2), y);
2077+ pDC->LineTo((xpos + nSpaces * GetCharWidth()) + rc.left - CDPIAware::Instance().ScaleX(6), y + CDPIAware::Instance().ScaleY(4));
20802078 pDC->SelectObject(oldPen);
20812079 }
20822080 }
@@ -2090,8 +2088,8 @@
20902088 pLastSpace = pszChars + 1;
20912089 if (xpos >= 0)
20922090 {
2093- const int cxWhitespace = dpi.ScaleX(2);
2094- const int cyWhitespace = dpi.ScaleY(2);
2091+ const int cxWhitespace = CDPIAware::Instance().ScaleX(2);
2092+ const int cyWhitespace = CDPIAware::Instance().ScaleY(2);
20952093 // draw 2-logical pixel rectangle, like Scintilla editor.
20962094 pDC->FillSolidRect(xpos + rc.left + GetCharWidth() / 2 - cxWhitespace/2, y,
20972095 cxWhitespace, cyWhitespace, m_WhiteSpaceFg);
Show on old repository browser