2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * Contributor(s): Blender Foundation
23 * ***** END GPL LICENSE BLOCK *****
26 /** \file blender/editors/interface/interface_draw.c
27 * \ingroup edinterface
34 #include "DNA_color_types.h"
35 #include "DNA_screen_types.h"
36 #include "DNA_movieclip_types.h"
40 #include "BLI_string.h"
41 #include "BLI_utildefines.h"
43 #include "BKE_colortools.h"
45 #include "BKE_texture.h"
46 #include "BKE_tracking.h"
49 #include "IMB_imbuf.h"
50 #include "IMB_imbuf_types.h"
51 #include "IMB_colormanagement.h"
54 #include "BIF_glutil.h"
58 #include "UI_interface.h"
61 #include "interface_intern.h"
63 static int roundboxtype = UI_CNR_ALL;
65 void uiSetRoundBox(int type)
67 /* Not sure the roundbox function is the best place to change this
68 * if this is undone, its not that big a deal, only makes curves edges
74 int uiGetRoundBox(void)
79 void uiDrawBox(int mode, float minx, float miny, float maxx, float maxy, float rad)
81 float vec[7][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
82 {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
86 for (a = 0; a < 7; a++) {
87 mul_v2_fl(vec[a], rad);
92 /* start with corner right-bottom */
93 if (roundboxtype & UI_CNR_BOTTOM_RIGHT) {
94 glVertex2f(maxx - rad, miny);
95 for (a = 0; a < 7; a++) {
96 glVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]);
98 glVertex2f(maxx, miny + rad);
101 glVertex2f(maxx, miny);
104 /* corner right-top */
105 if (roundboxtype & UI_CNR_TOP_RIGHT) {
106 glVertex2f(maxx, maxy - rad);
107 for (a = 0; a < 7; a++) {
108 glVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]);
110 glVertex2f(maxx - rad, maxy);
113 glVertex2f(maxx, maxy);
116 /* corner left-top */
117 if (roundboxtype & UI_CNR_TOP_LEFT) {
118 glVertex2f(minx + rad, maxy);
119 for (a = 0; a < 7; a++) {
120 glVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]);
122 glVertex2f(minx, maxy - rad);
125 glVertex2f(minx, maxy);
128 /* corner left-bottom */
129 if (roundboxtype & UI_CNR_BOTTOM_LEFT) {
130 glVertex2f(minx, miny + rad);
131 for (a = 0; a < 7; a++) {
132 glVertex2f(minx + vec[a][1], miny + rad - vec[a][0]);
134 glVertex2f(minx + rad, miny);
137 glVertex2f(minx, miny);
143 static void round_box_shade_col(const float col1[3], float const col2[3], const float fac)
147 col[0] = (fac * col1[0] + (1.0f - fac) * col2[0]);
148 col[1] = (fac * col1[1] + (1.0f - fac) * col2[1]);
149 col[2] = (fac * col1[2] + (1.0f - fac) * col2[2]);
153 /* linear horizontal shade within button or in outline */
154 /* view2d scrollers use it */
155 void uiDrawBoxShade(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadetop, float shadedown)
157 float vec[7][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
158 {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
159 const float div = maxy - miny;
160 const float idiv = 1.0f / div;
161 float coltop[3], coldown[3], color[4];
165 for (a = 0; a < 7; a++) {
166 mul_v2_fl(vec[a], rad);
168 /* get current color, needs to be outside of glBegin/End */
169 glGetFloatv(GL_CURRENT_COLOR, color);
171 /* 'shade' defines strength of shading */
172 coltop[0] = min_ff(1.0f, color[0] + shadetop);
173 coltop[1] = min_ff(1.0f, color[1] + shadetop);
174 coltop[2] = min_ff(1.0f, color[2] + shadetop);
175 coldown[0] = max_ff(0.0f, color[0] + shadedown);
176 coldown[1] = max_ff(0.0f, color[1] + shadedown);
177 coldown[2] = max_ff(0.0f, color[2] + shadedown);
179 glShadeModel(GL_SMOOTH);
182 /* start with corner right-bottom */
183 if (roundboxtype & UI_CNR_BOTTOM_RIGHT) {
185 round_box_shade_col(coltop, coldown, 0.0);
186 glVertex2f(maxx - rad, miny);
188 for (a = 0; a < 7; a++) {
189 round_box_shade_col(coltop, coldown, vec[a][1] * idiv);
190 glVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]);
193 round_box_shade_col(coltop, coldown, rad * idiv);
194 glVertex2f(maxx, miny + rad);
197 round_box_shade_col(coltop, coldown, 0.0);
198 glVertex2f(maxx, miny);
201 /* corner right-top */
202 if (roundboxtype & UI_CNR_TOP_RIGHT) {
204 round_box_shade_col(coltop, coldown, (div - rad) * idiv);
205 glVertex2f(maxx, maxy - rad);
207 for (a = 0; a < 7; a++) {
208 round_box_shade_col(coltop, coldown, (div - rad + vec[a][1]) * idiv);
209 glVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]);
211 round_box_shade_col(coltop, coldown, 1.0);
212 glVertex2f(maxx - rad, maxy);
215 round_box_shade_col(coltop, coldown, 1.0);
216 glVertex2f(maxx, maxy);
219 /* corner left-top */
220 if (roundboxtype & UI_CNR_TOP_LEFT) {
222 round_box_shade_col(coltop, coldown, 1.0);
223 glVertex2f(minx + rad, maxy);
225 for (a = 0; a < 7; a++) {
226 round_box_shade_col(coltop, coldown, (div - vec[a][1]) * idiv);
227 glVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]);
230 round_box_shade_col(coltop, coldown, (div - rad) * idiv);
231 glVertex2f(minx, maxy - rad);
234 round_box_shade_col(coltop, coldown, 1.0);
235 glVertex2f(minx, maxy);
238 /* corner left-bottom */
239 if (roundboxtype & UI_CNR_BOTTOM_LEFT) {
241 round_box_shade_col(coltop, coldown, rad * idiv);
242 glVertex2f(minx, miny + rad);
244 for (a = 0; a < 7; a++) {
245 round_box_shade_col(coltop, coldown, (rad - vec[a][1]) * idiv);
246 glVertex2f(minx + vec[a][1], miny + rad - vec[a][0]);
249 round_box_shade_col(coltop, coldown, 0.0);
250 glVertex2f(minx + rad, miny);
253 round_box_shade_col(coltop, coldown, 0.0);
254 glVertex2f(minx, miny);
258 glShadeModel(GL_FLAT);
261 /* linear vertical shade within button or in outline */
262 /* view2d scrollers use it */
263 void uiDrawBoxVerticalShade(int mode, float minx, float miny, float maxx, float maxy,
264 float rad, float shadeLeft, float shadeRight)
266 float vec[7][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
267 {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
268 const float div = maxx - minx;
269 const float idiv = 1.0f / div;
270 float colLeft[3], colRight[3], color[4];
274 for (a = 0; a < 7; a++) {
275 mul_v2_fl(vec[a], rad);
277 /* get current color, needs to be outside of glBegin/End */
278 glGetFloatv(GL_CURRENT_COLOR, color);
280 /* 'shade' defines strength of shading */
281 colLeft[0] = min_ff(1.0f, color[0] + shadeLeft);
282 colLeft[1] = min_ff(1.0f, color[1] + shadeLeft);
283 colLeft[2] = min_ff(1.0f, color[2] + shadeLeft);
284 colRight[0] = max_ff(0.0f, color[0] + shadeRight);
285 colRight[1] = max_ff(0.0f, color[1] + shadeRight);
286 colRight[2] = max_ff(0.0f, color[2] + shadeRight);
288 glShadeModel(GL_SMOOTH);
291 /* start with corner right-bottom */
292 if (roundboxtype & UI_CNR_BOTTOM_RIGHT) {
293 round_box_shade_col(colLeft, colRight, 0.0);
294 glVertex2f(maxx - rad, miny);
296 for (a = 0; a < 7; a++) {
297 round_box_shade_col(colLeft, colRight, vec[a][0] * idiv);
298 glVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]);
301 round_box_shade_col(colLeft, colRight, rad * idiv);
302 glVertex2f(maxx, miny + rad);
305 round_box_shade_col(colLeft, colRight, 0.0);
306 glVertex2f(maxx, miny);
309 /* corner right-top */
310 if (roundboxtype & UI_CNR_TOP_RIGHT) {
311 round_box_shade_col(colLeft, colRight, 0.0);
312 glVertex2f(maxx, maxy - rad);
314 for (a = 0; a < 7; a++) {
316 round_box_shade_col(colLeft, colRight, (div - rad - vec[a][0]) * idiv);
317 glVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]);
319 round_box_shade_col(colLeft, colRight, (div - rad) * idiv);
320 glVertex2f(maxx - rad, maxy);
323 round_box_shade_col(colLeft, colRight, 0.0);
324 glVertex2f(maxx, maxy);
327 /* corner left-top */
328 if (roundboxtype & UI_CNR_TOP_LEFT) {
329 round_box_shade_col(colLeft, colRight, (div - rad) * idiv);
330 glVertex2f(minx + rad, maxy);
332 for (a = 0; a < 7; a++) {
333 round_box_shade_col(colLeft, colRight, (div - rad + vec[a][0]) * idiv);
334 glVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]);
337 round_box_shade_col(colLeft, colRight, 1.0);
338 glVertex2f(minx, maxy - rad);
341 round_box_shade_col(colLeft, colRight, 1.0);
342 glVertex2f(minx, maxy);
345 /* corner left-bottom */
346 if (roundboxtype & UI_CNR_BOTTOM_LEFT) {
347 round_box_shade_col(colLeft, colRight, 1.0);
348 glVertex2f(minx, miny + rad);
350 for (a = 0; a < 7; a++) {
351 round_box_shade_col(colLeft, colRight, (vec[a][0]) * idiv);
352 glVertex2f(minx + vec[a][1], miny + rad - vec[a][0]);
355 round_box_shade_col(colLeft, colRight, 1.0);
356 glVertex2f(minx + rad, miny);
359 round_box_shade_col(colLeft, colRight, 1.0);
360 glVertex2f(minx, miny);
364 glShadeModel(GL_FLAT);
367 /* plain antialiased unfilled rectangle */
368 void uiRoundRect(float minx, float miny, float maxx, float maxy, float rad)
372 if (roundboxtype & UI_RB_ALPHA) {
373 glGetFloatv(GL_CURRENT_COLOR, color);
379 /* set antialias line */
380 glEnable(GL_LINE_SMOOTH);
383 uiDrawBox(GL_LINE_LOOP, minx, miny, maxx, maxy, rad);
386 glDisable(GL_LINE_SMOOTH);
389 /* (old, used in outliner) plain antialiased filled box */
390 void uiRoundBox(float minx, float miny, float maxx, float maxy, float rad)
392 ui_draw_anti_roundbox(GL_POLYGON, minx, miny, maxx, maxy, rad, roundboxtype & UI_RB_ALPHA);
395 /* ************** SPECIAL BUTTON DRAWING FUNCTIONS ************* */
397 void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *rect)
403 ImBuf *ibuf = (ImBuf *)but->poin;
409 w = BLI_rcti_size_x(rect);
410 h = BLI_rcti_size_y(rect);
412 /* scissor doesn't seem to be doing the right thing...? */
414 //glColor4f(1.0, 0.f, 0.f, 1.f);
415 //fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax)
417 /* prevent drawing outside widget area */
418 glGetIntegerv(GL_SCISSOR_BOX, scissor);
419 glScissor(ar->winrct.xmin + rect->xmin, ar->winrct.ymin + rect->ymin, w, h);
423 glColor4f(0.0, 0.0, 0.0, 0.0);
425 if (w != ibuf->x || h != ibuf->y) {
426 float facx = (float)w / (float)ibuf->x;
427 float facy = (float)h / (float)ibuf->y;
428 glPixelZoom(facx, facy);
430 glaDrawPixelsAuto((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, ibuf->rect);
432 glPixelZoom(1.0f, 1.0f);
437 // restore scissortest
438 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
444 static void draw_scope_end(const rctf *rect, GLint *scissor)
446 /* restore scissortest */
447 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
449 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
452 glColor4f(0.f, 0.f, 0.f, 0.5f);
453 uiSetRoundBox(UI_CNR_ALL);
454 uiDrawBox(GL_LINE_LOOP, rect->xmin - 1, rect->ymin, rect->xmax + 1, rect->ymax + 1, 3.0f);
457 static void histogram_draw_one(float r, float g, float b, float alpha,
458 float x, float y, float w, float h, const float *data, int res, const bool is_line)
465 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
466 glColor4f(r, g, b, alpha);
470 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
471 glEnable(GL_LINE_SMOOTH);
472 glBegin(GL_LINE_STRIP);
473 for (i = 0; i < res; i++) {
474 float x2 = x + i * (w / (float)res);
475 glVertex2f(x2, y + (data[i] * h));
478 glDisable(GL_LINE_SMOOTH);
483 /* under the curve */
484 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
485 glColor4f(r, g, b, alpha);
487 glShadeModel(GL_FLAT);
488 glBegin(GL_QUAD_STRIP);
490 glVertex2f(x, y + (data[0] * h));
491 for (i = 1; i < res; i++) {
492 float x2 = x + i * (w / (float)res);
493 glVertex2f(x2, y + (data[i] * h));
499 glColor4f(0.f, 0.f, 0.f, 0.25f);
501 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
502 glEnable(GL_LINE_SMOOTH);
503 glBegin(GL_LINE_STRIP);
504 for (i = 0; i < res; i++) {
505 float x2 = x + i * (w / (float)res);
506 glVertex2f(x2, y + (data[i] * h));
509 glDisable(GL_LINE_SMOOTH);
513 #define HISTOGRAM_TOT_GRID_LINES 4
515 void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
517 Histogram *hist = (Histogram *)but->poin;
518 int res = hist->x_resolution;
522 const bool is_line = (hist->flag & HISTO_FLAG_LINE) != 0;
526 rect.xmin = (float)recti->xmin + 1;
527 rect.xmax = (float)recti->xmax - 1;
528 rect.ymin = (float)recti->ymin + 1;
529 rect.ymax = (float)recti->ymax - 1;
531 w = BLI_rctf_size_x(&rect);
532 h = BLI_rctf_size_y(&rect) * hist->ymax;
535 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
537 glColor4f(0.f, 0.f, 0.f, 0.3f);
538 uiSetRoundBox(UI_CNR_ALL);
539 uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f);
541 /* need scissor test, histogram can draw outside of boundary */
542 glGetIntegerv(GL_VIEWPORT, scissor);
543 glScissor(ar->winrct.xmin + (rect.xmin - 1),
544 ar->winrct.ymin + (rect.ymin - 1),
545 (rect.xmax + 1) - (rect.xmin - 1),
546 (rect.ymax + 1) - (rect.ymin - 1));
548 glColor4f(1.f, 1.f, 1.f, 0.08f);
549 /* draw grid lines here */
550 for (i = 1; i <= HISTOGRAM_TOT_GRID_LINES; i++) {
551 const float fac = (float)i / (float)HISTOGRAM_TOT_GRID_LINES;
553 /* so we can tell the 1.0 color point */
554 if (i == HISTOGRAM_TOT_GRID_LINES) {
555 glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
558 fdrawline(rect.xmin, rect.ymin + fac * h, rect.xmax, rect.ymin + fac * h);
559 fdrawline(rect.xmin + fac * w, rect.ymin, rect.xmin + fac * w, rect.ymax);
562 if (hist->mode == HISTO_MODE_LUMA) {
563 histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res, is_line);
565 else if (hist->mode == HISTO_MODE_ALPHA) {
566 histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_a, res, is_line);
569 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_R)
570 histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res, is_line);
571 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_G)
572 histogram_draw_one(0.0, 1.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_g, res, is_line);
573 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_B)
574 histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res, is_line);
578 draw_scope_end(&rect, scissor);
581 #undef HISTOGRAM_TOT_GRID_LINES
583 void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
585 Scopes *scopes = (Scopes *)but->poin;
588 float w, w3, h, alpha, yofs;
591 float colorsycc[3][3] = {{1, 0, 1}, {1, 1, 0}, {0, 1, 1}};
592 float colors_alpha[3][3], colorsycc_alpha[3][3]; /* colors pre multiplied by alpha for speed up */
595 if (scopes == NULL) return;
597 rect.xmin = (float)recti->xmin + 1;
598 rect.xmax = (float)recti->xmax - 1;
599 rect.ymin = (float)recti->ymin + 1;
600 rect.ymax = (float)recti->ymax - 1;
602 if (scopes->wavefrm_yfac < 0.5f)
603 scopes->wavefrm_yfac = 0.98f;
604 w = BLI_rctf_size_x(&rect) - 7;
605 h = BLI_rctf_size_y(&rect) * scopes->wavefrm_yfac;
606 yofs = rect.ymin + (BLI_rctf_size_y(&rect) - h) / 2.0f;
609 /* log scale for alpha */
610 alpha = scopes->wavefrm_alpha * scopes->wavefrm_alpha;
614 for (c = 0; c < 3; c++) {
615 for (i = 0; i < 3; i++) {
616 colors_alpha[c][i] = colors[c][i] * alpha;
617 colorsycc_alpha[c][i] = colorsycc[c][i] * alpha;
622 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
624 glColor4f(0.f, 0.f, 0.f, 0.3f);
625 uiSetRoundBox(UI_CNR_ALL);
626 uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f);
628 /* need scissor test, waveform can draw outside of boundary */
629 glGetIntegerv(GL_VIEWPORT, scissor);
630 glScissor(ar->winrct.xmin + (rect.xmin - 1),
631 ar->winrct.ymin + (rect.ymin - 1),
632 (rect.xmax + 1) - (rect.xmin - 1),
633 (rect.ymax + 1) - (rect.ymin - 1));
635 glColor4f(1.f, 1.f, 1.f, 0.08f);
636 /* draw grid lines here */
637 for (i = 0; i < 6; i++) {
639 BLI_snprintf(str, sizeof(str), "%-3d", i * 20);
641 fdrawline(rect.xmin + 22, yofs + (i / 5.f) * h, rect.xmax + 1, yofs + (i / 5.f) * h);
642 BLF_draw_default(rect.xmin + 1, yofs - 5 + (i / 5.f) * h, 0, str, sizeof(str) - 1);
643 /* in the loop because blf_draw reset it */
645 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
647 /* 3 vertical separation */
648 if (scopes->wavefrm_mode != SCOPES_WAVEFRM_LUMA) {
649 for (i = 1; i < 3; i++) {
650 fdrawline(rect.xmin + i * w3, rect.ymin, rect.xmin + i * w3, rect.ymax);
654 /* separate min max zone on the right */
655 fdrawline(rect.xmin + w, rect.ymin, rect.xmin + w, rect.ymax);
656 /* 16-235-240 level in case of ITU-R BT601/709 */
657 glColor4f(1.f, 0.4f, 0.f, 0.2f);
658 if (ELEM(scopes->wavefrm_mode, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_709)) {
659 fdrawline(rect.xmin + 22, yofs + h * 16.0f / 255.0f, rect.xmax + 1, yofs + h * 16.0f / 255.0f);
660 fdrawline(rect.xmin + 22, yofs + h * 235.0f / 255.0f, rect.xmin + w3, yofs + h * 235.0f / 255.0f);
661 fdrawline(rect.xmin + 3 * w3, yofs + h * 235.0f / 255.0f, rect.xmax + 1, yofs + h * 235.0f / 255.0f);
662 fdrawline(rect.xmin + w3, yofs + h * 240.0f / 255.0f, rect.xmax + 1, yofs + h * 240.0f / 255.0f);
664 /* 7.5 IRE black point level for NTSC */
665 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA)
666 fdrawline(rect.xmin, yofs + h * 0.075f, rect.xmax + 1, yofs + h * 0.075f);
668 if (scopes->ok && scopes->waveform_1 != NULL) {
670 /* LUMA (1 channel) */
671 glBlendFunc(GL_ONE, GL_ONE);
672 glColor3f(alpha, alpha, alpha);
673 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) {
675 glBlendFunc(GL_ONE, GL_ONE);
678 glEnableClientState(GL_VERTEX_ARRAY);
680 glTranslatef(rect.xmin, yofs, 0.f);
682 glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1);
683 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
685 glDisableClientState(GL_VERTEX_ARRAY);
689 glColor3f(0.5f, 0.5f, 0.5f);
690 min = yofs + scopes->minmax[0][0] * h;
691 max = yofs + scopes->minmax[0][1] * h;
692 CLAMP(min, rect.ymin, rect.ymax);
693 CLAMP(max, rect.ymin, rect.ymax);
694 fdrawline(rect.xmax - 3, min, rect.xmax - 3, max);
697 /* RGB / YCC (3 channels) */
698 else if (ELEM(scopes->wavefrm_mode,
700 SCOPES_WAVEFRM_YCC_601,
701 SCOPES_WAVEFRM_YCC_709,
702 SCOPES_WAVEFRM_YCC_JPEG))
704 int rgb = (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB);
706 glBlendFunc(GL_ONE, GL_ONE);
709 glEnableClientState(GL_VERTEX_ARRAY);
711 glTranslatef(rect.xmin, yofs, 0.f);
712 glScalef(w3, h, 0.f);
714 glColor3fv((rgb) ? colors_alpha[0] : colorsycc_alpha[0]);
715 glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1);
716 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
718 glTranslatef(1.f, 0.f, 0.f);
719 glColor3fv((rgb) ? colors_alpha[1] : colorsycc_alpha[1]);
720 glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_2);
721 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
723 glTranslatef(1.f, 0.f, 0.f);
724 glColor3fv((rgb) ? colors_alpha[2] : colorsycc_alpha[2]);
725 glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_3);
726 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
728 glDisableClientState(GL_VERTEX_ARRAY);
733 for (c = 0; c < 3; c++) {
734 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB)
735 glColor3f(colors[c][0] * 0.75f, colors[c][1] * 0.75f, colors[c][2] * 0.75f);
737 glColor3f(colorsycc[c][0] * 0.75f, colorsycc[c][1] * 0.75f, colorsycc[c][2] * 0.75f);
738 min = yofs + scopes->minmax[c][0] * h;
739 max = yofs + scopes->minmax[c][1] * h;
740 CLAMP(min, rect.ymin, rect.ymax);
741 CLAMP(max, rect.ymin, rect.ymax);
742 fdrawline(rect.xmin + w + 2 + c * 2, min, rect.xmin + w + 2 + c * 2, max);
748 draw_scope_end(&rect, scissor);
751 static float polar_to_x(float center, float diam, float ampli, float angle)
753 return center + diam * ampli * cosf(angle);
756 static float polar_to_y(float center, float diam, float ampli, float angle)
758 return center + diam * ampli * sinf(angle);
761 static void vectorscope_draw_target(float centerx, float centery, float diam, const float colf[3])
764 float tangle = 0.f, tampli;
765 float dangle, dampli, dangle2, dampli2;
767 rgb_to_yuv(colf[0], colf[1], colf[2], &y, &u, &v);
768 if (u > 0 && v >= 0) tangle = atanf(v / u);
769 else if (u > 0 && v < 0) tangle = atanf(v / u) + 2.0f * (float)M_PI;
770 else if (u < 0) tangle = atanf(v / u) + (float)M_PI;
771 else if (u == 0 && v > 0.0f) tangle = (float)M_PI / 2.0f;
772 else if (u == 0 && v < 0.0f) tangle = -(float)M_PI / 2.0f;
773 tampli = sqrtf(u * u + v * v);
775 /* small target vary by 2.5 degree and 2.5 IRE unit */
776 glColor4f(1.0f, 1.0f, 1.0, 0.12f);
777 dangle = DEG2RADF(2.5f);
778 dampli = 2.5f / 200.0f;
779 glBegin(GL_LINE_STRIP);
780 glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle));
781 glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle + dangle), polar_to_y(centery, diam, tampli - dampli, tangle + dangle));
782 glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle - dangle), polar_to_y(centery, diam, tampli - dampli, tangle - dangle));
783 glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle - dangle), polar_to_y(centery, diam, tampli + dampli, tangle - dangle));
784 glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle));
786 /* big target vary by 10 degree and 20% amplitude */
787 glColor4f(1.0f, 1.0f, 1.0, 0.12f);
788 dangle = DEG2RADF(10.0f);
789 dampli = 0.2f * tampli;
790 dangle2 = DEG2RADF(5.0f);
791 dampli2 = 0.5f * dampli;
792 glBegin(GL_LINE_STRIP);
793 glVertex2f(polar_to_x(centerx, diam, tampli + dampli - dampli2, tangle + dangle), polar_to_y(centery, diam, tampli + dampli - dampli2, tangle + dangle));
794 glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle));
795 glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle - dangle2), polar_to_y(centery, diam, tampli + dampli, tangle + dangle - dangle2));
797 glBegin(GL_LINE_STRIP);
798 glVertex2f(polar_to_x(centerx, diam, tampli - dampli + dampli2, tangle + dangle), polar_to_y(centery, diam, tampli - dampli + dampli2, tangle + dangle));
799 glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle + dangle), polar_to_y(centery, diam, tampli - dampli, tangle + dangle));
800 glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle + dangle - dangle2), polar_to_y(centery, diam, tampli - dampli, tangle + dangle - dangle2));
802 glBegin(GL_LINE_STRIP);
803 glVertex2f(polar_to_x(centerx, diam, tampli - dampli + dampli2, tangle - dangle), polar_to_y(centery, diam, tampli - dampli + dampli2, tangle - dangle));
804 glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle - dangle), polar_to_y(centery, diam, tampli - dampli, tangle - dangle));
805 glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle - dangle + dangle2), polar_to_y(centery, diam, tampli - dampli, tangle - dangle + dangle2));
807 glBegin(GL_LINE_STRIP);
808 glVertex2f(polar_to_x(centerx, diam, tampli + dampli - dampli2, tangle - dangle), polar_to_y(centery, diam, tampli + dampli - dampli2, tangle - dangle));
809 glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle - dangle), polar_to_y(centery, diam, tampli + dampli, tangle - dangle));
810 glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle - dangle + dangle2), polar_to_y(centery, diam, tampli + dampli, tangle - dangle + dangle2));
814 void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
816 const float skin_rad = DEG2RADF(123.0f); /* angle in radians of the skin tone line */
817 Scopes *scopes = (Scopes *)but->poin;
820 float w, h, centerx, centery, diam;
822 const float colors[6][3] = {
823 {0.75, 0.0, 0.0}, {0.75, 0.75, 0.0}, {0.0, 0.75, 0.0},
824 {0.0, 0.75, 0.75}, {0.0, 0.0, 0.75}, {0.75, 0.0, 0.75}};
827 rect.xmin = (float)recti->xmin + 1;
828 rect.xmax = (float)recti->xmax - 1;
829 rect.ymin = (float)recti->ymin + 1;
830 rect.ymax = (float)recti->ymax - 1;
832 w = BLI_rctf_size_x(&rect);
833 h = BLI_rctf_size_y(&rect);
834 centerx = rect.xmin + w / 2;
835 centery = rect.ymin + h / 2;
836 diam = (w < h) ? w : h;
838 alpha = scopes->vecscope_alpha * scopes->vecscope_alpha * scopes->vecscope_alpha;
841 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
843 glColor4f(0.f, 0.f, 0.f, 0.3f);
844 uiSetRoundBox(UI_CNR_ALL);
845 uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f);
847 /* need scissor test, hvectorscope can draw outside of boundary */
848 glGetIntegerv(GL_VIEWPORT, scissor);
849 glScissor(ar->winrct.xmin + (rect.xmin - 1),
850 ar->winrct.ymin + (rect.ymin - 1),
851 (rect.xmax + 1) - (rect.xmin - 1),
852 (rect.ymax + 1) - (rect.ymin - 1));
854 glColor4f(1.f, 1.f, 1.f, 0.08f);
855 /* draw grid elements */
857 fdrawline(centerx - (diam / 2) - 5, centery, centerx + (diam / 2) + 5, centery);
858 fdrawline(centerx, centery - (diam / 2) - 5, centerx, centery + (diam / 2) + 5);
860 for (j = 0; j < 5; j++) {
861 glBegin(GL_LINE_STRIP);
862 for (i = 0; i <= 360; i = i + 15) {
863 const float a = DEG2RADF((float)i);
864 const float r = (j + 1) / 10.0f;
865 glVertex2f(polar_to_x(centerx, diam, r, a), polar_to_y(centery, diam, r, a));
870 glColor4f(1.f, 0.4f, 0.f, 0.2f);
871 fdrawline(polar_to_x(centerx, diam, 0.5f, skin_rad), polar_to_y(centery, diam, 0.5, skin_rad),
872 polar_to_x(centerx, diam, 0.1f, skin_rad), polar_to_y(centery, diam, 0.1, skin_rad));
873 /* saturation points */
874 for (i = 0; i < 6; i++)
875 vectorscope_draw_target(centerx, centery, diam, colors[i]);
877 if (scopes->ok && scopes->vecscope != NULL) {
878 /* pixel point cloud */
879 glBlendFunc(GL_ONE, GL_ONE);
880 glColor3f(alpha, alpha, alpha);
883 glEnableClientState(GL_VERTEX_ARRAY);
885 glTranslatef(centerx, centery, 0.f);
886 glScalef(diam, diam, 0.f);
888 glVertexPointer(2, GL_FLOAT, 0, scopes->vecscope);
889 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
891 glDisableClientState(GL_VERTEX_ARRAY);
896 draw_scope_end(&rect, scissor);
901 static void ui_draw_colorband_handle_tri_hlight(float x1, float y1, float halfwidth, float height)
905 glEnable(GL_LINE_SMOOTH);
907 glBegin(GL_LINE_STRIP);
908 copy_v2_fl2(v, x1 + halfwidth, y1);
910 copy_v2_fl2(v, x1, y1 + height);
912 copy_v2_fl2(v, x1 - halfwidth, y1);
916 glDisable(GL_LINE_SMOOTH);
919 static void ui_draw_colorband_handle_tri(float x1, float y1, float halfwidth, float height, bool fill)
924 glPolygonMode(GL_FRONT, GL_FILL);
925 glEnable(GL_POLYGON_SMOOTH);
928 glPolygonMode(GL_FRONT, GL_LINE);
929 glEnable(GL_LINE_SMOOTH);
932 glBegin(GL_TRIANGLES);
933 copy_v2_fl2(v, x1 + halfwidth, y1);
935 copy_v2_fl2(v, x1, y1 + height);
937 copy_v2_fl2(v, x1 - halfwidth, y1);
942 glDisable(GL_POLYGON_SMOOTH);
945 glDisable(GL_LINE_SMOOTH);
946 glPolygonMode(GL_FRONT, GL_FILL);
950 static void ui_draw_colorband_handle_box(float x1, float y1, float x2, float y2, bool fill)
955 glPolygonMode(GL_FRONT, GL_FILL);
958 glPolygonMode(GL_FRONT, GL_LINE);
962 copy_v2_fl2(v, x1, y1);
964 copy_v2_fl2(v, x1, y2);
966 copy_v2_fl2(v, x2, y2);
968 copy_v2_fl2(v, x2, y1);
973 glPolygonMode(GL_FRONT, GL_FILL);
977 static void ui_draw_colorband_handle(
978 const rcti *rect, float x,
979 const float rgb[3], struct ColorManagedDisplay *display,
982 const float sizey = BLI_rcti_size_y(rect);
983 const float min_width = 3.0f;
984 float half_width, height, y1, y2;
985 float colf[3] = {UNPACK3(rgb)};
987 half_width = floorf(sizey / 3.5f);
988 height = half_width * 1.4f;
990 y1 = rect->ymin + (sizey * 0.16f);
993 /* align to pixels */
994 x = floorf(x + 0.5f);
995 y1 = floorf(y1 + 0.5f);
997 if (active || half_width < min_width) {
1003 setlinestyle(active ? 2 : 1);
1005 glColor3ub(200, 200, 200);
1011 /* hide handles when zoomed out too far */
1012 if (half_width < min_width) {
1017 /* shift handle down */
1018 y1 = y1 - half_width;
1020 glColor3ub(0, 0, 0);
1021 ui_draw_colorband_handle_box(x - half_width, y1 - 1, x + half_width, y1 + height, false);
1023 /* draw all triangles blended */
1026 ui_draw_colorband_handle_tri(x, y1 + height, half_width, half_width, true);
1029 glColor3ub(196, 196, 196);
1031 glColor3ub(96, 96, 96);
1032 ui_draw_colorband_handle_tri(x, y1 + height, half_width, half_width, true);
1035 glColor3ub(255, 255, 255);
1037 glColor3ub(128, 128, 128);
1038 ui_draw_colorband_handle_tri_hlight(x, y1 + height - 1, (half_width - 1), (half_width - 1));
1040 glColor3ub(0, 0, 0);
1041 ui_draw_colorband_handle_tri_hlight(x, y1 + height, half_width, half_width);
1043 glDisable(GL_BLEND);
1045 glColor3ub(128, 128, 128);
1046 ui_draw_colorband_handle_box(x - (half_width - 1), y1, x + (half_width - 1), y1 + height, true);
1049 IMB_colormanagement_scene_linear_to_display_v3(colf, display);
1053 ui_draw_colorband_handle_box(x - (half_width - 2), y1 + 1, x + (half_width - 2), y1 + height - 2, true);
1056 void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *rect)
1060 float x1, y1, sizex, sizey, sizey_solid;
1063 float pos, colf[4] = {0, 0, 0, 0}; /* initialize in case the colorband isn't valid */
1064 struct ColorManagedDisplay *display = NULL;
1066 coba = (ColorBand *)(but->editcoba ? but->editcoba : but->poin);
1067 if (coba == NULL) return;
1069 if (but->block->color_profile)
1070 display = ui_block_display_get(but->block);
1073 sizex = rect->xmax - x1;
1074 sizey = BLI_rcti_size_y(rect);
1075 sizey_solid = sizey / 4;
1078 /* layer: background, to show tranparency */
1079 glColor4ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, 255);
1080 glRectf(x1, y1, x1 + sizex, rect->ymax);
1081 glEnable(GL_POLYGON_STIPPLE);
1082 glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
1083 glPolygonStipple(stipple_checker_8px);
1084 glRectf(x1, y1, x1 + sizex, rect->ymax);
1085 glDisable(GL_POLYGON_STIPPLE);
1087 /* layer: color ramp */
1088 glShadeModel(GL_FLAT);
1093 v1[1] = y1 + sizey_solid;
1096 glBegin(GL_QUAD_STRIP);
1097 for (a = 0; a <= sizex; a++) {
1098 pos = ((float)a) / sizex;
1099 do_colorband(coba, pos, colf);
1101 IMB_colormanagement_scene_linear_to_display_v3(colf, display);
1103 v1[0] = v2[0] = x1 + a;
1111 /* layer: color ramp without alpha for reference when manipulating ramp properties */
1113 v2[1] = y1 + sizey_solid;
1115 glBegin(GL_QUAD_STRIP);
1116 for (a = 0; a <= sizex; a++) {
1117 pos = ((float)a) / sizex;
1118 do_colorband(coba, pos, colf);
1120 IMB_colormanagement_scene_linear_to_display_v3(colf, display);
1122 v1[0] = v2[0] = x1 + a;
1124 glColor4f(colf[0], colf[1], colf[2], 1.0f);
1130 glDisable(GL_BLEND);
1131 glShadeModel(GL_SMOOTH);
1133 /* layer: box outline */
1134 glColor4f(0.0, 0.0, 0.0, 1.0);
1135 fdrawbox(x1, y1, x1 + sizex, rect->ymax);
1137 /* layer: box outline */
1139 glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
1140 fdrawline(x1, y1, x1 + sizex, y1);
1141 glColor4f(1.0f, 1.0f, 1.0f, 0.25f);
1142 fdrawline(x1, y1 - 1, x1 + sizex, y1 - 1);
1143 glDisable(GL_BLEND);
1145 /* layer: draw handles */
1146 for (a = 0; a < coba->tot; a++, cbd++) {
1147 if (a != coba->cur) {
1148 pos = x1 + cbd->pos * (sizex - 1) + 1;
1149 ui_draw_colorband_handle(rect, pos, &cbd->r, display, false);
1153 /* layer: active handle */
1154 if (coba->tot != 0) {
1155 cbd = &coba->data[coba->cur];
1156 pos = x1 + cbd->pos * (sizex - 1) + 1;
1157 ui_draw_colorband_handle(rect, pos, &cbd->r, display, true);
1161 void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
1163 static GLuint displist = 0;
1165 GLfloat diff[4], diffn[4] = {1.0f, 1.0f, 1.0f, 1.0f};
1166 float vec0[4] = {0.0f, 0.0f, 0.0f, 0.0f};
1170 glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
1173 glColor3ubv((unsigned char *)wcol->inner);
1174 uiSetRoundBox(UI_CNR_ALL);
1175 uiDrawBox(GL_POLYGON, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f);
1178 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffn);
1179 glCullFace(GL_BACK);
1180 glEnable(GL_CULL_FACE);
1182 /* disable blender light */
1183 for (a = 0; a < 8; a++) {
1184 old[a] = glIsEnabled(GL_LIGHT0 + a);
1185 glDisable(GL_LIGHT0 + a);
1189 glEnable(GL_LIGHT7);
1190 glEnable(GL_LIGHTING);
1192 ui_get_but_vectorf(but, dir);
1194 dir[3] = 0.0f; /* glLightfv needs 4 args, 0.0 is sun */
1195 glLightfv(GL_LIGHT7, GL_POSITION, dir);
1196 glLightfv(GL_LIGHT7, GL_DIFFUSE, diffn);
1197 glLightfv(GL_LIGHT7, GL_SPECULAR, vec0);
1198 glLightf(GL_LIGHT7, GL_CONSTANT_ATTENUATION, 1.0f);
1199 glLightf(GL_LIGHT7, GL_LINEAR_ATTENUATION, 0.0f);
1201 /* transform to button */
1203 glTranslatef(rect->xmin + 0.5f * BLI_rcti_size_x(rect), rect->ymin + 0.5f * BLI_rcti_size_y(rect), 0.0f);
1205 if (BLI_rcti_size_x(rect) < BLI_rcti_size_y(rect))
1206 size = BLI_rcti_size_x(rect) / 200.f;
1208 size = BLI_rcti_size_y(rect) / 200.f;
1210 glScalef(size, size, size);
1212 if (displist == 0) {
1213 GLUquadricObj *qobj;
1215 displist = glGenLists(1);
1216 glNewList(displist, GL_COMPILE);
1218 qobj = gluNewQuadric();
1219 gluQuadricDrawStyle(qobj, GLU_FILL);
1220 glShadeModel(GL_SMOOTH);
1221 gluSphere(qobj, 100.0, 32, 24);
1222 glShadeModel(GL_FLAT);
1223 gluDeleteQuadric(qobj);
1228 glCallList(displist);
1231 glDisable(GL_LIGHTING);
1232 glDisable(GL_CULL_FACE);
1233 glMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
1234 glDisable(GL_LIGHT7);
1238 glEnable(GL_LINE_SMOOTH);
1239 glColor3ubv((unsigned char *)wcol->inner);
1240 glutil_draw_lined_arc(0.0f, M_PI * 2.0, 100.0f, 32);
1241 glDisable(GL_BLEND);
1242 glDisable(GL_LINE_SMOOTH);
1244 /* matrix after circle */
1247 /* enable blender light */
1248 for (a = 0; a < 8; a++) {
1250 glEnable(GL_LIGHT0 + a);
1254 static void ui_draw_but_curve_grid(const rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step)
1256 float dx, dy, fx, fy;
1260 fx = rect->xmin + zoomx * (-offsx);
1261 if (fx > rect->xmin) fx -= dx * (floorf(fx - rect->xmin));
1262 while (fx < rect->xmax) {
1263 glVertex2f(fx, rect->ymin);
1264 glVertex2f(fx, rect->ymax);
1269 fy = rect->ymin + zoomy * (-offsy);
1270 if (fy > rect->ymin) fy -= dy * (floorf(fy - rect->ymin));
1271 while (fy < rect->ymax) {
1272 glVertex2f(rect->xmin, fy);
1273 glVertex2f(rect->xmax, fy);
1280 static void gl_shaded_color(unsigned char *col, int shade)
1282 glColor3ub(col[0] - shade > 0 ? col[0] - shade : 0,
1283 col[1] - shade > 0 ? col[1] - shade : 0,
1284 col[2] - shade > 0 ? col[2] - shade : 0);
1287 void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, const rcti *rect)
1289 CurveMapping *cumap;
1292 float fx, fy, fac[2], zoomx, zoomy, offsx, offsy;
1297 if (but->editcumap) {
1298 cumap = but->editcumap;
1301 cumap = (CurveMapping *)but->poin;
1304 cuma = &cumap->cm[cumap->cur];
1306 /* need scissor test, curve can draw outside of boundary */
1307 glGetIntegerv(GL_VIEWPORT, scissor);
1308 scissor_new.xmin = ar->winrct.xmin + rect->xmin;
1309 scissor_new.ymin = ar->winrct.ymin + rect->ymin;
1310 scissor_new.xmax = ar->winrct.xmin + rect->xmax;
1311 scissor_new.ymax = ar->winrct.ymin + rect->ymax;
1312 BLI_rcti_isect(&scissor_new, &ar->winrct, &scissor_new);
1313 glScissor(scissor_new.xmin,
1315 BLI_rcti_size_x(&scissor_new),
1316 BLI_rcti_size_y(&scissor_new));
1318 /* calculate offset and zoom */
1319 zoomx = (BLI_rcti_size_x(rect) - 2.0f) / BLI_rctf_size_x(&cumap->curr);
1320 zoomy = (BLI_rcti_size_y(rect) - 2.0f) / BLI_rctf_size_y(&cumap->curr);
1321 offsx = cumap->curr.xmin - (1.0f / zoomx);
1322 offsy = cumap->curr.ymin - (1.0f / zoomy);
1325 if (but->a1 == UI_GRAD_H) {
1326 /* magic trigger for curve backgrounds */
1328 float col[3] = {0.0f, 0.0f, 0.0f}; /* dummy arg */
1330 grid.xmin = rect->xmin + zoomx * (-offsx);
1331 grid.xmax = grid.xmin + zoomx;
1332 grid.ymin = rect->ymin + zoomy * (-offsy);
1333 grid.ymax = grid.ymin + zoomy;
1335 ui_draw_gradient(&grid, col, UI_GRAD_H, 1.0f);
1337 /* grid, hsv uses different grid */
1339 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1340 glColor4ub(0, 0, 0, 48);
1341 ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.1666666f);
1342 glDisable(GL_BLEND);
1345 if (cumap->flag & CUMA_DO_CLIP) {
1346 gl_shaded_color((unsigned char *)wcol->inner, -20);
1347 glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1348 glColor3ubv((unsigned char *)wcol->inner);
1349 glRectf(rect->xmin + zoomx * (cumap->clipr.xmin - offsx),
1350 rect->ymin + zoomy * (cumap->clipr.ymin - offsy),
1351 rect->xmin + zoomx * (cumap->clipr.xmax - offsx),
1352 rect->ymin + zoomy * (cumap->clipr.ymax - offsy));
1355 glColor3ubv((unsigned char *)wcol->inner);
1356 glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1359 /* grid, every 0.25 step */
1360 gl_shaded_color((unsigned char *)wcol->inner, -16);
1361 ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.25f);
1362 /* grid, every 1.0 step */
1363 gl_shaded_color((unsigned char *)wcol->inner, -24);
1364 ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 1.0f);
1366 gl_shaded_color((unsigned char *)wcol->inner, -50);
1368 glVertex2f(rect->xmin, rect->ymin + zoomy * (-offsy));
1369 glVertex2f(rect->xmax, rect->ymin + zoomy * (-offsy));
1370 glVertex2f(rect->xmin + zoomx * (-offsx), rect->ymin);
1371 glVertex2f(rect->xmin + zoomx * (-offsx), rect->ymax);
1378 if (cumap->flag & CUMA_DRAW_CFRA) {
1379 glColor3ub(0x60, 0xc0, 0x40);
1381 glVertex2f(rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymin);
1382 glVertex2f(rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymax);
1388 if (cumap->flag & CUMA_DRAW_SAMPLE) {
1389 if (but->a1 == UI_GRAD_H) {
1392 linearrgb_to_srgb_v3_v3(tsample, cumap->sample);
1393 rgb_to_hsv_v(tsample, hsv);
1394 glColor3ub(240, 240, 240);
1397 glVertex2f(rect->xmin + zoomx * (hsv[0] - offsx), rect->ymin);
1398 glVertex2f(rect->xmin + zoomx * (hsv[0] - offsx), rect->ymax);
1401 else if (cumap->cur == 3) {
1402 float lum = rgb_to_bw(cumap->sample);
1403 glColor3ub(240, 240, 240);
1406 glVertex2f(rect->xmin + zoomx * (lum - offsx), rect->ymin);
1407 glVertex2f(rect->xmin + zoomx * (lum - offsx), rect->ymax);
1411 if (cumap->cur == 0)
1412 glColor3ub(240, 100, 100);
1413 else if (cumap->cur == 1)
1414 glColor3ub(100, 240, 100);
1416 glColor3ub(100, 100, 240);
1419 glVertex2f(rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymin);
1420 glVertex2f(rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymax);
1426 glColor3ubv((unsigned char *)wcol->item);
1427 glEnable(GL_LINE_SMOOTH);
1429 glBegin(GL_LINE_STRIP);
1431 if (cuma->table == NULL)
1432 curvemapping_changed(cumap, false);
1436 if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) {
1437 glVertex2f(rect->xmin, rect->ymin + zoomy * (cmp[0].y - offsy));
1440 fx = rect->xmin + zoomx * (cmp[0].x - offsx + cuma->ext_in[0]);
1441 fy = rect->ymin + zoomy * (cmp[0].y - offsy + cuma->ext_in[1]);
1444 for (a = 0; a <= CM_TABLE; a++) {
1445 fx = rect->xmin + zoomx * (cmp[a].x - offsx);
1446 fy = rect->ymin + zoomy * (cmp[a].y - offsy);
1450 if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) {
1451 glVertex2f(rect->xmax, rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy));
1454 fx = rect->xmin + zoomx * (cmp[CM_TABLE].x - offsx - cuma->ext_out[0]);
1455 fy = rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy - cuma->ext_out[1]);
1459 glDisable(GL_LINE_SMOOTH);
1460 glDisable(GL_BLEND);
1462 /* the points, use aspect to make them visible on edges */
1465 bglBegin(GL_POINTS);
1466 for (a = 0; a < cuma->totpoint; a++) {
1467 if (cmp[a].flag & CUMA_SELECT)
1468 UI_ThemeColor(TH_TEXT_HI);
1470 UI_ThemeColor(TH_TEXT);
1471 fac[0] = rect->xmin + zoomx * (cmp[a].x - offsx);
1472 fac[1] = rect->ymin + zoomy * (cmp[a].y - offsy);
1478 /* restore scissortest */
1479 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
1482 glColor3ubv((unsigned char *)wcol->outline);
1483 fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1486 void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
1492 MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
1494 rect.xmin = (float)recti->xmin + 1;
1495 rect.xmax = (float)recti->xmax - 1;
1496 rect.ymin = (float)recti->ymin + 1;
1497 rect.ymax = (float)recti->ymax - 1;
1499 width = BLI_rctf_size_x(&rect) + 1;
1500 height = BLI_rctf_size_y(&rect);
1503 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1505 /* need scissor test, preview image can draw outside of boundary */
1506 glGetIntegerv(GL_VIEWPORT, scissor);
1507 glScissor(ar->winrct.xmin + (rect.xmin - 1),
1508 ar->winrct.ymin + (rect.ymin - 1),
1509 (rect.xmax + 1) - (rect.xmin - 1),
1510 (rect.ymax + 1) - (rect.ymin - 1));
1512 if (scopes->track_disabled) {
1513 glColor4f(0.7f, 0.3f, 0.3f, 0.3f);
1514 uiSetRoundBox(UI_CNR_ALL);
1515 uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f);
1519 else if ((scopes->track_search) &&
1520 ((!scopes->track_preview) ||
1521 (scopes->track_preview->x != width || scopes->track_preview->y != height)))
1525 if (scopes->track_preview)
1526 IMB_freeImBuf(scopes->track_preview);
1528 tmpibuf = BKE_tracking_sample_pattern(scopes->frame_width, scopes->frame_height,
1529 scopes->track_search, scopes->track,
1530 &scopes->undist_marker, true, scopes->use_track_mask,
1531 width, height, scopes->track_pos);
1534 if (tmpibuf->rect_float)
1535 IMB_rect_from_float(tmpibuf);
1538 scopes->track_preview = tmpibuf;
1540 IMB_freeImBuf(tmpibuf);
1544 if (!ok && scopes->track_preview) {
1551 track_pos[0] = scopes->track_pos[0];
1552 track_pos[1] = scopes->track_pos[1];
1554 /* draw content of pattern area */
1555 glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin + rect.ymin, scissor[2], scissor[3]);
1557 if (width > 0 && height > 0) {
1558 drawibuf = scopes->track_preview;
1560 if (scopes->use_track_mask) {
1561 glColor4f(0.0f, 0.0f, 0.0f, 0.3f);
1562 uiSetRoundBox(UI_CNR_ALL);
1563 uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f);
1566 glaDrawPixelsSafe(rect.xmin, rect.ymin + 1, drawibuf->x, drawibuf->y,
1567 drawibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, drawibuf->rect);
1569 /* draw cross for pizel position */
1570 glTranslatef(rect.xmin + track_pos[0], rect.ymin + track_pos[1], 0.f);
1571 glScissor(ar->winrct.xmin + rect.xmin,
1572 ar->winrct.ymin + rect.ymin,
1573 BLI_rctf_size_x(&rect),
1574 BLI_rctf_size_y(&rect));
1576 for (a = 0; a < 2; a++) {
1578 glLineStipple(3, 0xaaaa);
1579 glEnable(GL_LINE_STIPPLE);
1580 UI_ThemeColor(TH_SEL_MARKER);
1583 UI_ThemeColor(TH_MARKER_OUTLINE);
1587 glVertex2f(-10.0f, 0.0f);
1588 glVertex2f(10.0f, 0.0f);
1589 glVertex2f(0.0f, -10.0f);
1590 glVertex2f(0.0f, 10.0f);
1595 glDisable(GL_LINE_STIPPLE);
1602 glColor4f(0.f, 0.f, 0.f, 0.3f);
1603 uiSetRoundBox(UI_CNR_ALL);
1604 uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f);
1608 draw_scope_end(&rect, scissor);
1610 glDisable(GL_BLEND);
1613 void ui_draw_but_NODESOCKET(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
1615 static const float size = 5.0f;
1617 /* 16 values of sin function */
1618 const float si[16] = {
1619 0.00000000f, 0.39435585f, 0.72479278f, 0.93775213f,
1620 0.99871650f, 0.89780453f, 0.65137248f, 0.29936312f,
1621 -0.10116832f, -0.48530196f, -0.79077573f, -0.96807711f,
1622 -0.98846832f, -0.84864425f, -0.57126821f, -0.20129852f
1624 /* 16 values of cos function */
1625 const float co[16] = {
1626 1.00000000f, 0.91895781f, 0.68896691f, 0.34730525f,
1627 -0.05064916f, -0.44039415f, -0.75875812f, -0.95413925f,
1628 -0.99486932f, -0.87434661f, -0.61210598f, -0.25065253f,
1629 0.15142777f, 0.52896401f, 0.82076344f, 0.97952994f,
1632 unsigned char *col = but->col;
1638 x = 0.5f * (recti->xmin + recti->xmax);
1639 y = 0.5f * (recti->ymin + recti->ymax);
1641 /* need scissor test, can draw outside of boundary */
1642 glGetIntegerv(GL_VIEWPORT, scissor);
1643 scissor_new.xmin = ar->winrct.xmin + recti->xmin;
1644 scissor_new.ymin = ar->winrct.ymin + recti->ymin;
1645 scissor_new.xmax = ar->winrct.xmin + recti->xmax;
1646 scissor_new.ymax = ar->winrct.ymin + recti->ymax;
1647 BLI_rcti_isect(&scissor_new, &ar->winrct, &scissor_new);
1648 glScissor(scissor_new.xmin,
1650 BLI_rcti_size_x(&scissor_new),
1651 BLI_rcti_size_y(&scissor_new));
1656 glBegin(GL_POLYGON);
1657 for (a = 0; a < 16; a++)
1658 glVertex2f(x + size * si[a], y + size * co[a]);
1660 glDisable(GL_BLEND);
1662 glColor4ub(0, 0, 0, 150);
1665 glEnable(GL_LINE_SMOOTH);
1666 glBegin(GL_LINE_LOOP);
1667 for (a = 0; a < 16; a++)
1668 glVertex2f(x + size * si[a], y + size * co[a]);
1670 glDisable(GL_LINE_SMOOTH);
1671 glDisable(GL_BLEND);
1674 /* restore scissortest */
1675 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
1678 /* ****************************************************** */
1681 static void ui_shadowbox(float minx, float miny, float maxx, float maxy, float shadsize, unsigned char alpha)
1684 glShadeModel(GL_SMOOTH);
1687 glBegin(GL_POLYGON);
1688 glColor4ub(0, 0, 0, alpha);
1689 glVertex2f(maxx, miny);
1690 glVertex2f(maxx, maxy - 0.3f * shadsize);
1691 glColor4ub(0, 0, 0, 0);
1692 glVertex2f(maxx + shadsize, maxy - 0.75f * shadsize);
1693 glVertex2f(maxx + shadsize, miny);
1697 glBegin(GL_POLYGON);
1698 glColor4ub(0, 0, 0, alpha);
1699 glVertex2f(maxx, miny);
1700 glColor4ub(0, 0, 0, 0);
1701 glVertex2f(maxx + shadsize, miny);
1702 glVertex2f(maxx + 0.7f * shadsize, miny - 0.7f * shadsize);
1703 glVertex2f(maxx, miny - shadsize);
1707 glBegin(GL_POLYGON);
1708 glColor4ub(0, 0, 0, alpha);
1709 glVertex2f(minx + 0.3f * shadsize, miny);
1710 glVertex2f(maxx, miny);
1711 glColor4ub(0, 0, 0, 0);
1712 glVertex2f(maxx, miny - shadsize);
1713 glVertex2f(minx + 0.5f * shadsize, miny - shadsize);
1716 glDisable(GL_BLEND);
1717 glShadeModel(GL_FLAT);
1720 void uiDrawBoxShadow(unsigned char alpha, float minx, float miny, float maxx, float maxy)
1722 /* accumulated outline boxes to make shade not linear, is more pleasant */
1723 ui_shadowbox(minx, miny, maxx, maxy, 11.0, (20 * alpha) >> 8);
1724 ui_shadowbox(minx, miny, maxx, maxy, 7.0, (40 * alpha) >> 8);
1725 ui_shadowbox(minx, miny, maxx, maxy, 5.0, (80 * alpha) >> 8);
1730 void ui_dropshadow(const rctf *rct, float radius, float aspect, float alpha, int UNUSED(select))
1735 float dalpha = alpha * 2.0f / 255.0f, calpha;
1739 if (radius > (BLI_rctf_size_y(rct) - 10.0f) / 2.0f)
1740 rad = (BLI_rctf_size_y(rct) - 10.0f) / 2.0f;
1747 a = i * aspect; /* same as below */
1756 for (; i--; a -= aspect) {
1757 /* alpha ranges from 2 to 20 or so */
1758 glColor4f(0.0f, 0.0f, 0.0f, calpha);
1761 uiDrawBox(GL_POLYGON, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax - 10.0f + a, rad + a);
1764 /* outline emphasis */
1765 glEnable(GL_LINE_SMOOTH);
1766 glColor4ub(0, 0, 0, 100);
1767 uiDrawBox(GL_LINE_LOOP, rct->xmin - 0.5f, rct->ymin - 0.5f, rct->xmax + 0.5f, rct->ymax + 0.5f, radius + 0.5f);
1768 glDisable(GL_LINE_SMOOTH);
1770 glDisable(GL_BLEND);