module Wumpus.Basic.Graphic.DrawingAttr
(
DrawingAttr(..)
, standardAttr
, strokeAttr
, fillAttr
, textAttr
, markHeight
, textDimensions
, thick
, ultrathick
, thin
, fontsize
, fontface
) where
import Wumpus.Basic.SafeFonts
import Wumpus.Basic.SVGColours
import Wumpus.Basic.Utils.Combinators
import Wumpus.Core
import Control.Applicative
data DrawingAttr = DrawingAttr
{ line_width :: Double
, font_props :: FontAttr
, stroke_colour :: DRGB
, fill_colour :: DRGB
}
deriving (Eq,Show)
standardAttr :: FontSize -> DrawingAttr
standardAttr sz = DrawingAttr { line_width = std_line_width
, font_props = FontAttr sz courier
, stroke_colour = black
, fill_colour = gold }
strokeAttr :: DrawingAttr -> (DRGB, StrokeAttr)
strokeAttr = liftA2 (,) stroke_colour (LineWidth . line_width)
fillAttr :: DrawingAttr -> DRGB
fillAttr = fill_colour
textAttr :: DrawingAttr -> (DRGB,FontAttr)
textAttr = liftA2 (,) stroke_colour font_props
markHeight :: FromPtSize u => DrawingAttr -> u
markHeight = fromPtSize . xcharHeight . font_size . font_props
textDimensions :: FromPtSize u => String -> DrawingAttr -> (u,u)
textDimensions str attr = (w,h)
where
sz = font_size $ font_props attr
w = fromPtSize $ textWidth sz (1 + length str)
h = fromPtSize $ textHeight sz
std_line_width :: Double
std_line_width = 1.0
thick_line :: Double
thick_line = 2.0
ultra_thick_line :: Double
ultra_thick_line = 4.0
thin_line :: Double
thin_line = 0.5
thick :: DrawingAttr -> DrawingAttr
thick attr = attr { line_width = thick_line }
ultrathick :: DrawingAttr -> DrawingAttr
ultrathick attr = attr { line_width = ultra_thick_line }
thin :: DrawingAttr -> DrawingAttr
thin attr = attr { line_width = thin_line }
fontface :: FontFace -> DrawingAttr -> DrawingAttr
fontface ff = star (\s i -> s { font_props = upd i }) font_props
where
upd (FontAttr sz _) = FontAttr sz ff
fontsize :: Int -> DrawingAttr -> DrawingAttr
fontsize sz = star (\s i -> s { font_props = upd i }) font_props
where
upd (FontAttr _ ff) = FontAttr sz ff