Esempio n. 1
0
func rect(path draw2d.GraphicContext, x1, x2, y1, y2 float64) {
	path.MoveTo(x1, y1)
	path.LineTo(x2, y1)
	path.LineTo(x2, y2)
	path.LineTo(x1, y2)
	path.Close()
}
Esempio n. 2
0
func android(gc draw2d.GraphicContext, x, y float64) {
	gc.SetLineCap(draw2d.RoundCap)
	gc.SetLineWidth(5)
	gc.ArcTo(x+80, y+70, 50, 50, 180*(math.Pi/180), 360*(math.Pi/180)) // head
	gc.FillStroke()
	gc.MoveTo(x+60, y+25)
	gc.LineTo(x+50, y+10)
	gc.MoveTo(x+100, y+25)
	gc.LineTo(x+110, y+10)
	gc.Stroke()
	draw2d.Circle(gc, x+60, y+45, 5) // left eye
	gc.FillStroke()
	draw2d.Circle(gc, x+100, y+45, 5) // right eye
	gc.FillStroke()
	draw2d.RoundRect(gc, x+30, y+75, x+30+100, y+75+90, 10, 10) // body
	gc.FillStroke()
	draw2d.Rect(gc, x+30, y+75, x+30+100, y+75+80)
	gc.FillStroke()
	draw2d.RoundRect(gc, x+5, y+80, x+5+20, y+80+70, 10, 10) // left arm
	gc.FillStroke()
	draw2d.RoundRect(gc, x+135, y+80, x+135+20, y+80+70, 10, 10) // right arm
	gc.FillStroke()
	draw2d.RoundRect(gc, x+50, y+150, x+50+20, y+150+50, 10, 10) // left leg
	gc.FillStroke()
	draw2d.RoundRect(gc, x+90, y+150, x+90+20, y+150+50, 10, 10) // right leg
	gc.FillStroke()
}
Esempio n. 3
0
func (e *Entry) draw(gc draw2d.GraphicContext) {
	if e.textOffset+e.runeOffsets[e.cursor] < 5 {
		e.textOffset = 5 - e.runeOffsets[e.cursor]
	}
	if e.textOffset+e.runeOffsets[e.cursor] > e.Size.X-5 {
		e.textOffset = e.Size.X - 5 - e.runeOffsets[e.cursor]
	}

	gc.Clear()
	if e.HasKeyFocus {
		gc.SetFillColor(color.RGBA{150, 150, 150, 255})
		safeRect(gc, geom.Coord{0, 0}, e.Size)
		gc.Fill()
	}
	th := float64(e.textBuffer.Bounds().Max.Y - e.textBuffer.Bounds().Min.Y)
	gc.Save()
	gc.Translate(e.textOffset, 0)

	if e.selecting {
		start := e.runeOffsets[e.cursor]
		end := e.runeOffsets[e.selectCursor]
		if start > end {
			start, end = end, start
		}
		gc.SetFillColor(color.RGBA{200, 200, 200, 255})
		safeRect(gc, geom.Coord{start, 0}, geom.Coord{end, e.Size.Y})
		gc.Fill()
	}

	gc.Translate(0, (e.Size.Y-th)/2)

	gc.DrawImage(e.textBuffer)
	gc.Restore()
	if e.HasKeyFocus {
		un := time.Duration(time.Now().UnixNano())
		ms := un / time.Millisecond
		ms = ms % 750
		var intensity uint8 = 255
		if ms > 550 {
			diff := 650 - ms
			if diff < 0 {
				diff *= -1
			}
			intensity = uint8((diff * 255) / 200)
		}
		offset := float64(int(e.runeOffsets[e.cursor] + e.textOffset))
		gc.SetStrokeColor(color.RGBA{A: intensity})
		gc.MoveTo(offset, 0)
		gc.LineTo(offset, e.Size.Y)
		gc.Stroke()
		e.Invalidate(geom.Rect{
			Min: geom.Coord{offset - 1, 0},
			Max: geom.Coord{offset + 1, e.Size.Y},
		})
	}
}
Esempio n. 4
0
func safeRect(path draw2d.GraphicContext, min, max Coord) {
	x1, y1 := min.X, min.Y
	x2, y2 := max.X, max.Y
	x, y := path.LastPoint()
	path.MoveTo(x1, y1)
	path.LineTo(x2, y1)
	path.LineTo(x2, y2)
	path.LineTo(x1, y2)
	path.Close()
	path.MoveTo(x, y)
}
Esempio n. 5
0
func lineCoordSeq(ctxt draw2d.GraphicContext, cs *geos.CoordSeq, scale func(x, y float64) (float64, float64)) {
	n := cs.Size()
	if n == 0 {
		return
	}
	// XXX: interface like sql.Scan() and .Error()
	getX := getOrd(cs, (*geos.CoordSeq).GetX)
	getY := getOrd(cs, (*geos.CoordSeq).GetY)
	x, y := getX(0), getY(0)
	ctxt.MoveTo(scale(x, y))
	for i := 1; i < n; i++ {
		x, y = getX(i), getY(i)
		x, y = scale(x, y)
		ctxt.LineTo(x, y)
	}
}
Esempio n. 6
0
func TestDrawCubicCurve(gc draw2d.GraphicContext) {
	// draw a cubic curve
	x, y := 25.6, 128.0
	x1, y1 := 102.4, 230.4
	x2, y2 := 153.6, 25.6
	x3, y3 := 230.4, 128.0

	gc.SetStrokeColor(color.NRGBA{0, 0, 0, 0xFF})
	gc.SetLineWidth(10)
	gc.MoveTo(x, y)
	gc.CubicCurveTo(x1, y1, x2, y2, x3, y3)
	gc.Stroke()

	gc.SetStrokeColor(color.NRGBA{0xFF, 0, 0, 0xFF})

	gc.SetLineWidth(6)
	// draw segment of curve
	gc.MoveTo(x, y)
	gc.LineTo(x1, y1)
	gc.LineTo(x2, y2)
	gc.LineTo(x3, y3)
	gc.Stroke()
}
Esempio n. 7
0
func (g *Grid) draw(gc draw2d.GraphicContext) {
	gc.Clear()
	gc.SetFillColor(color.RGBA{150, 150, 150, 255})
	safeRect(gc, geom.Coord{0, 0}, g.Size)
	gc.FillStroke()

	g.reflex()

	_, minXs, _ := g.hflex.constrain(g.Size.X)
	for _, x := range minXs[1:] {
		gc.MoveTo(x, 0)
		gc.LineTo(x, g.Size.Y)

	}
	_, minYs, _ := g.vflex.constrain(g.Size.Y)
	for _, y := range minYs[1:] {
		gc.MoveTo(0, y)
		gc.LineTo(g.Size.X, y)

	}
	gc.Stroke()
	// _, _, maxYs := g.vflex.constrain(g.Size.Y)
}
Esempio n. 8
0
func arrow(path draw2d.GraphicContext, x, y, w, h float64, up bool) {
	var m float64 = 1
	if up {
		m = 3
	}

	path.MoveTo(x+w/2, y)
	path.LineTo(x+w, y+(h/4)*m)
	path.LineTo(x+w/2, y+h)
	path.LineTo(x, y+(h/4)*m)
	path.Close()
}
Esempio n. 9
0
func (c *Checkbox) draw(gc draw2d.GraphicContext) {
	gc.Clear()
	gc.SetStrokeColor(color.Black)
	if c.pressed {
		gc.SetFillColor(color.RGBA{155, 0, 0, 255})
	} else {
		gc.SetFillColor(color.RGBA{255, 0, 0, 255})
	}

	// Draw background rect
	x, y := gc.LastPoint()
	gc.MoveTo(0, 0)
	gc.LineTo(c.Size.X, 0)
	gc.LineTo(c.Size.X, c.Size.Y)
	gc.LineTo(0, c.Size.Y)
	gc.Close()
	gc.FillStroke()

	// Draw inner rect
	if c.state {
		gc.SetFillColor(color.Black)
		gc.MoveTo(5, 5)
		gc.LineTo(c.Size.X-5, 5)
		gc.LineTo(c.Size.X-5, c.Size.Y-5)
		gc.LineTo(5, c.Size.Y-5)
		gc.Close()
		gc.FillStroke()
	}

	gc.MoveTo(x, y)
}
Esempio n. 10
0
func drawUptimes(gc draw2d.GraphicContext) {
	y, m, d := curTime.Add(Day * -6).Date()
	sday := time.Date(y, m, d, 0, 0, 0, 0, time.Local)
	eday := sday.Add(Day - time.Second)

	gc.SetFontSize(40)

	// draw frame
	gc.SetStrokeColor(color.RGBA{0x00, 0x00, 0x00, 0xff})
	rect(gc, BAR_START_X, BAR_START_X+BAR_WIDTH, BAR_START_Y, BAR_START_Y+2+float64(7*BAR_HEIGHT))
	gc.Stroke()

	u := 0
	for i := 0; i < 7; i++ {
		gc.MoveTo(FONT_START_X, FONT_START_Y+float64(i*BAR_HEIGHT))
		gc.SetStrokeColor(color.RGBA{0x00, 0x00, 0x00, 0xff})
		gc.FillString(sday.Weekday().String()[0:2])

		upday := make([]w32uptime.Uptime, 0)
		for e := u; e < len(uptimes); e++ {
			if uptimes[e].Start.After(eday) {
				u = e - 1
				if u < 0 {
					u = 0
				}
				break
			}

			if isUptimeInRange(sday, eday, uptimes[e]) {
				upday = append(upday, uptimes[e])
			}
		}

		gc.SetFillColor(color.RGBA{0xE0, 0xA6, 0x2C, 0xFF})
		if len(upday) > 0 {
			for e := 0; e < len(upday); e++ {
				ps, pe := 0, BAR_WIDTH

				if upday[e].Start.After(sday) {
					ps = timeToBarwidth(upday[e].Start)
				}

				if upday[e].End.Before(eday) {
					pe = timeToBarwidth(upday[e].End)
				}

				rect(gc, float64(BAR_START_X+ps), float64(BAR_START_X+pe), BAR_START_Y+1+float64(i*BAR_HEIGHT), BAR_START_Y+1+float64((i+1)*BAR_HEIGHT))
				gc.Fill()
			}
		}

		if i != 6 {
			gc.SetStrokeColor(color.RGBA{0x00, 0x00, 0x00, 0xff})
			gc.MoveTo(BAR_START_X, BAR_START_Y+float64((i+1)*BAR_HEIGHT))
			gc.LineTo(BAR_START_X+BAR_WIDTH, BAR_START_Y+float64((i+1)*BAR_HEIGHT))
			gc.Close()
			gc.Stroke()
		}

		sday = sday.Add(Day)
		eday = sday.Add(Day - time.Second)
	}

	// middle line
	gc.SetStrokeColor(color.RGBA{0x00, 0x00, 0x00, 0xff})
	gc.MoveTo(BAR_START_X+BAR_WIDTH/2, BAR_START_Y+1)
	gc.LineTo(BAR_START_X+BAR_WIDTH/2, BAR_START_Y+1+float64(7*BAR_HEIGHT))
	gc.Close()
	gc.Stroke()
}