Inv(#1020): framework for custom drawing

This commit is contained in:
Fischlurch 2016-10-30 02:15:01 +01:00
parent ae07329ada
commit 1255a4fc04
4 changed files with 150 additions and 9 deletions

View file

@ -68,9 +68,6 @@ namespace panel {
: Panel(panelManager, dockItem, getTitle(), getStockID())
, twoParts_(Gtk::ORIENTATION_VERTICAL)
, buttons_()
, button_1_()
, button_2_()
, button_3_()
, frame_("Gtk::Layout Experiments")
, scroller_()
, canvas_()
@ -115,6 +112,13 @@ namespace panel {
button_5_.signal_clicked().connect(
mem_fun(*this, &TimelinePanel::experiment_5));
buttons_.add(button_5_);
toggleDraw_.set_label("draw");
toggleDraw_.signal_clicked().connect(
[this]() {
canvas_.enableDraw (this->toggleDraw_.get_active());
});
buttons_.add(toggleDraw_);
//(End)buttons...
frame_.add(scroller_);
@ -240,6 +244,29 @@ namespace panel {
}
void
Canvas::enableDraw (bool yes)
{
shallDraw_ = yes;
if (shallDraw_)
{
///TODO invalidate
cout << "DRRRRAW!"<<endl;
}
}
bool
Canvas::on_draw(Cairo::RefPtr<Cairo::Context> const& cox)
{
if (shallDraw_)
{
cout << "Canvas::on_draw("<<cox<<");"<<endl;
}
return Gtk::Layout::on_draw(cox);
}
/* === Support for Investigation === */
namespace {

View file

@ -48,7 +48,7 @@ namespace panel {
//using std::shared_ptr;
/**
* "experimental" child widget for investigation of gtk::Layout
* "experimental" child widget for investigation of Gtk::Layout
*/
class ChildEx
: public Gtk::Button
@ -67,6 +67,24 @@ namespace panel {
/**
* "experimental" custom canvas, based on Gtk::Layout.
* In addition this customised widget supports direct drawing
*/
class Canvas
: public Gtk::Layout
{
bool shallDraw_;
public:
void enableDraw (bool);
private:
virtual bool on_draw (Cairo::RefPtr<Cairo::Context> const&) override;
};
/**
* Dockable panel to hold timeline widget(s).
* @todo build the actual implementation, after finishing the investigation
@ -110,9 +128,10 @@ namespace panel {
Gtk::Button button_3_;
Gtk::Button button_4_;
Gtk::Button button_5_;
Gtk::CheckButton toggleDraw_;
Gtk::Frame frame_;
Gtk::ScrolledWindow scroller_;
Gtk::Layout canvas_;
Canvas canvas_;
ChildEx* makeChld();

View file

@ -2398,6 +2398,15 @@ On a second thought, the fact that the [[Bus-MObject|BusMO]] is rather void of a
:sound mixing desks use list style arrangement, and this has proven to be quite viable, when combined with the ability to //send over// output from one mixer stripe to the input of another, allowing to build arbitrary complex filter matrices. On the other hand, organising a mix in //subgroups// can be considered best practice. This leads to arranging the pipes //as wood:// by default and on top level as list, optionally expanding into a subtree with automatic rooting, augmented by the ability to route any output to any input (cycles being detected and flagged as error).
</pre>
</div>
<div title="GtkCustomDrawing" creator="Ichthyostega" modifier="Ichthyostega" created="201610300111" modified="201610300113" tags="spec GuiPattern" changecount="6">
<pre>//some information how to achieve custom drawing with ~GTKmm...//
valuable reference documentation comes bundled with lib ~GTKmm, in the guide [[&quot;Programming with GTKmm|https://developer.gnome.org/gtkmm-tutorial/stable/index.html.en]]
* the chapter detailing [[use of the Gtk::DrawingArea|https://developer.gnome.org/gtkmm-tutorial/stable/chapter-drawingarea.html.en]], including an introduction to [[Cairomm|https://www.cairographics.org/documentation/cairomm/reference/]]
* the chapter about [[constructing a custom widget|https://developer.gnome.org/gtkmm-tutorial/stable/sec-custom-widgets.html.en]]
Basically we have to handle the {{{signal_draw}}} events. Since we need to control the event processing, it is recommended to do this event handling by //overriding the {{{on_draw()}}} function,// not by connecting a slot directly to the signal. Two details are to be considered here: the //return value// controls if the event can be considered as fully handled. If we return {{{false}}}, enclosing (parent) widgets get also to handle this event. And, secondly, if we derive from any widget, it is a good idea to invoke the //parent implementation of {{{on_draw()}}} at the appropriate point.// This is especially relevant when our custom drawing involves the ''canvas widget'' ({{{Gtk::Layout}}}), which has the ability to place several further widgets embedded onto the canvas area. Without invoking this parent event handler, those embedded widgets won't be shown.
</pre>
</div>
<div title="GtkLayoutWidget" creator="Ichthyostega" modifier="Ichthyostega" created="201610141819" modified="201610141820" tags="GuiPattern impl" changecount="3">
<pre>//This is the canvas widget of ~GTK-3//
It allows not only custom drawing, but also to embed other widgets at defined coordinates.
@ -2635,7 +2644,7 @@ In the most general case, there can be per-track content and nested content at t
&amp;rarr; important question: how to [[organise the widgets|GuiTimelineWidgetStructure]]
</pre>
</div>
<div title="GuiTimelineWidgetStructure" creator="Ichthyostega" modifier="Ichthyostega" created="201410250002" modified="201610291617" tags="GuiPattern discuss decision impl" changecount="49">
<div title="GuiTimelineWidgetStructure" creator="Ichthyostega" modifier="Ichthyostega" created="201410250002" modified="201610300058" tags="GuiPattern discuss decision impl" changecount="50">
<pre>The Timeline is probably the most prominent place in the GUI where we need to come up with a custom UI design.
Instead of combining standard components in one of the well-known ways, here we need to come up with our own handling solution -- which also means to write one or several custom GTK widgets. Thus the question of layout and screen space division and organisation becomes a crucial design decision. The ~GTK-2 Gui, as implemented currently, did already take some steps along this route, yet this kind of decision should be cast and documented explicitly (be it after the fact).
@ -2716,6 +2725,8 @@ In order to build a sensible plan for our timeline structure, we need to investi
://problematic//
:* the signal based {{{foreach}}} does not work -- there seems to be a problem with the slot's signature causing a wrong address to be passed in
:* the interface {{{Gtk::Container}}} exposes a {{{get_children}}} function, but this returns a //copy// of the vector with pointers to all child widgets
;about GtkCustomDrawing
:need to derive from {{{Gtk::Layout}}} and override the {{{on_draw(cairocontext)}}} function
</pre>
</div>
<div title="HighLevelModel" modifier="Ichthyostega" created="200808152311" modified="201505310109" tags="Model spec design discuss img" changecount="2">

View file

@ -8,7 +8,19 @@
<node CREATED="1455289597596" ID="ID_970065036" MODIFIED="1455289601196" TEXT="work site"/>
<node CREATED="1455289466261" ID="ID_273679080" MODIFIED="1455289469961" TEXT="PresentationState"/>
</node>
<node CREATED="1476376882857" HGAP="193" ID="ID_1420903777" MODIFIED="1476376900764" TEXT="Kern-Elemente" VSHIFT="-34">
<node CREATED="1477784761581" HGAP="72" ID="ID_854334914" MODIFIED="1477784783508" TEXT="Rahmen" VSHIFT="-21">
<node CREATED="1477784793993" ID="ID_1868522177" MODIFIED="1477784810257" TEXT="Umbau">
<icon BUILTIN="hourglass"/>
<node CREATED="1477784813895" ID="ID_1343270939" MODIFIED="1477784821050" TEXT="Model durch UI-Bus ersetzen"/>
<node CREATED="1477784829157" ID="ID_1998357180" MODIFIED="1477784838700" TEXT="Icon-Laden modernisieren"/>
<node CREATED="1477784821925" FOLDED="true" ID="ID_1871474250" MODIFIED="1477784892461" TEXT="Styling aufr&#xe4;umen">
<node CREATED="1477784846162" ID="ID_1164942946" MODIFIED="1477784889994" TEXT="siehe Info zum CssProvider">
<arrowlink DESTINATION="ID_1810760662" ENDARROW="Default" ENDINCLINATION="1846;-61;" ID="Arrow_ID_1610122569" STARTARROW="None" STARTINCLINATION="-227;-646;"/>
</node>
</node>
</node>
</node>
<node CREATED="1476376882857" HGAP="193" ID="ID_1420903777" MODIFIED="1477784783964" TEXT="Kern-Elemente" VSHIFT="-34">
<node CREATED="1476376913589" ID="ID_1887326939" MODIFIED="1476376917001" TEXT="Timeline">
<node CREATED="1477599995452" ID="ID_97568136" MODIFIED="1477599999383" TEXT="Bestandteile">
<node CREATED="1476377043180" ID="ID_1179709828" MODIFIED="1476377047495" TEXT="Head">
@ -9269,8 +9281,24 @@
</richcontent>
</node>
</node>
<node CREATED="1477785704584" ID="ID_528329491" MODIFIED="1477785711408" TEXT="event handling">
<node CREATED="1477785727469" ID="ID_129787833" LINK="https://developer.gnome.org/gtkmm-tutorial/stable/chapter-signals.html.en" MODIFIED="1477785743493" TEXT="Guide: Kapitel &quot;Signals&quot;"/>
<node CREATED="1477785747138" ID="ID_4618201" LINK="https://developer.gnome.org/gtkmm-tutorial/stable/sec-xeventsignals.html.en" MODIFIED="1477785785076" TEXT="speziell Details zu event Handlern: X event signals">
<icon BUILTIN="idea"/>
</node>
<node CREATED="1477785807338" ID="ID_80062368" MODIFIED="1477788924929" TEXT="wie">
<icon BUILTIN="info"/>
<node CREATED="1477785809930" ID="ID_596393977" MODIFIED="1477785817884" TEXT="signal connect()"/>
<node COLOR="#ca1b00" CREATED="1477785830295" ID="ID_94782325" MODIFIED="1477785836644" TEXT="-- oder --"/>
<node CREATED="1477785818920" ID="ID_1600280983" MODIFIED="1477788924929" TEXT="on_xxx() &#xfc;berschreiben">
<linktarget COLOR="#a9b4c1" DESTINATION="ID_1600280983" ENDARROW="Default" ENDINCLINATION="893;0;" ID="Arrow_ID_1707544457" SOURCE="ID_111966354" STARTARROW="None" STARTINCLINATION="893;0;"/>
</node>
</node>
<node CREATED="1477785856731" ID="ID_63204089" MODIFIED="1477785865998" TEXT="R&#xfc;ckgabewert: true == fertig behandelt"/>
</node>
<node CREATED="1477526858307" ID="ID_676269117" MODIFIED="1477526862502" TEXT="custom widget">
<node COLOR="#ca1b00" CREATED="1477526864162" ID="ID_1385929770" LINK="https://developer.gnome.org/gtkmm-tutorial/stable/sec-custom-widgets.html.en" MODIFIED="1477526888486" TEXT="Beispiel">
<node COLOR="#ca1b00" CREATED="1477526864162" ID="ID_1385929770" LINK="https://developer.gnome.org/gtkmm-tutorial/stable/sec-custom-widgets.html.en" MODIFIED="1477788908756" TEXT="Beispiel">
<linktarget COLOR="#a9b4c1" DESTINATION="ID_1385929770" ENDARROW="Default" ENDINCLINATION="1055;0;" ID="Arrow_ID_1314305180" SOURCE="ID_426069181" STARTARROW="None" STARTINCLINATION="1055;0;"/>
<icon BUILTIN="idea"/>
</node>
<node CREATED="1477527104426" ID="ID_334736261" MODIFIED="1477527138549" TEXT="custom style properties">
@ -9291,8 +9319,29 @@
<icon BUILTIN="info"/>
</node>
</node>
<node CREATED="1446515847047" ID="ID_290915762" MODIFIED="1446515861953" TEXT="GtkCssProvider">
<node CREATED="1446515847047" FOLDED="true" ID="ID_290915762" MODIFIED="1477784898996" TEXT="GtkCssProvider">
<node CREATED="1446515865029" ID="ID_1503616150" MODIFIED="1446515869624" TEXT="parsing errors"/>
<node CREATED="1477784584821" ID="ID_1810760662" LINK="https://developer.gnome.org/gtkmm-tutorial/stable/sec-custom-widgets.html.en" MODIFIED="1477784889994" TEXT="Beispiel im GTKmm-Guide (custom widget)">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
in der Implementierung, mywidget.cc
</p>
<p>
ist eine komplette Sequenz, wie man einen CSS-StyleProvider setzt
</p>
<p>
und auch ein Signal f&#252;r Parse-Fehler anschlie&#223;t
</p>
</body>
</html>
</richcontent>
<linktarget COLOR="#a9b4c1" DESTINATION="ID_1810760662" ENDARROW="Default" ENDINCLINATION="1846;-61;" ID="Arrow_ID_1610122569" SOURCE="ID_1164942946" STARTARROW="None" STARTINCLINATION="-227;-646;"/>
<icon BUILTIN="info"/>
</node>
</node>
<node CREATED="1476375676818" ID="ID_1029920942" MODIFIED="1476375683685" TEXT="Canvas">
<node CREATED="1476375696215" ID="ID_1397403295" MODIFIED="1476375700698" TEXT="GtkDrawingArea">
@ -9355,6 +9404,41 @@
<node CREATED="1477595418669" ID="ID_517122292" MODIFIED="1477596119220" TEXT="# learn how to draw">
<font ITALIC="true" NAME="SansSerif" SIZE="12"/>
<icon BUILTIN="full-2"/>
<node CREATED="1477788816168" ID="ID_904860978" MODIFIED="1477788929338" TEXT="documentation">
<icon BUILTIN="info"/>
<node CREATED="1477788823751" ID="ID_111966354" LINK="https://developer.gnome.org/gtkmm-tutorial/stable/chapter-drawingarea.html.en" MODIFIED="1477788918987" TEXT="read the custom drawing chapter">
<arrowlink DESTINATION="ID_1600280983" ENDARROW="Default" ENDINCLINATION="893;0;" ID="Arrow_ID_1707544457" STARTARROW="None" STARTINCLINATION="893;0;"/>
</node>
<node CREATED="1477788855234" ID="ID_426069181" LINK="https://developer.gnome.org/gtkmm-tutorial/stable/sec-custom-widgets.html.en" MODIFIED="1477788908756" TEXT="read the example code of a custom widget">
<arrowlink DESTINATION="ID_1385929770" ENDARROW="Default" ENDINCLINATION="1055;0;" ID="Arrow_ID_1314305180" STARTARROW="None" STARTINCLINATION="1055;0;"/>
</node>
<node CREATED="1477789514451" ID="ID_84890591" LINK="https://www.cairographics.org/documentation/cairomm/reference/" MODIFIED="1477789523593" TEXT="Cairomm API-doc"/>
</node>
<node CREATED="1477784938038" ID="ID_93104177" MODIFIED="1477784941482" TEXT="how-to...">
<node CREATED="1477788718965" ID="ID_1354942176" MODIFIED="1477788722040" TEXT="derived class"/>
<node CREATED="1477788722228" ID="ID_720985572" MODIFIED="1477788730239" TEXT="override on_draw()"/>
<node CREATED="1477788731163" ID="ID_421749777" MODIFIED="1477788740646" TEXT="invoke inherited on_draw()">
<icon BUILTIN="messagebox_warning"/>
</node>
<node CREATED="1477788749289" ID="ID_1466181075" MODIFIED="1477788790117" TEXT="returns false">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
...meaning, &quot;this event is not yet fully processed&quot;,
</p>
<p>
i.e. the enclosing parent widget also gets a chance to redraw itself
</p>
</body>
</html>
</richcontent>
</node>
</node>
<node CREATED="1477784943797" ID="ID_298493039" MODIFIED="1477784946617" TEXT="layering"/>
<node CREATED="1477784949533" ID="ID_1496795315" MODIFIED="1477784952776" TEXT="custom styling"/>
</node>
<node CREATED="1477595418670" ID="ID_770195423" MODIFIED="1477596119220" TEXT="# place a huge number of widgets, to scrutinise scrolling and performance">
<font ITALIC="true" NAME="SansSerif" SIZE="12"/>