[Bf-blender-cvs] [796aae61d95] greasepencil-object: WIP: Define basic struct/functions for modal fill
Antonio Vazquez
noreply at git.blender.org
Wed Dec 20 17:39:03 CET 2017
Commit: 796aae61d953aad4f3087b9b68ed29c111c42593
Author: Antonio Vazquez
Date: Wed Dec 20 17:38:50 2017 +0100
Branches: greasepencil-object
https://developer.blender.org/rB796aae61d953aad4f3087b9b68ed29c111c42593
WIP: Define basic struct/functions for modal fill
Not implement yet.
Prepare the different elements required by modal operator.
===================================================================
M source/blender/editors/gpencil/drawgpencil.c
M source/blender/editors/gpencil/gpencil_fill.c
M source/blender/editors/include/ED_gpencil.h
===================================================================
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index dda65d04ea3..f5d25b7fad9 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -1482,6 +1482,14 @@ void ED_gp_draw_primitives(const bContext *C, tGPDprimitive *tgpi, const int typ
glDisable(GL_BLEND);
}
+/* draw fill mask (used only while operator is running) */
+void ED_gp_draw_fill(const struct bContext *UNUSED(C), struct tGPDfill *UNUSED(tgpf))
+{
+ /* TODO: Not implemented yet */
+ float color[4];
+ UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, color);
+}
+
/* loop over gpencil data layers, drawing them */
static void gp_draw_data_layers(
const bGPDbrush *brush, float alpha, Object *ob, bGPdata *gpd,
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index 960d617a464..b62b2ec12d7 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -29,6 +29,8 @@
#include <stdio.h>
+#include "MEM_guardedalloc.h"
+
#include "BLI_utildefines.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
@@ -37,12 +39,15 @@
#include "DNA_gpencil_types.h"
#include "DNA_windowmanager_types.h"
+#include "BKE_main.h"
#include "BKE_gpencil.h"
#include "BKE_context.h"
#include "BKE_screen.h"
+#include "BKE_paint.h"
#include "ED_gpencil.h"
#include "ED_screen.h"
+#include "ED_space_api.h"
#include "GPU_immediate.h"
#include "GPU_draw.h"
@@ -149,6 +154,16 @@ static unsigned int *gp_draw_offscreen_strokes(Scene *scene, Object *ob, rcti re
return data;
}
+/* ----------------------- */
+/* Drawing Callbacks */
+
+/* Drawing callback for modal operator in 3d mode */
+static void gpencil_fill_draw_3d(const bContext *C, ARegion *UNUSED(ar), void *arg)
+{
+ tGPDfill *tgpf = (tGPDfill *)arg;
+ //ED_gp_draw_fill(C, tgpf, REGION_DRAW_POST_VIEW);
+}
+
/* check if context is suitable for filling */
static int gpencil_fill_poll(bContext *C)
{
@@ -169,15 +184,36 @@ static int gpencil_fill_poll(bContext *C)
return 0;
}
-/* start of interactive part of operator */
-static int gpencil_fill_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+/* Allocate memory and initialize values */
+static tGPDfill *gp_session_init_fill(bContext *C, wmOperator *op)
{
- WM_cursor_modal_set(CTX_wm_window(C), BC_PAINTBRUSHCURSOR);
+ tGPDfill *tgpf = MEM_callocN(sizeof(tGPDfill), "GPencil Fill Data");
- /* add a modal handler for this operator*/
- WM_event_add_modal_handler(C, op);
+ /* define initial values */
+ ToolSettings *ts = CTX_data_tool_settings(C);
+ bGPdata *gpd = CTX_data_gpencil_data(C);
+ Main *bmain = CTX_data_main(C);
- return OPERATOR_RUNNING_MODAL;
+ /* set current scene and window info */
+ tgpf->scene = CTX_data_scene(C);
+ tgpf->ob = CTX_data_active_object(C);
+ tgpf->sa = CTX_wm_area(C);
+ tgpf->ar = CTX_wm_region(C);
+ tgpf->rv3d = tgpf->ar->regiondata;
+ tgpf->v3d = tgpf->sa->spacedata.first;
+
+ /* set GP datablock */
+ tgpf->gpd = gpd;
+
+ /* get palette and color info */
+ bGPDpaletteref *palslot = BKE_gpencil_paletteslot_validate(bmain, gpd);
+ tgpf->palette = palslot->palette;
+ tgpf->palcolor = BKE_palette_color_get_active(tgpf->palette);
+
+ tgpf->lock_axis = ts->gp_sculpt.lock_axis;
+
+ /* return context data for running operator */
+ return tgpf;
}
/* end operator */
@@ -187,6 +223,23 @@ static void gpencil_fill_exit(bContext *C, wmOperator *op)
/* restore cursor to indicate end of fill */
WM_cursor_modal_restore(CTX_wm_window(C));
+ tGPDfill *tgpf = op->customdata;
+ bGPdata *gpd = tgpf->gpd;
+
+ /* don't assume that operator data exists at all */
+ if (tgpf) {
+ /* remove drawing handler */
+ if (tgpf->draw_handle_3d) {
+ ED_region_draw_cb_exit(tgpf->ar->type, tgpf->draw_handle_3d);
+ }
+
+ /* finally, free memory used by temp data */
+ MEM_freeN(tgpf);
+ }
+
+ /* clear pointer */
+ op->customdata = NULL;
+
/* drawing batch cache is dirty now */
if ((ob) && (ob->type == OB_GPENCIL) && (ob->data)) {
bGPdata *gpd = ob->data;
@@ -201,6 +254,49 @@ static void gpencil_fill_cancel(bContext *C, wmOperator *op)
gpencil_fill_exit(C, op);
}
+/* Init: Allocate memory and set init values */
+static int gpencil_fill_init(bContext *C, wmOperator *op)
+{
+ tGPDfill *tgpf;
+
+ /* check context */
+ tgpf = op->customdata = gp_session_init_fill(C, op);
+ if (tgpf == NULL) {
+ /* something wasn't set correctly in context */
+ gpencil_fill_exit(C, op);
+ return 0;
+ }
+
+ /* everything is now setup ok */
+ return 1;
+}
+
+/* start of interactive part of operator */
+static int gpencil_fill_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ tGPDfill *tgpf = NULL;
+
+ /* try to initialize context data needed */
+ if (!gpencil_fill_init(C, op)) {
+ if (op->customdata)
+ MEM_freeN(op->customdata);
+ return OPERATOR_CANCELLED;
+ }
+ else {
+ tgpf = op->customdata;
+ }
+
+ /* Enable custom drawing handlers */
+ tgpf->draw_handle_3d = ED_region_draw_cb_activate(tgpf->ar->type, gpencil_fill_draw_3d, tgpf, REGION_DRAW_POST_VIEW);
+
+ WM_cursor_modal_set(CTX_wm_window(C), BC_PAINTBRUSHCURSOR);
+
+ /* add a modal handler for this operator*/
+ WM_event_add_modal_handler(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
/* events handling during interactive part of operator */
static int gpencil_fill_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 6eb7872da26..b80a310e1d4 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -121,6 +121,25 @@ typedef struct tGPDprimitive {
void *draw_handle_3d; /* handle for drawing strokes while operator is running 3d stuff */
} tGPDprimitive;
+/* Temporary fill operation data */
+typedef struct tGPDfill {
+ struct Scene *scene; /* current scene from context */
+ struct Object *ob; /* current active gp object */
+ struct ScrArea *sa; /* area where painting originated */
+ struct RegionView3D *rv3d; /* region where painting originated */
+ struct View3D *v3d; /* view3 where painting originated */
+ struct ARegion *ar; /* region where painting originated */
+ struct bGPdata *gpd; /* current GP datablock */
+ struct Palette *palette; /* current palette */
+ struct PaletteColor *palcolor; /* current palette color */
+ struct bGPDlayer *gpl; /* layer */
+ struct bGPDframe *gpf; /* frame */
+
+ int lock_axis; /* lock to viewport axis */
+
+ void *draw_handle_3d; /* handle for drawing strokes while operator is running 3d stuff */
+} tGPDfill;
+
/* Temporary 'Stroke Point' data
*
* Used as part of the 'stroke cache' used during drawing of new strokes
More information about the Bf-blender-cvs
mailing list