On 18/08/2014 at 13:54, xxxxxxxx wrote:
Hello,
creating your own node system is an ambitious task. And as stated before you may use a GeUserArea within a GeDialog.
So the first thing to do is to create you own dialog. You just need a dialog class based on GeDialog. An example is the ActiveObjectDialog in the SDK.
class ExampleDialog : public GeDialog
{
public:
ExampleDialog()
{
};
virtual Bool CreateLayout()
{
SetTitle("My Node System");
return true;
}
};
The layout of the dialog is defined in the CreateLayout function. Elements are not placed by absolute coordinates but are arranged in groups like in Cinemas *.res files. You can add Cinema's default widgets, menues and your own interactive widgets. Such a widget must be based on GeUserArea. An example is the SDKGradientArea in the SDK.
class ExampleUserArea : public GeUserArea
{
public:
virtual void DrawMsg(Int32 x1, Int32 y1, Int32 x2, Int32 y2, const BaseContainer& msg)
{
// we will draw the widget here
};
virtual Bool InputEvent(const BaseContainer& msg)
{
// we will handle user input here
return true;
};
};
The widget is drawn in DrawMsg :
virtual void DrawMsg(Int32 x1, Int32 y1, Int32 x2, Int32 y2, const BaseContainer& msg)
{
OffScreenOn();
// draw background
DrawSetPen(Vector(0.8, 0.8, 0.8));
DrawRectangle(0, 0, 400, 400);
// draw a simple rectangle
DrawSetPen(Vector(0.4, 0.4, 0.9));
DrawRectangle(100, 100, 200, 200);
};
You want to be able to interact with your nodes by clicking on them. To catch user interaction events use the InputEvent function:
virtual Bool InputEvent(const BaseContainer& msg)
{
GeData data;
// check if mouse event
msg.GetParameter(DescLevel(BFM_INPUT_DEVICE), data);
if (data.GetInt32() == BFM_INPUT_MOUSE)
{
// check if left mouse button
msg.GetParameter(DescLevel(BFM_INPUT_CHANNEL), data);
if (data.GetInt32() == BFM_INPUT_MOUSELEFT)
{
// now get the coordinates
msg.GetParameter(DescLevel(BFM_INPUT_X), data);
const Int32 xCoordiante = data.GetInt32();
msg.GetParameter(DescLevel(BFM_INPUT_Y), data);
const Int32 yCoordiante = data.GetInt32();
GePrint("UserArea hit at " + String::IntToString(xCoordiante) + " : " + String::IntToString(yCoordiante));
}
}
return true;
};
Finally you need to use your UserArea within your dialog:
virtual Bool CreateLayout()
{
SetTitle("My Node System");
C4DGadget * userAreaGadget = this->AddUserArea(1000, BFH_LEFT, 400, 300);
this->AttachUserArea(_exampleUserArea, userAreaGadget);
return true;
}
You simply create a new C4DGadget of the type UserArea and then attach an instance of your UserArea (_exampleUserArea) to this gadget.
Based on the user interaction you can update your node system; in DrawMsg you can draw you node system. Another thing is when you want to solve your node system; when should it be executed? This can happen when a new frame is processed; you may take a look at this thread.
With these elements you are able to build your own fully functional GUI. But still, building your own node system is a big undertaking that needs good planning.
Best wishes,
Sebastian