2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2009 Blender Foundation.
19 * All rights reserved.
21 * Contributor(s): Blender Foundation
23 * ***** END GPL LICENSE BLOCK *****
32 #include "DNA_screen_types.h"
33 #include "DNA_userdef_types.h"
36 #include "BLI_listbase.h"
38 #include "BLI_string.h"
39 #include "BLI_utildefines.h"
41 #include "BKE_context.h"
42 #include "BKE_curve.h"
43 #include "BKE_utildefines.h"
45 #include "RNA_access.h"
48 #include "BIF_glutil.h"
52 #include "UI_interface.h"
53 #include "UI_interface_icons.h"
56 #include "interface_intern.h"
58 /* ************** widget base functions ************** */
60 - in: roundbox codes for corner types and radius
61 - return: array of [size][2][x,y] points, the edges of the roundbox, + UV coords
63 - draw black box with alpha 0 on exact button boundbox
65 - draw the inner part for a round filled box, with color blend codes or texture coords
66 - draw outline in outline color
67 - draw outer part, bottom half, extruded 1 pixel to bottom, for emboss shadow
68 - draw extra decorations
69 - draw background color box with alpha 1 on exact button boundbox
73 /* fill this struct with polygon info to draw AA'ed */
74 /* it has outline, back, and two optional tria meshes */
76 typedef struct uiWidgetTrias {
84 typedef struct uiWidgetBase {
86 int totvert, halfwayvert;
89 float inner_uv[64][2];
91 short inner, outline, emboss; /* set on/off */
99 /* uiWidgetType: for time being only for visual appearance,
100 later, a handling callback can be added too
102 typedef struct uiWidgetType {
104 /* pointer to theme color definition */
105 uiWidgetColors *wcol_theme;
106 uiWidgetStateColors *wcol_state;
108 /* converted colors for state */
111 void (*state)(struct uiWidgetType *, int state);
112 void (*draw)(uiWidgetColors *, rcti *, int state, int roundboxalign);
113 void (*custom)(uiBut *, uiWidgetColors *, rcti *, int state, int roundboxalign);
114 void (*text)(uiFontStyle *, uiWidgetColors *, uiBut *, rcti *);
119 /* *********************** draw data ************************** */
121 static float cornervec[9][2]= {{0.0, 0.0}, {0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169},
122 {0.707, 0.293}, {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}, {1.0, 1.0}};
124 static float jit[8][2]= {{0.468813 , -0.481430}, {-0.155755 , -0.352820},
125 {0.219306 , -0.238501}, {-0.393286 , -0.110949}, {-0.024699 , 0.013908},
126 {0.343805 , 0.147431}, {-0.272855 , 0.269918}, {0.095909 , 0.388710}};
128 static float num_tria_vert[3][2]= {
129 {-0.352077, 0.532607}, {-0.352077, -0.549313}, {0.330000, -0.008353}};
131 static int num_tria_face[1][3]= {
134 static float scroll_circle_vert[16][2]= {
135 {0.382684, 0.923879}, {0.000001, 1.000000}, {-0.382683, 0.923880}, {-0.707107, 0.707107},
136 {-0.923879, 0.382684}, {-1.000000, 0.000000}, {-0.923880, -0.382684}, {-0.707107, -0.707107},
137 {-0.382683, -0.923880}, {0.000000, -1.000000}, {0.382684, -0.923880}, {0.707107, -0.707107},
138 {0.923880, -0.382684}, {1.000000, -0.000000}, {0.923880, 0.382683}, {0.707107, 0.707107}};
140 static int scroll_circle_face[14][3]= {
141 {0, 1, 2}, {2, 0, 3}, {3, 0, 15}, {3, 15, 4}, {4, 15, 14}, {4, 14, 5}, {5, 14, 13}, {5, 13, 6},
142 {6, 13, 12}, {6, 12, 7}, {7, 12, 11}, {7, 11, 8}, {8, 11, 10}, {8, 10, 9}};
144 static float menu_tria_vert[6][2]= {
145 {-0.41, 0.16}, {0.41, 0.16}, {0, 0.82},
146 {0, -0.82}, {-0.41, -0.16}, {0.41, -0.16}};
148 static int menu_tria_face[2][3]= {{2, 0, 1}, {3, 5, 4}};
150 static float check_tria_vert[6][2]= {
151 {-0.578579, 0.253369}, {-0.392773, 0.412794}, {-0.004241, -0.328551},
152 {-0.003001, 0.034320}, {1.055313, 0.864744}, {0.866408, 1.026895}};
154 static int check_tria_face[4][3]= {
155 {3, 2, 4}, {3, 4, 5}, {1, 0, 3}, {0, 2, 3}};
157 /* ************************************************* */
159 void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3)
165 glGetFloatv(GL_CURRENT_COLOR, color);
169 /* for each AA step */
171 glTranslatef(1.0*jit[j][0], 1.0*jit[j][1], 0.0f);
179 glTranslatef(-1.0*jit[j][0], -1.0*jit[j][1], 0.0f);
186 static void widget_init(uiWidgetBase *wtb)
188 wtb->totvert= wtb->halfwayvert= 0;
198 /* helper call, makes shadow rect, with 'sun' above menu, so only shadow to left/right/bottom */
200 static int round_box_shadow_edges(float (*vert)[2], rcti *rect, float rad, int roundboxalign, float step)
203 float minx, miny, maxx, maxy;
208 if(2.0f*rad > rect->ymax-rect->ymin)
209 rad= 0.5f*(rect->ymax-rect->ymin);
211 minx= rect->xmin-step;
212 miny= rect->ymin-step;
213 maxx= rect->xmax+step;
214 maxy= rect->ymax+step;
218 vec[a][0]= rad*cornervec[a][0];
219 vec[a][1]= rad*cornervec[a][1];
222 /* start with left-top, anti clockwise */
223 if(roundboxalign & 1) {
224 for(a=0; a<9; a++, tot++) {
225 vert[tot][0]= minx+rad-vec[a][0];
226 vert[tot][1]= maxy-vec[a][1];
230 for(a=0; a<9; a++, tot++) {
236 if(roundboxalign & 8) {
237 for(a=0; a<9; a++, tot++) {
238 vert[tot][0]= minx+vec[a][1];
239 vert[tot][1]= miny+rad-vec[a][0];
243 for(a=0; a<9; a++, tot++) {
249 if(roundboxalign & 4) {
250 for(a=0; a<9; a++, tot++) {
251 vert[tot][0]= maxx-rad+vec[a][0];
252 vert[tot][1]= miny+vec[a][1];
256 for(a=0; a<9; a++, tot++) {
262 if(roundboxalign & 2) {
263 for(a=0; a<9; a++, tot++) {
264 vert[tot][0]= maxx-vec[a][1];
265 vert[tot][1]= maxy-rad+vec[a][0];
269 for(a=0; a<9; a++, tot++) {
277 /* this call has 1 extra arg to allow mask outline */
278 static void round_box__edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, float rad, float radi)
280 float vec[9][2], veci[9][2];
281 float minx= rect->xmin, miny= rect->ymin, maxx= rect->xmax, maxy= rect->ymax;
282 float minxi= minx + 1.0f; /* boundbox inner */
283 float maxxi= maxx - 1.0f;
284 float minyi= miny + 1.0f;
285 float maxyi= maxy - 1.0f;
286 float facxi= (maxxi!=minxi) ? 1.0f/(maxxi-minxi) : 0.0f; /* for uv, can divide by zero */
287 float facyi= (maxyi!=minyi) ? 1.0f/(maxyi-minyi) : 0.0f;
288 int a, tot= 0, minsize;
289 const int hnum= ((roundboxalign & (1|2))==(1|2) || (roundboxalign & (4|8))==(4|8)) ? 1 : 2;
290 const int vnum= ((roundboxalign & (1|8))==(1|8) || (roundboxalign & (2|4))==(2|4)) ? 1 : 2;
292 minsize= MIN2((rect->xmax-rect->xmin)*hnum, (rect->ymax-rect->ymin)*vnum);
294 if(2.0f*rad > minsize)
297 if(2.0f*(radi+1.0f) > minsize)
298 radi= 0.5f*minsize - 1.0f;
302 veci[a][0]= radi*cornervec[a][0];
303 veci[a][1]= radi*cornervec[a][1];
304 vec[a][0]= rad*cornervec[a][0];
305 vec[a][1]= rad*cornervec[a][1];
308 /* corner left-bottom */
309 if(roundboxalign & 8) {
311 for(a=0; a<9; a++, tot++) {
312 wt->inner_v[tot][0]= minxi+veci[a][1];
313 wt->inner_v[tot][1]= minyi+radi-veci[a][0];
315 wt->outer_v[tot][0]= minx+vec[a][1];
316 wt->outer_v[tot][1]= miny+rad-vec[a][0];
318 wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
319 wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
323 wt->inner_v[tot][0]= minxi;
324 wt->inner_v[tot][1]= minyi;
326 wt->outer_v[tot][0]= minx;
327 wt->outer_v[tot][1]= miny;
329 wt->inner_uv[tot][0]= 0.0f;
330 wt->inner_uv[tot][1]= 0.0f;
335 /* corner right-bottom */
336 if(roundboxalign & 4) {
338 for(a=0; a<9; a++, tot++) {
339 wt->inner_v[tot][0]= maxxi-radi+veci[a][0];
340 wt->inner_v[tot][1]= minyi+veci[a][1];
342 wt->outer_v[tot][0]= maxx-rad+vec[a][0];
343 wt->outer_v[tot][1]= miny+vec[a][1];
345 wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
346 wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
350 wt->inner_v[tot][0]= maxxi;
351 wt->inner_v[tot][1]= minyi;
353 wt->outer_v[tot][0]= maxx;
354 wt->outer_v[tot][1]= miny;
356 wt->inner_uv[tot][0]= 1.0f;
357 wt->inner_uv[tot][1]= 0.0f;
362 wt->halfwayvert= tot;
364 /* corner right-top */
365 if(roundboxalign & 2) {
367 for(a=0; a<9; a++, tot++) {
368 wt->inner_v[tot][0]= maxxi-veci[a][1];
369 wt->inner_v[tot][1]= maxyi-radi+veci[a][0];
371 wt->outer_v[tot][0]= maxx-vec[a][1];
372 wt->outer_v[tot][1]= maxy-rad+vec[a][0];
374 wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
375 wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
379 wt->inner_v[tot][0]= maxxi;
380 wt->inner_v[tot][1]= maxyi;
382 wt->outer_v[tot][0]= maxx;
383 wt->outer_v[tot][1]= maxy;
385 wt->inner_uv[tot][0]= 1.0f;
386 wt->inner_uv[tot][1]= 1.0f;
391 /* corner left-top */
392 if(roundboxalign & 1) {
394 for(a=0; a<9; a++, tot++) {
395 wt->inner_v[tot][0]= minxi+radi-veci[a][0];
396 wt->inner_v[tot][1]= maxyi-veci[a][1];
398 wt->outer_v[tot][0]= minx+rad-vec[a][0];
399 wt->outer_v[tot][1]= maxy-vec[a][1];
401 wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
402 wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
408 wt->inner_v[tot][0]= minxi;
409 wt->inner_v[tot][1]= maxyi;
411 wt->outer_v[tot][0]= minx;
412 wt->outer_v[tot][1]= maxy;
414 wt->inner_uv[tot][0]= 0.0f;
415 wt->inner_uv[tot][1]= 1.0f;
423 static void round_box_edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, float rad)
425 round_box__edges(wt, roundboxalign, rect, rad, rad-1.0f);
429 /* based on button rect, return scaled array of triangles */
430 static void widget_num_tria(uiWidgetTrias *tria, rcti *rect, float triasize, char where)
432 float centx, centy, sizex, sizey, minsize;
435 minsize= MIN2(rect->xmax-rect->xmin, rect->ymax-rect->ymin);
437 /* center position and size */
438 centx= (float)rect->xmin + 0.5f*minsize;
439 centy= (float)rect->ymin + 0.5f*minsize;
440 sizex= sizey= -0.5f*triasize*minsize;
443 centx= (float)rect->xmax - 0.5f*minsize;
446 else if(where=='t') {
447 centy= (float)rect->ymax - 0.5f*minsize;
451 else if(where=='b') {
457 tria->vec[a][0]= sizex*num_tria_vert[a][i1] + centx;
458 tria->vec[a][1]= sizey*num_tria_vert[a][i2] + centy;
462 tria->index= num_tria_face;
465 static void widget_scroll_circle(uiWidgetTrias *tria, rcti *rect, float triasize, char where)
467 float centx, centy, sizex, sizey, minsize;
470 minsize= MIN2(rect->xmax-rect->xmin, rect->ymax-rect->ymin);
472 /* center position and size */
473 centx= (float)rect->xmin + 0.5f*minsize;
474 centy= (float)rect->ymin + 0.5f*minsize;
475 sizex= sizey= -0.5f*triasize*minsize;
478 centx= (float)rect->xmax - 0.5f*minsize;
481 else if(where=='t') {
482 centy= (float)rect->ymax - 0.5f*minsize;
486 else if(where=='b') {
491 for(a=0; a<16; a++) {
492 tria->vec[a][0]= sizex*scroll_circle_vert[a][i1] + centx;
493 tria->vec[a][1]= sizey*scroll_circle_vert[a][i2] + centy;
497 tria->index= scroll_circle_face;
500 static void widget_trias_draw(uiWidgetTrias *tria)
504 glBegin(GL_TRIANGLES);
505 for(a=0; a<tria->tot; a++) {
506 glVertex2fv(tria->vec[ tria->index[a][0] ]);
507 glVertex2fv(tria->vec[ tria->index[a][1] ]);
508 glVertex2fv(tria->vec[ tria->index[a][2] ]);
514 static void widget_menu_trias(uiWidgetTrias *tria, rcti *rect)
516 float centx, centy, size, asp;
519 /* center position and size */
520 centx= rect->xmax - 0.5f*(rect->ymax-rect->ymin);
521 centy= rect->ymin + 0.5f*(rect->ymax-rect->ymin);
522 size= 0.4f*(rect->ymax-rect->ymin);
525 asp= ((float)rect->xmax-rect->xmin)/((float)rect->ymax-rect->ymin);
526 if(asp > 1.2f && asp < 2.6f)
527 centx= rect->xmax - 0.3f*(rect->ymax-rect->ymin);
530 tria->vec[a][0]= size*menu_tria_vert[a][0] + centx;
531 tria->vec[a][1]= size*menu_tria_vert[a][1] + centy;
535 tria->index= menu_tria_face;
538 static void widget_check_trias(uiWidgetTrias *tria, rcti *rect)
540 float centx, centy, size;
543 /* center position and size */
544 centx= rect->xmin + 0.5f*(rect->ymax-rect->ymin);
545 centy= rect->ymin + 0.5f*(rect->ymax-rect->ymin);
546 size= 0.5f*(rect->ymax-rect->ymin);
549 tria->vec[a][0]= size*check_tria_vert[a][0] + centx;
550 tria->vec[a][1]= size*check_tria_vert[a][1] + centy;
554 tria->index= check_tria_face;
558 /* prepares shade colors */
559 static void shadecolors4(char *coltop, char *coldown, const char *color, short shadetop, short shadedown)
562 coltop[0]= CLAMPIS(color[0]+shadetop, 0, 255);
563 coltop[1]= CLAMPIS(color[1]+shadetop, 0, 255);
564 coltop[2]= CLAMPIS(color[2]+shadetop, 0, 255);
567 coldown[0]= CLAMPIS(color[0]+shadedown, 0, 255);
568 coldown[1]= CLAMPIS(color[1]+shadedown, 0, 255);
569 coldown[2]= CLAMPIS(color[2]+shadedown, 0, 255);
570 coldown[3]= color[3];
573 static void round_box_shade_col4(const char *col1, const char *col2, float fac)
576 unsigned char col[4];
578 faci= floor(255.1f*fac);
581 col[0]= (faci*col1[0] + facm*col2[0])>>8;
582 col[1]= (faci*col1[1] + facm*col2[1])>>8;
583 col[2]= (faci*col1[2] + facm*col2[2])>>8;
584 col[3]= (faci*col1[3] + facm*col2[3])>>8;
589 static void widgetbase_outline(uiWidgetBase *wtb)
594 glBegin(GL_QUAD_STRIP);
595 for(a=0; a<wtb->totvert; a++) {
596 glVertex2fv(wtb->outer_v[a]);
597 glVertex2fv(wtb->inner_v[a]);
599 glVertex2fv(wtb->outer_v[0]);
600 glVertex2fv(wtb->inner_v[0]);
604 static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
610 /* backdrop non AA */
612 if(wcol->shaded==0) {
613 if (wcol->alpha_check) {
614 GLubyte checker_stipple_sml[32*32/8] =
616 255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
617 255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
618 0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
619 0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
620 255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
621 255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
622 0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
623 0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
626 float x_mid= 0.0f; /* used for dumb clamping of values */
629 glColor4ub(100, 100, 100, 255);
631 for(a=0; a<wtb->totvert; a++) {
632 glVertex2fv(wtb->inner_v[a]);
637 glEnable(GL_POLYGON_STIPPLE);
638 glColor4ub(160, 160, 160, 255);
639 glPolygonStipple(checker_stipple_sml);
641 for(a=0; a<wtb->totvert; a++) {
642 glVertex2fv(wtb->inner_v[a]);
645 glDisable(GL_POLYGON_STIPPLE);
648 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
650 glColor4ubv((unsigned char*)wcol->inner);
652 for(a=0; a<wtb->totvert; a++) {
653 glVertex2fv(wtb->inner_v[a]);
654 x_mid += wtb->inner_v[a][0];
656 x_mid /= wtb->totvert;
659 /* 1/2 solid color */
660 glColor4ub(wcol->inner[0], wcol->inner[1], wcol->inner[2], 255);
662 for(a=0; a<wtb->totvert; a++)
663 glVertex2f(MIN2(wtb->inner_v[a][0], x_mid), wtb->inner_v[a][1]);
668 glColor4ubv((unsigned char*)wcol->inner);
670 for(a=0; a<wtb->totvert; a++)
671 glVertex2fv(wtb->inner_v[a]);
676 char col1[4], col2[4];
678 shadecolors4(col1, col2, wcol->inner, wcol->shadetop, wcol->shadedown);
680 glShadeModel(GL_SMOOTH);
682 for(a=0; a<wtb->totvert; a++) {
683 round_box_shade_col4(col1, col2, wtb->inner_uv[a][wtb->shadedir]);
684 glVertex2fv(wtb->inner_v[a]);
687 glShadeModel(GL_FLAT);
691 /* for each AA step */
694 glTranslatef(1.0*jit[j][0], 1.0*jit[j][1], 0.0f);
697 glColor4ub(wcol->outline[0], wcol->outline[1], wcol->outline[2], 32);
698 glBegin(GL_QUAD_STRIP);
699 for(a=0; a<wtb->totvert; a++) {
700 glVertex2fv(wtb->outer_v[a]);
701 glVertex2fv(wtb->inner_v[a]);
703 glVertex2fv(wtb->outer_v[0]);
704 glVertex2fv(wtb->inner_v[0]);
707 /* emboss bottom shadow */
709 glColor4f(1.0f, 1.0f, 1.0f, 0.02f);
710 glBegin(GL_QUAD_STRIP);
711 for(a=0; a<wtb->halfwayvert; a++) {
712 glVertex2fv(wtb->outer_v[a]);
713 glVertex2f(wtb->outer_v[a][0], wtb->outer_v[a][1]-1.0f);
718 glTranslatef(-1.0*jit[j][0], -1.0*jit[j][1], 0.0f);
723 if(wtb->tria1.tot || wtb->tria2.tot) {
724 /* for each AA step */
726 glTranslatef(1.0*jit[j][0], 1.0*jit[j][1], 0.0f);
729 glColor4ub(wcol->item[0], wcol->item[1], wcol->item[2], 32);
730 widget_trias_draw(&wtb->tria1);
733 glColor4ub(wcol->item[0], wcol->item[1], wcol->item[2], 32);
734 widget_trias_draw(&wtb->tria2);
737 glTranslatef(-1.0*jit[j][0], -1.0*jit[j][1], 0.0f);
745 /* *********************** text/icon ************************************** */
747 #define PREVIEW_PAD 4
749 static void widget_draw_preview(BIFIconID icon, float UNUSED(alpha), rcti *rect)
756 w = rect->xmax - rect->xmin;
757 h = rect->ymax - rect->ymin;
759 size -= PREVIEW_PAD*2; /* padding */
762 int x = rect->xmin + w/2 - size/2;
763 int y = rect->ymin + h/2 - size/2;
765 UI_icon_draw_preview_aspect_size(x, y, icon, 1.0f, size);
770 /* icons have been standardized... and this call draws in untransformed coordinates */
771 #define ICON_HEIGHT 16.0f
773 static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, rcti *rect)
776 float aspect, height;
778 if (but->flag & UI_ICON_PREVIEW) {
779 widget_draw_preview(icon, alpha, rect);
783 /* this icon doesn't need draw... */
784 if(icon==ICON_BLANK1 && (but->flag & UI_ICON_SUBMENU)==0) return;
786 /* we need aspect from block, for menus... these buttons are scaled in uiPositionBlock() */
787 aspect= but->block->aspect;
788 if(aspect != but->aspect) {
789 /* prevent scaling up icon in pupmenu */
796 height= ICON_HEIGHT/aspect;
801 /* calculate blend color */
802 if ELEM4(but->type, TOG, ROW, TOGN, LISTROW) {
803 if(but->flag & UI_SELECT);
804 else if(but->flag & UI_ACTIVE);
808 /* extra feature allows more alpha blending */
809 if(but->type==LABEL && but->a1==1.0f) alpha *= but->a2;
813 if(icon && icon!=ICON_BLANK1) {
814 if(but->flag & UI_ICON_LEFT) {
815 if (but->type==BUT_TOGDUAL) {
816 if (but->drawstr[0]) {
819 xs= (rect->xmin+rect->xmax- height)/2;
822 else if (but->block->flag & UI_BLOCK_LOOP) {
823 if(but->type==SEARCH_MENU)
828 else if ((but->type==ICONROW) || (but->type==ICONTEXTROW)) {
834 ys= (rect->ymin+rect->ymax- height)/2;
837 xs= (rect->xmin+rect->xmax- height)/2;
838 ys= (rect->ymin+rect->ymax- height)/2;
841 /* to indicate draggable */
842 if(but->dragpoin && (but->flag & UI_ACTIVE)) {
843 float rgb[3]= {1.25f, 1.25f, 1.25f};
844 UI_icon_draw_aspect_color(xs, ys, icon, aspect, rgb);
847 UI_icon_draw_aspect(xs, ys, icon, aspect, alpha);
850 if(but->flag & UI_ICON_SUBMENU) {
852 ys= (rect->ymin+rect->ymax- height)/2;
854 UI_icon_draw_aspect(xs, ys, ICON_RIGHTARROW_THIN, aspect, alpha);
860 /* sets but->ofs to make sure text is correctly visible */
861 static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
863 int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10;
864 int okwidth= rect->xmax-rect->xmin - border;
866 if (but->flag & UI_HAS_ICON) okwidth -= 16;
868 /* need to set this first */
869 uiStyleFontSet(fstyle);
871 if (fstyle->kerning==1) /* for BLF_width */
872 BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
874 /* if text editing we define ofs dynamically */
875 if(but->editstr && but->pos >= 0) {
876 if(but->ofs > but->pos)
881 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
883 while(but->strwidth > okwidth) {
885 /* textbut exception, clip right when... */
886 if(but->editstr && but->pos >= 0) {
890 /* copy draw string */
891 BLI_strncpy(buf, but->drawstr, sizeof(buf));
892 /* string position of cursor */
894 width= BLF_width(fstyle->uifont_id, buf+but->ofs);
896 /* if cursor is at 20 pixels of right side button we clip left */
897 if(width > okwidth-20)
900 /* shift string to the left */
901 if(width < 20 && but->ofs > 0)
903 but->drawstr[ strlen(but->drawstr)-1 ]= 0;
909 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
911 if(but->strwidth < 10) break;
914 if (fstyle->kerning==1)
915 BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
918 static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
920 int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10;
921 int okwidth= rect->xmax-rect->xmin - border;
923 char *cpend = but->drawstr + strlen(but->drawstr);
925 /* need to set this first */
926 uiStyleFontSet(fstyle);
928 if (fstyle->kerning==1) /* for BLF_width */
929 BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
931 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr);
934 /* find the space after ':' separator */
935 cpoin= strrchr(but->drawstr, ':');
937 if (cpoin && (cpoin < cpend-2)) {
940 /* chop off the leading text, starting from the right */
941 while (but->strwidth > okwidth && cp2 > but->drawstr) {
942 /* shift the text after and including cp2 back by 1 char, +1 to include null terminator */
943 memmove(cp2-1, cp2, strlen(cp2)+1);
946 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
947 if(but->strwidth < 10) break;
951 /* after the leading text is gone, chop off the : and following space, with ofs */
952 while ((but->strwidth > okwidth) && (but->ofs < 2))
955 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
956 if(but->strwidth < 10) break;
961 /* once the label's gone, chop off the least significant digits */
962 while(but->strwidth > okwidth ) {
963 int pos= strlen(but->drawstr);
965 but->drawstr[ pos-1 ] = 0;
968 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
969 if(but->strwidth < 10) break;
972 if (fstyle->kerning==1)
973 BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
977 static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
982 /* for underline drawing */
983 float font_xofs, font_yofs;
985 uiStyleFontSet(fstyle);
987 if(but->editstr || (but->flag & UI_TEXT_LEFT))
988 fstyle->align= UI_STYLE_TEXT_LEFT;
990 fstyle->align= UI_STYLE_TEXT_CENTER;
992 if (fstyle->kerning==1) /* for BLF_width */
993 BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
995 /* text button selection and cursor */
996 if(but->editstr && but->pos != -1) {
997 short t=0, pos=0, ch;
998 short selsta_tmp, selend_tmp, selsta_draw, selwidth_draw;
1000 if ((but->selend - but->selsta) > 0) {
1001 /* text button selection */
1002 selsta_tmp = but->selsta;
1003 selend_tmp = but->selend;
1005 if(but->drawstr[0]!=0) {
1007 if (but->selsta >= but->ofs) {
1008 ch= but->drawstr[selsta_tmp];
1009 but->drawstr[selsta_tmp]= 0;
1011 selsta_draw = BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
1013 but->drawstr[selsta_tmp]= ch;
1017 ch= but->drawstr[selend_tmp];
1018 but->drawstr[selend_tmp]= 0;
1020 selwidth_draw = BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
1022 but->drawstr[selend_tmp]= ch;
1024 glColor3ubv((unsigned char*)wcol->item);
1025 glRects(rect->xmin+selsta_draw, rect->ymin+2, rect->xmin+selwidth_draw, rect->ymax-2);
1030 if(pos >= but->ofs) {
1031 if(but->drawstr[0]!=0) {
1032 ch= but->drawstr[pos];
1033 but->drawstr[pos]= 0;
1035 t= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs) / but->aspect;
1037 but->drawstr[pos]= ch;
1040 glColor3f(0.20, 0.6, 0.9);
1041 glRects(rect->xmin+t, rect->ymin+2, rect->xmin+t+2, rect->ymax-2);
1046 if (fstyle->kerning == 1)
1047 BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
1049 // ui_rasterpos_safe(x, y, but->aspect);
1050 // if(but->type==IDPOIN) transopts= 0; // no translation, of course!
1051 // else transopts= ui_translate_buttons();
1053 /* cut string in 2 parts - only for menu entries */
1054 if((but->block->flag & UI_BLOCK_LOOP)) {
1055 if(ELEM5(but->type, SLI, NUM, TEX, NUMSLI, NUMABS)==0) {
1056 cpoin= strchr(but->drawstr, '|');
1057 if(cpoin) *cpoin= 0;
1061 glColor3ubv((unsigned char*)wcol->text);
1063 uiStyleFontDrawExt(fstyle, rect, but->drawstr+but->ofs, &font_xofs, &font_yofs);
1065 if(but->menu_key != '\0') {
1069 BLI_strncpy(fixedbuf, but->drawstr + but->ofs, sizeof(fixedbuf));
1071 str= strchr(fixedbuf, but->menu_key-32); /* upper case */
1073 str= strchr(fixedbuf, but->menu_key);
1079 ul_index= (int)(str - fixedbuf);
1081 if (fstyle->kerning == 1) {
1082 BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
1085 fixedbuf[ul_index]= '\0';
1086 ul_advance= BLF_width(fstyle->uifont_id, fixedbuf);
1088 BLF_position(fstyle->uifont_id, rect->xmin+font_xofs + ul_advance, rect->ymin+font_yofs, 0.0f);
1089 BLF_draw(fstyle->uifont_id, "_", 2);
1091 if (fstyle->kerning == 1) {
1092 BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
1097 /* part text right aligned */
1099 fstyle->align= UI_STYLE_TEXT_RIGHT;
1101 uiStyleFontDraw(fstyle, rect, cpoin+1);
1106 /* draws text and icons for buttons */
1107 static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
1110 if(but==NULL) return;
1112 /* clip but->drawstr to fit in available space */
1113 if (but->editstr && but->pos >= 0) {
1114 ui_text_leftclip(fstyle, but, rect);
1116 else if (ELEM4(but->type, NUM, NUMABS, NUMSLI, SLI)) {
1117 ui_text_label_rightclip(fstyle, but, rect);
1119 else if (ELEM(but->type, TEX, SEARCH_MENU)) {
1120 ui_text_leftclip(fstyle, but, rect);
1122 else if ((but->block->flag & UI_BLOCK_LOOP) && (but->type == BUT)) {
1123 ui_text_leftclip(fstyle, but, rect);
1127 /* check for button text label */
1128 if (but->type == ICONTEXTROW) {
1129 widget_draw_icon(but, (BIFIconID) (but->icon+but->iconadd), 1.0f, rect);
1133 if(but->type==BUT_TOGDUAL) {
1135 if(but->pointype==SHO)
1136 dualset= BTST( *(((short *)but->poin)+1), but->bitnr);
1137 else if(but->pointype==INT)
1138 dualset= BTST( *(((int *)but->poin)+1), but->bitnr);
1140 widget_draw_icon(but, ICON_DOT, dualset?1.0f:0.25f, rect);
1143 /* If there's an icon too (made with uiDefIconTextBut) then draw the icon
1144 and offset the text label to accommodate it */
1146 if (but->flag & UI_HAS_ICON) {
1147 widget_draw_icon(but, but->icon+but->iconadd, 1.0f, rect);
1149 rect->xmin += UI_icon_get_width(but->icon+but->iconadd);
1151 if(but->editstr || (but->flag & UI_TEXT_LEFT))
1154 else if((but->flag & UI_TEXT_LEFT))
1157 /* always draw text for textbutton cursor */
1158 widget_draw_text(fstyle, wcol, but, rect);
1165 /* *********************** widget types ************************************* */
1168 /* uiWidgetStateColors
1170 char inner_anim_sel[4];
1172 char inner_key_sel[4];
1173 char inner_driven[4];
1174 char inner_driven_sel[4];
1179 static struct uiWidgetStateColors wcol_state_colors= {
1180 {115, 190, 76, 255},
1182 {240, 235, 100, 255},
1183 {215, 211, 75, 255},
1198 float shadetop, shadedown;
1201 static struct uiWidgetColors wcol_num= {
1203 {180, 180, 180, 255},
1204 {153, 153, 153, 255},
1208 {255, 255, 255, 255},
1214 static struct uiWidgetColors wcol_numslider= {
1216 {180, 180, 180, 255},
1217 {153, 153, 153, 255},
1218 {128, 128, 128, 255},
1221 {255, 255, 255, 255},
1227 static struct uiWidgetColors wcol_text= {
1229 {153, 153, 153, 255},
1230 {153, 153, 153, 255},
1234 {255, 255, 255, 255},
1240 static struct uiWidgetColors wcol_option= {
1244 {255, 255, 255, 255},
1247 {255, 255, 255, 255},
1253 /* button that shows popup */
1254 static struct uiWidgetColors wcol_menu= {
1258 {255, 255, 255, 255},
1260 {255, 255, 255, 255},
1261 {204, 204, 204, 255},
1267 /* button that starts pulldown */
1268 static struct uiWidgetColors wcol_pulldown= {
1271 {86, 128, 194, 255},
1272 {255, 255, 255, 255},
1281 /* button inside menu */
1282 static struct uiWidgetColors wcol_menu_item= {
1285 {86, 128, 194, 255},
1286 {255, 255, 255, 255},
1288 {255, 255, 255, 255},
1295 /* backdrop menu + title text color */
1296 static struct uiWidgetColors wcol_menu_back= {
1300 {100, 100, 100, 255},
1302 {160, 160, 160, 255},
1303 {255, 255, 255, 255},
1310 static struct uiWidgetColors wcol_radio= {
1313 {86, 128, 194, 255},
1314 {255, 255, 255, 255},
1316 {255, 255, 255, 255},
1323 static struct uiWidgetColors wcol_regular= {
1325 {153, 153, 153, 255},
1326 {100, 100, 100, 255},
1330 {255, 255, 255, 255},
1336 static struct uiWidgetColors wcol_tool= {
1338 {153, 153, 153, 255},
1339 {100, 100, 100, 255},
1343 {255, 255, 255, 255},
1349 static struct uiWidgetColors wcol_box= {
1351 {128, 128, 128, 255},
1352 {100, 100, 100, 255},
1356 {255, 255, 255, 255},
1362 static struct uiWidgetColors wcol_toggle= {
1364 {153, 153, 153, 255},
1365 {100, 100, 100, 255},
1369 {255, 255, 255, 255},
1375 static struct uiWidgetColors wcol_scroll= {
1378 {100, 100, 100, 180},
1379 {128, 128, 128, 255},
1382 {255, 255, 255, 255},
1388 static struct uiWidgetColors wcol_progress= {
1390 {190, 190, 190, 255},
1391 {100, 100, 100, 180},
1395 {255, 255, 255, 255},
1401 static struct uiWidgetColors wcol_list_item= {
1404 {86, 128, 194, 255},
1414 /* free wcol struct to play with */
1415 static struct uiWidgetColors wcol_tmp= {
1417 {128, 128, 128, 255},
1418 {100, 100, 100, 255},
1422 {255, 255, 255, 255},
1429 /* called for theme init (new theme) and versions */
1430 void ui_widget_color_init(ThemeUI *tui)
1432 tui->wcol_regular= wcol_regular;
1433 tui->wcol_tool= wcol_tool;
1434 tui->wcol_text= wcol_text;
1435 tui->wcol_radio= wcol_radio;
1436 tui->wcol_option= wcol_option;
1437 tui->wcol_toggle= wcol_toggle;
1438 tui->wcol_num= wcol_num;
1439 tui->wcol_numslider= wcol_numslider;
1440 tui->wcol_menu= wcol_menu;
1441 tui->wcol_pulldown= wcol_pulldown;
1442 tui->wcol_menu_back= wcol_menu_back;
1443 tui->wcol_menu_item= wcol_menu_item;
1444 tui->wcol_box= wcol_box;
1445 tui->wcol_scroll= wcol_scroll;
1446 tui->wcol_list_item= wcol_list_item;
1447 tui->wcol_progress= wcol_progress;
1449 tui->wcol_state= wcol_state_colors;
1452 /* ************ button callbacks, state ***************** */
1454 static void widget_state_blend(char *cp, const char *cpstate, const float fac)
1457 cp[0]= (int)((1.0f-fac)*cp[0] + fac*cpstate[0]);
1458 cp[1]= (int)((1.0f-fac)*cp[1] + fac*cpstate[1]);
1459 cp[2]= (int)((1.0f-fac)*cp[2] + fac*cpstate[2]);
1463 /* copy colors from theme, and set changes in it based on state */
1464 static void widget_state(uiWidgetType *wt, int state)
1466 uiWidgetStateColors *wcol_state= wt->wcol_state;
1468 wt->wcol= *(wt->wcol_theme);
1470 if(state & UI_SELECT) {
1471 QUATCOPY(wt->wcol.inner, wt->wcol.inner_sel)
1473 if(state & UI_BUT_ANIMATED_KEY)
1474 widget_state_blend(wt->wcol.inner, wcol_state->inner_key_sel, wcol_state->blend);
1475 else if(state & UI_BUT_ANIMATED)
1476 widget_state_blend(wt->wcol.inner, wcol_state->inner_anim_sel, wcol_state->blend);
1477 else if(state & UI_BUT_DRIVEN)
1478 widget_state_blend(wt->wcol.inner, wcol_state->inner_driven_sel, wcol_state->blend);
1480 VECCOPY(wt->wcol.text, wt->wcol.text_sel);
1482 if(state & UI_SELECT)
1483 SWAP(short, wt->wcol.shadetop, wt->wcol.shadedown);
1486 if(state & UI_BUT_ANIMATED_KEY)
1487 widget_state_blend(wt->wcol.inner, wcol_state->inner_key, wcol_state->blend);
1488 else if(state & UI_BUT_ANIMATED)
1489 widget_state_blend(wt->wcol.inner, wcol_state->inner_anim, wcol_state->blend);
1490 else if(state & UI_BUT_DRIVEN)
1491 widget_state_blend(wt->wcol.inner, wcol_state->inner_driven, wcol_state->blend);
1493 if(state & UI_ACTIVE) { /* mouse over? */
1494 wt->wcol.inner[0]= wt->wcol.inner[0]>=240? 255 : wt->wcol.inner[0]+15;
1495 wt->wcol.inner[1]= wt->wcol.inner[1]>=240? 255 : wt->wcol.inner[1]+15;
1496 wt->wcol.inner[2]= wt->wcol.inner[2]>=240? 255 : wt->wcol.inner[2]+15;
1500 if(state & UI_BUT_REDALERT) {
1501 char red[4]= {255, 0, 0};
1502 widget_state_blend(wt->wcol.inner, red, 0.4f);
1506 /* sliders use special hack which sets 'item' as inner when drawing filling */
1507 static void widget_state_numslider(uiWidgetType *wt, int state)
1509 uiWidgetStateColors *wcol_state= wt->wcol_state;
1510 float blend= wcol_state->blend - 0.2f; // XXX special tweak to make sure that bar will still be visible
1512 /* call this for option button */
1513 widget_state(wt, state);
1515 /* now, set the inner-part so that it reflects state settings too */
1516 // TODO: maybe we should have separate settings for the blending colors used for this case?
1517 if(state & UI_SELECT) {
1519 if(state & UI_BUT_ANIMATED_KEY)
1520 widget_state_blend(wt->wcol.item, wcol_state->inner_key_sel, blend);
1521 else if(state & UI_BUT_ANIMATED)
1522 widget_state_blend(wt->wcol.item, wcol_state->inner_anim_sel, blend);
1523 else if(state & UI_BUT_DRIVEN)
1524 widget_state_blend(wt->wcol.item, wcol_state->inner_driven_sel, blend);
1526 if(state & UI_SELECT)
1527 SWAP(short, wt->wcol.shadetop, wt->wcol.shadedown);
1530 if(state & UI_BUT_ANIMATED_KEY)
1531 widget_state_blend(wt->wcol.item, wcol_state->inner_key, blend);
1532 else if(state & UI_BUT_ANIMATED)
1533 widget_state_blend(wt->wcol.item, wcol_state->inner_anim, blend);
1534 else if(state & UI_BUT_DRIVEN)
1535 widget_state_blend(wt->wcol.item, wcol_state->inner_driven, blend);
1539 /* labels use theme colors for text */
1540 static void widget_state_label(uiWidgetType *wt, int state)
1542 /* call this for option button */
1543 widget_state(wt, state);
1545 if(state & UI_SELECT)
1546 UI_GetThemeColor4ubv(TH_TEXT_HI, (unsigned char *)wt->wcol.text);
1548 UI_GetThemeColor4ubv(TH_TEXT, (unsigned char *)wt->wcol.text);
1552 static void widget_state_nothing(uiWidgetType *wt, int UNUSED(state))
1554 wt->wcol= *(wt->wcol_theme);
1557 /* special case, button that calls pulldown */
1558 static void widget_state_pulldown(uiWidgetType *wt, int state)
1560 wt->wcol= *(wt->wcol_theme);
1562 QUATCOPY(wt->wcol.inner, wt->wcol.inner_sel);
1563 VECCOPY(wt->wcol.outline, wt->wcol.inner);
1565 if(state & UI_ACTIVE)
1566 VECCOPY(wt->wcol.text, wt->wcol.text_sel);
1569 /* special case, menu items */
1570 static void widget_state_menu_item(uiWidgetType *wt, int state)
1572 wt->wcol= *(wt->wcol_theme);
1574 if(state & (UI_BUT_DISABLED|UI_BUT_INACTIVE)) {
1575 wt->wcol.text[0]= 0.5f*(wt->wcol.text[0]+wt->wcol.text_sel[0]);
1576 wt->wcol.text[1]= 0.5f*(wt->wcol.text[1]+wt->wcol.text_sel[1]);
1577 wt->wcol.text[2]= 0.5f*(wt->wcol.text[2]+wt->wcol.text_sel[2]);
1579 else if(state & UI_ACTIVE) {
1580 QUATCOPY(wt->wcol.inner, wt->wcol.inner_sel);
1581 VECCOPY(wt->wcol.text, wt->wcol.text_sel);
1588 /* ************ menu backdrop ************************* */
1590 /* outside of rect, rad to left/bottom/right */
1591 static void widget_softshadow(rcti *rect, int roundboxalign, float radin, float radout)
1595 float alpha, alphastep;
1598 /* prevent tooltips to not show round shadow */
1599 if( 2.0f*radout > 0.2f*(rect1.ymax-rect1.ymin) )
1600 rect1.ymax -= 0.2f*(rect1.ymax-rect1.ymin);
1602 rect1.ymax -= 2.0f*radout;
1605 tot= round_box_shadow_edges(wtb.inner_v, &rect1, radin, roundboxalign & 12, 0.0f);
1607 /* inverse linear shadow alpha */
1611 for(step= 1; step<=radout; step++, alpha*=alphastep) {
1612 round_box_shadow_edges(wtb.outer_v, &rect1, radin, 15, (float)step);
1614 glColor4f(0.0f, 0.0f, 0.0f, alpha);
1616 glBegin(GL_QUAD_STRIP);
1617 for(a=0; a<tot; a++) {
1618 glVertex2fv(wtb.outer_v[a]);
1619 glVertex2fv(wtb.inner_v[a]);
1626 static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int direction)
1629 int roundboxalign= 15;
1633 /* menu is 2nd level or deeper */
1634 if (flag & UI_BLOCK_POPUP) {
1635 //rect->ymin -= 4.0;
1636 //rect->ymax += 4.0;
1638 else if (direction == UI_DOWN) {
1642 else if (direction == UI_TOP) {
1648 widget_softshadow(rect, roundboxalign, 5.0f, 8.0f);
1650 round_box_edges(&wtb, roundboxalign, rect, 5.0f);
1652 widgetbase_draw(&wtb, wcol);
1654 glDisable(GL_BLEND);
1658 static void ui_hsv_cursor(float x, float y)
1662 glTranslatef(x, y, 0.0f);
1664 glColor3f(1.0f, 1.0f, 1.0f);
1665 glutil_draw_filled_arc(0.0f, M_PI*2.0, 3.0f, 8);
1668 glEnable(GL_LINE_SMOOTH );
1669 glColor3f(0.0f, 0.0f, 0.0f);
1670 glutil_draw_lined_arc(0.0f, M_PI*2.0, 3.0f, 12);
1671 glDisable(GL_BLEND);
1672 glDisable(GL_LINE_SMOOTH );
1678 void ui_hsvcircle_vals_from_pos(float *valrad, float *valdist, rcti *rect, float mx, float my)
1680 /* duplication of code... well, simple is better now */
1681 float centx= (float)(rect->xmin + rect->xmax)/2;
1682 float centy= (float)(rect->ymin + rect->ymax)/2;
1685 if( rect->xmax-rect->xmin > rect->ymax-rect->ymin )
1686 radius= (float)(rect->ymax - rect->ymin)/2;
1688 radius= (float)(rect->xmax - rect->xmin)/2;
1692 dist= sqrt( mx*mx + my*my);
1694 *valdist= dist/radius;
1698 *valrad= atan2(mx, my)/(2.0f*M_PI) + 0.5f;
1701 void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect)
1703 /* gouraud triangle fan */
1704 float radstep, ang= 0.0f;
1705 float centx, centy, radius;
1706 float rgb[3], hsvo[3], hsv[3], col[3], colcent[3];
1708 int color_profile = but->block->color_profile;
1710 if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
1711 color_profile = BLI_PR_NONE;
1713 radstep= 2.0f*M_PI/(float)tot;
1714 centx= (float)(rect->xmin + rect->xmax)/2;
1715 centy= (float)(rect->ymin + rect->ymax)/2;
1717 if( rect->xmax-rect->xmin > rect->ymax-rect->ymin )
1718 radius= (float)(rect->ymax - rect->ymin)/2;
1720 radius= (float)(rect->xmax - rect->xmin)/2;
1723 ui_get_but_vectorf(but, rgb);
1724 copy_v3_v3(hsv, ui_block_hsv_get(but->block));
1725 rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
1726 copy_v3_v3(hsvo, hsv);
1728 /* exception: if 'lock' is set
1729 * lock the value of the color wheel to 1.
1730 * Useful for color correction tools where you're only interested in hue. */
1731 if (but->flag & UI_BUT_COLOR_LOCK)
1733 else if (color_profile)
1734 hsv[2] = linearrgb_to_srgb(hsv[2]);
1736 hsv_to_rgb(0.f, 0.f, hsv[2], colcent, colcent+1, colcent+2);
1738 glShadeModel(GL_SMOOTH);
1740 glBegin(GL_TRIANGLE_FAN);
1741 glColor3fv(colcent);
1742 glVertex2f( centx, centy);
1744 for(a=0; a<=tot; a++, ang+=radstep) {
1748 ui_hsvcircle_vals_from_pos(hsv, hsv+1, rect, centx + co*radius, centy + si*radius);
1749 CLAMP(hsv[2], 0.0f, 1.0f); /* for display only */
1751 hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2);
1753 glVertex2f( centx + co*radius, centy + si*radius);
1757 glShadeModel(GL_FLAT);
1759 /* fully rounded outline */
1761 glTranslatef(centx, centy, 0.0f);
1763 glEnable(GL_LINE_SMOOTH );
1764 glColor3ubv((unsigned char*)wcol->outline);
1765 glutil_draw_lined_arc(0.0f, M_PI*2.0, radius, tot + 1);
1766 glDisable(GL_BLEND);
1767 glDisable(GL_LINE_SMOOTH );
1771 ang= 2.0f*M_PI*hsvo[0] + 0.5f*M_PI;
1773 if(but->flag & UI_BUT_COLOR_CUBIC)
1774 radius= (1.0f - pow(1.0f - hsvo[1], 3.0f)) *radius;
1776 radius= hsvo[1] * radius;
1778 ui_hsv_cursor(centx + cos(-ang)*radius, centy + sin(-ang)*radius);
1782 /* ************ custom buttons, old stuff ************** */
1784 /* draws in resolution of 20x4 colors */
1785 void ui_draw_gradient(rcti *rect, float *hsv, int type, float alpha)
1788 float h= hsv[0], s= hsv[1], v= hsv[2];
1789 float dx, dy, sx1, sx2, sy;
1790 float col0[4][3]; // left half, rect bottom to top
1791 float col1[4][3]; // right half, rect bottom to top
1793 /* draw series of gouraud rects */
1794 glShadeModel(GL_SMOOTH);
1798 hsv_to_rgb(h, 0.0, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1799 hsv_to_rgb(h, 0.333, 0.0, &col1[1][0], &col1[1][1], &col1[1][2]);
1800 hsv_to_rgb(h, 0.666, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
1801 hsv_to_rgb(h, 1.0, 0.0, &col1[3][0], &col1[3][1], &col1[3][2]);
1804 hsv_to_rgb(0.0, s, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1805 hsv_to_rgb(0.0, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
1806 hsv_to_rgb(0.0, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
1807 hsv_to_rgb(0.0, s, 1.0, &col1[3][0], &col1[3][1], &col1[3][2]);
1810 hsv_to_rgb(0.0, 0.0, v, &col1[0][0], &col1[0][1], &col1[0][2]);
1811 hsv_to_rgb(0.0, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
1812 hsv_to_rgb(0.0, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
1813 hsv_to_rgb(0.0, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
1816 hsv_to_rgb(0.0, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1817 VECCOPY(col1[1], col1[0]);
1818 VECCOPY(col1[2], col1[0]);
1819 VECCOPY(col1[3], col1[0]);
1822 hsv_to_rgb(1.0, 0.0, 1.0, &col1[1][0], &col1[1][1], &col1[1][2]);
1823 VECCOPY(col1[0], col1[1]);
1824 VECCOPY(col1[2], col1[1]);
1825 VECCOPY(col1[3], col1[1]);
1828 hsv_to_rgb(1.0, 1.0, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
1829 VECCOPY(col1[0], col1[2]);
1830 VECCOPY(col1[1], col1[2]);
1831 VECCOPY(col1[3], col1[2]);
1834 assert(!"invalid 'type' argument");
1835 hsv_to_rgb(1.0, 1.0, 1.0, &col1[2][0], &col1[2][1], &col1[2][2]);
1836 VECCOPY(col1[0], col1[2]);
1837 VECCOPY(col1[1], col1[2]);
1838 VECCOPY(col1[3], col1[2]);
1843 for(dx=0.0; dx<1.0; dx+= 0.05) {
1845 VECCOPY(col0[0], col1[0]);
1846 VECCOPY(col0[1], col1[1]);
1847 VECCOPY(col0[2], col1[2]);
1848 VECCOPY(col0[3], col1[3]);
1853 hsv_to_rgb(h, 0.0, dx, &col1[0][0], &col1[0][1], &col1[0][2]);
1854 hsv_to_rgb(h, 0.333, dx, &col1[1][0], &col1[1][1], &col1[1][2]);
1855 hsv_to_rgb(h, 0.666, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
1856 hsv_to_rgb(h, 1.0, dx, &col1[3][0], &col1[3][1], &col1[3][2]);
1859 hsv_to_rgb(dx, s, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1860 hsv_to_rgb(dx, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
1861 hsv_to_rgb(dx, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
1862 hsv_to_rgb(dx, s, 1.0, &col1[3][0], &col1[3][1], &col1[3][2]);
1865 hsv_to_rgb(dx, 0.0, v, &col1[0][0], &col1[0][1], &col1[0][2]);
1866 hsv_to_rgb(dx, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
1867 hsv_to_rgb(dx, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
1868 hsv_to_rgb(dx, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
1871 hsv_to_rgb(dx, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1872 VECCOPY(col1[1], col1[0]);
1873 VECCOPY(col1[2], col1[0]);
1874 VECCOPY(col1[3], col1[0]);
1877 hsv_to_rgb(h, dx, 1.0, &col1[1][0], &col1[1][1], &col1[1][2]);
1878 VECCOPY(col1[0], col1[1]);
1879 VECCOPY(col1[2], col1[1]);
1880 VECCOPY(col1[3], col1[1]);
1883 hsv_to_rgb(h, 1.0, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
1884 VECCOPY(col1[0], col1[2]);
1885 VECCOPY(col1[1], col1[2]);
1886 VECCOPY(col1[3], col1[2]);
1891 sx1= rect->xmin + dx*(rect->xmax-rect->xmin);
1892 sx2= rect->xmin + (dx+0.05)*(rect->xmax-rect->xmin);
1894 dy= (rect->ymax-rect->ymin)/3.0;
1897 for(a=0; a<3; a++, sy+=dy) {
1898 glColor4f(col0[a][0], col0[a][1], col0[a][2], alpha);
1899 glVertex2f(sx1, sy);
1901 glColor4f(col1[a][0], col1[a][1], col1[a][2], alpha);
1902 glVertex2f(sx2, sy);
1904 glColor4f(col1[a+1][0], col1[a+1][1], col1[a+1][2], alpha);
1905 glVertex2f(sx2, sy+dy);
1907 glColor4f(col0[a+1][0], col0[a+1][1], col0[a+1][2], alpha);
1908 glVertex2f(sx1, sy+dy);
1913 glShadeModel(GL_FLAT);
1919 static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
1921 float rgb[3], h,s,v;
1922 float x=0.0f, y=0.0f;
1923 float *hsv= ui_block_hsv_get(but->block);
1930 ui_get_but_vectorf(but, rgb);
1931 rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], &h, &s, &v);
1937 ui_draw_gradient(rect, hsvn, but->a1, 1.f);
1939 switch((int)but->a1) {
1947 x= h; y= 0.5; break;
1949 x= s; y= 0.5; break;
1951 x= v; y= 0.5; break;
1955 x= rect->xmin + x*(rect->xmax-rect->xmin);
1956 y= rect->ymin + y*(rect->ymax-rect->ymin);
1957 CLAMP(x, rect->xmin+3.0, rect->xmax-3.0);
1958 CLAMP(y, rect->ymin+3.0, rect->ymax-3.0);
1960 ui_hsv_cursor(x, y);
1963 glColor3ub(0, 0, 0);
1964 fdrawbox((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
1967 /* vertical 'value' slider, using new widget code */
1968 static void ui_draw_but_HSV_v(uiBut *but, rcti *rect)
1971 float rad= 0.5f*(rect->xmax - rect->xmin);
1973 float rgb[3], hsv[3], v, range;
1974 int color_profile = but->block->color_profile;
1976 if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
1977 color_profile = BLI_PR_NONE;
1979 ui_get_but_vectorf(but, rgb);
1980 rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
1984 v = linearrgb_to_srgb(v);
1986 /* map v from property range to [0,1] */
1987 range = but->softmax - but->softmin;
1988 v = (v - but->softmin)/range;
1993 round_box_edges(&wtb, 15, rect, rad);
1995 /* setup temp colors */
1996 wcol_tmp.outline[0]= wcol_tmp.outline[1]= wcol_tmp.outline[2]= 0;
1997 wcol_tmp.inner[0]= wcol_tmp.inner[1]= wcol_tmp.inner[2]= 128;
1998 wcol_tmp.shadetop= 127;
1999 wcol_tmp.shadedown= -128;
2002 widgetbase_draw(&wtb, &wcol_tmp);
2005 x= rect->xmin + 0.5f * (rect->xmax-rect->xmin);
2006 y= rect->ymin + v * (rect->ymax-rect->ymin);
2007 CLAMP(y, rect->ymin+3.0, rect->ymax-3.0);
2009 ui_hsv_cursor(x, y);
2014 /* ************ separator, for menus etc ***************** */
2015 static void ui_draw_separator(rcti *rect, uiWidgetColors *wcol)
2017 int y = rect->ymin + (rect->ymax - rect->ymin)/2 - 1;
2018 unsigned char col[4];
2020 col[0] = wcol->text[0];
2021 col[1] = wcol->text[1];
2022 col[2] = wcol->text[2];
2027 sdrawline(rect->xmin, y, rect->xmax, y);
2028 glDisable(GL_BLEND);
2031 /* ************ button callbacks, draw ***************** */
2033 static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2036 float rad= 0.5f*(rect->ymax - rect->ymin);
2037 float textofs = rad*0.75;
2039 if(state & UI_SELECT)
2040 SWAP(short, wcol->shadetop, wcol->shadedown);
2045 round_box_edges(&wtb, roundboxalign, rect, rad);
2048 if(!(state & UI_TEXTINPUT)) {
2049 widget_num_tria(&wtb.tria1, rect, 0.6f, 'l');
2050 widget_num_tria(&wtb.tria2, rect, 0.6f, 'r');
2053 widgetbase_draw(&wtb, wcol);
2056 rect->xmin += textofs;
2057 rect->xmax -= textofs;
2060 //static int ui_link_bezier_points(rcti *rect, float coord_array[][2], int resol)
2061 int ui_link_bezier_points(rcti *rect, float coord_array[][2], int resol)
2063 float dist, vec[4][2];
2065 vec[0][0]= rect->xmin;
2066 vec[0][1]= rect->ymin;
2067 vec[3][0]= rect->xmax;
2068 vec[3][1]= rect->ymax;
2070 dist= 0.5f*ABS(vec[0][0] - vec[3][0]);
2072 vec[1][0]= vec[0][0]+dist;
2073 vec[1][1]= vec[0][1];
2075 vec[2][0]= vec[3][0]-dist;
2076 vec[2][1]= vec[3][1];
2078 forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0], coord_array[0], resol, sizeof(float)*2);
2079 forward_diff_bezier(vec[0][1], vec[1][1], vec[2][1], vec[3][1], coord_array[0]+1, resol, sizeof(float)*2);
2084 #define LINK_RESOL 24
2085 void ui_draw_link_bezier(rcti *rect)
2087 float coord_array[LINK_RESOL+1][2];
2089 if(ui_link_bezier_points(rect, coord_array, LINK_RESOL)) {
2093 /* we can reuse the dist variable here to increment the GL curve eval amount*/
2094 dist = 1.0f/(float)LINK_RESOL;
2097 glEnable(GL_LINE_SMOOTH);
2099 glBegin(GL_LINE_STRIP);
2100 for(i=0; i<=LINK_RESOL; i++) {
2101 glVertex2fv(coord_array[i]);
2105 glDisable(GL_BLEND);
2106 glDisable(GL_LINE_SMOOTH);
2111 /* function in use for buttons and for view2d sliders */
2112 void uiWidgetScrollDraw(uiWidgetColors *wcol, rcti *rect, rcti *slider, int state)
2121 /* determine horizontal/vertical */
2122 horizontal= (rect->xmax - rect->xmin > rect->ymax - rect->ymin);
2125 rad= 0.5f*(rect->ymax - rect->ymin);
2127 rad= 0.5f*(rect->xmax - rect->xmin);
2129 wtb.shadedir= (horizontal)? 1: 0;
2131 /* draw back part, colors swapped and shading inverted */
2133 SWAP(short, wcol->shadetop, wcol->shadedown);
2135 round_box_edges(&wtb, 15, rect, rad);
2136 widgetbase_draw(&wtb, wcol);
2139 if(slider->xmax-slider->xmin<2 || slider->ymax-slider->ymin<2);
2142 SWAP(short, wcol->shadetop, wcol->shadedown);
2144 QUATCOPY(wcol->inner, wcol->item);
2146 if(wcol->shadetop>wcol->shadedown)
2147 wcol->shadetop+= 20; /* XXX violates themes... */
2148 else wcol->shadedown+= 20;
2150 if(state & UI_SCROLL_PRESSED) {
2151 wcol->inner[0]= wcol->inner[0]>=250? 255 : wcol->inner[0]+5;
2152 wcol->inner[1]= wcol->inner[1]>=250? 255 : wcol->inner[1]+5;
2153 wcol->inner[2]= wcol->inner[2]>=250? 255 : wcol->inner[2]+5;
2157 wtb.emboss= 0; /* only emboss once */
2159 /* exception for progress bar */
2160 if (state & UI_SCROLL_NO_OUTLINE)
2161 SWAP(short, outline, wtb.outline);
2163 round_box_edges(&wtb, 15, slider, rad);
2165 if(state & UI_SCROLL_ARROWS) {
2166 if(wcol->item[0] > 48) wcol->item[0]-= 48;
2167 if(wcol->item[1] > 48) wcol->item[1]-= 48;
2168 if(wcol->item[2] > 48) wcol->item[2]-= 48;
2172 widget_scroll_circle(&wtb.tria1, slider, 0.6f, 'l');
2173 widget_scroll_circle(&wtb.tria2, slider, 0.6f, 'r');
2176 widget_scroll_circle(&wtb.tria1, slider, 0.6f, 'b');
2177 widget_scroll_circle(&wtb.tria2, slider, 0.6f, 't');
2180 widgetbase_draw(&wtb, wcol);
2182 if (state & UI_SCROLL_NO_OUTLINE)
2183 SWAP(short, outline, wtb.outline);
2187 static void widget_scroll(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
2191 float fac, size, min;
2194 /* calculate slider part */
2195 value= ui_get_but_val(but);
2197 size= (but->softmax + but->a1 - but->softmin);
2198 size= MAX2(size, 2);
2203 /* determine horizontal/vertical */
2204 horizontal= (rect->xmax - rect->xmin > rect->ymax - rect->ymin);
2207 fac= (rect->xmax - rect->xmin)/(size);
2208 rect1.xmin= rect1.xmin + ceil(fac*(value - but->softmin));
2209 rect1.xmax= rect1.xmin + ceil(fac*(but->a1 - but->softmin));
2211 /* ensure minimium size */
2212 min= rect->ymax - rect->ymin;
2214 if(rect1.xmax - rect1.xmin < min) {
2215 rect1.xmax= rect1.xmin + min;
2217 if(rect1.xmax > rect->xmax) {
2218 rect1.xmax= rect->xmax;
2219 rect1.xmin= MAX2(rect1.xmax - min, rect->xmin);
2224 fac= (rect->ymax - rect->ymin)/(size);
2225 rect1.ymax= rect1.ymax - ceil(fac*(value - but->softmin));
2226 rect1.ymin= rect1.ymax - ceil(fac*(but->a1 - but->softmin));
2228 /* ensure minimium size */
2229 min= rect->xmax - rect->xmin;
2231 if(rect1.ymax - rect1.ymin < min) {
2232 rect1.ymax= rect1.ymin + min;
2234 if(rect1.ymax > rect->ymax) {
2235 rect1.ymax= rect->ymax;
2236 rect1.ymin= MAX2(rect1.ymax - min, rect->ymin);
2241 if(state & UI_SELECT)
2242 state= UI_SCROLL_PRESSED;
2245 uiWidgetScrollDraw(wcol, rect, &rect1, state);
2248 static void widget_progressbar(uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
2250 rcti rect_prog = *rect, rect_bar = *rect;
2251 float value = but->a1;
2254 /* make the progress bar a proportion of the original height */
2255 /* hardcoded 4px high for now */
2256 rect_prog.ymax = rect_prog.ymin + 4;
2257 rect_bar.ymax = rect_bar.ymin + 4;
2259 w = value * (rect_prog.xmax - rect_prog.xmin);
2261 /* ensure minimium size */
2262 min= rect_prog.ymax - rect_prog.ymin;
2265 rect_bar.xmax = rect_bar.xmin + w;
2267 uiWidgetScrollDraw(wcol, &rect_prog, &rect_bar, UI_SCROLL_NO_OUTLINE);
2269 /* raise text a bit */
2274 static void widget_link(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
2277 if(but->flag & UI_SELECT) {
2280 UI_ThemeColor(TH_TEXT_HI);
2282 rectlink.xmin= (rect->xmin+rect->xmax)/2;
2283 rectlink.ymin= (rect->ymin+rect->ymax)/2;
2284 rectlink.xmax= but->linkto[0];
2285 rectlink.ymax= but->linkto[1];
2287 ui_draw_link_bezier(&rectlink);
2291 static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2293 uiWidgetBase wtb, wtb1;
2296 float offs, toffs, fac;
2302 /* backdrop first */
2305 offs= 0.5f*(rect->ymax - rect->ymin);
2307 round_box_edges(&wtb, roundboxalign, rect, offs);
2310 widgetbase_draw(&wtb, wcol);
2313 VECCOPY(outline, wcol->outline);
2314 VECCOPY(wcol->outline, wcol->item);
2315 VECCOPY(wcol->inner, wcol->item);
2317 if(!(state & UI_SELECT))
2318 SWAP(short, wcol->shadetop, wcol->shadedown);
2322 value= ui_get_but_val(but);
2323 fac= (value-but->softmin)*(rect1.xmax - rect1.xmin - offs)/(but->softmax - but->softmin);
2325 /* left part of slider, always rounded */
2326 rect1.xmax= rect1.xmin + ceil(offs+1.0f);
2327 round_box_edges(&wtb1, roundboxalign & ~6, &rect1, offs);
2329 widgetbase_draw(&wtb1, wcol);
2331 /* right part of slider, interpolate roundness */
2332 rect1.xmax= rect1.xmin + fac + offs;
2333 rect1.xmin+= floor(offs-1.0f);
2334 if(rect1.xmax + offs > rect->xmax)
2335 offs*= (rect1.xmax + offs - rect->xmax)/offs;
2338 round_box_edges(&wtb1, roundboxalign & ~9, &rect1, offs);
2340 widgetbase_draw(&wtb1, wcol);
2341 VECCOPY(wcol->outline, outline);
2343 if(!(state & UI_SELECT))
2344 SWAP(short, wcol->shadetop, wcol->shadedown);
2349 widgetbase_draw(&wtb, wcol);
2352 rect->xmin += toffs;
2353 rect->xmax -= toffs;
2356 /* I think 3 is sufficient border to indicate keyed status */
2357 #define SWATCH_KEYED_BORDER 3
2359 static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2363 int color_profile = but->block->color_profile;
2368 if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
2369 color_profile = BLI_PR_NONE;
2371 if(RNA_property_array_length(&but->rnapoin, but->rnaprop)==4) {
2372 col[3]= RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3);
2379 round_box_edges(&wtb, roundboxalign, rect, 5.0f);
2381 ui_get_but_vectorf(but, col);
2383 if(state & (UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN|UI_BUT_REDALERT)) {
2384 // draw based on state - color for keyed etc
2385 widgetbase_draw(&wtb, wcol);
2387 // inset to draw swatch color
2388 rect->xmin+= SWATCH_KEYED_BORDER;
2389 rect->xmax-= SWATCH_KEYED_BORDER;
2390 rect->ymin+= SWATCH_KEYED_BORDER;
2391 rect->ymax-= SWATCH_KEYED_BORDER;
2393 round_box_edges(&wtb, roundboxalign, rect, 5.0f);
2397 linearrgb_to_srgb_v3_v3(col, col);
2399 wcol->inner[0]= FTOCHAR(col[0]);
2400 wcol->inner[1]= FTOCHAR(col[1]);
2401 wcol->inner[2]= FTOCHAR(col[2]);
2402 wcol->inner[3]= FTOCHAR(col[3]);
2404 wcol->alpha_check = (wcol->inner[3] < 255);
2406 widgetbase_draw(&wtb, wcol);
2410 static void widget_icon_has_anim(uiBut *UNUSED(but), uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
2412 if(state & (UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN|UI_BUT_REDALERT)) {
2419 round_box_edges(&wtb, 15, rect, 10.0f);
2420 widgetbase_draw(&wtb, wcol);
2425 static void widget_textbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2429 if(state & UI_SELECT)
2430 SWAP(short, wcol->shadetop, wcol->shadedown);
2435 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2437 widgetbase_draw(&wtb, wcol);
2442 static void widget_menubut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2449 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2452 widget_menu_trias(&wtb.tria1, rect);
2454 widgetbase_draw(&wtb, wcol);
2457 rect->xmax -= (rect->ymax-rect->ymin);
2460 static void widget_menuiconbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2467 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2470 widgetbase_draw(&wtb, wcol);
2473 static void widget_pulldownbut(uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
2475 if(state & UI_ACTIVE) {
2477 float rad= 0.5f*(rect->ymax - rect->ymin); // 4.0f
2482 round_box_edges(&wtb, 15, rect, rad);
2484 widgetbase_draw(&wtb, wcol);
2488 static void widget_menu_itembut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
2494 /* not rounded, no outline */
2496 round_box_edges(&wtb, 0, rect, 0.0f);
2498 widgetbase_draw(&wtb, wcol);
2501 static void widget_list_itembut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
2507 /* rounded, but no outline */
2509 round_box_edges(&wtb, 15, rect, 4.0f);
2511 widgetbase_draw(&wtb, wcol);
2514 static void widget_optionbut(uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
2517 rcti recttemp= *rect;
2523 recttemp.xmax= recttemp.xmin + (recttemp.ymax-recttemp.ymin);
2526 delta= 1 + (recttemp.ymax-recttemp.ymin)/8;
2527 recttemp.xmin+= delta;
2528 recttemp.ymin+= delta;
2529 recttemp.xmax-= delta;
2530 recttemp.ymax-= delta;
2533 round_box_edges(&wtb, 15, &recttemp, 4.0f);
2536 if(state & UI_SELECT) {
2537 widget_check_trias(&wtb.tria1, &recttemp);
2540 widgetbase_draw(&wtb, wcol);
2543 rect->xmin += (rect->ymax-rect->ymin)*0.7 + delta;
2547 static void widget_radiobut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2554 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2556 widgetbase_draw(&wtb, wcol);
2560 static void widget_box(uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2567 VECCOPY(old_col, wcol->inner);
2569 /* abuse but->hsv - if it's non-zero, use this color as the box's background */
2571 wcol->inner[0] = but->col[0];
2572 wcol->inner[1] = but->col[1];
2573 wcol->inner[2] = but->col[2];
2577 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2579 widgetbase_draw(&wtb, wcol);
2581 /* store the box bg as gl clearcolor, to retrieve later when drawing semi-transparent rects
2582 * over the top to indicate disabled buttons */
2583 glClearColor(wcol->inner[0]/255.0, wcol->inner[1]/255.0, wcol->inner[2]/255.0, 1.0);
2585 VECCOPY(wcol->inner, old_col);
2588 static void widget_but(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2595 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2597 widgetbase_draw(&wtb, wcol);
2601 static void widget_roundbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2604 float rad= 5.0f; //0.5f*(rect->ymax - rect->ymin);
2609 round_box_edges(&wtb, roundboxalign, rect, rad);
2611 widgetbase_draw(&wtb, wcol);
2614 static void widget_draw_extra_mask(const bContext *C, uiBut *but, uiWidgetType *wt, rcti *rect)
2617 unsigned char col[4];
2620 wt->wcol= *(wt->wcol_theme);
2624 if(but->block->drawextra) {
2625 /* note: drawextra can change rect +1 or -1, to match round errors of existing previews */
2626 but->block->drawextra(C, but->poin, but->block->drawextra_arg1, but->block->drawextra_arg2, rect);
2628 /* make mask to draw over image */
2629 UI_GetThemeColor3ubv(TH_BACK, col);
2632 round_box__edges(&wtb, 15, rect, 0.0f, 4.0);
2633 widgetbase_outline(&wtb);
2637 round_box_edges(&wtb, 15, rect, 5.0f);
2640 widgetbase_draw(&wtb, &wt->wcol);
2645 static void widget_disabled(rcti *rect)
2651 /* can't use theme TH_BACK or TH_PANEL... undefined */
2652 glGetFloatv(GL_COLOR_CLEAR_VALUE, col);
2653 glColor4f(col[0], col[1], col[2], 0.5f);
2655 /* need -1 and +1 to make it work right for aligned buttons,
2656 * but problem may be somewhere else? */
2657 glRectf(rect->xmin-1, rect->ymin-1, rect->xmax, rect->ymax+1);
2659 glDisable(GL_BLEND);
2662 static uiWidgetType *widget_type(uiWidgetTypeEnum type)
2664 bTheme *btheme= U.themes.first;
2665 static uiWidgetType wt;
2668 wt.wcol_theme= &btheme->tui.wcol_regular;
2669 wt.wcol_state= &btheme->tui.wcol_state;
2670 wt.state= widget_state;
2671 wt.draw= widget_but;
2673 wt.text= widget_draw_text_icon;
2676 case UI_WTYPE_REGULAR:
2679 case UI_WTYPE_LABEL:
2681 wt.state= widget_state_label;
2684 case UI_WTYPE_TOGGLE:
2685 wt.wcol_theme= &btheme->tui.wcol_toggle;
2688 case UI_WTYPE_OPTION:
2689 wt.wcol_theme= &btheme->tui.wcol_option;
2690 wt.draw= widget_optionbut;
2693 case UI_WTYPE_RADIO:
2694 wt.wcol_theme= &btheme->tui.wcol_radio;
2695 wt.draw= widget_radiobut;
2698 case UI_WTYPE_NUMBER:
2699 wt.wcol_theme= &btheme->tui.wcol_num;
2700 wt.draw= widget_numbut;
2703 case UI_WTYPE_SLIDER:
2704 wt.wcol_theme= &btheme->tui.wcol_numslider;
2705 wt.custom= widget_numslider;
2706 wt.state= widget_state_numslider;
2710 wt.wcol_theme= &btheme->tui.wcol_tool;
2711 wt.draw= widget_roundbut;
2717 wt.wcol_theme= &btheme->tui.wcol_text;
2718 wt.draw= widget_textbut;
2721 case UI_WTYPE_NAME_LINK:
2724 case UI_WTYPE_POINTER_LINK:
2727 case UI_WTYPE_FILENAME:
2732 case UI_WTYPE_MENU_RADIO:
2733 wt.wcol_theme= &btheme->tui.wcol_menu;
2734 wt.draw= widget_menubut;
2737 case UI_WTYPE_MENU_ICON_RADIO:
2738 wt.wcol_theme= &btheme->tui.wcol_menu;
2739 wt.draw= widget_menuiconbut;
2742 case UI_WTYPE_MENU_POINTER_LINK:
2743 wt.wcol_theme= &btheme->tui.wcol_menu;
2744 wt.draw= widget_menubut;
2747 case UI_WTYPE_PULLDOWN:
2748 wt.wcol_theme= &btheme->tui.wcol_pulldown;
2749 wt.draw= widget_pulldownbut;
2750 wt.state= widget_state_pulldown;
2754 case UI_WTYPE_MENU_ITEM:
2755 wt.wcol_theme= &btheme->tui.wcol_menu_item;
2756 wt.draw= widget_menu_itembut;
2757 wt.state= widget_state_menu_item;
2760 case UI_WTYPE_MENU_BACK:
2761 wt.wcol_theme= &btheme->tui.wcol_menu_back;
2762 wt.draw= widget_menu_back;
2767 wt.custom= widget_icon_has_anim;
2770 case UI_WTYPE_SWATCH:
2771 wt.custom= widget_swatch;
2775 wt.custom= widget_box;
2776 wt.wcol_theme= &btheme->tui.wcol_box;
2779 case UI_WTYPE_RGB_PICKER:
2782 case UI_WTYPE_NORMAL:
2785 case UI_WTYPE_SCROLL:
2786 wt.wcol_theme= &btheme->tui.wcol_scroll;
2787 wt.state= widget_state_nothing;
2788 wt.custom= widget_scroll;
2791 case UI_WTYPE_LISTITEM:
2792 wt.wcol_theme= &btheme->tui.wcol_list_item;
2793 wt.draw= widget_list_itembut;
2796 case UI_WTYPE_PROGRESSBAR:
2797 wt.wcol_theme= &btheme->tui.wcol_progress;
2798 wt.custom= widget_progressbar;
2806 static int widget_roundbox_set(uiBut *but, rcti *rect)
2809 if(but->flag & UI_BUT_ALIGN) {
2811 if(but->flag & UI_BUT_ALIGN_TOP)
2813 if(but->flag & UI_BUT_ALIGN_LEFT)
2816 switch(but->flag & UI_BUT_ALIGN) {
2817 case UI_BUT_ALIGN_TOP:
2820 case UI_BUT_ALIGN_DOWN:
2823 case UI_BUT_ALIGN_LEFT:
2826 case UI_BUT_ALIGN_RIGHT:
2830 case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT:
2833 case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT:
2836 case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT:
2839 case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT:
2851 /* conversion from old to new buttons, so still messy */
2852 void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rcti *rect)
2854 bTheme *btheme= U.themes.first;
2855 ThemeUI *tui= &btheme->tui;
2856 uiFontStyle *fstyle= &style->widget;
2857 uiWidgetType *wt= NULL;
2859 /* handle menus separately */
2860 if(but->dt==UI_EMBOSSP) {
2861 switch (but->type) {
2863 widget_draw_text_icon(&style->widgetlabel, &tui->wcol_menu_back, but, rect);
2866 ui_draw_separator(rect, &tui->wcol_menu_item);
2870 wt= widget_type(UI_WTYPE_MENU_ITEM);
2873 else if(but->dt==UI_EMBOSSN) {
2875 wt= widget_type(UI_WTYPE_ICON);
2879 switch (but->type) {
2881 if(but->block->flag & UI_BLOCK_LOOP)
2882 widget_draw_text_icon(&style->widgetlabel, &tui->wcol_menu_back, but, rect);
2884 wt= widget_type(UI_WTYPE_LABEL);
2885 fstyle= &style->widgetlabel;
2893 wt= widget_type(UI_WTYPE_EXEC);
2897 wt= widget_type(UI_WTYPE_NUMBER);
2902 wt= widget_type(UI_WTYPE_SLIDER);
2906 wt= widget_type(UI_WTYPE_RADIO);
2910 wt= widget_type(UI_WTYPE_LISTITEM);
2914 wt= widget_type(UI_WTYPE_NAME);
2918 wt= widget_type(UI_WTYPE_NAME);
2919 if(but->block->flag & UI_BLOCK_LOOP)
2920 wt->wcol_theme= &btheme->tui.wcol_menu_back;
2927 wt= widget_type(UI_WTYPE_TOGGLE);
2932 if (!(but->flag & UI_HAS_ICON)) {
2933 wt= widget_type(UI_WTYPE_OPTION);
2934 but->flag |= UI_TEXT_LEFT;
2937 wt= widget_type(UI_WTYPE_TOGGLE);
2943 if(!but->str[0] && but->icon)
2944 wt= widget_type(UI_WTYPE_MENU_ICON_RADIO);
2946 wt= widget_type(UI_WTYPE_MENU_RADIO);
2950 wt= widget_type(UI_WTYPE_PULLDOWN);
2954 wt= widget_type(UI_WTYPE_MENU_ITEM);
2958 wt= widget_type(UI_WTYPE_SWATCH);
2963 wt= widget_type(UI_WTYPE_BOX);
2968 wt= widget_type(UI_WTYPE_ICON);
2969 wt->custom= widget_link;
2974 widget_draw_extra_mask(C, but, widget_type(UI_WTYPE_BOX), rect);
2978 if(but->a1 == UI_GRAD_V_ALT) // vertical V slider, uses new widget draw now
2979 ui_draw_but_HSV_v(but, rect);
2980 else // other HSV pickers...
2981 ui_draw_but_HSVCUBE(but, rect);
2985 ui_draw_but_HSVCIRCLE(but, &tui->wcol_regular, rect);
2989 ui_draw_but_COLORBAND(but, &tui->wcol_regular, rect);
2993 ui_draw_but_NORMAL(but, &tui->wcol_regular, rect);
2997 ui_draw_but_IMAGE(ar, but, &tui->wcol_regular, rect);
3001 ui_draw_but_HISTOGRAM(ar, but, &tui->wcol_regular, rect);
3005 ui_draw_but_WAVEFORM(ar, but, &tui->wcol_regular, rect);
3009 ui_draw_but_VECTORSCOPE(ar, but, &tui->wcol_regular, rect);
3013 ui_draw_but_CURVE(ar, but, &tui->wcol_regular, rect);
3017 wt= widget_type(UI_WTYPE_PROGRESSBAR);
3018 fstyle= &style->widgetlabel;
3022 wt= widget_type(UI_WTYPE_SCROLL);
3026 wt= widget_type(UI_WTYPE_REGULAR);
3031 rcti disablerect= *rect; /* rect gets clipped smaller for text */
3032 int roundboxalign, state;
3034 roundboxalign= widget_roundbox_set(but, rect);
3037 if(but->editstr) state |= UI_TEXTINPUT;
3039 wt->state(wt, state);
3041 wt->custom(but, &wt->wcol, rect, state, roundboxalign);
3043 wt->draw(&wt->wcol, rect, state, roundboxalign);
3044 wt->text(fstyle, &wt->wcol, but, rect);
3046 if(state & (UI_BUT_DISABLED|UI_BUT_INACTIVE))
3047 if(but->dt!=UI_EMBOSSP)
3048 widget_disabled(&disablerect);