@@ -19,6 +19,7 @@ module Graphics.Vty.Image ( Image(..)
1919 , char_fill
2020 , empty_image
2121 , translate
22+ , crop
2223 -- | The possible display attributes used in constructing an `Image`.
2324 , module Graphics.Vty.Attributes
2425 )
@@ -99,6 +100,8 @@ data Image =
99100 -- Any image of zero size equals the empty image.
100101 | EmptyImage
101102 | Translation (Int, Int) Image
103+ -- Crop an image to a size
104+ | ImageCrop (Int, Int) Image
102105 deriving Eq
103106
104107instance Show Image where
@@ -112,6 +115,8 @@ instance Show Image where
112115 = "VertJoin (" ++ show c ++ ", " ++ show r ++ ") ( " ++ show t ++ " ) <-> ( " ++ show b ++ " )"
113116 show ( Translation offset i )
114117 = "Translation ( " ++ show offset ++ ", " ++ show i ++ " )"
118+ show ( ImageCrop size i )
119+ = "ImageCrop ( " ++ show size ++ ", " ++ show i ++ " )"
115120 show ( EmptyImage ) = "EmptyImage"
116121
117122-- | Currently append in the Monoid instance is equivalent to <->. Future versions will just stack
@@ -203,6 +208,7 @@ image_width VertJoin { output_width = w } = w
203208image_width BGFill { output_width = w } = w
204209image_width EmptyImage = 0
205210image_width ( Translation _v i ) = image_width i
211+image_width ( ImageCrop _v i ) = min (image_width i) (toEnum $ fst _v)
206212
207213-- | The height of an Image. This is the number of display rows the image will occupy.
208214image_height :: Image -> Word
@@ -212,6 +218,7 @@ image_height VertJoin { output_height = r } = r
212218image_height BGFill { output_height = r } = r
213219image_height EmptyImage = 0
214220image_height ( Translation _v i ) = image_height i
221+image_height ( ImageCrop _v i ) = min (image_height i) (toEnum $ fst _v)
215222
216223-- | Combines two images side by side.
217224--
@@ -328,3 +335,6 @@ empty_image = EmptyImage
328335translate :: (Int, Int) -> Image -> Image
329336translate v i = Translation v i
330337
338+crop :: (Int, Int) -> Image -> Image
339+crop v i = ImageCrop v i
340+