View Single Post
Old 09-06-2020, 02:23 AM   #15
stw
Human being with feelings
 
stw's Avatar
 
Join Date: Apr 2012
Posts: 279
Default

Yes, this very likely seems to be the root of your problem. IMHO it's not a good idea to trigger drawings that way.
For controls that need a regular draw update i have a dedicated control that triggers all drawings on the GUI thread (similar to your IControl approach - mDirty always true, but only for that 'trigger' control) thru a function pointer. So only the added controls inside that function are redrawed at fps rate.
Implementation here looks like this:
Code:
// Trigger Control Template in my ctrls.h

template <class T>
class DrawDummy : public IControl
{
private:
	typedef void (T::*void_Ptr)();
	void_Ptr voidPtr;
	T   *parent;
	
public:
	DrawDummy(IPlugBase *pPlug)
	: IControl(pPlug, IRECT(0,0,0,0)){}
	
	void setPtr(T *_Parent, void (T::*f)())
	{
		voidPtr = f;
		parent = _Parent;
	}
	
	bool IsDirty()
	{
		((parent)->*(this->voidPtr))();
		return true;
	}
	
	bool Draw(IGraphics* pGraphics) { return true;};
};
Attach and set drawing function in the GUI init section:
Code:
pGraphics->AttachControl(MyDrawdummy = new DrawDummy<MyPlug>(this));
MyDrawdummy->setPtr(this, &MyPlug::DoGraphics);
and then doing all the drawing stuff inside the DoGraphics function:
Code:
void MyPlug::DoGraphics()
{
        ctrl1->SetValueFromPlug(x);
        ctrl2->SetValueFromPlug(y)

...etc
};
Maybe you can try it this way.
stw is offline   Reply With Quote