-
Notifications
You must be signed in to change notification settings - Fork 2
/
Painting Program - CTRL pick color - Example.bb
201 lines (189 loc) · 4.18 KB
/
Painting Program - CTRL pick color - Example.bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
Global win = CreateWindow("Painting Program - CTRL pick color - Example",100,100,800,600,0,1)
Global can = CreateCanvas(0,20,800,600,win)
Dim cols(10,3);the colors
Global mw = 48;wapwidth
Global mh = 48;height
Global tw = 640/mw;tilewidth
Global th = 480/mh;height
Dim map(mw,mh);create map
Global canim = CreateImage(800,600);the image (speedup)
Global brushindex=5;brushcolor
Global brushsize=4
Global cmx;mouse x pos
Global cmy; mouse y pos
Global tileim = CreateImage(tw,th,11)
Global tileimbig = CreateImage(32,32,11)
Global pickcolor = False
Global ctrldown = False
; create the colors and images
refreshtileimages(True)
; our area of operation
Global screen$="canvas"
updateinterface
.main
Repeat
we = WaitEvent()
If we=$101 ; keydown
If screen="canvas"
If EventData()=29 ; left ctrl key
pickcolor = True
ctrldown = True
updateinterface
End If
End If
End If
If we=$102;keyup
If screen = "canvas"
If EventData()=29 ; ctrl key
pickcolor = False
ctrldown = False
End If
If EventData()>=2 And EventData()<=10
brushsize = EventData()-1
updateinterface
End If
End If
End If
If we=$201;mosuedown
End If
If we=$202;mouseup
If EventSource() = can
If EventData() = 1
If ctrldown = True
If RectsOverlap(cmx,cmy,1,1,0,0,(mw+1)*tw,(mh+1)*th)
brushindex = map(cmx/tw,cmy/th)
updateinterface
End If
End If
If ctrldown=False
If RectsOverlap(cmx,cmy,1,1,680,0,32,11*32)
brushindex=cmy/32
updateinterface
End If
If RectsOverlap(cmx,cmy,1,1,0,0,(mw+1)*tw,(mh+1)*th)
brushdown(cmx,cmy,brushindex)
updateinterface
End If
End If
End If
If EventData() = 2
If RectsOverlap(cmx,cmy,1,1,680,0,32,11*32)
If RequestColor()=True
brushindex=cmy/32
cols(brushindex,0) = RequestedRed()
cols(brushindex,1) = RequestedGreen()
cols(brushindex,2) = RequestedBlue()
refreshtileimages
updateinterface
End If
End If
If RectsOverlap(cmx,cmy,1,1,0,0,(mw+1)*tw,(mh+1)*th)
brushdown(cmx,cmy,0)
updateinterface
End If
End If
End If
End If
If we=$203;mousemove
If EventSource()=can
cmx = EventX()
cmy = EventY()
If ctrldown = False
If MouseDown(1) = True
If RectsOverlap(cmx,cmy,1,1,0,0,(mw+1)*tw,(mh+1)*th)
brushdown(cmx,cmy,brushindex)
updateinterface
End If
End If
If MouseDown(2) = True
If RectsOverlap(cmx,cmy,1,1,0,0,(mw+1)*tw,(mh+1)*th)
brushdown(cmx,cmy,0)
updateinterface
End If
End If
End If
updateinterface
End If
End If
If we=$401;gadgetaction
End If
If we=$4001
End If
If we=$803 Then Exit
Forever
End
.funcs
Function updateinterface()
SetBuffer ImageBuffer(canim)
Cls
Color 255,255,255
For y=0 To mh-1
For x=0 To mw-1
DrawImage tileim,x*tw,y*th,map(x,y)
Next
Next
For y=0 To 10
DrawImage tileimbig,680,y*32,y
If brushindex = y
Rect 681,y*32,31,31,False
End If
Next
For y=0 To 47
For x=0 To 47
a = map(x,y)
Color cols(a,0),cols(a,1),cols(a,2)
Rect x*2+660,y*2+370,2,2
Next
Next
; draw the brush view
Color 255,255,255
Rect cmx-brushsize*tw/2,cmy-brushsize*th/2,brushsize*tw,brushsize*th,False
Text 10,500,"Brush size :"+brushsize+" (press 1 to 9)
If pickcolor = True
Text 10,515,"Pickcolor"
Else
End If
SetBuffer CanvasBuffer(can)
Cls
DrawImage canim,0,0
FlipCanvas can
End Function
Function refreshtileimages(init=False)
For i = 0 To 10
SetBuffer ImageBuffer(tileim,i)
If init=True
Color 200+i*3,10+i*20,10
cols(i,0) = ColorRed()
cols(i,1) = ColorGreen()
cols(i,2) = ColorBlue()
End If
Color cols(i,0),cols(i,1),cols(i,2)
Rect 0,0,tw,th,True
SetBuffer ImageBuffer(tileimbig,i)
Color cols(i,0),cols(i,1),cols(i,2)
Rect 0,0,32,32
For x=-1 To 1
For y=-1 To 1
Color 4,4,4
Text tw/2+x,th/2+y,i,1,1
Next
Next
Color 255,255,255
Text tw/2,th/2,i,1,1
Next
End Function
.brushfuncs
Function brushdown(cmx,cmy,ind)
If brushsize=1 Then map(cmx/tw,cmy/th) = ind
If brushsize>1 Then
For y=-brushsize/2 To brushsize/2
For x=-brushsize/2 To brushsize/2
If cmx/tw+x >=0 And cmx/tw+x <=mw
If cmy/th+y >=0 And cmy/th+y <=mh
map(cmx/tw+x,cmy/th+y) = ind
End If
End If
Next
Next
End If
End Function