summaryrefslogtreecommitdiff
path: root/ImsgHandler.c
blob: 285d344ce45471b6bd31cd46c3044d99ac6dab79 (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
#include <proto/exec.h>
#include <proto/intuition.h>

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

extern struct MenuItem ToolWindowMenuItem,LayerModeMenuItem,
						OrgGridMenuItem,BobBordersMenuItem,
						CollisionRectMenuItem;
extern struct Screen *mainscreen;
extern struct MyBob *BobTable[];
extern WORD options,mainx0,mainy0,actbobnum,numbobs;
extern UWORD mainpalette[];
extern struct Gadget PosPropGadget,AutoSizeGadget,AutoOrgGadget,AnimKeyGadget;

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

void HandleImsg(struct IntuiMessage *imsg,struct Menu *menustrip)
{
	register struct MyBob *bob;
	register ULONG class;
	register UWORD code;
	register WORD hitflags;

	class = imsg->Class;
	code  = imsg->Code;
	bob   = BobTable[actbobnum];

	switch(class)
	{
		case CLOSEWINDOW:
			ToolWindowMenuItem.Flags &= ~CHECKED;
			ToolWindowFunc();
			break;

		case MOUSEBUTTONS:
			switch(code)
			{
			case SELECTDOWN:
				if((options & GOF_LAYERMODE) && bob)
				{
					hitflags=BobHit(bob,imsg->MouseX,imsg->MouseY);
					if(!hitflags) DragBobFunc();
					else
					{
						if(hitflags&1) bob->Y0++;
						if(hitflags&2) bob->Y0--;
						if(hitflags&4) bob->X0++;
						if(hitflags&8) bob->X0--;
					}
				}
				break;

			case MENUUP:
				LoadPalette(mainpalette);
				break;

			default:
				break;
			}
			break;

		case GADGETDOWN:
			if(imsg->IAddress == (APTR)&PosPropGadget)
			{
				MovePosFunc();
			}
			break;

		case GADGETUP:
			if(bob)
			{
				if(AutoSizeGadget.Flags & SELECTED)
					bob->Flags |=  BOBF_AUTOSIZE;
				else
					bob->Flags &= ~BOBF_AUTOSIZE;

				if(AutoOrgGadget.Flags & SELECTED)
					bob->Flags |=  BOBF_AUTOORG;
				else
					bob->Flags &= ~BOBF_AUTOORG;

				if(AnimKeyGadget.Flags & SELECTED)
					bob->Flags |=  BODF_ANIMKEY;
				else
					bob->Flags &= ~BODF_ANIMKEY;
			}

			HandleEvent((APTR)imsg->IAddress);
			break;

		case MENUPICK:
			LoadPalette(mainpalette);
			if(code != MENUNULL)
				HandleEvent((APTR)ItemAddress(menustrip,(LONG)code));
			break;

		case RAWKEY:
#ifdef DEBUG
			if(code&0x80)
			{
				printf("Rohe Taste losgelassen: $%02lx\n",code&0x7f);
			}
			else
#endif
			{
				switch(code)
				{
					case 0x5f:			/* HELP */
						AboutFunc();
						break;

					case 0x50:			/* F1 GetBob */
						GetBobFunc();
						break;

					case 0x51:			/* F2 Get multiple bobs */
						GetMultiFunc();
						break;

					case 0x52:			/* F3 SetOrg */
						SetOrgFunc();
						break;

					case 0x53:			/* F4 Set CollisionBounds */
						SetCollBoundsFunc();
						break;

					case 0x58:			/* F9 Insert New */
						InsertNewBobFunc();
						break;

					case 0x59:			/* F10 DeleteBob */
						DeleteActBobFunc();
						break;

					case 0x4c:			/* Cursor rauf: 1. Bob */
						actbobnum=0;
						RefreshBobNum();
						break;

					case 0x4d:			/* Cursor runter: letztes Bob */
						actbobnum=numbobs;
						RefreshBobNum();
						break;

					case 0x4e:			/* Cursor rechts: 1 Bob vor */
						if(actbobnum<numbobs) actbobnum++;
						RefreshBobNum();
						break;

					case 0x4f:			/* Cursor links: 1 Bob zurück */
						if(actbobnum>0) actbobnum--;
						RefreshBobNum();
						break;

					case 0x3e:			/* NumPad 8: Bob rauf schieben */
						if(bob)
							/* if((mainy0-bob->Y0) > MINY) */
								bob->Y0++;
						break;

					case 0x1e:			/* NumPad 2: Bob runter */
						if(bob)
							/* if((mainy0+bob->Height-bob->Y0) < MAXY) */
								bob->Y0--;
						break;

					case 0x2d:			/* NumPad 4: Bob links */
						if(bob)
							/* if((mainx0-bob->X0) > MINX) */
								bob->X0++;
						break;

					case 0x2f:			/* NumPad 6: Bob rechts */
						if(bob)
							/* if((mainx0+bob->Width-bob->X0) < MAXX) */
								bob->X0--;
						break;

					case 0x2e:		/* NumPad 5: Bob zentrieren gemäss Modus */
						if(bob)
						{
							SetBobDefaultOrg(bob);
						}
						break;

					case 0x40:			/* Space-Taste : Redraw screen */
						Cleanup(FALSE);	
						OpenMain();
						LoadPalette(mainpalette);
						break;

					case 0x01:			/* Normale '1': SetFirstAnimBob */
						SetFirstBobFunc();
						break;

					case 0x02:			/* Normale '2': SetLastAnimBob */
						SetLastBobFunc();
						break;

					case 0x20:			/* 'A': Start Animation */
						StartAnimFunc();
						break;

					case 0x11:			/* 'W': Tool Window on/off */
						ToolWindowMenuItem.Flags ^= CHECKED;
						ToolWindowFunc();
						break;

					case 0x35:			/* 'B': Bob Border on/off */
						BobBordersMenuItem.Flags ^= CHECKED;
						break;

					case 0x33:			/* 'C': Collision Border on/off */
						CollisionRectMenuItem.Flags ^= CHECKED;
						break;

					case 0x28:			/* 'L': Layer mode on/off */
						LayerModeMenuItem.Flags ^= CHECKED;
						break;

					case 0x18:			/* 'O': Org Grid on/off */
						OrgGridMenuItem.Flags ^= CHECKED;
						break;

					case 0x19:			/* 'P': Edit Palette */
						EditPaletteFunc();
						break;

					case 0x13:			/* 'R': Rotate */
						RotateFunc();
						break;

					case 0x32:			/* 'X': Flip X */
						FlipXFunc();
						break;

					case 0x15:			/* 'Y' (on ASCII keyboards ONLY) */
						FlipYFunc();
						break;

					case 0x31:			/* 'Z' (on ASCII keyboards ONLY) */
						ZoomFunc();
						break;

					default:
						/* DisplayBeep(mainscreen); */
						/* printf("Rohe Taste gedrückt: $%02lx\n",code); */
						break;
				}
			}
			break;

		default:
		{
			char buf[100];
			sprintf(buf,"HandleImsg(): class=$%08lx, code=$%04lx",class,code);
			ShowMonoReq2(buf);
		}
		break;
	}
}