/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 */

#import <Cocoa/Cocoa.h>

#import "common.h"
#import "com_sun_rain_graphics_Color.h"

static jclass jColorClass = NULL;

/*
 * Class:     com_sun_rain_graphics_Color
 * Method:    _initIDs
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_com_sun_rain_graphics_Color__1initIDs
  (JNIEnv *env, jclass jClass)
{
    jColorClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "com/sun/rain/graphics/Color"));
}

/*
 * Class:     com_sun_rain_graphics_Color
 * Method:    _createColor
 * Signature: (FFFF)V
 */
JNIEXPORT void JNICALL Java_com_sun_rain_graphics_Color__1createColor
  (JNIEnv *env, jobject jcolor, jfloat alpha, jfloat red, jfloat green, jfloat blue)
{
    CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
    CGFloat components[] = { red, green, blue, alpha };
    CGColorRef colorRef = CGColorCreate(rgbColorSpace, components);
    CGColorSpaceRelease(rgbColorSpace);
    
    (*env)->SetLongField(env, jcolor, (*env)->GetFieldID(env, jColorClass, "ptr", "J"), ptr_to_jlong(colorRef));
}
