Skip to content

Commit fc74cd0

Browse files
committed
- Add /blank command line parameter to avoid creating any default drawable objects.
- If all drawable objects have been deleted by the user, ensure at least one drawable object is created upon loading a font file or dragping&dropping.
1 parent caefd34 commit fc74cd0

2 files changed

Lines changed: 54 additions & 33 deletions

File tree

MainWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class MainWindow
6262

6363
struct FontFamilyNameProperties;
6464

65+
void InitializeDefaultDrawableObjects();
6566
HRESULT LoadTextFileIntoDrawableObjects(_In_z_ char16_t const* filePath);
6667
HRESULT StoreTextFileFromDrawableObjects(_In_z_ char16_t const* filePath);
6768
HRESULT LoadFontFileIntoDrawableObjects(_In_z_ char16_t const* filePath);
@@ -89,6 +90,7 @@ class MainWindow
8990
void UpdateDrawableObjectsListView();
9091
void DeleteDrawableObjectsListViewSelected();
9192
void CreateDrawableObjectsListViewSelected();
93+
void EnsureAtLeastOneDrawableObject();
9294
void ShiftSelectedDrawableObjects(int32_t shiftDirection /* down = positive, up = negative */);
9395
HRESULT LoadDrawableObjectsSettings(bool clearExistingItems = true, bool merge = false);
9496
HRESULT StoreDrawableObjectsSettings();

MainWindow.ixx

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ int APIENTRY wWinMain(
9494
Application::g_hModule = hInstance;
9595

9696
_wsetlocale(LC_ALL, L""); // Unicode, not ANSI!
97+
bool wantBlankCanvas = false;
9798

9899
////////////////////
99100
// Read command line parameters.
@@ -112,12 +113,16 @@ int APIENTRY wWinMain(
112113
MessageBox(nullptr, L"TextLayoutSampler.exe [SomeFile.TextLayoutSamplerSettings].", APPLICATION_TITLE, MB_OK);
113114
return (int)0;
114115
}
116+
else if (_wcsicmp(ToWChar(trimmedCommandLine.c_str()), L"/blank") == 0)
117+
{
118+
wantBlankCanvas = true;
119+
}
115120
else if (trimmedCommandLine[0] == '/')
116121
{
117122
Application::Fail(trimmedCommandLine.c_str(), u"Unknown command line option.\r\n\r\n\"%s\"", 0);
118123
}
119124
UnquoteString(IN OUT trimmedCommandLine);
120-
// Else just pass the command line to the main window.
125+
// Else just pass parse command line as a settings file name.
121126
}
122127

123128
////////////////////
@@ -137,6 +142,10 @@ int APIENTRY wWinMain(
137142
{
138143
mainWindow.LoadDrawableObjectsSettings(trimmedCommandLine.data());
139144
}
145+
else if (!wantBlankCanvas)
146+
{
147+
mainWindow.InitializeDefaultDrawableObjects();
148+
}
140149

141150
while (GetMessage(&Application::g_msg, nullptr, 0, 0) > 0)
142151
{
@@ -405,31 +414,6 @@ INT_PTR MainWindow::InitializeMainDialog()
405414
);
406415
#endif
407416

408-
////////////////////
409-
// Initialize with initialize objects.
410-
411-
char16_t* const functionNames[] = {
412-
u"D2D DrawTextLayout",
413-
u"IDWriteBitmapRenderTarget IDWriteTextLayout",
414-
u"User32 DrawText",
415-
u"GDIPlus DrawString",
416-
//u"GDI ExtTextOut",
417-
//u"IDWriteBitmapRenderTarget DrawGlyphRun",
418-
//u"GDIPlus DrawDriverString",
419-
};
420-
drawableObjects_.clear();
421-
drawableObjects_.resize(countof(functionNames));
422-
423-
for (size_t i = 0; i < countof(functionNames); ++i)
424-
{
425-
auto& drawableObject = drawableObjects_[i];
426-
drawableObject.Set(DrawableObjectAttributeFunction, functionNames[i]);
427-
drawableObject.Set(DrawableObjectAttributeText, u"This is a test.");
428-
drawableObject.Set(DrawableObjectAttributeFontFamily, u"Segoe UI");
429-
drawableObject.Set(DrawableObjectAttributeFontSize, u"18");
430-
drawableObject.Update();
431-
}
432-
433417
Edit_LimitText(GetWindowFromId(hwnd_, IdcLog), 1048576);
434418

435419
// Subclass the values edit box for a few reasons.
@@ -1009,7 +993,44 @@ namespace
1009993
drawableObjectAndValues.Set(DrawableObjectAttributeText, u"This is a test.");
1010994
drawableObjectAndValues.Set(DrawableObjectAttributeFontFamily, u"Segoe UI");
1011995
drawableObjectAndValues.Set(DrawableObjectAttributeFontSize, u"18");
1012-
drawableObjectAndValues.Update();
996+
}
997+
}
998+
999+
1000+
void MainWindow::InitializeDefaultDrawableObjects()
1001+
{
1002+
////////////////////
1003+
// Initialize with typical APIs.
1004+
1005+
char16_t* const functionNames[] = {
1006+
u"D2D DrawTextLayout",
1007+
u"IDWriteBitmapRenderTarget IDWriteTextLayout",
1008+
u"User32 DrawText",
1009+
u"GDIPlus DrawString",
1010+
//u"GDI ExtTextOut",
1011+
//u"IDWriteBitmapRenderTarget DrawGlyphRun",
1012+
//u"GDIPlus DrawDriverString",
1013+
};
1014+
drawableObjects_.clear();
1015+
drawableObjects_.resize(countof(functionNames));
1016+
1017+
for (size_t i = 0; i < countof(functionNames); ++i)
1018+
{
1019+
auto& drawableObject = drawableObjects_[i];
1020+
InitializeDefaultDrawableObjectAndValues(drawableObject);
1021+
drawableObject.Set(DrawableObjectAttributeFunction, functionNames[i]);
1022+
drawableObject.Update();
1023+
}
1024+
}
1025+
1026+
1027+
void MainWindow::EnsureAtLeastOneDrawableObject()
1028+
{
1029+
if (drawableObjects_.empty())
1030+
{
1031+
drawableObjects_.resize(1);
1032+
InitializeDefaultDrawableObjectAndValues(drawableObjects_.front());
1033+
drawableObjects_.front().Update();
10131034
}
10141035
}
10151036

@@ -1026,8 +1047,7 @@ void MainWindow::CreateDrawableObjectsListViewSelected()
10261047
if (originalDrawableObjectsCount == 0)
10271048
{
10281049
// Initialize new default object because there are no existing ones.
1029-
drawableObjects_.resize(1);
1030-
InitializeDefaultDrawableObjectAndValues(drawableObjects_.front());
1050+
EnsureAtLeastOneDrawableObject();
10311051
}
10321052
else
10331053
{
@@ -1591,6 +1611,8 @@ HRESULT MainWindow::SelectFontFile()
15911611

15921612
HRESULT MainWindow::LoadFontFileIntoDrawableObjects(_In_z_ char16_t const* filePath)
15931613
{
1614+
EnsureAtLeastOneDrawableObject();
1615+
15941616
// Update the path for every selected drawable object.
15951617
std::vector<uint32_t> const drawableObjectIndices = GetSelectedDrawableObjectIndices();
15961618
DrawableObjectAndValues::Set(drawableObjects_, drawableObjectIndices, DrawableObjectAttributeFontFilePath, filePath);
@@ -1792,12 +1814,9 @@ HRESULT MainWindow::LoadTextFileIntoDrawableObjects(_In_z_ char16_t const* fileP
17921814

17931815
if (drawableObjects_.empty())
17941816
{
1795-
// todo::: Initialize defaults somewhere shared.
17961817
drawableObjects_.resize(1);
17971818
auto& drawableObject = drawableObjects_[0];
1798-
drawableObject.Set(DrawableObjectAttributeFunction, u"IDWriteBitmapRenderTarget IDWriteTextLayout");
1799-
drawableObject.Set(DrawableObjectAttributeFontFamily, u"Segoe UI");
1800-
drawableObject.Set(DrawableObjectAttributeFontSize, u"18");
1819+
InitializeDefaultDrawableObjectAndValues(drawableObject);
18011820
}
18021821

18031822
for (auto& drawableObject : drawableObjects_)

0 commit comments

Comments
 (0)