on master help sign in
just about finished the maybe_clipped renderer
commit73415951e010e0c0a22c2135f7002d91d1eb9392 authorCorey O'Connor <coreyoconnor@gmail.com> dateMon 20 May 2013, 09:03 (13 years ago) parent26663ac
1 file changed+70−48
src/Graphics/Vty/Span.hs+70−48
src/Graphics/Vty/Span.hs+70−48
@@ -208,6 +208,9 @@ is_out_of_bounds image s
208208 | s ^. remain_rows <= 0 = True
209209 | otherwise = False
210210
211+-- TODO: prove skip_columns, skip_rows == 0
212+-- TODO: prove remaining_columns >= image_width
213+-- TODO: prove remaining_rows >= image_height
211214add_unclipped :: Image -> BlitM s ()
212215add_unclipped EmptyImage = return ()
213216add_unclipped (HorizText text_str _ow _cw) = do
@@ -227,59 +230,78 @@ add_unclipped (VertJoin part_top part_bottom _ow _oh) = do
227230 -- TODO: assumes background character is 1 column
228231add_unclipped (BGFill ow oh) = do
229232 Background c a <- view bg
233+ y <- use row_offset
230234 let op = TextSpan ow ow (TL.replicate (fromIntegral ow) c)
231235 forM_ [y..y+oh] $ snoc_op op
232−
233−-- TODO: prove this cannot be called in fully clipped case
236+-- TODO: we know it's clipped actually, the equations that are exposed that introduce a
237+-- Crop all assure the image exceeds the crop in the relevant direction.
238+add_unclipped CropRight {cropped_image, output_width} = do
239+ remaining_columns .= output_width
240+ add_maybe_clipped cropped_image
241+add_unclipped CropLeft {cropped_image, left_skip} = do
242+ skip_columns .= left_skip
243+ add_maybe_clipped cropped_image
244+add_unclipped CropBottom {cropped_image, output_height} = do
245+ remaining_rows .= output_height
246+ add_maybe_clipped cropped_image
247+add_unclipped CropTop {cropped_image, top_skip} = do
248+ skip_rows .= top_skip
249+ add_maybe_clipped cropped_image
250+
251+-- TODO: prove this cannot be called in an out of bounds case.
234252add_maybe_clipped :: Image -> BlitM s ()
235253add_maybe_clipped EmptyImage = return ()
236254add_maybe_clipped (HorizText text_str ow _cw) = do
237− use row_offset >>= snoc_op (AttributeChange a)
238− left_clip <- use skip_columns
239− right_clip <- use remaining_columns
240− let left_clipped = left_clip > 0
241− right_clipped = (ow - left_clip) > right_clip
242− if left_clipped || right_clipped
243− then let text_str' = clip_text left_clip right_clip
244− in add_unclipped_text text_str'
245− else add_unclipped_text text_str
246−add_maybe_clipped (VertJoin top_image bottom_image ow oh) = do
247− add_maybe_clipped top_image
248− row_offset += image_height top_image
249− add_maybe_clipped bottom_image
250−add_maybe_clipped (HorizJoin left_image right_image ow oh) -> do
251− add_maybe_clipped left_image
252− add_maybe_clipped right_image
253−
254− (skip_row',skip_col') <- row_ops_for_image mrow_ops l bg region skip_dim y remaining_columns remain_rows
255− -- Don't output the right part unless there is at least a single column left after
256− -- outputting the left part.
257− if image_width l - (skip_col - skip_col') > remaining_columns
258− then return (skip_row,skip_col')
259− else do
260− (skip_row'',skip_col'') <- row_ops_for_image mrow_ops r bg region (skip_row, skip_col') y (remaining_columns - image_width l + (skip_col - skip_col')) remain_rows
261− return (min skip_row' skip_row'', skip_col'')
262−add_maybe_clipped (BGFill width height) -> do
263− let min_height = if y + height > (region_height region)
264− then region_height region - y
265− else min height remain_rows
266− min_width = min width remaining_columns
267− actual_height = if skip_row > min_height
268− then 0
269− else min_height - skip_row
270− actual_width = if skip_col > min_width
271− then 0
272− else min_width - skip_col
273− forM_ [y .. y + actual_height - 1] $! \y' -> snoc_bg_fill mrow_ops bg actual_width y'
274− let skip_row' = if actual_height > skip_row
275− then 0
276− else skip_row - min_height
277− skip_col' = if actual_width > skip_col
278− then 0
279− else skip_col - min_width
280− return (skip_row',skip_col')
281− ImageCrop (max_w,max_h) i ->
282− row_ops_for_image mrow_ops i bg region skip_dim y (min remaining_columns max_w) (min remain_rows max_h)
255+ -- TODO: assumption that text spans are only 1 row high.
256+ s <- use skip_rows
257+ when (s < 1) $ do
258+ use row_offset >>= snoc_op (AttributeChange a)
259+ left_clip <- use skip_columns
260+ right_clip <- use remaining_columns
261+ let left_clipped = left_clip > 0
262+ right_clipped = (ow - left_clip) > right_clip
263+ if left_clipped || right_clipped
264+ then let text_str' = clip_text left_clip right_clip
265+ in add_unclipped_text text_str'
266+ else add_unclipped_text text_str
267+add_maybe_clipped (VertJoin top_image bottom_image _ow oh) = do
268+ add_maybe_clipped_join "vert_join" skip_rows remaining_rows row_offset
269+ (image_height top_image)
270+ top_image
271+ bottom_image
272+ oh
273+add_maybe_clipped (HorizJoin left_image right_image ow _oh) = do
274+ add_maybe_clipped_join "horiz_join" skip_columns remaining_columns devoid
275+ (image_width right_image)
276+ left_image
277+ right_image
278+ ow
279+add_maybe_clipped BGFill {output_width, output_height} = do
280+ s <- get
281+ let output_width' = min (output_width - s.^skip_columns) s.^remaining_columns
282+ output_height' = min (output_height - s.^skip_rows ) s.^remaining_rows
283+ add_unclipped (BGFill output_width' output_height')
284+add_maybe_clipped_join name skip remaining offset i0_dim i0 i1 size = do
285+ state <- get
286+ when (state^.remaining == 0) $ fail $ name ++ " with remaining == 0"
287+ case state^.skip of
288+ s | s >= size -> fail $ name ++ " on fully clipped"
289+ -- TODO: check if clipped in other dim. if not use add_unclipped
290+ | s == 0 -> case state^.remaining of
291+ r | r > i0_dim -> do
292+ add_maybe_clipped i0
293+ put $ state & offset +~ i0_dim & remaining -~ i0_dim
294+ add_maybe_clipped i1
295+ | otherwise -> add_maybe_clipped i0
296+ | s >= i0_dim -> do
297+ put $ state & skip -~ i0_dim
298+ add_maybe_clipped i1
299+ | otherwise -> case i0_dim - s of
300+ i0_dim' | state^.remaining <= i0_dim' -> add_maybe_clipped i0
301+ | otherwise -> do
302+ add_maybe_clipped i0
303+ put $ state & offset +~ i0_dim' & remaining -~ i0_dim'
304+ add_maybe_clipped i1
283305
284306-- TODO: store a skip list in HorizText
285307-- TODO: represent display strings containing chars that are not 1 column chars as a separate