Revision: 59835
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59835
Author:   ton
Date:     2013-09-05 13:03:03 +0000 (Thu, 05 Sep 2013)
Log Message:
-----------
Bugfix #35920

Adding a new node in Node Editor failed for "High DPI" (Only Mac retina now).

- Py script for adding nodes was doing dpi magic, which it shouldn't. It has 
  been replaced with a (temporary) API call to set the correct cursor location.
  (Thanks to Lukas T for helping here)

- The SpaceNode->cursor[2] property now is *only* storing the coordinate
  in "adding new node space". Use of this has been removed from the code where
  possible, with as only exception the code to draw noodles while adding them.

Special coder note: Nodes should respect the DPI value, and draw larger with
larger buttons if you increase this size. The hack here is that this can only
work nice if also the node positions are scaled accordingly.

A better fix could be to check on scaling the node view itself for it. That
then would also remove this Python API call that was added in this commit.
However, that again might fight with how buttons layout code works now...
needs some careful checking.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_operators/node.py
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/editors/space_node/node_add.c
    trunk/blender/source/blender/editors/space_node/node_draw.c
    trunk/blender/source/blender/editors/space_node/node_edit.c
    trunk/blender/source/blender/editors/space_node/node_intern.h
    trunk/blender/source/blender/editors/space_node/node_relationships.c
    trunk/blender/source/blender/editors/space_node/node_select.c
    trunk/blender/source/blender/editors/space_node/space_node.c
    trunk/blender/source/blender/makesrna/intern/rna_space.c

Modified: trunk/blender/release/scripts/startup/bl_operators/node.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/node.py  2013-09-05 
12:23:33 UTC (rev 59834)
+++ trunk/blender/release/scripts/startup/bl_operators/node.py  2013-09-05 
13:03:03 UTC (rev 59835)
@@ -66,12 +66,8 @@
 
         # convert mouse position to the View2D for later node placement
         if context.region.type == 'WINDOW':
-            # XXX, temp fix for [#35920], still fails for (U.pixelsize != 1)
-            dpi_fac = context.user_preferences.system.dpi / 72.0
-            space.cursor_location = v2d.region_to_view(event.mouse_region_x,
-                                                       event.mouse_region_y)
-            space.cursor_location /= dpi_fac
-
+            # convert mouse position to the View2D for later node placement
+            space.cursor_location_from_region(event.mouse_region_x, 
event.mouse_region_y) 
         else:
             space.cursor_location = tree.view_center
 

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c  2013-09-05 
12:23:33 UTC (rev 59834)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c  2013-09-05 
13:03:03 UTC (rev 59835)
@@ -3075,7 +3075,16 @@
 {
        float dist, vec[4][2];
        float deltax, deltay;
+       float cursor[2] = {0.0f, 0.0f};
        int toreroute, fromreroute;
+       
+       /* this function can be called with snode null (via 
cut_links_intersect) */
+       /* XXX map snode->cursor back to view space */
+       if (snode) {
+               cursor[0] = snode->cursor[0] * UI_DPI_FAC;
+               cursor[1] = snode->cursor[1] * UI_DPI_FAC;
+       }
+       
        /* in v0 and v3 we put begin/end points */
        if (link->fromsock) {
                vec[0][0] = link->fromsock->locx;
@@ -3084,7 +3093,7 @@
        }
        else {
                if (snode == NULL) return 0;
-               copy_v2_v2(vec[0], snode->cursor);
+               copy_v2_v2(vec[0], cursor);
                fromreroute = 0;
        }
        if (link->tosock) {
@@ -3094,7 +3103,7 @@
        }
        else {
                if (snode == NULL) return 0;
-               copy_v2_v2(vec[3], snode->cursor);
+               copy_v2_v2(vec[3], cursor);
                toreroute = 0;
        }
 

Modified: trunk/blender/source/blender/editors/space_node/node_add.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_add.c  2013-09-05 
12:23:33 UTC (rev 59834)
+++ trunk/blender/source/blender/editors/space_node/node_add.c  2013-09-05 
13:03:03 UTC (rev 59835)
@@ -84,10 +84,6 @@
        node->locy = locy + 60.0f;     /* arbitrary... so its visible, (0,0) is 
top of node */
        nodeSetSelected(node, TRUE);
        
-       /* node location is mapped */
-       locx /= UI_DPI_FAC;
-       locy /= UI_DPI_FAC;
-       
        node->locx = locx;
        node->locy = locy + 60.0f;
        
@@ -417,9 +413,8 @@
        return ED_operator_node_editable(C) && snode->nodetree->type == 
NTREE_COMPOSIT;
 }
 
-static int node_add_mask_invoke(bContext *C, wmOperator *op, const wmEvent 
*event)
+static int node_add_mask_exec(bContext *C, wmOperator *op)
 {
-       ARegion *ar = CTX_wm_region(C);
        SpaceNode *snode = CTX_wm_space_node(C);
        bNode *node;
        ID *mask = NULL;
@@ -435,9 +430,6 @@
 
        ED_preview_kill_jobs(C);
 
-       /* convert mouse coordinates to v2d space */
-       UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1],
-                                &snode->cursor[0], &snode->cursor[1]);
        node = node_add_node(C, NULL, CMP_NODE_MASK, snode->cursor[0], 
snode->cursor[1]);
 
        if (!node) {
@@ -462,7 +454,7 @@
        ot->idname = "NODE_OT_add_mask";
 
        /* callbacks */
-       ot->invoke = node_add_mask_invoke;
+       ot->exec = node_add_mask_exec;
        ot->poll = node_add_mask_poll;
 
        /* flags */

Modified: trunk/blender/source/blender/editors/space_node/node_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_draw.c 2013-09-05 
12:23:33 UTC (rev 59834)
+++ trunk/blender/source/blender/editors/space_node/node_draw.c 2013-09-05 
13:03:03 UTC (rev 59835)
@@ -1075,31 +1075,31 @@
                return CURSOR_EDIT;
 }
 
-void node_set_cursor(wmWindow *win, SpaceNode *snode)
+void node_set_cursor(wmWindow *win, SpaceNode *snode, float cursor[2])
 {
        bNodeTree *ntree = snode->edittree;
        bNode *node;
        bNodeSocket *sock;
-       int cursor = CURSOR_STD;
+       int wmcursor = CURSOR_STD;
        
        if (ntree) {
-               if (node_find_indicated_socket(snode, &node, &sock, SOCK_IN | 
SOCK_OUT)) {
+               if (node_find_indicated_socket(snode, &node, &sock, cursor, 
SOCK_IN | SOCK_OUT)) {
                        /* pass */
                }
                else {
                        /* check nodes front to back */
                        for (node = ntree->nodes.last; node; node = node->prev) 
{
-                               if (BLI_rctf_isect_pt(&node->totr, 
snode->cursor[0], snode->cursor[1]))
+                               if (BLI_rctf_isect_pt(&node->totr, cursor[0], 
cursor[1]))
                                        break;  /* first hit on node stops */
                        }
                        if (node) {
-                               int dir = 
node->typeinfo->resize_area_func(node, snode->cursor[0], snode->cursor[1]);
-                               cursor = node_get_resize_cursor(dir);
+                               int dir = 
node->typeinfo->resize_area_func(node, cursor[0], cursor[1]);
+                               wmcursor = node_get_resize_cursor(dir);
                        }
                }
        }
        
-       WM_cursor_set(win, cursor);
+       WM_cursor_set(win, wmcursor);
 }
 
 void node_draw_default(const bContext *C, ARegion *ar, SpaceNode *snode, 
bNodeTree *ntree, bNode *node, bNodeInstanceKey key)
@@ -1251,6 +1251,7 @@
 
 void drawnodespace(const bContext *C, ARegion *ar)
 {
+       wmWindow *win = CTX_wm_window(C);
        View2DScrollers *scrollers;
        SpaceNode *snode = CTX_wm_space_node(C);
        View2D *v2d = &ar->v2d;
@@ -1259,7 +1260,13 @@
        glClear(GL_COLOR_BUFFER_BIT);
 
        UI_view2d_view_ortho(v2d);
-
+       
+       /* XXX snode->cursor set in coordspace for placing new nodes, used for 
drawing noodles too */
+       UI_view2d_region_to_view(&ar->v2d, win->eventstate->x - 
ar->winrct.xmin, win->eventstate->y - ar->winrct.ymin,
+                                &snode->cursor[0], &snode->cursor[1]);
+       snode->cursor[0] /= UI_DPI_FAC;
+       snode->cursor[1] /= UI_DPI_FAC;
+       
        ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
 
        /* only set once */

Modified: trunk/blender/source/blender/editors/space_node/node_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_edit.c 2013-09-05 
12:23:33 UTC (rev 59834)
+++ trunk/blender/source/blender/editors/space_node/node_edit.c 2013-09-05 
13:03:03 UTC (rev 59835)
@@ -1056,7 +1056,7 @@
 
 /* checks snode->mouse position, and returns found node/socket */
 /* type is SOCK_IN and/or SOCK_OUT */
-int node_find_indicated_socket(SpaceNode *snode, bNode **nodep, bNodeSocket 
**sockp, int in_out)
+int node_find_indicated_socket(SpaceNode *snode, bNode **nodep, bNodeSocket 
**sockp, float cursor[2], int in_out)
 {
        bNode *node;
        bNodeSocket *sock;
@@ -1068,10 +1068,10 @@
        /* check if we click in a socket */
        for (node = snode->edittree->nodes.first; node; node = node->next) {
                
-               rect.xmin = snode->cursor[0] - (NODE_SOCKSIZE + 4);
-               rect.ymin = snode->cursor[1] - (NODE_SOCKSIZE + 4);
-               rect.xmax = snode->cursor[0] + (NODE_SOCKSIZE + 4);
-               rect.ymax = snode->cursor[1] + (NODE_SOCKSIZE + 4);
+               rect.xmin = cursor[0] - (NODE_SOCKSIZE + 4);
+               rect.ymin = cursor[1] - (NODE_SOCKSIZE + 4);
+               rect.xmax = cursor[0] + (NODE_SOCKSIZE + 4);
+               rect.ymax = cursor[1] + (NODE_SOCKSIZE + 4);
                
                if (!(node->flag & NODE_HIDDEN)) {
                        /* extra padding inside and out - allow dragging on the 
text areas too */
@@ -2087,17 +2087,6 @@
        return OPERATOR_FINISHED;
 }
 
-static int node_clipboard_paste_invoke(bContext *C, wmOperator *op, const 
wmEvent *event)
-{
-       ARegion *ar = CTX_wm_region(C);
-       SpaceNode *snode = CTX_wm_space_node(C);
-
-       /* convert mouse coordinates to v2d space */
-       UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], 
&snode->cursor[0], &snode->cursor[1]);
-
-       return node_clipboard_paste_exec(C, op);
-}
-
 void NODE_OT_clipboard_paste(wmOperatorType *ot)
 {
        /* identifiers */
@@ -2107,7 +2096,6 @@
 
        /* api callbacks */
        ot->exec = node_clipboard_paste_exec;
-       ot->invoke = node_clipboard_paste_invoke;
        ot->poll = ED_operator_node_editable;
 
        /* flags */

Modified: trunk/blender/source/blender/editors/space_node/node_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_intern.h       
2013-09-05 12:23:33 UTC (rev 59834)
+++ trunk/blender/source/blender/editors/space_node/node_intern.h       
2013-09-05 13:03:03 UTC (rev 59835)
@@ -84,7 +84,7 @@
                         struct bNodeTree *ntree, bNodeInstanceKey parent_key);
 void drawnodespace(const bContext *C, ARegion *ar);
 
-void node_set_cursor(struct wmWindow *win, struct SpaceNode *snode);
+void node_set_cursor(struct wmWindow *win, struct SpaceNode *snode, float 
cursor[2]);
        /* DPI scaled coords */
 void node_to_view(struct bNode *node, float x, float y, float *rx, float *ry);
 void node_from_view(struct bNode *node, float x, float y, float *rx, float 
*ry);
@@ -183,7 +183,7 @@
 int node_has_hidden_sockets(bNode *node);
 void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set);
 int node_render_changed_exec(bContext *, struct wmOperator *);
-int node_find_indicated_socket(struct SpaceNode *snode, struct bNode **nodep, 
struct bNodeSocket **sockp, int in_out);
+int node_find_indicated_socket(struct SpaceNode *snode, struct bNode **nodep, 
struct bNodeSocket **sockp, float cursor[2], int in_out);
 
 void NODE_OT_duplicate(struct wmOperatorType *ot);
 void NODE_OT_delete(struct wmOperatorType *ot);

Modified: trunk/blender/source/blender/editors/space_node/node_relationships.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_relationships.c        
2013-09-05 12:23:33 UTC (rev 59834)
+++ trunk/blender/source/blender/editors/space_node/node_relationships.c        
2013-09-05 13:03:03 UTC (rev 59835)
@@ -443,18 +443,19 @@
        bNodeSocket *tsock = NULL;
        bNodeLink *link;
        LinkData *linkdata;
+       float cursor[2];
        int in_out;
 
        in_out = nldrag->in_out;
        
        UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1],
-                                &snode->cursor[0], &snode->cursor[1]);
+                                &cursor[0], &cursor[1]);
 
        switch (event->type) {
                case MOUSEMOVE:
                        
                        if (in_out == SOCK_OUT) {
-                               if (node_find_indicated_socket(snode, &tnode, 
&tsock, SOCK_IN)) {

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to