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!
Post Reply
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

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

Post by vanuan »

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
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Custom cursors and high dpi

Post by openBrain »

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: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: Custom cursors and high dpi

Post by vanuan »

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
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Custom cursors and high dpi

Post by openBrain »

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

Re: Custom cursors and high dpi

Post by vanuan »

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
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Custom cursors and high dpi

Post by openBrain »

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
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Custom cursors and high dpi

Post by Kunda1 »

What about looking at how other FOSS projects deal with this perhaps we can use their assets too?
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
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Custom cursors and high dpi

Post by openBrain »

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: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: Custom cursors and high dpi

Post by vanuan »

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: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: Custom cursors and high dpi

Post by vanuan »

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?
Post Reply