Custom cursors and high dpi (Windows and MacOS testers needed)

A forum for research and development of the user interface of FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Custom cursors and high dpi

Post by Kunda1 »

FYI, there is an open ticket on Qt possibly related to this endeavor as we proceed:
https://bugreports.qt.io/browse/QTBUG-46259 "High dpi cursors"
When I try to create a cursor from some png pixmaps it won't work.
Looks like a bug because it works fine in the Qt 4.8.6 as expected.
A sample application that reproduces a bug I attached.
See line 37 of the QTWidget.cpp

If to set the same pixmap file as a button icon it works as expected too.
This is mentioned in the Krita source code: https://github.com/KDE/krita/blob/maste ... _cache.cpp

Apparently Krita is still having some bugs related to HiDPI, especially on Windows.

Edit: Here are all open tickets on Qt bugtracker that are mouse related:
https://bugreports.qt.io/browse/QTBUG-8 ... 0touch)%22

Edit2: Also https://bugreports.qt.io/browse/QTBUG-80571 HiDPI/DPR scaling leads to blurry pixmaps (apparently fixed in Qt 5.14)

We should be talking about what version of Qt we're all using, BTW
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
bitacovir
Veteran
Posts: 1570
Joined: Sat Apr 19, 2014 6:23 am
Contact:

Re: Custom cursors and high dpi

Post by bitacovir »

vanuan wrote: Sat Jul 18, 2020 5:11 am Need help with custom cursors
https://forum.freecadweb.org/viewtopic.php?f=3&t=48681

Currently, those are defined as hard-coded 32x32 bitmaps, e.g.: src/Mod/Sketcher/Gui/CommandCreateGeo.cpp

As 4K displays become more common, cursor icons need to be scaled up to 200% or 300%.
Unfortunately, naive scaling makes cursor icons to be blurry/pixelated.

I can make a PR for crude scaling, but it would be much better to actually make higher resolution cursor.

Bitmaps look like this:

Code: Select all

"......+.........................",
"......+.........................",
"......+.........................",
"......+.........................",
"......+.........................",
"................................",
"+++++...+++++...................",
"................................",
"......+.........................",
"......+.........................",
"......+.........................",
"......+.........................",
"......+.........................",
"................................",
"................................",
"..........................###...",
"........###################.##..",
".......#..................###.#.",
"......#........................#",
".....#.........................#",
"....#.....###..................#",
"....#.....#.#..................#",
".....#....###.................#.",
"......#.......................#.",
".......#.....................#..",
"........#####################...",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................"};
Do you need a svg file of a cursor?
::bitacovir::
==================
One must be absolutely modern.
Arthur Rimbaud (A Season in Hell -1873)

Canal Youtube Grupo Telegram de FreeCAD Español

My personal web site
My GitHub repository
Mini Airflow Tunnel Project
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: Custom cursors and high dpi

Post by vanuan »

Kunda1 wrote: Sat Jul 18, 2020 11:08 am FYI, there is an open ticket on Qt possibly related to this endeavor as we proceed:
I've read all the Qt bugs related to HighDPI cursor. Most of them are closed/fixed in Qt 5.6 which was released in 2016

Unfortunately, I can't verify my code on Windows and OS X, so I'd appreciate if you help me test it.

The issue in the Krita code is that they don't provide larger bitmaps for higher device pixel ratios and the don't scale the bitmap either.
I veritifed and indeed, Krita's custom cursor is smaller than the default one. So they use 32x32 cursor, set DPI ratio to 2, so that cursor becomes 16x16, 4 times smaller than the default one. They should've scaled it to 64x64, so that it becomes a "normal" size.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Custom cursors and high dpi

Post by Kunda1 »

vanuan wrote: Sat Jul 18, 2020 11:23 am Unfortunately, I can't verify my code on Windows and OS X, so I'd appreciate if you help me test it.
I'm on Linux. Lets see if we can rally anyone in the community that is on windows/MacOS to be involved in the testing.
Can we create a clear sequence for them to execute so that they can record their results and post to the forum ?
vanuan wrote: Sat Jul 18, 2020 11:23 am The issue in the Krita code is that they don't provide larger bitmaps for higher device pixel ratios and the don't scale the bitmap either.
I veritifed and indeed, Krita's custom cursor is smaller than the default one. So they use 32x32 cursor, set DPI ratio to 2, so that cursor becomes 16x16, 4 times smaller than the default one. They should've scaled it to 64x64, so that it becomes a "normal" size.
Wow. Sounds kinda hacky.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Custom cursors and high dpi (Windows and MacOS testers needed)

Post by Kunda1 »

Updated thread title to rally the troops
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: Custom cursors and high dpi

Post by vanuan »

bitacovir wrote: Sat Jul 18, 2020 11:16 am Do you need a svg file of a cursor?
Or a higher resolution bitmap. 64x64 would be good for 200%, 128x128 would cover 400% scaling.

There are a lot of cursors in Sketcher, I can't do it myself.
Also, there are other places where custom cursors are used, not only in Sketcher.
Search for "setCursor":
https://github.com/FreeCAD/FreeCAD/sear ... =setCursor
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: Custom cursors and high dpi

Post by vanuan »

Kunda1 wrote: Sat Jul 18, 2020 11:29 am Wow. Sounds kinda hacky.
Well, it's how HiDPI works. You must provide different sizes for the raster graphics. You can provide a single high-resolution image and scale it down, but you would get the Aliasing problem. You can provide a single low-resolution image and scale it up but you would get blurry or pixelated images. Or you could skip scaling and images would just be small.

It's not rocket science, really.
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: Custom cursors and high dpi (Windows and MacOS testers needed)

Post by vanuan »

Steps to reproduce in Windows 10:

(1) Open the "Display settings".
(All settings > System > Display)

(2) Change resolution to the highest value. Change the scaling level to a high value (200% and higher).
Win10_DPI_en.png
Win10_DPI_en.png (69.56 KiB) Viewed 2191 times
(3) Open FreeCAD, create a sketch, create a constraint, notice if the custom cursor size is smaller or the larger than the default one.
Screenshot from 2020-07-18 14-57-19.png
Screenshot from 2020-07-18 14-57-19.png (419.45 KiB) Viewed 2188 times
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Custom cursors and high dpi (Windows and MacOS testers needed)

Post by Kunda1 »

apeltauer wrote::bell:
@apeltauer would you mind testing on Windows and reporting back?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
apeltauer
Posts: 399
Joined: Fri Aug 11, 2017 2:19 pm

Re: Custom cursors and high dpi (Windows and MacOS testers needed)

Post by apeltauer »

Kunda1 wrote: Sat Jul 18, 2020 12:30 pm
apeltauer wrote::bell:
@apeltauer would you mind testing on Windows and reporting back?
Would be no problem but right now i have no 4k display. Just have my notebook with me....
Post Reply