Пример #1
0
func (g *TextGraphics) Rect(x, y, w, h int, style chart.Style) {
	chart.SanitizeRect(x, y, w, h, 1)
	// Border
	if style.LineWidth > 0 {
		for i := 0; i < w; i++ {
			g.tb.Put(x+i, y, rune(style.Symbol))
			g.tb.Put(x+i, y+h-1, rune(style.Symbol))
		}
		for i := 1; i < h-1; i++ {
			g.tb.Put(x, y+i, rune(style.Symbol))
			g.tb.Put(x+w-1, y+i, rune(style.Symbol))
		}
	}

	// Filling
	if style.FillColor != "" {
		// TODO: fancier logic
		var s int
		if style.FillColor == "#000000" {
			s = '#' // black
		} else if style.FillColor == "#ffffff" {
			s = ' ' // white
		} else {
			s = style.Symbol
		}
		for i := 1; i < h-1; i++ {
			for j := 1; j < w-1; j++ {
				g.tb.Put(x+j, y+i, rune(s))
			}
		}
	}
}
Пример #2
0
func (sg *OpenGLGraphics) Rect(x, y, w, h int, style chart.Style) {
	// log.Panicf("Unimplemented: %s", whoami())
	x, y, w, h = chart.SanitizeRect(x, y, w, h, style.LineWidth)
	defer glh.OpenGLSentinel()()

	//

	glh.With(glh.Attrib{gl.ENABLE_BIT | gl.COLOR_BUFFER_BIT}, func() {
		glh.ColorC(style.FillColor)

		gl.Enable(gl.BLEND)
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

		gl.Begin(gl.QUADS)
		glh.Squarei(x, y, w, h)
		gl.End()
	})

	if style.LineWidth != 0 {
		gl.LineWidth(float32(style.LineWidth))
		//log.Print("Linewidth: ", float32(style.LineWidth))

		glh.With(glh.Attrib{gl.ENABLE_BIT | gl.COLOR_BUFFER_BIT}, func() {
			glh.ColorC(style.LineColor)

			gl.Enable(gl.BLEND)
			gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

			gl.Begin(gl.LINE_LOOP)
			glh.Squarei(x, y, w, h)
			gl.End()
		})
	}

	// linecol := style.LineColor
	// if linecol != "" {
	// 	s = fmt.Sprintf("stroke:%s; ", linecol)
	// } else {
	// 	linecol = "#808080"
	// }
	// s += fmt.Sprintf("stroke-width: %d; ", style.LineWidth)
	// s += fmt.Sprintf("opacity: %.2f; ", 1-style.Alpha)
	// if style.FillColor != "" {
	// 	s += fmt.Sprintf("fill: %s; fill-opacity: %.2f", style.FillColor, 1-style.Alpha)
	// } else {
	// 	s += "fill-opacity: 0"
	// }
	// sg.svg.Rect(x, y, w, h, s)
	// GenericRect(sg, x, y, w, h, style) // TODO
}
Пример #3
0
func (sg *SvgGraphics) Rect(x, y, w, h int, style chart.Style) {
	var s string
	x, y, w, h = chart.SanitizeRect(x, y, w, h, style.LineWidth)
	linecol := style.LineColor
	if linecol != nil {
		s = fmt.Sprintf("stroke:%s; ", hexcol(linecol))
		s += fmt.Sprintf("stroke-opacity: %s; ", alpha(linecol))
	} else {
		s = "stroke:#808080; "
	}
	s += fmt.Sprintf("stroke-width: %d; ", style.LineWidth)
	if style.FillColor != nil {
		s += fmt.Sprintf("fill: %s; fill-opacity: %s", hexcol(style.FillColor), alpha(style.FillColor))
	} else {
		s += "fill-opacity: 0"
	}
	sg.svg.Rect(x, y, w, h, s)
	// GenericRect(sg, x, y, w, h, style) // TODO
}
Пример #4
0
func (sg *SvgGraphics) Rect(x, y, w, h int, style chart.Style) {
	var s string
	x, y, w, h = chart.SanitizeRect(x, y, w, h, style.LineWidth)
	linecol := style.LineColor
	if linecol != "" {
		s = fmt.Sprintf("stroke:%s; ", linecol)
	} else {
		linecol = "#808080"
	}
	s += fmt.Sprintf("stroke-width: %d; ", style.LineWidth)
	s += fmt.Sprintf("opacity: %.2f; ", 1-style.Alpha)
	if style.FillColor != "" {
		s += fmt.Sprintf("fill: %s; fill-opacity: %.2f", style.FillColor, 1-style.Alpha)
	} else {
		s += "fill-opacity: 0"
	}
	sg.svg.Rect(x, y, w, h, s)
	// GenericRect(sg, x, y, w, h, style) // TODO
}