/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 */
#include "common.h"
#include <windows.h>
#include "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 = (jclass)env->NewGlobalRef(env->FindClass("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)
{
    //TODO: for some reason alpha doesn't work here - it blackens the color. Pre-multiplying doesn't help either.
    //      For now use the RGB components only.
    COLORREF colorRef = /*((BYTE)(alpha * 255.f) << 24) |*/ RGB((BYTE)(red * 255.f), (BYTE)(green * 255.f), (BYTE)(blue * 255.f));
    env->SetLongField(jcolor, env->GetFieldID(jColorClass, "ptr", "J"), ptr_to_jlong(colorRef));
}
