Use a proper API for default parameters
This commit is contained in:
parent
22d7ea501d
commit
884a8a3121
6
Defaults.hs
Normal file
6
Defaults.hs
Normal 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
|
14
Diagram.hs
14
Diagram.hs
@ -1,18 +1,28 @@
|
|||||||
module Diagram where
|
module Diagram where
|
||||||
|
|
||||||
|
import Defaults
|
||||||
import Diagrams.Prelude
|
import Diagrams.Prelude
|
||||||
import Diagrams.Backend.Cairo
|
import Diagrams.Backend.Cairo
|
||||||
import Meshparser
|
import Meshparser
|
||||||
import Util
|
import Util
|
||||||
|
|
||||||
|
|
||||||
|
instance Def DiagProp where
|
||||||
|
def = defaultProp
|
||||||
|
|
||||||
|
|
||||||
-- |Holds the properties for a Diagram, like thickness of 2d points etc.
|
-- |Holds the properties for a Diagram, like thickness of 2d points etc.
|
||||||
data DiagProp = MkProp {
|
data DiagProp = MkProp {
|
||||||
-- |Get the thickness of the dot.
|
-- |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.
|
-- |Create the Diagram from the VTable.
|
||||||
diagFromVTable :: DiagProp -> VTable -> Diagram Cairo R2
|
diagFromVTable :: DiagProp -> VTable -> Diagram Cairo R2
|
||||||
diagFromVTable prop vt
|
diagFromVTable prop vt
|
||||||
@ -22,7 +32,7 @@ diagFromVTable prop vt
|
|||||||
`atop` vrule 500 # centerY # moveTo (p2(-250, 0))
|
`atop` vrule 500 # centerY # moveTo (p2(-250, 0))
|
||||||
`atop` square 550 # lwG 0.00 # bg white
|
`atop` square 550 # lwG 0.00 # bg white
|
||||||
where dot = (circle $
|
where dot = (circle $
|
||||||
getThickness prop :: Diagram Cairo R2) # fc black
|
t prop :: Diagram Cairo R2) # fc black
|
||||||
mkPoint (x,y) = p2 (x,y)
|
mkPoint (x,y) = p2 (x,y)
|
||||||
|
|
||||||
-- |Create the Diagram from a String.
|
-- |Create the Diagram from a String.
|
||||||
|
5
Gtk.hs
5
Gtk.hs
@ -2,6 +2,7 @@ module Gtk where
|
|||||||
|
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
import Defaults
|
||||||
import Diagram
|
import Diagram
|
||||||
import Diagrams.Prelude
|
import Diagrams.Prelude
|
||||||
import Diagrams.Backend.Cairo
|
import Diagrams.Backend.Cairo
|
||||||
@ -126,7 +127,7 @@ drawDiag' fp da scale' =
|
|||||||
scaleVal <- adjustmentGetValue adjustment
|
scaleVal <- adjustmentGetValue adjustment
|
||||||
let (_, r) = renderDia Cairo
|
let (_, r) = renderDia Cairo
|
||||||
(CairoOptions "" (Width 600) SVG False)
|
(CairoOptions "" (Width 600) SVG False)
|
||||||
(diagFromString (MkProp scaleVal) mesh)
|
(diagFromString (def{t = scaleVal}) mesh)
|
||||||
renderWithDrawable dw r
|
renderWithDrawable dw r
|
||||||
return True
|
return True
|
||||||
else return False
|
else return False
|
||||||
@ -138,6 +139,6 @@ saveDiag' fp =
|
|||||||
if cmpExt "obj" fp
|
if cmpExt "obj" fp
|
||||||
then do
|
then do
|
||||||
mesh <- readFile fp
|
mesh <- readFile fp
|
||||||
renderCairo "out.svg" (Width 600) (diagFromString (MkProp 2) mesh)
|
renderCairo "out.svg" (Width 600) (diagFromString def mesh)
|
||||||
return True
|
return True
|
||||||
else return False
|
else return False
|
||||||
|
Loading…
Reference in New Issue
Block a user