Changeset View
Standalone View
source/blender/editors/interface/view2d.c
| Show First 20 Lines • Show All 1,500 Lines • ▼ Show 20 Lines | if (count_x > 0 || count_y > 0) { | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| } | } | ||||
| /* Draw a multi-level grid in given 2d-region */ | /* Draw a multi-level grid in given 2d-region */ | ||||
| void UI_view2d_multi_grid_draw(View2D *v2d, int colorid, float step, int level_size, int totlevels) | void UI_view2d_multi_grid_draw(View2D *v2d, int colorid, float step, int level_size, int totlevels) | ||||
| { | { | ||||
| /* Exit if there is nothing to draw */ | |||||
| if (totlevels == 0) | |||||
| return; | |||||
| int offset = -10; | int offset = -10; | ||||
| float lstep = step; | float lstep = step; | ||||
| int level; | char cur_xmin_positive = v2d->cur.xmin >= 0.0f, | ||||
krash: Can remove these, cur_xmin_positive and cur_ymin_positive | |||||
| cur_ymin_positive = v2d->cur.ymin >= 0.0f; | |||||
| unsigned char grid_line_color[3]; | |||||
| /* Make an estimate of at least how many vertices will be needed */ | |||||
| unsigned vertex_count = 4; | |||||
| vertex_count += 2 * (int)((v2d->cur.xmax - v2d->cur.xmin) / lstep); | |||||
| vertex_count += 2 * (int)((v2d->cur.ymax - v2d->cur.ymin) / lstep); | |||||
krashUnsubmitted Done Inline ActionsYou need a +1 on this for cases where cur spans just over grid lines. Simple example, let's say lstep is 40 (what it is on my setup), xmin is 30 and xmax is 90. xmax-xmin is 60. 60/40 turns into 1. But grid lines are drawn at 40 and 80 because xmin starts at 30. krash: You need a +1 on this for cases where cur spans just over grid lines. Simple example, let's… | |||||
Done Inline ActionsFew things here. I think you need to cast the ((v2d->cur.xmax) / lstep) to integers. I'm getting assert below at immBeginAtMost with vertex_count of 149. Other thing is that you can't just use "cur.xmax". If you put axis close to right of screen then xmax is close to 0, which will give you almost no vertexes. Try it and it'll assert because you go past vertex count. You probably want difference of xmax and xmin. Using totlevels is ok but it gives you way more verts then needed because verts needed for other levels is reduced. Actually it skips verts on first levels if they are on next level so you may not even need to multiply by totlevels, you'll have to test. krash: Few things here. I think you need to cast the ((v2d->cur.xmax) / lstep) to integers. I'm… | |||||
| 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); | |||||
Done Inline ActionsThere is a double negative here. I tested with removing it (as well as the other ones) and it didn't look like it messed with anything. Should I go ahead and submit a diff with those removed (also at lines 1486, 1521, and 1532)? define-private-public: There is a double negative here. I tested with removing it (as well as the other ones) and it… | |||||
| glLineWidth(1.0f); | glLineWidth(1.0f); | ||||
| for (level = 0; level < totlevels; ++level) { | |||||
| int i; | |||||
| float start; | |||||
Done Inline ActionsC99 style thing -- can declare these below, first time they're used: int i = (int)(v2d ... float start = i * lstep; merwin: C99 style thing -- can declare these below, first time they're used:
```
int i = (int)(v2d ... | |||||
Done Inline Actionsfor (int level = 0 ... Delete declaration of level earlier this function. merwin: ```
for (int level = 0 ...
```
Delete declaration of level earlier this function. | |||||
| UI_ThemeColorShade(colorid, offset); | immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); | ||||
Done Inline ActionsUsing immSkipAttrib means you can't setup color ahead of time here, have to remove this line and line 1520 to stop asserts. krash: Using immSkipAttrib means you can't setup color ahead of time here, have to remove this line… | |||||
| immBeginAtMost(GL_LINES, vertex_count); | |||||
| for (int level = 0; level < totlevels; ++level) { | |||||
| UI_GetThemeColorShade3ubv(colorid, offset, grid_line_color); | |||||
| i = (v2d->cur.xmin >= 0.0f ? -(int)(-v2d->cur.xmin / lstep) : (int)(v2d->cur.xmin / lstep)); | int i = (int)(v2d->cur.xmin / lstep); | ||||
| start = i * lstep; | float start = i * lstep; | ||||
krashUnsubmitted Done Inline ActionsNeed to increment "i" here if cur.xmin is positive before using it to set "start". Simple example again, converting a float to int throws away the decimal, so 1.5 becomes 1, and -1.5 becomes -1. This shows that converting to int will always round towards 0. This is fine for negative cur because it rounds up, but if cur is positive it will round down and you will be drawing the first grid line outside the cur rect. krash: Need to increment "i" here if cur.xmin is positive before using it to set "start". Simple… | |||||
| glBegin(GL_LINES); | |||||
| for (; start < v2d->cur.xmax; start += lstep, ++i) { | for (; start < v2d->cur.xmax; start += lstep, ++i) { | ||||
| if (i == 0 || (level < totlevels - 1 && i % level_size == 0)) | if (i == 0 || (level < totlevels - 1 && i % level_size == 0)) | ||||
| continue; | continue; | ||||
| glVertex2f(start, v2d->cur.ymin); | |||||
| glVertex2f(start, v2d->cur.ymax); | immSkipAttrib(color); | ||||
| immVertex2f(pos, start, v2d->cur.ymin); | |||||
| immAttrib3ubv(color, grid_line_color); | |||||
| immVertex2f(pos, start, v2d->cur.ymax); | |||||
| } | } | ||||
| i = (v2d->cur.ymin >= 0.0f ? -(int)(-v2d->cur.ymin / lstep) : (int)(v2d->cur.ymin / lstep)); | i = (int)(v2d->cur.ymin / lstep); | ||||
| start = i * lstep; | start = i * lstep; | ||||
krashUnsubmitted Done Inline ActionsSame here, need to increment "i" if ymin > 0 krash: Same here, need to increment "i" if ymin > 0 | |||||
| for (; start < v2d->cur.ymax; start += lstep, ++i) { | for (; start < v2d->cur.ymax; start += lstep, ++i) { | ||||
| if (i == 0 || (level < totlevels - 1 && i % level_size == 0)) | if (i == 0 || (level < totlevels - 1 && i % level_size == 0)) | ||||
| continue; | continue; | ||||
| glVertex2f(v2d->cur.xmin, start); | |||||
| glVertex2f(v2d->cur.xmax, start); | |||||
| } | |||||
| /* X and Y axis */ | |||||
| UI_ThemeColorShade(colorid, offset - 8); | |||||
| glVertex2f(0.0f, v2d->cur.ymin); | |||||
| glVertex2f(0.0f, v2d->cur.ymax); | |||||
| glVertex2f(v2d->cur.xmin, 0.0f); | |||||
| glVertex2f(v2d->cur.xmax, 0.0f); | |||||
| glEnd(); | immSkipAttrib(color); | ||||
| immVertex2f(pos, v2d->cur.xmin, start); | |||||
| immAttrib3ubv(color, grid_line_color); | |||||
| immVertex2f(pos, v2d->cur.xmax, start); | |||||
| } | |||||
| lstep *= level_size; | lstep *= level_size; | ||||
Done Inline ActionsNot sure why drawing X and Y axis is inside the levels loop. Doesn't this just draw them repeatedly for no reason? It was inside the loop in the old code too, strange. Maybe I miss something. krash: Not sure why drawing X and Y axis is inside the levels loop. Doesn't this just draw them… | |||||
| offset -= 6; | offset -= 6; | ||||
| } | } | ||||
| /* X and Y axis */ | |||||
| UI_GetThemeColorShade3ubv(colorid, -18 + ((totlevels - 1) * -6) , grid_line_color); | |||||
| immSkipAttrib(color); | |||||
| immVertex2f(pos, 0.0f, v2d->cur.ymin); | |||||
| immAttrib3ubv(color, grid_line_color); | |||||
| immVertex2f(pos, 0.0f, v2d->cur.ymax); | |||||
Done Inline ActionsEmpty (code) line between these 2 (GL) lines, for clarity. merwin: Empty (code) line between these 2 (GL) lines, for clarity. | |||||
| immSkipAttrib(color); | |||||
| immVertex2f(pos, v2d->cur.xmin, 0.0f); | |||||
| immAttrib3ubv(color, grid_line_color); | |||||
| immVertex2f(pos, v2d->cur.xmax, 0.0f); | |||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| } | } | ||||
| /* the price we pay for not exposting structs :( */ | /* the price we pay for not exposting structs :( */ | ||||
| void UI_view2d_grid_size(View2DGrid *grid, float *r_dx, float *r_dy) | void UI_view2d_grid_size(View2DGrid *grid, float *r_dx, float *r_dy) | ||||
| { | { | ||||
| *r_dx = grid->dx; | *r_dx = grid->dx; | ||||
| *r_dy = grid->dy; | *r_dy = grid->dy; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 950 Lines • Show Last 20 Lines | |||||
Can remove these, cur_xmin_positive and cur_ymin_positive