forked from google/gxui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background_border_painter.go
63 lines (52 loc) · 1.46 KB
/
background_border_painter.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package parts
import (
"github.com/google/gxui"
"github.com/google/gxui/math"
"github.com/google/gxui/mixins/outer"
)
type BackgroundBorderPainterOuter interface {
outer.Redrawer
}
type BackgroundBorderPainter struct {
outer BackgroundBorderPainterOuter
brush gxui.Brush
pen gxui.Pen
}
func (b *BackgroundBorderPainter) Init(outer BackgroundBorderPainterOuter) {
b.outer = outer
b.brush = gxui.DefaultBrush
b.pen = gxui.DefaultPen
}
func (b *BackgroundBorderPainter) PaintBackground(c gxui.Canvas, r math.Rect) {
if b.brush.Color.A != 0 {
borderF32 := b.pen.Width
c.DrawRoundedRect(r, borderF32, borderF32, borderF32, borderF32, gxui.TransparentPen, b.brush)
}
}
func (b *BackgroundBorderPainter) PaintBorder(c gxui.Canvas, r math.Rect) {
if b.pen.Color.A != 0 {
borderF32 := b.pen.Width
c.DrawRoundedRect(r, borderF32, borderF32, borderF32, borderF32, b.pen, gxui.TransparentBrush)
}
}
func (b *BackgroundBorderPainter) BackgroundBrush() gxui.Brush {
return b.brush
}
func (b *BackgroundBorderPainter) SetBackgroundBrush(brush gxui.Brush) {
if b.brush != brush {
b.brush = brush
b.outer.Redraw()
}
}
func (b *BackgroundBorderPainter) BorderPen() gxui.Pen {
return b.pen
}
func (b *BackgroundBorderPainter) SetBorderPen(pen gxui.Pen) {
if b.pen != pen {
b.pen = pen
b.outer.Redraw()
}
}