473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

I need a container to hold grid positions and the objects on the grid?


I'm creating a GUI which is a bitmap with active areas, so when I paint
the dialog I calculate the rectangles containing objects.

When I get a click event, I want to know which (if any) rectangle
encompasses the click (so I know which object is clicked).

In the past I've created a vector of rectangles and gone though them
one by one testing for PointInRect or whatever but I reckon this is a
bit clunky, and I'm up to 100 or so objects on a screen.

So RECT is my reference to an object
POINT is what I need to test to get an object.

Any thoughts on what sort of collection could do this neatly for me?

Thanks.

Mar 31 '06 #1
3 1499
Simon L wrote:
I'm creating a GUI which is a bitmap with active areas, so when I paint
the dialog I calculate the rectangles containing objects.

When I get a click event, I want to know which (if any) rectangle
encompasses the click (so I know which object is clicked).

In the past I've created a vector of rectangles and gone though them
one by one testing for PointInRect or whatever but I reckon this is a
bit clunky, and I'm up to 100 or so objects on a screen.

So RECT is my reference to an object
POINT is what I need to test to get an object.

Any thoughts on what sort of collection could do this neatly for me?

Thanks.


You might have to build your own depending on how you use it, but you
might be able to get by with a std::set<RECT> if you create a dummy
point-sized RECT for the lookup and a custom comparison functor for
RECTs. Search time should be O(log N).

Cheers! --M

Mar 31 '06 #2
Simon L wrote:
I'm creating a GUI which is a bitmap with active areas, so when I paint
the dialog I calculate the rectangles containing objects.

When I get a click event, I want to know which (if any) rectangle
encompasses the click (so I know which object is clicked).

In the past I've created a vector of rectangles and gone though them
one by one testing for PointInRect or whatever but I reckon this is a
bit clunky, and I'm up to 100 or so objects on a screen.

So RECT is my reference to an object
POINT is what I need to test to get an object.

Any thoughts on what sort of collection could do this neatly for me?


Sounds to me like you require some kind of hierarchical representation,
which is probably implicit in the structure of the GUI.

You ask the parent if the point is inside of it's RECT, if not, nothing
has been clicked, if so, you ask the first child, if so, you ask it's
children, if not you ask the next child etc.

Sounds like a simple tree traversal to me, and it sounds like your RECTs
are implicitly defined by each window object.

If you create a vector of RECTs, you lose the hierarchical nature (Z
dimension), many rectangles may match a point, you want the "closest"
one. You also have to manage the vector whenever a window is added or
removed, sounds like a good source of trouble.

I suggest most of this information is already available in the structure
of the GUI elements, and a simple traversal is required.

Correct me if I'm wrong.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Mar 31 '06 #3
Simon L wrote:
I'm creating a GUI which is a bitmap with active areas, so when I
paint the dialog I calculate the rectangles containing objects.

When I get a click event, I want to know which (if any) rectangle
encompasses the click (so I know which object is clicked).

In the past I've created a vector of rectangles and gone though them
one by one testing for PointInRect or whatever but I reckon this is a
bit clunky, and I'm up to 100 or so objects on a screen.


100 is not that many items to deal with. If this is purely a performance
concern have you measured to see if this is a bottleneck?

Your subject line specifies "grid" while your description here makes no
mention that your "rectangles" are layed out in a grid. If in fact you do
have a grid layout, you could achieve O(rows) + O(cols) by maintaining
sorted vectors of row heights and of col widths, and use upper/lower_bound
to determine row/col indices. Of course if all heights/widths are equal, you
could achieve O(1) complexity by simply calculating the row/col indices. If
you're dealing with 'dense' data use a std::vector< std::vector< ... > >, if
the data is 'sparse' you can use a std::map< key, ... > where key encodes
the indices and provides the necessary strict weak ordering requirments(
possibly use a std::vector<int> of size 2).

Mar 31 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: kk | last post by:
I have 2 issues, please help ! 1st issue : -------------------------------------------------------- Loading Grid ------------ 1) creating new rows in a datatable and adding data a array...
5
by: TheFerryman | last post by:
How bad is it to include a non const accessor to a container of objects? For instance template <class WheelType> class CarBase { typedef std::list<WheelType*> WheelList; private:
0
by: Stephen Horne | last post by:
I've only very recently started with .NET, and need to use some existing container libraries in new code. I'd like to minimise the amount of porting, but of course these containers are not designed...
0
by: Reza Nabi | last post by:
Dear All: Banckgroud: I have a datagrid which lives inside a repeater. Which is working fine. What i need is to dyanamically set the column width of the grid (which lieves inside the repeater)....
18
by: bsruth | last post by:
I tried for an hour to find some reference to concrete information on why this particular inheritance implementation is a bad idea, but couldn't. So I'm sorry if this has been answered before....
4
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
6
by: naknak | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
2
by: jm.suresh | last post by:
Hi, I have containers to hold geometrical objects. The members in these containers can again be containers them self. Now, In the program I would be moving objects from one container to another....
1
by: Doogie | last post by:
Hi, I have been trying to get a checkbox added to a repeater control of mine and then try to access events of the repeater control when a user clicks the checkbox. At first, since the control is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.