/*
    RDECocoaGlue_NXColor.m

    Copyright 2019 Josh Freeman
    http://www.twilightedge.com

    This file is part of ReDoomEd for Mac OS X and GNUstep. ReDoomEd is a Doom game map
    editor, ported from id Software's DoomEd for NeXTSTEP.

    This file is distributed under the terms of the GNU Affero General Public License
    as published by the Free Software Foundation. You can redistribute it and/or modify
    it under the terms of version 3 of the License, or (at your option) any later
    version approved for distribution by this file's copyright holder (or an authorized
    proxy).

    ReDoomEd is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
    PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License along with
    this program. If not, see <http://www.gnu.org/licenses/>.
*/

#import "RDECocoaGlue_NXColor.h"

#import "../RDEUtilities/PPSRGBUtilities.h"


NXColor NXConvertRGBToColor(float r, float g, float b)
{
    return NXConvertRGBAToColor(r, g, b, 1);
}

NXColor NXConvertRGBAToColor(float r, float g, float b, float a)
{
    NXColor color;

    color.r = r;
    color.g = g;
    color.b = b;
    color.a = a;

    return color;
}

void NXConvertColorToRGB(NXColor nxColor, float *r, float *g, float *b)
{
    *r = NXRedComponent(nxColor);
    *g = NXGreenComponent(nxColor);
    *b = NXBlueComponent(nxColor);
}

void NXSetColor(NXColor nxColor)
{
    RDE_DPSGlue_SetNSColor(RDE_NSColorFromNXColor(nxColor));
}

NSColor *RDE_NSColorFromNXColor(NXColor nxColor)
{
    return [NSColor ppSRGBColorWithRed: NXRedComponent(nxColor)
                                green: NXGreenComponent(nxColor)
                                blue: NXBlueComponent(nxColor)
                                alpha: NXAlphaComponent(nxColor)];
}

NXColor RDE_NXColorFromNSColor(NSColor *color)
{
    CGFloat colorComponents[4];

    color = [color ppSRGBColor];

    [color getComponents: colorComponents];

    return NXConvertRGBAToColor(colorComponents[0], colorComponents[1], colorComponents[2],
                                colorComponents[3]);
}
