Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * Contributor(s): Blender Foundation 00022 * 00023 * ***** END GPL LICENSE BLOCK ***** 00024 */ 00025 00031 #include <math.h> 00032 #include <string.h> 00033 00034 #include "DNA_color_types.h" 00035 #include "DNA_object_types.h" 00036 #include "DNA_screen_types.h" 00037 #include "DNA_movieclip_types.h" 00038 00039 #include "BLI_math.h" 00040 #include "BLI_rect.h" 00041 #include "BLI_string.h" 00042 #include "BLI_utildefines.h" 00043 00044 #include "BKE_colortools.h" 00045 #include "BKE_texture.h" 00046 00047 00048 #include "IMB_imbuf.h" 00049 #include "IMB_imbuf_types.h" 00050 00051 #include "BIF_gl.h" 00052 #include "BIF_glutil.h" 00053 00054 #include "BLF_api.h" 00055 00056 #include "UI_interface.h" 00057 00058 /* own include */ 00059 #include "interface_intern.h" 00060 00061 #define UI_DISABLED_ALPHA_OFFS -160 00062 00063 static int roundboxtype= UI_CNR_ALL; 00064 00065 void uiSetRoundBox(int type) 00066 { 00067 /* Not sure the roundbox function is the best place to change this 00068 * if this is undone, its not that big a deal, only makes curves edges 00069 * square for the */ 00070 roundboxtype= type; 00071 00072 } 00073 00074 int uiGetRoundBox(void) 00075 { 00076 return roundboxtype; 00077 } 00078 00079 void uiDrawBox(int mode, float minx, float miny, float maxx, float maxy, float rad) 00080 { 00081 float vec[7][2]= {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293}, 00082 {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}}; 00083 int a; 00084 00085 /* mult */ 00086 for(a=0; a<7; a++) { 00087 vec[a][0]*= rad; vec[a][1]*= rad; 00088 } 00089 00090 glBegin(mode); 00091 00092 /* start with corner right-bottom */ 00093 if(roundboxtype & UI_CNR_BOTTOM_RIGHT) { 00094 glVertex2f(maxx-rad, miny); 00095 for(a=0; a<7; a++) { 00096 glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]); 00097 } 00098 glVertex2f(maxx, miny+rad); 00099 } 00100 else glVertex2f(maxx, miny); 00101 00102 /* corner right-top */ 00103 if(roundboxtype & UI_CNR_TOP_RIGHT) { 00104 glVertex2f(maxx, maxy-rad); 00105 for(a=0; a<7; a++) { 00106 glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]); 00107 } 00108 glVertex2f(maxx-rad, maxy); 00109 } 00110 else glVertex2f(maxx, maxy); 00111 00112 /* corner left-top */ 00113 if(roundboxtype & UI_CNR_TOP_LEFT) { 00114 glVertex2f(minx+rad, maxy); 00115 for(a=0; a<7; a++) { 00116 glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]); 00117 } 00118 glVertex2f(minx, maxy-rad); 00119 } 00120 else glVertex2f(minx, maxy); 00121 00122 /* corner left-bottom */ 00123 if(roundboxtype & UI_CNR_BOTTOM_LEFT) { 00124 glVertex2f(minx, miny+rad); 00125 for(a=0; a<7; a++) { 00126 glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]); 00127 } 00128 glVertex2f(minx+rad, miny); 00129 } 00130 else glVertex2f(minx, miny); 00131 00132 glEnd(); 00133 } 00134 00135 static void round_box_shade_col(const float col1[3], float const col2[3], const float fac) 00136 { 00137 float col[3]; 00138 00139 col[0]= (fac*col1[0] + (1.0f-fac)*col2[0]); 00140 col[1]= (fac*col1[1] + (1.0f-fac)*col2[1]); 00141 col[2]= (fac*col1[2] + (1.0f-fac)*col2[2]); 00142 glColor3fv(col); 00143 } 00144 00145 /* linear horizontal shade within button or in outline */ 00146 /* view2d scrollers use it */ 00147 void uiDrawBoxShade(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadetop, float shadedown) 00148 { 00149 float vec[7][2]= {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293}, 00150 {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}}; 00151 const float div= maxy - miny; 00152 const float idiv= 1.0f / div; 00153 float coltop[3], coldown[3], color[4]; 00154 int a; 00155 00156 /* mult */ 00157 for(a=0; a<7; a++) { 00158 vec[a][0]*= rad; vec[a][1]*= rad; 00159 } 00160 /* get current color, needs to be outside of glBegin/End */ 00161 glGetFloatv(GL_CURRENT_COLOR, color); 00162 00163 /* 'shade' defines strength of shading */ 00164 coltop[0]= color[0]+shadetop; if(coltop[0]>1.0f) coltop[0]= 1.0f; 00165 coltop[1]= color[1]+shadetop; if(coltop[1]>1.0f) coltop[1]= 1.0f; 00166 coltop[2]= color[2]+shadetop; if(coltop[2]>1.0f) coltop[2]= 1.0f; 00167 coldown[0]= color[0]+shadedown; if(coldown[0]<0.0f) coldown[0]= 0.0f; 00168 coldown[1]= color[1]+shadedown; if(coldown[1]<0.0f) coldown[1]= 0.0f; 00169 coldown[2]= color[2]+shadedown; if(coldown[2]<0.0f) coldown[2]= 0.0f; 00170 00171 glShadeModel(GL_SMOOTH); 00172 glBegin(mode); 00173 00174 /* start with corner right-bottom */ 00175 if(roundboxtype & UI_CNR_BOTTOM_RIGHT) { 00176 00177 round_box_shade_col(coltop, coldown, 0.0); 00178 glVertex2f(maxx-rad, miny); 00179 00180 for(a=0; a<7; a++) { 00181 round_box_shade_col(coltop, coldown, vec[a][1]*idiv); 00182 glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]); 00183 } 00184 00185 round_box_shade_col(coltop, coldown, rad*idiv); 00186 glVertex2f(maxx, miny+rad); 00187 } 00188 else { 00189 round_box_shade_col(coltop, coldown, 0.0); 00190 glVertex2f(maxx, miny); 00191 } 00192 00193 /* corner right-top */ 00194 if(roundboxtype & UI_CNR_TOP_RIGHT) { 00195 00196 round_box_shade_col(coltop, coldown, (div-rad)*idiv); 00197 glVertex2f(maxx, maxy-rad); 00198 00199 for(a=0; a<7; a++) { 00200 round_box_shade_col(coltop, coldown, (div-rad+vec[a][1])*idiv); 00201 glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]); 00202 } 00203 round_box_shade_col(coltop, coldown, 1.0); 00204 glVertex2f(maxx-rad, maxy); 00205 } 00206 else { 00207 round_box_shade_col(coltop, coldown, 1.0); 00208 glVertex2f(maxx, maxy); 00209 } 00210 00211 /* corner left-top */ 00212 if(roundboxtype & UI_CNR_TOP_LEFT) { 00213 00214 round_box_shade_col(coltop, coldown, 1.0); 00215 glVertex2f(minx+rad, maxy); 00216 00217 for(a=0; a<7; a++) { 00218 round_box_shade_col(coltop, coldown, (div-vec[a][1])*idiv); 00219 glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]); 00220 } 00221 00222 round_box_shade_col(coltop, coldown, (div-rad)*idiv); 00223 glVertex2f(minx, maxy-rad); 00224 } 00225 else { 00226 round_box_shade_col(coltop, coldown, 1.0); 00227 glVertex2f(minx, maxy); 00228 } 00229 00230 /* corner left-bottom */ 00231 if(roundboxtype & UI_CNR_BOTTOM_LEFT) { 00232 00233 round_box_shade_col(coltop, coldown, rad*idiv); 00234 glVertex2f(minx, miny+rad); 00235 00236 for(a=0; a<7; a++) { 00237 round_box_shade_col(coltop, coldown, (rad-vec[a][1])*idiv); 00238 glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]); 00239 } 00240 00241 round_box_shade_col(coltop, coldown, 0.0); 00242 glVertex2f(minx+rad, miny); 00243 } 00244 else { 00245 round_box_shade_col(coltop, coldown, 0.0); 00246 glVertex2f(minx, miny); 00247 } 00248 00249 glEnd(); 00250 glShadeModel(GL_FLAT); 00251 } 00252 00253 /* linear vertical shade within button or in outline */ 00254 /* view2d scrollers use it */ 00255 void uiDrawBoxVerticalShade(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadeLeft, float shadeRight) 00256 { 00257 float vec[7][2]= {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293}, 00258 {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}}; 00259 const float div= maxx - minx; 00260 const float idiv= 1.0f / div; 00261 float colLeft[3], colRight[3], color[4]; 00262 int a; 00263 00264 /* mult */ 00265 for(a=0; a<7; a++) { 00266 vec[a][0]*= rad; vec[a][1]*= rad; 00267 } 00268 /* get current color, needs to be outside of glBegin/End */ 00269 glGetFloatv(GL_CURRENT_COLOR, color); 00270 00271 /* 'shade' defines strength of shading */ 00272 colLeft[0]= color[0]+shadeLeft; if(colLeft[0]>1.0f) colLeft[0]= 1.0f; 00273 colLeft[1]= color[1]+shadeLeft; if(colLeft[1]>1.0f) colLeft[1]= 1.0f; 00274 colLeft[2]= color[2]+shadeLeft; if(colLeft[2]>1.0f) colLeft[2]= 1.0f; 00275 colRight[0]= color[0]+shadeRight; if(colRight[0]<0.0f) colRight[0]= 0.0f; 00276 colRight[1]= color[1]+shadeRight; if(colRight[1]<0.0f) colRight[1]= 0.0f; 00277 colRight[2]= color[2]+shadeRight; if(colRight[2]<0.0f) colRight[2]= 0.0f; 00278 00279 glShadeModel(GL_SMOOTH); 00280 glBegin(mode); 00281 00282 /* start with corner right-bottom */ 00283 if(roundboxtype & UI_CNR_BOTTOM_RIGHT) { 00284 round_box_shade_col(colLeft, colRight, 0.0); 00285 glVertex2f(maxx-rad, miny); 00286 00287 for(a=0; a<7; a++) { 00288 round_box_shade_col(colLeft, colRight, vec[a][0]*idiv); 00289 glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]); 00290 } 00291 00292 round_box_shade_col(colLeft, colRight, rad*idiv); 00293 glVertex2f(maxx, miny+rad); 00294 } 00295 else { 00296 round_box_shade_col(colLeft, colRight, 0.0); 00297 glVertex2f(maxx, miny); 00298 } 00299 00300 /* corner right-top */ 00301 if(roundboxtype & UI_CNR_TOP_RIGHT) { 00302 round_box_shade_col(colLeft, colRight, 0.0); 00303 glVertex2f(maxx, maxy-rad); 00304 00305 for(a=0; a<7; a++) { 00306 00307 round_box_shade_col(colLeft, colRight, (div-rad-vec[a][0])*idiv); 00308 glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]); 00309 } 00310 round_box_shade_col(colLeft, colRight, (div-rad)*idiv); 00311 glVertex2f(maxx-rad, maxy); 00312 } 00313 else { 00314 round_box_shade_col(colLeft, colRight, 0.0); 00315 glVertex2f(maxx, maxy); 00316 } 00317 00318 /* corner left-top */ 00319 if(roundboxtype & UI_CNR_TOP_LEFT) { 00320 round_box_shade_col(colLeft, colRight, (div-rad)*idiv); 00321 glVertex2f(minx+rad, maxy); 00322 00323 for(a=0; a<7; a++) { 00324 round_box_shade_col(colLeft, colRight, (div-rad+vec[a][0])*idiv); 00325 glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]); 00326 } 00327 00328 round_box_shade_col(colLeft, colRight, 1.0); 00329 glVertex2f(minx, maxy-rad); 00330 } 00331 else { 00332 round_box_shade_col(colLeft, colRight, 1.0); 00333 glVertex2f(minx, maxy); 00334 } 00335 00336 /* corner left-bottom */ 00337 if(roundboxtype & UI_CNR_BOTTOM_LEFT) { 00338 round_box_shade_col(colLeft, colRight, 1.0); 00339 glVertex2f(minx, miny+rad); 00340 00341 for(a=0; a<7; a++) { 00342 round_box_shade_col(colLeft, colRight, (vec[a][0])*idiv); 00343 glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]); 00344 } 00345 00346 round_box_shade_col(colLeft, colRight, 1.0); 00347 glVertex2f(minx+rad, miny); 00348 } 00349 else { 00350 round_box_shade_col(colLeft, colRight, 1.0); 00351 glVertex2f(minx, miny); 00352 } 00353 00354 glEnd(); 00355 glShadeModel(GL_FLAT); 00356 } 00357 00358 /* plain antialiased unfilled rectangle */ 00359 void uiRoundRect(float minx, float miny, float maxx, float maxy, float rad) 00360 { 00361 float color[4]; 00362 00363 if(roundboxtype & UI_RB_ALPHA) { 00364 glGetFloatv(GL_CURRENT_COLOR, color); 00365 color[3]= 0.5; 00366 glColor4fv(color); 00367 glEnable( GL_BLEND ); 00368 } 00369 00370 /* set antialias line */ 00371 glEnable( GL_LINE_SMOOTH ); 00372 glEnable( GL_BLEND ); 00373 00374 uiDrawBox(GL_LINE_LOOP, minx, miny, maxx, maxy, rad); 00375 00376 glDisable( GL_BLEND ); 00377 glDisable( GL_LINE_SMOOTH ); 00378 } 00379 00380 /* (old, used in outliner) plain antialiased filled box */ 00381 void uiRoundBox(float minx, float miny, float maxx, float maxy, float rad) 00382 { 00383 float color[4]; 00384 00385 if(roundboxtype & UI_RB_ALPHA) { 00386 glGetFloatv(GL_CURRENT_COLOR, color); 00387 color[3]= 0.5; 00388 glColor4fv(color); 00389 glEnable( GL_BLEND ); 00390 } 00391 00392 ui_draw_anti_roundbox(GL_POLYGON, minx, miny, maxx, maxy, rad); 00393 } 00394 00395 00396 /* ************** generic embossed rect, for window sliders etc ************* */ 00397 00398 00399 /* text_draw.c uses this */ 00400 void uiEmboss(float x1, float y1, float x2, float y2, int sel) 00401 { 00402 00403 /* below */ 00404 if(sel) glColor3ub(200,200,200); 00405 else glColor3ub(50,50,50); 00406 fdrawline(x1, y1, x2, y1); 00407 00408 /* right */ 00409 fdrawline(x2, y1, x2, y2); 00410 00411 /* top */ 00412 if(sel) glColor3ub(50,50,50); 00413 else glColor3ub(200,200,200); 00414 fdrawline(x1, y2, x2, y2); 00415 00416 /* left */ 00417 fdrawline(x1, y1, x1, y2); 00418 00419 } 00420 00421 /* ************** SPECIAL BUTTON DRAWING FUNCTIONS ************* */ 00422 00423 void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect) 00424 { 00425 #ifdef WITH_HEADLESS 00426 (void)rect; 00427 (void)but; 00428 #else 00429 ImBuf *ibuf= (ImBuf *)but->poin; 00430 //GLint scissor[4]; 00431 //int w, h; 00432 00433 if (!ibuf) return; 00434 00435 /* scissor doesn't seem to be doing the right thing...? 00436 //glColor4f(1.0, 0.f, 0.f, 1.f); 00437 //fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax) 00438 00439 w = (rect->xmax - rect->xmin); 00440 h = (rect->ymax - rect->ymin); 00441 // prevent drawing outside widget area 00442 glGetIntegerv(GL_SCISSOR_BOX, scissor); 00443 glScissor(ar->winrct.xmin + rect->xmin, ar->winrct.ymin + rect->ymin, w, h); 00444 */ 00445 00446 glEnable(GL_BLEND); 00447 glColor4f(0.0, 0.0, 0.0, 0.0); 00448 00449 glaDrawPixelsSafe((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); 00450 //glaDrawPixelsTex((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect); 00451 00452 glDisable(GL_BLEND); 00453 00454 /* 00455 // restore scissortest 00456 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); 00457 */ 00458 00459 #endif 00460 } 00461 00462 #if 0 00463 #ifdef WITH_INTERNATIONAL 00464 static void ui_draw_but_CHARTAB(uiBut *but) 00465 { 00466 /* XXX 2.50 bad global access */ 00467 /* Some local variables */ 00468 float sx, sy, ex, ey; 00469 float width, height; 00470 float butw, buth; 00471 int x, y, cs; 00472 wchar_t wstr[2]; 00473 unsigned char ustr[16]; 00474 PackedFile *pf; 00475 int result = 0; 00476 int charmax = G.charmax; 00477 00478 /* FO_BUILTIN_NAME font in use. There are TTF FO_BUILTIN_NAME and non-TTF FO_BUILTIN_NAME fonts */ 00479 if(!strcmp(G.selfont->name, FO_BUILTIN_NAME)) { 00480 if(G.ui_international == TRUE) { 00481 charmax = 0xff; 00482 } 00483 else { 00484 charmax = 0xff; 00485 } 00486 } 00487 00488 /* Category list exited without selecting the area */ 00489 if(G.charmax == 0) 00490 charmax = G.charmax = 0xffff; 00491 00492 /* Calculate the size of the button */ 00493 width = abs(rect->xmax - rect->xmin); 00494 height = abs(rect->ymax - rect->ymin); 00495 00496 butw = floor(width / 12); 00497 buth = floor(height / 6); 00498 00499 /* Initialize variables */ 00500 sx = rect->xmin; 00501 ex = rect->xmin + butw; 00502 sy = rect->ymin + height - buth; 00503 ey = rect->ymin + height; 00504 00505 cs = G.charstart; 00506 00507 /* Set the font, in case it is not FO_BUILTIN_NAME font */ 00508 if(G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) { 00509 // Is the font file packed, if so then use the packed file 00510 if(G.selfont->packedfile) { 00511 pf = G.selfont->packedfile; 00512 FTF_SetFont(pf->data, pf->size, 14.0); 00513 } 00514 else { 00515 char tmpStr[256]; 00516 int err; 00517 00518 BLI_strncpy(tmpStr, G.selfont->name, sizeof(tmpStr)); 00519 BLI_path_abs(tmpStr, G.main->name); 00520 err = FTF_SetFont((unsigned char *)tmpStr, 0, 14.0); 00521 } 00522 } 00523 else { 00524 if(G.ui_international == TRUE) { 00525 FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 14.0); 00526 } 00527 } 00528 00529 /* Start drawing the button itself */ 00530 glShadeModel(GL_SMOOTH); 00531 00532 glColor3ub(200, 200, 200); 00533 glRectf((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax)); 00534 00535 glColor3ub(0, 0, 0); 00536 for(y = 0; y < 6; y++) { 00537 // Do not draw more than the category allows 00538 if(cs > charmax) break; 00539 00540 for(x = 0; x < 12; x++) 00541 { 00542 // Do not draw more than the category allows 00543 if(cs > charmax) break; 00544 00545 // Draw one grid cell 00546 glBegin(GL_LINE_LOOP); 00547 glVertex2f(sx, sy); 00548 glVertex2f(ex, sy); 00549 glVertex2f(ex, ey); 00550 glVertex2f(sx, ey); 00551 glEnd(); 00552 00553 // Draw character inside the cell 00554 memset(wstr, 0, sizeof(wchar_t)*2); 00555 memset(ustr, 0, 16); 00556 00557 // Set the font to be either unicode or FO_BUILTIN_NAME 00558 wstr[0] = cs; 00559 if(strcmp(G.selfont->name, FO_BUILTIN_NAME)) 00560 { 00561 BLI_strncpy_wchar_as_utf8((char *)ustr, (wchar_t *)wstr, sizeof(ustr)); 00562 } 00563 else 00564 { 00565 if(G.ui_international == TRUE) 00566 { 00567 BLI_strncpy_wchar_as_utf8((char *)ustr, (wchar_t *)wstr, sizeof(ustr)); 00568 } 00569 else 00570 { 00571 ustr[0] = cs; 00572 ustr[1] = 0; 00573 } 00574 } 00575 00576 if((G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) || (G.selfont && !strcmp(G.selfont->name, FO_BUILTIN_NAME) && G.ui_international == TRUE)) 00577 { 00578 float wid; 00579 float llx, lly, llz, urx, ury, urz; 00580 float dx, dy; 00581 float px, py; 00582 00583 // Calculate the position 00584 wid = FTF_GetStringWidth((char *) ustr, FTF_USE_GETTEXT | FTF_INPUT_UTF8); 00585 FTF_GetBoundingBox((char *) ustr, &llx,&lly,&llz,&urx,&ury,&urz, FTF_USE_GETTEXT | FTF_INPUT_UTF8); 00586 dx = urx-llx; 00587 dy = ury-lly; 00588 00589 // This isn't fully functional since the but->aspect isn't working like I suspected 00590 px = sx + ((butw/but->aspect)-dx)/2; 00591 py = sy + ((buth/but->aspect)-dy)/2; 00592 00593 // Set the position and draw the character 00594 ui_rasterpos_safe(px, py, but->aspect); 00595 FTF_DrawString((char *) ustr, FTF_USE_GETTEXT | FTF_INPUT_UTF8); 00596 } 00597 else 00598 { 00599 ui_rasterpos_safe(sx + butw/2, sy + buth/2, but->aspect); 00600 UI_DrawString(but->font, (char *) ustr, 0); 00601 } 00602 00603 // Calculate the next position and character 00604 sx += butw; ex +=butw; 00605 cs++; 00606 } 00607 /* Add the y position and reset x position */ 00608 sy -= buth; 00609 ey -= buth; 00610 sx = rect->xmin; 00611 ex = rect->xmin + butw; 00612 } 00613 glShadeModel(GL_FLAT); 00614 00615 /* Return Font Settings to original */ 00616 if(U.fontsize && U.fontname[0]) { 00617 result = FTF_SetFont((unsigned char *)U.fontname, 0, U.fontsize); 00618 } 00619 else if (U.fontsize) { 00620 result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, U.fontsize); 00621 } 00622 00623 if (result == 0) { 00624 result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 11); 00625 } 00626 00627 /* resets the font size */ 00628 if(G.ui_international == TRUE) { 00629 // uiSetCurFont(but->block, UI_HELV); 00630 } 00631 } 00632 00633 #endif // WITH_INTERNATIONAL 00634 #endif 00635 00636 static void draw_scope_end(rctf *rect, GLint *scissor) 00637 { 00638 float scaler_x1, scaler_x2; 00639 00640 /* restore scissortest */ 00641 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); 00642 00643 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 00644 00645 /* scale widget */ 00646 scaler_x1 = rect->xmin + (rect->xmax - rect->xmin)/2 - SCOPE_RESIZE_PAD; 00647 scaler_x2 = rect->xmin + (rect->xmax - rect->xmin)/2 + SCOPE_RESIZE_PAD; 00648 00649 glColor4f(0.f, 0.f, 0.f, 0.25f); 00650 fdrawline(scaler_x1, rect->ymin-4, scaler_x2, rect->ymin-4); 00651 fdrawline(scaler_x1, rect->ymin-7, scaler_x2, rect->ymin-7); 00652 glColor4f(1.f, 1.f, 1.f, 0.25f); 00653 fdrawline(scaler_x1, rect->ymin-5, scaler_x2, rect->ymin-5); 00654 fdrawline(scaler_x1, rect->ymin-8, scaler_x2, rect->ymin-8); 00655 00656 /* outline */ 00657 glColor4f(0.f, 0.f, 0.f, 0.5f); 00658 uiSetRoundBox(UI_CNR_ALL); 00659 uiDrawBox(GL_LINE_LOOP, rect->xmin-1, rect->ymin, rect->xmax+1, rect->ymax+1, 3.0f); 00660 } 00661 00662 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) 00663 { 00664 int i; 00665 00666 /* under the curve */ 00667 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 00668 glColor4f(r, g, b, alpha); 00669 00670 glShadeModel(GL_FLAT); 00671 glBegin(GL_QUAD_STRIP); 00672 glVertex2f(x, y); 00673 glVertex2f(x, y + (data[0]*h)); 00674 for (i=1; i < res; i++) { 00675 float x2 = x + i * (w/(float)res); 00676 glVertex2f(x2, y + (data[i]*h)); 00677 glVertex2f(x2, y); 00678 } 00679 glEnd(); 00680 00681 /* curve outline */ 00682 glColor4f(0.f, 0.f, 0.f, 0.25f); 00683 00684 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00685 glEnable(GL_LINE_SMOOTH); 00686 glBegin(GL_LINE_STRIP); 00687 for (i=0; i < res; i++) { 00688 float x2 = x + i * (w/(float)res); 00689 glVertex2f(x2, y + (data[i]*h)); 00690 } 00691 glEnd(); 00692 glDisable(GL_LINE_SMOOTH); 00693 } 00694 00695 void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti) 00696 { 00697 Histogram *hist = (Histogram *)but->poin; 00698 int res = hist->x_resolution; 00699 rctf rect; 00700 int i; 00701 float w, h; 00702 //float alpha; 00703 GLint scissor[4]; 00704 00705 rect.xmin = (float)recti->xmin+1; 00706 rect.xmax = (float)recti->xmax-1; 00707 rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2; 00708 rect.ymax = (float)recti->ymax-1; 00709 00710 w = rect.xmax - rect.xmin; 00711 h = (rect.ymax - rect.ymin) * hist->ymax; 00712 00713 glEnable(GL_BLEND); 00714 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 00715 00716 glColor4f(0.f, 0.f, 0.f, 0.3f); 00717 uiSetRoundBox(UI_CNR_ALL); 00718 uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f); 00719 00720 /* need scissor test, histogram can draw outside of boundary */ 00721 glGetIntegerv(GL_VIEWPORT, scissor); 00722 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)); 00723 00724 glColor4f(1.f, 1.f, 1.f, 0.08f); 00725 /* draw grid lines here */ 00726 for (i=1; i<4; i++) { 00727 fdrawline(rect.xmin, rect.ymin+(i/4.f)*h, rect.xmax, rect.ymin+(i/4.f)*h); 00728 fdrawline(rect.xmin+(i/4.f)*w, rect.ymin, rect.xmin+(i/4.f)*w, rect.ymax); 00729 } 00730 00731 if (hist->mode == HISTO_MODE_LUMA) 00732 histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res); 00733 else { 00734 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_R) 00735 histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res); 00736 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_G) 00737 histogram_draw_one(0.0, 1.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_g, res); 00738 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_B) 00739 histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res); 00740 } 00741 00742 /* outline, scale gripper */ 00743 draw_scope_end(&rect, scissor); 00744 } 00745 00746 void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti) 00747 { 00748 Scopes *scopes = (Scopes *)but->poin; 00749 rctf rect; 00750 int i, c; 00751 float w, w3, h, alpha, yofs; 00752 GLint scissor[4]; 00753 float colors[3][3]= MAT3_UNITY; 00754 float colorsycc[3][3] = {{1,0,1},{1,1,0},{0,1,1}}; 00755 float colors_alpha[3][3], colorsycc_alpha[3][3]; /* colors pre multiplied by alpha for speed up */ 00756 float min, max; 00757 00758 if (scopes==NULL) return; 00759 00760 rect.xmin = (float)recti->xmin+1; 00761 rect.xmax = (float)recti->xmax-1; 00762 rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2; 00763 rect.ymax = (float)recti->ymax-1; 00764 00765 if (scopes->wavefrm_yfac < 0.5f ) 00766 scopes->wavefrm_yfac =0.98f; 00767 w = rect.xmax - rect.xmin-7; 00768 h = (rect.ymax - rect.ymin)*scopes->wavefrm_yfac; 00769 yofs= rect.ymin + (rect.ymax - rect.ymin -h)/2.0f; 00770 w3=w/3.0f; 00771 00772 /* log scale for alpha */ 00773 alpha = scopes->wavefrm_alpha*scopes->wavefrm_alpha; 00774 00775 for(c=0; c<3; c++) { 00776 for(i=0; i<3; i++) { 00777 colors_alpha[c][i] = colors[c][i] * alpha; 00778 colorsycc_alpha[c][i] = colorsycc[c][i] * alpha; 00779 } 00780 } 00781 00782 glEnable(GL_BLEND); 00783 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 00784 00785 glColor4f(0.f, 0.f, 0.f, 0.3f); 00786 uiSetRoundBox(UI_CNR_ALL); 00787 uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f); 00788 00789 00790 /* need scissor test, waveform can draw outside of boundary */ 00791 glGetIntegerv(GL_VIEWPORT, scissor); 00792 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)); 00793 00794 glColor4f(1.f, 1.f, 1.f, 0.08f); 00795 /* draw grid lines here */ 00796 for (i=0; i<6; i++) { 00797 char str[4]; 00798 BLI_snprintf(str, sizeof(str), "%-3d",i*20); 00799 str[3]='\0'; 00800 fdrawline(rect.xmin+22, yofs+(i/5.f)*h, rect.xmax+1, yofs+(i/5.f)*h); 00801 BLF_draw_default(rect.xmin+1, yofs-5+(i/5.f)*h, 0, str, sizeof(str)-1); 00802 /* in the loop because blf_draw reset it */ 00803 glEnable(GL_BLEND); 00804 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 00805 } 00806 /* 3 vertical separation */ 00807 if (scopes->wavefrm_mode!= SCOPES_WAVEFRM_LUMA) { 00808 for (i=1; i<3; i++) { 00809 fdrawline(rect.xmin+i*w3, rect.ymin, rect.xmin+i*w3, rect.ymax); 00810 } 00811 } 00812 00813 /* separate min max zone on the right */ 00814 fdrawline(rect.xmin+w, rect.ymin, rect.xmin+w, rect.ymax); 00815 /* 16-235-240 level in case of ITU-R BT601/709 */ 00816 glColor4f(1.f, 0.4f, 0.f, 0.2f); 00817 if (ELEM(scopes->wavefrm_mode, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_709)){ 00818 fdrawline(rect.xmin+22, yofs+h*16.0f/255.0f, rect.xmax+1, yofs+h*16.0f/255.0f); 00819 fdrawline(rect.xmin+22, yofs+h*235.0f/255.0f, rect.xmin+w3, yofs+h*235.0f/255.0f); 00820 fdrawline(rect.xmin+3*w3, yofs+h*235.0f/255.0f, rect.xmax+1, yofs+h*235.0f/255.0f); 00821 fdrawline(rect.xmin+w3, yofs+h*240.0f/255.0f, rect.xmax+1, yofs+h*240.0f/255.0f); 00822 } 00823 /* 7.5 IRE black point level for NTSC */ 00824 if (scopes->wavefrm_mode== SCOPES_WAVEFRM_LUMA) 00825 fdrawline(rect.xmin, yofs+h*0.075f, rect.xmax+1, yofs+h*0.075f); 00826 00827 if (scopes->ok && scopes->waveform_1 != NULL) { 00828 00829 /* LUMA (1 channel) */ 00830 glBlendFunc(GL_ONE,GL_ONE); 00831 glColor3f(alpha, alpha, alpha); 00832 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA){ 00833 00834 glBlendFunc(GL_ONE,GL_ONE); 00835 00836 glPushMatrix(); 00837 glEnableClientState(GL_VERTEX_ARRAY); 00838 00839 glTranslatef(rect.xmin, yofs, 0.f); 00840 glScalef(w, h, 0.f); 00841 glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1); 00842 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); 00843 00844 glDisableClientState(GL_VERTEX_ARRAY); 00845 glPopMatrix(); 00846 00847 /* min max */ 00848 glColor3f(.5f, .5f, .5f); 00849 min= yofs+scopes->minmax[0][0]*h; 00850 max= yofs+scopes->minmax[0][1]*h; 00851 CLAMP(min, rect.ymin, rect.ymax); 00852 CLAMP(max, rect.ymin, rect.ymax); 00853 fdrawline(rect.xmax-3,min,rect.xmax-3,max); 00854 } 00855 00856 /* RGB / YCC (3 channels) */ 00857 else if (ELEM4(scopes->wavefrm_mode, SCOPES_WAVEFRM_RGB, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_709, SCOPES_WAVEFRM_YCC_JPEG)) { 00858 int rgb = (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB); 00859 00860 glBlendFunc(GL_ONE,GL_ONE); 00861 00862 glPushMatrix(); 00863 glEnableClientState(GL_VERTEX_ARRAY); 00864 00865 glTranslatef(rect.xmin, yofs, 0.f); 00866 glScalef(w3, h, 0.f); 00867 00868 glColor3fv((rgb)?colors_alpha[0]:colorsycc_alpha[0]); 00869 glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1); 00870 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); 00871 00872 glTranslatef(1.f, 0.f, 0.f); 00873 glColor3fv((rgb)?colors_alpha[1]:colorsycc_alpha[1]); 00874 glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_2); 00875 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); 00876 00877 glTranslatef(1.f, 0.f, 0.f); 00878 glColor3fv((rgb)?colors_alpha[2]:colorsycc_alpha[2]); 00879 glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_3); 00880 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); 00881 00882 glDisableClientState(GL_VERTEX_ARRAY); 00883 glPopMatrix(); 00884 00885 00886 /* min max */ 00887 for (c=0; c<3; c++) { 00888 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB) 00889 glColor3f(colors[c][0]*0.75f, colors[c][1]*0.75f, colors[c][2]*0.75f); 00890 else 00891 glColor3f(colorsycc[c][0]*0.75f, colorsycc[c][1]*0.75f, colorsycc[c][2]*0.75f); 00892 min= yofs+scopes->minmax[c][0]*h; 00893 max= yofs+scopes->minmax[c][1]*h; 00894 CLAMP(min, rect.ymin, rect.ymax); 00895 CLAMP(max, rect.ymin, rect.ymax); 00896 fdrawline(rect.xmin+w+2+c*2,min,rect.xmin+w+2+c*2,max); 00897 } 00898 } 00899 00900 } 00901 00902 /* outline, scale gripper */ 00903 draw_scope_end(&rect, scissor); 00904 } 00905 00906 static float polar_to_x(float center, float diam, float ampli, float angle) 00907 { 00908 return center + diam * ampli * cosf(angle); 00909 } 00910 00911 static float polar_to_y(float center, float diam, float ampli, float angle) 00912 { 00913 return center + diam * ampli * sinf(angle); 00914 } 00915 00916 static void vectorscope_draw_target(float centerx, float centery, float diam, const float colf[3]) 00917 { 00918 float y,u,v; 00919 float tangle=0.f, tampli; 00920 float dangle, dampli, dangle2, dampli2; 00921 00922 rgb_to_yuv(colf[0], colf[1], colf[2], &y, &u, &v); 00923 if (u>0 && v>=0) tangle=atanf(v/u); 00924 else if (u>0 && v<0) tangle= atanf(v/u) + 2.0f * (float)M_PI; 00925 else if (u<0) tangle=atanf(v/u) + (float)M_PI; 00926 else if (u==0 && v > 0.0f) tangle= (float)M_PI/2.0f; 00927 else if (u==0 && v < 0.0f) tangle=-(float)M_PI/2.0f; 00928 tampli= sqrtf(u*u+v*v); 00929 00930 /* small target vary by 2.5 degree and 2.5 IRE unit */ 00931 glColor4f(1.0f, 1.0f, 1.0, 0.12f); 00932 dangle= DEG2RADF(2.5f); 00933 dampli= 2.5f/200.0f; 00934 glBegin(GL_LINE_STRIP); 00935 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle), polar_to_y(centery,diam,tampli+dampli,tangle+dangle)); 00936 glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle+dangle), polar_to_y(centery,diam,tampli-dampli,tangle+dangle)); 00937 glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle-dangle), polar_to_y(centery,diam,tampli-dampli,tangle-dangle)); 00938 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle-dangle), polar_to_y(centery,diam,tampli+dampli,tangle-dangle)); 00939 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle), polar_to_y(centery,diam,tampli+dampli,tangle+dangle)); 00940 glEnd(); 00941 /* big target vary by 10 degree and 20% amplitude */ 00942 glColor4f(1.0f, 1.0f, 1.0, 0.12f); 00943 dangle= DEG2RADF(10.0f); 00944 dampli= 0.2f*tampli; 00945 dangle2= DEG2RADF(5.0f); 00946 dampli2= 0.5f*dampli; 00947 glBegin(GL_LINE_STRIP); 00948 glVertex2f(polar_to_x(centerx,diam,tampli+dampli-dampli2,tangle+dangle), polar_to_y(centery,diam,tampli+dampli-dampli2,tangle+dangle)); 00949 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle), polar_to_y(centery,diam,tampli+dampli,tangle+dangle)); 00950 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle-dangle2), polar_to_y(centery,diam,tampli+dampli,tangle+dangle-dangle2)); 00951 glEnd(); 00952 glBegin(GL_LINE_STRIP); 00953 glVertex2f(polar_to_x(centerx,diam,tampli-dampli+dampli2,tangle+dangle), polar_to_y(centery ,diam,tampli-dampli+dampli2,tangle+dangle)); 00954 glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle+dangle), polar_to_y(centery,diam,tampli-dampli,tangle+dangle)); 00955 glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle+dangle-dangle2), polar_to_y(centery,diam,tampli-dampli,tangle+dangle-dangle2)); 00956 glEnd(); 00957 glBegin(GL_LINE_STRIP); 00958 glVertex2f(polar_to_x(centerx,diam,tampli-dampli+dampli2,tangle-dangle), polar_to_y(centery,diam,tampli-dampli+dampli2,tangle-dangle)); 00959 glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle-dangle), polar_to_y(centery,diam,tampli-dampli,tangle-dangle)); 00960 glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle-dangle+dangle2), polar_to_y(centery,diam,tampli-dampli,tangle-dangle+dangle2)); 00961 glEnd(); 00962 glBegin(GL_LINE_STRIP); 00963 glVertex2f(polar_to_x(centerx,diam,tampli+dampli-dampli2,tangle-dangle), polar_to_y(centery,diam,tampli+dampli-dampli2,tangle-dangle)); 00964 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle-dangle), polar_to_y(centery,diam,tampli+dampli,tangle-dangle)); 00965 glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle-dangle+dangle2), polar_to_y(centery,diam,tampli+dampli,tangle-dangle+dangle2)); 00966 glEnd(); 00967 } 00968 00969 void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti) 00970 { 00971 const float skin_rad= DEG2RADF(123.0f); /* angle in radians of the skin tone line */ 00972 Scopes *scopes = (Scopes *)but->poin; 00973 rctf rect; 00974 int i, j; 00975 float w, h, centerx, centery, diam; 00976 float alpha; 00977 const float colors[6][3]={{.75,0,0},{.75,.75,0},{0,.75,0},{0,.75,.75},{0,0,.75},{.75,0,.75}}; 00978 GLint scissor[4]; 00979 00980 rect.xmin = (float)recti->xmin+1; 00981 rect.xmax = (float)recti->xmax-1; 00982 rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2; 00983 rect.ymax = (float)recti->ymax-1; 00984 00985 w = rect.xmax - rect.xmin; 00986 h = rect.ymax - rect.ymin; 00987 centerx = rect.xmin + w/2; 00988 centery = rect.ymin + h/2; 00989 diam= (w<h)?w:h; 00990 00991 alpha = scopes->vecscope_alpha*scopes->vecscope_alpha*scopes->vecscope_alpha; 00992 00993 glEnable(GL_BLEND); 00994 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 00995 00996 glColor4f(0.f, 0.f, 0.f, 0.3f); 00997 uiSetRoundBox(UI_CNR_ALL); 00998 uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f); 00999 01000 /* need scissor test, hvectorscope can draw outside of boundary */ 01001 glGetIntegerv(GL_VIEWPORT, scissor); 01002 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)); 01003 01004 glColor4f(1.f, 1.f, 1.f, 0.08f); 01005 /* draw grid elements */ 01006 /* cross */ 01007 fdrawline(centerx - (diam/2)-5, centery, centerx + (diam/2)+5, centery); 01008 fdrawline(centerx, centery - (diam/2)-5, centerx, centery + (diam/2)+5); 01009 /* circles */ 01010 for(j=0; j<5; j++) { 01011 glBegin(GL_LINE_STRIP); 01012 for(i=0; i<=360; i=i+15) { 01013 const float a= DEG2RADF((float)i); 01014 const float r= (j+1)/10.0f; 01015 glVertex2f(polar_to_x(centerx,diam,r,a), polar_to_y(centery,diam,r,a)); 01016 } 01017 glEnd(); 01018 } 01019 /* skin tone line */ 01020 glColor4f(1.f, 0.4f, 0.f, 0.2f); 01021 fdrawline(polar_to_x(centerx, diam, 0.5f, skin_rad), polar_to_y(centery,diam,0.5,skin_rad), 01022 polar_to_x(centerx, diam, 0.1f, skin_rad), polar_to_y(centery,diam,0.1,skin_rad)); 01023 /* saturation points */ 01024 for(i=0; i<6; i++) 01025 vectorscope_draw_target(centerx, centery, diam, colors[i]); 01026 01027 if (scopes->ok && scopes->vecscope != NULL) { 01028 /* pixel point cloud */ 01029 glBlendFunc(GL_ONE,GL_ONE); 01030 glColor3f(alpha, alpha, alpha); 01031 01032 glPushMatrix(); 01033 glEnableClientState(GL_VERTEX_ARRAY); 01034 01035 glTranslatef(centerx, centery, 0.f); 01036 glScalef(diam, diam, 0.f); 01037 01038 glVertexPointer(2, GL_FLOAT, 0, scopes->vecscope); 01039 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); 01040 01041 glDisableClientState(GL_VERTEX_ARRAY); 01042 glPopMatrix(); 01043 } 01044 01045 /* outline, scale gripper */ 01046 draw_scope_end(&rect, scissor); 01047 01048 glDisable(GL_BLEND); 01049 } 01050 01051 void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect) 01052 { 01053 ColorBand *coba; 01054 CBData *cbd; 01055 float x1, y1, sizex, sizey; 01056 float v3[2], v1[2], v2[2], v1a[2], v2a[2]; 01057 int a; 01058 float pos, colf[4]= {0,0,0,0}; /* initialize incase the colorband isnt valid */ 01059 01060 coba= (ColorBand *)(but->editcoba? but->editcoba: but->poin); 01061 if(coba==NULL) return; 01062 01063 x1= rect->xmin; 01064 y1= rect->ymin; 01065 sizex= rect->xmax-x1; 01066 sizey= rect->ymax-y1; 01067 01068 /* first background, to show tranparency */ 01069 01070 glColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255); 01071 glRectf(x1, y1, x1+sizex, y1+sizey); 01072 glEnable(GL_POLYGON_STIPPLE); 01073 glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255); 01074 glPolygonStipple(checker_stipple_sml); 01075 glRectf(x1, y1, x1+sizex, y1+sizey); 01076 glDisable(GL_POLYGON_STIPPLE); 01077 01078 glShadeModel(GL_FLAT); 01079 glEnable(GL_BLEND); 01080 01081 cbd= coba->data; 01082 01083 v1[0]= v2[0]= x1; 01084 v1[1]= y1; 01085 v2[1]= y1+sizey; 01086 01087 glBegin(GL_QUAD_STRIP); 01088 01089 glColor4fv( &cbd->r ); 01090 glVertex2fv(v1); glVertex2fv(v2); 01091 01092 for( a = 1; a <= sizex; a++ ) { 01093 pos = ((float)a) / (sizex-1); 01094 do_colorband( coba, pos, colf ); 01095 if (but->block->color_profile != BLI_PR_NONE) 01096 linearrgb_to_srgb_v3_v3(colf, colf); 01097 01098 v1[0]=v2[0]= x1 + a; 01099 01100 glColor4fv( colf ); 01101 glVertex2fv(v1); glVertex2fv(v2); 01102 } 01103 01104 glEnd(); 01105 glShadeModel(GL_FLAT); 01106 glDisable(GL_BLEND); 01107 01108 /* outline */ 01109 glColor4f(0.0, 0.0, 0.0, 1.0); 01110 fdrawbox(x1, y1, x1+sizex, y1+sizey); 01111 01112 /* help lines */ 01113 v1[0]= v2[0]=v3[0]= x1; 01114 v1[1]= y1; 01115 v1a[1]= y1+0.25f*sizey; 01116 v2[1]= y1+0.5f*sizey; 01117 v2a[1]= y1+0.75f*sizey; 01118 v3[1]= y1+sizey; 01119 01120 01121 cbd= coba->data; 01122 glBegin(GL_LINES); 01123 for(a=0; a<coba->tot; a++, cbd++) { 01124 v1[0]=v2[0]=v3[0]=v1a[0]=v2a[0]= x1+ cbd->pos*sizex; 01125 01126 if(a==coba->cur) { 01127 glColor3ub(0, 0, 0); 01128 glVertex2fv(v1); 01129 glVertex2fv(v3); 01130 glEnd(); 01131 01132 setlinestyle(2); 01133 glBegin(GL_LINES); 01134 glColor3ub(255, 255, 255); 01135 glVertex2fv(v1); 01136 glVertex2fv(v3); 01137 glEnd(); 01138 setlinestyle(0); 01139 glBegin(GL_LINES); 01140 01141 /* glColor3ub(0, 0, 0); 01142 glVertex2fv(v1); 01143 glVertex2fv(v1a); 01144 glColor3ub(255, 255, 255); 01145 glVertex2fv(v1a); 01146 glVertex2fv(v2); 01147 glColor3ub(0, 0, 0); 01148 glVertex2fv(v2); 01149 glVertex2fv(v2a); 01150 glColor3ub(255, 255, 255); 01151 glVertex2fv(v2a); 01152 glVertex2fv(v3); 01153 */ 01154 } 01155 else { 01156 glColor3ub(0, 0, 0); 01157 glVertex2fv(v1); 01158 glVertex2fv(v2); 01159 01160 glColor3ub(255, 255, 255); 01161 glVertex2fv(v2); 01162 glVertex2fv(v3); 01163 } 01164 } 01165 glEnd(); 01166 01167 } 01168 01169 void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, rcti *rect) 01170 { 01171 static GLuint displist=0; 01172 int a, old[8]; 01173 GLfloat diff[4], diffn[4]={1.0f, 1.0f, 1.0f, 1.0f}; 01174 float vec0[4]={0.0f, 0.0f, 0.0f, 0.0f}; 01175 float dir[4], size; 01176 01177 /* store stuff */ 01178 glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff); 01179 01180 /* backdrop */ 01181 glColor3ubv((unsigned char*)wcol->inner); 01182 uiSetRoundBox(UI_CNR_ALL); 01183 uiDrawBox(GL_POLYGON, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f); 01184 01185 /* sphere color */ 01186 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffn); 01187 glCullFace(GL_BACK); glEnable(GL_CULL_FACE); 01188 01189 /* disable blender light */ 01190 for(a=0; a<8; a++) { 01191 old[a]= glIsEnabled(GL_LIGHT0+a); 01192 glDisable(GL_LIGHT0+a); 01193 } 01194 01195 /* own light */ 01196 glEnable(GL_LIGHT7); 01197 glEnable(GL_LIGHTING); 01198 01199 ui_get_but_vectorf(but, dir); 01200 01201 dir[3]= 0.0f; /* glLight needs 4 args, 0.0 is sun */ 01202 glLightfv(GL_LIGHT7, GL_POSITION, dir); 01203 glLightfv(GL_LIGHT7, GL_DIFFUSE, diffn); 01204 glLightfv(GL_LIGHT7, GL_SPECULAR, vec0); 01205 glLightf(GL_LIGHT7, GL_CONSTANT_ATTENUATION, 1.0f); 01206 glLightf(GL_LIGHT7, GL_LINEAR_ATTENUATION, 0.0f); 01207 01208 /* transform to button */ 01209 glPushMatrix(); 01210 glTranslatef(rect->xmin + 0.5f*(rect->xmax-rect->xmin), rect->ymin+ 0.5f*(rect->ymax-rect->ymin), 0.0f); 01211 01212 if( rect->xmax-rect->xmin < rect->ymax-rect->ymin) 01213 size= (rect->xmax-rect->xmin)/200.f; 01214 else 01215 size= (rect->ymax-rect->ymin)/200.f; 01216 01217 glScalef(size, size, size); 01218 01219 if(displist==0) { 01220 GLUquadricObj *qobj; 01221 01222 displist= glGenLists(1); 01223 glNewList(displist, GL_COMPILE_AND_EXECUTE); 01224 01225 qobj= gluNewQuadric(); 01226 gluQuadricDrawStyle(qobj, GLU_FILL); 01227 glShadeModel(GL_SMOOTH); 01228 gluSphere( qobj, 100.0, 32, 24); 01229 glShadeModel(GL_FLAT); 01230 gluDeleteQuadric(qobj); 01231 01232 glEndList(); 01233 } 01234 else glCallList(displist); 01235 01236 /* restore */ 01237 glDisable(GL_LIGHTING); 01238 glDisable(GL_CULL_FACE); 01239 glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); 01240 glDisable(GL_LIGHT7); 01241 01242 /* AA circle */ 01243 glEnable(GL_BLEND); 01244 glEnable(GL_LINE_SMOOTH ); 01245 glColor3ubv((unsigned char*)wcol->inner); 01246 glutil_draw_lined_arc(0.0f, M_PI*2.0, 100.0f, 32); 01247 glDisable(GL_BLEND); 01248 glDisable(GL_LINE_SMOOTH ); 01249 01250 /* matrix after circle */ 01251 glPopMatrix(); 01252 01253 /* enable blender light */ 01254 for(a=0; a<8; a++) { 01255 if(old[a]) 01256 glEnable(GL_LIGHT0+a); 01257 } 01258 } 01259 01260 static void ui_draw_but_curve_grid(rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step) 01261 { 01262 float dx, dy, fx, fy; 01263 01264 glBegin(GL_LINES); 01265 dx= step*zoomx; 01266 fx= rect->xmin + zoomx*(-offsx); 01267 if(fx > rect->xmin) fx -= dx*(floorf(fx-rect->xmin)); 01268 while(fx < rect->xmax) { 01269 glVertex2f(fx, rect->ymin); 01270 glVertex2f(fx, rect->ymax); 01271 fx+= dx; 01272 } 01273 01274 dy= step*zoomy; 01275 fy= rect->ymin + zoomy*(-offsy); 01276 if(fy > rect->ymin) fy -= dy*(floorf(fy-rect->ymin)); 01277 while(fy < rect->ymax) { 01278 glVertex2f(rect->xmin, fy); 01279 glVertex2f(rect->xmax, fy); 01280 fy+= dy; 01281 } 01282 glEnd(); 01283 01284 } 01285 01286 static void glColor3ubvShade(unsigned char *col, int shade) 01287 { 01288 glColor3ub(col[0]-shade>0?col[0]-shade:0, 01289 col[1]-shade>0?col[1]-shade:0, 01290 col[2]-shade>0?col[2]-shade:0); 01291 } 01292 01293 void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect) 01294 { 01295 CurveMapping *cumap; 01296 CurveMap *cuma; 01297 CurveMapPoint *cmp; 01298 float fx, fy, fac[2], zoomx, zoomy, offsx, offsy; 01299 GLint scissor[4]; 01300 rcti scissor_new; 01301 int a; 01302 01303 cumap= (CurveMapping *)(but->editcumap? but->editcumap: but->poin); 01304 cuma= cumap->cm+cumap->cur; 01305 01306 /* need scissor test, curve can draw outside of boundary */ 01307 glGetIntegerv(GL_VIEWPORT, scissor); 01308 scissor_new.xmin= ar->winrct.xmin + rect->xmin; 01309 scissor_new.ymin= ar->winrct.ymin + rect->ymin; 01310 scissor_new.xmax= ar->winrct.xmin + rect->xmax; 01311 scissor_new.ymax= ar->winrct.ymin + rect->ymax; 01312 BLI_isect_rcti(&scissor_new, &ar->winrct, &scissor_new); 01313 glScissor(scissor_new.xmin, scissor_new.ymin, scissor_new.xmax-scissor_new.xmin, scissor_new.ymax-scissor_new.ymin); 01314 01315 /* calculate offset and zoom */ 01316 zoomx= (rect->xmax-rect->xmin-2.0f*but->aspect)/(cumap->curr.xmax - cumap->curr.xmin); 01317 zoomy= (rect->ymax-rect->ymin-2.0f*but->aspect)/(cumap->curr.ymax - cumap->curr.ymin); 01318 offsx= cumap->curr.xmin-but->aspect/zoomx; 01319 offsy= cumap->curr.ymin-but->aspect/zoomy; 01320 01321 /* backdrop */ 01322 if(cumap->flag & CUMA_DO_CLIP) { 01323 glColor3ubvShade((unsigned char *)wcol->inner, -20); 01324 glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); 01325 glColor3ubv((unsigned char*)wcol->inner); 01326 glRectf(rect->xmin + zoomx*(cumap->clipr.xmin-offsx), 01327 rect->ymin + zoomy*(cumap->clipr.ymin-offsy), 01328 rect->xmin + zoomx*(cumap->clipr.xmax-offsx), 01329 rect->ymin + zoomy*(cumap->clipr.ymax-offsy)); 01330 } 01331 else { 01332 glColor3ubv((unsigned char*)wcol->inner); 01333 glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); 01334 } 01335 01336 /* grid, every .25 step */ 01337 glColor3ubvShade((unsigned char *)wcol->inner, -16); 01338 ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.25f); 01339 /* grid, every 1.0 step */ 01340 glColor3ubvShade((unsigned char *)wcol->inner, -24); 01341 ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 1.0f); 01342 /* axes */ 01343 glColor3ubvShade((unsigned char *)wcol->inner, -50); 01344 glBegin(GL_LINES); 01345 glVertex2f(rect->xmin, rect->ymin + zoomy*(-offsy)); 01346 glVertex2f(rect->xmax, rect->ymin + zoomy*(-offsy)); 01347 glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymin); 01348 glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymax); 01349 glEnd(); 01350 01351 /* magic trigger for curve backgrounds */ 01352 if (but->a1 != -1) { 01353 if (but->a1 == UI_GRAD_H) { 01354 rcti grid; 01355 float col[3]= {0.0f, 0.0f, 0.0f}; /* dummy arg */ 01356 01357 grid.xmin = rect->xmin + zoomx*(-offsx); 01358 grid.xmax = rect->xmax + zoomx*(-offsx); 01359 grid.ymin = rect->ymin + zoomy*(-offsy); 01360 grid.ymax = rect->ymax + zoomy*(-offsy); 01361 01362 glEnable(GL_BLEND); 01363 ui_draw_gradient(&grid, col, UI_GRAD_H, 0.5f); 01364 glDisable(GL_BLEND); 01365 } 01366 } 01367 01368 01369 /* cfra option */ 01370 /* XXX 2.48 01371 if(cumap->flag & CUMA_DRAW_CFRA) { 01372 glColor3ub(0x60, 0xc0, 0x40); 01373 glBegin(GL_LINES); 01374 glVertex2f(rect->xmin + zoomx*(cumap->sample[0]-offsx), rect->ymin); 01375 glVertex2f(rect->xmin + zoomx*(cumap->sample[0]-offsx), rect->ymax); 01376 glEnd(); 01377 }*/ 01378 /* sample option */ 01379 /* XXX 2.48 01380 * if(cumap->flag & CUMA_DRAW_SAMPLE) { 01381 if(cumap->cur==3) { 01382 float lum= cumap->sample[0]*0.35f + cumap->sample[1]*0.45f + cumap->sample[2]*0.2f; 01383 glColor3ub(240, 240, 240); 01384 01385 glBegin(GL_LINES); 01386 glVertex2f(rect->xmin + zoomx*(lum-offsx), rect->ymin); 01387 glVertex2f(rect->xmin + zoomx*(lum-offsx), rect->ymax); 01388 glEnd(); 01389 } 01390 else { 01391 if(cumap->cur==0) 01392 glColor3ub(240, 100, 100); 01393 else if(cumap->cur==1) 01394 glColor3ub(100, 240, 100); 01395 else 01396 glColor3ub(100, 100, 240); 01397 01398 glBegin(GL_LINES); 01399 glVertex2f(rect->xmin + zoomx*(cumap->sample[cumap->cur]-offsx), rect->ymin); 01400 glVertex2f(rect->xmin + zoomx*(cumap->sample[cumap->cur]-offsx), rect->ymax); 01401 glEnd(); 01402 } 01403 }*/ 01404 01405 /* the curve */ 01406 glColor3ubv((unsigned char*)wcol->item); 01407 glEnable(GL_LINE_SMOOTH); 01408 glEnable(GL_BLEND); 01409 glBegin(GL_LINE_STRIP); 01410 01411 if(cuma->table==NULL) 01412 curvemapping_changed(cumap, 0); /* 0 = no remove doubles */ 01413 cmp= cuma->table; 01414 01415 /* first point */ 01416 if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0) 01417 glVertex2f(rect->xmin, rect->ymin + zoomy*(cmp[0].y-offsy)); 01418 else { 01419 fx= rect->xmin + zoomx*(cmp[0].x-offsx + cuma->ext_in[0]); 01420 fy= rect->ymin + zoomy*(cmp[0].y-offsy + cuma->ext_in[1]); 01421 glVertex2f(fx, fy); 01422 } 01423 for(a=0; a<=CM_TABLE; a++) { 01424 fx= rect->xmin + zoomx*(cmp[a].x-offsx); 01425 fy= rect->ymin + zoomy*(cmp[a].y-offsy); 01426 glVertex2f(fx, fy); 01427 } 01428 /* last point */ 01429 if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0) 01430 glVertex2f(rect->xmax, rect->ymin + zoomy*(cmp[CM_TABLE].y-offsy)); 01431 else { 01432 fx= rect->xmin + zoomx*(cmp[CM_TABLE].x-offsx - cuma->ext_out[0]); 01433 fy= rect->ymin + zoomy*(cmp[CM_TABLE].y-offsy - cuma->ext_out[1]); 01434 glVertex2f(fx, fy); 01435 } 01436 glEnd(); 01437 glDisable(GL_LINE_SMOOTH); 01438 glDisable(GL_BLEND); 01439 01440 /* the points, use aspect to make them visible on edges */ 01441 cmp= cuma->curve; 01442 glPointSize(3.0f); 01443 bglBegin(GL_POINTS); 01444 for(a=0; a<cuma->totpoint; a++) { 01445 if(cmp[a].flag & SELECT) 01446 UI_ThemeColor(TH_TEXT_HI); 01447 else 01448 UI_ThemeColor(TH_TEXT); 01449 fac[0]= rect->xmin + zoomx*(cmp[a].x-offsx); 01450 fac[1]= rect->ymin + zoomy*(cmp[a].y-offsy); 01451 bglVertex2fv(fac); 01452 } 01453 bglEnd(); 01454 glPointSize(1.0f); 01455 01456 /* restore scissortest */ 01457 glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); 01458 01459 /* outline */ 01460 glColor3ubv((unsigned char*)wcol->outline); 01461 fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax); 01462 } 01463 01464 static ImBuf *scale_trackpreview_ibuf(ImBuf *ibuf, float zoomx, float zoomy) 01465 { 01466 ImBuf *scaleibuf; 01467 int x, y, w= ibuf->x*zoomx, h= ibuf->y*zoomy; 01468 const float scalex= 1.0f/zoomx; 01469 const float scaley= 1.0f/zoomy; 01470 01471 scaleibuf= IMB_allocImBuf(w, h, 32, IB_rect); 01472 01473 for(y= 0; y<h; y++) { 01474 for (x= 0; x<w; x++) { 01475 float src_x= scalex*x; 01476 float src_y= scaley*y; 01477 01478 bicubic_interpolation(ibuf, scaleibuf, src_x, src_y, x, y); 01479 } 01480 } 01481 01482 return scaleibuf; 01483 } 01484 01485 void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti) 01486 { 01487 rctf rect; 01488 int ok= 0; 01489 GLint scissor[4]; 01490 MovieClipScopes *scopes = (MovieClipScopes *)but->poin; 01491 01492 rect.xmin = (float)recti->xmin+1; 01493 rect.xmax = (float)recti->xmax-1; 01494 rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2; 01495 rect.ymax = (float)recti->ymax-1; 01496 01497 glEnable(GL_BLEND); 01498 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 01499 01500 /* need scissor test, preview image can draw outside of boundary */ 01501 glGetIntegerv(GL_VIEWPORT, scissor); 01502 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)); 01503 01504 if(scopes->track_disabled) { 01505 glColor4f(0.7f, 0.3f, 0.3f, 0.3f); 01506 uiSetRoundBox(15); 01507 uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f); 01508 01509 ok= 1; 01510 } 01511 else if(scopes->track_preview) { 01512 /* additional margin around image */ 01513 /* NOTE: should be kept in sync with value from BKE_movieclip_update_scopes */ 01514 const int margin= 3; 01515 float zoomx, zoomy, track_pos[2], off_x, off_y, x0, y0; 01516 int a; 01517 ImBuf *drawibuf; 01518 01519 glPushMatrix(); 01520 01521 track_pos[0]= scopes->track_pos[0]-margin; 01522 track_pos[1]= scopes->track_pos[1]-margin; 01523 01524 /* draw content of pattern area */ 01525 glScissor(ar->winrct.xmin+rect.xmin, ar->winrct.ymin+rect.ymin, scissor[2], scissor[3]); 01526 01527 zoomx= (rect.xmax-rect.xmin) / (scopes->track_preview->x-2*margin); 01528 zoomy= (rect.ymax-rect.ymin) / (scopes->track_preview->y-2*margin); 01529 01530 off_x= ((int)track_pos[0]-track_pos[0]+0.5)*zoomx; 01531 off_y= ((int)track_pos[1]-track_pos[1]+0.5)*zoomy; 01532 x0= (int)(off_x+rect.xmin-zoomx*(margin-0.5f))+1; 01533 y0= (int)(off_y+rect.ymin-zoomy*(margin-0.5f))+1; 01534 01535 drawibuf= scale_trackpreview_ibuf(scopes->track_preview, zoomx, zoomy); 01536 glaDrawPixelsSafe(x0, y0, rect.xmax-x0+1, rect.ymax-y0+1, 01537 drawibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, drawibuf->rect); 01538 IMB_freeImBuf(drawibuf); 01539 01540 /* draw cross for pizel position */ 01541 glTranslatef(off_x+rect.xmin+track_pos[0]*zoomx, off_y+rect.ymin+track_pos[1]*zoomy, 0.f); 01542 glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin+rect.ymin, rect.xmax-rect.xmin, rect.ymax-rect.ymin); 01543 01544 for(a= 0; a< 2; a++) { 01545 if(a==1) { 01546 glLineStipple(3, 0xaaaa); 01547 glEnable(GL_LINE_STIPPLE); 01548 UI_ThemeColor(TH_SEL_MARKER); 01549 } 01550 else { 01551 UI_ThemeColor(TH_MARKER_OUTLINE); 01552 } 01553 01554 glBegin(GL_LINES); 01555 glVertex2f(-10.0f, 0.0f); 01556 glVertex2f(10.0f, 0.0f); 01557 glVertex2f(0.0f, -10.0f); 01558 glVertex2f(0.0f, 10.0f); 01559 glEnd(); 01560 } 01561 01562 glDisable(GL_LINE_STIPPLE); 01563 glPopMatrix(); 01564 01565 ok= 1; 01566 } 01567 01568 if(!ok) { 01569 glColor4f(0.f, 0.f, 0.f, 0.3f); 01570 uiSetRoundBox(15); 01571 uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f); 01572 } 01573 01574 /* outline, scale gripper */ 01575 draw_scope_end(&rect, scissor); 01576 01577 glDisable(GL_BLEND); 01578 } 01579 01580 /* ****************************************************** */ 01581 01582 01583 static void ui_shadowbox(float minx, float miny, float maxx, float maxy, float shadsize, unsigned char alpha) 01584 { 01585 glEnable(GL_BLEND); 01586 glShadeModel(GL_SMOOTH); 01587 01588 /* right quad */ 01589 glBegin(GL_POLYGON); 01590 glColor4ub(0, 0, 0, alpha); 01591 glVertex2f(maxx, miny); 01592 glVertex2f(maxx, maxy-0.3f*shadsize); 01593 glColor4ub(0, 0, 0, 0); 01594 glVertex2f(maxx+shadsize, maxy-0.75f*shadsize); 01595 glVertex2f(maxx+shadsize, miny); 01596 glEnd(); 01597 01598 /* corner shape */ 01599 glBegin(GL_POLYGON); 01600 glColor4ub(0, 0, 0, alpha); 01601 glVertex2f(maxx, miny); 01602 glColor4ub(0, 0, 0, 0); 01603 glVertex2f(maxx+shadsize, miny); 01604 glVertex2f(maxx+0.7f*shadsize, miny-0.7f*shadsize); 01605 glVertex2f(maxx, miny-shadsize); 01606 glEnd(); 01607 01608 /* bottom quad */ 01609 glBegin(GL_POLYGON); 01610 glColor4ub(0, 0, 0, alpha); 01611 glVertex2f(minx+0.3f*shadsize, miny); 01612 glVertex2f(maxx, miny); 01613 glColor4ub(0, 0, 0, 0); 01614 glVertex2f(maxx, miny-shadsize); 01615 glVertex2f(minx+0.5f*shadsize, miny-shadsize); 01616 glEnd(); 01617 01618 glDisable(GL_BLEND); 01619 glShadeModel(GL_FLAT); 01620 } 01621 01622 void uiDrawBoxShadow(unsigned char alpha, float minx, float miny, float maxx, float maxy) 01623 { 01624 /* accumulated outline boxes to make shade not linear, is more pleasant */ 01625 ui_shadowbox(minx, miny, maxx, maxy, 11.0, (20*alpha)>>8); 01626 ui_shadowbox(minx, miny, maxx, maxy, 7.0, (40*alpha)>>8); 01627 ui_shadowbox(minx, miny, maxx, maxy, 5.0, (80*alpha)>>8); 01628 01629 } 01630 01631 01632 void ui_dropshadow(rctf *rct, float radius, float aspect, int UNUSED(select)) 01633 { 01634 int i; 01635 float rad; 01636 float a; 01637 char alpha= 2; 01638 01639 glEnable(GL_BLEND); 01640 01641 if(radius > (rct->ymax-rct->ymin-10.0f)/2.0f) 01642 rad= (rct->ymax-rct->ymin-10.0f)/2.0f; 01643 else 01644 rad= radius; 01645 01646 i= 12; 01647 #if 0 01648 if(select) { 01649 a= i*aspect; /* same as below */ 01650 } 01651 else 01652 #endif 01653 { 01654 a= i*aspect; 01655 } 01656 01657 for(; i--; a-=aspect) { 01658 /* alpha ranges from 2 to 20 or so */ 01659 glColor4ub(0, 0, 0, alpha); 01660 alpha+= 2; 01661 01662 uiDrawBox(GL_POLYGON, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax-10.0f + a, rad+a); 01663 } 01664 01665 /* outline emphasis */ 01666 glEnable( GL_LINE_SMOOTH ); 01667 glColor4ub(0, 0, 0, 100); 01668 uiDrawBox(GL_LINE_LOOP, rct->xmin-0.5f, rct->ymin-0.5f, rct->xmax+0.5f, rct->ymax+0.5f, radius+0.5f); 01669 glDisable( GL_LINE_SMOOTH ); 01670 01671 glDisable(GL_BLEND); 01672 } 01673