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

A forum for research and development of the user interface of FreeCAD

Moderator: agryson

User avatar
vanuan
Posts: 457
Joined: Wed Oct 24, 2018 9:49 pm

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

Postby vanuan » 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

"......+.........................",
"......+.........................",
"......+.........................",
"......+.........................",
"......+.........................",
"................................",
"+++++...+++++...................",
"................................",
"......+.........................",
"......+.........................",
"......+.........................",
"......+.........................",
"......+.........................",
"................................",
"................................",
"..........................###...",
"........###################.##..",
".......#..................###.#.",
"......#........................#",
".....#.........................#",
"....#.....###..................#",
"....#.....#.#..................#",
".....#....###.................#.",
"......#.......................#.",
".......#.....................#..",
"........#####################...",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................"};
Last edited by Kunda1 on Sat Jul 18, 2020 11:30 am, edited 1 time in total.
Reason: Added request for Windows and MacOS testers in forum thread
openBrain
Posts: 4655
Joined: Fri Nov 09, 2018 5:38 pm

Re: Custom cursors and high dpi

Postby openBrain » Sat Jul 18, 2020 7:24 am

Cursors are XPM but I guess it would be doable to define them as SVG then use BitmapFactory or some Qt graphics class to convert them.
To me a problem is to manage things correctly when viewport spans over a HiDpi display and a "standard" one.
User avatar
vanuan
Posts: 457
Joined: Wed Oct 24, 2018 9:49 pm

Re: Custom cursors and high dpi

Postby vanuan » Sat Jul 18, 2020 9:40 am

Let's solve the problems one by one. This one is about the discrepancy between standard cursors and custom ones.

Here's a solution without SVG files (results in blurred icons): https://github.com/FreeCAD/FreeCAD/pull/3712
openBrain
Posts: 4655
Joined: Fri Nov 09, 2018 5:38 pm

Re: Custom cursors and high dpi

Postby openBrain » Sat Jul 18, 2020 10:02 am

This is what I call solving problem half by half.
User avatar
vanuan
Posts: 457
Joined: Wed Oct 24, 2018 9:49 pm

Re: Custom cursors and high dpi

Postby vanuan » Sat Jul 18, 2020 10:10 am

openBrain wrote:
Sat Jul 18, 2020 10:02 am
This is what I call solving problem half by half.
I dare you to try it, maybe it's fully solved :)
If not, I'm waiting for feedback.
Unforutnately, I don't have access to a second monitor right now.
openBrain
Posts: 4655
Joined: Fri Nov 09, 2018 5:38 pm

Re: Custom cursors and high dpi

Postby openBrain » Sat Jul 18, 2020 10:20 am

I don't have HiDpi. The main problem with your PR is that it will scale cursor in every case, even if not needed. So everybody will get a blurred cursor, even those that don't deserve it.
User avatar
Kunda1
Posts: 8456
Joined: Thu Jan 05, 2017 9:03 pm

Re: Custom cursors and high dpi

Postby Kunda1 » Sat Jul 18, 2020 10:30 am

What about looking at how other FOSS projects deal with this perhaps we can use their assets too?
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
openBrain
Posts: 4655
Joined: Fri Nov 09, 2018 5:38 pm

Re: Custom cursors and high dpi

Postby openBrain » Sat Jul 18, 2020 10:43 am

IMO, as cursor isn't generally the only implication (but also are icons, fonts, ...), we'd better use Qt abilities rather than some custom algorithm. ;)
User avatar
vanuan
Posts: 457
Joined: Wed Oct 24, 2018 9:49 pm

Re: Custom cursors and high dpi

Postby vanuan » Sat Jul 18, 2020 10:57 am

openBrain wrote:
Sat Jul 18, 2020 10:20 am
I don't have HiDpi. The main problem with your PR is that it will scale cursor in every case, even if not needed. So everybody will get a blurred cursor, even those that don't deserve it.
Nope, if not needed, devicePixelRatio will return 1, so it would be of original size.
User avatar
vanuan
Posts: 457
Joined: Wed Oct 24, 2018 9:49 pm

Re: Custom cursors and high dpi

Postby vanuan » Sat Jul 18, 2020 11:03 am

openBrain wrote:
Sat Jul 18, 2020 10:43 am
IMO, as cursor isn't generally the only implication (but also are icons, fonts, ...), we'd better use Qt abilities rather than some custom algorithm. ;)
My solution is based on the Qt documentation
https://doc.qt.io/qt-5/scalability.html ... n-platform

Code: Select all

if ( QGuiApplication::primaryScreen()->devicePixelRatio() >= 2 ) {
    imageVariant = "@2x";
} else {
    imageVariant = "";
}
This is for QML, but FreeCAD doesn't currently use QML, so I adapted accordingly.

The issue is that we don't have multiple icon sizes for different pixel ratios, hence why I asked for help. Is anybody familiar with Inkscape? Or could provide raster icons of 2X-4X size?