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 » Sun Aug 14, 2005 4:33 am

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
Moderator
Moderator
Posts: 536
Joined: Fri Jan 07, 2005 3:44 pm
Location: Finland
Contact:

Post by vdell » Sun Aug 14, 2005 8:54 am

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 » Sun Aug 14, 2005 6:06 pm

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 » Mon Aug 15, 2005 1:58 am

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 » Mon Aug 15, 2005 11:53 am

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
Moderator
Moderator
Posts: 536
Joined: Fri Jan 07, 2005 3:44 pm
Location: Finland
Contact:

Post by vdell » Mon Aug 15, 2005 12:18 pm

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 » Mon Aug 15, 2005 10:16 pm

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

Post Reply