Page 1 of 1

Array of Array of wxPoints

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

Posted: Sun Aug 14, 2005 8:54 am
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);

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

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

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

Posted: Mon Aug 15, 2005 12:18 pm
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).

Posted: Mon Aug 15, 2005 10:16 pm
by ionstream
Alright, its fixed, the problem was that I was adding pointers to the array, and not just objects. Thanks!