Skip to content

Commit

Permalink
Configurable screenshot behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
andon authored and andon committed Feb 11, 2017
1 parent 6b77546 commit 445588b
Show file tree
Hide file tree
Showing 7 changed files with 493 additions and 34 deletions.
4 changes: 2 additions & 2 deletions include/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#define TBF_MAJOR 0
#define TBF_MINOR 9
#define TBF_BUILD 3
#define TBF_REV 2
#define TBF_BUILD 4
#define TBF_REV 0



Expand Down
30 changes: 28 additions & 2 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@
extern std::wstring TBF_VER_STR;
extern std::wstring DEFAULT_BK2;

struct keybind_s
{
std::wstring human_readable;

struct {
bool ctrl,
shift,
alt;
};

BYTE vKey;

void parse (void);
void update (void);
};

struct tbf_config_t
{
struct {
Expand Down Expand Up @@ -99,10 +115,20 @@ struct tbf_config_t
} input;

struct {
std::wstring swap_keys = L"";
bool swap_wasd = false;
std::wstring swap_keys = L"";
bool swap_wasd = false;

keybind_s hudless { L"Ctrl+Shift+F10", { true, true, false }, VK_F10 },
screenshot { L"F10", { false, false, false }, VK_F10 },
config_menu { L"Ctrl+Shift+Backspace", { true, true, false }, VK_BACK };

} keyboard;

struct {
bool keep = true;
bool import_to_steam = true;
} screenshots;

struct {
std::wstring
version = TBF_VER_STR;
Expand Down
108 changes: 108 additions & 0 deletions src/ImGui/control_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,76 @@ TBFix_GamepadConfigDlg (void)
}
}

DWORD TBFix_Modal = 0UL;

void
TBFix_KeybindDialog (keybind_s* keybind)
{
const float font_size = ImGui::GetFont ()->FontSize * ImGui::GetIO ().FontGlobalScale;
static bool was_open = false;

static BYTE bind_keys [256] = { 0 };

ImGui::SetNextWindowSizeConstraints ( ImVec2 (font_size * 9, font_size * 3), ImVec2 (font_size * 30, font_size * 6));

if (ImGui::BeginPopupModal ("Keyboard Binding", NULL, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_ShowBorders))
{
ImGui::GetIO ().WantCaptureKeyboard = false;

int keys = 256;

if (! was_open)
{
//keybind->vKey = 0;

for (int i = 0 ; i < keys ; i++ ) bind_keys [i] = GetKeyState (i);

was_open = true;
}

BYTE active_keys [256];

for (int i = 0 ; i < keys ; i++ ) active_keys [i] = GetKeyState (i);

if (memcmp (active_keys, bind_keys, keys))
{
int i = 0;

for (i = (VK_MENU + 1); i < keys; i++)
{
if ( i == VK_LCONTROL || i == VK_RCONTROL ||
i == VK_LSHIFT || i == VK_RSHIFT ||
i == VK_LMENU || i == VK_RMENU )
continue;

if ( active_keys [i] != bind_keys [i] )
break;
}

if (i != keys)
{
keybind->vKey = i;
was_open = false;
ImGui::CloseCurrentPopup ();
}

//memcpy (bind_keys, active_keys, keys);
}

keybind->ctrl = GetAsyncKeyState (VK_CONTROL);
keybind->shift = GetAsyncKeyState (VK_SHIFT);
keybind->alt = GetAsyncKeyState (VK_MENU);

keybind->update ();

ImGui::Text ("Binding: %ws", keybind->human_readable.c_str ());

TBFix_Modal = timeGetTime ();

ImGui::EndPopup ();
}
}

#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))

IMGUI_API
Expand Down Expand Up @@ -727,6 +797,44 @@ TBFix_DrawConfigUI (void)
ImGui::TreePop ( );
}

if (ImGui::CollapsingHeader ("Screenshots"))
{
if (ImGui::IsItemHovered ())
{
char szWorkingDir [MAX_PATH];
GetCurrentDirectoryA (MAX_PATH, szWorkingDir);

ImGui::SetTooltip ("Screenshots are stored in '%s\\Screenshots'", szWorkingDir);
}

ImGui::TreePush ("");

ImGui::Text ("No HUD Keybinding: %ws", config.keyboard.hudless.human_readable.c_str ());

if (ImGui::IsItemClicked ()) {
ImGui::OpenPopup ("Keyboard Binding");
}

TBFix_KeybindDialog (&config.keyboard.hudless);

ImGui::Checkbox ("Import Screenshot to Steam", &config.screenshots.import_to_steam);

if (config.screenshots.import_to_steam)
{
ImGui::TreePush ("");
ImGui::Checkbox ("Keep High Quality PNG Screenshot After Import", &config.screenshots.keep);

if (ImGui::IsItemHovered ())
ImGui::SetTooltip ("Screenshots will register in Steam much quicker with this disabled.");

ImGui::TreePop ();
}
else
config.screenshots.keep = true;

ImGui::TreePop ();
}

if (ImGui::CollapsingHeader ("Audio"))
{
ImGui::TreePush ("");
Expand Down
168 changes: 168 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ struct {
tbf::ParameterFloat* ui_scale;
} render;

struct {
tbf::ParameterBool* keep;
tbf::ParameterBool* add_to_steam;
tbf::ParameterStringW* hudless_keybind;
tbf::ParameterStringW* regular_keybind;
} screenshots;

struct {
tbf::ParameterBool* remaster;
tbf::ParameterBool* uncompressed;
Expand Down Expand Up @@ -399,6 +406,41 @@ TBF_LoadConfig (std::wstring name)
L"ImGui.Settings",
L"ShowOSDDisclaimer" );


screenshots.hudless_keybind =
static_cast <tbf::ParameterStringW *>
(g_ParameterFactory.create_parameter <std::wstring> (
L"HUDless Screenshot Keybinding")
);

screenshots.hudless_keybind->register_to_ini (
render_ini,
L"Screenshot.Capture",
L"KeybindNoHUD" );

screenshots.keep =
static_cast <tbf::ParameterBool *>
(g_ParameterFactory.create_parameter <bool> (
L"Keep Original (High Quality) Screenshots")
);

screenshots.keep->register_to_ini (
render_ini,
L"Screenshot.Capture",
L"KeepOriginal" );

screenshots.add_to_steam =
static_cast <tbf::ParameterBool *>
(g_ParameterFactory.create_parameter <bool> (
L"Add Screenshot to Steam Library")
);

screenshots.add_to_steam->register_to_ini (
render_ini,
L"Screenshot.Capture",
L"AddToSteamLibrary" );


framerate.replace_limiter =
static_cast <tbf::ParameterBool *>
(g_ParameterFactory.create_parameter <bool> (
Expand Down Expand Up @@ -545,6 +587,12 @@ TBF_LoadConfig (std::wstring name)
framerate.tolerance->load (config.framerate.tolerance);
//framerate.limit_addr->load (config.framerate.limit_addr);

screenshots.add_to_steam->load (config.screenshots.import_to_steam);
screenshots.keep->load (config.screenshots.keep);
screenshots.hudless_keybind->load (config.keyboard.hudless.human_readable);

config.keyboard.hudless.parse ();

textures.remaster->load (config.textures.remaster);
textures.uncompressed->load (config.textures.uncompressed);
textures.lod_bias->load (config.textures.lod_bias);
Expand Down Expand Up @@ -600,6 +648,12 @@ TBF_SaveConfig (std::wstring name, bool close_config)
input.gamepad.texture_set->store (config.input.gamepad.texture_set);
input.gamepad.virtual_controllers->store (config.input.gamepad.virtual_controllers);

config.keyboard.hudless.update ();

screenshots.add_to_steam->store (config.screenshots.import_to_steam);
screenshots.keep->store (config.screenshots.keep);
screenshots.hudless_keybind->store (config.keyboard.hudless.human_readable);

keyboard.swap_wasd->store (config.keyboard.swap_wasd);
keyboard.swap_keys->store (config.keyboard.swap_keys);

Expand Down Expand Up @@ -663,4 +717,118 @@ TBF_SaveConfig (std::wstring name, bool close_config)
keyboard_ini = nullptr;
}
}
}



#include <unordered_map>

std::unordered_map <std::wstring, BYTE> humanKeyNameToVirtKeyCode;
std::unordered_map <BYTE, std::wstring> virtKeyCodeToHumanKeyName;

#include <queue>

void
keybind_s::update (void)
{
human_readable = L"";

std::wstring key_name = virtKeyCodeToHumanKeyName [vKey];

if (! key_name.length ())
return;

std::queue <std::wstring> words;

if (ctrl)
words.push (L"Ctrl");

if (alt)
words.push (L"Alt");

if (shift)
words.push (L"Shift");

words.push (key_name);

while (! words.empty ())
{
human_readable += words.front ();
words.pop ();

if (! words.empty ())
human_readable += L"+";
}
}

void
keybind_s::parse (void)
{
vKey = 0x00;

static bool init = false;

if (! init)
{
for (int i = 0; i < 0xFF; i++)
{
wchar_t name [32] = { L'\0' };

GetKeyNameText ( (MapVirtualKey (i, MAPVK_VK_TO_VSC) & 0xFF) << 16,
name,
32 );

if (i != VK_CONTROL && i != VK_MENU && i != VK_SHIFT && i != VK_OEM_PLUS && i != VK_OEM_MINUS)
{
humanKeyNameToVirtKeyCode [ name] = (BYTE)i;
virtKeyCodeToHumanKeyName [(BYTE)i] = name;
}
}

humanKeyNameToVirtKeyCode [L"Plus"] = VK_OEM_PLUS;
humanKeyNameToVirtKeyCode [L"Minus"] = VK_OEM_MINUS;
humanKeyNameToVirtKeyCode [L"Ctrl"] = VK_CONTROL;
humanKeyNameToVirtKeyCode [L"Alt"] = VK_MENU;
humanKeyNameToVirtKeyCode [L"Shift"] = VK_SHIFT;

virtKeyCodeToHumanKeyName [VK_CONTROL] = L"Ctrl";
virtKeyCodeToHumanKeyName [VK_MENU] = L"Alt";
virtKeyCodeToHumanKeyName [VK_SHIFT] = L"Shift";
virtKeyCodeToHumanKeyName [VK_OEM_PLUS] = L"Plus";
virtKeyCodeToHumanKeyName [VK_OEM_MINUS] = L"Minus";

init = true;
}

wchar_t wszKeyBind [128] = { L'\0' };

wcsncpy (wszKeyBind, human_readable.c_str (), 128);

wchar_t* wszBuf;
wchar_t* wszTok = std::wcstok (wszKeyBind, L"+", &wszBuf);

ctrl = false;
alt = false;
shift = false;

if (wszTok == nullptr)
{
vKey = humanKeyNameToVirtKeyCode [wszKeyBind];
}

while (wszTok)
{
BYTE vKey_ = humanKeyNameToVirtKeyCode [wszTok];

if (vKey_ == VK_CONTROL)
ctrl = true;
else if (vKey_ == VK_SHIFT)
shift = true;
else if (vKey_ == VK_MENU)
alt = true;
else
vKey = vKey_;

wszTok = std::wcstok (nullptr, L"+", &wszBuf);
}
}
Loading

0 comments on commit 445588b

Please sign in to comment.