[Bf-blender-cvs] [384a16b] master: cleanup: C99
Mike Erwin
noreply at git.blender.org
Sat Jan 16 08:20:51 CET 2016
Commit: 384a16bfbc802f9f7a6f3a666c9583f35468531d
Author: Mike Erwin
Date: Sat Jan 16 02:17:05 2016 -0500
Branches: master
https://developer.blender.org/rB384a16bfbc802f9f7a6f3a666c9583f35468531d
cleanup: C99
- tighter scoping
- declare closer to use
- struct initializers
- bool vs int
===================================================================
M source/blender/editors/interface/interface_draw.c
===================================================================
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 4067f2b..2ba5218 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -145,11 +145,11 @@ void UI_draw_roundbox_gl_mode(int mode, float minx, float miny, float maxx, floa
static void round_box_shade_col(const float col1[3], float const col2[3], const float fac)
{
- float col[3];
-
- col[0] = (fac * col1[0] + (1.0f - fac) * col2[0]);
- col[1] = (fac * col1[1] + (1.0f - fac) * col2[1]);
- col[2] = (fac * col1[2] + (1.0f - fac) * col2[2]);
+ float col[3] = {
+ fac * col1[0] + (1.0f - fac) * col2[0],
+ fac * col1[1] + (1.0f - fac) * col2[1],
+ fac * col1[2] + (1.0f - fac) * col2[2]
+ };
glColor3fv(col);
}
@@ -413,13 +413,11 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w
(void)but;
#else
ImBuf *ibuf = (ImBuf *)but->poin;
- //GLint scissor[4];
- int w, h;
if (!ibuf) return;
- w = BLI_rcti_size_x(rect);
- h = BLI_rcti_size_y(rect);
+ int w = BLI_rcti_size_x(rect);
+ int h = BLI_rcti_size_y(rect);
/* scissor doesn't seem to be doing the right thing...? */
#if 0
@@ -427,6 +425,7 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w
//fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax)
/* prevent drawing outside widget area */
+ GLint scissor[4];
glGetIntegerv(GL_SCISSOR_BOX, scissor);
glScissor(ar->winrct.xmin + rect->xmin, ar->winrct.ymin + rect->ymin, w, h);
#endif
@@ -466,10 +465,10 @@ void UI_draw_safe_areas(
const float size_y_half = (y2 - y1) * 0.5f;
const float *safe_areas[] = {title_aspect, action_aspect};
- int i, safe_len = ARRAY_SIZE(safe_areas);
+ int safe_len = ARRAY_SIZE(safe_areas);
bool is_first = true;
- for (i = 0; i < safe_len; i++) {
+ for (int i = 0; i < safe_len; i++) {
if (safe_areas[i][0] || safe_areas[i][1]) {
float margin_x, margin_y;
float minx, miny, maxx, maxy;
@@ -515,10 +514,7 @@ static void histogram_draw_one(
float r, float g, float b, float alpha,
float x, float y, float w, float h, const float *data, int res, const bool is_line)
{
- int i;
-
if (is_line) {
-
glLineWidth(1.5);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4f(r, g, b, alpha);
@@ -528,7 +524,7 @@ static void histogram_draw_one(
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_LINE_SMOOTH);
glBegin(GL_LINE_STRIP);
- for (i = 0; i < res; i++) {
+ for (int i = 0; i < res; i++) {
float x2 = x + i * (w / (float)res);
glVertex2f(x2, y + (data[i] * h));
}
@@ -546,7 +542,7 @@ static void histogram_draw_one(
glBegin(GL_TRIANGLE_STRIP);
glVertex2f(x, y);
glVertex2f(x, y + (data[0] * h));
- for (i = 1; i < res; i++) {
+ for (int i = 1; i < res; i++) {
float x2 = x + i * (w / (float)res);
glVertex2f(x2, y + (data[i] * h));
glVertex2f(x2, y);
@@ -559,7 +555,7 @@ static void histogram_draw_one(
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glBegin(GL_LINE_STRIP);
- for (i = 0; i < res; i++) {
+ for (int i = 0; i < res; i++) {
float x2 = x + i * (w / (float)res);
glVertex2f(x2, y + (data[i] * h));
}
@@ -574,20 +570,17 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
{
Histogram *hist = (Histogram *)but->poin;
int res = hist->x_resolution;
- rctf rect;
- int i;
- float w, h;
const bool is_line = (hist->flag & HISTO_FLAG_LINE) != 0;
- //float alpha;
- GLint scissor[4];
- rect.xmin = (float)recti->xmin + 1;
- rect.xmax = (float)recti->xmax - 1;
- rect.ymin = (float)recti->ymin + 1;
- rect.ymax = (float)recti->ymax - 1;
+ rctf rect = {
+ .xmin = (float)recti->xmin + 1,
+ .xmax = (float)recti->xmax - 1,
+ .ymin = (float)recti->ymin + 1,
+ .ymax = (float)recti->ymax - 1
+ };
- w = BLI_rctf_size_x(&rect);
- h = BLI_rctf_size_y(&rect) * hist->ymax;
+ float w = BLI_rctf_size_x(&rect);
+ float h = BLI_rctf_size_y(&rect) * hist->ymax;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -597,6 +590,7 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
UI_draw_roundbox_gl_mode(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f);
/* need scissor test, histogram can draw outside of boundary */
+ GLint scissor[4];
glGetIntegerv(GL_VIEWPORT, scissor);
glScissor(ar->winrct.xmin + (rect.xmin - 1),
ar->winrct.ymin + (rect.ymin - 1),
@@ -605,7 +599,7 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
glColor4f(1.f, 1.f, 1.f, 0.08f);
/* draw grid lines here */
- for (i = 1; i <= HISTOGRAM_TOT_GRID_LINES; i++) {
+ for (int i = 1; i <= HISTOGRAM_TOT_GRID_LINES; i++) {
const float fac = (float)i / (float)HISTOGRAM_TOT_GRID_LINES;
/* so we can tell the 1.0 color point */
@@ -641,9 +635,6 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
{
Scopes *scopes = (Scopes *)but->poin;
- rctf rect;
- int i, c;
- float w, w3, h, alpha, yofs;
GLint scissor[4];
float colors[3][3];
float colorsycc[3][3] = {{1, 0, 1}, {1, 1, 0}, {0, 1, 1}};
@@ -652,25 +643,27 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
if (scopes == NULL) return;
- rect.xmin = (float)recti->xmin + 1;
- rect.xmax = (float)recti->xmax - 1;
- rect.ymin = (float)recti->ymin + 1;
- rect.ymax = (float)recti->ymax - 1;
+ rctf rect = {
+ .xmin = (float)recti->xmin + 1,
+ .xmax = (float)recti->xmax - 1,
+ .ymin = (float)recti->ymin + 1,
+ .ymax = (float)recti->ymax - 1
+ };
if (scopes->wavefrm_yfac < 0.5f)
scopes->wavefrm_yfac = 0.98f;
- w = BLI_rctf_size_x(&rect) - 7;
- h = BLI_rctf_size_y(&rect) * scopes->wavefrm_yfac;
- yofs = rect.ymin + (BLI_rctf_size_y(&rect) - h) / 2.0f;
- w3 = w / 3.0f;
+ float w = BLI_rctf_size_x(&rect) - 7;
+ float h = BLI_rctf_size_y(&rect) * scopes->wavefrm_yfac;
+ float yofs = rect.ymin + (BLI_rctf_size_y(&rect) - h) / 2.0f;
+ float w3 = w / 3.0f;
/* log scale for alpha */
- alpha = scopes->wavefrm_alpha * scopes->wavefrm_alpha;
+ float alpha = scopes->wavefrm_alpha * scopes->wavefrm_alpha;
unit_m3(colors);
- for (c = 0; c < 3; c++) {
- for (i = 0; i < 3; i++) {
+ for (int c = 0; c < 3; c++) {
+ for (int i = 0; i < 3; i++) {
colors_alpha[c][i] = colors[c][i] * alpha;
colorsycc_alpha[c][i] = colorsycc[c][i] * alpha;
}
@@ -692,7 +685,7 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
glColor4f(1.f, 1.f, 1.f, 0.08f);
/* draw grid lines here */
- for (i = 0; i < 6; i++) {
+ for (int i = 0; i < 6; i++) {
char str[4];
BLI_snprintf(str, sizeof(str), "%-3d", i * 20);
str[3] = '\0';
@@ -704,7 +697,7 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
}
/* 3 vertical separation */
if (scopes->wavefrm_mode != SCOPES_WAVEFRM_LUMA) {
- for (i = 1; i < 3; i++) {
+ for (int i = 1; i < 3; i++) {
fdrawline(rect.xmin + i * w3, rect.ymin, rect.xmin + i * w3, rect.ymax);
}
}
@@ -790,7 +783,7 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
/* min max */
- for (c = 0; c < 3; c++) {
+ for (int c = 0; c < 3; c++) {
if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB)
glColor3f(colors[c][0] * 0.75f, colors[c][1] * 0.75f, colors[c][2] * 0.75f);
else
@@ -874,27 +867,25 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
{
const float skin_rad = DEG2RADF(123.0f); /* angle in radians of the skin tone line */
Scopes *scopes = (Scopes *)but->poin;
- rctf rect;
- int i, j;
- float w, h, centerx, centery, diam;
- float alpha;
+
const float colors[6][3] = {
{0.75, 0.0, 0.0}, {0.75, 0.75, 0.0}, {0.0, 0.75, 0.0},
{0.0, 0.75, 0.75}, {0.0, 0.0, 0.75}, {0.75, 0.0, 0.75}};
- GLint scissor[4];
- rect.xmin = (float)recti->xmin + 1;
- rect.xmax = (float)recti->xmax - 1;
- rect.ymin = (float)recti->ymin + 1;
- rect.ymax = (float)recti->ymax - 1;
+ rctf rect = {
+ .xmin = (float)recti->xmin + 1,
+ .xmax = (float)recti->xmax - 1,
+ .ymin = (float)recti->ymin + 1,
+ .ymax = (float)recti->ymax - 1
+ };
- w = BLI_rctf_size_x(&rect);
- h = BLI_rctf_size_y(&rect);
- centerx = rect.xmin + w / 2;
- centery = rect.ymin + h / 2;
- diam = (w < h) ? w : h;
+ float w = BLI_rctf_size_x(&rect);
+ float h = BLI_rctf_size_y(&rect);
+ float centerx = rect.xmin + w / 2;
+ float centery = rect.ymin + h / 2;
+ float diam = (w < h) ? w : h;
- alpha = scopes->vecscope_alpha * scopes->vecscope_alpha * scopes->vecscope_alpha;
+ float alpha = scopes->vecscope_alpha * scopes->vecscope_alpha * scopes->vecscope_alpha;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -904,6 +895,7 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
UI_draw_roundbox_gl_mode(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f);
/* need scissor test, hvectorscope can draw outside of boundary */
+ GLint scissor[4];
glGetIntegerv(GL_VIEWPORT, scissor);
glScissor(ar->winrct.xmin + (rect.xmin - 1),
ar->winrct.ymin + (rect.ymin - 1),
@@ -916,10 +908,10 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
fdrawline(centerx - (diam / 2) - 5, centery, centerx + (diam / 2) + 5, centery);
fdrawline(centerx, centery - (diam / 2) - 5, centerx, centery + (diam / 2) + 5);
/* circles */
- for (j = 0; j < 5; j++) {
+ for (int j = 0; j < 5; j++) {
glBegin(GL_LINE_LOOP);
const int increment = 15;
- for (i = 0; i <= 360 - increment; i += increment) {
+ for (int i = 0; i <= 360 - increment; i += increment) {
const float a = DEG2RADF((float)i);
const float r = (j + 1) / 10.0f;
glVertex2f(polar_to_x(centerx, diam, r, a), polar_to_y(centery, diam, r, a));
@@ -931,7 +923,7 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
fdrawline(polar_to_x(centerx, d
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list