"Fossies" - the Fresh Open Source Software Archive

Member "rawtherapee-5.7/rtgui/previewwindow.cc" (10 Sep 2019, 9264 Bytes) of package /linux/misc/rawtherapee-5.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "previewwindow.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.6_vs_5.7.

    1 /*
    2  *  This file is part of RawTherapee.
    3  *
    4  *  Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
    5  *
    6  *  RawTherapee is free software: you can redistribute it and/or modify
    7  *  it under the terms of the GNU General Public License as published by
    8  *  the Free Software Foundation, either version 3 of the License, or
    9  *  (at your option) any later version.
   10  *
   11  *  RawTherapee is distributed in the hope that it will be useful,
   12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  *  GNU General Public License for more details.
   15  *
   16  *  You should have received a copy of the GNU General Public License
   17  *  along with RawTherapee.  If not, see <https://www.gnu.org/licenses/>.
   18  */
   19 #include "previewwindow.h"
   20 #include "guiutils.h"
   21 #include "imagearea.h"
   22 #include "cursormanager.h"
   23 
   24 #include "../rtengine/procparams.h"
   25 
   26 PreviewWindow::PreviewWindow () : previewHandler(nullptr), mainCropWin(nullptr), imageArea(nullptr), imgX(0), imgY(0), imgW(0), imgH(0),
   27     zoom(0.0), press_x(0), press_y(0), isMoving(false), needsUpdate(false), cursor_type(CSUndefined)
   28 
   29 {
   30     set_name("PreviewWindow");
   31     get_style_context()->add_class("drawingarea");
   32     rconn = signal_size_allocate().connect( sigc::mem_fun(*this, &PreviewWindow::on_resized) );
   33 }
   34 
   35 void PreviewWindow::on_realize ()
   36 {
   37 
   38     Gtk::DrawingArea::on_realize ();
   39     add_events(Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
   40 }
   41 
   42 void PreviewWindow::getObservedFrameArea (int& x, int& y, int& w, int& h)
   43 {
   44 
   45     if (mainCropWin) {
   46         int cropX, cropY, cropW, cropH;
   47         mainCropWin->getCropRectangle (cropX, cropY, cropW, cropH);
   48         // translate it to screen coordinates
   49         x = imgX + round(cropX * zoom);
   50         y = imgY + round(cropY * zoom);
   51         w = round(cropW * zoom);
   52         h = round(cropH * zoom);
   53     }
   54 }
   55 
   56 void PreviewWindow::updatePreviewImage ()
   57 {
   58 
   59     int W = get_width(), H = get_height();
   60     Glib::RefPtr<Gdk::Window> wind = get_window();
   61 
   62     if( ! wind ) {
   63         needsUpdate = true;
   64         return;
   65     }
   66 
   67     backBuffer = Cairo::RefPtr<BackBuffer> ( new BackBuffer(W, H, Cairo::FORMAT_ARGB32) );
   68     Cairo::RefPtr<Cairo::ImageSurface> surface = backBuffer->getSurface();
   69     Glib::RefPtr<Gtk::StyleContext> style = get_style_context();
   70     Cairo::RefPtr<Cairo::Context> cc = Cairo::Context::create(surface);
   71     cc->set_source_rgba (0., 0., 0., 0.);
   72     cc->set_operator (Cairo::OPERATOR_CLEAR);
   73     cc->paint ();
   74     cc->set_operator (Cairo::OPERATOR_OVER);
   75     cc->set_antialias(Cairo::ANTIALIAS_NONE);
   76     cc->set_line_join(Cairo::LINE_JOIN_MITER);
   77 
   78     if (previewHandler) {
   79         Glib::RefPtr<Gdk::Pixbuf> resPixbuf = previewHandler->getRoughImage (W, H, zoom);
   80 
   81         if (resPixbuf) {
   82             imgW = resPixbuf->get_width();
   83             imgH = resPixbuf->get_height();
   84             imgX = (W - imgW) / 2;
   85             imgY = (H - imgH) / 2;
   86             Gdk::Cairo::set_source_pixbuf(cc, resPixbuf, imgX, imgY);
   87             cc->rectangle(imgX, imgY, imgW, imgH);
   88             cc->fill();
   89 
   90             if (previewHandler->getCropParams().enabled) {
   91                 rtengine::CropParams cparams = previewHandler->getCropParams();
   92                 switch (options.cropGuides) {
   93                 case Options::CROP_GUIDE_NONE:
   94                     cparams.guide = "None";
   95                     break;
   96                 case Options::CROP_GUIDE_FRAME:
   97                     cparams.guide = "Frame";
   98                     break;
   99                 default:
  100                     break;
  101                 }
  102                 drawCrop (cc, imgX, imgY, imgW, imgH, 0, 0, zoom, cparams, true, false);
  103             }
  104         }
  105     }
  106 }
  107 
  108 void PreviewWindow::setPreviewHandler (PreviewHandler* ph)
  109 {
  110 
  111     previewHandler = ph;
  112 
  113     if (previewHandler) {
  114         previewHandler->addPreviewImageListener (this);
  115     }
  116 }
  117 
  118 void PreviewWindow::on_resized (Gtk::Allocation& req)
  119 {
  120 
  121     updatePreviewImage ();
  122     queue_draw ();
  123 }
  124 
  125 bool PreviewWindow::on_draw(const ::Cairo::RefPtr< Cairo::Context> &cr)
  126 {
  127     const Glib::RefPtr<Gtk::StyleContext> style = get_style_context();
  128     style->render_background(cr, 0, 0, get_width(), get_height());
  129 
  130     if (!backBuffer) {
  131         return true;
  132     }
  133 
  134     int bufferW, bufferH;
  135     bufferW = backBuffer->getWidth();
  136     bufferH = backBuffer->getHeight();
  137 
  138     if (!mainCropWin && imageArea) {
  139         mainCropWin = imageArea->getMainCropWindow ();
  140 
  141         if (mainCropWin) {
  142             mainCropWin->addCropWindowListener (this);
  143         }
  144     }
  145 
  146     if ((get_width() != bufferW && get_height() != bufferH) || needsUpdate) {
  147         needsUpdate = false;
  148         updatePreviewImage ();
  149     }
  150 
  151     backBuffer->copySurface(cr, NULL);
  152 
  153     if (mainCropWin && zoom > 0.0) {
  154         int x, y, w, h;
  155         getObservedFrameArea (x, y, w, h);
  156         if (x>imgX || y>imgY || w < imgW || h < imgH) {
  157             double s = RTScalable::getScale();
  158             double rectX = x + 0.5;
  159             double rectY = y + 0.5;
  160             double rectW = std::min(w, (int)(imgW - (x - imgX) - 1));
  161             double rectH = std::min(h, (int)(imgH - (y - imgY) - 1));
  162 
  163             // draw a black "shadow" line
  164             cr->set_source_rgba (0.0, 0.0, 0.0, 0.65);
  165             cr->set_line_width (1. * s);
  166             cr->set_line_join(Cairo::LINE_JOIN_MITER);
  167             cr->rectangle (rectX + 1. * s, rectY + 1. * s, rectW - 2. * s, rectH - 2. * s);
  168             cr->stroke ();
  169 
  170             // draw a "frame" line. Color of frame line can be set in preferences
  171             cr->set_source_rgba(options.navGuideBrush[0], options.navGuideBrush[1], options.navGuideBrush[2], options.navGuideBrush[3]); //( 1.0, 1.0, 1.0, 1.0);
  172             cr->rectangle (rectX, rectY, rectW, rectH);
  173             cr->stroke ();
  174         }
  175     }
  176 
  177     style->render_frame (cr, 0, 0, get_width(), get_height());
  178 
  179     return true;
  180 }
  181 
  182 void PreviewWindow::previewImageChanged ()
  183 {
  184 
  185     updatePreviewImage ();
  186     queue_draw ();
  187 }
  188 
  189 void PreviewWindow::setImageArea (ImageArea* ia)
  190 {
  191 
  192     imageArea = ia;
  193     mainCropWin = ia->getMainCropWindow ();
  194 
  195     if (mainCropWin) {
  196         mainCropWin->addCropWindowListener (this);
  197     }
  198 }
  199 
  200 void PreviewWindow::cropPositionChanged(CropWindow* w)
  201 {
  202     queue_draw ();
  203 }
  204 
  205 void PreviewWindow::cropWindowSizeChanged(CropWindow* w)
  206 {
  207     queue_draw ();
  208 }
  209 
  210 void PreviewWindow::cropZoomChanged(CropWindow* w)
  211 {
  212     queue_draw ();
  213 }
  214 
  215 void PreviewWindow::initialImageArrived()
  216 {
  217 }
  218 
  219 bool PreviewWindow::on_motion_notify_event (GdkEventMotion* event)
  220 {
  221 
  222     if (!mainCropWin) {
  223         return true;
  224     }
  225 
  226     int x, y, w, h;
  227     getObservedFrameArea (x, y, w, h);
  228     if (x>imgX || y>imgY || w < imgW || h < imgH) {
  229         bool inside =     event->x > x - 6 && event->x < x + w - 1 + 6 && event->y > y - 6 && event->y < y + h - 1 + 6;
  230 
  231         CursorShape newType = cursor_type;
  232 
  233         if (isMoving) {
  234             mainCropWin->remoteMove ((event->x - press_x) / zoom, (event->y - press_y) / zoom);
  235             press_x = event->x;
  236             press_y = event->y;
  237             newType = CSHandClosed;
  238         } else if (inside) {
  239             newType = CSHandOpen;
  240         } else {
  241             newType = CSArrow;
  242         }
  243 
  244         if (newType != cursor_type) {
  245             cursor_type = newType;
  246             CursorManager::setWidgetCursor(get_window(), cursor_type);
  247         }
  248     }
  249 
  250     return true;
  251 }
  252 
  253 bool PreviewWindow::on_button_press_event (GdkEventButton* event)
  254 {
  255 
  256     if (!mainCropWin) {
  257         return true;
  258     }
  259 
  260     int x, y, w, h;
  261     getObservedFrameArea (x, y, w, h);
  262     if (x>imgX || y>imgY || w < imgW || h < imgH) {
  263 
  264         if (!isMoving) {
  265             isMoving = true;
  266 
  267             press_x = event->x;
  268             press_y = event->y;
  269 
  270             if (cursor_type != CSHandClosed) {
  271                 cursor_type = CSHandClosed;
  272                 CursorManager::setWidgetCursor(get_window(), cursor_type);
  273             }
  274         }
  275     }
  276 
  277     return true;
  278 }
  279 
  280 bool PreviewWindow::on_button_release_event (GdkEventButton* event)
  281 {
  282 
  283     if (!mainCropWin) {
  284         return true;
  285     }
  286 
  287     if (isMoving) {
  288         isMoving = false;
  289 
  290         if (cursor_type != CSArrow) {
  291             cursor_type = CSArrow;
  292             CursorManager::setWidgetCursor(get_window(), cursor_type);
  293         }
  294 
  295         mainCropWin->remoteMoveReady ();
  296     }
  297 
  298     return true;
  299 }
  300 
  301 Gtk::SizeRequestMode PreviewWindow::get_request_mode_vfunc () const
  302 {
  303     return Gtk::SIZE_REQUEST_CONSTANT_SIZE;
  304 }
  305 
  306 void PreviewWindow::get_preferred_height_vfunc (int &minimum_height, int &natural_height) const
  307 {
  308     minimum_height= 50 * RTScalable::getScale();
  309     natural_height = 100 * RTScalable::getScale();
  310 }
  311 
  312 void PreviewWindow::get_preferred_width_vfunc (int &minimum_width, int &natural_width) const
  313 {
  314     minimum_width = 80 * RTScalable::getScale();
  315     natural_width = 120 * RTScalable::getScale();
  316 }
  317 
  318 void PreviewWindow::get_preferred_height_for_width_vfunc (int width, int &minimum_height, int &natural_height) const
  319 {
  320     get_preferred_height_vfunc(minimum_height, natural_height);
  321 }
  322 
  323 void PreviewWindow::get_preferred_width_for_height_vfunc (int height, int &minimum_width, int &natural_width) const
  324 {
  325     get_preferred_width_vfunc (minimum_width, natural_width);
  326 }