Skip to content

Commit

Permalink
Slight refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma-axis committed Jul 13, 2024
1 parent 925aa67 commit 17839f6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
40 changes: 25 additions & 15 deletions reactive_dlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ using namespace ExEdit;
#include "slim_formatter.hpp"
#include "memory_protect.hpp"


////////////////////////////////
// 主要情報源の変数アドレス.
////////////////////////////////
Expand Down Expand Up @@ -863,7 +864,7 @@ struct Easings : SettingDlg {
script_names.shrink_to_fit();
}
}
// built-in script names.
// built-in easing names.
constexpr static std::string_view const basic_track_mode_names[]{
"移動無し",
"直線移動",
Expand Down Expand Up @@ -909,23 +910,31 @@ struct Easings : SettingDlg {
dec = (mode.num & mode.isDecelerate) != 0,
is_scr = basic_idx == mode.isScript;

// name of the easing.
std::string ret{ is_scr ?
script_names[mode.script_idx].name :
basic_track_mode_names[basic_idx] };

// identify its specification, especially whether it accepts a parameter.
easing_spec spec = is_scr ? easing_spec{ exedit.easing_specs_script[mode.script_idx] } :
easing_spec{ exedit.easing_specs_builtin[basic_idx] };
if (!spec.loaded) {
// script wasn't loaded yet. try after loading.
exedit.load_easing_spec(mode.script_idx, 0, 0);
spec = { exedit.easing_specs_script[mode.script_idx] };
}

// integral parameter.
if (spec.param)
ret += "\nパラメタ: " + std::to_string(param);

// two more booleans.
if (acc || dec) {
if (spec.param) ret += ", ";
else ret += "\n";
ret += spec.param ? ", " : "\n";
if (acc) ret += "+加速 ";
if (dec) ret += "+減速 ";
ret.pop_back();
}
if (acc) ret += "+加速 ";
if (dec) ret += "+減速 ";

return ret;
}
Expand Down Expand Up @@ -1006,19 +1015,20 @@ struct Easings : SettingDlg {
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

// associate the tooltip with each trackbar button.
TTTOOLINFOA ti{
.cbSize = sizeof(ti),
.uFlags = TTF_IDISHWND | TTF_TRANSPARENT,
.hinst = exedit.fp->hinst_parent,
.lpszText = LPSTR_TEXTCALLBACKA,
};
for (size_t i = 0; i < ExEdit::Object::MAX_TRACK; i++) {
HWND tgt = exedit.hwnd_track_buttons[i];

ti.hwnd = tgt;
ti.uId = reinterpret_cast<uintptr_t>(tgt);

// note that the only A-variant can successfully register
// if dark-mode isn't applied.
TTTOOLINFOA ti{
.cbSize = sizeof(ti),
.uFlags = TTF_IDISHWND | TTF_TRANSPARENT,
.hwnd = tgt,
.uId = reinterpret_cast<uintptr_t>(tgt),
.hinst = exedit.fp->hinst_parent,
.lpszText = LPSTR_TEXTCALLBACKA,
};
// if dark-mode isn't applied (i.e. TTM_ADDTOOLW would fail otherwise).
::SendMessageW(tooltip, TTM_ADDTOOLA, 0, reinterpret_cast<LPARAM>(&ti));
}

Expand Down Expand Up @@ -2027,7 +2037,7 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID lpvReserved)
// 看板.
////////////////////////////////
#define PLUGIN_NAME "Reactive Dialog"
#define PLUGIN_VERSION "v1.51-test2"
#define PLUGIN_VERSION "v1.60-beta3"
#define PLUGIN_AUTHOR "sigma-axis"
#define PLUGIN_INFO_FMT(name, ver, author) (name##" "##ver##" by "##author)
#define PLUGIN_INFO PLUGIN_INFO_FMT(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
Expand Down
22 changes: 16 additions & 6 deletions slim_formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,23 @@ class slim_formatter {
public:
constexpr std::wstring operator()(std::wstring const& name) const
{
std::wstring ret = base; // copy.
ret.reserve(ret.size() + name.size() * holes.size());
std::wstring ret(base.size() + name.size() * holes.size(), L'\0');

// alternatingly copy to `ret` the strings `base` and `name`.
size_t l = 0; auto p = ret.data();
for (auto i : holes) {
base.copy(p, i - l, l);
p += i - l;

name.copy(p, name.size());
p += name.size();

l = i;
}

// and the final tail part.
base.copy(p, base.size() - l, l);

// insert the name into the 'holes'.
for (auto i : holes) ret.insert(i, name);
ret.shrink_to_fit();
return ret;
}
constexpr std::wstring operator()(char const* name) const { return (*this)(Encodes::to_wstring<CP_ACP>(name)); }
Expand Down Expand Up @@ -83,7 +94,6 @@ class slim_formatter {
if (has_hole) holes.emplace_back(i);
}

std::reverse(holes.begin(), holes.end()); // holes are filled in the reversed order.
base.shrink_to_fit();
holes.shrink_to_fit();
}
Expand Down

0 comments on commit 17839f6

Please sign in to comment.