on master help sign in
Add padded image ctor and related code
commitadfb3b35e7d995bba7d481dd2abdf1d7ccb28129 authorBen Boeckel <MathStuf@gmail.com> dateSat 2 Apr 2011, 00:41 (16 years ago) parenta5d0a6b
3 files changed+18
src/Graphics/Vty/Image.hs+9 src/Graphics/Vty/Picture.hs+1 src/Graphics/Vty/Span.hs+8
src/Graphics/Vty/Image.hs+9
@@ -20,6 +20,7 @@ module Graphics.Vty.Image ( Image(..)
2020 , empty_image
2121 , translate
2222 , crop
23+ , pad
2324 -- | The possible display attributes used in constructing an `Image`.
2425 , module Graphics.Vty.Attributes
2526 )
@@ -102,6 +103,8 @@ data Image =
102103 | Translation (Int, Int) Image
103104 -- Crop an image to a size
104105 | ImageCrop (Int, Int) Image
106+ -- Pad an image up to a size
107+ | ImagePad (Int, Int) Image
105108 deriving Eq
106109
107110instance Show Image where
@@ -117,6 +120,8 @@ instance Show Image where
117120 = "Translation ( " ++ show offset ++ ", " ++ show i ++ " )"
118121 show ( ImageCrop size i )
119122 = "ImageCrop " ++ show size ++ " ( " ++ show i ++ " )"
123+ show ( ImagePad size i )
124+ = "ImagePad " ++ show size ++ " ( " ++ show i ++ " )"
120125 show ( EmptyImage ) = "EmptyImage"
121126
122127-- | Currently append in the Monoid instance is equivalent to <->. Future versions will just stack
@@ -209,6 +214,7 @@ image_width BGFill { output_width = w } = w
209214image_width EmptyImage = 0
210215image_width ( Translation _v i ) = image_width i
211216image_width ( ImageCrop _v i ) = min (image_width i) (toEnum $ fst _v)
217+image_width ( ImagePad _v i ) = max (image_width i) (toEnum $ fst _v)
212218
213219-- | The height of an Image. This is the number of display rows the image will occupy.
214220image_height :: Image -> Word
@@ -219,6 +225,7 @@ image_height BGFill { output_height = r } = r
219225image_height EmptyImage = 0
220226image_height ( Translation _v i ) = image_height i
221227image_height ( ImageCrop _v i ) = min (image_height i) (toEnum $ snd _v)
228+image_height ( ImagePad _v i ) = max (image_height i) (toEnum $ snd _v)
222229
223230-- | Combines two images side by side.
224231--
@@ -338,3 +345,5 @@ translate v i = Translation v i
338345crop :: (Int, Int) -> Image -> Image
339346crop v i = ImageCrop v i
340347
348+pad :: (Int, Int) -> Image -> Image
349+pad = ImagePad v i
src/Graphics/Vty/Picture.hs+1
@@ -17,6 +17,7 @@ module Graphics.Vty.Picture ( module Graphics.Vty.Picture
1717 , empty_image
1818 , translate
1919 , crop
20+ , pad
2021 -- | The possible display attributes used in constructing an `Image`.
2122 , module Graphics.Vty.Attributes
2223 )
src/Graphics/Vty/Span.hs+8
@@ -156,6 +156,14 @@ ops_for_row mrow_ops bg region image y remaining_columns
156156 if y >= (toEnum $ snd _size)
157157 then return ()
158158 else ops_for_row mrow_ops bg region i y (min remaining_columns $ toEnum $ fst _size)
159+ ImagePad (x,y) i -> do
160+ let hpad = if image_width i < x
161+ then background_fill (x - image_width i) (image_height i)
162+ else empty_image
163+ let vpad = if image_height i < y
164+ then background_fill (image_width i) (y - image_height i)
165+ else empty_image
166+ ops_for_row mrow_ops bg region (vert_join (horiz_join i hpad) vpad) y remaining_columns
159167
160168snoc_text_span :: (Foldable.Foldable t)
161169 => Attr