don't attempt to draw outline when brush is empty

This commit is contained in:
sheaf 2020-09-05 15:35:01 +02:00
parent a098eb6471
commit 930fa0ebf9
3 changed files with 41 additions and 24 deletions

View file

@ -383,6 +383,17 @@ data Redo = Redo
instance HandleAction Redo where instance HandleAction Redo where
handleAction _ _ _ = pure () handleAction _ _ _ = pure ()
---------------------
-- Discard changes --
---------------------
data DiscardChanges = DiscardChanges
deriving stock Show
-- TODO
instance HandleAction DiscardChanges where
handleAction _ _ _ = pure ()
--------- ---------
-- Cut -- -- Cut --
--------- ---------

View file

@ -134,16 +134,17 @@ data FileMenu ( rt :: ResourceType )
data EditMenu ( rt :: ResourceType ) data EditMenu ( rt :: ResourceType )
= EditMenu = EditMenu
{ undo :: !( MenuItem Undo NoSubresource rt ) { undo :: !( MenuItem Undo NoSubresource rt )
, redo :: !( MenuItem Redo NoSubresource rt ) , redo :: !( MenuItem Redo NoSubresource rt )
, editSep1 :: !( Separator rt ) , discardChanges :: !( MenuItem DiscardChanges NoSubresource rt )
, cut :: !( MenuItem Cut NoSubresource rt ) , editSep1 :: !( Separator rt )
, copy :: !( MenuItem Copy NoSubresource rt ) , cut :: !( MenuItem Cut NoSubresource rt )
, paste :: !( MenuItem Paste NoSubresource rt ) , copy :: !( MenuItem Copy NoSubresource rt )
, duplicate :: !( MenuItem Duplicate NoSubresource rt ) , paste :: !( MenuItem Paste NoSubresource rt )
, delete :: !( MenuItem Delete NoSubresource rt ) , duplicate :: !( MenuItem Duplicate NoSubresource rt )
, editSep2 :: !( Separator rt ) , delete :: !( MenuItem Delete NoSubresource rt )
, preferences :: !( MenuItem () NoSubresource rt ) , editSep2 :: !( Separator rt )
, preferences :: !( MenuItem () NoSubresource rt )
} }
deriving stock Generic deriving stock Generic
@ -191,16 +192,17 @@ fileMenuDescription
editMenuDescription :: EditMenu Description editMenuDescription :: EditMenu Description
editMenuDescription editMenuDescription
= EditMenu = EditMenu
{ undo = MenuItemDescription "Undo" [ "submenuItem" ] Undo ( Just ( GDK.KEY_Z, [ Control L ] ) ) NoSubresource { undo = MenuItemDescription "Undo" [ "submenuItem" ] Undo ( Just ( GDK.KEY_Z, [ Control L ] ) ) NoSubresource
, redo = MenuItemDescription "Redo" [ "submenuItem" ] Redo ( Just ( GDK.KEY_Y, [ Control L ] ) ) NoSubresource , redo = MenuItemDescription "Redo" [ "submenuItem" ] Redo ( Just ( GDK.KEY_Y, [ Control L ] ) ) NoSubresource
, editSep1 = SeparatorDescription [ "submenuSeparator" ] , discardChanges = MenuItemDescription "Discard changes" [ "submenuItem" ] DiscardChanges ( Just ( GDK.KEY_Z, [ Control L, Shift L ] ) ) NoSubresource
, cut = MenuItemDescription "Cut" [ "submenuItem" ] Cut ( Just ( GDK.KEY_X, [ Control L ] ) ) NoSubresource , editSep1 = SeparatorDescription [ "submenuSeparator" ]
, copy = MenuItemDescription "Copy" [ "submenuItem" ] Copy ( Just ( GDK.KEY_C, [ Control L ] ) ) NoSubresource , cut = MenuItemDescription "Cut" [ "submenuItem" ] Cut ( Just ( GDK.KEY_X, [ Control L ] ) ) NoSubresource
, paste = MenuItemDescription "Paste" [ "submenuItem" ] Paste ( Just ( GDK.KEY_V, [ Control L ] ) ) NoSubresource , copy = MenuItemDescription "Copy" [ "submenuItem" ] Copy ( Just ( GDK.KEY_C, [ Control L ] ) ) NoSubresource
, duplicate = MenuItemDescription "Duplicate" [ "submenuItem" ] Duplicate ( Just ( GDK.KEY_D, [ Control L ] ) ) NoSubresource , paste = MenuItemDescription "Paste" [ "submenuItem" ] Paste ( Just ( GDK.KEY_V, [ Control L ] ) ) NoSubresource
, delete = MenuItemDescription "Delete" [ "submenuItem" ] Delete ( Just ( GDK.KEY_Delete, [] ) ) NoSubresource , duplicate = MenuItemDescription "Duplicate" [ "submenuItem" ] Duplicate ( Just ( GDK.KEY_D, [ Control L ] ) ) NoSubresource
, editSep2 = SeparatorDescription [ "submenuSeparator" ] , delete = MenuItemDescription "Delete" [ "submenuItem" ] Delete ( Just ( GDK.KEY_Delete, [] ) ) NoSubresource
, preferences = MenuItemDescription "Preferences" [ "submenuItem" ] () ( Just ( GDK.KEY_P, [ Control L, Shift L ] ) ) NoSubresource , editSep2 = SeparatorDescription [ "submenuSeparator" ]
, preferences = MenuItemDescription "Preferences" [ "submenuItem" ] () ( Just ( GDK.KEY_P, [ Control L, Shift L ] ) ) NoSubresource
} }
viewMenuDescription :: ViewMenu Description viewMenuDescription :: ViewMenu Description

View file

@ -113,9 +113,13 @@ stroke Empty = Left Empty
stroke ( spt0 :<| Empty ) = Left . removePointData $ ( Point2D 0 0 --> coords spt0 :: Vector2D Double ) brushShape @x spt0 stroke ( spt0 :<| Empty ) = Left . removePointData $ ( Point2D 0 0 --> coords spt0 :: Vector2D Double ) brushShape @x spt0
stroke allPts@( spt0 :<| spt1 :<| spts ) stroke allPts@( spt0 :<| spt1 :<| spts )
| isClosed | isClosed
= Right ( fwdPts, bwdPts ) = if null ( brushShape @x spt0 )
then Right ( Empty, Empty )
else Right ( fwdPts, bwdPts )
| otherwise | otherwise
= Left ( startingCap <> fwdPts <> bwdPts ) = if null ( brushShape @x spt0 )
then Left Empty
else Left ( startingCap <> fwdPts <> bwdPts )
where where
startOffset, endOffset :: Vector2D Double startOffset, endOffset :: Vector2D Double
@ -124,9 +128,9 @@ stroke allPts@( spt0 :<| spt1 :<| spts )
startOffset = Point2D 0 0 --> coords spt0 startOffset = Point2D 0 0 --> coords spt0
tgt_start = coords spt0 --> coords spt1 tgt_start = coords spt0 --> coords spt1
( tgt_end, endOffset, brush_end ) = case allPts of ( tgt_end, endOffset, brush_end ) = case allPts of
_ :|> sptnm1 :|> sptn -> ( coords sptnm1 --> coords sptn, Point2D 0 0 --> coords sptn, brushShape sptn ) _ :|> sptnm1 :|> sptn -> ( coords sptnm1 --> coords sptn, Point2D 0 0 --> coords sptn, brushShape @x sptn )
_ -> error "impossible" _ -> error "impossible"
brush_start = brushShape spt0 brush_start = brushShape @x spt0
isClosed :: Bool isClosed :: Bool
isClosed = case ( spt1 :<| spts ) of isClosed = case ( spt1 :<| spts ) of