summaryrefslogtreecommitdiffstats
path: root/Mac/Wastemods/WEObjectHandlers.c
blob: f1dd5af21cef98eed7809c3f87d5854a1bca7c5c (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
/*
	WASTE Demo Project:
	Sample WASTE Object Handlers

	Copyright © 1993-1998 Marco Piovanelli
	All Rights Reserved
*/

#include "WEObjectHandlers.h"

#ifndef __ICONS__
#include <Icons.h>
#endif

#ifndef __SOUND__
#include <Sound.h>
#endif

/* PICTURES */

pascal OSErr HandleNewPicture(Point *defaultObjectSize, WEObjectReference objectRef)
{
	PicHandle thePicture;
	Rect frame;

	/* get handle to object data (in this case, a picture handle) */
	thePicture = (PicHandle) WEGetObjectDataHandle(objectRef);

	/* figure out the default object size by looking at the picFrame record */
	frame = (*thePicture)->picFrame;
	OffsetRect(&frame, -frame.left, -frame.top);
	defaultObjectSize->v = frame.bottom;
	defaultObjectSize->h = frame.right;

	return noErr;
}

pascal OSErr HandleDisposePicture(WEObjectReference objectRef)
{
	PicHandle thePicture;

	/* get handle to object data (in this case, a picture handle) */
	thePicture = (PicHandle) WEGetObjectDataHandle(objectRef);

	/* kill the picture */
	KillPicture(thePicture);

	return MemError();
}

pascal OSErr HandleDrawPicture(const Rect *destRect, WEObjectReference objectRef)
{
	PicHandle thePicture;

	/* get handle to object data (in this case, a picture handle) */
	thePicture = (PicHandle) WEGetObjectDataHandle(objectRef);

	/* draw the picture */
	DrawPicture(thePicture, destRect);

	return noErr;
}


/* SOUND */

pascal OSErr HandleNewSound(Point *defaultObjectSize, WEObjectReference objectRef)
{
#pragma unused(objectRef)

	/* sounds are drawn as standard 32x32 icons */
	defaultObjectSize->v = 32;
	defaultObjectSize->h = 32;

	return noErr;
}

pascal OSErr HandleDrawSound(const Rect *destRect, WEObjectReference objectRef)
{
#pragma unused(objectRef)

	/* draw the sound icon */
	return PlotIconID(destRect, kAlignNone, kTransformNone, kSoundIconID);
}

pascal Boolean HandleClickSound(Point hitPt, EventModifiers modifiers,
					UInt32 clickTime, WEObjectReference objectRef)
{
#pragma unused(hitPt, clickTime)

	SndListHandle theSound;

	/* WASTE sets the low bit of modifiers on double (multiple) clicks */
	if (modifiers & 0x0001)
	{

		/* get a handle to the object data (in this case, a sound handle) */
		theSound = (SndListHandle) WEGetObjectDataHandle(objectRef);

		/* play the sound */
		SndPlay(nil, theSound, false);

		/* return TRUE so WASTE knows we handled the click */
		return true;
	}
	else
	{
		/* not a double click: let WASTE handle the mouse-down */
		return false;
	}
}