[Bf-blender-cvs] [27efbf447ff] greasepencil-object: GPencil: Basic structure for Tint Tool
Antonio Vazquez
noreply at git.blender.org
Sat Nov 2 17:24:51 CET 2019
Commit: 27efbf447ff4ef87fd74c6767e289887d9188369
Author: Antonio Vazquez
Date: Sat Nov 2 14:08:28 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB27efbf447ff4ef87fd74c6767e289887d9188369
GPencil: Basic structure for Tint Tool
Still not working, but all pieces put in place.
===================================================================
M release/scripts/presets/keyconfig/keymap_data/blender_default.py
M release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
M source/blender/blenkernel/intern/brush.c
M source/blender/editors/gpencil/CMakeLists.txt
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_ops.c
A source/blender/editors/gpencil/gpencil_tint.c
M source/blender/editors/interface/interface_icons.c
M source/blender/makesdna/DNA_brush_types.h
M source/blender/makesrna/intern/rna_brush.c
===================================================================
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index aeefd710337..6cb8e31e546 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -3282,7 +3282,10 @@ def km_grease_pencil_stroke_paint_tint(params):
items.extend([
# Tint
- ("gpencil.tint", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
+ ("gpencil.tint", {"type": 'LEFTMOUSE', "value": 'PRESS'},
+ {"properties": [("wait_for_input", False)]}),
+ ("gpencil.tint", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
+ {"properties": [("wait_for_input", False)]}),
])
return keymap
diff --git a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
index 7d5250b85fe..0ecffefc2b9 100644
--- a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
+++ b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
@@ -2471,7 +2471,10 @@ def km_grease_pencil_stroke_paint_tint(params):
items.extend([
# Tint
- ("gpencil.tint", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
+ ("gpencil.tint", {"type": 'LEFTMOUSE', "value": 'PRESS'},
+ {"properties": [("wait_for_input", False)]}),
+ ("gpencil.tint", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
+ {"properties": [("wait_for_input", False)]}),
])
return keymap
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 0834656a88d..297060c1f5b 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -642,6 +642,21 @@ void BKE_brush_gpencil_presets(Main *bmain, ToolSettings *ts)
brush->gpencil_settings->icon_id = GP_BRUSH_ICON_ERASE_STROKE;
brush->gpencil_tool = GPAINT_TOOL_ERASE;
+ /* Tint brush. */
+ brush = BLI_findstring(&bmain->brushes, "Tint", offsetof(ID, name) + 2);
+ if (brush == NULL) {
+ brush = BKE_brush_add_gpencil(bmain, ts, "Tint");
+ }
+
+ brush->size = 25.0f;
+ brush->gpencil_settings->flag |= (GP_BRUSH_USE_PRESSURE | GP_BRUSH_ENABLE_CURSOR);
+
+ brush->gpencil_settings->draw_strength = 0.6f;
+ brush->gpencil_settings->flag |= GP_BRUSH_USE_STENGTH_PRESSURE;
+
+ brush->gpencil_settings->icon_id = GP_BRUSH_ICON_TINT;
+ brush->gpencil_tool = GPAINT_TOOL_TINT;
+
/* set default brush. */
BKE_paint_brush_set(paint, deft);
}
diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt
index 0ba081de8ca..81443cb4968 100644
--- a/source/blender/editors/gpencil/CMakeLists.txt
+++ b/source/blender/editors/gpencil/CMakeLists.txt
@@ -48,6 +48,7 @@ set(SRC
gpencil_data.c
gpencil_edit.c
gpencil_fill.c
+ gpencil_tint.c
gpencil_interpolate.c
gpencil_merge.c
gpencil_ops.c
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index c7a3b32b866..93d5db28ab4 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -365,6 +365,7 @@ void GPENCIL_OT_annotate(struct wmOperatorType *ot);
void GPENCIL_OT_draw(struct wmOperatorType *ot);
void GPENCIL_OT_fill(struct wmOperatorType *ot);
+void GPENCIL_OT_tint(struct wmOperatorType *ot);
/* Guides ----------------------- */
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 2c8a1b2192f..60ffbe8cff3 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -240,6 +240,7 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_draw);
WM_operatortype_append(GPENCIL_OT_fill);
+ WM_operatortype_append(GPENCIL_OT_tint);
/* Guides ----------------------- */
diff --git a/source/blender/editors/gpencil/gpencil_tint.c b/source/blender/editors/gpencil/gpencil_tint.c
new file mode 100644
index 00000000000..cb70006ce9b
--- /dev/null
+++ b/source/blender/editors/gpencil/gpencil_tint.c
@@ -0,0 +1,913 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2015, Blender Foundation
+ * This is a new part of Blender
+ * Brush based operators for editing Grease Pencil strokes
+ */
+
+/** \file
+ * \ingroup edgpencil
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+
+#include "BLT_translation.h"
+
+#include "DNA_brush_types.h"
+#include "DNA_gpencil_types.h"
+
+#include "BKE_colortools.h"
+#include "BKE_context.h"
+#include "BKE_gpencil.h"
+#include "BKE_gpencil_modifier.h"
+#include "BKE_material.h"
+#include "BKE_report.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "UI_view2d.h"
+
+#include "ED_gpencil.h"
+#include "ED_screen.h"
+#include "ED_view3d.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "gpencil_intern.h"
+
+/* ************************************************ */
+/* General Brush Editing Context */
+
+/* Context for brush operators */
+typedef struct tGP_BrushTintData {
+ /* Current editor/region/etc. */
+ /* NOTE: This stuff is mainly needed to handle 3D view projection stuff... */
+ struct Main *bmain;
+ Scene *scene;
+ Object *object;
+
+ ScrArea *sa;
+ ARegion *ar;
+
+ /* Current GPencil datablock */
+ bGPdata *gpd;
+
+ Brush *brush;
+ eGP_Sculpt_Flag flag;
+
+ /* Space Conversion Data */
+ GP_SpaceConversion gsc;
+
+ /* Is the brush currently painting? */
+ bool is_painting;
+ bool is_transformed;
+
+ /* Start of new tint */
+ bool first;
+
+ /* Is multiframe editing enabled, and are we using falloff for that? */
+ bool is_multiframe;
+ bool use_multiframe_falloff;
+
+ /* Brush Runtime Data: */
+ /* - position and pressure
+ * - the *_prev variants are the previous values
+ */
+ float mval[2], mval_prev[2];
+ float pressure, pressure_prev;
+
+ /* - effect vector */
+ float dvec[3];
+
+ /* rotation for evaluated data */
+ float rot_eval;
+
+ /* - multiframe falloff factor */
+ float mf_falloff;
+
+ /* brush geometry (bounding box) */
+ rcti brush_rect;
+
+ /* Object invert matrix */
+ float inv_mat[4][4];
+
+} tGP_BrushTintData;
+
+/* Callback for performing some brush operation on a single point */
+typedef bool (*GP_TintApplyCb)(tGP_BrushTintData *gso,
+ bGPDstroke *gps,
+ float rotation,
+ int pt_index,
+ const int radius,
+ const int co[2]);
+
+/* Brush Operations ------------------------------- */
+
+/* Invert behavior of brush? */
+static bool brush_invert_check(tGP_BrushTintData *gso)
+{
+ /* The basic setting is no inverted */
+ bool invert = false;
+
+ /* During runtime, the user can hold down the Ctrl key to invert the basic behavior */
+ if (gso->flag & GP_SCULPT_FLAG_INVERT) {
+ invert ^= true;
+ }
+
+ return invert;
+}
+
+/* Compute strength of effect. */
+static float brush_influence_calc(tGP_BrushTintData *gso, const int radius, const int co[2])
+{
+ Brush *brush = gso->brush;
+ float influence = brush->size;
+
+ /* use pressure? */
+ if (brush->flag & GP_SCULPT_FLAG_USE_PRESSURE) {
+ influence *= gso->pressure;
+ }
+
+ /* distance fading */
+ if (brush->flag & GP_SCULPT_FLAG_USE_FALLOFF) {
+ int mval_i[2];
+ round_v2i_v2fl(mval_i, gso->mval);
+ float distance = (float)len_v2v2_int(mval_i, co);
+ float fac;
+
+ CLAMP(distance, 0.0f, (float)radius);
+ fac = 1.0f - (distance / (float)radius);
+
+ influence *= fac;
+ }
+
+ /* apply multiframe falloff */
+ influence *= gso->mf_falloff;
+
+ /* return influence */
+ return influence;
+}
+
+/* Compute effect vector for directional brushes. */
+static void brush_grab_calc_dvec(tGP_BrushTintData *gso)
+{
+ /* Convert mouse-movements to movement vector */
+ RegionView3D *rv3d = gso->ar->regiondata;
+ float *rvec = gso->object->loc;
+ float zfac = ED_view3d_calc_zfac(rv3d, rvec, NULL);
+
+ float mval_f[2];
+
+ /* convert from 2D screenspace to 3D... */
+ mval_f[0] = (float)(gso->mval[0] - gso->mval_prev[0]);
+ mval_f[1] = (float)(gso->mval[1] - gso->mval_prev[1]);
+
+ /* apply evaluated data transformation */
+ if (gso->rot_eval != 0.0f) {
+ const float cval = cos(gso->rot_eval);
+ const float sval = sin(gso->rot_eval);
+ float r[2];
+ r[0] = (mval_f[0] * cval) - (mval_f[1] * sval);
+ r[1] = (mval_f[0] * sval) + (mval_f[1] * cval);
+ copy_v2_v2(mval_f, r);
+ }
+
+ ED_view3d_win_to_delta(gso->ar, mval_f, gso->dvec, zfac);
+}
+
+/* ************************************************ */
+/* Brush Callbacks
+/* This section defines the callbacks used by each brush to perform their magic.
+ * These are called on each point within the brush's radius. */
+
+/* Tint Brush */
+static bool brush_tint_apply(tGP_BrushTintData *gso,
+ bGPDstroke *gps,
+ float UNUSED(rot_eval),
+ int pt_index,
+ const int radius,
+ const int co[2])
+{
+ float inf;
+ /* Compute strength of effect
+ * - We divide the strength by 10, so that users can set "sa
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list