creativity  v1.3.0
Agent-based model of creativity and piracy
GraphArea.hpp
1 #pragma once
2 #include <eris/types.hpp>
3 #include <eris/noncopyable.hpp>
4 #include <eris/WrappedPositional.hpp>
5 #include <gtkmm/drawingarea.h>
6 #include <cairomm/matrix.h>
7 #include <cairomm/pattern.h>
8 #include <cairomm/refptr.h>
9 #include <cairomm/surface.h>
10 #include <cstddef>
11 #include <vector>
12 
13 namespace Cairo { class Context; }
14 
15 namespace creativity { namespace gui {
16 
17 class GUI;
18 
20 class GraphArea : public Gtk::DrawingArea, eris::noncopyable {
21  public:
22  GraphArea() = delete;
23 
26  GraphArea(GUI &gui);
27 
37  Cairo::Matrix graph_to_canvas() const;
38 
42  Cairo::Matrix canvas_to_graph() const;
43 
55  eris::Position graph_position(const eris::Position &p);
56 
59  virtual bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) override;
60 
62  enum class PointType {
63  X,
64  CROSS,
65  SQUARE
66  };
67 
69  using Colour = Cairo::RefPtr<Cairo::SolidPattern>;
70 
81  void drawPoint(const Cairo::RefPtr<Cairo::Context> &cr, const Cairo::Matrix &trans, const eris::Position &point,
82  const PointType &type, const Colour &colour, double radius, double line_width);
83 
105  void drawGraphCircle(const Cairo::RefPtr<Cairo::Context> &cr, const Cairo::Matrix &trans,
106  double cx, double cy, double r, const Colour &colour, double stroke_width, double radial_stroke_width = 0.0);
107 
128  void drawCanvasCircle(const Cairo::RefPtr<Cairo::Context> &cr, const Cairo::Matrix &trans,
129  const eris::Position &centre, double r, const Colour &colour, double stroke_width, double radial_stroke_width = 0.0);
130 
145  void drawLine(const Cairo::RefPtr<Cairo::Context> &cr, const Cairo::Matrix &trans,
146  const eris::Position &from, const eris::Position &to,
147  double min_length = 0.0, Colour start_colour = Colour(), Colour end_colour = Colour());
148 
154  void drawAxes(const Cairo::RefPtr<Cairo::Context> &cr, const Cairo::Matrix &trans);
155 
163  void drawCircularAxis(const Cairo::RefPtr<Cairo::Context> &cr, const Cairo::Matrix &trans);
164 
168  struct {
170  struct {
171  bool
172  reader = true,
173  friendship = true,
174  movement = true,
175  book_live = true,
176  book_dead = true,
177  book_public = true,
178  author_live = true,
179  author_dead = true,
180  author_public = true,
181  reading = true,
182  utility_gain = true,
183  utility_loss = true,
184  axes = true;
185  } enabled;
186 
188  struct {
189  Colour
191  book_live = Cairo::SolidPattern::create_rgb(0, .4, 1),
193  book_dead = Cairo::SolidPattern::create_rgb(0.5, 0.5, 0.5),
195  book_public = Cairo::SolidPattern::create_rgb(0.306, 0.604, 0.024),
197  author_live = Cairo::SolidPattern::create_rgba(0.5, 0.2, 0.5, 0.5),
199  author_dead = Cairo::SolidPattern::create_rgba(0.75, 0.5, 0.75, 0.5),
201  author_public = Cairo::SolidPattern::create_rgba(0.5, 0.2, 0.5, 0.25),
203  reading = Cairo::SolidPattern::create_rgba(1, 0.55, 0, 0.5),
205  reader = Cairo::SolidPattern::create_rgb(1, 0, 0),
207  friendship = Cairo::SolidPattern::create_rgba(0.75, 0, 0, 0.5),
211  movement = Cairo::SolidPattern::create_rgba(1, 0, 0, 0.75),
213  utility_gain = Cairo::SolidPattern::create_rgba(.133, .545, .133, 0.5),
215  utility_loss = Cairo::SolidPattern::create_rgba(.545, .133, .133, 0.5),
217  axes = Cairo::SolidPattern::create_rgb(0, 0, 0),
219  background = Cairo::SolidPattern::create_rgb(1, 1, 1);
220  } colour;
221 
226  struct {
227  std::vector<double>
231  author_dead{{3.0, 2.0}},
233  author_public{{3.0, 2.0}},
235  reading,
237  friendship{{12.0, 3.0}},
239  movement,
241  utility;
242  } dash;
243 
245  struct {
246  double
247  book_live = 2.0,
248  book_dead = 2.0,
249  book_public = 2.0,
250  author_live = 2.0,
251  author_dead = 2.0,
252  author_public = 2.0,
253  reading = 2.0,
254  reader = 2.0,
255  friendship = 1.0,
256  movement = 3.0,
257  utility = 2.0,
258  utility_radial = 1.0,
259  axes = 2.0,
260  axes_ticks = 1.0,
261  axes_ticks_big = 2.0;
262  } stroke_width;
263 
265  struct {
266  double
267  reader = 7.071,
268 
271  book = 5.0,
275  book_scale_a = 3.0,
279  book_scale_b = 0.3,
284  utility_gain_scale = 5.0,
289  utility_loss_scale = 5.0,
293  tick = 6.0,
295  tick_big = 18.0;
296 
297  } size;
298 
300  struct {
301  PointType
303  reader = PointType::X,
305  book_live = PointType::CROSS,
307  book_dead = PointType::CROSS,
309  book_public = PointType::CROSS;
310 
311  double
313  tick_every = 1.0,
315  movement_alpha_multiplier = 0.1;
316 
317  unsigned int
319  tick_big = 5;
320  } style;
321 
325  size_t subdimensionX = 0;
329  size_t subdimensionY = 1;
330 
331  } design;
332 
337  void resetCache();
338 
339  protected:
348  void drawPointSingle(const Cairo::RefPtr<Cairo::Context> &cr, const Cairo::Matrix &trans,
349  double x, double y, const PointType &type, const Colour &colour, double radius, double line_width);
350 
354  eris::WrappedPositionalBase wpb_;
355 
360  std::list<std::pair<eris::eris_time_t, Cairo::RefPtr<Cairo::ImageSurface>>> drawing_cache_;
362  int drawing_cache_width_ = -1;
364  int drawing_cache_height_ = -1;
365 
366 };
367 
368 } }
Primary namespace for all Creativity library code.
Definition: config.hpp:4
std::vector< double > reading
The dash pattern of lines from readers to newly purchased books.
Definition: GraphArea.hpp:233
Gtk drawing area upon which the simulation state visualization is drawn.
Definition: GraphArea.hpp:20
Class that runs a GUI in a thread, collecting its events into a queue to be processed periodically (e...
Definition: GUI.hpp:49
eris::WrappedPositionalBase wpb_
Helper object for doing wrapping calculations.
Definition: GraphArea.hpp:354
Cairo::RefPtr< Cairo::SolidPattern > Colour
Typedef of Colour to the appropriate ref-pointed Cairo class.
Definition: GraphArea.hpp:69
GUI & gui_
The parent GUI.
Definition: GraphArea.hpp:352
Definition: GraphArea.hpp:13
std::list< std::pair< eris::eris_time_t, Cairo::RefPtr< Cairo::ImageSurface > > > drawing_cache_
Cache of the most recently used image surfaces; these save redrawing when transitioning back and fort...
Definition: GraphArea.hpp:360
PointType
The types of points drawn by this class.
Definition: GraphArea.hpp:62
std::vector< double > utility
The dash pattern of the utility circle (for readers with utility > 1000)
Definition: GraphArea.hpp:237
std::vector< double > author_live
The dash pattern of author lines to on-market books.
Definition: GraphArea.hpp:229