4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * Contributor(s): Blender Foundation
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file blender/editors/interface/interface_draw.c
29 * \ingroup edinterface
36 #include "DNA_color_types.h"
37 #include "DNA_object_types.h"
38 #include "DNA_screen_types.h"
42 #include "BLI_utildefines.h"
44 #include "BKE_colortools.h"
45 #include "BKE_texture.h"
48 #include "IMB_imbuf.h"
49 #include "IMB_imbuf_types.h"
52 #include "BIF_glutil.h"
56 #include "UI_interface.h"
59 #include "interface_intern.h"
61 #define UI_RB_ALPHA 16
62 #define UI_DISABLED_ALPHA_OFFS -160
64 static int roundboxtype= 15;
66 void uiSetRoundBox(int type)
68 /* Not sure the roundbox function is the best place to change this
69 * if this is undone, its not that big a deal, only makes curves edges
73 /* flags to set which corners will become rounded:
82 int uiGetRoundBox(void)
87 void uiDrawBox(int mode, float minx, float miny, float maxx, float maxy, float rad)
89 float vec[7][2]= {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
90 {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
95 vec[a][0]*= rad; vec[a][1]*= rad;
100 /* start with corner right-bottom */
101 if(roundboxtype & 4) {
102 glVertex2f(maxx-rad, miny);
104 glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]);
106 glVertex2f(maxx, miny+rad);
108 else glVertex2f(maxx, miny);
110 /* corner right-top */
111 if(roundboxtype & 2) {
112 glVertex2f(maxx, maxy-rad);
114 glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]);
116 glVertex2f(maxx-rad, maxy);
118 else glVertex2f(maxx, maxy);
120 /* corner left-top */
121 if(roundboxtype & 1) {
122 glVertex2f(minx+rad, maxy);
124 glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]);
126 glVertex2f(minx, maxy-rad);
128 else glVertex2f(minx, maxy);
130 /* corner left-bottom */
131 if(roundboxtype & 8) {
132 glVertex2f(minx, miny+rad);
134 glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]);
136 glVertex2f(minx+rad, miny);
138 else 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];
166 vec[a][0]*= rad; vec[a][1]*= 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]= color[0]+shadetop; if(coltop[0]>1.0f) coltop[0]= 1.0f;
173 coltop[1]= color[1]+shadetop; if(coltop[1]>1.0f) coltop[1]= 1.0f;
174 coltop[2]= color[2]+shadetop; if(coltop[2]>1.0f) coltop[2]= 1.0f;
175 coldown[0]= color[0]+shadedown; if(coldown[0]<0.0f) coldown[0]= 0.0f;
176 coldown[1]= color[1]+shadedown; if(coldown[1]<0.0f) coldown[1]= 0.0f;
177 coldown[2]= color[2]+shadedown; if(coldown[2]<0.0f) coldown[2]= 0.0f;
179 glShadeModel(GL_SMOOTH);
182 /* start with corner right-bottom */
183 if(roundboxtype & 4) {
185 round_box_shade_col(coltop, coldown, 0.0);
186 glVertex2f(maxx-rad, miny);
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 & 2) {
204 round_box_shade_col(coltop, coldown, (div-rad)*idiv);
205 glVertex2f(maxx, maxy-rad);
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 & 1) {
222 round_box_shade_col(coltop, coldown, 1.0);
223 glVertex2f(minx+rad, maxy);
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 & 8) {
241 round_box_shade_col(coltop, coldown, rad*idiv);
242 glVertex2f(minx, miny+rad);
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, float rad, float shadeLeft, float shadeRight)
265 float vec[7][2]= {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
266 {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
267 const float div= maxx - minx;
268 const float idiv= 1.0f / div;
269 float colLeft[3], colRight[3], color[4];
274 vec[a][0]*= rad; vec[a][1]*= rad;
276 /* get current color, needs to be outside of glBegin/End */
277 glGetFloatv(GL_CURRENT_COLOR, color);
279 /* 'shade' defines strength of shading */
280 colLeft[0]= color[0]+shadeLeft; if(colLeft[0]>1.0f) colLeft[0]= 1.0f;
281 colLeft[1]= color[1]+shadeLeft; if(colLeft[1]>1.0f) colLeft[1]= 1.0f;
282 colLeft[2]= color[2]+shadeLeft; if(colLeft[2]>1.0f) colLeft[2]= 1.0f;
283 colRight[0]= color[0]+shadeRight; if(colRight[0]<0.0f) colRight[0]= 0.0f;
284 colRight[1]= color[1]+shadeRight; if(colRight[1]<0.0f) colRight[1]= 0.0f;
285 colRight[2]= color[2]+shadeRight; if(colRight[2]<0.0f) colRight[2]= 0.0f;
287 glShadeModel(GL_SMOOTH);
290 /* start with corner right-bottom */
291 if(roundboxtype & 4) {
292 round_box_shade_col(colLeft, colRight, 0.0);
293 glVertex2f(maxx-rad, miny);
296 round_box_shade_col(colLeft, colRight, vec[a][0]*idiv);
297 glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]);
300 round_box_shade_col(colLeft, colRight, rad*idiv);
301 glVertex2f(maxx, miny+rad);
304 round_box_shade_col(colLeft, colRight, 0.0);
305 glVertex2f(maxx, miny);
308 /* corner right-top */
309 if(roundboxtype & 2) {
310 round_box_shade_col(colLeft, colRight, 0.0);
311 glVertex2f(maxx, maxy-rad);
315 round_box_shade_col(colLeft, colRight, (div-rad-vec[a][0])*idiv);
316 glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]);
318 round_box_shade_col(colLeft, colRight, (div-rad)*idiv);
319 glVertex2f(maxx-rad, maxy);
322 round_box_shade_col(colLeft, colRight, 0.0);
323 glVertex2f(maxx, maxy);
326 /* corner left-top */
327 if(roundboxtype & 1) {
328 round_box_shade_col(colLeft, colRight, (div-rad)*idiv);
329 glVertex2f(minx+rad, maxy);
332 round_box_shade_col(colLeft, colRight, (div-rad+vec[a][0])*idiv);
333 glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]);
336 round_box_shade_col(colLeft, colRight, 1.0);
337 glVertex2f(minx, maxy-rad);
340 round_box_shade_col(colLeft, colRight, 1.0);
341 glVertex2f(minx, maxy);
344 /* corner left-bottom */
345 if(roundboxtype & 8) {
346 round_box_shade_col(colLeft, colRight, 1.0);
347 glVertex2f(minx, miny+rad);
350 round_box_shade_col(colLeft, colRight, (vec[a][0])*idiv);
351 glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]);
354 round_box_shade_col(colLeft, colRight, 1.0);
355 glVertex2f(minx+rad, miny);
358 round_box_shade_col(colLeft, colRight, 1.0);
359 glVertex2f(minx, miny);
363 glShadeModel(GL_FLAT);
366 /* plain antialiased unfilled rectangle */
367 void uiRoundRect(float minx, float miny, float maxx, float maxy, float rad)
371 if(roundboxtype & UI_RB_ALPHA) {
372 glGetFloatv(GL_CURRENT_COLOR, color);
375 glEnable( GL_BLEND );
378 /* set antialias line */
379 glEnable( GL_LINE_SMOOTH );
380 glEnable( GL_BLEND );
382 uiDrawBox(GL_LINE_LOOP, minx, miny, maxx, maxy, rad);
384 glDisable( GL_BLEND );
385 glDisable( GL_LINE_SMOOTH );
388 /* plain fake antialiased unfilled round rectangle */
389 #if 0 /* UNUSED 2.5 */
390 static void uiRoundRectFakeAA(float minx, float miny, float maxx, float maxy, float rad, float asp)
392 float color[4], alpha;
396 /* get the color and divide up the alpha */
397 glGetFloatv(GL_CURRENT_COLOR, color);
398 alpha = 1; //color[3];
399 color[3]= 0.5*alpha/(float)passes;
402 /* set the 'jitter amount' */
403 raddiff = (1/(float)passes) * asp;
405 glEnable( GL_BLEND );
407 /* draw lots of lines on top of each other */
408 for (i=passes; i>=(-passes); i--) {
409 uiDrawBox(GL_LINE_LOOP, minx, miny, maxx, maxy, rad+(i*raddiff));
412 glDisable( GL_BLEND );
419 /* (old, used in outliner) plain antialiased filled box */
420 void uiRoundBox(float minx, float miny, float maxx, float maxy, float rad)
424 if(roundboxtype & UI_RB_ALPHA) {
425 glGetFloatv(GL_CURRENT_COLOR, color);
428 glEnable( GL_BLEND );
432 uiDrawBox(GL_POLYGON, minx, miny, maxx, maxy, rad);
434 /* set antialias line */
435 glEnable( GL_LINE_SMOOTH );
436 glEnable( GL_BLEND );
438 uiDrawBox(GL_LINE_LOOP, minx, miny, maxx, maxy, rad);
440 glDisable( GL_BLEND );
441 glDisable( GL_LINE_SMOOTH );
445 /* ************** generic embossed rect, for window sliders etc ************* */
448 /* text_draw.c uses this */
449 void uiEmboss(float x1, float y1, float x2, float y2, int sel)
453 if(sel) glColor3ub(200,200,200);
454 else glColor3ub(50,50,50);
455 fdrawline(x1, y1, x2, y1);
458 fdrawline(x2, y1, x2, y2);
461 if(sel) glColor3ub(50,50,50);
462 else glColor3ub(200,200,200);
463 fdrawline(x1, y2, x2, y2);
466 fdrawline(x1, y1, x1, y2);
470 /* ************** SPECIAL BUTTON DRAWING FUNCTIONS ************* */
472 void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *UNUSED(but), uiWidgetColors *UNUSED(wcol), rcti *rect)
477 extern char datatoc_splash_png[];
478 extern int datatoc_splash_png_size;
483 /* hardcoded to splash, loading and freeing every draw, eek! */
484 ibuf= IMB_ibImageFromMemory((unsigned char*)datatoc_splash_png, datatoc_splash_png_size, IB_rect);
488 /* scissor doesn't seem to be doing the right thing...?
489 //glColor4f(1.0, 0.f, 0.f, 1.f);
490 //fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax)
492 w = (rect->xmax - rect->xmin);
493 h = (rect->ymax - rect->ymin);
494 // prevent drawing outside widget area
495 glGetIntegerv(GL_SCISSOR_BOX, scissor);
496 glScissor(ar->winrct.xmin + rect->xmin, ar->winrct.ymin + rect->ymin, w, h);
500 glColor4f(0.0, 0.0, 0.0, 0.0);
502 glaDrawPixelsSafe((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
503 //glaDrawPixelsTex((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
508 // restore scissortest
509 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
518 static void ui_draw_but_CHARTAB(uiBut *but)
520 /* XXX 2.50 bad global access */
521 /* Some local variables */
522 float sx, sy, ex, ey;
527 unsigned char ustr[16];
530 int charmax = G.charmax;
532 /* FO_BUILTIN_NAME font in use. There are TTF FO_BUILTIN_NAME and non-TTF FO_BUILTIN_NAME fonts */
533 if(!strcmp(G.selfont->name, FO_BUILTIN_NAME)) {
534 if(G.ui_international == TRUE) {
542 /* Category list exited without selecting the area */
544 charmax = G.charmax = 0xffff;
546 /* Calculate the size of the button */
547 width = abs(rect->xmax - rect->xmin);
548 height = abs(rect->ymax - rect->ymin);
550 butw = floor(width / 12);
551 buth = floor(height / 6);
553 /* Initialize variables */
555 ex = rect->xmin + butw;
556 sy = rect->ymin + height - buth;
557 ey = rect->ymin + height;
561 /* Set the font, in case it is not FO_BUILTIN_NAME font */
562 if(G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) {
563 // Is the font file packed, if so then use the packed file
564 if(G.selfont->packedfile) {
565 pf = G.selfont->packedfile;
566 FTF_SetFont(pf->data, pf->size, 14.0);
572 BLI_strncpy(tmpStr, G.selfont->name, sizeof(tmpStr));
573 BLI_path_abs(tmpStr, G.main->name);
574 err = FTF_SetFont((unsigned char *)tmpStr, 0, 14.0);
578 if(G.ui_international == TRUE) {
579 FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 14.0);
583 /* Start drawing the button itself */
584 glShadeModel(GL_SMOOTH);
586 glColor3ub(200, 200, 200);
587 glRectf((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
590 for(y = 0; y < 6; y++) {
591 // Do not draw more than the category allows
592 if(cs > charmax) break;
594 for(x = 0; x < 12; x++)
596 // Do not draw more than the category allows
597 if(cs > charmax) break;
599 // Draw one grid cell
600 glBegin(GL_LINE_LOOP);
607 // Draw character inside the cell
608 memset(wstr, 0, sizeof(wchar_t)*2);
611 // Set the font to be either unicode or FO_BUILTIN_NAME
613 if(strcmp(G.selfont->name, FO_BUILTIN_NAME))
615 wcs2utf8s((char *)ustr, (wchar_t *)wstr);
619 if(G.ui_international == TRUE)
621 wcs2utf8s((char *)ustr, (wchar_t *)wstr);
630 if((G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) || (G.selfont && !strcmp(G.selfont->name, FO_BUILTIN_NAME) && G.ui_international == TRUE))
633 float llx, lly, llz, urx, ury, urz;
637 // Calculate the position
638 wid = FTF_GetStringWidth((char *) ustr, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
639 FTF_GetBoundingBox((char *) ustr, &llx,&lly,&llz,&urx,&ury,&urz, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
643 // This isn't fully functional since the but->aspect isn't working like I suspected
644 px = sx + ((butw/but->aspect)-dx)/2;
645 py = sy + ((buth/but->aspect)-dy)/2;
647 // Set the position and draw the character
648 ui_rasterpos_safe(px, py, but->aspect);
649 FTF_DrawString((char *) ustr, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
653 ui_rasterpos_safe(sx + butw/2, sy + buth/2, but->aspect);
654 UI_DrawString(but->font, (char *) ustr, 0);
657 // Calculate the next position and character
658 sx += butw; ex +=butw;
661 /* Add the y position and reset x position */
665 ex = rect->xmin + butw;
667 glShadeModel(GL_FLAT);
669 /* Return Font Settings to original */
670 if(U.fontsize && U.fontname[0]) {
671 result = FTF_SetFont((unsigned char *)U.fontname, 0, U.fontsize);
673 else if (U.fontsize) {
674 result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, U.fontsize);
678 result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 11);
681 /* resets the font size */
682 if(G.ui_international == TRUE) {
683 // uiSetCurFont(but->block, UI_HELV);
687 #endif // INTERNATIONAL
690 static void draw_scope_end(rctf *rect, GLint *scissor)
692 float scaler_x1, scaler_x2;
694 /* restore scissortest */
695 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
697 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
700 scaler_x1 = rect->xmin + (rect->xmax - rect->xmin)/2 - SCOPE_RESIZE_PAD;
701 scaler_x2 = rect->xmin + (rect->xmax - rect->xmin)/2 + SCOPE_RESIZE_PAD;
703 glColor4f(0.f, 0.f, 0.f, 0.25f);
704 fdrawline(scaler_x1, rect->ymin-4, scaler_x2, rect->ymin-4);
705 fdrawline(scaler_x1, rect->ymin-7, scaler_x2, rect->ymin-7);
706 glColor4f(1.f, 1.f, 1.f, 0.25f);
707 fdrawline(scaler_x1, rect->ymin-5, scaler_x2, rect->ymin-5);
708 fdrawline(scaler_x1, rect->ymin-8, scaler_x2, rect->ymin-8);
711 glColor4f(0.f, 0.f, 0.f, 0.5f);
713 uiDrawBox(GL_LINE_LOOP, rect->xmin-1, rect->ymin, rect->xmax+1, rect->ymax+1, 3.0f);
716 static void histogram_draw_one(float r, float g, float b, float alpha, float x, float y, float w, float h, float *data, int res)
720 /* under the curve */
721 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
722 glColor4f(r, g, b, alpha);
724 glShadeModel(GL_FLAT);
725 glBegin(GL_QUAD_STRIP);
727 glVertex2f(x, y + (data[0]*h));
728 for (i=1; i < res; i++) {
729 float x2 = x + i * (w/(float)res);
730 glVertex2f(x2, y + (data[i]*h));
736 glColor4f(0.f, 0.f, 0.f, 0.25f);
738 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
739 glEnable(GL_LINE_SMOOTH);
740 glBegin(GL_LINE_STRIP);
741 for (i=0; i < res; i++) {
742 float x2 = x + i * (w/(float)res);
743 glVertex2f(x2, y + (data[i]*h));
746 glDisable(GL_LINE_SMOOTH);
749 void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
751 Histogram *hist = (Histogram *)but->poin;
752 int res = hist->x_resolution;
759 rect.xmin = (float)recti->xmin+1;
760 rect.xmax = (float)recti->xmax-1;
761 rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
762 rect.ymax = (float)recti->ymax-1;
764 w = rect.xmax - rect.xmin;
765 h = (rect.ymax - rect.ymin) * hist->ymax;
768 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
770 glColor4f(0.f, 0.f, 0.f, 0.3f);
772 uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
774 glColor4f(1.f, 1.f, 1.f, 0.08f);
775 /* draw grid lines here */
776 for (i=1; i<4; i++) {
777 fdrawline(rect.xmin, rect.ymin+(i/4.f)*h, rect.xmax, rect.ymin+(i/4.f)*h);
778 fdrawline(rect.xmin+(i/4.f)*w, rect.ymin, rect.xmin+(i/4.f)*w, rect.ymax);
781 /* need scissor test, histogram can draw outside of boundary */
782 glGetIntegerv(GL_VIEWPORT, scissor);
783 glScissor(ar->winrct.xmin + (rect.xmin-1), ar->winrct.ymin+(rect.ymin-1), (rect.xmax+1)-(rect.xmin-1), (rect.ymax+1)-(rect.ymin-1));
785 if (hist->mode == HISTO_MODE_LUMA)
786 histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res);
788 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_R)
789 histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res);
790 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_G)
791 histogram_draw_one(0.0, 1.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_g, res);
792 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_B)
793 histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res);
796 /* outline, scale gripper */
797 draw_scope_end(&rect, scissor);
800 void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
802 Scopes *scopes = (Scopes *)but->poin;
805 float w, w3, h, alpha, yofs;
807 float colors[3][3]= MAT3_UNITY;
808 float colorsycc[3][3] = {{1,0,1},{1,1,0},{0,1,1}};
809 float colors_alpha[3][3], colorsycc_alpha[3][3]; /* colors pre multiplied by alpha for speed up */
812 if (scopes==NULL) return;
814 rect.xmin = (float)recti->xmin+1;
815 rect.xmax = (float)recti->xmax-1;
816 rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
817 rect.ymax = (float)recti->ymax-1;
819 if (scopes->wavefrm_yfac < 0.5f )
820 scopes->wavefrm_yfac =0.98f;
821 w = rect.xmax - rect.xmin-7;
822 h = (rect.ymax - rect.ymin)*scopes->wavefrm_yfac;
823 yofs= rect.ymin + (rect.ymax - rect.ymin -h)/2.0f;
826 /* log scale for alpha */
827 alpha = scopes->wavefrm_alpha*scopes->wavefrm_alpha;
831 colors_alpha[c][i] = colors[c][i] * alpha;
832 colorsycc_alpha[c][i] = colorsycc[c][i] * alpha;
837 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
839 glColor4f(0.f, 0.f, 0.f, 0.3f);
841 uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
844 /* need scissor test, waveform can draw outside of boundary */
845 glGetIntegerv(GL_VIEWPORT, scissor);
846 glScissor(ar->winrct.xmin + (rect.xmin-1), ar->winrct.ymin+(rect.ymin-1), (rect.xmax+1)-(rect.xmin-1), (rect.ymax+1)-(rect.ymin-1));
848 glColor4f(1.f, 1.f, 1.f, 0.08f);
849 /* draw grid lines here */
850 for (i=0; i<6; i++) {
852 sprintf(str,"%-3d",i*20);
854 fdrawline(rect.xmin+22, yofs+(i/5.f)*h, rect.xmax+1, yofs+(i/5.f)*h);
855 BLF_draw_default(rect.xmin+1, yofs-5+(i/5.f)*h, 0, str, sizeof(str)-1);
856 /* in the loop because blf_draw reset it */
858 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
860 /* 3 vertical separation */
861 if (scopes->wavefrm_mode!= SCOPES_WAVEFRM_LUMA) {
862 for (i=1; i<3; i++) {
863 fdrawline(rect.xmin+i*w3, rect.ymin, rect.xmin+i*w3, rect.ymax);
867 /* separate min max zone on the right */
868 fdrawline(rect.xmin+w, rect.ymin, rect.xmin+w, rect.ymax);
869 /* 16-235-240 level in case of ITU-R BT601/709 */
870 glColor4f(1.f, 0.4f, 0.f, 0.2f);
871 if (ELEM(scopes->wavefrm_mode, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_709)){
872 fdrawline(rect.xmin+22, yofs+h*16.0f/255.0f, rect.xmax+1, yofs+h*16.0f/255.0f);
873 fdrawline(rect.xmin+22, yofs+h*235.0f/255.0f, rect.xmin+w3, yofs+h*235.0f/255.0f);
874 fdrawline(rect.xmin+3*w3, yofs+h*235.0f/255.0f, rect.xmax+1, yofs+h*235.0f/255.0f);
875 fdrawline(rect.xmin+w3, yofs+h*240.0f/255.0f, rect.xmax+1, yofs+h*240.0f/255.0f);
877 /* 7.5 IRE black point level for NTSC */
878 if (scopes->wavefrm_mode== SCOPES_WAVEFRM_LUMA)
879 fdrawline(rect.xmin, yofs+h*0.075f, rect.xmax+1, yofs+h*0.075f);
881 if (scopes->ok && scopes->waveform_1 != NULL) {
883 /* LUMA (1 channel) */
884 glBlendFunc(GL_ONE,GL_ONE);
885 glColor3f(alpha, alpha, alpha);
886 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA){
888 glBlendFunc(GL_ONE,GL_ONE);
891 glEnableClientState(GL_VERTEX_ARRAY);
893 glTranslatef(rect.xmin, yofs, 0.f);
895 glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1);
896 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
898 glDisableClientState(GL_VERTEX_ARRAY);
902 glColor3f(.5f, .5f, .5f);
903 min= yofs+scopes->minmax[0][0]*h;
904 max= yofs+scopes->minmax[0][1]*h;
905 CLAMP(min, rect.ymin, rect.ymax);
906 CLAMP(max, rect.ymin, rect.ymax);
907 fdrawline(rect.xmax-3,min,rect.xmax-3,max);
910 /* RGB / YCC (3 channels) */
911 else if (ELEM4(scopes->wavefrm_mode, SCOPES_WAVEFRM_RGB, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_709, SCOPES_WAVEFRM_YCC_JPEG)) {
912 int rgb = (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB);
914 glBlendFunc(GL_ONE,GL_ONE);
917 glEnableClientState(GL_VERTEX_ARRAY);
919 glTranslatef(rect.xmin, yofs, 0.f);
920 glScalef(w3, h, 0.f);
922 glColor3fv((rgb)?colors_alpha[0]:colorsycc_alpha[0]);
923 glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1);
924 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
926 glTranslatef(1.f, 0.f, 0.f);
927 glColor3fv((rgb)?colors_alpha[1]:colorsycc_alpha[1]);
928 glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_2);
929 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
931 glTranslatef(1.f, 0.f, 0.f);
932 glColor3fv((rgb)?colors_alpha[2]:colorsycc_alpha[2]);
933 glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_3);
934 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
936 glDisableClientState(GL_VERTEX_ARRAY);
941 for (c=0; c<3; c++) {
942 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB)
943 glColor3f(colors[c][0]*0.75f, colors[c][1]*0.75f, colors[c][2]*0.75f);
945 glColor3f(colorsycc[c][0]*0.75f, colorsycc[c][1]*0.75f, colorsycc[c][2]*0.75f);
946 min= yofs+scopes->minmax[c][0]*h;
947 max= yofs+scopes->minmax[c][1]*h;
948 CLAMP(min, rect.ymin, rect.ymax);
949 CLAMP(max, rect.ymin, rect.ymax);
950 fdrawline(rect.xmin+w+2+c*2,min,rect.xmin+w+2+c*2,max);
956 /* outline, scale gripper */
957 draw_scope_end(&rect, scissor);
960 static float polar_to_x(float center, float diam, float ampli, float angle)
962 return center + diam * ampli * cosf(angle);
965 static float polar_to_y(float center, float diam, float ampli, float angle)
967 return center + diam * ampli * sinf(angle);
970 static void vectorscope_draw_target(float centerx, float centery, float diam, float r, float g, float b)
973 float tangle=0.f, tampli;
974 float dangle, dampli, dangle2, dampli2;
976 rgb_to_yuv(r,g,b, &y, &u, &v);
977 if (u>0 && v>=0) tangle=atanf(v/u);
978 else if (u>0 && v<0) tangle= atanf(v/u) + 2.0f * (float)M_PI;
979 else if (u<0) tangle=atanf(v/u) + (float)M_PI;
980 else if (u==0 && v > 0.0f) tangle= (float)M_PI/2.0f;
981 else if (u==0 && v < 0.0f) tangle=-(float)M_PI/2.0f;
982 tampli= sqrtf(u*u+v*v);
984 /* small target vary by 2.5 degree and 2.5 IRE unit */
985 glColor4f(1.0f, 1.0f, 1.0, 0.12f);
986 dangle= 2.5f*(float)M_PI/180.0f;
988 glBegin(GL_LINE_STRIP);
989 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle), polar_to_y(centery,diam,tampli+dampli,tangle+dangle));
990 glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle+dangle), polar_to_y(centery,diam,tampli-dampli,tangle+dangle));
991 glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle-dangle), polar_to_y(centery,diam,tampli-dampli,tangle-dangle));
992 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle-dangle), polar_to_y(centery,diam,tampli+dampli,tangle-dangle));
993 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle), polar_to_y(centery,diam,tampli+dampli,tangle+dangle));
995 /* big target vary by 10 degree and 20% amplitude */
996 glColor4f(1.0f, 1.0f, 1.0, 0.12f);
997 dangle= 10.0f*(float)M_PI/180.0f;
999 dangle2= 5.0f*(float)M_PI/180.0f;
1000 dampli2= 0.5f*dampli;
1001 glBegin(GL_LINE_STRIP);
1002 glVertex2f(polar_to_x(centerx,diam,tampli+dampli-dampli2,tangle+dangle), polar_to_y(centery,diam,tampli+dampli-dampli2,tangle+dangle));
1003 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle), polar_to_y(centery,diam,tampli+dampli,tangle+dangle));
1004 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle-dangle2), polar_to_y(centery,diam,tampli+dampli,tangle+dangle-dangle2));
1006 glBegin(GL_LINE_STRIP);
1007 glVertex2f(polar_to_x(centerx,diam,tampli-dampli+dampli2,tangle+dangle), polar_to_y(centery ,diam,tampli-dampli+dampli2,tangle+dangle));
1008 glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle+dangle), polar_to_y(centery,diam,tampli-dampli,tangle+dangle));
1009 glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle+dangle-dangle2), polar_to_y(centery,diam,tampli-dampli,tangle+dangle-dangle2));
1011 glBegin(GL_LINE_STRIP);
1012 glVertex2f(polar_to_x(centerx,diam,tampli-dampli+dampli2,tangle-dangle), polar_to_y(centery,diam,tampli-dampli+dampli2,tangle-dangle));
1013 glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle-dangle), polar_to_y(centery,diam,tampli-dampli,tangle-dangle));
1014 glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle-dangle+dangle2), polar_to_y(centery,diam,tampli-dampli,tangle-dangle+dangle2));
1016 glBegin(GL_LINE_STRIP);
1017 glVertex2f(polar_to_x(centerx,diam,tampli+dampli-dampli2,tangle-dangle), polar_to_y(centery,diam,tampli+dampli-dampli2,tangle-dangle));
1018 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle-dangle), polar_to_y(centery,diam,tampli+dampli,tangle-dangle));
1019 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle-dangle+dangle2), polar_to_y(centery,diam,tampli+dampli,tangle-dangle+dangle2));
1023 void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
1025 Scopes *scopes = (Scopes *)but->poin;
1028 int skina= 123; /* angle in degree of the skin tone line */
1029 float w, h, centerx, centery, diam;
1031 float colors[6][3]={{.75,0,0},{.75,.75,0},{0,.75,0},{0,.75,.75},{0,0,.75},{.75,0,.75}};
1034 rect.xmin = (float)recti->xmin+1;
1035 rect.xmax = (float)recti->xmax-1;
1036 rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
1037 rect.ymax = (float)recti->ymax-1;
1039 w = rect.xmax - rect.xmin;
1040 h = rect.ymax - rect.ymin;
1041 centerx = rect.xmin + w/2;
1042 centery = rect.ymin + h/2;
1045 alpha = scopes->vecscope_alpha*scopes->vecscope_alpha*scopes->vecscope_alpha;
1048 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1050 glColor4f(0.f, 0.f, 0.f, 0.3f);
1052 uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
1054 /* need scissor test, hvectorscope can draw outside of boundary */
1055 glGetIntegerv(GL_VIEWPORT, scissor);
1056 glScissor(ar->winrct.xmin + (rect.xmin-1), ar->winrct.ymin+(rect.ymin-1), (rect.xmax+1)-(rect.xmin-1), (rect.ymax+1)-(rect.ymin-1));
1058 glColor4f(1.f, 1.f, 1.f, 0.08f);
1059 /* draw grid elements */
1061 fdrawline(centerx - (diam/2)-5, centery, centerx + (diam/2)+5, centery);
1062 fdrawline(centerx, centery - (diam/2)-5, centerx, centery + (diam/2)+5);
1064 for(j=0; j<5; j++) {
1065 glBegin(GL_LINE_STRIP);
1066 for(i=0; i<=360; i=i+15) {
1067 float a= i*M_PI/180.0;
1068 float r= (j+1)/10.0f;
1069 glVertex2f( polar_to_x(centerx,diam,r,a), polar_to_y(centery,diam,r,a));
1073 /* skin tone line */
1074 glColor4f(1.f, 0.4f, 0.f, 0.2f);
1075 fdrawline( polar_to_x(centerx, diam, 0.5f, skina*M_PI/180.0), polar_to_y(centery,diam,0.5,skina*M_PI/180.0),
1076 polar_to_x(centerx, diam, 0.1f, skina*M_PI/180.0), polar_to_y(centery,diam,0.1,skina*M_PI/180.0));
1077 /* saturation points */
1079 vectorscope_draw_target(centerx, centery, diam, colors[i][0], colors[i][1], colors[i][2]);
1081 if (scopes->ok && scopes->vecscope != NULL) {
1082 /* pixel point cloud */
1083 glBlendFunc(GL_ONE,GL_ONE);
1084 glColor3f(alpha, alpha, alpha);
1087 glEnableClientState(GL_VERTEX_ARRAY);
1089 glTranslatef(centerx, centery, 0.f);
1090 glScalef(diam, diam, 0.f);
1092 glVertexPointer(2, GL_FLOAT, 0, scopes->vecscope);
1093 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
1095 glDisableClientState(GL_VERTEX_ARRAY);
1099 /* outline, scale gripper */
1100 draw_scope_end(&rect, scissor);
1102 glDisable(GL_BLEND);
1105 void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect)
1109 float x1, y1, sizex, sizey;
1110 float v3[2], v1[2], v2[2], v1a[2], v2a[2];
1112 float pos, colf[4]= {0,0,0,0}; /* initialize incase the colorband isnt valid */
1114 coba= (ColorBand *)(but->editcoba? but->editcoba: but->poin);
1115 if(coba==NULL) return;
1119 sizex= rect->xmax-x1;
1120 sizey= rect->ymax-y1;
1122 /* first background, to show tranparency */
1124 glColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255);
1125 glRectf(x1, y1, x1+sizex, y1+sizey);
1126 glEnable(GL_POLYGON_STIPPLE);
1127 glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255);
1128 glPolygonStipple(checker_stipple_sml);
1129 glRectf(x1, y1, x1+sizex, y1+sizey);
1130 glDisable(GL_POLYGON_STIPPLE);
1132 glShadeModel(GL_FLAT);
1141 glBegin(GL_QUAD_STRIP);
1143 glColor4fv( &cbd->r );
1144 glVertex2fv(v1); glVertex2fv(v2);
1146 for( a = 1; a <= sizex; a++ ) {
1147 pos = ((float)a) / (sizex-1);
1148 do_colorband( coba, pos, colf );
1149 if (but->block->color_profile != BLI_PR_NONE)
1150 linearrgb_to_srgb_v3_v3(colf, colf);
1152 v1[0]=v2[0]= x1 + a;
1155 glVertex2fv(v1); glVertex2fv(v2);
1159 glShadeModel(GL_FLAT);
1160 glDisable(GL_BLEND);
1163 glColor4f(0.0, 0.0, 0.0, 1.0);
1164 fdrawbox(x1, y1, x1+sizex, y1+sizey);
1167 v1[0]= v2[0]=v3[0]= x1;
1169 v1a[1]= y1+0.25f*sizey;
1170 v2[1]= y1+0.5f*sizey;
1171 v2a[1]= y1+0.75f*sizey;
1177 for(a=0; a<coba->tot; a++, cbd++) {
1178 v1[0]=v2[0]=v3[0]=v1a[0]=v2a[0]= x1+ cbd->pos*sizex;
1181 glColor3ub(0, 0, 0);
1188 glColor3ub(255, 255, 255);
1195 /* glColor3ub(0, 0, 0);
1198 glColor3ub(255, 255, 255);
1201 glColor3ub(0, 0, 0);
1204 glColor3ub(255, 255, 255);
1210 glColor3ub(0, 0, 0);
1214 glColor3ub(255, 255, 255);
1223 void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, rcti *rect)
1225 static GLuint displist=0;
1227 GLfloat diff[4], diffn[4]={1.0f, 1.0f, 1.0f, 1.0f};
1228 float vec0[4]={0.0f, 0.0f, 0.0f, 0.0f};
1232 glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
1235 glColor3ubv((unsigned char*)wcol->inner);
1237 uiDrawBox(GL_POLYGON, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f);
1240 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffn);
1241 glCullFace(GL_BACK); glEnable(GL_CULL_FACE);
1243 /* disable blender light */
1244 for(a=0; a<8; a++) {
1245 old[a]= glIsEnabled(GL_LIGHT0+a);
1246 glDisable(GL_LIGHT0+a);
1250 glEnable(GL_LIGHT7);
1251 glEnable(GL_LIGHTING);
1253 ui_get_but_vectorf(but, dir);
1255 dir[3]= 0.0f; /* glLight needs 4 args, 0.0 is sun */
1256 glLightfv(GL_LIGHT7, GL_POSITION, dir);
1257 glLightfv(GL_LIGHT7, GL_DIFFUSE, diffn);
1258 glLightfv(GL_LIGHT7, GL_SPECULAR, vec0);
1259 glLightf(GL_LIGHT7, GL_CONSTANT_ATTENUATION, 1.0f);
1260 glLightf(GL_LIGHT7, GL_LINEAR_ATTENUATION, 0.0f);
1262 /* transform to button */
1264 glTranslatef(rect->xmin + 0.5f*(rect->xmax-rect->xmin), rect->ymin+ 0.5f*(rect->ymax-rect->ymin), 0.0f);
1266 if( rect->xmax-rect->xmin < rect->ymax-rect->ymin)
1267 size= (rect->xmax-rect->xmin)/200.f;
1269 size= (rect->ymax-rect->ymin)/200.f;
1271 glScalef(size, size, size);
1274 GLUquadricObj *qobj;
1276 displist= glGenLists(1);
1277 glNewList(displist, GL_COMPILE_AND_EXECUTE);
1279 qobj= gluNewQuadric();
1280 gluQuadricDrawStyle(qobj, GLU_FILL);
1281 glShadeModel(GL_SMOOTH);
1282 gluSphere( qobj, 100.0, 32, 24);
1283 glShadeModel(GL_FLAT);
1284 gluDeleteQuadric(qobj);
1288 else glCallList(displist);
1291 glDisable(GL_LIGHTING);
1292 glDisable(GL_CULL_FACE);
1293 glMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
1294 glDisable(GL_LIGHT7);
1298 glEnable(GL_LINE_SMOOTH );
1299 glColor3ubv((unsigned char*)wcol->inner);
1300 glutil_draw_lined_arc(0.0f, M_PI*2.0, 100.0f, 32);
1301 glDisable(GL_BLEND);
1302 glDisable(GL_LINE_SMOOTH );
1304 /* matrix after circle */
1307 /* enable blender light */
1308 for(a=0; a<8; a++) {
1310 glEnable(GL_LIGHT0+a);
1314 static void ui_draw_but_curve_grid(rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step)
1316 float dx, dy, fx, fy;
1320 fx= rect->xmin + zoomx*(-offsx);
1321 if(fx > rect->xmin) fx -= dx*(floorf(fx-rect->xmin));
1322 while(fx < rect->xmax) {
1323 glVertex2f(fx, rect->ymin);
1324 glVertex2f(fx, rect->ymax);
1329 fy= rect->ymin + zoomy*(-offsy);
1330 if(fy > rect->ymin) fy -= dy*(floorf(fy-rect->ymin));
1331 while(fy < rect->ymax) {
1332 glVertex2f(rect->xmin, fy);
1333 glVertex2f(rect->xmax, fy);
1340 static void glColor3ubvShade(unsigned char *col, int shade)
1342 glColor3ub(col[0]-shade>0?col[0]-shade:0,
1343 col[1]-shade>0?col[1]-shade:0,
1344 col[2]-shade>0?col[2]-shade:0);
1347 void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect)
1349 CurveMapping *cumap;
1352 float fx, fy, fac[2], zoomx, zoomy, offsx, offsy;
1357 cumap= (CurveMapping *)(but->editcumap? but->editcumap: but->poin);
1358 cuma= cumap->cm+cumap->cur;
1360 /* need scissor test, curve can draw outside of boundary */
1361 glGetIntegerv(GL_VIEWPORT, scissor);
1362 scissor_new.xmin= ar->winrct.xmin + rect->xmin;
1363 scissor_new.ymin= ar->winrct.ymin + rect->ymin;
1364 scissor_new.xmax= ar->winrct.xmin + rect->xmax;
1365 scissor_new.ymax= ar->winrct.ymin + rect->ymax;
1366 BLI_isect_rcti(&scissor_new, &ar->winrct, &scissor_new);
1367 glScissor(scissor_new.xmin, scissor_new.ymin, scissor_new.xmax-scissor_new.xmin, scissor_new.ymax-scissor_new.ymin);
1369 /* calculate offset and zoom */
1370 zoomx= (rect->xmax-rect->xmin-2.0f*but->aspect)/(cumap->curr.xmax - cumap->curr.xmin);
1371 zoomy= (rect->ymax-rect->ymin-2.0f*but->aspect)/(cumap->curr.ymax - cumap->curr.ymin);
1372 offsx= cumap->curr.xmin-but->aspect/zoomx;
1373 offsy= cumap->curr.ymin-but->aspect/zoomy;
1376 if(cumap->flag & CUMA_DO_CLIP) {
1377 glColor3ubvShade((unsigned char *)wcol->inner, -20);
1378 glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1379 glColor3ubv((unsigned char*)wcol->inner);
1380 glRectf(rect->xmin + zoomx*(cumap->clipr.xmin-offsx),
1381 rect->ymin + zoomy*(cumap->clipr.ymin-offsy),
1382 rect->xmin + zoomx*(cumap->clipr.xmax-offsx),
1383 rect->ymin + zoomy*(cumap->clipr.ymax-offsy));
1386 glColor3ubv((unsigned char*)wcol->inner);
1387 glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1390 /* grid, every .25 step */
1391 glColor3ubvShade((unsigned char *)wcol->inner, -16);
1392 ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.25f);
1393 /* grid, every 1.0 step */
1394 glColor3ubvShade((unsigned char *)wcol->inner, -24);
1395 ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 1.0f);
1397 glColor3ubvShade((unsigned char *)wcol->inner, -50);
1399 glVertex2f(rect->xmin, rect->ymin + zoomy*(-offsy));
1400 glVertex2f(rect->xmax, rect->ymin + zoomy*(-offsy));
1401 glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymin);
1402 glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymax);
1405 /* magic trigger for curve backgrounds */
1406 if (but->a1 != -1) {
1407 if (but->a1 == UI_GRAD_H) {
1409 float col[3]= {0.0f, 0.0f, 0.0f}; /* dummy arg */
1411 grid.xmin = rect->xmin + zoomx*(-offsx);
1412 grid.xmax = rect->xmax + zoomx*(-offsx);
1413 grid.ymin = rect->ymin + zoomy*(-offsy);
1414 grid.ymax = rect->ymax + zoomy*(-offsy);
1417 ui_draw_gradient(&grid, col, UI_GRAD_H, 0.5f);
1418 glDisable(GL_BLEND);
1425 if(cumap->flag & CUMA_DRAW_CFRA) {
1426 glColor3ub(0x60, 0xc0, 0x40);
1428 glVertex2f(rect->xmin + zoomx*(cumap->sample[0]-offsx), rect->ymin);
1429 glVertex2f(rect->xmin + zoomx*(cumap->sample[0]-offsx), rect->ymax);
1434 * if(cumap->flag & CUMA_DRAW_SAMPLE) {
1436 float lum= cumap->sample[0]*0.35f + cumap->sample[1]*0.45f + cumap->sample[2]*0.2f;
1437 glColor3ub(240, 240, 240);
1440 glVertex2f(rect->xmin + zoomx*(lum-offsx), rect->ymin);
1441 glVertex2f(rect->xmin + zoomx*(lum-offsx), rect->ymax);
1446 glColor3ub(240, 100, 100);
1447 else if(cumap->cur==1)
1448 glColor3ub(100, 240, 100);
1450 glColor3ub(100, 100, 240);
1453 glVertex2f(rect->xmin + zoomx*(cumap->sample[cumap->cur]-offsx), rect->ymin);
1454 glVertex2f(rect->xmin + zoomx*(cumap->sample[cumap->cur]-offsx), rect->ymax);
1460 glColor3ubv((unsigned char*)wcol->item);
1461 glEnable(GL_LINE_SMOOTH);
1463 glBegin(GL_LINE_STRIP);
1465 if(cuma->table==NULL)
1466 curvemapping_changed(cumap, 0); /* 0 = no remove doubles */
1470 if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0)
1471 glVertex2f(rect->xmin, rect->ymin + zoomy*(cmp[0].y-offsy));
1473 fx= rect->xmin + zoomx*(cmp[0].x-offsx + cuma->ext_in[0]);
1474 fy= rect->ymin + zoomy*(cmp[0].y-offsy + cuma->ext_in[1]);
1477 for(a=0; a<=CM_TABLE; a++) {
1478 fx= rect->xmin + zoomx*(cmp[a].x-offsx);
1479 fy= rect->ymin + zoomy*(cmp[a].y-offsy);
1483 if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0)
1484 glVertex2f(rect->xmax, rect->ymin + zoomy*(cmp[CM_TABLE].y-offsy));
1486 fx= rect->xmin + zoomx*(cmp[CM_TABLE].x-offsx - cuma->ext_out[0]);
1487 fy= rect->ymin + zoomy*(cmp[CM_TABLE].y-offsy - cuma->ext_out[1]);
1491 glDisable(GL_LINE_SMOOTH);
1492 glDisable(GL_BLEND);
1494 /* the points, use aspect to make them visible on edges */
1497 bglBegin(GL_POINTS);
1498 for(a=0; a<cuma->totpoint; a++) {
1499 if(cmp[a].flag & SELECT)
1500 UI_ThemeColor(TH_TEXT_HI);
1502 UI_ThemeColor(TH_TEXT);
1503 fac[0]= rect->xmin + zoomx*(cmp[a].x-offsx);
1504 fac[1]= rect->ymin + zoomy*(cmp[a].y-offsy);
1510 /* restore scissortest */
1511 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
1514 glColor3ubv((unsigned char*)wcol->outline);
1515 fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1519 /* ****************************************************** */
1522 static void ui_shadowbox(float minx, float miny, float maxx, float maxy, float shadsize, unsigned char alpha)
1525 glShadeModel(GL_SMOOTH);
1528 glBegin(GL_POLYGON);
1529 glColor4ub(0, 0, 0, alpha);
1530 glVertex2f(maxx, miny);
1531 glVertex2f(maxx, maxy-0.3f*shadsize);
1532 glColor4ub(0, 0, 0, 0);
1533 glVertex2f(maxx+shadsize, maxy-0.75f*shadsize);
1534 glVertex2f(maxx+shadsize, miny);
1538 glBegin(GL_POLYGON);
1539 glColor4ub(0, 0, 0, alpha);
1540 glVertex2f(maxx, miny);
1541 glColor4ub(0, 0, 0, 0);
1542 glVertex2f(maxx+shadsize, miny);
1543 glVertex2f(maxx+0.7f*shadsize, miny-0.7f*shadsize);
1544 glVertex2f(maxx, miny-shadsize);
1548 glBegin(GL_POLYGON);
1549 glColor4ub(0, 0, 0, alpha);
1550 glVertex2f(minx+0.3f*shadsize, miny);
1551 glVertex2f(maxx, miny);
1552 glColor4ub(0, 0, 0, 0);
1553 glVertex2f(maxx, miny-shadsize);
1554 glVertex2f(minx+0.5f*shadsize, miny-shadsize);
1557 glDisable(GL_BLEND);
1558 glShadeModel(GL_FLAT);
1561 void uiDrawBoxShadow(unsigned char alpha, float minx, float miny, float maxx, float maxy)
1563 /* accumulated outline boxes to make shade not linear, is more pleasant */
1564 ui_shadowbox(minx, miny, maxx, maxy, 11.0, (20*alpha)>>8);
1565 ui_shadowbox(minx, miny, maxx, maxy, 7.0, (40*alpha)>>8);
1566 ui_shadowbox(minx, miny, maxx, maxy, 5.0, (80*alpha)>>8);
1571 void ui_dropshadow(rctf *rct, float radius, float aspect, int UNUSED(select))
1580 if(radius > (rct->ymax-rct->ymin-10.0f)/2.0f)
1581 rad= (rct->ymax-rct->ymin-10.0f)/2.0f;
1588 a= i*aspect; /* same as below */
1596 for(; i--; a-=aspect) {
1597 /* alpha ranges from 2 to 20 or so */
1598 glColor4ub(0, 0, 0, alpha);
1601 uiDrawBox(GL_POLYGON, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax-10.0f + a, rad+a);
1604 /* outline emphasis */
1605 glEnable( GL_LINE_SMOOTH );
1606 glColor4ub(0, 0, 0, 100);
1607 uiDrawBox(GL_LINE_LOOP, rct->xmin-0.5f, rct->ymin-0.5f, rct->xmax+0.5f, rct->ymax+0.5f, radius+0.5f);
1608 glDisable( GL_LINE_SMOOTH );
1610 glDisable(GL_BLEND);