Skip to content

Commit

Permalink
improve patterns dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Mar 24, 2023
1 parent 4d34709 commit eb245d7
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 27 deletions.
6 changes: 6 additions & 0 deletions GUI.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#pragma once

#ifdef _MSC_VER
#define XG_NOINLINE __declspec(noinline)
#else
#define XG_NOINLINE __attribute__((noinline))
#endif

// ヒントウィンドウを作成する。
BOOL XgCreateHintsWnd(HWND hwnd);
// ヒントウィンドウを破棄する。
Expand Down
6 changes: 4 additions & 2 deletions HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,11 @@
- Improved "Marking" dialog.
- Correctly undoing "setting a double-frame word".
- Added labels to THEME.txt.
- 20XX-YY-ZZ ver.5.0.3
- 2023-03-25 ver.5.0.3
- Made the maximum size of the block patterns 20x20.
- Improved block patterns (PAT.txt).
- Global optimization that focuses on the fact that there are fewer candidates for longer words.
- Improved block patterns dialog.

# 開発履歴 (Japanese)

Expand Down Expand Up @@ -729,7 +730,8 @@
- 「二重マス単語の候補と配置」ダイアログを改良。
- 二重マス単語を正しく「元に戻す」。
- THEME.txtの各項目にラベルを追加。
- 20XX年YY月ZZ日 ver.5.0.3
- 2023年03月25日 ver.5.0.3
- 黒マスパターンの最大サイズを20x20に。
- 黒マスパターン(PAT.txt)を改良。
- 長い単語には候補が少ないことに着目した大局的な最適化。
- 黒マスパターンダイアログの改良。
67 changes: 48 additions & 19 deletions XG_PatternDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,32 @@ class XG_PatternDialog : public XG_Dialog
}

// タイプによりフィルターを行う。
BOOL FilterPatBySize(const XG_PATDATA& pat, INT type) {
XG_NOINLINE
BOOL FilterPatBySize(const XG_PATDATA& pat, INT type0, INT type1) {
if (pat.num_columns > XG_MAX_PAT_SIZE || pat.num_rows > XG_MAX_PAT_SIZE)
return FALSE;

switch (type) {
case -1:
break;
switch (type0) {
case rad1:
if (pat.num_columns != pat.num_rows)
return FALSE;
if (!(pat.num_columns >= 13 && pat.num_rows >= 13))
if (!(pat.num_columns + pat.num_rows >= 28))
return FALSE;
break;
case rad2:
if (pat.num_columns != pat.num_rows)
return FALSE;
if (!(8 <= pat.num_columns && pat.num_columns <= 12 &&
8 <= pat.num_rows && pat.num_rows <= 12))
if (!(pat.num_columns + pat.num_rows < 28 &&
pat.num_columns + pat.num_rows > 16))
{
return FALSE;
}
break;
case rad3:
if (pat.num_columns != pat.num_rows)
return FALSE;
if (!(pat.num_columns <= 8 && pat.num_rows <= 8))
if (!(pat.num_columns + pat.num_rows <= 16))
return FALSE;
break;
default:
assert(0);
}

switch (type1) {
case rad4:
if (pat.num_columns <= pat.num_rows)
return FALSE;
Expand All @@ -82,7 +80,8 @@ class XG_PatternDialog : public XG_Dialog
return TRUE;
}

BOOL RefreshContents(HWND hwnd, INT type)
XG_NOINLINE
BOOL RefreshContents(HWND hwnd, INT type0, INT type1)
{
// リストボックスをクリアする。
ListBox_ResetContent(GetDlgItem(hwnd, lst1));
Expand Down Expand Up @@ -121,7 +120,7 @@ class XG_PatternDialog : public XG_Dialog
continue;
}

if (FilterPatBySize(pat, type))
if (FilterPatBySize(pat, type0, type1))
{
pats.push_back(pat);
}
Expand All @@ -141,6 +140,7 @@ class XG_PatternDialog : public XG_Dialog
}

// WM_INITDIALOG
XG_NOINLINE
BOOL OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
XgCenterDialog(hwnd);
Expand All @@ -156,8 +156,9 @@ class XG_PatternDialog : public XG_Dialog
else
CheckDlgButton(hwnd, chx1, BST_UNCHECKED);

CheckRadioButton(hwnd, rad1, rad6, rad6);
RefreshContents(hwnd, rad6);
CheckRadioButton(hwnd, rad1, rad3, rad2);
CheckRadioButton(hwnd, rad4, rad6, rad6);
RefreshContents(hwnd, rad2, rad6);

static const LAYOUT_INFO layouts[] =
{
Expand Down Expand Up @@ -198,6 +199,7 @@ class XG_PatternDialog : public XG_Dialog
}

// 黒マスパターンのコピー。
XG_NOINLINE
void OnCopy(HWND hwnd)
{
HWND hLst1 = GetDlgItem(hwnd, lst1);
Expand Down Expand Up @@ -227,6 +229,7 @@ class XG_PatternDialog : public XG_Dialog
}

// 黒マスパターンで「OK」ボタンを押した。
XG_NOINLINE
void OnOK(HWND hwnd)
{
HWND hLst1 = GetDlgItem(hwnd, lst1);
Expand Down Expand Up @@ -286,7 +289,30 @@ class XG_PatternDialog : public XG_Dialog
ShellExecuteW(hwnd, NULL, L"https://katahiromz.web.fc2.com/xword/patterns", NULL, NULL, SW_SHOWNORMAL);
}

INT GetType0()
{
if (IsDlgButtonChecked(m_hWnd, rad1) == BST_CHECKED)
return rad1;
if (IsDlgButtonChecked(m_hWnd, rad2) == BST_CHECKED)
return rad2;
if (IsDlgButtonChecked(m_hWnd, rad3) == BST_CHECKED)
return rad3;
return -1;
}

INT GetType1()
{
if (IsDlgButtonChecked(m_hWnd, rad4) == BST_CHECKED)
return rad4;
if (IsDlgButtonChecked(m_hWnd, rad5) == BST_CHECKED)
return rad5;
if (IsDlgButtonChecked(m_hWnd, rad6) == BST_CHECKED)
return rad6;
return -1;
}

// WM_COMMAND
XG_NOINLINE
void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch (id)
Expand Down Expand Up @@ -315,14 +341,15 @@ class XG_PatternDialog : public XG_Dialog
case rad4:
case rad5:
case rad6:
RefreshContents(hwnd, id);
RefreshContents(hwnd, GetType0(), GetType1());
break;
}
}

const INT cxCell = 5, cyCell = 5; // 小さなセルのサイズ。

// WM_MEASUREITEM
XG_NOINLINE
void OnMeasureItem(HWND hwnd, MEASUREITEMSTRUCT * lpMeasureItem)
{
// リストボックスの lst1 か?
Expand All @@ -339,6 +366,7 @@ class XG_PatternDialog : public XG_Dialog
}

// WM_DRAWITEM
XG_NOINLINE
void OnDrawItem(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem)
{
// リストボックスの lst1 か?
Expand Down Expand Up @@ -492,6 +520,7 @@ class XG_PatternDialog : public XG_Dialog
}

// 「黒マスパターン」ダイアログプロシージャ。
XG_NOINLINE
virtual INT_PTR CALLBACK
DialogProcDx(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
Expand Down
6 changes: 3 additions & 3 deletions lang/en_US.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1306,12 +1306,12 @@ STYLE DS_CENTER | DS_MODALFRAME | WS_POPUPWINDOW | WS_CAPTION | WS_THICKFRAME |
FONT 9, "Tahoma"
{
LTEXT "Please select a pattern from the list below.", stc1, 5, 2, 220, 12
AUTORADIOBUTTON "&Large", rad1, 5, 15, 45, 16, WS_TABSTOP
AUTORADIOBUTTON "&Large", rad1, 5, 15, 45, 16, WS_TABSTOP | WS_GROUP
AUTORADIOBUTTON "&Medium", rad2, 55, 15, 50, 16, WS_TABSTOP
AUTORADIOBUTTON "&Small", rad3, 110, 15, 50, 16, WS_TABSTOP
AUTORADIOBUTTON "L&andscape", rad4, 175, 15, 48, 16, WS_TABSTOP
AUTORADIOBUTTON "L&andscape", rad4, 175, 15, 48, 16, WS_TABSTOP | WS_GROUP
AUTORADIOBUTTON "&Portrait", rad5, 227, 15, 43, 16, WS_TABSTOP
AUTORADIOBUTTON "&N/A", rad6, 275, 15, 55, 16, WS_TABSTOP
AUTORADIOBUTTON "S&quare", rad6, 275, 15, 55, 16, WS_TABSTOP
LTEXT "Lis&t:", stc2, 8, 37, 47, 12
LISTBOX lst1, 5, 50, 325, 190, LBS_DISABLENOSCROLL | LBS_MULTICOLUMN | LBS_NOINTEGRALHEIGHT | LBS_OWNERDRAWFIXED | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP
PUSHBUTTON "&Copy", psh1, 5, 245, 60, 15
Expand Down
6 changes: 3 additions & 3 deletions lang/ja_JP.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1309,12 +1309,12 @@ STYLE DS_CENTER | DS_MODALFRAME | WS_POPUPWINDOW | WS_CAPTION | WS_THICKFRAME |
FONT 9, "MS UI Gothic"
{
LTEXT "下のリストから黒マスパターンをお選び下さい。", stc1, 5, 2, 220, 12
AUTORADIOBUTTON "大(&Large)", rad1, 5, 15, 45, 16, WS_TABSTOP
AUTORADIOBUTTON "大(&Large)", rad1, 5, 15, 45, 16, WS_TABSTOP | WS_GROUP
AUTORADIOBUTTON "中(&Medium)", rad2, 55, 15, 50, 16, WS_TABSTOP
AUTORADIOBUTTON "小(&Small)", rad3, 110, 15, 50, 16, WS_TABSTOP
AUTORADIOBUTTON "横長(&H)", rad4, 175, 15, 40, 16, WS_TABSTOP
AUTORADIOBUTTON "横長(&H)", rad4, 175, 15, 40, 16, WS_TABSTOP | WS_GROUP
AUTORADIOBUTTON "縦長(&V)", rad5, 220, 15, 40, 16, WS_TABSTOP
AUTORADIOBUTTON "指定なし(&N)", rad6, 275, 15, 55, 16, WS_TABSTOP
AUTORADIOBUTTON "正方形(&Q)", rad6, 275, 15, 55, 16, WS_TABSTOP
LTEXT "リスト(&T):", stc2, 8, 37, 47, 12
LISTBOX lst1, 5, 50, 325, 190, LBS_DISABLENOSCROLL | LBS_MULTICOLUMN | LBS_NOINTEGRALHEIGHT | LBS_OWNERDRAWFIXED | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP
PUSHBUTTON "コピー(&C)", psh1, 5, 245, 60, 15
Expand Down

0 comments on commit eb245d7

Please sign in to comment.