void Thing::RestoreContext(Cairo::RefPtr<Cairo::Context> myCr) const { myCr->rotate_degrees(-orientationAngle); myCr->translate(-position[0], -position[1]); myCr->scale(1/scalingFactor, 1/scalingFactor); }
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 Thing::TransformContext(Cairo::RefPtr<Cairo::Context> myCr) const { myCr->scale(scalingFactor, scalingFactor); myCr->translate(position[0], position[1]); myCr->rotate_degrees(-orientationAngle); }