2020-09-06 12:54:18 +00:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
2020-09-02 02:52:08 +00:00
|
|
|
{-# LANGUAGE DerivingStrategies #-}
|
|
|
|
|
|
|
|
module MetaBrush.Context
|
|
|
|
( UIElements(..), Variables(..)
|
2020-09-02 13:58:00 +00:00
|
|
|
, LR(..), Modifier(..), modifierKey, modifierType
|
2020-09-05 22:35:00 +00:00
|
|
|
, HoldAction(..), GuideAction(..), PartialPath(..)
|
2020-09-02 02:52:08 +00:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
-- base
|
|
|
|
import Data.Word
|
|
|
|
( Word32 )
|
|
|
|
|
|
|
|
-- containers
|
|
|
|
import Data.Set
|
|
|
|
( Set )
|
|
|
|
import Data.Map.Strict
|
|
|
|
( Map )
|
|
|
|
|
|
|
|
-- gi-gtk
|
|
|
|
import qualified GI.Gdk as GDK
|
|
|
|
|
|
|
|
-- gi-gtk
|
|
|
|
import qualified GI.Gtk as GTK
|
|
|
|
|
|
|
|
-- stm
|
|
|
|
import qualified Control.Concurrent.STM.TVar as STM
|
2020-09-10 16:43:42 +00:00
|
|
|
( TVar )
|
2020-09-05 00:56:59 +00:00
|
|
|
|
2020-09-02 02:52:08 +00:00
|
|
|
-- MetaBrush
|
2020-09-07 15:38:22 +00:00
|
|
|
import Math.Bezier.Cubic.Fit
|
|
|
|
( FitParameters )
|
2020-09-02 02:52:08 +00:00
|
|
|
import Math.Vector2D
|
|
|
|
( Point2D )
|
2020-09-04 20:28:31 +00:00
|
|
|
import MetaBrush.Asset.Colours
|
|
|
|
( Colours )
|
2020-09-02 02:52:08 +00:00
|
|
|
import MetaBrush.Document.Draw
|
|
|
|
( DrawAnchor )
|
2020-09-10 16:43:42 +00:00
|
|
|
import MetaBrush.Document.History
|
|
|
|
( DocumentHistory(..) )
|
2020-09-02 02:52:08 +00:00
|
|
|
import {-# SOURCE #-} MetaBrush.UI.FileBar
|
2020-09-10 16:43:42 +00:00
|
|
|
( FileBar )
|
2020-09-02 02:52:08 +00:00
|
|
|
import {-# SOURCE #-} MetaBrush.UI.InfoBar
|
2020-09-10 16:43:42 +00:00
|
|
|
( InfoBar )
|
2020-09-06 12:54:18 +00:00
|
|
|
import {-# SOURCE #-} MetaBrush.UI.Menu
|
|
|
|
( Menu, ResourceType(Object) )
|
2020-09-02 02:52:08 +00:00
|
|
|
import MetaBrush.UI.ToolBar
|
|
|
|
( Tool, Mode )
|
2020-09-05 22:35:00 +00:00
|
|
|
import MetaBrush.UI.Viewport
|
|
|
|
( Viewport(..), Ruler(..) )
|
2020-09-02 02:52:08 +00:00
|
|
|
import MetaBrush.Unique
|
|
|
|
( UniqueSupply, Unique )
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
data UIElements
|
|
|
|
= UIElements
|
2020-09-05 22:35:00 +00:00
|
|
|
{ window :: !GTK.Window
|
|
|
|
, title :: !GTK.Label
|
|
|
|
, titleBar :: !GTK.Box
|
|
|
|
, fileBar :: !FileBar
|
|
|
|
, viewport :: !Viewport
|
|
|
|
, infoBar :: !InfoBar
|
2020-09-06 12:54:18 +00:00
|
|
|
, menu :: Menu Object -- needs to be lazy for "recursive do"
|
2020-09-05 22:35:00 +00:00
|
|
|
, colours :: !Colours
|
2020-09-02 02:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data Variables
|
|
|
|
= Variables
|
|
|
|
{ uniqueSupply :: !UniqueSupply
|
2020-09-10 16:43:42 +00:00
|
|
|
, activeDocumentTVar :: !( STM.TVar ( Maybe Unique ) )
|
|
|
|
, openDocumentsTVar :: !( STM.TVar ( Map Unique DocumentHistory ) )
|
|
|
|
, mousePosTVar :: !( STM.TVar ( Maybe ( Point2D Double ) ) )
|
|
|
|
, mouseHoldTVar :: !( STM.TVar ( Maybe HoldAction ) )
|
|
|
|
, modifiersTVar :: !( STM.TVar ( Set Modifier ) )
|
|
|
|
, toolTVar :: !( STM.TVar Tool )
|
|
|
|
, modeTVar :: !( STM.TVar Mode )
|
|
|
|
, partialPathTVar :: !( STM.TVar ( Maybe PartialPath ) )
|
|
|
|
, fileBarTabsTVar :: !( STM.TVar ( Map Unique ( GTK.Box, GTK.RadioButton ) ) )
|
|
|
|
, showGuidesTVar :: !( STM.TVar Bool )
|
|
|
|
, maxHistorySizeTVar :: !( STM.TVar Int )
|
|
|
|
, fitParametersTVar :: !( STM.TVar FitParameters )
|
2020-09-02 02:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
data LR = L | R
|
|
|
|
deriving stock ( Show, Eq, Ord )
|
|
|
|
|
|
|
|
data Modifier
|
|
|
|
= Control LR
|
|
|
|
| Alt LR
|
|
|
|
| Shift LR
|
|
|
|
deriving stock ( Show, Eq, Ord )
|
|
|
|
|
|
|
|
modifierKey :: Word32 -> Maybe Modifier
|
|
|
|
modifierKey GDK.KEY_Control_L = Just ( Control L )
|
|
|
|
modifierKey GDK.KEY_Control_R = Just ( Control R )
|
|
|
|
modifierKey GDK.KEY_Shift_L = Just ( Shift L )
|
|
|
|
modifierKey GDK.KEY_Shift_R = Just ( Shift R )
|
|
|
|
modifierKey GDK.KEY_Alt_L = Just ( Alt L )
|
|
|
|
modifierKey GDK.KEY_Alt_R = Just ( Alt R )
|
|
|
|
modifierKey _ = Nothing
|
|
|
|
|
2020-09-02 13:58:00 +00:00
|
|
|
modifierType :: Modifier -> GDK.ModifierType
|
|
|
|
modifierType ( Control _ ) = GDK.ModifierTypeControlMask
|
|
|
|
modifierType ( Alt _ ) = GDK.ModifierTypeMod1Mask
|
|
|
|
modifierType ( Shift _ ) = GDK.ModifierTypeShiftMask
|
|
|
|
|
2020-09-05 22:35:00 +00:00
|
|
|
|
|
|
|
data GuideAction
|
|
|
|
= CreateGuide !Ruler
|
|
|
|
| MoveGuide !Unique
|
|
|
|
deriving stock Show
|
|
|
|
|
2020-09-02 02:52:08 +00:00
|
|
|
-- | Keep track of a mouse hold action:
|
|
|
|
--
|
|
|
|
-- - start a rectangular selection,
|
|
|
|
-- - move objects by dragging,
|
2020-09-05 22:35:00 +00:00
|
|
|
-- - drawing a control point,
|
|
|
|
-- - create/modify a guide.
|
2020-09-02 02:52:08 +00:00
|
|
|
data HoldAction
|
|
|
|
= SelectionHold { holdStartPos :: !( Point2D Double ) }
|
|
|
|
| DragMoveHold { holdStartPos :: !( Point2D Double ) }
|
|
|
|
| DrawHold { holdStartPos :: !( Point2D Double ) }
|
2020-09-05 22:35:00 +00:00
|
|
|
| GuideAction { holdStartPos :: !( Point2D Double )
|
|
|
|
, guideAction :: !GuideAction
|
|
|
|
}
|
2020-09-02 02:52:08 +00:00
|
|
|
deriving stock Show
|
|
|
|
|
|
|
|
-- | Keep track of a path that is in the middle of being drawn.
|
|
|
|
data PartialPath
|
|
|
|
= PartialPath
|
|
|
|
{ partialStartPos :: !( Point2D Double )
|
|
|
|
, partialControlPoint :: !( Maybe ( Point2D Double ) )
|
|
|
|
, partialPathAnchor :: !DrawAnchor
|
|
|
|
, firstPoint :: !Bool
|
|
|
|
}
|
|
|
|
deriving stock Show
|