6 """Return the subsurface of a surface, with some help, checks.
8 <pre>subsurface(s,r): return surface</pre>
11 if r
.x
< 0 or r
.y
< 0:
12 raise "gui.subsurface: %d %d %s"%(s
.get_width(),s
.get_height(),r
)
13 w
,h
= s
.get_width(),s
.get_height()
18 assert(r
.w
>= 0 and r
.h
>= 0)
19 return s
.subsurface(r
)
23 A surface-like object which smartly handle out-of-area blitting.
25 <pre>ProxySurface(parent, rect, real_surface=None, offset=(0, 0))</pre>
27 <p>only one of parent and real_surface should be supplied (non None)</p>
29 <dt>parent<dd>a ProxySurface object
30 <dt>real_surface<dd>a pygame Surface object
33 <strong>Variables</strong>
36 <dt>mysubsurface<dd>a real and valid pygame.Surface object to be used
38 <dt>x, y<dd>if the proxy surface is lefter or higher than the parent,
40 <dt>offset<dd>an optional feature which let you scroll the whole blitted
44 def __init__(self
, parent
, rect
, real_surface
, offset
=(0, 0)):
47 if rect
.x
< 0: self
.x
= rect
.x
48 if rect
.y
< 0: self
.y
= rect
.y
49 self
.real_surface
= real_surface
50 if real_surface
== None:
51 self
.mysubsurface
= parent
.mysubsurface
.subsurface(
52 parent
.mysubsurface
.get_rect().clip(rect
))
54 self
.mysubsurface
= real_surface
.subsurface(
55 real_surface
.get_rect().clip(rect
))
59 def blit(self
, s
, pos
, rect
=None):
60 if rect
== None: rect
= s
.get_rect()
61 pos
= (pos
[0] + self
.offset
[0] + self
.x
, pos
[1] + self
.offset
[1] + self
.y
)
62 self
.mysubsurface
.blit(s
, pos
, rect
)
64 def subsurface(self
, rect
):
65 r
= pygame
.Rect(rect
).move(self
.offset
[0] + self
.x
,
66 self
.offset
[1] + self
.y
)
67 return ProxySurface(self
, r
, self
.real_surface
)
69 def fill(self
, color
, rect
=None):
70 if rect
!= None: self
.mysubsurface
.fill(color
, rect
)
71 else: self
.mysubsurface
.fill(color
)
72 def get_rect(self
): return self
.rect
73 def get_width(self
): return self
.rect
[2]
74 def get_height(self
): return self
.rect
[3]
75 def get_abs_offset(): return self
.rect
[:2]
76 def get_abs_parent(): return self
.mysubsurface
.get_abs_parent()
77 def set_clip(self
, rect
=None):
78 if rect
== None: self
.mysubsurface
.set_clip()
80 rect
= [rect
[0] + self
.offset
[0] + self
.x
, rect
[1] + self
.offset
[0] + self
.y
, rect
[2], rect
[3]]
81 self
.mysubsurface
.set_clip(rect
)
90 A surface-like object which smartly handle out-of-area blitting.
92 <pre>ProxySurface(parent, rect, real_surface=None, offset=(0, 0))</pre>
94 <p>only one of parent and real_surface should be supplied (non None)</p>
96 <dt>parent<dd>a ProxySurface object
97 <dt>real_surface<dd>a pygame Surface object
100 <strong>Variables</strong>
103 <dt>mysubsurface<dd>a real and valid pygame.Surface object to be used
105 <dt>x, y<dd>if the proxy surface is lefter or higher than the parent,
107 <dt>offset<dd>an optional feature which let you scroll the whole blitted
111 def __init__(self
, parent
, rect
, real_surface
, offset
=(0, 0)):
114 if rect
[0] < 0: self
.x
= rect
[0]
115 if rect
[1] < 0: self
.y
= rect
[1]
116 self
.real_surface
= real_surface
117 if real_surface
== None:
118 self
.mysubsurface
= parent
.mysubsurface
.subsurface(parent
.mysubsurface
.get_rect().clip(rect
))
120 self
.mysubsurface
= real_surface
.subsurface(real_surface
.get_rect().clip(rect
))
121 rect
[0], rect
[1] = 0, 0
124 def blit(self
, s
, pos
, rect
=None):
125 if rect
== None: rect
= s
.get_rect()
126 pos
= (pos
[0] + self
.offset
[0] + self
.x
, pos
[1] + self
.offset
[1] + self
.y
)
127 self
.mysubsurface
.blit(s
, pos
, rect
)
129 def subsurface(self
, rect
): return ProxySurface(self
, pygame
.Rect(rect
).move(self
.offset
[0] + self
.x
, self
.offset
[1] + self
.y
),self
.real_surface
)
130 def fill(self
, color
, rect
=None):
131 if rect
!= None: self
.mysubsurface
.fill(color
, rect
)
132 else: self
.mysubsurface
.fill(color
)
133 def get_rect(self
): return self
.rect
134 def get_width(self
): return self
.rect
[2]
135 def get_height(self
): return self
.rect
[3]
136 def get_abs_offset(): return self
.rect
[:2]
137 def get_abs_parent(): return self
.mysubsurface
.get_abs_parent()
138 def set_clip(self
, rect
=None):
139 if rect
== None: self
.mysubsurface
.set_clip()
141 rect
= [rect
[0] + self
.offset
[0] + self
.x
, rect
[1] + self
.offset
[0] + self
.y
, rect
[2], rect
[3]]
142 self
.mysubsurface
.set_clip(rect
)