Skip to content

Commit

Permalink
add styleFillTexture, styleLineTexture
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyrosenbluth committed Apr 29, 2014
1 parent 0924cc0 commit e2c157e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Diagrams/TwoD.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,13 @@ module Diagrams.TwoD
, tailGap
, gaps, gap
, headColor
, headTexture
, headStyle
, tailColor
, tailTexture
, tailStyle
, shaftColor
, shaftTexture
, shaftStyle
, headSize
, tailSize
Expand Down
18 changes: 18 additions & 0 deletions src/Diagrams/TwoD/Arrow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ module Diagrams.TwoD.Arrow
, tailGap
, gaps, gap
, headColor
, headTexture
, headStyle
, headSize
, tailColor
, tailTexture
, tailStyle
, tailSize
, shaftColor
, shaftTexture
, shaftStyle
, straightShaft

Expand Down Expand Up @@ -235,6 +238,21 @@ tailColor = tailStyle . styleFillColor
shaftColor :: Color c => Setter' ArrowOpts c
shaftColor = shaftStyle . styleLineColor

-- | A lens for setting or modifying the texture of an arrow
-- head.
headTexture :: Setter' ArrowOpts Texture
headTexture = headStyle . styleFillTexture

-- | A lens for setting or modifying the texture of an arrow
-- tail.
tailTexture :: Setter' ArrowOpts Texture
tailTexture = tailStyle . styleFillTexture

-- | A lens for setting or modifying the texture of an arrow
-- shaft.
shaftTexture :: Setter' ArrowOpts Texture
shaftTexture = shaftStyle . styleLineTexture

-- Set the default shaft style of an `ArrowOpts` record by applying the
-- default style after all other styles have been applied.
-- The semigroup stucture of the lw attribute will insure that the default
Expand Down
34 changes: 34 additions & 0 deletions src/Diagrams/TwoD/Attributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ module Diagrams.TwoD.Attributes (

-- ** Line texture
, LineTexture(..), getLineTexture, lineTexture, lineTextureA
, mkLineTexture, styleLineTexture

-- ** Line color
, LineColor, lineColor, getLineColor, lc, lcA, lineColorA
, mkLineColor, styleLineColor

-- ** Fill texture
, FillTexture(..), getFillTexture, fillTexture
, mkFillTexture, styleFillTexture

-- ** Fill color
, FillColor, fillColor, getFillColor, fc, fcA, recommendFillColor
Expand Down Expand Up @@ -381,6 +383,20 @@ lineTexture = applyTAttr . LineTexture . Last
lineTextureA :: (HasStyle a, V a ~ R2) => LineTexture -> a -> a
lineTextureA = applyTAttr

mkLineTexture :: Texture -> LineTexture
mkLineTexture = LineTexture . Last

styleLineTexture :: Setter (Style v) (Style v) Texture Texture
styleLineTexture = sets modifyLineTexture
where
modifyLineTexture f s
= flip setAttr s
. mkLineTexture
. f
. getLineTexture
. fromMaybe def . getAttr
$ s

-- | The color with which lines (strokes) are drawn. Note that child
-- colors always override parent colors; that is, @'lineColor' c1
-- . 'lineColor' c2 $ d@ is equivalent to @'lineColor' c2 $ d@.
Expand Down Expand Up @@ -473,12 +489,30 @@ instance Transformable FillTexture where
rgt = _RG . rGradTrans %~ f
f = transform t

instance Default FillTexture where
def = FillTexture (Recommend (Last (SC
(SomeColor (transparent :: AlphaColour Double)))))

getFillTexture :: FillTexture -> Texture
getFillTexture (FillTexture tx) = getLast . getRecommend $ tx

fillTexture :: (HasStyle a, V a ~ R2) => Texture -> a -> a
fillTexture = applyTAttr . FillTexture . Commit . Last

mkFillTexture :: Texture -> FillTexture
mkFillTexture = FillTexture . Commit . Last

styleFillTexture :: Setter (Style v) (Style v) Texture Texture
styleFillTexture = sets modifyFillTexture
where
modifyFillTexture f s
= flip setAttr s
. mkFillTexture
. f
. getFillTexture
. fromMaybe def . getAttr
$ s

-- | The color with which shapes are filled. Note that child
-- colors always override parent colors; that is, @'fillColor' c1
-- . 'fillColor' c2 $ d@ is equivalent to @'lineColor' c2 $ d@.
Expand Down

4 comments on commit e2c157e

@byorgey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you really mean to push this to arrow-env? I guess it doesn't matter if we're going to merge arrow-env anyway.

@jeffreyrosenbluth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what to do about styleFillColor and styleLineColor yet.
They do nothing in backends that support gradients.
For fillColor and lineColor we were able to accommodate backends
that did not support gradients by dumping both a FillTexture attribute
and FillColor attribute into the style but that strategy may not work here.

@jeffreyrosenbluth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@byorgey I took a little liberty since they both effect arrows.
I probably should have started a new branch.

@byorgey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, no problem. I thought maybe you meant to push it directly to master.

Please sign in to comment.