views:

186

answers:

3

I want to learn how to draw shapes with wxWidgets. Where do I start? In case there are multiple ways, I prefer ease of use over cross-platform compatibility. I'm a Windows user.

A: 

This is done by creating a wxPanel, connecting to the paint event, and using the DC provided in that paint event to draw various things.

The DC has a number of drawing related functions. This will probably be using Windows GDI or something similar, which means performance probably won't be fantastic, but it should work for simple purposes. You can find a tutorial with sample code on the Wiki. Look for the documentation for the wxDC class to see a list of drawing functions you can use.

If you need something with more performance, look into the wxGLCanvas which renders a hardware accelerated OpenGL canvas.

cecilkorik
I noticed that wxPanels don't support the OnLeftDown event. I want users to be able to "paint" with their mouse pointer, so I need that event. Is there an alternative approach to this?
Pieter
I use wxPython instead of the C wxWidgets, but they are very similar in design and I can't see any reason you shouldn't be able to connect a left click event to a wxPanel. It may not have a built-in virtual function for that event, but you should still be able to connect the event directly somehow. In Python "self.panel.Bind(wx.EVT_LEFT_DOWN, self.onClick)" would do it. Does that help at all? I will look into it more to see if I can figure it out.
cecilkorik
Yeah you should be able to bind the EVT_LEFT_DOWN event inside your Panel's EVENT_TABLE. All you should have to do is find (or create?) an event table for your wxPanel and add a line like "EVT_LEFT_DOWN(MyFrame::MyClickFunc)". See http://docs.wxwidgets.org/stable/wx_eventhandlingoverview.html for details.
cecilkorik
Thanks for your advice on this issue!
Pieter
A: 

I recommend looking at the old OGL library (included in contrib of wx 2.8, but not in the later versions of wx) or wxArt2D. This is simpler than doing it manually, although you can, of course, still do it, after all both of these libraries are implemented in wxWidgets.

VZ
A: 

You should look at wxShapeFramework (http://sourceforge.net/projects/wxsf/)

wxShapeFramework (wxSF) is a software library/framework based on wxWidgets which allows easy development of software applications manipulating with graphical objects (shapes) like various CASE tools, technological processes modeling tools, etc.

Rui Curado