Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To answer my own question, here is a minimal paint example in C++ using wxWidgets. I have mainly assembled snippets from the book <a href="http://www.wxwidgets.org/docs/book/" rel="nofollow noreferrer">Cross-Platform GUI Programming with wxWidgets</a> which is available online for free.</p> <p>The drawing is as smooth as it can get, there are no problems with mouse event frequency, as can be seen from the screenshot. Note that the drawing will be lost when the window is resized, though. <a href="http://i33.tinypic.com/20rlnw2.jpg" rel="nofollow noreferrer">wxWidgets paint example http://i33.tinypic.com/20rlnw2.jpg</a></p> <p>Here is the C++ source code, assumed to be in a file <code>minimal.cpp</code>.</p> <pre><code>// Name: minimal.cpp // Purpose: Minimal wxWidgets sample // Author: Julian Smart, extended by Heinrich Apfelmus #include &lt;wx/wx.h&gt; // **************************** Class declarations **************************** class MyApp : public wxApp { virtual bool OnInit(); }; class MyFrame : public wxFrame { public: MyFrame(const wxString&amp; title); // constructor void OnQuit(wxCommandEvent&amp; event); void OnAbout(wxCommandEvent&amp; event); void OnMotion(wxMouseEvent&amp; event); private: DECLARE_EVENT_TABLE() // this class handles events }; // **************************** Implementation **************************** // **************************** MyApp DECLARE_APP(MyApp) // Implements MyApp&amp; GetApp() IMPLEMENT_APP(MyApp) // Give wxWidgets the means to create a MyApp object // Initialize the application bool MyApp::OnInit() { // Create main application window MyFrame *frame = new MyFrame(wxT("Minimal wxWidgets App")); //Show it frame-&gt;Show(true); //Start event loop return true; } // **************************** MyFrame // Event table for MyFrame BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) EVT_MENU(wxID_EXIT , MyFrame::OnQuit) END_EVENT_TABLE() void MyFrame::OnAbout(wxCommandEvent&amp; event) { wxString msg; msg.Printf(wxT("Hello and welcome to %s"), wxVERSION_STRING); wxMessageBox(msg, wxT("About Minimal"), wxOK | wxICON_INFORMATION, this); } void MyFrame::OnQuit(wxCommandEvent&amp; event) { Close(); } // Draw a dot on every mouse move event void MyFrame::OnMotion(wxMouseEvent&amp; event) { if (event.Dragging()) { wxClientDC dc(this); wxPen pen(*wxBLACK, 3); // black pen of width 3 dc.SetPen(pen); dc.DrawPoint(event.GetPosition()); dc.SetPen(wxNullPen); } } // Create the main frame MyFrame::MyFrame(const wxString&amp; title) : wxFrame(NULL, wxID_ANY, title) { // Create menu bar wxMenu *fileMenu = new wxMenu; wxMenu *helpMenu = new wxMenu; helpMenu-&gt;Append(wxID_ABOUT, wxT("&amp;About...\tF1"), wxT("Show about dialog")); fileMenu-&gt;Append(wxID_EXIT, wxT("E&amp;xit\tAlt-X"), wxT("Quit this program")); // Now append the freshly created menu to the menu bar... wxMenuBar *menuBar = new wxMenuBar(); menuBar-&gt;Append(fileMenu, wxT("&amp;File")); menuBar-&gt;Append(helpMenu, wxT("&amp;Help")); // ... and attach this menu bar to the frame SetMenuBar(menuBar); // Create a status bar just for fun CreateStatusBar(2); SetStatusText(wxT("Warning: Resize erases drawing.")); // Create a panel to draw on // Note that the panel will be erased when the window is resized. wxPanel* panel = new wxPanel(this, wxID_ANY); // Listen to mouse move events on that panel panel-&gt;Connect( wxID_ANY, wxEVT_MOTION, wxMouseEventHandler(MyFrame::OnMotion)); } </code></pre> <p>To build, I use the following <code>Makefile</code>, but this will not work for you, since you probably don't have the <code>macosx-app</code> utility. Please consult the wiki guide to <a href="http://wiki.wxwidgets.org/WxMac_Issues#Building_a_MacOSX_application_bundle" rel="nofollow noreferrer">Building a MacOSX application bundle</a>.</p> <pre><code>CC = g++ -m32 minimal: minimal.o $(CC) -o minimal minimal.o `wx-config --libs` macosx-app $@ minimal.o: minimal.cpp $(CC) `wx-config --cxxflags` -c minimal.cpp -o minimal.o clean: rm -f *.o minimal </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload