diff options
author | FeralChild64 <unknown> | 2022-11-03 02:03:25 +0300 |
---|---|---|
committer | kcgen <1557255+kcgen@users.noreply.github.com> | 2022-11-04 06:11:22 +0300 |
commit | 7c14affc646665d1907ce32b334a15f8c384e818 (patch) | |
tree | 688c0b1008fcb0c8e10bc1793969fb2d6f82ea83 | |
parent | d1d8f515df0ca0bfbc031cfdc2853bb2daf83aa9 (diff) |
Add mouse related hints to title bar
-rw-r--r-- | include/sdlmain.h | 6 | ||||
-rw-r--r-- | include/video.h | 13 | ||||
-rw-r--r-- | src/dos/program_mousectl.cpp | 2 | ||||
-rw-r--r-- | src/gui/sdlmain.cpp | 118 | ||||
-rw-r--r-- | src/hardware/mouse/mouse.cpp | 25 |
5 files changed, 147 insertions, 17 deletions
diff --git a/include/sdlmain.h b/include/sdlmain.h index 5dbc4e4be..05c70eeaf 100644 --- a/include/sdlmain.h +++ b/include/sdlmain.h @@ -165,6 +165,12 @@ struct SDL_Block { SCREEN_TYPES want_type = SCREEN_SURFACE; } desktop = {}; struct { + int num_cycles = 0; + std::string hint_mouse_str = {}; + std::string hint_paused_str = {}; + std::string cycles_ms_str = {}; + } title_bar = {}; + struct { VsyncPreference when_windowed = {}; VsyncPreference when_fullscreen = {}; VSYNC_STATE current = VSYNC_STATE::ON; diff --git a/include/video.h b/include/video.h index 1b3b741dd..77539600e 100644 --- a/include/video.h +++ b/include/video.h @@ -82,6 +82,19 @@ void GFX_GetSize(int &width, int &height, bool &fullscreen); void GFX_LosingFocus(); void GFX_RegenerateWindow(Section *sec); +enum class MouseHint { + None, // no hint to display + NoMouse, // no mouse mode + CapturedHotkey, // mouse captured, use hotkey to release + CapturedHotkeyMiddle, // mouse captured, use hotkey or middle-click to release + ReleasedHotkey, // mouse released, use hotkey to capture + ReleasedHotkeyMiddle, // mouse released, use hotkey or middle-click to capture + ReleasedHotkeyAnyButton, // mouse released, use hotkey or any click to capture + SeamlessHotkey, // seamless mouse, use hotkey to capture + SeamlessHotkeyMiddle, // seamless mouse, use hotkey or middle-click to capture +}; + +void GFX_SetMouseHint(const MouseHint requested_hint_id); void GFX_SetMouseCapture(const bool requested_capture); void GFX_SetMouseVisibility(const bool requested_visible); void GFX_SetMouseRawInput(const bool requested_raw_input); diff --git a/src/dos/program_mousectl.cpp b/src/dos/program_mousectl.cpp index 66f90611f..ad0159c1e 100644 --- a/src/dos/program_mousectl.cpp +++ b/src/dos/program_mousectl.cpp @@ -550,7 +550,7 @@ void MOUSECTL::AddMessages() "Wrong syntax, sampling rate has to be one of:\n%s"); MSG_Add("SHELL_CMD_MOUSECTL_MAPPING_NO_MOUSE", - "Mapping not available in NoMouse mode."); + "Mapping not available in no-mouse mode."); MSG_Add("SHELL_CMD_MOUSECTL_NO_INTERFACES", "No mouse interfaces available."); MSG_Add("SHELL_CMD_MOUSECTL_MISSING_INTERFACES", "Mouse interface not available."); diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 4eb0d7e94..10a38bfaa 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -315,26 +315,39 @@ extern bool CPU_CycleAutoAdjust; bool startup_state_numlock=false; bool startup_state_capslock=false; -void GFX_SetTitle(int32_t cycles, int /*frameskip*/, bool paused) +void GFX_SetTitle(int32_t new_num_cycles, int /*frameskip*/, bool is_paused) { - char title[200] = {0}; + char title_buf[200] = {0}; #if !defined(NDEBUG) - const char* build_type = " (debug build)"; + #define APP_NAME_STR "DOSBox Staging (debug build)" #else - const char* build_type = ""; + #define APP_NAME_STR "DOSBox Staging" #endif - static int32_t internal_cycles = 0; - if (cycles != -1) - internal_cycles = cycles; + auto &num_cycles = sdl.title_bar.num_cycles; + auto &cycles_ms_str = sdl.title_bar.cycles_ms_str; + auto &hint_mouse_str = sdl.title_bar.hint_mouse_str; + auto &hint_paused_str = sdl.title_bar.hint_paused_str; - const char *msg = CPU_CycleAutoAdjust - ? "%8s - max %d%% - DOSBox Staging%s%s" - : "%8s - %d cycles/ms - DOSBox Staging%s%s"; - safe_sprintf(title, msg, RunningProgram, internal_cycles, build_type, - paused ? " (PAUSED)" : ""); - SDL_SetWindowTitle(sdl.window, title); + if (new_num_cycles != -1) + num_cycles = new_num_cycles; + + if (cycles_ms_str.empty()) { + cycles_ms_str = MSG_GetRaw("TITLEBAR_CYCLES_MS"); + hint_paused_str = std::string(" ") + MSG_GetRaw("TITLEBAR_HINT_PAUSED"); + } + + if (CPU_CycleAutoAdjust) + safe_sprintf(title_buf, "%8s - max %d%% - " APP_NAME_STR "%s", + RunningProgram, num_cycles, + is_paused ? hint_paused_str.c_str() : hint_mouse_str.c_str()); + else + safe_sprintf(title_buf, "%8s - %d %s - " APP_NAME_STR "%s", + RunningProgram, num_cycles, cycles_ms_str.c_str(), + is_paused ? hint_paused_str.c_str() : hint_mouse_str.c_str()); + + SDL_SetWindowTitle(sdl.window, title_buf); } static double get_host_refresh_rate() @@ -2167,6 +2180,57 @@ void GFX_SetShader([[maybe_unused]] const std::string &source) #endif } +void GFX_SetMouseHint(const MouseHint hint_id) +{ + static const std::string prexix = " - "; + + auto create_hint_str = [](const char *requested_name) { + char hint_buffer[200] = {0}; + + safe_sprintf(hint_buffer, + MSG_GetRaw(requested_name), + PRIMARY_MOD_NAME); + return prexix + hint_buffer; + }; + + auto &hint_str = sdl.title_bar.hint_mouse_str; + switch (hint_id) { + case MouseHint::None: + hint_str.clear(); + break; + case MouseHint::NoMouse: + hint_str = prexix + MSG_GetRaw("TITLEBAR_HINT_NOMOUSE"); + break; + case MouseHint::CapturedHotkey: + hint_str = create_hint_str("TITLEBAR_HINT_CAPTURED_HOTKEY"); + break; + case MouseHint::CapturedHotkeyMiddle: + hint_str = create_hint_str("TITLEBAR_HINT_CAPTURED_HOTKEY_MIDDLE"); + break; + case MouseHint::ReleasedHotkey: + hint_str = create_hint_str("TITLEBAR_HINT_RELEASED_HOTKEY"); + break; + case MouseHint::ReleasedHotkeyMiddle: + hint_str = create_hint_str("TITLEBAR_HINT_RELEASED_HOTKEY_MIDDLE"); + break; + case MouseHint::ReleasedHotkeyAnyButton: + hint_str = create_hint_str("TITLEBAR_HINT_RELEASED_HOTKEY_ANY_BUTTON"); + break; + case MouseHint::SeamlessHotkey: + hint_str = create_hint_str("TITLEBAR_HINT_SEAMLESS_HOTKEY"); + break; + case MouseHint::SeamlessHotkeyMiddle: + hint_str = create_hint_str("TITLEBAR_HINT_SEAMLESS_HOTKEY_MIDDLE"); + break; + default: + assert(false); + hint_str.clear(); + break; + } + + GFX_SetTitle(-1, -1, false); +} + void GFX_SetMouseRawInput(const bool requested_raw_input) { if (SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, @@ -4003,8 +4067,29 @@ static std::vector<std::string> Get_SDL_TextureRenderers() return drivers; } -void Config_Add_SDL() { - Section_prop * sdl_sec=control->AddSection_prop("sdl",&GUI_StartUp); +static void messages_add_sdl() +{ + MSG_Add("TITLEBAR_CYCLES_MS", "cycles/ms"); + MSG_Add("TITLEBAR_HINT_PAUSED", "(PAUSED)"); + MSG_Add("TITLEBAR_HINT_NOMOUSE", "no-mouse mode"); + MSG_Add("TITLEBAR_HINT_CAPTURED_HOTKEY", + "mouse captured, %s+F10 to release"); + MSG_Add("TITLEBAR_HINT_CAPTURED_HOTKEY_MIDDLE", + "mouse captured, %s+F10 or middle-click to release"); + MSG_Add("TITLEBAR_HINT_RELEASED_HOTKEY", + "to capture the mouse press %s+F10"); + MSG_Add("TITLEBAR_HINT_RELEASED_HOTKEY_MIDDLE", + "to capture the mouse press %s+F10 or middle-click"); + MSG_Add("TITLEBAR_HINT_RELEASED_HOTKEY_ANY_BUTTON", + "to capture the mouse press %s+F10 or click any button"); + MSG_Add("TITLEBAR_HINT_SEAMLESS_HOTKEY", + "seamless mouse, %s+F10 to capture"); + MSG_Add("TITLEBAR_HINT_SEAMLESS_HOTKEY_MIDDLE", + "seamless mouse, %s+F10 or middle-click to capture"); +} + +void config_add_sdl() { + Section_prop *sdl_sec=control->AddSection_prop("sdl", &GUI_StartUp); sdl_sec->AddInitFunction(&MAPPER_StartUp); Prop_bool *Pbool; // use pbool for new properties Prop_bool *pbool; @@ -4416,7 +4501,8 @@ int sdl_main(int argc, char *argv[]) CROSS_DetermineConfigPaths(); /* Init the configuration system and add default values */ - Config_Add_SDL(); + messages_add_sdl(); + config_add_sdl(); DOSBOX_Init(); if (control->cmdline->FindExist("--editconf") || diff --git a/src/hardware/mouse/mouse.cpp b/src/hardware/mouse/mouse.cpp index 891c7a194..ee249f2ba 100644 --- a/src/hardware/mouse/mouse.cpp +++ b/src/hardware/mouse/mouse.cpp @@ -70,6 +70,8 @@ static struct { bool should_release_on_middle = false; // if middle button press should release the mouse bool should_toggle_on_hotkey = false; // if hotkey should toggle mouse capture + MouseHint hint_id = MouseHint::None; // hint to be displayed on title bar + } state; static void update_cursor_absolute_position(const int32_t x_abs, const int32_t y_abs) @@ -182,6 +184,7 @@ static void update_state() // updates whole 'state' structure, except cursor vis // Store internally old settings, to avoid unnecessary GFX calls const auto old_is_captured = state.is_captured; const auto old_is_input_raw = state.is_input_raw; + const auto old_hint_id = state.hint_id; // Raw input depends on the user configuration state.is_input_raw = mouse_config.raw_input; @@ -261,11 +264,33 @@ static void update_state() // updates whole 'state' structure, except cursor vis state.is_captured && mouse_config.middle_release; + // Select hint to be displayed on a title bar + if (state.is_fullscreen || state.gui_has_taken_over || !state.has_focus) + state.hint_id = MouseHint::None; + else if (is_config_no_mouse) + state.hint_id = MouseHint::NoMouse; + else if (state.is_captured && state.should_release_on_middle) + state.hint_id = MouseHint::CapturedHotkeyMiddle; + else if (state.is_captured) + state.hint_id = MouseHint::CapturedHotkey; + else if (state.should_capture_on_click) + state.hint_id = MouseHint::ReleasedHotkeyAnyButton; + else if (state.should_capture_on_middle) + state.hint_id = state.is_seamless + ? MouseHint::SeamlessHotkeyMiddle + : MouseHint::ReleasedHotkeyMiddle; + else + state.hint_id = state.is_seamless + ? MouseHint::SeamlessHotkey + : MouseHint::ReleasedHotkey; + // Apply calculated settings if changed or if this is the first run if (first_time || old_is_captured != state.is_captured) GFX_SetMouseCapture(state.is_captured); if (first_time || old_is_input_raw != state.is_input_raw) GFX_SetMouseRawInput(state.is_input_raw); + if (first_time || old_hint_id != state.hint_id) + GFX_SetMouseHint(state.hint_id); for (auto &interface : mouse_interfaces) interface->UpdateInputType(); |