COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 03-09-2012, 07:31 AM   #1
virt
Human being with feelings
 
Join Date: Mar 2012
Location: Switzerland
Posts: 3
Default Best way to set a text from plug

Hey everyone,

First off, thanks a lot for everyone involved in making wdl/Iplug. I really enjoyed using it so far!

Now I have a pretty simple question (I guess), which somehow I cannot figure out by myself:

Say I have a "knob" whose value is set in ProcessDoubleReplacing() via SetControlFromPlug() (not associated with a "real" parameter). What is the best way to also display the numerical value of it on the GUI?

I've tried
Code:
idx = pGraphics->AttachControl(new IBitmapControl(...))
pGraphics->AttachControl(new ICaptionControl(this, &rect, idx, &text));
but this crashed my host. Did I miss something or is there any better way? Maybe via ITextControl and some set-function in the plug?

Thanks a lot in advance!
virt
virt is offline   Reply With Quote
Old 03-09-2012, 11:01 AM   #2
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Well, I don't know if this is the best way (probably not), but I would make a customized control in which I would override the Draw() method. Then I would simply call DrawIText() to draw the numerical value, i.e.:

Code:
class MyBitmapControl: public IBitmapControl
{
	MyBitmapControl(IPlugBase* pPlug, int x, int y, IBitmap* pBitmap):
	IBitmapControl(pPlug, x, y, -1, pBitmap) {}

	bool Draw(IGraphics* pGraphics)
	{
		IText font = IText(16, &COLOR_BLACK, NULL, IText::kStyleNormal, IText::kAlignCenter);
		IRECT rect = IRECT(mRECT.L, mRECT.B - 16, mRECT.R, mRECT.B);
		char str[10];
		sprintf(str, "%0.01f", mValue);
		return IBitmapControl::Draw(pGraphics) && pGraphics->DrawIText(&font, str, &rect);
	}
};
Tale is offline   Reply With Quote
Old 03-12-2012, 01:10 AM   #3
virt
Human being with feelings
 
Join Date: Mar 2012
Location: Switzerland
Posts: 3
Default

Excellent, thanks!
virt is offline   Reply With Quote
Old 03-12-2012, 03:54 AM   #4
virt
Human being with feelings
 
Join Date: Mar 2012
Location: Switzerland
Posts: 3
Default

Hmm, so now of course, the displayed value equals the internal 0-1 mValue. Is there an easy way to get something similar to the
Code:
InitDouble("disp value", 0.0, 0.0, 3.0, 0.1, "");
functionality for my display-only knob value?

I guess that comes down to the question, what would be a good way to use an IParam, without it residing on the base-class's mParams vector, and therefore without the option to access it via some paramIdx?

I realized I would have to rewrite quite a lot of classes in order to hand over a IPlugExample class member variable IParam, right?
virt is offline   Reply With Quote
Old 03-12-2012, 06:34 AM   #5
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

You could use IParam::GetDisplayForHost instead of sprintf, i.e.:

Code:
char str[100];
mPlug->GetParam(mParamIdx)->GetDisplayForHost(mValue, true, str);
Tale is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:02 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.