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

Interaction with shapes #2330

Open
VeyDlin opened this issue Dec 5, 2022 · 6 comments
Open

Interaction with shapes #2330

VeyDlin opened this issue Dec 5, 2022 · 6 comments

Comments

@VeyDlin
Copy link

VeyDlin commented Dec 5, 2022

I'm trying to determine which shapes are located by coordinates (mouse click).

I realized that skia does not provide such an API and I need to implement it myself, but I have no ideas on this.

Everything is complicated by the fact that I need to understand exactly that the click occurred on the figure, and not its square hitbox, for example, I can click inside the text with the number "0" and this should not be considered a hit, there are also rectangles with rounded edges, complex curves, different shapes, and there are thousands of them on the canvas

I will be grateful for any advice because right now I don't even know how to Google for a solution to my problem

@themcoo
Copy link

themcoo commented Dec 6, 2022

Skia is a rendering library, what you are asking for is completely out of scope.

@VeyDlin
Copy link
Author

VeyDlin commented Dec 6, 2022

Skia is a rendering library, what you are asking for is completely out of scope.

Yes, I understand that, I just wanted to find out what ways there are in general,

I could create a mathematical model of each figure I draw and count its collision,

or I could add its own canvas to each drawn figure and draw it there again and get a pixel at the right coordinates (if there is such a function in skia at all), then I will get thousands of canvases, or tens of thousands, and maybe it won't even work too slowly,

I could also create a polygon around pixels, for this I also need to somehow get a drawn shape separately from the general canvas, is this possible in skia?

But it still seems to me that there should be an easier way, if skia returned at least some information about the shape that it just rendered, it would be easier, I think

@willn1337
Copy link

willn1337 commented Dec 6, 2022

you could draw the shapes to a new surface (not rendered to the screen), pass a unique color for each shape, then call hittestsurface.ReadPixels(..., mousePos) and check if the pixel color is a match?

@utenma
Copy link

utenma commented Jul 30, 2024

this is just speculation at the moment but representing the UI as a DOM-like tree of System.Drawing.Drawing2D or equivalent for .Net Core objects then mapping the DOM-like tree to skia drawing methods should be one approach

Then on pointer events use

Rectangle.Contains
GraphicsPath.IsVisible

For prioritizing elements of top of others, the DOM-like tree need z-index

@VeyDlin issue should be closed and instead a discussion thread in discussions as it's outside skia codebase

@wieslawsoltes
Copy link

You can try https://github.com/wieslawsoltes/Draw2D

@Aniganesh
Copy link

Hi @wieslawsoltes! I opened your library and it seems the github pages deployment has failed.

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

6 participants