@@ -19,6 +19,7 @@ module Graphics.Vty.Image ( Image(..)
19 , char_fill
19 , char_fill
20 , empty_image
20 , empty_image
21 , translate
21 , translate
22 -- | The possible display attributes used in constructing an `Image`.
23 -- | The possible display attributes used in constructing an `Image`.
23 , module Graphics.Vty.Attributes
24 , module Graphics.Vty.Attributes
@@ -99,6 +100,8 @@ data Image =
99 -- Any image of zero size equals the empty image.
100 -- Any image of zero size equals the empty image.
100 | EmptyImage
101 | EmptyImage
101 | Translation (Int, Int) Image
102 | Translation (Int, Int) Image
103+ -- Crop an image to a size
104+ | ImageCrop (Int, Int) Image
102 deriving Eq
105 deriving Eq
104instance Show Image where
107instance Show Image where
@@ -112,6 +115,8 @@ instance Show Image where
112 = "VertJoin (" ++ show c ++ ", " ++ show r ++ ") ( " ++ show t ++ " ) <-> ( " ++ show b ++ " )"
115 = "VertJoin (" ++ show c ++ ", " ++ show r ++ ") ( " ++ show t ++ " ) <-> ( " ++ show b ++ " )"
113 show ( Translation offset i )
116 show ( Translation offset i )
114 = "Translation ( " ++ show offset ++ ", " ++ show i ++ " )"
117 = "Translation ( " ++ show offset ++ ", " ++ show i ++ " )"
118+ show ( ImageCrop size i )
119+ = "ImageCrop ( " ++ show size ++ ", " ++ show i ++ " )"
115 show ( EmptyImage ) = "EmptyImage"
120 show ( EmptyImage ) = "EmptyImage"
117-- | Currently append in the Monoid instance is equivalent to <->. Future versions will just stack
122-- | 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
203image_width BGFill { output_width = w } = w
208image_width BGFill { output_width = w } = w
204image_width EmptyImage = 0
209image_width EmptyImage = 0
205image_width ( Translation _v i ) = image_width i
210image_width ( Translation _v i ) = image_width i
211+image_width ( ImageCrop _v i ) = min (image_width i) (toEnum $ fst _v)
207-- | The height of an Image. This is the number of display rows the image will occupy.
213-- | The height of an Image. This is the number of display rows the image will occupy.
208image_height :: Image -> Word
214image_height :: Image -> Word
@@ -212,6 +218,7 @@ image_height VertJoin { output_height = r } = r
212image_height BGFill { output_height = r } = r
218image_height BGFill { output_height = r } = r
213image_height EmptyImage = 0
219image_height EmptyImage = 0
214image_height ( Translation _v i ) = image_height i
220image_height ( Translation _v i ) = image_height i
221+image_height ( ImageCrop _v i ) = min (image_height i) (toEnum $ fst _v)
216-- | Combines two images side by side.
223-- | Combines two images side by side.
@@ -328,3 +335,6 @@ empty_image = EmptyImage
328translate :: (Int, Int) -> Image -> Image
335translate :: (Int, Int) -> Image -> Image
329translate v i = Translation v i
336translate v i = Translation v i
338+crop :: (Int, Int) -> Image -> Image
339+crop v i = ImageCrop v i