void Terminal::drawSurroundingShape( Cairo::RefPtr< Cairo::Context > ctx, double width, double height ) const { ctx->move_to( height / 2, 0 ); ctx->line_to( width - height / 2, 0 ); ctx->arc( width - height / 2, height / 2, height / 2, -M_PI / 2, M_PI / 2 ); ctx->line_to( height / 2, height ); ctx->arc( height / 2, height / 2, height / 2, M_PI / 2, -M_PI / 2 ); }
void GraphicalItem::drawRoundedRectangle( const Cairo::RefPtr<Cairo::Context>& context, int x, int y, int width, int height, double aspect, double corner_radius, double red, double green, double blue) { double radius = corner_radius / aspect; double degrees = M_PI / 180.0; context->begin_new_sub_path(); context->arc(x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees); context->arc(x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees); context->arc(x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees); context->arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees); context->close_path(); context->set_source_rgb(red, green, blue); context->fill_preserve(); setColor(Settings::settings().getForegroundColor(), context); context->stroke(); }
//! Only renders the shield background, the text is rendered in renderLabels void Renderer::renderShields(const Cairo::RefPtr<Cairo::Context>& cr, std::vector<shared_ptr<Shield> >& shields) const { cr->save(); cr->set_line_join(Cairo::LINE_JOIN_ROUND); for (auto& shield : shields) { const Style* s = shield->style; double x0, y0, height, width; double border = ceil(s->shield_frame_width/2.0 + s->shield_casing_width); x0 = shield->shield.minX + border; y0 = shield->shield.minY + border; width = shield->shield.getWidth() - 2*border; height = shield->shield.getHeight() - 2*border; if ((int) s->shield_frame_width % 2 == 1) { x0 -= 0.5; y0 -= 0.5; } if (s->shield_shape == Style::ShieldShape::ROUNDED) { cr->arc(x0 + height/2.0, y0 + height/2.0, height/2.0, boost::math::constants::pi<double>()/2.0, 3.0*boost::math::constants::pi<double>()/2.0); cr->arc(x0 + width - height/2.0, y0 + height/2.0, height/2.0, 3.0*boost::math::constants::pi<double>()/2.0, boost::math::constants::pi<double>()/2.0); cr->close_path(); } else cr->rectangle(x0, y0, width, height); // shield casing if (s->shield_casing_width > 0) { cr->set_source_color(s->shield_casing_color), cr->set_line_width(s->shield_frame_width + s->shield_casing_width * 2.0); cr->stroke_preserve(); } // shield background cr->set_source_color(s->shield_color), cr->fill_preserve(); // shield frame cr->set_source_color(s->shield_frame_color), cr->set_line_width(s->shield_frame_width); cr->stroke(); } cr->restore(); }
/** Drawing event handler. */ virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) { switch (_curShape) { case SHAPE_RECTANGLE: cr->rectangle(20, 20, 200, 100); cr->set_source_rgb(0, 0.8, 0); cr->fill_preserve(); break; case SHAPE_ELLIPSE: cr->arc(150, 100, 90, 0, 2 * 3.14); cr->set_source_rgb(0.8, 0, 0); cr->fill_preserve(); break; case SHAPE_TRIANGLE: cr->move_to(40, 40); cr->line_to(200, 40); cr->line_to(120, 160); cr->line_to(40, 40); cr->set_source_rgb(0.8, 0, 0.8); cr->fill_preserve(); cr->set_line_cap(Cairo::LINE_CAP_ROUND); cr->set_line_join(Cairo::LINE_JOIN_ROUND); break; } cr->set_line_width(3); cr->set_source_rgb(0, 0, 0); cr->stroke(); return true; }
int main(int, char**) { Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create( Cairo::FORMAT_ARGB32, WIDTH, HEIGHT); Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface); // fill background in white cr->set_source_rgb(1.0, 1.0, 1.0); cr->paint(); // draw a little dot at the point where text will be drawn cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2 * M_PI); cr->set_source_rgba(0.0, 1.0, 0.0, 0.5); cr->fill(); // draw the text cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y); cr->set_source_rgb(0.8, 0.2, 0.2); Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create( "Bitstream Charter", Cairo::FONT_SLANT_ITALIC, Cairo::FONT_WEIGHT_BOLD); cr->set_font_face(font); cr->set_font_size(FONT_SIZE); cr->show_text("cairomm!"); surface->write_to_png("toy-text.png"); return 0; }
bool Balls::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) { Gtk::Allocation allocation = get_allocation(); const int width = allocation.get_width(); const int height = allocation.get_height(); cr->save(); cr->scale(width, height); cr->set_line_width(0.001); for (auto ball : balls_) { cr->set_source_rgb(ball.color_r,ball.color_g,ball.color_b); cr->arc(ball.p.x,ball.p.y, ball.rad, 0,2*M_PI); cr->fill(); cr->stroke(); } cr->restore(); const Ball &ball1 = balls_[balls_.size()-1]; std::ostringstream info; info << "x = " << ball1.p.x << "\ny = " << ball1.p.y; infobox_.show(cr,width,height,info.str()); return true; }
void HomVectorDrawer::draw(Cairo::RefPtr<Cairo::Context>& context) { context->save(); HomPoint start, end; if (m_offset) { start = HomPoint( m_offset->x(), m_offset->y() ); end = HomPoint( m_offset->x() + m_vector->x(), m_offset->y() + m_vector->y() ); } else { start = HomPoint( 0.0, 0.0 ); end = HomPoint( m_vector->x(), m_vector->y() ); } context->move_to( start.x(), start.y() ); context->line_to( end.x() , end.y() ); context->arc( end.x(), end.y(), 0.06, 0.0, 2.0 * M_PI); context->fill(); context->stroke(); context->restore(); }
void NodeSurface::DrawRoundedRectangle( Cairo::RefPtr<Cairo::Context> refCairo, double x, double y, double width, double height, double radius, double red, double green, double blue, bool selected ) { refCairo->save(); if ( (radius > height/2.0) || (radius > width/2.0) ) { radius = std::min<double>(height / 2, width / 2); } refCairo->move_to( x, y + radius ); refCairo->arc( x + radius, y + radius, radius, sk_pi, -sk_pi / 2.0 ); refCairo->line_to( x + width - radius, y ); refCairo->arc( x + width - radius, y + radius, radius, -sk_pi / 2.0, 0 ); refCairo->line_to( x + width, y + height - radius ); refCairo->arc( x + width - radius, y + height - radius, radius, 0, sk_pi / 2.0 ); refCairo->line_to( x + radius, y + height ); refCairo->arc( x + radius, y + height - radius, radius, sk_pi / 2.0, sk_pi ); refCairo->close_path(); refCairo->set_source_rgb( red, green, blue ); refCairo->fill_preserve(); if ( selected == true ) { refCairo->set_source_rgb( 1.0, 0.0, 0.0 ); refCairo->set_line_width( 2 ); refCairo->stroke(); } else { refCairo->set_source_rgb( 0.0, 0.0, 0.0 ); refCairo->set_line_width( 1 ); refCairo->stroke(); } refCairo->restore(); }
/** Draw scale box. * Draws a circle with a radius of 1m around the robot. * @param window Gdk window * @param cr Cairo context to draw to. It is assumed that possible transformations * have been setup before. */ void LaserDrawingArea::draw_scalebox(Glib::RefPtr<Gdk::Window> &window, const Cairo::RefPtr<Cairo::Context> &cr) { cr->save(); cr->set_source_rgba(0, 0, 0.8, 0.2); cr->arc(0, 0, 1.0, 0, 2 * M_PI); cr->stroke(); cr->restore(); }
void GraficoDeTorta::dibujarArco(const Cairo::RefPtr<Cairo::Context>& c,int x, int y, int radio, float angulo0, float angulo1,float r, float g, float b){ c->set_source_rgb(1,1,1); c->set_line_width(2); c->arc(x,y,radio, angulo0, angulo1); c->line_to(x,y); c->close_path(); c->stroke_preserve(); c->set_source_rgb(r,g,b); c->fill(); }
void NodeRenderer::stroke(const Cairo::RefPtr<Cairo::Context>& cr) { // nothing to stroke if (s->width <= 0.0) return; cr->save(); cr->arc(location.x, location.y, s->width/2.0, 0, 2*M_PI); cr->set_source_color(s->color); cr->fill(); cr->restore(); }
void NodeRenderer::casing(const Cairo::RefPtr<Cairo::Context>& cr) { // nothing to render if (s->casing_width <= 0.0) return; cr->save(); cr->arc(location.x, location.y, s->width/2.0 + s->casing_width, 0, 2*boost::math::constants::pi<double>()); cr->set_source_color(s->casing_color); cr->fill(); cr->restore(); }
int main() { #ifdef CAIRO_HAS_PDF_SURFACE std::string filename = "image.pdf"; int width = 600; int height = 400; Cairo::RefPtr<Cairo::PdfSurface> surface = Cairo::PdfSurface::create( filename, width, height); Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface); cr->save(); // save the state of the context cr->set_source_rgb(0.86, 0.85, 0.47); cr->paint(); // fill image with the color cr->restore(); // color is back to black now cr->save(); // draw a border around the image cr->set_line_width(20.0); // make the line wider cr->rectangle(0.0, 0.0, cairo_image_surface_get_width(surface->cobj()), height); cr->stroke(); cr->set_source_rgba(0.0, 0.0, 0.0, 0.7); // draw a circle in the center of the image cr->arc(width / 2.0, height / 2.0, height / 4.0, 0.0, 2.0 * M_PI); cr->stroke(); // draw a diagonal line cr->move_to(width / 4.0, height / 4.0); cr->line_to(width * 3.0 / 4.0, height * 3.0 / 4.0); cr->stroke(); cr->restore(); cr->show_page(); std::cout << "Wrote PDF file \"" << filename << "\"" << std::endl; return 0; #else std::cout << "You must compile cairo with PDF support for this example to work." << std::endl; return 1; #endif }
int main() { Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 600, 400); Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface); cr->save(); // save the state of the context cr->set_source_rgb(0.86, 0.85, 0.47); cr->paint(); // fill image with the color cr->restore(); // color is back to black now cr->save(); // draw a border around the image cr->set_line_width(20.0); // make the line wider cr->rectangle(0.0, 0.0, surface->get_width(), surface->get_height()); cr->stroke(); cr->set_source_rgba(0.0, 0.0, 0.0, 0.7); // draw a circle in the center of the image cr->arc(surface->get_width() / 2.0, surface->get_height() / 2.0, surface->get_height() / 4.0, 0.0, 2.0 * M_PI); cr->stroke(); // draw a diagonal line cr->move_to(surface->get_width() / 4.0, surface->get_height() / 4.0); cr->line_to(surface->get_width() * 3.0 / 4.0, surface->get_height() * 3.0 / 4.0); cr->stroke(); cr->restore(); #ifdef CAIRO_HAS_PNG_FUNCTIONS std::string filename = "image.png"; surface->write_to_png(filename); std::cout << "Wrote png file \"" << filename << "\"" << std::endl; #else std::cout << "You must compile cairo with PNG support for this example to work." << std::endl; #endif }
int main(int, char**) { Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create( Cairo::FORMAT_ARGB32, WIDTH, HEIGHT); Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface); // fill background in white cr->set_source_rgb(1.0, 1.0, 1.0); cr->paint(); // draw a little dot at the point where text will be drawn cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2 * M_PI); cr->set_source_rgba(0.0, 1.0, 0.0, 0.5); cr->fill(); // draw the text cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y); cr->set_source_rgb(0.8, 0.2, 0.2); Cairo::RefPtr<BoxFontFace> font = BoxFontFace::create(); cr->set_font_face(font); cr->set_font_size(FONT_SIZE); cr->show_text("cairomm!"); // Now show it with the toy text API to // demonstrate how the glyphs match up cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y); cr->set_source_rgba(0.2, 0.2, 0.2, 0.3); Cairo::RefPtr<Cairo::ToyFontFace> toy_font = Cairo::ToyFontFace::create( "Bitstream Charter", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD); cr->set_font_face(toy_font); cr->set_font_size(FONT_SIZE); cr->show_text("cairomm!"); const char* filename = "user-font.png"; try { surface->write_to_png(filename); std::cout << "Wrote Image " << filename << std::endl; return 0; } catch (const std::exception& e) { std::cout << "** Unable to write Image " << filename << std::endl; return 1; } }
//const Cairo::RefPtr<Cairo::Context>& cr virtual bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) { Gtk::Allocation alloc = get_allocation(); int ancho = alloc.get_width(); int alto = alloc.get_height(); int x = ancho / 2; int y = alto / 2; int w = 3 * ancho / 4.0; int h = alto / 2.0; cr->save(); cr->translate(x, y); cr->scale(w, h); cr->arc(0, 0, 1.0, 0, 2 * M_PI); cr->set_source_rgba(0, 0, 1.0, 0); // cr->fill_preserve(); cr->restore(); // back to opaque black cr->stroke(); return true; }
static void skillgui_cairo_render_ellipse(GVJ_t *job, pointf *A, int filled) { #ifdef USE_GVPLUGIN_TIMETRACKER __tt.ping_start(__ttc_ellipse); ++__num_ellipse; #endif //printf("Render ellipse\n"); SkillGuiCairoRenderInstructor *cri = (SkillGuiCairoRenderInstructor *)job->context; Cairo::RefPtr<Cairo::Context> cairo = cri->get_cairo(); obj_state_t *obj = job->obj; Cairo::Matrix old_matrix; cairo->get_matrix(old_matrix); skillgui_cairo_set_penstyle(cairo, job); cairo->translate(A[0].x, -A[0].y); double rx = A[1].x - A[0].x; double ry = A[1].y - A[0].y; cairo->scale(1, ry / rx); cairo->move_to(rx, 0); cairo->arc(0, 0, rx, 0, 2 * M_PI); cairo->close_path(); cairo->set_matrix(old_matrix); 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_ellipse); #endif }
void OutputFile::generate() { unsigned E=es.size(); bool cleanupRoutes=false; if(routes==NULL) { cleanupRoutes=true; routes = new vector<straightener::Route*>(E); for(unsigned i=0;i<E;i++) { straightener::Route* r=new straightener::Route(2); r->xs[0]=rs[es[i].first]->getCentreX(); r->ys[0]=rs[es[i].first]->getCentreY(); r->xs[1]=rs[es[i].second]->getCentreX(); r->ys[1]=rs[es[i].second]->getCentreY(); (*routes)[i]=r; } } #if defined (CAIRO_HAS_SVG_SURFACE) && defined (CAIRO_HAS_PDF_SURFACE) double width,height,r=2; if(rects) r=rs[0]->width()/2; double xmin=DBL_MAX, ymin=xmin; double xmax=-DBL_MAX, ymax=xmax; for (unsigned i=0;i<rs.size();i++) { double x=rs[i]->getCentreX(), y=rs[i]->getCentreY(); xmin=min(xmin,x); ymin=min(ymin,y); xmax=max(xmax,x); ymax=max(ymax,y); } xmax+=2*r; ymax+=2*r; xmin-=2*r; ymin-=2*r; width=xmax-xmin; height=ymax-ymin; Cairo::RefPtr<Cairo::Context> cr; openCairo(cr,width,height); /* set background colour cr->save(); // save the state of the context cr->set_source_rgb(0.86, 0.85, 0.47); cr->paint(); // fill image with the color cr->restore(); // color is back to black now */ cr->set_line_width(1.); cr->set_font_size(8); cr->save(); if(rc) for(Clusters::const_iterator c=rc->clusters.begin();c!=rc->clusters.end();c++) { draw_cluster_boundary(cr,**c,xmin,ymin); } if(curvedEdges) draw_curved_edges(cr,es,xmin,ymin); else draw_edges(cr,*routes,xmin,ymin); Cairo::TextExtents te; for (unsigned i=0;i<rs.size();i++) { if(!rects) { double x=rs[i]->getCentreX()-xmin, y=rs[i]->getCentreY()-ymin; cr->arc(x,y,r, 0.0, 2.0 * M_PI); cr->fill(); } else { double x=rs[i]->getMinX()-xmin+0.5, y=rs[i]->getMinY()-ymin+0.5; std::string str; if(labels.size()==rs.size()) { str=labels[i]; } else { std::stringstream s; s<<i; str=s.str(); } cr->get_text_extents(str,te); /* double llx = x-te.width/2.-1; double lly = y-te.height/2.-1; cr->rectangle(llx,lly,te.width+2,te.height+2); */ cr->rectangle(x,y, rs[i]->width()-1,rs[i]->height()-1); cr->stroke_preserve(); cr->save(); cr->set_source_rgba(245./255., 233./255., 177./255., 0.6); cr->fill(); cr->restore(); if(labels.size()==rs.size()) { cr->move_to(x-te.x_bearing+te.width/2.,y-te.y_bearing+te.height/2.); cr->show_text(str); } cr->stroke(); } } cr->show_page(); std::cout << "Wrote file \"" << fname << "\"" << std::endl; #else std::cout << "WARNING: cola::OutputFile::generate(): No SVG file produced." << std::endl << " You must have cairomm (and cairo with SVG support) " << "this to work." << std::endl; #endif if(cleanupRoutes) { for(unsigned i=0;i<E;i++) { delete (*routes)[i]; } delete routes; } }
void dot(Cairo::RefPtr<Cairo::Context> & cr, double x, double y) { cr->arc(x, y, 2., 0.0, 2.0 * M_PI); cr->stroke(); }
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(); } const DuckList duck_list(get_work_area()->get_duck_list()); std::list<ScreenDuck> screen_duck_list; const float radius((abs(pw)+abs(ph))*4); etl::handle<Duck> hover_duck(get_work_area()->find_duck(get_work_area()->get_cursor_pos(),radius, get_work_area()->get_type_mask())); // Render the ducks for(std::list<handle<Duck> >::const_iterator iter=duck_list.begin();iter!=duck_list.end();++iter) { // If this type of duck has been masked, then skip it if(!(*iter)->get_type() || (!(get_work_area()->get_type_mask() & (*iter)->get_type()))) continue; Point sub_trans_point((*iter)->get_sub_trans_point()); Point sub_trans_origin((*iter)->get_sub_trans_origin()); if (App::restrict_radius_ducks && (*iter)->is_radius()) { if (sub_trans_point[0] < sub_trans_origin[0]) sub_trans_point[0] = sub_trans_origin[0]; if (sub_trans_point[1] < sub_trans_origin[1]) sub_trans_point[1] = sub_trans_origin[1]; } Point point((*iter)->get_transform_stack().perform(sub_trans_point)); Point origin((*iter)->get_transform_stack().perform(sub_trans_origin)); point[0]=(point[0]-window_start[0])/pw; point[1]=(point[1]-window_start[1])/ph; bool has_connect = (*iter)->get_tangent() || ((*iter)->get_type()&( Duck::TYPE_ANGLE | Duck::TYPE_SKEW | Duck::TYPE_SCALE_X | Duck::TYPE_SCALE_Y )); if((*iter)->get_connect_duck()) { has_connect=true; origin=(*iter)->get_connect_duck()->get_trans_point(); } origin[0]=(origin[0]-window_start[0])/pw; origin[1]=(origin[1]-window_start[1])/ph; bool selected(get_work_area()->duck_is_selected(*iter)); bool hover(*iter==hover_duck || (*iter)->get_hover()); if(get_work_area()->get_selected_value_node()) { synfigapp::ValueDesc value_desc((*iter)->get_value_desc()); if (value_desc.is_valid() && ((value_desc.is_value_node() && get_work_area()->get_selected_value_node() == value_desc.get_value_node()) || (value_desc.parent_is_value_node() && get_work_area()->get_selected_value_node() == value_desc.get_parent_value_node()))) { cr->save(); cr->rectangle( round_to_int(point[0]-5), round_to_int(point[1]-5), 10, 10 ); cr->set_line_width(2.0); cr->set_source_rgb(1, 0, 0); //DUCK_COLOR_SELECTED cr->stroke(); cr->restore(); } } if((*iter)->get_box_duck()) { Point boxpoint((*iter)->get_box_duck()->get_trans_point()); boxpoint[0]=(boxpoint[0]-window_start[0])/pw; boxpoint[1]=(boxpoint[1]-window_start[1])/ph; Point tl(min(point[0],boxpoint[0]),min(point[1],boxpoint[1])); cr->save(); cr->rectangle( round_to_int(tl[0]), round_to_int(tl[1]), round_to_int(abs(boxpoint[0]-point[0])), round_to_int(abs(boxpoint[1]-point[1])) ); // Solid white box cr->set_line_width(1.0); cr->set_source_rgb(1,1,1); //DUCK_COLOR_BOX_1 cr->stroke_preserve(); // Dashes cr->set_source_rgb(0,0,0); //DUCK_COLOR_BOX_2 std::valarray<double> dashes(2); dashes[0]=5.0; dashes[1]=5.0; cr->set_dash(dashes, 0); cr->stroke(); cr->restore(); } if((*iter)->is_axes_tracks()) { Point pos((*iter)->get_point()); Point points[] = { (*iter)->get_sub_trans_origin(), (*iter)->get_sub_trans_point(Point(pos[0],0)), (*iter)->get_sub_trans_point(), (*iter)->get_sub_trans_point(Point(0,pos[1])), (*iter)->get_sub_trans_origin() }; cr->save(); for(int i = 0; i < 5; i++) { Point p((*iter)->get_transform_stack().perform(points[i])); Real x = (p[0]-window_start[0])/pw; Real y = (p[1]-window_start[1])/ph; if (i == 0) cr->move_to(x, y); else cr->line_to(x, y); } // Solid white box cr->set_line_width(1.0); cr->set_source_rgb(1,1,1); //DUCK_COLOR_BOX_1 cr->stroke_preserve(); // Dashes cr->set_source_rgb(0,0,0); //DUCK_COLOR_BOX_2 std::valarray<double> dashes(2); dashes[0]=5.0; dashes[1]=5.0; cr->set_dash(dashes, 0); cr->stroke(); cr->restore(); } ScreenDuck screen_duck; screen_duck.pos=point; screen_duck.selected=selected; screen_duck.hover=hover; screen_duck.has_alternative=(*iter)->get_alternative_value_desc().is_valid(); if(!(*iter)->get_editable(alternative)) screen_duck.color=(DUCK_COLOR_NOT_EDITABLE); else if((*iter)->get_tangent()) if(0){ // Tangents have different color depending on the split state (disabled for now) // // Check if we can reach the canvas and set the time to // evaluate the split value accordingly synfig::Canvas::Handle canvas_h(get_work_area()->get_canvas()); synfig::Time time(canvas_h?canvas_h->get_time():synfig::Time(0)); // Retrieve the split value of the bline point. const synfigapp::ValueDesc& v_d((*iter)->get_value_desc()); synfig::LinkableValueNode::Handle parent; if(v_d.parent_is_linkable_value_node()) { parent=v_d.get_parent_value_node(); bool split; synfig::ValueNode::Handle child(parent->get_link("split")); if(synfig::ValueNode_Animated::Handle::cast_dynamic(child)) { synfig::ValueNode_Animated::Handle animated_child(synfig::ValueNode_Animated::Handle::cast_dynamic(child)); split=animated_child->new_waypoint_at_time(time).get_value(time).get(split); } else if(synfig::ValueNode_Const::Handle::cast_dynamic(child)) { synfig::ValueNode_Const::Handle const_child(synfig::ValueNode_Const::Handle::cast_dynamic(child)); split=(const_child->get_value()).get(split); } screen_duck.color=(split? DUCK_COLOR_TANGENT_2 : DUCK_COLOR_TANGENT_1); } else screen_duck.color=DUCK_COLOR_TANGENT_1; } else { // All tangents are the same color screen_duck.color=((*iter)->get_scalar()<0 ? DUCK_COLOR_TANGENT_1 : DUCK_COLOR_TANGENT_1); } else if((*iter)->get_type()&Duck::TYPE_VERTEX) screen_duck.color=DUCK_COLOR_VERTEX; else if((*iter)->get_type()&Duck::TYPE_RADIUS) screen_duck.color=((*iter)->is_linear() ? DUCK_COLOR_LINEAR : DUCK_COLOR_RADIUS); else if((*iter)->get_type()&Duck::TYPE_WIDTH) screen_duck.color=DUCK_COLOR_WIDTH; else if((*iter)->get_type()&Duck::TYPE_ANGLE) screen_duck.color=(DUCK_COLOR_ANGLE); else if((*iter)->get_type()&Duck::TYPE_WIDTHPOINT_POSITION) screen_duck.color=(DUCK_COLOR_WIDTHPOINT_POSITION); else screen_duck.color=DUCK_COLOR_OTHER; screen_duck_list.push_front(screen_duck); if(has_connect) { cr->save(); cr->move_to(origin[0], origin[1]); cr->line_to(point[0], point[1]); if(solid_lines) { // Outside cr->set_line_width(3.0); cr->set_source_rgb(0,0,0); //DUCK_COLOR_CONNECT_OUTSIDE cr->stroke_preserve(); // Inside cr->set_line_width(1.0); cr->set_source_rgb(159.0/255,239.0/255,239.0/255); //DUCK_COLOR_CONNECT_INSIDE cr->stroke(); } else { // White background cr->set_line_width(1.0); cr->set_source_rgb(0,0,0); //DUCK_COLOR_CONNECT_OUTSIDE cr->stroke_preserve(); // Dashes on top of the background cr->set_source_rgb(159.0/255,239.0/255,239.0/255); //DUCK_COLOR_CONNECT_INSIDE std::valarray<double> dashes(2); dashes[0]=5.0; dashes[1]=5.0; cr->set_dash(dashes, 0); cr->stroke(); } cr->restore(); } if((*iter)->is_radius()) { if (!(*iter)->is_linear()) { const Real mag((point-origin).mag()); cr->save(); cr->arc( origin[0], origin[1], mag, 0, M_PI*2 ); if(solid_lines) { cr->set_line_width(3.0); cr->set_source_rgb(0,0,0); cr->stroke_preserve(); cr->set_source_rgb(175.0/255.0,175.0/255.0,175.0/255.0); } else { cr->set_source_rgb(1.0,1.0,1.0); // Operator difference was added in Cairo 1.9.4 // It currently isn't supported by Cairomm #if CAIRO_VERSION >= 10904 cairo_set_operator(cr->cobj(), CAIRO_OPERATOR_DIFFERENCE); #else // Fallback: set color to black cr->set_source_rgb(0,0,0); #endif } cr->set_line_width(1.0); cr->stroke(); cr->restore(); } if(hover) { Real mag; if ((*iter)->get_exponential()){ mag = log((*iter)->get_point().mag()); } else if (App::restrict_radius_ducks) { Point sub_trans_point((*iter)->get_sub_trans_point()); Point sub_trans_origin((*iter)->get_sub_trans_origin()); if (sub_trans_point[0] < sub_trans_origin[0]) sub_trans_point[0] = sub_trans_origin[0]; if (sub_trans_point[1] < sub_trans_origin[1]) sub_trans_point[1] = sub_trans_origin[1]; Point point((*iter)->get_transform_stack().perform(sub_trans_point)); Point origin((*iter)->get_transform_stack().perform(sub_trans_origin)); mag = (point-origin).mag(); } else mag = ((*iter)->get_trans_point()-(*iter)->get_trans_origin()).mag(); Distance real_mag(mag, Distance::SYSTEM_UNITS); if (!(*iter)->get_exponential()) real_mag.convert(App::distance_system,get_work_area()->get_rend_desc()); cr->save(); layout->set_text(real_mag.get_string()); cr->set_source_rgb(0,0,0); // DUCK_COLOR_WIDTH_TEXT_1 cr->move_to( point[0]+1+6, point[1]+1-8 ); layout->show_in_cairo_context(cr); cr->stroke(); cr->set_source_rgb(1,0,1); // DUCK_COLOR_WIDTH_TEXT_2 cr->move_to( point[0]+6, point[1]-8 ); layout->show_in_cairo_context(cr); cr->stroke(); cr->restore(); } } if((*iter)->get_type()&&Duck::TYPE_WIDTHPOINT_POSITION) { if(hover) { synfig::Canvas::Handle canvas_h(get_work_area()->get_canvas()); synfig::Time time(canvas_h?canvas_h->get_time():synfig::Time(0)); synfigapp::ValueDesc value_desc((*iter)->get_value_desc()); synfig::ValueNode_WPList::Handle wplist=NULL; ValueNode_Composite::Handle wpoint_composite=NULL; Real radius=0.0; Real new_value; Point p(sub_trans_point-sub_trans_origin); if(value_desc.parent_is_value_node()) wplist=synfig::ValueNode_WPList::Handle::cast_dynamic(value_desc.get_parent_value_node()); if(wplist) { bool wplistloop(wplist->get_loop()); synfig::ValueNode_BLine::Handle bline(synfig::ValueNode_BLine::Handle::cast_dynamic(wplist->get_bline())); wpoint_composite=ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()); if(bline && wpoint_composite) { bool blineloop(bline->get_loop()); bool homogeneous=false; // Retrieve the homogeneous layer parameter std::set<Node*>::iterator iter; for(iter=wplist->parent_set.begin();iter!=wplist->parent_set.end();++iter) { Layer::Handle layer; layer=Layer::Handle::cast_dynamic(*iter); if(layer && layer->get_name() == "advanced_outline") { homogeneous=layer->get_param("homogeneous").get(bool()); break; } } WidthPoint wp((*wpoint_composite)(time).get(WidthPoint())); if(wplistloop) { // The wplist is looped. This may require a position parameter // outside the range of 0-1, so make sure that the position doesn't // change drastically. // First normalise the current position Real value_old(wp.get_norm_position(wplistloop)); Real value_old_b(wp.get_bound_position(wplistloop)); // If it is homogeneous then convert it to standard value_old=homogeneous?hom_to_std((*bline)(time), value_old, wplistloop, blineloop):value_old; // grab a new position given by duck's position on the bline Real value_new = synfig::find_closest_point((*bline)(time), p , radius, blineloop); // calculate the difference between old and new positions Real difference = fmod( fmod(value_new - value_old, 1.0) + 1.0 , 1.0); //fmod is called twice to avoid negative values if (difference > 0.5) difference=difference-1.0; // calculate a new value for the position new_value=value_old+difference; // restore the homogeneous value if needed new_value = homogeneous?std_to_hom((*bline)(time), new_value, wplistloop, blineloop):new_value; // this is the difference between the new value and the old value inside the boundaries Real bound_diff((wp.get_lower_bound() + new_value*(wp.get_upper_bound()-wp.get_lower_bound()))-value_old_b); // add the new diff to the current value new_value = wp.get_position() + bound_diff; } else { // grab a new position given by duck's position on the bline new_value = synfig::find_closest_point((*bline)(time), p , radius, blineloop); // if it is homogeneous then convert to it new_value=homogeneous?std_to_hom((*bline)(time), new_value, wplistloop, blineloop):new_value; // convert the value inside the boundaries new_value = wp.get_lower_bound()+new_value*(wp.get_upper_bound()-wp.get_lower_bound()); } cr->save(); layout->set_text(strprintf("%2.3f", new_value)); cr->set_source_rgb(0,0,0); // DUCK_COLOR_WIDTH_TEXT_1 cr->move_to( point[0]+1+6, point[1]+1-18 ); layout->show_in_cairo_context(cr); cr->stroke(); cr->set_source_rgb(1,0,1); // DUCK_COLOR_WIDTH_TEXT_2 cr->move_to( point[0]+6, point[1]-18 ); layout->show_in_cairo_context(cr); cr->stroke(); cr->restore(); } } } } } for(;screen_duck_list.size();screen_duck_list.pop_front()) { Gdk::Color color(screen_duck_list.front().color); double radius = 4; double outline = 1; bool duck_alternative = alternative && screen_duck_list.front().has_alternative; // Draw the hovered duck last (on top of everything) if(screen_duck_list.front().hover && !screen_duck_list.back().hover && screen_duck_list.size()>1) { screen_duck_list.push_back(screen_duck_list.front()); continue; } cr->save(); if(!screen_duck_list.front().selected) { color.set_red(color.get_red()*2/3); color.set_green(color.get_green()*2/3); color.set_blue(color.get_blue()*2/3); } if(screen_duck_list.front().hover) { radius += 1; outline += 1; } cr->arc( screen_duck_list.front().pos[0], screen_duck_list.front().pos[1], radius, 0, M_PI*2 ); cr->set_source_rgba( color.get_red_p(), color.get_green_p(), color.get_blue_p(), duck_alternative ? 0.5 : 1.0 ); cr->fill_preserve(); cr->set_line_width(outline); cr->set_source_rgba(0,0,0,1); //DUCK_COLOR_OUTLINE cr->stroke(); cr->restore(); } }
/** Draw person legs. * Draws the legs of persons * @param window Gdk window * @param cr Cairo context to draw to. It is assumed that possible transformations * have been setup before. */ void LaserDrawingArea::draw_persons_legs(Glib::RefPtr<Gdk::Window> &window, const Cairo::RefPtr<Cairo::Context> &cr) { std::list<ObjectPositionInterface*>::iterator objpos_if_itt;; cr->save(); if (__l_objpos_if_persons) { cr->set_source_rgb(0,0,1); for( objpos_if_itt = __l_objpos_if_persons->begin(); objpos_if_itt != __l_objpos_if_persons->end() && (*objpos_if_itt)->has_writer(); objpos_if_itt++ ) { if(!__break_drawing) (*objpos_if_itt)->read(); if ((*objpos_if_itt)->is_valid()){ std::pair<float,float> pos = transform_coords_from_fawkes((*objpos_if_itt)->relative_x(), (*objpos_if_itt)->relative_y()); float x=pos.first; float y=pos.second; cr->move_to(x, y); // cr->arc(x, y, std::max((*objpos_if_itt)->extent_x(),(*objpos_if_itt)->extent_y()), 0, 2*M_PI); cr->arc(x, y, 0.2, 0, 2*M_PI); } } cr->stroke(); } if (__l_objpos_if_legs) { cr->set_source_rgb(0,1,0); for( objpos_if_itt = __l_objpos_if_legs->begin(); objpos_if_itt != __l_objpos_if_legs->end() && (*objpos_if_itt)->has_writer() ; objpos_if_itt++ ) { if(!__break_drawing) (*objpos_if_itt)->read(); if ((*objpos_if_itt)->is_valid()){ std::pair<float,float> pos = transform_coords_from_fawkes((*objpos_if_itt)->relative_x(), (*objpos_if_itt)->relative_y()); float x=pos.first; float y=pos.second; cr->move_to(x, y); cr->arc(x, y, 0.1, 0, 2*M_PI); } } cr->stroke(); } if (__l_objpos_if_misc) { cr->set_source_rgb(0,1,1); for( objpos_if_itt = __l_objpos_if_misc->begin(); objpos_if_itt != __l_objpos_if_misc->end() && (*objpos_if_itt)->has_writer() ; objpos_if_itt++ ) { if(!__break_drawing) (*objpos_if_itt)->read(); if ((*objpos_if_itt)->is_valid()){ // switch( (*objpos_if_itt)->object_type() ){ // case ObjectPositionInterface::TYPE_BALL: //TYPE_OPPONENT if((*objpos_if_itt)->object_type()==ObjectPositionInterface::TYPE_BALL){ std::pair<float,float> pos = transform_coords_from_fawkes((*objpos_if_itt)->relative_x(), (*objpos_if_itt)->relative_y()); float x=pos.first; float y=pos.second; pos = transform_coords_from_fawkes((*objpos_if_itt)->world_x(), (*objpos_if_itt)->world_y()); float begin_x=pos.first; float begin_y=pos.second; pos = transform_coords_from_fawkes((*objpos_if_itt)->world_x_velocity(), (*objpos_if_itt)->world_y_velocity()); float end_x= pos.first; float end_y= pos.first; float angle1=atan2(begin_y- y, begin_x - x); float angle2=atan2(end_y- y, end_x - x); float radius=(*objpos_if_itt)->relative_x_velocity(); float probability = (*objpos_if_itt)->relative_z_velocity(); cr->move_to(begin_x, begin_y); cr->arc(x, y, radius, angle2, angle1); // Cairo::TextExtents te; std::string t = StringConversions::to_string(probability); t.erase(5); // cr->set_source_rgb(0,1 ,1); cr->set_font_size(0.08); // cr->get_text_extents(t, te); // cr->move_to(- te.width / 2, -te.height / 2); cr->move_to(begin_x, begin_y); cr->show_text(t); // cr->set_source_rgb(0,0,1); // break; // case ObjectPositionInterface::TYPE_LINE: }else if((*objpos_if_itt)->object_type()==ObjectPositionInterface::TYPE_LINE){ std::pair<float,float> pos = transform_coords_from_fawkes((*objpos_if_itt)->world_x(), (*objpos_if_itt)->world_y()); float begin_x=pos.first; float begin_y=pos.second; pos = transform_coords_from_fawkes((*objpos_if_itt)->world_x_velocity(), (*objpos_if_itt)->world_y_velocity()); float end_x= pos.first; float end_y= pos.first; cr->move_to(begin_x, begin_y); cr->line_to(end_x, end_y); //break; } } } // cr->fill_preserve(); cr->stroke(); } cr->set_source_rgb(1,0,1); float r,g,b; r=g=b=0.0; int color_it=0; float delta = 0.25; if (__l_track_if) { std::list<Position2DTrackInterface*>::iterator track_if_itt;; const float radius (0.1); float* x_positions1; float* y_positions1; int* timestamps1; float* x_positions2 = NULL; float* y_positions2 = NULL; unsigned int track_length1 = 0; unsigned int track_length2 = 0; int* timestamps2 = NULL; unsigned int id; cr->set_font_size(0.03); #ifdef LASERGUI_DEBUG_PRINT_TRACKS printf("\n\n################################\n"); #endif for( track_if_itt = __l_track_if->begin(); track_if_itt != __l_track_if->end() && (*track_if_itt)->has_writer();) { bool b_compound_track(false); if(!__break_drawing) (*track_if_itt)->read(); if ((*track_if_itt)->is_valid()){ x_positions1=(*track_if_itt)->track_x_positions(); y_positions1=(*track_if_itt)->track_y_positions(); timestamps1=(*track_if_itt)->track_timestamps(); track_length1 = (*track_if_itt)->length(); id = (*track_if_itt)->track_id(); ++track_if_itt; if( track_if_itt != __l_track_if->end() && (*track_if_itt)->has_writer()){ if(!__break_drawing) (*track_if_itt)->read(); if( (*track_if_itt)->is_valid() && (*track_if_itt)->track_id()==id ){ b_compound_track = true; x_positions2=(*track_if_itt)->track_x_positions(); y_positions2=(*track_if_itt)->track_y_positions(); timestamps2=(*track_if_itt)->track_timestamps(); track_length2 = (*track_if_itt)->length(); ++track_if_itt; } } #ifdef LASERGUI_DEBUG_PRINT_TRACKS printf("\n trackid %d\n", id); #endif unsigned int i(0); unsigned int j(0); float x = x_positions1[i]; float y = y_positions1[i]; if(b_compound_track){ while(j+1 < track_length2 && timestamps2[j] < timestamps1[i]){ ++j; } if(timestamps2[j] == timestamps1[i]){ x += x_positions2[i]; x /= 2; y += y_positions2[i]; y /=2; } } std::pair<float,float> pos = transform_coords_from_fawkes(x,y); cr->move_to(pos.first,pos.second); for (; i < track_length1; ++i){ x = x_positions1[i]; y = y_positions1[i]; if(b_compound_track){ while(j+1 < track_length2 && timestamps2[j] < timestamps1[i]){ ++j; } if(timestamps2[j] == timestamps1[i]){ x += x_positions2[i]; x /= 2; y += y_positions2[i]; y /=2; } } std::pair<float,float> pos = transform_coords_from_fawkes(x,y); //cr->move_to(pos.first - radius, pos.second); // cr->arc(pos.first, pos.second, radius, 0, 2*M_PI); cr->line_to(pos.first, pos.second); // cr->rectangle(x_positions[i], y_positions[i], 4 / __zoom_factor, 4 / __zoom_factor); // std::string t = StringConversions::toString(id) + "-" + StringConversions::toString(timestamps[i]); std::string t = StringConversions::to_string(timestamps1[i]); // cr->move_to(begin_x, begin_y); cr->show_text(t); cr->move_to(pos.first, pos.second); #ifdef LASERGUI_DEBUG_PRINT_TRACKS printf("( %f,%f,[%d] )", pos.first, pos.second, timestamps1[i] ); #endif } // chose color if (div(color_it,3).rem == 0) r+= delta; if (div(color_it,3).rem == 1) g+= delta; if (div(color_it,3).rem == 2) b+= delta; cr->set_source_rgb(r,g,b); color_it++; cr->stroke(); i = std::max(0, (int) track_length1 - CFG_PRINT_NR_TRACKELEMENTS); j = 0; for (; i < track_length1; ++i){ x = x_positions1[i]; y = y_positions1[i]; if(b_compound_track){ while(j+1 < track_length2 && timestamps2[j] < timestamps1[i]){ ++j; } } std::pair<float,float> pos = transform_coords_from_fawkes(x_positions1[i],y_positions1[i]); cr->move_to(pos.first - radius, pos.second); cr->arc(pos.first, pos.second, radius, 0, 2*M_PI); if(b_compound_track && timestamps2[j] == timestamps1[i]){ cr->move_to(pos.first, pos.second); std::pair<float,float> pos = transform_coords_from_fawkes(x_positions2[j],y_positions2[j]); cr->line_to(pos.first, pos.second); cr->move_to(pos.first - radius, pos.second); cr->arc(pos.first, pos.second, radius, 0, 2*M_PI); } } cr->set_source_rgb(0,0,1); cr->stroke(); } else{ break; } } } /* DRAW TARGET */ if(__target_if && __target_if->has_writer()){ __target_if->read(); if(__target_if->is_valid()){ cr->set_source_rgb(1,0,0); std::pair<float,float> pos = transform_coords_from_fawkes(__target_if->relative_x(), __target_if->relative_y()); float x=pos.first; float y=pos.second; float radius = 0.1; cr->move_to(x, y); cr->arc(x, y, radius, 0, 2*M_PI); cr->move_to(x - radius, y); cr->line_to(x + radius, y); cr->move_to(x, y - radius ); cr->line_to(x, y + radius); cr->stroke(); } } /* float r,g,b; r=g=b=0.0; float delta = 0.2; for (int i = 0; i< 15 ; i++){ if (div(i,3).rem == 0) r+= delta; if (div(i,3).rem == 1) g+= delta; if (div(i,3).rem == 2) b+= delta; // printf("i %d rem %d| r %f, g %f, b %f\n", i, div(i,3).rem,r,g,b); cr->move_to(0, (i+1)*0.125); cr->set_source_rgb(r,g,b); cr->rectangle(0, (i+1)*0.125, 0.1 , 0.1 ); cr->fill_preserve(); cr->stroke(); } */ // cr->stroke(); cr->restore(); }
void VistaIdentificador::dibujar(Cairo::RefPtr<Cairo::Context> cr) { std::vector<VistaAtributo *>::iterator i; std::vector<VistaUnionEntidadRelacion *>::iterator j; cr->set_line_width(1); if (!this->seleccionado) { cr->set_source_rgb(colorNegro.get_red_p(), colorNegro.get_green_p(), colorNegro.get_blue_p()); } else { cr->set_source_rgb(colorDeSeleccion.get_red_p(), colorDeSeleccion.get_green_p(), colorDeSeleccion.get_blue_p()); } double x0, x1, y0, y1; if (this->vistasAtributo.size() == 1) { if (this->vistasEntidadesFuertes.empty()) { this->vistasAtributo[0]->setEsIdentificador(true); this->vistasAtributo[0]->dibujar(cr); } else { this->vistasAtributo[0]->getPuntoMedioLinea(x0, y0); cr->arc(x0, y0, RADIO_CIRCULOS_REDIMENSION, 0, 2 * M_PI); cr->fill(); cr->move_to(x0, y0); for (j = this->vistasEntidadesFuertes.begin(); j != this->vistasEntidadesFuertes.end(); j++) { (*j)->getPuntoMedioLinea(x1, y1); cr->line_to(x1, y1); cr->stroke(); cr->arc(x1, y1, RADIO_CIRCULOS_REDIMENSION, 0, 2 * M_PI); cr->fill(); cr->move_to(x0, y0); } cr->stroke(); } } else { this->vistasAtributo[0]->getPuntoMedioLinea(x0, y0); cr->arc(x0, y0, RADIO_CIRCULOS_REDIMENSION, 0, 2 * M_PI); cr->fill(); cr->move_to(x0, y0); for (i = (this->vistasAtributo.begin() + 1); i != this->vistasAtributo.end(); i++) { (*i)->getPuntoMedioLinea(x1, y1); cr->line_to(x1, y1); cr->stroke(); cr->arc(x1, y1, RADIO_CIRCULOS_REDIMENSION, 0, 2 * M_PI); cr->fill(); cr->move_to(x1, y1); } cr->stroke(); if (!this->vistasEntidadesFuertes.empty()) { cr->move_to(x0, y0); for (j = this->vistasEntidadesFuertes.begin(); j != this->vistasEntidadesFuertes.end(); j++) { (*j)->getPuntoMedioLinea(x1, y1); cr->line_to(x1, y1); #if DEBUG_DIBUJAR==1 cout << "X1=" << x1 << " Y1=" << y1 << endl; #endif cr->stroke(); cr->arc(x1, y1, RADIO_CIRCULOS_REDIMENSION, 0, 2 * M_PI); cr->fill(); cr->move_to(x0, y0); } cr->stroke(); } } /*if (this->vistaAtributos.empty()) { double radio; radio = 3; centro_x = this->pos_ini_x + radio; centro_y = this->pos_ini_y + radio; this->pos_fin_x = centro_x + radio; this->pos_fin_y = centro_y + radio; //cr->move_to(centro_x, this->pos_ini_y); cr->arc(centro_x, centro_y, radio, 0, 2 * M_PI); // TODO if es parte de una clave candidata FILL //cr->fill(); cr->stroke(); } else { double delta_x, delta_y; if (this->pos_fin_x < this->pos_ini_x || this->pos_fin_y < this->pos_ini_y) { cr->get_text_extents(this->atributo->getNombre(), textExtents); this->calcularDimensionesAPartirDeTexto(&textExtents); } // Dibujo una elipse centro_x = (this->pos_ini_x + this->pos_fin_x) / 2; centro_y = (this->pos_ini_y + this->pos_fin_y) / 2; delta_x = centro_x - this->pos_ini_x; delta_y = centro_y - this->pos_ini_y; this->dibujarNombreCentrado(cr, this->atributo->getNombre()); cr->save(); cr->set_line_width(2 / MAX(delta_x, delta_y));// make (centro_x, centro_y) == (0, 0) cr->translate(centro_x, centro_y); cr->scale(delta_x, delta_y); cr->arc(0.0, 0.0, 1.0, 0.0, 2 * M_PI); cr->stroke(); cr->restore(); // back to opaque black if (this->seleccionado) { dibujarCirculosDeRedimension(cr); } }*/ }
bool CalibrationArea::on_expose_event(GdkEventExpose *event) { // check that screensize did not change if (display_width != get_width() || display_height != get_height()) { set_display_size(get_width(), get_height()); } Glib::RefPtr<Gdk::Window> window = get_window(); if (window) { Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context(); cr->save(); cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height); cr->clip(); // Print the text cr->set_font_size(font_size); double text_height = -1; double text_width = -1; Cairo::TextExtents extent; for (int i = 0; i != help_lines; i++) { cr->get_text_extents(help_text[i], extent); text_width = std::max(text_width, extent.width); text_height = std::max(text_height, extent.height); } text_height += 2; double x = (display_width - text_width) / 2; double y = (display_height - text_height) / 2 - 60; cr->set_line_width(2); cr->rectangle(x - 10, y - (help_lines*text_height) - 10, text_width + 20, (help_lines*text_height) + 20); // Print help lines y -= 3; for (int i = help_lines-1; i != -1; i--) { cr->get_text_extents(help_text[i], extent); cr->move_to(x + (text_width-extent.width)/2, y); cr->show_text(help_text[i]); y -= text_height; } cr->stroke(); // Draw the points for (int i = 0; i <= calibrator->get_numclicks(); i++) { // set color: already clicked or not if (i < calibrator->get_numclicks()) cr->set_source_rgb(1.0, 1.0, 1.0); else cr->set_source_rgb(0.8, 0.0, 0.0); cr->set_line_width(1); cr->move_to(X[i] - cross_lines, Y[i]); cr->rel_line_to(cross_lines*2, 0); cr->move_to(X[i], Y[i] - cross_lines); cr->rel_line_to(0, cross_lines*2); cr->stroke(); cr->arc(X[i], Y[i], cross_circle, 0.0, 2.0 * M_PI); cr->stroke(); } // Draw the clock background cr->arc(display_width/2, display_height/2, clock_radius/2, 0.0, 2.0 * M_PI); cr->set_source_rgb(0.5, 0.5, 0.5); cr->fill_preserve(); cr->stroke(); cr->set_line_width(clock_line_width); cr->arc(display_width/2, display_height/2, (clock_radius - clock_line_width)/2, 3/2.0*M_PI, (3/2.0*M_PI) + ((double)time_elapsed/(double)max_time) * 2*M_PI); cr->set_source_rgb(0.0, 0.0, 0.0); cr->stroke(); // Draw the message (if any) if (message != NULL) { // Frame the message cr->set_font_size(font_size); Cairo::TextExtents extent; cr->get_text_extents(this->message, extent); text_width = extent.width; text_height = extent.height; x = (display_width - text_width) / 2; y = (display_height - text_height + clock_radius) / 2 + 60; cr->set_line_width(2); cr->rectangle(x - 10, y - text_height - 10, text_width + 20, text_height + 25); // Print the message cr->move_to(x, y); cr->show_text(this->message); cr->stroke(); } cr->restore(); } return true; }
void arc__(Glib::ustring& d1,Glib::ustring& d2,Glib::ustring& d3,Glib::ustring& d4,Glib::ustring& d5){ cr_->arc(s2f__(d1),s2f__(d2),s2f__(d3),s2f__(d4),s2f__(d5)); }
void area___::test__(){ int width, height; width=da_->get_allocation().get_width(); height=da_->get_allocation().get_height(); double m_radius=0.42; double m_line_width=0.05; // scale to unit square and translate (0, 0) to be (0.5, 0.5), i.e. // the center of the window cr_->scale(width, height); cr_->translate(0.5, 0.5); cr_->set_line_width(m_line_width); cr_->save(); cr_->set_source_rgba(0.337, 0.612, 0.117, 0.9); // green cr_->paint(); cr_->restore(); cr_->arc(0, 0, m_radius, 0, 2 * M_PI); cr_->save(); cr_->set_source_rgba(1.0, 1.0, 1.0, 0.8); cr_->fill_preserve(); cr_->restore(); cr_->stroke_preserve(); cr_->clip(); //clock ticks for (int i = 0; i < 12; i++) { double inset = 0.05; cr_->save(); cr_->set_line_cap(Cairo::LINE_CAP_ROUND); if(i % 3 != 0) { inset *= 0.8; cr_->set_line_width(0.03); } cr_->move_to( (m_radius - inset) * cos (i * M_PI / 6), (m_radius - inset) * sin (i * M_PI / 6)); cr_->line_to ( m_radius * cos (i * M_PI / 6), m_radius * sin (i * M_PI / 6)); cr_->stroke(); cr_->restore(); // stack-pen-size } // store the current time time_t rawtime; time(&rawtime); struct tm * timeinfo = localtime (&rawtime); // compute the angles of the indicators of our clock double minutes = timeinfo->tm_min * M_PI / 30; double hours = timeinfo->tm_hour * M_PI / 6; double seconds= timeinfo->tm_sec * M_PI / 30; cout<<timeinfo->tm_min<<","<<timeinfo->tm_hour<<","<<timeinfo->tm_sec<<endl; cr_->save(); cr_->set_line_cap(Cairo::LINE_CAP_ROUND); // draw the seconds hand cr_->save(); cr_->set_line_width(m_line_width / 3); cr_->set_source_rgba(0.7, 0.7, 0.7, 0.8); // gray cr_->move_to(0, 0); cr_->line_to(sin(seconds) * (m_radius * 0.9), -cos(seconds) * (m_radius * 0.9)); cr_->stroke(); cr_->restore(); // draw the minutes hand cr_->set_source_rgba(0.117, 0.337, 0.612, 0.9); // blue cr_->move_to(0, 0); cr_->line_to(sin(minutes + seconds / 60) * (m_radius * 0.8), -cos(minutes + seconds / 60) * (m_radius * 0.8)); cr_->stroke(); // draw the hours hand cr_->set_source_rgba(0.337, 0.612, 0.117, 0.9); // green cr_->move_to(0, 0); cr_->line_to(sin(hours + minutes / 12.0) * (m_radius * 0.5), -cos(hours + minutes / 12.0) * (m_radius * 0.5)); cr_->stroke(); cr_->restore(); // draw a little dot in the middle cr_->arc(0, 0, m_line_width / 3.0, 0, 2 * M_PI); cr_->fill(); }
void Switch::draw(const Cairo::RefPtr<Cairo::Context>& cr){ cr->save(); cr->translate(parent->xoffset + x, y); /* cr->set_source_rgb(200.0/256.0, 200.0/256.0, 215.0/256.0); cr->set_source_rgb(140.0/256.0, 140.0/256.0, 150.0/256.0); cr->set_source_rgb(160.0/256.0, 160.0/256.0, 170.0/256.0); */ cr->set_source_rgb(200.0/256.0, 200.0/256.0, 215.0/256.0); cr->arc(0,0, 10, 0.0, 2*M_PI); cr->fill(); //hole cr->set_source_rgb(30.0/256.0, 30.0/256.0, 30.0/256.0); cr->arc(0,0, 7, 0.0, 2*M_PI); cr->fill(); //handle const double len = 15.0; double endx, endy; if(!vertical){ if(value) {endx = len; endy = 0.0;} else {endx = -len; endy = 0.0;} }else{ if(value) {endx = 0.0; endy = len;} else {endx = 0.0; endy = -len;} } cr->set_line_width(6.0); cr->set_line_cap(Cairo::LINE_CAP_ROUND); cr->set_source_rgb(1.0,1.0,1.0); cr->move_to(0.0,0.0); cr->line_to(endx,endy); cr->stroke(); cr->set_source_rgb(170.0/256.0, 170.0/256.0, 170.0/256.0); cr->move_to(endx,endy); cr->arc(endx,endy,4,0.0,2*M_PI); cr->fill(); //text cr->select_font_face("Verdana",Cairo::FONT_SLANT_NORMAL,Cairo::FONT_WEIGHT_BOLD); cr->set_font_size(10.0); cr->set_source_rgb(1.0,1.0,1.0); Cairo::TextExtents tx; if(!vertical){ cr->get_text_extents(text1,tx); cr->move_to(-tx.width - 24.0, 3.0 ); cr->show_text(text1); cr->get_text_extents(text2,tx); cr->move_to(22.0, 3.0 ); cr->show_text(text2); }else{ cr->get_text_extents(text1,tx); cr->move_to(-tx.width/2.0, -22.0 ); cr->show_text(text1); cr->move_to(-tx.width/2.0, 27.0 ); cr->get_text_extents(text2,tx); cr->show_text(text2); } cr->restore(); }
void MyWidget::drawWidget() { Painter p(this); if (m_color) { p.setSourceRGB(1.0, 0, 0); } else { p.setSourceRGB(0, 0, 0); } p.translate(minimumSize().width() / 2.0, minimumSize().height() / 2.0); p.setLineWidth(m_lineWidth); p.arc(0, 0, m_radius, 0, 2 * M_PI); p.save(); p.setSourceRGBA(1.0, 1.0, 1.0, 0.8); p.fillPreserve(); p.restore(); p.strokePreserve(); p.clip(); for (int i = 0; i < 12; ++i) { double inset = 30; p.save(); p.setLineCap(Painter::RoundLineCap); if(i % 3 != 0) { inset *= 0.8; p.setLineWidth(1.0); } p.moveTo((m_radius - inset) * cos (i * M_PI / 6.0), (m_radius - inset) * sin (i * M_PI / 6.0)); p.lineTo(m_radius * cos (i * M_PI / 6.0), m_radius * sin (i * M_PI / 6.0)); p.stroke(); p.restore(); } // store the current time time_t rawtime; time(&rawtime); struct tm * timeinfo = localtime (&rawtime); // compute the angles of the indicators of our clock double minutes = timeinfo->tm_min * M_PI / 30; double hours = timeinfo->tm_hour * M_PI / 6; double seconds= timeinfo->tm_sec * M_PI / 30; p.save(); p.setLineCap(Painter::RoundLineCap); // draw the seconds hand p.save(); p.setLineWidth(m_lineWidth); p.setSourceRGBA(0.7, 0.7, 0.7, 0.8); p.moveTo(0, 0); p.lineTo(sin(seconds) * (m_radius * 0.9), -cos(seconds) * (m_radius * 0.9)); p.stroke(); p.restore(); // draw the minutes hand p.setSourceRGBA(0.117, 0.337, 0.612, 0.9); p.moveTo(0, 0); p.lineTo(sin(minutes + seconds / 60.0) * (m_radius * 0.8), -cos(minutes + seconds / 60.0) * (m_radius * 0.8)); p.stroke(); // draw the hours hand p.setSourceRGBA(0.337, 0.612, 0.117, 0.9); p.moveTo(0, 0); p.lineTo(sin(hours + minutes / 12.0) * (m_radius * 0.5), -cos(hours + minutes / 12.0) * (m_radius * 0.5)); p.stroke(); p.restore(); p.setSourceRGBA(1, 0, 0, 0.5); p.arc(0, 0, m_lineWidth * 2.0, 0, 2.0 * M_PI); p.fill(); #if 0 // This is where we draw on the window Glib::RefPtr<Gdk::Window> window = get_window(); if(window) { Gtk::Allocation allocation = get_allocation(); const int width = allocation.get_width(); const int height = allocation.get_height(); Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context(); if(event) { // clip to the area indicated by the expose event so that we only // redraw the portion of the window that needs to be redrawn cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height); cr->clip(); } // background gradient { Cairo::RefPtr<Cairo::LinearGradient> pat = Cairo::LinearGradient::create(0.0, 0.0, 0.0, height); pat->add_color_stop_rgb(1.0, 1.0, 1.0, 1.0); pat->add_color_stop_rgb(0.0, 0.0, 0.0, 0.0); cr->rectangle(0, 0, width, height); cr->set_source(pat); cr->fill(); } // scale to unit square and translate (0, 0) to be (0.5, 0.5), i.e. // the center of the window cr->scale(width, height); cr->translate(0.5, 0.5); cr->set_line_width(m_line_width); cr->arc(0, 0, m_radius, 0, 2 * M_PI); cr->save(); cr->set_source_rgba(1.0, 1.0, 1.0, 0.8); cr->fill_preserve(); cr->restore(); cr->stroke_preserve(); cr->clip(); //clock ticks for (int i = 0; i < 12; i++) { double inset = 0.05; cr->save(); cr->set_line_cap(Cairo::LINE_CAP_ROUND); if(i % 3 != 0) { inset *= 0.8; cr->set_line_width(0.03); } cr->move_to( (m_radius - inset) * cos (i * M_PI / 6), (m_radius - inset) * sin (i * M_PI / 6)); cr->line_to ( m_radius * cos (i * M_PI / 6), m_radius * sin (i * M_PI / 6)); cr->stroke(); cr->restore(); /* stack-pen-size */ } // store the current time time_t rawtime; time(&rawtime); struct tm * timeinfo = localtime (&rawtime); // compute the angles of the indicators of our clock double minutes = timeinfo->tm_min * M_PI / 30; double hours = timeinfo->tm_hour * M_PI / 6; double seconds= timeinfo->tm_sec * M_PI / 30; cr->save(); cr->set_line_cap(Cairo::LINE_CAP_ROUND); // draw the seconds hand cr->save(); cr->set_line_width(m_line_width / 3); cr->set_source_rgba(0.7, 0.7, 0.7, 0.8); // gray cr->move_to(0, 0); cr->line_to(sin(seconds) * (m_radius * 0.9), -cos(seconds) * (m_radius * 0.9)); cr->stroke(); cr->restore(); // draw the minutes hand cr->set_source_rgba(0.117, 0.337, 0.612, 0.9); // blue cr->move_to(0, 0); cr->line_to(sin(minutes + seconds / 60) * (m_radius * 0.8), -cos(minutes + seconds / 60) * (m_radius * 0.8)); cr->stroke(); // draw the hours hand cr->set_source_rgba(0.337, 0.612, 0.117, 0.9); // green cr->move_to(0, 0); cr->line_to(sin(hours + minutes / 12.0) * (m_radius * 0.5), -cos(hours + minutes / 12.0) * (m_radius * 0.5)); cr->stroke(); cr->restore(); // draw a little dot in the middle cr->arc(0, 0, m_line_width / 3.0, 0, 2 * M_PI); cr->fill(); } #endif }
bool PhotoPreview::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) { if (!Image) return false; int Width,Height; Gtk::Allocation Allocation = get_allocation(); Width=Allocation.get_width(); Height=Allocation.get_height(); if (Width<=1 || Height<=1) return false; /* Scale the photo */ Glib::RefPtr<Gdk::Pixbuf> Scaled; /* Preserve aspect ratio */ double ImageAspectRatio,PreviewAspectRatio; PreviewAspectRatio=(float)Width/Height; ImageAspectRatio=(float)Image->get_width()/Image->get_height(); if (ImageAspectRatio<PreviewAspectRatio) { Width=Height*ImageAspectRatio; } else { Height=Width/ImageAspectRatio; } Scaled=Image->scale_simple( Width, Height, Gdk::INTERP_BILINEAR); if (Cfg->GetFlipPreview()) Scaled=Scaled->flip(); Gdk::Cairo::set_source_pixbuf(cr, Scaled, (Allocation.get_width()/2)-(Scaled->get_width()/2), (Allocation.get_height()/2)-(Scaled->get_height()/2) ); cr->paint(); double TimeLeft=Util::TimeDiff(&PhotoTime,NULL); double MinDim=get_width(); if (get_height()<MinDim) MinDim=get_height(); if (Overlay.length()==0 && TimeLeft>0) { double TotalTime=Cfg->GetCountdownCount()*(Cfg->GetCountdownTimeout()/1000.0); unsigned int Whole=floor(Cfg->GetCountdownCount()*TimeLeft/TotalTime); float Frac=(Cfg->GetCountdownCount()*TimeLeft/TotalTime)-Whole; Cairo::RefPtr<Cairo::Context> Context = get_window()->create_cairo_context(); Context->set_source_rgba(1.0, 1.0, 1.0,0.5); Context->translate(get_width()/2.0,get_height()/2.0); /* Draw the fractional portion of the countdown */ Context->save(); Context->rotate(M_PI/2.0); Context->arc(0.0,0.0,MinDim/4.0,0,Frac*2*M_PI); Context->fill(); Context->restore(); /* Draw the Whole portion of the countdown */ Context->save(); Context->set_font_size(MinDim/2.0); char StrBuf[1024]; snprintf(StrBuf,sizeof(StrBuf),"%d",Whole+1); Cairo::TextExtents Extents; Context->get_text_extents(StrBuf,Extents); Context->translate(-Extents.width/2.0,Extents.height/2.0); Context->show_text(StrBuf); Context->stroke(); Context->restore(); } if (Overlay.length()) { Cairo::RefPtr<Cairo::Context> Context = get_window()->create_cairo_context(); Context->set_source_rgba(1.0, 1.0, 1.0,0.5); Context->translate(get_width()/2.0,get_height()/2.0); Context->save(); Context->set_font_size(MinDim/2.0); Cairo::TextExtents Extents; Context->get_text_extents(Overlay,Extents); Context->translate(-Extents.width/2.0,Extents.height/2.0); Context->show_text(Overlay); Context->stroke(); Context->restore(); } return true; }
bool knob::on_expose_event(GdkEventExpose* event) { // This is where we draw on the window Glib::RefPtr<Gdk::Window> window = get_window(); if(window) { Gtk::Allocation allocation = get_allocation(); const int width = allocation.get_width(); const int height = allocation.get_height() - (allocation.get_height()/3); const int height_offset = allocation.get_height()/6; // coordinates for the center of the window int xc, yc; xc = width / 2; yc = height / 2; Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context(); cr->set_line_width(6.0); // clip to the area indicated by the expose event so that we only redraw // the portion of the window that needs to be redrawn cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height); cr->clip(); // background grad Cairo::RefPtr<Cairo::LinearGradient> back_grad = Cairo::LinearGradient::create( 0,0,0,allocation.get_height() ); switch (pos_mode) { case 0: back_grad->add_color_stop_rgba(0,top_colour.get_red_p(),top_colour.get_green_p(),top_colour.get_blue_p(),1); back_grad->add_color_stop_rgba(1,bottom_colour.get_red_p(),bottom_colour.get_green_p(),bottom_colour.get_blue_p(),1); break; case 1: back_grad->add_color_stop_rgba(0,top_colour.get_red_p(),top_colour.get_green_p(),top_colour.get_blue_p(),1); back_grad->add_color_stop_rgba(1, (bottom_colour.get_red_p() + top_colour.get_red_p())/2, (bottom_colour.get_green_p() + top_colour.get_green_p())/2, (bottom_colour.get_blue_p() + top_colour.get_blue_p())/2, 1); break; case 2: back_grad->add_color_stop_rgba(0, (bottom_colour.get_red_p() + top_colour.get_red_p())/2, (bottom_colour.get_green_p() + top_colour.get_green_p())/2, (bottom_colour.get_blue_p() + top_colour.get_blue_p())/2, 1); back_grad->add_color_stop_rgba(1,bottom_colour.get_red_p(),bottom_colour.get_green_p(),bottom_colour.get_blue_p(),1); break; } // fill background if (rounded<5) { rounded_rectangle(cr,rounded, grad_top_colour, grad_bottom_colour, event->area.x, event->area.y, event->area.width, event->area.height,pos_mode, top_colour.to_string(),bottom_colour.to_string() ); } else { cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height); } cr->set_source(back_grad); cr->fill(); // ------------------------------------------------------------------ float cos_x = (allocation.get_width()/5) * (cos(((((1-knob_value)*0.75)-0.3)*2) * M_PI)); float sin_y = (allocation.get_width()/5) * (sin(((((1-knob_value)*0.75)-0.3)*2) * M_PI)); Cairo::RefPtr<Cairo::RadialGradient> grad1 = Cairo::RadialGradient::create( (allocation.get_width()/2) + sin_y, (allocation.get_height()/2) + cos_x, 0, (allocation.get_width()/2) , (allocation.get_height()/2) ,(allocation.get_width()/2.5)); grad1->add_color_stop_rgba(0,0.4,0.4,0.4,1); grad1->add_color_stop_rgba(0.5,0.2,0.2,0.2,1); grad1->add_color_stop_rgba(0.8,0.17,0.17,0.17,1); grad1->add_color_stop_rgba(1.0,0.0,0.0,0.0,1); cos_x = (allocation.get_width()/5) * (cos((((knob_value*0.75)-0.61)*2) * M_PI)); sin_y = (allocation.get_width()/5) * (sin((((knob_value*0.75)-0.61)*2) * M_PI)); cr->set_source(grad1); cr->arc(allocation.get_width()/2, allocation.get_height()/2, (allocation.get_width()/2.5), 0.0, 2 * M_PI); cr->fill(); cr->set_source_rgb(0.0, 0.0, 0.0); cr->arc((allocation.get_width()/2) +cos_x, (allocation.get_height()/2)+sin_y, (allocation.get_width()/16), 0.0, 2 * M_PI); cr->fill(); // draw text label cr->select_font_face("Bitstream Vera Sans", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL); cr->set_font_size(width/4.5); cr->set_source_rgba(0.9,0.9,0.9,0.8); Cairo::FontOptions font_options; font_options.set_hint_style(Cairo::HINT_STYLE_NONE); font_options.set_hint_metrics(Cairo::HINT_METRICS_OFF); font_options.set_antialias(Cairo::ANTIALIAS_GRAY); int x_font_centre = (width/2) - ((width/5) * (label.length()/3.5)); cr->set_font_options(font_options); cr->move_to(x_font_centre,height/3.5); cr->show_text(label); cr->move_to(x_font_centre,allocation.get_height() - (height_offset/3) ); ostringstream slider_value; slider_value.str(""); if (invert) { slider_value << max - value; } else { slider_value << value; } slider_value.str(slider_value.str().substr(0,5)); x_font_centre = (width/2) - ((width/5) * (slider_value.str().length()/3.5)); cr->move_to(x_font_centre,allocation.get_height() - (height_offset/1.5) ); cr->show_text(slider_value.str()); } return true; }
bool ClockDrawArea::on_draw(const Cairo::RefPtr<Cairo::Context>& context){ //Get the drawing area auto allocation = get_allocation(); const int width = allocation.get_width(); const int height = allocation.get_height(); //Set the scale to a unit square context->scale(width, height); //Set (0.5, 0.5) to (0, 0). convenient to draw with arc. context->translate(0.5, 0.5); //Paint the background of the window; context->save(); context->set_source_rgba(0.337, 0.612, 0.117, 0.9); context->paint(); context->restore(); //Draw the outer edge of the clock context->set_line_width(3 * m_LineWidth); context->arc(0, 0, m_Radius, 0, 2 * M_PI); //Paint the background color of the clock context->save(); context->set_source_rgba(1.0, 1.0, 1.0, 0.8); context->fill_preserve(); context->restore(); //Draw a center point for good looking context->stroke(); context->arc(0, 0, 0.05 * m_Radius, 0, 2 * M_PI); context->stroke(); //Draw ticks context->save(); double l = 1; for(int i = 0; i <= 11; i++){ if((i % 3) == 0) { l = m_Radius * 0.8; }else{ l = m_Radius * 0.9; } context->move_to(l * cos(i * 2* M_PI /12), l * sin(i * 2 * M_PI /12)); context->line_to(m_Radius * cos(i * 2 * M_PI /12), m_Radius * sin(i * 2 * M_PI /12)); } context->stroke(); context->restore(); //Get the current time from system and save info to a timeinfo struct time_t rawTime; time(&rawTime); struct tm * timeinfo = localtime(&rawTime); //Calculate the angle of hands of the clock auto radSeconds = (timeinfo->tm_sec * 2 * M_PI /60) - M_PI/2; auto radMinutes = (timeinfo->tm_min * 2 * M_PI /60) - M_PI/2; auto radHours = (timeinfo->tm_hour * 2 * M_PI /12) - M_PI/2 + timeinfo->tm_min * 2 * M_PI /(60 * 12); //Draw the hands of the clock context->save(); //The hand of seconds context->set_source_rgba(0.823, 0.322, 0.155, 0.9); context->set_line_width(m_LineWidth); l = 0.9 * m_Radius; context->move_to(0,0); context->line_to(l * cos(radSeconds), l * sin(radSeconds)); context->stroke(); //The hand of minutes context->set_source_rgba(0.632, 0.802, 0.266, 0.9); context->set_line_width(2 * m_LineWidth); l = 0.8 * m_Radius; context->move_to(0,0); context->line_to(l * cos(radMinutes), l * sin(radMinutes)); context->stroke(); //The hand of hours context->set_source_rgba(0.104, 0.582, 0.723, 0.9); context->set_line_width(3 * m_LineWidth); l = 0.65 * m_Radius; context->move_to(0,0); context->line_to(l * cos(radHours), l * sin(radHours)); context->stroke(); context->restore(); return true; }