A second tutorial: Part 5 Coloring with the mouse

This tutorial makes a  simple wxWidgets program to edit XPM format files

Select a color
Set up a response to Select | Color and add a Color Dialog. Modify the inserted code by deleting the line wxColour myColour; as we have already declared myColour as a variable in MyFrame.

Draw by Moving the mouse
Right click in the middle of the Menuzone and choose Go Mouse Move. Add code to draw with the selected color on the screen:

if (event.Dragging())
     {
     wxClientDC dc(this);
     PrepareDC(dc);

     dc.SetPen(wxPen(pFrame->myColour,1,wxSOLID));
     dc.DrawPoint(event.GetX(), event.GetY());
     }

When the mouse is released, we need to save this to the memory bitmap; so right click the Menuzone and choose Go Left up. This reponds to the up movement of the mouse and add code to keep the picture:
      wxClientDC dc(this);
    PrepareDC(dc);

    wxMemoryDC temp_dc;
    temp_dc.SelectObject(pFrame -> myBitmap);
    temp_dc.Blit(0,0,pFrame -> myBitmap.GetWidth(),
                     pFrame -> myBitmap.GetHeight(),&dc,0,0);
 

Compile it now

Next
Back


wxHatch Home link to wxhatch help index