COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 01-30-2020, 03:30 AM   #1
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default Simple Draw Rectangle Control error

I made a Control to write a simple dynamic rectangle.

I have modified IControl.h Tale version as follows:

Code:
class IDrawRect : public IControl {
public:

	IDrawRect(IPlugBase* pPlug, IRECT* pR, const IColor* pColor)
	:   IControl(pPlug, pR), mColor(*pColor) {
			myRect.L=pR->L;	
			myRect.T=pR->T;
			myRect.R=pR->R;
			myRect.B=pR->B;
	}
	~IDrawRect() {}

	bool Draw(IGraphics* pGraphics);
	void SetRectFromPlug(IRECT* pR);
	void DelRectFromPlug();

protected:
	IColor mColor;
	IRECT myRect;
};
Also IControl.cpp:

Code:
bool IDrawRect::Draw(IGraphics* pGraphics) {
		return pGraphics->FillIRect(&mColor, &myRect);
}
void IDrawRect::SetRectFromPlug(IRECT* pR) {
		myRect.L=pR->L;	
		myRect.T=pR->T;
		myRect.R=pR->R;
		myRect.B=pR->B;
		SetDirty(false);
		Redraw();
}
void IDrawRect::DelRectFromPlug() {
		myRect.B=myRect.T;
		myRect.R=myRect.L;
		SetDirty(false);
		Redraw();
}
When I use to draw more rectangles it gives me errors: the first rectangle is deleted and the second one is incomplete.
__________________
Audio plugins | BrainWaveProducer | EmRysRa
SaschArt is offline   Reply With Quote
Old 01-30-2020, 07:08 AM   #2
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,652
Default

In your SetRectFromPlug() you probably should also update mRECT (and maybe also mTargetRECT), because that's used by IGraphics:: Draw() (see IGraphics.cpp).
Tale is online now   Reply With Quote
Old 01-30-2020, 09:42 AM   #3
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default

Still draw wrong, even with mTargetRECT update
__________________
Audio plugins | BrainWaveProducer | EmRysRa
SaschArt is offline   Reply With Quote
Old 01-31-2020, 04:17 AM   #4
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,652
Default

Weird, because I've quickly added your code tyo Lem Echo Music, and it seems to work just fine. Maybe the bug is in the calling code? I just added this to my main plug-in's constructor:

Code:
IRECT r1(100, 100, 400, 300);
pGraphics->AttachControl(new IDrawRect(this, &r1, &COLOR_RED));
IRECT r2(150, 150, 450, 200);
pGraphics->AttachControl(new IDrawRect(this, &r2, &COLOR_GREEN));
Do note that I haven't tried SetRectFromPlug() or DelRectFromPlug(), because, like I said, that would require more work (i.e. updating at least mRECT).
Tale is online now   Reply With Quote
Old 01-31-2020, 07:19 AM   #5
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default

Used in a static way there are no problems but dynamic yes.

In plugin constructor


Code:
	lfoRect = new IDrawRect(this, &IRECT(33, 327, 33+160, 327+6), &IColor(180,75,255,220));
	lfoRect1 = new IDrawRect(this, &IRECT(239, 327, 239+160, 327+6), &IColor(180,75,255,220));
In OnParamChange(int id)

Code:
	lfoRect->SetRectFromPlug(&IRECT(33+round((lfo_mid[0]-lfo_depth[0])*bar_width), 327, 33+round((lfo_mid[0]+lfo_depth[0])*bar_width), 327+6));

	lfoRect1->SetRectFromPlug(&IRECT(239+round((lfo_mid[0]-lfo_depth[0])*bar_width), 327, 239+round((lfo_mid[0]+lfo_depth[0])*bar_width), 327+6));
Rectangle from SetRectFromPlug() argument does not exceed the area initially draw in the constructor. But still draw wrong becouse of Dirty() I suppose

GetGUI()->IsDirty(&IRECT(33, 327, 33+160, 327+6)); in OnParamChange() seems to have no effect
__________________
Audio plugins | BrainWaveProducer | EmRysRa

Last edited by SaschArt; 01-31-2020 at 08:16 AM.
SaschArt is offline   Reply With Quote
Old 01-31-2020, 08:29 AM   #6
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default

The error was from some wrong parameters in OnParamChange(). No need to update mRECT, but must cover myRect
__________________
Audio plugins | BrainWaveProducer | EmRysRa
SaschArt 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 12:20 AM.


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