In general, Xojo’s HiDPI support is pretty good. It requires very little thought. Until you need to create pictures…
In this case, I’m taking a few different pictures and compositing them together into a single picture to reuse it multiple times. It greatly simplifies the code. Normally, it would look something like:
Dim Composite As New Picture(40, 40)
Composite.Graphics.DrawPicture(Shadow, 0, 0)
Composite.Graphics.DrawPicture(Background, 0, 0)
Composite.Graphics.DrawPicture(Foreground, 0, 0)
And I’d be done. But with HiDPI, that will only produce a 1.0 image, which is understandable. The problem is creating a version for the intended scale. This is in a paint event, so I only ever need a single scaling factor at a time.
I have tried setting Composite.Graphics.ScaleX and ScaleY accordingly, but that just makes everything draw larger. Composite.HorizontalResolution and VerticalResolution have no effect.
The ONLY thing I’ve found to work is manually creating one picture for each possible scale factor:
[code]Dim Composites() As Picture
For Factor As Integer = 1 To 3
Dim BestShadow As Picture = Shadow.BestRepresentation(40, 40, Factor)
Dim BestBackground As Picture = Shadow.BestRepresentation(40, 40, Factor)
Dim BestForeground As Picture = Shadow.BestRepresentation(40, 40, Factor)
Dim Pic As New Picture(40 * Factor, 40 * Factor)
Pic.Graphics.DrawPicture(BestShadow, 0, 0, BestShadow.Width, BestShadow.Height, 0, 0, BestShadow.Width, BestShadow.Height)
Pic.Graphics.DrawPicture(BestBackground, 0, 0, BestBackground.Width, BestBackground.Height, 0, 0, BestBackground.Width, BestBackground.Height)
Pic.Graphics.DrawPicture(BestForeground, 0, 0, BestForeground.Width, BestForeground.Height, 0, 0, BestForeground.Width, BestForeground.Height)
Composites.Append(Pic)
Next
Dim Composite As New Picture(40, 40, Composites)[/code]
This is maddeningly frustrating because it’s not only a lot of code, I have no use for 2/3 of the images I just created. There has to be a better way. Please tell me I’m missing something obvious. Because everything else about Xojo’s HiDPI is pretty elegant, I have a hard time believing this mess is the “right” way to do it.