Skip to content

Commit

Permalink
fixes #34
Browse files Browse the repository at this point in the history
  • Loading branch information
as committed Nov 19, 2017
1 parent f22f3a1 commit 83ac017
Showing 1 changed file with 60 additions and 16 deletions.
76 changes: 60 additions & 16 deletions tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
)

const (
tickWidth = 3
tickOff = 0
tickOn = 1
TickOff = 0
TickOn = 1
)

func (f *Frame) Untick() {
Expand All @@ -23,38 +22,83 @@ func (f *Frame) Tick() {
}

func (f *Frame) SetTick(style int) {
f.tickoff = style == tickOff
f.tickoff = style == TickOff
}
func mktick(fontY int) (boxw int, linew int) {
const magic = 12
boxw = 3 + 1*(fontY/magic)
for boxw%3 != 0 {
boxw--
}
if boxw < 3 {
boxw = 3
}

linew = boxw / 3
for boxw%linew != 0 {
boxw--
}
if linew < 1 {
linew = 1
}
return
}

func (f *Frame) tickbg() image.Image {
return f.Color.Hi.Back
/*
r, g, b, a := f.Color.Hi.Back.At(0,0).RGBA()
a=a
return image.NewUniform(color.RGBA{
uint8(r),
uint8(g),
uint8(b),
uint8(0),
})
*/

}
func (f *Frame) inittick() {
h := f.Font.Dy()
r := image.Rect(0, 0, tickWidth, h).Inset(-1)
f.tickscale = 1 // TODO implement scalesize
boxw, linew := mktick(h)
linew2 := linew / 2
if linew < 1 {
linew = 1
}
r := image.Rect(0, 0, boxw, h)
r = r.Sub(image.Pt(r.Dx()/2, 0))
f.tick = image.NewRGBA(r)
f.tickback = image.NewRGBA(r)

//draw.Draw(f.tick, f.tick.Bounds(), f.tickbg(), image.ZP, draw.Src)

drawtick := func(x0, y0, x1, y1 int) {
draw.Draw(f.tick, image.Rect(x0+1, y0+1, x1+1, y1+1), f.Color.Text, image.ZP, draw.Src)
draw.Draw(f.tick, image.Rect(x0, y0, x1, y1), f.Color.Text, image.ZP, draw.Src)
}
drawtick(tickWidth/2, 0, tickWidth/2+1, h)
drawtick(0, 0, tickWidth, h/5)
drawtick(0, h-h/5, tickWidth, h)
drawtick(r.Min.X, r.Min.Y, r.Max.X, r.Min.Y+boxw)
if boxw%2 != 0 {
drawtick(-linew2, 0, linew2+1, h)
} else {
drawtick(-linew2, 0, linew2, h)
}
drawtick(r.Min.X, r.Max.Y-(boxw), r.Max.X, r.Max.Y)
}

// Put
func (f *Frame) tickat(pt image.Point, ticked bool) {
if f.Ticked == ticked || f.tick == nil || !pt.In(f.Bounds().Inset(-1)) {
return
}
//pt.X--
pt.X -= 1
r := f.tick.Bounds().Add(pt)
if r.Max.X > f.r.Max.X {
r.Max.X = f.r.Max.X
} //
adj := image.Pt(1, 1)
}
if ticked {
draw.Draw(f.tickback, f.tickback.Bounds(), f.b, pt.Sub(adj), draw.Src)
f.Draw(f.b, r.Sub(adj), f.tick, image.ZP, draw.Over)
draw.Draw(f.tickback, f.tickback.Bounds(), f.b, pt.Add(f.tickback.Bounds().Min), draw.Src)
f.Draw(f.b, r, f.tick, f.tick.Bounds().Min, draw.Over)
} else {
f.Draw(f.b, r, f.tickback, image.ZP.Sub(adj), draw.Src)
f.Draw(f.b, r, f.tickback, f.tickback.Bounds().Min, draw.Src)
}
f.Ticked = ticked
}

0 comments on commit 83ac017

Please sign in to comment.