AeFloatFieldUI.c++ 1.84 KB
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <limits.h>

#include "AeTypes.h"
#include "AeFieldUI.h"
#include "AeAsset.h"
#include "AeAssetUI.h"


AeFloatFieldUI::AeFloatFieldUI (const char * name,
				Boolean isEditable,
				Boolean isSelectable,
				Boolean isHierarchical,
				TJustify justify,
				TFloatGetProc getProc,
				TFloatSetProc setProc) :
    AeFieldUI (name, isEditable, isSelectable, isHierarchical, False, justify, kFloatMaxLen)
{
    fGetProc = getProc;
    fSetProc = setProc;
    
    fMin = FLT_MIN;
    fMax = FLT_MAX;
    fDefault = 0;
}

AeFloatFieldUI::AeFloatFieldUI (const char * name,
				Boolean isEditable,
				Boolean isSelectable,
				Boolean isHierarchical,
				TJustify justify,
				TFloatGetProc getProc,
				TFloatSetProc setProc,
				float min, float max, float def) : 
    AeFieldUI (name, isEditable, isSelectable, isHierarchical, False, justify, kFloatMaxLen)
{
    fGetProc = getProc;
    fSetProc = setProc;
    
    fMin = min;
    fMax = max;
    fDefault = def;
}

AeFloatFieldUI::~AeFloatFieldUI (void)
{
}

void
AeFloatFieldUI::GetValueString (AeAsset * asset, String string)
{
    float value = fGetProc (asset);
    sprintf (string, "%.1f", value);
}

Boolean
AeFloatFieldUI::SetValueString (AeAsset * asset, String string)
{
    assert (fSetProc);

    float value = atof (string);
	
    assert (value >= fMin && value <= fMax);

    if (value == fGetProc (asset))
	return False;

    fSetProc (asset, value);
    return True;
}

Boolean
AeFloatFieldUI::VerifyValueString (String string)
{
    float value = atof (string);
	
    if (value < fMin || value > fMax)
	return False;

    return True;
}

Boolean
AeFloatFieldUI::VerifyInput (XmTextVerifyCallbackStruct * verify, const char * prevStr)
{
    // we will need to fill this in as soon as we use an actual float field
    return True;
}