The layout of a C.O.F.F.E.E. dialog is specified in the CreateLayout()
function. This function, which always should be overloaded in derived dialog classes, is called by C4D whenever the dialog is opened. There are two ways to specify the layout:
The recommended way is to use layout files, just as C4D does internally. Then the typical CreateLayout()
becomes as easy as:
MyDialog::CreateLayout()
{
return LoadDialogResource(MY_DIALOG, myResource, 0);
}
The key here is that MY_DIALOG
corresponds to a MY_DIALOG.res file in the res/dialogs directory (see the Directory Structure chapter). This file might look like this: (More information on the syntax of dialog resources can be found here.)
DIALOG MY_DIALOG
{
NAME DIALOG_TITLE;
GROUP
{
COLUMNS 1;
SPACE 4,4;
BORDERSIZE 4,4,4,4;
STATICTEXT { NAME HELLO_WORLD; }
}
DLGGROUP { OK; CANCEL; }
}
Using a separate dialog resource like this has several advantages. Besides that it's easy to edit the dialog layout, it also facilitates international support greatly. The NAME
fields above doesn't specify their strings directly. Instead they point to the strings in the MY_DIALOG.str file in the strings_us/dialogs directory:
DIALOGSTRINGS MY_DIALOG
{
DIALOG_TITLE "My Dialog";
HELLO_WORLD "Hello World!";
}
If you would like to support German as well, just copy the strings_us directory to a new strings_de directory, and change the above file to:
DIALOGSTRINGS MY_DIALOG
{
DIALOG_TITLE "Mein Dialog";
HELLO_WORLD "Hallo Welt!";
}
The myResource
parameter is of the class GeResource
. It is recommended that you create such a resource object in the main()
function of your plugin, storing it in a global variable. The GetString()
member function of the resource class can be used to load other localizable strings (for example member messages), from the file c4d_strings.str:
STRINGTABLE
{
MY_ERROR "Oops! Something went wrong.";
}
The string files are stored in Unicode UTF-8, which means that they handle almost every language there is. A good Windows editor for Unicode files is Unipad. However, as long as you are only going to make English resources any text editor will do.
The id MY_ERROR
must be available as an enum in the c4d_symbols.h file. This also applies to the id of the dialog resources:
enum
{
MY_DIALOG = 10000,
MY_ERROR = 10001
};
This file is automatically read by C4D when it parses your resources, but you must include it in your plugin files yourself using this line at the top:
include "c4d_symbols.h"
If you for some reason don't want to use dialog resources for your dialog, all the resource commands for adding groups and dialog components are there as functions in the GeUserDialog class. So then the above dialog's CreateLayout()
function would look like this:
MyDialog::CreateLayout()
{
SetTitle("My Dialog");
AddGroupBeginV(100010, 0, 1, "", 0);
AddGroupSpace(4, 4);
AddGroupBorderSpace(4, 4, 4, 4);
AddStaticText(100011, 0, 0, 0, "Hello World!", 0);
AddGroupEnd();
AddDlgGroup(OK + CANCEL);
return TRUE;
}
Important: Please note that you have now lost all the localization features, unless you manually code all strings using the GeResource
class.
Example: ModalBounce.cof, HelloWorld.cof
The only area where you are unfortunately limited to non-resource solutions is menus. These are also be added in the CreateLayout()
function, using functions in the GeUserDialog
class:
MyDialog::CreateLayout()
{
MenuFlushAll();
MenuSubBegin("My Menu");
MenuAddString(MY_ITEM, "My Item");
MenuSubEnd();
MenuFinished();
...
}
To be able to localize the above code, just replace the strings like this:
MenuAddString(MY_ITEM, myResource->GetString(MY_ITEM_STRING));
Example: GuiDemo.cof