0 | module CyBy.Draw.Internal.Settings
 1 |
 2 | import CyBy.Draw.Internal.Abbreviations
 3 | import CyBy.Draw.Internal.Color
 4 | import CyBy.Draw.Internal.CoreDims
 5 | import Text.SVG
 6 | import Derive.Prelude
 7 | import Chem
 8 | import Geom
 9 |
10 | %default total
11 | %language ElabReflection
12 |
13 | --------------------------------------------------------------------------------
14 | --          Settings
15 | --------------------------------------------------------------------------------
16 |
17 | public export
18 | record DrawSettings where
19 |   [noHints]
20 |   constructor MS
21 |   core              : CoreDims
22 |   abbreviations     : List Abbreviation
23 |   bondColor         : SVGColor
24 |   defaultBG         : SVGColor
25 |   errorBG           : SVGColor
26 |   highlightBG       : SVGColor
27 |   hoverBG           : SVGColor
28 |   newBG             : SVGColor
29 |   originBG          : SVGColor
30 |   selectBG          : SVGColor
31 |   selectFG          : SVGColor
32 |   showC             : Bool
33 |   textColor         : SVGColor
34 |   elemColor         : Elem -> SVGColor -- color scheme to use
35 |   maxZoom           : Scale
36 |   minZoom           : Scale
37 |   pseFontSize       : Nat
38 |   resizeCornerRad   : Double
39 |
40 | export
41 | defaultSettings : List Abbreviation -> DrawSettings
42 | defaultSettings as =
43 |   MS {
44 |      abbreviations     = as
45 |    , core              = defaultCore
46 |    , hoverBG           = RGBA 71 112 204 50.perc
47 |    , originBG          = RGB 132 197 98
48 |    , newBG             = lightgrey
49 |    , selectBG          = RGBA 132 197 98 50.perc
50 |    , selectFG          = RGBA 132 197 98 50.perc
51 |    , defaultBG         = white
52 |    , highlightBG       = lightgreen
53 |    , errorBG           = RGB 255 150 150
54 |    , textColor         = black
55 |    , elemColor         = basicColors
56 |    , bondColor         = black
57 |    , showC             = False
58 |    , maxZoom           = 20
59 |    , minZoom           = 0.1
60 |    , pseFontSize       = 11
61 |    , resizeCornerRad   = 20.0
62 |    }
63 |
64 | export %inline %hint
65 | toCoreDims : (ds : DrawSettings) => CoreDims
66 | toCoreDims = ds.core
67 |
68 | export
69 | (.selectBufferV) : DrawSettings -> Vector Id
70 | s.selectBufferV = vid s.core.selectBufferSize s.core.selectBufferSize
71 |
72 | ||| Makes sure the given scaling factor does not exceed the valid
73 | ||| zoom levels.
74 | export
75 | validScale : (s : DrawSettings) => AffineTransformation -> Scale -> Scale
76 | validScale t sc =
77 |   let tot      := sc * t.transform.scale -- new scaling factor we would get
78 |       validTot := min (max tot s.minZoom) s.maxZoom -- valid scaling factor
79 |       False    := validTot == tot | True => sc
80 |    in sc * scale (validTot.value / tot.value) -- adjust scale if result would be out of bounds
81 |