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).
This commit is contained in:
Joshua Leung
2009-08-30 13:32:08 +00:00
parent d4d520c9a2
commit 7df39b5ea2
14 changed files with 82 additions and 49 deletions

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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
}
}
}

View File

@@ -62,8 +62,7 @@ struct bGPdata *gpencil_data_get_active(struct bContext *C);
/* ----------- Grease Pencil Operators ----------------- */
void gpencil_common_keymap(struct wmWindowManager *wm, ListBase *keymap);
void ED_keymap_gpencil(struct wmWindowManager *wm);
void ED_operatortypes_gpencil(void);
/* ------------ Grease-Pencil Drawing API ------------------ */

View File

@@ -150,7 +150,7 @@ int ED_operator_posemode(struct bContext *C);
#define ED_KEYMAP_MARKERS 4
#define ED_KEYMAP_ANIMATION 8
#define ED_KEYMAP_FRAMES 16
#define ED_KEYMAP_GPENCIL 32
#endif /* ED_SCREEN_H */

View File

@@ -797,6 +797,10 @@ static void ed_default_handlers(wmWindowManager *wm, ListBase *handlers, int fla
ListBase *keymap= WM_keymap_listbase(wm, "Frames", 0, 0);
WM_event_add_keymap_handler(handlers, keymap);
}
if(flag & ED_KEYMAP_GPENCIL) {
ListBase *keymap= WM_keymap_listbase(wm, "Grease Pencil", 0, 0);
WM_event_add_keymap_handler(handlers, keymap);
}
}

View File

@@ -86,6 +86,7 @@ void ED_spacetypes_init(void)
ED_operatortypes_screen();
ED_operatortypes_anim();
ED_operatortypes_animchannels();
ED_operatortypes_gpencil();
ED_operatortypes_object();
ED_operatortypes_mesh();
ED_operatortypes_sculpt();
@@ -99,7 +100,6 @@ void ED_spacetypes_init(void)
ED_operatortypes_fluid();
ED_operatortypes_metaball();
ED_operatortypes_boids();
ED_operatortypes_gpencil();
ED_operatortypes_sound();
ui_view2d_operatortypes();
@@ -121,6 +121,7 @@ void ED_spacetypes_keymap(wmWindowManager *wm)
ED_keymap_screen(wm);
ED_keymap_anim(wm);
ED_keymap_animchannels(wm);
ED_keymap_gpencil(wm);
ED_keymap_object(wm);
ED_keymap_mesh(wm);
ED_keymap_uvedit(wm);

View File

@@ -67,6 +67,7 @@
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "ED_gpencil.h"
#include "ED_image.h"
#include "ED_mesh.h"
#include "ED_space_api.h"
@@ -1438,6 +1439,12 @@ void image_buttons_register(ARegionType *art)
strcpy(pt->label, "Curves");
pt->draw= image_panel_curves;
BLI_addtail(&art->paneltypes, pt);
pt= MEM_callocN(sizeof(PanelType), "spacetype image panel gpencil");
strcpy(pt->idname, "IMAGE_PT_gpencil");
strcpy(pt->label, "Grease Pencil");
pt->draw= gpencil_panel_standard;
BLI_addtail(&art->paneltypes, pt);
}
static int image_properties(bContext *C, wmOperator *op)

View File

@@ -44,6 +44,7 @@
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "BKE_context.h"
#include "BKE_colortools.h"
#include "BKE_global.h"
#include "BKE_image.h"
@@ -53,6 +54,7 @@
#include "BIF_gl.h"
#include "BIF_glutil.h"
#include "ED_gpencil.h"
#include "ED_image.h"
#include "ED_screen.h"
@@ -525,22 +527,26 @@ static void draw_image_buffer_repeated(SpaceImage *sima, ARegion *ar, Scene *sce
/* draw uv edit */
/* draw grease pencil */
static void draw_image_grease_pencil(SpaceImage *sima, ImBuf *ibuf)
void draw_image_grease_pencil(bContext *C, short onlyv2d)
{
/* XXX bring back */
/* draw grease-pencil ('image' strokes) */
if (sima->flag & SI_DISPGP)
; // XXX draw_gpencil_2dimage(sa, ibuf);
#if 0
mywinset(sa->win); /* restore scissor after gla call... */
wmOrtho2(-0.375, sa->winx-0.375, -0.375, sa->winy-0.375);
#endif
/* draw grease-pencil (screen strokes) */
if (sima->flag & SI_DISPGP)
; // XXX draw_gpencil_2dview(sa, NULL);
/* draw in View2D space? */
if (onlyv2d) {
/* assume that UI_view2d_ortho(C) has been called... */
SpaceImage *sima= (SpaceImage *)CTX_wm_space_data(C);
ImBuf *ibuf= ED_space_image_buffer(sima);
/* draw grease-pencil ('image' strokes) */
//if (sima->flag & SI_DISPGP)
draw_gpencil_2dimage(C, ibuf);
}
else {
/* assume that UI_view2d_restore(C) has been called... */
SpaceImage *sima= (SpaceImage *)CTX_wm_space_data(C);
/* draw grease-pencil ('screen' strokes) */
//if (sima->flag & SI_DISPGP)
draw_gpencil_2dview(C, 0);
}
}
/* XXX becomes WM paint cursor */
@@ -689,9 +695,6 @@ void draw_image_main(SpaceImage *sima, ARegion *ar, Scene *scene)
else
draw_image_buffer(sima, ar, scene, ima, ibuf, 0.0f, 0.0f, zoomx, zoomy);
/* grease pencil */
draw_image_grease_pencil(sima, ibuf);
/* paint helpers */
draw_image_paint_helpers(sima, ar, scene, zoomx, zoomy);

View File

@@ -53,6 +53,7 @@ void IMAGE_OT_toolbox(struct wmOperatorType *ot);
/* image_draw.c */
void draw_image_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene);
void draw_image_info(struct ARegion *ar, int channels, int x, int y, char *cp, float *fp, int *zp, float *zpf);
void draw_image_grease_pencil(struct bContext *C, short onlyv2d);
/* image_ops.c */
int space_image_main_area_poll(struct bContext *C);

View File

@@ -54,6 +54,7 @@
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "ED_gpencil.h"
#include "ED_image.h"
#include "ED_mesh.h"
#include "ED_space_api.h"
@@ -430,16 +431,22 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
/* we set view2d from own zoom and offset each time */
image_main_area_set_view2d(sima, ar, scene);
/* we draw image in pixelspace */
draw_image_main(sima, ar, scene);
/* and uvs in 0.0-1.0 space */
UI_view2d_view_ortho(C, v2d);
draw_uvedit_main(sima, ar, scene, obedit);
ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST);
draw_uvedit_main(sima, ar, scene, obedit);
ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST);
/* Grease Pencil too (in addition to UV's) */
draw_image_grease_pencil((bContext *)C, 1);
UI_view2d_view_restore(C);
/* draw Grease Pencil - screen space only */
draw_image_grease_pencil((bContext *)C, 0);
/* scrollers? */
/*scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
UI_view2d_scrollers_draw(C, v2d, scrollers);
@@ -558,11 +565,10 @@ void ED_spacetype_image(void)
/* regions: main window */
art= MEM_callocN(sizeof(ARegionType), "spacetype image region");
art->regionid = RGN_TYPE_WINDOW;
art->keymapflag= ED_KEYMAP_FRAMES;
art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_GPENCIL;
art->init= image_main_area_init;
art->draw= image_main_area_draw;
art->listener= image_main_area_listener;
art->keymapflag= 0;
BLI_addhead(&st->regiontypes, art);

View File

@@ -871,7 +871,7 @@ void ED_spacetype_view3d(void)
/* regions: main window */
art= MEM_callocN(sizeof(ARegionType), "spacetype view3d region");
art->regionid = RGN_TYPE_WINDOW;
art->keymapflag= ED_KEYMAP_FRAMES;
art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_GPENCIL;
art->draw= view3d_main_area_draw;
art->init= view3d_main_area_init;
art->free= view3d_main_area_free;

View File

@@ -52,7 +52,6 @@
#include "WM_api.h"
#include "WM_types.h"
#include "ED_gpencil.h"
#include "ED_screen.h"
#include "ED_transform.h"
@@ -133,9 +132,6 @@ void view3d_keymap(wmWindowManager *wm)
km = WM_keymap_add_item(keymap, "SKETCH_OT_draw_preview", MOUSEMOVE, KM_ANY, KM_CTRL, 0);
RNA_boolean_set(km->ptr, "snap", 1);
/* grease pencil */
gpencil_common_keymap(wm, keymap);
WM_keymap_verify_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, 0, 0); /* manipulator always on left mouse, not on action mouse*/
WM_keymap_verify_item(keymap, "VIEW3D_OT_cursor3d", ACTIONMOUSE, KM_PRESS, 0, 0);