| 166 | |
| 167 | |
| 168 | int Identify::ObjectsInRectangle(const Box &rectangle, id_list &list) |
| 169 | // ---------------------------------------------------------------------------- |
| 170 | // Return the list of objects under the rectangle |
| 171 | // ---------------------------------------------------------------------------- |
| 172 | { |
| 173 | int hits = 0; |
| 174 | GLuint selected = 0; |
| 175 | GLuint capacity = widget->selectionCapacity(); |
| 176 | |
| 177 | // Create the select buffer and switch to select mode |
| 178 | GLuint *buffer = new GLuint[capacity]; |
| 179 | memset(buffer, 0, capacity * sizeof(GLuint)); |
| 180 | GL.SelectBuffer(capacity, buffer); |
| 181 | GL.RenderMode(GL_SELECT); |
| 182 | |
| 183 | // Adjust viewport for rendering |
| 184 | widget->setup(widget->width(), widget->height(), &rectangle); |
| 185 | |
| 186 | // Initialize names |
| 187 | GL.InitNames(); |
| 188 | |
| 189 | // Draw the items in "Identity" mode (simplified drawing) |
| 190 | widget->identifySelection(); |
| 191 | |
| 192 | // Get number of hits and extract selection |
| 193 | // Each record is as follows: |
| 194 | // [0]: Depth of the name stack |
| 195 | // [1]: Minimum depth |
| 196 | // [2]: Maximum depth |
| 197 | // [3..3+[0]-1]: List of names |
| 198 | hits = GL.RenderMode(GL_RENDER); |
| 199 | if (hits > 0) |
| 200 | { |
| 201 | GLuint *ptr = buffer; |
| 202 | for (int i = 0; i < hits; i++) |
| 203 | { |
| 204 | // With a drag rectangle, we only select the top item in a |
| 205 | // hierarchy. For example, in a group, we only select the top group |
| 206 | uint size = ptr[0]; |
| 207 | selected = ptr[3]; |
| 208 | if (selected & Widget::SELECTION_MASK) |
| 209 | list.push_back(selected); |
| 210 | ptr += 3 + size; |
| 211 | } |
| 212 | } |
| 213 | delete[] buffer; |
| 214 | |
| 215 | if (hits < 0) |
| 216 | std::cout << "Capacity is incorrectly computed\n"; |
| 217 | |
| 218 | return hits; |
| 219 | } |
| 220 | |
| 221 | |
| 222 | // ============================================================================ |
nothing calls this directly
no test coverage detected