"Fossies" - the Fresh Open Source Software Archive

Member "darktable-2.6.3/src/gui/color_picker_proxy.c" (20 Oct 2019, 4205 Bytes) of package /linux/misc/darktable-2.6.3.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 "color_picker_proxy.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.6.3_vs_3.0.0.rc0.

    1 /*
    2     This file is part of darktable,
    3     copyright (c) 2018 Pascal Obry.
    4 
    5     darktable is free software: you can redistribute it and/or modify
    6     it under the terms of the GNU Lesser General Public License as published by
    7     the Free Software Foundation, either version 3 of the License, or
    8     (at your option) any later version.
    9 
   10     darktable is distributed in the hope that it will be useful,
   11     but WITHOUT ANY WARRANTY; without even the implied warranty of
   12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13     GNU Lesser General Public License for more details.
   14 
   15     You should have received a copy of the GNU Lesser General Public License
   16     along with darktable.  If not, see <http://www.gnu.org/licenses/>.
   17 */
   18 
   19 #include "gui/color_picker_proxy.h"
   20 #include "libs/lib.h"
   21 #include "control/control.h"
   22 
   23 /* a callback for the "draw" signal on the main IOP widget (self->widget) passed to gui_init. this is
   24    to used to apply the picked value (requested in dt_iop_color_picker_callback) when available. */
   25 static gboolean _iop_color_picker_draw(GtkWidget *widget, cairo_t *cr, dt_iop_color_picker_t *self);
   26 
   27 void dt_iop_color_picker_reset(dt_iop_color_picker_t *picker, gboolean update)
   28 {
   29   picker->module->request_color_pick = DT_REQUEST_COLORPICK_OFF;
   30   picker->reset(picker->module);
   31   if (update) picker->update(picker->module);
   32 }
   33 
   34 int dt_iop_color_picker_get_set(dt_iop_color_picker_t *picker, GtkWidget *button)
   35 {
   36   return picker->get_set(picker->module, button);
   37 }
   38 
   39 void dt_iop_color_picker_apply(dt_iop_color_picker_t *picker)
   40 {
   41   picker->apply(picker->module);
   42 }
   43 
   44 void dt_iop_color_picker_update(dt_iop_color_picker_t *picker)
   45 {
   46   picker->update(picker->module);
   47 }
   48 
   49 void init_picker (dt_iop_color_picker_t *picker,
   50                   dt_iop_module_t *module,
   51                   int (*get_set)(dt_iop_module_t *self, GtkWidget *button),
   52                   void (*apply)(dt_iop_module_t *self),
   53                   void (*reset)(dt_iop_module_t *self),
   54                   void (*update)(dt_iop_module_t *self))
   55 {
   56   picker->module  = module;
   57   picker->get_set = get_set;
   58   picker->apply   = apply;
   59   picker->reset   = reset;
   60   picker->update  = update;
   61 
   62   dt_iop_color_picker_reset(picker, TRUE);
   63 
   64   /* The widget receives a draw signal right before being applied in
   65      the pipeline. This is when we want to take into account the  picked color. */
   66   g_signal_connect(G_OBJECT(picker->module->widget), "draw", G_CALLBACK(_iop_color_picker_draw), picker);
   67 }
   68 
   69 void dt_iop_color_picker_callback(GtkWidget *button, dt_iop_color_picker_t *self)
   70 {
   71   if(self->module->dt->gui->reset) return;
   72 
   73   // set module active if not yet the case
   74   if(self->module->off) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self->module->off), 1);
   75 
   76   // get the current color picker (a module can have multiple one)
   77   // should returns -1 if the same picker was already selected.
   78   const int clicked_colorpick = self->get_set(self->module, button);
   79 
   80   if(self->module->request_color_pick == DT_REQUEST_COLORPICK_OFF || clicked_colorpick != ALREADY_SELECTED)
   81   {
   82     self->module->request_color_pick = DT_REQUEST_COLORPICK_MODULE;
   83     dt_lib_colorpicker_set_area(darktable.lib, 0.99);
   84     dt_dev_reprocess_all(self->module->dev);
   85   }
   86   else
   87   {
   88     /* focus on the center area, to force a redraw when focus on module is called below */
   89     dt_iop_color_picker_reset(self, FALSE);
   90   }
   91   self->update(self->module);
   92   dt_control_queue_redraw();
   93   dt_iop_request_focus(self->module);
   94 }
   95 
   96 static gboolean _iop_color_picker_draw(GtkWidget *widget, cairo_t *cr, dt_iop_color_picker_t *self)
   97 {
   98   if(darktable.gui->reset) return FALSE;
   99 
  100   /* No color picked, or picked color already applied */
  101   if(self->module->picked_color_max[0] < 0.0f) return FALSE;
  102 
  103   self->apply(self->module);
  104   /* Make sure next call won't re-apply in loop: draw -> picker -> set_sliders -> draw. */
  105   self->module->picked_color_max[0] = -INFINITY;
  106 
  107   return FALSE;
  108 }
  109 
  110 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
  111 // vim: shiftwidth=2 expandtab tabstop=2 cindent
  112 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;