Skip to content

Commit 1791bc4

Browse files
committed
Display object selection in viewing window even without ListView control by changing object label color.
Ctrl+left click on viewing window now toggles selection. Enable buttons copy, delete, shift even in simple settings mode.
1 parent 487caa2 commit 1791bc4

12 files changed

Lines changed: 700 additions & 534 deletions

Common.ArrayRef.natvis

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
3+
<Type Name="array_ref&lt;*&gt;">
4+
<DisplayString>{{ Count={end_ - begin_} }}</DisplayString>
5+
<Expand>
6+
<Item Name="[Count]" ExcludeView="simple">end_ - begin_</Item>
7+
<ArrayItems>
8+
<Size>end_ - begin_</Size>
9+
<ValuePointer>begin_</ValuePointer>
10+
</ArrayItems>
11+
</Expand>
12+
</Type>
13+
</AutoVisualizer>

Common.AutoResource.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ class AutoResource
9090
ResourceTypePolicy::Acquire(resource_);
9191
}
9292

93+
AutoResource(Self&& other)
94+
{
95+
resource_ = other.resource_;
96+
ResourceTypePolicy::InitializeEmpty(Cast(&other.resource_));
97+
}
98+
9399
inline AutoResource()
94100
{
95101
ResourceTypePolicy::InitializeEmpty(Cast(&resource_));
@@ -186,7 +192,7 @@ class AutoResource
186192
return Set(other.resource_);
187193
}
188194

189-
inline ResourceType Set(Self&& other)
195+
ResourceType Set(Self&& other)
190196
{
191197
if (other.resource_ != resource_)
192198
{
@@ -211,6 +217,12 @@ class AutoResource
211217
return *this;
212218
}
213219

220+
inline Self& operator=(Self&& resource)
221+
{
222+
Set(std::move(resource));
223+
return *this;
224+
}
225+
214226
// No check. Just set it directly.
215227
inline ResourceType SetDirectly(ResourceType resource)
216228
{

Common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ bool TestBit(void const* memoryBase, uint32_t bitIndex) noexcept;
6262
bool ClearBit(void* memoryBase, uint32_t bitIndex) noexcept;
6363
bool SetBit(void* memoryBase, uint32_t bitIndex) noexcept;
6464

65+
// Returns true if current flags were updated (false if unchanged).
66+
template<typename EnumType>
67+
bool UpdateFlags(IN OUT EnumType& currentFlags, bool condition, EnumType flagsWhenTrue)
68+
{
69+
EnumType previousFlags = currentFlags;
70+
currentFlags = (previousFlags & ~flagsWhenTrue) | (condition ? flagsWhenTrue : EnumType(0));
71+
return previousFlags != currentFlags;
72+
}
73+
6574
template<typename T>
6675
T* PtrAddByteOffset(T* p, size_t offset)
6776
{

DrawableObjectAndValues.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ EXPORT_BEGIN
3737
// Combination of the drawable object and its associated attribute values.
3838
struct DrawableObjectAndValues : public IAttributeSource
3939
{
40+
public:
41+
enum Flags : uint32_t
42+
{
43+
FlagsNone = 0x00000000,
44+
FlagsSelected = 0x00000001,
45+
FlagsInitialDefaults = FlagsSelected,
46+
};
47+
4048
public:
4149
ComPtr<DrawableObject> drawableObject_;
4250
AttributeValue values_[DrawableObjectAttributeTotal];
@@ -45,10 +53,14 @@ struct DrawableObjectAndValues : public IAttributeSource
4553
D2D_RECT_F objectRect_; // Object rectangle in post-transform canvas coordinates. Best rounded to whole pixel.
4654
D2D_RECT_F layoutBounds_; // Extents of layout boundary, in pre-transform world coordinates.
4755
D2D_RECT_F contentBounds_; // Actual content boundary, in pre-transform world coordinates.
48-
CachedTransform transform_; // Transform from world coordinates to
56+
CachedTransform transform_; // Transform from world coordinates to screen.
4957
D2D_POINT_2F origin_; // Offset from <0,0>. May be non-zero if rotation exists or content is larger than layout.
58+
Flags flags_;
5059

5160
public:
61+
DrawableObjectAndValues();
62+
DrawableObjectAndValues(DrawableObjectAndValues const&) = default;
63+
5264
// IAttributeSource implementation.
5365
virtual HRESULT GetString(uint32_t id, _Out_ array_ref<char16_t>& value) override;
5466
using IAttributeSource::GetString;
@@ -140,4 +152,6 @@ struct DrawableObjectAndValues : public IAttributeSource
140152
);
141153
};
142154

155+
DEFINE_ENUM_FLAG_OPERATORS(DrawableObjectAndValues::Flags);
156+
143157
EXPORT_END

DrawableObjectAndValues.ixx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ namespace
3030

3131
static const COLORREF s_defaultLabelTextColor = 0x00FFFFFF;
3232
static const COLORREF s_defaultErrorTextColor = 0x004040FF;
33+
static const COLORREF s_defaultLabelBackColor = 0x00805050;
34+
}
35+
36+
37+
DrawableObjectAndValues::DrawableObjectAndValues()
38+
: labelRect_{},
39+
objectRect_{}, // Object rectangle in post-transform canvas coordinates. Best rounded to whole pixel.
40+
layoutBounds_{},
41+
contentBounds_{},
42+
origin_{},
43+
flags_{FlagsSelected}
44+
{
3345
}
3446

3547

@@ -158,7 +170,8 @@ void DrawableObjectAndValues::Draw(
158170
SetWorldTransform(currentHdc, &finalTransform.gdi);
159171
HFONT previousFont = SelectFont(currentHdc, labelFont);
160172
SetTextColor(currentHdc, s_defaultErrorTextColor);
161-
SetBkMode(currentHdc, TRANSPARENT);
173+
SetBkMode(currentHdc, OPAQUE);
174+
SetBkColor(currentHdc, s_defaultLabelBackColor);
162175
DrawText(currentHdc, ToWChar(errorString.c_str()), int(errorString.size()), &errorRect, DT_NOCLIP | DT_NOPREFIX);
163176
SelectFont(currentHdc, previousFont);
164177
SetWorldTransform(currentHdc, &DrawableObject::identityTransform.gdi);
@@ -204,29 +217,21 @@ void DrawableObjectAndValues::Draw(
204217
{
205218
HFONT previousFont = SelectFont(hdc, labelFont);
206219
SetTextColor(hdc, s_defaultLabelTextColor);
207-
SetBkMode(hdc, TRANSPARENT);
220+
if (objectAndValues.flags_ & DrawableObjectAndValues::FlagsSelected)
221+
{
222+
SetBkMode(hdc, OPAQUE);
223+
SetBkColor(hdc, s_defaultLabelBackColor);
224+
}
225+
else
226+
{
227+
SetBkMode(hdc, TRANSPARENT);
228+
}
208229
DrawText(hdc, ToWChar(objectAndValues.label_.data()), int(objectAndValues.label_.size()), &objectAndValues.labelRect_, DT_NOCLIP | DT_NOPREFIX);
209230
SelectFont(hdc, previousFont);
210231
}
211232
}
212233
SetWorldTransform(hdc, &DrawableObject::identityTransform.gdi);
213234
drawingCanvas.SwitchRenderingAPI(DrawingCanvas::CurrentRenderingApiAny);
214-
215-
#if 0 // todo::: delete hack
216-
DrawingCanvas::RawPixels rawPixels = drawingCanvas.GetRawPixels();
217-
std::vector<Edge> edges = {{0,1},{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,0}, {8,9},{9,10},{10,11},{11,8}, {12,13},{13,14},{14,15},{15,12}};
218-
std::vector<PointI> points = {{100,100},{150,0},{250,150},{250,0},{300,100},{250,200},{150,50},{150,200}, {400,150},{600,200},{350,350},{300,250}, {400,200},{450,250},{400,275},{350,250}};
219-
FillPolyline(rawPixels, canvasTransform, points, IN OUT edges, 0xFFE080C0);
220-
//DrawLineTransformed(
221-
// rawPixels,
222-
// canvasTransform,
223-
// 100,
224-
// 100,
225-
// 100,
226-
// 200,
227-
// 0xFFE080C0
228-
// );
229-
#endif
230235
}
231236

232237

DrawingCanvasControl.ixx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ LRESULT CALLBACK DrawingCanvasControl::WindowProc(HWND hwnd, UINT message, WPARA
112112
GetCursorPos(&cursorPoint);
113113
TrackPopupMenu(menu, TPM_LEFTALIGN|TPM_NOANIMATION|TPM_RIGHTBUTTON, cursorPoint.x, cursorPoint.y, 0, hwnd, 0);
114114
DestroyMenu(menu);
115-
116-
SendMouseNotification();
117115
}
118116
break;
119117

@@ -137,7 +135,6 @@ LRESULT CALLBACK DrawingCanvasControl::WindowProc(HWND hwnd, UINT message, WPARA
137135
case WM_LBUTTONUP:
138136
case WM_MBUTTONUP:
139137
ReleaseCapture();
140-
SendMouseNotification();
141138
break;
142139

143140
case WM_CAPTURECHANGED:
@@ -209,8 +206,6 @@ LRESULT CALLBACK DrawingCanvasControl::WindowProc(HWND hwnd, UINT message, WPARA
209206
{
210207
Pan(xDif, yDif);
211208
}
212-
213-
SendMouseNotification();
214209
}
215210
break;
216211

MainWindow.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class MainWindow
9696
void FillAttributesListView();
9797
void InitializeAttributeValuesListView();
9898
void UpdateUi();
99-
void DeferUpdateUi(NeededUiUpdate neededUiUpdate = NeededUiUpdateNone);
99+
void DeferUpdateUi(NeededUiUpdate neededUiUpdate = NeededUiUpdateNone, uint32_t timeOut = 50);
100100
void UpdateDrawableObjectsListView();
101101
void DeleteDrawableObjectsListViewSelected();
102102
void CreateDrawableObjectsListViewSelected();
@@ -117,7 +117,7 @@ class MainWindow
117117
void Resize(int id);
118118
HRESULT SelectFontFile();
119119
HRESULT SelectFontFamily();
120-
std::vector<uint32_t> GetSelectedDrawableObjectIndices();
120+
std::vector<uint32_t> GetSelectedDrawableObjectIndices(bool returnAllIfEmpty = true);
121121
std::vector<uint32_t> GetSelectedAttributeIndices();
122122
HRESULT GetFileOrFamilyName(uint32_t selectedDrawableObjectIndex, _Out_ std::u16string& fileOrFamilyName);
123123

0 commit comments

Comments
 (0)