On 30/01/2016 at 10:18, xxxxxxxx wrote:
I found a way to toggle the border of the button. But it's a bit heavy handed and long in the tooth.
I'll post it here in case anyone needs this kind of behavior.
//The SDK BITMAPBUTTON_TOGGLE option does not let you keep the button looking like it's in a pressed state
//This code creates a GeDialog plugin with a bitmap button on it
//The button's image and border style toggles like an actual physical button (it stays pressed or unpressed)
//To make the border style change. I had to use LayoutFlushGroup() to destroy and re-make the entire button
//It works...But it requires a lot of code for something as trivial as toggeling a button's border
#include "c4d.h"
#include "c4d_symbols.h"
#define PLUGIN_ID 1000006 // be sure to use a unique ID obtained from www.plugincafe.com
enum
{
BTN_GRP = 10001,
MY_BITMAP_BUTTON1 = 10002
};
class MyDialog : public GeDialog
{
public:
MyDialog(void);
~MyDialog(void);
virtual Bool CreateLayout(void);
virtual Bool InitValues(void);
virtual Bool Command(LONG id,const BaseContainer &msg);
private:
MyDialog *dlg;
BitmapButtonCustomGui *myButton; //The button with an image on it
Bool btnState = false; //The state of the toggle button
void ReLayout(void); //Used to redraw the GeDialog
void CreateButton(void); //Used to create the bitmap button dynamically
};
MyDialog::MyDialog(void)
{
}
MyDialog::~MyDialog(void)
{
GeFree(dlg);
}
Bool MyDialog::CreateLayout(void)
{
Bool res = TRUE;
res = LoadDialogResource(IDS_RESDIALOG,NULL,0);
//This is an example of creating a custom button locally(not in the .res file) with AddCustomGui()
GroupBegin(BTN_GRP, BFH_LEFT, 2, 0, "MyButtonGroup", 0);
{
CreateButton();
}
GroupEnd();
return res;
}
Bool MyDialog::InitValues(void)
{
if (!GeDialog::InitValues()) return FALSE;
return TRUE;
}
void MyDialog::ReLayout(void)
{
LayoutFlushGroup(BTN_GRP);
CreateButton();
LayoutChanged(BTN_GRP);
}
void MyDialog::CreateButton(void)
{
BaseContainer bbc; //Create a container to hold our custom button gizmo
if(btnState == false)
{
bbc.SetBool(BITMAPBUTTON_BORDER, BORDER_OUT);
bbc.SetString(BITMAPBUTTON_TOOLTIP, "I'm Up");
bbc.SetLong(BITMAPBUTTON_ICONID1, RESOURCEIMAGE_ROTATE);
}
else
{
bbc.SetBool(BITMAPBUTTON_BORDER, BORDER_IN);
bbc.SetString(BITMAPBUTTON_TOOLTIP, "I'm Down");
bbc.SetLong(BITMAPBUTTON_ICONID1, RESOURCEIMAGE_MOVE);
}
myButton = static_cast<BitmapButtonCustomGui*>(this->AddCustomGui(MY_BITMAP_BUTTON1, CUSTOMGUI_BITMAPBUTTON, "Bitmap Button", BFH_SCALEFIT | BFH_SCALEFIT, 130, 30, bbc));
}
Bool MyDialog::Command(LONG id,const BaseContainer &msg)
{
switch (id)
{
case MY_BITMAP_BUTTON1:
GePrint("Bitmap Button Was Pressed");
btnState = !btnState; //Makes the variable toggle true / false
myButton->SetToggleState(btnState); //Toggles the button image
ReLayout(); //Run the custom method that creates the button dynamically
break;
}
EventAdd();
return TRUE;
}
class MyDialogCMD : public CommandData
{
private:
MyDialog dlg;
public:
virtual Bool Execute(BaseDocument *doc);
virtual Bool RestoreLayout(void *secret);
};
Bool MyDialogCMD::Execute(BaseDocument *doc)
{
StopAllThreads();
return dlg.Open(DLG_TYPE_ASYNC,PLUGIN_ID, -1, -1, 200,200);
}
Bool MyDialogCMD::RestoreLayout(void *secret)
{
return dlg.RestoreLayout(PLUGIN_ID,0,secret);
}
Bool RegisterMyDialogCMD(void)
{
String Help = "Toggles Bitmap Button's border style"; //This string appears in the status bar when the user hovers over the plugin name in the menu
//Register the plugin
return RegisterCommandPlugin(PLUGIN_ID, GeLoadString(IDS_RESDIALOG), 0, AutoBitmap("icon.tif"), Help, gNew MyDialogCMD);
}
-ScottA
*Edit- Oops. Cross posted with you there.
Thanks again for the code Katachi