5namespace Stroika::Frameworks::Led {
7#if qStroika_Frameworks_Led_SupportGDI
13 inline void MultiRowTextImager::InvalidateTotalRowsInWindow ()
15 fTotalRowsInWindow = 0;
17 inline MultiRowTextImager::RowReference MultiRowTextImager::GetTopRowReferenceInWindow ()
const
21 const_cast<MultiRowTextImager*
> (
this)->ReValidateSubRowInTopLineInWindow ();
22 return (RowReference (fTopLinePartitionMarkerInWindow, fSubRowInTopLineInWindow));
24 inline size_t MultiRowTextImager::GetTotalRowsInWindow_ ()
const
26 if (fTotalRowsInWindow == 0) {
27 fTotalRowsInWindow = ComputeRowsThatWouldFitInWindowWithTopRow (GetTopRowReferenceInWindow ());
29 Assert (fTotalRowsInWindow >= 1);
30 Assert (fTotalRowsInWindow == ComputeRowsThatWouldFitInWindowWithTopRow (GetTopRowReferenceInWindow ()));
31 return (fTotalRowsInWindow);
39 inline MultiRowTextImager::PartitionElementCacheInfo::Rep::Rep ()
40 : fPixelHeightCache (DistanceType (-1))
43 , fRowStartArray (nullptr)
44 , fRowHeightArray (nullptr)
47 inline MultiRowTextImager::PartitionElementCacheInfo::Rep::~Rep ()
49 if (fRowCountCache > kPackRowStartCount + 1) {
50 delete[] fRowStartArray;
52 if (fRowCountCache > kPackRowHeightCount) {
53 delete[] fRowHeightArray;
62 inline MultiRowTextImager::PartitionElementCacheInfo::PartitionElementCacheInfo ()
63 : fRep (make_shared<Rep> ())
73 inline DistanceType MultiRowTextImager::PartitionElementCacheInfo::GetInterLineSpace ()
const
75 Assert (fRep->fInterlineSpace != DistanceType (-1));
76 return (fRep->fInterlineSpace);
78 inline void MultiRowTextImager::PartitionElementCacheInfo::SetInterLineSpace (DistanceType interlineSpace)
80 Assert (interlineSpace != DistanceType (-1));
81 fRep->fInterlineSpace = interlineSpace;
88 inline DistanceType MultiRowTextImager::PartitionElementCacheInfo::GetPixelHeight ()
const
90 return (fRep->fPixelHeightCache + GetInterLineSpace ());
98 inline size_t MultiRowTextImager::PartitionElementCacheInfo::GetRowCount ()
const
100 Assert (fRep->fRowCountCache >= 1);
101 return (fRep->fRowCountCache);
109 inline size_t MultiRowTextImager::PartitionElementCacheInfo::PeekRowCount ()
const
111 return (fRep->fRowCountCache);
118 inline size_t MultiRowTextImager::PartitionElementCacheInfo::GetLastRow ()
const
120 return GetRowCount () - 1;
128 inline DistanceType MultiRowTextImager::PartitionElementCacheInfo::PeekAtRowHeight (
size_t i)
const
130 Assert (i < fRep->fRowCountCache);
137 if (fRep->fRowCountCache <= kPackRowHeightCount) {
139 const RowHeight_* theArray =
reinterpret_cast<const RowHeight_*
> (&fRep->fRowHeightArray);
140 return (theArray[i]);
143 return (fRep->fRowHeightArray[i]);
149 inline void MultiRowTextImager::PartitionElementCacheInfo::SetRowHeight (
size_t i, DistanceType rowHeight)
151 Assert (i < fRep->fRowCountCache);
152 Assert (
sizeof (RowHeight_) > 1 or rowHeight <= 0xff);
153 Assert (
sizeof (RowHeight_) > 2 or rowHeight <= 0xffff);
157 if (fRep->fRowCountCache <= kPackRowHeightCount) {
159 RowHeight_* theArray =
reinterpret_cast<RowHeight_*
> (&fRep->fRowHeightArray);
160 theArray[i] = RowHeight_ (rowHeight);
164 fRep->fRowHeightArray[i] = RowHeight_ (rowHeight);
172 inline size_t MultiRowTextImager::PartitionElementCacheInfo::PeekAtRowStart (
size_t i)
const
174 Assert (i < fRep->fRowCountCache);
184 if (fRep->fRowCountCache <= kPackRowStartCount + 1) {
186 const RowStart_* theArray =
reinterpret_cast<const RowStart_*
> (&fRep->fRowStartArray);
187 return (theArray[i - 1]);
190 return (fRep->fRowStartArray[i - 1]);
198 inline void MultiRowTextImager::PartitionElementCacheInfo::SetRowStart (
size_t i,
size_t rowStart)
200 Assert (i < fRep->fRowCountCache);
203 Assert (rowStart == 0);
210 Assert (
sizeof (RowStart_) > 1 or rowStart <= 0xff);
211 Assert (
sizeof (RowStart_) > 2 or rowStart <= 0xffff);
212 if (fRep->fRowCountCache <= kPackRowStartCount + 1) {
214 RowStart_* theArray =
reinterpret_cast<RowStart_*
> (&fRep->fRowStartArray);
215 theArray[i - 1] = RowStart_ (rowStart);
219 fRep->fRowStartArray[i - 1] = RowStart_ (rowStart);
223 inline size_t MultiRowTextImager::PartitionElementCacheInfo::GetLineRelativeRowStartPosition (
size_t ithRow)
const
225 return (PeekAtRowStart (ithRow));
227 inline DistanceType MultiRowTextImager::PartitionElementCacheInfo::GetRowHeight (
size_t ithRow)
const
229 return (PeekAtRowHeight (ithRow));
231 inline size_t MultiRowTextImager::PartitionElementCacheInfo::LineRelativePositionInWhichRow (
size_t charPos)
const
236 for (
size_t row = fRep->fRowCountCache; row >= 1; --row) {
237 if (charPos >= PeekAtRowStart (row - 1)) {
250 inline MultiRowTextImager::RowReference::RowReference (PartitionMarker* partitionMarker,
size_t subRow)
251 : fPartitionMarker (partitionMarker)
255 inline MultiRowTextImager::RowReference& MultiRowTextImager::RowReference::operator= (
const MultiRowTextImager::RowReference& rhs)
257 fPartitionMarker = rhs.fPartitionMarker;
258 fSubRow = rhs.fSubRow;
261 inline MultiRowTextImager::PartitionMarker* MultiRowTextImager::RowReference::GetPartitionMarker ()
const
263 return (fPartitionMarker);
265 inline size_t MultiRowTextImager::RowReference::GetSubRow ()
const
269 inline bool MultiRowTextImager::RowReference::operator== (MultiRowTextImager::RowReference rhs)
const
271 return this->GetPartitionMarker () == rhs.GetPartitionMarker () and this->GetSubRow () == rhs.GetSubRow ();
285 inline bool MultiRowTextImager::GetNextRowReference (RowReference* adjustMeInPlace)
const
288 PartitionMarker* cur = adjustMeInPlace->GetPartitionMarker ();
289 size_t subRow = adjustMeInPlace->GetSubRow ();
290 PartitionElementCacheInfo pmCacheInfo = GetPartitionElementCacheInfo (cur);
291 if (subRow + 1 < pmCacheInfo.GetRowCount ()) {
293 *adjustMeInPlace = RowReference{cur, subRow};
297 if (cur->GetNext () ==
nullptr) {
301 cur = cur->GetNext ();
303 *adjustMeInPlace = RowReference{cur, subRow};
314 inline bool MultiRowTextImager::GetPreviousRowReference (RowReference* adjustMeInPlace)
const
317 PartitionMarker* cur = adjustMeInPlace->GetPartitionMarker ();
318 size_t subRow = adjustMeInPlace->GetSubRow ();
321 *adjustMeInPlace = RowReference{cur, subRow};
325 if (cur->GetPrevious () ==
nullptr) {
329 cur = cur->GetPrevious ();
330 PartitionElementCacheInfo pmCacheInfo = GetPartitionElementCacheInfo (cur);
331 subRow = pmCacheInfo.GetRowCount () - 1;
332 *adjustMeInPlace = RowReference{cur, subRow};
344 inline MultiRowTextImager::RowReference MultiRowTextImager::GetIthRowReferenceFromHere (RowReference fromHere, ptrdiff_t ith)
const
346 [[maybe_unused]]
bool result = GetIthRowReferenceFromHere (&fromHere, ith);
356 inline MultiRowTextImager::RowReference MultiRowTextImager::GetIthRowReference (
size_t ith)
const
358 RowReference fromHere (GetFirstPartitionMarker (), 0);
359 [[maybe_unused]]
bool result = GetIthRowReferenceFromHere (&fromHere, ith);
368 inline size_t MultiRowTextImager::GetRowLength (RowReference row)
const
370 return (GetEndOfRow (row) - GetStartOfRow (row));
376 inline MultiRowTextImager::RowReference MultiRowTextImager::GetLastRowReferenceInWindow ()
const
378 RowReference row = GetTopRowReferenceInWindow ();
379 Assert (GetTotalRowsInWindow_ () >= 1);
380 (void)GetIthRowReferenceFromHere (&row, GetTotalRowsInWindow_ () - 1);
383 inline void MultiRowTextImager::SetTopRowInWindow_ (RowReference row)
385 fTopLinePartitionMarkerInWindow = row.GetPartitionMarker ();
386 fSubRowInTopLineInWindow = row.GetSubRow ();
388 InvalidateTotalRowsInWindow ();
394 inline DistanceType MultiRowTextImager::GetRowHeight (RowReference row)
const
397 return GetPartitionElementCacheInfo (row.GetPartitionMarker ()).GetRowHeight (row.GetSubRow ());
#define RequireNotNull(p)