Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Reader/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ void Cache::default_header(header_t* header)
// default bk color
header->bg_color = 0x00ffffff; // White
header->alpha = 0xff;
header->transparent_bg = 0;

header->char_gap = 0;
header->line_gap = 5;
Expand Down
7 changes: 7 additions & 0 deletions Reader/DisplaySet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct display_set_data_t
int word_wrap;
int line_indent;
int blank_lines;
int transparent_bg;
int chapter_page;
int is_save;
} display_set_data_t;
Expand Down Expand Up @@ -80,6 +81,7 @@ static void _update_preview(HDC hDC, RECT *rc);
(d)->word_wrap = (s)->word_wrap; \
(d)->line_indent = (s)->line_indent; \
(d)->blank_lines = (s)->blank_lines; \
(d)->transparent_bg = (s)->transparent_bg; \
(d)->chapter_page = (s)->chapter_page;

void OpenDisplaySetDlg(void)
Expand Down Expand Up @@ -224,6 +226,10 @@ static INT_PTR CALLBACK DisplaySetDlgProc(HWND hDlg, UINT message, WPARAM wParam
res = (int)SendMessage(GetDlgItem(hDlg, IDC_CHECK_BLANKLINES), BM_GETCHECK, 0, NULL);
_display.blank_lines = BST_CHECKED == res ? 1 : 0;
break;
case IDC_CHECK_TRANS_BG:
res = (int)SendMessage(GetDlgItem(hDlg, IDC_CHECK_TRANS_BG), BM_GETCHECK, 0, NULL);
_display.transparent_bg = BST_CHECKED == res ? 1 : 0;
break;
case IDC_CHECK_CHAPTER_PAGE:
res = (int)SendMessage(GetDlgItem(hDlg, IDC_CHECK_CHAPTER_PAGE), BM_GETCHECK, 0, NULL);
_display.chapter_page = BST_CHECKED == res ? 1 : 0;
Expand Down Expand Up @@ -315,6 +321,7 @@ static void _init_layout_set(HWND hDlg)
SendMessage(GetDlgItem(hDlg, IDC_CHECK_WORD_WRAP), BM_SETCHECK, _display.word_wrap ? BST_CHECKED : BST_UNCHECKED, NULL);
SendMessage(GetDlgItem(hDlg, IDC_CHECK_INDENT), BM_SETCHECK, _display.line_indent ? BST_CHECKED : BST_UNCHECKED, NULL);
SendMessage(GetDlgItem(hDlg, IDC_CHECK_BLANKLINES), BM_SETCHECK, _display.blank_lines ? BST_CHECKED : BST_UNCHECKED, NULL);
SendMessage(GetDlgItem(hDlg, IDC_CHECK_TRANS_BG), BM_SETCHECK, _display.transparent_bg ? BST_CHECKED : BST_UNCHECKED, NULL);
SendMessage(GetDlgItem(hDlg, IDC_CHECK_CHAPTER_PAGE), BM_SETCHECK, _display.chapter_page ? BST_CHECKED : BST_UNCHECKED, NULL);
}

Expand Down
5 changes: 5 additions & 0 deletions Reader/Jsondata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ class json_header_t
cJSON* line_indent;
cJSON* blank_lines;
cJSON* chapter_page;
cJSON* transparent_bg;
cJSON* ingore_version;
cJSON* checkver_time;
cJSON* global_key;
Expand Down Expand Up @@ -656,6 +657,7 @@ class json_header_t
line_indent = cJSON_AddNumberToObject(parent, "line_indent", data->line_indent);
blank_lines = cJSON_AddNumberToObject(parent, "blank_lines", data->blank_lines);
chapter_page = cJSON_AddNumberToObject(parent, "chapter_page", data->chapter_page);
transparent_bg = cJSON_AddNumberToObject(parent, "transparent_bg", data->transparent_bg);
ingore_version = cJSON_AddStringToObject(parent, "ingore_version", Utf16ToUtf8(data->ingore_version));
checkver_time = cJSON_AddULongToObject(parent, "checkver_time", data->checkver_time);

Expand Down Expand Up @@ -779,6 +781,7 @@ class json_header_t
line_indent = cJSON_GetObjectItem(parent, "line_indent");
blank_lines = cJSON_GetObjectItem(parent, "blank_lines");
chapter_page = cJSON_GetObjectItem(parent, "chapter_page");
transparent_bg = cJSON_GetObjectItem(parent, "transparent_bg");
ingore_version = cJSON_GetObjectItem(parent, "ingore_version");
checkver_time = cJSON_GetObjectItem(parent, "checkver_time");

Expand Down Expand Up @@ -966,6 +969,8 @@ class json_header_t
data->blank_lines = blank_lines->valueint;
if (chapter_page)
data->chapter_page = chapter_page->valueint;
if (transparent_bg)
data->transparent_bg = transparent_bg->valueint;
if (ingore_version)
wcscpy(data->ingore_version, Utf8ToUtf16(ingore_version->valuestring));
if (checkver_time)
Expand Down
82 changes: 68 additions & 14 deletions Reader/Keyset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern LRESULT OnChapterUp(HWND, UINT, WPARAM, LPARAM);
extern LRESULT OnChapterDown(HWND, UINT, WPARAM, LPARAM);
extern LRESULT OnFontZoomIn(HWND, UINT, WPARAM, LPARAM);
extern LRESULT OnFontZoomOut(HWND, UINT, WPARAM, LPARAM);
extern LRESULT OnTransBG(HWND, UINT, WPARAM, LPARAM);
extern int MessageBoxFmt_(HWND hWnd, UINT captionId, UINT uType, UINT formatId, ...);

extern HINSTANCE hInst;
Expand All @@ -34,6 +35,9 @@ static BOOL _unregister_hotkey(HWND hWnd, DWORD kid);
keydata_t g_Keysets[KI_MAXCOUNT] =
{
{ MAKELONG(KT_HOTKEY, KI_HIDE), IDHK_SHWIN, 0, 0, MAKEWORD('H', HOTKEYF_ALT), IDC_HK_HIDE, IDC_CHECK_HIDE, OnHideWin, IDS_HIDE_SHOW_WINDOW },
{ MAKELONG(KT_HOTKEY, KI_HIDE2), ID_HOTKEY_SHOW_HIDE_WINDOW2, 0, 0, MAKEWORD('H', HOTKEYF_CONTROL|HOTKEYF_ALT), IDC_HK_HIDE2, IDC_CHECK_HIDE2, OnHideWin, IDS_HIDE_SHOW_WINDOW },
{ MAKELONG(KT_HOTKEY, KI_HIDE3), ID_HOTKEY_SHOW_HIDE_WINDOW3, 0, 0, MAKEWORD('H', HOTKEYF_CONTROL|HOTKEYF_SHIFT), IDC_HK_HIDE3, IDC_CHECK_HIDE3, OnHideWin, IDS_HIDE_SHOW_WINDOW },
{ MAKELONG(KT_HOTKEY, KI_HIDE4), ID_HOTKEY_SHOW_HIDE_WINDOW4, 0, 0, MAKEWORD('Q', HOTKEYF_ALT), IDC_HK_HIDE4, IDC_CHECK_HIDE4, OnHideWin, IDS_HIDE_SHOW_WINDOW },
{ MAKELONG(KT_SHORTCUTKEY, KI_BORDER), 0, 0, 0, MAKEWORD(VK_F12, 0), IDC_HK_BORDER, IDC_CHECK_BORDER, OnHideBorder, IDS_HIDE_SHOW_BORDER },
{ MAKELONG(KT_SHORTCUTKEY, KI_FULLSCREEN), 0, 0, 0, MAKEWORD(VK_F11, 0), IDC_HK_FULLSCREEN, IDC_CHECK_FULLSCREEN, OnFullScreen, IDS_FULLSRCEEN },
{ MAKELONG(KT_SHORTCUTKEY, KI_TOP), 0, 0, 0, MAKEWORD('T', HOTKEYF_CONTROL), IDC_HK_TOP, IDC_CHECK_TOP, OnTopmost, IDS_TOPMOST },
Expand All @@ -50,7 +54,8 @@ keydata_t g_Keysets[KI_MAXCOUNT] =
{ MAKELONG(KT_SHORTCUTKEY, KI_CHAPTERUP), 0, 0, 0, MAKEWORD(VK_LEFT, HOTKEYF_EXT|HOTKEYF_CONTROL), IDC_HK_CHAPTERUP, IDC_CHECK_CHAPTERUP, OnChapterUp, IDS_CHAPTER_UP },
{ MAKELONG(KT_SHORTCUTKEY, KI_CHAPTERDOWN), 0, 0, 0, MAKEWORD(VK_RIGHT, HOTKEYF_EXT|HOTKEYF_CONTROL), IDC_HK_CHAPTERDOWN, IDC_CHECK_CHAPTERDOWN, OnChapterDown, IDS_CHAPTER_DOWN },
{ MAKELONG(KT_SHORTCUTKEY, KI_FONTZOOMIN), 0, 0, 0, MAKEWORD(VK_OEM_PLUS, HOTKEYF_CONTROL), IDC_HK_FONTZOOMIN, IDC_CHECK_FONTZOOMIN, OnFontZoomIn, IDS_FONT_ZOOMIN },
{ MAKELONG(KT_SHORTCUTKEY, KI_FONTZOOMOUT), 0, 0, 0, MAKEWORD(VK_OEM_MINUS, HOTKEYF_CONTROL), IDC_HK_FONTZOOMOUT, IDC_CHECK_FONTZOOMOUT, OnFontZoomOut, IDS_FONT_ZOOMOUT }
{ MAKELONG(KT_SHORTCUTKEY, KI_FONTZOOMOUT), 0, 0, 0, MAKEWORD(VK_OEM_MINUS, HOTKEYF_CONTROL), IDC_HK_FONTZOOMOUT, IDC_CHECK_FONTZOOMOUT, OnFontZoomOut, IDS_FONT_ZOOMOUT },
{ MAKELONG(KT_SHORTCUTKEY, KI_TRANS), 0, 0, 0, MAKEWORD(VK_F9, 0), IDC_HK_TRANS, IDC_CHECK_TRANS, OnTransBG, IDS_TRANS_TOGGLE }
};


Expand All @@ -65,31 +70,69 @@ void KS_Init(HWND hWnd, keyset_t *keyset)
SetGlobalKey(hWnd);
}

// The config slot of an entry is the keyid stored in key (HIWORD), NOT its array
// index in g_Keysets. This decouples the table layout from the persisted config:
// a new key can be inserted anywhere in g_Keysets without moving the slot of any
// existing key, so configs written by older versions keep their meaning
// (keyset[] is serialized positionally into JSON).
static int _keyset_slot(const keydata_t *kd)
{
int kid = (int)HIWORD(kd->key);

return (kid >= 0 && kid < MAX_KEYSET_COUNT) ? kid : -1;
}

// Which keys are enabled out of the box. Everything else starts disabled and
// is opt-in from the key settings dialog.
static BOOL _default_enable(int kid)
{
switch (kid)
{
case KI_HIDE: // boss key 1 (Alt+H)
case KI_BORDER: // hide/show border (F12)
case KI_PAGEUP: // previous page (Left)
case KI_PAGEDOWN: // next page (Right)
case KI_LINEUP: // line up (Up)
case KI_LINEDOWN: // line down (Down)
return TRUE;
default:
return FALSE;
}
}

void KS_UpdateKeyset(keyset_t *keyset)
{
int i;
int i, kid;

if (!keyset)
return;

for (i=KI_HIDE; i<KI_MAXCOUNT && i<MAX_KEYSET_COUNT; i++)
for (i=KI_HIDE; i<KI_MAXCOUNT; i++)
{
g_Keysets[i].pvalue = &(keyset[i].value);
g_Keysets[i].is_disable = &(keyset[i].is_disable);
kid = _keyset_slot(&g_Keysets[i]);
if (kid < 0)
continue;

g_Keysets[i].pvalue = &(keyset[kid].value);
g_Keysets[i].is_disable = &(keyset[kid].is_disable);
}
}

void KS_GetDefaultKeyset(keyset_t *keyset)
{
int i;
int i, kid;

if (!keyset)
return;

for (i=KI_HIDE; i<KI_MAXCOUNT && i<MAX_KEYSET_COUNT; i++)
for (i=KI_HIDE; i<KI_MAXCOUNT; i++)
{
keyset[i].value = g_Keysets[i].defval;
keyset[i].is_disable = 0;
kid = _keyset_slot(&g_Keysets[i]);
if (kid < 0)
continue;

keyset[kid].value = g_Keysets[i].defval;
keyset[kid].is_disable = _default_enable(kid) ? 0 : 1;
}
}

Expand All @@ -101,6 +144,8 @@ void KS_OpenDlg(void)
INT_PTR CALLBACK KS_DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
int i,j;
int kid = 0;
BOOL enable = FALSE;
LRESULT res;
DWORD tempkeys[KI_MAXCOUNT] = {0};
int tempable[KI_MAXCOUNT] = {0};
Expand Down Expand Up @@ -228,11 +273,18 @@ INT_PTR CALLBACK KS_DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPara
return (INT_PTR)TRUE;
break;
case IDC_BUTTON_DEFAULT:
// Keep in sync with KS_GetDefaultKeyset: restore the default values and
// check/enable only the keys that are enabled by default.
for (i=KI_HIDE; i<KI_MAXCOUNT; i++)
{
kid = _keyset_slot(&g_Keysets[i]);
if (kid < 0)
continue;

enable = _default_enable(kid);
SendMessage(GetDlgItem(hDlg, g_Keysets[i].ctrl_id), HKM_SETHOTKEY, g_Keysets[i].defval, 0);
SendMessage(GetDlgItem(hDlg, g_Keysets[i].able_id), BM_SETCHECK, BST_CHECKED, NULL);
EnableWindow(GetDlgItem(hDlg, g_Keysets[i].ctrl_id), TRUE);
SendMessage(GetDlgItem(hDlg, g_Keysets[i].able_id), BM_SETCHECK, enable ? BST_CHECKED : BST_UNCHECKED, NULL);
EnableWindow(GetDlgItem(hDlg, g_Keysets[i].ctrl_id), enable);
}
break;
default:
Expand Down Expand Up @@ -380,21 +432,23 @@ static BOOL _unregister_hotkey(HWND hWnd, DWORD kid)

BOOL KS_RegisterAllHotKey(HWND hWnd)
{
int i;
int i, fail = 0;
TCHAR desc[256] = { 0 };

for (i=KI_HIDE; i<KI_MAXCOUNT; i++)
{
if (LOWORD(g_Keysets[i].key) == KT_HOTKEY)
{
if (g_Keysets[i].is_disable && *(g_Keysets[i].is_disable))
continue;
LoadString(hInst, g_Keysets[i].desc, desc, 256);
if (!_register_hotkey(hWnd, g_Keysets[i].key_id, *(g_Keysets[i].pvalue), desc))
{
return FALSE;
fail++; // do not abort: other hot keys must still register
}
}
}
return TRUE;
return (fail == 0);
}

BOOL KS_UnRegisterAllHotKey(HWND hWnd)
Expand Down
4 changes: 4 additions & 0 deletions Reader/Keyset.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ typedef enum keyid_t
KI_CHAPTERDOWN,
KI_FONTZOOMIN,
KI_FONTZOOMOUT,
KI_HIDE2, // boss key 2 (config slot comes from keyid, so its position here keeps old configs valid)
KI_HIDE3, // boss key 3
KI_HIDE4, // boss key 4
KI_TRANS, // toggle transparent background (config slot comes from keyid, so appending keeps old configs valid)
KI_MAXCOUNT
} keyid_t;

Expand Down
22 changes: 22 additions & 0 deletions Reader/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,12 @@ LRESULT OnCreate(HWND hWnd)
_WndInfo.bTopMost = (_header->exstyle & WS_EX_TOPMOST) == WS_EX_TOPMOST;
_WndInfo.status = (_header->style & WS_MINIMIZEBOX) == 0 ? ds_fullscreen : (((_header->style & WS_CAPTION) == 0) ? ds_borderless : ds_normal);

// Borderless mode removes the menu bar, so the "hide/show border" key is the only
// way back to it. Never run without that escape hatch (e.g. after hand-editing the
// config), otherwise the menu would be unreachable for good.
if (_WndInfo.status == ds_borderless && _header->keyset[KI_BORDER].is_disable)
_header->keyset[KI_BORDER].is_disable = 0;

_WndInfo.hMenu = GetMenu(hWnd);
// create status bar
_WndInfo.hStatusBar = CreateStatusWindow(WS_CHILD | WS_VISIBLE, _T("Please open a text."), hWnd, IDC_STATUSBAR);
Expand Down Expand Up @@ -2191,6 +2197,13 @@ VOID OnDraw(HWND hWnd)
{
alpha = _header->alpha < MIN_ALPHA_VALUE ? MIN_ALPHA_VALUE : _header->alpha;
}
else if (_header->transparent_bg)
{
// Transparent background: alpha 0 makes the desktop show through and
// UpdateLayeredWindow turns those pixels click-through. The text is
// composited separately with _textAlpha, so it stays opaque.
alpha = 0;
}

// load bg image
image = LoadBGImage(w, h, alpha);
Expand Down Expand Up @@ -2505,6 +2518,15 @@ LRESULT OnTopmost(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
}

// Toggle the transparent-background flag. The visual effect only shows in
// borderless mode (F12), matching the display-settings checkbox behaviour.
LRESULT OnTransBG(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
_header->transparent_bg = !_header->transparent_bg;
Invalidate(hWnd, TRUE, FALSE);
return 0;
}

LRESULT OnOpenFile(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (IsWindow(_hFindDlg))
Expand Down
1 change: 1 addition & 0 deletions Reader/Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ LRESULT OnSize(HWND, UINT, WPARAM, LPARAM);
// WM_KEYWORD begin
LRESULT OnHideWin(HWND, UINT, WPARAM, LPARAM);
LRESULT OnHideBorder(HWND, UINT, WPARAM, LPARAM);
LRESULT OnTransBG(HWND, UINT, WPARAM, LPARAM);
LRESULT OnFullScreen(HWND, UINT, WPARAM, LPARAM);
LRESULT OnTopmost(HWND, UINT, WPARAM, LPARAM);
LRESULT OnOpenFile(HWND, UINT, WPARAM, LPARAM);
Expand Down
Binary file modified Reader/Reader_zh-cn.rc
Binary file not shown.
Binary file modified Reader/resource.h
Binary file not shown.
7 changes: 7 additions & 0 deletions Reader/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@


#define ID_HOTKEY_SHOW_HIDE_WINDOW 100

#define ID_HOTKEY_SHOW_HIDE_WINDOW2 200 // RegisterHotKey id: boss key 2
#define ID_HOTKEY_SHOW_HIDE_WINDOW3 201 // RegisterHotKey id: boss key 3
#define ID_HOTKEY_SHOW_HIDE_WINDOW4 202 // RegisterHotKey id: boss key 4
#define MAX_BOSS_KEY 4 // boss key count

#define IDT_TIMER_PAGE 102
#ifdef ENABLE_NETWORK
#define IDT_TIMER_UPGRADE 103
Expand Down Expand Up @@ -203,6 +209,7 @@ typedef struct header_t
int use_same_font;
u32 bg_color;
BYTE alpha;
int transparent_bg; // 1 = background fully transparent, text stays opaque
int char_gap;
int line_gap;
int paragraph_gap;
Expand Down