-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
ink.go
47 lines (39 loc) · 1.31 KB
/
ink.go
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
// Copyright (c) 2021-2024 by Richard A. Wilkes. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, version 2.0.
package unison
import "github.com/richardwilkes/unison/enums/paintstyle"
var (
_ Ink = &IndirectInk{}
_ Ink = &ColorFilteredInk{}
)
// Ink holds a color, pattern, or gradient to draw with.
type Ink interface {
Paint(canvas *Canvas, rect Rect, style paintstyle.Enum) *Paint
}
// IndirectInk an ink that references another ink.
type IndirectInk struct {
Target Ink
}
// Paint implements Ink.
func (i *IndirectInk) Paint(canvas *Canvas, rect Rect, style paintstyle.Enum) *Paint {
return i.Target.Paint(canvas, rect, style)
}
// ColorFilteredInk holds an ink and a color filter to apply to the ink.
type ColorFilteredInk struct {
OriginalInk Ink
ColorFilter *ColorFilter
}
// Paint implements Ink.
func (c *ColorFilteredInk) Paint(canvas *Canvas, rect Rect, style paintstyle.Enum) *Paint {
paint := c.OriginalInk.Paint(canvas, rect, style)
if c.ColorFilter != nil {
paint.SetColorFilter(c.ColorFilter)
}
return paint
}