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; }
virtual bool on_expose_event(GdkEventExpose* ) { Glib::RefPtr<Gdk::Drawable> drawable = get_window(); vc.get_frame(pixbuf); drawable->draw_pixbuf(get_style()->get_bg_gc(Gtk::STATE_NORMAL), pixbuf->scale_simple(get_width(), get_height(), Gdk::INTERP_BILINEAR), 0, 0, 0, 0, -1 , -1, Gdk::RGB_DITHER_NONE, 0, 0); Gdk::Point rect[4], barcode_center; string str; bool res = decode_barcode(pixbuf, rect, str, 100); if (res) { Cairo::RefPtr<Cairo::Context> cr = drawable->create_cairo_context(); cr->set_line_width(3); cr->set_source_rgb(1, 0.0, 0.0); cr->move_to(rect[0].get_x(), rect[0].get_y() ); cr->line_to(rect[1].get_x(), rect[1].get_y() ); cr->line_to(rect[2].get_x(), rect[2].get_y() ); cr->line_to(rect[3].get_x(), rect[3].get_y() ); cr->line_to(rect[0].get_x(), rect[0].get_y() ); cr->stroke(); BarcodePropertyEstimation distance(get_width(), get_height(), rect[0].get_x(), rect[0].get_y(), rect[1].get_x(), rect[1].get_y(), rect[2].get_x(), rect[2].get_y(), rect[3].get_x(), rect[3].get_y()); Glib::RefPtr<Pango::Layout> pango_layout = Pango::Layout::create(cr); Pango::FontDescription desc("Arial Rounded MT Bold"); desc.set_size(14 * PANGO_SCALE); pango_layout->set_font_description(desc); pango_layout->set_alignment(Pango::ALIGN_CENTER); double dir = distance.calcDirection(); string dir_str; if (dir > 2.3) dir_str = "right"; else if (dir < -2.3) dir_str = "left"; else dir_str = "front"; double dist = distance.calcDistance(); string text = "Object ID: " + str + "\nDistance: " + lexical_cast<string>(int(dist * 100) / 100) + "." + lexical_cast<string>(int(dist * 100) % 100) + "\nDirection: " + dir_str; pango_layout->set_text(text); Gdk::Point* max_x, *min_x, *max_y, *min_y; boost::function<bool (Gdk::Point, Gdk::Point)> compare; compare = bind(less<int>(), bind(&Gdk::Point::get_x, _1), bind(&Gdk::Point::get_x, _2)); max_x = max_element(rect, rect + 4, compare); min_x = min_element(rect, rect + 4, compare); compare = bind(less<int>(), bind(&Gdk::Point::get_y, _1), bind(&Gdk::Point::get_y, _2)); max_y = max_element(rect, rect + 4, compare); min_y = min_element(rect, rect + 4, compare); barcode_center = Gdk::Point( (max_x->get_x() + min_x->get_x()) / 2, (max_y->get_y() + min_y->get_y()) / 2); const Pango::Rectangle extent = pango_layout->get_pixel_logical_extents(); cr->move_to(get_width() - extent.get_width() - 10, get_height() - extent.get_height() - 10); pango_layout->show_in_cairo_context(cr); DetectedBarcode barcode(str, dir_str, distance.calcDistance()); vector<DetectedBarcode> vec; vec.push_back(barcode); ostringstream ostr; xmlpp::Document document1; listDetectedBarcodesToXML(document1.create_root_node("ObjectList"), vec); document1.write_to_stream(ostr, "UTF-8"); mut.lock(); strXML = ostr.str(); mut.unlock(); } return true; }
bool SamplerWidget::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 { allocation = get_allocation(); int width = allocation.get_width(); int height = allocation.get_height(); //std::cout << "Width: " << width << std::endl; //std::cout << "Height: " << height << std::endl; //std::cout << "Height / 12: " << height /12.0 << std::endl; // 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(); // 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 -> set_source_rgba(0 , 0, 0 , 1); cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height); //cr->rectangle(0,0,event->area.x,event->area.y); //cr->stroke_preserve(); cr->clip(); cr -> set_line_join (Cairo::LINE_JOIN_ROUND); cr -> move_to( 7, 7); cr -> line_to( width-7, 7); cr -> line_to( width-7, height-7); cr -> line_to( 7, height-7); cr -> close_path(); // Draw outline shape cr -> set_source_rgb (0.1,0.1,0.1); cr -> fill_preserve(); if (!padOnBool) { cr->set_source_rgba( 0.6, 0.6, 0.6, 0.5); cr->set_line_width ( 10.0); cr->stroke(); } else { cr->set_source_rgba( 1.0,0.4,0.0, 0.8); cr->set_line_width ( 10.4); cr->stroke(); } /* Pan functionality Not yet implemented in sampler. // Draw Pan line: pixel pan = width * pan cr -> set_line_cap (Cairo::LINE_CAP_ROUND); cr -> set_line_width ( 4.8); cr -> set_source_rgba( 1.0,0.8,0.8,0.8); cr -> move_to ( width/2 + ((width*pan)/2) , height - (height*volume) + 20); cr -> line_to ( width/2 + ((width*pan)/2) , height - (height*volume) - 20); cr -> stroke(); */ // Draw Volume line: pixel vol = height * volume cr -> set_line_width ( 5.1); cr -> set_source_rgb( 0.2,0.2,0.2); cr -> move_to ( 10 , (height - ((height-20)*volume))-8 ); cr -> line_to ( width-10, (height - ((height-20)*volume))-8 ); cr -> line_to ( width-10, height-10); cr -> line_to ( 10, height-10); cr -> close_path(); cr -> fill(); // Draw Mode: Loop/Hit if ( !loopSampleBool) { cr->set_line_width ( 2.2); cr->set_source_rgb(0.2,0.2,0.2); cr->move_to(width/5,(height/5)*2); cr->line_to((width/5)*3,(height/5)*2); cr->line_to((width/5)*3,(height/5)*1); cr->line_to((width/5)*4,height/2); // point of arrow cr->line_to((width/5)*3,(height/5)*4); cr->line_to((width/5)*3,(height/5)*3); cr->line_to(width/5,(height/5)*3); cr->close_path(); cr->fill_preserve(); cr->set_source_rgb(0.0,0.9,0.0); cr->stroke(); } else // Loop Sample { cr -> set_source_rgb(0.2,0.2,0.2); cr -> arc_negative (width/2, height/2, ((height + width)/8)-5 , 6.0, 0.6); // inner curve cr -> arc (width/2, height/2, ((height + width)/6)-5 , 0.5, 6.1); // outer curve cr -> line_to ((width-width/3.5) + width/8 , height/2 - height/18 ); // right point of arrow cr -> line_to ( width-width/3.5, height/2 + height/18 ); // point of arrow cr -> line_to ((width-width/3.5) - width/8 , height/2 - height/18 ); // left point of arrow cr -> close_path(); cr -> fill_preserve(); cr -> set_line_width(1.9); cr -> set_source_rgb(0.0,0.9,0.0); cr -> stroke(); } // Impose orange volume line (over SampleLoop/Play) cr -> move_to ( 10 , (height - ((height-20)*volume))-8 ); cr -> line_to ( width-10, (height - ((height-20)*volume))-8 ); cr -> set_source_rgb(1.0,0.4,0.0); cr -> stroke(); // Draw Text in center. Audio Clip name. cr -> set_source_rgb( 1.0,0.4,0.0); cr -> select_font_face ("Impact" , Cairo::FONT_SLANT_NORMAL,Cairo::FONT_WEIGHT_NORMAL); cr -> set_font_size ( 3 + xc/4 ); Cairo::TextExtents extents; std::transform(sampleName.begin(), sampleName.end(), sampleName.begin(), toupper); cr -> get_text_extents(sampleName, extents); cr -> move_to ( xc - extents.width/2 , height/2+height/18); cr -> show_text (sampleName); // sampleName defined in hpp as std::string } return true; }
bool studio::Widget_NavView::on_drawto_draw(const Cairo::RefPtr<Cairo::Context> &cr) { #ifdef SINGLE_THREADED // don't redraw if the previous redraw is still running single-threaded // or we end up destroying the renderer that's rendering it if (App::single_threaded && renderer && renderer->updating) return false; #endif //draw the good stuff on_start_render(); //if we've got a preview etc. display it... if(get_canvas_view()) { //axis transform from units to pixel coords float xaxis = 0, yaxis = 0; int canvw = get_canvas_view()->get_canvas()->rend_desc().get_w(); int w, h; float pw = get_canvas_view()->get_canvas()->rend_desc().get_pw(); float ph = get_canvas_view()->get_canvas()->rend_desc().get_ph(); if(prev && !studio::App::navigator_uses_cairo) { w = prev->get_width(); h = prev->get_height(); } if(studio::App::navigator_uses_cairo) { w=cairo_image_surface_get_width(cairo_surface); h=cairo_image_surface_get_height(cairo_surface); } //scale up/down to the nearest pixel ratio... //and center in center float offx=0, offy=0; float sx, sy; int nw,nh; sx = drawto.get_width() / (float)w; sy = drawto.get_height() / (float)h; //round to smallest scale (fit entire thing in window without distortion) if(sx > sy) sx = sy; //else sy = sx; //scaling and stuff // the point to navpixel space conversion should be: // (navpixels / canvpixels) * (canvpixels / canvsize) // or (navpixels / prevpixels) * (prevpixels / navpixels) xaxis = sx * w / (float)canvw; yaxis = xaxis/ph; xaxis /= pw; //scale to a new pixmap and then copy over to the window nw = (int)(w*sx); nh = (int)(h*sx); //must now center to be cool offx = (drawto.get_width() - nw)/2; offy = (drawto.get_height() - nh)/2; //trivial escape if(nw == 0 || nh == 0)return true; //draw to drawing area if(prev && !studio::App::navigator_uses_cairo) { Glib::RefPtr<Gdk::Pixbuf> scalepx = prev->scale_simple(nw,nh,Gdk::INTERP_NEAREST); cr->save(); //synfig::warning("Nav: Drawing scaled bitmap"); Gdk::Cairo::set_source_pixbuf( cr, //cairo context scalepx, //pixbuf (int)offx, (int)offy //coordinates to place upper left corner of pixbuf ); cr->paint(); cr->restore(); } if(studio::App::navigator_uses_cairo) { cr->save(); cr->scale(sx, sx); cairo_set_source_surface(cr->cobj(), cairo_surface, offx/sx, offy/sx); cairo_pattern_set_filter(cairo_get_source(cr->cobj()), CAIRO_FILTER_NEAREST); cr->paint(); cr->restore(); } cr->save(); //draw fancy red rectangle around focus point const Point &wtl = get_canvas_view()->work_area->get_window_tl(), &wbr = get_canvas_view()->work_area->get_window_br(); //it must be clamped to the drawing area though int l=0,rw=0,t=0,rh=0; const Point fp = -get_canvas_view()->work_area->get_focus_point(); //get focus point in normal space rw = (int)(abs((wtl[0]-wbr[0])*xaxis)); rh = (int)(abs((wtl[1]-wbr[1])*yaxis)); //transform into pixel space l = (int)(drawto.get_width()/2 + fp[0]*xaxis - rw/2); t = (int)(drawto.get_height()/2 + fp[1]*yaxis - rh/2); //coord system: // tl : (offx,offy) // axis multipliers = xaxis,yaxis cr->set_line_width(2.0); cr->set_line_cap(Cairo::LINE_CAP_BUTT); cr->set_line_join(Cairo::LINE_JOIN_MITER); cr->set_antialias(Cairo::ANTIALIAS_NONE); // Visually distinguish when using Cairo on Navigator or not. if(!studio::App::navigator_uses_cairo) cr->set_source_rgb(1,0,0); else cr->set_source_rgb(0,1,0); cr->rectangle(l,t,rw,rh); cr->stroke(); cr->restore(); } return false; //draw everything else too }
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 Widget_Curves::on_draw(const Cairo::RefPtr<Cairo::Context> &cr) { const int h(get_height()); const int w(get_width()); get_style_context()->render_background(cr, 0, 0, w, h); if(!time_adjustment_ || !range_adjustment_ || !h || !w) return false; if(!curve_list_.size()) return false; const Real t_begin(time_adjustment_->get_lower()); const Real t_end(time_adjustment_->get_upper()); const Real dt((t_end-t_begin)/w); const Real r_bottom(range_adjustment_->get_value()); const Real r_top(r_bottom+range_adjustment_->get_page_size()); const Real dr((r_top-r_bottom)/h); Real r_max(-100000000); Real r_min(100000000); std::list<CurveStruct>::iterator curve_iter; //Figure out maximum number of channels for(curve_iter=curve_list_.begin();curve_iter!=curve_list_.end();++curve_iter) { int channels(curve_iter->channels.size()); if(channels>MAX_CHANNELS) { channels=MAX_CHANNELS; synfig::warning("Not allowed more than %d channels! Truncating...", MAX_CHANNELS); } } // and use it when sizing the points vector<Gdk::Point> points[MAX_CHANNELS]; // Draw zero mark cr->set_source_rgb(0.31, 0.31, 0.31); cr->rectangle(0, round_to_int((0-r_bottom)/dr), w, 0); cr->stroke(); // This try to find a valid canvas to show the keyframes of those // valuenodes. If not canvas found then no keyframes marks are shown. synfig::Canvas::Handle canvas=0; for(curve_iter=curve_list_.begin();curve_iter!=curve_list_.end();++curve_iter) { canvas=curve_iter->value_desc.get_canvas(); if(canvas) break; } if(canvas) { // Draw vertical lines for the keyframes marks. const synfig::KeyframeList& keyframe_list(canvas->keyframe_list()); synfig::KeyframeList::const_iterator iter; for(iter=keyframe_list.begin();iter!=keyframe_list.end();++iter) { if(!iter->get_time().is_valid()) continue; const int x((int)((float)w/(t_end-t_begin)*(iter->get_time()-t_begin))); if(iter->get_time()>=t_begin && iter->get_time()<t_end) { cr->set_source_rgb(0.63, 0.5, 0.5); cr->rectangle(x, 0, 1, h); cr->fill(); } } } // Draw current time cr->set_source_rgb(0, 0, 1); cr->rectangle(round_to_int((time_adjustment_->get_value()-t_begin)/dt), 0, 0, h); cr->stroke(); // Draw curves for the valuenodes stored in the curve list for(curve_iter=curve_list_.begin();curve_iter!=curve_list_.end();++curve_iter) { Real t; int i; int channels(curve_iter->channels.size()); for(i=0;i<channels;i++) points[i].clear(); for(i=0,t=t_begin;i<w;i++,t+=dt) { for(int chan=0;chan<channels;chan++) { Real x(curve_iter->get_value(chan,t,dt)); r_max=max(r_max,x); r_min=min(r_min,x); points[chan].push_back( Gdk::Point( i, round_to_int( ( x-r_bottom )/dr ) ) ); } } // Draw the graph curves with 0.5 width cr->set_line_width(0.5); for(int chan=0;chan<channels;chan++) { // Draw the curve std::vector<Gdk::Point> &p = points[chan]; for(std::vector<Gdk::Point>::iterator i = p.begin(); i != p.end(); ++i) { if (i == p.begin()) cr->move_to(i->get_x(), i->get_y()); else cr->line_to(i->get_x(), i->get_y()); } const Gdk::Color &color = curve_iter->channels[chan].color; cr->set_source_rgb(color.get_red_p(), color.get_green_p(), color.get_blue_p()); cr->stroke(); Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context())); layout->set_text(curve_iter->channels[chan].name); cr->move_to(1, points[chan][0].get_y()+1); layout->show_in_cairo_context(cr); } } if(!curve_list_.empty()) { range_adjustment_->set_upper(r_max+range_adjustment_->get_page_size()/2); range_adjustment_->set_lower(r_min-range_adjustment_->get_page_size()/2); } return true; }
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 ); cr->set_line_width(3); if ( active ) setColour(cr, COLOUR_GREY_2 ); else setColour(cr, COLOUR_GREY_3 ); cr->stroke(); //std::cout << "LupppWidget::FrequencyGraph() called!" << std::endl; }
bool TimeLine::on_draw(Cairo::RefPtr<Cairo::Context> const& cr) { if(!m_mainWindow->IsFileOpened()) { return false; } cr->save(); cr->set_antialias(Cairo::ANTIALIAS_NONE); Gtk::Allocation allocation = get_allocation(); cr->set_source_rgb(1.0, 1.0, 1.0); cr->rectangle(0.0, 0.0, allocation.get_width(), allocation.get_height()); cr->fill(); cr->set_line_width(1.0); cr->set_source_rgb(0.0, 0.0, 0.0); cr->move_to(0.0, 1.0); cr->line_to(allocation.get_width(), 1.0); cr->stroke(); cr->move_to(0.0, allocation.get_height() - 1); cr->line_to(allocation.get_width(), allocation.get_height()); cr->stroke(); double floorStart = (floor(m_timeStart) - m_timeStart) * m_mainWindow->GetTimeScale(); int numTicks = ceil(allocation.get_width() / m_mainWindow->GetTimeScale()); for(int i = 0; i <= numTicks; ++i) { double x = floorStart + i * m_mainWindow->GetTimeScale(); if(m_timeStart != 0.0 || i != 0) { // Get the text dimensions. int textWidth; int textHeight; char timeStr[10]; sprintf(timeStr, "%d s", int(floor(m_timeStart) + i)); m_layout->set_text(timeStr); m_layout->get_pixel_size(textWidth, textHeight); // Position the text in the middle cr->move_to(x - textWidth / 2, 0.0); m_layout->show_in_cairo_context(cr); // Draw tick. cr->move_to(x, allocation.get_height() - 8.0); cr->line_to(x, allocation.get_height()); cr->stroke(); } if(i < numTicks) { // Draw sub-tick. double nextX = floorStart + (i + 1) * m_mainWindow->GetTimeScale(); double tickWidth = nextX - x; if(tickWidth > 200.0) { // Get the text dimensions. int textWidth; int textHeight; char timeStr[10]; sprintf(timeStr, "%d.5 s", int(floor(m_timeStart) + i)); m_layout->set_text(timeStr); m_layout->get_pixel_size(textWidth, textHeight); // Position the text in the middle cr->move_to(x + (tickWidth - textWidth) / 2, 0.0); m_layout->show_in_cairo_context(cr); } cr->move_to(x + tickWidth / 2, allocation.get_height() - 4.0); cr->line_to(x + tickWidth / 2, allocation.get_height()); cr->stroke(); } } cr->restore(); return true; }
void ImageDrawable::drawImage(const Cairo::RefPtr<Cairo::Context> &cr, const Gtk::Allocation &allocation) { auto image = images->current(); auto surface = image->getPrimary(); int rwidth, rheight; double rscale; double rx, ry; //cout << "image " << iwidth << "x" << iheight << " " << iorientation.first << "," << iorientation.second << endl; calcRenderedImage(image, allocation, rwidth, rheight, rscale, rx, ry); cr->translate(rx, ry); cr->scale(rscale, rscale); waiting = !surface; if (image->isPrimaryFailed()) { // TODO display fancy failed indicator cr->set_source_rgb(0.75, 0.5, 0.5); cr->rectangle(0, 0, rwidth, rheight); cr->clip(); cr->paint(); return; } else if (!surface) { // TODO display fancy loading animation cr->set_source_rgb(0.5, 0.75, 0.5); cr->rectangle(0, 0, rwidth, rheight); cr->clip(); cr->paint(); return; } switch (image->getOrientation().first) { case Image::Rotate::ROTATE_NONE: break; case Image::Rotate::ROTATE_90: cr->translate(image->height(), 0); cr->rotate_degrees(90); break; case Image::Rotate::ROTATE_180: cr->translate(image->width(), image->height()); cr->rotate_degrees(180); break; case Image::Rotate::ROTATE_270: cr->translate(0, image->width()); cr->rotate_degrees(270); break; } if (image->getOrientation().second) { cr->translate(image->width(), 0); cr->scale(-1, 1); } auto pattern = Cairo::SurfacePattern::create(surface); pattern->set_filter(Cairo::Filter::FILTER_FAST); cr->set_source(pattern); //auto start = chrono::steady_clock::now(); cr->paint(); //auto stop = chrono::steady_clock::now(); //cout << "paint " << chrono::duration_cast<chrono::milliseconds>(stop - start).count() << "ms" << endl; if (afPoints) { //start = chrono::steady_clock::now(); auto properties = image->getProperties(); valarray<double> dashes(5.0 / rscale, 5.0 / rscale); cr->save(); cr->set_operator(static_cast<Cairo::Operator>(CAIRO_OPERATOR_DIFFERENCE)); for (auto &rect : properties.focusPoints) { if (properties.focusPointsActive.find(rect) != properties.focusPointsActive.cend()) { cr->set_source_rgb(1, 0, 1); cr->set_line_width(4.0 / rscale); cr->unset_dash(); } else if (properties.focusPointsSelected.find(rect) != properties.focusPointsSelected.cend()) { cr->set_source_rgb(1, 0, 0); cr->set_line_width(2.0 / rscale); cr->unset_dash(); } else { cr->set_source_rgb(1, 1, 1); cr->set_line_width(1.0 / rscale); cr->set_dash(dashes, 0); } cr->rectangle(rect.x, rect.y, rect.width, rect.height); cr->stroke(); } cr->restore(); //stop = chrono::steady_clock::now(); //cout << "afpaint " << chrono::duration_cast<chrono::milliseconds>(stop - start).count() << "ms" << endl; } }
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(); } }
void VistaUnionEntidadRelacion::dibujar(Cairo::RefPtr<Cairo::Context> cr) { // Dibujo el cuadrado en el contexto // Ancho de linea arbitrario 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, x2, x3, y0, y1, y2, y3; this->entidad->getposini(x0, y0); this->entidad->getposfin(x1, y1); this->relacion->getposini(x2, y2); this->relacion->getposfin(x3, y3); this->actualizar_coordenadas(); // TODO VER SI LO PONGO EN ENTIDAD //if (!this->entidad->esDebil()) { this->entidad->obtenerInterseccionConLinea(this->pos_ini_x, this->pos_ini_y, this->pos_fin_x, this->pos_fin_y, this->pos_ini_x, this->pos_ini_y); this->relacion->obtenerInterseccionConLinea(this->pos_ini_x, this->pos_ini_y, this->pos_fin_x, this->pos_fin_y, this->pos_fin_x, this->pos_fin_y); cr->move_to(this->pos_ini_x, this->pos_ini_y); cr->line_to(this->pos_fin_x, this->pos_fin_y); cr->stroke(); /*} else { Geometria::obtenerLineasParalelas(this->pos_ini_x, this->pos_ini_y, this->pos_fin_x, this->pos_fin_y, 1.6, x0, y0, x1, y1, x2, y2, x3, y3); this->entidad->obtenerInterseccionConLinea(x0, y0, x1, y1, x0, y0); this->relacion->obtenerInterseccionConLinea(x0, y0, x1, y1, x1, y1); this->entidad->obtenerInterseccionConLinea(x2, y2, x3, y3, x2, y2); this->relacion->obtenerInterseccionConLinea(x2, y2, x3, y3, x3, y3); cr->move_to(x0, y0); cr->line_to(x1, y1); cr->stroke(); cr->move_to(x2, y2); cr->line_to(x3, y3); cr->stroke(); }*/ if (this->dibujar_cardinalidad) { Cairo::TextExtents textExtents; std::string texto; texto = "("; texto.append(this->unionModelo->getCardinalidadMinima()); texto.append(";"); texto.append(this->unionModelo->getCardinalidadMaxima()); texto.append(")"); if (this->unionModelo->getRol() != "") { texto.append(":"); texto.append(this->unionModelo->getRol()); } cr->get_text_extents(texto, textExtents); double x_texto, y_texto; Geometria::obtenerPuntoDeDibujoDeTextoCentradoEnLinea(this->pos_ini_x, this->pos_ini_y, this->pos_fin_x, this->pos_fin_y, textExtents.width, textExtents.height, x_texto, y_texto); cr->move_to(x_texto, y_texto); cr->show_text(texto); cr->stroke(); } }
void set_line_width__(Glib::ustring& d1){ cr_->set_line_width(s2f__(d1)); }
static void draw_text (Cairo::RefPtr<Cairo::Context> cr, int wdh, int hgt) { RefPtr<Pango::Layout> layout = Pango::Layout::create(cr); //layout->set_single_paragraph_mode(true); layout->set_text("MTextTextM\nAbc\nff"); Pango::FontDescription dsc(FONT); layout->set_font_description(dsc); int t_wdh, t_hgt; layout->get_size(t_wdh, t_hgt); double t_sz = (double)dsc.get_size()/t_wdh; double new_sz = wdh * t_sz ; io::cout << "new_sz " << new_sz << io::endl; io::cout << "wdh " << wdh << io::endl; dsc.set_size( int(new_sz*PANGO_SCALE) ); layout->set_font_description(dsc); layout->get_size(t_wdh, t_hgt); io::cout << "t_wdh " << t_wdh/(double)PANGO_SCALE << io::endl; // для наглядности cr->set_line_width(1.0); cr->rectangle(0, 0, wdh, hgt); cr->stroke(); cr->save(); cr->move_to(0, 0); cr->scale( 1.0, hgt / ((double)t_hgt/PANGO_SCALE) ); //cr->scale( wdh / ((double)t_wdh/PANGO_SCALE), hgt / ((double)t_hgt/PANGO_SCALE) ); layout->update_from_cairo_context(cr); pango_cairo_show_layout(cr->cobj(), layout->gobj()); { Pango::Rectangle w_rct, s_rct; int cur_pos; cur_pos = 1; layout->get_cursor_pos(cur_pos, w_rct, s_rct); pango_extents_to_pixels(0, w_rct.gobj()); io::cout << "curs - x, y, hgt " << w_rct.get_x() << " " << w_rct.get_y() << " " << w_rct.get_height() << io::endl; cr->move_to(w_rct.get_x()+5, w_rct.get_y()); cr->line_to(w_rct.get_x()+5, w_rct.get_y()+w_rct.get_height()); cr->stroke(); cur_pos = 11; layout->get_cursor_pos(cur_pos, w_rct, s_rct); pango_extents_to_pixels(0, w_rct.gobj()); io::cout << "curs - x, y, hgt " << w_rct.get_x() << " " << w_rct.get_y() << " " << w_rct.get_height() << io::endl; cr->move_to(w_rct.get_x()+5, w_rct.get_y()); cr->line_to(w_rct.get_x()+5, w_rct.get_y()+w_rct.get_height()); cr->stroke(); } cr->restore(); }
int render_png(Graph* graph) { int i_side = (graph->side_length - 1) * SPACING + PADDING; //Cairo ImageSurface. This one will be saved afterwards as a png file Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, i_side + PADDING * 2, i_side + PADDING * 2); //Cairo Context. Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface); cr->save(); // save the state of the context cr->set_source_rgb(1.0, 1.0, 1.0); cr->paint(); // fill image with the color cr->restore(); // color is back to black now //Storing state to start drawing cr->save(); //setting brush color to black cr->set_source_rgb(0.0, 0.0, 0.0); cr->set_line_width(1.0); //drawing lines for (int i = 0; i < graph->side_length; i++) { for (int j = 0; j < graph->side_length; j++) { //for a current node Node* current = graph->matrix.at(i).at(j); //find all friends for (int k = 0; k < current->friends.size(); k++) { pair<int, int> current_friend = *std::next(current->friends.begin(), k); //Move brush to current node cr->move_to(current->coors.first * SPACING + PADDING, current->coors.second * SPACING + PADDING); //Draw a line to current friend cr->line_to(current_friend.first * SPACING + PADDING, current_friend.second * SPACING + PADDING); cr->stroke(); } } } //setting brush color to red cr->set_source_rgb(1.0, 0.0, 0.0); //drawing vertices after lines are drawn for (int i = 0; i < graph->side_length; i++) { for (int j = 0; j < graph->side_length; j++) { Node* current = graph->matrix.at(i).at(j); cr->arc(current->coors.first * SPACING + PADDING, current->coors.second * SPACING + PADDING, 1.0, 0.0, 2.0 * M_PI); cr->stroke(); } } cr->restore(); #ifdef CAIRO_HAS_PNG_FUNCTIONS std::string filename = build_name("result"); 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 }
void NodeSurface::DrawPorts( Cairo::RefPtr<Cairo::Context> refCairo, TopologyNode* pNode ) { refCairo->save(); const float k_divisor = 255.0; float red = 38 / k_divisor; float green = 199 / k_divisor; float blue = 38 / k_divisor; refCairo->set_source_rgb( red, green, blue ); refCairo->set_source_rgb( 0, 0, 0 ); refCairo->set_line_width( 5 ); int numChildren = 0; for ( unsigned int i=0; i < pNode->GetNumPorts(); i++ ) { if ( pNode->GetPortType(i) == TopologyNode::CONNECTED_TO_CHILD ) { numChildren++; } } int childIndex = 0; for ( unsigned int i=0; i < pNode->GetNumPorts(); i++ ) { TopologyNode::PortType currPort = pNode->GetPortType(i); switch (currPort) { case TopologyNode::NOT_CONNECTED: break; case TopologyNode::CONNECTED_TO_PARENT: { refCairo->move_to( sk_nodeWidth/2 - sk_portWidth/2, 0 ); refCairo->rel_line_to( sk_portWidth, 0 ); refCairo->rel_line_to( 0, sk_portHeight ); refCairo->rel_line_to( -sk_portWidth, 0 ); refCairo->fill(); } break; case TopologyNode::CONNECTED_TO_CHILD: { int startX = (sk_nodeWidth / (numChildren+1)) * (childIndex+1); refCairo->move_to( startX - sk_portWidth/2, sk_nodeHeight ); refCairo->rel_line_to( sk_portWidth, 0 ); refCairo->rel_line_to( 0, -sk_portHeight ); refCairo->rel_line_to( -sk_portWidth, 0 ); refCairo->fill(); childIndex++; } break; default: break; } } refCairo->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); } }*/ }
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; } }
bool graphView::on_draw(const Cairo::RefPtr<Cairo::Context>& cr){ //Get the allocation of our widget, and get the height and width from it Gtk::Allocation wAllocation = this->get_allocation(); const int wHeight = wAllocation.get_height(); const int wWidth = wAllocation.get_width(); const double lineWidth = wHeight; //scale the Cario context obj to the current wHeight and wWidth //cr->scale(wWidth, wHeight); //now change the offset point coordinates, so point (0,0) will be at (0.5,0.5) cr->translate(wWidth/2, wHeight/2); //set the line width to 2 px, this should be a settings for each graph in the futur cr->set_line_width(1); //paint the background white cr->set_source_rgb(1,1,1); cr->paint(); //draw the coordinatesystem cr->set_source_rgb(0,0,0); cr->move_to(0,0); cr->line_to(wWidth,0); cr->move_to(0,0); cr->line_to(0,wHeight); cr->move_to(0,0); cr->line_to(-1*wWidth,0); cr->move_to(0,0); cr->line_to(0,-1*wHeight); //draw the axes unit, again this should't be hardcoded in the futur cr->move_to(0,0); for(int i = 1; i <= 25; i++) { cr->move_to((wWidth*0.5/25)*i,0); cr->rel_move_to(0, -8); cr->rel_line_to(0,16); cr->rel_move_to(0, -8); cr->move_to((wWidth*0.5/25)*-i,0); cr->rel_move_to(0, -8); cr->rel_line_to(0,16); cr->rel_move_to(0, -8); } cr->move_to(0, 0); for(int i = 1; i <= 25; i++) { cr->move_to(0,(wHeight*0.5/25)*i); cr->rel_move_to(-8,0); cr->rel_line_to(16,0); cr->rel_move_to(-8,0); cr->move_to(0,(wHeight*0.5/25)*-i); cr->rel_move_to(-8,0); cr->rel_line_to(16,0); cr->rel_move_to(-8,0); } cr->stroke(); cr->set_source_rgb(0.8,0,0); if(this->tree) { cr->set_line_width(3); std::vector<equation*> eqs = this->tree->getEquations(); double pxWidth = wWidth/50; double pxHeight = wHeight/50; for(int i = 0; i < eqs.size(); i++){ equation *eq = eqs[i]; for(double x = -25; x<= 25; x+= 0.01) { double y = eq->getYFromX(x); cr->move_to(x*pxWidth,-1*(y*pxHeight)); cr->rel_line_to(1,1); } cr->stroke(); } } return true; }
Cairo::RefPtr<Cairo::ImageSurface> TextSurface::create_cairo_surface(const std::string& text, const TextProperties& text_props, Cairo::TextExtents& out_text_extents, Cairo::FontExtents& out_font_extents) { { // get TextExtents and FontExtents Cairo::RefPtr<Cairo::ImageSurface> tmp_surface = Cairo::ImageSurface::create(Cairo::FORMAT_RGB24, 0, 0); Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(tmp_surface); cr->set_font_size(text_props.get_font_size()); cr->select_font_face(text_props.get_font(), Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL); cr->get_text_extents(text, out_text_extents); cr->get_font_extents(out_font_extents); } Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, static_cast<int>(out_text_extents.width + text_props.get_line_width()), static_cast<int>(out_text_extents.height + text_props.get_line_width())); Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface); // set the font cr->set_font_size(text_props.get_font_size()); cr->select_font_face(text_props.get_font(), Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL); if (text_props.get_line_width() != 0) { // create path cr->move_to(-out_text_extents.x_bearing + text_props.get_line_width()/2.0, -out_text_extents.y_bearing + text_props.get_line_width()/2.0); cr->text_path(text); // paint cr->set_line_width(text_props.get_line_width()); cr->set_line_join(Cairo::LINE_JOIN_ROUND); cr->set_source_rgb(0.0, 0.0, 0.0); cr->stroke(); } // print text cr->move_to(-out_text_extents.x_bearing + text_props.get_line_width()/2.0, -out_text_extents.y_bearing + text_props.get_line_width()/2.0); cr->set_source_rgb(1.0, 1.0, 0.0); double y = -out_text_extents.y_bearing - out_font_extents.ascent; // toying around with color gradients if (false) { Cairo::RefPtr<Cairo::LinearGradient> gradient = Cairo::LinearGradient::create(0, y, 0, y + out_font_extents.ascent + out_font_extents.descent); gradient->add_color_stop_rgb(0.0, 1.0, 1.0, 0.0); gradient->add_color_stop_rgb(0.5, 1.0, 1.0, 1.0); gradient->add_color_stop_rgb(0.5, 0.4, 0.4, 0.2); gradient->add_color_stop_rgb(1.0, 1.0, 1.0, 0.0); cr->set_source(gradient); } cr->show_text(text); return surface; }
virtual bool on_expose_event(GdkEventExpose* ) { Glib::RefPtr<Gdk::Drawable> drawable = get_window(); vc.get_frame(pixbuf); drawable->draw_pixbuf(get_style()->get_bg_gc(Gtk::STATE_NORMAL), pixbuf, 0, 0, 0, 0, -1 , -1, Gdk::RGB_DITHER_NONE, 0, 0); Gdk::Point rect[4], barcode_center; string str; bool res = decode_barcode(pixbuf, rect, str, 500); if (res) { Cairo::RefPtr<Cairo::Context> cr = drawable->create_cairo_context(); cr->set_line_width(3); cr->set_source_rgb(1, 0.0, 0.0); cr->move_to(rect[0].get_x(), rect[0].get_y()); cr->line_to(rect[1].get_x(), rect[1].get_y()); cr->line_to(rect[2].get_x(), rect[2].get_y()); cr->line_to(rect[3].get_x(), rect[3].get_y()); cr->line_to(rect[0].get_x(), rect[0].get_y()); cr->stroke(); DataMtxPlace distance(get_width(), get_height(), rect[0].get_x(), rect[0].get_y(), rect[1].get_x(), rect[1].get_y(), rect[2].get_x(), rect[2].get_y(), rect[3].get_x(), rect[3].get_y()); cout << "Distance: " << distance.calcDistance() << "\tSquare: " << distance.calcSquare() << "\tDirection: " << distance.calcDirection() << endl; Glib::RefPtr<Pango::Layout> pango_layout = Pango::Layout::create(cr); Pango::FontDescription desc("Arial Rounded MT Bold"); desc.set_size(14 * PANGO_SCALE); pango_layout->set_font_description(desc); pango_layout->set_alignment(Pango::ALIGN_CENTER); string text = "Msg: " + str + "\nDist: " + lexical_cast<string>(distance.calcDistance()) + "\nDir: " + lexical_cast<string>(distance.calcDirection()); pango_layout->set_text(text); Gdk::Point* max_x, *min_x, *max_y, *min_y; boost::function<bool (Gdk::Point, Gdk::Point)> compare; compare = bind(less<int>(), bind(&Gdk::Point::get_x, _1), bind(&Gdk::Point::get_x, _2)); max_x = max_element(rect, rect + 4, compare); min_x = min_element(rect, rect + 4, compare); compare = bind(less<int>(), bind(&Gdk::Point::get_y, _1), bind(&Gdk::Point::get_y, _2)); max_y = max_element(rect, rect + 4, compare); min_y = min_element(rect, rect + 4, compare); barcode_center = Gdk::Point( (max_x->get_x() + min_x->get_x()) / 2, (max_y->get_y() + min_y->get_y()) / 2); const Pango::Rectangle extent = pango_layout->get_pixel_logical_extents(); cr->move_to(barcode_center.get_x() - extent.get_width() / 2, barcode_center.get_y() - extent.get_height() / 2); pango_layout->show_in_cairo_context(cr); // cr->set_source_rgba(0, 0, 0, 0.6); // // int i = 0; // if (center_barcode.get_x() < get_width() / 3) // i = 0; // else if (center_barcode.get_x() > (2 * get_width() / 3)) // i = 2; // else // i = 1; // // cr->rectangle(i * get_width() / 3, 0, i * get_width() / 3 + get_width() / 3, get_height()); // cr->fill_preserve(); } // cr->set_source_rgba(0, 0, 0, 0.6); // cr->move_to(get_width() / 3, 0); // cr->line_to(get_width() / 3, get_height()); // cr->move_to(2 * get_width() / 3, 0); // cr->line_to(2 * get_width() / 3, get_height()); // cr->stroke(); 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; }
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(); }
bool studio::Widget_NavView::on_expose_draw(GdkEventExpose */*exp*/) { #ifdef SINGLE_THREADED // don't redraw if the previous redraw is still running single-threaded // or we end up destroying the renderer that's rendering it if (App::single_threaded && renderer && renderer->updating) return false; #endif //print out the zoom //HACK kind of... //zoom_print.set_text(strprintf("%.1f%%",100*unit_to_zoom(adj_zoom.get_value()))); //draw the good stuff on_start_render(); //if we've got a preview etc. display it... if(get_canvas_view() && prev) { //axis transform from units to pixel coords float xaxis = 0, yaxis = 0; int canvw = get_canvas_view()->get_canvas()->rend_desc().get_w(); //int canvh = get_canvas_view()->get_canvas()->rend_desc().get_h(); float pw = get_canvas_view()->get_canvas()->rend_desc().get_pw(); float ph = get_canvas_view()->get_canvas()->rend_desc().get_ph(); int w = prev->get_width(); int h = prev->get_height(); //scale up/down to the nearest pixel ratio... //and center in center int offx=0, offy=0; float sx, sy; int nw,nh; sx = drawto.get_width() / (float)w; sy = drawto.get_height() / (float)h; //synfig::warning("Nav redraw: now to scale the bitmap: %.3f x %.3f",sx,sy); //round to smallest scale (fit entire thing in window without distortion) if(sx > sy) sx = sy; //else sy = sx; //scaling and stuff // the point to navpixel space conversion should be: // (navpixels / canvpixels) * (canvpixels / canvsize) // or (navpixels / prevpixels) * (prevpixels / navpixels) xaxis = sx * w / (float)canvw; yaxis = xaxis/ph; xaxis /= pw; //scale to a new pixmap and then copy over to the window nw = (int)(w*sx); nh = (int)(h*sx); //must now center to be cool offx = (drawto.get_width() - nw)/2; offy = (drawto.get_height() - nh)/2; //trivial escape if(nw == 0 || nh == 0)return true; //draw to drawing area Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(drawto.get_window()); Cairo::RefPtr<Cairo::Context> cr = drawto.get_window()->create_cairo_context(); //synfig::warning("Nav: Scaling pixmap to off (%d,%d) with size (%d,%d)", offx,offy,nw, nh); Glib::RefPtr<Gdk::Pixbuf> scalepx = prev->scale_simple(nw,nh,Gdk::INTERP_NEAREST); cr->save(); //synfig::warning("Nav: Drawing scaled bitmap"); Gdk::Cairo::set_source_pixbuf( cr, //cairo context scalepx, //pixbuf offx, offy //coordinates to place upper left corner of pixbuf ); cr->paint(); //draw fancy red rectangle around focus point const Point &wtl = get_canvas_view()->work_area->get_window_tl(), &wbr = get_canvas_view()->work_area->get_window_br(); //it must be clamped to the drawing area though int l=0,rw=0,t=0,rh=0; const Point fp = -get_canvas_view()->work_area->get_focus_point(); //get focus point in normal space rw = (int)(abs((wtl[0]-wbr[0])*xaxis)); rh = (int)(abs((wtl[1]-wbr[1])*yaxis)); //transform into pixel space l = (int)(drawto.get_width()/2 + fp[0]*xaxis - rw/2); t = (int)(drawto.get_height()/2 + fp[1]*yaxis - rh/2); //coord system: // tl : (offx,offy) // axis multipliers = xaxis,yaxis //synfig::warning("Nav: tl (%f,%f), br (%f,%f)", wtl[0],wtl[1],wbr[0],wbr[1]); //synfig::warning("Nav: tl (%f,%f), br (%f,%f)", wtl[0],wtl[1],wbr[0],wbr[1]); //synfig::warning("Nav: Drawing Rectangle (%d,%d) with dim (%d,%d)", l,t,rw,rh); cr->set_line_width(2.0); cr->set_line_cap(Cairo::LINE_CAP_BUTT); cr->set_line_join(Cairo::LINE_JOIN_MITER); cr->set_antialias(Cairo::ANTIALIAS_NONE); cr->set_source_rgb(1,0,0); cr->rectangle(l,t,rw,rh); cr->stroke(); cr->restore(); } return false; //draw everything else too }
/** * Render the Preview * @param Cairo::Context cr * @return Gtk::Window::on_draw(cr) */ bool Preview::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) { Configuration::Theme theme = Configuration::getTheme(); if (theme.forPreview().enabled()) { cr->set_source_rgba( theme.forPreview().background().red, theme.forPreview().background().green, theme.forPreview().background().blue, theme.forPreview().background().alpha); Utilities::RoundedRectangle(cr, 0, 0, this->get_width(), this->get_height(), theme.forPreview().roundedRatious()); cr->fill(); } if (!m_isActive) { return Gtk::Window::on_draw(cr); } if (m_previewtems.size() < 1) { this->hideMe(); return Gtk::Window::on_draw(cr); } int idx = 0; for (DockItem* item : m_previewtems) { if (item->m_window == NULL || item->m_xid == 0 || !item->visible) continue; int pos_x = 20 + (m_previewWidth * idx); int pos_y = 16; int pos_width = m_previewWidth - DEF_PREVIEW_LEFT_MARGING; int pos_height = 20; cr->set_source_rgba( theme.forPreview().foreground().red, theme.forPreview().foreground().green, theme.forPreview().foreground().blue, theme.forPreview().foreground().alpha); cr->set_line_width(theme.forPreview().lineWith()); if (item->m_imageLoadedRequired) cr->set_line_width(theme.forPreview().lineWith() + 0.5); if (theme.getPreviewBinaryValue() == 0) { Utilities::RoundedRectangle(cr, DEF_PREVIEW_LEFT_MARGING + (m_previewWidth * idx), 16, m_previewWidth, m_previewHeight - DEF_PREVIEW_RIGHT_MARGING, theme.forPreview().roundedRatious()); cr->stroke(); } else { cr->set_line_width(theme.forPreview().lineWith()); int pos_x = DEF_PREVIEW_LEFT_MARGING + (m_previewWidth * idx); int y_pos = 16; int width = m_previewWidth; int height = m_previewHeight; int value = theme.getPreviewBinaryValue(); /* Vertical Left*/ int bit = CHECK_BIT(value, 3); if (bit == 1) { cr->set_line_width(theme.forPreview().lineWith()); cr->move_to(pos_x, y_pos); cr->line_to(pos_x, y_pos); cr->line_to(pos_x, y_pos + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING)); cr->stroke(); } /* Top */ bit = CHECK_BIT(value, 2); if (bit == 1) { cr->set_line_width(theme.forPreview().lineWith()); cr->move_to(pos_x, y_pos); cr->line_to(pos_x, y_pos); cr->line_to(pos_x + (m_previewWidth), y_pos); cr->stroke(); } /* Right vertical */ bit = CHECK_BIT(value, 1); if (bit == 1) { cr->set_line_width(theme.forPreview().lineWith()); cr->move_to(pos_x + m_previewWidth, y_pos); cr->line_to(pos_x + m_previewWidth, y_pos); cr->line_to(pos_x + m_previewWidth, y_pos + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING)); cr->stroke(); } bit = CHECK_BIT(value, 0); if (bit == 1) { cr->set_line_width(theme.forPreview().lineWith()); cr->move_to(pos_x, y_pos + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING)); cr->line_to(pos_x, y_pos + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING)); cr->line_to(pos_x + m_previewWidth, y_pos + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING)); cr->stroke(); } } // TEXT // draw title and create clipping rectangle // JG cr->set_source_rgba( theme.forPreviewTitle().background().red, theme.forPreviewTitle().background().green, theme.forPreviewTitle().background().blue, theme.forPreviewTitle().foreground().alpha); cr->rectangle(pos_x, pos_y + 2, pos_width + 2, pos_height); // cr->clip_preserve(); cr->fill(); // JG cr->set_source_rgba( theme.forPreviewTitle().foreground().red, theme.forPreviewTitle().foreground().green, theme.forPreviewTitle().foreground().blue, theme.forPreviewTitle().foreground().alpha); cr->set_line_width(theme.forPreviewTitle().lineWith()); cr->rectangle(pos_x, pos_y + 2, pos_width + 2, pos_height); cr->stroke(); // draw title the clipping rectangle //cr->set_source_rgba(1.0, 1.0, 1.0, 0.0); cr->rectangle(pos_x, pos_y + 2, pos_width, pos_height); cr->clip_preserve(); cr->stroke(); cr->set_source_rgba( theme.forPreviewTitleText().foreground().red, theme.forPreviewTitleText().foreground().green, theme.forPreviewTitleText().foreground().blue, theme.forPreviewTitleText().foreground().alpha); auto layout = create_pango_layout(item->m_titlename); layout->set_font_description(font); //cr->set_source_rgba(1.0, 1.0, 1.0, 1.0); // white text cr->move_to(pos_x, pos_y + 2); layout->show_in_cairo_context(cr); cr->reset_clip(); // Reset the clipping if (item->m_imageLoadedRequired) { GdkPixbuf *scaledpb = getScaledPixbuf(item); if (scaledpb == nullptr) { continue; } // show the loaded image. showPreview(cr, scaledpb, idx); // Checks if the image have movement. if (item->isMovementDetected(scaledpb) && !item->m_isDynamic) { item->m_isDynamic = true; } // if no movement has been detected, means that the image // is static and we don't need to reload it again if (++item->m_frames > 3 && !item->m_isDynamic) { item->m_scaledPixbuf = scaledpb; item->m_frames = 0; item->m_imageLoadedRequired = false; } // if the image is static do not unreference the scaledpb. if (item->m_imageLoadedRequired) g_object_unref(scaledpb); } else { // show the loaded static image. showPreview(cr, item->m_scaledPixbuf, idx); } // selector if (m_currentIndex == idx) { // rectangle background selector pos_x = DEF_PREVIEW_LEFT_MARGING + (m_previewWidth * m_currentIndex); pos_y = 16; pos_width = m_previewWidth + 1; pos_height = m_previewHeight - DEF_PREVIEW_RIGHT_MARGING; if (m_previewtems.size() > 1) { cr->set_source_rgba( theme.forPreviewSelector().background().red, theme.forPreviewSelector().background().green, theme.forPreviewSelector().background().blue, theme.forPreviewSelector().background().alpha); Utilities::RoundedRectangle(cr, pos_x, pos_y, pos_width, pos_height, theme.forPreviewSelector().roundedRatious()); cr->fill(); } cr->set_source_rgba( theme.forPreviewSelector().foreground().red, theme.forPreviewSelector().foreground().green, theme.forPreviewSelector().foreground().blue, theme.forPreviewSelector().foreground().alpha); cr->set_line_width(theme.forPreviewSelector().lineWith()); if (theme.getPreviewSelectorBinaryValue() == 0) { Utilities::RoundedRectangle(cr, pos_x, pos_y, pos_width, pos_height, theme.forPreviewSelector().roundedRatious()); cr->stroke(); } else { int value = theme.getPreviewSelectorBinaryValue(); // /* Vertical Left*/ int bit = CHECK_BIT(value, 3); if (bit == 1) { cr->move_to(pos_x, pos_y); cr->line_to(pos_x, pos_y); cr->line_to(pos_x, pos_y + (pos_height)); cr->stroke(); } /* Top */ bit = CHECK_BIT(value, 2); if (bit == 1) { cr->move_to(pos_x, pos_y); cr->line_to(pos_x, pos_y); cr->line_to(pos_x + (pos_width), pos_y); cr->stroke(); } /* Right vertical */ bit = CHECK_BIT(value, 1); if (bit == 1) { cr->move_to(pos_x + pos_width, pos_y); cr->line_to(pos_x + pos_width, pos_y); cr->line_to(pos_x + pos_width, pos_y + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING)); cr->stroke(); } bit = CHECK_BIT(value, 0); if (bit == 1) { cr->move_to(pos_x, pos_y + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING)); cr->line_to(pos_x, pos_y + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING)); cr->line_to(pos_x + m_previewWidth, pos_y + (m_previewHeight - DEF_PREVIEW_RIGHT_MARGING)); cr->stroke(); } } cr->set_source_rgba( theme.forPreviewSelectorClose().background().red, theme.forPreviewSelectorClose().background().green, theme.forPreviewSelectorClose().background().blue, theme.forPreviewSelectorClose().background().alpha); pos_x = (m_previewWidth - 5) + (m_previewWidth * m_currentIndex); cr->move_to(pos_x + 3, DEF_PREVIEW_RIGHT_MARGING); cr->rectangle(pos_x, 18, DEF_PREVIEW_LEFT_MARGING, DEF_PREVIEW_LEFT_MARGING + 2); cr->fill(); cr->set_source_rgba( theme.forPreviewSelectorClose().foreground().red, theme.forPreviewSelectorClose().foreground().green, theme.forPreviewSelectorClose().foreground().blue, theme.forPreviewSelectorClose().foreground().alpha); cr->set_line_width(theme.forPreviewSelectorClose().lineWith()); // Close X text cr->move_to(pos_x + 3, DEF_PREVIEW_RIGHT_MARGING - 1); cr->show_text("X"); } idx++; } return Gtk::Window::on_draw(cr); }
/** * Does something when the speed graph is drawn. */ bool GtkGraph::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) { cr->set_line_width(1.0); const double width = (double)get_allocation().get_width(); const double height = (double)get_allocation().get_height(); std::vector <double> dash = { 5 }; Gdk::Cairo::set_source_rgba(cr, get_style_context()->get_background_color()); double increment = (width - m_labelLength) / (m_displaySize-1); std::queue<double> download = lastElements(m_history[m_selected].first, m_displaySize); std::queue<double> upload = lastElements(m_history[m_selected].second, m_displaySize); unsigned order; if(max(download, upload) <= 10 * 1024) order = 1; else if(max(download, upload) <= 100 * 1024) order = 10; else if(max(download, upload) <= 1000 * 1024) order = 100; else order = 1000; int maxValue = max(download, upload) + (order * 1024) - (double)((int)(max(m_history[m_selected].first, m_history[m_selected].second)) % (order * 1024)); // draw curves //Gdk::Cairo::set_source_rgba(cr, get_style_context()->get_color()); Gdk::Cairo::set_source_rgba(cr, Gdk::RGBA(gt::Settings::settings["GraphUploadCurveColor"])); std::string label; if(gt::Settings::settings["ShowLegend"] != "No") { label = "Upload"; cr->move_to(10, (height-m_labelHeight) / 2 - 15); cr->text_path(label); cr->fill(); } upl = true; if(gt::Settings::settings["GraphUploadCurveStyle"] == "Dash") cr->set_dash(dash, 0); draw(download, (height-m_labelHeight), increment, maxValue, cr); cr->unset_dash(); upl = false; Gdk::Cairo::set_source_rgba(cr, Gdk::RGBA(gt::Settings::settings["GraphDownloadCurveColor"])); if(gt::Settings::settings["ShowLegend"] != "No") { label = "Download"; cr->move_to(10, (height-m_labelHeight) / 2 - 30); cr->text_path(label); cr->fill(); cr->stroke(); } if(gt::Settings::settings["GraphDownloadCurveStyle"] == "Dash") cr->set_dash(dash, 0); draw(upload, (height-m_labelHeight), increment, maxValue, cr); cr->unset_dash(); // draw grid Gdk::Cairo::set_source_rgba(cr, Gdk::RGBA(gt::Settings::settings["GraphBorderColor"])); for(unsigned i = 0, val = 0;i<6;++i) { Gdk::Cairo::set_source_rgba(cr, Gdk::RGBA(gt::Settings::settings["GraphBorderColor"])); cr->move_to(i * ((width-m_labelLength)/5), height); std::string label = timestr(val); cr->text_path(label); cr->fill(); val += m_displaySize/5; Gdk::Cairo::set_source_rgba(cr, Gdk::RGBA(gt::Settings::settings["GraphHLineColor"])); cr->move_to(i * ((width-m_labelLength)/5), (height-m_labelHeight)+2); cr->line_to(i * ((width-m_labelLength)/5), gt::Settings::settings["ShowGrid"] == "Yes" ? 0 : (height-m_labelHeight)); cr->stroke(); cr->set_line_width(1.0); } cr->stroke(); cr->move_to(0, (height-m_labelHeight)); cr->line_to(width, (height-m_labelHeight)); cr->move_to(0, (height-m_labelHeight)); cr->line_to(0, 0); cr->move_to(width - m_labelLength, 0); cr->line_to(width - m_labelLength, (height-m_labelHeight)); cr->stroke(); int lValue = maxValue + 5 - (maxValue % 5); for(int i = 1; i <= 6; ++i) { Gdk::Cairo::set_source_rgba(cr, Gdk::RGBA(gt::Settings::settings["GraphBorderColor"])); std::string label = speedstr(lValue - ((lValue / 5) * (i - 1))); cr->move_to(width - m_labelLength +2, 10 + (((height-m_labelHeight -10) / 5) * (i - 1))); cr->text_path(label); cr->fill(); Gdk::Cairo::set_source_rgba(cr, Gdk::RGBA(gt::Settings::settings["GraphHLineColor"])); cr->set_line_width(0.6); cr->move_to(width - m_labelLength +2, 13 + (((height-m_labelHeight-13) / 5) * (i - 1))); cr->line_to(gt::Settings::settings["ShowGrid"] == "Yes" ? 0 : width - m_labelLength, 13 + (((height-m_labelHeight-13) / 5) * (i - 1))); cr->stroke(); cr->set_line_width(1.0); } Gdk::Cairo::set_source_rgba(cr, Gdk::RGBA(gt::Settings::settings["GraphBorderColor"])); cr->move_to(width - 37, (height-m_labelHeight) - 5); cr->text_path("0B/s"); cr->fill(); return true; }
bool CPagePreview::on_expose_event(GdkEventExpose *event) { Glib::RefPtr<Gdk::Window> window = get_window(); if(window) { // get the cairo context amd allocation Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context(); Gtk::Allocation allocation = get_allocation(); const int width = allocation.get_width(); const int height = allocation.get_height(); // coordinates for the center of the window int xc, yc; xc = width / 2; yc = height / 2; // 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(); // draw a neat shadow cr->set_source_rgba(0.0,0.0,0.0,0.4); cr->begin_new_path(); cr->move_to( xborder+offset,yborder+offset ); cr->line_to( width-xborder+offset,yborder+offset ); cr->line_to( width-xborder+offset,height-yborder+offset ); cr->line_to( xborder+offset,height-yborder+offset ); cr->close_path(); cr->fill(); // draw the page outline cr->set_source_rgb(0.0,0.0,0.0); // black cr->set_line_width( 2.0 ); cr->begin_new_path(); cr->move_to( xborder-offset,yborder-offset ); cr->line_to( width-xborder-offset,yborder-offset ); cr->line_to( width-xborder-offset,height-yborder-offset ); cr->line_to( xborder-offset,height-yborder-offset ); cr->close_path(); cr->stroke_preserve(); // fill the page with white cr->save(); cr->set_source_rgb(1.0,1.0,1.0); // white cr->fill_preserve(); cr->restore(); // draw the page margin cr->set_source_rgb( 0.8,0.8,0.8 ); // light grey cr->set_line_width( 1.0 ); cr->begin_new_path(); cr->move_to( uleft.x, uleft.y ); cr->line_to( lright.x, uleft.y ); cr->line_to( lright.x, lright.y ); cr->line_to( uleft.x, lright.y ); cr->close_path(); cr->stroke(); // and the image preview ImagePixbuf->render_to_drawable( get_window(), get_style()->get_black_gc(), 0, 0, xpos, ypos, ImagePixbuf->get_width(), //image->get_width(), ImagePixbuf->get_height(), //image->get_height(), Gdk::RGB_DITHER_NONE,0,0 ); // */ return true; } }
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(); }
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 ) xSize2CP2 = 75; if ( xSize2End > 75 ) xSize2End = 75; cr->curve_to( xSize2CP1, y+(ySize*0.3), // control point 1 xSize2CP2, y+(ySize*0.3), // control point 2 xSize2End, y+(ySize) ); // end of curve on floor if (active) setColour(cr, COLOUR_BLUE_1, 0.2 ); else setColour(cr, COLOUR_GREY_1, 0.2 ); cr->close_path(); cr->fill_preserve(); // stroke cutoff line cr->set_line_width(2.5); if ( active ) setColour(cr, COLOUR_BLUE_1 ); else setColour(cr, COLOUR_GREY_1 ); cr->stroke(); // click center if ( globalUnit ) { if ( active ) setColour(cr, COLOUR_GREEN_1, 0.9 ); else setColour(cr, COLOUR_GREY_1,0.9 ); cr->move_to( xSize * cutoff - 5, ySize*q - 5 ); cr->line_to( xSize * cutoff + 5, ySize*q + 5 ); cr->move_to( xSize * cutoff - 5, ySize*q + 5 ); cr->line_to( xSize * cutoff + 5, ySize*q - 5 ); cr->stroke(); } else { if ( active ) setColour(cr, COLOUR_ORANGE_1, 0.9 ); else setColour(cr, COLOUR_GREY_1, 0.9 ); cr->arc( xSize*cutoff, ySize*q, 7, 0, 6.2830 ); cr->stroke(); } // dials Dial(cr, active, 70, 140, cutoffRangeZeroOne, DIAL_MODE_NORMAL); Dial(cr, active, 150,140, q , DIAL_MODE_NORMAL); // outline setColour(cr, COLOUR_GREY_3 ); cr->rectangle( x, y , xSize, ySize ); cr->set_line_width(3); setColour(cr, COLOUR_GREY_2 ); cr->stroke(); /* if ( state.selected ) { cr->rectangle(0, 0, 74, 216); setColour( cr, COLOUR_PURPLE_1 ); cr->set_line_width(1); cr->stroke(); } */ } return true; }