Array of Array of wxPoints Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ionstream
Earned a small fee
Earned a small fee
Posts: 23
Joined: Wed Jan 05, 2005 6:49 pm

Array of Array of wxPoints

Post by ionstream »

I'm making a simple drawing application that uses vectors to draw things onto the screen (boy that was a weirdly worded sentence). Anyways, when the user clicks on the drawing space with the brush setting on, I need to:

1: Create a new object that contains the points of the line
2: Create a dynamic array containing all the points on that line
3: Append the new object onto a main array, so I can loop through that array and draw each line.


Does anyone know how I would do this? I don't know how to use wxArrays or wxLists, those macros creating them confuse me. Explanation?

Also, on a side note (but still relating to my program), does anyone know how to draw antialiased lines in wxWidgets?
vdell
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 536
Joined: Fri Jan 07, 2005 3:44 pm
Location: Finland
Contact:

Post by vdell »

In your hpp file:

Code: Select all

WX_DECLARE_OBJARRAY(wxPoint, PointArray);
WX_DECLARE_OBJARRAY(PointArray, PointArrayList);
and at the end of your cpp file:

Code: Select all

#include <wx/arrimpl.cpp>
WX_DEFINE_OBJARRAY(PointArray);
WX_DEFINE_OBJARRAY(PointArrayList);
Visual C++ 9.0 / Windows XP Pro SP3 / wxWidgets 2.9.0 (SVN) | Colligere
ionstream
Earned a small fee
Earned a small fee
Posts: 23
Joined: Wed Jan 05, 2005 6:49 pm

Post by ionstream »

All right, but how would I use that in my program? Do I have to create a new PointArrayList object? And how would I dynamically add some PointArrays to PointArrayList?

Thanks!


EDIT: Nevermind, it turns out that I do need to create a new PointArrayList object, and new PointArrays. I did this by putting "static PointArray *temp = NULL" in my mouse click event handler, and when the mouse button is down, I use "new" to allocate it, and when the mouse is up, I use temp->Clear and temp = NULL.

Thanks, hopefully my software will be finished soon!
ionstream
Earned a small fee
Earned a small fee
Posts: 23
Joined: Wed Jan 05, 2005 6:49 pm

Post by ionstream »

Now I'm having a problem getting PointArrays from the main PointArrayList. I do:

Code: Select all

PointArray p = pointlist.Item(0);
wxPoint point = p.Item(0);
But that crashes as soon as it gets to p.Item(0). Can anyone help?
ssigala
Earned some good credits
Earned some good credits
Posts: 109
Joined: Fri Sep 03, 2004 9:30 am
Location: Brescia, Italy

Post by ssigala »

ionstream wrote:Now I'm having a problem getting PointArrays from the main PointArrayList. I do:

Code: Select all

PointArray p = pointlist.Item(0);
wxPoint point = p.Item(0);
But that crashes as soon as it gets to p.Item(0). Can anyone help?
Have you inserted some items before the .Item(0) call?
Sandro Sigala - Kynosoft, Brescia
vdell
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 536
Joined: Fri Jan 07, 2005 3:44 pm
Location: Finland
Contact:

Post by vdell »

Btw, use an debug build of your app. It will give you an nice assertion message (i.e. the reason of the crash).
Visual C++ 9.0 / Windows XP Pro SP3 / wxWidgets 2.9.0 (SVN) | Colligere
ionstream
Earned a small fee
Earned a small fee
Posts: 23
Joined: Wed Jan 05, 2005 6:49 pm

Post by ionstream »

Alright, its fixed, the problem was that I was adding pointers to the array, and not just objects. Thanks!
Post Reply