34#ifndef RENDERCONTEXT_H
35#define RENDERCONTEXT_H
38#include <wx/dcclient.h>
64 : m_recalcDC(o.m_recalcDC),
65 m_canvasSize(o.m_canvasSize),
66 m_updateRegion(o.m_updateRegion),
67 m_visibleRegion(o.m_visibleRegion),
68 m_worksheetPosition(o.m_worksheetPosition),
69 m_backgroundBrush(o.m_backgroundBrush),
70 m_clipToDrawRegion(o.m_clipToDrawRegion),
71 m_printing(o.m_printing)
88 m_worksheetDC = std::unique_ptr<wxClientDC>(
new wxClientDC(worksheet));
89 m_recalcDC = m_worksheetDC.get();
94 if (m_recalcDC == m_worksheetDC.get())
96 m_worksheetDC.reset();
122 if (!m_cellRedrawTrace)
123 m_cellRedrawTrace.reset(
new std::vector<const Cell *>);
125 m_cellRedrawTrace->clear();
132 if (m_cellRedrawTrace && cell)
133 m_cellRedrawTrace->push_back(cell);
143 if (!m_cellRedrawTrace)
145 std::sort(m_cellRedrawTrace->begin(), m_cellRedrawTrace->end());
147 const Cell *prev =
nullptr;
148 for (
const Cell *cell : *m_cellRedrawTrace) {
151 report(counter, prev);
158 report(counter, prev);
165 { m_clipToDrawRegion = clipToDrawRegion; }
171 { m_worksheetPosition = worksheetPosition; }
181 m_layoutDeadline = std::chrono::steady_clock::now() +
182 std::chrono::seconds(seconds);
183 m_layoutCancelled.store(
false, std::memory_order_relaxed);
184 m_layoutDeadlineActive =
true;
189 m_layoutDeadlineActive =
false;
190 m_layoutCancelled.store(
false, std::memory_order_relaxed);
195 if (m_layoutCancelled.load(std::memory_order_relaxed))
197 if (m_layoutDeadlineActive &&
198 std::chrono::steady_clock::now() >= m_layoutDeadline) {
199 m_layoutCancelled.store(
true, std::memory_order_relaxed);
207 wxDC *m_recalcDC =
nullptr;
209 std::unique_ptr<wxClientDC> m_worksheetDC;
213 wxRect m_updateRegion;
215 wxRect m_visibleRegion;
217 wxPoint m_worksheetPosition;
219 wxBrush m_backgroundBrush;
221 bool m_clipToDrawRegion =
true;
223 bool m_printing =
false;
230 std::unique_ptr<std::vector<const Cell *>> m_cellRedrawTrace;
232 std::chrono::steady_clock::time_point m_layoutDeadline;
234 bool m_layoutDeadlineActive =
false;
236 mutable std::atomic<bool> m_layoutCancelled{
false};
The base class all cell types the worksheet can consist of are derived from.
Definition: Cell.h:141
The state of the current worksheet render pass.
Definition: RenderContext.h:60
void SetRecalcDC(wxDC *dc)
Tells us which dc to measure text sizes on.
Definition: RenderContext.h:79
void SetWorksheetPosition(wxPoint worksheetPosition)
Sets where the worksheet is to be drawn.
Definition: RenderContext.h:170
void NotifyOfCellRedraw(const Cell *cell)
Records that this cell has been drawn, if tracing is enabled.
Definition: RenderContext.h:128
void DetachWorksheetDC()
Drops the worksheet client DC created by AttachWorksheetDC() again.
Definition: RenderContext.h:92
void ClearLayoutCancelled()
Stops the layout deadline and clears the cancelled flag.
Definition: RenderContext.h:187
wxRect GetUpdateRegion() const
The rectangle of the worksheet that is currently being redrawn.
Definition: RenderContext.h:105
void SetVisibleRegion(wxRect visibleRegion)
Sets the rectangle of the worksheet that is currently visible.
Definition: RenderContext.h:112
void ReportMultipleRedraws(Report report)
Calls report(count, cell) for each cell that was drawn more than once.
Definition: RenderContext.h:141
void SetPrinting(bool printing)
Sets whether we are currently rendering for the printer.
Definition: RenderContext.h:117
bool ClipToDrawRegion() const
Do we want to omit drawing outside the current update region?
Definition: RenderContext.h:162
void ClearAndEnableRedrawTracing()
Starts (or restarts) recording which cells this render pass has drawn.
Definition: RenderContext.h:120
bool Printing() const
Are we currently rendering for the printer rather than the screen?
Definition: RenderContext.h:115
void AttachWorksheetDC(wxWindow *worksheet)
Creates a client DC for the given window and measures text on it.
Definition: RenderContext.h:86
void SetLayoutDeadline(int seconds)
Starts a layout deadline this many seconds in the future.
Definition: RenderContext.h:179
wxBrush GetBackgroundBrush() const
The brush the worksheet's background is painted with.
Definition: RenderContext.h:174
void SetCanvasSize(wxSize siz)
Sets the size of the worksheet's visible window.
Definition: RenderContext.h:102
void ClipToDrawRegion(bool clipToDrawRegion)
Whether to omit drawing outside the current update region.
Definition: RenderContext.h:164
bool IsLayoutCancelled() const
Has the current layout pass exceeded its deadline?
Definition: RenderContext.h:193
wxDC * GetRecalcDC() const
The dc "recalculate" (measuring text) currently draws to.
Definition: RenderContext.h:77
wxPoint GetWorksheetPosition() const
Where is the worksheet to be drawn?
Definition: RenderContext.h:168
wxSize GetCanvasSize() const
The size of the worksheet's visible window.
Definition: RenderContext.h:100
void SetBackgroundBrush(const wxBrush &brush)
Sets the brush the worksheet's background is painted with.
Definition: RenderContext.h:176
wxRect GetVisibleRegion() const
The rectangle of the worksheet that is currently visible.
Definition: RenderContext.h:110
void SetUpdateRegion(wxRect rect)
Sets the rectangle of the worksheet that is currently being redrawn.
Definition: RenderContext.h:107