GeDialog ColorChooser Color + Alpha
-
I am creating my own iCumstomGUI and I want to add a colorchooser with alpha
But there is only a function called AddColorChooser which creates a color chooser without alphaThis one in particular:
-
Hey @ECHekman,
Thank you for reaching out to us. To be a little bit more verbose, you want to have color with alpha custom GUI in a dialog, and maybe are trying to use the native color field wrappers of a dialog, right?
You have to use a custom GUI in that case, because that is what that UI is. There is sort of a trick in this case, as the custom GUI for colors and colors with an alpha is actually the same (
CUSTOMGUI_COLOR
), what determines the layout, is for which data type you initialize the settings container for the GUI (DTYPE_COLOR
vs.DTYPE_COLORA
). So, adding such field to a dialog goes like this:// We create a datatype settings container for DTYPE_COLORA, i.e., a color with an alpha component. BaseContainer settings = GetCustomDataTypeDefault(DTYPE_COLORA); // ... do more settings work, check the user data editor with the data type Color with Alpha and there the details for all the settings, or the docs for `DR_COLORFIELD_...` // Now we add a #CUSTOMGUI_COLOR to the dialog with our settings. AddCustomGui(id, CUSTOMGUI_COLOR, String(), flags, 0, 0, settings);
Reading and writing would then be done with these two little monstrosities, as the native color getters and setters of
GeDialog
won't work:Bool MyDialog::GetColorAlphaField(Int32 id, ColorA& color) { iBaseCustomGui* colorChooser = static_cast<iBaseCustomGui*>(FindCustomGui(id, CUSTOMGUI_COLOR)); if (colorChooser) { TriState<GeData> colorData = colorChooser->GetData(); const ColorA* col = reinterpret_cast<const ColorA*>(colorData.GetValue().GetCustomDataTypeI(DTYPE_COLORA)); if (col) { color = *col; return true; } } return false; } Bool MyDialog::SetColorAlphaField(Int32 id, const ColorA& color) { iBaseCustomGui* colorChooser = static_cast<iBaseCustomGui*>(FindCustomGui(id, CUSTOMGUI_COLOR)); if (colorChooser) return colorChooser->SetData(TriState<GeData>(GeData(reinterpret_cast<const CustomDataType&>(color), DTYPE_COLORA))); return false; }
I hope this helps.
Cheers,
Ferdinand -
Thank you for your response that did the trick.
// ... do more settings work, check the user data editor with the data type Color with Alpha and there the details for all the settings, or the docs for
DR_COLORFIELD_...
|I am not familiar with the "user data editor". I am interested in changing the settings because this is what it looks like now:
I would like it to look like this - including the ability to fold it
-
Hey @ECHekman,
well, I was talking about User Data, as they can be a nice way to inspect what data types and their custom GUIs can do.
For what you want to do, this will however not help, as there are only the description settings listed, which necessarily do not have to be all settings there are. To start with an expanded GUI, you must set
LAYOUTMODE_MAXIMIZED
. I think the little toggle arrows are not supported in dialogs, but I might be wrong. When you want to know more about the little toggle arrow, I would suggest to write us a mail, so that I can forward it to a GUI specialist, as I do not know if and how you could make the arrow work.This is one of the cases how we internally setup such GUI in a dialog, maybe this already helps (but there are many, and they are not all the same). The a bit odd looking
SetInt32
('abcd', value)` thing, where we express an Int32 ID as four chars is something we sometimes do internally. Some people find it apparently easier to read/handle than symbols. It often also means that there is no proper integer value and symbol for that ID.void MyDialog::AddColorAlphaChooser(Int32 id, Int32 flags, Int32 layoutFlags) { BaseContainer colorUISettings = GetCustomDataTypeDefault(DTYPE_COLORA); colorUISettings.SetInt32(CUSTOMGUI_LAYOUTMODE, LAYOUTMODE_MAXIMIZED); colorUISettings.SetInt32('iccc', layoutFlags & (DR_COLORFIELD_ICC_BPTEX | DR_COLORFIELD_ICC_BASEDOC)); colorUISettings.SetInt32('cfld', layoutFlags); AddCustomGui(id, CUSTOMGUI_COLOR, String(), flags, 0, 0, colorUISettings); }
Cheers,
Ferdinand