Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2009-08-28 16:41:45 +0400
committerJoshua Leung <aligorith@gmail.com>2009-08-28 16:41:45 +0400
commitc15db042cc1b1168a9894a7f5848a866e7b3575a (patch)
treecf7c2fb5eba821163a92a4a186157905c9443b01
parentd7656684e213e4755e6f499d2e3a0734507e803d (diff)
Grease Pencil: WIP Code Reordering + Context Stuff
* Shuffled some code around, and renamed some functions used for getting context info - Split UI-buttons into a separate file from stroke-drawing code - Removed some obsolete code (i.e. old paint code that used to be in _edit, but which has been moved to _paint). * Made drawing in 3D-View default to using the active object as the owner of the Grease Pencil data. For now, the drawing code will therefore only show the GP data for the active object only. More work to come on this. * Fixed freeing code for Objects/Scenes with GP data.
-rw-r--r--source/blender/blenkernel/intern/object.c1
-rw-r--r--source/blender/blenkernel/intern/scene.c5
-rw-r--r--source/blender/blenloader/intern/readfile.c4
-rw-r--r--source/blender/editors/animation/anim_filter.c2
-rw-r--r--source/blender/editors/gpencil/drawgpencil.c341
-rw-r--r--source/blender/editors/gpencil/gpencil_buttons.c334
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c1636
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c122
-rw-r--r--source/blender/editors/include/ED_gpencil.h36
-rw-r--r--source/blender/editors/transform/transform_conversions.c2
-rw-r--r--source/blender/makesdna/DNA_object_types.h7
-rw-r--r--source/blender/makesrna/intern/rna_object.c7
12 files changed, 477 insertions, 2020 deletions
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 5e2a00c219d..6f57a658efa 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -284,6 +284,7 @@ void free_object(Object *ob)
if(ob->adt) BKE_free_animdata((ID *)ob);
if(ob->poselib) ob->poselib->id.us--;
if(ob->dup_group) ob->dup_group->id.us--;
+ if(ob->gpd) ob->gpd->id.us--;
if(ob->defbase.first)
BLI_freelistN(&ob->defbase);
if(ob->pose)
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 6dd362d15a8..63dabf18faa 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -245,6 +245,11 @@ void free_scene(Scene *sce)
base= base->next;
}
/* do not free objects! */
+
+ if(sce->gpd) {
+ sce->gpd->id.us--;
+ sce->gpd= NULL;
+ }
BLI_freelistN(&sce->base);
seq_free_editing(sce);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 5d61e3d305e..1a811ebc08a 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3449,6 +3449,8 @@ static void lib_link_object(FileData *fd, Main *main)
}
for(a=0; a<ob->totcol; a++) ob->mat[a]= newlibadr_us(fd, ob->id.lib, ob->mat[a]);
+ ob->gpd= newlibadr_us(fd, ob->id.lib, ob->gpd);
+
ob->id.flag -= LIB_NEEDLINK;
/* if id.us==0 a new base will be created later on */
@@ -10418,6 +10420,8 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob)
expand_doit(fd, mainvar, ob->poselib);
expand_constraints(fd, mainvar, &ob->constraints);
+ expand_doit(fd, mainvar, ob->gpd);
+
// XXX depreceated - old animation system (for version patching only)
expand_doit(fd, mainvar, ob->ipo);
expand_doit(fd, mainvar, ob->action);
diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c
index 37c8aeac13a..55fb1ccace0 100644
--- a/source/blender/editors/animation/anim_filter.c
+++ b/source/blender/editors/animation/anim_filter.c
@@ -885,7 +885,7 @@ static int animdata_filter_gpencil (ListBase *anim_data, bScreen *sc, int filter
for (sa= sc->areabase.first; sa; sa= sa->next) {
/* try to get gp data */
// XXX need to put back grease pencil api...
- gpd= gpencil_data_getactive(sa);
+ gpd= gpencil_data_get_active(sa);
if (gpd == NULL) continue;
/* add gpd as channel too (if for drawing, and it has layers) */
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 242be943507..4a48e9a4e3b 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -67,279 +67,12 @@
#include "ED_sequencer.h"
#include "ED_util.h"
-#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_view2d.h"
#include "gpencil_intern.h"
/* ************************************************** */
-/* GREASE PENCIL PANEL-UI DRAWING */
-
-/* Every space which implements Grease-Pencil functionality should have a panel
- * for the settings. All of the space-dependent parts should be coded in the panel
- * code for that space, but the rest is all handled by generic panel here.
- */
-
-/* ------- Callbacks ----------- */
-/* These are just 'dummy wrappers' around gpencil api calls */
-
-#if 0
-// XXX
-/* make layer active one after being clicked on */
-void gp_ui_activelayer_cb (void *gpd, void *gpl)
-{
- gpencil_layer_setactive(gpd, gpl);
-
- scrarea_queue_winredraw(curarea);
- allqueue(REDRAWACTION, 0);
-}
-
-/* rename layer and set active */
-void gp_ui_renamelayer_cb (void *gpd_arg, void *gpl_arg)
-{
- bGPdata *gpd= (bGPdata *)gpd_arg;
- bGPDlayer *gpl= (bGPDlayer *)gpl_arg;
-
- BLI_uniquename(&gpd->layers, gpl, "GP_Layer", '.', offsetof(bGPDlayer, info[0]), 128);
- gpencil_layer_setactive(gpd, gpl);
-
- scrarea_queue_winredraw(curarea);
- allqueue(REDRAWACTION, 0);
-}
-
-/* add a new layer */
-void gp_ui_addlayer_cb (void *gpd, void *dummy)
-{
- gpencil_layer_addnew(gpd);
-
- scrarea_queue_winredraw(curarea);
- allqueue(REDRAWACTION, 0);
-}
-
-/* delete active layer */
-void gp_ui_dellayer_cb (void *gpd, void *dummy)
-{
- gpencil_layer_delactive(gpd);
-
- scrarea_queue_winredraw(curarea);
- allqueue(REDRAWACTION, 0);
-}
-
-/* delete last stroke of active layer */
-void gp_ui_delstroke_cb (void *gpd, void *gpl)
-{
- bGPDframe *gpf= gpencil_layer_getframe(gpl, CFRA, 0);
-
- if (gpf) {
- if (gpf->framenum != CFRA) return;
-
- gpencil_layer_setactive(gpd, gpl);
- gpencil_frame_delete_laststroke(gpl, gpf);
-
- scrarea_queue_winredraw(curarea);
- }
-}
-
-/* delete active frame of active layer */
-void gp_ui_delframe_cb (void *gpd, void *gpl)
-{
- bGPDframe *gpf= gpencil_layer_getframe(gpl, CFRA, 0);
-
- gpencil_layer_setactive(gpd, gpl);
- gpencil_layer_delframe(gpl, gpf);
-
- scrarea_queue_winredraw(curarea);
- allqueue(REDRAWACTION, 0);
-}
-
-/* convert the active layer to geometry */
-void gp_ui_convertlayer_cb (void *gpd, void *gpl)
-{
- gpencil_layer_setactive(gpd, gpl);
- gpencil_convert_menu();
-
- scrarea_queue_winredraw(curarea);
-}
-#endif
-
-/* ------- Drawing Code ------- */
-
-#if 0
-/* XXX */
-/* draw the controls for a given layer */
-static void gp_drawui_layer (uiBlock *block, bGPdata *gpd, bGPDlayer *gpl, short *xco, short *yco)
-{
- uiBut *but;
- short active= (gpl->flag & GP_LAYER_ACTIVE);
- short width= 314;
- short height;
- int rb_col;
-
- /* unless button has own callback, it adds this callback to button */
- uiBlockSetFunc(block, gp_ui_activelayer_cb, gpd, gpl);
-
- /* draw header */
- {
- uiBlockSetEmboss(block, UI_EMBOSSN);
-
- /* rounded header */
- if (active) uiBlockSetCol(block, TH_BUT_ACTION);
- rb_col= (active)?-20:20;
- uiDefBut(block, ROUNDBOX, B_REDR, "", *xco-8, *yco-2, width, 24, NULL, 5.0, 0.0, 15.0, (float)(rb_col-20), "");
- if (active) uiBlockSetCol(block, TH_AUTO);
-
- /* lock toggle */
- uiDefIconButBitI(block, ICONTOG, GP_LAYER_LOCKED, B_REDR, ICON_UNLOCKED, *xco-7, *yco-1, 20, 20, &gpl->flag, 0.0, 0.0, 0, 0, "Layer cannot be modified");
- }
-
- /* when layer is locked or hidden, only draw header */
- if (gpl->flag & (GP_LAYER_LOCKED|GP_LAYER_HIDE)) {
- char name[256]; /* gpl->info is 128, but we need space for 'locked/hidden' as well */
-
- height= 0;
-
- /* visibility button (only if hidden but not locked!) */
- if ((gpl->flag & GP_LAYER_HIDE) && !(gpl->flag & GP_LAYER_LOCKED))
- uiDefIconButBitI(block, ICONTOG, GP_LAYER_HIDE, B_REDR, ICON_RESTRICT_VIEW_OFF, *xco+12, *yco-1, 20, 20, &gpl->flag, 0.0, 0.0, 0, 0, "Visibility of layer");
-
- /* name */
- if (gpl->flag & GP_LAYER_HIDE)
- sprintf(name, "%s (Hidden)", gpl->info);
- else
- sprintf(name, "%s (Locked)", gpl->info);
- uiDefBut(block, LABEL, 1, name, *xco+35, *yco, 240, 20, NULL, 0.0, 0.0, 0, 0, "Short description of what this layer is for (optional)");
-
- /* delete button (only if hidden but not locked!) */
- if ((gpl->flag & GP_LAYER_HIDE) & !(gpl->flag & GP_LAYER_LOCKED)) {
- but= uiDefIconBut(block, BUT, B_REDR, ICON_X, *xco+(width-30), *yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Delete layer");
- uiButSetFunc(but, gp_ui_dellayer_cb, gpd, NULL);
- }
- uiBlockSetEmboss(block, UI_EMBOSS);
- }
- else {
- height= 97;
-
- /* draw rest of header */
- {
- /* visibility button */
- uiDefIconButBitI(block, ICONTOG, GP_LAYER_HIDE, B_REDR, ICON_RESTRICT_VIEW_OFF, *xco+12, *yco-1, 20, 20, &gpl->flag, 0.0, 0.0, 0, 0, "Visibility of layer");
-
- uiBlockSetEmboss(block, UI_EMBOSS);
-
- /* name */
- but= uiDefButC(block, TEX, B_REDR, "Info:", *xco+36, *yco, 240, 19, gpl->info, 0, 127, 0, 0, "Short description of what this layer is for (optional)");
- uiButSetFunc(but, gp_ui_renamelayer_cb, gpd, gpl);
-
- /* delete 'button' */
- uiBlockSetEmboss(block, UI_EMBOSSN);
-
- but= uiDefIconBut(block, BUT, B_REDR, ICON_X, *xco+(width-30), *yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Delete layer");
- uiButSetFunc(but, gp_ui_dellayer_cb, gpd, NULL);
-
- uiBlockSetEmboss(block, UI_EMBOSS);
- }
-
- /* draw backdrop */
- if (active) uiBlockSetCol(block, TH_BUT_ACTION);
- uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-8, *yco-height, width, height-1, NULL, 5.0, 0.0, 12.0, (float)rb_col, "");
- if (active) uiBlockSetCol(block, TH_AUTO);
-
- /* draw settings */
- {
- /* color */
- uiBlockBeginAlign(block);
- uiDefButF(block, COL, B_REDR, "", *xco, *yco-26, 150, 19, gpl->color, 0, 0, 0, 0, "Color to use for all strokes on this Grease Pencil Layer");
- uiDefButF(block, NUMSLI, B_REDR, "Opacity: ", *xco,*yco-45,150,19, &gpl->color[3], 0.3f, 1.0f, 0, 0, "Visibility of stroke (0.3 to 1.0)");
- uiBlockEndAlign(block);
-
- /* stroke thickness */
- uiDefButS(block, NUMSLI, B_REDR, "Thickness:", *xco, *yco-75, 150, 20, &gpl->thickness, 1, 10, 0, 0, "Thickness of strokes (in pixels)");
-
- /* debugging options */
- if (G.f & G_DEBUG) {
- uiDefButBitI(block, TOG, GP_LAYER_DRAWDEBUG, B_REDR, "Show Points", *xco, *yco-95, 150, 20, &gpl->flag, 0, 0, 0, 0, "Show points which form the strokes");
- }
-
- /* onion-skinning */
- uiBlockBeginAlign(block);
- uiDefButBitI(block, TOG, GP_LAYER_ONIONSKIN, B_REDR, "Onion-Skin", *xco+160, *yco-26, 140, 20, &gpl->flag, 0, 0, 0, 0, "Ghost frames on either side of frame");
- uiDefButS(block, NUMSLI, B_REDR, "GStep:", *xco+160, *yco-46, 140, 20, &gpl->gstep, 0, 120, 0, 0, "Max number of frames on either side of active frame to show (0 = just 'first' available sketch on either side)");
- uiBlockEndAlign(block);
-
- /* options */
- uiBlockBeginAlign(block);
- if (curarea->spacetype == SPACE_VIEW3D) {
- but= uiDefBut(block, BUT, B_REDR, "Convert to...", *xco+160, *yco-75, 140, 20, NULL, 0, 0, 0, 0, "Converts this layer's strokes to geometry (Hotkey = Alt-Shift-C)");
- uiButSetFunc(but, gp_ui_convertlayer_cb, gpd, gpl);
- }
- else {
- but= uiDefBut(block, BUT, B_REDR, "Del Active Frame", *xco+160, *yco-75, 140, 20, NULL, 0, 0, 0, 0, "Erases the the active frame for this layer (Hotkey = Alt-XKEY/DEL)");
- uiButSetFunc(but, gp_ui_delframe_cb, gpd, gpl);
- }
-
- but= uiDefBut(block, BUT, B_REDR, "Del Last Stroke", *xco+160, *yco-95, 140, 20, NULL, 0, 0, 0, 0, "Erases the last stroke from the active frame (Hotkey = Alt-XKEY/DEL)");
- uiButSetFunc(but, gp_ui_delstroke_cb, gpd, gpl);
- uiBlockEndAlign(block);
- }
- }
-
- /* adjust height for new to start */
- (*yco) -= (height + 27);
-}
-#endif
-/* Draw the contents for a grease-pencil panel. This assumes several things:
- * - that panel has been created, is 318 x 204. max yco is 225
- * - that a toggle for turning on/off gpencil drawing is 150 x 20, starting from (10,225)
- * which is basically the top left-hand corner
- * It will return the amount of extra space to extend the panel by
- */
-short draw_gpencil_panel (uiBlock *block, bGPdata *gpd, ScrArea *sa)
-{
-#if 0
- uiBut *but;
- bGPDlayer *gpl;
- short xco= 10, yco= 170;
-
- /* draw gpd settings first */
- {
- /* add new layer buttons */
- but= uiDefBut(block, BUT, B_REDR, "Add New Layer", 10,205,150,20, 0, 0, 0, 0, 0, "Adds a new Grease Pencil Layer");
- uiButSetFunc(but, gp_ui_addlayer_cb, gpd, NULL);
-
-
- /* show override lmb-clicks button + painting lock */
- uiBlockBeginAlign(block);
- if ((gpd->flag & GP_DATA_EDITPAINT)==0) {
- uiDefButBitI(block, TOG, GP_DATA_EDITPAINT, B_REDR, "Draw Mode", 170, 225, 130, 20, &gpd->flag, 0, 0, 0, 0, "Interpret click-drag as new strokes");
-
- uiBlockSetCol(block, TH_BUT_SETTING);
- uiDefIconButBitI(block, ICONTOG, GP_DATA_LMBPLOCK, B_REDR, ICON_UNLOCKED, 300, 225, 20, 20, &gpd->flag, 0.0, 0.0, 0, 0, "Painting cannot occur with Shift-LMB (when making selections)");
- uiBlockSetCol(block, TH_AUTO);
- }
- else
- uiDefButBitI(block, TOG, GP_DATA_EDITPAINT, B_REDR, "Draw Mode", 170, 225, 150, 20, &gpd->flag, 0, 0, 0, 0, "Interpret click-drag as new strokes");
- uiBlockEndAlign(block);
-
- /* 'view align' button (naming depends on context) */
- if (sa->spacetype == SPACE_VIEW3D)
- uiDefButBitI(block, TOG, GP_DATA_VIEWALIGN, B_REDR, "Sketch in 3D", 170, 205, 150, 20, &gpd->flag, 0, 0, 0, 0, "New strokes are added in 3D-space");
- else
- uiDefButBitI(block, TOG, GP_DATA_VIEWALIGN, B_REDR, "Stick to View", 170, 205, 150, 20, &gpd->flag, 0, 0, 0, 0, "New strokes are added on 2d-canvas");
- }
-
- /* draw for each layer */
- for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
- gp_drawui_layer(block, gpd, gpl, &xco, &yco);
- }
-
- /* return new height if necessary */
- return (yco < 0) ? (204 - yco) : 204;
-#endif
- return 0;
-}
-
-/* ************************************************** */
/* GREASE PENCIL DRAWING */
/* ----- General Defines ------ */
@@ -432,8 +165,8 @@ static void gp_draw_stroke_point (bGPDspoint *points, short thickness, short sfl
co[1]= (points->y * winy) + offsy;
}
else {
- co[0]= (points->x / 1000 * winx);
- co[1]= (points->y / 1000 * winy);
+ co[0]= (points->x / 100 * winx);
+ co[1]= (points->y / 100 * winy);
}
/* if thickness is less than GP_DRAWTHICKNESS_SPECIAL, simple dot looks ok
@@ -525,8 +258,8 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
glVertex2f(x, y);
}
else {
- const float x= (pt->x / 1000 * winx);
- const float y= (pt->y / 1000 * winy);
+ const float x= (pt->x / 100 * winx);
+ const float y= (pt->y / 100 * winy);
glVertex2f(x, y);
}
@@ -565,10 +298,10 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
s1[1]= (pt2->y * winy) + offsy;
}
else {
- s0[0]= (pt1->x / 1000 * winx);
- s0[1]= (pt1->y / 1000 * winy);
- s1[0]= (pt2->x / 1000 * winx);
- s1[1]= (pt2->y / 1000 * winy);
+ s0[0]= (pt1->x / 100 * winx);
+ s0[1]= (pt1->y / 100 * winy);
+ s1[0]= (pt2->x / 100 * winx);
+ s1[1]= (pt2->y / 100 * winy);
}
/* calculate gradient and normal - 'angle'=(ny/nx) */
@@ -713,8 +446,8 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
glVertex2f(x, y);
}
else {
- const float x= (float)(pt->x / 1000 * winx);
- const float y= (float)(pt->y / 1000 * winy);
+ const float x= (float)(pt->x / 100 * winx);
+ const float y= (float)(pt->y / 100 * winy);
glVertex2f(x, y);
}
@@ -872,47 +605,7 @@ static void gp_draw_data (bGPdata *gpd, int offsx, int offsy, int winx, int winy
/* turn off alpha blending, then smooth lines */
glDisable(GL_BLEND); // alpha blending
glDisable(GL_LINE_SMOOTH); // smooth lines
-
- /* show info for debugging the status of gpencil */
-#if 0
- if ( ((dflag & GP_DRAWDATA_NOSTATUS)==0) && (gpd->flag & GP_DATA_DISPINFO) ) {
- char printable[256];
- short xmax;
- /* get text to display */
- if (actlay) {
- if (gpd->flag & GP_DATA_EDITPAINT)
- UI_ThemeColor(TH_BONE_POSE); // should be blue-ish
- else if (actlay->actframe == NULL)
- UI_ThemeColor(TH_REDALERT);
- else if (actlay->actframe->framenum == cfra)
- UI_ThemeColor(TH_VERTEX_SELECT); // should be yellow
- else
- UI_ThemeColor(TH_TEXT_HI);
-
- if (actlay->actframe) {
- sprintf(printable, "GPencil: Layer ('%s'), Frame (%d)%s",
- actlay->info, actlay->actframe->framenum,
- ((gpd->flag & GP_DATA_EDITPAINT)?" , Draw Mode On":"") );
- }
- else {
- sprintf(printable, "GPencil: Layer ('%s'), Frame <None>%s",
- actlay->info, ((gpd->flag & GP_DATA_EDITPAINT)?" , Draw Mode On":"") );
- }
- }
- else {
- UI_ThemeColor(TH_REDALERT);
- sprintf(printable, "GPencil: Layer <None>");
- }
- xmax= GetButStringLength(printable);
-
- /* only draw it if view is wide enough (assume padding of 20 is enough for now) */
- if (winx > (xmax + 20)) {
- BLF_draw_default(winx-xmax, winy-20, 0.0f, printable);
- }
- }
-#endif
-
/* restore initial gl conditions */
glLineWidth(1.0);
glPointSize(1.0);
@@ -921,6 +614,12 @@ static void gp_draw_data (bGPdata *gpd, int offsx, int offsy, int winx, int winy
/* ----- Grease Pencil Sketches Drawing API ------ */
+// ............................
+// XXX
+// We need to review the calls below, since they may be/are not that suitable for
+// the new ways that we intend to be drawing data...
+// ............................
+
/* draw grease-pencil sketches to specified 2d-view that uses ibuf corrections */
void draw_gpencil_2dimage (bContext *C, ImBuf *ibuf)
{
@@ -933,7 +632,7 @@ void draw_gpencil_2dimage (bContext *C, ImBuf *ibuf)
/* check that we have grease-pencil stuff to draw */
if (ELEM(NULL, sa, ibuf)) return;
- gpd= gpencil_data_getactive(C);
+ gpd= gpencil_data_get_active(C); // XXX
if (gpd == NULL) return;
/* calculate rect */
@@ -1007,7 +706,7 @@ void draw_gpencil_2dview (bContext *C, short onlyv2d)
/* check that we have grease-pencil stuff to draw */
if (sa == NULL) return;
- gpd= gpencil_data_getactive(C);
+ gpd= gpencil_data_get_active(C); // XXX
if (gpd == NULL) return;
/* draw it! */
@@ -1026,7 +725,7 @@ void draw_gpencil_3dview (bContext *C, short only3d)
int dflag = 0;
/* check that we have grease-pencil stuff to draw */
- gpd= gpencil_data_getactive(C);
+ gpd= gpencil_data_get_active(C); // XXX
if (gpd == NULL) return;
/* draw it! */
@@ -1046,7 +745,7 @@ void draw_gpencil_oglrender (bContext *C)
/* assume gpencil data comes from v3d */
if (v3d == NULL) return;
- gpd= gpencil_data_getactive(C);
+ gpd= gpencil_data_get_active(C);
if (gpd == NULL) return;
/* pass 1: draw 3d-strokes ------------ > */
diff --git a/source/blender/editors/gpencil/gpencil_buttons.c b/source/blender/editors/gpencil/gpencil_buttons.c
new file mode 100644
index 00000000000..87f3b60dcc2
--- /dev/null
+++ b/source/blender/editors/gpencil/gpencil_buttons.c
@@ -0,0 +1,334 @@
+/**
+ * $Id: drawgpencil.c 22802 2009-08-26 12:01:15Z aligorith $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2008, Blender Foundation, Joshua Leung
+ * This is a new part of Blender
+ *
+ * Contributor(s): Joshua Leung
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stddef.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_arithb.h"
+#include "BLI_blenlib.h"
+
+#include "DNA_gpencil_types.h"
+#include "DNA_listBase.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_gpencil.h"
+#include "BKE_utildefines.h"
+
+#include "PIL_time.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "ED_gpencil.h"
+#include "ED_sequencer.h"
+#include "ED_util.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+#include "UI_view2d.h"
+
+#include "gpencil_intern.h"
+
+/* ************************************************** */
+/* GREASE PENCIL PANEL-UI DRAWING */
+
+/* Every space which implements Grease-Pencil functionality should have a panel
+ * for the settings. All of the space-dependent parts should be coded in the panel
+ * code for that space, but the rest is all handled by generic panel here.
+ */
+
+/* ------- Callbacks ----------- */
+/* These are just 'dummy wrappers' around gpencil api calls */
+
+#if 0
+// XXX
+/* make layer active one after being clicked on */
+void gp_ui_activelayer_cb (void *gpd, void *gpl)
+{
+ gpencil_layer_setactive(gpd, gpl);
+
+ scrarea_queue_winredraw(curarea);
+ allqueue(REDRAWACTION, 0);
+}
+
+/* rename layer and set active */
+void gp_ui_renamelayer_cb (void *gpd_arg, void *gpl_arg)
+{
+ bGPdata *gpd= (bGPdata *)gpd_arg;
+ bGPDlayer *gpl= (bGPDlayer *)gpl_arg;
+
+ BLI_uniquename(&gpd->layers, gpl, "GP_Layer", '.', offsetof(bGPDlayer, info[0]), 128);
+ gpencil_layer_setactive(gpd, gpl);
+
+ scrarea_queue_winredraw(curarea);
+ allqueue(REDRAWACTION, 0);
+}
+
+/* add a new layer */
+void gp_ui_addlayer_cb (void *gpd, void *dummy)
+{
+ gpencil_layer_addnew(gpd);
+
+ scrarea_queue_winredraw(curarea);
+ allqueue(REDRAWACTION, 0);
+}
+
+/* delete active layer */
+void gp_ui_dellayer_cb (void *gpd, void *dummy)
+{
+ gpencil_layer_delactive(gpd);
+
+ scrarea_queue_winredraw(curarea);
+ allqueue(REDRAWACTION, 0);
+}
+
+/* delete last stroke of active layer */
+void gp_ui_delstroke_cb (void *gpd, void *gpl)
+{
+ bGPDframe *gpf= gpencil_layer_getframe(gpl, CFRA, 0);
+
+ if (gpf) {
+ if (gpf->framenum != CFRA) return;
+
+ gpencil_layer_setactive(gpd, gpl);
+ gpencil_frame_delete_laststroke(gpl, gpf);
+
+ scrarea_queue_winredraw(curarea);
+ }
+}
+
+/* delete active frame of active layer */
+void gp_ui_delframe_cb (void *gpd, void *gpl)
+{
+ bGPDframe *gpf= gpencil_layer_getframe(gpl, CFRA, 0);
+
+ gpencil_layer_setactive(gpd, gpl);
+ gpencil_layer_delframe(gpl, gpf);
+
+ scrarea_queue_winredraw(curarea);
+ allqueue(REDRAWACTION, 0);
+}
+
+/* convert the active layer to geometry */
+void gp_ui_convertlayer_cb (void *gpd, void *gpl)
+{
+ gpencil_layer_setactive(gpd, gpl);
+ gpencil_convert_menu();
+
+ scrarea_queue_winredraw(curarea);
+}
+#endif
+
+/* ------- Drawing Code ------- */
+
+#if 0
+/* XXX */
+/* draw the controls for a given layer */
+static void gp_drawui_layer (uiBlock *block, bGPdata *gpd, bGPDlayer *gpl, short *xco, short *yco)
+{
+ uiBut *but;
+ short active= (gpl->flag & GP_LAYER_ACTIVE);
+ short width= 314;
+ short height;
+ int rb_col;
+
+ /* unless button has own callback, it adds this callback to button */
+ uiBlockSetFunc(block, gp_ui_activelayer_cb, gpd, gpl);
+
+ /* draw header */
+ {
+ uiBlockSetEmboss(block, UI_EMBOSSN);
+
+ /* rounded header */
+ if (active) uiBlockSetCol(block, TH_BUT_ACTION);
+ rb_col= (active)?-20:20;
+ uiDefBut(block, ROUNDBOX, B_REDR, "", *xco-8, *yco-2, width, 24, NULL, 5.0, 0.0, 15.0, (float)(rb_col-20), "");
+ if (active) uiBlockSetCol(block, TH_AUTO);
+
+ /* lock toggle */
+ uiDefIconButBitI(block, ICONTOG, GP_LAYER_LOCKED, B_REDR, ICON_UNLOCKED, *xco-7, *yco-1, 20, 20, &gpl->flag, 0.0, 0.0, 0, 0, "Layer cannot be modified");
+ }
+
+ /* when layer is locked or hidden, only draw header */
+ if (gpl->flag & (GP_LAYER_LOCKED|GP_LAYER_HIDE)) {
+ char name[256]; /* gpl->info is 128, but we need space for 'locked/hidden' as well */
+
+ height= 0;
+
+ /* visibility button (only if hidden but not locked!) */
+ if ((gpl->flag & GP_LAYER_HIDE) && !(gpl->flag & GP_LAYER_LOCKED))
+ uiDefIconButBitI(block, ICONTOG, GP_LAYER_HIDE, B_REDR, ICON_RESTRICT_VIEW_OFF, *xco+12, *yco-1, 20, 20, &gpl->flag, 0.0, 0.0, 0, 0, "Visibility of layer");
+
+ /* name */
+ if (gpl->flag & GP_LAYER_HIDE)
+ sprintf(name, "%s (Hidden)", gpl->info);
+ else
+ sprintf(name, "%s (Locked)", gpl->info);
+ uiDefBut(block, LABEL, 1, name, *xco+35, *yco, 240, 20, NULL, 0.0, 0.0, 0, 0, "Short description of what this layer is for (optional)");
+
+ /* delete button (only if hidden but not locked!) */
+ if ((gpl->flag & GP_LAYER_HIDE) & !(gpl->flag & GP_LAYER_LOCKED)) {
+ but= uiDefIconBut(block, BUT, B_REDR, ICON_X, *xco+(width-30), *yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Delete layer");
+ uiButSetFunc(but, gp_ui_dellayer_cb, gpd, NULL);
+ }
+ uiBlockSetEmboss(block, UI_EMBOSS);
+ }
+ else {
+ height= 97;
+
+ /* draw rest of header */
+ {
+ /* visibility button */
+ uiDefIconButBitI(block, ICONTOG, GP_LAYER_HIDE, B_REDR, ICON_RESTRICT_VIEW_OFF, *xco+12, *yco-1, 20, 20, &gpl->flag, 0.0, 0.0, 0, 0, "Visibility of layer");
+
+ uiBlockSetEmboss(block, UI_EMBOSS);
+
+ /* name */
+ but= uiDefButC(block, TEX, B_REDR, "Info:", *xco+36, *yco, 240, 19, gpl->info, 0, 127, 0, 0, "Short description of what this layer is for (optional)");
+ uiButSetFunc(but, gp_ui_renamelayer_cb, gpd, gpl);
+
+ /* delete 'button' */
+ uiBlockSetEmboss(block, UI_EMBOSSN);
+
+ but= uiDefIconBut(block, BUT, B_REDR, ICON_X, *xco+(width-30), *yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Delete layer");
+ uiButSetFunc(but, gp_ui_dellayer_cb, gpd, NULL);
+
+ uiBlockSetEmboss(block, UI_EMBOSS);
+ }
+
+ /* draw backdrop */
+ if (active) uiBlockSetCol(block, TH_BUT_ACTION);
+ uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-8, *yco-height, width, height-1, NULL, 5.0, 0.0, 12.0, (float)rb_col, "");
+ if (active) uiBlockSetCol(block, TH_AUTO);
+
+ /* draw settings */
+ {
+ /* color */
+ uiBlockBeginAlign(block);
+ uiDefButF(block, COL, B_REDR, "", *xco, *yco-26, 150, 19, gpl->color, 0, 0, 0, 0, "Color to use for all strokes on this Grease Pencil Layer");
+ uiDefButF(block, NUMSLI, B_REDR, "Opacity: ", *xco,*yco-45,150,19, &gpl->color[3], 0.3f, 1.0f, 0, 0, "Visibility of stroke (0.3 to 1.0)");
+ uiBlockEndAlign(block);
+
+ /* stroke thickness */
+ uiDefButS(block, NUMSLI, B_REDR, "Thickness:", *xco, *yco-75, 150, 20, &gpl->thickness, 1, 10, 0, 0, "Thickness of strokes (in pixels)");
+
+ /* debugging options */
+ if (G.f & G_DEBUG) {
+ uiDefButBitI(block, TOG, GP_LAYER_DRAWDEBUG, B_REDR, "Show Points", *xco, *yco-95, 150, 20, &gpl->flag, 0, 0, 0, 0, "Show points which form the strokes");
+ }
+
+ /* onion-skinning */
+ uiBlockBeginAlign(block);
+ uiDefButBitI(block, TOG, GP_LAYER_ONIONSKIN, B_REDR, "Onion-Skin", *xco+160, *yco-26, 140, 20, &gpl->flag, 0, 0, 0, 0, "Ghost frames on either side of frame");
+ uiDefButS(block, NUMSLI, B_REDR, "GStep:", *xco+160, *yco-46, 140, 20, &gpl->gstep, 0, 120, 0, 0, "Max number of frames on either side of active frame to show (0 = just 'first' available sketch on either side)");
+ uiBlockEndAlign(block);
+
+ /* options */
+ uiBlockBeginAlign(block);
+ if (curarea->spacetype == SPACE_VIEW3D) {
+ but= uiDefBut(block, BUT, B_REDR, "Convert to...", *xco+160, *yco-75, 140, 20, NULL, 0, 0, 0, 0, "Converts this layer's strokes to geometry (Hotkey = Alt-Shift-C)");
+ uiButSetFunc(but, gp_ui_convertlayer_cb, gpd, gpl);
+ }
+ else {
+ but= uiDefBut(block, BUT, B_REDR, "Del Active Frame", *xco+160, *yco-75, 140, 20, NULL, 0, 0, 0, 0, "Erases the the active frame for this layer (Hotkey = Alt-XKEY/DEL)");
+ uiButSetFunc(but, gp_ui_delframe_cb, gpd, gpl);
+ }
+
+ but= uiDefBut(block, BUT, B_REDR, "Del Last Stroke", *xco+160, *yco-95, 140, 20, NULL, 0, 0, 0, 0, "Erases the last stroke from the active frame (Hotkey = Alt-XKEY/DEL)");
+ uiButSetFunc(but, gp_ui_delstroke_cb, gpd, gpl);
+ uiBlockEndAlign(block);
+ }
+ }
+
+ /* adjust height for new to start */
+ (*yco) -= (height + 27);
+}
+#endif
+/* Draw the contents for a grease-pencil panel. This assumes several things:
+ * - that panel has been created, is 318 x 204. max yco is 225
+ * - that a toggle for turning on/off gpencil drawing is 150 x 20, starting from (10,225)
+ * which is basically the top left-hand corner
+ * It will return the amount of extra space to extend the panel by
+ */
+short draw_gpencil_panel (uiBlock *block, bGPdata *gpd, ScrArea *sa)
+{
+#if 0
+ uiBut *but;
+ bGPDlayer *gpl;
+ short xco= 10, yco= 170;
+
+ /* draw gpd settings first */
+ {
+ /* add new layer buttons */
+ but= uiDefBut(block, BUT, B_REDR, "Add New Layer", 10,205,150,20, 0, 0, 0, 0, 0, "Adds a new Grease Pencil Layer");
+ uiButSetFunc(but, gp_ui_addlayer_cb, gpd, NULL);
+
+
+ /* show override lmb-clicks button + painting lock */
+ uiBlockBeginAlign(block);
+ if ((gpd->flag & GP_DATA_EDITPAINT)==0) {
+ uiDefButBitI(block, TOG, GP_DATA_EDITPAINT, B_REDR, "Draw Mode", 170, 225, 130, 20, &gpd->flag, 0, 0, 0, 0, "Interpret click-drag as new strokes");
+
+ uiBlockSetCol(block, TH_BUT_SETTING);
+ uiDefIconButBitI(block, ICONTOG, GP_DATA_LMBPLOCK, B_REDR, ICON_UNLOCKED, 300, 225, 20, 20, &gpd->flag, 0.0, 0.0, 0, 0, "Painting cannot occur with Shift-LMB (when making selections)");
+ uiBlockSetCol(block, TH_AUTO);
+ }
+ else
+ uiDefButBitI(block, TOG, GP_DATA_EDITPAINT, B_REDR, "Draw Mode", 170, 225, 150, 20, &gpd->flag, 0, 0, 0, 0, "Interpret click-drag as new strokes");
+ uiBlockEndAlign(block);
+
+ /* 'view align' button (naming depends on context) */
+ if (sa->spacetype == SPACE_VIEW3D)
+ uiDefButBitI(block, TOG, GP_DATA_VIEWALIGN, B_REDR, "Sketch in 3D", 170, 205, 150, 20, &gpd->flag, 0, 0, 0, 0, "New strokes are added in 3D-space");
+ else
+ uiDefButBitI(block, TOG, GP_DATA_VIEWALIGN, B_REDR, "Stick to View", 170, 205, 150, 20, &gpd->flag, 0, 0, 0, 0, "New strokes are added on 2d-canvas");
+ }
+
+ /* draw for each layer */
+ for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
+ gp_drawui_layer(block, gpd, gpl, &xco, &yco);
+ }
+
+ /* return new height if necessary */
+ return (yco < 0) ? (204 - yco) : 204;
+#endif
+ return 0;
+}
+
+/* ************************************************** */
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 4480da45572..3130e190ce2 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
- * The Original Code is Copyright (C) 2008, Blender Foundation
+ * The Original Code is Copyright (C) 2008, Blender Foundation, Joshua Leung
* This is a new part of Blender
*
* Contributor(s): Joshua Leung
@@ -25,8 +25,7 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#if 0 // XXX COMPILE GUARDS FOR OLD CODE
-
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -69,6 +68,8 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "RNA_access.h"
+
#include "UI_view2d.h"
#include "ED_armature.h"
@@ -76,1627 +77,70 @@
#include "ED_sequencer.h"
#include "ED_view3d.h"
-#include "PIL_time.h" /* sleep */
-
#include "gpencil_intern.h"
-/* XXX */
-static void BIF_undo_push() {}
-static void error() {}
-static int pupmenu() {return 0;}
-static void add_object_draw() {}
-static int get_activedevice() {return 0;}
-#define L_MOUSE 0
-#define R_MOUSE 0
-
-/* ************************************************** */
-/* XXX - OLD DEPRECEATED CODE... */
-
-/* ----------- GP-Datablock API ------------- */
-
-/* get the appropriate bGPdata from the active/given context */
-// XXX region or region data?
-bGPdata *gpencil_data_getactive (ScrArea *sa)
-{
- ScrArea *curarea= NULL; // XXX
-
- /* error checking */
- if ((sa == NULL) && (curarea == NULL))
- return NULL;
- if (sa == NULL)
- sa= curarea;
-
- /* handle depending on spacetype */
- switch (sa->spacetype) {
- case SPACE_VIEW3D:
- {
- View3D *v3d= sa->spacedata.first;
- return v3d->gpd;
- }
- break;
- case SPACE_NODE:
- {
- SpaceNode *snode= sa->spacedata.first;
- return snode->gpd;
- }
- break;
- case SPACE_SEQ:
- {
- SpaceSeq *sseq= sa->spacedata.first;
-
- /* only applicable for image modes */
- if (sseq->mainb != SEQ_DRAW_SEQUENCE)
- return sseq->gpd;
- }
- break;
- case SPACE_IMAGE:
- {
- SpaceImage *sima= sa->spacedata.first;
- return sima->gpd;
- }
- break;
- }
-
- /* nothing found */
- return NULL;
-}
-
-/* set bGPdata for the active/given context, and return success/fail */
-short gpencil_data_setactive (ScrArea *sa, bGPdata *gpd)
-{
- ScrArea *curarea= NULL; // XXX
-
- /* error checking */
- if ((sa == NULL) && (curarea == NULL))
- return 0;
- if (gpd == NULL)
- return 0;
- if (sa == NULL)
- sa= curarea;
-
- /* handle depending on spacetype */
- // TODO: someday we should have multi-user data, so no need to loose old data
- switch (sa->spacetype) {
- case SPACE_VIEW3D:
- {
- View3D *v3d= sa->spacedata.first;
-
- /* free the existing block */
- if (v3d->gpd)
- free_gpencil_data(v3d->gpd);
- v3d->gpd= gpd;
-
- return 1;
- }
- break;
- case SPACE_NODE:
- {
- SpaceNode *snode= sa->spacedata.first;
-
- /* free the existing block */
- if (snode->gpd)
- free_gpencil_data(snode->gpd);
- snode->gpd= gpd;
-
- /* set special settings */
- gpd->flag |= GP_DATA_VIEWALIGN;
-
- return 1;
- }
- break;
- case SPACE_SEQ:
- {
- SpaceSeq *sseq= sa->spacedata.first;
-
- /* only applicable if right mode */
- if (sseq->mainb != SEQ_DRAW_SEQUENCE) {
- /* free the existing block */
- if (sseq->gpd)
- free_gpencil_data(sseq->gpd);
- sseq->gpd= gpd;
-
- return 1;
- }
- }
- break;
- case SPACE_IMAGE:
- {
- SpaceImage *sima= sa->spacedata.first;
-
- if (sima->gpd)
- free_gpencil_data(sima->gpd);
- sima->gpd= gpd;
-
- return 1;
- }
- break;
- }
-
- /* failed to add */
- return 0;
-}
-
-/* return the ScrArea that has the given GP-datablock
- * - assumes that only searching in current screen
- * - is based on GP-datablocks only being able to
- * exist for one area at a time (i.e. not multiuser)
- */
-ScrArea *gpencil_data_findowner (bGPdata *gpd)
-{
- bScreen *curscreen= NULL; // XXX
- ScrArea *sa;
-
- /* error checking */
- if (gpd == NULL)
- return NULL;
-
- /* loop over all scrareas for current screen, and check if that area has this gpd */
- for (sa= curscreen->areabase.first; sa; sa= sa->next) {
- /* use get-active func to see if match */
- if (gpencil_data_getactive(sa) == gpd)
- return sa;
- }
-
- /* not found */
- return NULL;
-}
-
-/* ************************************************** */
-/* GREASE-PENCIL EDITING - Tools */
-
-/* --------- Data Deletion ---------- */
-
-/* delete the last stroke on the active layer */
-void gpencil_delete_laststroke (bGPdata *gpd, int cfra)
-{
- bGPDlayer *gpl= gpencil_layer_getactive(gpd);
- bGPDframe *gpf= gpencil_layer_getframe(gpl, cfra, 0);
-
- gpencil_frame_delete_laststroke(gpl, gpf);
-}
-
-/* delete the active frame */
-void gpencil_delete_actframe (bGPdata *gpd, int cfra)
-{
- bGPDlayer *gpl= gpencil_layer_getactive(gpd);
- bGPDframe *gpf= gpencil_layer_getframe(gpl, cfra, 0);
-
- gpencil_layer_delframe(gpl, gpf);
-}
-
-
-
-/* delete various grase-pencil elements
- * mode: 1 - last stroke
- * 2 - active frame
- * 3 - active layer
- */
-void gpencil_delete_operation (int cfra, short mode)
-{
- bGPdata *gpd;
-
- /* get datablock to work on */
- gpd= gpencil_data_getactive(NULL);
- if (gpd == NULL) return;
-
- switch (mode) {
- case 1: /* last stroke */
- gpencil_delete_laststroke(gpd, cfra);
- break;
- case 2: /* active frame */
- gpencil_delete_actframe(gpd, cfra);
- break;
- case 3: /* active layer */
- gpencil_layer_delactive(gpd);
- break;
- }
-
- /* redraw and undo-push */
- BIF_undo_push("GPencil Delete");
-}
-
-/* display a menu for deleting different grease-pencil elements */
-void gpencil_delete_menu (void)
-{
- bGPdata *gpd= gpencil_data_getactive(NULL);
- int cfra= 0; // XXX
- short mode;
-
- /* only show menu if it will be relevant */
- if (gpd == NULL) return;
-
- mode= pupmenu("Grease Pencil Erase...%t|Last Stroke%x1|Active Frame%x2|Active Layer%x3");
- if (mode <= 0) return;
-
- gpencil_delete_operation(cfra, mode);
-}
-
-/* --------- Data Conversion ---------- */
-
-/* convert the coordinates from the given stroke point into 3d-coordinates */
-static void gp_strokepoint_convertcoords (bGPDstroke *gps, bGPDspoint *pt, float p3d[3])
-{
- ARegion *ar= NULL; // XXX
-
- if (gps->flag & GP_STROKE_3DSPACE) {
- /* directly use 3d-coordinates */
- VecCopyf(p3d, &pt->x);
- }
- else {
- short mval[2];
- int mx=0, my=0;
- float *fp= give_cursor(NULL, NULL); // XXX should be scene, v3d
- float dvec[3];
-
- /* get screen coordinate */
- if (gps->flag & GP_STROKE_2DSPACE) {
- // XXX
- // View2D *v2d= spacelink_get_view2d(curarea->spacedata.first);
- // UI_view2d_view_to_region(v2d, pt->x, pt->y, &mx, &my);
- }
- else {
- // XXX
- // mx= (short)(pt->x / 1000 * curarea->winx);
- // my= (short)(pt->y / 1000 * curarea->winy);
- }
-
- /* convert screen coordinate to 3d coordinates
- * - method taken from editview.c - mouse_cursor()
- */
- project_short_noclip(ar, fp, mval);
- window_to_3d_delta(ar, dvec, mval[0]-mx, mval[1]-my);
- VecSubf(p3d, fp, dvec);
- }
-}
-
-/* --- */
+/* ************************************************ */
+/* Context Wrangling... */
-/* convert stroke to 3d path */
-static void gp_stroke_to_path (bGPDlayer *gpl, bGPDstroke *gps, Curve *cu)
+/* Get pointer to active Grease Pencil datablock, and an RNA-pointer to trace back to whatever owns it */
+bGPdata **gpencil_data_get_pointers (bContext *C, PointerRNA *ptr)
{
- bGPDspoint *pt;
- Nurb *nu;
- BPoint *bp;
- int i;
-
- /* create new 'nurb' within the curve */
- nu = (Nurb *)MEM_callocN(sizeof(Nurb), "gpstroke_to_path(nurb)");
-
- nu->pntsu= gps->totpoints;
- nu->pntsv= 1;
- nu->orderu= gps->totpoints;
- nu->flagu= 2; /* endpoint */
- nu->resolu= 32;
-
- nu->bp= (BPoint *)MEM_callocN(sizeof(BPoint)*gps->totpoints, "bpoints");
-
- /* add points */
- for (i=0, pt=gps->points, bp=nu->bp; i < gps->totpoints; i++, pt++, bp++) {
- float p3d[3];
-
- /* get coordinates to add at */
- gp_strokepoint_convertcoords(gps, pt, p3d);
- VecCopyf(bp->vec, p3d);
-
- /* set settings */
- bp->f1= SELECT;
- bp->radius = bp->weight = pt->pressure * gpl->thickness;
- }
-
- /* add nurb to curve */
- BLI_addtail(&cu->nurb, nu);
-}
-
-/* convert stroke to 3d bezier */
-static void gp_stroke_to_bezier (bGPDlayer *gpl, bGPDstroke *gps, Curve *cu)
-{
- bGPDspoint *pt;
- Nurb *nu;
- BezTriple *bezt;
- int i;
-
- /* create new 'nurb' within the curve */
- nu = (Nurb *)MEM_callocN(sizeof(Nurb), "gpstroke_to_bezier(nurb)");
-
- nu->pntsu= gps->totpoints;
- nu->resolu= 12;
- nu->resolv= 12;
- nu->type= CU_BEZIER;
- nu->bezt = (BezTriple *)MEM_callocN(gps->totpoints*sizeof(BezTriple), "bezts");
-
- /* add points */
- for (i=0, pt=gps->points, bezt=nu->bezt; i < gps->totpoints; i++, pt++, bezt++) {
- float p3d[3];
-
- /* get coordinates to add at */
- gp_strokepoint_convertcoords(gps, pt, p3d);
-
- /* TODO: maybe in future the handles shouldn't be in same place */
- VecCopyf(bezt->vec[0], p3d);
- VecCopyf(bezt->vec[1], p3d);
- VecCopyf(bezt->vec[2], p3d);
-
- /* set settings */
- bezt->h1= bezt->h2= HD_FREE;
- bezt->f1= bezt->f2= bezt->f3= SELECT;
- bezt->radius = bezt->weight = pt->pressure * gpl->thickness * 0.1f;
- }
-
- /* must calculate handles or else we crash */
- calchandlesNurb(nu);
-
- /* add nurb to curve */
- BLI_addtail(&cu->nurb, nu);
-}
-
-/* convert a given grease-pencil layer to a 3d-curve representation (using current view if appropriate) */
-static void gp_layer_to_curve (bGPdata *gpd, bGPDlayer *gpl, Scene *scene, short mode)
-{
- bGPDframe *gpf= gpencil_layer_getframe(gpl, scene->r.cfra, 0);
- bGPDstroke *gps;
- Object *ob;
- Curve *cu;
-
- /* error checking */
- if (ELEM3(NULL, gpd, gpl, gpf))
- return;
-
- /* only convert if there are any strokes on this layer's frame to convert */
- if (gpf->strokes.first == NULL)
- return;
+ Scene *scene= CTX_data_scene(C);
+ ScrArea *sa= CTX_wm_area(C);
- /* init the curve object (remove rotation and get curve data from it)
- * - must clear transforms set on object, as those skew our results
+ /* if there's an active area, check if the particular editor may
+ * have defined any special Grease Pencil context for editing...
*/
- add_object_draw(OB_CURVE);
- ob= OBACT;
- ob->loc[0]= ob->loc[1]= ob->loc[2]= 0;
- ob->rot[0]= ob->rot[1]= ob->rot[2]= 0;
- cu= ob->data;
- cu->flag |= CU_3D;
-
- /* rename object and curve to layer name */
- rename_id((ID *)ob, gpl->info);
- rename_id((ID *)cu, gpl->info);
-
- /* add points to curve */
- for (gps= gpf->strokes.first; gps; gps= gps->next) {
- switch (mode) {
- case 1:
- gp_stroke_to_path(gpl, gps, cu);
- break;
- case 2:
- gp_stroke_to_bezier(gpl, gps, cu);
- break;
- }
- }
-}
-
-/* --- */
-
-/* convert a stroke to a bone chain */
-static void gp_stroke_to_bonechain (bGPDlayer *gpl, bGPDstroke *gps, bArmature *arm, ListBase *bones)
-{
- EditBone *ebo, *prev=NULL;
- bGPDspoint *pt, *ptn;
- int i;
-
- /* add each segment separately */
- for (i=0, pt=gps->points, ptn=gps->points+1; i < (gps->totpoints-1); prev=ebo, i++, pt++, ptn++) {
- float p3da[3], p3db[3];
-
- /* get coordinates to add at */
- gp_strokepoint_convertcoords(gps, pt, p3da);
- gp_strokepoint_convertcoords(gps, ptn, p3db);
-
- /* allocate new bone */
- ebo= MEM_callocN(sizeof(EditBone), "eBone");
-
- VecCopyf(ebo->head, p3da);
- VecCopyf(ebo->tail, p3db);
-
- /* add new bone - note: sync with editarmature.c::add_editbone() */
- {
- BLI_strncpy(ebo->name, "Stroke", 32);
- unique_editbone_name(bones, ebo->name, NULL);
-
- BLI_addtail(bones, ebo);
-
- if (i > 0)
+ if (sa) {
+ switch (sa->spacetype) {
+ case SPACE_VIEW3D: /* 3D-View */
{
- ebo->flag |= BONE_CONNECTED;
- }
- ebo->weight= 1.0f;
- ebo->dist= 0.25f;
- ebo->xwidth= 0.1f;
- ebo->zwidth= 0.1f;
- ebo->ease1= 1.0f;
- ebo->ease2= 1.0f;
- ebo->rad_head= pt->pressure * gpl->thickness * 0.1f;
- ebo->rad_tail= ptn->pressure * gpl->thickness * 0.1f;
- ebo->segments= 1;
- ebo->layer= arm->layer;
- }
-
- /* set parenting */
- ebo->parent= prev;
- }
-}
-
-/* convert a given grease-pencil layer to a 3d-curve representation (using current view if appropriate) */
-// XXX depreceated... we now have etch-a-ton for this...
-static void gp_layer_to_armature (bGPdata *gpd, bGPDlayer *gpl, Scene *scene, View3D *v3d, short mode)
-{
- bGPDframe *gpf= gpencil_layer_getframe(gpl, scene->r.cfra, 0);
- bGPDstroke *gps;
- Object *ob;
- bArmature *arm;
-
- /* error checking */
- if (ELEM3(NULL, gpd, gpl, gpf))
- return;
-
- /* only convert if there are any strokes on this layer's frame to convert */
- if (gpf->strokes.first == NULL)
- return;
-
- /* init the armature object (remove rotation and assign armature data to it)
- * - must clear transforms set on object, as those skew our results
- */
- add_object_draw(OB_ARMATURE);
- ob= OBACT;
- ob->loc[0]= ob->loc[1]= ob->loc[2]= 0;
- ob->rot[0]= ob->rot[1]= ob->rot[2]= 0;
- arm= ob->data;
-
- /* rename object and armature to layer name */
- rename_id((ID *)ob, gpl->info);
- rename_id((ID *)arm, gpl->info);
-
- /* this is editmode armature */
- arm->edbo= MEM_callocN(sizeof(ListBase), "arm edbo");
-
- /* convert segments to bones, strokes to bone chains */
- for (gps= gpf->strokes.first; gps; gps= gps->next) {
- gp_stroke_to_bonechain(gpl, gps, arm, arm->edbo);
- }
-
- /* adjust roll of bones
- * - set object as EditMode object, but need to clear afterwards!
- * - use 'align to world z-up' option
- */
- {
- /* set our data as if we're in editmode to fool auto_align_armature() */
- scene->obedit= ob;
-
- /* WARNING: need to make sure this magic number doesn't change */
- auto_align_armature(scene, v3d, 2);
-
- scene->obedit= NULL;
- }
-
- /* flush editbones to armature */
- ED_armature_from_edit(scene, ob);
- ED_armature_edit_free(ob);
-}
-
-/* --- */
-
-/* convert grease-pencil strokes to another representation
- * mode: 1 - Active layer to path
- * 2 - Active layer to bezier
- * 3 - Active layer to armature
- */
-void gpencil_convert_operation (short mode)
-{
- Scene *scene= NULL; // XXX
- View3D *v3d= NULL; // XXX
- RegionView3D *rv3d= NULL; // XXX
- bGPdata *gpd;
- float *fp= give_cursor(scene, v3d);
-
- /* get datablock to work on */
- gpd= gpencil_data_getactive(NULL);
- if (gpd == NULL) return;
-
- /* initialise 3d-cursor correction globals */
- initgrabz(rv3d, fp[0], fp[1], fp[2]);
-
- /* handle selection modes */
- switch (mode) {
- case 1: /* active layer only (to path) */
- case 2: /* active layer only (to bezier) */
- {
- bGPDlayer *gpl= gpencil_layer_getactive(gpd);
- gp_layer_to_curve(gpd, gpl, scene, mode);
- }
- break;
- case 3: /* active layer only (to armature) */
- {
- bGPDlayer *gpl= gpencil_layer_getactive(gpd);
- gp_layer_to_armature(gpd, gpl, scene, v3d, mode);
- }
- break;
- }
-
- /* redraw and undo-push */
- BIF_undo_push("GPencil Convert");
-}
-
-/* ************************************************** */
-/* GREASE-PENCIL EDITING MODE - Painting */
-
-/* ---------- 'Globals' and Defines ----------------- */
-
-/* maximum sizes of gp-session buffer */
-#define GP_STROKE_BUFFER_MAX 5000
-
-/* Macros for accessing sensitivity thresholds... */
- /* minimum number of pixels mouse should move before new point created */
-#define MIN_MANHATTEN_PX (U.gp_manhattendist)
- /* minimum length of new segment before new point can be added */
-#define MIN_EUCLIDEAN_PX (U.gp_euclideandist)
-
-/* macro to test if only converting endpoints - only for use when converting! */
-#define GP_BUFFER2STROKE_ENDPOINTS ((gpd->flag & GP_DATA_EDITPAINT) && (ctrl))
-
-/* ------ */
-
-/* Temporary 'Stroke' Operation data */
-typedef struct tGPsdata {
- Scene *scene; /* current scene from context */
- ScrArea *sa; /* area where painting originated */
- ARegion *ar; /* region where painting originated */
- View2D *v2d; /* needed for GP_STROKE_2DSPACE */
-
- ImBuf *ibuf; /* needed for GP_STROKE_2DIMAGE */
- struct IBufViewSettings {
- int offsx, offsy; /* offsets */
- int sizex, sizey; /* dimensions to use as scale-factor */
- } im2d_settings; /* needed for GP_STROKE_2DIMAGE */
-
- bGPdata *gpd; /* gp-datablock layer comes from */
- bGPDlayer *gpl; /* layer we're working on */
- bGPDframe *gpf; /* frame we're working on */
-
- short status; /* current status of painting */
- short paintmode; /* mode for painting */
-
- short mval[2]; /* current mouse-position */
- short mvalo[2]; /* previous recorded mouse-position */
-
- float pressure; /* current stylus pressure */
- float opressure; /* previous stylus pressure */
-
- short radius; /* radius of influence for eraser */
-} tGPsdata;
-
-/* values for tGPsdata->status */
-enum {
- GP_STATUS_NORMAL = 0, /* running normally */
- GP_STATUS_ERROR, /* something wasn't correctly set up */
- GP_STATUS_DONE /* painting done */
-};
-
-/* values for tGPsdata->paintmode */
-enum {
- GP_PAINTMODE_DRAW = 0,
- GP_PAINTMODE_ERASER
-};
-
-/* Return flags for adding points to stroke buffer */
-enum {
- GP_STROKEADD_INVALID = -2, /* error occurred - insufficient info to do so */
- GP_STROKEADD_OVERFLOW = -1, /* error occurred - cannot fit any more points */
- GP_STROKEADD_NORMAL, /* point was successfully added */
- GP_STROKEADD_FULL /* cannot add any more points to buffer */
-};
-
-/* ---------- Stroke Editing ------------ */
-
-/* clear the session buffers (call this before AND after a paint operation) */
-static void gp_session_validatebuffer (tGPsdata *p)
-{
- bGPdata *gpd= p->gpd;
-
- /* clear memory of buffer (or allocate it if starting a new session) */
- if (gpd->sbuffer)
- memset(gpd->sbuffer, 0, sizeof(tGPspoint)*GP_STROKE_BUFFER_MAX);
- else
- gpd->sbuffer= MEM_callocN(sizeof(tGPspoint)*GP_STROKE_BUFFER_MAX, "gp_session_strokebuffer");
-
- /* reset indices */
- gpd->sbuffer_size = 0;
-
- /* reset flags */
- gpd->sbuffer_sflag= 0;
-}
-
-/* check if the current mouse position is suitable for adding a new point */
-static short gp_stroke_filtermval (tGPsdata *p, short mval[2], short pmval[2])
-{
- short dx= abs(mval[0] - pmval[0]);
- short dy= abs(mval[1] - pmval[1]);
-
- /* check if mouse moved at least certain distance on both axes (best case) */
- if ((dx > MIN_MANHATTEN_PX) && (dy > MIN_MANHATTEN_PX))
- return 1;
-
- /* check if the distance since the last point is significant enough */
- // future optimisation: sqrt here may be too slow?
- else if (sqrt(dx*dx + dy*dy) > MIN_EUCLIDEAN_PX)
- return 1;
-
- /* mouse 'didn't move' */
- else
- return 0;
-}
-
-/* convert screen-coordinates to buffer-coordinates */
-static void gp_stroke_convertcoords (tGPsdata *p, short mval[], float out[])
-{
- bGPdata *gpd= p->gpd;
-
- /* in 3d-space - pt->x/y/z are 3 side-by-side floats */
- if (gpd->sbuffer_sflag & GP_STROKE_3DSPACE) {
- const short mx=mval[0], my=mval[1];
- float *fp= give_cursor(p->scene, NULL); // XXX NULL could be v3d
- float dvec[3];
-
- /* Current method just converts each point in screen-coordinates to
- * 3D-coordinates using the 3D-cursor as reference. In general, this
- * works OK, but it could of course be improved.
- *
- * TODO:
- * - investigate using nearest point(s) on a previous stroke as
- * reference point instead or as offset, for easier stroke matching
- * - investigate projection onto geometry (ala retopo)
- */
-
- /* method taken from editview.c - mouse_cursor() */
- project_short_noclip(p->ar, fp, mval);
- window_to_3d_delta(p->ar, dvec, mval[0]-mx, mval[1]-my);
- VecSubf(out, fp, dvec);
- }
-
- /* 2d - on 'canvas' (assume that p->v2d is set) */
- else if ((gpd->sbuffer_sflag & GP_STROKE_2DSPACE) && (p->v2d)) {
- float x, y;
-
- UI_view2d_region_to_view(p->v2d, mval[0], mval[1], &x, &y);
-
- out[0]= x;
- out[1]= y;
- }
-
- /* 2d - on image 'canvas' (assume that p->v2d is set) */
- else if (gpd->sbuffer_sflag & GP_STROKE_2DIMAGE) {
- int sizex, sizey, offsx, offsy;
-
- /* get stored settings
- * - assume that these have been set already (there are checks that set sane 'defaults' just in case)
- */
- sizex= p->im2d_settings.sizex;
- sizey= p->im2d_settings.sizey;
- offsx= p->im2d_settings.offsx;
- offsy= p->im2d_settings.offsy;
-
- /* calculate new points */
- out[0]= (float)(mval[0] - offsx) / (float)sizex;
- out[1]= (float)(mval[1] - offsy) / (float)sizey;
- }
-
- /* 2d - relative to screen (viewport area) */
- else {
- out[0] = (float)(mval[0]) / (float)(p->sa->winx) * 1000;
- out[1] = (float)(mval[1]) / (float)(p->sa->winy) * 1000;
- }
-}
-
-/* add current stroke-point to buffer (returns whether point was successfully added) */
-static short gp_stroke_addpoint (tGPsdata *p, short mval[2], float pressure)
-{
- bGPdata *gpd= p->gpd;
- tGPspoint *pt;
-
- /* check if still room in buffer */
- if (gpd->sbuffer_size >= GP_STROKE_BUFFER_MAX)
- return GP_STROKEADD_OVERFLOW;
-
- /* get pointer to destination point */
- pt= ((tGPspoint *)(gpd->sbuffer) + gpd->sbuffer_size);
-
- /* store settings */
- pt->x= mval[0];
- pt->y= mval[1];
- pt->pressure= pressure;
-
- /* increment counters */
- gpd->sbuffer_size++;
-
- /* check if another operation can still occur */
- if (gpd->sbuffer_size == GP_STROKE_BUFFER_MAX)
- return GP_STROKEADD_FULL;
- else
- return GP_STROKEADD_NORMAL;
-}
-
-/* smooth a stroke (in buffer) before storing it */
-static void gp_stroke_smooth (tGPsdata *p)
-{
- bGPdata *gpd= p->gpd;
- int i=0, cmx=gpd->sbuffer_size;
- int ctrl= 0; // XXX
-
- /* only smooth if smoothing is enabled, and we're not doing a straight line */
- if (!(U.gp_settings & GP_PAINT_DOSMOOTH) || GP_BUFFER2STROKE_ENDPOINTS)
- return;
-
- /* don't try if less than 2 points in buffer */
- if ((cmx <= 2) || (gpd->sbuffer == NULL))
- return;
-
- /* apply weighting-average (note doing this along path sequentially does introduce slight error) */
- for (i=0; i < gpd->sbuffer_size; i++) {
- tGPspoint *pc= (((tGPspoint *)gpd->sbuffer) + i);
- tGPspoint *pb= (i-1 > 0)?(pc-1):(pc);
- tGPspoint *pa= (i-2 > 0)?(pc-2):(pb);
- tGPspoint *pd= (i+1 < cmx)?(pc+1):(pc);
- tGPspoint *pe= (i+2 < cmx)?(pc+2):(pd);
-
- pc->x= (short)(0.1*pa->x + 0.2*pb->x + 0.4*pc->x + 0.2*pd->x + 0.1*pe->x);
- pc->y= (short)(0.1*pa->y + 0.2*pb->y + 0.4*pc->y + 0.2*pd->y + 0.1*pe->y);
- }
-}
-
-/* simplify a stroke (in buffer) before storing it
- * - applies a reverse Chaikin filter
- * - code adapted from etch-a-ton branch (editarmature_sketch.c)
- */
-static void gp_stroke_simplify (tGPsdata *p)
-{
- bGPdata *gpd= p->gpd;
- tGPspoint *old_points= (tGPspoint *)gpd->sbuffer;
- short num_points= gpd->sbuffer_size;
- short flag= gpd->sbuffer_sflag;
- short i, j;
- int ctrl= 0; // XXX
-
- /* only simplify if simlification is enabled, and we're not doing a straight line */
- if (!(U.gp_settings & GP_PAINT_DOSIMPLIFY) || GP_BUFFER2STROKE_ENDPOINTS)
- return;
-
- /* don't simplify if less than 4 points in buffer */
- if ((num_points <= 2) || (old_points == NULL))
- return;
-
- /* clear buffer (but don't free mem yet) so that we can write to it
- * - firstly set sbuffer to NULL, so a new one is allocated
- * - secondly, reset flag after, as it gets cleared auto
- */
- gpd->sbuffer= NULL;
- gp_session_validatebuffer(p);
- gpd->sbuffer_sflag = flag;
-
-/* macro used in loop to get position of new point
- * - used due to the mixture of datatypes in use here
- */
-#define GP_SIMPLIFY_AVPOINT(offs, sfac) \
- { \
- co[0] += (float)(old_points[offs].x * sfac); \
- co[1] += (float)(old_points[offs].y * sfac); \
- pressure += old_points[offs].pressure * sfac; \
- }
-
- for (i = 0, j = 0; i < num_points; i++)
- {
- if (i - j == 3)
- {
- float co[2], pressure;
- short mco[2];
-
- /* initialise values */
- co[0]= 0;
- co[1]= 0;
- pressure = 0;
-
- /* using macro, calculate new point */
- GP_SIMPLIFY_AVPOINT(j, -0.25f);
- GP_SIMPLIFY_AVPOINT(j+1, 0.75f);
- GP_SIMPLIFY_AVPOINT(j+2, 0.75f);
- GP_SIMPLIFY_AVPOINT(j+3, -0.25f);
-
- /* set values for adding */
- mco[0]= (short)co[0];
- mco[1]= (short)co[1];
-
- /* ignore return values on this... assume to be ok for now */
- gp_stroke_addpoint(p, mco, pressure);
-
- j += 2;
- }
- }
-
- /* free old buffer */
- MEM_freeN(old_points);
-}
-
-
-/* make a new stroke from the buffer data */
-static void gp_stroke_newfrombuffer (tGPsdata *p)
-{
- bGPdata *gpd= p->gpd;
- bGPDstroke *gps;
- bGPDspoint *pt;
- tGPspoint *ptc;
- int i, totelem;
- int ctrl= 0; // XXX
-
- /* get total number of points to allocate space for:
- * - in 'Draw Mode', holding the Ctrl-Modifier will only take endpoints
- * - otherwise, do whole stroke
- */
- if (GP_BUFFER2STROKE_ENDPOINTS)
- totelem = (gpd->sbuffer_size >= 2) ? 2: gpd->sbuffer_size;
- else
- totelem = gpd->sbuffer_size;
-
- /* exit with error if no valid points from this stroke */
- if (totelem == 0) {
- if (G.f & G_DEBUG)
- printf("Error: No valid points in stroke buffer to convert (tot=%d) \n", gpd->sbuffer_size);
- return;
- }
-
- /* allocate memory for a new stroke */
- gps= MEM_callocN(sizeof(bGPDstroke), "gp_stroke");
-
- /* allocate enough memory for a continuous array for storage points */
- pt= gps->points= MEM_callocN(sizeof(bGPDspoint)*totelem, "gp_stroke_points");
-
- /* copy appropriate settings for stroke */
- gps->totpoints= totelem;
- gps->thickness= p->gpl->thickness;
- gps->flag= gpd->sbuffer_sflag;
-
- /* copy points from the buffer to the stroke */
- if (GP_BUFFER2STROKE_ENDPOINTS) {
- /* 'Draw Mode' + Ctrl-Modifier - only endpoints */
- {
- /* first point */
- ptc= gpd->sbuffer;
-
- /* convert screen-coordinates to appropriate coordinates (and store them) */
- gp_stroke_convertcoords(p, &ptc->x, &pt->x);
-
- /* copy pressure */
- pt->pressure= ptc->pressure;
-
- pt++;
- }
-
- if (totelem == 2) {
- /* last point if applicable */
- ptc= ((tGPspoint *)gpd->sbuffer) + (gpd->sbuffer_size - 1);
-
- /* convert screen-coordinates to appropriate coordinates (and store them) */
- gp_stroke_convertcoords(p, &ptc->x, &pt->x);
-
- /* copy pressure */
- pt->pressure= ptc->pressure;
- }
- }
- else {
- /* convert all points (normal behaviour) */
- for (i=0, ptc=gpd->sbuffer; i < gpd->sbuffer_size && ptc; i++, ptc++) {
- /* convert screen-coordinates to appropriate coordinates (and store them) */
- gp_stroke_convertcoords(p, &ptc->x, &pt->x);
-
- /* copy pressure */
- pt->pressure= ptc->pressure;
-
- pt++;
- }
- }
-
- /* add stroke to frame */
- BLI_addtail(&p->gpf->strokes, gps);
-}
-
-/* --- 'Eraser' for 'Paint' Tool ------ */
-
-/* eraser tool - remove segment from stroke/split stroke (after lasso inside) */
-static short gp_stroke_eraser_splitdel (bGPDframe *gpf, bGPDstroke *gps, int i)
-{
- bGPDspoint *pt_tmp= gps->points;
- bGPDstroke *gsn = NULL;
-
- /* if stroke only had two points, get rid of stroke */
- if (gps->totpoints == 2) {
- /* free stroke points, then stroke */
- MEM_freeN(pt_tmp);
- BLI_freelinkN(&gpf->strokes, gps);
-
- /* nothing left in stroke, so stop */
- return 1;
- }
-
- /* if last segment, just remove segment from the stroke */
- else if (i == gps->totpoints - 2) {
- /* allocate new points array, and assign most of the old stroke there */
- gps->totpoints--;
- gps->points= MEM_callocN(sizeof(bGPDspoint)*gps->totpoints, "gp_stroke_points");
- memcpy(gps->points, pt_tmp, sizeof(bGPDspoint)*gps->totpoints);
-
- /* free temp buffer */
- MEM_freeN(pt_tmp);
-
- /* nothing left in stroke, so stop */
- return 1;
- }
-
- /* if first segment, just remove segment from the stroke */
- else if (i == 0) {
- /* allocate new points array, and assign most of the old stroke there */
- gps->totpoints--;
- gps->points= MEM_callocN(sizeof(bGPDspoint)*gps->totpoints, "gp_stroke_points");
- memcpy(gps->points, pt_tmp + 1, sizeof(bGPDspoint)*gps->totpoints);
-
- /* free temp buffer */
- MEM_freeN(pt_tmp);
-
- /* no break here, as there might still be stuff to remove in this stroke */
- return 0;
- }
-
- /* segment occurs in 'middle' of stroke, so split */
- else {
- /* duplicate stroke, and assign 'later' data to that stroke */
- gsn= MEM_dupallocN(gps);
- gsn->prev= gsn->next= NULL;
- BLI_insertlinkafter(&gpf->strokes, gps, gsn);
-
- gsn->totpoints= gps->totpoints - i;
- gsn->points= MEM_callocN(sizeof(bGPDspoint)*gsn->totpoints, "gp_stroke_points");
- memcpy(gsn->points, pt_tmp + i, sizeof(bGPDspoint)*gsn->totpoints);
-
- /* adjust existing stroke */
- gps->totpoints= i;
- gps->points= MEM_callocN(sizeof(bGPDspoint)*gps->totpoints, "gp_stroke_points");
- memcpy(gps->points, pt_tmp, sizeof(bGPDspoint)*i);
-
- /* free temp buffer */
- MEM_freeN(pt_tmp);
-
- /* nothing left in stroke, so stop */
- return 1;
- }
-}
-
-/* eraser tool - check if part of stroke occurs within last segment drawn by eraser */
-static short gp_stroke_eraser_strokeinside (short mval[], short mvalo[], short rad, short x0, short y0, short x1, short y1)
-{
- /* simple within-radius check for now */
- if (edge_inside_circle(mval[0], mval[1], rad, x0, y0, x1, y1))
- return 1;
-
- /* not inside */
- return 0;
-}
-
-/* eraser tool - evaluation per stroke */
-static void gp_stroke_eraser_dostroke (tGPsdata *p, short mval[], short mvalo[], short rad, rcti *rect, bGPDframe *gpf, bGPDstroke *gps)
-{
- bGPDspoint *pt1, *pt2;
- int x0=0, y0=0, x1=0, y1=0;
- short xyval[2];
- int i;
-
- if (gps->totpoints == 0) {
- /* just free stroke */
- if (gps->points)
- MEM_freeN(gps->points);
- BLI_freelinkN(&gpf->strokes, gps);
- }
- else if (gps->totpoints == 1) {
- /* get coordinates */
- if (gps->flag & GP_STROKE_3DSPACE) {
- project_short(p->ar, &gps->points->x, xyval);
- x0= xyval[0];
- y0= xyval[1];
- }
- else if (gps->flag & GP_STROKE_2DSPACE) {
- UI_view2d_view_to_region(p->v2d, gps->points->x, gps->points->y, &x0, &y0);
- }
- else if (gps->flag & GP_STROKE_2DIMAGE) {
- int offsx, offsy, sizex, sizey;
-
- /* get stored settings */
- sizex= p->im2d_settings.sizex;
- sizey= p->im2d_settings.sizey;
- offsx= p->im2d_settings.offsx;
- offsy= p->im2d_settings.offsy;
-
- /* calculate new points */
- x0= (short)((gps->points->x * sizex) + offsx);
- y0= (short)((gps->points->y * sizey) + offsy);
- }
- else {
- x0= (short)(gps->points->x / 1000 * p->sa->winx);
- y0= (short)(gps->points->y / 1000 * p->sa->winy);
- }
-
- /* do boundbox check first */
- if (BLI_in_rcti(rect, x0, y0)) {
- /* only check if point is inside */
- if ( ((x0-mval[0])*(x0-mval[0]) + (y0-mval[1])*(y0-mval[1])) <= rad*rad ) {
- /* free stroke */
- MEM_freeN(gps->points);
- BLI_freelinkN(&gpf->strokes, gps);
- }
- }
- }
- else {
- /* loop over the points in the stroke, checking for intersections
- * - an intersection will require the stroke to be split
- */
- for (i=0; (i+1) < gps->totpoints; i++) {
- /* get points to work with */
- pt1= gps->points + i;
- pt2= gps->points + i + 1;
-
- /* get coordinates */
- if (gps->flag & GP_STROKE_3DSPACE) {
- project_short(p->ar, &pt1->x, xyval);
- x0= xyval[0];
- y0= xyval[1];
-
- project_short(p->ar, &pt2->x, xyval);
- x1= xyval[0];
- y1= xyval[1];
- }
- else if (gps->flag & GP_STROKE_2DSPACE) {
- UI_view2d_view_to_region(p->v2d, pt1->x, pt1->y, &x0, &y0);
-
- UI_view2d_view_to_region(p->v2d, pt2->x, pt2->y, &x1, &y1);
- }
- else if (gps->flag & GP_STROKE_2DIMAGE) {
- int offsx, offsy, sizex, sizey;
-
- /* get stored settings */
- sizex= p->im2d_settings.sizex;
- sizey= p->im2d_settings.sizey;
- offsx= p->im2d_settings.offsx;
- offsy= p->im2d_settings.offsy;
+ Object *ob= CTX_data_active_object(C);
- /* calculate new points */
- x0= (short)((pt1->x * sizex) + offsx);
- y0= (short)((pt1->y * sizey) + offsy);
+ // TODO: we can include other data-types such as bones later if need be...
- x1= (short)((pt2->x * sizex) + offsx);
- y1= (short)((pt2->y * sizey) + offsy);
- }
- else {
- x0= (short)(pt1->x / 1000 * p->sa->winx);
- y0= (short)(pt1->y / 1000 * p->sa->winy);
- x1= (short)(pt2->x / 1000 * p->sa->winx);
- y1= (short)(pt2->y / 1000 * p->sa->winy);
- }
-
- /* check that point segment of the boundbox of the eraser stroke */
- if (BLI_in_rcti(rect, x0, y0) || BLI_in_rcti(rect, x1, y1)) {
- /* check if point segment of stroke had anything to do with
- * eraser region (either within stroke painted, or on its lines)
- * - this assumes that linewidth is irrelevant
- */
- if (gp_stroke_eraser_strokeinside(mval, mvalo, rad, x0, y0, x1, y1)) {
- /* if function returns true, break this loop (as no more point to check) */
- if (gp_stroke_eraser_splitdel(gpf, gps, i))
- break;
+ /* just in case no active object */
+ if (ob) {
+ /* for now, as long as there's an object, default to using that in 3D-View */
+ if (ptr) RNA_id_pointer_create(&ob->id, ptr);
+ return &ob->gpd;
}
}
- }
- }
-}
-
-/* erase strokes which fall under the eraser strokes */
-static void gp_stroke_doeraser (tGPsdata *p)
-{
- bGPDframe *gpf= p->gpf;
- bGPDstroke *gps, *gpn;
- rcti rect;
-
- /* rect is rectangle of eraser */
- rect.xmin= p->mval[0] - p->radius;
- rect.ymin= p->mval[1] - p->radius;
- rect.xmax= p->mval[0] + p->radius;
- rect.ymax= p->mval[1] + p->radius;
-
- /* loop over strokes, checking segments for intersections */
- for (gps= gpf->strokes.first; gps; gps= gpn) {
- gpn= gps->next;
- gp_stroke_eraser_dostroke(p, p->mval, p->mvalo, p->radius, &rect, gpf, gps);
- }
-}
-
-/* ---------- 'Paint' Tool ------------ */
-
-/* init new painting session */
-static void gp_session_initpaint (bContext *C, tGPsdata *p)
-{
- ScrArea *curarea= CTX_wm_area(C);
- ARegion *ar= CTX_wm_region(C);
-
- /* clear previous data (note: is on stack) */
- memset(p, 0, sizeof(tGPsdata));
-
- /* make sure the active view (at the starting time) is a 3d-view */
- if (curarea == NULL) {
- p->status= GP_STATUS_ERROR;
- if (G.f & G_DEBUG)
- printf("Error: No active view for painting \n");
- return;
- }
-
- /* pass on current scene */
- p->scene= CTX_data_scene(C);
-
- switch (curarea->spacetype) {
- /* supported views first */
- case SPACE_VIEW3D:
- {
- View3D *v3d= curarea->spacedata.first;
-
- /* set current area */
- p->sa= curarea;
- p->ar= ar;
-
- /* check that gpencil data is allowed to be drawn */
- if ((v3d->flag2 & V3D_DISPGP)==0) {
- p->status= GP_STATUS_ERROR;
- if (G.f & G_DEBUG)
- printf("Error: In active view, Grease Pencil not shown \n");
- return;
- }
- }
- break;
- case SPACE_NODE:
- {
- SpaceNode *snode= curarea->spacedata.first;
-
- /* set current area */
- p->sa= curarea;
- p->ar= ar;
- p->v2d= &ar->v2d;
-
- /* check that gpencil data is allowed to be drawn */
- if ((snode->flag & SNODE_DISPGP)==0) {
- p->status= GP_STATUS_ERROR;
- if (G.f & G_DEBUG)
- printf("Error: In active view, Grease Pencil not shown \n");
- return;
- }
- }
- break;
- case SPACE_SEQ:
- {
- SpaceSeq *sseq= curarea->spacedata.first;
-
- /* set current area */
- p->sa= curarea;
- p->ar= ar;
- p->v2d= &ar->v2d;
-
- /* check that gpencil data is allowed to be drawn */
- if (sseq->mainb == SEQ_DRAW_SEQUENCE) {
- p->status= GP_STATUS_ERROR;
- if (G.f & G_DEBUG)
- printf("Error: In active view (sequencer), active mode doesn't support Grease Pencil \n");
- return;
- }
- if ((sseq->flag & SEQ_DRAW_GPENCIL)==0) {
- p->status= GP_STATUS_ERROR;
- if (G.f & G_DEBUG)
- printf("Error: In active view, Grease Pencil not shown \n");
- return;
- }
- }
- break;
- case SPACE_IMAGE:
- {
- SpaceImage *sima= curarea->spacedata.first;
-
- /* set the current area */
- p->sa= curarea;
- p->ar= ar;
- p->v2d= &ar->v2d;
- p->ibuf= BKE_image_get_ibuf(sima->image, &sima->iuser);
+ break;
- /* check that gpencil data is allowed to be drawn */
- if ((sima->flag & SI_DISPGP)==0) {
- p->status= GP_STATUS_ERROR;
- if (G.f & G_DEBUG)
- printf("Error: In active view, Grease Pencil not shown \n");
- return;
- }
- }
- break;
- /* unsupported views */
- default:
- {
- p->status= GP_STATUS_ERROR;
- if (G.f & G_DEBUG)
- printf("Error: Active view not appropriate for Grease Pencil drawing \n");
- return;
- }
- break;
- }
-
- /* get gp-data */
- p->gpd= gpencil_data_getactive(p->sa);
- if (p->gpd == NULL) {
- short ok;
-
- p->gpd= gpencil_data_addnew("GPencil");
- ok= gpencil_data_setactive(p->sa, p->gpd);
-
- /* most of the time, the following check isn't needed */
- if (ok == 0) {
- /* free gpencil data as it can't be used */
- free_gpencil_data(p->gpd);
- p->gpd= NULL;
- p->status= GP_STATUS_ERROR;
- if (G.f & G_DEBUG)
- printf("Error: Could not assign newly created Grease Pencil data to active area \n");
- return;
- }
- }
-
- /* set edit flags */
- G.f |= G_GREASEPENCIL;
-
- /* clear out buffer (stored in gp-data) in case something contaminated it */
- gp_session_validatebuffer(p);
-
- /* set 'default' im2d_settings just in case something that uses this doesn't set it */
- p->im2d_settings.sizex= 1;
- p->im2d_settings.sizey= 1;
-}
-
-/* cleanup after a painting session */
-static void gp_session_cleanup (tGPsdata *p)
-{
- bGPdata *gpd= p->gpd;
-
- /* error checking */
- if (gpd == NULL)
- return;
-
- /* free stroke buffer */
- if (gpd->sbuffer) {
- MEM_freeN(gpd->sbuffer);
- gpd->sbuffer= NULL;
- }
-
- /* clear flags */
- gpd->sbuffer_size= 0;
- gpd->sbuffer_sflag= 0;
-}
-
-/* init new stroke */
-static void gp_paint_initstroke (tGPsdata *p, short paintmode)
-{
- /* get active layer (or add a new one if non-existent) */
- p->gpl= gpencil_layer_getactive(p->gpd);
- if (p->gpl == NULL)
- p->gpl= gpencil_layer_addnew(p->gpd);
- if (p->gpl->flag & GP_LAYER_LOCKED) {
- p->status= GP_STATUS_ERROR;
- if (G.f & G_DEBUG)
- printf("Error: Cannot paint on locked layer \n");
- return;
- }
-
- /* get active frame (add a new one if not matching frame) */
- p->gpf= gpencil_layer_getframe(p->gpl, p->scene->r.cfra, 1);
- if (p->gpf == NULL) {
- p->status= GP_STATUS_ERROR;
- if (G.f & G_DEBUG)
- printf("Error: No frame created (gpencil_paint_init) \n");
- return;
- }
- else
- p->gpf->flag |= GP_FRAME_PAINT;
-
- /* set 'eraser' for this stroke if using eraser */
- p->paintmode= paintmode;
- if (p->paintmode == GP_PAINTMODE_ERASER)
- p->gpd->sbuffer_sflag |= GP_STROKE_ERASER;
-
- /* check if points will need to be made in view-aligned space */
- if (p->gpd->flag & GP_DATA_VIEWALIGN) {
- switch (p->sa->spacetype) {
- case SPACE_VIEW3D:
+ case SPACE_NODE: /* Nodes Editor */
{
- View3D *v3d= (View3D *)p->sa->spacedata.first;
- RegionView3D *rv3d= NULL; // XXX
- float *fp= give_cursor(p->scene, v3d);
+ //SpaceNode *snode= (SpaceNode *)CTX_wm_space_data(C);
- initgrabz(rv3d, fp[0], fp[1], fp[2]);
-
- p->gpd->sbuffer_sflag |= GP_STROKE_3DSPACE;
+ /* return the GP data for the active node block/node */
}
break;
- case SPACE_NODE:
- {
- p->gpd->sbuffer_sflag |= GP_STROKE_2DSPACE;
- }
- break;
- case SPACE_SEQ:
- {
- SpaceSeq *sseq= (SpaceSeq *)p->sa->spacedata.first;
- int rectx, recty;
- float zoom, zoomx, zoomy;
-
- /* set draw 2d-stroke flag */
- p->gpd->sbuffer_sflag |= GP_STROKE_2DIMAGE;
- /* calculate zoom factor */
- zoom= (float)(SEQ_ZOOM_FAC(sseq->zoom));
- if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
- zoomx = zoom * ((float)p->scene->r.xasp / (float)p->scene->r.yasp);
- zoomy = zoom;
- }
- else
- zoomx = zoomy = zoom;
-
- /* calculate rect size to use to calculate the size of the drawing area
- * - We use the size of the output image not the size of the ibuf being shown
- * as it is too messy getting the ibuf (and could be too slow). This should be
- * a reasonable for most cases anyway.
- */
- rectx= (p->scene->r.size * p->scene->r.xsch) / 100;
- recty= (p->scene->r.size * p->scene->r.ysch) / 100;
-
- /* set offset and scale values for opertations to use */
- p->im2d_settings.sizex= (int)(zoomx * rectx);
- p->im2d_settings.sizey= (int)(zoomy * recty);
- p->im2d_settings.offsx= (int)((p->sa->winx-p->im2d_settings.sizex)/2 + sseq->xof);
- p->im2d_settings.offsy= (int)((p->sa->winy-p->im2d_settings.sizey)/2 + sseq->yof);
- }
- break;
- case SPACE_IMAGE:
+ case SPACE_SEQ: /* Sequencer */
{
- /* check if any ibuf available */
- if (p->ibuf)
- p->gpd->sbuffer_sflag |= GP_STROKE_2DSPACE;
+ //SpaceSeq *sseq= (SpaceSeq *)CTX_wm_space_data(C);
+
+ /* return the GP data for the active strips/image/etc. */
}
break;
}
}
-}
-
-/* finish off a stroke (clears buffer, but doesn't finish the paint operation) */
-static void gp_paint_strokeend (tGPsdata *p)
-{
- /* check if doing eraser or not */
- if ((p->gpd->sbuffer_sflag & GP_STROKE_ERASER) == 0) {
- /* smooth stroke before transferring? */
- gp_stroke_smooth(p);
-
- /* simplify stroke before transferring? */
- gp_stroke_simplify(p);
-
- /* transfer stroke to frame */
- gp_stroke_newfrombuffer(p);
- }
- /* clean up buffer now */
- gp_session_validatebuffer(p);
+ /* just fall back on the scene's GP data */
+ if (ptr) RNA_id_pointer_create((ID *)scene, ptr);
+ return (scene) ? &scene->gpd : NULL;
}
-/* finish off stroke painting operation */
-static void gp_paint_cleanup (tGPsdata *p)
+/* Get the active Grease Pencil datablock */
+bGPdata *gpencil_data_get_active (bContext *C)
{
- /* finish off a stroke */
- gp_paint_strokeend(p);
-
- /* "unlock" frame */
- p->gpf->flag &= ~GP_FRAME_PAINT;
-
- /* add undo-push so stroke can be undone */
- /* FIXME: currently disabled, as it's impossible to get this working nice
- * as gpenci data is on currently screen-level (which isn't saved to undo files)
- */
- //BIF_undo_push("GPencil Stroke");
-
- /* force redraw after drawing action */
- // XXX force_draw_plus(SPACE_ACTION, 0);
+ bGPdata **gpd_ptr= gpencil_data_get_pointers(C, NULL);
+ return (gpd_ptr) ? *(gpd_ptr) : NULL;
}
-/* -------- */
-
-/* main call to paint a new stroke */
-// XXX will become modal(), gets event, includes all info!
-short gpencil_paint (bContext *C, short paintmode)
-{
- tGPsdata p;
- short ok = GP_STROKEADD_NORMAL;
-
- /* init paint-data */
- gp_session_initpaint(C, &p);
- if (p.status == GP_STATUS_ERROR) {
- gp_session_cleanup(&p);
- return 0;
- }
- gp_paint_initstroke(&p, paintmode);
- if (p.status == GP_STATUS_ERROR) {
- gp_session_cleanup(&p);
- return 0;
- }
-
- /* set cursor to indicate drawing */
- // XXX (cursor callbacks in regiontype) setcursor_space(p.sa->spacetype, CURSOR_VPAINT);
-
- /* init drawing-device settings */
- // XXX getmouseco_areawin(p.mval);
- // XXX p.pressure = get_pressure();
-
- p.mvalo[0]= p.mval[0];
- p.mvalo[1]= p.mval[1];
- p.opressure= p.pressure;
-
- /* radius for eraser circle is defined in userprefs now */
- // TODO: make this more easily tweaked...
- p.radius= U.gp_eraser;
-
- /* start drawing eraser-circle (if applicable) */
- //if (paintmode == GP_PAINTMODE_ERASER)
- // XXX draw_sel_circle(p.mval, NULL, p.radius, p.radius, 0); // draws frontbuffer, but sets backbuf again
-
- /* only allow painting of single 'dots' if:
- * - pressure is not excessive (as it can be on some windows tablets)
- * - draw-mode for active datablock is turned on
- * - not erasing
- */
- if (paintmode != GP_PAINTMODE_ERASER) {
- if (!(p.pressure >= 0.99f) || (p.gpd->flag & GP_DATA_EDITPAINT)) {
- gp_stroke_addpoint(&p, p.mval, p.pressure);
- }
- }
-
- /* XXX paint loop */
- if(0) {
- /* get current user input */
- // XXX getmouseco_areawin(p.mval);
- // XXX p.pressure = get_pressure();
-
- /* only add current point to buffer if mouse moved (otherwise wait until it does) */
- if (paintmode == GP_PAINTMODE_ERASER) {
- /* do 'live' erasing now */
- gp_stroke_doeraser(&p);
-
- // XXX draw_sel_circle(p.mval, p.mvalo, p.radius, p.radius, 0);
- // XXX force_draw(0);
-
- p.mvalo[0]= p.mval[0];
- p.mvalo[1]= p.mval[1];
- p.opressure= p.pressure;
- }
- else if (gp_stroke_filtermval(&p, p.mval, p.mvalo)) {
- /* try to add point */
- ok= gp_stroke_addpoint(&p, p.mval, p.pressure);
-
- /* handle errors while adding point */
- if ((ok == GP_STROKEADD_FULL) || (ok == GP_STROKEADD_OVERFLOW)) {
- /* finish off old stroke */
- gp_paint_strokeend(&p);
-
- /* start a new stroke, starting from previous point */
- gp_stroke_addpoint(&p, p.mvalo, p.opressure);
- ok= gp_stroke_addpoint(&p, p.mval, p.pressure);
- }
- else if (ok == GP_STROKEADD_INVALID) {
- /* the painting operation cannot continue... */
- error("Cannot paint stroke");
- p.status = GP_STATUS_ERROR;
-
- if (G.f & G_DEBUG)
- printf("Error: Grease-Pencil Paint - Add Point Invalid \n");
- // XXX break;
- }
- // XXX force_draw(0);
-
- p.mvalo[0]= p.mval[0];
- p.mvalo[1]= p.mval[1];
- p.opressure= p.pressure;
- }
-
- /* do mouse checking at the end, so don't check twice, and potentially
- * miss a short tap
- */
- }
-
- /* clear edit flags */
- G.f &= ~G_GREASEPENCIL;
-
- /* restore cursor to indicate end of drawing */
- // XXX (cursor callbacks in regiontype) setcursor_space(p.sa->spacetype, CURSOR_STD);
-
- /* check size of buffer before cleanup, to determine if anything happened here */
- if (paintmode == GP_PAINTMODE_ERASER) {
- ok= 1; /* assume that we did something... */
- // XXX draw_sel_circle(NULL, p.mvalo, 0, p.radius, 0);
- }
- else
- ok= p.gpd->sbuffer_size;
-
- /* cleanup */
- gp_paint_cleanup(&p);
- gp_session_cleanup(&p);
-
- /* done! return if a stroke was successfully added */
- return ok;
-}
+/* ************************************************ */
+/* Panel Operators */
-/* All event (loops) handling checking if stroke drawing should be initiated
- * should call this function.
- */
-short gpencil_do_paint (bContext *C)
-{
- ScrArea *sa= CTX_wm_area(C);
- bGPdata *gpd = gpencil_data_getactive(sa);
- short retval= 0;
- int alt= 0, shift= 0, mbut= 0; // XXX
-
- /* check if possible to do painting */
- if (gpd == NULL)
- return 0;
-
- /* currently, we will only 'paint' if:
- * 1. draw-mode on gpd is set (for accessibility reasons)
- * a) single dots are only available by this method if a single click is made
- * b) a straight line is drawn if ctrl-modifier is held (check is done when stroke is converted!)
- * 2. if shift-modifier is held + lmb -> 'quick paint'
- *
- * OR
- *
- * draw eraser stroke if:
- * 1. using the eraser on a tablet
- * 2. draw-mode on gpd is set (for accessiblity reasons)
- * (eraser is mapped to right-mouse)
- * 3. Alt + 'select' mouse-button
- * i.e. if LMB = select: Alt-LMB
- * if RMB = select: Alt-RMB
- */
- if (get_activedevice() == 2) {
- /* eraser on a tablet - always try to erase strokes */
- retval = gpencil_paint(C, GP_PAINTMODE_ERASER);
- }
- else if (gpd->flag & GP_DATA_EDITPAINT) {
- /* try to paint/erase */
- if (mbut == L_MOUSE)
- retval = gpencil_paint(C, GP_PAINTMODE_DRAW);
- else if (mbut == R_MOUSE)
- retval = gpencil_paint(C, GP_PAINTMODE_ERASER);
- }
- else if (!(gpd->flag & GP_DATA_LMBPLOCK)) {
- /* try to paint/erase as not locked */
- if (shift && (mbut == L_MOUSE)) {
- retval = gpencil_paint(C, GP_PAINTMODE_DRAW);
- }
- else if (alt) {
- if ((U.flag & USER_LMOUSESELECT) && (mbut == L_MOUSE))
- retval = gpencil_paint(C, GP_PAINTMODE_ERASER);
- else if (!(U.flag & USER_LMOUSESELECT) && (mbut == R_MOUSE))
- retval = gpencil_paint(C, GP_PAINTMODE_ERASER);
- }
- }
-
- /* return result of trying to paint */
- return retval;
-}
-/* ************************************************** */
-#endif // XXX COMPILE GUARDS FOR OLD CODE
+/* ************************************************ */
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 2f60efb2179..d6bdea2db55 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1,5 +1,28 @@
-/* Grease Pencil - version 2
- * By Joshua Leung
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2008, Blender Foundation, Joshua Leung
+ * This is a new part of Blender
+ *
+ * Contributor(s): Joshua Leung
+ *
+ * ***** END GPL LICENSE BLOCK *****
*/
#include <stdio.h>
@@ -38,8 +61,8 @@
#include "ED_view3d.h"
#include "RNA_access.h"
-#include "RNA_define.h"
+#include "RNA_define.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -48,65 +71,6 @@
/* ******************************************* */
/* Context Wrangling... */
-/* Get the active Grease Pencil datablock */
-// TODO: move this to a gpencil_utils.c?
-bGPdata *gpencil_data_getactive (bContext *C)
-{
- Scene *scene= CTX_data_scene(C);
- ScrArea *sa= CTX_wm_area(C);
-
- /* if there's an active area, check if the particular editor may
- * have defined any special Grease Pencil context for editing...
- */
- if (sa) {
- switch (sa->spacetype) {
- case SPACE_VIEW3D: /* 3D-View */
- {
- Object *ob= CTX_data_active_object(C);
-
- /* just in case... */
- if (ob) {
- /* depending on the mode of the object, we may be able to get some GP data
- * from different elements - i.e. bones...
- */
- if (ob->mode & OB_MODE_POSE) {
- //bPoseChannel *pchan= CTX_data_active_pchan(C);
-
- /* if posechannel has GP data, use that... */
- //if (pchan && pchan->gpd)
- // return pchan->gpd;
- }
-
- /* still here, so check if active Object has GP data */
- //if (ob->gpd)
- // return ob->gpd;
- }
- }
- break;
-
- case SPACE_NODE: /* Nodes Editor */
- {
- //SpaceNode *snode= (SpaceNode *)CTX_wm_space_data(C);
-
- /* return the GP data for the active node block/node */
- }
- break;
-
- case SPACE_SEQ: /* Sequencer */
- {
- //SpaceSeq *sseq= (SpaceSeq *)CTX_wm_space_data(C);
-
- /* return the GP data for the active strips/image/etc. */
- }
- break;
- }
- }
-
- /* just fall back on the scene's GP data */
- return (scene) ? scene->gpd : NULL;
-}
-
-
/* check if context is suitable for drawing */
static int gpencil_draw_poll (bContext *C)
{
@@ -282,8 +246,8 @@ static void gp_stroke_convertcoords (tGPsdata *p, short mval[], float out[])
/* 2d - relative to screen (viewport area) */
else {
- out[0] = (float)(mval[0]) / (float)(p->sa->winx) * 1000;
- out[1] = (float)(mval[1]) / (float)(p->sa->winy) * 1000;
+ out[0] = (float)(mval[0]) / (float)(p->sa->winx) * 100;
+ out[1] = (float)(mval[1]) / (float)(p->sa->winy) * 100;
}
}
@@ -616,8 +580,8 @@ static void gp_stroke_eraser_dostroke (tGPsdata *p, int mval[], int mvalo[], sho
}
#endif
else {
- x0= (int)(gps->points->x / 1000 * p->sa->winx);
- y0= (int)(gps->points->y / 1000 * p->sa->winy);
+ x0= (int)(gps->points->x / 100 * p->sa->winx);
+ y0= (int)(gps->points->y / 100 * p->sa->winy);
}
/* do boundbox check first */
@@ -673,10 +637,10 @@ static void gp_stroke_eraser_dostroke (tGPsdata *p, int mval[], int mvalo[], sho
}
#endif
else {
- x0= (int)(pt1->x / 1000 * p->sa->winx);
- y0= (int)(pt1->y / 1000 * p->sa->winy);
- x1= (int)(pt2->x / 1000 * p->sa->winx);
- y1= (int)(pt2->y / 1000 * p->sa->winy);
+ x0= (int)(pt1->x / 100 * p->sa->winx);
+ y0= (int)(pt1->y / 100 * p->sa->winy);
+ x1= (int)(pt2->x / 100 * p->sa->winx);
+ y1= (int)(pt2->y / 100 * p->sa->winy);
}
/* check that point segment of the boundbox of the eraser stroke */
@@ -740,6 +704,7 @@ static void gp_session_validatebuffer (tGPsdata *p)
static tGPsdata *gp_session_initpaint (bContext *C)
{
tGPsdata *p = NULL;
+ bGPdata **gpd_ptr = NULL;
ScrArea *curarea= CTX_wm_area(C);
ARegion *ar= CTX_wm_region(C);
@@ -852,11 +817,18 @@ static tGPsdata *gp_session_initpaint (bContext *C)
}
/* get gp-data */
- p->gpd= gpencil_data_getactive(C);
- if (p->gpd == NULL) {
- /* add new GPencil block for the active scene for now... */
- p->gpd= gpencil_data_addnew("GPencil");
- p->scene->gpd= p->gpd;
+ gpd_ptr= gpencil_data_get_pointers(C, NULL);
+ if (gpd_ptr == NULL) {
+ p->status= GP_STATUS_ERROR;
+ if (G.f & G_DEBUG)
+ printf("Error: Current context doesn't allow for any Grease Pencil data \n");
+ return p;
+ }
+ else {
+ /* if no existing GPencil block exists, add one */
+ if (*gpd_ptr == NULL)
+ *gpd_ptr= gpencil_data_addnew("GPencil");
+ p->gpd= *gpd_ptr;
}
/* set edit flags - so that buffer will get drawn */
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index c1e37ce2e81..25e622d8551 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -38,49 +38,35 @@ struct SpaceSeq;
struct bGPdata;
struct bGPDlayer;
struct bGPDframe;
-struct bGPdata;
+struct PointerRNA;
+struct uiLayout;
struct uiBlock;
struct ImBuf;
struct wmWindowManager;
-/* ------------- Grease-Pencil Helpers -------------- */
+/* ------------- Grease-Pencil Helpers ---------------- */
-/* Temporary 'Stroke Point' data */
+/* Temporary 'Stroke Point' data
+ *
+ * Used as part of the 'stroke cache' used during drawing of new strokes
+ */
typedef struct tGPspoint {
short x, y; /* x and y coordinates of cursor (in relative to area) */
float pressure; /* pressure of tablet at this point */
} tGPspoint;
-/* ----------- Grease Pencil New Tools ------------- */
+/* ----------- Grease Pencil Tools/Context ------------- */
-struct bGPdata *gpencil_data_getactive(struct bContext *C);
+struct bGPdata **gpencil_data_get_pointers(struct bContext *C, struct PointerRNA *ptr);
+struct bGPdata *gpencil_data_get_active(struct bContext *C);
-/* ----------- Grease Pencil Operators ------------- */
+/* ----------- Grease Pencil Operators ----------------- */
void gpencil_common_keymap(struct wmWindowManager *wm, ListBase *keymap);
void ED_operatortypes_gpencil(void);
-/* ------------ Grease-Pencil Depreceated Stuff ------------------ */
-
-//struct bGPdata *gpencil_data_getactive(struct ScrArea *sa);
-short gpencil_data_setactive(struct ScrArea *sa, struct bGPdata *gpd);
-struct ScrArea *gpencil_data_findowner(struct bGPdata *gpd);
-
-/* ------------ Grease-Pencil Editing API ------------------ */
-
-void gpencil_delete_actframe(struct bGPdata *gpd, int cfra);
-void gpencil_delete_laststroke(struct bGPdata *gpd, int cfra);
-
-void gpencil_delete_operation(int cfra, short mode);
-void gpencil_delete_menu(void);
-
-void gpencil_convert_operation(short mode);
-void gpencil_convert_menu(void);
-
-short gpencil_do_paint(struct bContext *C);
-
/* ------------ Grease-Pencil Drawing API ------------------ */
/* drawgpencil.c */
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index 48947794620..5c5b7281f20 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -4736,7 +4736,7 @@ void special_aftertrans_update(TransInfo *t)
* - sync this with actdata_filter_gpencil() in editaction.c
*/
for (sa= sc->areabase.first; sa; sa= sa->next) {
- bGPdata *gpd= gpencil_data_getactive(sa);
+ bGPdata *gpd= gpencil_data_get_active(sa);
if (gpd)
posttrans_gpd_clean(gpd);
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index 25fdf615adb..d1e70c16408 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -54,7 +54,10 @@ struct FluidsimSettings;
struct ParticleSystem;
struct DerivedMesh;
struct SculptSession;
+struct bGPdata;
+
+/* Vertex Groups - Name Info */
typedef struct bDeformGroup {
struct bDeformGroup *next, *prev;
char name[32];
@@ -110,6 +113,8 @@ typedef struct Object {
struct bPose *pose;
void *data;
+ struct bGPdata *gpd; /* Grease Pencil data */
+
ListBase constraintChannels; // XXX depreceated... old animation system
ListBase effect;
ListBase disp;
@@ -209,7 +214,7 @@ typedef struct Object {
short recalc; /* dependency flag */
float anisotropicFriction[3];
- ListBase constraints;
+ ListBase constraints; /* object constraints */
ListBase nlastrips; // XXX depreceated... old animation system
ListBase hooks;
ListBase particlesystem; /* particle systems */
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index f0b055bd0e8..cae96b0af4b 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -1464,6 +1464,13 @@ static void rna_def_object(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "X-Ray", "Makes the object draw in front of others.");
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+ /* Grease Pencil */
+ prop= RNA_def_property(srna, "grease_pencil", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "gpd");
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_struct_type(prop, "GreasePencil");
+ RNA_def_property_ui_text(prop, "Grease Pencil Data", "Grease Pencil datablock");
+
/* pose */
prop= RNA_def_property(srna, "pose_library", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "poselib");