mirror of
https://gitlab.com/sheaf/metabrush.git
synced 2024-11-05 23:03:38 +00:00
add toggle for showing guides
This commit is contained in:
parent
3660cb8dce
commit
091c1603bb
23
app/Main.hs
23
app/Main.hs
|
@ -12,7 +12,7 @@ module Main
|
||||||
|
|
||||||
-- base
|
-- base
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
( void )
|
( void, when )
|
||||||
import Data.Foldable
|
import Data.Foldable
|
||||||
( for_ )
|
( for_ )
|
||||||
import Data.Int
|
import Data.Int
|
||||||
|
@ -181,6 +181,7 @@ main = do
|
||||||
modeTVar <- STM.newTVarIO @Mode Path
|
modeTVar <- STM.newTVarIO @Mode Path
|
||||||
partialPathTVar <- STM.newTVarIO @( Maybe PartialPath ) Nothing
|
partialPathTVar <- STM.newTVarIO @( Maybe PartialPath ) Nothing
|
||||||
fileBarTabsTVar <- STM.newTVarIO @( Map Unique GTK.Box ) Map.empty
|
fileBarTabsTVar <- STM.newTVarIO @( Map Unique GTK.Box ) Map.empty
|
||||||
|
showGuidesTVar <- STM.newTVarIO @Bool True
|
||||||
|
|
||||||
-- Put all these stateful variables in a record for conciseness.
|
-- Put all these stateful variables in a record for conciseness.
|
||||||
let
|
let
|
||||||
|
@ -297,15 +298,17 @@ main = do
|
||||||
mbHoldAction <- STM.readTVar mouseHoldTVar
|
mbHoldAction <- STM.readTVar mouseHoldTVar
|
||||||
mbPartialPath <- STM.readTVar partialPathTVar
|
mbPartialPath <- STM.readTVar partialPathTVar
|
||||||
mode <- STM.readTVar modeTVar
|
mode <- STM.readTVar modeTVar
|
||||||
|
showGuides <- STM.readTVar showGuidesTVar
|
||||||
pure do
|
pure do
|
||||||
renderDocument
|
renderDocument
|
||||||
colours mode ( viewportWidth, viewportHeight )
|
colours mode ( viewportWidth, viewportHeight )
|
||||||
mbMousePos mbHoldAction mbPartialPath
|
mbMousePos mbHoldAction mbPartialPath
|
||||||
doc
|
doc
|
||||||
renderGuides
|
when showGuides do
|
||||||
colours ( viewportWidth, viewportHeight ) ViewportOrigin ( viewportWidth, viewportHeight )
|
renderGuides
|
||||||
mbMousePos mbHoldAction
|
colours ( viewportWidth, viewportHeight ) ViewportOrigin ( viewportWidth, viewportHeight )
|
||||||
doc
|
mbMousePos mbHoldAction
|
||||||
|
doc
|
||||||
case mbRender of
|
case mbRender of
|
||||||
Just render -> Cairo.renderWithContext render ctx
|
Just render -> Cairo.renderWithContext render ctx
|
||||||
Nothing -> Cairo.renderWithContext ( blankRender colours ) ctx
|
Nothing -> Cairo.renderWithContext ( blankRender colours ) ctx
|
||||||
|
@ -324,11 +327,13 @@ main = do
|
||||||
mbRender <- STM.atomically $ withCurrentDocument variables \ doc@( Document {..} ) -> do
|
mbRender <- STM.atomically $ withCurrentDocument variables \ doc@( Document {..} ) -> do
|
||||||
mbMousePos <- STM.readTVar mousePosTVar
|
mbMousePos <- STM.readTVar mousePosTVar
|
||||||
mbHoldAction <- STM.readTVar mouseHoldTVar
|
mbHoldAction <- STM.readTVar mouseHoldTVar
|
||||||
|
showGuides <- STM.readTVar showGuidesTVar
|
||||||
pure do
|
pure do
|
||||||
renderGuides
|
when showGuides do
|
||||||
colours ( viewportWidth, viewportHeight ) ( RulerOrigin ruler ) ( width, height )
|
renderGuides
|
||||||
mbMousePos mbHoldAction
|
colours ( viewportWidth, viewportHeight ) ( RulerOrigin ruler ) ( width, height )
|
||||||
doc
|
mbMousePos mbHoldAction
|
||||||
|
doc
|
||||||
for_ mbRender \ render -> Cairo.renderWithContext render ctx
|
for_ mbRender \ render -> Cairo.renderWithContext render ctx
|
||||||
|
|
||||||
pure True
|
pure True
|
||||||
|
|
|
@ -76,7 +76,7 @@
|
||||||
background-color: rgba(48, 45, 38, 0.66);
|
background-color: rgba(48, 45, 38, 0.66);
|
||||||
}
|
}
|
||||||
.guide {
|
.guide {
|
||||||
color: rgba(28, 196, 79, 0.66)
|
color: rgba(28, 196, 79, 0.4)
|
||||||
}
|
}
|
||||||
.magnifier {
|
.magnifier {
|
||||||
color: rgb(236, 223, 210);
|
color: rgb(236, 223, 210);
|
||||||
|
|
|
@ -482,6 +482,20 @@ instance HandleAction Delete where
|
||||||
pure ( UpdateDocTo $ Just ( deleteSelected mode doc ) )
|
pure ( UpdateDocTo $ Just ( deleteSelected mode doc ) )
|
||||||
_ -> pure ()
|
_ -> pure ()
|
||||||
|
|
||||||
|
-------------------
|
||||||
|
-- Toggle guides --
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
data ToggleGuides = ToggleGuides
|
||||||
|
deriving stock Show
|
||||||
|
|
||||||
|
instance HandleAction ToggleGuides where
|
||||||
|
handleAction ( UIElements { viewport = Viewport {..} } ) ( Variables { showGuidesTVar } ) _ = do
|
||||||
|
STM.atomically $ STM.modifyTVar' showGuidesTVar not
|
||||||
|
GTK.widgetQueueDraw viewportDrawingArea
|
||||||
|
for_ [ rulerCornerDrawingArea, topRulerDrawingArea, leftRulerDrawingArea ] \ drawingArea -> do
|
||||||
|
GTK.widgetQueueDraw drawingArea
|
||||||
|
|
||||||
------------
|
------------
|
||||||
-- Confirm --
|
-- Confirm --
|
||||||
------------
|
------------
|
||||||
|
@ -659,16 +673,18 @@ instance HandleAction MouseClick where
|
||||||
_ -> pure Don'tModifyDoc
|
_ -> pure Don'tModifyDoc
|
||||||
|
|
||||||
RulerOrigin ruler -> do
|
RulerOrigin ruler -> do
|
||||||
let
|
showGuides <- STM.readTVar showGuidesTVar
|
||||||
mbGuide :: Maybe Guide
|
when showGuides do
|
||||||
mbGuide = selectGuide pos doc
|
let
|
||||||
guideAction :: GuideAction
|
mbGuide :: Maybe Guide
|
||||||
guideAction
|
mbGuide = selectGuide pos doc
|
||||||
| Just guide <- mbGuide
|
guideAction :: GuideAction
|
||||||
= MoveGuide ( guideUnique guide )
|
guideAction
|
||||||
| otherwise
|
| Just guide <- mbGuide
|
||||||
= CreateGuide ruler
|
= MoveGuide ( guideUnique guide )
|
||||||
STM.writeTVar mouseHoldTVar ( Just $ GuideAction { holdStartPos = pos, guideAction } )
|
| otherwise
|
||||||
|
= CreateGuide ruler
|
||||||
|
STM.writeTVar mouseHoldTVar ( Just $ GuideAction { holdStartPos = pos, guideAction } )
|
||||||
pure Don'tModifyDoc
|
pure Don'tModifyDoc
|
||||||
|
|
||||||
-- Right mouse button: end partial path.
|
-- Right mouse button: end partial path.
|
||||||
|
|
|
@ -108,6 +108,7 @@ data Variables
|
||||||
, modeTVar :: !( STM.TVar Mode )
|
, modeTVar :: !( STM.TVar Mode )
|
||||||
, partialPathTVar :: !( STM.TVar ( Maybe PartialPath ) )
|
, partialPathTVar :: !( STM.TVar ( Maybe PartialPath ) )
|
||||||
, fileBarTabsTVar :: !( STM.TVar ( Map Unique GTK.Box ) )
|
, fileBarTabsTVar :: !( STM.TVar ( Map Unique GTK.Box ) )
|
||||||
|
, showGuidesTVar :: !( STM.TVar Bool )
|
||||||
}
|
}
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
|
@ -360,7 +360,7 @@ renderGuide ( Colours {..} ) zoom ( Guide { guidePoint = Point2D x y , guideNorm
|
||||||
Cairo.translate x y
|
Cairo.translate x y
|
||||||
Cairo.scale ( 1 / zoom ) ( 1 / zoom )
|
Cairo.scale ( 1 / zoom ) ( 1 / zoom )
|
||||||
|
|
||||||
Cairo.setLineWidth 2.0
|
Cairo.setLineWidth 1.5
|
||||||
withRGBA guide Cairo.setSourceRGBA
|
withRGBA guide Cairo.setSourceRGBA
|
||||||
|
|
||||||
Cairo.moveTo ( 1e5 * ny ) ( -1e5 * nx )
|
Cairo.moveTo ( 1e5 * ny ) ( -1e5 * nx )
|
||||||
|
|
|
@ -158,6 +158,8 @@ data ViewMenu ( rt :: ResourceType )
|
||||||
, metaparameters :: !( MenuItem () NoSubresource rt )
|
, metaparameters :: !( MenuItem () NoSubresource rt )
|
||||||
, viewSep2 :: !( Separator rt )
|
, viewSep2 :: !( Separator rt )
|
||||||
, transform :: !( MenuItem () NoSubresource rt )
|
, transform :: !( MenuItem () NoSubresource rt )
|
||||||
|
, viewSep3 :: !( Separator rt )
|
||||||
|
, guides :: !( MenuItem ToggleGuides NoSubresource rt )
|
||||||
}
|
}
|
||||||
deriving stock Generic
|
deriving stock Generic
|
||||||
|
|
||||||
|
@ -216,6 +218,8 @@ viewMenuDescription
|
||||||
, metaparameters = MenuItemDescription "Metaparameters" [ "submenuItem" ] () Nothing NoSubresource
|
, metaparameters = MenuItemDescription "Metaparameters" [ "submenuItem" ] () Nothing NoSubresource
|
||||||
, viewSep2 = SeparatorDescription [ "submenuSeparator" ]
|
, viewSep2 = SeparatorDescription [ "submenuSeparator" ]
|
||||||
, transform = MenuItemDescription "Transform" [ "submenuItem" ] () Nothing NoSubresource
|
, transform = MenuItemDescription "Transform" [ "submenuItem" ] () Nothing NoSubresource
|
||||||
|
, viewSep3 = SeparatorDescription [ "submenuSeparator" ]
|
||||||
|
, guides = MenuItemDescription "Guides" [ "submenuItem" ] ToggleGuides ( Just ( GDK.KEY_G, [] ) ) NoSubresource
|
||||||
}
|
}
|
||||||
|
|
||||||
helpMenuDescription :: HelpMenu Description
|
helpMenuDescription :: HelpMenu Description
|
||||||
|
|
Loading…
Reference in a new issue