[Bf-blender-cvs] [017d36b5574] greasepencil-object: GPencil: More work to make Tint operator
Antonio Vazquez
noreply at git.blender.org
Sat Nov 2 17:24:53 CET 2019
Commit: 017d36b5574d9093b5ac065be4eafccba18e035f
Author: Antonio Vazquez
Date: Sat Nov 2 16:56:37 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB017d36b5574d9093b5ac065be4eafccba18e035f
GPencil: More work to make Tint operator
===================================================================
M release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M release/scripts/startup/bl_ui/space_view3d.py
M release/scripts/startup/bl_ui/space_view3d_toolbar.py
M source/blender/blenkernel/intern/brush.c
M source/blender/editors/gpencil/gpencil_tint.c
M source/blender/editors/gpencil/gpencil_utils.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 2a6b1b42e21..c271512d150 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -19,7 +19,7 @@
# <pep8 compliant>
import bpy
-from bpy.types import Menu, UIList
+from bpy.types import Menu, UIList, Operator
from bpy.app.translations import pgettext_iface as iface_
@@ -912,7 +912,7 @@ class GreasePencilMaterialsPanel:
row.prop(gpcolor, "color", text="Stroke Color")
# Mix color
- if is_view3d and brush is not None:
+ if is_view3d and brush is not None and brush.gpencil_tool == 'DRAW':
if gpcolor.stroke_style == 'SOLID' or gpcolor.use_stroke_pattern:
gp_settings = brush.gpencil_settings
row = layout.row()
@@ -989,6 +989,35 @@ class GreasePencilSimplifyPanel:
sub.active = rd.simplify_gpencil_view_fill
sub.prop(rd, "simplify_gpencil_remove_lines", text="Lines")
+class GreasePencilFlipTintColors(Operator):
+ bl_label = "Flip Colors"
+ bl_idname = "gpencil.tint_flip"
+ bl_description = "Switch Tint colors"
+
+ def execute(self, context):
+ try:
+ ts = context.tool_settings
+ settings = ts.gpencil_paint
+ brush = settings.brush
+ if brush is not None:
+ color = brush.color
+ secondary_color = brush.secondary_color
+
+ orig_prim = color.hsv
+ orig_sec = secondary_color.hsv
+
+ color.hsv = orig_sec
+ secondary_color.hsv = orig_prim
+
+ return {'FINISHED'}
+
+ except Exception as e:
+ utils_core.error_handlers(self, "gpencil.tint_flip", e,
+ "Flip Colors could not be completed")
+
+ return {'CANCELLED'}
+
+
classes = (
GPENCIL_MT_pie_tool_palette,
@@ -1004,6 +1033,8 @@ classes = (
GPENCIL_UL_annotation_layer,
GPENCIL_UL_layer,
+
+ GreasePencilFlipTintColors,
)
if __name__ == "__main__": # only for live edit.
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index d6e47e4bee0..82478491e99 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -347,9 +347,11 @@ class _draw_tool_settings_context_mode:
row.prop(gp_settings, "use_material_pin", text="")
- if ma and (ma.grease_pencil.stroke_style != 'TEXTURE' or ma.grease_pencil.use_stroke_pattern):
- row.separator(factor=0.4)
- row.prop(gp_settings, "mix_color", text="")
+ if brush.gpencil_tool == 'DRAW':
+ if ma and (ma.grease_pencil.stroke_style != 'TEXTURE' or
+ ma.grease_pencil.use_stroke_pattern):
+ row.separator(factor=0.4)
+ row.prop(gp_settings, "mix_color", text="")
row = layout.row(align=True)
tool_settings = context.scene.tool_settings
@@ -359,6 +361,11 @@ class _draw_tool_settings_context_mode:
if context.object and brush.gpencil_tool in {'FILL', 'DRAW'}:
draw_color_selector()
+ if context.object and brush.gpencil_tool == 'TINT':
+ row.separator(factor=0.4)
+ row.label(text="Mix")
+ row.prop(brush, "color", text="")
+
from bl_ui.properties_paint_common import (
brush_basic_gpencil_paint_settings,
)
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index f23b9447775..14f0e0f5606 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -23,6 +23,7 @@ from bl_ui.properties_grease_pencil_common import (
GreasePencilStrokeSculptPanel,
GreasePencilSculptOptionsPanel,
GreasePencilAppearancePanel,
+ GreasePencilFlipTintColors,
)
from bl_ui.properties_paint_common import (
UnifiedPaintPanel,
@@ -1885,7 +1886,7 @@ class VIEW3D_PT_tools_grease_pencil_brush_option(View3DPanel, Panel):
@classmethod
def poll(cls, context):
brush = context.tool_settings.gpencil_paint.brush
- return brush is not None and brush.gpencil_tool not in {'ERASE', 'FILL'}
+ return brush is not None and brush.gpencil_tool not in {'ERASE', 'FILL', 'TINT'}
def draw_header_preset(self, _context):
VIEW3D_PT_gpencil_brush_presets.draw_panel_header(self.layout)
@@ -2038,7 +2039,13 @@ class VIEW3D_PT_tools_grease_pencil_brush_mixcolor(View3DPanel, Panel):
def poll(cls, context):
ob = context.object
brush = context.tool_settings.gpencil_paint.brush
- if ob is None or brush is None or brush.gpencil_tool != 'DRAW':
+ if ob is None or brush is None:
+ return False
+
+ if brush.gpencil_tool == 'TINT':
+ return True
+
+ if brush.gpencil_tool != 'DRAW':
return False
gp_settings = brush.gpencil_settings
@@ -2057,14 +2064,32 @@ class VIEW3D_PT_tools_grease_pencil_brush_mixcolor(View3DPanel, Panel):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
-
- settings = context.tool_settings.gpencil_paint
+ ts = context.tool_settings
+ settings = ts.gpencil_paint
brush = settings.brush
gp_settings = brush.gpencil_settings
row = layout.row(align=True)
- row.prop(gp_settings, "mix_color", text="")
- row = layout.row(align=True)
- row.template_color_picker(gp_settings, "mix_color", value_slider=True)
+
+ if brush.gpencil_tool == 'DRAW':
+ row.prop(gp_settings, "mix_color", text="")
+ row = layout.row(align=True)
+ row.template_color_picker(gp_settings, "mix_color", value_slider=True)
+
+ if brush.gpencil_tool == 'TINT':
+ row.prop(brush, "color", text="")
+ row = layout.row(align=True)
+ row.template_color_picker(brush, "color", value_slider=True)
+
+ sub_row = layout.row(align=True)
+ sub_row.prop(brush, "color", text="")
+ sub_row.prop(brush, "secondary_color", text="")
+
+ sub_row.operator("gpencil.tint_flip", icon='FILE_REFRESH', text="")
+
+ row = layout.row(align=True)
+ row.template_ID(ts.gpencil_paint, "palette", new="palette.new")
+ if settings.palette:
+ layout.template_palette(ts.gpencil_paint, "palette", color=True)
# Grease Pencil drawingcurves
@@ -2077,7 +2102,7 @@ class VIEW3D_PT_tools_grease_pencil_brushcurves(View3DPanel, Panel):
@classmethod
def poll(cls, context):
brush = context.tool_settings.gpencil_paint.brush
- return brush is not None and brush.gpencil_tool not in {'ERASE', 'FILL'}
+ return brush is not None and brush.gpencil_tool not in {'ERASE', 'FILL', 'TINT'}
def draw(self, context):
pass
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 297060c1f5b..0abc6cd6723 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -653,6 +653,9 @@ void BKE_brush_gpencil_presets(Main *bmain, ToolSettings *ts)
brush->gpencil_settings->draw_strength = 0.6f;
brush->gpencil_settings->flag |= GP_BRUSH_USE_STENGTH_PRESSURE;
+ brush->rgb[0] = 0.8f;
+ brush->rgb[1] = 0.5f;
+ brush->rgb[2] = 0.0f;
brush->gpencil_settings->icon_id = GP_BRUSH_ICON_TINT;
brush->gpencil_tool = GPAINT_TOOL_TINT;
diff --git a/source/blender/editors/gpencil/gpencil_tint.c b/source/blender/editors/gpencil/gpencil_tint.c
index cb70006ce9b..1afc6922905 100644
--- a/source/blender/editors/gpencil/gpencil_tint.c
+++ b/source/blender/editors/gpencil/gpencil_tint.c
@@ -145,22 +145,20 @@ static float brush_influence_calc(tGP_BrushTintData *gso, const int radius, cons
float influence = brush->size;
/* use pressure? */
- if (brush->flag & GP_SCULPT_FLAG_USE_PRESSURE) {
+ if (brush->gpencil_settings->flag & GP_BRUSH_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;
+ 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);
+ CLAMP(distance, 0.0f, (float)radius);
+ fac = 1.0f - (distance / (float)radius);
- influence *= fac;
- }
+ influence *= fac;
/* apply multiframe falloff */
influence *= gso->mf_falloff;
@@ -209,25 +207,26 @@ static bool brush_tint_apply(tGP_BrushTintData *gso,
const int radius,
const int co[2])
{
- float inf;
- /* Compute strength of effect
- * - We divide the strength by 10, so that users can set "sane" values.
- * Otherwise, good default values are in the range of 0.093
- */
- inf = brush_influence_calc(gso, radius, co) / 10.0f;
-
- float curweight = 0.0f;
+ /* Attenuate factor to get a smoother tinting. */
+ float inf = brush_influence_calc(gso, radius, co) / 200.0f;
+ Brush *brush = gso->brush;
+ bGPDspoint *pt = &gps->points[pt_index];
+ float alpha = pt->mix_color[3];
if (brush_invert_check(gso)) {
- curweight -= inf;
+ alpha -= inf;
}
else {
- /* increase weight */
- curweight += inf;
- /* verify maximum target weight */
- CLAMP_MAX(curweight, gso->brush->weight);
+ alpha += inf;
+ /* Limit max strength target. */
+ CLAMP_MAX(alpha, brush->gpencil_settings->draw_strength);
}
- printf("%f ", curweight);
+
+ CLAMP(alpha, 0.0f, 1.
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list