View Full Version : Fast method to show a "settings window" II
pylorca
02-14-2011, 03:10 PM
continuing the thread http://forum.cockos.com/showthread.php?t=71657
I want to show a settings windows.
1) at the start, I hide all settings controls.
2) when I clicked a rect, I show a bitmat overlay with the backgound settings.
3) show all settings controls.
The problem is that I'm a dummy guy :-S
IBitmap bitmapBackpanel = pGraphics->LoadIBitmap(BACKPANEL_ID, BACKPANEL_FN, 1);
iBackpanel = new IBitmapOverlayControl(this, 1, 1, &bitmapBackpanel, &IRECT(94, 389, 94+90, 389+20));
mBackpanel = pGraphics->AttachControl(iBackpanel);
Ok, this shows the background image, now I want to write the show_settings_controls when the backpanel is shown.
I'm a bit lost, a little help?
This is what I do: I enumerate all GUI controls, so I can access them by control index number rather then by parameter index number or pointer. The tricky part is I have to attach my controls in the right order. I then have a method that hides/shows all settings controls, background included.
enum EGuiControls
{
kGuiBg = 0,
kGuiSlider1,
kGuiSlider2,
kGuiSettingsBg,
kGuiSettingsSlider1,
kGuiSettingsSlider2,
kGuiNumControls
};
...
void MyPlug::HideSettingsControls(bool hide)
{
for (int i = kGuiSettingsBg; i <= kGuiSettingsSlider2; ++i)
{
GetGUI()->GetControl(i)->Hide(hide);
}
}
pylorca
02-14-2011, 06:55 PM
Thanks Tale!
I have omitted an important part in the previous message, sorry.
I thought I could use IBitmapOverlayControl, but it hasn't a callback (to place the unhide rutine when the rect is clicked)
I think I'll have to insert into iPlug and create a control but I did not want to come to this.
You don't need to insert anything into IPlug, just make a control that derives from ISwitchControl in your project.
Here's one I just did, a splash screen that can display some text.
The .h file:
#include "IControl.h"
// started life as IBitmapOverlayControl
class SplashControl : public ISwitchControl
{
public:
SplashControl(IPlugBase* pPlug, int x, int y, IBitmap* pBitmap, IRECT* pTargetArea)
: ISwitchControl(pPlug, x, y, -1, pBitmap), mTargetArea(*pTargetArea),
mText( *(ITEXT_FONT(&IColor(255,200,200,200),IText::kAlignCenter)) ),
mTextRECT(14,306,319,330) {
mStr.Set("");
}
~SplashControl() {}
bool Draw(IGraphics* pGraphics);
void SetTextFromPlug(char* str);
private:
IRECT mTargetArea; // Keep this around to swap in & out.
IText mText;
WDL_String mStr;
IRECT mTextRECT;
};
The .cpp file:
#include "SplashControl.h"
bool SplashControl::Draw(IGraphics* pGraphics)
{
if (mValue < 0.5) {
mTargetRECT = mTargetArea;
return true; // Don't draw anything.
}
else {
bool rc = IBitmapControl::Draw(pGraphics);
// &= for rest
char* cStr = mStr.Get();
if (CSTR_NOT_EMPTY(cStr)) {
rc &= pGraphics->DrawIText(&mText, cStr, &mTextRECT);
}
mTargetRECT = mRECT;
return rc;
}
}
void SplashControl::SetTextFromPlug(char* str) {
if (strcmp(mStr.Get(), str)) {
SetDirty(false);
mStr.Set(str);
}
}
pylorca
02-15-2011, 06:04 AM
Thanks cc_!
So and now can override OnMouseDown and access to the plug controls via mPlug. like: mPlug->GetGUI()->HideControl(xcontrol,false)
:)
pylorca
02-15-2011, 06:42 AM
It works!! :)
#include "../../../libs/wdl/IPlug/IControl.h"
class IBackPannelControl : public ISwitchControl
{
public:
IBackPannelControl(IPlugBase* pPlug, int x, int y, int paramIdx, IBitmap* pBitmap, IRECT* pTargetArea)
: ISwitchControl(pPlug, x, y, paramIdx, pBitmap), mTargetArea(*pTargetArea) {}
IBackPannelControl(IPlugBase* pPlug, int x, int y, IBitmap* pBitmap, IRECT* pTargetArea)
: ISwitchControl(pPlug, x, y, -1, pBitmap), mTargetArea(*pTargetArea) {}
~IBackPannelControl() {}
bool Draw(IGraphics* pGraphics);
void OnMouseDown(int x, int y, IMouseMod* pMod);
private:
IRECT mTargetArea; // Keep this around to swap in & out.
};
#include "CustomControls.h"
bool IBackPannelControl::Draw(IGraphics* pGraphics)
{
if (mValue < 0.5) {
mTargetRECT = mTargetArea;
return true; // Don't draw anything.
}
else {
mTargetRECT = mRECT;
return IBitmapControl::Draw(pGraphics);
}
}
void IBackPannelControl::OnMouseDown(int x, int y, IMouseMod* pMod)
{
// shows the pannel
if (mValue < 1.001)
{
mValue += 1.0;
mPlug->GetGUI()->HideControl(6,false); // HARDCODE!!!
}
// hide the pannel:
if (mValue > 1.001)
{
mValue = 0.0;
mPlug->GetGUI()->HideControl(6,true);// HARDCODE!!!
}
SetDirty();
vBulletin® v3.8.11, Copyright ©2000-2024, vBulletin Solutions Inc.