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 an optional rectangle parameter to TextureNode #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/pygame_sdl2/render.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,28 @@ cdef class TextureNode:
cdef int source_w
cdef int source_h

def __init__(self, tex):
""" Create a TextureNode with a Texture and an optional rectangle that represents the area of the texture to use."""
def __init__(self, tex, rect=None):
if isinstance(tex, Texture):
self.texture = tex
to_sdl_rect((0,0,tex.w,tex.h), &self.source_rect)
to_sdl_rect((0,0,tex.w,tex.h), &self.trimmed_rect)
self.source_w = tex.w
self.source_h = tex.h

elif isinstance(tex, TextureNode):
self.texture = (<TextureNode>tex).texture

else:
raise ValueError()

if rect is not None:
to_sdl_rect(rect, &self.source_rect)
to_sdl_rect((0,0,rect[2],rect[3]), &self.trimmed_rect)
self.source_w = rect[2]
self.source_h = rect[3]
else:
to_sdl_rect((0,0,self.texture.w,self.texture.h), &self.source_rect)
to_sdl_rect((0,0,self.texture.w,self.texture.h), &self.trimmed_rect)
self.source_w = self.texture.w
self.source_h = self.texture.h

def render(self, dest=None):
cdef SDL_Rect dest_rect

Expand Down