Higher precision Real CustomGui
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/10/2009 at 15:04, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 10-11.5
Platform: Windows ; Mac OSX ;
Language(s) : C++ ;---------
I wrote a CustomGui for Real to allow input of more decimal places because I need this occasionally in my plugins.Since this might be interestion for you folks so I decided to share the code here.
Theres a little limitation tho: Currently it doesnt use the UNIT set in the description. Is there an easy way to find out which unit is set? (so i can append it to the string)
looks like this:

-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/10/2009 at 15:06, xxxxxxxx wrote:
The code:
>
\> #include "c4d.h" \> \> const LONG CINDIGO_REAL_CUSTOMGUI = 1000001; //TODO: get plugin ID \> \> static LONG restypetable[] = { DA_REAL }; \> \> class CindigoRealDlg : public iCustomGui \> { \> INSTANCEOF(CindigoRealDlg, iCustomGui) \> private: \> BaseContainer m_settings; \> \> Real m_real; \> Bool m_tristate; \> \> public: \> CindigoRealDlg(const BaseContainer &settings;, CUSTOMGUIPLUGIN \*plugin) \> : iCustomGui(settings, plugin), m_real(), m_tristate(false), m_settings(settings) \> { \> \> } \> \> virtual void CustomGuiRedraw() \> { \> } \> \> virtual void DestroyWindow(void) \> { \> \> } \> \> virtual Bool CreateLayout (void) \> { \> AddEditNumberArrows(1000,0,80,0); \> \> return TRUE; \> } \> \> virtual Bool SupportLayoutSwitch() \> { \> return FALSE; \> } \> \> virtual Bool InitValues() \> { \> SetUnclampedReal(m_real); \> \> return TRUE; \> } \> \> void SetUnclampedReal(Real r) \> { \> SetReal(1000, r); \> String s = RealToString(r,-1,5); \> \> //if r == 0.0 set 0 \> if (r == 0.0) { \> s = "0"; \> } else { \> //cut of trailing zeros \> LONG i = 0; \> for(i = s.GetLength()-1; i > 0; i--) \> { \> if (s[i] != '0') break; \> } \> s = s.SubStr(0, i+1); \> } \> \> SetString(1000, s); \> } \> \> virtual LONG Message(const BaseContainer& msg, BaseContainer& result) \> { \> if ((msg.GetId() == BFM_ACTION) && msg.GetLong(BFM_ACTION_ID) == 1000) \> { \> if (msg.GetLong(BFM_ACTION_VALCHG) || msg.GetReal(BFM_ACTION_VALUE,MAXREAL) != MAXREAL) \> { \> m_real = msg.GetReal(BFM_ACTION_VALUE); \> \> SetUnclampedReal(m_real); \> \> return TRUE; //message processed \> } \> } \> \> return GeDialog::Message(msg,result); \> } \> \> virtual Bool Command(LONG id, const BaseContainer& msg) \> { \> switch (id) \> { \> case 1000: \> { \> BaseContainer m(msg); \> m.SetLong(BFM_ACTION_ID, GetId()); \> m.RemoveData(BFM_ACTION_VALUE); \> m.SetData(BFM_ACTION_VALUE, GetData().GetValue()); \> SendParentMessage(m); \> \> break; \> } \> } \> return TRUE; \> } \> \> virtual Bool SetData(const TriState<GeData> &tristate;) \> { \> m_real = tristate.GetValue().GetReal(); \> m_tristate = tristate.GetTri(); \> \> return TRUE; \> } \> \> virtual TriState<GeData> GetData() \> { \> GetReal(1000, m_real); \> return GeData(m_real); \> } \> }; \> \> class CindigoRealGui : public CustomGuiData \> { \> public: \> virtual LONG GetId() { return CINDIGO_REAL_CUSTOMGUI; } \> \> virtual CDialog\* Alloc(const BaseContainer &settings;) \> { \> CindigoRealDlg\* dlg = gNew CindigoRealDlg(settings, GetPlugin()); \> if (!dlg) return NULL; \> \> CDialog \*cdlg = dlg->Get(); \> if (!cdlg) return NULL; \> \> return cdlg; \> } \> \> virtual void Free(CDialog \*dlg, void \*userdata) \> { \> if (!dlg || !userdata) return; \> CindigoRealDlg \*sub = static_cast<CindigoRealDlg\*>(userdata); \> gDelete(sub); \> } \> \> #ifdef CINDIGO_C4D_VERSION_R115 \> virtual const CHAR \*GetResourceSym() \> #else \> virtual CHAR \*GetResourceSym() \> #endif \> { \> return "CINDIGO_REAL_GUI"; \> } \> \> virtual LONG GetResourceDataType(LONG \*&table;) \> { \> table = restypetable; \> return sizeof(restypetable)/sizeof(LONG); \> } \> }; \> \> \> \> Bool RegisterRealGUI() \> { \> static BaseCustomGuiLib mylib; \> ClearMem(&mylib;,sizeof(mylib)); \> FillBaseCustomGui(mylib); \> \> return InstallLibrary(CINDIGO_REAL_CUSTOMGUI, &mylib;, 1000, sizeof(mylib)) \> \> && \> \> RegisterCustomGuiPlugin("My String GUI", PLUGINFLAG_HIDE, gNew CindigoRealGui); \> } \> -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/10/2009 at 16:35, xxxxxxxx wrote:
Thanks. Generous to share. I always simply use percentage fields so I can support more digits but this is also nice.
Usually you use FormatNumber() which will give you a string with the current unit attached but you can also read out the units from the preferences and do it yourself (or add your own units). That´s what I did for my real customgui. Here is a code snippet:
> <code>
> enum
> {
> BPERCENT=0,
> BMETER,
> BDEGREE,
> BREAL,
> BLONG,
> _dummy
> };
>
> iDpitBarDialog(const BaseContainer &settings;,CUSTOMGUIPLUGIN *plugin) : iCustomGui(settings,plugin)
> {
> ra.min = R_rmin = settings.GetReal(DESC_MIN);
> ra.max = R_rmax = settings.GetReal(DESC_MAX);
> R_rtype = settings.GetLong(DESC_UNIT);
>
> if(R_rmin==R_rmax || R_rmin==0 && R_rmax==0)
> {
> ra.min = R_rmin = settings.GetReal(DPIT_REAL_MIN);
> ra.max = R_rmax = settings.GetReal(DPIT_REAL_MAX);
> R_rtype = settings.GetLong(DPIT_REAL_TYPE);
>
> switch(R_rtype)
> {
> case BREAL: R_rtype=DESC_UNIT_REAL;break;
> case BPERCENT: R_rtype=DESC_UNIT_PERCENT;break;
> case BDEGREE: R_rtype=DESC_UNIT_DEGREE;break;
> case BMETER: R_rtype=DESC_UNIT_METER;break;
> case BLONG: R_rtype=DESC_UNIT_LONG;break;
> }
> if(R_rmin==R_rmax || R_rmin==0 && R_rmax==0)
> {
> ra.min = -100;
> ra.max = 100;
> R_rtype = DESC_UNIT_REAL;
> }
> }
>
> ra.unit = GetWorldContainer().GetLong(WPREF_UNITS_BASIC);
> }</code> -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/10/2009 at 16:48, xxxxxxxx wrote:
Awesome, thank you, Katachi!
I'll add it to my code tomorrow.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/10/2009 at 01:39, xxxxxxxx wrote:
Looks like I can't append a unit string. As soon as enter a value smaller than 0.001 with a unit string appended ("m", for example), C4D apparently parses the whole thing wrong and throws weird numbers at me.
I'm not going to spend any more time on this - but if someone figures it out, please let me know

-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/12/2010 at 03:21, xxxxxxxx wrote:
Does this code really work for you? For me it doesn´t do anything. The value doesn´t even change and element->GetReal(ID) does always return the initial value.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/12/2010 at 03:29, xxxxxxxx wrote:
ok, ok, my fault. It works but you need to get rid of this line:
return TRUE; //message processed -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/12/2010 at 06:03, xxxxxxxx wrote:
The problem with the unit appending is that c4d tries to interpret the appended unit as the unit that is currently set in the c4d preferences.