From 7df39b5ea2bd8bfd0c5a2a08aa2c52d051aa5fd5 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sun, 30 Aug 2009 13:32:08 +0000 Subject: Grease Pencil: Basic Support for Image Editor Again * Grease Pencil works again from Image Editor now. For now, the GPencil datablock is linked to the Image Editor space, but this can be changed if need be. * Made Grease Pencil hotkeys into a separate Grease Pencil keymap, which can get included automagically like for frames/ui/v2d/etc. by supplying ED_KEYMAP_GPENCIL as part of st->keymapflag * Temporarily restored the nasty hack to make View2D-aligned sketches in Image Editor to use OpenGL lines only. I still dunno why this doesn't work normally. (Probably related is that strokes are not visible when there's no image visible atm). --- source/blender/editors/gpencil/drawgpencil.c | 17 ++++++++++++----- source/blender/editors/gpencil/gpencil_edit.c | 11 +++++++++++ source/blender/editors/gpencil/gpencil_ops.c | 7 ++----- source/blender/editors/gpencil/gpencil_paint.c | 15 ++++++++------- 4 files changed, 33 insertions(+), 17 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index d6678b50d7b..81ee2378717 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -83,6 +83,7 @@ enum { GP_DRAWDATA_ONLY3D = (1<<1), /* only draw 3d-strokes */ GP_DRAWDATA_ONLYV2D = (1<<2), /* only draw 'canvas' strokes */ GP_DRAWDATA_ONLYI2D = (1<<3), /* only draw 'image' strokes */ + GP_DRAWDATA_IEDITHACK = (1<<4), /* special hack for drawing strokes in Image Editor (weird coordinates) */ }; /* thickness above which we should use special drawing */ @@ -254,14 +255,12 @@ static void gp_draw_stroke_3d (bGPDspoint *points, int totpoints, short thicknes /* draw a given stroke in 2d */ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness, short dflag, short sflag, short debug, int offsx, int offsy, int winx, int winy) -{ - int spacetype= 0; // XXX make local gpencil state var? - +{ /* if thickness is less than GP_DRAWTHICKNESS_SPECIAL, 'smooth' opengl lines look better * - 'smooth' opengl lines are also required if Image Editor 'image-based' stroke */ if ( (thickness < GP_DRAWTHICKNESS_SPECIAL) || - ((spacetype==SPACE_IMAGE) && (dflag & GP_DRAWDATA_ONLYV2D)) ) + ((dflag & GP_DRAWDATA_IEDITHACK) && (dflag & GP_DRAWDATA_ONLYV2D)) ) { bGPDspoint *pt; int i; @@ -519,6 +518,9 @@ static void gp_draw_data (bGPdata *gpd, int offsx, int offsy, int winx, int winy { bGPDlayer *gpl, *actlay=NULL; + /* reset line drawing style (in case previous user didn't reset) */ + setlinestyle(0); + /* turn on smooth lines (i.e. anti-aliasing) */ glEnable(GL_LINE_SMOOTH); @@ -669,7 +671,7 @@ void draw_gpencil_2dimage (bContext *C, ImBuf *ibuf) wmOrtho2(ar->v2d.cur.xmin, ar->v2d.cur.xmax, ar->v2d.cur.ymin, ar->v2d.cur.ymax); - dflag |= GP_DRAWDATA_ONLYV2D; + dflag |= GP_DRAWDATA_ONLYV2D|GP_DRAWDATA_IEDITHACK; } break; @@ -729,6 +731,11 @@ void draw_gpencil_2dview (bContext *C, short onlyv2d) gpd= gpencil_data_get_active(C); // XXX if (gpd == NULL) return; + /* special hack for Image Editor */ + // FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled + if (sa->spacetype == SPACE_IMAGE) + dflag |= GP_DRAWDATA_IEDITHACK; + /* draw it! */ if (onlyv2d) dflag |= (GP_DRAWDATA_ONLYV2D|GP_DRAWDATA_NOSTATUS); gp_draw_data(gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag); diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index b2228134750..74fbe250d37 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -125,6 +125,17 @@ bGPdata **gpencil_data_get_pointers (bContext *C, PointerRNA *ptr) } break; + case SPACE_IMAGE: /* Image/UV Editor */ + { + SpaceImage *sima= (SpaceImage *)CTX_wm_space_data(C); + + /* for now, Grease Pencil data is associated with the space... */ + // XXX our convention for everything else is to link to data though... + if (ptr) RNA_pointer_create((ID *)CTX_wm_screen(C), &RNA_SpaceImageEditor, sima, ptr); + return &sima->gpd; + } + break; + default: /* unsupported space */ return NULL; } diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c index 2d23a331211..3acbded0bf8 100644 --- a/source/blender/editors/gpencil/gpencil_ops.c +++ b/source/blender/editors/gpencil/gpencil_ops.c @@ -45,14 +45,11 @@ /* ****************************************** */ /* Generic Editing Keymap */ -void gpencil_common_keymap(wmWindowManager *wm, ListBase *keymap) +void ED_keymap_gpencil(wmWindowManager *wm) { + ListBase *keymap= WM_keymap_listbase(wm, "Grease Pencil", 0, 0); wmKeymapItem *kmi; - /* if no keymap provided, use default */ - if (keymap == NULL) - keymap= WM_keymap_listbase(wm, "Grease Pencil Generic", 0, 0); - /* Draw */ /* draw */ WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, 0, DKEY); diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index b5d25ce651f..67bf2951bf8 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -828,6 +828,7 @@ static tGPsdata *gp_session_initpaint (bContext *C) } } break; +#endif case SPACE_IMAGE: { SpaceImage *sima= curarea->spacedata.first; @@ -836,18 +837,20 @@ static tGPsdata *gp_session_initpaint (bContext *C) p->sa= curarea; p->ar= ar; p->v2d= &ar->v2d; - p->ibuf= BKE_image_get_ibuf(sima->image, &sima->iuser); + //p->ibuf= BKE_image_get_ibuf(sima->image, &sima->iuser); +#if 0 // XXX disabled for now /* 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; + return p; } +#endif } break; -#endif + /* unsupported views */ default: { @@ -998,14 +1001,12 @@ static void gp_paint_initstroke (tGPsdata *p, short paintmode) p->im2d_settings.offsy= (int)((p->sa->winy-p->im2d_settings.sizey)/2 + sseq->yof); } break; +#endif case SPACE_IMAGE: { - /* check if any ibuf available */ - if (p->ibuf) - p->gpd->sbuffer_sflag |= GP_STROKE_2DSPACE; + p->gpd->sbuffer_sflag |= GP_STROKE_2DSPACE; } break; -#endif } } } -- cgit v1.2.3