diff --git a/image/jp-dark.ico b/image/jp-dark.ico new file mode 100644 index 00000000..c1819eec Binary files /dev/null and b/image/jp-dark.ico differ diff --git a/image/jp-light.ico b/image/jp-light.ico new file mode 100644 index 00000000..b5ebf82d Binary files /dev/null and b/image/jp-light.ico differ diff --git a/src/Header/Define.h b/src/Header/Define.h index 2f29c577..28620821 100644 --- a/src/Header/Define.h +++ b/src/Header/Define.h @@ -15,6 +15,8 @@ #define IME_MODE_OFF_ICON_INDEX IDI_IME_MODE_OFF #define IME_MODE_ON_DARK_ICON_INDEX IDI_IME_MODE_ON_DARK #define IME_MODE_OFF_DARK_ICON_INDEX IDI_IME_MODE_OFF_DARK +#define IME_MODE_ON_JP_ICON_INDEX IDI_IME_MODE_ON_JP +#define IME_MODE_ON_JP_DARK_ICON_INDEX IDI_IME_MODE_ON_JP_DARK #define IME_DOUBLE_ON_INDEX IDI_DOUBLE_SINGLE_BYTE_ON #define IME_DOUBLE_OFF_INDEX IDI_DOUBLE_SINGLE_BYTE_OFF #define IME_PUNCTUATION_ON_INDEX IDI_PUNCTUATION_ON diff --git a/src/Header/resource.h b/src/Header/resource.h index ae349525..3be4f114 100644 --- a/src/Header/resource.h +++ b/src/Header/resource.h @@ -17,6 +17,8 @@ #define IDI_PUNCTUATION_OFF 28 #define IDI_IME_MODE_ON_DARK 29 #define IDI_IME_MODE_OFF_DARK 30 +#define IDI_IME_MODE_ON_JP 31 +#define IDI_IME_MODE_ON_JP_DARK 32 #define IDR_VERSION2 107 // Next default values for new objects diff --git a/src/IME/MetasequoiaIME.rc b/src/IME/MetasequoiaIME.rc index a3a10bc1..fa15f9c7 100644 --- a/src/IME/MetasequoiaIME.rc +++ b/src/IME/MetasequoiaIME.rc @@ -20,6 +20,8 @@ IDI_IME_MODE_ON ICON "..\\..\\image\\cn-light.ico" IDI_IME_MODE_OFF ICON "..\\..\\image\\en-light.ico" IDI_IME_MODE_ON_DARK ICON "..\\..\\image\\cn-dark.ico" IDI_IME_MODE_OFF_DARK ICON "..\\..\\image\\en-dark.ico" +IDI_IME_MODE_ON_JP ICON "..\\..\\image\\jp-light.ico" +IDI_IME_MODE_ON_JP_DARK ICON "..\\..\\image\\jp-dark.ico" IDI_DOUBLE_SINGLE_BYTE_ON ICON "..\\..\\image\\DoubleSingleByteOn.ico" IDI_DOUBLE_SINGLE_BYTE_OFF ICON "..\\..\\image\\DoubleSingleByteOff.ico" IDI_PUNCTUATION_ON ICON "..\\..\\image\\PunctuationOn.ico" diff --git a/src/LanguageBar/LanguageBar.cpp b/src/LanguageBar/LanguageBar.cpp index 2bae5afd..c7fbd6c5 100644 --- a/src/LanguageBar/LanguageBar.cpp +++ b/src/LanguageBar/LanguageBar.cpp @@ -14,11 +14,6 @@ #include "Compartment.h" #include "Ipc.h" #include "fmt/xchar.h" -#include -#include -#include -#include -#include namespace { @@ -46,108 +41,16 @@ DWORD ResolveThemeIconIndex(DWORD lightIconIndex) { return static_cast(IME_MODE_ON_DARK_ICON_INDEX); } + if (lightIconIndex == static_cast(IME_MODE_ON_JP_ICON_INDEX)) + { + return static_cast(IME_MODE_ON_JP_DARK_ICON_INDEX); + } if (lightIconIndex == static_cast(IME_MODE_OFF_ICON_INDEX)) { return static_cast(IME_MODE_OFF_DARK_ICON_INDEX); } return lightIconIndex; } - -HICON CreateJapaneseModeIcon(int size, bool darkMode) -{ - if (size <= 0) - { - size = 16; - } - - BITMAPINFO info{}; - info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - info.bmiHeader.biWidth = size; - info.bmiHeader.biHeight = -size; - info.bmiHeader.biPlanes = 1; - info.bmiHeader.biBitCount = 32; - info.bmiHeader.biCompression = BI_RGB; - - void *bits = nullptr; - HDC screen = GetDC(nullptr); - HDC dc = CreateCompatibleDC(screen); - HBITMAP color = CreateDIBSection(dc, &info, DIB_RGB_COLORS, &bits, nullptr, 0); - if (!dc || !color || !bits) - { - if (color) - { - DeleteObject(color); - } - if (dc) - { - DeleteDC(dc); - } - if (screen) - { - ReleaseDC(nullptr, screen); - } - return nullptr; - } - - std::memset(bits, 0, static_cast(size) * static_cast(size) * 4); - const std::uint32_t pixel = darkMode ? 0xFFFFFFFFu : 0xFF1A1A1Au; - auto *pixels = static_cast(bits); - const auto map = [size](double value) { - const int mapped = static_cast(std::lround(value * size / 24.0)); - return (std::max)(0, (std::min)(size, mapped)); - }; - const auto fill = [&](double left, double top, double right, double bottom) { - const int x0 = map(left); - const int y0 = map(top); - const int x1 = map(right); - const int y1 = map(bottom); - for (int y = y0; y < y1; ++y) - { - for (int x = x0; x < x1; ++x) - { - pixels[static_cast(y) * static_cast(size) + static_cast(x)] = pixel; - } - } - }; - fill(5.0, 4.4, 19.0, 5.9); - fill(5.0, 18.1, 19.0, 19.6); - fill(5.0, 4.4, 6.5, 19.6); - fill(17.5, 4.4, 19.0, 19.6); - fill(6.5, 11.25, 17.5, 12.75); - - const int maskStride = ((size + 31) / 32) * 4; - std::vector maskBits(static_cast(maskStride) * static_cast(size), 0xFF); - for (int y = 0; y < size; ++y) - { - for (int x = 0; x < size; ++x) - { - if (pixels[static_cast(y) * static_cast(size) + static_cast(x)] == 0) - { - continue; - } - const int bit = 7 - (x % 8); - const int maskY = size - 1 - y; - maskBits[static_cast(maskY) * static_cast(maskStride) + static_cast(x / 8)] &= - static_cast(~(1u << bit)); - } - } - HBITMAP mask = CreateBitmap(size, size, 1, 1, maskBits.data()); - ICONINFO iconInfo{}; - iconInfo.fIcon = TRUE; - iconInfo.hbmMask = mask; - iconInfo.hbmColor = color; - HICON icon = mask ? CreateIconIndirect(&iconInfo) : nullptr; - - if (mask) - { - DeleteObject(mask); - } - SelectObject(dc, GetStockObject(NULL_BRUSH)); - DeleteObject(color); - DeleteDC(dc); - ReleaseDC(nullptr, screen); - return icon; -} } // namespace //+--------------------------------------------------------------------------- @@ -618,23 +521,19 @@ STDAPI CLangBarItemButton::GetIcon(_Out_ HICON *phIcon) desiredSize = 24; } - const DWORD iconIndex = - ResolveThemeIconIndex((isOn && !(status & TF_LBI_STATUS_DISABLED)) ? _onIconIndex : _offIconIndex); + DWORD lightIconIndex = (isOn && !(status & TF_LBI_STATUS_DISABLED)) ? _onIconIndex : _offIconIndex; + if (isOn && !(status & TF_LBI_STATUS_DISABLED) && + _onIconIndex == static_cast(IME_MODE_ON_ICON_INDEX) && + Global::JapaneseInputModeEnabled.load(std::memory_order_relaxed)) + { + lightIconIndex = static_cast(IME_MODE_ON_JP_ICON_INDEX); + } + const DWORD iconIndex = ResolveThemeIconIndex(lightIconIndex); if (Global::dllInstanceHandle) { - const bool japaneseOn = isOn && !(status & TF_LBI_STATUS_DISABLED) && - _onIconIndex == static_cast(IME_MODE_ON_ICON_INDEX) && - Global::JapaneseInputModeEnabled.load(std::memory_order_relaxed); - if (japaneseOn) - { - *phIcon = CreateJapaneseModeIcon(desiredSize, IsSystemDarkMode()); - } - else - { - *phIcon = reinterpret_cast(LoadImage(Global::dllInstanceHandle, MAKEINTRESOURCE(iconIndex), IMAGE_ICON, - desiredSize, desiredSize, 0)); - } + *phIcon = reinterpret_cast(LoadImage(Global::dllInstanceHandle, MAKEINTRESOURCE(iconIndex), IMAGE_ICON, + desiredSize, desiredSize, 0)); } return (*phIcon != NULL) ? S_OK : E_FAIL;