Use a proper API for default parameters

This commit is contained in:
hasufell 2014-10-05 15:50:42 +02:00
parent 22d7ea501d
commit 884a8a3121
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
3 changed files with 21 additions and 4 deletions

6
Defaults.hs Normal file
View File

@ -0,0 +1,6 @@
module Defaults where
-- |Used to create a common interface for default settings of data types.
class Def a where
def :: a

View File

@ -1,18 +1,28 @@
module Diagram where
import Defaults
import Diagrams.Prelude
import Diagrams.Backend.Cairo
import Meshparser
import Util
instance Def DiagProp where
def = defaultProp
-- |Holds the properties for a Diagram, like thickness of 2d points etc.
data DiagProp = MkProp {
-- |Get the thickness of the dot.
getThickness :: Double
t :: Double
}
-- |The default properties of the Diagram.
defaultProp :: DiagProp
defaultProp = MkProp 2
-- |Create the Diagram from the VTable.
diagFromVTable :: DiagProp -> VTable -> Diagram Cairo R2
diagFromVTable prop vt
@ -22,7 +32,7 @@ diagFromVTable prop vt
`atop` vrule 500 # centerY # moveTo (p2(-250, 0))
`atop` square 550 # lwG 0.00 # bg white
where dot = (circle $
getThickness prop :: Diagram Cairo R2) # fc black
t prop :: Diagram Cairo R2) # fc black
mkPoint (x,y) = p2 (x,y)
-- |Create the Diagram from a String.

5
Gtk.hs
View File

@ -2,6 +2,7 @@ module Gtk where
import Control.Monad.IO.Class
import Control.Monad
import Defaults
import Diagram
import Diagrams.Prelude
import Diagrams.Backend.Cairo
@ -126,7 +127,7 @@ drawDiag' fp da scale' =
scaleVal <- adjustmentGetValue adjustment
let (_, r) = renderDia Cairo
(CairoOptions "" (Width 600) SVG False)
(diagFromString (MkProp scaleVal) mesh)
(diagFromString (def{t = scaleVal}) mesh)
renderWithDrawable dw r
return True
else return False
@ -138,6 +139,6 @@ saveDiag' fp =
if cmpExt "obj" fp
then do
mesh <- readFile fp
renderCairo "out.svg" (Width 600) (diagFromString (MkProp 2) mesh)
renderCairo "out.svg" (Width 600) (diagFromString def mesh)
return True
else return False