Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/drawnode.c
| Context not available. | |||||
| #include "BLF_api.h" | #include "BLF_api.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "GPU_draw.h" | |||||
| #include "GPU_basic_shader.h" | |||||
| #include "GPU_immediate.h" | |||||
| #include "BIF_gl.h" | #include "BIF_gl.h" | ||||
| #include "BIF_glutil.h" | #include "BIF_glutil.h" | ||||
| Context not available. | |||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "UI_view2d.h" | |||||
| #include "IMB_colormanagement.h" | #include "IMB_colormanagement.h" | ||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
merwin: I recently added Batch_Uniform1b for booleans. Will add same thing for immediate mode so you… | |||||
Not Done Inline ActionsReturn true or false. merwin: Return true or false. | |||||
| Context not available. | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* if v2d not NULL, it clips and returns 0 if not visible */ | |||||
| bool node_link_bezier_points_glsl(View2D *v2d, SpaceNode *snode, bNodeLink *link, float vec[4][2]) | |||||
| { | |||||
| float dist; | |||||
| 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; | |||||
| vec[0][1] = link->fromsock->locy; | |||||
| fromreroute = (link->fromnode && link->fromnode->type == NODE_REROUTE); | |||||
| } | |||||
| else { | |||||
| if (snode == NULL) return 0; | |||||
| copy_v2_v2(vec[0], cursor); | |||||
| fromreroute = 0; | |||||
| } | |||||
| if (link->tosock) { | |||||
| vec[3][0] = link->tosock->locx; | |||||
| vec[3][1] = link->tosock->locy; | |||||
| toreroute = (link->tonode && link->tonode->type == NODE_REROUTE); | |||||
| } | |||||
| else { | |||||
| if (snode == NULL) return 0; | |||||
| copy_v2_v2(vec[3], cursor); | |||||
| toreroute = 0; | |||||
| } | |||||
| /* may be called outside of drawing (so pass spacetype) */ | |||||
| dist = UI_GetThemeValueType(TH_NODE_CURVING, SPACE_NODE) * 0.10f * fabsf(vec[0][0] - vec[3][0]); | |||||
| deltax = vec[3][0] - vec[0][0]; | |||||
| deltay = vec[3][1] - vec[0][1]; | |||||
| /* check direction later, for top sockets */ | |||||
| if (fromreroute) { | |||||
| if (ABS(deltax) > ABS(deltay)) { | |||||
| vec[1][1] = vec[0][1]; | |||||
| vec[1][0] = vec[0][0] + (deltax > 0 ? dist : -dist); | |||||
| } | |||||
| else { | |||||
| vec[1][0] = vec[0][0]; | |||||
| vec[1][1] = vec[0][1] + (deltay > 0 ? dist : -dist); | |||||
| } | |||||
| } | |||||
| else { | |||||
| vec[1][0] = vec[0][0] + dist; | |||||
| vec[1][1] = vec[0][1]; | |||||
| } | |||||
| if (toreroute) { | |||||
| if (ABS(deltax) > ABS(deltay)) { | |||||
| vec[2][1] = vec[3][1]; | |||||
| vec[2][0] = vec[3][0] + (deltax > 0 ? -dist : dist); | |||||
| } | |||||
| else { | |||||
| vec[2][0] = vec[3][0]; | |||||
| vec[2][1] = vec[3][1] + (deltay > 0 ? -dist : dist); | |||||
| } | |||||
| } | |||||
| else { | |||||
| vec[2][0] = vec[3][0] - dist; | |||||
| vec[2][1] = vec[3][1]; | |||||
| } | |||||
| if (v2d && min_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax) { | |||||
| /* clipped */ | |||||
| } | |||||
| else if (v2d && max_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin) { | |||||
| /* clipped */ | |||||
| } | |||||
| else { | |||||
| /* always do all three, to prevent data hanging around */ | |||||
| return 1; | |||||
| } | |||||
| return 0; | |||||
| } | |||||
| void node_draw_link_bezier_glsl(View2D *v2d, SpaceNode *snode, bNodeLink *link, | |||||
| int th_col1, bool do_shaded, int th_col2, bool do_triple, int th_col3, unsigned attrib_array[3]) | |||||
| { | |||||
| float coord_array[4][2]; | |||||
| bool drawarrow; | |||||
| float xscale, yscale; | |||||
Not Done Inline ActionsSame here, return true or false. merwin: Same here, return true or false. | |||||
| if (node_link_bezier_points_glsl(v2d, snode, link, coord_array)) { | |||||
| unsigned pos = attrib_array[0]; | |||||
| unsigned color = attrib_array[1]; | |||||
| unsigned handle = attrib_array[2]; | |||||
| UI_view2d_scale_get(v2d, &xscale, &yscale); | |||||
| immUniform1f("scale", xscale); | |||||
| immUniform1f("line_width", 1.5f * UI_DPI_WINDOW_FAC); | |||||
| if (!do_triple) | |||||
| immUniform1f("triple_width", 0.0f * UI_DPI_WINDOW_FAC); | |||||
| else { | |||||
| float col[4]; | |||||
| UI_GetThemeColorShadeAlpha4fv(th_col3, -80, -120, col); | |||||
| immUniform4fv("triple_color", col); | |||||
| immUniform1f("triple_width", 4.0f * UI_DPI_WINDOW_FAC); | |||||
| } | |||||
| drawarrow = ((link->tonode && (link->tonode->type == NODE_REROUTE)) && | |||||
| (link->fromnode && (link->fromnode->type == NODE_REROUTE))); | |||||
| if (drawarrow) | |||||
| immUniform1i("drawarrow", 1); | |||||
| else | |||||
| immUniform1i("drawarrow", 0); | |||||
| immBegin(GL_LINES, 2); | |||||
| float col[3]; | |||||
| UI_GetThemeColor3fv(th_col1, col); | |||||
| immAttrib2fv(handle, coord_array[1]); | |||||
| immAttrib3fv(color, col); | |||||
| immVertex2fv(pos, coord_array[0]); | |||||
| if (do_shaded) | |||||
| UI_GetThemeColor3fv(th_col2, col); | |||||
| immAttrib2fv(handle, coord_array[2]); | |||||
| immAttrib3fv(color, col); | |||||
| immVertex2fv(pos, coord_array[3]); | |||||
| immEnd(); | |||||
| } | |||||
| } | |||||
| #define LINK_RESOL 24 | #define LINK_RESOL 24 | ||||
| #define LINK_ARROW 12 /* position of arrow on the link, LINK_RESOL/2 */ | #define LINK_ARROW 12 /* position of arrow on the link, LINK_RESOL/2 */ | ||||
| #define ARROW_SIZE (7 * UI_DPI_FAC) | #define ARROW_SIZE (7 * UI_DPI_FAC) | ||||
| void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, | void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, | ||||
| int th_col1, bool do_shaded, int th_col2, bool do_triple, int th_col3) | int th_col1, bool do_shaded, int th_col2, bool do_triple, int th_col3) | ||||
| { | { | ||||
| Context not available. | |||||
| #endif | #endif | ||||
| /* note; this is used for fake links in groups too */ | /* note; this is used for fake links in groups too */ | ||||
| void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link) | void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link, unsigned attrib_array[3]) | ||||
| { | { | ||||
| bool do_shaded = false; | bool do_shaded = false; | ||||
| bool do_triple = false; | bool do_triple = false; | ||||
| Context not available. | |||||
| th_col1 = TH_REDALERT; | th_col1 = TH_REDALERT; | ||||
| } | } | ||||
| } | } | ||||
| node_draw_link_bezier(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3); | node_draw_link_bezier_glsl(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3, attrib_array); | ||||
| // node_draw_link_straight(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3); | // node_draw_link_straight(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3); | ||||
| } | } | ||||
| Context not available. | |||||
I recently added Batch_Uniform1b for booleans. Will add same thing for immediate mode so you can say this:
immUniform1b("drawarrow", drawarrow);