2020-09-02 02:52:08 +00:00
|
|
|
|
module MetaBrush.Context
|
|
|
|
|
( UIElements(..), Variables(..)
|
2021-04-21 15:08:33 +00:00
|
|
|
|
, LR(..), Modifier(..), modifierKey
|
2020-09-05 22:35:00 +00:00
|
|
|
|
, HoldAction(..), GuideAction(..), PartialPath(..)
|
2020-09-02 02:52:08 +00:00
|
|
|
|
)
|
|
|
|
|
where
|
|
|
|
|
|
|
|
|
|
-- base
|
2021-02-23 20:52:03 +00:00
|
|
|
|
import Data.Int
|
|
|
|
|
( Int32 )
|
2020-09-02 02:52:08 +00:00
|
|
|
|
import Data.Word
|
|
|
|
|
( Word32 )
|
|
|
|
|
|
|
|
|
|
-- containers
|
|
|
|
|
import Data.Set
|
|
|
|
|
( Set )
|
|
|
|
|
import Data.Map.Strict
|
|
|
|
|
( Map )
|
|
|
|
|
|
2021-02-23 19:58:53 +00:00
|
|
|
|
-- gi-cairo-render
|
|
|
|
|
import qualified GI.Cairo.Render as Cairo
|
|
|
|
|
( Render )
|
|
|
|
|
|
2021-04-21 15:08:33 +00:00
|
|
|
|
-- gi-gdk
|
2020-09-02 02:52:08 +00:00
|
|
|
|
import qualified GI.Gdk as GDK
|
|
|
|
|
|
2021-04-21 15:08:33 +00:00
|
|
|
|
-- gi-gio
|
|
|
|
|
import qualified GI.Gio as GIO
|
|
|
|
|
|
2020-09-02 02:52:08 +00:00
|
|
|
|
-- 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-11-14 22:32:23 +00:00
|
|
|
|
-- unordered-containers
|
|
|
|
|
import Data.HashMap.Strict
|
|
|
|
|
( HashMap )
|
|
|
|
|
|
2020-09-02 02:52:08 +00:00
|
|
|
|
-- MetaBrush
|
2020-09-07 15:38:22 +00:00
|
|
|
|
import Math.Bezier.Cubic.Fit
|
|
|
|
|
( FitParameters )
|
2023-01-08 16:16:14 +00:00
|
|
|
|
import Math.Linear
|
2023-01-09 03:27:08 +00:00
|
|
|
|
( ℝ(..) )
|
2021-04-21 15:08:33 +00:00
|
|
|
|
import {-# SOURCE #-} MetaBrush.Action
|
|
|
|
|
( ActionName )
|
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-18 09:40:14 +00:00
|
|
|
|
import MetaBrush.Document.Selection
|
|
|
|
|
( DragMoveSelect )
|
2020-09-02 02:52:08 +00:00
|
|
|
|
import {-# SOURCE #-} MetaBrush.UI.FileBar
|
2021-04-21 15:08:33 +00:00
|
|
|
|
( FileBar, FileBarTab )
|
2020-09-02 02:52:08 +00:00
|
|
|
|
import {-# SOURCE #-} MetaBrush.UI.InfoBar
|
2020-09-10 16:43:42 +00:00
|
|
|
|
( InfoBar )
|
2020-09-14 04:03:45 +00:00
|
|
|
|
import {-# SOURCE #-} MetaBrush.UI.ToolBar
|
2020-09-02 02:52:08 +00:00
|
|
|
|
( 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
|
2021-04-21 15:08:33 +00:00
|
|
|
|
{ application :: !GTK.Application
|
|
|
|
|
, window :: !GTK.ApplicationWindow
|
|
|
|
|
, windowKeys :: !GTK.EventControllerKey
|
|
|
|
|
, titleBar :: !GTK.HeaderBar
|
|
|
|
|
, titleLabel :: !GTK.Label
|
|
|
|
|
, fileBar :: !FileBar
|
|
|
|
|
, viewport :: !Viewport
|
|
|
|
|
, infoBar :: !InfoBar
|
|
|
|
|
, menuBar :: GTK.PopoverMenuBar -- needs to be lazy for RecursiveDo
|
|
|
|
|
, menuActions :: !( HashMap ActionName GIO.SimpleAction )
|
|
|
|
|
, colours :: !Colours
|
2020-09-02 02:52:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data Variables
|
|
|
|
|
= Variables
|
2021-02-23 19:58:53 +00:00
|
|
|
|
{ uniqueSupply :: !UniqueSupply
|
2021-04-21 15:08:33 +00:00
|
|
|
|
, recomputeStrokesTVar :: !( STM.TVar Bool )
|
|
|
|
|
, documentRenderTVar :: !( STM.TVar ( ( Int32, Int32 ) -> Cairo.Render () ) )
|
|
|
|
|
, activeDocumentTVar :: !( STM.TVar ( Maybe Unique ) )
|
|
|
|
|
, openDocumentsTVar :: !( STM.TVar ( Map Unique DocumentHistory ) )
|
2023-01-09 03:27:08 +00:00
|
|
|
|
, mousePosTVar :: !( STM.TVar ( Maybe ( ℝ 2 ) ) )
|
2021-04-21 15:08:33 +00:00
|
|
|
|
, mouseHoldTVar :: !( STM.TVar ( Maybe HoldAction ) )
|
|
|
|
|
, modifiersTVar :: !( STM.TVar ( Set Modifier ) )
|
|
|
|
|
, toolTVar :: !( STM.TVar Tool )
|
|
|
|
|
, modeTVar :: !( STM.TVar Mode )
|
|
|
|
|
, debugTVar :: !( STM.TVar Bool )
|
|
|
|
|
, partialPathTVar :: !( STM.TVar ( Maybe PartialPath ) )
|
|
|
|
|
, fileBarTabsTVar :: !( STM.TVar ( Map Unique FileBarTab ) )
|
|
|
|
|
, 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
|
2021-04-21 15:08:33 +00:00
|
|
|
|
modifierKey n = case fromIntegral n of
|
|
|
|
|
GDK.KEY_Control_L -> Just ( Control L )
|
|
|
|
|
GDK.KEY_Control_R -> Just ( Control R )
|
|
|
|
|
GDK.KEY_Shift_L -> Just ( Shift L )
|
|
|
|
|
GDK.KEY_Shift_R -> Just ( Shift R )
|
|
|
|
|
GDK.KEY_Alt_L -> Just ( Alt L )
|
|
|
|
|
GDK.KEY_Alt_R -> Just ( Alt R )
|
|
|
|
|
_ -> Nothing
|
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-18 09:40:14 +00:00
|
|
|
|
-- - draw a control point,
|
2020-09-05 22:35:00 +00:00
|
|
|
|
-- - create/modify a guide.
|
2020-09-02 02:52:08 +00:00
|
|
|
|
data HoldAction
|
2023-01-09 03:27:08 +00:00
|
|
|
|
= SelectionHold { holdStartPos :: !( ℝ 2 ) }
|
|
|
|
|
| DragMoveHold { holdStartPos :: !( ℝ 2 )
|
2020-09-18 09:40:14 +00:00
|
|
|
|
, dragAction :: !DragMoveSelect
|
|
|
|
|
}
|
2023-01-09 03:27:08 +00:00
|
|
|
|
| DrawHold { holdStartPos :: !( ℝ 2 ) }
|
|
|
|
|
| GuideAction { holdStartPos :: !( ℝ 2 )
|
|
|
|
|
, guideAction :: !GuideAction
|
2020-09-05 22:35:00 +00:00
|
|
|
|
}
|
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
|
2023-01-09 03:27:08 +00:00
|
|
|
|
{ partialStartPos :: !( ℝ 2 )
|
|
|
|
|
, partialControlPoint :: !( Maybe ( ℝ 2 ) )
|
2020-09-02 02:52:08 +00:00
|
|
|
|
, partialPathAnchor :: !DrawAnchor
|
|
|
|
|
, firstPoint :: !Bool
|
|
|
|
|
}
|
|
|
|
|
deriving stock Show
|