Drawcontext

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

Hi,
i want to draw some point. I try draw point to my frame , but i see nothing..
what function i should to view my frame?
Thanks Jan


long ADEditor::open (void *ptr)
{
CRect size (0, 0, hBackground->getWidth (), hBackground->getHeight ());
frame = new CFrame (size, ptr, this);
frame->setBackground (hBackground);
......
CPoint p;
CColor greenColor = {0, 255, 0, 0};
pcontext = new CDrawContext(frame, NULL, ptr);
pcontext->drawPoint(p(50,10), greenColor);
.....
}

Post

I wrote these classes quite a while ago, and don't use vstgui anymore. Might be of use to you.


e.g. usage:

Code: Select all

void 
FillSolid(CBitmap& bitmap, const CRect& r, const CColor& c)
{
	BitmapContext bc(bitmap);   	// creates a draw context on the bitmap.
	bc->setFillColor(c);		// access context as you would a normal cdrawcontext.
	bc->fillRect(r);	
}

enum {
	EWidth = 100,
	EHeight = 100
};

...


	SmartBitmap bmp(*frame, EWidth, EHeight);
	CColor c;

	FillSolid(*bmp, 
		CRect(0, 0, EWidth / 2, EHeight / 2), 	// fill a quarter of the bitmap
		c(0xAA, 0xFF, 0xAA, 0)
	);

	bitmap_view_ = new CBitmapView(CRect(0, 0, EWidth, EHeight), bmp);
	frame->addView(bitmap_view_);

	// you could potentially draw onto the background bitmap.



"smartbitmap.h"

Code: Select all

#include "vstgui.h"

#ifndef smartbitmap_h
#define smartbitmap_h

class SmartBitmap
{
public:
	explicit SmartBitmap(long resourceID)
		: b_(new CBitmap(resourceID)) {}

	SmartBitmap(CFrame &frame, long width, long height) 
		: b_(new CBitmap(frame, width, height)) {}

	explicit SmartBitmap(const char *filename)
		: b_(new CBitmapEx(filename)) {}

	SmartBitmap(const SmartBitmap& rhs) : b_(rhs.bitmap()) {
		b_->remember();
	}

	SmartBitmap& operator=(const SmartBitmap& rhs) {
		if (this != &rhs) {
			b_->forget();
			b_ = rhs.bitmap();
			b_->remember();
		}
		return *this;
	}

	SmartBitmap& operator=(CBitmap* rhs) {
		if (b_ != rhs) {
			b_->forget();
			b_ = rhs;
			b_->remember();
		}
		return *this;
	}

	~SmartBitmap() { b_->forget(); }

	CBitmap* bitmap() const { return b_; }

	// Implicit type conversion - should generally be wary of this
	// I think it is OK here though
	operator CBitmap*() { return b_; }
	CBitmap* operator->() { return b_; }
	CBitmap& operator*() { return *b_; }

private:
	SmartBitmap& operator=(const CBitmap* rhs); // prevent this
	CBitmap *b_;
};

#endif // smartbitmap_h

"bitmapcontext.h"

Code: Select all

#ifndef bitmapcontext_h
#define bitmapcontext_h

#include "vstgui.h"

class BitmapContext
{
public:
	BitmapContext(CBitmap& bmp);
	~BitmapContext();

	COffscreenContext* operator->() { return poc_; }
	COffscreenContext* operator&() { return poc_; }
	COffscreenContext& operator*() { return *poc_; }

private:
	BitmapContext(const BitmapContext&); // disable copy and assignment
	BitmapContext& operator= (const BitmapContext&);

	static int dcref_;
	static CDrawContext *pdc_;

	COffscreenContext *poc_;
	CBitmap& bmp_;
};

#endif
"bitmapcontext.cpp"

Code: Select all


#include "bitmapcontext.h"

int BitmapContext::dcref_;
CDrawContext *BitmapContext::pdc_;

BitmapContext::BitmapContext(CBitmap& bmp) 
: bmp_(bmp), 
  poc_(0)
{
	if (!poc_) {
		if (dcref_ == 0) {
			pdc_ = new CDrawContext(NULL, NULL, NULL);
		}
		++dcref_;

		poc_ = new COffscreenContext(pdc_, &bmp_, true);
	}

	bmp.remember();
}

BitmapContext::~BitmapContext() 
{
	--dcref_;

	if (dcref_ == 0) {
		delete pdc_;
		pdc_ = 0;
	}

	bmp_.forget();
	delete poc_;
}

"bitmapview.h"

Code: Select all


#include "vstgui.h"

#ifndef bitmapview_h
#define bitmapview_h

class CBitmapView : public CView 
{
	friend class CBitmapView;

public:
	CBitmapView(CRect& rect, CBitmap &bmp) 
	: CView(rect), pbmp_(&bmp) {	
		bmp.remember();	
	}

	CBitmapView(const CBitmapView& rhs) 
		: CView(rhs.size), pbmp_(rhs.pbmp_) {
		pbmp_->remember();
	}

	CBitmapView& operator= (const CBitmapView& rhs)
	{
		pbmp_ = rhs.pbmp_;
		pbmp_->remember();
	}

	~CBitmapView() { 
		pbmp_->forget(); 
	}

	virtual void draw(CDrawContext *pdc) {
		CView::draw (pdc);
		pbmp_->draw(pdc, size);
	}


private:
	CBitmap *pbmp_;
};

#endif

Post

...very usefull , thank you. And how can i do it using vstgui?
Jan

Post

That is using vstgui!!

(hence they say #include "vstgui.h" in them)

Post Reply

Return to “DSP and Plugin Development”