diff options
author | Ton Roosendaal <ton@blender.org> | 2009-01-09 18:04:52 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2009-01-09 18:04:52 +0300 |
commit | 2fe5005bbb6b81831eba33f3d6a93c4719b912a0 (patch) | |
tree | 9acfe689896396844f5466bafab10cfa91e47ab6 /source/blender/editors | |
parent | c7fa55eebdd74812c5bd993e8ec54ec5b04197f2 (diff) |
2.5
New: Custom region draw callbacks.
For Martin: an example is now in space_view3d/view3d_edit.c
On middlemouse rotate view, it draws a small square in center.
It works likes this:
#include "ED_space_api.h"
handle= ED_region_draw_cb_activate(region->type, drawfunc, type)
and to stop it:
ED_region_draw_cb_exit(region->type, handle)
drawfunc is of type (const bContext *C, ARegion *ar)
currently it gets called only as type REGION_DRAW_POST, later we
can add more (PRE, POST_XRAY, POST_2D, etc).
For correct usage, these calls should return leaving view transform
unaltered.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_space_api.h | 12 | ||||
-rw-r--r-- | source/blender/editors/space_api/spacetypes.c | 55 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/space_view3d.c | 9 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 18 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 14 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_intern.h | 25 |
6 files changed, 101 insertions, 32 deletions
diff --git a/source/blender/editors/include/ED_space_api.h b/source/blender/editors/include/ED_space_api.h index b705c050aa3..20b1e2b5499 100644 --- a/source/blender/editors/include/ED_space_api.h +++ b/source/blender/editors/include/ED_space_api.h @@ -29,6 +29,9 @@ #ifndef ED_SPACE_API_H #define ED_SPACE_API_H +struct ARegionType; +struct bContext; + /* the pluginnable API for export to editors */ /* calls for registering default spaces */ @@ -54,5 +57,14 @@ void ED_spacetype_sequencer(void); void ED_file_init(void); void ED_file_exit(void); +#define REGION_DRAW_PRE 1 +#define REGION_DRAW_POST 0 + +void *ED_region_draw_cb_activate(struct ARegionType *, + void (*draw)(const struct bContext *, struct ARegion *), + int type); +void ED_region_draw_cb_draw(const struct bContext *, struct ARegion *, int); +void ED_region_draw_cb_exit(struct ARegionType *, void *); + #endif /* ED_SPACE_API_H */ diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c index 325227a2fc5..8ed9bb10fd5 100644 --- a/source/blender/editors/space_api/spacetypes.c +++ b/source/blender/editors/space_api/spacetypes.c @@ -123,7 +123,60 @@ void ED_spacetypes_keymap(wmWindowManager *wm) } } -/* ****************************** space template *********************** */ +/* ********************** custom drawcall api ***************** */ + +/* type */ +#define REGION_DRAW_PRE 1 +#define REGION_DRAW_POST 0 + +typedef struct RegionDrawCB { + struct RegionDrawCB *next, *prev; + + void (*draw)(const struct bContext *, struct ARegion *); + + int type; + +} RegionDrawCB; + +void *ED_region_draw_cb_activate(ARegionType *art, + void (*draw)(const struct bContext *, struct ARegion *), + int type) +{ + RegionDrawCB *rdc= MEM_callocN(sizeof(RegionDrawCB), "RegionDrawCB"); + + BLI_addtail(&art->drawcalls, rdc); + rdc->draw= draw; + rdc->type= type; + + return rdc; +} + +void ED_region_draw_cb_exit(ARegionType *art, void *handle) +{ + RegionDrawCB *rdc; + + for(rdc= art->drawcalls.first; rdc; rdc= rdc->next) { + if(rdc==(RegionDrawCB *)handle) { + BLI_remlink(&art->drawcalls, rdc); + MEM_freeN(rdc); + return; + } + } +} + +void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type) +{ + RegionDrawCB *rdc; + + for(rdc= ar->type->drawcalls.first; rdc; rdc= rdc->next) { + if(rdc->type==type) + rdc->draw(C, ar); + } +} + + + +/* ********************* space template *********************** */ /* allocate and init some vars */ static SpaceLink *xxx_new(const bContext *C) diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 8ac672eb260..675fbc5aab2 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -181,15 +181,6 @@ static SpaceLink *view3d_duplicate(SpaceLink *sl) return (SpaceLink *)v3dn; } -static void view3d_main_area_draw(const bContext *C, ARegion *ar) -{ - /* draw entirely, view changes should be handled here */ - ScrArea *sa= CTX_wm_area(C); - View3D *v3d= sa->spacedata.first; /* XXX get from region */ - - drawview3dspace(CTX_wm_screen(C), CTX_data_scene(C), ar, v3d); -} - /* add handlers, stuff you only do once or on area/region changes */ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar) { diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 48fb6d76703..4fc64782fe8 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -51,6 +51,7 @@ #include "BLI_rand.h" #include "BKE_anim.h" +#include "BKE_context.h" #include "BKE_customdata.h" #include "BKE_image.h" #include "BKE_ipo.h" @@ -76,6 +77,7 @@ #include "ED_keyframing.h" #include "ED_mesh.h" #include "ED_screen.h" +#include "ED_space_api.h" #include "ED_util.h" #include "ED_types.h" @@ -1835,10 +1837,11 @@ static CustomDataMask get_viewedit_datamask(bScreen *screen) return mask; } - - -void drawview3dspace(bScreen *screen, Scene *scene, ARegion *ar, View3D *v3d) +void view3d_main_area_draw(const bContext *C, ARegion *ar) { + Scene *scene= CTX_data_scene(C); + ScrArea *sa= CTX_wm_area(C); + View3D *v3d= sa->spacedata.first; /* XXX get from region */ Scene *sce; Base *base; Object *ob; @@ -1846,7 +1849,7 @@ void drawview3dspace(bScreen *screen, Scene *scene, ARegion *ar, View3D *v3d) Object *obact = OBACT; /* from now on all object derived meshes check this */ - v3d->customdata_mask= get_viewedit_datamask(screen); + v3d->customdata_mask= get_viewedit_datamask(CTX_wm_screen(C)); /* update all objects, ipos, matrices, displists, etc. Flags set by depgraph or manual, no layer check here, gets correct flushed */ @@ -1999,12 +2002,7 @@ void drawview3dspace(bScreen *screen, Scene *scene, ARegion *ar, View3D *v3d) view3d_update_depths(ar, v3d); } - if(G.moving) { -// BIF_drawConstraint(); -// if(obedit || (G.f & G_PARTICLEEDIT)) -// BIF_drawPropCircle(); // only editmode and particles have proportional edit -// BIF_drawSnap(); - } + ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST); // REEB_draw(); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 666bb297495..90bc976f015 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -69,6 +69,7 @@ #include "RNA_access.h" #include "RNA_define.h" +#include "ED_space_api.h" #include "ED_screen.h" #include "ED_types.h" @@ -96,6 +97,7 @@ typedef struct ViewOpsData { int origx, origy, oldx, oldy; int origkey; + void *vh; // XXX temp } ViewOpsData; #define TRACKBALLSIZE (1.1) @@ -362,6 +364,10 @@ static int viewrotate_modal(bContext *C, wmOperator *op, wmEvent *event) default: if(event->type==vod->origkey && event->val==0) { + if(vod->vh) { + ED_region_draw_cb_exit(CTX_wm_region(C)->type, vod->vh); + ED_region_tag_redraw(CTX_wm_region(C)); + } MEM_freeN(vod); op->customdata= NULL; @@ -372,6 +378,12 @@ static int viewrotate_modal(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_RUNNING_MODAL; } +static void vh_draw(const bContext *C, ARegion *ar) +{ + glColor3ub(100, 200, 100); + glRectf(-0.2, -0.2, 0.2, 0.2); +} + static int viewrotate_invoke(bContext *C, wmOperator *op, wmEvent *event) { ViewOpsData *vod; @@ -380,6 +392,8 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, wmEvent *event) viewops_data(C, op, event); vod= op->customdata; + vod->vh= ED_region_draw_cb_activate(CTX_wm_region(C)->type, vh_draw, REGION_DRAW_POST); + /* switch from camera view when: */ if(vod->v3d->persp != V3D_PERSP) { diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 7fb17071e71..8fc00ffd538 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -33,6 +33,7 @@ /* internal exports only */ struct bScreen; +struct ARegion; struct BoundBox; struct Object; struct DerivedMesh; @@ -64,7 +65,7 @@ typedef struct ViewDepths { #define IS_CLIPPED 12000 /* view3d_header.c */ -void view3d_header_buttons(const struct bContext *C, ARegion *ar); +void view3d_header_buttons(const struct bContext *C, struct ARegion *ar); /* view3d_ops.c */ void view3d_operatortypes(void); @@ -83,7 +84,7 @@ void VIEW3D_OT_render_border(struct wmOperatorType *ot); void VIEW3D_OT_drawtype(struct wmOperatorType *ot); /* drawobject.c */ -void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag); +void draw_object(Scene *scene, struct ARegion *ar, View3D *v3d, Base *base, int flag); int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, int dt); void drawcircball(int mode, float *cent, float rad, float tmat[][4]); void draw_object_instance(Scene *scene, View3D *v3d, Object *ob, int dt, int outline); @@ -97,17 +98,17 @@ int draw_armature(Scene *scene, View3D *v3d, Base *base, int dt, int flag); void draw_mesh_textured(Scene *scene, View3D *v3d, Object *ob, struct DerivedMesh *dm, int faceselect); /* view3d_draw.c */ -void drawview3dspace(struct bScreen *screen, Scene *scene, ARegion *ar, View3D *v3d); -void draw_depth(Scene *scene, ARegion *ar, View3D *v3d, int (* func)(void *)); +void view3d_main_area_draw(const struct bContext *C, struct ARegion *ar); +void draw_depth(Scene *scene, struct ARegion *ar, View3D *v3d, int (* func)(void *)); void view3d_clr_clipping(void); void view3d_set_clipping(View3D *v3d); void add_view3d_after(View3D *v3d, Base *base, int type, int flag); void make_axis_color(char *col, char *col2, char axis); -void calc_viewborder(Scene *scene, ARegion *ar, View3D *v3d, rctf *viewborder_r); +void calc_viewborder(Scene *scene, struct ARegion *ar, View3D *v3d, rctf *viewborder_r); void circf(float x, float y, float rad); void circ(float x, float y, float rad); -void view3d_update_depths(ARegion *ar, View3D *v3d); +void view3d_update_depths(struct ARegion *ar, View3D *v3d); /* view3d_select.c */ void VIEW3D_OT_select(struct wmOperatorType *ot); @@ -130,19 +131,19 @@ void view3d_operator_needs_opengl(const struct bContext *C); int boundbox_clip(View3D *v3d, float obmat[][4], struct BoundBox *bb); -void view3d_project_short_clip(ARegion *ar, View3D *v3d, float *vec, short *adr, float projmat[4][4], float wmat[4][4]); -void view3d_project_short_noclip(ARegion *ar, float *vec, short *adr, float mat[4][4]); -void view3d_project_float(ARegion *a, float *vec, float *adr, float mat[4][4]); +void view3d_project_short_clip(struct ARegion *ar, View3D *v3d, float *vec, short *adr, float projmat[4][4], float wmat[4][4]); +void view3d_project_short_noclip(struct ARegion *ar, float *vec, short *adr, float mat[4][4]); +void view3d_project_float(struct ARegion *a, float *vec, float *adr, float mat[4][4]); void view3d_get_object_project_mat(View3D *v3d, struct Object *ob, float pmat[4][4], float vmat[4][4]); -void view3d_project_float(ARegion *ar, float *vec, float *adr, float mat[4][4]); +void view3d_project_float(struct ARegion *ar, float *vec, float *adr, float mat[4][4]); int get_view3d_viewplane(View3D *v3d, int winxi, int winyi, rctf *viewplane, float *clipsta, float *clipend, float *pixsize); -void initlocalview(Scene *scene, ARegion *ar, View3D *v3d); +void initlocalview(Scene *scene, struct ARegion *ar, View3D *v3d); void restore_localviewdata(View3D *vd); void endlocalview(Scene *scene, ScrArea *sa); -void centerview(ARegion *ar, View3D *v3d); +void centerview(struct ARegion *ar, View3D *v3d); void smooth_view(struct bContext *C, Object *, Object *, float *ofs, float *quat, float *dist, float *lens); |