MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ListBoxProc

Method ListBoxProc

editor/GrListBox.cpp:289–404  ·  view source on GitHub ↗

draws all the items in the list, or don't draw. invoking DrawItem and uses the list management functions

Source from the content-addressed store, hash-verified

287
288// draws all the items in the list, or don't draw. invoking DrawItem and uses the list management functions
289void CGrListBox::ListBoxProc(bool do_draw) {
290 static bool in_listboxproc = false;
291 grHardwareSurface m_ItemSurf;
292 grHardwareSurface m_ItemSurfSel;
293 RECT box_rect;
294 int left, top, draw_x, draw_y;
295 int box_width, box_height;
296 int num_items, item;
297
298 // don't draw if editor is in background.
299 if (in_listboxproc)
300 return;
301 in_listboxproc = true;
302 if (!Editor_active)
303 do_draw = false;
304
305 // initialize graphic objects
306 CWnd::GetClientRect(&box_rect);
307 box_height = box_rect.bottom - box_rect.top;
308 box_width = box_rect.right - box_rect.left;
309
310 if (do_draw) {
311 Desktop_surf->attach_to_window((unsigned)CWnd::m_hWnd);
312 Desktop_surf->clear(0, 0, box_width, box_height);
313 m_ItemSurf.create(m_SurfDimension, m_SurfDimension, BPP_16);
314 m_ItemSurfSel.create(m_SurfDimension + 8, m_SurfDimension + 8, BPP_16);
315 }
316
317 // initialize list manager.
318 items_per_row = box_width / (m_SurfDimension + 8);
319 items_max_row = box_height / (m_SurfDimension + 8);
320 m_ListLen = this->ListEnumerate();
321 m_ListItem = (m_ListItem / items_per_row) * items_per_row; // align rows correctly
322 m_ListItem = this->ListFirstItem(m_ListItem);
323
324 // start drawing items in list box.
325 left = (box_width / 2) - (items_per_row * (m_SurfDimension + 8)) / 2;
326 top = (box_height / 2) - (items_max_row * (m_SurfDimension + 8)) / 2;
327 num_items = 0;
328 item = m_ListItem;
329 m_IsItemSelInBox = false; // this will turn true during the drawing loop
330
331 // drawing and item selection check all purpose loop
332 // if our start list function returned a -1, this means that there are no list items to draw!
333 // also stop if we've exceeded the number of items that can exist in the limited box of visible
334 // space.
335 while ((m_ListItem > -1) && (num_items < (items_per_row * items_max_row))) {
336 int previtem;
337
338 // draw at draw_x, draw_y. go to next item in list and check if we are at end of list.
339 draw_x = left + ((num_items % items_per_row) * (m_SurfDimension + 8));
340 draw_y = top + ((num_items / items_per_row) * (m_SurfDimension + 8));
341
342 previtem = item;
343
344 if (m_CheckHit)
345 if (m_HitX >= draw_x && m_HitX <= (draw_x + m_SurfDimension + 8) && m_HitY >= draw_y &&
346 m_HitY <= (draw_y + m_SurfDimension + 8)) {

Callers

nothing calls this directly

Calls 15

attach_to_windowMethod · 0.80
ListEnumerateMethod · 0.80
ListFirstItemMethod · 0.80
rectMethod · 0.80
get_parentMethod · 0.80
ListNextItemMethod · 0.80
GR_RGBFunction · 0.50
clearMethod · 0.45
createMethod · 0.45
lockMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected