[ttssh2-commit] [10021] 背景テーマを整理

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2022年 6月 26日 (日) 01:14:37 JST


Revision: 10021
          https://osdn.net/projects/ttssh2/scm/svn/commits/10021
Author:   zmatsuo
Date:     2022-06-26 01:14:37 +0900 (Sun, 26 Jun 2022)
Log Message:
-----------
背景テーマを整理

- 背景テーマ
  - BG Enable on/off -> 次の3種類に変更
    - テーマを使用しない
    - 固定テーマ(テーマファイル指定)
      - テーマファイル指定追加
      - 従来の ImageFile.INI を暗黙に使用するのをやめた
      - theme\\ImageFile, theme\\*.INI に関する部分を削除
    - ランダムテーマ
  - プロパティページ(追加設定/表示タブ)の調整
  - 内部のthemeのパスの扱いをUnicode化した
  - 背景画像選択時カレントディレクトリを移動しないようにした
  - できるところをフルパス化
- tttypes.h
  - ts.eterm_lookfeel_t.BGIgnoreThemeFile 削除
  - ts.BGImageFilePath 削除
  - ts.BGImgBrightness 削除
- vtdisp.c
  - テーマファイルの読込など修正
- テスト用テーマファイル追加
  - theme/sample_bg.ini
  - theme/sample_wallpaper.ini

Modified Paths:
--------------
    branches/theme/teraterm/common/teraterm.h
    branches/theme/teraterm/common/tt_res.h
    branches/theme/teraterm/common/ttlib.h
    branches/theme/teraterm/common/ttlib_static_cpp.cpp
    branches/theme/teraterm/common/tttypes.h
    branches/theme/teraterm/teraterm/addsetting.cpp
    branches/theme/teraterm/teraterm/setupdirdlg.cpp
    branches/theme/teraterm/teraterm/ttermpro.rc
    branches/theme/teraterm/teraterm/vtdisp.c
    branches/theme/teraterm/teraterm/vtdisp.h
    branches/theme/teraterm/teraterm/vtwin.cpp
    branches/theme/teraterm/ttpset/ttset.c

Added Paths:
-----------
    branches/theme/installer/release/theme/sample_bg.ini
    branches/theme/installer/release/theme/sample_wallpaper.ini

-------------- next part --------------
Added: branches/theme/installer/release/theme/sample_bg.ini
===================================================================
--- branches/theme/installer/release/theme/sample_bg.ini	                        (rev 0)
+++ branches/theme/installer/release/theme/sample_bg.ini	2022-06-25 16:14:37 UTC (rev 10021)
@@ -0,0 +1,16 @@
+[BG]
+; base background image
+BGDestFile=scale\43.jpg
+BGDestPattern=stretch
+;BGDestPattern=center
+BGDestColor=0, 0, 0
+
+; Desktop wallpaper
+  ; 0(no effect)...255(wallpaper only)
+BGSrc1Alpha=0
+BGSrc1Color=0, 0, 0
+
+; blend color
+  ; 0(no effect)...255(fill color)
+BGSrc2Alpha=40
+BGSrc2Color=255, 255, 255 ; R, G, B

Added: branches/theme/installer/release/theme/sample_wallpaper.ini
===================================================================
--- branches/theme/installer/release/theme/sample_wallpaper.ini	                        (rev 0)
+++ branches/theme/installer/release/theme/sample_wallpaper.ini	2022-06-25 16:14:37 UTC (rev 10021)
@@ -0,0 +1,16 @@
+[BG]
+; base background image
+BGDestFile=
+BGDestPattern=stretch
+;BGDestPattern=center
+BGDestColor=0, 0, 0
+
+; Desktop wallpaper
+  ; 0(no effect)...255(wallpaper only)
+BGSrc1Alpha=180
+BGSrc1Color=0, 0, 0
+
+; blend color
+  ; 0(no effect)...255(fill color)
+BGSrc2Alpha=0
+BGSrc2Color=0, 0, 0 ; R, G, B

Modified: branches/theme/teraterm/common/teraterm.h
===================================================================
--- branches/theme/teraterm/common/teraterm.h	2022-06-25 16:12:49 UTC (rev 10020)
+++ branches/theme/teraterm/common/teraterm.h	2022-06-25 16:14:37 UTC (rev 10021)
@@ -63,15 +63,16 @@
 #define BG_DESTFILE "BGDestFile"
 #define BG_DESTFILEW L"BGDestFile"
 #define BG_THEME_DIR L"theme"
-#define BG_THEME_IMAGEFILE "theme\\ImageFile.INI"
-#define BG_THEME_IMAGEFILE_DEFAULT "theme\\*.INI"
+//#define BG_THEME_IMAGEFILE "theme\\ImageFile.INI"
+//#define BG_THEME_IMAGEFILE_DEFAULT "theme\\*.INI"
 #define BG_THEME_IMAGE_BRIGHTNESS_DEFAULT 64
 #define BG_THEME_IMAGE_BRIGHTNESS1 "BGSrc1Alpha"
 #define BG_THEME_IMAGE_BRIGHTNESS1W L"BGSrc1Alpha"
 #define BG_THEME_IMAGE_BRIGHTNESS2 "BGSrc2Alpha"
-#define BG_THEME_IMAGEFILE_NAME "ImageFile.INI"
-#define BG_THEME_THEMEFILE_SCALE "Scale.INI"
-#define BG_THEME_THEMEFILE_TILE "Tile.INI"
+//#define BG_THEME_IMAGEFILE_NAME "ImageFile.INI"
+//#define BG_THEME_IMAGEFILE_NAMEW L"ImageFile.INI"
+//#define BG_THEME_THEMEFILE_SCALE "Scale.INI"
+//#define BG_THEME_THEMEFILE_TILE "Tile.INI"
 
 // Added by 337 2006/03/01
 #define USE_NORMAL_BGCOLOR

Modified: branches/theme/teraterm/common/tt_res.h
===================================================================
--- branches/theme/teraterm/common/tt_res.h	2022-06-25 16:12:49 UTC (rev 10020)
+++ branches/theme/teraterm/common/tt_res.h	2022-06-25 16:14:37 UTC (rev 10021)
@@ -146,6 +146,7 @@
 #define IDC_SCP_PATH                    2510
 #define IDC_BGIMG_EDIT                  2510
 #define IDC_ROTATE_SIZE                 2510
+#define IDC_THEME_EDIT                  2511
 #define IDC_CONFIRM_CHANGE_PASTE        2512
 #define IDC_CURSOR_CTRL_SEQ             2512
 #define IDC_LOG_ROTATE                  2512
@@ -174,6 +175,7 @@
 #define IDC_BGIMG_BUTTON                2528
 #define IDC_CLIPBOARD_ACCESS_LABEL      2529
 #define IDC_ROTATE_SIZE_TYPE            2529
+#define IDC_THEME_BUTTON                2529
 #define IDC_CLIPBOARD_ACCESS            2530
 #define IDC_ROTATE_STEP                 2530
 #define IDC_ROTATE_STEP_TEXT            2531
@@ -233,6 +235,9 @@
 #define IDC_SENDFILE_DELAYTIME_EDIT     2605
 #define IDC_SENDFILE_CHECK_4            2606
 #define IDC_SETUP_DIR_LIST              2607
+#define IDC_THEME_FILE                  2609
+#define IDC_TH_READ                     2610
+#define IDC_TH_WRITE                    2611
 #define ID_ACC_SENDBREAK                50001
 #define ID_ACC_COPY                     50002
 #define ID_ACC_NEWCONNECTION            50003
@@ -327,13 +332,13 @@
 #define ID_FILE_TERATERMMENU            52006
 
 // Next default values for new objects
-//
+// 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NO_MFC                     1
 #define _APS_NEXT_RESOURCE_VALUE        132
 #define _APS_NEXT_COMMAND_VALUE         52031
-#define _APS_NEXT_CONTROL_VALUE         2608
+#define _APS_NEXT_CONTROL_VALUE         2612
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif

Modified: branches/theme/teraterm/common/ttlib.h
===================================================================
--- branches/theme/teraterm/common/ttlib.h	2022-06-25 16:12:49 UTC (rev 10020)
+++ branches/theme/teraterm/common/ttlib.h	2022-06-25 16:14:37 UTC (rev 10021)
@@ -202,6 +202,7 @@
 BOOL ConvertIniFileCharCode(const wchar_t *fname,  const wchar_t *bak_str);
 wchar_t *MakeISO8601Str(time_t t);
 int KanjiCodeToISO8859Part(int kanjicode);
+void SaveBmpFromHDC(const wchar_t* fname, HDC hdc, int width, int height);
 
 #ifdef __cplusplus
 }

Modified: branches/theme/teraterm/common/ttlib_static_cpp.cpp
===================================================================
--- branches/theme/teraterm/common/ttlib_static_cpp.cpp	2022-06-25 16:12:49 UTC (rev 10020)
+++ branches/theme/teraterm/common/ttlib_static_cpp.cpp	2022-06-25 16:14:37 UTC (rev 10021)
@@ -1442,3 +1442,54 @@
 	wcsftime(date_str, _countof(date_str), L"%Y%m%dT%H%M%S%z", &now_tm);
 	return _wcsdup(date_str);
 }
+
+// base
+// https://www.daniweb.com/programming/software-development/threads/481786/saving-an-hdc-as-a-bmp-file
+void HDCToFile(const wchar_t* fname, HDC hdc, RECT Area, WORD BitsPerPixel = 24)
+{
+    LONG Width = Area.right - Area.left;
+    LONG Height = Area.bottom - Area.top;
+
+    BITMAPINFO Info;
+    BITMAPFILEHEADER Header;
+    memset(&Info, 0, sizeof(Info));
+    memset(&Header, 0, sizeof(Header));
+    Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+    Info.bmiHeader.biWidth = Width;
+    Info.bmiHeader.biHeight = Height;
+    Info.bmiHeader.biPlanes = 1;
+    Info.bmiHeader.biBitCount = BitsPerPixel;
+    Info.bmiHeader.biCompression = BI_RGB;
+    Info.bmiHeader.biSizeImage = Width * Height * (BitsPerPixel > 24 ? 4 : 3);
+    Header.bfType = 0x4D42;
+    Header.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
+
+    char* Pixels = NULL;
+    HDC MemDC = CreateCompatibleDC(hdc);
+    HBITMAP Section = CreateDIBSection(hdc, &Info, DIB_RGB_COLORS, (void**)&Pixels, 0, 0);
+    DeleteObject(SelectObject(MemDC, Section));
+    BitBlt(MemDC, 0, 0, Width, Height, hdc, Area.left, Area.top, SRCCOPY);
+    DeleteDC(MemDC);
+
+	FILE *fp;
+	_wfopen_s(&fp, fname, L"wb");
+    if (fp != NULL) {
+        fwrite((char*)&Header, sizeof(Header), 1, fp);
+		fwrite((char *)&Info.bmiHeader, sizeof(Info.bmiHeader),1, fp);
+		fwrite(Pixels, (((BitsPerPixel * Width + 31) & ~31) / 8) * Height, 1, fp);
+		fclose(fp);
+    }
+
+    DeleteObject(Section);
+}
+
+void SaveBmpFromHDC(const wchar_t* fname, HDC hdc, int width, int height)
+{
+	RECT rect;
+	rect.top = 0;
+	rect.left = 0;
+	rect.right = width;
+	rect.bottom = height;
+
+	HDCToFile(fname, hdc, rect);
+}

Modified: branches/theme/teraterm/common/tttypes.h
===================================================================
--- branches/theme/teraterm/common/tttypes.h	2022-06-25 16:12:49 UTC (rev 10020)
+++ branches/theme/teraterm/common/tttypes.h	2022-06-25 16:14:37 UTC (rev 10021)
@@ -321,15 +321,13 @@
 
 // Eterm lookfeel alphablend structure
 typedef struct {
-	int BGEnable;
+	int BGEnable;	// 0/1/2 = theme\x8Eg\x97p\x82\xB5\x82Ȃ\xA2/\x8CŒ\xE8\x83e\x81[\x83}/\x83\x89\x83\x93\x83_\x83\x80\x83e\x81[\x83}
 	int BGUseAlphaBlendAPI;
-	char BGSPIPath[MAX_PATH];
+	char reserve_BGSPIPath[MAX_PATH];
 	int BGFastSizeMove;
 	int BGNoCopyBits;
 	int BGNoFrame;
-	char BGThemeFile[MAX_PATH];
-	int BGIgnoreThemeFile;
-	char reserve[20];
+	char reserver_BGThemeFile[MAX_PATH - sizeof(wchar_t *) * 2];
 	wchar_t *BGThemeFileW;
 	wchar_t *BGSPIPathW;
 } eterm_lookfeel_t;
@@ -590,7 +588,7 @@
 	WORD KermitOpt;
 	WORD FontQuality;
 	char ScpSendDir[MAXPATHLEN];
-	char BGImageFilePath[MAX_PATH];
+	char reserver_BGImageFilePath[MAX_PATH];
 	int LogRotate;		//	enum rotate_mode LogRotate;
 	DWORD LogRotateSize;
 	WORD LogRotateSizeType;
@@ -610,7 +608,7 @@
 	int SendBreakTime;
 	WORD FileSendHighSpeedMode;
 	WORD AutoComPortReconnect;
-	WORD BGImgBrightness;
+	WORD reserver_BGImgBrightness;
 	cygterm_t CygtermSettings;
 	int XmodemTimeOutInit;
 	int XmodemTimeOutInitCRC;
@@ -650,7 +648,6 @@
 	wchar_t *ExeDirW;					// ttermpro.exe \x82̂\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_
 	wchar_t *LogDirW;					// log\x82\xE2\x83_\x83\x93\x83v\x82\xF0\x92u\x82\xAD\x83t\x83H\x83\x8B\x83_
 	wchar_t *FileDirW;					// \x83_\x83E\x83\x93\x83\x8D\x81[\x83h\x83p\x83X("%APPDATA%" \x93\x99\x82\xAA\x8A܂܂\xEA\x82\xE9,\x8Eg\x97p\x91O\x82Ɋ‹\xAB\x95ϐ\x94\x82\xF0\x93W\x8AJ\x82\xB7\x82邱\x82\xC6)
-	wchar_t *BGImageFilePathW;
 	wchar_t *LogDefaultPathW;			// \x83\x8D\x83O\x83t\x83H\x83\x8B\x83_([file]/[log]\x83\x81\x83j\x83\x85\x81[\x82̃\x8D\x83O)
 	HINSTANCE PluginVTIconInstance;
 	WORD PluginVTIconID;

Modified: branches/theme/teraterm/teraterm/addsetting.cpp
===================================================================
--- branches/theme/teraterm/teraterm/addsetting.cpp	2022-06-25 16:12:49 UTC (rev 10020)
+++ branches/theme/teraterm/teraterm/addsetting.cpp	2022-06-25 16:14:37 UTC (rev 10021)
@@ -649,7 +649,9 @@
 		{ IDC_ALPHABLEND, "DLG_TAB_VISUAL_ALPHA" },
 		{ IDC_ALPHA_BLEND_ACTIVE_LABEL, "DLG_TAB_VISUAL_ALPHA_ACTIVE" },
 		{ IDC_ALPHA_BLEND_INACTIVE_LABEL, "DLG_TAB_VISUAL_ALPHA_INACTIVE" },
+#if 0
 		{ IDC_ETERM_LOOKFEEL, "DLG_TAB_VISUAL_ETERM" },
+#endif
 		{ IDC_MIXED_THEME_FILE, "DLG_TAB_VISUAL_BGMIXED_THEMEFILE" },
 		{ IDC_BGIMG_CHECK, "DLG_TAB_VISUAL_BGIMG" },
 		{ IDC_BGIMG_BRIGHTNESS, "DLG_TAB_VISUAL_BGIMG_BRIGHTNESS" },
@@ -694,6 +696,22 @@
 	EnableDlgItem(IDC_ALPHA_BLEND_INACTIVE, isLayeredWindowSupported);
 	EnableDlgItem(IDC_ALPHA_BLEND_INACTIVE_TRACKBAR, isLayeredWindowSupported);
 
+	{
+		SendDlgItemMessageA(IDC_THEME_FILE, CB_ADDSTRING, 0, (LPARAM)"\x8Eg\x97p\x82\xB5\x82Ȃ\xA2");
+		SendDlgItemMessageA(IDC_THEME_FILE, CB_ADDSTRING, 1, (LPARAM)"\x8CŒ\xE8\x83e\x81[\x83}(\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x8Ew\x92\xE8)");
+		SendDlgItemMessageA(IDC_THEME_FILE, CB_ADDSTRING, 2, (LPARAM)"\x83\x89\x83\x93\x83_\x83\x80\x83e\x81[\x83}");
+		int sel = ts.EtermLookfeel.BGEnable;
+		if (sel < 0) sel = 0;
+		if (sel > 2) sel = 2;
+		SendDlgItemMessageA(IDC_THEME_FILE, CB_SETCURSEL, sel, 0);
+		BOOL enable = (sel == 1) ? TRUE : FALSE;
+		EnableDlgItem(IDC_THEME_EDIT, enable);
+		EnableDlgItem(IDC_THEME_BUTTON, enable);
+
+		SetDlgItemTextW(IDC_THEME_EDIT, ts.EtermLookfeel.BGThemeFileW);
+	}
+
+#if 0
 	// (2)[BG] BGEnable
 	SetCheck(IDC_ETERM_LOOKFEEL, ts.EtermLookfeel.BGEnable);
 
@@ -743,6 +761,7 @@
 
 		EnableDlgItem(IDC_MIXED_THEME_FILE, FALSE);
 	}
+#endif
 
 	// (3)Mouse cursor type
 	int sel = 0;
@@ -873,7 +892,16 @@
 	int sel;
 
 	switch (wParam) {
-	case IDC_ETERM_LOOKFEEL:
+		case IDC_THEME_FILE | (CBN_SELCHANGE << 16): {
+			int r = GetCurSel(IDC_THEME_FILE);
+			// \x8CŒ\xE8\x82̂Ƃ\xAB\x81A\x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x93\xFC\x97͂ł\xAB\x82\xE9\x82悤\x82ɂ\xB7\x82\xE9
+			BOOL enable = (r == 1) ? TRUE : FALSE;
+			EnableDlgItem(IDC_THEME_EDIT, enable);
+			EnableDlgItem(IDC_THEME_BUTTON, enable);
+			break;
+		}
+#if 0
+		case IDC_ETERM_LOOKFEEL:
 			// \x83`\x83F\x83b\x83N\x82\xB3\x82ꂽ\x82\xE7 Enable/Disable \x82\xF0\x83g\x83O\x83\x8B\x82\xB7\x82\xE9\x81B
 			if (GetCheck(IDC_ETERM_LOOKFEEL)) {
 				EnableDlgItem(IDC_MIXED_THEME_FILE, TRUE);
@@ -908,7 +936,6 @@
 				EnableDlgItem(IDC_MIXED_THEME_FILE, FALSE);
 			}
 			return TRUE;
-
 		case IDC_MIXED_THEME_FILE:
 			if (GetCheck(IDC_MIXED_THEME_FILE)) {
 				// \x94w\x8Ci\x89摜\x82̃`\x83F\x83b\x83N\x82͊O\x82\xB7\x81B
@@ -915,7 +942,6 @@
 				SetCheck(IDC_BGIMG_CHECK, BST_UNCHECKED);
 			}
 			return TRUE;
-
 		case IDC_BGIMG_CHECK:
 			if (GetCheck(IDC_BGIMG_CHECK)) {
 				EnableDlgItem(IDC_BGIMG_EDIT, TRUE);
@@ -941,12 +967,48 @@
 				SetDlgItemInt(IDC_EDIT_BGIMG_BRIGHTNESS, BG_THEME_IMAGE_BRIGHTNESS_DEFAULT);
 			}
 			return TRUE;
+#endif
+	case IDC_THEME_BUTTON | (BN_CLICKED << 16): {
+		// \x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82\xF0\x91I\x91\xF0\x82\xB7\x82\xE9
+		OPENFILENAMEW ofn = {};
+		wchar_t szFile[MAX_PATH];
+		wchar_t *curdir;
+		wchar_t *theme_dir;
+		hGetCurrentDirectoryW(&curdir);
 
+		if (GetFileAttributesW(ts.EtermLookfeel.BGThemeFileW) != INVALID_FILE_ATTRIBUTES) {
+			wcsncpy_s(szFile, _countof(szFile), ts.EtermLookfeel.BGThemeFileW, _TRUNCATE);
+		} else {
+			szFile[0] = 0;
+		}
+
+		aswprintf(&theme_dir, L"%s\\theme", ts.HomeDirW);
+
+		ofn.lStructSize = get_OPENFILENAME_SIZEW();
+		ofn.hwndOwner = GetSafeHwnd();
+		ofn.lpstrFilter = L"Theme Files(*.ini)\0*.ini\0All Files(*.*)\0*.*\0";
+		ofn.lpstrFile = szFile;
+		ofn.nMaxFile = _countof(szFile);
+		ofn.lpstrTitle = L"select theme file";
+		ofn.lpstrInitialDir = theme_dir;
+		ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
+		BOOL ok = GetOpenFileNameW(&ofn);
+		SetCurrentDirectoryW(curdir);
+		free(curdir);
+		free(theme_dir);
+		if (ok) {
+			SetDlgItemTextW(IDC_THEME_EDIT, szFile);
+		}
+		return TRUE;
+	}
+
 		case IDC_BGIMG_BUTTON | (BN_CLICKED << 16):
 			// \x94w\x8Ci\x89摜\x82\xF0\x83_\x83C\x83A\x83\x8D\x83O\x82Ŏw\x92肷\x82\xE9\x81B
 			{
 				OPENFILENAMEW ofn;
 				wchar_t szFile[MAX_PATH];
+				wchar_t *curdir;
+				hGetCurrentDirectoryW(&curdir);
 
 				memset(&ofn, 0, sizeof(ofn));
 				memset(szFile, 0, sizeof(szFile));
@@ -958,6 +1020,8 @@
 				ofn.lpstrTitle = L"select image file";
 				ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
 				BOOL ok = GetOpenFileNameW(&ofn);
+				SetCurrentDirectoryW(curdir);
+				free(curdir);
 				if (ok) {
 					SetDlgItemTextW(IDC_BGIMG_EDIT, szFile);
 				}
@@ -1119,6 +1183,7 @@
 	}
 
 	// (2)
+#if 0
 	// \x83O\x83\x8D\x81[\x83o\x83\x8B\x95ϐ\x94 BGEnable \x82𒼐ڏ\x91\x82\xAB\x8A\xB7\x82\xA6\x82\xE9\x82ƁA\x83v\x83\x8D\x83O\x83\x89\x83\x80\x82\xAA\x97\x8E\x82\xBF\x82邱\x82Ƃ\xAA
 	// \x82\xA0\x82\xE9\x82̂ŃR\x83s\x81[\x82\xF0\x8FC\x90\xB3\x82\xB7\x82\xE9\x82݂̂Ƃ\xB7\x82\xE9\x81B(2005.4.24 yutaka)
 	if (ts.EtermLookfeel.BGEnable != GetCheck(IDC_ETERM_LOOKFEEL)) {
@@ -1158,8 +1223,42 @@
 		// BG\x82\xAA\x96\xB3\x8C\xF8\x82̏ꍇ\x82̓f\x83t\x83H\x83\x8B\x83g\x82ɖ߂\xB5\x82Ă\xA8\x82\xAD\x81B
 		strncpy_s(ts.EtermLookfeel.BGThemeFile, BG_THEME_IMAGEFILE_DEFAULT, sizeof(ts.EtermLookfeel.BGThemeFile));
 	}
+#endif
+	{
+		int r = GetCurSel(IDC_THEME_FILE);
+		switch (r) {
+		default:
+			assert(FALSE);
+			// fall through
+		case 0:
+			ts.EtermLookfeel.BGEnable = 0;
+			break;
+		case 1: {
+			// \x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x8Ew\x92\xE8
+			ts.EtermLookfeel.BGEnable = 1;
 
+			wchar_t* theme_file;
+			hGetDlgItemTextW(m_hWnd, IDC_THEME_EDIT, &theme_file);
 
+			if (ts.EtermLookfeel.BGThemeFileW != NULL) {
+				free(ts.EtermLookfeel.BGThemeFileW);
+			}
+			ts.EtermLookfeel.BGThemeFileW = theme_file;
+			break;
+		}
+		case 2: {
+			// \x83\x89\x83\x93\x83_\x83\x80\x83e\x81[\x83}
+			ts.EtermLookfeel.BGEnable = 2;
+			if (ts.EtermLookfeel.BGThemeFileW != NULL) {
+				free(ts.EtermLookfeel.BGThemeFileW);
+			}
+			ts.EtermLookfeel.BGThemeFileW = NULL;
+			break;
+		}
+		}
+	}
+
+
 	// (3)
 	sel = GetCurSel(IDC_MOUSE_CURSOR);
 	if (sel >= 0 && sel < MOUSE_CURSOR_MAX) {

Modified: branches/theme/teraterm/teraterm/setupdirdlg.cpp
===================================================================
--- branches/theme/teraterm/teraterm/setupdirdlg.cpp	2022-06-25 16:12:49 UTC (rev 10020)
+++ branches/theme/teraterm/teraterm/setupdirdlg.cpp	2022-06-25 16:14:37 UTC (rev 10021)
@@ -451,9 +451,8 @@
  */
 static wchar_t *GetSusiePluginPath(const SetupList *, const TTTSet *pts)
 {
-	const char *spi_path = pts->EtermLookfeel.BGSPIPath;
 	wchar_t *path;
-	aswprintf(&path, L"%s\\%hs", pts->ExeDirW, spi_path);
+	aswprintf(&path, L"%s\\%s", pts->ExeDirW, pts->EtermLookfeel.BGSPIPathW);
 	return path;
 }
 

Modified: branches/theme/teraterm/teraterm/ttermpro.rc
===================================================================
--- branches/theme/teraterm/teraterm/ttermpro.rc	2022-06-25 16:12:49 UTC (rev 10020)
+++ branches/theme/teraterm/teraterm/ttermpro.rc	2022-06-25 16:14:37 UTC (rev 10021)
@@ -135,7 +135,7 @@
                     "Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,160,229,10
 END
 
-IDD_TABSHEET_VISUAL DIALOGEX 0, 0, 258, 221
+IDD_TABSHEET_VISUAL DIALOGEX 0, 0, 337, 282
 STYLE DS_SETFONT | DS_CONTROL | WS_CHILD | WS_SYSMENU
 FONT 8, "Tahoma", 0, 0, 0x0
 BEGIN
@@ -146,15 +146,15 @@
     LTEXT           "Ina&ctive",IDC_ALPHA_BLEND_INACTIVE_LABEL,7,45,60,12
     EDITTEXT        IDC_ALPHA_BLEND_INACTIVE,69,44,19,12,ES_AUTOHSCROLL | ES_NUMBER
     CONTROL         "",IDC_ALPHA_BLEND_INACTIVE_TRACKBAR,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,4,58,89,12
-    GROUPBOX        "",IDC_STATIC,97,2,155,70
-    CONTROL         "&Eterm lookfeel(*)",IDC_ETERM_LOOKFEEL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,99,8,74,12
+    GROUPBOX        "BG theme edit",IDC_STATIC,94,2,155,77,NOT WS_VISIBLE
+    CONTROL         "&Eterm lookfeel(*)",IDC_ETERM_LOOKFEEL,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,106,64,74,12
     CONTROL         "Mixed &ThemeFile to Background",IDC_MIXED_THEME_FILE,
-                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,103,21,115,10
-    LTEXT           "Image Brightness",IDC_BGIMG_BRIGHTNESS,166,32,56,8
-    EDITTEXT        IDC_EDIT_BGIMG_BRIGHTNESS,225,30,22,14,ES_AUTOHSCROLL | ES_NUMBER
-    CONTROL         "Background &Image",IDC_BGIMG_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,103,40,73,10
-    EDITTEXT        IDC_BGIMG_EDIT,103,51,108,14,ES_AUTOHSCROLL
-    PUSHBUTTON      "...",IDC_BGIMG_BUTTON,217,51,14,14
+                    "Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,99,51,115,10
+    LTEXT           "Image Brightness",IDC_BGIMG_BRIGHTNESS,112,39,56,8,NOT WS_VISIBLE
+    EDITTEXT        IDC_EDIT_BGIMG_BRIGHTNESS,172,37,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT WS_VISIBLE
+    CONTROL         "Background &Image",IDC_BGIMG_CHECK,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,100,12,73,10
+    EDITTEXT        IDC_BGIMG_EDIT,109,23,108,14,ES_AUTOHSCROLL | NOT WS_VISIBLE
+    PUSHBUTTON      "...",IDC_BGIMG_BUTTON,222,18,14,14,NOT WS_VISIBLE
     LTEXT           "&Mouse cursor",IDC_MOUSE,5,72,70,8
     COMBOBOX        IDC_MOUSE_CURSOR,13,81,80,66,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
     RTEXT           "&Font Quality",IDC_FONT_QUALITY_LABEL,102,82,61,12
@@ -178,9 +178,13 @@
                     "Button",BS_AUTOCHECKBOX | WS_TABSTOP,125,133,105,12
     CONTROL         "Enable A&NSI color",IDC_ENABLE_ANSI_COLOR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,125,145,105,12
     CONTROL         "Un&derline URL string",IDC_URL_UNDERLINE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,125,157,105,12
-    LTEXT           "(*)Need to Save setup and restart Tera Term",IDC_RESTART,15,172,237,8
+    LTEXT           "(*)Need to Save setup and restart Tera Term",IDC_RESTART,69,172,177,8,WS_DISABLED
     CONTROL         "FastSizeMove",IDC_CHECK_FAST_SIZE_MOVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,133,188,105,12
     CONTROL         "FlickerLessMove",IDC_CHECK_FLICKER_LESS_MOVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,133,200,105,12
+    COMBOBOX        IDC_THEME_FILE,22,229,120,55,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
+    EDITTEXT        IDC_THEME_EDIT,22,245,269,14,ES_AUTOHSCROLL
+    GROUPBOX        "BG theme(old Eterm lookfeel)",IDC_STATIC,13,217,304,48
+    PUSHBUTTON      "...",IDC_THEME_BUTTON,295,245,14,14
 END
 
 IDD_TABSHEET_LOG DIALOGEX 0, 0, 258, 188
@@ -391,10 +395,10 @@
     IDD_TABSHEET_VISUAL, DIALOG
     BEGIN
         LEFTMARGIN, 5
-        RIGHTMARGIN, 252
+        RIGHTMARGIN, 331
         VERTGUIDE, 48
         TOPMARGIN, 5
-        BOTTOMMARGIN, 218
+        BOTTOMMARGIN, 279
     END
 
     IDD_TABSHEET_LOG, DIALOG
@@ -489,14 +493,23 @@
 // Icon with lowest ID value placed first to ensure application icon
 // remains consistent on all systems.
 IDI_TTERM               ICON                    "../common/teraterm.ico"
+
 IDI_VT                  ICON                    "../common/vt.ico"
+
 IDI_TEK                 ICON                    "../common/tek.ico"
+
 IDI_TTERM_CLASSIC       ICON                    "../common/teraterm_classic.ico"
+
 IDI_VT_CLASSIC          ICON                    "../common/vt_classic.ico"
+
 IDI_TTERM_3D            ICON                    "../common/teraterm_3d.ico"
+
 IDI_VT_3D               ICON                    "../common/vt_3d.ico"
+
 IDI_TTERM_FLAT          ICON                    "../common/teraterm_flat.ico"
+
 IDI_VT_FLAT             ICON                    "../common/vt_flat.ico"
+
 IDI_CYGTERM             ICON                    "../../cygwin/cygterm/cygterm.ico"
 
 

Modified: branches/theme/teraterm/teraterm/vtdisp.c
===================================================================
--- branches/theme/teraterm/teraterm/vtdisp.c	2022-06-25 16:12:49 UTC (rev 10020)
+++ branches/theme/teraterm/teraterm/vtdisp.c	2022-06-25 16:14:37 UTC (rev 10021)
@@ -45,6 +45,7 @@
 #include "asprintf.h"
 #include "inifile_com.h"
 #include "win32helper.h"
+#include "ttknownfolders.h" // for FOLDERID_Desktop
 
 #include "vtdisp.h"
 
@@ -168,10 +169,8 @@
 static BGSrc BGSrc1;
 static BGSrc BGSrc2;
 
-int  BGEnable;
+static int  BGEnable;
 static int  BGReverseTextAlpha;
-static int  BGUseAlphaBlendAPI;
-static BOOL BGFastSizeMove;
 
 static COLORREF BGVTColor[2];
 static COLORREF BGVTBoldColor[2];
@@ -333,6 +332,46 @@
   DeleteObject(hBrush);
 }
 
+#if 0
+static void DebugSaveFile(const wchar_t* fname, HDC hdc, int width, int height)
+{
+	if (IsRelativePathW(fname)) {
+		wchar_t *desktop;
+		wchar_t *bmpfile;
+		_SHGetKnownFolderPath(&FOLDERID_Desktop, KF_FLAG_CREATE, NULL, &desktop);
+		bmpfile = NULL;
+		awcscats(&bmpfile, desktop, L"\\", fname, NULL);
+		free(desktop);
+		SaveBmpFromHDC(bmpfile, hdc, width, height);
+		free(bmpfile);
+	}
+	else {
+		SaveBmpFromHDC(fname, hdc, width, height);
+	}
+}
+#else
+static void DebugSaveFile(const wchar_t* fname, HDC hdc, int width, int height)
+{
+	(void)fname;
+	(void)hdc;
+	(void)width;
+	(void)height;
+}
+#endif
+
+
+/**
+ *	\x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x89\x83\x93\x83_\x83\x80\x82ɑI\x82\xD4
+ *
+ *	@param[in] filespec_src		\x93\xFC\x97̓t\x83@\x83C\x83\x8B\x96\xBC
+ *								\x83\x8F\x83C\x83\x8B\x83h\x83J\x81[\x83h("*","?"\x82Ȃ\xC7)\x82\xAA\x93\xFC\x82\xC1\x82Ă\xA2\x82Ă\xE0\x82悢\x81A\x82Ȃ\xAD\x82Ă\xE0\x82悢
+ *								\x83\x8F\x83C\x83\x8B\x83h\x83J\x81[\x83h\x82\xAA\x93\xFC\x82\xC1\x82Ă\xA2\x82\xE9\x82Ƃ\xAB\x82̓\x89\x83\x93\x83_\x83\x80\x82Ƀt\x83@\x83C\x83\x8B\x82\xAA\x8Fo\x97͂\xB3\x82\xEA\x82\xE9
+ *								\x83t\x83\x8B\x83p\x83X\x82łȂ\xAD\x82Ă\xE0\x82悢
+ *	@param[out]	filename		\x83t\x83\x8B\x83p\x83X\x83t\x83@\x83C\x83\x8B\x96\xBC
+ *								\x83J\x83\x8C\x83\x93\x83g\x83t\x83H\x83\x8B\x83_\x91\x8A\x91΂Ńt\x83\x8B\x83p\x83X\x82ɕϊ\xB7\x82\xB3\x82\xEA\x82\xE9
+ *								\x83t\x83@\x83C\x83\x8B\x82\xAA\x82Ȃ\xA2\x82Ƃ\xAB\x82\xCD [0] = NULL
+ *	@param[in]	destlen			filename \x82̗̈撷
+ */
 static void RandomFile(const char *filespec_src,char *filename, int destlen)
 {
   int    i;
@@ -343,15 +382,28 @@
   HANDLE hFind;
   WIN32_FIND_DATA fd;
 
-  ExpandEnvironmentStrings(filespec_src, filespec, sizeof(filespec));
+  //\x8A‹\xAB\x95ϐ\x94\x82\xF0\x93W\x8AJ
+  ExpandEnvironmentStringsA(filespec_src, filespec, sizeof(filespec));
 
   //\x90\xE2\x91΃p\x83X\x82ɕϊ\xB7
-  if(!GetFullPathName(filespec,MAX_PATH,fullpath,&filePart))
-    return;
+  if(!GetFullPathNameA(filespec,MAX_PATH,fullpath,&filePart)) {
+	filename[0] = 0;
+	return;
+  }
 
+  //\x83t\x83@\x83C\x83\x8B\x82\xAA\x91\xB6\x8D݂\xB5\x82Ă\xA2\x82邩?
+  if (GetFileAttributesA(fullpath) != INVALID_FILE_ATTRIBUTES) {
+	// \x83}\x83X\x83N("*.jpg"\x82Ȃ\xC7)\x82\xAA\x82Ȃ\xAD\x83t\x83@\x83C\x83\x8B\x82\xAA\x92\xBC\x90ڎw\x92肵\x82Ă\xA0\x82\xE9\x8Fꍇ
+	strncpy_s(filename,destlen,fullpath,_TRUNCATE);
+	return;
+  }
+
   //\x83t\x83@\x83C\x83\x8B\x82𐔂\xA6\x82\xE9
   hFind = FindFirstFile(fullpath,&fd);
-
+  if (hFind == INVALID_HANDLE_VALUE) {
+	filename[0] = 0;
+	return;
+  }
   file_num = 0;
 
   if(hFind != INVALID_HANDLE_VALUE && filePart)
@@ -404,6 +456,7 @@
     strncpy_s(filename,destlen,tmp,_TRUNCATE);
   }
 
+#if 0
   // \x83A\x83h\x83z\x83b\x83N\x82ł͂\xA0\x82邪\x81AImageFile.INI\x82Ȃ\xE7\x95ʖ\xBC\x82ɂ\xB7\x82\xE9\x81B
   // ImageFile.INI\x82̓e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82Ƃ\xB5\x82Ďg\x82\xA6\x82Ȃ\xA2\x82\xBD\x82߁B
   if (strcmp(filespec_src, BG_THEME_IMAGEFILE_DEFAULT) == 0) {
@@ -411,10 +464,20 @@
 		  _snprintf_s(fd.cFileName, sizeof(fd.cFileName), _TRUNCATE, "%s", BG_THEME_THEMEFILE_SCALE);
 	  }
   }
+#endif
 
   strncat_s(filename,destlen,fd.cFileName,_TRUNCATE);
 }
 
+static wchar_t *RandomFileW(const wchar_t *filespecW)
+{
+	char filespecA[MAX_PATH];
+	char filenameA[MAX_PATH];
+	WideCharToACP_t(filespecW, filespecA, _countof(filespecA));
+	RandomFile(filespecA, filenameA, _countof(filenameA));
+	return ToWcharA(filenameA);
+}
+
 static BOOL SaveBitmapFile(const char *nameFile,unsigned char *pbuf,BITMAPINFO *pbmi)
 {
   int    bmiSize;
@@ -462,16 +525,14 @@
   return TRUE;
 }
 
-static BOOL LoadWithSPI(const char *src, const char *spi_path, const char *out)
+static BOOL LoadWithSPI(const char *src, const wchar_t *spi_path, const char *out)
 {
 	HANDLE hbmi;
 	HANDLE hbuf;
 	BOOL r;
-	wchar_t *spi_pathW = ToWcharA(spi_path);
 	wchar_t *srcW = ToWcharA(src);
 
-	r = SusieLoadPicture(srcW, spi_pathW, &hbmi, &hbuf);
-	free(spi_pathW);
+	r = SusieLoadPicture(srcW, spi_path, &hbmi, &hbuf);
 	free(srcW);
 	if (r == FALSE) {
 		return FALSE;
@@ -524,7 +585,7 @@
 {
   HBITMAP hbm;
   char *load_file = src->file;
-  const char *spi_path = ts.EtermLookfeel.BGSPIPath;
+  const wchar_t *spi_path = ts.EtermLookfeel.BGSPIPathW;
 
   if (LoadWithSPI(src->file, spi_path, src->fileTmp) == TRUE) {
 	  load_file = src->fileTmp;
@@ -1162,6 +1223,7 @@
 
     //\x94w\x8Ci\x90\xB6\x90\xAC
     BGLoadSrc(hdcBG,&BGDest);
+    DebugSaveFile(L"bg_1.bmp", hdcBG, ScreenWidth, ScreenHeight);
 
     ZeroMemory(&bf,sizeof(bf));
     bf.BlendOp = AC_SRC_OVER;
@@ -1172,6 +1234,7 @@
       BGLoadSrc(hdcSrc,&BGSrc1);
       (BGAlphaBlend)(hdcBG,0,0,ScreenWidth,ScreenHeight,hdcSrc,0,0,ScreenWidth,ScreenHeight,bf);
     }
+    DebugSaveFile(L"bg_2.bmp", hdcBG, ScreenWidth, ScreenHeight);
 
     bf.SourceConstantAlpha = BGSrc2.alpha;
     if(bf.SourceConstantAlpha)
@@ -1179,6 +1242,7 @@
       BGLoadSrc(hdcSrc,&BGSrc2);
       (BGAlphaBlend)(hdcBG,0,0,ScreenWidth,ScreenHeight,hdcSrc,0,0,ScreenWidth,ScreenHeight,bf);
     }
+    DebugSaveFile(L"bg_3.bmp", hdcBG, ScreenWidth, ScreenHeight);
 
     DeleteBitmapDC(&hdcSrc);
   }
@@ -1277,34 +1341,83 @@
 	/* end - ishizaki */
 }
 
+static void WriteInt(PCHAR Sect, PCHAR Key, const wchar_t *FName, int i)
+{
+	char Temp[15];
+	_snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%d", i);
+	WritePrivateProfileStringAFileW(Sect, Key, Temp, FName);
+}
+
+void BGWriteThemeFile(const wchar_t *theme_file)
+{
+	WritePrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, BGDest.file, theme_file);
+	BGSrc1.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", BGSrc1.alpha, theme_file);
+	WriteInt(BG_SECTION, BG_THEME_IMAGE_BRIGHTNESS1, theme_file, BGSrc1.alpha);
+	WriteInt(BG_SECTION, BG_THEME_IMAGE_BRIGHTNESS2, theme_file, BGSrc2.alpha);
+}
+
+/**
+ *	\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82̓ǂݍ\x9E\x82\xDD
+ */
 static void BGReadIniFile(const wchar_t *file)
 {
+	wchar_t *dir;
+	wchar_t *prevDir;
 	char path[MAX_PATH];
 
-	// Easy Setting
-	BGDest.pattern = BGGetPattern("BGPicturePattern", BGSrc1.pattern, file);
-	BGDest.color = BGGetColor("BGPictureBaseColor", BGSrc1.color, file);
+	// \x83J\x83\x8C\x83\x93\x83g\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82\xF0\x95ۑ\xB6
+	hGetCurrentDirectoryW(&prevDir);
 
-	GetPrivateProfileStringAFileW(BG_SECTION, "BGPictureFile", BGSrc1.file, path, MAX_PATH, file);
-	RandomFile(path, BGDest.file, sizeof(BGDest.file));
+	// \x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82̂\xA0\x82\xE9\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82Ɉꎞ\x93I\x82Ɉړ\xAE
+	//		\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x91\x8A\x91΃p\x83X\x82œǂݍ\x9E\x82߂\xE9\x82悤
+	dir = ExtractDirNameW(file);
+	SetCurrentDirectoryW(dir);
+	free(dir);
 
-	BGSrc1.alpha = 255 - GetPrivateProfileIntAFileW(BG_SECTION, "BGPictureTone", 255 - BGSrc1.alpha, file);
+	//\x83f\x83t\x83H\x83\x8B\x83g\x92l
+	BGDest.type = BG_PICTURE;
+	BGDest.pattern = BG_STRETCH;
+	BGDest.color = RGB(0, 0, 0);
+	BGDest.antiAlias = TRUE;
+	strncpy_s(BGDest.file, sizeof(BGDest.file), "", _TRUNCATE);
 
-	if (!strcmp(BGDest.file, ""))
-		BGSrc1.alpha = 255;
+	BGSrc1.type = BG_WALLPAPER;
+	BGSrc1.pattern = BG_STRETCH;
+	BGSrc1.color = RGB(255, 255, 255);
+	BGSrc1.antiAlias = TRUE;
+	BGSrc1.alpha = 255;
+	strncpy_s(BGSrc1.file, sizeof(BGSrc1.file), "", _TRUNCATE);
 
-	BGSrc2.alpha = 255 - GetPrivateProfileIntAFileW(BG_SECTION, "BGFadeTone", 255 - BGSrc2.alpha, file);
-	BGSrc2.color = BGGetColor("BGFadeColor", BGSrc2.color, file);
+	BGSrc2.type = BG_COLOR;
+	BGSrc2.pattern = BG_STRETCH;
+	BGSrc2.color = RGB(0, 0, 0);
+	BGSrc2.antiAlias = TRUE;
+	BGSrc2.alpha = 128;
+	strncpy_s(BGSrc2.file, sizeof(BGSrc2.file), "", _TRUNCATE);
 
-	BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextTone", BGReverseTextAlpha, file);
+	BGReverseTextAlpha = 255;
 
+	// Dest \x82̓ǂݏo\x82\xB5
+	BGDest.type = BGGetType("BGDestType", BGDest.type, file);
+	BGDest.pattern = BGGetPattern("BGPicturePattern", BGSrc1.pattern, file);
+	BGDest.pattern = BGGetPattern("BGDestPattern", BGDest.pattern, file);
+	BGDest.antiAlias = BGGetOnOff("BGDestAntiAlias", BGDest.antiAlias, file);
+	BGDest.color = BGGetColor("BGPictureBaseColor", BGDest.color, file);
+	BGDest.color = BGGetColor("BGDestColor", BGDest.color, file);
+	GetPrivateProfileStringAFileW(BG_SECTION, "BGPictureFile", BGDest.file, path, MAX_PATH, file);
+	strcpy_s(BGDest.file, _countof(BGDest.file), path);
+	GetPrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, BGDest.file, path, MAX_PATH, file);
+	RandomFile(path, BGDest.file, sizeof(BGDest.file));
+
 	// Src1 \x82̓ǂݏo\x82\xB5
 	BGSrc1.type = BGGetType("BGSrc1Type", BGSrc1.type, file);
 	BGSrc1.pattern = BGGetPattern("BGSrc1Pattern", BGSrc1.pattern, file);
 	BGSrc1.antiAlias = BGGetOnOff("BGSrc1AntiAlias", BGSrc1.antiAlias, file);
+	BGSrc1.alpha = 255 - GetPrivateProfileIntAFileW(BG_SECTION, "BGPictureTone", 255 - BGSrc1.alpha, file);
+	if (!strcmp(BGDest.file, ""))
+		BGSrc1.alpha = 255;
 	BGSrc1.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc1Alpha", BGSrc1.alpha, file);
 	BGSrc1.color = BGGetColor("BGSrc1Color", BGSrc1.color, file);
-
 	GetPrivateProfileStringAFileW(BG_SECTION, "BGSrc1File", BGSrc1.file, path, MAX_PATH, file);
 	RandomFile(path, BGSrc1.file, sizeof(BGSrc1.file));
 
@@ -1312,24 +1425,21 @@
 	BGSrc2.type = BGGetType("BGSrc2Type", BGSrc2.type, file);
 	BGSrc2.pattern = BGGetPattern("BGSrc2Pattern", BGSrc2.pattern, file);
 	BGSrc2.antiAlias = BGGetOnOff("BGSrc2AntiAlias", BGSrc2.antiAlias, file);
+	BGSrc2.alpha = 255 - GetPrivateProfileIntAFileW(BG_SECTION, "BGFadeTone", 255 - BGSrc2.alpha, file);
 	BGSrc2.alpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGSrc2Alpha", BGSrc2.alpha, file);
+	BGSrc2.color = BGGetColor("BGFadeColor", BGSrc2.color, file);
 	BGSrc2.color = BGGetColor("BGSrc2Color", BGSrc2.color, file);
-
 	GetPrivateProfileStringAFileW(BG_SECTION, "BGSrc2File", BGSrc2.file, path, MAX_PATH, file);
 	RandomFile(path, BGSrc2.file, sizeof(BGSrc2.file));
 
-	// Dest \x82̓ǂݏo\x82\xB5
-	BGDest.type = BGGetType("BGDestType", BGDest.type, file);
-	BGDest.pattern = BGGetPattern("BGDestPattern", BGDest.pattern, file);
-	BGDest.antiAlias = BGGetOnOff("BGDestAntiAlias", BGDest.antiAlias, file);
-	BGDest.color = BGGetColor("BGDestColor", BGDest.color, file);
-
-	GetPrivateProfileStringAFileW(BG_SECTION, BG_DESTFILE, BGDest.file, path, MAX_PATH, file);
-	RandomFile(path, BGDest.file, sizeof(BGDest.file));
-
 	//\x82\xBB\x82̑\xBC\x93ǂݏo\x82\xB5
+	BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextTone", BGReverseTextAlpha, file);
 	BGReverseTextAlpha = GetPrivateProfileIntAFileW(BG_SECTION, "BGReverseTextAlpha", BGReverseTextAlpha, file);
 	BGReadTextColorConfig(file);
+
+	// \x83J\x83\x8C\x83\x93\x83g\x83t\x83H\x83\x8B\x83_\x82\xF0\x8C\xB3\x82ɖ߂\xB7
+	SetCurrentDirectoryW(prevDir);
+	free(prevDir);
 }
 
 static void BGDestruct(void)
@@ -1359,11 +1469,8 @@
  */
 void BGInitialize(BOOL initialize_once)
 {
-	char path[MAX_PATH];
-	char config_file[MAX_PATH];
+	(void)initialize_once;
 
-	ZeroMemory(config_file, sizeof(config_file));
-
 	// VTColor \x82\xF0\x93ǂݍ\x9E\x82\xDD
 	BGVTColor[0] = ts.VTColor[0];
 	BGVTColor[1] = ts.VTColor[1];
@@ -1387,6 +1494,12 @@
 	BGDestruct();
 
 	// BG \x82\xAA\x97L\x8C\xF8\x82\xA9\x83`\x83F\x83b\x83N
+	BGEnable = ts.EtermLookfeel.BGEnable;
+	if (!BGEnable)
+		return;
+
+#if 0
+	// BG \x82\xAA\x97L\x8C\xF8\x82\xA9\x83`\x83F\x83b\x83N
 	//  \x8B\xF3\x82̏ꍇ\x82̂݁A\x83f\x83B\x83X\x83N\x82\xA9\x82\xE7\x93ǂށBBGInitialize()\x82\xAA Tera Term \x8BN\x93\xAE\x8E\x9E\x88ȊO\x82ɂ\xE0\x81A
 	//  Additional settings \x82\xA9\x82\xE7\x8CĂяo\x82\xB3\x82\xEA\x82邱\x82Ƃ\xAA\x82\xA0\x82邽\x82߁B
 	if (ts.EtermLookfeel.BGThemeFile[0] == '\0') {
@@ -1409,10 +1522,7 @@
 		// \x83e\x81[\x83}\x83t\x83@\x83C\x83\x8BImageFile.INI\x82\xA9\x82\xE7
 		aswprintf(&theme_imagefile, L"%s\\%hs", ts.HomeDirW, BG_THEME_IMAGEFILE);
 
-		// \x94w\x8Ci\x89摜\x82̓ǂݍ\x9E\x82\xDD
-		hGetPrivateProfileStringW(BG_SECTIONW, BG_DESTFILEW, L"", theme_imagefile, &ts.BGImageFilePathW);
-		WideCharToACP_t(ts.BGImageFilePathW, ts.BGImageFilePath, _countof(ts.BGImageFilePath));
-
+		// \x8Eg\x82\xED\x82\xEA\x82Ă\xA2\x82Ȃ\xA2\x81A\x95s\x97v
 		// \x94w\x8Ci\x89摜\x82̖\xBE\x82邳\x82̓ǂݍ\x9E\x82݁B
 		// BGSrc1Alpha \x82\xC6 BGSrc2Alpha\x82͓\xAF\x92l\x82Ƃ\xB5\x82Ĉ\xB5\x82\xA4\x81B
 		ts.BGImgBrightness =
@@ -1427,18 +1537,12 @@
 		// Tera Term\x8BN\x93\xAE\x8E\x9E\x82Ɉ\xEA\x93x\x82\xBE\x82\xAF\x93ǂށB
 		ts.EtermLookfeel.BGIgnoreThemeFile = BGGetOnOff("BGIgnoreThemeFile", FALSE, ts.SetupFNameW);
 	}
+#endif
 
-	if (!BGEnable)
-		return;
-
 	//\x97\x90\x90\x94\x8F\x89\x8A\xFA\x89\xBB
 	// add cast (2006.2.18 yutaka)
 	srand((unsigned int)time(NULL));
 
-	// BG\x83V\x83X\x83e\x83\x80\x90ݒ\xE8\x93ǂݏo\x82\xB5
-	BGUseAlphaBlendAPI = ts.EtermLookfeel.BGUseAlphaBlendAPI;
-	BGFastSizeMove = ts.EtermLookfeel.BGFastSizeMove;
-
 	//\x83e\x83\x93\x83|\x83\x89\x83\x8A\x81[\x83t\x83@\x83C\x83\x8B\x96\xBC\x82𐶐\xAC
 	{
 		char tempPath[MAX_PATH];
@@ -1449,63 +1553,23 @@
 		GetTempFileNameA(tempPath, "ttAK", 0, BGSrc2.fileTmp);
 	}
 
-	//\x83f\x83t\x83H\x83\x8B\x83g\x92l
-	BGDest.type = BG_PICTURE;
-	BGDest.pattern = BG_STRETCH;
-	BGDest.color = RGB(0, 0, 0);
-	BGDest.antiAlias = TRUE;
-	strncpy_s(BGDest.file, sizeof(BGDest.file), "", _TRUNCATE);
-
-	BGSrc1.type = BG_WALLPAPER;
-	BGSrc1.pattern = BG_STRETCH;
-	BGSrc1.color = RGB(255, 255, 255);
-	BGSrc1.antiAlias = TRUE;
-	BGSrc1.alpha = 255;
-	strncpy_s(BGSrc1.file, sizeof(BGSrc1.file), "", _TRUNCATE);
-
-	BGSrc2.type = BG_COLOR;
-	BGSrc2.pattern = BG_STRETCH;
-	BGSrc2.color = RGB(0, 0, 0);
-	BGSrc2.antiAlias = TRUE;
-	BGSrc2.alpha = 128;
-	strncpy_s(BGSrc2.file, sizeof(BGSrc2.file), "", _TRUNCATE);
-
-	BGReverseTextAlpha = 255;
-
 	//\x90ݒ\xE8\x82̓ǂݏo\x82\xB5
 	BGReadIniFile(ts.SetupFNameW);
 
-	//\x83R\x83\x93\x83t\x83B\x83O\x83t\x83@\x83C\x83\x8B\x82̌\x88\x92\xE8
-	GetPrivateProfileStringAFileW(BG_SECTION, "BGThemeFile", "", path, MAX_PATH, ts.SetupFNameW);
-	RandomFile(path, config_file, sizeof(config_file));
-
-	// ImageFile.INI\x82ł͂Ȃ\xA2\x8Fꍇ\x82̓\x89\x83\x93\x83_\x83\x80\x82ɑI\x82ԁB
-	if (strstr(path, BG_THEME_IMAGEFILE_NAME) == NULL) {
-		// \x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82𖳎\x8B\x82\xB7\x82\xE9\x8Fꍇ\x82͋\xF3\x82ɂ\xB7\x82\xE9\x81B
-		if (ts.EtermLookfeel.BGIgnoreThemeFile) {
-			ZeroMemory(config_file, sizeof(config_file));
-		}
+	// \x83R\x83\x93\x83t\x83B\x83O\x83t\x83@\x83C\x83\x8B(\x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B)\x82̌\x88\x92\xE8
+	if (ts.EtermLookfeel.BGEnable == 1 && ts.EtermLookfeel.BGThemeFileW != NULL) {
+		// \x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82̎w\x92肪\x82\xA0\x82\xE9
+		BGReadIniFile(ts.EtermLookfeel.BGThemeFileW);
 	}
-
-	//\x90ݒ\xE8\x82̃I\x81[\x83o\x81[\x83\x89\x83C\x83h
-	if (strcmp(config_file, "")) {
-		wchar_t *dir;
-		wchar_t *prevDir;
-		wchar_t *config_fileW;
-
-		hGetCurrentDirectoryW(&prevDir);
-
-		// INI\x83t\x83@\x83C\x83\x8B\x82̂\xA0\x82\xE9\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82Ɉꎞ\x93I\x82Ɉړ\xAE
-		config_fileW = ToWcharA(config_file);
-		dir = ExtractDirNameW(config_fileW);
-		SetCurrentDirectoryW(dir);
-		free(dir);
-
-		BGReadIniFile(config_fileW);
-
-		// \x83J\x83\x8C\x83\x93\x83g\x83t\x83H\x83\x8B\x83_\x82\xF0\x8C\xB3\x82ɖ߂\xB7
-		SetCurrentDirectoryW(prevDir);
-		free(prevDir);
+	else {
+		// \x83\x89\x83\x93\x83_\x83\x80\x83e\x81[\x83} (or \x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82\xF0\x8Ew\x92肪\x82Ȃ\xA2)
+		wchar_t *theme_mask;
+		wchar_t *theme_file;
+		aswprintf(&theme_mask, L"%s\\theme\\*.ini", ts.HomeDirW);
+		theme_file = RandomFileW(theme_mask);
+		free(theme_mask);
+		BGReadIniFile(theme_file);
+		free(theme_file);
 	}
 
 	//\x95ǎ\x86 or \x94w\x8Ci\x82\xF0\x83v\x83\x8A\x83\x8D\x81[\x83h
@@ -1514,7 +1578,7 @@
 	BGPreloadSrc(&BGSrc2);
 
 	// AlphaBlend \x82̃A\x83h\x83\x8C\x83X\x82\xF0\x93ǂݍ\x9E\x82\xDD
-	if (BGUseAlphaBlendAPI) {
+	if (ts.EtermLookfeel.BGUseAlphaBlendAPI) {
 		if (pAlphaBlend != NULL)
 			BGAlphaBlend = pAlphaBlend;
 		else
@@ -1598,7 +1662,7 @@
 {
   int  r,g,b;
 
-  if(!BGEnable || !BGFastSizeMove)
+  if(!BGEnable || !ts.EtermLookfeel.BGFastSizeMove)
     return;
 
   BGInSizeMove = TRUE;
@@ -1621,7 +1685,7 @@
 
 void BGOnExitSizeMove(void)
 {
-  if(!BGEnable || !BGFastSizeMove)
+  if(!BGEnable || !ts.EtermLookfeel.BGFastSizeMove)
     return;
 
   BGInSizeMove = FALSE;

Modified: branches/theme/teraterm/teraterm/vtdisp.h
===================================================================
--- branches/theme/teraterm/teraterm/vtdisp.h	2022-06-25 16:12:49 UTC (rev 10020)
+++ branches/theme/teraterm/teraterm/vtdisp.h	2022-06-25 16:14:37 UTC (rev 10021)
@@ -39,6 +39,7 @@
 //<!--by AKASI
 void BGInitialize(BOOL initialize_once);
 void BGSetupPrimary(BOOL);
+void BGWriteThemeFile(const wchar_t *theme_file);
 
 void BGExchangeColor(void);
 
@@ -46,7 +47,7 @@
 void BGOnEnterSizeMove(void);
 void BGOnExitSizeMove(void);
 
-extern BOOL BGEnable;
+//extern BOOL BGEnable;
 //-->
 
 void InitDisp(void);

Modified: branches/theme/teraterm/teraterm/vtwin.cpp
===================================================================
--- branches/theme/teraterm/teraterm/vtwin.cpp	2022-06-25 16:12:49 UTC (rev 10020)
+++ branches/theme/teraterm/teraterm/vtwin.cpp	2022-06-25 16:14:37 UTC (rev 10021)
@@ -2803,7 +2803,7 @@
 LRESULT CVTWindow::OnWindowPosChanging(WPARAM wParam, LPARAM lParam)
 {
 #ifdef ALPHABLEND_TYPE2
-	if(BGEnable && ts.EtermLookfeel.BGNoCopyBits) {
+	if(ts.EtermLookfeel.BGEnable && ts.EtermLookfeel.BGNoCopyBits) {
 		((WINDOWPOS*)lParam)->flags |= SWP_NOCOPYBITS;
 	}
 #endif

Modified: branches/theme/teraterm/ttpset/ttset.c
===================================================================
--- branches/theme/teraterm/ttpset/ttset.c	2022-06-25 16:12:49 UTC (rev 10020)
+++ branches/theme/teraterm/ttpset/ttset.c	2022-06-25 16:14:37 UTC (rev 10021)
@@ -740,10 +740,47 @@
  */
 static void DispReadIni(const wchar_t *FName, PTTSet ts)
 {
+	wchar_t *base;
+	ts->EtermLookfeel.BGEnable = GetPrivateProfileInt(BG_SECTION, "BGEnable", 0, FName);
 	ts->EtermLookfeel.BGUseAlphaBlendAPI = GetOnOff(BG_SECTION, "BGUseAlphaBlendAPI", FName, TRUE);
 	ts->EtermLookfeel.BGNoFrame = GetOnOff(BG_SECTION, "BGNoFrame", FName, FALSE);
 	ts->EtermLookfeel.BGFastSizeMove = GetOnOff(BG_SECTION, "BGFastSizeMove", FName, TRUE);
 	ts->EtermLookfeel.BGNoCopyBits = GetOnOff(BG_SECTION, "BGFlickerlessMove", FName, TRUE);
+	if (ts->EtermLookfeel.BGSPIPathW != NULL) {
+		free(ts->EtermLookfeel.BGSPIPathW);
+	}
+	hGetPrivateProfileStringW(BG_SECTIONW, L"BGSPIPath", L"plugin", FName, &base);
+	if (base[0] == 0) {
+		free(base);
+		ts->EtermLookfeel.BGSPIPathW = NULL;
+	}
+	else {
+		wchar_t *full;
+		if (IsRelativePathW(base)) {
+			aswprintf(&full, L"%s\\%s", ts->HomeDirW, base);
+			ts->EtermLookfeel.BGSPIPathW = full;
+			free(base);
+		}
+		else {
+			ts->EtermLookfeel.BGSPIPathW = base;
+		}
+	}
+	hGetPrivateProfileStringW(BG_SECTIONW, L"BGThemeFile", L"", FName, &base);
+	if (base[0] == 0) {
+		free(base);
+		ts->EtermLookfeel.BGThemeFileW = NULL;
+	}
+	else {
+		if (IsRelativePathW(base)) {
+			wchar_t *full;
+			aswprintf(&full, L"%s\\%s", ts->HomeDirW, base);
+			ts->EtermLookfeel.BGThemeFileW = full;
+			free(base);
+		}
+		else {
+			ts->EtermLookfeel.BGThemeFileW = base;
+		}
+	}
 }
 
 /**
@@ -752,10 +789,14 @@
  */
 static void DispWriteIni(const wchar_t *FName, PTTSet ts)
 {
+	// Eterm lookfeel alphablend (theme file)
+	WriteInt(BG_SECTION, "BGEnable", FName, ts->EtermLookfeel.BGEnable);
+	WritePrivateProfileStringW(BG_SECTIONW, L"BGThemeFile",
+	                          ts->EtermLookfeel.BGThemeFileW, FName);
 	WriteOnOff(BG_SECTION, "BGUseAlphaBlendAPI", FName,
 	           ts->EtermLookfeel.BGUseAlphaBlendAPI);
-	WritePrivateProfileString(BG_SECTION, "BGSPIPath",
-	                          ts->EtermLookfeel.BGSPIPath, FName);
+	WritePrivateProfileStringW(BG_SECTIONW, L"BGSPIPath",
+	                          ts->EtermLookfeel.BGSPIPathW, FName);
 	WriteOnOff(BG_SECTION, "BGFastSizeMove", FName,
 	           ts->EtermLookfeel.BGFastSizeMove);
 	WriteOnOff(BG_SECTION, "BGFlickerlessMove", FName,
@@ -3108,12 +3149,6 @@
 
 	DispWriteIni(FName, ts);
 
-	// Eterm lookfeel alphablend (2005.4.24 yutaka)
-	WriteOnOff(BG_SECTION, "BGEnable", FName,
-	           ts->EtermLookfeel.BGEnable);
-	WritePrivateProfileString(BG_SECTION, "BGThemeFile",
-	                          ts->EtermLookfeel.BGThemeFile, FName);
-
 	// theme\x83t\x83H\x83\x8B\x83_\x82\xF0\x8D\xEC\x82\xE9
 	{
 		wchar_t *theme_folder = NULL;
@@ -3124,6 +3159,7 @@
 
 	// \x83e\x81[\x83}\x83t\x83@\x83C\x83\x8B\x82ɕۑ\xB6("theme\\ImageFile.INI")
 	//		TODO BGThemeFile\x82̓`\x83F\x83b\x83N\x82\xB5\x82Ȃ\xAD\x82Ă悢?
+#if 0
 	{
 		wchar_t *theme_file = NULL;
 		aswprintf(&theme_file, L"%s\\%hs", ts->HomeDirW, BG_THEME_IMAGEFILE);
@@ -3132,10 +3168,8 @@
 		WriteInt(BG_SECTION, BG_THEME_IMAGE_BRIGHTNESS2, theme_file, ts->BGImgBrightness);
 		free(theme_file);
 	}
+#endif
 
-	WriteOnOff(BG_SECTION, "BGIgnoreThemeFile", FName,
-		ts->EtermLookfeel.BGIgnoreThemeFile);
-
 #ifdef USE_NORMAL_BGCOLOR
 	// UseNormalBGColor
 	WriteOnOff(Section, "UseNormalBGColor", FName, ts->UseNormalBGColor);


ttssh2-commit メーリングリストの案内
Back to archive index