Minsky: 3.17.0
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 51 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.

51  :
52  Pango(cairo? cairo: dummySurf.cairo()), var(var), cairo(cairo)
53 {
54  setFontSize(12);
56  {
57  try
58  {
59  auto val=var.engExp();
60  if (val.engExp==-3) val.engExp=0; //0.001-1.0
61  setMarkup(var.mantissa(val)+expMultiplier(val.engExp));
62  }
63  catch (const std::exception& ex)
64  {
65  setMarkup("0");
66  }
67  w=0.5*Pango::width();
68  h=0.5*Pango::height();
69  }
70  else
71  {
72  setMarkup(latexToPango(var.name()));
73  w=0.5*Pango::width();
74  h=0.5*Pango::height();
75  if (!var.ioVar())
76  { // add additional space for numerical display
77  w+=12;
78  h+=4;
79  }
80  }
81  hoffs=Pango::top();
82 }
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:243
EngNotation engExp() const
return formatted mantissa and exponent in engineering format
Definition: variable.h:214
virtual std::string name() const
variable displayed name
Definition: variable.cc:186
std::string mantissa(const EngNotation &e, int digits=3) const
Definition: variable.h:216
Here is the call graph for this function:

Member Function Documentation

◆ draw()

void RenderVariable::draw ( )

render the cairo image

Definition at line 84 of file cairoItems.cc.

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

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

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

◆ handlePos()

double RenderVariable::handlePos ( ) const

Definition at line 98 of file cairoItems.cc.

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

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

99 {
100  if (auto vv=var.vValue())
101  {
102  vv->adjustSliderBounds();
103  assert(vv->sliderMin<vv->sliderMax);
104  return (w<0.5*var.iWidth()? 0.5*var.iWidth() : w)*(vv->value()-0.5*(vv->sliderMin+vv->sliderMax))/(vv->sliderMax-vv->sliderMin);
105  }
106  return 0;
107 }
const VariableBase & var
Definition: cairoItems.h:36
float iWidth() const
Definition: item.h:214
std::shared_ptr< VariableValue > vValue() const
variableValue associated with this. nullptr if not associated with a variableValue ...
Definition: variable.cc:146
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 90 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().

91 {
92  const float dx=x-var.x(), dy=y-var.y();
93  const float rx=dx*cos(var.rotation()*M_PI/180)-dy*sin(var.rotation()*M_PI/180);
94  const float ry=dy*cos(var.rotation()*M_PI/180)+dx*sin(var.rotation()*M_PI/180);
95  return rx>=-w && rx<=w && ry>=-h && ry <= h;
96 }
#define M_PI
some useful geometry types, defined from boost::geometry
Definition: geometry.h:29
Expr sin(const Expr &x)
Definition: expr.h:130
Expr cos(const Expr &x)
Definition: expr.h:136
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:208
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: