vstgui
vstgui copied to clipboard
[Mac] Bitmaps always drawn in integral mode - is this deliberate?
On Mac the bitmap drawing methods in CGDrawContext.cpp
always use integral mode:
https://github.com/steinbergmedia/vstgui/blob/2bf29afb1a6cadae2f189e8266a53d3b96d2ff74/vstgui/lib/platform/mac/cgdrawcontext.cpp#L609
https://github.com/steinbergmedia/vstgui/blob/2bf29afb1a6cadae2f189e8266a53d3b96d2ff74/vstgui/lib/platform/mac/cgdrawcontext.cpp#L573
Every other invocation of beginContext()
in that file uses the integral mode as the second argument, looking like this:
https://github.com/steinbergmedia/vstgui/blob/2bf29afb1a6cadae2f189e8266a53d3b96d2ff74/vstgui/lib/platform/mac/cgdrawcontext.cpp#L136
I found this out because I was drawing a rotating dial. The rotation works fine (including interpolation), but the offset is rounded to the nearest integral position, causing my dial to jump around within a pixel (screencap video). When I changed the above two lines to match the others, the rotation became smooth.
(I haven't checked this on Windows (only just starting out), so I don't know whether gdiplusdrawcontext.cpp
does the same thing.)
Yes, this is intentional. Otherwise bitmaps will be drawn blurry when the scale factor of the transformation matrix is not an integer. Why don't you pre render your dial and use the CAnimKnob class ?
If the transformation matrix is doing non-integer scaling, then yes, your bitmap's location might land on a non-integer co-ordinate. I didn't see a visual difference when I changed it, except my offsets stopped snapping to the nearest pixel, but admittedly I was also scaling the bitmap so it was interpolating anyway. (Wouldn't that be fairly common though, for a non-integer scale-factor?)
Anyway - if that's the issue, couldn't users enable/disable integral mode for that draw?
This is the same issue as when you draw a line which is meant to be exact-pixel-aligned, but a transform means it's not. I thought choosing what to do in that situation is exactly why "integral mode" is optional?
You'll see the difference when you use a CNinePartTiledBitmap on a scaled context. And for line drawing, pixel aligned drawing should work with a transform, sure only the start and end point is pixel aligned, but if you choose a line width of exactly one pixel (see CDrawContext::getHairlineSize) then it is pixel aligned. You've not answered my question, why you don't choose a pre rendered bitmap ? But anyway, to add an option to draw a bitmap not pixel aligned is always an option. If you like you can work this out and create a pull request.