From 65a21f56583073a5dbee67e1fea6fd080bdc0a18 Mon Sep 17 00:00:00 2001 From: Nathan Lee <2431820-nathanal@users.noreply.gitlab.com> Date: Wed, 24 Jul 2019 09:02:23 +0200 Subject: Allow scaling down trace dialog --- src/ui/dialog/tracedialog.cpp | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/tracedialog.cpp b/src/ui/dialog/tracedialog.cpp index 3d92c53c9..00c461def 100644 --- a/src/ui/dialog/tracedialog.cpp +++ b/src/ui/dialog/tracedialog.cpp @@ -51,6 +51,7 @@ class TraceDialogImpl2 : public TraceDialog { void abort(); void previewCallback(); + bool previewResize(const Cairo::RefPtr&); void traceCallback(); void onSelectionModified(guint flags); void onSetDefaults(); @@ -76,7 +77,8 @@ class TraceDialogImpl2 : public TraceDialog { Gtk::Box *mainBox; Gtk::Stack *choice_scan; Gtk::Notebook *choice_tab; - Gtk::Image *previewImage; + Glib::RefPtr scaledPreview; + Gtk::DrawingArea *previewArea; }; void TraceDialogImpl2::setDesktop(SPDesktop *desktop) @@ -181,15 +183,14 @@ void TraceDialogImpl2::traceProcess(bool do_i_trace) if (preview) { int width = preview->get_width(); int height = preview->get_height(); - const Gtk::Allocation &vboxAlloc = previewImage->get_allocation(); + const Gtk::Allocation &vboxAlloc = previewArea->get_allocation(); double scaleFX = vboxAlloc.get_width() / (double)width; double scaleFY = vboxAlloc.get_height() / (double)height; double scaleFactor = scaleFX > scaleFY ? scaleFY : scaleFX; int newWidth = (int)(((double)width) * scaleFactor); int newHeight = (int)(((double)height) * scaleFactor); - Glib::RefPtr scaledPreview = preview->scale_simple(newWidth, newHeight, Gdk::INTERP_NEAREST); - // g_object_unref(preview); - previewImage->set(scaledPreview); + scaledPreview = preview->scale_simple(newWidth, newHeight, Gdk::INTERP_NEAREST); + previewArea->queue_draw(); } } if (do_i_trace){ @@ -209,6 +210,26 @@ void TraceDialogImpl2::traceProcess(bool do_i_trace) desktop->clearWaitingCursor(); } +bool TraceDialogImpl2::previewResize(const Cairo::RefPtr& cr) +{ + if (!scaledPreview) return false; // return early + int width = scaledPreview->get_width(); + int height = scaledPreview->get_height(); + const Gtk::Allocation &vboxAlloc = previewArea->get_allocation(); + double scaleFX = vboxAlloc.get_width() / (double)width; + double scaleFY = vboxAlloc.get_height() / (double)height; + double scaleFactor = scaleFX > scaleFY ? scaleFY : scaleFX; + int newWidth = (int)(((double)width) * scaleFactor); + int newHeight = (int)(((double)height) * scaleFactor); + int offsetX = (vboxAlloc.get_width() - newWidth)/2; + int offsetY = (vboxAlloc.get_height() - newHeight)/2; + + Glib::RefPtr temp = scaledPreview->scale_simple(newWidth, newHeight, Gdk::INTERP_NEAREST); + Gdk::Cairo::set_source_pixbuf(cr, temp, offsetX, offsetY); + cr->paint(); + return false; +} + void TraceDialogImpl2::abort() { SPDesktop *desktop = SP_ACTIVE_DESKTOP; @@ -263,7 +284,7 @@ TraceDialogImpl2::TraceDialogImpl2() "CB_MS_stack", "CB_MS_rb", "CB_speckles", "CB_smooth", "CB_optimize", /*"CB_live",*/ "CB_SIOX", "CBT_SS", "CBT_MS", "B_RESET", "B_STOP", "B_OK", "mainBox", "choice_tab", "choice_scan", - "previewImage" }; + "previewArea" }; Glib::ustring gladefile = get_filename(Inkscape::IO::Resource::UIS, "dialog-trace.glade"); try { builder = Gtk::Builder::create_from_file(gladefile); @@ -271,6 +292,7 @@ TraceDialogImpl2::TraceDialogImpl2() g_warning("Glade file loading failed for filter effect dialog"); return; } + Glib::RefPtr test; for (std::string w : req_widgets) { test = builder->get_object(w); @@ -320,7 +342,7 @@ TraceDialogImpl2::TraceDialogImpl2() GET_W(mainBox) GET_W(choice_tab) GET_W(choice_scan) - GET_W(previewImage) + GET_W(previewArea) #undef GET_W #undef GET_O _getContents()->add(*mainBox); @@ -332,6 +354,7 @@ TraceDialogImpl2::TraceDialogImpl2() B_OK->signal_clicked().connect(sigc::mem_fun(*this, &TraceDialogImpl2::traceCallback)); B_STOP->signal_clicked().connect(sigc::mem_fun(*this, &TraceDialogImpl2::abort)); B_RESET->signal_clicked().connect(sigc::mem_fun(*this, &TraceDialogImpl2::onSetDefaults)); + previewArea->signal_draw().connect(sigc::mem_fun(*this, &TraceDialogImpl2::previewResize)); } -- cgit v1.2.3