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
|
@ -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,11 +298,13 @@ 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
|
||||||
|
when showGuides do
|
||||||
renderGuides
|
renderGuides
|
||||||
colours ( viewportWidth, viewportHeight ) ViewportOrigin ( viewportWidth, viewportHeight )
|
colours ( viewportWidth, viewportHeight ) ViewportOrigin ( viewportWidth, viewportHeight )
|
||||||
mbMousePos mbHoldAction
|
mbMousePos mbHoldAction
|
||||||
|
@ -324,7 +327,9 @@ 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
|
||||||
|
when showGuides do
|
||||||
renderGuides
|
renderGuides
|
||||||
colours ( viewportWidth, viewportHeight ) ( RulerOrigin ruler ) ( width, height )
|
colours ( viewportWidth, viewportHeight ) ( RulerOrigin ruler ) ( width, height )
|
||||||
mbMousePos mbHoldAction
|
mbMousePos mbHoldAction
|
||||||
|
|
|
@ -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,6 +673,8 @@ instance HandleAction MouseClick where
|
||||||
_ -> pure Don'tModifyDoc
|
_ -> pure Don'tModifyDoc
|
||||||
|
|
||||||
RulerOrigin ruler -> do
|
RulerOrigin ruler -> do
|
||||||
|
showGuides <- STM.readTVar showGuidesTVar
|
||||||
|
when showGuides do
|
||||||
let
|
let
|
||||||
mbGuide :: Maybe Guide
|
mbGuide :: Maybe Guide
|
||||||
mbGuide = selectGuide pos doc
|
mbGuide = selectGuide pos doc
|
||||||
|
|
|
@ -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