Bitmap button / advice needed [SOLVED]
-
On 22/10/2014 at 09:53, xxxxxxxx wrote:
User Information:
Cinema 4D Version: r14
Platform: Windows ;
Language(s) : C++ ;---------
hi there,
i am having a hard time creating a few bitmap buttons for my object plugin. maybe someone can tell me how i can create 5 buttons using different images.edit: i've updated the code for all five buttons. they do show up and work correctly, but strangely they look the same....
in the res file: GROUP { LAYOUTGROUP; COLUMNS 5; GROUP { BITMAPBUTTON BUTTON1 {ANIM OFF;} } GROUP { BITMAPBUTTON BUTTON2 {ANIM OFF;} } GROUP { BITMAPBUTTON BUTTON3 {ANIM OFF;} } GROUP { BITMAPBUTTON BUTTON4 {ANIM OFF;} } GROUP { BITMAPBUTTON BUTTON5 {ANIM OFF;} } } and the source: #define pluginID 1000001 #define pluginName "test" #include "c4d.h" #include "c4d_symbols.h" #include "test.h" class test : public ObjectData { INSTANCEOF(test,ObjectData); private: LONG myType; public: virtual BaseObject* GetVirtualObjects(BaseObject *op, HierarchyHelp *hh); virtual Bool Message(GeListNode *node, LONG type, void *t_data); static NodeData *Alloc(void) { return gNew test; } virtual Bool Init(GeListNode *node); virtual Bool GetDParameter(GeListNode *node, const DescID &id, GeData &t_data, DESCFLAGS_GET &flags) ; virtual Bool GetDDescription(GeListNode *node, Description *description, DESCFLAGS_DESC &flags); }; Bool test::Init(GeListNode *node) { myType = BUTTON1; return true; } Bool test::GetDParameter(GeListNode *node, const DescID &id, GeData &t_data, DESCFLAGS_GET &flags) { LONG dirty = 0; BitmapButtonStruct bbs(static_cast<BaseObject*>(node), id, dirty); switch(id[0].id) { case BUTTON1: t_data = GeData(CUSTOMDATATYPE_BITMAPBUTTON, bbs); flags |= DESCFLAGS_GET_PARAM_GET; break; case BUTTON2: t_data = GeData(CUSTOMDATATYPE_BITMAPBUTTON, bbs); flags |= DESCFLAGS_GET_PARAM_GET; break; case BUTTON3: t_data = GeData(CUSTOMDATATYPE_BITMAPBUTTON, bbs); flags |= DESCFLAGS_GET_PARAM_GET; break; case BUTTON4: t_data = GeData(CUSTOMDATATYPE_BITMAPBUTTON, bbs); flags |= DESCFLAGS_GET_PARAM_GET; break; case BUTTON5: t_data = GeData(CUSTOMDATATYPE_BITMAPBUTTON, bbs); flags |= DESCFLAGS_GET_PARAM_GET; break; } return SUPER::GetDParameter(node, id, t_data, flags); } Bool test::GetDDescription(GeListNode *node, Description *description, DESCFLAGS_DESC &flags) { if (!description->LoadDescription(node->GetType())) return false; DescID btnId1 = DescLevel(BUTTON1, CUSTOMDATATYPE_BITMAPBUTTON, 0); BaseContainer btnBC1 = GetCustomDataTypeDefault(CUSTOMDATATYPE_BITMAPBUTTON); btnBC1.SetLong(BITMAPBUTTON_BORDER, BORDER_OUT); btnBC1.SetBool(BITMAPBUTTON_BUTTON, TRUE); if (myType==BUTTON1) btnBC1.SetLong(BITMAPBUTTON_BACKCOLOR, COLOR_EDGELT); if (!description->SetParameter(btnId1,btnBC1,DescLevel(ID_OBJECTPROPERTIES))) return false; DescID btnId2 = DescLevel(BUTTON2, CUSTOMDATATYPE_BITMAPBUTTON, 0); BaseContainer btnBC2 = GetCustomDataTypeDefault(CUSTOMDATATYPE_BITMAPBUTTON); btnBC2.SetLong(BITMAPBUTTON_BORDER, BORDER_OUT); btnBC2.SetBool(BITMAPBUTTON_BUTTON, TRUE); if (myType==BUTTON2) btnBC2.SetLong(BITMAPBUTTON_BACKCOLOR, COLOR_EDGELT); if (!description->SetParameter(btnId2,btnBC2,DescLevel(ID_OBJECTPROPERTIES))) return false; DescID btnId3 = DescLevel(BUTTON3, CUSTOMDATATYPE_BITMAPBUTTON, 0); BaseContainer btnBC3 = GetCustomDataTypeDefault(CUSTOMDATATYPE_BITMAPBUTTON); btnBC3.SetLong(BITMAPBUTTON_BORDER, BORDER_OUT); btnBC3.SetBool(BITMAPBUTTON_BUTTON, TRUE); if (myType==BUTTON3) btnBC3.SetLong(BITMAPBUTTON_BACKCOLOR, COLOR_EDGELT); if (!description->SetParameter(btnId3,btnBC3,DescLevel(ID_OBJECTPROPERTIES))) return false; DescID btnId4 = DescLevel(BUTTON4, CUSTOMDATATYPE_BITMAPBUTTON, 0); BaseContainer btnBC4 = GetCustomDataTypeDefault(CUSTOMDATATYPE_BITMAPBUTTON); btnBC4.SetLong(BITMAPBUTTON_BORDER, BORDER_OUT); btnBC4.SetBool(BITMAPBUTTON_BUTTON, TRUE); if (myType==BUTTON4) btnBC4.SetLong(BITMAPBUTTON_BACKCOLOR, COLOR_EDGELT); if (!description->SetParameter(btnId4,btnBC4,DescLevel(ID_OBJECTPROPERTIES))) return false; DescID btnId5 = DescLevel(BUTTON5, CUSTOMDATATYPE_BITMAPBUTTON, 0); BaseContainer btnBC5 = GetCustomDataTypeDefault(CUSTOMDATATYPE_BITMAPBUTTON); btnBC5.SetLong(BITMAPBUTTON_BORDER, BORDER_OUT); btnBC5.SetBool(BITMAPBUTTON_BUTTON, TRUE); if (myType==BUTTON5) btnBC5.SetLong(BITMAPBUTTON_BACKCOLOR, COLOR_EDGELT); if (!description->SetParameter(btnId5,btnBC5,DescLevel(ID_OBJECTPROPERTIES))) return false; flags |= DESCFLAGS_DESC_LOADED; return SUPER::GetDDescription(node, description, flags); } Bool test::Message(GeListNode *node, LONG type, void *t_data) { BaseObject *op = (BaseObject* )node; if (!op) return false; BaseContainer *data = op->GetDataInstance(); switch(type) { case MSG_DESCRIPTION_COMMAND: switch(static_cast<DescriptionCommand*>(t_data)->id[0].id) { case BUTTON1: data->SetString(NFO,"Button1"); myType = BUTTON1; break; case BUTTON2: data->SetString(NFO,"Button2"); myType = BUTTON2; break; case BUTTON3: data->SetString(NFO,"Button3"); myType = BUTTON3; break; case BUTTON4: data->SetString(NFO,"Button4"); myType = BUTTON4; break; case BUTTON5: data->SetString(NFO,"Button5"); myType = BUTTON5; break; } break; case MSG_DESCRIPTION_GETBITMAP: DescriptionGetBitmap *dgb1 = static_cast<DescriptionGetBitmap*>(t_data); dgb1->id[0] == BUTTON1; AutoAlloc<BaseBitmap> bm1; bm1->Init(GeGetPluginPath()+"res"+"btn1.tif"); dgb1->bmp = bm1.Release(); DescriptionGetBitmap *dgb2 = static_cast<DescriptionGetBitmap*>(t_data); dgb2->id[0] == BUTTON2; AutoAlloc<BaseBitmap> bm2; bm2->Init(GeGetPluginPath()+"res"+"btn2.tif"); dgb2->bmp = bm2.Release(); DescriptionGetBitmap *dgb3 = static_cast<DescriptionGetBitmap*>(t_data); dgb3->id[0] == BUTTON3; AutoAlloc<BaseBitmap> bm3; bm3->Init(GeGetPluginPath()+"res"+"btn3.tif"); dgb3->bmp = bm3.Release(); DescriptionGetBitmap *dgb4 = static_cast<DescriptionGetBitmap*>(t_data); dgb4->id[0] == BUTTON4; AutoAlloc<BaseBitmap> bm4; bm4->Init(GeGetPluginPath()+"res"+"btn4.tif"); dgb4->bmp = bm4.Release(); DescriptionGetBitmap *dgb5 = static_cast<DescriptionGetBitmap*>(t_data); dgb5->id[0] == BUTTON5; AutoAlloc<BaseBitmap> bm5; bm5->Init(GeGetPluginPath()+"res"+"btn5.tif"); dgb5->bmp = bm5.Release(); break; } return true; } BaseObject *test::GetVirtualObjects(BaseObject *op, HierarchyHelp *hh) { Bool dirty = op->CheckCache(hh) || op->IsDirty(DIRTYFLAGS_DATA); dirty = dirty || !op->CompareDependenceList(); if (!dirty) { return op->GetCache(hh); } BaseObject *main = BaseObject::Alloc(Onull); main->SetName("test"); if (main) { return main; } return NULL; } Bool Register_test(void) { GePrint(pluginName); return RegisterObjectPlugin(pluginID,pluginName,OBJECT_GENERATOR|OBJECT_INPUT,test::Alloc,"Test",AutoBitmap("test.tif"),0); } [CODE] hope someone can bring some light here. cheers, ello
-
On 23/10/2014 at 03:21, xxxxxxxx wrote:
Hello,
you are comparing the DescID with the button's ID without any context. So this line
dgb1->id[0] == BUTTON1;
won't make sense. You have to add a "if" structure or use a switch.
Best wishes,
Sebastian -
On 23/10/2014 at 03:37, xxxxxxxx wrote:
thank you very much! this works now:
DescriptionGetBitmap *dgb = static_cast<DescriptionGetBitmap*>(t_data); AutoAlloc<BaseBitmap> bm; switch(dgb->id[0].id) { case BUTTON1: bm->Init(GeGetPluginPath()+"res"+"btn1.tif"); break; case BUTTON2: bm->Init(GeGetPluginPath()+"res"+"btn2.tif"); break; case BUTTON3: bm->Init(GeGetPluginPath()+"res"+"btn3.tif"); break; case BUTTON4: bm->Init(GeGetPluginPath()+"res"+"btn4.tif"); break; case BUTTON5: bm->Init(GeGetPluginPath()+"res"+"btn5.tif"); break; } dgb->bmp = bm.Release();