Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mac] Bitmaps always drawn in integral mode - is this deliberate? #90

Open
geraintluff opened this issue Jan 15, 2019 · 3 comments
Open

Comments

@geraintluff
Copy link

geraintluff commented Jan 15, 2019

On Mac the bitmap drawing methods in CGDrawContext.cpp always use integral mode:

if (auto context = beginCGContext (false, true))

if (auto context = beginCGContext (false, true))

Every other invocation of beginContext() in that file uses the integral mode as the second argument, looking like this:

if (auto context = beginCGContext (true, getDrawMode ().integralMode ()))

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.)

@geraintluff geraintluff changed the title [Mac] Why are bitmaps always drawn in integral mode? [Mac] Bitmaps always drawn in integral mode - is this deliberate? Jan 15, 2019
@scheffle
Copy link
Collaborator

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 ?

@geraintluff
Copy link
Author

geraintluff commented Jan 15, 2019

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?

@scheffle
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants