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

Graphx coordinate system and platforms #51

Open
tlvenn opened this issue Nov 29, 2022 · 3 comments
Open

Graphx coordinate system and platforms #51

tlvenn opened this issue Nov 29, 2022 · 3 comments

Comments

@tlvenn
Copy link
Contributor

tlvenn commented Nov 29, 2022

Hi @roipeker,

I have observed some weird behaviors regarding the coordinate system and its origin depending on the platform.
I have tested it on OSX and on the web with Flutter 3.3.9

My expectation is as follow, given the following code :

final rect = GShape();
rect.graphics.lineStyle(1, Colors.red, false).drawRect(0, 0, 9, 9);
addChild(rect);

I would expect to see a rectangle of 10px * 10px starting at the very top left of the stage.

  1. OSX

With OSX, no matter the app / stage dimension I consistently get the following:
image

The height of the rectangle is 8px and the width is 9px.

If i want to draw a line at the very top of the stage, i have to do

final vline = GShape();
vline.graphics.lineStyle(1, Colors.green, false).moveTo(0, 2).lineTo(100, 2).endFill();
addChild(vline);

image

  1. Web (Chrome)

Things get funky here, 1px is always missing on the left so the rectangle is 9px wide, same as on OSX.

However depending on the height of the chrome window, the stage origin float between 2 int coordinates and can even fall in between resulting in more than 1 pixel being painted for the line.

The code for the following is exactly as before and what was posted above for the rectangle and the line.
Only the height of the Chrome window changed.

image
image
image
image
image

There are probably multiple things at play here but is my expectation correct to begin with ?

@roipeker
Copy link
Owner

That's how Flutter renders the line Paint. Always expect the line to be centered. Regarding the inconsistency on platforms, again should be on Flutter side (GraphX doesn't make much on that area except a warning when not rendering using WebGL as several features are not supported on html rendering).

I would expect to see 0.5px red line on the left side.

Why the web sample is cropped at the bottom?

Try CustomPainter and see if you get different results.

@roipeker
Copy link
Owner

Also, i would suggest u join the Discord or Telegram channels as it seems you are using GraphX regularly; and it's a great way to bounce ideas faster.

@roipeker
Copy link
Owner

That's how Flutter renders the line Paint. Always expect the line to be centered. Regarding the inconsistency on platforms, again should be on Flutter side (GraphX doesn't make much on that area except a warning when not rendering using WebGL as several features are not supported on html rendering).

I would expect to see 0.5px red line on the left side.

Why the web sample is cropped at the bottom?

Try CustomPainter and see if you get different results.

Beware the dpi scale factor in Flutter. 1px is actually a logical pixel... retina renders at 2x. If you wanna get a real pixel line use lineStyle(0)

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

No branches or pull requests

2 participants