示例#1
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;
}
示例#2
0
void EmblemCellRenderer::do_render(const Cairo::RefPtr<Cairo::Context>& context, int widget, int background_area, Gdk::Rectangle &cell_area, int flags) {
    context->translate(cell_area.get_x(), cell_area.get_y());
    context->rectangle(0, 0, cell_area.get_width(), cell_area.get_height());
    context->clip();

    // TODO: Incorporate padding
    context->push_group();
    if (!this->_icon_name.empty()) {
        Glib::RefPtr<Gdk::Pixbuf> pixbuf = this->_get_pixbuf(this->_icon_name, this->_icon_size);
        context->set_operator(Cairo::OPERATOR_SOURCE);
        // Assumes square icons; may break if we don't get the requested size
        int height_offset = int((cell_area.get_height() - pixbuf->get_height())/2);
        Gdk::Cairo::set_source_pixbuf(context, pixbuf, 0, height_offset);
        context->rectangle(0, height_offset,
                          pixbuf->get_width(), pixbuf->get_height());
        context->fill();

        if (this->_tint_color) {
            Gdk::RGBA* c = this->_tint_color;
            gushort r = c->get_red();
            gushort g = c->get_green();
            gushort b = c->get_blue();
            // Figure out the difference between our tint colour and an
            // empirically determined (i.e., guessed) satisfying luma and
            // adjust the base colours accordingly
            double luma = (r + r + b + g + g + g) / 6.;
            double extra_luma = (1.2 - luma) / 3.;
            r = std::min(r + extra_luma, 1.);
            g = std::min(g + extra_luma, 1.);
            b = std::min(b + extra_luma, 1.);
            context->set_source_rgba(r, g, b, 0.4);
            context->set_operator(Cairo::OPERATOR_ATOP);
            context->paint();
        }

        if (!this->_emblem_name.empty()) {
            Glib::RefPtr<Gdk::Pixbuf> pixbuf = this->_get_pixbuf(this->_emblem_name, this->_emblem_size);
            int x_offset = this->_icon_size - this->_emblem_size;
            context->set_operator(Cairo::OPERATOR_OVER);
            Gdk::Cairo::set_source_pixbuf(context, pixbuf, x_offset, 0);
            context->rectangle(x_offset, 0,
                              cell_area.get_width(), this->_emblem_size);
            context->fill();
        }
    }

    context->pop_group_to_source();
    context->set_operator(Cairo::OPERATOR_OVER);
    context->paint();
}
示例#3
0
static void ClearCanvas(Cairo::RefPtr<Cairo::Context>& cr)
{
    CairoStateSave save(cr);

    cr->set_operator(Cairo::OPERATOR_CLEAR);
    cr->paint();
}
示例#4
0
	void clear()
	{
		cr->save();

		cr->set_operator(Cairo::OPERATOR_CLEAR);
		cr->set_source_rgba(1.0, 1.0, 1.0, 1.0);
		cr->paint();

		cr->restore();
	}
示例#5
0
/**
 * Makes the window draw itself.
 */
void Window::redraw()
{
	LOG(kLogDebug, "Redrawing window %p", this);
	needsRedraw = false;
	Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create(store);

	context->save();
	context->set_operator(Cairo::OPERATOR_CLEAR);
	context->paint();
	context->restore();

	draw(context);
	loadTexture();
}
示例#6
0
bool Liveplay::window_expose_event(GdkEventExpose *event) {
    Cairo::RefPtr<Cairo::Context> cr = Glib::wrap(event->window, true)->create_cairo_context();
    Gtk::Allocation a = liveplay_canvas->get_allocation();
    Gdk::Region region(a);
    region.intersect(Glib::wrap(event->region, true));
    Gdk::Cairo::add_region_to_path(cr, region);
    cr->clip();
    cr->set_operator(Cairo::OPERATOR_SOURCE);
    cr->set_source_rgb(0,0,0);
    cr->paint();
    //gdk_cairo_set_source_window(cr->cobj(), liveplay_canvas->get_window()->gobj(), a.get_x(), a.get_y()); gtk 2.24
    gdk_cairo_set_source_pixmap(cr->cobj(), liveplay_canvas->get_window()->gobj(), a.get_x(), a.get_y());
    cr->paint_with_alpha(pow(brightness_adj->get_value(),2.2));
    return false;
}
bool TransparentSlider::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
{
    auto window = get_window();

    Cairo::RectangleInt window_size;
    Cairo::RectangleInt clip;
    double x1, y1, x2, y2;
    cr->get_clip_extents(x1, y1, x2, y2);

    clip.height = _round(y2-y1);
    clip.width = _round(x2-x1);
    clip.x = _round(x1);
    clip.y = _round(y1);

    window_size.x = 0;
    window_size.y = 0;
    window_size.height = window->get_height();
    window_size.width = window->get_width();

    cr->save();

    if (_SUPPORTS_ALPHA) {
        cr->set_source_rgba(                    // transparent
                _adjustmentRed->get_value(),
                _adjustmentGreen->get_value(),
                _adjustmentBlue->get_value(),
                _adjustmentAlpha->get_value());
    } else {
        cr->set_source_rgb(                     // opaque
                _adjustmentRed->get_value(),
                _adjustmentGreen->get_value(),
                _adjustmentBlue->get_value());
    }
    cr->set_operator(Cairo::OPERATOR_SOURCE);

    if (clip.height==window_size.height && clip.width==window_size.width && clip.x==window_size.x && clip.y==window_size.y) {
    } else {
        window->invalidate(true);
    }
    cr->reset_clip();
    cr->paint();
    cr->restore();

    return Gtk::Window::on_draw(cr);
}
void HistogramDrawingArea::DrawSingleHistogramLine( 
    Cairo::RefPtr<Cairo::Context> refCairo,
    ImageStatistics::StatisticsChannel channel )
{       
    unsigned int rangeMin, rangeMax, pixelValueMin, pixelValueMax;
    unsigned int numPixelValues;
    float pixelValueMean;
    int* pHistogram;

    m_histogramStats.GetStatistics( 
        channel,
        &rangeMin,
        &rangeMax,
        &pixelValueMin,
        &pixelValueMax,
        &numPixelValues,
        &pixelValueMean,
        &pHistogram );    
           
    std::vector<float> percentages = GetPercentages( numPixelValues, pHistogram );

    refCairo->save();

    // Reserve the outside 10%
    float paddedLeft, paddedTop, paddedWidth, paddedHeight;
    GetPaddedSize( paddedLeft, paddedTop, paddedWidth, paddedHeight ); 

    const float xScale = static_cast<float>(paddedWidth / numPixelValues);
    const float yScale = paddedHeight / static_cast<float>(m_maxVal);

    // Set draw color
    double red, green, blue;
    GetLineColor( channel, red, green, blue );
    refCairo->set_source_rgb(red, green, blue);

    // Set line width
    refCairo->set_line_width(1.0);

    if ( numPixelValues > 256 )
    {        
        const int k_pixelsToAvg = static_cast<int>(numPixelValues / paddedWidth);

        for ( unsigned int i=0; i < numPixelValues; i += k_pixelsToAvg )
        {
            float maxVal = 0.0;
            for ( int j=0; j < k_pixelsToAvg; j++ )
            {
                if ( i+j >= numPixelValues )
                {
                    break;
                }

                if ( percentages[i+j] > maxVal )
                {
                    maxVal = percentages[i+j];
                }
            }

            // Calculate the scaled height of the current percentage
            float yScaledHeight = yScale * maxVal;

            if ( i == 0 )
            {
                refCairo->move_to( paddedLeft, (paddedTop + paddedHeight - yScaledHeight) );
            }

            refCairo->line_to( paddedLeft + (xScale * i), paddedTop + paddedHeight - yScaledHeight );    
        }
    }
    else
    {
        for ( unsigned int i=0; i < numPixelValues; i++ )
        {
            // Calculate the scaled height of the current percentage
            float yScaledHeight = yScale * percentages[i];

            if ( i == 0 )
            {
                refCairo->move_to( paddedLeft, (paddedTop + paddedHeight - yScaledHeight) );
            }

            refCairo->line_to( paddedLeft + (xScale * i), paddedTop + paddedHeight - yScaledHeight );    
        }
    }    
   
    refCairo->stroke();

    // Overwrite anything that appears on the paddedTop section
    refCairo->rectangle(
        paddedLeft, 
        0,
        paddedWidth, 
        paddedTop );

    refCairo->set_source_rgb( 255, 255, 255 );

    refCairo->set_operator( Cairo::OPERATOR_OVER );

    refCairo->fill();    

    refCairo->restore();
}
示例#9
0
文件: ImageDrawable.cpp 项目: lp0/fiv
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;
	}
}