Timeline: refactor common drawing code into an abstract baseclass

This commit is contained in:
Fischlurch 2019-07-14 23:24:28 +02:00
parent 713178aecd
commit d1e2ddc56e
2 changed files with 56 additions and 45 deletions

View file

@ -76,31 +76,61 @@ namespace timeline {
lumiera::advice::Request<PStyleContext> trackBodyStyle{"style(trackBody)"}; lumiera::advice::Request<PStyleContext> trackBodyStyle{"style(trackBody)"};
class TrackGroundingRenderer /**
* @internal drawing routines to paint the nested system
* of insets and rulers in the track content display
* @remarks the actual sequence of elements to draw is established by
* [evaluating](\ref TrackBody::establishTrackSpace (TrackProfile&))
* the nested widget structure; this results in a sequence of drawing
* "verbs", which we call the \ref TrackProfile. This class here
* implements a \ref ProfileInterpreter, which is a double-dispatch
* mechanism to call a set of (virtual) drawing primitives, the
* actual drawing code is in the two following subclasses,
* for the background and for drawing overlays.
*/
class AbstractTrackRenderer
: public ProfileInterpreter : public ProfileInterpreter
{ {
protected:
CairoC cox_; CairoC cox_;
StyleC style_; StyleC style_;
PixSpan visible_; PixSpan visible_;
/** the current "water level". /** the current painting "water level".
* To be updated while drawing top-down */ * To be updated while drawing top-down */
int line_ = 0; int line_ = 0;
/** paint the top of the track body area
*/
void void
prelude() override fillBackground (int height)
{ {
int topMargin = style_->get_margin().get_top();
style_->render_background (cox_ style_->render_background (cox_
,visible_.b // left start of the rectangle ,visible_.b // left start of the rectangle
,line_ // top of the rectangle ,line_ // top of the rectangle
,visible_.delta() // width of the area ,visible_.delta() // width of the area
,topMargin // height to fill ,height // height to fill
); );
line_ += topMargin; line_ += height;
}
public:
AbstractTrackRenderer (CairoC currentDrawContext, DisplayManager& layout)
: cox_{currentDrawContext}
, style_{trackBodyStyle.getAdvice()}
, visible_{layout.getPixSpan()}
{ }
};
class TrackGroundingRenderer
: public AbstractTrackRenderer
{
/** paint the top of the track body area */
void
prelude() override
{
int topMargin = style_->get_margin().get_top();
fillBackground (topMargin);
line_ += 5; //////////////////////////////////////////////////////////////////TODO: visual debugging line_ += 5; //////////////////////////////////////////////////////////////////TODO: visual debugging
} }
@ -110,13 +140,7 @@ namespace timeline {
coda (uint pad) override coda (uint pad) override
{ {
int bottomPad = pad + style_->get_margin().get_bottom(); int bottomPad = pad + style_->get_margin().get_bottom();
style_->render_background (cox_ fillBackground (bottomPad);
,visible_.b // left start of the rectangle
,line_ // top of the rectangle
,visible_.delta() // width of the area
,bottomPad // height to fill
);
line_ += bottomPad;
} }
/** draw grounding of an overview/ruler track /** draw grounding of an overview/ruler track
@ -139,13 +163,7 @@ namespace timeline {
void void
content (uint h) override content (uint h) override
{ {
style_->render_background (cox_ fillBackground (h);
,visible_.b // left start of the rectangle
,line_ // top of the rectangle
,visible_.delta() // width of the area
,h // height to fill
);
line_ += h;
line_ += 8; //////////////////////////////////////////////////////////////////TODO: visual debugging line_ += 8; //////////////////////////////////////////////////////////////////TODO: visual debugging
} }
@ -165,29 +183,17 @@ namespace timeline {
UNIMPLEMENTED ("paint upward slope"); UNIMPLEMENTED ("paint upward slope");
} }
public: public:
TrackGroundingRenderer (CairoC currentDrawContext, DisplayManager& layout) using AbstractTrackRenderer::AbstractTrackRenderer;
: cox_{currentDrawContext}
, style_{trackBodyStyle.getAdvice()}
, visible_{layout.getPixSpan()}
{ }
}; };
class TrackOverlayRenderer class TrackOverlayRenderer
: public ProfileInterpreter : public AbstractTrackRenderer
{ {
CairoC cox_;
StyleC style_;
PixSpan visible_;
int line_ = 0; /** overlays to show at top of the track body area */
/** overlays to show at top of the track body area
*/
void void
prelude() override prelude() override
{ {
@ -243,15 +249,11 @@ namespace timeline {
UNIMPLEMENTED ("overlays for upward slope"); UNIMPLEMENTED ("overlays for upward slope");
} }
public: public:
TrackOverlayRenderer (CairoC currentDrawContext, DisplayManager& layout) using AbstractTrackRenderer::AbstractTrackRenderer;
: cox_{currentDrawContext}
, style_{trackBodyStyle.getAdvice()}
, visible_{layout.getPixSpan()}
{ }
}; };
template<class PINT, bool isRuler> template<class PINT, bool isRuler>
auto auto
makeRenderer (DisplayManager& layout, BodyCanvasWidget::ProfileGetter& getProfile) makeRenderer (DisplayManager& layout, BodyCanvasWidget::ProfileGetter& getProfile)

View file

@ -22040,6 +22040,15 @@
</node> </node>
</node> </node>
</node> </node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1563143002107" ID="ID_1177786099" MODIFIED="1563143014910" TEXT="verschiedene Ruler-Arten">
<icon BUILTIN="hourglass"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1563143025272" ID="ID_31825370" MODIFIED="1563143052140" TEXT="Anzeige-H&#xf6;he steuern">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1563143033085" ID="ID_149529437" MODIFIED="1563143047761" TEXT="woher kommt die Info?">
<icon BUILTIN="help"/>
</node>
</node> </node>
</node> </node>
<node CREATED="1554517044045" ID="ID_520113686" MODIFIED="1557498707230" TEXT="Farben bereitstellen"> <node CREATED="1554517044045" ID="ID_520113686" MODIFIED="1557498707230" TEXT="Farben bereitstellen">