diff options
author | Nathan Letwory <nathan@letworyinteractive.com> | 2009-01-01 19:27:02 +0300 |
---|---|---|
committer | Nathan Letwory <nathan@letworyinteractive.com> | 2009-01-01 19:27:02 +0300 |
commit | 029b0c3ecf89323b7ee943e5c09fbde4ca2fbc60 (patch) | |
tree | 7d236e2ef0905d257236389f5823a432be88a4e7 /source/blender | |
parent | fc7944f436657ce4a9a479aff3d5903b79bd6ede (diff) |
2.5 / Nodes
* HOMEKEY enabled (view all), made into operator.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_node/node_edit.c | 75 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_header.c | 9 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_state.c | 26 |
5 files changed, 71 insertions, 43 deletions
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 1589c10539a..7ed00c722d9 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -22,7 +22,7 @@ * * The Original Code is: all of this file. * - * Contributor(s): David Millan Escriva, Juho Vepsäläinen + * Contributor(s): David Millan Escriva, Juho Vepsäläinen, Nathan Letwory * * ***** END GPL LICENSE BLOCK ***** */ @@ -102,6 +102,8 @@ #include "WM_types.h" +#include "UI_view2d.h" + // XXX XXX XXX static void BIF_undo_push(char *s) {} @@ -913,8 +915,6 @@ bNode *next_node(bNodeTree *ntree) return NULL; } -#if 0 - /* is rct in visible part of node? */ static bNode *visible_node(SpaceNode *snode, rctf *rct) { @@ -927,60 +927,57 @@ static bNode *visible_node(SpaceNode *snode, rctf *rct) return tnode; } -void snode_home(ScrArea *sa, SpaceNode *snode) +void snode_home(ScrArea *sa, ARegion *ar, SpaceNode* snode) { bNode *node; + rctf *cur, *tot; + float oldwidth, oldheight, width, height; int first= 1; - snode->v2d.cur.xmin= snode->v2d.cur.ymin= 0.0f; - snode->v2d.cur.xmax= sa->winx; - snode->v2d.cur.xmax= sa->winy; + cur= &ar->v2d.cur; + tot= &ar->v2d.tot; + + oldwidth= cur->xmax - cur->xmin; + oldheight= cur->ymax - cur->ymin; + + cur->xmin= cur->ymin= 0.0f; + cur->xmax=ar->winx; + cur->xmax= ar->winy; if(snode->edittree) { for(node= snode->edittree->nodes.first; node; node= node->next) { if(first) { first= 0; - snode->v2d.cur= node->totr; + ar->v2d.cur= node->totr; } else { - BLI_union_rctf(&snode->v2d.cur, &node->totr); + BLI_union_rctf(cur, &node->totr); } } } - snode->v2d.tot= snode->v2d.cur; - - snode->xof = snode->yof = 0.0; - - test_view2d(G.v2d, sa->winx, sa->winy); - -} - -void snode_zoom_out(ScrArea *sa) -{ - float dx; - dx= (float)(0.15*(G.v2d->cur.xmax-G.v2d->cur.xmin)); - G.v2d->cur.xmin-= dx; - G.v2d->cur.xmax+= dx; - dx= (float)(0.15*(G.v2d->cur.ymax-G.v2d->cur.ymin)); - G.v2d->cur.ymin-= dx; - G.v2d->cur.ymax+= dx; - test_view2d(G.v2d, sa->winx, sa->winy); -} - -void snode_zoom_in(ScrArea *sa) -{ - float dx; + snode->xof= 0; + snode->yof= 0; + width= cur->xmax - cur->xmin; + height= cur->ymax- cur->ymin; + if(width > height) { + float newheight; + newheight= oldheight * width/oldwidth; + cur->ymin= cur->ymin - newheight/4; + cur->ymax= cur->ymin + newheight; + } + else { + float newwidth; + newwidth= oldwidth * height/oldheight; + cur->xmin= cur->xmin - newwidth/4; + cur->xmax= cur->xmin + newwidth; + } - dx= (float)(0.1154*(G.v2d->cur.xmax-G.v2d->cur.xmin)); - G.v2d->cur.xmin+= dx; - G.v2d->cur.xmax-= dx; - dx= (float)(0.1154*(G.v2d->cur.ymax-G.v2d->cur.ymin)); - G.v2d->cur.ymin+= dx; - G.v2d->cur.ymax-= dx; - test_view2d(G.v2d, sa->winx, sa->winy); + ar->v2d.tot= ar->v2d.cur; + UI_view2d_curRect_validate(&ar->v2d); } +#if 0 static void snode_bg_viewmove(SpaceNode *snode) { ScrArea *sa; diff --git a/source/blender/editors/space_node/node_header.c b/source/blender/editors/space_node/node_header.c index 9bf5bf09b25..ba6abc72e09 100644 --- a/source/blender/editors/space_node/node_header.c +++ b/source/blender/editors/space_node/node_header.c @@ -586,17 +586,18 @@ static uiBlock *node_nodemenu(bContext *C, uiMenuBlockHandle *handle, void *arg_ static void do_node_viewmenu(bContext *C, void *arg, int event) { + SpaceNode *snode= (SpaceNode*)CTX_wm_space_data(C); + ARegion *ar= CTX_wm_region(C); ScrArea *sa= CTX_wm_area(C); switch(event) { + /* cases 1 and 2 are now handled automagically by View2D code */ case 1: /* Zoom in */ - // XXX snode_zoom_in(sa); - break; case 2: /* View all */ - // XXX snode_zoom_out(sa); break; case 3: /* View all */ - // XXX snode_home(sa, snode); + printf("calling snode_home\n"); + //snode_home(sa, ar, snode); break; case 4: /* Grease Pencil */ // XXX add_blockhandler(sa, NODES_HANDLER_GREASEPENCIL, UI_PNL_UNSTOW); diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h index 88954a01e64..a8857671f4b 100644 --- a/source/blender/editors/space_node/node_intern.h +++ b/source/blender/editors/space_node/node_intern.h @@ -53,6 +53,7 @@ void node_keymap(wmWindowManager *wm); void NODE_OT_select(struct wmOperatorType *ot); void NODE_OT_extend_select(struct wmOperatorType *ot); void NODE_OT_toggle_visibility(struct wmOperatorType *ot); +void NODE_OT_fit_all(struct wmOperatorType *ot); /* drawnode.c */ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link); @@ -64,6 +65,7 @@ bNode *next_node(bNodeTree *ntree); void snode_set_context(SpaceNode *snode, Scene *scene); void scale_node(SpaceNode *snode, bNode *node); void snode_make_group_editable(SpaceNode *snode, bNode *gnode); +void snode_home(ScrArea *sa, ARegion *ar, SpaceNode *snode); void node_set_active(SpaceNode *snode, bNode *node); void node_deselectall(SpaceNode *snode, int swap); diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c index dd97d17d0fb..937b85beabe 100644 --- a/source/blender/editors/space_node/node_ops.c +++ b/source/blender/editors/space_node/node_ops.c @@ -49,6 +49,7 @@ void node_operatortypes(void) WM_operatortype_append(NODE_OT_select); WM_operatortype_append(NODE_OT_extend_select); WM_operatortype_append(NODE_OT_toggle_visibility); + WM_operatortype_append(NODE_OT_fit_all); } void node_keymap(struct wmWindowManager *wm) @@ -58,4 +59,5 @@ void node_keymap(struct wmWindowManager *wm) RNA_enum_set(WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, 0, 0)->ptr, "select_type", NODE_SELECT_MOUSE); RNA_enum_set(WM_keymap_add_item(keymap, "NODE_OT_extend_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select_type", NODE_SELECT_MOUSE); WM_keymap_add_item(keymap, "NODE_OT_toggle_visibility", ACTIONMOUSE, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "NODE_OT_fit_all", HOMEKEY, KM_PRESS, 0, 0); } diff --git a/source/blender/editors/space_node/node_state.c b/source/blender/editors/space_node/node_state.c index fdd1bcf1073..088df34a05f 100644 --- a/source/blender/editors/space_node/node_state.c +++ b/source/blender/editors/space_node/node_state.c @@ -192,3 +192,29 @@ void NODE_OT_toggle_visibility(wmOperatorType *ot) prop = RNA_def_property(ot->srna, "mx", PROP_INT, PROP_NONE); prop = RNA_def_property(ot->srna, "my", PROP_INT, PROP_NONE); } + +static int node_fit_all_exec(bContext *C, wmOperator *op) +{ + ScrArea *sa= CTX_wm_area(C); + ARegion *ar= CTX_wm_region(C); + SpaceNode *snode= (SpaceNode *)CTX_wm_space_data(C); + snode_home(sa, ar, snode); + ED_region_tag_redraw(ar); + return OPERATOR_FINISHED; +} + +static int node_fit_all_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + return node_fit_all_exec(C, op); +} + +void NODE_OT_fit_all(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Fit All"; + ot->idname= "NODE_OT_fit_all"; + + /* api callbacks */ + ot->invoke= node_fit_all_invoke; + ot->poll= ED_operator_node_active; +}
\ No newline at end of file |