示例#1
0
文件: main.cpp 项目: vagran/adk
        /** Drawing event handler. */
        virtual bool
        on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
        {
            switch (_curShape) {
            case SHAPE_RECTANGLE:
                cr->rectangle(20, 20, 200, 100);
                cr->set_source_rgb(0, 0.8, 0);
                cr->fill_preserve();
                break;
            case SHAPE_ELLIPSE:
                cr->arc(150, 100, 90, 0, 2 * 3.14);
                cr->set_source_rgb(0.8, 0, 0);
                cr->fill_preserve();
                break;
            case SHAPE_TRIANGLE:
                cr->move_to(40, 40);
                cr->line_to(200, 40);
                cr->line_to(120, 160);
                cr->line_to(40, 40);
                cr->set_source_rgb(0.8, 0, 0.8);
                cr->fill_preserve();
                cr->set_line_cap(Cairo::LINE_CAP_ROUND);
                cr->set_line_join(Cairo::LINE_JOIN_ROUND);
                break;
            }

            cr->set_line_width(3);
            cr->set_source_rgb(0, 0, 0);
            cr->stroke();
            return true;
        }
//Lots of this function needs to be optimised, including the pixbuf/bitmap thing and having to draw pretty much double the squares
void Simple_GOL_Area::draw_sim_data(const Cairo::RefPtr<Cairo::Context>& cr, int window_width, int window_height)
{
	time_t seconds = time(NULL);
	std::cout << "Rendering Simulation " << seconds << "\n";
	
	if (sim_data->get_size() != 0)
	{
		int data_width =  sim_data->get_width();
		int data_height = sim_data->get_height();
		double step_value_x = double(window_width)/double(sim_data->get_width());
		double step_value_y = double(window_height)/double(sim_data->get_height());
		
		for(int i=0; i<data_width; i++)
		{
			for(int j=0; j<data_height; j++)
			{
				if(sim_data->get(i,j))
				{
					cr->set_source_rgb(1,1,1);
				}
				else
				{
					cr->set_source_rgb(0,0,0);
				}
				
				//Yet to figure out why I have to draw in the black squares as well. 
				cr->rectangle(int(i*step_value_x), int(j*step_value_y),
				 			int((i+1)*step_value_x), int((j+1)*step_value_y));
				//Use bitmap classes so that I don't have to fill every time
				cr->fill();
			}	
		}

	}
}
示例#3
0
int main(int, char**) {
	Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(
			Cairo::FORMAT_ARGB32, WIDTH, HEIGHT);
	Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
	// fill background in white
	cr->set_source_rgb(1.0, 1.0, 1.0);
	cr->paint();

	// draw a little dot at the point where text will be drawn
	cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2 * M_PI);
	cr->set_source_rgba(0.0, 1.0, 0.0, 0.5);
	cr->fill();

	// draw the text
	cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
	cr->set_source_rgb(0.8, 0.2, 0.2);
	Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create(
			"Bitstream Charter", Cairo::FONT_SLANT_ITALIC,
			Cairo::FONT_WEIGHT_BOLD);
	cr->set_font_face(font);
	cr->set_font_size(FONT_SIZE);
	cr->show_text("cairomm!");
	surface->write_to_png("toy-text.png");
	return 0;
}
示例#4
0
bool
ButtonWidget::on_expose_event(GdkEventExpose* event)
{
  Gtk::DrawingArea::on_expose_event(event);
  Glib::RefPtr<Gdk::Window> window = get_window();
  if(window)
    {
      Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();

      int w  = get_allocation().get_width()  - 10;
      int h  = get_allocation().get_height() - 10;

      cr->set_source_rgb(0.0, 0.0, 0.0);
      cr->set_line_width(1.0);
      cr->translate(5, 5);
      cr->rectangle(0, 0, w, h);
      
      if (down)
        cr->fill_preserve();

      cr->stroke();

      if (down)
        cr->set_source_rgb(1.0, 1.0, 1.0);

      // FIXME: There are better ways to center text
      if (name.size() == 2)
        cr->move_to(w/2-6, h/2+3);
      else
        cr->move_to(w/2-4, h/2+3);
      cr->show_text(name);
    }

  return true;
}
示例#5
0
void MapDrawArea::DrawObstacles(const Cairo::RefPtr<Cairo::Context>& cr)
{
	// Get size characteristics of the window
	Gtk::Allocation allocation = get_allocation();
	const int width = allocation.get_width();
	const int height = allocation.get_height();
	const int lesser = MIN(width, height);

	// We should be able to just store the obstacles and path once
	// Do need to update based on the window size
	std::vector<Coord> vObstacles = guiMapData.copyObstacles();
	Coord maxXY = guiMapData.copyMaxCoord();
	Coord originCoord = guiMapData.copyStartCoord();
	Coord goalCoord = guiMapData.copyEndCoord();

	// These have to be updated each iteration
	originCoord.x = int( float(width)*float(originCoord.x)/float(maxXY.x) );
	originCoord.y = int( float(height)*float(originCoord.y)/float(maxXY.y) );
	goalCoord.x = int( float(width)*float(goalCoord.x)/float(maxXY.x) );
	goalCoord.y = int( float(height)*float(goalCoord.y)/float(maxXY.y) );

	// Draw obstacles
	std::vector<Coord> scaledObstacleCoord;
	std::vector<Coord> rawObstacleCoord = guiMapData.copyObstacles();
	Coord stdCoord;

	// Adjust obstacle values based on window size
	for(std::vector<Coord>::const_iterator itr=rawObstacleCoord.begin();itr!=rawObstacleCoord.end();++itr)
	{
		stdCoord.x = int( float(width)*float(itr->x)/float(maxXY.x) );
		stdCoord.y = int( height*float(itr->y)/float(maxXY.y) );
		scaledObstacleCoord.push_back(stdCoord);
	}

	cr->save();
	cr->set_source_rgb(0.0, 0.0, 0.0);	// black for obstacles
	cr->set_line_width(lesser * 0.005);
	cr->set_line_cap(Cairo::LINE_CAP_ROUND);

	// Plot obstacles
	for(std::vector<Coord>::iterator itr=scaledObstacleCoord.begin();itr != scaledObstacleCoord.end();++itr)
	{
		cr->move_to( itr->x,itr->y );
		cr->line_to( itr->x,itr->y );
		cr->stroke();
	}

	// Plot start/end coord
	cr->save();
	cr->set_line_width(lesser * 0.015);
	cr->set_source_rgb(1.0, 0.0, 0.0);	// red for start point
	cr->move_to( originCoord.x,originCoord.y );
	cr->line_to( originCoord.x,originCoord.y );
	cr->stroke();
	cr->save();
	cr->set_source_rgb(0.0, 1.0, 0.0);	// green for end point
	cr->move_to( goalCoord.x,goalCoord.y );
	cr->line_to( goalCoord.x,goalCoord.y );
	cr->stroke();
}
示例#6
0
void enigma_rotor_window::draw(Cairo::RefPtr<Cairo::Context> cr)
{
    vector<double> dashes;
    // Pattern used to draw a dashed line (15 pixels of line followed by 15 "empty" pixels)
    dashes.push_back(15.0);
    dashes.push_back(15.0);
    
    if (has_ellipse)
    {
        cr->save();
        
            // Draw background ellipse
            cr->set_source_rgb(bkg_r, bkg_g, bkg_b);
            draw_ellipse(cr, x, y, ellipse_width, ellipse_height);
            cr->fill();
            // Draw black border of background ellipse
            cr->set_source_rgb(BLACK);
            cr->set_line_width(1.2);
            draw_ellipse(cr, x, y, ellipse_width, ellipse_height);
            cr->stroke();
        
        cr->restore();
    }
    
    cr->save();  
    
        // Draw a line of width rotor_rim_width in the dash background colour
        cr->set_line_width(rotor_rim_width);
        cr->set_source_rgb(dash_bkg_r, dash_bkg_g, dash_bkg_b);
        cr->move_to(x + window_size, y - (2 * window_size));
        cr->line_to(x + window_size, y + (2 * window_size));
        cr->stroke();
        
        // Draw a dashed line in the dash colour inside the previously drawn line
        // This creates the impression of "notches" on the handle/rim
        cr->set_source_rgb(dash_r, dash_g, dash_b);
        cr->set_dash(dashes, ((wheel_pos - 'A') & 1) * 15); // modifying the offset creates illusion of movement
        
        cr->move_to(x + window_size, y - (2 * window_size));
        cr->line_to(x + window_size, y + (2 * window_size));
        cr->stroke();
        
        // Draw border around handle/rim
        cr->set_line_width(2.0);
        cr->unset_dash();
        cr->set_source_rgb(DARK_GREY);
        cr->rectangle(x + padded_size, y - (2 * window_size), rotor_rim_width, (4 * window_size));
        cr->stroke();
    
    cr->restore();

    draw_wheel_pos(cr, wheel_pos);
    
    if (has_ellipse)
    {
        // Draw screws
        upper->draw(cr);
        lower->draw(cr);    
    }
}
示例#7
0
/// Same as draw_buffer, with only the curr_item's full text
void
ViewDrawingArea::render_full_article()
{
	// Dimensions of drawing area
	Gtk::Allocation allocation = get_allocation();
	const int height = allocation.get_height();
	const int width = allocation.get_width();

	Cairo::RefPtr<Cairo::Context> cr = _pixmap->create_cairo_context();
	cr->reset_clip();
	cr->rectangle (0.0, 0.0, width, height);
	cr->clip();
	cr->set_source_rgb (1.0, 1.0, 1.0);
	cr->paint();
	cr->set_source_rgb (0.0, 0.0, 0.0);

	Item *item = AppContext::get().get_curr_item();
	item->make_display_unit();
	ItemDisplayUnit *du = item->get_display_unit();
	du->render (cr, 0, -_vadj->get_value());
	cr->show_page();
	
	double h = du->get_height();
	if (h > height)
		_vadj->set_upper (h - height);
	else
		_vadj->set_upper (0);

	_vadj->set_page_size (height);
	_vadj->set_step_increment (height * 1.0/16.0);
	_vadj->set_page_increment (height * 15.0/16.0);
	_vadj->changed();
}
示例#8
0
void
Renderer_BBox::render_vfunc(
	const Glib::RefPtr<Gdk::Window>& drawable,
	const Gdk::Rectangle& /*expose_area*/
)
{
	assert(get_work_area());
	if(!get_work_area())
		return;

	Cairo::RefPtr<Cairo::Context> cr = drawable->create_cairo_context();

	const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
	const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
	const float pw(get_pw()),ph(get_ph());

	const synfig::Point curr_point(get_bbox().get_min());
	const synfig::Point drag_point(get_bbox().get_max());
	if(get_bbox().area()<10000000000000000.0 && get_bbox().area()>0.00000000000000001)
	{
		Point tl(std::min(drag_point[0],curr_point[0]),std::min(drag_point[1],curr_point[1]));
		Point br(std::max(drag_point[0],curr_point[0]),std::max(drag_point[1],curr_point[1]));

		tl[0]=(tl[0]-window_startx)/pw;
		tl[1]=(tl[1]-window_starty)/ph;
		br[0]=(br[0]-window_startx)/pw;
		br[1]=(br[1]-window_starty)/ph;
		if(tl[0]>br[0])
			swap(tl[0],br[0]);
		if(tl[1]>br[1])
			swap(tl[1],br[1]);

		cr->save();
		cr->set_line_cap(Cairo::LINE_CAP_BUTT);
		cr->set_line_join(Cairo::LINE_JOIN_MITER);

		cr->set_line_width(1.0);
		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->rectangle(
			int(tl[0])+0.5,
			int(tl[1])+0.5,
			int(br[0]-tl[0]+1),
			int(br[1]-tl[1]+1)
		);
		cr->stroke();

		cr->restore();
	}
}
示例#9
0
bool BookArea::on_draw(const Cairo::RefPtr<Cairo::Context> & cr)
{

    Cairo::RefPtr<Cairo::Surface> surface = cr->get_target();

    PageDescriptor pd = pages.get(pagenum);

    Gtk::Allocation allocation = get_allocation();
    const int width = allocation.get_width();
    const int height = allocation.get_height();

    const int rectangle_width = width;
    const int rectangle_height = height;

    //cr->set_antialias(ANTIALIAS_BEST);

    cr->set_source_rgb(1.0, 1.0, 1.0);
    DrawingUtils::draw_rectangle(cr, rectangle_width, rectangle_height);

    cr->set_source_rgb(0.15, 0.15, 0.15);
    //cr->set_source_rgb(1, 0.33, 0.33);

    int start_pos = 0;

    int itemid = 0;

    for(PageContentItem pci : pd.items) {

        if(pci.pct == PAGE_H1) {
            start_pos += DrawingUtils::draw_h1(cr, pci.content, rectangle_width, rectangle_height);
        }
        else if(pci.pct == PAGE_H2) {
            // Only pack out the header when it's not the first thing in the page
            if (itemid != 0) {
                start_pos += 35;
            }

            start_pos += DrawingUtils::draw_h2(cr, pci.content, rectangle_width, rectangle_height, start_pos);
            start_pos += 35;
        }
        else if(pci.pct == PAGE_PARAGRAPH) {
            start_pos += DrawingUtils::draw_text(cr, pci.content, rectangle_width, rectangle_height, start_pos);
        }
        else if(pci.pct == PAGE_FRAGMENT) {
            start_pos += DrawingUtils::draw_fragment(cr, pci.content, rectangle_width, rectangle_height, start_pos);
        }

        itemid++;

    }

    //auto it = book.opf_files[0].metadata.find(MetadataType::TITLE);
    //const ustring title = it->second.contents;
    cr->set_source_rgb(0.5, 0.5, 0.5);
    page_num_rect = DrawingUtils::draw_header(cr, rectangle_width, rectangle_height, "Pride and Prejudice", pagenum + 1);

    return true;
}
示例#10
0
bool AdvEnvGUIScope::on_expose_event(GdkEventExpose* event)
{
	Glib::RefPtr<Gdk::Window> window = get_window();
	if (window)
	{
		float len, x, y, xscale, yscale;

		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();
		cr->set_line_width(2.0);
		cr->set_source_rgb(0.0, 0.0, 0.0);
		cr->paint();

		cr->set_source_rgb(0.0, 0.8, 0.0);

		cr->rectangle(event->area.x, event->area.y, event->area.width, event->area.height);
		cr->clip();

		cr->move_to(width, height);

		len = m_valueDelay + m_valueAttackTime1 + m_valueAttackTime2 + m_valueAttackTime3 + m_valueAttackTime4 + m_valueReleaseTime1 + m_valueReleaseTime2 + m_valueReleaseTime3 + SUSTAIN_LEN;
		xscale = (float) width / len;
		yscale = (float) (height - 6);

		x = m_valueDelay * xscale;
		cr->line_to((int) x, height);
		x += m_valueAttackTime1 * xscale;
		y = m_valueAttackLevel1 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueAttackTime2 * xscale;
		y = m_valueAttackLevel2 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueAttackTime3 * xscale;
		y = m_valueAttackLevel3 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueAttackTime4 * xscale;
		y = m_valueSustain * yscale;
		cr->line_to((int) x, height - (int) y);
		x += SUSTAIN_LEN * xscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueReleaseTime1 * xscale;
		y = m_valueReleaseLevel1 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueReleaseTime2 * xscale;
		y = m_valueReleaseLevel2 * yscale;
		cr->line_to((int) x, height - (int) y);
		x += m_valueReleaseTime3 * xscale;
		cr->line_to((int) x, height);
		x = m_valueDelay * xscale;
		cr->line_to((int) x, height);
		cr->stroke();
	}

	return true;
}
示例#11
0
void GraficoDeTorta::dibujarArco(const Cairo::RefPtr<Cairo::Context>& c,int x, int y, int radio, float angulo0, float angulo1,float r, float g, float b){
	c->set_source_rgb(1,1,1);
	c->set_line_width(2);
	c->arc(x,y,radio, angulo0, angulo1);
	c->line_to(x,y);
	c->close_path();
	c->stroke_preserve();
	c->set_source_rgb(r,g,b);
	c->fill();
}
示例#12
0
void ItemView::drawBackground(const Cairo::RefPtr<Cairo::Context>& cr, const int width, const int height)
{
    //fill background
    if (isSelected())
    {
        cr->set_source_rgb(1, 1, 1);
        cr->rectangle(0, 0, width, height);
        cr->fill();
    }
    else
    {
        cr->set_source_rgb(0.98, 0.98, 0.98);
        cr->rectangle(0, 0, width, height);
        cr->fill();
    }

    //time area
    Cairo::RefPtr<Cairo::LinearGradient> linearGradientTime = Cairo::LinearGradient::create(0, 0, 0, height);

    //set color by status
    ColorMode colorMode = getColorMode();

    if (colorMode == COLOR_INACTIVE)
    {
        //gray
        linearGradientTime->add_color_stop_rgb(0, 0.75, 0.75, 0.75);
        linearGradientTime->add_color_stop_rgb(1, 0.65, 0.65, 0.65);
    }

    if (colorMode == COLOR_ALARM)
    {
        //orange
        linearGradientTime->add_color_stop_rgb(0, 1.00, 0.60, 0.30);
        linearGradientTime->add_color_stop_rgb(1, 0.90, 0.50, 0.20);
    }

    if (colorMode == COLOR_OK)
    {
        //green
        linearGradientTime->add_color_stop_rgb(0, 0.40, 0.70, 0.45);
        linearGradientTime->add_color_stop_rgb(1, 0.30, 0.60, 0.35);
    }

    cr->set_source(linearGradientTime);
    cr->rectangle(0, 0, TIME_WIDTH, height);
    cr->fill();

    if (isSelected())
        drawInnerShadow(cr, width, height);
}
示例#13
0
void ItemView::drawTime(const Cairo::RefPtr<Cairo::Context>& cr, const int width, const int height)
{
    int text_width;
    int text_height;

    Glib::RefPtr<Pango::Layout> layTime = Pango::Layout::create(cr);
    layTime->set_font_description(fontTime);
    layTime->set_text(data.getTimeText());
    layTime->get_pixel_size(text_width, text_height);

    rectTime.set_x((TIME_WIDTH * 0.5) - (text_width * 0.5));
    rectTime.set_y((int)PADDING);
    rectTime.set_width(text_width);
    rectTime.set_height(text_height);

    //highlight
    const int highlightSize = 1;

    cr->move_to(rectTime.get_x(), rectTime.get_y() - highlightSize);

    //set colors
    ColorMode colorMode = getColorMode();

    if (colorMode == COLOR_INACTIVE)
    {
        //gray
        cr->set_source_rgb(0.6, 0.6, 0.6);
    }

    if (colorMode == COLOR_ALARM)
    {
        //orange
        cr->set_source_rgb(0.8, 0.40, 0.0);
    }

    if (colorMode == COLOR_OK)
    {
        //green
        cr->set_source_rgb(0.0, 0.55, 0.0);
    }

    layTime->show_in_cairo_context(cr);

    //inner color
    cr->move_to(rectTime.get_x(), rectTime.get_y());
    cr->set_source_rgb(1.0, 1.0, 1.0);
    layTime->show_in_cairo_context(cr);
}
bool CompVis::on_expose_event(GdkEventExpose* event) {
    Glib::RefPtr<Gdk::Window> window = get_window();
    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();
        
    // 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();
           
    rms_dB = 20*log10(rms);
    thresh_fraction = (threshold -  p_ports[p_threshold].min)/threshold_range;
    rms_dB_fraction = (rms_dB - p_ports[p_threshold].min)/threshold_range;

    // Draw the graph
    cr->set_source_rgb(0.5,0.1,0.1);
    cr->set_line_width(2);
    cr->move_to(0,height);

    if (rms_dB <= threshold) {
        cr->line_to(rms_dB_fraction*width, height-rms_dB_fraction*height);
        cr->line_to(rms_dB_fraction*width, height);
        cr->line_to(0,height);
    } else {
        cr->line_to(thresh_fraction*width, height-thresh_fraction*height);
        cr->line_to(rms_dB_fraction*width, height-(thresh_fraction*height + height*(rms_dB_fraction-thresh_fraction)/ratio));
        cr->line_to(rms_dB_fraction*width, height);
        cr->line_to(0,height);
    }
    cr->fill();

    // draw the compression curve:
    cr->set_source_rgb(0.1,0.1,0.1);
    cr->move_to(0, height);
    cr->line_to(thresh_fraction*width, height-thresh_fraction*height);
    cr->line_to(width, height-(thresh_fraction*height + height*(1-thresh_fraction)/ratio));
    cr->stroke();

    // Draw the gain
    cr->set_source_rgb(0.1,0.8,0.1);
    cr->rectangle(0,(float)height - (float)height*gain, 10, height);
    cr->fill();
    return true;
}
示例#15
0
void CairoPlugin::init()
{
    int height, width;

    preferredSize(width, height);

    m_img = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, width, height);
    m_store = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, width, height);
    m_ctx = Cairo::Context::create(m_img);

    Cairo::RefPtr < Cairo::Context > ctx = Cairo::Context::create(m_store);

    ctx->save();
    ctx->set_source_rgb(1.0, 1.0, 1.0);
    ctx->set_operator(Cairo::OPERATOR_SOURCE);
    ctx->paint();
    ctx->set_operator(Cairo::OPERATOR_OVER);
    ctx->restore();

    m_ctx->save();
    m_ctx->set_source_rgb(1.0, 1.0, 1.0);
    m_ctx->set_operator(Cairo::OPERATOR_SOURCE);
    m_ctx->paint();
    m_ctx->set_operator(Cairo::OPERATOR_OVER);
    m_ctx->restore();

    m_init = false;
    m_need = true;
}
示例#16
0
void ItemView::drawDescription(const Cairo::RefPtr<Cairo::Context>& cr, const int width, const int height)
{
    //reference vertical position for later use
    int firstBaseline = rectTitle.get_y() + rectTitle.get_height() + PADDING;

    int text_width;
    int text_height;

    Glib::RefPtr<Pango::Layout> layDescription = Pango::Layout::create(cr);
    layDescription->set_font_description(fontDescription);
    layDescription->set_text(data.getDetails());
    layDescription->get_pixel_size(text_width, text_height);

    rectDescription.set_x(PADDING + TIME_WIDTH + SPACE);
    rectDescription.set_y(firstBaseline);
    rectDescription.set_width(width - TIME_WIDTH - getAllButtonsWidth() - (PADDING * 2));
    rectDescription.set_height(height - firstBaseline - PADDING);

    cr->move_to(rectDescription.get_x(), rectDescription.get_y());
    cr->set_source_rgb(0.4, 0.4, 0.4);

    layDescription->set_width(rectDescription.get_width() * PANGO_SCALE);
    layDescription->set_height(rectDescription.get_height() * PANGO_SCALE);
    layDescription->set_wrap(Pango::WRAP_WORD);
    layDescription->set_ellipsize(Pango::ELLIPSIZE_END);

    layDescription->set_single_paragraph_mode(false);
    layDescription->show_in_cairo_context(cr);
}
示例#17
0
void Simple_GOL_Area::draw_grid(const Cairo::RefPtr<Cairo::Context>& cr, int window_width, int window_height)
{	
	int data_amount = sim_data->get_size();
	
	if (data_amount != 0)
	{
		//sim_data->set_width(20);
		double step_value_x = double(window_width)/double(sim_data->get_width());
		double step_value_y = double(window_height)/double(sim_data->get_height());

		cr->save();
	
		cr->set_line_width(1.0);
		cr->set_source_rgb(0.5,0.5,1);
		cr->move_to(0,0);

		for(double i=0; i<window_width; i = i+ step_value_x)
		{
			cr->move_to(i, 0);
			cr->line_to(i, window_height);
		}
	
		for(double i=0; i<window_height; i = i+step_value_y)
		{
			cr->move_to(0, i);
			cr->line_to(window_width, i);
		}
	
		cr->stroke();
		cr->restore();
	}	
}
示例#18
0
void
Renderer_Dragbox::render_vfunc(
	const Glib::RefPtr<Gdk::Window>& drawable,
	const Gdk::Rectangle& /*expose_area*/
)
{
	assert(get_work_area());
	if(!get_work_area())
		return;

	// const synfig::Vector focus_point(get_work_area()->get_focus_point());
	// Warning : Unused focus_point
	int drawable_w = drawable->get_width();
	int drawable_h = drawable->get_height();

	Cairo::RefPtr<Cairo::Context> cr = drawable->create_cairo_context();

	const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
	const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
	const float pw(get_pw()),ph(get_ph());

	const synfig::Point& curr_point(get_curr_point());
	const synfig::Point& drag_point(get_drag_point());

	{
		cr->save();
		cr->set_line_cap(Cairo::LINE_CAP_BUTT);
		cr->set_line_join(Cairo::LINE_JOIN_MITER);
		cr->set_antialias(Cairo::ANTIALIAS_NONE);

		cr->set_line_width(1.0);
		cr->set_source_rgb(0,0,0);
		std::valarray<double> dashes(2);
		dashes[0]=5.0;
		dashes[1]=5.0;
		cr->set_dash(dashes, 0);

		Point tl(std::min(drag_point[0],curr_point[0]),std::min(drag_point[1],curr_point[1]));
		Point br(std::max(drag_point[0],curr_point[0]),std::max(drag_point[1],curr_point[1]));

		tl[0]=(tl[0]-window_startx)/pw;
		tl[1]=(tl[1]-window_starty)/ph;
		br[0]=(br[0]-window_startx)/pw;
		br[1]=(br[1]-window_starty)/ph;
		if(tl[0]>br[0])
			swap(tl[0],br[0]);
		if(tl[1]>br[1])
			swap(tl[1],br[1]);

		cr->rectangle(
			tl[0],
			tl[1],
			br[0]-tl[0],
			br[1]-tl[1]
		);
		cr->stroke();

		cr->restore();
	}
}
示例#19
0
void MapDrawArea::DrawOptimalPath(const Cairo::RefPtr<Cairo::Context>& cr)
{
	// This is where we draw on the window
	Gtk::Allocation allocation = get_allocation();
	const int width = allocation.get_width();
	const int height = allocation.get_height();
	const int lesser = MIN(width, height);
	const Coord maxXY = guiMapData.copyMaxCoord();

	// Copy the optimal path to the draw area
	std::vector<Coord> optimalPath = guiMapData.copyOptPath();

	// Plot the path
	cr->save();
	cr->set_source_rgb(1.0, 0.08, 0.58);	// pink for path
	cr->set_line_width(lesser * 0.005);
	cr->set_line_cap(Cairo::LINE_CAP_ROUND);

	for(std::vector<Coord>::iterator itr=optimalPath.begin();itr != optimalPath.end();++itr)
	{
		cr->move_to( int( float(width)*float(itr->x)/float(maxXY.x) ),int( height*float(itr->y)/float(maxXY.y)));
		cr->line_to( int( float(width)*float(itr->x)/float(maxXY.x) ),int( height*float(itr->y)/float(maxXY.y)));
		cr->stroke();
	}
}
示例#20
0
void Format7DrawingArea::DrawDisabledText(Cairo::RefPtr<Cairo::Context> refCairo)
{
    refCairo->save();

    // Set the font parameters
    refCairo->select_font_face(
        "monospace",
        Cairo::FONT_SLANT_NORMAL,
        Cairo::FONT_WEIGHT_BOLD );
    refCairo->set_font_size( 10 );

    // Set draw color to black
    refCairo->set_source_rgb(0.0, 0.0, 0.0);

    // Print current cursor position
    char cursorPosition[128];
    sprintf(
        cursorPosition,
        "Custom Image is not supported by this camera.");

    // Get width / height of widget
    int width;
    int height;
    get_window()->get_size( width, height );

    Cairo::TextExtents textExtents;
    refCairo->get_text_extents( cursorPosition, textExtents );
    refCairo->move_to(
        (width/2) - (textExtents.width/2),
        (height/2) + textExtents.height + (textExtents.height/2));
    refCairo->show_text( cursorPosition );

    refCairo->restore();
}
示例#21
0
bool CircuitWidget::on_expose_event(GdkEventExpose* event)
{

    (void)event; // placate compiler..
    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();
        double xc = width/2.0;
        double yc = height/2.0;

        Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
        circuitDrawer.renderCairo(cr->cobj());
        cr->rectangle(event->area.x, event->area.y,
                      event->area.width, event->area.height);
        cr->clip();
        cr->rectangle (0, 0, width, height);
        cr->set_source_rgb (1,1,1);
        cr->fill ();
        cr->translate (xc-ext.width/2.0-cx*scale, yc-ext.height/2.0-cy*scale);
        if (circuit) {
            rects = circuitDrawer.draw(*circuit, drawarch, drawparallel, ext, wirestart, wireend, scale, selections, ft_default, wirelabels);
            generate_layout_rects ();
        }
    }

    return true;
}
示例#22
0
void GraphicalItem::drawRoundedRectangle(
    const Cairo::RefPtr<Cairo::Context>& context,
    int x, int y,
    int width, int height,
    double aspect,
    double corner_radius,
    double red, double green, double blue)
{
    double radius = corner_radius / aspect;
    double degrees = M_PI / 180.0;

    context->begin_new_sub_path();
    context->arc(x + width - radius, y + radius, radius,
        -90 * degrees, 0 * degrees);
    context->arc(x + width - radius, y + height - radius,
        radius, 0 * degrees, 90 * degrees);
    context->arc(x + radius, y + height - radius, radius,
        90 * degrees, 180 * degrees);
    context->arc(x + radius, y + radius, radius,
        180 * degrees, 270 * degrees);
    context->close_path();

    context->set_source_rgb(red, green, blue);
    context->fill_preserve();
    setColor(Settings::settings().getForegroundColor(), context);
    context->stroke();
}
示例#23
0
void GraphicalItem::setColor(const Gdk::Color& color,
    const Cairo::RefPtr<Cairo::Context>& context)
{
        context->set_source_rgb(color.get_red_p(),
        color.get_green_p(),
        color.get_blue_p());
}
示例#24
0
void
Renderer_BoneSetup::render_vfunc(const Glib::RefPtr<Gdk::Window>& drawable,
								 const Gdk::Rectangle& /*expose_area*/ )
{
	assert(get_work_area());
	if(!get_work_area())
		return;

	Cairo::RefPtr<Cairo::Context> cr = drawable->create_cairo_context();
	Canvas::Handle canvas(get_work_area()->get_canvas());

	// Print out the bonesetup
	{
		Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_work_area()->get_pango_context()));

		bool recursive(get_work_area()->get_type_mask() & Duck::TYPE_BONE_RECURSIVE);
		if (recursive)
		{
			int w, h;
			layout->set_text(_("Bone Recursive Scale Mode"));
			layout->get_size(w, h);
			get_work_area()->bonesetup_width = int(w*1.0/Pango::SCALE);
			get_work_area()->bonesetup_height = int(h*1.0/Pango::SCALE);
		}
		else
			get_work_area()->timecode_width = get_work_area()->timecode_height = 0;

		Gdk::RGBA c("#5f0000");
		cr->set_source_rgb(c.get_red(), c.get_green(), c.get_blue());
		cr->move_to(bonesetup_x, bonesetup_y);
		layout->show_in_cairo_context(cr);
	}
}
示例#25
0
文件: balls.cpp 项目: jogojapan/simul
bool Balls::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
  Gtk::Allocation allocation = get_allocation();
  const int width = allocation.get_width();
  const int height = allocation.get_height();

  cr->save();
  cr->scale(width, height);

  cr->set_line_width(0.001);
  for (auto ball : balls_)
    {
      cr->set_source_rgb(ball.color_r,ball.color_g,ball.color_b);
      cr->arc(ball.p.x,ball.p.y,
              ball.rad,
              0,2*M_PI);
      cr->fill();
      cr->stroke();
    }

  cr->restore();

  const Ball &ball1 = balls_[balls_.size()-1];
  std::ostringstream info;
  info << "x = " << ball1.p.x << "\ny = " << ball1.p.y;
  infobox_.show(cr,width,height,info.str());

  return true;
}
示例#26
0
/* Callback on_draw */
bool SensorsMap::on_draw (const Cairo::RefPtr<Cairo::Context>& cr)
{
  /* Get window allocation */
  Gtk::Allocation allocation = get_allocation ();
  const int width = allocation.get_width ();
  const int height = allocation.get_height ();

  /* Get center of the window */
  int xc, yc;
  xc = width / 2;
  yc = height / 2;

// DEBUG
cr->set_line_width(10.0);

// draw red lines out from the center of the window
cr->set_source_rgb(0.8, 0.0, 0.0);
cr->move_to(0, 0);
cr->line_to(xc, yc);
cr->line_to(0, height);
cr->move_to(xc, yc);
cr->line_to(width, yc);
cr->stroke();
// END DEBUG

  /* Return success */
  return true;
}
bool ScreenAreaCairo::on_draw(const Cairo::RefPtr<Cairo::Context>& poContext)
{
    DrawingArea::on_draw(poContext);
    Cairo::RefPtr<Cairo::ImageSurface> poImage;
    Cairo::RefPtr<Cairo::SurfacePattern> poPattern;
    Cairo::Matrix oMatrix;
    const int iScaledPitch = (m_iScaledWidth + 1) * sizeof(u32);

    //poContext->set_identity_matrix();
    poContext->scale(m_dScaleFactor, m_dScaleFactor);

    poImage = Cairo::ImageSurface::create((u8*)m_puiPixels, Cairo::FORMAT_RGB24,
        m_iScaledWidth, m_iScaledHeight, iScaledPitch);

    //cairo_matrix_init_translate(&oMatrix, -m_iAreaLeft, -m_iAreaTop);
    poPattern = Cairo::SurfacePattern::create(poImage);
    poPattern->set_filter(Cairo::FILTER_NEAREST);
    //poPattern->set_matrix (oMatrix);
    poContext->set_source_rgb(0.0, 0.0, 0.0);
    poContext->paint();

    poContext->set_source(poPattern);
    poContext->paint();

    return true;
}
示例#28
0
void List::draw_label_helper(const Cairo::RefPtr<Cairo::Context> & cr, ListNode * label, const char * text, int x, int y, LabelArrowPos arrowPos) {
	cr->set_source_rgb(0.0, 0.0, 0.0);
	Pango::FontDescription font;
	font.set_family("Monospace");
	font.set_weight(Pango::WEIGHT_BOLD);
	Glib::RefPtr<Pango::Layout> layout = create_pango_layout(text);
	layout->set_font_description(font);
	int text_w, text_h;
	layout->get_pixel_size(text_w, text_h);
	cr->move_to(x, y);
	layout->show_in_cairo_context(cr);
	if (label != NULL) {
		if (arrowPos == RIGHT) {
		draw_arrow_helper(cr, x + text_w + 10, y + text_h / 2, label->x - 10, label->y + ListNode::field_h);
		} else {
		draw_arrow_helper(cr, x - 10, y + text_h / 2, label->x + ListNode::field_w + 10, label->y + ListNode::field_h);
		}
	} else {
		if (arrowPos == RIGHT) {
			draw_null_arrow(cr, x + text_w + 10, y + text_h / 2, true);
		} else {
			draw_null_arrow(cr, x - 10, y + text_h / 2, false);
		}
	}
}
示例#29
0
bool guiRenderer2D::on_expose_event(GdkEventExpose* event) {

	Glib::RefPtr<Gdk::Window> window = get_window();
	if(window) {
		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
			//printf("event->area.x: %d, event->area.y: %d, event->area.width: %d, event->area.height: %d\n", event->area.x, event->area.y, event->area.width, event->area.height );
			cr->rectangle(event->area.x, event->area.y,	event->area.width, event->area.height);
			cr->clip();
		}

		// Background
		// cr->set_source_rgb(0.0, 0.0, 0.0);
		cr->set_source_rgb(1.0, 1.0, 1.0);
		cr->paint();

		if(m_isRendering && m_layoutAvailable) {
			Gtk::Allocation allocation = get_allocation();
			int width = allocation.get_width();
			int height = allocation.get_height();

			if(width != m_widgetWidth || height != m_widgetHeight ) { // Allocation changed
				rescaleSensorLayout(width, height);
			}

			drawMatrices(cr, width, height, false);
		}
	}

	return true;
}
示例#30
0
bool Terminal::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) {
    Box::on_draw(cr);

    cr->set_source_rgb(1, 0, 0);
    cr->rectangle(dock_hint.x, dock_hint.y, dock_hint.x+dock_hint.width, dock_hint.y+dock_hint.height);
    cr->fill();
}