How to draw a Bitmap in a wxDataViewCtrl Cell Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
katuday
Earned some good credits
Earned some good credits
Posts: 134
Joined: Fri Aug 17, 2012 2:22 am

How to draw a Bitmap in a wxDataViewCtrl Cell

Post by katuday »

I am using custom renderer such as

Code: Select all

class MyRenderer: public wxDataViewCustomRenderer
{
public:
	explicit MyRenderer(wxDataViewCellMode mode)
		: wxDataViewCustomRenderer("string", mode, wxALIGN_CENTER)
	{ }
	virtual bool Render(wxRect rect, wxDC *dc, int state) wxOVERRIDE
	{
		dc->DrawBitmap(m_wheel, rect.GetX(), rect.GetY(), false);
	}
};
the member variable

Code: Select all

m_wheel
is an xpm file that contains a bitmap which is green circle and I want to be rendered as is in the cell. What I am getting is a black rectangle not a green circle.
I need help with the correct placement and correct colour of the bitmap.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to draw a Bitmap in a wxDataViewCtrl Cell

Post by doublemax »

The code looks ok. Did you check if the bitmap is loaded correctly? Try a png with alpha channel for a test and set the useMask parameter of the drawbitmap call to true.
Use the source, Luke!
katuday
Earned some good credits
Earned some good credits
Posts: 134
Joined: Fri Aug 17, 2012 2:22 am

Re: How to draw a Bitmap in a wxDataViewCtrl Cell

Post by katuday »

doublemax wrote:The code looks ok. Did you check if the bitmap is loaded correctly? Try a png with alpha channel for a test and set the useMask parameter of the drawbitmap call to true.
Do you mean like this?

Code: Select all

if (m_pass.IsOk())
{
	wxMessageBox("OK");
	dc->DrawBitmap(m_pass, rect.GetX(), rect.GetY(), true); // set true
}
else
{
	wxMessageBox("Not OK");
}
The bitmap is loaded. But now I get a blank spot where I expect the bitmap
As for png with alpha channel? I am not sure what you mean. The original bitmap was a png which I converted to a xmp,
Here it is

Code: Select all

/* XPM */
static char *wheel_xpm[] = {
/* columns rows colors chars-per-pixel */
"98 128 24 1 ",
"  c #3FAB47",
". c #3FAC47",
"X c #3FAD47",
"o c #3FAB48",
"O c #3FAB49",
"+ c #3FAD48",
"@ c #3FAC49",
"# c #3FAD49",
"$ c #41AB47",
"% c #40AC47",
"& c #41AC47",
"* c #41AD47",
"= c #40AB48",
"- c #40AB49",
"; c #41AB49",
": c #40AC48",
"> c #41AC48",
", c #40AD48",
"< c #41AD48",
"1 c #40AC49",
"2 c #41AC49",
"3 c #40AD49",
"4 c #41AD49",
"5 c None",
/* pixels */
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555554.+44..44+4%5555555555555555555555555555555555555555555",
"555555555555555555555555555555555555554.4444444444444444444455555555555555555555555555555555555555",
"55555555555555555555555555555555555==4444444444444444444444444455555555555555555555555555555555555",
"555555555555555555555555555555554%444444444444444444444444444444+%55555555555555555555555555555555",
"555555555555555555555555555555%4444444444444444444444444444444444444555555555555555555555555555555",
"55555555555555555555555555554444444444444444444444444444444444444444445555555555555555555555555555",
"555555555555555555555555555.4444444444444444444444444444444444444444444555555555555555555555555555",
"55555555555555555555555554444444444444444444444444444444444444444444444445555555555555555555555555",
"5555555555555555555555554444444444444444444444444444444444444444444444444+555555555555555555555555",
"55555555555555555555555444444444444444444444444444444444444444444444444444#55555555555555555555555",
"5555555555555555555555*4444444444444444444444444444444444444444444444444444;5555555555555555555555",
"55555555555555555555544444444444444444444444444444444444444444444444444444444555555555555555555555",
"55555555555555555555444444444444444444444444444444444444444444444444444444444455555555555555555555",
"55555555555555555554444444444444444444444444444444444444444444444444444444444445555555555555555555",
"555555555555555555%444444444444444444444444444444444444444444444444444444444444;555555555555555555",
"5555555555555555544444444444444444444444444444444444444444444444444444O444444444455555555555555555",
"555555555555555544444444444444444444444444444444444444444444444444444455444444444%5555555555555555",
"555555555555555%4444444444444444444444444444444444444444444444444444%55554444444444555555555555555",
"5555555555555554444444444444444444444444444444444444444444444444444%555555#44444444555555555555555",
"55555555555555+444444444444444444444444444444444444444444444444444%55555555#4444444O55555555555555",
"5555555555555444444444444444444444444444444444444444444444444444445555555555#444444455555555555555",
"5555555555555444444444444444444444444444444444444444444444444444%555555555555+444444+5555555555555",
"555555555555%44444444444444444444444444444444444444444444444444*55555555555555+4444444555555555555",
"55555555555544444444444444444444444444444444444444444444444444*5555555555555555+44444O555555555555",
"5555555555544444444444444444444444444444444444444444444444444*555555555555555555+44444455555555555",
"55555555555%444444444444444444444444444444444444444444444444*5555555555555555555=44444%55555555555",
"55555555555444444444444444444444444444444444444444444444444*5555555555555555555%444444455555555555",
"5555555555444444444444444444444444444444444444444444444444*5555555555555555555&44444444+5555555555",
"555555555544444444444444444444444444444444444444444444444*5555555555555555555&44444444445555555555",
"55555555554444444444444444444444444444444444444444444444*5555555555555555555$444444444445555555555",
"555555555+444444444444444444444444444444444444444444444*5555555555555555555$4444444444444555555555",
"555555555.44444444444444444444444444444444444444444444*5555555555555555555$4444444444444O555555555",
"55555555544444444444444444444444444444444444444444444*5555555555555555555$444444444444444555555555",
"5555555554444444444444444444444444444444444444444444*5555555555555555555$4444444444444444555555555",
"555555555444444444444444444444444444444444444444444*5555555555555555555$44444444444444444555555555",
"555555554444444444444444444=4444444444444444444444*5555555555555555555$444444444444444444455555555",
"55555555.4444444444444444455%44444444444444444444*5555555555555555555$4444444444444444444 55555555",
"55555555+44444444444444445555%444444444444444444*5555555555555555555$44444444444444444444455555555",
"55555555%444444444444444555555%4444444444444444*5555555555555555555$444444444444444444444=55555555",
"5555555544444444444444455555555%44444444444444*5555555555555555555$4444444444444444444444+55555555",
"55555555.44444444444445555555555*444444444444*5555555555555555555$44444444444444444444444=55555555",
"55555555+44444444444+555555555555*4444444444%5555555555555555555$444444444444444444444444O55555555",
"5555555544444444444#55555555555555*44444444%5555555555555555555$4444444444444444444444444O55555555",
"555555554444444444#5555555555555555*444444%5555555555555555555$44444444444444444444444444O55555555",
"55555555+44444444#555555555555555555*4444%5555555555555555555$444444444444444444444444444455555555",
"55555555=44444444#5555555555555555555*44%5555555555555555555$4444444444444444444444444444=55555555",
"555555554444444444O5555555555555555555**5555555555555555555$44444444444444444444444444444+55555555",
"5555555554444444444O55555555555555555555555555555555555555$444444444444444444444444444444555555555",
"55555555544444444444O555555555555555555555555555555555555$4444444444444444444444444444444555555555",
"555555555444444444444O5555555555555555555555555555555555$44444444444444444444444444444444555555555",
"555555555;444444444444O55555555555555555555555555555555$444444444444444444444444444444444555555555",
"55555555544444444444444O555555555555555555555555555555$4444444444444444444444444444444444555555555",
"555555555544444444444444O5555555555555555555555555555$44444444444444444444444444444444445555555555",
"5555555555;44444444444444O55555555555555555555555555$4444444444444444444444444444444444=5555555555",
"55555555554444444444444444O555555555555555555555555$4444444444444444444444444444444444445555555555",
"555555555554444444444444444O5555555555555555555555$44444444444444444444444444444444444455555555555",
"55555555555#4444444444444444O55555555555555555555$444444444444444444444444444444444444455555555555",
"55555555555444444444444444444O555555555555555555$4444444444444444444444444444444444444455555555555",
"555555555555444444444444444444O5555555555555555$44444444444444444444444444444444444444555555555555",
"555555555555%444444444444444444O55555555555555$44444444444444444444444444444444444444=555555555555",
"555555555555544444444444444444444555555555555$4444444444444444444444444444444444444445555555555555",
"55555555555554444444444444444444445555555555$44444444444444444444444444444444444444455555555555555",
"5555555555555544444444444444444444O55555555$444444444444444444444444444444444444444=55555555555555",
"555555555555555444444444444444444444555555$444444444444444444444444444444444444444=555555555555555",
"555555555555555444444444444444444444O5555$44444444444444444444444444444444444444444555555555555555",
"5555555555555555+44444444444444444444O55$444444444444444444444444444444444444444445555555555555555",
"55555555555555555444444444444444444444O$4444444444444444444444444444444444444444455555555555555555",
"555555555555555555=4444444444444444444444444444444444444444444444444444444444444555555555555555555",
"555555555555555555544444444444444444444444444444444444444444444444444444444444=5555555555555555555",
"55555555555555555555444444444444444444444444444444444444444444444444444444444455555555555555555555",
"5555555555555555555554444444444444444444444444444444444444444444444444444444=555555555555555555555",
"5555555555555555555555=444444444444444444444444444444444444444444444444444445555555555555555555555",
"55555555555555555555555+44444444444444444444444444444444444444444444444444455555555555555555555555",
"555555555555555555555555%4444444444444444444444444444444444444444444444444555555555555555555555555",
"55555555555555555555555554444444444444444444444444444444444444444444444=45555555555555555555555555",
"555555555555555555555555555O444444444444444444444444444444444444444444O555555555555555555555555555",
"55555555555555555555555555555+44444444444444444444444444444444444444455555555555555555555555555555",
"5555555555555555555555555555554O44444444444444444444444444444444444=555555555555555555555555555555",
"555555555555555555555555555555554%4444444444444444444444444444444455555555555555555555555555555555",
"555555555555555555555555555555555554+444444444444444444444444O455555555555555555555555555555555555",
"55555555555555555555555555555555555555+O4444444444444444444455555555555555555555555555555555555555",
"55555555555555555555555555555555555555555554=4=+=O+O4=+5555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
"55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
};
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to draw a Bitmap in a wxDataViewCtrl Cell

Post by doublemax »

As for png with alpha channel? I am not sure what you mean.
Just for a test - to make sure the bitmap is not the problem - use a PNG that has an alpha channel, e.g. the toucan.png from the image sample. It will probably too big to fit in the cell, but that doesn't matter as it's just a test.

To check that the position is correct, you could just draw a red rectangle in that location.
Use the source, Luke!
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: How to draw a Bitmap in a wxDataViewCtrl Cell

Post by Manolo »

If you want to put a bitmap in a cell then change "string" in

Code: Select all

explicit MyRenderer(wxDataViewCellMode mode)
      : wxDataViewCustomRenderer("string", mode, wxALIGN_CENTER)
to "wxBitmap"

Code: Select all

explicit MyRenderer(wxDataViewCellMode mode)
      : wxDataViewCustomRenderer("wxBitmap", mode, wxALIGN_CENTER)
so the wxDVC knows what goes in that cell (string, bitmap...) in order to calculate sizes, etc.

It's a pity the docs and the sample about wxDVC lack so many things.

If you don't plan to change the cell frequently, why don't you use wxDataViewBitmapRenderer http://docs.wxwidgets.org/trunk/classwx ... derer.html directly instead of a custom render?
katuday
Earned some good credits
Earned some good credits
Posts: 134
Joined: Fri Aug 17, 2012 2:22 am

Re: How to draw a Bitmap in a wxDataViewCtrl Cell

Post by katuday »

Manolo wrote:If you want to put a bitmap in a cell then change "string" in

Code: Select all

explicit MyRenderer(wxDataViewCellMode mode)
      : wxDataViewCustomRenderer("string", mode, wxALIGN_CENTER)
to "wxBitmap"

If you don't plan to change the cell frequently, why don't you use wxDataViewBitmapRenderer http://docs.wxwidgets.org/trunk/classwx ... derer.html directly instead of a custom render?
Wow! Even more straight forward.
Post Reply