Selection renderers are special Heidi renderers for selecting geometry in 2D or 3D. They can be used for determining the exact items that were selected from the draw and for hit testing; for example, when a user is selecting geometry, closest to the cursor on the screen, to be translated or moved to a new location.
There are currently five variations:
For example, to set up the area selection renderer, the application should perform the following steps:
HT_Create_Selector generator = (HT_Create_Selector) HD_Load_Dynamic_Routine ("selarea7.hdi", "HD_Selector");
m_selector = generator ();
m_selector.set_configure ("Selection Area", HT_Option_Value (50, 250, 50, 250));
m_selector.establish ();The Selection Process
For example, the following
code fragment initializes the selection renderer by issuing a begin_picture
and sends a DC polygon to the selection renderer. The selection process
is finished by issuing an update
and an end_picture. The
selection information is retrieved by calling show_selection_count
which returns the number of primitives that have been selected. If
the count comes back >
0, then the application
iterates through the HT_Selector_Item
list via show_next_selection_item().
stack HT_DC_Point sprite[4];
sprite[0] = HT_DC_Point ((float)right, (float)top, m_sprite_depth) sprite[1] = HT_DC_Point ((float)left, (float)top, m_sprite_depth); sprite[2] = HT_DC_Point ((float)left, (float)bottom, m_sprite_depth); sprite[3] = HT_DC_Point ((float)right, (float)bottom, m_sprite_depth); m_selector.begin_picture (); m_selector.draw_dc_polygon (rendition, 4, sprite); m_selector.update (); m_selector.end_picture (); m_selected = m_selector.show_selection_count();
stack HT_Selection_Item selector_item; stack long my_key; stack int my_sequnece; stack float my_distance;
for (I = 0; I < m_selected; I++) {
if (!m_selector. show_next_selection_item (&selection_item)
break;
my_key = selector_item.key();
my_sequence = selector_item.sequence();
my_distance = selector_item.distance();
}
HT_Selector
Besides the app-defined
key, you can also get the sequence number ¾
a
count of how many draw_...
calls you've made with the current key. HT_Selector_Item
also provides information for the distance
between the selection area and the drawables. The selected items
are sorted by the distance from near to far.
The selection class now enables you to set a specific key to be selected as opposed to just any hit. When you draw something, you can determine if it was selected, since in most cases, the key can identify the pointer to the object. For example, you could determine which 3 particular items were actually selected from a draw that was stored in a data base ¾ such as polygons number 35, 36 and 37.
Selection also allows multiple keys to be assigned and a combined selection renderer is available. For example, the selection renderer could include a window, nearest and perpendicular for applications such as AutoCAD.
For a detailed description, see class HT_Selector,
in Appendix A, "Heidi Class Reference."
The default setting is one, in which case any line weight larger than one will be broken down into triangles and go through a slower yet more accurate selection path.