summaryrefslogtreecommitdiff
path: root/Anim.c
blob: c4aa3c0466f0b8d20368d7aa22cdae4c37fb45ce (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
/*
**  Bobi - The Ultimate Amiga Bob Manipulator
**
**  Anim.c - Bobs animieren
**
**  COPYRIGHT (C) 1989-1993 BY CHRISTIAN A. WEBER, ZUERICH, SWITZERLAND.
**  ALL RIGHTS RESERVED. NO PART OF THIS SOFTWARE MAY BE COPIED, REPRODUCED,
**  OR TRANSMITTED IN ANY FORM OR BY ANY MEANS, WITHOUT THE PRIOR WRITTEN
**  PERMISSION OF THE AUTHOR. NO WARRANTY. USE AT YOUR OWN RISK.
*/

#include <proto/exec.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/dos.h>

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

#define MAXANIMDELAY 50

extern struct Gadget AnimSpeedGadget;
extern struct PropInfo AnimSpeedGadgetSInfo;
extern struct MyBob *BobTable[];
extern struct Window *mainwindow,*toolwindow;
extern WORD numbobs,actbobnum;
extern WORD firstanimbob,lastanimbob,animflags;

extern struct MenuItem ForwardItem,BackwardItem,PingPongItem;


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

void SetFirstBobFunc()
{
	if(BobTable[actbobnum]) firstanimbob = actbobnum;
	else                    ShowMonoReq2("No bob selected!");
}


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

void SetLastBobFunc()
{
	if(BobTable[actbobnum]) lastanimbob = actbobnum;
	else                    ShowMonoReq2("No bob selected!");
}


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

void StartAnimFunc()
{
	register struct IntuiMessage *msg;
	register LONG bobnum,dir,delay,i;
	struct Menu *mainmenus,*toolmenus;
	STRPTR oldmaintitle,oldtooltitle;

	oldmaintitle=mainwindow->ScreenTitle;
	SetWindowTitles(mainwindow,(STRPTR)(~0L),"Hit <ESC> or RMB to stop animation");
	mainmenus = mainwindow->MenuStrip;
	ClearMenuStrip(mainwindow);

	if(toolwindow)
	{
		oldtooltitle=toolwindow->ScreenTitle;
		SetWindowTitles(toolwindow,(STRPTR)(~0L),"Hit <ESC> or RMB to stop animation");
		toolmenus = toolwindow->MenuStrip;
		ClearMenuStrip(toolwindow);
	}

	if(lastanimbob < firstanimbob)
	{
		bobnum = lastanimbob;
		lastanimbob = firstanimbob;
		firstanimbob = bobnum;
	}
	bobnum = firstanimbob;
	dir=1; if(animflags & AF_BACKWARD) dir=-1;

	for(;;)
	{
		delay = (GetAnimSpeed()*MAXANIMDELAY+0x7fffL)>>16;
		for(i=0; i<delay; ++i)
		{
			WaitTOF();
			msg=(struct IntuiMessage *)GetMsg(mainwindow->UserPort);
			if(toolwindow)
			{
				if(!msg) msg=(struct IntuiMessage *)GetMsg(toolwindow->UserPort);
			}

			if(msg)
			{
				if((msg->Class==MENUPICK) ||
				   ((msg->Class==RAWKEY)     && (msg->Code==0x45)))
				{
					ReplyMsg((struct Message *)msg);
					goto endanim;
				}
				ReplyMsg((struct Message *)msg);
			}
		}
		bobnum += dir;
		if(animflags & AF_BOUNCE)
		{
			if((bobnum>lastanimbob) || (bobnum<firstanimbob))
			{
				dir = (-dir);
				bobnum += dir;
				bobnum += dir;
			}
		}
		else
		{
			if(bobnum>lastanimbob)  bobnum = firstanimbob;
			if(bobnum<firstanimbob) bobnum = lastanimbob;
		}
		ShowBob(BobTable[bobnum]);
	}
endanim:
	actbobnum = bobnum;
	SetWindowTitles(mainwindow,(STRPTR)(~0L),oldmaintitle);
	if(toolwindow) SetWindowTitles(toolwindow,(STRPTR)(~0L),oldtooltitle);
	ShowFrame(actbobnum);
	SetMenuStrip(mainwindow,mainmenus);
	if(toolwindow) SetMenuStrip(toolwindow,toolmenus);
}


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

UWORD GetAnimSpeed()
{
	return(AnimSpeedGadgetSInfo.VertPot);
}


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

void SetAnimSpeed(UWORD speed)
{
	AnimSpeedGadgetSInfo.VertBody = 0xffffL/MAXANIMDELAY;
	AnimSpeedGadgetSInfo.VertPot  = speed;

	if(toolwindow)
		RefreshGList(&AnimSpeedGadget,toolwindow,0,1);
}


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

void SetAnimFlags(WORD flags)
{
	ForwardItem.MutualExclude  = 6;
	BackwardItem.MutualExclude = 5;
	PingPongItem.MutualExclude = 3;

	ForwardItem.Flags  &= ~CHECKED;
	BackwardItem.Flags &= ~CHECKED;
	PingPongItem.Flags &= ~CHECKED;

	if(flags & AF_FORWARD)
	{
		ForwardItem.Flags  |= CHECKED;
	}
	if(flags & AF_BACKWARD)
	{
		BackwardItem.Flags |= CHECKED;
	}
	if(flags & AF_BOUNCE)
	{
		PingPongItem.Flags |= CHECKED;
	}

	animflags = flags;
}


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

void SetAnimModeFunc()
{
	if(ForwardItem.Flags & CHECKED)
	{
		animflags = AF_FORWARD;
	}
	else if(BackwardItem.Flags & CHECKED)
	{
		animflags = 0;
	}
	else /* if(PingPongItem.Flags & CHECKED) */
	{
		animflags = AF_BOUNCE;
	}
}