Minsky: 3.17.0
minskyCairoRenderer.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2023
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef MINSKYCAIRORENDERER_H
21 #define MINSKYCAIRORENDERER_H
22 #include "cairoRenderer.h"
23 #include "pango.h"
24 
25 namespace minsky
26 {
27  struct CairoRenderer: public ravel::CairoRenderer
28  {
29  ecolab::Pango m_pango;
30 
31  static ecolab::Pango& pango(CAPIRenderer* r) {return static_cast<CairoRenderer*>(r)->m_pango;}
32 
33  static void s_showText(CAPIRenderer* c, const char* s)
34  {
35  double x,y;
36  cairo_get_current_point(cairo(c),&x,&y);
37  pango(c).setText(s);
38  // paint a partially obscure white rectange to make the text pop
39  cairo_save(cairo(c));
40  cairo_rectangle(cairo(c),x,y,pango(c).width(),pango(c).height());
41  cairo_set_source_rgba(cairo(c),1,1,1,0.3);
42  cairo_fill(cairo(c));
43  cairo_restore(cairo(c));
44  cairo_move_to(cairo(c),x,y);
45  pango(c).show();
46  }
47  static void s_setTextExtents(CAPIRenderer* c, const char* s)
48  {pango(c).setText(s);}
49  static double s_textWidth(CAPIRenderer* c) {return pango(c).width();}
50  static double s_textHeight(CAPIRenderer* c) {return pango(c).height();}
51 
52  CairoRenderer(cairo_t* cairo): ravel::CairoRenderer(cairo), m_pango(cairo) {
53  showText=s_showText;
54  setTextExtents=s_setTextExtents;
55  textWidth=s_textWidth;
56  textHeight=s_textHeight;
57  }
58 
59  };
60 }
61 
62 #endif
static void s_showText(CAPIRenderer *c, const char *s)
CairoRenderer(cairo_t *cairo)
static ecolab::Pango & pango(CAPIRenderer *r)
static void s_setTextExtents(CAPIRenderer *c, const char *s)
static double s_textHeight(CAPIRenderer *c)
static double s_textWidth(CAPIRenderer *c)