SetAxisOrientation does not work on wxBufferedPaintDC, but only on wxPaintDC

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
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

SetAxisOrientation does not work on wxBufferedPaintDC, but only on wxPaintDC

Post by ollydbg23 »

Hi, I try to implement this feature: Reverse Y-Axis in wxMathplot

The first thing I found was using the SetAxisOrientation function before any function call inside wxMathplot's GDI function call.

So, I did some test, here is the test code:

Code: Select all

#include <wx/app.h>
#include <wx/frame.h>
#include <wx/dcclient.h>
#include <wx/dcbuffer.h>



class Drawing1Frame : public wxFrame
{
public:
    Drawing1Frame(const wxString& title);

private:
    void OnPaint(wxPaintEvent& evt);

    wxDECLARE_EVENT_TABLE();
};

wxBEGIN_EVENT_TABLE(Drawing1Frame, wxFrame)
    EVT_PAINT(Drawing1Frame::OnPaint)
wxEND_EVENT_TABLE()


class Drawing1App : public wxApp
{
public:
    virtual bool OnInit();
};

wxIMPLEMENT_APP(Drawing1App);

bool Drawing1App::OnInit()
{
    Drawing1Frame* frame = new Drawing1Frame("Drawing1");
    frame->Show(true);
    return true;
}


Drawing1Frame::Drawing1Frame(const wxString& title)
    : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600), wxDEFAULT_FRAME_STYLE|wxCLIP_CHILDREN|wxFULL_REPAINT_ON_RESIZE)
{
    SetBackgroundColour(*wxWHITE);
}

void Drawing1Frame::OnPaint(wxPaintEvent& evt)
{
    //wxPaintDC bufDC(this);
    wxBufferedPaintDC bufDC(this);

    PrepareDC(bufDC);

    bufDC.SetDeviceOrigin( bufDC.GetSize().GetWidth()/2, bufDC.GetSize().GetHeight()/2);

    //bufDC.SetLogicalOrigin(400, 400);
    bufDC.SetAxisOrientation(false, false);
    //bufDC.SetUserScale(1.0, 1.0);
    //bufDC.SetMapMode(wxMM_TEXT);
    bufDC.SetBackgroundMode(wxBRUSHSTYLE_SOLID);
    bufDC.Clear();

    bufDC.SetBrush(*wxTRANSPARENT_BRUSH);
    bufDC.SetPen(*wxRED_PEN);

    /// draw red rectangle
    bufDC.DrawRectangle(50, 50, 200, 100);

    /// draw blue rectangle
    bufDC.SetPen(*wxBLUE_PEN);
    bufDC.DrawRectangle(100, 100, 250, 150);

}
You can see the image shot below, it looks like the SetAxisOrientation function only works under wxPaintDC, but not wxBufferedPaintDC.

Any idea how to make a reversed Y axis on wxMathplot control?

Thanks.
Attachments
2021-12-01 10 50 14.png
2021-12-01 10 50 14.png (22.67 KiB) Viewed 572 times
2021-12-01 10 49 21.png
2021-12-01 10 49 21.png (23.33 KiB) Viewed 572 times
2021-12-01 10 48 01.png
2021-12-01 10 48 01.png (24.66 KiB) Viewed 572 times
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

Re: SetAxisOrientation does not work on wxBufferedPaintDC, but only on wxPaintDC

Post by ollydbg23 »

Here is the screen shot of the wxBufferedPaintDC. (It looks like I can only upload 3 images in a single post)
Attachments
2021-12-01 10 57 01.png
2021-12-01 10 57 01.png (28.8 KiB) Viewed 569 times
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: SetAxisOrientation does not work on wxBufferedPaintDC, but only on wxPaintDC

Post by PB »

I remember writing about this years ago here: viewtopic.php?f=1&t=44508#p183739 I suppose this is the same?

The post above shows how to reproduce with a wxWidgets sample, which could be useful when reporting the issue on wxTrac.
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

Re: SetAxisOrientation does not work on wxBufferedPaintDC, but only on wxPaintDC

Post by ollydbg23 »

Hi, PB, thanks for the reply.

I just read the thread and I found a workaround by doublemax.

Re: Change wxPaintDC to wxBufferedPaintDC

The core solution is to create a wxMemoryDC, and copy all the attributes from the wxPaintDC to the wxMemoryDC (by the function call CopyAttributes()).

Then I can first draw on the wxMemoryDC, and at the last stage, just paint the bitmap on the wxPaintDC by calling ( DrawBitmap( buffer, 0, 0 ); ).

Now, I can make SetAxisOrientation function works as expected in the wxMemoryDC (as the same as the wxPaintDC). But the remaining issue is that why wxBufferedPaintDC dose not copy all the attributes by default once it created?
Post Reply