Text dialogs are used to display a short string of text and then let the user choose between a limited number of choices:
TextDialog("Hello World!", DLG_OKCANCEL);
More information about text dialogs can be found here.
In addition to the primitive methods above, plugins can communicate with the user through a GUI (graphical user interface). The main concept is the dialog. Plugins can open dialogs, both modal and non-modal, that can contain GUI components like buttons and text fields. There is a very versatile set of dialog interface features in the SDK, that allows plugins to be nearly fully integrated into the C4D environment.
A modal dialog is a dialog that takes full control of the application, requiring the user to dismiss it before continuing working. In C.O.F.F.E.E. such dialogs are created by deriving a class from GeModalDialog
.
The basic header of such a dialog would look like this:
class MyDialog : GeModalDialog
{
public:
MyDialog();
CreateLayout();
}
The CreateLayout()
function specifies how the dialog should look. You can read more about it here.
Once you have created the CreateLayout() function, you can open your dialog like this:
var dialog = new(MyDialog);
dialog->Open(-1, -1);
var result = dialog->GetResult();
If the dialog has a dialog group (i.e. OK and Cancel buttons), result
will contain either TRUE
or FALSE
depending on which one was pressed. The -1, -1 coordinates specify that the dialog should be opened at the current mouse position.
Other interesting overloads include the Command()
function, which is called when the user clicks on a button in the dialog or changes any of the fields, and the AskClose()
function, which gives the possibility to check the input values before the dialog is closed.
Examples: ModalBounce.cof
Non-modal dialogs behave like C4D's built-in managers. The user can continue working without having to close the dialog, and the dialogs can be docked with the C4D manager layout. This kind of dialog is created by deriving a class from GeDialog
.
The non-modal dialog class is somewhat more complicated that the modal class, and requires more knowledge about C4D's message system. A typical dialog might look like this:
class MyDialog : GeDialog
{
public:
MyDialog();
CreateLayout();
Command(id,msg);
Message(msg);
CoreMessage(id,msg);
}
Just as the modal dialog it has a CreateLayout()
function and a Command()
function, and they are used in the same way. The dialog is also opened in a similar way:
var dialog = new(MyDialog);
dialog->Open(TRUE, -1, -1);
The TRUE
specifies that the dialog should be non-modal. So yes, you can use the GeDialog
class for modal dialogs too if you want full control.
One difference is that you need to store the created dialog in for example a global variable, so that the garbage collector doesn't destroy it. To ensure that a dialog can be docked in the C4D layout, it must be created by a MenuPlugin
that has a RestoreLayout()
function:
// Global storage
var d;
MyMenuPlugin::Execute(doc)
{
// Open dialog when menu plugin is selected
d->Open(TRUE,-1,-1);
}
MyMenuPlugin::RestoreLayout(secret)
{
// Called by C4D to restore the dialog
if (!d) d = new(MyDialog);
d->RestoreLayout(secret);
}
main()
{
// Initialize the dialog
d = new(MyDialog);
Register(MyMenuPlugin);
}
Confused? Just have a look at, and/or copy one of the examples.
Examples: AsyncBounce.cof, GuiDemo.cof