// -*- objc -*-

#import "MiscColorMerge.h"

#import "MiscColorMergeInspector.h"

@implementation MiscColorMergeInspector

- init
{
    char buf[MAXPATHLEN + 1];
    id bundle;

    [super init];

    bundle = [NXBundle bundleForClass: [MiscColorMerge class]];
    [bundle getPath: buf forResource: "Inspector" ofType: "nib"];
    [NXApp loadNibFile: buf owner: self withNames: NO fromZone: [self zone]];

    return self;
}

- (BOOL) wantsButtons
{
    return NO;
}

- revert: sender
{
    int numColors = [object numPureColors],
	i;

    [mergeModeMatrix selectCellWithTag: [object mergeMode]];

    [colorMerge setAutodisplay: NO];

    [colorMerge removeAllColors];
    for (i = 0; i < numColors; ++i)
    {
	NXColor color;
	double position;

	[object getColor: &color andPosition: &position atIndex: i];
	[colorMerge addColor: color atPosition: position];
    }

    [colorMerge setAutodisplay: YES];

    return [super revert: self];
}

- mergeModeChanged: sender
{
    [colorMerge setMergeMode: [[mergeModeMatrix selectedCell] tag]];
    [object setMergeMode: [[mergeModeMatrix selectedCell] tag]];

    return [super ok: sender];;
}

- colorMergeDidChange: sender
{
    BOOL isAutodisplay = [object isAutodisplay];
    int numColors,
	i;

    [object setAutodisplay: NO];

    [object removeAllColors];
    numColors = [colorMerge numPureColors];
    for (i = 0; i < numColors; ++i)
    {
	NXColor color;
	double position;

	[colorMerge getColor: &color andPosition: &position atIndex: i];
	[object addColor: color atPosition: position];
    }

    [object setAutodisplay: isAutodisplay];

    return [super ok: sender];
}

@end
