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

Function draw_hook

src/ui/ui_state.cpp:551–779  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

549}
550
551void draw_hook(plume::RenderCommandList* command_list, plume::RenderFramebuffer* swap_chain_framebuffer) {
552
553 apply_background_input_mode();
554
555 // Return early if the ui context has been destroyed already.
556 if (!ui_state) {
557 return;
558 }
559
560 // Return to the launcher if no menu is open and the game isn't started.
561 if (!recompui::is_any_context_shown() && !ultramodern::is_game_started()) {
562 recompui::show_context(recompui::get_launcher_context_id(), "");
563 }
564
565 std::lock_guard lock{ ui_state_mutex };
566
567 SDL_Event cur_event{};
568
569 bool mouse_moved = false;
570 bool mouse_clicked = false;
571 bool non_mouse_interacted = false;
572 bool cont_interacted = false;
573 bool kb_interacted = false;
574
575 bool config_was_open = recompui::is_context_shown(recompui::get_config_context_id()) || recompui::is_context_shown(recompui::get_config_sub_menu_context_id());
576
577 using clock = std::chrono::system_clock;
578
579 // TODO move these into a more appropriate place.
580 constexpr clock::duration start_repeat_delay = std::chrono::milliseconds{500};
581 constexpr clock::duration repeat_rate = std::chrono::milliseconds{50};
582 static clock::time_point next_repeat_time = {};
583 static int latest_controller_key_pressed = SDLK_UNKNOWN;
584
585 while (recompui::try_deque_event(cur_event)) {
586 bool context_capturing_input = recompui::is_context_capturing_input();
587 bool context_capturing_mouse = recompui::is_context_capturing_mouse();
588
589 // Handle up button events even when input is disabled to avoid missing them during binding.
590 if (cur_event.type == SDL_EventType::SDL_CONTROLLERBUTTONUP) {
591 int sdl_key = cont_button_to_key(cur_event.cbutton);
592 if (sdl_key == latest_controller_key_pressed) {
593 latest_controller_key_pressed = SDLK_UNKNOWN;
594 }
595 }
596
597 if (!recomp::all_input_disabled()) {
598 bool is_mouse_input = false;
599 // Implement some additional behavior for specific events on top of what RmlUi normally does with them.
600 switch (cur_event.type) {
601 case SDL_EventType::SDL_MOUSEMOTION: {
602 int *last_mouse_pos = ui_state->last_active_mouse_position;
603
604 if (!ui_state->mouse_is_active) {
605 float xD = cur_event.motion.x - last_mouse_pos[0];
606 float yD = cur_event.motion.y - last_mouse_pos[1];
607 if (sqrt(xD * xD + yD * yD) < 100) {
608 break;

Callers

nothing calls this directly

Calls 10

cont_button_to_keyFunction · 0.85
cont_axis_to_keyFunction · 0.85
update_primary_inputMethod · 0.80
update_focusMethod · 0.80
update_contextsMethod · 0.80
UpdateMethod · 0.80
startMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected