1 // Convert spray can into material draw tool.
2
3 #appendto SprayCan
4
5 local paint_bg;
6 local brush_mode = 1; // 1 = Draw Brush, 2 = Quad Brush, 3 = Eraser
7
Construction()8 public func Construction()
9 {
10 SetColor(RGB(Random(256), Random(256), Random(256)));
11 return;
12 }
13
14 // Item activation
ControlUseStart(object clonk,int x,int y)15 public func ControlUseStart(object clonk, int x, int y)
16 {
17 paint_col = clonk.SelectedBrushMaterial;
18 paint_bg = clonk.SelectedBrushBgMaterial;
19 brush_mode = clonk.SelectedBrushMode;
20 return ControlUseHolding(clonk, x, y);
21 }
22
HoldingEnabled()23 public func HoldingEnabled() { return true; }
24
ControlUseHolding(object clonk,int new_x,int new_y)25 public func ControlUseHolding(object clonk, int new_x, int new_y)
26 {
27 // Work in global coordinates.
28 new_x += GetX(); new_y += GetY();
29
30 // (re-)start spraying.
31 if (GetAction() != "Spraying")
32 StartSpraying(clonk, new_x, new_y);
33
34 // Spray paint if position moved.
35 if (new_x == last_x && new_y == last_y)
36 return true;
37 var wdt = clonk.SelectedBrushSize;
38 var dx = new_x - last_x, dy = new_y - last_y;
39 var d = Distance(dx, dy);
40 var ldx = dy * wdt / d, ldy = -dx * wdt / d;
41 if (!last_ldx && !last_ldy)
42 {
43 last_ldx = ldx;
44 last_ldy = ldy;
45 }
46
47 if (brush_mode == 1)
48 {
49 DrawMaterialQuad(paint_col, last_x - last_ldx, last_y - last_ldy, last_x + last_ldx, last_y + last_ldy, new_x + ldx,new_y + ldy, new_x - ldx, new_y - ldy, paint_bg);
50 }
51
52 else if (brush_mode == 2)
53 {
54 DrawMaterialQuad(paint_col, new_x - (wdt / 2), new_y - (wdt / 2), new_x + (wdt / 2), new_y - (wdt / 2), new_x + (wdt / 2), new_y + (wdt / 2), new_x - (wdt / 2), new_y + (wdt / 2), paint_bg);
55 }
56
57 else if (brush_mode == 3)
58 {
59 // Draw something to set BG Mat to sky (workaround for not being able to draw Sky via DrawMaterialQuad)
60 DrawMaterialQuad(paint_col, new_x - (wdt / 2), new_y - (wdt / 2), new_x + (wdt / 2), new_y - (wdt / 2), new_x + (wdt / 2), new_y + (wdt / 2), new_x - (wdt / 2), new_y + (wdt / 2), DMQ_Sky);
61 ClearFreeRect(new_x - (wdt / 2), new_y - (wdt / 2), wdt, wdt);
62 }
63
64 last_x = new_x; last_y = new_y;
65 last_ldx = ldx; last_ldy = ldy;
66 return true;
67 }
68
QueryRejectDeparture(object clonk)69 public func QueryRejectDeparture(object clonk)
70 {
71 return true;
72 }
73
Departure(object clonk)74 public func Departure(object clonk)
75 {
76 RemoveObject();
77 return;
78 }
79
80