本文整理汇总了C++中cairo::RefPtr::curve_to方法的典型用法代码示例。如果您正苦于以下问题:C++ RefPtr::curve_to方法的具体用法?C++ RefPtr::curve_to怎么用?C++ RefPtr::curve_to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo::RefPtr
的用法示例。
在下文中一共展示了RefPtr::curve_to方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
static void
skillgui_cairo_render_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start,
int arrow_at_end, int filled)
{
#ifdef USE_GVPLUGIN_TIMETRACKER
__tt.ping_start(__ttc_bezier);
++__num_bezier;
#endif
//printf("Bezier\n");
SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context;
Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo();
obj_state_t *obj = job->obj;
skillgui_cairo_set_penstyle(cairo, job);
cairo->move_to(A[0].x, -A[0].y);
for (int i = 1; i < n; i += 3)
cairo->curve_to(A[i].x, -A[i].y, A[i + 1].x, -A[i + 1].y,
A[i + 2].x, -A[i + 2].y);
if (filled) {
skillgui_cairo_set_color(cairo, &(obj->fillcolor));
cairo->fill_preserve();
}
skillgui_cairo_set_color(cairo, &(obj->pencolor));
cairo->stroke();
#ifdef USE_GVPLUGIN_TIMETRACKER
__tt.ping_end(__ttc_bezier);
#endif
}
示例2: draw
void DependencyArrow::draw(const Cairo::RefPtr<Cairo::Context>& context) const
{
// the way to compute the (tcx, tcy) single control point of the
// quadratic
double dX = mControlPoint.getX() - mOrigin->getX();
double dY = mControlPoint.getY() - mOrigin->getY();
double d1 = std::sqrt(dX * dX + dY * dY);
double d = d1;
dX = mDestination->getX() - mControlPoint.getX();
dY = mDestination->getY() - mControlPoint.getY();
d += std::sqrt(dX * dX + dY * dY);
double t = d1/d;
double t1 = 1.0 - t;
double tSq = t * t;
double denom = 2.0 * t * t1;
double tcx = (mControlPoint.getX() - t1 * t1 * mOrigin->getX() -
tSq * mDestination->getX()) / denom;
double tcy = (mControlPoint.getY() - t1 * t1 * mOrigin->getY() -
tSq * mDestination->getY()) / denom;
// from the single point of the quadratic to the both of the cubic
double tcxq1 = mOrigin->getX() + 2. * (tcx - mOrigin->getX()) / 3.;
double tcyq1 = mOrigin->getY() + 2. * (tcy - mOrigin->getY()) / 3.;
double tcxq2 = mDestination->getX() +
2. * (tcx - mDestination->getX()) / 3.;
double tcyq2 = mDestination->getY() +
2. * (tcy - mDestination->getY()) / 3.;
// and now to draw,
std::valarray< double > dashes(2);
double angle = atan2 (mDestination->getY() - tcyq2,
mDestination->getX() - tcxq2) + M_PI;
double x1 = mDestination->getX() + 9 * std::cos(angle - 0.35);
double y1 = mDestination->getY() + 9 * std::sin(angle - 0.35);
double x2 = mDestination->getX() + 9 * std::cos(angle + 0.35);
double y2 = mDestination->getY() + 9 * std::sin(angle + 0.35);
dashes[0] = 8.0;
dashes[1] = 3.0;
context->save();
context->set_line_width(1);
context->move_to(mDestination->getX(), mDestination->getY());
context->line_to(x1,y1);
context->line_to(x2,y2);
context->line_to(mDestination->getX(), mDestination->getY());
context->fill();
context->set_dash(dashes,0.);
context->move_to(mOrigin->getX(), mOrigin->getY());
context->curve_to(tcxq1, tcyq1, tcxq2, tcyq2, mDestination->getX(),
mDestination->getY());
context->stroke();
context->restore();
}
示例3: draw
/**
* Draws a curve for the speed graph.
*/
void GtkGraph::draw(std::queue<double> q, double height, double increment, double maxValue, const Cairo::RefPtr<Cairo::Context>& cr)
{
// wizards use computers
// computers use numbers
// no magic
double offset = increment * (m_displaySize - q.size());
cr->move_to(0, height);
for(unsigned i = 0; i< (m_displaySize - q.size());++i)
cr->line_to(i*increment, height);
double oldy;
if(q.empty()) return;
oldy = height - (q.front() * height / maxValue);
cr->line_to(offset, oldy);
q.pop();
double x = increment + offset;
while(!q.empty())
{
double y = height - (q.front() * height / maxValue);
cr->curve_to(x - increment/2, oldy, x - increment/2, y, x, y);
q.pop();
oldy = y;
x += increment;
}
if(gt::Settings::settings["GraphStyle"] == "Fill")
{
cr->stroke_preserve();
Gdk::Cairo::set_source_rgba(cr, Gdk::RGBA(gt::Settings::settings[(upl) ? "GraphUploadFillColor" : "GraphDownloadFillColor"]));
cr->line_to(x - increment, height);
cr->line_to(0,height);
auto k = Gdk::RGBA(gt::Settings::settings[(upl) ? "GraphUploadFillColor" : "GraphDownloadFillColor"]);
cr->set_source_rgba(k.get_red(), k.get_green(), k.get_blue(), k.get_alpha() * 0.5);
cr->fill();
}
else cr->stroke();
}
示例4: FrequencyGraph
void FrequencyGraph( Cairo::RefPtr<Cairo::Context> cr, bool active, float x, float y, float xS, float yS, EqualizerState state)
{
cr->set_line_cap( Cairo::LINE_CAP_ROUND );
cr->set_line_join( Cairo::LINE_JOIN_ROUND);
int xSize = xS;
int ySize = yS;
// works but a bit simple
cr -> move_to( x , y );
cr -> line_to( x + xSize, y );
cr -> line_to( x + xSize, y + ySize );
cr -> line_to( x , y + ySize );
cr -> close_path();
// Draw outline shape
cr -> set_source_rgb (0.1,0.1,0.1);
cr -> fill();
// draw "frequency guides"
std::valarray< double > dashes(2);
dashes[0] = 2.0;
dashes[1] = 2.0;
cr->set_dash (dashes, 0.0);
cr->set_line_width(1.0);
cr->set_source_rgb (0.4,0.4,0.4);
for ( int i = 0; i < 4; i++ )
{
cr->move_to( x + ((xSize / 4.f)*i), y );
cr->line_to( x + ((xSize / 4.f)*i), y + ySize );
}
for ( int i = 0; i < 4; i++ )
{
cr->move_to( x , y + ((ySize / 4.f)*i) );
cr->line_to( x +xSize, y + ((ySize / 4.f)*i) );
}
cr->stroke();
cr->unset_dash();
// set colour based on active or not
if ( active )
setColour(cr, COLOUR_BLUE_1, 0.2 );
else
setColour(cr, COLOUR_GREY_1, 0.2 );
int tmpX = x;
int tmpY = y;
// precalculate some variables
float oldGainPix = (ySize / 60.f) * (state.gain[0] - 0.5 ) * 40;
float oldXLoc = 0;
float qPix = ((xSize * 0.2) / 3.f );
//float oldCutoff = 0;
// move to bottom left, draw line to middle left
cr->move_to( tmpX, tmpY + ySize );
cr->line_to( tmpX, tmpY + (ySize * 0.5) - oldGainPix );
for ( int i = 0; i < 4; i++ )
{
//float cutoff = state.cutoffFreq[i] / 20000;
float gainPix = (ySize / 60.f) * (state.gain[i] - 0.5 ) * 40;
float xLoc = xSize * 0.2 * (i+1);
//std::cout << "I: " << i << " GainPix: " << gainPix << " tmpY - gainPix" << tmpY - gainPix << std::endl;
cr->curve_to( tmpX + oldXLoc + qPix, tmpY + (ySize * 0.5) - oldGainPix ,// control point 1
tmpX + xLoc - qPix , tmpY + (ySize * 0.5) - gainPix , // control point 2
tmpX + xLoc , tmpY + (ySize * 0.5) - gainPix ); // end of curve
// update variables for next iter
oldGainPix = gainPix;
oldXLoc = xLoc;
//oldCutoff = cutoff;
}
// last bit of curve to the right edge
cr->curve_to( tmpX + oldXLoc + qPix, tmpY + (ySize * 0.5) - oldGainPix, // control point 1
tmpX + xSize - qPix, tmpY + (ySize * 0.5) - oldGainPix, // control point 2
tmpX + xSize , tmpY + (ySize * 0.5) - oldGainPix); // end of curve
cr->line_to( tmpX + xSize , tmpY + ySize );
cr->close_path();
cr->fill_preserve();
cr->set_line_width(2.5);
if ( active )
setColour(cr, COLOUR_BLUE_1 );
else
setColour(cr, COLOUR_GREY_1 );
cr->stroke();
// outline
cr->rectangle( x, y , xS, yS );
//.........这里部分代码省略.........
示例5: draw_curved_edges
//.........这里部分代码省略.........
for (unsigned i=0;i<es.size();i++) {
CEdge *e=&edges[i];
unsigned start=es[i].first;
unsigned end=es[i].second;
e->startID=start;
e->endID=end;
nodes[start].x=rs[start]->getCentreX()-xmin;
nodes[start].y=rs[start]->getCentreY()-ymin;
nodes[end].x=rs[end]->getCentreX()-xmin;
nodes[end].y=rs[end]->getCentreY()-ymin;
e->x0=nodes[start].x;
e->x1=nodes[start].x;
e->x2=nodes[end].x;
e->x3=nodes[end].x;
e->y0=nodes[start].y;
e->y1=nodes[start].y;
e->y2=nodes[end].y;
e->y3=nodes[end].y;
nodes[end].edges.push_back(e);
nodes[start].edges.push_back(e);
}
for (unsigned i=0;i<nodes.size();i++) {
CNode u=nodes[i];
if(u.edges.size()<2) continue;
for (unsigned j=0;j<u.edges.size();j++) {
CBundle* b=new CBundle(u);
b->addEdge(u.edges[j]);
u.bundles.push_back(b);
}
u.bundles.sort(clockwise());
/*
printf("Sorted: \n");
list<CBundle*>::iterator i,j;
for(list<CBundle*>::iterator i=u.bundles.begin();i!=u.bundles.end();i++) {
CBundle* a=*i;
a->dump();
printf(" angle=%f\n",a->yangle());
}
printf("---------\n");
*/
while(true) {
double minAngle=DBL_MAX;
list<CBundle*>::iterator mini,minj,i,j;
for(i=u.bundles.begin();i!=u.bundles.end();i++) {
j=i;
if(++j==u.bundles.end()) {
j=u.bundles.begin();
}
CBundle* a=*i;
CBundle* b=*j;
double angle=b->yangle()-a->yangle();
if(angle<0) angle+=2*M_PI;
//printf("between ");
//a->dump(); b->dump();
//printf(" angle=%f\n",angle);
if(angle<minAngle) {
minAngle=angle;
mini=i;
minj=j;
}
}
if(minAngle>cos(M_PI/8.)) break;
CBundle* a=*mini;
CBundle* b=*minj;
//a->dump();
//b->dump();
b->merge(a);
//printf("***Merged on %f***: ",minAngle);
//b->dump();
//printf("\n");
u.bundles.erase(mini);
if(u.bundles.size() < 2) break;
}
for(list<CBundle*>::iterator i=u.bundles.begin();i!=u.bundles.end();i++) {
CBundle* b=*i;
for(unsigned i=0;i<b->edges.size();i++) {
CEdge* e=b->edges[i];
if(e->x0==u.x&&e->y0==u.y) {
e->x1=b->x1();
e->y1=b->y1();
} else {
e->x2=b->x1();
e->y2=b->y1();
}
}
}
}
cr->save();
// background
cr->set_source_rgba(0,0,1,0.2);
for (unsigned i=0;i<edges.size();i++) {
CEdge &e=edges[i];
cr->move_to(e.x0,e.y0);
cr->curve_to(e.x1,e.y1,e.x2,e.y2,e.x3,e.y3);
cr->stroke();
}
cr->restore();
}
示例6: pw
void
Renderer_Ducks::render_vfunc(
const Glib::RefPtr<Gdk::Drawable>& drawable,
const Gdk::Rectangle& /*expose_area*/
)
{
assert(get_work_area());
if(!get_work_area())
return;
const synfig::Point window_start(get_work_area()->get_window_tl());
const float pw(get_pw()),ph(get_ph());
const bool solid_lines(get_work_area()->solid_lines);
bool alternative = get_work_area()->get_alternative_mode();
const std::list<etl::handle<Duckmatic::Bezier> >& bezier_list(get_work_area()->bezier_list());
const std::list<handle<Duckmatic::Stroke> >& stroke_list(get_work_area()->stroke_list());
Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_work_area()->get_pango_context()));
Cairo::RefPtr<Cairo::Context> cr = drawable->create_cairo_context();
cr->save();
cr->set_line_cap(Cairo::LINE_CAP_BUTT);
cr->set_line_join(Cairo::LINE_JOIN_MITER);
// Render the strokes
for(std::list<handle<Duckmatic::Stroke> >::const_iterator iter=stroke_list.begin();iter!=stroke_list.end();++iter)
{
cr->save();
std::list<synfig::Point>::iterator iter2;
for(iter2=(*iter)->stroke_data->begin();iter2!=(*iter)->stroke_data->end();++iter2)
{
cr->line_to(
((*iter2)[0]-window_start[0])/pw,
((*iter2)[1]-window_start[1])/ph
);
}
cr->set_line_width(1.0);
cr->set_source_rgb(
colorconv_synfig2gdk((*iter)->color).get_red_p(),
colorconv_synfig2gdk((*iter)->color).get_green_p(),
colorconv_synfig2gdk((*iter)->color).get_blue_p()
);
cr->stroke();
cr->restore();
}
// Render the beziers
for(std::list<handle<Duckmatic::Bezier> >::const_iterator iter=bezier_list.begin();iter!=bezier_list.end();++iter)
{
Point p1((*iter)->p1->get_trans_point()-window_start);
Point p2((*iter)->p2->get_trans_point()-window_start);
Point c1((*iter)->c1->get_trans_point()-window_start);
Point c2((*iter)->c2->get_trans_point()-window_start);
p1[0]/=pw;p1[1]/=ph;
p2[0]/=pw;p2[1]/=ph;
c1[0]/=pw;c1[1]/=ph;
c2[0]/=pw;c2[1]/=ph;
cr->save();
cr->move_to(p1[0], p1[1]);
cr->curve_to(c1[0], c1[1], c2[0], c2[1], p2[0], p2[1]);
/*
if (solid_lines)
{
cr->set_source_rgb(0,0,0); // DUCK_COLOR_BEZIER_1
cr->set_line_width(3.0);
cr->stroke_preserve();
cr->set_source_rgb(175.0/255.0,175.0/255.0,175.0/255.0); //DUCK_COLOR_BEZIER_2
cr->set_line_width(1.0);
cr->stroke();
}
else
*/
{
//Solid line background
cr->set_line_width(1.0);
cr->set_source_rgb(0,0,0); // DUCK_COLOR_BEZIER_1
cr->stroke_preserve();
//Dashes
cr->set_source_rgb(175.0/255.0,175.0/255.0,175.0/255.0); //DUCK_COLOR_BEZIER_2
std::valarray<double> dashes(2);
dashes[0]=5.0;
dashes[1]=5.0;
cr->set_dash(dashes, 0);
cr->stroke();
}
cr->restore();
}
//.........这里部分代码省略.........
示例7: on_expose_event
bool GHighPass::on_expose_event(GdkEventExpose* event)
{
// This is where we draw on the window
Glib::RefPtr<Gdk::Window> window = get_window();
if(window) // Only run if Window does exist
{
Gtk::Allocation allocation = get_allocation();
int width = allocation.get_width();
int height = allocation.get_height();
// clip to the area indicated by the expose event so that we only redraw
// the portion of the window that needs to be redrawn
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
cr->rectangle(event->area.x, event->area.y,
event->area.width, event->area.height);
cr->clip();
cr->rectangle(event->area.x, event->area.y,
event->area.width, event->area.height);
setColour(cr, COLOUR_GREY_3 );
cr->fill();
//cout << "HighPass getting state ID " << ID << endl;
float cutoffRangeZeroOne = stateStore->effectState.at(ID).values[0];
cutoff = cutoffRangeZeroOne;
bool active = stateStore->effectState.at(ID).active;
bool globalUnit = stateStore->effectState.at(ID).globalUnit;
int x = 0;
int y = 0;
xSize = 73;
ySize = 37;
// works but a bit simple
cr -> move_to( x , y );
cr -> line_to( x + xSize, y );
cr -> line_to( x + xSize, y + ySize );
cr -> line_to( x , y + ySize );
cr -> close_path();
// Draw outline shape
cr -> set_source_rgb (0.1,0.1,0.1);
cr -> fill();
// draw "frequency guides"
std::valarray< double > dashes(2);
dashes[0] = 2.0;
dashes[1] = 2.0;
cr->set_dash (dashes, 0.0);
cr->set_line_width(1.0);
cr->set_source_rgb (0.4,0.4,0.4);
for ( int i = 0; i < 3; i++ )
{
cr->move_to( x + ((xSize / 3.f)*i), y );
cr->line_to( x + ((xSize / 3.f)*i), y + ySize );
}
for ( int i = 0; i < 3; i++ )
{
cr->move_to( x , y + ((ySize / 3.f)*i) );
cr->line_to( x +xSize, y + ((ySize / 3.f)*i) );
}
cr->stroke();
cr->unset_dash();
// move to bottom left, draw line to middle left
cr->move_to( x + xSize-2 , y + ySize );
cr->line_to( x + xSize-2 , y + (ySize/2));
int startHorizontalLine = xSize* (cutoff + 0.4);
if ( startHorizontalLine > 75 )
startHorizontalLine = 75;
cr->line_to( startHorizontalLine, y + (ySize/2) ); // horizontal line to start of curve
int xSize1CP1 = xSize* (cutoff +0.1);
int xSize1CP2 = xSize* (cutoff +0.08);
int xSize1End = xSize* cutoff;
if ( xSize1CP1 > 75 )
xSize1CP1 = 75;
if ( xSize1CP2 > 75 )
xSize1CP2 = 75;
if ( xSize1End > 75 )
xSize1End = 75;
cr->curve_to( xSize1CP1, y+(ySize*0.5), // control point 1
xSize1CP2, y+(ySize*0.3), // control point 2
xSize1End, y+(ySize*0.3)); // end of curve 1, start curve 2
int xSize2CP1 = xSize* (cutoff - 0.03);
int xSize2CP2 = xSize* (cutoff - 0.08);
int xSize2End = xSize* (cutoff - 0.15);
if ( xSize2CP1 > 75 )
xSize2CP1 = 75;
if ( xSize2CP2 > 75 )
//.........这里部分代码省略.........