44package inspector
55
66import (
7+ "fmt"
78 "math"
89
910 "github.com/elgopher/pi"
@@ -26,39 +27,42 @@ func selectTool(icon byte) {
2627 tool = & Pset {}
2728 case icons .LineTool :
2829 tool = & Shape {
29- draw : pi .Line ,
30- function : "Line" ,
31- icon : icons .LineTool ,
30+ draw : drawShape ("Line" , pi .Line ),
31+ icon : icons .LineTool ,
3232 }
3333 case icons .RectTool :
3434 tool = & Shape {
35- draw : pi .Rect ,
36- function : "Rect" ,
37- icon : icons .RectTool ,
35+ draw : drawShape ("Rect" , pi .Rect ),
36+ icon : icons .RectTool ,
3837 }
3938 case icons .RectFillTool :
4039 tool = & Shape {
41- draw : pi .RectFill ,
42- function : "RectFill" ,
43- icon : icons .RectFillTool ,
40+ draw : drawShape ("RectFill" , pi .RectFill ),
41+ icon : icons .RectFillTool ,
4442 }
4543 case icons .CircTool :
4644 tool = & Shape {
47- draw : drawCirc (pi .Circ ),
48- function : "Circ" ,
49- icon : icons .CircTool ,
45+ draw : drawCirc ("Circ" , pi .Circ ),
46+ icon : icons .CircTool ,
5047 }
5148 case icons .CircFillTool :
5249 tool = & Shape {
53- draw : drawCirc (pi .CircFill ),
54- function : "CircFill" ,
55- icon : icons .CircFillTool ,
50+ draw : drawCirc ("CircFill" , pi .CircFill ),
51+ icon : icons .CircFillTool ,
5652 }
5753 }
5854}
5955
60- func drawCirc (f func (cx , cy , r int , color byte )) func (x0 int , y0 int , x1 int , y1 int , color byte ) {
61- return func (x0 , y0 , x1 , y1 int , color byte ) {
56+ func drawShape (name string , f func (x0 , y0 , x1 , y1 int , color byte )) func (x0 , y0 , x1 , y1 int , color byte ) string {
57+ return func (x0 , y0 , x1 , y1 int , color byte ) string {
58+ f (x0 , y0 , x1 , y1 , color )
59+ command := fmt .Sprintf ("pi.%s(%d, %d, %d, %d, %d)" , name , x0 , y0 , x1 , y1 , color )
60+ return command
61+ }
62+ }
63+
64+ func drawCirc (name string , f func (cx , cy , r int , color byte )) func (x0 int , y0 int , x1 int , y1 int , color byte ) string {
65+ return func (x0 , y0 , x1 , y1 int , color byte ) string {
6266 dx := x1 - x0
6367 cx := x0 + dx
6468 if dx < 0 {
@@ -73,5 +77,8 @@ func drawCirc(f func(cx, cy, r int, color byte)) func(x0 int, y0 int, x1 int, y1
7377 r := int (math .Sqrt (float64 (dx * dx + dy * dy )))
7478
7579 f (cx , cy , r , FgColor )
80+
81+ command := fmt .Sprintf ("pi.%s(%d, %d, %d, %d)" , name , cx , cy , r , color )
82+ return command
7683 }
7784}
0 commit comments