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/space_api | |
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/space_api')
-rw-r--r-- | source/blender/editors/space_api/spacetypes.c | 55 |
1 files changed, 54 insertions, 1 deletions
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) |