Beispiel #1
0
func (l *Label) draw(gc draw2d.GraphicContext) {
	gc.SetStrokeColor(color.Black)

	font := draw2d.GetFont(gc.GetFontData())
	bounds := font.Bounds()
	height := float64(bounds.YMax-bounds.YMin) * l.FontSize / float64(font.UnitsPerEm())

	offset := l.Size.Y - (l.Size.Y-height)/2

	safeRect(gc, Coord{0, 0}, l.Size)
	gc.FillStroke()
	gc.Translate(10, offset)
	gc.SetFontSize(l.FontSize)
	gc.FillString(l.Text)
}
Beispiel #2
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()
}
Beispiel #3
0
func drawInfoarea(gc draw2d.GraphicContext) {
	gc.SetFontSize(20)
	gc.SetFillColor(color.RGBA{0xFF, 0xFF, 0xFF, 0xFF})
	gc.MoveTo(BAR_START_X, IA_START_Y)
	gc.FillString(curTime.Add(Day*-7).Format(DATE_FORMAT) + " - " + curTime.Format(DATE_FORMAT))
}