metabrush/src/app/MetaBrush/Asset/Colours.hs

106 lines
4 KiB
Haskell
Raw Normal View History

2020-08-05 20:23:16 +00:00
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# OPTIONS_GHC -fno-warn-deprecations #-}
module MetaBrush.Asset.Colours
( ColourRecord(..), ColourType
2020-08-07 22:41:08 +00:00
, Colours, getColours
2020-08-05 20:23:16 +00:00
)
where
-- base
import Data.Traversable
( for )
-- gi-gdk
import qualified GI.Gdk as GDK
-- gi-gtk
import qualified GI.Gtk as GTK
-- text
import Data.Text
( Text )
--------------------------------------------------------------------------------
data ColourRecord a
= Colours
2020-08-07 22:41:08 +00:00
{ bg :: !a
, active :: !a
, highlight :: !a
, cursor :: !a
, cursorOutline :: !a
, plain :: !a
, base :: !a
, splash :: !a
, pathPoint :: !a
, pathPointOutline :: !a
, controlPoint :: !a
, controlPointOutline :: !a
, path :: !a
, brushStroke :: !a
2020-08-13 17:05:19 +00:00
, pointHover :: !a
, pointSelected :: !a
2020-08-07 22:41:08 +00:00
, viewport :: !a
, viewportScrollbar :: !a
, tabScrollbar :: !a
, magnifier :: !a
, glass :: !a
}
2020-08-05 20:23:16 +00:00
deriving stock ( Show, Functor, Foldable, Traversable )
data ColourType
2020-08-07 22:41:08 +00:00
= Colour
| BackgroundColour
2020-08-05 20:23:16 +00:00
deriving stock Show
data ColourName
= ColourName
{ colourName :: !Text
, colourType :: !ColourType
, stateFlags :: ![ GTK.StateFlags ]
}
deriving stock Show
colourNames :: ColourRecord ColourName
colourNames = Colours
2020-08-07 22:41:08 +00:00
{ bg = ColourName "bg" BackgroundColour [ GTK.StateFlagsNormal ]
, active = ColourName "active" BackgroundColour [ GTK.StateFlagsNormal ]
, highlight = ColourName "highlight" Colour [ GTK.StateFlagsNormal ]
, cursor = ColourName "cursor" Colour [ GTK.StateFlagsNormal ]
, cursorOutline = ColourName "cursorStroke" Colour [ GTK.StateFlagsNormal ]
, plain = ColourName "plain" Colour [ GTK.StateFlagsNormal ]
, base = ColourName "base" Colour [ GTK.StateFlagsNormal ]
, splash = ColourName "splash" Colour [ GTK.StateFlagsNormal ]
, pathPoint = ColourName "pathPoint" Colour [ GTK.StateFlagsNormal ]
, pathPointOutline = ColourName "pathPointStroke" Colour [ GTK.StateFlagsNormal ]
, controlPoint = ColourName "controlPoint" Colour [ GTK.StateFlagsNormal ]
, controlPointOutline = ColourName "controlPointStroke" Colour [ GTK.StateFlagsNormal ]
, path = ColourName "path" Colour [ GTK.StateFlagsNormal ]
, brushStroke = ColourName "brushStroke" Colour [ GTK.StateFlagsNormal ]
2020-08-13 17:05:19 +00:00
, pointHover = ColourName "pointHover" Colour [ GTK.StateFlagsNormal ]
, pointSelected = ColourName "pointSelected" Colour [ GTK.StateFlagsNormal ]
2020-08-08 03:33:35 +00:00
, viewport = ColourName "viewport" BackgroundColour [ GTK.StateFlagsNormal ]
2020-08-07 22:41:08 +00:00
, viewportScrollbar = ColourName "viewportScrollbar" BackgroundColour [ GTK.StateFlagsNormal ]
, tabScrollbar = ColourName "tabScrollbar" BackgroundColour [ GTK.StateFlagsNormal ]
, magnifier = ColourName "magnifier" Colour [ GTK.StateFlagsNormal ]
, glass = ColourName "glass" Colour [ GTK.StateFlagsNormal ]
}
2020-08-05 20:23:16 +00:00
type Colours = ColourRecord GDK.RGBA
2020-08-07 22:41:08 +00:00
getColours :: GTK.WidgetPath -> IO Colours
getColours windowWidgetPath =
2020-08-05 21:30:36 +00:00
for colourNames \ ( ColourName { .. } ) -> do
style <- GTK.styleContextNew
GTK.styleContextSetPath style windowWidgetPath
GTK.styleContextAddClass style colourName
case colourType of
2020-08-07 22:41:08 +00:00
BackgroundColour -> GTK.styleContextGetBackgroundColor style stateFlags
Colour -> GTK.styleContextGetColor style stateFlags