0
votes

i'm be beginning to use wxWidgets in a project and i'm using wxClientDc to draw on a image. I created a class that inherits wxStaticBitmap adding my properties and drawing over it. To clear the image i'm setting the background as the same wxBitmap that i used in MY image:

    //that is my class
    class myImage : public wxStaticBitmap { 
    public: 
        wxBitmap frame;  //imagem
        myImage(wxWindow* parent, wxWindowID id, wxPoint pos, wxSize size, wxBitmap frame);
    private:
        void redesenha();
        void mouseUp(wxMouseEvent& event);
        void mouseDown(wxMouseEvent& event); 
        void mouseMove(wxMouseEvent& event); 
        wxDECLARE_EVENT_TABLE();
    };
    myImage::myImage(wxWindow* parent, wxWindowID id, wxPoint pos, wxSize size, wxBitmap frame): wxStaticBitmap(parent, id, frame, pos, size){
        this->frame = frame;
    }
    
    //that is my function to clear my image
    void myFrame::onClickClear(wxCommandEvent& event)
    {
        wxClientDC dc(myImg);
        dc.SetBackground(wxBrush(myImg->frame)); //frame is a wxBitmap type
        dc.Clear();
    }

The issue is that works in my laptop but when my friend download and compile it's doesn't work in his laptop.

1
usual stanza - 1. OS? 2 OS version? 3 wx version? 4 did you build wx dynamically or statically? And it goes for both you and your friend machine. On top of that - define . doesn't work. Throws an exception? Retruns an error? Produces wrong results? If yes - which operation? Did you also look at wxOverlay? - Igor
@Igor we are using windows 10 and wxWidgets 3.1.4 build the screen dynamically. Our machines have been configured with the same version of wxWidgets. Sorry, i forgot to explain why does'n work. On my friend's laptop when the Clear function is called the image is filled with black instead the Bitmap but when he set a color to backgrount it work correctly. - Danilo Namitala
and I presume you use the same compiler and same compilation options for both the library and the application? Did you try to handle wxEVT_ERASEBACKGROUND? Do you have wxEVT_PAINT handler? - Igor
@Igor i don't have. what should i put in these events? - Danilo Namitala

1 Answers

0
votes

If you need to "clear" a wxStaticBitmap, just assign a solid bitmap with the given colour.

More generally speaking, you shouldn't try to draw over the native controls (such as wxStaticBitmap) and you shouldn't use wxClientDC at all as drawing is only supported from wxEVT_PAINT handlers on many modern systems (e.g. macOS).