Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/screen/area.c
| Context not available. | |||||
| float gridsize, gridstep = 1.0f / 32.0f; | float gridsize, gridstep = 1.0f / 32.0f; | ||||
| float fac, blendfac; | float fac, blendfac; | ||||
| int x1, y1, x2, y2; | int x1, y1, x2, y2; | ||||
| int count_fine, count_large; | |||||
| float theme_color[3]; | |||||
| int i; | |||||
merwin: We're using C99, so declare these closer to where they are used. See below. | |||||
| VertexFormat* format = immVertexFormat(); | |||||
| unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); | |||||
| unsigned color = add_attrib(format, "color", GL_FLOAT, 3, KEEP_FLOAT); | |||||
| /* the image is located inside (0, 0), (1, 1) as set by view2d */ | /* the image is located inside (0, 0), (1, 1) as set by view2d */ | ||||
| UI_ThemeColorShade(TH_BACK, 20); | UI_GetThemeColorShade3fv(TH_BACK, 20, theme_color); | ||||
| UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x1, &y1); | UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x1, &y1); | ||||
| UI_view2d_view_to_region(&ar->v2d, 1.0f, 1.0f, &x2, &y2); | UI_view2d_view_to_region(&ar->v2d, 1.0f, 1.0f, &x2, &y2); | ||||
| glRectf(x1, y1, x2, y2); | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); | |||||
| /* TODO: Use immRect once api is finished */ | |||||
merwinUnsubmitted Done Inline ActionsimmRectf is now ready! Use GPU_SHADER_2D_UNIFORM_COLOR and immUniformColor3fv(theme_color) before calling immRectf. merwin: immRectf is now ready!
Use GPU_SHADER_2D_UNIFORM_COLOR and immUniformColor3fv(theme_color)… | |||||
| immBegin(GL_TRIANGLE_FAN, 4); | |||||
| immAttrib3fv(color, theme_color); | |||||
| immVertex2f(pos, x1, y1); | |||||
| immVertex2f(pos, x2, y1); | |||||
| immVertex2f(pos, x2, y2); | |||||
| immVertex2f(pos, x1, y2); | |||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| /* gridsize adapted to zoom level */ | /* gridsize adapted to zoom level */ | ||||
| gridsize = 0.5f * (zoomx + zoomy); | gridsize = 0.5f * (zoomx + zoomy); | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| /* the fine resolution level */ | |||||
| blendfac = 0.25f * gridsize - floorf(0.25f * gridsize); | blendfac = 0.25f * gridsize - floorf(0.25f * gridsize); | ||||
| CLAMP(blendfac, 0.0f, 1.0f); | CLAMP(blendfac, 0.0f, 1.0f); | ||||
| UI_ThemeColorShade(TH_BACK, (int)(20.0f * (1.0f - blendfac))); | |||||
| count_fine = 1.0f / gridstep; | |||||
merwinUnsubmitted Done Inline Actionsfloat count_fine = ... float count_large = ... Why floats anyway? Floats are for measuring, integers are for counting. merwin: ```lang=c
float count_fine = ...
float count_large = ...
```
Why floats anyway? Floats are for… | |||||
krashAuthorUnsubmitted Not Done Inline ActionsNot sure I understand what you mean, they are ints aren't they? I can move declaration to there if it makes more sense. krash: Not sure I understand what you mean, they are ints aren't they? I can move declaration to… | |||||
| fac = 0.0f; | count_large = 1.0f / (4.0f * gridstep); | ||||
| glBegin(GL_LINES); | |||||
| while (fac < 1.0f) { | if(count_fine > 0) { | ||||
merwinUnsubmitted Done Inline Actionsstyle: add space between if and ( merwin: style: add space between if and ( | |||||
| glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac); | immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); | ||||
merwinUnsubmitted Done Inline ActionsSince the UNIFORM_COLOR shader does not have a color attribute you'll have to reset the vertex format and add "pos" & "color". How to reset: VertexFormat_clear(format); This might be an opportunity to talk about VertexFormat API improvements. merwin: Since the UNIFORM_COLOR shader does not have a color attribute you'll have to reset the vertex… | |||||
| glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac); | immBegin(GL_LINES, 4 * count_fine + 4 * count_large); | ||||
| glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1); | |||||
| glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2); | UI_GetThemeColorShade3fv(TH_BACK, (int)(20.0f * (1.0f - blendfac)), theme_color); | ||||
| fac += gridstep; | immAttrib3fv(color, theme_color); | ||||
| } | fac = 0.0f; | ||||
| /* the large resolution level */ | /* the fine resolution level */ | ||||
| UI_ThemeColor(TH_BACK); | for (i = 0; i < count_fine; i++) { | ||||
merwinUnsubmitted Done Inline Actionsfor (int i = ... merwin: ```lang=c
for (int i = ...
``` | |||||
| immVertex2f(pos, x1, y1 * (1.0f - fac) + y2 * fac); | |||||
| fac = 0.0f; | immVertex2f(pos, x2, y1 * (1.0f - fac) + y2 * fac); | ||||
| while (fac < 1.0f) { | immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y1); | ||||
| glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac); | immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y2); | ||||
| glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac); | fac += gridstep; | ||||
| glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1); | } | ||||
| glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2); | |||||
| fac += 4.0f * gridstep; | if (count_large > 0) { | ||||
| } | |||||
| glEnd(); | UI_GetThemeColor3fv(TH_BACK, theme_color); | ||||
| immAttrib3fv(color, theme_color); | |||||
| fac = 0.0f; | |||||
| /* the large resolution level */ | |||||
| for (i = 0; i < count_large; i++) { | |||||
| immVertex2f(pos, x1, y1 * (1.0f - fac) + y2 * fac); | |||||
| immVertex2f(pos, x2, y1 * (1.0f - fac) + y2 * fac); | |||||
| immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y1); | |||||
| immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y2); | |||||
| fac += 4.0f * gridstep; | |||||
| } | |||||
| } | |||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| } | |||||
| } | } | ||||
| /* If the area has overlapping regions, it returns visible rect for Region *ar */ | /* If the area has overlapping regions, it returns visible rect for Region *ar */ | ||||
| Context not available. | |||||
We're using C99, so declare these closer to where they are used. See below.