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

[DisplayServer] Implement screen_get_pixel method for LinuxBSD/X11, macOS and Windows. #74087

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Feb 27, 2023

Adds function to get screen pixel color. A base for better ColorPicker eyedropper implementation.

@Sauermann
Copy link
Contributor

The ColorPicker would need to decide, if it can rely on DisplayServer to get screen-pixel-colors.
Is this a feature, that should be announced in DisplayServer::has_feature?

@bruvzg bruvzg marked this pull request as ready for review March 1, 2023 07:32
@bruvzg bruvzg requested review from a team as code owners March 1, 2023 07:32
@akien-mga akien-mga modified the milestones: 4.x, 4.1 Mar 2, 2023
@akien-mga akien-mga merged commit 5f2137a into godotengine:master Mar 6, 2023
@akien-mga
Copy link
Member

Thanks!

My understanding would be that this feature could be used to fix #74048 properly?

@CsloudX
Copy link

CsloudX commented Mar 7, 2023

Love this method!

Comment on lines +645 to +650
HDC dc = GetDC(0);
COLORREF col = GetPixel(dc, p.x, p.y);
if (col != CLR_INVALID) {
return Color(float(col & 0x000000FF) / 256.0, float((col & 0x0000FF00) >> 8) / 256.0, float((col & 0x00FF0000) >> 16) / 256.0, 1.0);
}
ReleaseDC(NULL, dc);
Copy link

Choose a reason for hiding this comment

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

Why we don't call ReleaseDC(...) if the color is valid?
And why we don't check that GetDC(0) is not NULL?

Copy link
Contributor

Choose a reason for hiding this comment

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

If not wrong, window's style class uses CS_OWNDC flag, meaning the DC is unique and shared for all drawing operations.

@bruvzg bruvzg deleted the get_screen_px branch May 21, 2023 20:48
@akien-mga akien-mga changed the title [DisplayServer] Implement screen_get_pixel method for LinuxBSD/X11, macOS and Windows. [DisplayServer] Implement screen_get_pixel method for LinuxBSD/X11, macOS and Windows. Jul 5, 2023
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.

6 participants