And finished the histogram example.
This commit is contained in:
parent
7d83b8ad37
commit
4b38b1621a
|
@ -12,8 +12,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
histogram *ui.Area
|
||||||
datapoints [10]*ui.Spinbox
|
datapoints [10]*ui.Spinbox
|
||||||
colorButton *ui.ColorButton
|
colorButton *ui.ColorButton
|
||||||
|
|
||||||
|
currentPoint = -1
|
||||||
)
|
)
|
||||||
|
|
||||||
// some metrics
|
// some metrics
|
||||||
|
@ -117,7 +120,7 @@ func (areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
||||||
|
|
||||||
// now transform the coordinate space so (0, 0) is the top-left corner of the graph
|
// now transform the coordinate space so (0, 0) is the top-left corner of the graph
|
||||||
m := ui.NewMatrix()
|
m := ui.NewMatrix()
|
||||||
m.Translate(xoffLeft, yoffTop);
|
m.Translate(xoffLeft, yoffTop)
|
||||||
p.Context.Transform(m)
|
p.Context.Transform(m)
|
||||||
|
|
||||||
// now get the color for the graph itself and set up the brush
|
// now get the color for the graph itself and set up the brush
|
||||||
|
@ -140,24 +143,20 @@ func (areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
||||||
p.Context.Stroke(path, brush, sp)
|
p.Context.Stroke(path, brush, sp)
|
||||||
path.Free()
|
path.Free()
|
||||||
|
|
||||||
/*
|
|
||||||
// now draw the point being hovered over
|
// now draw the point being hovered over
|
||||||
if (currentPoint != -1) {
|
if currentPoint != -1 {
|
||||||
double xs[10], ys[10];
|
xs, ys := pointLocations(graphWidth, graphHeight)
|
||||||
|
path = ui.NewPath(ui.Winding)
|
||||||
pointLocations(graphWidth, graphHeight, xs, ys);
|
path.NewFigureWithArc(
|
||||||
path = uiDrawNewPath(uiDrawFillModeWinding);
|
|
||||||
uiDrawPathNewFigureWithArc(path,
|
|
||||||
xs[currentPoint], ys[currentPoint],
|
xs[currentPoint], ys[currentPoint],
|
||||||
pointRadius,
|
pointRadius,
|
||||||
0, 6.23, // TODO pi
|
0, 6.23, // TODO pi
|
||||||
0);
|
false)
|
||||||
uiDrawPathEnd(path);
|
path.End()
|
||||||
// use the same brush as for the histogram lines
|
// use the same brush as for the histogram lines
|
||||||
uiDrawFill(p->Context, path, &brush);
|
p.Context.Fill(path, brush)
|
||||||
uiDrawFreePath(path);
|
path.Free()
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func inPoint(x, y float64, xtest, ytest float64) bool {
|
func inPoint(x, y float64, xtest, ytest float64) bool {
|
||||||
|
@ -171,24 +170,19 @@ func inPoint(x, y float64, xtest, ytest float64) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
func (areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
||||||
/*
|
graphWidth, graphHeight := graphSize(me.AreaWidth, me.AreaHeight)
|
||||||
double graphWidth, graphHeight;
|
xs, ys := pointLocations(graphWidth, graphHeight)
|
||||||
double xs[10], ys[10];
|
|
||||||
int i;
|
|
||||||
|
|
||||||
graphSize(e->AreaWidth, e->AreaHeight, &graphWidth, &graphHeight);
|
currentPoint = -1
|
||||||
pointLocations(graphWidth, graphHeight, xs, ys);
|
for i := 0; i < 10; i++ {
|
||||||
|
if inPoint(me.X, me.Y, xs[i], ys[i]) {
|
||||||
|
currentPoint = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < 10; i++)
|
|
||||||
if (inPoint(e->X, e->Y, xs[i], ys[i]))
|
|
||||||
break;
|
|
||||||
if (i == 10) // not in a point
|
|
||||||
i = -1;
|
|
||||||
|
|
||||||
currentPoint = i;
|
|
||||||
// TODO only redraw the relevant area
|
// TODO only redraw the relevant area
|
||||||
uiAreaQueueRedrawAll(histogram);
|
histogram.QueueRedrawAll()
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (areaHandler) MouseCrossed(a *ui.Area, left bool) {
|
func (areaHandler) MouseCrossed(a *ui.Area, left bool) {
|
||||||
|
@ -225,7 +219,7 @@ func setupUI() {
|
||||||
vbox.SetPadded(true)
|
vbox.SetPadded(true)
|
||||||
hbox.Append(vbox, false)
|
hbox.Append(vbox, false)
|
||||||
|
|
||||||
histogram := ui.NewArea(areaHandler{})
|
histogram = ui.NewArea(areaHandler{})
|
||||||
|
|
||||||
rand.Seed(time.Now().Unix())
|
rand.Seed(time.Now().Unix())
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
|
@ -239,7 +233,7 @@ func setupUI() {
|
||||||
|
|
||||||
colorButton = ui.NewColorButton()
|
colorButton = ui.NewColorButton()
|
||||||
// TODO inline these
|
// TODO inline these
|
||||||
brush := mkSolidBrush(colorDodgerBlue, 1.0);
|
brush := mkSolidBrush(colorDodgerBlue, 1.0)
|
||||||
colorButton.SetColor(brush.R,
|
colorButton.SetColor(brush.R,
|
||||||
brush.G,
|
brush.G,
|
||||||
brush.B,
|
brush.B,
|
||||||
|
|
Loading…
Reference in New Issue