/*************************************************************************
*
* ADOBE SYSTEMS INCORPORATED
* Copyright 2000-2002 Adobe Systems Incorporated 
* All Rights Reserved

* NOTICE: Adobe permits you to use, modify, and distribute 
* this file in accordance with the terms of the Adobe license 
* agreement accompanying it. If you have received this file 
* from a source other than Adobe, then your use, modification, 
* or distribution of it requires the prior written permission 
* of Adobe.
*
**************************************************************************/

// ----------------------------------------------------------------
// JSASample.c
// Sample for the GoLive Extend Script SDK
// ----------------------------------------------------------------

#include "JSA.h"

#include <math.h>

#ifdef WIN32
#include <windows.h>
#else
#include <QuickDraw.h>
#endif

// Implement this macro once to set up the necessary structures.

JSA_INIT

// Return the power of arg1 to arg2.

static void power(int argc, JSValue *argv, JSValue returnValue)
{
	double a, b, c;
	a = JSAValueToDouble(argv[0]);
	b = JSAValueToDouble(argv[1]);
	
	c = pow (a, b);
	
	JSADoubleToValue(returnValue, c);
}

// Draw an oval into the given rectangle. This demonstrates the
// use of the JSADrawInfo structure.

static void drawOval(int argc, JSValue *argv, JSValue returnValue)
{
	long temp;
	JSADrawInfo* info;
#ifdef WIN32
	HDC dc;
	temp = JSAValueToInt (argv[0]);
	info = (JSADrawInfo*) temp;
	dc = (HDC) info->context;
	Ellipse (dc, info->left, info->top, info->right, info->bottom);
#else
	Rect r;
	temp = JSAValueToInt (argv[0]);
	info = (JSADrawInfo*) temp;
	r.left = (short) info->left;
	r.top = (short) info->top;
	r.right = (short) info->right;
	r.bottom = (short) info->bottom;
	FrameOval (&r);
#endif
}

// Implement the JSAMain function to register all callable functions.

void JSAEXPORT JSAMain(void)
{
	JSARegisterFunction("power",power);
	JSARegisterFunction("drawOval",drawOval);
}

// optional, may be omitted

void JSAEXPORT JSAExit(void)
{}
