creativity  v1.3.0
Agent-based model of creativity and piracy
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
creativity::gui::GraphArea Class Reference

Gtk drawing area upon which the simulation state visualization is drawn. More...

#include <creativity/gui/GraphArea.hpp>

Public Types

enum  PointType { PointType::X, PointType::CROSS, PointType::SQUARE }
 The types of points drawn by this class. More...
 
using Colour = Cairo::RefPtr< Cairo::SolidPattern >
 Typedef of Colour to the appropriate ref-pointed Cairo class.
 

Public Member Functions

 GraphArea (GUI &gui)
 Creates a graph area that draws according to the boundary of the given GUI object.
 
Cairo::Matrix graph_to_canvas () const
 Returns a Cairo::Matrix that translates graph coordinates into canvas (i.e. More...
 
Cairo::Matrix canvas_to_graph () const
 Returns a Cairo::Matrix that tranlates canvas coordinates into graph coordinates. More...
 
eris::Position graph_position (const eris::Position &p)
 Returns the graph position (with each dimension between -boundary and +boundary) from a simulation Position. More...
 
virtual bool on_draw (const Cairo::RefPtr< Cairo::Context > &cr) override
 Draws the current set of points/circles, and updates the data in any reader/book dialogs. More...
 
void drawPoint (const Cairo::RefPtr< Cairo::Context > &cr, const Cairo::Matrix &trans, const eris::Position &point, const PointType &type, const Colour &colour, double radius, double line_width)
 Draws a point. More...
 
void drawGraphCircle (const Cairo::RefPtr< Cairo::Context > &cr, const Cairo::Matrix &trans, double cx, double cy, double r, const Colour &colour, double stroke_width, double radial_stroke_width=0.0)
 Draws a circle in graph space, not canvas space, so this is actually going to end up drawing ovals (unless the canvas happens to be perfectly square). More...
 
void drawCanvasCircle (const Cairo::RefPtr< Cairo::Context > &cr, const Cairo::Matrix &trans, const eris::Position &centre, double r, const Colour &colour, double stroke_width, double radial_stroke_width=0.0)
 Draws a circle in canvas space, which will always appear circular on the GUI element (but won't be circular in graph space). More...
 
void drawLine (const Cairo::RefPtr< Cairo::Context > &cr, const Cairo::Matrix &trans, const eris::Position &from, const eris::Position &to, double min_length=0.0, Colour start_colour=Colour(), Colour end_colour=Colour())
 Draws the shortest line between two points, allowing the line to wrap across simulation boundaries. More...
 
void drawAxes (const Cairo::RefPtr< Cairo::Context > &cr, const Cairo::Matrix &trans)
 Draws a pair of graph axes going to -boundary to +boundary in each dimension. More...
 
void drawCircularAxis (const Cairo::RefPtr< Cairo::Context > &cr, const Cairo::Matrix &trans)
 Draws a circular single axis for a 1D model that goes from 0 (at the right) rotating counterclockwise through to boundary and clockwise to -boundary (both are the leftmost point). More...
 
void resetCache ()
 Resets the drawn image cache. More...
 

Public Attributes

struct {
   struct {
      bool   reader = true
 Whether to draw agents.
 
      bool   friendship = true
 Whether to draw friendship links.
 
      bool   movement = true
 Whether to draw a reader movement trail.
 
      bool   book_live = true
 Whether to draw on-market books.
 
      bool   book_dead = true
 Whether to draw off-market books.
 
      bool   book_public = true
 Whether to draw public-market books.
 
      bool   author_live = true
 Whether to draw on-market authorship lines.
 
      bool   author_dead = true
 Whether to draw off-market authorship lines.
 
      bool   author_public = true
 Whether to draw public-market authorship lines.
 
      bool   reading = true
 Whether to draw lines for newly obtained books.
 
      bool   utility_gain = true
 Whether to draw utility gain circles.
 
      bool   utility_loss = true
 Whether to draw utility loss circles.
 
      bool   axes = true
 Whether to draw the graph axes.
 
   }   enabled
 Struct controlling whether various elements are drawn in the graph.
 
   struct {
      Colour   book_live = Cairo::SolidPattern::create_rgb(0, .4, 1)
 The colour of private, on-market books.
 
      Colour   book_dead = Cairo::SolidPattern::create_rgb(0.5, 0.5, 0.5)
 The colour of off-market books.
 
      Colour   book_public = Cairo::SolidPattern::create_rgb(0.306, 0.604, 0.024)
 The colour of public-market books.
 
      Colour   author_live = Cairo::SolidPattern::create_rgba(0.5, 0.2, 0.5, 0.5)
 Authorship lines from author to book for on-market books.
 
      Colour   author_dead = Cairo::SolidPattern::create_rgba(0.75, 0.5, 0.75, 0.5)
 Authorship lines from author to book for off-market books.
 
      Colour   author_public = Cairo::SolidPattern::create_rgba(0.5, 0.2, 0.5, 0.25)
 Authorship lines from author to book for public-market books.
 
      Colour   reading = Cairo::SolidPattern::create_rgba(1, 0.55, 0, 0.5)
 The colour of lines from readers to newly purchased books.
 
      Colour   reader = Cairo::SolidPattern::create_rgb(1, 0, 0)
 The colour of agents (readers/authors)
 
      Colour   friendship = Cairo::SolidPattern::create_rgba(0.75, 0, 0, 0.5)
 The colour of friendship links between readers.
 
      Colour   movement = Cairo::SolidPattern::create_rgba(1, 0, 0, 0.75)
 The colour of the movement trail; the actual trail will be a gradient from fully transparent to this colour.
 
      Colour   utility_gain = Cairo::SolidPattern::create_rgba(.133, .545, .133, 0.5)
 The colour of the utility circle (for readers with utility > 1000)
 
      Colour   utility_loss = Cairo::SolidPattern::create_rgba(.545, .133, .133, 0.5)
 The colour of the utility loss circle (for readers with utility < 1000)
 
      Colour   axes = Cairo::SolidPattern::create_rgb(0, 0, 0)
 The colour of the graph axes and tick marks.
 
      Colour   background = Cairo::SolidPattern::create_rgb(1, 1, 1)
 The colour of the background.
 
   }   colour
 The colours of various visualization elements.
 
   struct {
      std::vector< double >   author_live
 The dash pattern of author lines to on-market books.
 
      std::vector< double >   author_dead {{3.0, 2.0}}
 The dash pattern of author lines to off-market books.
 
      std::vector< double >   author_public {{3.0, 2.0}}
 The dash pattern of author lines to public-market books.
 
      std::vector< double >   reading
 The dash pattern of lines from readers to newly purchased books.
 
      std::vector< double >   friendship {{12.0, 3.0}}
 The dash pattern of friendship links between readers.
 
      std::vector< double >   movement
 The dash pattern of reader movement trails.
 
      std::vector< double >   utility
 The dash pattern of the utility circle (for readers with utility > 1000)
 
   }   dash
 The dash pattern of various visualization elements. More...
 
   struct {
      double   book_live = 2.0
 Stroke width of live books.
 
      double   book_dead = 2.0
 Stroke width of dead books.
 
      double   book_public = 2.0
 Stroke width of public books.
 
      double   author_live = 2.0
 Stroke width of author-to-live book lines.
 
      double   author_dead = 2.0
 Stroke width of author-to-dead book lines.
 
      double   author_public = 2.0
 Stroke width of author-to-dead book lines.
 
      double   reading = 2.0
 Width of lines from readers to newly-obtained books.
 
      double   reader = 2.0
 Stroke width of agent icons.
 
      double   friendship = 1.0
 Stroke width of reader-to-reader friendship links.
 
      double   movement = 3.0
 Stroke width of movement path.
 
      double   utility = 2.0
 Stroke width of utility circles.
 
      double   utility_radial = 1.0
 Stroke width of the radial line of utility circles.
 
      double   axes = 2.0
 Stroke width of the graph axes.
 
      double   axes_ticks = 1.0
 Stroke width of graph axes tick marks.
 
      double   axes_ticks_big = 2.0
 Stroke width of every nth tick mark.
 
   }   stroke_width
 The stroke width used to draw various visualization elements.
 
   struct {
      double   reader = 7.071
 Radius of a reader "x" symbol.
 
      double   book = 5.0
 Minimum radius of a book "+" symbol. More...
 
      double   book_scale_a = 3.0
 Scaling parameter 'a' for live books; books are scaled to the above book_live parameter times \(\max(1.0, a - b \times age)\).
 
      double   book_scale_b = 0.3
 Scaling parameter 'b' for live books; books are scaled to the above book_live parameter times \(\max(1.0, a - b \times age)\).
 
      double   utility_gain_scale = 5.0
 The radius multiple for the reader utility gain circle; the circle is drawn with a radius around the reader of \(r*ln(u-999)\), where this value is \(r\), but only for readers with utility above 1000.
 
      double   utility_loss_scale = 5.0
 The radius multiple for the reader utility loss circle; the circle is drawn with a radius around the reader of \(r*ln(1001-u)\), where this value is \(r\), but only for readers with utility below 1000.
 
      double   tick = 6.0
 Length of regular tick marks, in pixels. More...
 
      double   tick_big = 18.0
 Length of big tick marks (every 5th tick, by default), in pixels.
 
   }   size
 The sizes of visual elements.
 
   struct {
      PointType   reader = PointType::X
 The point type of readers.
 
      PointType   book_live = PointType::CROSS
 The point type of live books.
 
      PointType   book_dead = PointType::CROSS
 The point type of dead books.
 
      PointType   book_public = PointType::CROSS
 The point type of public books.
 
      double   tick_every = 1.0
 Spacing of axes tick marks. 2.0 means ticks at 2, 4, 6, etc.
 
      double   movement_alpha_multiplier = 0.1
 Alpha multiplier for the starting colour of the movement line gradient.
 
      unsigned int   tick_big = 5
 Every style.tick_bigth tick will be size.tick_big-sized.
 
   }   style
 The visual design of types of points (readers and books)
 
   size_t   subdimensionX = 0
 If displaying a 3 (or more) dimensional simulation, this is the dimension index to display on the X axis.
 
   size_t   subdimensionY = 1
 If displaying a 3 (or more) dimensional simulation, this is the dimension index to display on the Y axis.
 
design
 Struct containing various graph properties such as colours, line widths, and dash styles.
 

Protected Member Functions

void drawPointSingle (const Cairo::RefPtr< Cairo::Context > &cr, const Cairo::Matrix &trans, double x, double y, const PointType &type, const Colour &colour, double radius, double line_width)
 Called by drawPoint() with graph coordinates to draw individual canvas points. More...
 

Protected Attributes

GUIgui_
 The parent GUI.
 
eris::WrappedPositionalBase wpb_
 Helper object for doing wrapping calculations.
 
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 forth between states. More...
 
int drawing_cache_width_ = -1
 The width of the elements in drawing_cache_.
 
int drawing_cache_height_ = -1
 The height of the elements in drawing_cache_.
 

Detailed Description

Gtk drawing area upon which the simulation state visualization is drawn.

Member Enumeration Documentation

§ PointType

The types of points drawn by this class.

Enumerator

A diagonal cross, used for readers.

CROSS 

A horizontal/vertical cross, used for books.

SQUARE 

A small square. Currently unused.

Member Function Documentation

§ canvas_to_graph()

Cairo::Matrix creativity::gui::GraphArea::canvas_to_graph ( ) const

Returns a Cairo::Matrix that tranlates canvas coordinates into graph coordinates.

To go the other way, call graph_to_canvas(), or .invert() the returned matrix.

§ drawAxes()

void creativity::gui::GraphArea::drawAxes ( const Cairo::RefPtr< Cairo::Context > &  cr,
const Cairo::Matrix &  trans 
)

Draws a pair of graph axes going to -boundary to +boundary in each dimension.

Parameters
crthe Cairo::Context on which to draw
transthe transformation matrix that converts graph points to canvas points

§ drawCanvasCircle()

void creativity::gui::GraphArea::drawCanvasCircle ( const Cairo::RefPtr< Cairo::Context > &  cr,
const Cairo::Matrix &  trans,
const eris::Position &  centre,
double  r,
const Colour colour,
double  stroke_width,
double  radial_stroke_width = 0.0 
)

Draws a circle in canvas space, which will always appear circular on the GUI element (but won't be circular in graph space).

A radial line will also be drawn (if radial_stroke_width > 0) from the center of the circle to a random point of the circumference. The pseudo-random angle is calculated using the given center point and radius so that redrawing and resizing the canvas will not change the angle.

Parameters
crthe Cairo::Context used for drawing
transthe transformation matrix that transforms graph points to canvas points
centrethe centre location, in simulation (not graph or canvas!) space
rthe radius of the circle, in canvas (not graph!) space
colourthe colour (and possibly alpha value) of the circle.
stroke_widththe width of the stroke used to draw the circle
radial_stroke_widththe width of the stroke used to draw a line from the centre to the circle circumference (at a random angle). If 0, no radial is drawn.
See also
drawCanvasCircle for drawing a circle in canvas space (which generally looks like an oval on the screen, unless the GraphArea canvas happens to be exactly square).

§ drawCircularAxis()

void creativity::gui::GraphArea::drawCircularAxis ( const Cairo::RefPtr< Cairo::Context > &  cr,
const Cairo::Matrix &  trans 
)

Draws a circular single axis for a 1D model that goes from 0 (at the right) rotating counterclockwise through to boundary and clockwise to -boundary (both are the leftmost point).

Parameters
crthe Cairo::Context on which to draw
transthe transformation matrix that converts graph points to canvas points

§ drawGraphCircle()

void creativity::gui::GraphArea::drawGraphCircle ( const Cairo::RefPtr< Cairo::Context > &  cr,
const Cairo::Matrix &  trans,
double  cx,
double  cy,
double  r,
const Colour colour,
double  stroke_width,
double  radial_stroke_width = 0.0 
)

Draws a circle in graph space, not canvas space, so this is actually going to end up drawing ovals (unless the canvas happens to be perfectly square).

The circle can also have a radial line drawn at a random angle, if given a non-zero radial stroke width. The angle is calculated from the given coordinates and radius, and so will not change across redraws.

Parameters
crthe Cairo::Context used for drawing
transthe transformation matrix that translates from graph space to canvas space
cxthe centre x coordinate, in graph space
cythe centre y coordinate, in graph space
rthe radius of the circle, in graph space
colourthe colour (and possibly alpha value) of the circle.
stroke_widththe width of the stroke used to draw the circle.
radial_stroke_widththe width of the stroke used to draw a line from the centre to the circle circumference (at a random angle). If 0, no radial is drawn.

Also note that circles currently do not wrap, unlike points and lines.

See also
drawCanvasCircle for drawing a circle in canvas space, i.e. something that will always show up to the user as a circle.

§ drawLine()

void creativity::gui::GraphArea::drawLine ( const Cairo::RefPtr< Cairo::Context > &  cr,
const Cairo::Matrix &  trans,
const eris::Position &  from,
const eris::Position &  to,
double  min_length = 0.0,
Colour  start_colour = Colour(),
Colour  end_colour = Colour() 
)

Draws the shortest line between two points, allowing the line to wrap across simulation boundaries.

Note that when a line wraps this actually involves drawing several line segments.

Parameters
crthe Cairo::Context on which to draw
transthe transformation matrix that converts graph points to canvas points
fromthe start position of the line, in simulation space
tothe end position of the line, in simulation space
min_lengththe minimum length line to draw; if the on-screen line length (in pixels) is less than this, it will not be drawn. If omitted, defaults to 0 (no minimum).
start_colourthe start colour of the line (if not specified, the stroke colour is not changed), for creating a line with a gradient.
end_colourthe ending colour of the line, for creating a line with a gradient.

§ drawPoint()

void creativity::gui::GraphArea::drawPoint ( const Cairo::RefPtr< Cairo::Context > &  cr,
const Cairo::Matrix &  trans,
const eris::Position &  point,
const PointType type,
const Colour colour,
double  radius,
double  line_width 
)

Draws a point.

Drawn points have a fixed size that does not depend on the drawing area size.

Parameters
crthe Cairo::Context used for drawing
transthe transformation matrix that translates from graph space to display space
pointthe location of the point, in simulation space
typethe type of point to draw
colourthe colour (and alpha channel) of the point
radiusthe radius of the point. 1 (the default) means default size.
line_widththe line width to use to draw the point indicator

§ drawPointSingle()

void creativity::gui::GraphArea::drawPointSingle ( const Cairo::RefPtr< Cairo::Context > &  cr,
const Cairo::Matrix &  trans,
double  x,
double  y,
const PointType type,
const Colour colour,
double  radius,
double  line_width 
)
protected

Called by drawPoint() with graph coordinates to draw individual canvas points.

This will be called from 1 to 4 times per drawPoint() call: once for the actual point, and potential other calls for the wrapped version when the point is close to an edge or corner.

The given x and y values are the graph coordinates (which will be translated in canvas coordinates).

§ graph_position()

eris::Position creativity::gui::GraphArea::graph_position ( const eris::Position &  p)

Returns the graph position (with each dimension between -boundary and +boundary) from a simulation Position.

If the simulation is two dimensional, the graph position equals the simulation Position. If one-dimensional, the graph position is the position on a circle of radius 0.9*boundary 1 dimension, where position 0 is the right-most point of the circle, boundary/2 is the top, boundary (and -boundary) is the left-most point, etc.

If 3- (or more) dimensional, the design.subdimensionX and design.subdimensionY dimension indices are used.

§ graph_to_canvas()

Cairo::Matrix creativity::gui::GraphArea::graph_to_canvas ( ) const

Returns a Cairo::Matrix that translates graph coordinates into canvas (i.e.

on-screen pixel) coordinates. To go the other way, call canvas_to_graph(), or .invert() the returned matrix.

Note that the graph is always 2-dimensional; when the simulation is 2-dimensional, graph positions are exactly simulation positions. When 1-dimensional, positions are mapped from 1D into a graph circle. When 3-dimensional, the graph position is the simulation position in the design.subdimensionX and design.subdimensionY indices.

§ on_draw()

virtual bool creativity::gui::GraphArea::on_draw ( const Cairo::RefPtr< Cairo::Context > &  cr)
overridevirtual

Draws the current set of points/circles, and updates the data in any reader/book dialogs.

§ resetCache()

void creativity::gui::GraphArea::resetCache ( )

Resets the drawn image cache.

This should be called after changing anything in .design. This does not, however, trigger a redraw, so this should typically be followed by a call to .queue_draw().

Member Data Documentation

§ book

double creativity::gui::GraphArea::book = 5.0

Minimum radius of a book "+" symbol.

Note that newer books are scaled to a multiple of this size.

§ dash

struct { ... } creativity::gui::GraphArea::dash

The dash pattern of various visualization elements.

An empty vector results in a solid line; otherwise vector elements are alternating lengths of on and off line segments along the path.

§ drawing_cache_

std::list<std::pair<eris::eris_time_t, Cairo::RefPtr<Cairo::ImageSurface> > > creativity::gui::GraphArea::drawing_cache_
protected

Cache of the most recently used image surfaces; these save redrawing when transitioning back and forth between states.

The size of the cache is governed by GUI::temporal_cache_size_.

§ reader

double creativity::gui::GraphArea::reader = 2.0

Stroke width of agent icons.

Radius of a reader "x" symbol.

§ tick

double creativity::gui::GraphArea::tick = 6.0

Length of regular tick marks, in pixels.

The tick extends half this distance away from the axis in both directions.

Inheritance diagram for creativity::gui::GraphArea:
[legend]
Collaboration diagram for creativity::gui::GraphArea:
[legend]

The documentation for this class was generated from the following file: