/*
* Author: Andrew Mann
*
* Copyright (C) 2004 PlaneShift Team (info@planeshift.it,
* http://www.planeshift.it)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation (version 2 of the License)
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*
*/


#include <psconfig.h>


#include "paws/pawsmanager.h"
#include "paws/pawsbutton.h"
#include "paws/pawstextbox.h"
#include "paws/pawsspinbox.h"

#include "gui_particlesystem.h"
#include "gui_colorrow.h"


guiColorRow::guiColorRow(PawsManager* manager )
            :pawsWidget( manager )
{
    button_remove=NULL;
    spinbox_red=NULL;
    spinbox_green=NULL;
    spinbox_blue=NULL;
    parent_particle_system=NULL;
}

guiColorRow::~guiColorRow()
{
}



bool guiColorRow::PostSetup()
{
    button_remove=(pawsButton *)FindWidget("remove_button");
    spinbox_red=(pawsSpinBox *)FindWidget("red_spinbox");
    spinbox_green=(pawsSpinBox *)FindWidget("green_spinbox");
    spinbox_blue=(pawsSpinBox *)FindWidget("blue_spinbox");

    return true;
}

bool guiColorRow::OnChange(pawsWidget * widget)
{
    if (widget == spinbox_red ||
        widget == spinbox_green ||
        widget == spinbox_blue )
    {
        if (parent_particle_system)
            parent_particle_system->ChangedColorRow(this);
        return true;
    }

    if (parent)
        return parent->OnChange(widget);
    return false;
}


bool guiColorRow::OnButtonPressed(int mouseButton, int keyModifier, pawsWidget* widget)
{
    if (!widget)
        return false;

    if (widget == button_remove)
    {
        if (parent_particle_system)
            parent_particle_system->DeleteColorRow(this);
        return true;
    }
    if (widget == spinbox_red ||
        widget == spinbox_green ||
        widget == spinbox_blue )
    {
        if (parent_particle_system)
            parent_particle_system->ChangedColorRow(this);
        return true;
    }

    if (parent)
        return parent->OnButtonPressed(mouseButton,keyModifier,widget);
    return false;
}

csColor guiColorRow::GetColor()
{
    csColor rval;
    if (!spinbox_red || !spinbox_blue || !spinbox_green)
        return csColor(0,0,0);

    rval.red=spinbox_red->GetValue();
    rval.green=spinbox_green->GetValue();
    rval.blue=spinbox_blue->GetValue();

    return rval;
}

void guiColorRow::SetColor(csColor col)
{
    if (!spinbox_red || !spinbox_blue || !spinbox_green)
        return;

    spinbox_red->SetValue(col.red);
    spinbox_green->SetValue(col.green);
    spinbox_blue->SetValue(col.blue);
}






