Drawing Order 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
Koji
In need of some credit
In need of some credit
Posts: 5
Joined: Thu May 25, 2006 4:02 am

Drawing Order

Post by Koji » Thu May 25, 2006 4:22 am

Hey everyone, I am curious if someone might be able to help me solve an issue.

I have designed a selection box using a transparent background and dc.DrawRectangle();

It works well however the real goal is to make a Photoshop/Imageready selection box on top of an image, however i am running into a problem when the screen renders.

The selection box is ending up behind the image like so.

Image

I am using the following code to make it all happen. (Note the TGA class is just one of many i have tried as far as images goes, the same happens with png, jpg, etc..)

Code: Select all

void Canvas::Draw(wxDC& dc)
{
	TGAImg *tga = new TGAImg();
	tga->Load("Layout.tga");
	wxImage img(tga->GetWidth(),tga->GetHeight(),tga->GetImg(),0,true);
	dc.DrawBitmap(wxBitmap(img),wxPoint(100,100));
	
}
The OnPaint methd looks as follows

Code: Select all

void Canvas::OnPaint(wxPaintEvent &WXUNUSED(event))
{
    wxPaintDC dc(this);
    PrepareDC(dc);

    m_parent->PrepareDC(dc);

    dc.SetBrush(*wxTRANSPARENT_BRUSH);
    dc.SetPen( wxPen( wxT("black"), 1, wxSOLID) );
    dc.DrawRectangle(origin,wxSize(delta.x,delta.y));

    Draw();

}
The Rectangle sizes are set elseware with mouse events.

If anyone has any insight as to why its doing this and how i can fix it, I would really appriciate it.

Cursor
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Aug 29, 2004 3:09 pm
Location: Grenoble, France
Contact:

Post by Cursor » Thu May 25, 2006 7:33 am

Simply, render is done in the order you write.
So if you write :

Code: Select all

dc.DrawRectangle(origin,wxSize(delta.x,delta.y));
dc.DrawBitmap(wxBitmap(img),wxPoint(100,100));
The rectangle is drawn before the image and will be drawn below the image.
So if you want an image with a rectangle on it, you must write :

Code: Select all

dc.DrawBitmap(wxBitmap(img),wxPoint(100,100));
dc.DrawRectangle(origin,wxSize(delta.x,delta.y));
What is little and green, witch go up and down ??
Yoda playing with the force.

Koji
In need of some credit
In need of some credit
Posts: 5
Joined: Thu May 25, 2006 4:02 am

Post by Koji » Thu May 25, 2006 11:05 pm

Ahh thank you very much, works perfectly =)

Post Reply