@@ -1908,20 +1908,91 @@ def yiq(self, value: Union[Seq, Vector4, Vector3]) -> None:
1908
1908
ColorPtr = POINTER (Color )
1909
1909
1910
1910
1911
- class Rectangle (Structure ):
1911
+ class _Rectangle (Structure ):
1912
1912
_fields_ = [
1913
1913
('x' , c_float ),
1914
1914
('y' , c_float ),
1915
1915
('width' , c_float ),
1916
1916
('height' , c_float ),
1917
1917
]
1918
1918
1919
+
1920
+ class Rectangle (_Rectangle ):
1921
+
1922
+ @classmethod
1923
+ def from_ltrb (cls , * args ) -> 'Rectangle' :
1924
+ """Alternate constructor."""
1925
+ result = _flatten ((int , float ), * args , map_to = float )
1926
+ if len (result ) != 4 :
1927
+ raise ValueError ("Too many or too few initializers ({} instead of 4)." .format (len (result )))
1928
+
1929
+ l , t , r , b = result
1930
+ return cls (l , t , r - l , t - b )
1931
+
1932
+ def __init__ (self , * args ) -> None :
1933
+ """Constructor."""
1934
+ result = _flatten ((int , float ), * args , map_to = float )
1935
+ if len (result ) != 4 :
1936
+ raise ValueError ("Too many or too few initializers ({} instead of 4)." .format (len (result )))
1937
+ super (Rectangle , self ).__init__ (* result )
1938
+
1919
1939
def __str__ (self ) -> str :
1920
1940
return "({}, {}, {}, {})" .format (self .x , self .y , self .width , self .height )
1921
1941
1922
1942
def __repr__ (self ) -> str :
1923
1943
return "{}({}, {}, {}, {})" .format (self .__class__ .__qualname__ , self .x , self .y , self .width , self .height )
1924
1944
1945
+ @property
1946
+ def empty (self ) -> bool :
1947
+ """Returns whether the rec's width or height is below or equal zero."""
1948
+ return self .width <= 0 or self .height <= 0
1949
+
1950
+ @property
1951
+ def r (self ) -> float :
1952
+ """Gets or sets the right-most rect coordinate."""
1953
+ return self .x + self .width
1954
+
1955
+ @r .setter
1956
+ def r (self , value : float ) -> None :
1957
+ self .x = float (value ) - self .width
1958
+
1959
+ @property
1960
+ def b (self ) -> float :
1961
+ """Gets or sets the bottom-most rect coordinate."""
1962
+ return self .y + self .height
1963
+
1964
+ @b .setter
1965
+ def b (self , value : float ) -> None :
1966
+ self .y = float (value ) - self .height
1967
+
1968
+ @property
1969
+ def center (self ) -> Vector2 :
1970
+ """Gets or sets the rec position relative to its center."""
1971
+ return Vector2 (self .x + self .width * 0.5 ,
1972
+ self .y + self .height * 0.5 )
1973
+
1974
+ @center .setter
1975
+ def center (self , value : Union [Seq , Vector2 ]) -> None :
1976
+ self .pos = _vec2 (value ) - self .size * 0.5
1977
+
1978
+ @property
1979
+ def pos (self ) -> Vector2 :
1980
+ """Gets or sets the rec top-left coordinate."""
1981
+ return Vector2 (self .x , self .y )
1982
+
1983
+ @pos .setter
1984
+ def pos (self , value : Union [Seq , Vector2 ]) -> None :
1985
+ self .x , self .y = map (float , value )
1986
+
1987
+ @property
1988
+ def size (self ) -> Vector2 :
1989
+ """Gets or sets the rec dimensions."""
1990
+ return Vector2 (self .width , self .height )
1991
+
1992
+ @size .setter
1993
+ def size (self , value : Union [Seq , Vector2 ]) -> None :
1994
+ self .width , self .height = map (float , value )
1995
+
1925
1996
1926
1997
class Image (Structure ):
1927
1998
_fields_ = [
@@ -1991,7 +2062,7 @@ def __str__(self) -> str:
1991
2062
return "(RENDERTEXTURE: {}w, {}h, texture: {}, depth: {})" .format (self .width , self .height , self .texture , self .depth )
1992
2063
1993
2064
1994
- class NPatchInfo (Structure ):
2065
+ class _NPatchInfo (Structure ):
1995
2066
_fields_ = [
1996
2067
('sourceRec' , Rectangle ),
1997
2068
('left' , c_int ),
@@ -2001,11 +2072,36 @@ class NPatchInfo(Structure):
2001
2072
('type' , c_int ),
2002
2073
]
2003
2074
2004
- def set_border_width (self , a : float , b : float , c : float , d : float ):
2005
- self .borderWidth = (c_float * 4 )(_float (a ), _float (b ), _float (c ), _float (d ))
2006
2075
2007
- def set_padding (self , a : int , b : int , c : int , d : int ):
2008
- self .padding = (c_int * 4 )(_int (a ), _int (b ), _int (c ), _int (d ))
2076
+ class NPatchInfo (_NPatchInfo ):
2077
+
2078
+ def __init__ (self , source_rec : 'Rectangle' , left : int = 1 , top :int = 1 , right : int = 1 , bottom : int = 1 , npatch_type : Union [int , 'NPatchType' ]= 0 ) -> None :
2079
+ if npatch_type not in NPatchType :
2080
+ npatch_type = {
2081
+ 0 : NPT_9PATCH ,
2082
+ 1 : NPT_3PATCH_VERTICAL ,
2083
+ 2 : NPT_3PATCH_VERTICAL
2084
+ }.get (npatch_type , NPT_9PATCH )
2085
+
2086
+ super (NPatchInfo , self ).__init__ (source_rec , left , top , right , bottom , npatch_type )
2087
+
2088
+ def __str__ (self ) -> str :
2089
+ """Textual representation."""
2090
+ npt = {
2091
+ 0 : NPT_9PATCH ,
2092
+ 1 : NPT_3PATCH_VERTICAL ,
2093
+ 2 : NPT_3PATCH_VERTICAL
2094
+ }.get (self .type , NPT_9PATCH ).name
2095
+ return "(NPATCHINFO: rec: {0.sourceRec}, ltrb: [{0.left}, {0.top}, {0.right}, {0.bottom}], type: {1})" .format (self , npt )
2096
+
2097
+ def __repr__ (self ) -> str :
2098
+ rc = repr (self .sourceRec )
2099
+ npt = {
2100
+ 0 : NPT_9PATCH ,
2101
+ 1 : NPT_3PATCH_VERTICAL ,
2102
+ 2 : NPT_3PATCH_VERTICAL
2103
+ }.get (self .type , NPT_9PATCH ).name
2104
+ return "{0.__class__.__qualname__}({1}, {0.left}, {0.top}, {0.right}, {0.bottom}, {2})" .format (self , rc , npt )
2009
2105
2010
2106
2011
2107
class CharInfo (Structure ):
@@ -5024,3 +5120,7 @@ def set_audio_stream_volume(stream: AudioStream, volume: float) -> None:
5024
5120
def set_audio_stream_pitch (stream : AudioStream , pitch : float ) -> None :
5025
5121
"""Set pitch for audio stream (1.0 is base level)"""
5026
5122
return _rl .SetAudioStreamPitch (stream , _float (pitch ))
5123
+
5124
+ np = NPatchInfo (Rectangle (5 , 5 , 10 , 10 ), 1 , 1 , 1 , 1 , 0 )
5125
+ print (repr (np ))
5126
+ print (np )
0 commit comments