Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/view2d.c
| Show First 20 Lines • Show All 1,287 Lines • ▼ Show 20 Lines | View2DGrid *UI_view2d_grid_calc( | ||||
| return grid; | return grid; | ||||
| } | } | ||||
| /* Draw gridlines in the given 2d-region */ | /* Draw gridlines in the given 2d-region */ | ||||
| void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag) | void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag) | ||||
| { | { | ||||
| float vec1[2], vec2[2]; | float vec1[2], vec2[2]; | ||||
| int a, step; | int a, step; | ||||
| int verticalMinorStep = (BLI_rcti_size_x(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC), | |||||
krash: I'm not fussed about style personally, but convention is to use style of surrounding code or… | |||||
| horizontalMajorStep = (BLI_rcti_size_y(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC); | |||||
| float drawColor[3]; | |||||
krashUnsubmitted Done Inline ActionsYou use float here for drawColor but then use "ubv" below for UI and attribute functions. I think either switch this to unsigned char or use "fv" functions below. krash: You use float here for drawColor but then use "ubv" below for UI and attribute functions. I… | |||||
| /* check for grid first, as it may not exist */ | /* check for grid first, as it may not exist */ | ||||
| if (grid == NULL) | if (grid == NULL) | ||||
| return; | return; | ||||
| glBegin(GL_LINES); | /* Setup Gawain */ | ||||
| VertexFormat *format = immVertexFormat(); | |||||
| unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); | |||||
| unsigned color = add_attrib(format, "color", GL_UNSIGNED_BYTE, 3, NORMALIZE_INT_TO_FLOAT); | |||||
| /* Count the needed gridlines */ | |||||
| unsigned vertexCount = 0; | |||||
| if (flag & V2D_VERTICAL_LINES) { | |||||
| /* vertical lines */ | |||||
| vertexCount += 2 * verticalMinorStep; /* minor gridlines */ | |||||
| vertexCount += 2 * (verticalMinorStep + 2); /* major gridlines */ | |||||
| } | |||||
| if (flag & V2D_HORIZONTAL_LINES) { | |||||
| /* horizontal lines */ | |||||
| vertexCount += 2 * (horizontalMajorStep + 1); /* major gridlines */ | |||||
| /* fine lines */ | |||||
| if (flag & V2D_HORIZONTAL_FINELINES) | |||||
| vertexCount += 2 * (horizontalMajorStep + 1); | |||||
| } | |||||
| /* axes */ | |||||
| if (flag & V2D_HORIZONTAL_AXIS) | |||||
| vertexCount += 2; | |||||
| if (flag & V2D_VERTICAL_AXIS) | |||||
| vertexCount += 2; | |||||
Done Inline ActionsThese comments are obvious & can be deleted: merwin: These comments are obvious & can be deleted:
Setup Gawain
Start Rendering
Stop Rendering | |||||
| /* Start Rendering */ | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); | |||||
krashUnsubmitted Done Inline ActionsI don't think you need smooth color between verts of single lines. Use GPU_SHADER_FLAT_COLOR. krash: I don't think you need smooth color between verts of single lines. Use GPU_SHADER_FLAT_COLOR. | |||||
| immBegin(GL_LINES, vertexCount); | |||||
krashUnsubmitted Done Inline ActionsNot sure if vertexCount is ever zero in current use of grid drawing (I tried in several editors to get zero but it never happened), but it would debug assert if it was ever possible. krash: Not sure if vertexCount is ever zero in current use of grid drawing (I tried in several editors… | |||||
| /* vertical lines */ | /* vertical lines */ | ||||
| if (flag & V2D_VERTICAL_LINES) { | if (flag & V2D_VERTICAL_LINES) { | ||||
| /* initialize initial settings */ | /* initialize initial settings */ | ||||
| vec1[0] = vec2[0] = grid->startx; | vec1[0] = vec2[0] = grid->startx; | ||||
| vec1[1] = grid->starty; | vec1[1] = grid->starty; | ||||
| vec2[1] = v2d->cur.ymax; | vec2[1] = v2d->cur.ymax; | ||||
| /* minor gridlines */ | /* minor gridlines */ | ||||
| step = (BLI_rcti_size_x(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC); | UI_GetThemeColor3ubv(TH_GRID, drawColor); | ||||
| UI_ThemeColor(TH_GRID); | immAttrib3ubv(color, drawColor); | ||||
| step = verticalMinorStep; | |||||
| for (a = 0; a < step; a++) { | for (a = 0; a < step; a++) { | ||||
| glVertex2fv(vec1); | immVertex2fv(pos, vec1); | ||||
| glVertex2fv(vec2); | immVertex2fv(pos, vec2); | ||||
| vec2[0] = vec1[0] += grid->dx; | vec2[0] = vec1[0] += grid->dx; | ||||
| } | } | ||||
| /* major gridlines */ | /* major gridlines */ | ||||
| vec2[0] = vec1[0] -= 0.5f * grid->dx; | vec2[0] = vec1[0] -= 0.5f * grid->dx; | ||||
| UI_ThemeColorShade(TH_GRID, 16); | |||||
| UI_GetThemeColorShade3ubv(TH_GRID, 16, drawColor); | |||||
| immAttrib3ubv(color, drawColor); | |||||
| step++; | step++; | ||||
| for (a = 0; a <= step; a++) { | for (a = 0; a <= step; a++) { | ||||
| glVertex2fv(vec1); | immVertex2fv(pos, vec1); | ||||
| glVertex2fv(vec2); | immVertex2fv(pos, vec2); | ||||
| vec2[0] = vec1[0] -= grid->dx; | vec2[0] = vec1[0] -= grid->dx; | ||||
| } | } | ||||
| } | } | ||||
| /* horizontal lines */ | /* horizontal lines */ | ||||
| if (flag & V2D_HORIZONTAL_LINES) { | if (flag & V2D_HORIZONTAL_LINES) { | ||||
| /* only major gridlines */ | /* only major gridlines */ | ||||
| vec1[1] = vec2[1] = grid->starty; | vec1[1] = vec2[1] = grid->starty; | ||||
| vec1[0] = grid->startx; | vec1[0] = grid->startx; | ||||
| vec2[0] = v2d->cur.xmax; | vec2[0] = v2d->cur.xmax; | ||||
| step = (BLI_rcti_size_y(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC); | step = horizontalMajorStep; | ||||
| UI_GetThemeColor3ubv(TH_GRID, drawColor); | |||||
| immAttrib3ubv(color, drawColor); | |||||
| UI_ThemeColor(TH_GRID); | |||||
| for (a = 0; a <= step; a++) { | for (a = 0; a <= step; a++) { | ||||
| glVertex2fv(vec1); | immVertex2fv(pos, vec1); | ||||
| glVertex2fv(vec2); | immVertex2fv(pos, vec2); | ||||
| vec2[1] = vec1[1] += grid->dy; | vec2[1] = vec1[1] += grid->dy; | ||||
| } | } | ||||
| /* fine grid lines */ | /* fine grid lines */ | ||||
| vec2[1] = vec1[1] -= 0.5f * grid->dy; | vec2[1] = vec1[1] -= 0.5f * grid->dy; | ||||
| step++; | step++; | ||||
| if (flag & V2D_HORIZONTAL_FINELINES) { | if (flag & V2D_HORIZONTAL_FINELINES) { | ||||
| UI_ThemeColorShade(TH_GRID, 16); | UI_GetThemeColorShade3ubv(TH_GRID, 16, drawColor); | ||||
| immAttrib3ubv(color, drawColor); | |||||
| for (a = 0; a < step; a++) { | for (a = 0; a < step; a++) { | ||||
| glVertex2fv(vec1); | immVertex2fv(pos, vec1); | ||||
| glVertex2fv(vec2); | immVertex2fv(pos, vec2); | ||||
| vec2[1] = vec1[1] -= grid->dy; | vec2[1] = vec1[1] -= grid->dy; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Axes are drawn as darker lines */ | /* Axes are drawn as darker lines */ | ||||
| UI_ThemeColorShade(TH_GRID, -50); | UI_GetThemeColorShade3ubv(TH_GRID, -50, drawColor); | ||||
| immAttrib3ubv(color, drawColor); | |||||
| /* horizontal axis */ | /* horizontal axis */ | ||||
| if (flag & V2D_HORIZONTAL_AXIS) { | if (flag & V2D_HORIZONTAL_AXIS) { | ||||
| vec1[0] = v2d->cur.xmin; | vec1[0] = v2d->cur.xmin; | ||||
| vec2[0] = v2d->cur.xmax; | vec2[0] = v2d->cur.xmax; | ||||
| vec1[1] = vec2[1] = 0.0f; | vec1[1] = vec2[1] = 0.0f; | ||||
| glVertex2fv(vec1); | immVertex2fv(pos, vec1); | ||||
| glVertex2fv(vec2); | immVertex2fv(pos, vec2); | ||||
| } | } | ||||
| /* vertical axis */ | /* vertical axis */ | ||||
| if (flag & V2D_VERTICAL_AXIS) { | if (flag & V2D_VERTICAL_AXIS) { | ||||
| vec1[1] = v2d->cur.ymin; | vec1[1] = v2d->cur.ymin; | ||||
| vec2[1] = v2d->cur.ymax; | vec2[1] = v2d->cur.ymax; | ||||
| vec1[0] = vec2[0] = 0.0f; | vec1[0] = vec2[0] = 0.0f; | ||||
| glVertex2fv(vec1); | immVertex2fv(pos, vec1); | ||||
| glVertex2fv(vec2); | immVertex2fv(pos, vec2); | ||||
| } | } | ||||
| glEnd(); | /* stop rendering */ | ||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| } | } | ||||
| /* Draw a constant grid in given 2d-region */ | /* Draw a constant grid in given 2d-region */ | ||||
| void UI_view2d_constant_grid_draw(View2D *v2d) | void UI_view2d_constant_grid_draw(View2D *v2d) | ||||
| { | { | ||||
| float start_x, start_y, step = 25.0f; | float start_x, start_y, step = 25.0f; | ||||
| int count_x, count_y; | int count_x, count_y; | ||||
| ▲ Show 20 Lines • Show All 1,063 Lines • Show Last 20 Lines | |||||
I'm not fussed about style personally, but convention is to use style of surrounding code or file. This would be one of few functions in this file that would use camel case for local variables. @Mike Erwin (merwin) can decide how picky to be.