Writing a paint program à la MS Paint - how to interpolate between mouse move events?

后端 未结 6 513
陌清茗
陌清茗 2020-12-14 22:48

I want to write a paint program in the style of MS Paint.

For painting things on screen when the user moves the mouse, I have to wait for mouse move events and draw

6条回答
  •  春和景丽
    2020-12-14 23:37

    I think you need to look into the Device Context documentation for wxWidgets.

    I have some code that draws like this:

    //screenArea is a wxStaticBitmap
    int startx, starty;
    void OnMouseDown(wxMouseEvent& event)
    {
        screenArea->CaptureMouse();
        xstart = event.GetX();
        ystart = event.GetY();
        event.Skip();
    }
    void OnMouseMove(wxMouseEvent& event)
    {
        if(event.Dragging() && event.LeftIsDown())
        {
            wxClientDC dc(screenArea);
            dc.SetPen(*wxBLACK_PEN);
            dc.DrawLine(startx, starty, event.GetX(), event.GetY());
        }
        startx = event.GetX();
        starty = event.GetY();
        event.Skip();
    }
    

    I know it's C++ but you said the language was irrelevant, so I hope it helps anyway.

    This lets me do this:

    alt text

    which seems significantly smoother than your example.

提交回复
热议问题