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

Add make_local_canvas_position_global, the inverse to make_canvas_position_local #36931

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Razzlegames
Copy link
Contributor

@Razzlegames Razzlegames commented Mar 9, 2020

Make a local canvas position transformed to global space.

  • Just the inverse of Vector2 make_canvas_position_local(const Vector2 &screen_point) const;

Finally a follow up to #4854 , you know... 4 years later. :)

Test project: /~https://github.com/Razzlegames/GodotCanvasLocalToGlobalTest

Make a local canvas position global
@Razzlegames Razzlegames requested a review from a team as a code owner March 9, 2020 05:35
@Razzlegames
Copy link
Contributor Author

Made a test project. Please let me know if there's a formal test framework to add something to. Gut is looking pretty great, by the way: /~https://github.com/bitwes/Gut

@Razzlegames Razzlegames changed the title Add inverse to make_canvas_position_local Add make_canvas_position_local, the inverse to make_canvas_position_local Mar 9, 2020
@Razzlegames Razzlegames changed the title Add make_canvas_position_local, the inverse to make_canvas_position_local Add make_local_canvas_position, the inverse to make_canvas_position_local Mar 9, 2020
@Calinou
Copy link
Member

Calinou commented Mar 9, 2020

Made a test project. Please let me know if there's a formal test framework to add something to. Gut is looking pretty great, by the way: /~https://github.com/bitwes/Gut

We don't have built-in unit tests yet, but once #30743 is merged, there will be a way to write unit tests in C++ (which involve less moving parts than tests written in GDScript).

@realkotob
Copy link
Contributor

I think the name of the function can be better, or at least it should follow the same naming pattern as the old function.

How about "make local position canvas"?

@Razzlegames
Copy link
Contributor Author

Razzlegames commented Mar 10, 2020

Hmm that's better. Honestly both are clumsy.

I hate the original naming I choose, but I was trying to stick to the previous convention based on suggestions. I'd rather call both something like global_position_to_local and local_position_to_global or something.

@realkotob
Copy link
Contributor

realkotob commented Mar 10, 2020

I prefer not to use local and global in this case, I think 'screen' and 'canvas' are better names since this code is specific to Canvas Item objects.

I think something like this would be best: make_canvas_position_to_screen_position and make_screen_position_to_canvas_position

or even better, convert_position_from_canvas_to_screen and convert_position_from_screen_to_canvas (instead of convert we can use change or even make).

@Razzlegames
Copy link
Contributor Author

Razzlegames commented Mar 10, 2020 via email

@Razzlegames Razzlegames changed the title Add make_local_canvas_position, the inverse to make_canvas_position_local Add make_local_canvas_position_global, the inverse to make_canvas_position_local Mar 13, 2020
@Razzlegames
Copy link
Contributor Author

Razzlegames commented Mar 13, 2020

Updated PR:

Ok what about make_local_canvas_position_global ? I think this follows the old naming: make_canvas_position_local

  • The position is local (to a canvas), so local is an adjective in, local_canvas_position ,
  • The position is in a CanvasItem so canvas is an adjective in local_canvas_position
  • The end transformation is global (as apposed to local) so the make...global seems to make sense

Also it won't break the old API

@Razzlegames Razzlegames force-pushed the CanvasLocalToGlobal_Master branch from 074ccc2 to 260a2a3 Compare March 18, 2020 19:12
@realkotob
Copy link
Contributor

realkotob commented Mar 19, 2020

@Razzlegames The new names sound fine to me, it's to have redundant function names exposed instead of unclear ones.

Can potentially be improved but unless we find some existing naming convention to follow, this is probably the best we can think of for now.

@Calinou Calinou added this to the 4.0 milestone Jan 5, 2021
@YuriSizov YuriSizov modified the milestones: 4.0, 4.x Feb 9, 2023
@KoBeWi
Copy link
Member

KoBeWi commented Oct 23, 2024

make_canvas_position_local() looks so obscure; I was not aware this method exists until now and I've been using equivalents (you just need get_viewport().canvas_transform to do the same). I guess if the original method exists, there is no reason not to have the opposite one, however the usefulness is questionable IMO.

Needs rebase and style fixes.

Comment on lines +545 to +546
Transforms [code]local_point[/code] to a screen point.
Basically the reverse of [code] make_canvas_position_local [/code]
Copy link
Member

@KoBeWi KoBeWi Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Transforms [code]local_point[/code] to a screen point.
Basically the reverse of [code] make_canvas_position_local [/code]
Transforms [code]local_point[/code] to a point in viewport's coordinate system.
See also [method get_global_transform_with_canvas].

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

Successfully merging this pull request may close these issues.

5 participants