[Bf-blender-cvs] [4a7d9697027] greasepencil-object: Cleanup: Move eraser brush draw to function and avoid duplicated code
Antonio Vazquez
noreply at git.blender.org
Fri Mar 2 21:13:19 CET 2018
Commit: 4a7d9697027e506cfc3afe6de8021a08a1ce9c2b
Author: Antonio Vazquez
Date: Fri Mar 2 21:13:06 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB4a7d9697027e506cfc3afe6de8021a08a1ce9c2b
Cleanup: Move eraser brush draw to function and avoid duplicated code
===================================================================
M source/blender/editors/gpencil/gpencil_paint.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/include/ED_gpencil.h
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 3ae1c7bdf94..d1232fce3a3 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1982,44 +1982,12 @@ static void gp_paint_cleanup(tGPsdata *p)
/* ------------------------------- */
/* Helper callback for drawing the cursor itself */
-static void gpencil_draw_eraser(bContext *UNUSED(C), int x, int y, void *p_ptr)
+static void gpencil_draw_eraser(bContext *C, int x, int y, void *p_ptr)
{
tGPsdata *p = (tGPsdata *)p_ptr;
- if (p->paintmode == GP_PAINTMODE_ERASER) {
- Gwn_VertFormat *format = immVertexFormat();
- const uint shdr_pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-
- glEnable(GL_LINE_SMOOTH);
- glEnable(GL_BLEND);
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-
- immUniformColor4ub(255, 100, 100, 20);
- imm_draw_circle_fill_2d(shdr_pos, x, y, p->radius, 40);
-
- immUnbindProgram();
-
- immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
-
- float viewport_size[4];
- glGetFloatv(GL_VIEWPORT, viewport_size);
- immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
-
- immUniformColor4f(1.0f, 0.39f, 0.39f, 0.78f);
- immUniform1i("num_colors", 0); /* "simple" mode */
- immUniform1f("dash_width", 12.0f);
- immUniform1f("dash_factor", 0.5f);
-
- imm_draw_circle_wire_2d(shdr_pos, x, y, p->radius,
- /* XXX Dashed shader gives bad results with sets of small segments currently,
- * temp hack around the issue. :( */
- max_ii(8, p->radius / 2)); /* was fixed 40 */
-
- immUnbindProgram();
-
- glDisable(GL_BLEND);
- glDisable(GL_LINE_SMOOTH);
+ if ((p) && (p->paintmode == GP_PAINTMODE_ERASER)) {
+ ED_gpencil_brush_draw_eraser(C, p->brush, x, y);
}
}
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 9ed28dd0d14..c61263d7025 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1290,7 +1290,7 @@ static bool gp_check_cursor_region(bContext *C, int mval[2])
}
/* draw eraser cursor */
-static void gp_brush_draw_eraser(bContext *C, bGPDbrush *brush, int x, int y)
+void ED_gpencil_brush_draw_eraser(bContext *C, bGPDbrush *brush, int x, int y)
{
short radius = (short)brush->thickness;
@@ -1388,7 +1388,7 @@ static void gp_brush_drawcursor(bContext *C, int x, int y, void *customdata)
/* eraser has special shape and use a different shader program */
if (paintbrush->type == GP_BRUSH_TYPE_ERASE) {
- gp_brush_draw_eraser(C, paintbrush, x, y);
+ ED_gpencil_brush_draw_eraser(C, paintbrush, x, y);
return;
}
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 47fdbc3c133..feeb7c834d4 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -40,6 +40,7 @@ struct bGPDlayer;
struct bGPDframe;
struct bGPDstroke;
struct bGPDspoint;
+struct bGPDbrush;
struct Main;
struct bContext;
@@ -183,6 +184,9 @@ void ED_gpencil_parent_location(struct Object *obact, struct bGPdata *gpd, struc
/* reset parent matrix for all layers */
void ED_gpencil_reset_layers_parent(struct Object *obact, struct bGPdata *gpd);
+/* cursor utilities */
+void ED_gpencil_brush_draw_eraser(struct bContext *C, struct bGPDbrush *brush, int x, int y);
+
/* ----------- Add Primitive Utilities -------------- */
void ED_gpencil_create_monkey(struct bContext *C, struct bGPdata *gpd);
More information about the Bf-blender-cvs
mailing list