diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-03-07 21:47:30 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-03-07 21:47:30 +0400 |
commit | 557b893dfd0fa2380ee159bb4fe7a28f09187036 (patch) | |
tree | 4ea73cdeefc2e0c1d1f54b42660c32d5abb21e91 /source/blender/editors/space_node | |
parent | a134d9ed517ef4173c1e8c19e77d652d52fe9258 (diff) |
Border for compositor viewer node feature
This adds border option to compositor, which affects on
a backdrop and viewer nodes, which is useful for faster
previews and tweaks.
Final compositing still happens for the whole frame, but
if it'll be needed it's not so difficult to support it
as well.
To use border there's Ctrl-B shortcut in the compositor
editor, which i used to define region you want to restrict
compositing to. There's also "Viewer Border" option in
the N-panel in case you'll want to disable border
compositing.
Some areas could be cleaned a bit, like ideally it shall
not be viewer image clearing in viewer_border_update RNA
callback, but currently it's not so much clear how to
make it the same fast as simple memset and glue it
somehow to compositor. Will think of nicer solution a
bit later.
Diffstat (limited to 'source/blender/editors/space_node')
-rw-r--r-- | source/blender/editors/space_node/drawnode.c | 18 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_edit.c | 104 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_ops.c | 4 |
4 files changed, 128 insertions, 0 deletions
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 8a2e03f2660..097469f396f 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -3320,6 +3320,7 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode) /** @note draw selected info on backdrop */ if (snode->edittree) { bNode *node = snode->edittree->nodes.first; + rctf *viewer_border = &snode->edittree->viewer_border; while (node) { if (node->flag & NODE_SELECT) { if (node->typeinfo->uibackdropfunc) { @@ -3328,6 +3329,23 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode) } node = node->next; } + + if ((snode->edittree->flag & NTREE_VIEWER_BORDER) && + viewer_border->xmin < viewer_border->xmax && + viewer_border->ymin < viewer_border->ymax) + { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + setlinestyle(3); + cpack(0x4040FF); + + glRectf(x + snode->zoom * viewer_border->xmin * ibuf->x, + y + snode->zoom * viewer_border->ymin * ibuf->y, + x + snode->zoom * viewer_border->xmax * ibuf->x, + y + snode->zoom * viewer_border->ymax * ibuf->y); + + setlinestyle(0); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + } } glMatrixMode(GL_PROJECTION); diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index fb4e4f62e52..ad863fca5a5 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -73,6 +73,8 @@ #include "GPU_material.h" +#include "IMB_imbuf_types.h" + #include "node_intern.h" /* own include */ #define USE_ESC_COMPO @@ -2281,3 +2283,105 @@ void NODE_OT_shader_script_update(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } +/* ********************** Viewer border ******************/ + +static void viewer_border_corner_to_backdrop(SpaceNode *snode, ARegion *ar, int x, int y, + int backdrop_width, int backdrop_height, + float *fx, float *fy) +{ + float bufx, bufy; + + bufx = backdrop_width * snode->zoom; + bufy = backdrop_height * snode->zoom; + + *fx = (bufx > 0.0f ? ((float) x - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f); + *fy = (bufy > 0.0f ? ((float) y - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f); +} + +static int viewer_border_exec(bContext *C, wmOperator *op) +{ + Image *ima; + void *lock; + ImBuf *ibuf; + + ED_preview_kill_jobs(C); + + ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node"); + ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + + if (ibuf) { + ARegion *ar = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *btree = snode->edittree; + rcti rect; + rctf rectf; + + /* get border from operator */ + WM_operator_properties_border_to_rcti(op, &rect); + + /* convert border to unified space within backdrop image */ + viewer_border_corner_to_backdrop(snode, ar, rect.xmin, rect.ymin, ibuf->x, ibuf->y, + &rectf.xmin, &rectf.ymin); + + viewer_border_corner_to_backdrop(snode, ar, rect.xmax, rect.ymax, ibuf->x, ibuf->y, + &rectf.xmax, &rectf.ymax); + + /* clamp coordinates */ + rectf.xmin = max_ff(rectf.xmin, 0.0f); + rectf.ymin = max_ff(rectf.ymin, 0.0f); + rectf.xmax = min_ff(rectf.xmax, 1.0f); + rectf.ymax = min_ff(rectf.ymax, 1.0f); + + if (rectf.xmin < rectf.xmax && rectf.ymin < rectf.ymax) { + btree->viewer_border = rectf; + + if (rectf.xmin == 0.0f && rectf.ymin == 0.0f && + rectf.xmax == 1.0f && rectf.ymax == 1.0f) + { + btree->flag &= ~NTREE_VIEWER_BORDER; + } + else { + if (ibuf->rect) + memset(ibuf->rect, 0, 4 * ibuf->x * ibuf->y); + + if (ibuf->rect_float) + memset(ibuf->rect_float, 0, 4 * ibuf->x * ibuf->y * sizeof(float)); + + ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID; + + btree->flag |= NTREE_VIEWER_BORDER; + } + + snode_notify(C, snode); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + } + else { + btree->flag &= ~NTREE_VIEWER_BORDER; + } + } + + BKE_image_release_ibuf(ima, ibuf, lock); + + return OPERATOR_FINISHED; +} + +void NODE_OT_viewer_border(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Viewer Border"; + ot->description = "Set the boundaries for viewer operations"; + ot->idname = "NODE_OT_viewer_border"; + + /* api callbacks */ + ot->invoke = WM_border_select_invoke; + ot->exec = viewer_border_exec; + ot->modal = WM_border_select_modal; + ot->cancel = WM_border_select_cancel; + ot->poll = composite_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + WM_operator_properties_gesture_border(ot, TRUE); +} diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h index e8dd1cf1528..cbf7101a101 100644 --- a/source/blender/editors/space_node/node_intern.h +++ b/source/blender/editors/space_node/node_intern.h @@ -217,6 +217,8 @@ void NODE_OT_clipboard_paste(struct wmOperatorType *ot); void NODE_OT_shader_script_update(struct wmOperatorType *ot); +void NODE_OT_viewer_border(struct wmOperatorType *ot); + extern const char *node_context_dir[]; // XXXXXX diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c index 8adccd9e6c4..d16c6627d3f 100644 --- a/source/blender/editors/space_node/node_ops.c +++ b/source/blender/editors/space_node/node_ops.c @@ -120,6 +120,8 @@ void node_operatortypes(void) WM_operatortype_append(NODE_OT_clipboard_paste); WM_operatortype_append(NODE_OT_shader_script_update); + + WM_operatortype_append(NODE_OT_viewer_border); } void ED_operatormacros_node(void) @@ -298,5 +300,7 @@ void node_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "NODE_OT_clipboard_copy", CKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "NODE_OT_clipboard_paste", VKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "NODE_OT_viewer_border", BKEY, KM_PRESS, KM_CTRL, 0); + transform_keymap_for_space(keyconf, keymap, SPACE_NODE); } |