Skip to content

Commit

Permalink
Fixed encoding of some default settings.
Browse files Browse the repository at this point in the history
+ Slight fixes to comments / variable names.
  • Loading branch information
sigma-axis committed Jul 21, 2024
1 parent 0330ad5 commit cb7ff87
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
41 changes: 20 additions & 21 deletions reactive_dlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ struct DropdownList : SettingDlg {


////////////////////////////////
// アニメーション効果の名前表示
// フィルタ効果のスクリプト名表示
////////////////////////////////
struct FilterName : SettingDlg {
private:
Expand Down Expand Up @@ -1000,12 +1000,6 @@ struct Easings : SettingDlg {
flag_loaded = 1 << 7;
};

// to store buffer for the tooltip text.
#ifndef _DEBUG
constinit // somehow it causes an error for debug build.
#endif
static inline std::string curr_tooltip_text{};

// formatting the tooltip text according to the track mode.
static std::string format_tooltip(ExEdit::Object::TrackMode const& mode, int32_t param)
{
Expand Down Expand Up @@ -1078,6 +1072,11 @@ struct Easings : SettingDlg {
auto const& mode = obj.track_mode[idx];
if (mode.num == 0) break; // 移動無し

#ifndef _DEBUG
constinit // somehow it causes an error for debug build.
#endif
static std::string curr_tooltip_text{};

// store the string and return it.
curr_tooltip_text = format_tooltip(mode, obj.track_param[idx]);
reinterpret_cast<NMTTDISPINFOA*>(lparam)->lpszText = curr_tooltip_text.data();
Expand Down Expand Up @@ -1289,19 +1288,19 @@ inline constinit struct Settings {

void load(const char* ini_file)
{
auto read_raw = [&](auto def, const char* section, const char* key) {
auto read_raw = [&](auto def, char const* section, char const* key) {
return static_cast<decltype(def)>(
::GetPrivateProfileIntA(section, key, static_cast<int32_t>(def), ini_file));
};
auto read_modkey = [&](modkeys def, const char* section, const char* key) {
auto read_modkey = [&](modkeys def, char const* section, char const* key) {
char str[std::bit_ceil(std::size("ctrl + shift + alt ****"))];
::GetPrivateProfileStringA(section, key, def.canon_name(), str, std::size(str), ini_file);
return modkeys{ str, def };
};
auto read_string = [&]<size_t max_len>(const char* def, const char* section, const char* key, const char* nil) {
auto read_string = [&]<size_t max_len>(char8_t const* def, char const* section, char const* key, char8_t const* nil) {
char str[max_len + 1];
::GetPrivateProfileStringA(section, key, def, str, std::size(str), ini_file);
if (std::strcmp(str, nil) == 0)
::GetPrivateProfileStringA(section, key, reinterpret_cast<char const*>(def), str, std::size(str), ini_file);
if (std::strcmp(str, reinterpret_cast<char const*>(nil)) == 0)
return std::unique_ptr<std::wstring>{ nullptr };
return std::make_unique<std::wstring>(Encodes::to_wstring(str));
};
Expand All @@ -1325,8 +1324,8 @@ inline constinit struct Settings {
[&](auto x) { return std::clamp(x, textTweaks.min_tabstops, textTweaks.max_tabstops); }, /* id */);
load_gen (textTweaks., tabstops_script, "TextBox.Tweaks",
[&](auto x) { return std::clamp(x, textTweaks.min_tabstops, textTweaks.max_tabstops); }, /* id */);
load_str (textTweaks., replace_tab_text, "TextBox.Tweaks", "\t", textTweaks.max_replace_tab_length);
load_str (textTweaks., replace_tab_script, "TextBox.Tweaks", "\t", textTweaks.max_replace_tab_length);
load_str (textTweaks., replace_tab_text, "TextBox.Tweaks", u8"\t", textTweaks.max_replace_tab_length);
load_str (textTweaks., replace_tab_script, "TextBox.Tweaks", u8"\t", textTweaks.max_replace_tab_length);

load_bool(trackKbd., updown, "Track.Keyboard");
load_bool(trackKbd., updown_clamp, "Track.Keyboard");
Expand Down Expand Up @@ -1357,12 +1356,12 @@ inline constinit struct Settings {

load_bool(dropdownKbd., search, "Dropdown.Keyboard");

load_str0(filterName., anim_eff_fmt, "FilterName", "{}(アニメーション効果)", filterName.max_fmt_length, "");
load_str0(filterName., cust_std_fmt, "FilterName", "{}(カスタムオブジェクト)[標準描画]", filterName.max_fmt_length, "");
load_str0(filterName., cust_ext_fmt, "FilterName", "{}(カスタムオブジェクト)[拡張描画]", filterName.max_fmt_length, "");
load_str0(filterName., cust_particle_fmt, "FilterName", "{}(カスタムオブジェクト)[パーティクル出力]", filterName.max_fmt_length, "");
load_str0(filterName., cam_eff_fmt, "FilterName", "{}(カメラ効果)", filterName.max_fmt_length, "");
load_str0(filterName., scn_change_fmt, "FilterName", "{}(シーンチェンジ)", filterName.max_fmt_length, "");
load_str0(filterName., anim_eff_fmt, "FilterName", u8"{}(アニメーション効果)", filterName.max_fmt_length, u8"");
load_str0(filterName., cust_std_fmt, "FilterName", u8"{}(カスタムオブジェクト)[標準描画]", filterName.max_fmt_length, u8"");
load_str0(filterName., cust_ext_fmt, "FilterName", u8"{}(カスタムオブジェクト)[拡張描画]", filterName.max_fmt_length, u8"");
load_str0(filterName., cust_particle_fmt, "FilterName", u8"{}(カスタムオブジェクト)[パーティクル出力]", filterName.max_fmt_length, u8"");
load_str0(filterName., cam_eff_fmt, "FilterName", u8"{}(カメラ効果)", filterName.max_fmt_length, u8"");
load_str0(filterName., scn_change_fmt, "FilterName", u8"{}(シーンチェンジ)", filterName.max_fmt_length, u8"");

load_bool(easings., linked_track_invert_shift, "Easings");
load_bool(easings., wheel_click, "Easings");
Expand Down Expand Up @@ -2152,7 +2151,7 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID lpvReserved)
// 看板.
////////////////////////////////
#define PLUGIN_NAME "Reactive Dialog"
#define PLUGIN_VERSION "v1.62"
#define PLUGIN_VERSION "v1.63-beta1"
#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
12 changes: 6 additions & 6 deletions slim_formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I
////////////////////////////////
class slim_formatter {
std::wstring base{};
std::vector<size_t> holes{}; // the 'holes' where the animation name is placed in.
std::vector<size_t> holes{}; // the 'holes' where the parameter is placed in.

public:
constexpr std::wstring operator()(std::wstring const& name) const
constexpr std::wstring operator()(std::wstring const& param) const
{
std::wstring ret(base.size() + name.size() * holes.size(), L'\0');
std::wstring ret(base.size() + param.size() * holes.size(), L'\0');

// alternatingly copy to `ret` the strings `base` and `name`.
// alternatingly copy to `ret` the strings `base` and `param`.
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();
param.copy(p, param.size());
p += param.size();

l = i;
}
Expand Down

0 comments on commit cb7ff87

Please sign in to comment.