improve node text alignment with different zoom levels
authorCampbell Barton <ideasman42@gmail.com>
Mon, 9 Jul 2012 19:50:43 +0000 (19:50 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 9 Jul 2012 19:50:43 +0000 (19:50 +0000)
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_node/node_draw.c
source/blender/editors/space_node/node_intern.h

index 5df978e73de03d97fb7b6d6634958f0214f6b5af..c81dc93cb0b14e954bf1dbe3f534f5c725ca4465 100644 (file)
@@ -216,15 +216,17 @@ static void node_draw_output_default(const bContext *C, uiBlock *block,
        int ofs = 0;
        const char *ui_name = IFACE_(name);
        UI_ThemeColor(TH_TEXT);
-       slen = snode->aspect_sqrt * UI_GetStringWidth(ui_name);
+       slen = (UI_GetStringWidth(ui_name) + NODE_MARGIN_X) * snode->aspect_sqrt;
        while (slen > node->width) {
                ofs++;
-               slen = snode->aspect_sqrt * UI_GetStringWidth(ui_name + ofs);
+               slen = (UI_GetStringWidth(ui_name + ofs) + NODE_MARGIN_X) * snode->aspect_sqrt;
        }
        uiDefBut(block, LABEL, 0, ui_name + ofs,
-                (int)(sock->locx - (15.0f * snode->aspect_sqrt) - slen), (int)(sock->locy - 9.0f),
+                (int)(sock->locx - slen), (int)(sock->locy - 9.0f),
                 (short)(node->width - NODE_DY), (short)NODE_DY,
                 NULL, 0, 0, 0, 0, "");
+
+       (void)snode;
 }
 
 /* ****************** BASE DRAW FUNCTIONS FOR NEW OPERATOR NODES ***************** */
@@ -830,7 +832,7 @@ static void node_draw_group(const bContext *C, ARegion *ar, SpaceNode *snode, bN
                UI_ThemeColor(TH_TEXT_HI);
        
                layout = uiBlockLayout(gnode->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL,
-                                      (int)(rect.xmin + 15), (int)(rect.ymax + group_header),
+                                      (int)(rect.xmin + NODE_MARGIN_X), (int)(rect.ymax + group_header),
                                       MIN2((int)(rect.xmax - rect.xmin - 18.0f), node_group_frame + 20), group_header, UI_GetStyle());
                RNA_pointer_create(&ntree->id, &RNA_Node, gnode, &ptr);
                uiTemplateIDBrowse(layout, (bContext *)C, &ptr, "node_tree", NULL, NULL, NULL);
index fdd3f6330ab677a61271e00bb537354d15943b97..7f3b7cd2dabc2a5405b69ad8818fd041ab8ed753 100644 (file)
@@ -798,7 +798,7 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
        //      BLI_snprintf(showname, sizeof(showname), "[%s]", showname); // XXX - don't print into self!
        
        uiDefBut(node->block, LABEL, 0, showname,
-                (int)(rct->xmin + 15), (int)(rct->ymax - NODE_DY),
+                (int)(rct->xmin + (NODE_MARGIN_X / snode->aspect_sqrt)), (int)(rct->ymax - NODE_DY),
                 (short)(iconofs - rct->xmin - 18.0f), (short)NODE_DY,
                 NULL, 0, 0, 0, 0, "");
 
@@ -841,7 +841,7 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
                node_socket_circle_draw(ntree, sock, NODE_SOCKSIZE, sock->flag & SELECT);
                
                node->typeinfo->drawinputfunc(C, node->block, ntree, node, sock, IFACE_(sock->name),
-                                             sock->locx+NODE_DYS, sock->locy-NODE_DYS, node->width-NODE_DY);
+                                             sock->locx + (NODE_DYS / snode->aspect_sqrt), sock->locy-NODE_DYS, node->width-NODE_DY);
        }
        
        /* socket outputs */
@@ -852,7 +852,7 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
                node_socket_circle_draw(ntree, sock, NODE_SOCKSIZE, sock->flag & SELECT);
                
                node->typeinfo->drawoutputfunc(C, node->block, ntree, node, sock, IFACE_(sock->name),
-                                              sock->locx-node->width+NODE_DYS, sock->locy-NODE_DYS, node->width-NODE_DY);
+                                              sock->locx - node->width + (NODE_DYS / snode->aspect_sqrt), sock->locy-NODE_DYS, node->width-NODE_DY);
        }
        
        /* preview */
@@ -949,7 +949,7 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b
                //      BLI_snprintf(showname, sizeof(showname), "[%s]", showname); // XXX - don't print into self!
 
                uiDefBut(node->block, LABEL, 0, showname,
-                        (int)(rct->xmin + 15), (int)(centy - 10),
+                        (int)(rct->xmin + (NODE_MARGIN_X / snode->aspect_sqrt)), (int)(centy - 10),
                         (short)(rct->xmax - rct->xmin-18.0f -12.0f), (short)NODE_DY,
                         NULL, 0, 0, 0, 0, "");
        }       
index d9dbd646fa52b7daa5fdabb7fc85040d088ca5d4..c2f3c66f4c1ea1bf966b2e3b2bf72e7768ee72e0 100644 (file)
@@ -196,6 +196,7 @@ extern const char *node_context_dir[];
 #define BASIS_RAD              8.0f
 #define NODE_DYS               (U.widget_unit/2)
 #define NODE_DY                        U.widget_unit
+#define NODE_MARGIN_X   15
 #define NODE_SOCKSIZE  5
 
 // XXX button events (butspace)