summaryrefslogtreecommitdiff
path: root/Layer.c
blob: 0e56e1ceb4161624854c4d8715246e3651a5db1f (plain)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#include <proto/exec.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <graphics/rastport.h>

#include "Bobi.h"
#include "BobStructure.h"

extern struct MyBob *BobTable[];
extern struct Screen *mainscreen;
extern struct Window *mainwindow,*toolwindow;
extern struct RastPort *mainrastport;
extern WORD numbobs,actbobnum,options,mainx0,mainy0;
extern struct Gadget AutoSizeGadget;
extern char LabelGadgetSIBuff[];
extern struct MenuItem CollisionRectMenuItem;

/************************************************************************/

static void DrawBobCross(struct MyBob *bob,WORD x,WORD y)
{
	register struct RastPort *rp=mainrastport;
	register WORD xl,yl;

	xl = mainx0-bob->X0;
	yl = mainy0-bob->Y0;

	SetDrMd(rp,COMPLEMENT);
	Move(rp,xl,y);
	Draw(rp,xl+bob->Width-1,y);
	Move(rp,x,yl);
	Draw(rp,x,yl+bob->Height-1);
}

/************************************************************************/

void SetOrgFunc()
{
	register struct MyBob *bob;
	register struct IntuiMessage *msg;
	register BOOL looping=TRUE;
	register ULONG oldidcmp;
	register WORD x,y;

	if((numbobs>0) && (numbobs!=actbobnum))
	{
		bob = BobTable[actbobnum];
		x = mainx0;
		y = mainy0;
		DrawBobCross(bob,x,y);
		oldidcmp = mainwindow->IDCMPFlags;
		mainwindow->Flags |= RMBTRAP;
		ModifyIDCMP(mainwindow,MOUSEBUTTONS);
		do
		{
			WaitTOF();
			if(msg = (struct IntuiMessage *)GetMsg(mainwindow->UserPort))
			{
				switch(msg->Code)
				{
					case SELECTDOWN:
						if(!BobHit(bob,msg->MouseX,msg->MouseY))
						{
							bob->X0 = x-mainx0+bob->X0;
							bob->Y0 = y-mainy0+bob->Y0;
						}
												/* hier kein break! */
					case MENUDOWN:
						looping=FALSE;
						break;
				}
			}
			else if(!BobHit(bob,mainwindow->MouseX,mainwindow->MouseY))
			{
				DrawBobCross(bob,x,y);
				x = mainwindow->MouseX;
				y = mainwindow->MouseY;
				DrawBobCross(bob,x,y);
			}
		} while(looping);

		DrawBobCross(bob,x,y);
		mainwindow->Flags &= ~RMBTRAP;
		ModifyIDCMP(mainwindow,oldidcmp);
	}
	else ShowMonoReq2("Please select a bob first!");
}

/************************************************************************/

void SetMainOrgFunc()
{
	register ULONG oldidcmp;
	register WORD x,y;

	x=mainx0; y=mainy0;
	DrawCross(mainscreen,x,y);

	oldidcmp = mainwindow->IDCMPFlags;
	mainwindow->Flags |= RMBTRAP;
	ModifyIDCMP(mainwindow,MOUSEBUTTONS);
	DrawCross(mainscreen,mainx0,mainy0); /* Am alten Ort zur Orientierung */
	for(;;)
	{
		register struct IntuiMessage *msg;

		WaitTOF();
		if(msg = (struct IntuiMessage *)GetMsg(mainwindow->UserPort))
		{
			DrawCross(mainscreen,mainx0,mainy0);
			if(msg->Code==SELECTDOWN)
			{
				mainx0=x;	/* Werte nur übernehmen wenn linke Maustaste */
				mainy0=y;
			}
			DrawCross(mainscreen,x,y);
			ReplyMsg((struct Message *)msg);
			break;
		}
		else
		{
			DrawCross(mainscreen,x,y);
			x = mainwindow->MouseX;
			y = mainwindow->MouseY;
			DrawCross(mainscreen,x,y);
		}
	}
	mainwindow->Flags &= ~RMBTRAP;
	ModifyIDCMP(mainwindow,oldidcmp);
}

/************************************************************************/

void DragBobFunc()
{
	WORD xold,yold,dx,dy;
	register struct MyBob *bob;
	register struct IntuiMessage *msg;
	register struct BitMap *tmpmap;
	register WORD x,y,xoff,yoff;
	BOOL looping=TRUE;
	LONG oldidcmp;

	if((numbobs>0) && (numbobs!=actbobnum))
	{
		bob = BobTable[actbobnum];
		if(tmpmap=MakeBitMap(bob->Width,bob->Height,bob->Depth))
		{
			CopyMem(bob->Planes[0],tmpmap->Planes[0],bob->PlaneSize*bob->Depth);

			xoff = mainwindow->MouseX+bob->X0-mainx0;
			yoff = mainwindow->MouseY+bob->Y0-mainy0;
			x = xold = mainwindow->MouseX-xoff;
			y = yold = mainwindow->MouseY-yoff;
			oldidcmp = mainwindow->IDCMPFlags;
			mainwindow->Flags |= RMBTRAP;
			ModifyIDCMP(mainwindow,MOUSEBUTTONS);
			DrawRect(mainrastport,(WORD)(x-1),(WORD)(y-1),(WORD)(x+bob->Width),
				(WORD)(y+bob->Height),0);	/* Macht SetAPen,0 */
			do
			{
				WaitTOF();
				msg=(struct IntuiMessage *)GetMsg(mainwindow->UserPort);
				if(toolwindow) if(!msg)
					msg=(struct IntuiMessage *)GetMsg(toolwindow->UserPort);
				if(msg)
				{
					switch(msg->Code)
					{
						case SELECTUP:
							bob->X0 = mainx0-x;
							bob->Y0 = mainy0-y;
							looping=FALSE;
							break;

						case MENUDOWN:
							RectFill(mainrastport,x-1,y-1,x+bob->Width,
							   y+bob->Height);
							looping=FALSE;
							break;
					}
					ReplyMsg((struct Message *)msg);
				}
				else
				{
					xold=x; yold=y;
					x = mainwindow->MouseX-xoff;
					y = mainwindow->MouseY-yoff;
		/*			if(x<MINX) x = MINX;
					if(y<MINY) y = MINY;
					if(x > MAXX-bob->Width)  x = MAXX-bob->Width;
					if(y > MAXY-bob->Height) y = MAXY-bob->Height;
		*/
					dx = x-xold; dy = y-yold;

					if(dx>0)
						RectFill(mainrastport,xold-1,yold-1,x-1,yold+bob->Height);
					else
						RectFill(mainrastport,x+bob->Width,yold-1,xold+bob->Width,yold+bob->Height);

					if(dy>0)
						RectFill(mainrastport,xold-1,yold-1,xold+bob->Width,y);
					else
						RectFill(mainrastport,xold-1,y+bob->Height,xold+bob->Width,yold+bob->Height);

					WaitTOF();
					BltBitMapRastPort(tmpmap,0,0,mainrastport,x,y,
					   bob->Width,bob->Height,0xc0);
				}
			} while(looping);
			mainwindow->Flags &= ~RMBTRAP;
			ModifyIDCMP(mainwindow,oldidcmp);
			MyFreeBitMap(tmpmap);
		}
		else ShowMonoReq2("Not enough memory to move bob!");
	}
	else ShowMonoReq2("Internal Error 193 in Layer.c !");
}

/************************************************************************/

void SetCollBoundsFunc()
{
	register struct MyBob *bob;
	register struct IntuiMessage *msg;
	register BOOL looping=TRUE;
	register ULONG oldidcmp;
	register WORD x,y;

	if((numbobs>0) && (numbobs!=actbobnum))
	{
		CollisionRectMenuItem.Flags |= CHECKED;	/* Enable collision */
		options |= GOF_COLLISIONRECT;

		bob = BobTable[actbobnum];
		x = mainx0-bob->X0+bob->CollX0;
		y = mainy0-bob->Y0+bob->CollY0;
		DrawCross(mainscreen,x,y);

		oldidcmp = mainwindow->IDCMPFlags;
		mainwindow->Flags |= RMBTRAP;
		ModifyIDCMP(mainwindow,MOUSEBUTTONS);
		do
		{
			WaitTOF();
			if(msg = (struct IntuiMessage *)GetMsg(mainwindow->UserPort))
			{
				switch(msg->Code)
				{
				case SELECTDOWN:
					/* if(!BobHit(bob,msg->MouseX,msg->MouseY)) */
					{
						DrawCross(mainscreen,x,y);
						bob->CollX0 = x+bob->X0-mainx0;
						bob->CollY0 = y+bob->Y0-mainy0;
						ShowBob(bob);
						x = mainx0-bob->X0+bob->CollX1;
						y = mainy0-bob->Y0+bob->CollY1;
						DrawCross(mainscreen,x,y);
					}
					break;

				case SELECTUP:
					/* if(!BobHit(bob,msg->MouseX,msg->MouseY)) */
					{
						DrawCross(mainscreen,x,y);
						bob->CollX1 = x+bob->X0-mainx0;
						bob->CollY1 = y+bob->Y0-mainy0;
					}
					looping=FALSE;
					break;
				}
				ReplyMsg((struct Message *)msg);
			}
			else /* if(!BobHit(bob,mainwindow->MouseX,mainwindow->MouseY)) */
			{
				DrawCross(mainscreen,x,y);
				x = mainwindow->MouseX;
				y = mainwindow->MouseY;
				DrawCross(mainscreen,x,y);
			}
		} while(looping);

		mainwindow->Flags &= ~RMBTRAP;
		ModifyIDCMP(mainwindow,oldidcmp);
	}
	else ShowMonoReq2("Please select a bob first!");
}