Problem with Blit

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
wingri
In need of some credit
In need of some credit
Posts: 9
Joined: Mon Mar 19, 2007 8:27 pm

Problem with Blit

Post by wingri » Sun Mar 25, 2007 12:11 am

Hi,
I`m getting some data from GPS receiver and I try to draw a trace of movement on the map. I use wxPaintDC and I draw in OnPaint method. I`m able to draw actuall position (a small circle on map), but I would like to draw a trace - a sequence of lines. When I get new actuall position I would like to add a line from previous position to actuall position.

I`m not sure how to do this. I thought about saving a bitmap with already drawn trace. And I would open it in next OnPaint event, add a new part of trace and save it again.

This is OnPaint method:

Code: Select all

void MyDC::OnPaint(wxPaintEvent& event)
{
  memory.SelectObject(bmpmask);
  if (first)
  // if the map is loaded for the first time load the original map
  {
       bmpmask.LoadFile(name, wxBITMAP_TYPE_BMP);    
       first = 0;

  }
  else 
  //otherway load map with drawed trace
       bmpmask.LoadFile(name2, wxBITMAP_TYPE_BMP);
     
  wxPaintDC dc(this);
  PrepareDC( dc );
       
  dc.DrawBitmap( bmpmask, 0, 0 , false);
  
  dc.SetPen(wxPen(wxColour(*wxRED),3,3));
  dc.SetBrush(wxBrush(wxColour(*wxRED),3));
  dc.DrawCircle(corx, cory, 5); 
  
  test = memory.Blit(0,0, Width, Height, &dc, 0, 0, false, 0, 0);   
  // the value of test is -1
  memory.SelectObject(wxNullBitmap);  
  bmpmask.SaveFile(name2, wxBITMAP_TYPE_BMP, NULL);
  
}

where:

Code: Select all


class MyDC:public wxScrolledWindow 
{
private:
      wxBitmap bmpmask;
      wxMemoryDC memory;
                  
      int PosX;
      int PosY;
      int Width;
      int Height;
      
      int first;
      
      wxString name;
      wxString name2;
      double corx;
      double cory;
    
public:
       MyDC(wxWindow* parent, wxWindowID id, int x, int y, int width, int height);
       ~MyDC() 
       {
       };
       
       void openmap(wxString name);
       void OnPaint(wxPaintEvent& event);  
       void setcor(double x, double y)
       {
            corx = x;
            cory = y;
       }
       
      DECLARE_EVENT_TABLE()    
};

MyDC::MyDC(wxWindow* parent, wxWindowID id, int x, int y, int width, int height):wxScrolledWindow(parent,id)  
{
  PosX = x;
  PosY = y;
  Width = width;
  Height = height;
  
  name = "map.bmp";
  name2 = "temp.bmp";
  
  corx = 0;
  cory = 0;
    
  SetSize(PosX,PosY,Width,Height,wxSIZE_AUTO);  
  
  SetBackgroundColour( *wxWHITE );  
  bmpmask.LoadFile(name, wxBITMAP_TYPE_BMP); 
  
  first = 1;
  
}

But this doesn`t work. I`m able to save a map to temp.bmp, but it`s just the original map - it doesn`t contains any drawn points. And I think it should. And function Blit returns -1.

I really don`t know, where the problem could be. Probably is there also better way how to draw a trace.

Probably this should run also without saving and loading bmpmask as a file. I also don`t draw lines now, painting points is a little easier.

I`m sorry for another topic about wxMemory, wxBitmap... but I feel quite lost in this wxWidgets drawing.

Thanks in advance.

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Sun Mar 25, 2007 1:17 am

I'n not pro in drawing, but i think it would be much easier to just keep a vector with a serie of coords in it, and then draw a serie of lines. Image I/O will slow down and is unnecessary

jazz
Experienced Solver
Experienced Solver
Posts: 73
Joined: Thu Jun 09, 2005 12:37 am
Contact:

Post by jazz » Sun Mar 25, 2007 9:55 pm

I don't see how this code would work either. You're drawing on the wxMemoryDC, not the wxBitmap. As far as I know, doing so will not update the original wxBitmap.

Regardless, the way you're doing it is going to be a massive resource hog. Like Auria said, I'd just maintain an vector of coords and draw them on each paint event.
[INSERT LAME SIG HERE]

Post Reply