-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcolor.go
133 lines (116 loc) · 3.26 KB
/
color.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"image"
"image/color"
"runtime"
"github.com/as/edit"
"github.com/as/frame"
"github.com/as/ui/reg"
"github.com/as/ui/win"
)
func uselightcolors() {
Palette = Lightpalette
updatecolors()
}
func usedarkcolors() {
Palette = Darkpalette
updatecolors()
}
func updatecolors() {
GridConfig.Color[0] = Palette["grid"]
ColConfig.Color[0] = Palette["col"]
TagConfig.Color[0] = Palette["tag"]
TagConfig.Color[1] = Palette["win"]
reg.PutImage(Shade, "scroll/fg")
reg.PutImage(Gray, "scroll/bg")
}
var (
Palette = Lightpalette
Lightpalette = map[string]frame.Color{
"grid": frame.Theme(Gray, Storm, White, Mauve),
"col": frame.Theme(Gray, Strata, White, Mauve),
"tag": frame.Theme(Gray, Strata, White, Mauve),
"win": frame.Theme(Gray, Peach, White, Mauve),
}
Darkpalette = map[string]frame.Color{
"grid": frame.Theme(LightGray, Darkbluegray, White, Darkbluegray),
"col": frame.Theme(LightGray, Gray, White, Darkbluegray),
"tag": frame.Theme(LightGray, Gray, White, Darkbluegray),
"win": frame.Theme(LightGray, Bluegray, White, Darkbluegray),
}
)
func (g *Grid) acolor(e edit.File) {
if t := g.FindName(e.Name); t != nil {
if t.Window == nil {
return
}
win := t.Window.(*win.Win)
if win == nil {
return
}
fr := win.Frame
p0, p1 := e.Q0, e.Q1
p0 -= clamp(p0-t.Window.Origin(), 0, fr.Len())
p1 -= clamp(p1-t.Window.Origin(), 0, fr.Len())
fr.Recolor(fr.PointOf(p0), p0, p1, frame.Mono.Palette)
fr.Mark()
}
}
var (
// Transparent and other colors
// These might not reflect any logical convention or standard
Transparent = uniform(0x00000000)
White = uniform(0xffffffff)
Black = uniform(0x000000ff)
Shade = uniform(0x121217ff)
Gray = uniform(0x1c1f26ff)
LightGray = uniform(0xb0b0c0ff)
DarkGray = uniform(0x120a14ff)
Yellow = uniform(0xfffffd0f)
Red = uniform(0xffd0d8ff)
Green = uniform(0xd8ffd0ff)
Blue = uniform(0xd8d0ffff)
Mauve = uniform(0x9090C0ff)
Peach = uniform(0xfff8e8ff)
Strata = uniform(0xf8f2f8ff)
Storm = uniform(0xd8d8e8ff)
Scroll = uniform(0x9d9da7ff)
Paleblue = uniform(0xf3f8feff)
Palegreen = uniform(0xe2ebe8ff)
Palegray = uniform(0xe2e1e8ff)
Palepink = uniform(0xfce8fcff)
Blueviolet = uniform(0x665588ff)
Bluegray = uniform(0x2b323bff)
Darkbluegray = uniform(0x1c1f26ff)
Seagreen = uniform(0x99cc99ff)
)
// Uniform is short for image.NewUniform(Hex(rgba)). On linux,
// we are doing something nasty by pre-swizzling the uniform
// colors. This is until I can fix the swizzle in as/shiny for linux
var uniform = func() func(rgba uint32) *image.Uniform {
if runtime.GOOS == "linux" {
return linuxuniform
}
return plan9uniform
}()
// plan9uniform is short for image.NewUniform(Hex(rgba))
func plan9uniform(rgba uint32) *image.Uniform {
return image.NewUniform(hex(rgba))
}
// linuxuniform is short for image.NewUniform(Hex(rgba))\
// this function exists because I haven't fixed swizzle on
// linux yet.
func linuxuniform(rgba uint32) *image.Uniform {
c := hex(rgba)
c.R, c.B = c.B, c.R
return image.NewUniform(c)
}
// hex converts a 32-bit RGBA quad to a color.RGBA
func hex(rgba uint32) color.RGBA {
return color.RGBA{
R: uint8(rgba >> 24),
G: uint8(rgba << 8 >> 24),
B: uint8(rgba << 16 >> 24),
A: uint8(rgba << 24 >> 24),
}
}