-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Frame.scala
90 lines (78 loc) · 2.71 KB
/
Frame.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright 2015 Creative Scala
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package doodle
package java2d
package effect
import doodle.core.Color
/** The [[Frame]] specifies how to create a [[Canvas]]. The idiomatic way to
* create a `Frame` is to start with `Frame.default` and then call the builder
* methods starting with `with`.
*
* For example, this `Frame` specifies a fixed size and a background color.
*
* ```
* Frame.default.withSize(300, 300).withBackground(Color.midnightBlue)
* ```
*/
final case class Frame(
size: Size,
title: String,
center: Center,
background: Option[Color],
redraw: Redraw
) {
/** Size the canvas with the given fixed dimensions. */
def withSize(width: Double, height: Double): Frame =
this.copy(size = Size.fixedSize(width, height))
/** Size the canvas to fit to the picture's bounding box, plus the given
* border around the bounding box.
*/
def withSizedToPicture(border: Int = 20): Frame =
this.copy(size = Size.fitToPicture(border))
/** Use the given color as the background.
*/
def withBackground(color: Color): Frame =
this.copy(background = Some(color))
/** Use a fully transparent background.
*/
def withNoBackground: Frame =
this.copy(background = None)
/** When redrawing, clear the screen with the background color. */
def withClearToBackground: Frame =
this.copy(redraw = Redraw.clearToBackground)
/** When redrawing, clear the screen with the given color. */
def withClearToColor(color: Color): Frame =
this.copy(redraw = Redraw.clearToColor(color))
/** Title the window with the given string. */
def withTitle(title: String): Frame =
this.copy(title = title)
/** Make the center of the canvas the center of the picture's bounding box. */
def withCenterOnPicture: Frame =
this.copy(center = Center.centeredOnPicture)
/** Make the center of the canvas the origin. */
def withCenterAtOrigin: Frame =
this.copy(center = Center.atOrigin)
}
object Frame {
val default =
Frame(
size = Size.fitToPicture(20),
title = "Doodle",
center = Center.centeredOnPicture,
background = Some(Color.white),
redraw = Redraw.clearToBackground
)
}