Skip to content

Added __int__() function to Color in graphics.pyx. Fixes #155: "Color… #158

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Necklaces
Copy link

@Necklaces Necklaces commented Jun 10, 2017

def __int__(self): added to the Color class in graphics.pyx, just like in sfml; https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1Color.php#a48f75a30fc93e79390e6d700e4b4b558
https://github.com/SFML/SFML/blob/fae3b65f0567f87fa9925cd42d28df15eb69e79c/src/SFML/Graphics/Color.cpp

What SFML does:

  1. shifts red (which is a uint8) 24 bits to the left
  2. shifts green (which is a uint8) 16 bits to the left
  3. shifts blue (which is a uint8) 8 bits to the left
  4. ORs (|) red, green, blue, and alpha together, forming a uint32 representation of the rgba color.

What this does:
Same, but since this is python it ANDs (&) self.r/g/b/a with 0xFF (8 bits) to make sure the shifting doesn't end up bigger or smaller than a 32bit uint.

SFML example: (1 << 24) | (2 << 16) | (3 << 8) | 4;
returns: 16909060

python-sfml: sf.Color(1,2,3,4).__int__()
returns: 16909060 

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

Successfully merging this pull request may close these issues.

2 participants