diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-07-13 02:13:01 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-07-13 02:13:01 +0200 |
commit | 5c9c99b41ce1ecfee70071ecd3b369855b72d259 (patch) | |
tree | 77e460321ef2375adeaec2e96c09484b5948cc0f /lib/Phi/Border.hs | |
parent | 982bcffcfeb074b4c1beff64ca7361a9a66ed273 (diff) | |
download | phi-5c9c99b41ce1ecfee70071ecd3b369855b72d259.tar phi-5c9c99b41ce1ecfee70071ecd3b369855b72d259.zip |
Added basic rendering functions
Diffstat (limited to 'lib/Phi/Border.hs')
-rw-r--r-- | lib/Phi/Border.hs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/Phi/Border.hs b/lib/Phi/Border.hs new file mode 100644 index 0000000..42a0e8e --- /dev/null +++ b/lib/Phi/Border.hs @@ -0,0 +1,77 @@ +module Phi.Border ( BorderWidth(..) + , simpleBorderWidth + , border + ) where + +import Phi.Panel + +import Graphics.Rendering.Cairo + + +data BorderWidth = BorderWidth { borderTop :: !Int + , borderRight :: !Int + , borderBottom :: !Int + , borderLeft :: !Int + } + +simpleBorderWidth :: Int -> BorderWidth +simpleBorderWidth w = BorderWidth w w w w + +borderH :: BorderWidth -> Int +borderH bw = borderLeft bw + borderRight bw + +borderV :: BorderWidth -> Int +borderV bw = borderTop bw + borderBottom bw + +data Border = Border { margin :: !BorderWidth + , borderWidth :: !Int + , padding :: !BorderWidth + , borderColor :: !Color + , backgroundColor :: !Color + , cornerRadius :: !Double + , borderWeight :: !Float + , content :: !Panel + } + +instance PanelClass Border where + minSize border = minSize c + borderH p + 2*bw + borderH m + where + m = margin border + bw = borderWidth border + p = padding border + c = content border + + weight border = borderWeight border + + render border w h = do + newPath + arc (x + width - radius) (y + radius) radius (-pi/2) 0 + arc (x + width - radius) (y + height - radius) radius 0 (pi/2) + arc (x + radius) (y + height - radius) radius (pi/2) pi + arc (x + radius) (y + radius) radius pi (pi*3/2) + closePath + + setSourceRGBA fr fg fb fa + fillPreserve + + setSourceRGBA br bg bb ba + setLineWidth $ fromIntegral bw + stroke + where + m = margin border + bw = borderWidth border + p = padding border + c = content border + radius = cornerRadius border + + x = (fromIntegral $ borderLeft m) + (fromIntegral bw)/2 + y = (fromIntegral $ borderTop m) + (fromIntegral bw)/2 + width = fromIntegral $ w - borderH m - bw + height = fromIntegral $ h - borderV m - bw + + (br, bg, bb, ba) = borderColor border + (fr, fg, fb, fa) = backgroundColor border + + +border :: BorderWidth -> Int -> BorderWidth -> Color -> Color -> Double -> Float -> Panel -> Panel +border m bw p border bc cr w c = Panel $ Border m bw p border bc cr w c
\ No newline at end of file |