wxGrid and wxBitmap 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
BigFreeze
Earned some good credits
Earned some good credits
Posts: 109
Joined: Wed Sep 13, 2006 10:15 am
Location: Gebesee, Germany
Contact:

wxGrid and wxBitmap

Post by BigFreeze »

Hi everyone,

here is my problem: I have a class derived from wxGrid. I want to show a bitmap in one column. I derived a class from wxGridCellRenderer and do the drawing in the Draw(...) method. The bitmap is shown in the grid, but even if I use SetCellOverflow for the specific cell, the bitmap is fully displayed and not only in the cell.

My problem is, that I have to clear the device context at redraw the bitmap at runtime. But when I use the Clear() method the whole wxGrid is cleared, not only the bitmap.

Can anybody help me?

Thanks in advance. BigFreeze
It does not require a majority to prevail, but rather an irate, tireless minority keen to set brush fires in people's minds. (Samuel Adams)

OS: Windows XP Pro
Compiler: VC++ 8.0
wxWidgets: 2.8.0
IDE: VC++
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Re: wxGrid and wxBitmap

Post by tan »

Hi.
BigFreeze wrote:Hi everyone,

here is my problem: I have a class derived from wxGrid. I want to show a bitmap in one column. I derived a class from wxGridCellRenderer and do the drawing in the Draw(...) method. The bitmap is shown in the grid, but even if I use SetCellOverflow for the specific cell, the bitmap is fully displayed and not only in the cell.
wxGridCellRenderer::Draw() method takes wxRect parameter. It is cell rectangle. You can get subbitmap from the bitmap with specified width and height and draw the subbitmap. Or you can set clipping region on the DC.
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
BigFreeze
Earned some good credits
Earned some good credits
Posts: 109
Joined: Wed Sep 13, 2006 10:15 am
Location: Gebesee, Germany
Contact:

Post by BigFreeze »

Thanks for your reply.

If I set the clipping region for the bitmap, the whole wxGrid is not shown. The wxGrid has the same size like the image. If I clear the device context, the whole wxGrid is shown correctly.

It seems, that the device context ist the whole wxGrid and not only the cell, I specified with SetCellRenderer.

Maybe I should post some code. It is like this:

Code: Select all

MyGrid* grid;
grid->SetCellRenderer(0, 0, new MySymbol(speak_xpm));

MySymbol::Draw(...)
{
  dc.DrawBitmap(m_bmp, 5, 3+17*row, true); 
}
It does not require a majority to prevail, but rather an irate, tireless minority keen to set brush fires in people's minds. (Samuel Adams)

OS: Windows XP Pro
Compiler: VC++ 8.0
wxWidgets: 2.8.0
IDE: VC++
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

May be i don't understand exactly what do you want.
Do you want draw bitmap ONLY in specific cell? Try anything like this:

Code: Select all

MySymbol::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
               const wxRect& rect, int row, int col, bool isSelected))
{
  dc.DrawBitmap(m_bmp.GetSubBitmap(wxRect(0, 0, rect.width, rect.height)), rect.x, rect.y, true);
}
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
BigFreeze
Earned some good credits
Earned some good credits
Posts: 109
Joined: Wed Sep 13, 2006 10:15 am
Location: Gebesee, Germany
Contact:

Post by BigFreeze »

Ok, the image is drawn into a cell without an overflow into other cells. But if I do a dc.Clear() the whole wxGrid is cleared not only the image. I just want to delete the image in the cell and show again after some time.
It does not require a majority to prevail, but rather an irate, tireless minority keen to set brush fires in people's minds. (Samuel Adams)

OS: Windows XP Pro
Compiler: VC++ 8.0
wxWidgets: 2.8.0
IDE: VC++
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

BigFreeze wrote:Ok, the image is drawn into a cell without an overflow into other cells. But if I do a dc.Clear() the whole wxGrid is cleared not only the image. I just want to delete the image in the cell and show again after some time.
Just draw rectangle with default background color to hide image:

Code: Select all

MySymbol::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
               const wxRect& rect, int row, int col, bool isSelected))
{
     wxColour BgColor = attr.GetBackgroundColour();
     dc.SetBrush(wxBrush(BgColor, wxSOLID));
     dc.SetPen(*wxTRANSPARENT_PEN);
     dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
}    
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
BigFreeze
Earned some good credits
Earned some good credits
Posts: 109
Joined: Wed Sep 13, 2006 10:15 am
Location: Gebesee, Germany
Contact:

Post by BigFreeze »

Thanks. It works fine. Good job! Now I understand the whole topic a little better...
It does not require a majority to prevail, but rather an irate, tireless minority keen to set brush fires in people's minds. (Samuel Adams)

OS: Windows XP Pro
Compiler: VC++ 8.0
wxWidgets: 2.8.0
IDE: VC++
Post Reply