//=================================================================================
// EQUINOX-3D plugin
//
// Path normal settings GUI for Extrude along Spline and Duplicate along Spline
//
// AUTHOR:  Gabor Nagy
// DATE:    2024-Aug-08 17:27:40
//
// Copyright (C) 1996-2026 By Gabor Nagy. All rights reserved.
//=================================================================================


//========================================
// Path normal GUI
//========================================
static void E3dPathNormalGUI_New(E3dPathNormalGUI* PGUI, XeWidget PParentW, EPointer PClientData, const uint8_t PNormalSource, const E3dCoord3* PNormal)
{
	XeWidget  LW;
	EArg      Args[256];int  ArgCnt;

	EXeStart;
	EXeSetArg(XeNMarginTop, 5);
	EXeSetArg(XeNRadioBehavior, TRUE);
	EXeSetArg(XeNOrientation, XeHORIZONTAL);
	EXeSetArg(XeNSpacingX, 8);EXeSetArg(XeNSpacingRight, 8);
	EXeSetArg(XeNMarginSizeY, 0);
	EXeSetArg(XeNMarginSizeX, 0);EXeSetArg(XeNMarginSizeY, 0);
	EXeSetArg(XeNBackgroundColorPtr, &Xe_BackgroundRGBAiColor);
	EXeSetArg(XeNResizableX, FALSE);EXeSetArg(XeNAlignmentX, XeAlignBEGINNING);
	EXeSetArg(XeNResizableY, FALSE);
	XeWidget  LMatrixW = XeWidget_ManagedNew("", XeMatrixWidget_class, PParentW,  Args, ArgCnt);
	PGUI->TopMatrixW = LMatrixW;

	EXeStart;
	EXeSetArg(XeNBackgroundColorPtr, &Xe_BackgroundRGBAiColor);
	EXeSetArg(XeNForegroundColorPtr, &Xe_ForegroundRGBAiColor);
	EXeSetArg(XeNResizableX, FALSE);EXeSetArg(XeNAlignmentX, XeAlignBEGINNING);
	EXeSetArg(XeNResizableY, FALSE);EXeSetArg(XeNAlignmentY, XeAlignCENTER);
	PGUI->LabelW = XeWidget_ManagedNew("Path normal", XeLabelWidget_class, LMatrixW,  Args, ArgCnt);

	EXeStart;
	EXeSetArg(XeNSpacingLeft, 4);
	EXeSetArg(XeNShadowThickness, 0);
	EXeSetArg(XeNHighlightThickness, 0);
	EXeSetArg(XeNSet, PNormalSource == E3dSplineNormalFIXED);
	XeToolTip8("Use the fixed direction specified below to orient each cross-section along the path Spline.");
	PGUI->FixedW = LW = XeWidget_ManagedNew("Fixed", XeToggleButton_class, LMatrixW,  Args, ArgCnt);
	XeAddCallback(LW, XeNValueChangedCallback, _CB_PathNormalFixed, PClientData);

	EXeStart;
	EXeSetArg(XeNShadowThickness, 0);
	EXeSetArg(XeNHighlightThickness, 0);
	EXeSetArg(XeNSet, PNormalSource == E3dSplineNormalCV);
	XeToolTip8(
"Use the normals stored in the path Spline to orient each cross-section.\nIf the Spline does not have valid normals, 'Auto' mode will be used.");
	PGUI->FromCVsW = LW = XeWidget_ManagedNew("From Spline", XeToggleButton_class, LMatrixW,  Args, ArgCnt);
	XeAddCallback(LW, XeNValueChangedCallback, _CB_PathNormalCV, PClientData);

	EXeStart;
	EXeSetArg(XeNShadowThickness, 0);
	EXeSetArg(XeNHighlightThickness, 0);
	EXeSetArg(XeNSet, PNormalSource == E3dSplineNormalAUTO);
	XeToolTip8("Automatically calculate normal vectors along the path\nSpline and use those to orient each cross-section.");
	PGUI->AutoW = LW = XeWidget_ManagedNew("Auto", XeToggleButton_class, LMatrixW,  Args, ArgCnt);
	XeAddCallback(LW, XeNValueChangedCallback, _CB_PathNormalAuto, PClientData);

	E3dpAxisSelector_New(&PGUI->AxisSelector, NULL, PParentW, TRUE,  _CB_PathNormalAxisSelector, PClientData,  PNormal->X, PNormal->Y, PNormal->Z);

	if(PNormalSource == E3dSplineNormalFIXED) XeWidget_Manage(PGUI->AxisSelector.MatrixW);
	else XeWidget_Unmanage(PGUI->AxisSelector.MatrixW);
}


static void _PathNormalGUIUpdate(E3dPathNormalGUI* PGUI, const uint8_t PNormalSource, const E3dCoord3* PNormal)
{
	XeToggleButton_SetState(PGUI->AutoW,     PNormalSource == E3dSplineNormalAUTO, FALSE);
	XeToggleButton_SetState(PGUI->FromCVsW,  PNormalSource == E3dSplineNormalCV, FALSE);
	XeToggleButton_SetState(PGUI->FixedW,    PNormalSource == E3dSplineNormalFIXED, FALSE);

	if(PNormalSource == E3dSplineNormalFIXED) XeWidget_Manage(PGUI->AxisSelector.MatrixW);
	else XeWidget_Unmanage(PGUI->AxisSelector.MatrixW);

	E3dpAxisSelector_Set(&PGUI->AxisSelector, PNormal->X, PNormal->Y, PNormal->Z);
}
