MCPcopy Create free account
hub / github.com/RevoSucks/BM64Recomp / mod_dragged

Method mod_dragged

src/ui/ui_mod_menu.cpp:350–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

348}
349
350void ModMenu::mod_dragged(uint32_t mod_index, EventDrag drag) {
351 constexpr float spacer_height = modEntryHeight + modEntryPadding * 2.0f;
352
353 switch (drag.phase) {
354 case DragPhase::Start: {
355 for (size_t i = 0; i < mod_entry_buttons.size(); i++) {
356 mod_entry_middles[i] = mod_entry_buttons[i]->get_absolute_top() + mod_entry_buttons[i]->get_client_height() / 2.0f;
357 }
358
359 // When the drag phase starts, we make the floating mod details visible and store the relative coordinate of the
360 // mouse cursor. Instantly hide the real element and use a spacer in its place that will stay on the same size as
361 // long as the cursor is hovering over this slot.
362 float width = mod_entry_buttons[mod_index]->get_client_width();
363 float height = mod_entry_buttons[mod_index]->get_client_height();
364 float left = mod_entry_buttons[mod_index]->get_absolute_left() - get_absolute_left();
365 float top = mod_entry_buttons[mod_index]->get_absolute_top() - (height / 2.0f); // TODO: Figure out why this adjustment is even necessary.
366 mod_entry_buttons[mod_index]->set_display(Display::None);
367 mod_entry_buttons[mod_index]->set_focused(false);
368 mod_entry_floating_view->set_display(Display::Flex);
369 mod_entry_floating_view->set_mod_details(mod_details[mod_index]);
370 mod_entry_floating_view->set_mod_thumbnail(generate_thumbnail_src_for_mod(mod_details[mod_index].mod_id));
371 mod_entry_floating_view->set_mod_enabled(is_mod_enabled_or_auto(mod_details[mod_index].mod_id));
372 mod_entry_floating_view->set_left(left, Unit::Px);
373 mod_entry_floating_view->set_top(top, Unit::Px);
374 mod_entry_floating_view->set_width(width, Unit::Px);
375 mod_entry_floating_view->set_height(height, Unit::Px);
376 mod_drag_start_coordinates[0] = drag.x;
377 mod_drag_start_coordinates[1] = drag.y;
378 mod_drag_view_coordinates[0] = left;
379 mod_drag_view_coordinates[1] = top;
380
381 mod_drag_target_index = mod_index;
382 mod_entry_spacers[mod_drag_target_index]->set_target_height(spacer_height, false);
383 break;
384 }
385 case DragPhase::Move: {
386 // Binary search for the drag area.
387 uint32_t low = 0;
388 uint32_t high = mod_entry_buttons.size();
389 while (low < high) {
390 uint32_t mid = low + (high - low) / 2;
391 if (drag.y < mod_entry_middles[mid]) {
392 high = mid;
393 }
394 else {
395 low = mid + 1;
396 }
397 }
398
399 uint32_t new_index = low;
400 float delta_x = drag.x - mod_drag_start_coordinates[0];
401 float delta_y = drag.y - mod_drag_start_coordinates[1];
402 mod_entry_floating_view->set_left(mod_drag_view_coordinates[0] + delta_x, Unit::Px);
403 mod_entry_floating_view->set_top(mod_drag_view_coordinates[1] + delta_y, Unit::Px);
404 if (mod_drag_target_index != new_index) {
405 mod_entry_spacers[mod_drag_target_index]->set_target_height(0.0f, true);
406 mod_entry_spacers[new_index]->set_target_height(spacer_height, true);
407 mod_drag_target_index = new_index;

Callers

nothing calls this directly

Calls 15

is_mod_enabled_or_autoFunction · 0.85
get_absolute_topMethod · 0.80
get_client_heightMethod · 0.80
get_client_widthMethod · 0.80
get_absolute_leftMethod · 0.80
set_focusedMethod · 0.80
set_mod_thumbnailMethod · 0.80
set_mod_enabledMethod · 0.80
set_leftMethod · 0.80
set_topMethod · 0.80
set_widthMethod · 0.80

Tested by

no test coverage detected