Minsky
minsky::RenderVariable Class Reference

#include <cairoItems.h>

Inheritance diagram for minsky::RenderVariable:
Inheritance graph
Collaboration diagram for minsky::RenderVariable:
Collaboration graph

Public Member Functions

 RenderVariable (const VariableBase &var, cairo_t *cairo=NULL)
 
void draw ()
 render the cairo image More...
 
float width () const
 half width of unrotated image More...
 
float height () const
 half height of unrotated image More...
 
bool inImage (float x, float y)
 return the boost geometry corresponding to this variable's shape More...
 
double handlePos () const
 

Private Attributes

const VariableBasevar
 
cairo_t * cairo
 
float w
 
float h
 
float hoffs
 

Detailed Description

class that renders a variable into a cairo context. A user can also query the size of the unrotated rendered image

Definition at line 34 of file cairoItems.h.

Constructor & Destructor Documentation

◆ RenderVariable()

RenderVariable::RenderVariable ( const VariableBase var,
cairo_t *  cairo = NULL 
)

Definition at line 50 of file cairoItems.cc.

References minsky::VariableType::constant, minsky::EngNotation::engExp, minsky::VariableBase::engExp(), minsky::expMultiplier(), h, hoffs, minsky::VariableBase::ioVar(), minsky::latexToPango(), minsky::VariableBase::mantissa(), minsky::VariableBase::name(), minsky::VariableBase::type(), var, and w.

50  :
51  Pango(cairo? cairo: dummySurf.cairo()), var(var), cairo(cairo)
52 {
53  setFontSize(12);
55  {
56  try
57  {
58  auto val=var.engExp();
59  if (val.engExp==-3) val.engExp=0; //0.001-1.0
60  setMarkup(var.mantissa(val)+expMultiplier(val.engExp));
61  }
62  catch (const std::exception& ex)
63  {
64  setMarkup("0");
65  }
66  w=0.5*Pango::width();
67  h=0.5*Pango::height();
68  }
69  else
70  {
71  setMarkup(latexToPango(var.name()));
72  w=0.5*Pango::width();
73  h=0.5*Pango::height();
74  if (!var.ioVar())
75  { // add additional space for numerical display
76  w+=12;
77  h+=4;
78  }
79  }
80  hoffs=Pango::top();
81 }
std::string expMultiplier(int exp)
std::string latexToPango(const char *s)
Definition: latexMarkup.h:30
virtual Type type() const =0
cairo::Surface dummySurf(cairo_image_surface_create(CAIRO_FORMAT_A1, 100, 100))
const VariableBase & var
Definition: cairoItems.h:36
bool ioVar() const override
indicates this is a group I/O variable
Definition: variable.cc:258
EngNotation engExp() const
return formatted mantissa and exponent in engineering format
Definition: variable.h:227
virtual std::string name() const
variable displayed name
Definition: variable.cc:201
std::string mantissa(const EngNotation &e, int digits=3) const
Definition: variable.h:229
Here is the call graph for this function:

Member Function Documentation

◆ draw()

void RenderVariable::draw ( )

render the cairo image

Definition at line 83 of file cairoItems.cc.

References cairo, minsky::VariableBase::draw(), and var.

Referenced by minsky::IntOp::draw(), minsky::VariablePaneCell::show(), and minsky::VariablePaneCell::VariablePaneCell().

84 {
85  var.draw(cairo);
86 
87 }
const VariableBase & var
Definition: cairoItems.h:36
void draw(cairo_t *) const override
Definition: variable.cc:704
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handlePos()

double RenderVariable::handlePos ( ) const

Definition at line 97 of file cairoItems.cc.

References minsky::Item::iWidth(), var, minsky::VariableBase::vValue(), and w.

Referenced by minsky::VariableBase::clickType().

98 {
99  if (auto vv=var.vValue())
100  {
101  vv->adjustSliderBounds();
102  assert(vv->sliderMin<vv->sliderMax);
103  return (w<0.5*var.iWidth()? 0.5*var.iWidth() : w)*(vv->value()-0.5*(vv->sliderMin+vv->sliderMax))/(vv->sliderMax-vv->sliderMin);
104  }
105  else
106  return 0;
107 }
const VariableBase & var
Definition: cairoItems.h:36
float iWidth() const
Definition: item.h:217
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:161
Here is the call graph for this function:
Here is the caller graph for this function:

◆ height()

float minsky::RenderVariable::height ( ) const
inline

half height of unrotated image

Definition at line 47 of file cairoItems.h.

References h.

Referenced by minsky::anonymous_namespace{godleyIcon.cc}::accumulateWidthHeight(), minsky::VariableBase::clickType(), minsky::Canvas::copyVars(), and minsky::IntOp::draw().

47 {return h;}
Here is the caller graph for this function:

◆ inImage()

bool RenderVariable::inImage ( float  x,
float  y 
)

return the boost geometry corresponding to this variable's shape

true if (x,y) within rendered image x coordinate of the slider handle in the unrotated/unscaled frame of reference

Definition at line 89 of file cairoItems.cc.

References MathDAG::cos(), h, M_PI, minsky::Item::rotation(), MathDAG::sin(), var, w, minsky::Item::x(), and minsky::Item::y().

Referenced by minsky::Group::select().

90 {
91  const float dx=x-var.x(), dy=y-var.y();
92  const float rx=dx*cos(var.rotation()*M_PI/180)-dy*sin(var.rotation()*M_PI/180);
93  const float ry=dy*cos(var.rotation()*M_PI/180)+dx*sin(var.rotation()*M_PI/180);
94  return rx>=-w && rx<=w && ry>=-h && ry <= h;
95 }
#define M_PI
some useful geometry types, defined from boost::geometry
Definition: geometry.h:29
Expr sin(const Expr &x)
Definition: expr.h:131
Expr cos(const Expr &x)
Definition: expr.h:137
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
const VariableBase & var
Definition: cairoItems.h:36
double rotation() const
Definition: item.h:211
Here is the call graph for this function:
Here is the caller graph for this function:

◆ width()

float minsky::RenderVariable::width ( ) const
inline

half width of unrotated image

Definition at line 45 of file cairoItems.h.

References w.

Referenced by minsky::anonymous_namespace{godleyIcon.cc}::accumulateWidthHeight(), minsky::Canvas::copyVars(), minsky::IntOp::draw(), and minsky::VariableBase::onMouseMotion().

45 {return w;}
Here is the caller graph for this function:

Member Data Documentation

◆ cairo

cairo_t* minsky::RenderVariable::cairo
private

Definition at line 37 of file cairoItems.h.

Referenced by draw().

◆ h

float minsky::RenderVariable::h
private

Definition at line 38 of file cairoItems.h.

Referenced by height(), inImage(), and RenderVariable().

◆ hoffs

float minsky::RenderVariable::hoffs
private

Definition at line 38 of file cairoItems.h.

Referenced by RenderVariable().

◆ var

const VariableBase& minsky::RenderVariable::var
private

Definition at line 36 of file cairoItems.h.

Referenced by draw(), handlePos(), inImage(), and RenderVariable().

◆ w

float minsky::RenderVariable::w
private

Definition at line 38 of file cairoItems.h.

Referenced by handlePos(), inImage(), RenderVariable(), and width().


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