just about finished the maybe_clipped renderer

This commit is contained in:
Corey O'Connor 2013-05-20 09:03:16 -07:00
parent 26663ac1d6
commit 73415951e0

View File

@ -208,6 +208,9 @@ is_out_of_bounds image s
| s ^. remain_rows <= 0 = True | s ^. remain_rows <= 0 = True
| otherwise = False | otherwise = False
-- TODO: prove skip_columns, skip_rows == 0
-- TODO: prove remaining_columns >= image_width
-- TODO: prove remaining_rows >= image_height
add_unclipped :: Image -> BlitM s () add_unclipped :: Image -> BlitM s ()
add_unclipped EmptyImage = return () add_unclipped EmptyImage = return ()
add_unclipped (HorizText text_str _ow _cw) = do add_unclipped (HorizText text_str _ow _cw) = do
@ -227,59 +230,78 @@ add_unclipped (VertJoin part_top part_bottom _ow _oh) = do
-- TODO: assumes background character is 1 column -- TODO: assumes background character is 1 column
add_unclipped (BGFill ow oh) = do add_unclipped (BGFill ow oh) = do
Background c a <- view bg Background c a <- view bg
y <- use row_offset
let op = TextSpan ow ow (TL.replicate (fromIntegral ow) c) let op = TextSpan ow ow (TL.replicate (fromIntegral ow) c)
forM_ [y..y+oh] $ snoc_op op forM_ [y..y+oh] $ snoc_op op
-- TODO: we know it's clipped actually, the equations that are exposed that introduce a
-- Crop all assure the image exceeds the crop in the relevant direction.
add_unclipped CropRight {cropped_image, output_width} = do
remaining_columns .= output_width
add_maybe_clipped cropped_image
add_unclipped CropLeft {cropped_image, left_skip} = do
skip_columns .= left_skip
add_maybe_clipped cropped_image
add_unclipped CropBottom {cropped_image, output_height} = do
remaining_rows .= output_height
add_maybe_clipped cropped_image
add_unclipped CropTop {cropped_image, top_skip} = do
skip_rows .= top_skip
add_maybe_clipped cropped_image
-- TODO: prove this cannot be called in fully clipped case -- TODO: prove this cannot be called in an out of bounds case.
add_maybe_clipped :: Image -> BlitM s () add_maybe_clipped :: Image -> BlitM s ()
add_maybe_clipped EmptyImage = return () add_maybe_clipped EmptyImage = return ()
add_maybe_clipped (HorizText text_str ow _cw) = do add_maybe_clipped (HorizText text_str ow _cw) = do
use row_offset >>= snoc_op (AttributeChange a) -- TODO: assumption that text spans are only 1 row high.
left_clip <- use skip_columns s <- use skip_rows
right_clip <- use remaining_columns when (s < 1) $ do
let left_clipped = left_clip > 0 use row_offset >>= snoc_op (AttributeChange a)
right_clipped = (ow - left_clip) > right_clip left_clip <- use skip_columns
if left_clipped || right_clipped right_clip <- use remaining_columns
then let text_str' = clip_text left_clip right_clip let left_clipped = left_clip > 0
in add_unclipped_text text_str' right_clipped = (ow - left_clip) > right_clip
else add_unclipped_text text_str if left_clipped || right_clipped
add_maybe_clipped (VertJoin top_image bottom_image ow oh) = do then let text_str' = clip_text left_clip right_clip
add_maybe_clipped top_image in add_unclipped_text text_str'
row_offset += image_height top_image else add_unclipped_text text_str
add_maybe_clipped bottom_image add_maybe_clipped (VertJoin top_image bottom_image _ow oh) = do
add_maybe_clipped (HorizJoin left_image right_image ow oh) -> do add_maybe_clipped_join "vert_join" skip_rows remaining_rows row_offset
add_maybe_clipped left_image (image_height top_image)
add_maybe_clipped right_image top_image
bottom_image
(skip_row',skip_col') <- row_ops_for_image mrow_ops l bg region skip_dim y remaining_columns remain_rows oh
-- Don't output the right part unless there is at least a single column left after add_maybe_clipped (HorizJoin left_image right_image ow _oh) = do
-- outputting the left part. add_maybe_clipped_join "horiz_join" skip_columns remaining_columns devoid
if image_width l - (skip_col - skip_col') > remaining_columns (image_width right_image)
then return (skip_row,skip_col') left_image
else do right_image
(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 ow
return (min skip_row' skip_row'', skip_col'') add_maybe_clipped BGFill {output_width, output_height} = do
add_maybe_clipped (BGFill width height) -> do s <- get
let min_height = if y + height > (region_height region) let output_width' = min (output_width - s.^skip_columns) s.^remaining_columns
then region_height region - y output_height' = min (output_height - s.^skip_rows ) s.^remaining_rows
else min height remain_rows add_unclipped (BGFill output_width' output_height')
min_width = min width remaining_columns add_maybe_clipped_join name skip remaining offset i0_dim i0 i1 size = do
actual_height = if skip_row > min_height state <- get
then 0 when (state^.remaining == 0) $ fail $ name ++ " with remaining == 0"
else min_height - skip_row case state^.skip of
actual_width = if skip_col > min_width s | s >= size -> fail $ name ++ " on fully clipped"
then 0 -- TODO: check if clipped in other dim. if not use add_unclipped
else min_width - skip_col | s == 0 -> case state^.remaining of
forM_ [y .. y + actual_height - 1] $! \y' -> snoc_bg_fill mrow_ops bg actual_width y' r | r > i0_dim -> do
let skip_row' = if actual_height > skip_row add_maybe_clipped i0
then 0 put $ state & offset +~ i0_dim & remaining -~ i0_dim
else skip_row - min_height add_maybe_clipped i1
skip_col' = if actual_width > skip_col | otherwise -> add_maybe_clipped i0
then 0 | s >= i0_dim -> do
else skip_col - min_width put $ state & skip -~ i0_dim
return (skip_row',skip_col') add_maybe_clipped i1
ImageCrop (max_w,max_h) i -> | otherwise -> case i0_dim - s of
row_ops_for_image mrow_ops i bg region skip_dim y (min remaining_columns max_w) (min remain_rows max_h) i0_dim' | state^.remaining <= i0_dim' -> add_maybe_clipped i0
| otherwise -> do
add_maybe_clipped i0
put $ state & offset +~ i0_dim' & remaining -~ i0_dim'
add_maybe_clipped i1
-- TODO: store a skip list in HorizText -- TODO: store a skip list in HorizText
-- TODO: represent display strings containing chars that are not 1 column chars as a separate -- TODO: represent display strings containing chars that are not 1 column chars as a separate