mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-05 17:44:55 -06:00
upp.src: HiDPI fixes
git-svn-id: svn://ultimatepp.org/upp/trunk@8790 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
6998e11c21
commit
4147ebe8ec
11 changed files with 56 additions and 122 deletions
|
|
@ -809,6 +809,18 @@ Font FontZ(int face, int height)
|
|||
return Font(face, Ctrl::VertLayoutZoom(height));
|
||||
}
|
||||
|
||||
bool ApplicationHiDPIEnabled;
|
||||
|
||||
void Ctrl::SetHiDPIEnabled(bool set)
|
||||
{
|
||||
ApplicationHiDPIEnabled = set;
|
||||
}
|
||||
|
||||
bool Ctrl::GetHiDPIEnabled()
|
||||
{
|
||||
return ApplicationHiDPIEnabled;
|
||||
}
|
||||
|
||||
Font StdFontZ(int height) { return FontZ(Font::STDFONT, height); }
|
||||
Font SansSerifZ(int height) { return FontZ(Font::SANSSERIF, height); }
|
||||
Font SerifZ(int height) { return FontZ(Font::SERIF, height); }
|
||||
|
|
|
|||
|
|
@ -1201,6 +1201,9 @@ public:
|
|||
static Size LayoutZoom(Size sz);
|
||||
static void NoLayoutZoom();
|
||||
static void GetZoomRatio(Size& m, Size& d);
|
||||
|
||||
static void SetHiDPIEnabled(bool set = true);
|
||||
static bool GetHiDPIEnabled();
|
||||
|
||||
static int Zx(int cx) { return HorzLayoutZoom(cx); }
|
||||
static int Zy(int cy) { return VertLayoutZoom(cy); }
|
||||
|
|
|
|||
|
|
@ -495,7 +495,7 @@ void ChHostSkin()
|
|||
if(i == CTRL_DISABLED)
|
||||
GTK_WIDGET_FLAGS (w) &= GTK_SENSITIVE;
|
||||
img = GetGTK(w, GTK_STATE_NORMAL, GTK_SHADOW_IN, "entry", GTK_SHADOW, 20, 20);
|
||||
if(i == 0)
|
||||
if(i == 0)
|
||||
efm = max(ImageMargin(img, 4, 0), 1);
|
||||
if(!Qt)
|
||||
img = GetGTK(w, GTK_STATE_NORMAL, GTK_SHADOW_IN,
|
||||
|
|
|
|||
|
|
@ -595,6 +595,24 @@ void ChSysInit()
|
|||
CtrlsImg::Reset();
|
||||
ChReset();
|
||||
XpClear();
|
||||
|
||||
BOOL (STDAPICALLTYPE * SetProcessDPIAware)(void);
|
||||
DllFn(SetProcessDPIAware, "User32.dll", "SetProcessDPIAware");
|
||||
if(SetProcessDPIAware/* && Ctrl::IsHiDPIEnabled()*/)
|
||||
(*SetProcessDPIAware)();
|
||||
NONCLIENTMETRICS ncm;
|
||||
#if (WINVER >= 0x0600)
|
||||
ncm.cbSize = sizeof(ncm) - sizeof(ncm.iPaddedBorderWidth); // WinXP does not like it...
|
||||
#else
|
||||
ncm.cbSize = sizeof(ncm);
|
||||
#endif
|
||||
::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
|
||||
String name = FromSystemCharset(ncm.lfMenuFont.lfFaceName);
|
||||
int height = abs((int)ncm.lfMenuFont.lfHeight);
|
||||
|
||||
int q = Font::FindFaceNameIndex(name);
|
||||
if(height > 0 && height < 200) // sanity..
|
||||
SetStdFont(Font(q >= 0 ? q : Font::SANSSERIF, height));
|
||||
|
||||
GUI_HiDPI_Write(GetStdFontCy() > 22);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,11 +29,6 @@ void Draw::SinCos(int angle, double& sina, double& cosa)
|
|||
}
|
||||
}
|
||||
|
||||
Draw::Draw()
|
||||
{
|
||||
hmul = 1;
|
||||
}
|
||||
|
||||
Draw::~Draw() {}
|
||||
|
||||
Size Draw::GetPixelsPerInch() const
|
||||
|
|
@ -120,11 +115,6 @@ int Draw::GetCloffLevel() const { return 0; }
|
|||
|
||||
// -------------------------------
|
||||
|
||||
Image Draw::Hmul(const Image& img)
|
||||
{
|
||||
return hmul ? CachedRescale(img, hmul * img.GetSize(), FILTER_LANCZOS3) : img;
|
||||
}
|
||||
|
||||
void Draw::SysDrawImageOp(int x, int y, const Image& img, Color color)
|
||||
{
|
||||
NEVER();
|
||||
|
|
@ -185,12 +175,12 @@ void Draw::DrawRect(const Rect& rect, Color color)
|
|||
|
||||
void Draw::DrawRect(int x, int y, int cx, int cy, Color color)
|
||||
{
|
||||
DrawRectOp(Hmul(x), Hmul(y), Hmul(cx), Hmul(cy), color);
|
||||
DrawRectOp(x, y, cx, cy, color);
|
||||
}
|
||||
|
||||
void Draw::DrawImage(int x, int y, int cx, int cy, const Image& img, const Rect& src)
|
||||
{
|
||||
DrawImageOp(Hmul(x), Hmul(y), Hmul(cx), Hmul(cy), Hmul(img), Hmul(src), Null);
|
||||
DrawImageOp(x, y, cx, cy, img, src, Null);
|
||||
}
|
||||
|
||||
void Draw::DrawImage(int x, int y, int cx, int cy, const Image& img)
|
||||
|
|
@ -201,7 +191,7 @@ void Draw::DrawImage(int x, int y, int cx, int cy, const Image& img)
|
|||
void Draw::DrawImage(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color)
|
||||
{
|
||||
if(IsNull(color)) return;
|
||||
DrawImageOp(Hmul(x), Hmul(y), Hmul(cx), Hmul(cy), Hmul(img), Hmul(src), color);
|
||||
DrawImageOp(x, y, cx, cy, img, src, color);
|
||||
}
|
||||
|
||||
void Draw::DrawImage(int x, int y, int cx, int cy, const Image& img, Color color)
|
||||
|
|
@ -235,36 +225,36 @@ void Draw::DrawImage(const Rect& r, const Image& img, Color color)
|
|||
void Draw::DrawImage(int x, int y, const Image& img, const Rect& src)
|
||||
{
|
||||
Size sz = src.GetSize();
|
||||
DrawImageOp(Hmul(x), Hmul(y), Hmul(sz.cx), Hmul(sz.cy), img, Hmul(src), Null);
|
||||
DrawImageOp(x, y, sz.cx, sz.cy, img, src, Null);
|
||||
}
|
||||
|
||||
void Draw::DrawImage(int x, int y, const Image& img)
|
||||
{
|
||||
Size sz = img.GetSize();
|
||||
DrawImageOp(Hmul(x), Hmul(y), Hmul(sz.cx), Hmul(sz.cy), Hmul(img), Hmul(img.GetSize()), Null);
|
||||
DrawImageOp(x, y, sz.cx, sz.cy, img, img.GetSize(), Null);
|
||||
}
|
||||
|
||||
void Draw::DrawImage(int x, int y, const Image& img, const Rect& src, Color color)
|
||||
{
|
||||
if(IsNull(color)) return;
|
||||
DrawImageOp(Hmul(x), Hmul(y), Hmul(src.Width()), Hmul(src.Height()), Hmul(img), Hmul(src), color);
|
||||
DrawImageOp(x, y, src.Width(), src.Height(), img, src, color);
|
||||
}
|
||||
|
||||
void Draw::DrawImage(int x, int y, const Image& img, Color color)
|
||||
{
|
||||
if(IsNull(color)) return;
|
||||
Size sz = img.GetSize();
|
||||
DrawImageOp(Hmul(x), Hmul(y), Hmul(sz.cx), Hmul(sz.cy), img, Hmul(sz), color);
|
||||
DrawImageOp(x, y, sz.cx, sz.cy, img, sz, color);
|
||||
}
|
||||
|
||||
void Draw::DrawData(int x, int y, int cx, int cy, const String& data, const char *type)
|
||||
{
|
||||
DrawDataOp(Hmul(x), Hmul(y), Hmul(cx), Hmul(cy), data, type);
|
||||
DrawDataOp(x, y, cx, cy, data, type);
|
||||
}
|
||||
|
||||
void Draw::DrawData(const Rect& r, const String& data, const char *type)
|
||||
{
|
||||
DrawDataOp(Hmul(r.left), Hmul(r.top), Hmul(r.GetWidth()), Hmul(r.GetHeight()), data, type);
|
||||
DrawDataOp(r.left, r.top, r.GetWidth(), r.GetHeight(), data, type);
|
||||
}
|
||||
|
||||
void Draw::DrawLine(Point p1, Point p2, int width, Color color)
|
||||
|
|
@ -274,27 +264,15 @@ void Draw::DrawLine(Point p1, Point p2, int width, Color color)
|
|||
|
||||
void Draw::DrawLine(int x1, int y1, int x2, int y2, int width, Color color)
|
||||
{
|
||||
DrawLineOp(Hmul(x1), Hmul(y1), Hmul(x2), Hmul(y2), Hmul(width), color);
|
||||
}
|
||||
|
||||
Buffer<Point> Draw::Hmul(const Point *p, int count)
|
||||
{
|
||||
Buffer<Point> r(count);
|
||||
for(int i = 0; i < count; i++)
|
||||
r[i] = hmul * p[i];
|
||||
return r;
|
||||
DrawLineOp(x1, y1, x2, y2, width, color);
|
||||
}
|
||||
|
||||
void Draw::DrawPolyPolyline(const Point *vertices, int vertex_count,
|
||||
const int *counts, int count_count,
|
||||
int width, Color color, Color doxor)
|
||||
{
|
||||
if(hmul != 1) {
|
||||
Buffer<Point> v2 = Hmul(vertices, vertex_count);
|
||||
DrawPolyPolylineOp(~v2, vertex_count, counts, count_count, Hmul(width), color, doxor);
|
||||
}
|
||||
else
|
||||
DrawPolyPolylineOp(vertices, vertex_count, counts, count_count, width, color, doxor);
|
||||
DrawPolyPolylineOp(vertices, vertex_count, counts, count_count, width,
|
||||
color, doxor);
|
||||
}
|
||||
|
||||
void Draw::DrawPolyPolyline(const Vector<Point>& vertices, const Vector<int>& counts,
|
||||
|
|
@ -323,16 +301,9 @@ void Draw::DrawPolyPolyPolygon(const Point *vertices, int vertex_count,
|
|||
int disjunct_polygon_count_count, Color color,
|
||||
int width, Color outline, uint64 pattern, Color doxor)
|
||||
{
|
||||
if(hmul != 1) {
|
||||
Buffer<Point> v2 = Hmul(vertices, vertex_count);
|
||||
DrawPolyPolyPolygonOp(~v2, vertex_count, subpolygon_counts, subpolygon_count_count,
|
||||
disjunct_polygon_counts, disjunct_polygon_count_count, color,
|
||||
width, outline, pattern, doxor);
|
||||
}
|
||||
else
|
||||
DrawPolyPolyPolygonOp(vertices, vertex_count, subpolygon_counts, subpolygon_count_count,
|
||||
disjunct_polygon_counts, disjunct_polygon_count_count, color,
|
||||
width, outline, pattern, doxor);
|
||||
DrawPolyPolyPolygonOp(vertices, vertex_count, subpolygon_counts, subpolygon_count_count,
|
||||
disjunct_polygon_counts, disjunct_polygon_count_count, color,
|
||||
width, outline, pattern, doxor);
|
||||
}
|
||||
|
||||
void Draw::DrawPolyPolyPolygon(const Vector<Point>& vertices,
|
||||
|
|
@ -397,17 +368,17 @@ void Draw::DrawPolygon(const Vector<Point>& vertices,
|
|||
|
||||
void Draw::DrawEllipse(int x, int y, int cx, int cy, Color color, int pen, Color pencolor)
|
||||
{
|
||||
DrawEllipse(RectC(x, y, cx, cy), color, Hmul(pen), pencolor);
|
||||
DrawEllipse(RectC(x, y, cx, cy), color, pen, pencolor);
|
||||
}
|
||||
|
||||
void Draw::DrawEllipse(const Rect& r, Color color, int pen, Color pencolor)
|
||||
{
|
||||
DrawEllipseOp(Hmul(r), color, Hmul(pen), pencolor);
|
||||
DrawEllipseOp(r, color, pen, pencolor);
|
||||
}
|
||||
|
||||
void Draw::DrawArc(const Rect& rc, Point start, Point end, int width, Color color)
|
||||
{
|
||||
DrawArcOp(Hmul(rc), Hmul(start), Hmul(end), Hmul(width), color);
|
||||
DrawArcOp(rc, start, end, width, color);
|
||||
}
|
||||
|
||||
void Draw::Offset(int x, int y)
|
||||
|
|
@ -488,11 +459,10 @@ Drawing AsDrawing(const Painting& pw)
|
|||
return dw.GetResult();
|
||||
}
|
||||
|
||||
void Draw::DrawPaintingOp(const Rect& target_, const Painting& pw)
|
||||
void Draw::DrawPaintingOp(const Rect& target, const Painting& pw)
|
||||
{
|
||||
if(!HasPainter())
|
||||
return;
|
||||
Rect target = Hmul(target_);
|
||||
Size sz = target.GetSize();
|
||||
if((sz.cx > 2000 || sz.cy > 1500) && IsPrinter()) {
|
||||
int yy = 0;
|
||||
|
|
|
|||
|
|
@ -412,15 +412,6 @@ void PaintImageBuffer(ImageBuffer& ib, const Drawing& p, int mode = MODE_ANTIALI
|
|||
class Draw : NoCopy {
|
||||
struct DrawingPos;
|
||||
|
||||
int hmul;
|
||||
|
||||
int Hmul(int x) { return hmul * x; }
|
||||
Point Hmul(Point p) { return hmul * p; }
|
||||
Size Hmul(Size sz) { return hmul * sz; }
|
||||
Rect Hmul(const Rect& r) { return Rect(Hmul(r.left), Hmul(r.top), Hmul(r.right), Hmul(r.bottom)); }
|
||||
Buffer<Point> Hmul(const Point *p, int count);
|
||||
Image Hmul(const Image& img);
|
||||
|
||||
public:
|
||||
enum {
|
||||
DOTS = 0x001,
|
||||
|
|
@ -610,16 +601,12 @@ public:
|
|||
|
||||
static void SinCos(int angle, double& sina, double& cosa);
|
||||
|
||||
void HDPIMultiplier(int m) { hmul = m; }
|
||||
|
||||
// deprecated:
|
||||
static void SetStdFont(Font font) { UPP::SetStdFont(font); }
|
||||
static Font GetStdFont() { return UPP::GetStdFont(); }
|
||||
static Size GetStdFontSize() { return UPP::GetStdFontSize(); }
|
||||
static int GetStdFontCy() { return GetStdFontSize().cy; }
|
||||
Size GetPagePixels() const { return GetPageSize(); }
|
||||
|
||||
Draw();
|
||||
};
|
||||
|
||||
void DrawImageBandRLE(Draw& w, int x, int y, const Image& m, int minp);
|
||||
|
|
|
|||
|
|
@ -31,17 +31,6 @@ WString TextUnicode(const char *s, int n, byte cs, Font font)
|
|||
void Draw::DrawText(int x, int y, int angle, const wchar *text, Font font,
|
||||
Color ink, int n, const int *dx)
|
||||
{
|
||||
Buffer<int> dx2;
|
||||
if(hmul != 1) {
|
||||
x = Hmul(x);
|
||||
y = Hmul(y);
|
||||
font.Height(Hmul(font.GetHeight()));
|
||||
if(dx) {
|
||||
dx2.Alloc(n);
|
||||
for(int i = 0; i < n; i++)
|
||||
dx2[i] = Hmul(dx[i]);
|
||||
}
|
||||
}
|
||||
#if defined(flagWINGL) || defined(flagLINUXGL)
|
||||
if(IsNull(ink))
|
||||
return;
|
||||
|
|
@ -124,7 +113,7 @@ void Draw::DrawText(int x, int y, int angle, const wchar *text, Font font,
|
|||
posx += dx ? *dx++ : gi.width;
|
||||
}
|
||||
|
||||
if((GetInfo() & DRAWTEXTLINES) && (font0.IsUnderline() || font0.IsStrikeout())) {
|
||||
if((GetInfo() & DRAWTEXTLINES) && (font0.IsUnderline() || font0.IsStrikeout())) {
|
||||
int hg = abs(font0.GetCy());
|
||||
if(hg == 0) hg = 10;
|
||||
int thickness = max(hg / 20, 1);
|
||||
|
|
@ -233,7 +222,7 @@ void Draw::DrawText(int x, int y, const String& text, Font font, Color ink, cons
|
|||
Size GetTextSize(const wchar *text, Font font, int n)
|
||||
{
|
||||
#if defined(flagWINGL) || defined(flagLINUXGL)
|
||||
return GetTextSize(text, resources.GetFont(font), n);
|
||||
return GetTextSize(text, resources.GetFont(font), n);
|
||||
#else
|
||||
FontInfo fi = font.Info();
|
||||
if(n < 0)
|
||||
|
|
|
|||
|
|
@ -163,28 +163,11 @@ void Font::SetStdFont(Font font)
|
|||
|
||||
void Font::InitStdFont()
|
||||
{
|
||||
ONCELOCK {
|
||||
ONCELOCK { // TODO: This is now sort of obsolete function....
|
||||
Mutex::Lock __(sFontLock);
|
||||
FaceList();
|
||||
AStdFont = Arial(12);
|
||||
String name;
|
||||
int height = 0;
|
||||
GetStdFontSys(name, height);
|
||||
#ifdef flagTEST_HIDPI
|
||||
height *= 2;
|
||||
#endif
|
||||
#ifdef PLATFORM_WIN32
|
||||
int q = FindFaceNameIndex(name);
|
||||
if(q <= 0)
|
||||
q = FindFaceNameIndex("Tahoma");
|
||||
if(q <= 0)
|
||||
q = FindFaceNameIndex("Microsoft Sans Serif");
|
||||
if(q <= 0)
|
||||
q = FindFaceNameIndex("MS Sans Serif");
|
||||
if(q > 0)
|
||||
AStdFont = Font(q, max(height, 1));
|
||||
SyncStdFont();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,11 +15,6 @@ FT_EXPORT( const char* ) FT_Get_X11_Font_Format( FT_Face face ); // Put here to
|
|||
|
||||
NAMESPACE_UPP
|
||||
|
||||
void GetStdFontSys(String& name, int& height)
|
||||
{
|
||||
name = "xxxx";
|
||||
}
|
||||
|
||||
static FT_Library sFTlib;
|
||||
|
||||
EXITBLOCK
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ void InvalidateFontList();
|
|||
|
||||
CommonFontInfo GetFontInfoSys(Font font);
|
||||
GlyphInfo GetGlyphInfoSys(Font font, int chr);
|
||||
void GetStdFontSys(String& name, int& height);
|
||||
Vector<FaceInfo> GetAllFacesSys();
|
||||
String GetFontDataSys(Font font);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,28 +9,6 @@ NAMESPACE_UPP
|
|||
#define LLOG(x) // LOG(x)
|
||||
#define LTIMING(x) // TIMING(x)
|
||||
|
||||
void GetStdFontSys(String& name, int& height)
|
||||
{
|
||||
#ifdef PLATFORM_WINCE
|
||||
name = "Arial";
|
||||
height = 10;
|
||||
#else
|
||||
BOOL (STDAPICALLTYPE * SetProcessDPIAware)(void);
|
||||
DllFn(SetProcessDPIAware, "User32.dll", "SetProcessDPIAware");
|
||||
if(SetProcessDPIAware)
|
||||
(*SetProcessDPIAware)();
|
||||
NONCLIENTMETRICS ncm;
|
||||
#if (WINVER >= 0x0600)
|
||||
ncm.cbSize = sizeof(ncm) - sizeof(ncm.iPaddedBorderWidth); // WinXP does not like it...
|
||||
#else
|
||||
ncm.cbSize = sizeof(ncm);
|
||||
#endif
|
||||
::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
|
||||
name = FromSystemCharset(ncm.lfMenuFont.lfFaceName);
|
||||
height = abs((int)ncm.lfMenuFont.lfHeight);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define FONTCACHE 96
|
||||
|
||||
struct HFontEntry {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue