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 *****
26 /** \file blender/editors/interface/interface_widgets.c
27 * \ingroup edinterface
37 #include "DNA_screen_types.h"
38 #include "DNA_userdef_types.h"
41 #include "BLI_listbase.h"
43 #include "BLI_string.h"
44 #include "BLI_utildefines.h"
46 #include "BKE_context.h"
47 #include "BKE_curve.h"
48 #include "BKE_utildefines.h"
50 #include "RNA_access.h"
53 #include "BIF_glutil.h"
57 #include "UI_interface.h"
58 #include "UI_interface_icons.h"
61 #include "interface_intern.h"
63 /* ************** widget base functions ************** */
65 - in: roundbox codes for corner types and radius
66 - return: array of [size][2][x,y] points, the edges of the roundbox, + UV coords
68 - draw black box with alpha 0 on exact button boundbox
70 - draw the inner part for a round filled box, with color blend codes or texture coords
71 - draw outline in outline color
72 - draw outer part, bottom half, extruded 1 pixel to bottom, for emboss shadow
73 - draw extra decorations
74 - draw background color box with alpha 1 on exact button boundbox
78 /* fill this struct with polygon info to draw AA'ed */
79 /* it has outline, back, and two optional tria meshes */
81 typedef struct uiWidgetTrias {
85 unsigned int (*index)[3];
89 /* max as used by round_box__edges */
90 #define WIDGET_CURVE_RESOLU 9
91 #define WIDGET_SIZE_MAX (WIDGET_CURVE_RESOLU*4)
93 typedef struct uiWidgetBase {
95 int totvert, halfwayvert;
96 float outer_v[WIDGET_SIZE_MAX][2];
97 float inner_v[WIDGET_SIZE_MAX][2];
98 float inner_uv[WIDGET_SIZE_MAX][2];
100 short inner, outline, emboss; /* set on/off */
108 /* uiWidgetType: for time being only for visual appearance,
109 later, a handling callback can be added too
111 typedef struct uiWidgetType {
113 /* pointer to theme color definition */
114 uiWidgetColors *wcol_theme;
115 uiWidgetStateColors *wcol_state;
117 /* converted colors for state */
120 void (*state)(struct uiWidgetType *, int state);
121 void (*draw)(uiWidgetColors *, rcti *, int state, int roundboxalign);
122 void (*custom)(uiBut *, uiWidgetColors *, rcti *, int state, int roundboxalign);
123 void (*text)(uiFontStyle *, uiWidgetColors *, uiBut *, rcti *);
128 /* *********************** draw data ************************** */
130 static float cornervec[WIDGET_CURVE_RESOLU][2]= {{0.0, 0.0}, {0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169},
131 {0.707, 0.293}, {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}, {1.0, 1.0}};
133 static float jit[8][2]= {{0.468813 , -0.481430}, {-0.155755 , -0.352820},
134 {0.219306 , -0.238501}, {-0.393286 , -0.110949}, {-0.024699 , 0.013908},
135 {0.343805 , 0.147431}, {-0.272855 , 0.269918}, {0.095909 , 0.388710}};
137 static float num_tria_vert[3][2]= {
138 {-0.352077, 0.532607}, {-0.352077, -0.549313}, {0.330000, -0.008353}};
140 static unsigned int num_tria_face[1][3]= {
143 static float scroll_circle_vert[16][2]= {
144 {0.382684, 0.923879}, {0.000001, 1.000000}, {-0.382683, 0.923880}, {-0.707107, 0.707107},
145 {-0.923879, 0.382684}, {-1.000000, 0.000000}, {-0.923880, -0.382684}, {-0.707107, -0.707107},
146 {-0.382683, -0.923880}, {0.000000, -1.000000}, {0.382684, -0.923880}, {0.707107, -0.707107},
147 {0.923880, -0.382684}, {1.000000, -0.000000}, {0.923880, 0.382683}, {0.707107, 0.707107}};
149 static unsigned int scroll_circle_face[14][3]= {
150 {0, 1, 2}, {2, 0, 3}, {3, 0, 15}, {3, 15, 4}, {4, 15, 14}, {4, 14, 5}, {5, 14, 13}, {5, 13, 6},
151 {6, 13, 12}, {6, 12, 7}, {7, 12, 11}, {7, 11, 8}, {8, 11, 10}, {8, 10, 9}};
153 static float menu_tria_vert[6][2]= {
154 {-0.41, 0.16}, {0.41, 0.16}, {0, 0.82},
155 {0, -0.82}, {-0.41, -0.16}, {0.41, -0.16}};
157 static unsigned int menu_tria_face[2][3]= {{2, 0, 1}, {3, 5, 4}};
159 static float check_tria_vert[6][2]= {
160 {-0.578579, 0.253369}, {-0.392773, 0.412794}, {-0.004241, -0.328551},
161 {-0.003001, 0.034320}, {1.055313, 0.864744}, {0.866408, 1.026895}};
163 static unsigned int check_tria_face[4][3]= {
164 {3, 2, 4}, {3, 4, 5}, {1, 0, 3}, {0, 2, 3}};
166 GLubyte checker_stipple_sml[32*32/8] =
168 255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
169 255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
170 0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
171 0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
172 255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
173 255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
174 0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
175 0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
178 /* ************************************************* */
180 void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3)
182 float tri_arr[3][2]= {{x1, y1}, {x2, y2}, {x3, y3}};
187 glGetFloatv(GL_CURRENT_COLOR, color);
191 glEnableClientState(GL_VERTEX_ARRAY);
192 glVertexPointer(2, GL_FLOAT, 0, tri_arr);
194 /* for each AA step */
196 glTranslatef(1.0f * jit[j][0], 1.0f * jit[j][1], 0.0f);
197 glDrawArrays(GL_TRIANGLES, 0, 3);
198 glTranslatef(-1.0f * jit[j][0], -1.0f * jit[j][1], 0.0f);
201 glDisableClientState(GL_VERTEX_ARRAY);
206 static void widget_init(uiWidgetBase *wtb)
208 wtb->totvert= wtb->halfwayvert= 0;
218 /* helper call, makes shadow rect, with 'sun' above menu, so only shadow to left/right/bottom */
220 static int round_box_shadow_edges(float (*vert)[2], rcti *rect, float rad, int roundboxalign, float step)
222 float vec[WIDGET_CURVE_RESOLU][2];
223 float minx, miny, maxx, maxy;
228 if(2.0f*rad > rect->ymax-rect->ymin)
229 rad= 0.5f*(rect->ymax-rect->ymin);
231 minx= rect->xmin-step;
232 miny= rect->ymin-step;
233 maxx= rect->xmax+step;
234 maxy= rect->ymax+step;
237 for(a=0; a < WIDGET_CURVE_RESOLU; a++) {
238 vec[a][0]= rad*cornervec[a][0];
239 vec[a][1]= rad*cornervec[a][1];
242 /* start with left-top, anti clockwise */
243 if(roundboxalign & UI_CNR_TOP_LEFT) {
244 for(a=0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
245 vert[tot][0]= minx+rad-vec[a][0];
246 vert[tot][1]= maxy-vec[a][1];
250 for(a=0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
256 if(roundboxalign & UI_CNR_BOTTOM_LEFT) {
257 for(a=0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
258 vert[tot][0]= minx+vec[a][1];
259 vert[tot][1]= miny+rad-vec[a][0];
263 for(a=0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
269 if(roundboxalign & UI_CNR_BOTTOM_RIGHT) {
270 for(a=0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
271 vert[tot][0]= maxx-rad+vec[a][0];
272 vert[tot][1]= miny+vec[a][1];
276 for(a=0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
282 if(roundboxalign & UI_CNR_TOP_RIGHT) {
283 for(a=0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
284 vert[tot][0]= maxx-vec[a][1];
285 vert[tot][1]= maxy-rad+vec[a][0];
289 for(a=0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
297 /* this call has 1 extra arg to allow mask outline */
298 static void round_box__edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, float rad, float radi)
300 float vec[WIDGET_CURVE_RESOLU][2], veci[WIDGET_CURVE_RESOLU][2];
301 float minx= rect->xmin, miny= rect->ymin, maxx= rect->xmax, maxy= rect->ymax;
302 float minxi= minx + 1.0f; /* boundbox inner */
303 float maxxi= maxx - 1.0f;
304 float minyi= miny + 1.0f;
305 float maxyi= maxy - 1.0f;
306 float facxi= (maxxi!=minxi) ? 1.0f/(maxxi-minxi) : 0.0f; /* for uv, can divide by zero */
307 float facyi= (maxyi!=minyi) ? 1.0f/(maxyi-minyi) : 0.0f;
308 int a, tot= 0, minsize;
309 const int hnum= ((roundboxalign & (UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT))==(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT) ||
310 (roundboxalign & (UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT))==(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT)) ? 1 : 2;
311 const int vnum= ((roundboxalign & (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT))==(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT) ||
312 (roundboxalign & (UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT))==(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT)) ? 1 : 2;
314 minsize= MIN2((rect->xmax-rect->xmin)*hnum, (rect->ymax-rect->ymin)*vnum);
316 if(2.0f*rad > minsize)
319 if(2.0f*(radi+1.0f) > minsize)
320 radi= 0.5f*minsize - 1.0f;
323 for(a=0; a < WIDGET_CURVE_RESOLU; a++) {
324 veci[a][0]= radi*cornervec[a][0];
325 veci[a][1]= radi*cornervec[a][1];
326 vec[a][0]= rad*cornervec[a][0];
327 vec[a][1]= rad*cornervec[a][1];
330 /* corner left-bottom */
331 if(roundboxalign & UI_CNR_BOTTOM_LEFT) {
333 for(a=0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
334 wt->inner_v[tot][0]= minxi+veci[a][1];
335 wt->inner_v[tot][1]= minyi+radi-veci[a][0];
337 wt->outer_v[tot][0]= minx+vec[a][1];
338 wt->outer_v[tot][1]= miny+rad-vec[a][0];
340 wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
341 wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
345 wt->inner_v[tot][0]= minxi;
346 wt->inner_v[tot][1]= minyi;
348 wt->outer_v[tot][0]= minx;
349 wt->outer_v[tot][1]= miny;
351 wt->inner_uv[tot][0]= 0.0f;
352 wt->inner_uv[tot][1]= 0.0f;
357 /* corner right-bottom */
358 if(roundboxalign & UI_CNR_BOTTOM_RIGHT) {
360 for(a=0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
361 wt->inner_v[tot][0]= maxxi-radi+veci[a][0];
362 wt->inner_v[tot][1]= minyi+veci[a][1];
364 wt->outer_v[tot][0]= maxx-rad+vec[a][0];
365 wt->outer_v[tot][1]= miny+vec[a][1];
367 wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
368 wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
372 wt->inner_v[tot][0]= maxxi;
373 wt->inner_v[tot][1]= minyi;
375 wt->outer_v[tot][0]= maxx;
376 wt->outer_v[tot][1]= miny;
378 wt->inner_uv[tot][0]= 1.0f;
379 wt->inner_uv[tot][1]= 0.0f;
384 wt->halfwayvert= tot;
386 /* corner right-top */
387 if(roundboxalign & UI_CNR_TOP_RIGHT) {
389 for(a=0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
390 wt->inner_v[tot][0]= maxxi-veci[a][1];
391 wt->inner_v[tot][1]= maxyi-radi+veci[a][0];
393 wt->outer_v[tot][0]= maxx-vec[a][1];
394 wt->outer_v[tot][1]= maxy-rad+vec[a][0];
396 wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
397 wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
401 wt->inner_v[tot][0]= maxxi;
402 wt->inner_v[tot][1]= maxyi;
404 wt->outer_v[tot][0]= maxx;
405 wt->outer_v[tot][1]= maxy;
407 wt->inner_uv[tot][0]= 1.0f;
408 wt->inner_uv[tot][1]= 1.0f;
413 /* corner left-top */
414 if(roundboxalign & UI_CNR_TOP_LEFT) {
416 for(a=0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
417 wt->inner_v[tot][0]= minxi+radi-veci[a][0];
418 wt->inner_v[tot][1]= maxyi-veci[a][1];
420 wt->outer_v[tot][0]= minx+rad-vec[a][0];
421 wt->outer_v[tot][1]= maxy-vec[a][1];
423 wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
424 wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
430 wt->inner_v[tot][0]= minxi;
431 wt->inner_v[tot][1]= maxyi;
433 wt->outer_v[tot][0]= minx;
434 wt->outer_v[tot][1]= maxy;
436 wt->inner_uv[tot][0]= 0.0f;
437 wt->inner_uv[tot][1]= 1.0f;
442 BLI_assert(tot <= WIDGET_SIZE_MAX);
447 static void round_box_edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, float rad)
449 round_box__edges(wt, roundboxalign, rect, rad, rad-1.0f);
453 /* based on button rect, return scaled array of triangles */
454 static void widget_num_tria(uiWidgetTrias *tria, rcti *rect, float triasize, char where)
456 float centx, centy, sizex, sizey, minsize;
459 minsize= MIN2(rect->xmax-rect->xmin, rect->ymax-rect->ymin);
461 /* center position and size */
462 centx= (float)rect->xmin + 0.5f*minsize;
463 centy= (float)rect->ymin + 0.5f*minsize;
464 sizex= sizey= -0.5f*triasize*minsize;
467 centx= (float)rect->xmax - 0.5f*minsize;
470 else if(where=='t') {
471 centy= (float)rect->ymax - 0.5f*minsize;
475 else if(where=='b') {
481 tria->vec[a][0]= sizex*num_tria_vert[a][i1] + centx;
482 tria->vec[a][1]= sizey*num_tria_vert[a][i2] + centy;
486 tria->index= num_tria_face;
489 static void widget_scroll_circle(uiWidgetTrias *tria, rcti *rect, float triasize, char where)
491 float centx, centy, sizex, sizey, minsize;
494 minsize= MIN2(rect->xmax-rect->xmin, rect->ymax-rect->ymin);
496 /* center position and size */
497 centx= (float)rect->xmin + 0.5f*minsize;
498 centy= (float)rect->ymin + 0.5f*minsize;
499 sizex= sizey= -0.5f*triasize*minsize;
502 centx= (float)rect->xmax - 0.5f*minsize;
505 else if(where=='t') {
506 centy= (float)rect->ymax - 0.5f*minsize;
510 else if(where=='b') {
515 for(a=0; a<16; a++) {
516 tria->vec[a][0]= sizex*scroll_circle_vert[a][i1] + centx;
517 tria->vec[a][1]= sizey*scroll_circle_vert[a][i2] + centy;
521 tria->index= scroll_circle_face;
524 static void widget_trias_draw(uiWidgetTrias *tria)
526 glEnableClientState(GL_VERTEX_ARRAY);
527 glVertexPointer(2, GL_FLOAT, 0, tria->vec);
528 glDrawElements(GL_TRIANGLES, tria->tot*3, GL_UNSIGNED_INT, tria->index);
529 glDisableClientState(GL_VERTEX_ARRAY);
532 static void widget_menu_trias(uiWidgetTrias *tria, rcti *rect)
534 float centx, centy, size, asp;
537 /* center position and size */
538 centx= rect->xmax - 0.5f*(rect->ymax-rect->ymin);
539 centy= rect->ymin + 0.5f*(rect->ymax-rect->ymin);
540 size= 0.4f*(rect->ymax-rect->ymin);
543 asp= ((float)rect->xmax-rect->xmin)/((float)rect->ymax-rect->ymin);
544 if(asp > 1.2f && asp < 2.6f)
545 centx= rect->xmax - 0.3f*(rect->ymax-rect->ymin);
548 tria->vec[a][0]= size*menu_tria_vert[a][0] + centx;
549 tria->vec[a][1]= size*menu_tria_vert[a][1] + centy;
553 tria->index= menu_tria_face;
556 static void widget_check_trias(uiWidgetTrias *tria, rcti *rect)
558 float centx, centy, size;
561 /* center position and size */
562 centx= rect->xmin + 0.5f*(rect->ymax-rect->ymin);
563 centy= rect->ymin + 0.5f*(rect->ymax-rect->ymin);
564 size= 0.5f*(rect->ymax-rect->ymin);
567 tria->vec[a][0]= size*check_tria_vert[a][0] + centx;
568 tria->vec[a][1]= size*check_tria_vert[a][1] + centy;
572 tria->index= check_tria_face;
576 /* prepares shade colors */
577 static void shadecolors4(char coltop[4], char *coldown, const char *color, short shadetop, short shadedown)
580 coltop[0]= CLAMPIS(color[0]+shadetop, 0, 255);
581 coltop[1]= CLAMPIS(color[1]+shadetop, 0, 255);
582 coltop[2]= CLAMPIS(color[2]+shadetop, 0, 255);
585 coldown[0]= CLAMPIS(color[0]+shadedown, 0, 255);
586 coldown[1]= CLAMPIS(color[1]+shadedown, 0, 255);
587 coldown[2]= CLAMPIS(color[2]+shadedown, 0, 255);
588 coldown[3]= color[3];
591 static void round_box_shade_col4_r(unsigned char col_r[4], const char col1[4], const char col2[4], const float fac)
593 const int faci= FTOCHAR(fac);
594 const int facm= 255-faci;
596 col_r[0]= (faci*col1[0] + facm*col2[0])>>8;
597 col_r[1]= (faci*col1[1] + facm*col2[1])>>8;
598 col_r[2]= (faci*col1[2] + facm*col2[2])>>8;
599 col_r[3]= (faci*col1[3] + facm*col2[3])>>8;
602 static void widget_verts_to_quad_strip(uiWidgetBase *wtb, const int totvert, float quad_strip[WIDGET_SIZE_MAX*2+2][2])
605 for(a=0; a<totvert; a++) {
606 copy_v2_v2(quad_strip[a*2], wtb->outer_v[a]);
607 copy_v2_v2(quad_strip[a*2+1], wtb->inner_v[a]);
609 copy_v2_v2(quad_strip[a*2], wtb->outer_v[0]);
610 copy_v2_v2(quad_strip[a*2+1], wtb->inner_v[0]);
613 static void widget_verts_to_quad_strip_open(uiWidgetBase *wtb, const int totvert, float quad_strip[WIDGET_SIZE_MAX*2][2])
616 for(a=0; a<totvert; a++) {
617 quad_strip[a*2][0]= wtb->outer_v[a][0];
618 quad_strip[a*2][1]= wtb->outer_v[a][1];
619 quad_strip[a*2+1][0]= wtb->outer_v[a][0];
620 quad_strip[a*2+1][1]= wtb->outer_v[a][1] - 1.0f;
624 static void widgetbase_outline(uiWidgetBase *wtb)
626 float quad_strip[WIDGET_SIZE_MAX*2+2][2]; /* + 2 because the last pair is wrapped */
627 widget_verts_to_quad_strip(wtb, wtb->totvert, quad_strip);
629 glEnableClientState(GL_VERTEX_ARRAY);
630 glVertexPointer(2, GL_FLOAT, 0, quad_strip);
631 glDrawArrays(GL_QUAD_STRIP, 0, wtb->totvert*2 + 2);
632 glDisableClientState(GL_VERTEX_ARRAY);
635 static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
641 /* backdrop non AA */
643 if(wcol->shaded==0) {
644 if (wcol->alpha_check) {
645 float inner_v_half[WIDGET_SIZE_MAX][2];
646 float x_mid= 0.0f; /* used for dumb clamping of values */
649 glColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255);
650 glEnableClientState(GL_VERTEX_ARRAY);
651 glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
652 glDrawArrays(GL_POLYGON, 0, wtb->totvert);
653 glDisableClientState(GL_VERTEX_ARRAY);
656 glEnable(GL_POLYGON_STIPPLE);
657 glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255);
658 glPolygonStipple(checker_stipple_sml);
660 glEnableClientState(GL_VERTEX_ARRAY);
661 glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
662 glDrawArrays(GL_POLYGON, 0, wtb->totvert);
663 glDisableClientState(GL_VERTEX_ARRAY);
665 glDisable(GL_POLYGON_STIPPLE);
668 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
670 glColor4ubv((unsigned char*)wcol->inner);
671 glEnableClientState(GL_VERTEX_ARRAY);
673 for(a=0; a<wtb->totvert; a++) {
674 x_mid += wtb->inner_v[a][0];
676 x_mid /= wtb->totvert;
678 glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
679 glDrawArrays(GL_POLYGON, 0, wtb->totvert);
680 glDisableClientState(GL_VERTEX_ARRAY);
682 /* 1/2 solid color */
683 glColor4ub(wcol->inner[0], wcol->inner[1], wcol->inner[2], 255);
685 for(a=0; a<wtb->totvert; a++) {
686 inner_v_half[a][0]= MIN2(wtb->inner_v[a][0], x_mid);
687 inner_v_half[a][1]= wtb->inner_v[a][1];
690 glEnableClientState(GL_VERTEX_ARRAY);
691 glVertexPointer(2, GL_FLOAT, 0, inner_v_half);
692 glDrawArrays(GL_POLYGON, 0, wtb->totvert);
693 glDisableClientState(GL_VERTEX_ARRAY);
697 glColor4ubv((unsigned char*)wcol->inner);
699 glEnableClientState(GL_VERTEX_ARRAY);
700 glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
701 glDrawArrays(GL_POLYGON, 0, wtb->totvert);
702 glDisableClientState(GL_VERTEX_ARRAY);
706 char col1[4], col2[4];
707 unsigned char col_array[WIDGET_SIZE_MAX * 4];
708 unsigned char *col_pt= col_array;
710 shadecolors4(col1, col2, wcol->inner, wcol->shadetop, wcol->shadedown);
712 glShadeModel(GL_SMOOTH);
713 for(a=0; a<wtb->totvert; a++, col_pt += 4) {
714 round_box_shade_col4_r(col_pt, col1, col2, wtb->inner_uv[a][wtb->shadedir]);
717 glEnableClientState(GL_VERTEX_ARRAY);
718 glEnableClientState(GL_COLOR_ARRAY);
719 glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
720 glColorPointer(4, GL_UNSIGNED_BYTE, 0, col_array);
721 glDrawArrays(GL_POLYGON, 0, wtb->totvert);
722 glDisableClientState(GL_VERTEX_ARRAY);
723 glDisableClientState(GL_COLOR_ARRAY);
725 glShadeModel(GL_FLAT);
729 /* for each AA step */
731 float quad_strip[WIDGET_SIZE_MAX*2+2][2]; /* + 2 because the last pair is wrapped */
732 float quad_strip_emboss[WIDGET_SIZE_MAX*2][2]; /* only for emboss */
734 widget_verts_to_quad_strip(wtb, wtb->totvert, quad_strip);
737 widget_verts_to_quad_strip_open(wtb, wtb->halfwayvert, quad_strip_emboss);
740 glEnableClientState(GL_VERTEX_ARRAY);
743 glTranslatef(1.0f * jit[j][0], 1.0f * jit[j][1], 0.0f);
746 glColor4ub(wcol->outline[0], wcol->outline[1], wcol->outline[2], 32);
748 glVertexPointer(2, GL_FLOAT, 0, quad_strip);
749 glDrawArrays(GL_QUAD_STRIP, 0, wtb->totvert*2 + 2);
751 /* emboss bottom shadow */
753 glColor4f(1.0f, 1.0f, 1.0f, 0.02f);
755 glVertexPointer(2, GL_FLOAT, 0, quad_strip_emboss);
756 glDrawArrays(GL_QUAD_STRIP, 0, wtb->halfwayvert*2);
759 glTranslatef(-1.0f * jit[j][0], -1.0f * jit[j][1], 0.0f);
762 glDisableClientState(GL_VERTEX_ARRAY);
766 if(wtb->tria1.tot || wtb->tria2.tot) {
767 /* for each AA step */
769 glTranslatef(1.0f * jit[j][0], 1.0f * jit[j][1], 0.0f);
772 glColor4ub(wcol->item[0], wcol->item[1], wcol->item[2], 32);
773 widget_trias_draw(&wtb->tria1);
776 glColor4ub(wcol->item[0], wcol->item[1], wcol->item[2], 32);
777 widget_trias_draw(&wtb->tria2);
780 glTranslatef(-1.0f * jit[j][0], -1.0f * jit[j][1], 0.0f);
788 /* *********************** text/icon ************************************** */
790 #define PREVIEW_PAD 4
792 static void widget_draw_preview(BIFIconID icon, float UNUSED(alpha), rcti *rect)
799 w = rect->xmax - rect->xmin;
800 h = rect->ymax - rect->ymin;
802 size -= PREVIEW_PAD*2; /* padding */
805 int x = rect->xmin + w/2 - size/2;
806 int y = rect->ymin + h/2 - size/2;
808 UI_icon_draw_preview_aspect_size(x, y, icon, 1.0f, size);
813 /* icons have been standardized... and this call draws in untransformed coordinates */
815 static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, rcti *rect)
818 float aspect, height;
820 if (but->flag & UI_ICON_PREVIEW) {
821 widget_draw_preview(icon, alpha, rect);
825 /* this icon doesn't need draw... */
826 if(icon==ICON_BLANK1 && (but->flag & UI_ICON_SUBMENU)==0) return;
828 /* we need aspect from block, for menus... these buttons are scaled in uiPositionBlock() */
829 aspect= but->block->aspect;
830 if(aspect != but->aspect) {
831 /* prevent scaling up icon in pupmenu */
833 height= UI_DPI_ICON_SIZE;
838 height= UI_DPI_ICON_SIZE/aspect;
841 height= UI_DPI_ICON_SIZE;
843 /* calculate blend color */
844 if ELEM4(but->type, TOG, ROW, TOGN, LISTROW) {
845 if(but->flag & UI_SELECT);
846 else if(but->flag & UI_ACTIVE);
850 /* extra feature allows more alpha blending */
851 if(but->type==LABEL && but->a1==1.0f) alpha *= but->a2;
855 if(icon && icon!=ICON_BLANK1) {
856 if(but->flag & UI_ICON_LEFT) {
857 if (but->type==BUT_TOGDUAL) {
858 if (but->drawstr[0]) {
861 xs= (rect->xmin+rect->xmax- height)/2;
864 else if (but->block->flag & UI_BLOCK_LOOP) {
865 if(but->type==SEARCH_MENU)
870 else if ((but->type==ICONROW) || (but->type==ICONTEXTROW)) {
876 ys= (rect->ymin+rect->ymax- height)/2;
879 xs= (rect->xmin+rect->xmax- height)/2;
880 ys= (rect->ymin+rect->ymax- height)/2;
883 /* to indicate draggable */
884 if(but->dragpoin && (but->flag & UI_ACTIVE)) {
885 float rgb[3]= {1.25f, 1.25f, 1.25f};
886 UI_icon_draw_aspect_color(xs, ys, icon, aspect, rgb);
889 UI_icon_draw_aspect(xs, ys, icon, aspect, alpha);
892 if((but->flag & UI_ICON_SUBMENU) && (but->dt == UI_EMBOSSP)) {
894 ys= (rect->ymin+rect->ymax- height)/2;
896 UI_icon_draw_aspect(xs, ys, ICON_RIGHTARROW_THIN, aspect, alpha);
902 /* sets but->ofs to make sure text is correctly visible */
903 static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
905 int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10;
906 int okwidth= rect->xmax-rect->xmin - border;
908 if (but->flag & UI_HAS_ICON) okwidth -= UI_DPI_ICON_SIZE;
910 /* need to set this first */
911 uiStyleFontSet(fstyle);
913 if (fstyle->kerning==1) /* for BLF_width */
914 BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
916 /* if text editing we define ofs dynamically */
917 if(but->editstr && but->pos >= 0) {
918 if(but->ofs > but->pos)
923 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
925 while(but->strwidth > okwidth) {
927 /* textbut exception, clip right when... */
928 if(but->editstr && but->pos >= 0) {
930 char buf[UI_MAX_DRAW_STR];
932 /* copy draw string */
933 BLI_strncpy(buf, but->drawstr, sizeof(buf));
934 /* string position of cursor */
936 width= BLF_width(fstyle->uifont_id, buf+but->ofs);
938 /* if cursor is at 20 pixels of right side button we clip left */
939 if(width > okwidth-20)
942 /* shift string to the left */
943 if(width < 20 && but->ofs > 0)
945 but->drawstr[ strlen(but->drawstr)-1 ]= 0;
951 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
953 if(but->strwidth < 10) break;
956 if (fstyle->kerning==1)
957 BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
960 static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
962 int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10;
963 int okwidth= rect->xmax-rect->xmin - border;
965 char *cpend = but->drawstr + strlen(but->drawstr);
967 /* need to set this first */
968 uiStyleFontSet(fstyle);
970 if (fstyle->kerning==1) /* for BLF_width */
971 BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
973 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr);
976 /* find the space after ':' separator */
977 cpoin= strrchr(but->drawstr, ':');
979 if (cpoin && (cpoin < cpend-2)) {
982 /* chop off the leading text, starting from the right */
983 while (but->strwidth > okwidth && cp2 > but->drawstr) {
984 /* shift the text after and including cp2 back by 1 char, +1 to include null terminator */
985 memmove(cp2-1, cp2, strlen(cp2)+1);
988 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
989 if(but->strwidth < 10) break;
993 /* after the leading text is gone, chop off the : and following space, with ofs */
994 while ((but->strwidth > okwidth) && (but->ofs < 2))
997 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
998 if(but->strwidth < 10) break;
1003 /* once the label's gone, chop off the least significant digits */
1004 while(but->strwidth > okwidth ) {
1005 int pos= strlen(but->drawstr);
1007 but->drawstr[ pos-1 ] = 0;
1010 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
1011 if(but->strwidth < 10) break;
1014 if (fstyle->kerning==1)
1015 BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
1019 static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
1024 /* for underline drawing */
1025 float font_xofs, font_yofs;
1027 uiStyleFontSet(fstyle);
1029 if(but->editstr || (but->flag & UI_TEXT_LEFT))
1030 fstyle->align= UI_STYLE_TEXT_LEFT;
1032 fstyle->align= UI_STYLE_TEXT_CENTER;
1034 if (fstyle->kerning==1) /* for BLF_width */
1035 BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
1037 /* text button selection and cursor */
1038 if(but->editstr && but->pos != -1) {
1039 short t=0, pos=0, ch;
1040 short selsta_tmp, selend_tmp, selsta_draw, selwidth_draw;
1042 if ((but->selend - but->selsta) > 0) {
1043 /* text button selection */
1044 selsta_tmp = but->selsta;
1045 selend_tmp = but->selend;
1047 if(but->drawstr[0]!=0) {
1049 if (but->selsta >= but->ofs) {
1050 ch= but->drawstr[selsta_tmp];
1051 but->drawstr[selsta_tmp]= 0;
1053 selsta_draw = BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
1055 but->drawstr[selsta_tmp]= ch;
1059 ch= but->drawstr[selend_tmp];
1060 but->drawstr[selend_tmp]= 0;
1062 selwidth_draw = BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
1064 but->drawstr[selend_tmp]= ch;
1066 glColor3ubv((unsigned char*)wcol->item);
1067 glRects(rect->xmin+selsta_draw, rect->ymin+2, rect->xmin+selwidth_draw, rect->ymax-2);
1072 if(pos >= but->ofs) {
1073 if(but->drawstr[0]!=0) {
1074 ch= but->drawstr[pos];
1075 but->drawstr[pos]= 0;
1077 t= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs) / but->aspect;
1079 but->drawstr[pos]= ch;
1082 glColor3f(0.20, 0.6, 0.9);
1083 glRects(rect->xmin+t, rect->ymin+2, rect->xmin+t+2, rect->ymax-2);
1088 if (fstyle->kerning == 1)
1089 BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
1091 // ui_rasterpos_safe(x, y, but->aspect);
1092 // if(but->type==IDPOIN) transopts= 0; // no translation, of course!
1093 // else transopts= ui_translate_buttons();
1095 /* cut string in 2 parts - only for menu entries */
1096 if((but->block->flag & UI_BLOCK_LOOP)) {
1097 if(ELEM5(but->type, SLI, NUM, TEX, NUMSLI, NUMABS)==0) {
1098 cpoin= strchr(but->drawstr, '|');
1099 if(cpoin) *cpoin= 0;
1103 glColor3ubv((unsigned char*)wcol->text);
1105 uiStyleFontDrawExt(fstyle, rect, but->drawstr+but->ofs, &font_xofs, &font_yofs);
1107 if(but->menu_key != '\0') {
1111 BLI_strncpy(fixedbuf, but->drawstr + but->ofs, sizeof(fixedbuf));
1113 str= strchr(fixedbuf, but->menu_key-32); /* upper case */
1115 str= strchr(fixedbuf, but->menu_key);
1121 ul_index= (int)(str - fixedbuf);
1123 if (fstyle->kerning == 1) {
1124 BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
1127 fixedbuf[ul_index]= '\0';
1128 ul_advance= BLF_width(fstyle->uifont_id, fixedbuf);
1130 BLF_position(fstyle->uifont_id, rect->xmin+font_xofs + ul_advance, rect->ymin+font_yofs, 0.0f);
1131 BLF_draw(fstyle->uifont_id, "_", 2);
1133 if (fstyle->kerning == 1) {
1134 BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
1139 /* part text right aligned */
1141 fstyle->align= UI_STYLE_TEXT_RIGHT;
1143 uiStyleFontDraw(fstyle, rect, cpoin+1);
1148 /* draws text and icons for buttons */
1149 static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
1152 if(but==NULL) return;
1154 /* clip but->drawstr to fit in available space */
1155 if (but->editstr && but->pos >= 0) {
1156 ui_text_leftclip(fstyle, but, rect);
1158 else if (ELEM4(but->type, NUM, NUMABS, NUMSLI, SLI)) {
1159 ui_text_label_rightclip(fstyle, but, rect);
1161 else if (ELEM(but->type, TEX, SEARCH_MENU)) {
1162 ui_text_leftclip(fstyle, but, rect);
1164 else if ((but->block->flag & UI_BLOCK_LOOP) && (but->type == BUT)) {
1165 ui_text_leftclip(fstyle, but, rect);
1169 /* check for button text label */
1170 if (but->type == ICONTEXTROW) {
1171 widget_draw_icon(but, (BIFIconID) (but->icon+but->iconadd), 1.0f, rect);
1175 if(but->type==BUT_TOGDUAL) {
1177 if(but->pointype==SHO)
1178 dualset= BTST( *(((short *)but->poin)+1), but->bitnr);
1179 else if(but->pointype==INT)
1180 dualset= BTST( *(((int *)but->poin)+1), but->bitnr);
1182 widget_draw_icon(but, ICON_DOT, dualset?1.0f:0.25f, rect);
1185 /* If there's an icon too (made with uiDefIconTextBut) then draw the icon
1186 and offset the text label to accommodate it */
1188 if (but->flag & UI_HAS_ICON) {
1189 widget_draw_icon(but, but->icon+but->iconadd, 1.0f, rect);
1191 rect->xmin += (int)((float)UI_icon_get_width(but->icon+but->iconadd) * UI_DPI_ICON_FAC);
1193 if(but->editstr || (but->flag & UI_TEXT_LEFT))
1196 else if((but->flag & UI_TEXT_LEFT))
1199 /* always draw text for textbutton cursor */
1200 widget_draw_text(fstyle, wcol, but, rect);
1207 /* *********************** widget types ************************************* */
1210 /* uiWidgetStateColors
1212 char inner_anim_sel[4];
1214 char inner_key_sel[4];
1215 char inner_driven[4];
1216 char inner_driven_sel[4];
1221 static struct uiWidgetStateColors wcol_state_colors= {
1222 {115, 190, 76, 255},
1224 {240, 235, 100, 255},
1225 {215, 211, 75, 255},
1240 float shadetop, shadedown;
1243 static struct uiWidgetColors wcol_num= {
1245 {180, 180, 180, 255},
1246 {153, 153, 153, 255},
1250 {255, 255, 255, 255},
1256 static struct uiWidgetColors wcol_numslider= {
1258 {180, 180, 180, 255},
1259 {153, 153, 153, 255},
1260 {128, 128, 128, 255},
1263 {255, 255, 255, 255},
1269 static struct uiWidgetColors wcol_text= {
1271 {153, 153, 153, 255},
1272 {153, 153, 153, 255},
1276 {255, 255, 255, 255},
1282 static struct uiWidgetColors wcol_option= {
1286 {255, 255, 255, 255},
1289 {255, 255, 255, 255},
1295 /* button that shows popup */
1296 static struct uiWidgetColors wcol_menu= {
1300 {255, 255, 255, 255},
1302 {255, 255, 255, 255},
1303 {204, 204, 204, 255},
1309 /* button that starts pulldown */
1310 static struct uiWidgetColors wcol_pulldown= {
1313 {86, 128, 194, 255},
1314 {255, 255, 255, 255},
1323 /* button inside menu */
1324 static struct uiWidgetColors wcol_menu_item= {
1327 {86, 128, 194, 255},
1328 {255, 255, 255, 255},
1330 {255, 255, 255, 255},
1337 /* backdrop menu + title text color */
1338 static struct uiWidgetColors wcol_menu_back= {
1342 {100, 100, 100, 255},
1344 {160, 160, 160, 255},
1345 {255, 255, 255, 255},
1352 static struct uiWidgetColors wcol_radio= {
1355 {86, 128, 194, 255},
1356 {255, 255, 255, 255},
1358 {255, 255, 255, 255},
1365 static struct uiWidgetColors wcol_regular= {
1367 {153, 153, 153, 255},
1368 {100, 100, 100, 255},
1372 {255, 255, 255, 255},
1378 static struct uiWidgetColors wcol_tool= {
1380 {153, 153, 153, 255},
1381 {100, 100, 100, 255},
1385 {255, 255, 255, 255},
1391 static struct uiWidgetColors wcol_box= {
1393 {128, 128, 128, 255},
1394 {100, 100, 100, 255},
1398 {255, 255, 255, 255},
1404 static struct uiWidgetColors wcol_toggle= {
1406 {153, 153, 153, 255},
1407 {100, 100, 100, 255},
1411 {255, 255, 255, 255},
1417 static struct uiWidgetColors wcol_scroll= {
1420 {100, 100, 100, 180},
1421 {128, 128, 128, 255},
1424 {255, 255, 255, 255},
1430 static struct uiWidgetColors wcol_progress= {
1432 {190, 190, 190, 255},
1433 {100, 100, 100, 180},
1437 {255, 255, 255, 255},
1443 static struct uiWidgetColors wcol_list_item= {
1446 {86, 128, 194, 255},
1456 /* free wcol struct to play with */
1457 static struct uiWidgetColors wcol_tmp= {
1459 {128, 128, 128, 255},
1460 {100, 100, 100, 255},
1464 {255, 255, 255, 255},
1471 /* called for theme init (new theme) and versions */
1472 void ui_widget_color_init(ThemeUI *tui)
1474 tui->wcol_regular= wcol_regular;
1475 tui->wcol_tool= wcol_tool;
1476 tui->wcol_text= wcol_text;
1477 tui->wcol_radio= wcol_radio;
1478 tui->wcol_option= wcol_option;
1479 tui->wcol_toggle= wcol_toggle;
1480 tui->wcol_num= wcol_num;
1481 tui->wcol_numslider= wcol_numslider;
1482 tui->wcol_menu= wcol_menu;
1483 tui->wcol_pulldown= wcol_pulldown;
1484 tui->wcol_menu_back= wcol_menu_back;
1485 tui->wcol_menu_item= wcol_menu_item;
1486 tui->wcol_box= wcol_box;
1487 tui->wcol_scroll= wcol_scroll;
1488 tui->wcol_list_item= wcol_list_item;
1489 tui->wcol_progress= wcol_progress;
1491 tui->wcol_state= wcol_state_colors;
1494 /* ************ button callbacks, state ***************** */
1496 static void widget_state_blend(char cp[3], const char cpstate[3], const float fac)
1499 cp[0]= (int)((1.0f-fac)*cp[0] + fac*cpstate[0]);
1500 cp[1]= (int)((1.0f-fac)*cp[1] + fac*cpstate[1]);
1501 cp[2]= (int)((1.0f-fac)*cp[2] + fac*cpstate[2]);
1505 /* copy colors from theme, and set changes in it based on state */
1506 static void widget_state(uiWidgetType *wt, int state)
1508 uiWidgetStateColors *wcol_state= wt->wcol_state;
1510 wt->wcol= *(wt->wcol_theme);
1512 if(state & UI_SELECT) {
1513 QUATCOPY(wt->wcol.inner, wt->wcol.inner_sel)
1515 if(state & UI_BUT_ANIMATED_KEY)
1516 widget_state_blend(wt->wcol.inner, wcol_state->inner_key_sel, wcol_state->blend);
1517 else if(state & UI_BUT_ANIMATED)
1518 widget_state_blend(wt->wcol.inner, wcol_state->inner_anim_sel, wcol_state->blend);
1519 else if(state & UI_BUT_DRIVEN)
1520 widget_state_blend(wt->wcol.inner, wcol_state->inner_driven_sel, wcol_state->blend);
1522 VECCOPY(wt->wcol.text, wt->wcol.text_sel);
1524 if(state & UI_SELECT)
1525 SWAP(short, wt->wcol.shadetop, wt->wcol.shadedown);
1528 if(state & UI_BUT_ANIMATED_KEY)
1529 widget_state_blend(wt->wcol.inner, wcol_state->inner_key, wcol_state->blend);
1530 else if(state & UI_BUT_ANIMATED)
1531 widget_state_blend(wt->wcol.inner, wcol_state->inner_anim, wcol_state->blend);
1532 else if(state & UI_BUT_DRIVEN)
1533 widget_state_blend(wt->wcol.inner, wcol_state->inner_driven, wcol_state->blend);
1535 if(state & UI_ACTIVE) { /* mouse over? */
1536 wt->wcol.inner[0]= wt->wcol.inner[0]>=240? 255 : wt->wcol.inner[0]+15;
1537 wt->wcol.inner[1]= wt->wcol.inner[1]>=240? 255 : wt->wcol.inner[1]+15;
1538 wt->wcol.inner[2]= wt->wcol.inner[2]>=240? 255 : wt->wcol.inner[2]+15;
1542 if(state & UI_BUT_REDALERT) {
1543 char red[4]= {255, 0, 0};
1544 widget_state_blend(wt->wcol.inner, red, 0.4f);
1548 /* sliders use special hack which sets 'item' as inner when drawing filling */
1549 static void widget_state_numslider(uiWidgetType *wt, int state)
1551 uiWidgetStateColors *wcol_state= wt->wcol_state;
1552 float blend= wcol_state->blend - 0.2f; // XXX special tweak to make sure that bar will still be visible
1554 /* call this for option button */
1555 widget_state(wt, state);
1557 /* now, set the inner-part so that it reflects state settings too */
1558 // TODO: maybe we should have separate settings for the blending colors used for this case?
1559 if(state & UI_SELECT) {
1561 if(state & UI_BUT_ANIMATED_KEY)
1562 widget_state_blend(wt->wcol.item, wcol_state->inner_key_sel, blend);
1563 else if(state & UI_BUT_ANIMATED)
1564 widget_state_blend(wt->wcol.item, wcol_state->inner_anim_sel, blend);
1565 else if(state & UI_BUT_DRIVEN)
1566 widget_state_blend(wt->wcol.item, wcol_state->inner_driven_sel, blend);
1568 if(state & UI_SELECT)
1569 SWAP(short, wt->wcol.shadetop, wt->wcol.shadedown);
1572 if(state & UI_BUT_ANIMATED_KEY)
1573 widget_state_blend(wt->wcol.item, wcol_state->inner_key, blend);
1574 else if(state & UI_BUT_ANIMATED)
1575 widget_state_blend(wt->wcol.item, wcol_state->inner_anim, blend);
1576 else if(state & UI_BUT_DRIVEN)
1577 widget_state_blend(wt->wcol.item, wcol_state->inner_driven, blend);
1581 /* labels use theme colors for text */
1582 static void widget_state_label(uiWidgetType *wt, int state)
1584 /* call this for option button */
1585 widget_state(wt, state);
1587 if(state & UI_SELECT)
1588 UI_GetThemeColor4ubv(TH_TEXT_HI, (unsigned char *)wt->wcol.text);
1590 UI_GetThemeColor4ubv(TH_TEXT, (unsigned char *)wt->wcol.text);
1594 /* labels use theme colors for text */
1595 static void widget_state_option_menu(uiWidgetType *wt, int state)
1598 /* call this for option button */
1599 widget_state(wt, state);
1601 /* if not selected we get theme from menu back */
1602 if(state & UI_SELECT)
1603 UI_GetThemeColor4ubv(TH_TEXT_HI, (unsigned char *)wt->wcol.text);
1605 bTheme *btheme= U.themes.first; /* XXX */
1607 VECCOPY(wt->wcol.text, btheme->tui.wcol_menu_back.text);
1612 static void widget_state_nothing(uiWidgetType *wt, int UNUSED(state))
1614 wt->wcol= *(wt->wcol_theme);
1617 /* special case, button that calls pulldown */
1618 static void widget_state_pulldown(uiWidgetType *wt, int state)
1620 wt->wcol= *(wt->wcol_theme);
1622 QUATCOPY(wt->wcol.inner, wt->wcol.inner_sel);
1623 VECCOPY(wt->wcol.outline, wt->wcol.inner);
1625 if(state & UI_ACTIVE)
1626 VECCOPY(wt->wcol.text, wt->wcol.text_sel);
1629 /* special case, menu items */
1630 static void widget_state_menu_item(uiWidgetType *wt, int state)
1632 wt->wcol= *(wt->wcol_theme);
1634 if(state & (UI_BUT_DISABLED|UI_BUT_INACTIVE)) {
1635 wt->wcol.text[0]= 0.5f*(wt->wcol.text[0]+wt->wcol.text_sel[0]);
1636 wt->wcol.text[1]= 0.5f*(wt->wcol.text[1]+wt->wcol.text_sel[1]);
1637 wt->wcol.text[2]= 0.5f*(wt->wcol.text[2]+wt->wcol.text_sel[2]);
1639 else if(state & UI_ACTIVE) {
1640 QUATCOPY(wt->wcol.inner, wt->wcol.inner_sel);
1641 VECCOPY(wt->wcol.text, wt->wcol.text_sel);
1646 /* ************ menu backdrop ************************* */
1648 /* outside of rect, rad to left/bottom/right */
1649 static void widget_softshadow(rcti *rect, int roundboxalign, float radin, float radout)
1653 float alpha, alphastep;
1655 float quad_strip[WIDGET_SIZE_MAX*2][2];
1657 /* prevent tooltips to not show round shadow */
1658 if( 2.0f*radout > 0.2f*(rect1.ymax-rect1.ymin) )
1659 rect1.ymax -= 0.2f*(rect1.ymax-rect1.ymin);
1661 rect1.ymax -= 2.0f*radout;
1664 totvert= round_box_shadow_edges(wtb.inner_v, &rect1, radin, roundboxalign & (UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT), 0.0f);
1666 /* inverse linear shadow alpha */
1670 glEnableClientState(GL_VERTEX_ARRAY);
1672 for(step= 1; step<=radout; step++, alpha*=alphastep) {
1673 round_box_shadow_edges(wtb.outer_v, &rect1, radin, UI_CNR_ALL, (float)step);
1675 glColor4f(0.0f, 0.0f, 0.0f, alpha);
1677 widget_verts_to_quad_strip_open(&wtb, totvert, quad_strip);
1679 glVertexPointer(2, GL_FLOAT, 0, quad_strip);
1680 glDrawArrays(GL_QUAD_STRIP, 0, totvert*2);
1683 glDisableClientState(GL_VERTEX_ARRAY);
1686 static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int direction)
1689 int roundboxalign= UI_CNR_ALL;
1693 /* menu is 2nd level or deeper */
1694 if (flag & UI_BLOCK_POPUP) {
1695 //rect->ymin -= 4.0;
1696 //rect->ymax += 4.0;
1698 else if (direction == UI_DOWN) {
1699 roundboxalign= (UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT);
1702 else if (direction == UI_TOP) {
1703 roundboxalign= UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT;
1708 widget_softshadow(rect, roundboxalign, 5.0f, 8.0f);
1710 round_box_edges(&wtb, roundboxalign, rect, 5.0f);
1712 widgetbase_draw(&wtb, wcol);
1714 glDisable(GL_BLEND);
1718 static void ui_hsv_cursor(float x, float y)
1722 glTranslatef(x, y, 0.0f);
1724 glColor3f(1.0f, 1.0f, 1.0f);
1725 glutil_draw_filled_arc(0.0f, M_PI*2.0, 3.0f, 8);
1728 glEnable(GL_LINE_SMOOTH );
1729 glColor3f(0.0f, 0.0f, 0.0f);
1730 glutil_draw_lined_arc(0.0f, M_PI*2.0, 3.0f, 12);
1731 glDisable(GL_BLEND);
1732 glDisable(GL_LINE_SMOOTH );
1738 void ui_hsvcircle_vals_from_pos(float *valrad, float *valdist, rcti *rect, float mx, float my)
1740 /* duplication of code... well, simple is better now */
1741 float centx= (float)(rect->xmin + rect->xmax)/2;
1742 float centy= (float)(rect->ymin + rect->ymax)/2;
1745 if( rect->xmax-rect->xmin > rect->ymax-rect->ymin )
1746 radius= (float)(rect->ymax - rect->ymin)/2;
1748 radius= (float)(rect->xmax - rect->xmin)/2;
1752 dist= sqrt( mx*mx + my*my);
1754 *valdist= dist/radius;
1758 *valrad= atan2f(mx, my)/(2.0f*(float)M_PI) + 0.5f;
1761 static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect)
1763 /* gouraud triangle fan */
1764 float radstep, ang= 0.0f;
1765 float centx, centy, radius;
1766 float rgb[3], hsvo[3], hsv[3], col[3], colcent[3];
1768 int color_profile = but->block->color_profile;
1770 if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
1771 color_profile = BLI_PR_NONE;
1773 radstep= 2.0f*(float)M_PI/(float)tot;
1774 centx= (float)(rect->xmin + rect->xmax)/2;
1775 centy= (float)(rect->ymin + rect->ymax)/2;
1777 if( rect->xmax-rect->xmin > rect->ymax-rect->ymin )
1778 radius= (float)(rect->ymax - rect->ymin)/2;
1780 radius= (float)(rect->xmax - rect->xmin)/2;
1783 ui_get_but_vectorf(but, rgb);
1784 copy_v3_v3(hsv, ui_block_hsv_get(but->block));
1785 rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
1786 copy_v3_v3(hsvo, hsv);
1788 /* exception: if 'lock' is set
1789 * lock the value of the color wheel to 1.
1790 * Useful for color correction tools where you're only interested in hue. */
1791 if (but->flag & UI_BUT_COLOR_LOCK)
1793 else if (color_profile)
1794 hsv[2] = linearrgb_to_srgb(hsv[2]);
1796 hsv_to_rgb(0.f, 0.f, hsv[2], colcent, colcent+1, colcent+2);
1798 glShadeModel(GL_SMOOTH);
1800 glBegin(GL_TRIANGLE_FAN);
1801 glColor3fv(colcent);
1802 glVertex2f( centx, centy);
1804 for(a=0; a<=tot; a++, ang+=radstep) {
1808 ui_hsvcircle_vals_from_pos(hsv, hsv+1, rect, centx + co*radius, centy + si*radius);
1809 CLAMP(hsv[2], 0.0f, 1.0f); /* for display only */
1811 hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2);
1813 glVertex2f( centx + co*radius, centy + si*radius);
1817 glShadeModel(GL_FLAT);
1819 /* fully rounded outline */
1821 glTranslatef(centx, centy, 0.0f);
1823 glEnable(GL_LINE_SMOOTH );
1824 glColor3ubv((unsigned char*)wcol->outline);
1825 glutil_draw_lined_arc(0.0f, M_PI*2.0, radius, tot + 1);
1826 glDisable(GL_BLEND);
1827 glDisable(GL_LINE_SMOOTH );
1831 ang= 2.0f*(float)M_PI*hsvo[0] + 0.5f*(float)M_PI;
1833 if(but->flag & UI_BUT_COLOR_CUBIC)
1834 radius= (1.0f - powf(1.0f - hsvo[1], 3.0f)) *radius;
1836 radius= hsvo[1] * radius;
1838 ui_hsv_cursor(centx + cosf(-ang)*radius, centy + sinf(-ang)*radius);
1842 /* ************ custom buttons, old stuff ************** */
1844 /* draws in resolution of 20x4 colors */
1845 void ui_draw_gradient(rcti *rect, float *hsv, int type, float alpha)
1848 float h= hsv[0], s= hsv[1], v= hsv[2];
1849 float dx, dy, sx1, sx2, sy;
1850 float col0[4][3]; // left half, rect bottom to top
1851 float col1[4][3]; // right half, rect bottom to top
1853 /* draw series of gouraud rects */
1854 glShadeModel(GL_SMOOTH);
1858 hsv_to_rgb(h, 0.0, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1859 hsv_to_rgb(h, 0.333, 0.0, &col1[1][0], &col1[1][1], &col1[1][2]);
1860 hsv_to_rgb(h, 0.666, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
1861 hsv_to_rgb(h, 1.0, 0.0, &col1[3][0], &col1[3][1], &col1[3][2]);
1864 hsv_to_rgb(0.0, s, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1865 hsv_to_rgb(0.0, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
1866 hsv_to_rgb(0.0, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
1867 hsv_to_rgb(0.0, s, 1.0, &col1[3][0], &col1[3][1], &col1[3][2]);
1870 hsv_to_rgb(0.0, 0.0, v, &col1[0][0], &col1[0][1], &col1[0][2]);
1871 hsv_to_rgb(0.0, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
1872 hsv_to_rgb(0.0, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
1873 hsv_to_rgb(0.0, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
1876 hsv_to_rgb(0.0, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1877 VECCOPY(col1[1], col1[0]);
1878 VECCOPY(col1[2], col1[0]);
1879 VECCOPY(col1[3], col1[0]);
1882 hsv_to_rgb(1.0, 0.0, 1.0, &col1[1][0], &col1[1][1], &col1[1][2]);
1883 VECCOPY(col1[0], col1[1]);
1884 VECCOPY(col1[2], col1[1]);
1885 VECCOPY(col1[3], col1[1]);
1888 hsv_to_rgb(1.0, 1.0, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
1889 VECCOPY(col1[0], col1[2]);
1890 VECCOPY(col1[1], col1[2]);
1891 VECCOPY(col1[3], col1[2]);
1894 assert(!"invalid 'type' argument");
1895 hsv_to_rgb(1.0, 1.0, 1.0, &col1[2][0], &col1[2][1], &col1[2][2]);
1896 VECCOPY(col1[0], col1[2]);
1897 VECCOPY(col1[1], col1[2]);
1898 VECCOPY(col1[3], col1[2]);
1903 for(dx=0.0f; dx<1.0f; dx+= 0.05f) {
1905 VECCOPY(col0[0], col1[0]);
1906 VECCOPY(col0[1], col1[1]);
1907 VECCOPY(col0[2], col1[2]);
1908 VECCOPY(col0[3], col1[3]);
1913 hsv_to_rgb(h, 0.0, dx, &col1[0][0], &col1[0][1], &col1[0][2]);
1914 hsv_to_rgb(h, 0.333, dx, &col1[1][0], &col1[1][1], &col1[1][2]);
1915 hsv_to_rgb(h, 0.666, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
1916 hsv_to_rgb(h, 1.0, dx, &col1[3][0], &col1[3][1], &col1[3][2]);
1919 hsv_to_rgb(dx, s, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1920 hsv_to_rgb(dx, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
1921 hsv_to_rgb(dx, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
1922 hsv_to_rgb(dx, s, 1.0, &col1[3][0], &col1[3][1], &col1[3][2]);
1925 hsv_to_rgb(dx, 0.0, v, &col1[0][0], &col1[0][1], &col1[0][2]);
1926 hsv_to_rgb(dx, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
1927 hsv_to_rgb(dx, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
1928 hsv_to_rgb(dx, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
1931 hsv_to_rgb(dx, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1932 VECCOPY(col1[1], col1[0]);
1933 VECCOPY(col1[2], col1[0]);
1934 VECCOPY(col1[3], col1[0]);
1937 hsv_to_rgb(h, dx, 1.0, &col1[1][0], &col1[1][1], &col1[1][2]);
1938 VECCOPY(col1[0], col1[1]);
1939 VECCOPY(col1[2], col1[1]);
1940 VECCOPY(col1[3], col1[1]);
1943 hsv_to_rgb(h, 1.0, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
1944 VECCOPY(col1[0], col1[2]);
1945 VECCOPY(col1[1], col1[2]);
1946 VECCOPY(col1[3], col1[2]);
1951 sx1= rect->xmin + dx*(rect->xmax-rect->xmin);
1952 sx2= rect->xmin + (dx+0.05f)*(rect->xmax-rect->xmin);
1954 dy= (rect->ymax-rect->ymin)/3.0;
1957 for(a=0; a<3; a++, sy+=dy) {
1958 glColor4f(col0[a][0], col0[a][1], col0[a][2], alpha);
1959 glVertex2f(sx1, sy);
1961 glColor4f(col1[a][0], col1[a][1], col1[a][2], alpha);
1962 glVertex2f(sx2, sy);
1964 glColor4f(col1[a+1][0], col1[a+1][1], col1[a+1][2], alpha);
1965 glVertex2f(sx2, sy+dy);
1967 glColor4f(col0[a+1][0], col0[a+1][1], col0[a+1][2], alpha);
1968 glVertex2f(sx1, sy+dy);
1973 glShadeModel(GL_FLAT);
1979 static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
1981 float rgb[3], h,s,v;
1982 float x=0.0f, y=0.0f;
1983 float *hsv= ui_block_hsv_get(but->block);
1990 ui_get_but_vectorf(but, rgb);
1991 rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], &h, &s, &v);
1997 ui_draw_gradient(rect, hsvn, but->a1, 1.f);
1999 switch((int)but->a1) {
2007 x= h; y= 0.5; break;
2009 x= s; y= 0.5; break;
2011 x= v; y= 0.5; break;
2015 x= rect->xmin + x*(rect->xmax-rect->xmin);
2016 y= rect->ymin + y*(rect->ymax-rect->ymin);
2017 CLAMP(x, rect->xmin+3.0f, rect->xmax-3.0f);
2018 CLAMP(y, rect->ymin+3.0f, rect->ymax-3.0f);
2020 ui_hsv_cursor(x, y);
2023 glColor3ub(0, 0, 0);
2024 fdrawbox((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
2027 /* vertical 'value' slider, using new widget code */
2028 static void ui_draw_but_HSV_v(uiBut *but, rcti *rect)
2031 float rad= 0.5f*(rect->xmax - rect->xmin);
2033 float rgb[3], hsv[3], v, range;
2034 int color_profile = but->block->color_profile;
2036 if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
2037 color_profile = BLI_PR_NONE;
2039 ui_get_but_vectorf(but, rgb);
2040 rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
2044 v = linearrgb_to_srgb(v);
2046 /* map v from property range to [0,1] */
2047 range = but->softmax - but->softmin;
2048 v = (v - but->softmin)/range;
2053 round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
2055 /* setup temp colors */
2056 wcol_tmp.outline[0]= wcol_tmp.outline[1]= wcol_tmp.outline[2]= 0;
2057 wcol_tmp.inner[0]= wcol_tmp.inner[1]= wcol_tmp.inner[2]= 128;
2058 wcol_tmp.shadetop= 127;
2059 wcol_tmp.shadedown= -128;
2062 widgetbase_draw(&wtb, &wcol_tmp);
2065 x= rect->xmin + 0.5f * (rect->xmax-rect->xmin);
2066 y= rect->ymin + v * (rect->ymax-rect->ymin);
2067 CLAMP(y, rect->ymin+3.0f, rect->ymax-3.0f);
2069 ui_hsv_cursor(x, y);
2074 /* ************ separator, for menus etc ***************** */
2075 static void ui_draw_separator(rcti *rect, uiWidgetColors *wcol)
2077 int y = rect->ymin + (rect->ymax - rect->ymin)/2 - 1;
2078 unsigned char col[4];
2080 col[0] = wcol->text[0];
2081 col[1] = wcol->text[1];
2082 col[2] = wcol->text[2];
2087 sdrawline(rect->xmin, y, rect->xmax, y);
2088 glDisable(GL_BLEND);
2091 /* ************ button callbacks, draw ***************** */
2093 static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2096 float rad= 0.5f*(rect->ymax - rect->ymin);
2097 float textofs = rad*0.75f;
2099 if(state & UI_SELECT)
2100 SWAP(short, wcol->shadetop, wcol->shadedown);
2105 round_box_edges(&wtb, roundboxalign, rect, rad);
2108 if(!(state & UI_TEXTINPUT)) {
2109 widget_num_tria(&wtb.tria1, rect, 0.6f, 'l');
2110 widget_num_tria(&wtb.tria2, rect, 0.6f, 'r');
2113 widgetbase_draw(&wtb, wcol);
2116 rect->xmin += textofs;
2117 rect->xmax -= textofs;
2120 //static int ui_link_bezier_points(rcti *rect, float coord_array[][2], int resol)
2121 int ui_link_bezier_points(rcti *rect, float coord_array[][2], int resol)
2123 float dist, vec[4][2];
2125 vec[0][0]= rect->xmin;
2126 vec[0][1]= rect->ymin;
2127 vec[3][0]= rect->xmax;
2128 vec[3][1]= rect->ymax;
2130 dist= 0.5f*ABS(vec[0][0] - vec[3][0]);
2132 vec[1][0]= vec[0][0]+dist;
2133 vec[1][1]= vec[0][1];
2135 vec[2][0]= vec[3][0]-dist;
2136 vec[2][1]= vec[3][1];
2138 forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0], coord_array[0], resol, sizeof(float)*2);
2139 forward_diff_bezier(vec[0][1], vec[1][1], vec[2][1], vec[3][1], coord_array[0]+1, resol, sizeof(float)*2);
2144 #define LINK_RESOL 24
2145 void ui_draw_link_bezier(rcti *rect)
2147 float coord_array[LINK_RESOL+1][2];
2149 if(ui_link_bezier_points(rect, coord_array, LINK_RESOL)) {
2150 /* we can reuse the dist variable here to increment the GL curve eval amount*/
2151 // const float dist= 1.0f/(float)LINK_RESOL; // UNUSED
2154 glEnable(GL_LINE_SMOOTH);
2156 glEnableClientState(GL_VERTEX_ARRAY);
2157 glVertexPointer(2, GL_FLOAT, 0, coord_array);
2158 glDrawArrays(GL_LINE_STRIP, 0, LINK_RESOL);
2159 glDisableClientState(GL_VERTEX_ARRAY);
2161 glDisable(GL_BLEND);
2162 glDisable(GL_LINE_SMOOTH);
2167 /* function in use for buttons and for view2d sliders */
2168 void uiWidgetScrollDraw(uiWidgetColors *wcol, rcti *rect, rcti *slider, int state)
2177 /* determine horizontal/vertical */
2178 horizontal= (rect->xmax - rect->xmin > rect->ymax - rect->ymin);
2181 rad= 0.5f*(rect->ymax - rect->ymin);
2183 rad= 0.5f*(rect->xmax - rect->xmin);
2185 wtb.shadedir= (horizontal)? 1: 0;
2187 /* draw back part, colors swapped and shading inverted */
2189 SWAP(short, wcol->shadetop, wcol->shadedown);
2191 round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
2192 widgetbase_draw(&wtb, wcol);
2195 if(slider->xmax-slider->xmin<2 || slider->ymax-slider->ymin<2);
2198 SWAP(short, wcol->shadetop, wcol->shadedown);
2200 QUATCOPY(wcol->inner, wcol->item);
2202 if(wcol->shadetop>wcol->shadedown)
2203 wcol->shadetop+= 20; /* XXX violates themes... */
2204 else wcol->shadedown+= 20;
2206 if(state & UI_SCROLL_PRESSED) {
2207 wcol->inner[0]= wcol->inner[0]>=250? 255 : wcol->inner[0]+5;
2208 wcol->inner[1]= wcol->inner[1]>=250? 255 : wcol->inner[1]+5;
2209 wcol->inner[2]= wcol->inner[2]>=250? 255 : wcol->inner[2]+5;
2213 wtb.emboss= 0; /* only emboss once */
2215 /* exception for progress bar */
2216 if (state & UI_SCROLL_NO_OUTLINE)
2217 SWAP(short, outline, wtb.outline);
2219 round_box_edges(&wtb, UI_CNR_ALL, slider, rad);
2221 if(state & UI_SCROLL_ARROWS) {
2222 if(wcol->item[0] > 48) wcol->item[0]-= 48;
2223 if(wcol->item[1] > 48) wcol->item[1]-= 48;
2224 if(wcol->item[2] > 48) wcol->item[2]-= 48;
2228 widget_scroll_circle(&wtb.tria1, slider, 0.6f, 'l');
2229 widget_scroll_circle(&wtb.tria2, slider, 0.6f, 'r');
2232 widget_scroll_circle(&wtb.tria1, slider, 0.6f, 'b');
2233 widget_scroll_circle(&wtb.tria2, slider, 0.6f, 't');
2236 widgetbase_draw(&wtb, wcol);
2238 if (state & UI_SCROLL_NO_OUTLINE)
2239 SWAP(short, outline, wtb.outline);
2243 static void widget_scroll(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
2247 float fac, size, min;
2250 /* calculate slider part */
2251 value= ui_get_but_val(but);
2253 size= (but->softmax + but->a1 - but->softmin);
2254 size= MAX2(size, 2);
2259 /* determine horizontal/vertical */
2260 horizontal= (rect->xmax - rect->xmin > rect->ymax - rect->ymin);
2263 fac= (rect->xmax - rect->xmin)/(size);
2264 rect1.xmin= rect1.xmin + ceilf(fac*((float)value - but->softmin));
2265 rect1.xmax= rect1.xmin + ceilf(fac*(but->a1 - but->softmin));
2267 /* ensure minimium size */
2268 min= rect->ymax - rect->ymin;
2270 if(rect1.xmax - rect1.xmin < min) {
2271 rect1.xmax= rect1.xmin + min;
2273 if(rect1.xmax > rect->xmax) {
2274 rect1.xmax= rect->xmax;
2275 rect1.xmin= MAX2(rect1.xmax - min, rect->xmin);
2280 fac= (rect->ymax - rect->ymin)/(size);
2281 rect1.ymax= rect1.ymax - ceilf(fac*((float)value - but->softmin));
2282 rect1.ymin= rect1.ymax - ceilf(fac*(but->a1 - but->softmin));
2284 /* ensure minimium size */
2285 min= rect->xmax - rect->xmin;
2287 if(rect1.ymax - rect1.ymin < min) {
2288 rect1.ymax= rect1.ymin + min;
2290 if(rect1.ymax > rect->ymax) {
2291 rect1.ymax= rect->ymax;
2292 rect1.ymin= MAX2(rect1.ymax - min, rect->ymin);
2297 if(state & UI_SELECT)
2298 state= UI_SCROLL_PRESSED;
2301 uiWidgetScrollDraw(wcol, rect, &rect1, state);
2304 static void widget_progressbar(uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
2306 rcti rect_prog = *rect, rect_bar = *rect;
2307 float value = but->a1;
2310 /* make the progress bar a proportion of the original height */
2311 /* hardcoded 4px high for now */
2312 rect_prog.ymax = rect_prog.ymin + 4;
2313 rect_bar.ymax = rect_bar.ymin + 4;
2315 w = value * (rect_prog.xmax - rect_prog.xmin);
2317 /* ensure minimium size */
2318 min= rect_prog.ymax - rect_prog.ymin;
2321 rect_bar.xmax = rect_bar.xmin + w;
2323 uiWidgetScrollDraw(wcol, &rect_prog, &rect_bar, UI_SCROLL_NO_OUTLINE);
2325 /* raise text a bit */
2330 static void widget_link(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
2333 if(but->flag & UI_SELECT) {
2336 UI_ThemeColor(TH_TEXT_HI);
2338 rectlink.xmin= (rect->xmin+rect->xmax)/2;
2339 rectlink.ymin= (rect->ymin+rect->ymax)/2;
2340 rectlink.xmax= but->linkto[0];
2341 rectlink.ymax= but->linkto[1];
2343 ui_draw_link_bezier(&rectlink);
2347 static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2349 uiWidgetBase wtb, wtb1;
2352 float offs, toffs, fac;
2358 /* backdrop first */
2361 offs= 0.5f*(rect->ymax - rect->ymin);
2363 round_box_edges(&wtb, roundboxalign, rect, offs);
2366 widgetbase_draw(&wtb, wcol);
2368 /* draw left/right parts only when not in text editing */
2369 if(!(state & UI_TEXTINPUT)) {
2372 VECCOPY(outline, wcol->outline);
2373 VECCOPY(wcol->outline, wcol->item);
2374 VECCOPY(wcol->inner, wcol->item);
2376 if(!(state & UI_SELECT))
2377 SWAP(short, wcol->shadetop, wcol->shadedown);
2381 value= ui_get_but_val(but);
2382 fac= ((float)value-but->softmin)*(rect1.xmax - rect1.xmin - offs)/(but->softmax - but->softmin);
2384 /* left part of slider, always rounded */
2385 rect1.xmax= rect1.xmin + ceil(offs+1.0f);
2386 round_box_edges(&wtb1, roundboxalign & ~(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT), &rect1, offs);
2388 widgetbase_draw(&wtb1, wcol);
2390 /* right part of slider, interpolate roundness */
2391 rect1.xmax= rect1.xmin + fac + offs;
2392 rect1.xmin+= floor(offs-1.0f);
2393 if(rect1.xmax + offs > rect->xmax)
2394 offs*= (rect1.xmax + offs - rect->xmax)/offs;
2397 round_box_edges(&wtb1, roundboxalign & ~(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT), &rect1, offs);
2399 widgetbase_draw(&wtb1, wcol);
2400 VECCOPY(wcol->outline, outline);
2402 if(!(state & UI_SELECT))
2403 SWAP(short, wcol->shadetop, wcol->shadedown);
2409 widgetbase_draw(&wtb, wcol);
2412 rect->xmin += toffs;
2413 rect->xmax -= toffs;
2416 /* I think 3 is sufficient border to indicate keyed status */
2417 #define SWATCH_KEYED_BORDER 3
2419 static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2423 int color_profile = but->block->color_profile;
2428 if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
2429 color_profile = BLI_PR_NONE;
2431 if(RNA_property_array_length(&but->rnapoin, but->rnaprop)==4) {
2432 col[3]= RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3);
2439 round_box_edges(&wtb, roundboxalign, rect, 5.0f);
2441 ui_get_but_vectorf(but, col);
2443 if(state & (UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN|UI_BUT_REDALERT)) {
2444 // draw based on state - color for keyed etc
2445 widgetbase_draw(&wtb, wcol);
2447 // inset to draw swatch color
2448 rect->xmin+= SWATCH_KEYED_BORDER;
2449 rect->xmax-= SWATCH_KEYED_BORDER;
2450 rect->ymin+= SWATCH_KEYED_BORDER;
2451 rect->ymax-= SWATCH_KEYED_BORDER;
2453 round_box_edges(&wtb, roundboxalign, rect, 5.0f);
2457 linearrgb_to_srgb_v3_v3(col, col);
2459 wcol->inner[0]= FTOCHAR(col[0]);
2460 wcol->inner[1]= FTOCHAR(col[1]);
2461 wcol->inner[2]= FTOCHAR(col[2]);
2462 wcol->inner[3]= FTOCHAR(col[3]);
2464 wcol->alpha_check = (wcol->inner[3] < 255);
2466 widgetbase_draw(&wtb, wcol);
2470 static void widget_icon_has_anim(uiBut *UNUSED(but), uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
2472 if(state & (UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN|UI_BUT_REDALERT)) {
2479 round_box_edges(&wtb, UI_CNR_ALL, rect, 10.0f);
2480 widgetbase_draw(&wtb, wcol);
2485 static void widget_textbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2489 if(state & UI_SELECT)
2490 SWAP(short, wcol->shadetop, wcol->shadedown);
2495 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2497 widgetbase_draw(&wtb, wcol);
2502 static void widget_menubut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2509 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2512 widget_menu_trias(&wtb.tria1, rect);
2514 widgetbase_draw(&wtb, wcol);
2517 rect->xmax -= (rect->ymax-rect->ymin);
2520 static void widget_menuiconbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2527 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2530 widgetbase_draw(&wtb, wcol);
2533 static void widget_pulldownbut(uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
2535 if(state & UI_ACTIVE) {
2537 float rad= 0.5f*(rect->ymax - rect->ymin); // 4.0f
2542 round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
2544 widgetbase_draw(&wtb, wcol);
2548 static void widget_menu_itembut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
2554 /* not rounded, no outline */
2556 round_box_edges(&wtb, 0, rect, 0.0f);
2558 widgetbase_draw(&wtb, wcol);
2561 static void widget_list_itembut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
2567 /* rounded, but no outline */
2569 round_box_edges(&wtb, UI_CNR_ALL, rect, 4.0f);
2571 widgetbase_draw(&wtb, wcol);
2574 static void widget_optionbut(uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
2577 rcti recttemp= *rect;
2583 recttemp.xmax= recttemp.xmin + (recttemp.ymax-recttemp.ymin);
2586 delta= 1 + (recttemp.ymax-recttemp.ymin)/8;
2587 recttemp.xmin+= delta;
2588 recttemp.ymin+= delta;
2589 recttemp.xmax-= delta;
2590 recttemp.ymax-= delta;
2593 round_box_edges(&wtb, UI_CNR_ALL, &recttemp, 4.0f);
2596 if(state & UI_SELECT) {
2597 widget_check_trias(&wtb.tria1, &recttemp);
2600 widgetbase_draw(&wtb, wcol);
2603 rect->xmin += (rect->ymax-rect->ymin)*0.7 + delta;
2607 static void widget_radiobut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2614 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2616 widgetbase_draw(&wtb, wcol);
2620 static void widget_box(uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2627 VECCOPY(old_col, wcol->inner);
2629 /* abuse but->hsv - if it's non-zero, use this color as the box's background */
2631 wcol->inner[0] = but->col[0];
2632 wcol->inner[1] = but->col[1];
2633 wcol->inner[2] = but->col[2];
2637 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2639 widgetbase_draw(&wtb, wcol);
2641 /* store the box bg as gl clearcolor, to retrieve later when drawing semi-transparent rects
2642 * over the top to indicate disabled buttons */
2643 /* XXX, this doesnt work right since the color applies to buttons outside the box too. */
2644 glClearColor(wcol->inner[0]/255.0, wcol->inner[1]/255.0, wcol->inner[2]/255.0, 1.0);
2646 VECCOPY(wcol->inner, old_col);
2649 static void widget_but(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2656 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2658 widgetbase_draw(&wtb, wcol);
2662 static void widget_roundbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2665 float rad= 5.0f; //0.5f*(rect->ymax - rect->ymin);
2670 round_box_edges(&wtb, roundboxalign, rect, rad);
2672 widgetbase_draw(&wtb, wcol);
2675 static void widget_draw_extra_mask(const bContext *C, uiBut *but, uiWidgetType *wt, rcti *rect)
2678 unsigned char col[4];
2681 wt->wcol= *(wt->wcol_theme);
2685 if(but->block->drawextra) {
2686 /* note: drawextra can change rect +1 or -1, to match round errors of existing previews */
2687 but->block->drawextra(C, but->poin, but->block->drawextra_arg1, but->block->drawextra_arg2, rect);
2689 /* make mask to draw over image */
2690 UI_GetThemeColor3ubv(TH_BACK, col);
2693 round_box__edges(&wtb, UI_CNR_ALL, rect, 0.0f, 4.0);
2694 widgetbase_outline(&wtb);
2698 round_box_edges(&wtb, UI_CNR_ALL, rect, 5.0f);
2701 widgetbase_draw(&wtb, &wt->wcol);
2706 static void widget_disabled(rcti *rect)
2712 /* can't use theme TH_BACK or TH_PANEL... undefined */
2713 glGetFloatv(GL_COLOR_CLEAR_VALUE, col);
2714 glColor4f(col[0], col[1], col[2], 0.5f);
2716 /* need -1 and +1 to make it work right for aligned buttons,
2717 * but problem may be somewhere else? */
2718 glRectf(rect->xmin-1, rect->ymin-1, rect->xmax, rect->ymax+1);
2720 glDisable(GL_BLEND);
2723 static uiWidgetType *widget_type(uiWidgetTypeEnum type)
2725 bTheme *btheme= U.themes.first;
2726 static uiWidgetType wt;
2729 wt.wcol_theme= &btheme->tui.wcol_regular;
2730 wt.wcol_state= &btheme->tui.wcol_state;
2731 wt.state= widget_state;
2732 wt.draw= widget_but;
2734 wt.text= widget_draw_text_icon;
2737 case UI_WTYPE_REGULAR:
2740 case UI_WTYPE_LABEL:
2742 wt.state= widget_state_label;
2745 case UI_WTYPE_TOGGLE:
2746 wt.wcol_theme= &btheme->tui.wcol_toggle;
2749 case UI_WTYPE_OPTION:
2750 wt.wcol_theme= &btheme->tui.wcol_option;
2751 wt.draw= widget_optionbut;
2754 case UI_WTYPE_RADIO:
2755 wt.wcol_theme= &btheme->tui.wcol_radio;
2756 wt.draw= widget_radiobut;
2759 case UI_WTYPE_NUMBER:
2760 wt.wcol_theme= &btheme->tui.wcol_num;
2761 wt.draw= widget_numbut;
2764 case UI_WTYPE_SLIDER:
2765 wt.wcol_theme= &btheme->tui.wcol_numslider;
2766 wt.custom= widget_numslider;
2767 wt.state= widget_state_numslider;
2771 wt.wcol_theme= &btheme->tui.wcol_tool;
2772 wt.draw= widget_roundbut;
2778 wt.wcol_theme= &btheme->tui.wcol_text;
2779 wt.draw= widget_textbut;
2782 case UI_WTYPE_NAME_LINK:
2785 case UI_WTYPE_POINTER_LINK:
2788 case UI_WTYPE_FILENAME:
2793 case UI_WTYPE_MENU_RADIO:
2794 wt.wcol_theme= &btheme->tui.wcol_menu;
2795 wt.draw= widget_menubut;
2798 case UI_WTYPE_MENU_ICON_RADIO:
2799 wt.wcol_theme= &btheme->tui.wcol_menu;
2800 wt.draw= widget_menuiconbut;
2803 case UI_WTYPE_MENU_POINTER_LINK:
2804 wt.wcol_theme= &btheme->tui.wcol_menu;
2805 wt.draw= widget_menubut;
2808 case UI_WTYPE_PULLDOWN:
2809 wt.wcol_theme= &btheme->tui.wcol_pulldown;
2810 wt.draw= widget_pulldownbut;
2811 wt.state= widget_state_pulldown;
2815 case UI_WTYPE_MENU_ITEM:
2816 wt.wcol_theme= &btheme->tui.wcol_menu_item;
2817 wt.draw= widget_menu_itembut;
2818 wt.state= widget_state_menu_item;
2821 case UI_WTYPE_MENU_BACK:
2822 wt.wcol_theme= &btheme->tui.wcol_menu_back;
2823 wt.draw= widget_menu_back;
2828 wt.custom= widget_icon_has_anim;
2831 case UI_WTYPE_SWATCH:
2832 wt.custom= widget_swatch;
2836 wt.custom= widget_box;
2837 wt.wcol_theme= &btheme->tui.wcol_box;
2840 case UI_WTYPE_RGB_PICKER:
2843 case UI_WTYPE_NORMAL:
2846 case UI_WTYPE_SCROLL:
2847 wt.wcol_theme= &btheme->tui.wcol_scroll;
2848 wt.state= widget_state_nothing;
2849 wt.custom= widget_scroll;
2852 case UI_WTYPE_LISTITEM:
2853 wt.wcol_theme= &btheme->tui.wcol_list_item;
2854 wt.draw= widget_list_itembut;
2857 case UI_WTYPE_PROGRESSBAR:
2858 wt.wcol_theme= &btheme->tui.wcol_progress;
2859 wt.custom= widget_progressbar;
2867 static int widget_roundbox_set(uiBut *but, rcti *rect)
2870 if(but->flag & UI_BUT_ALIGN) {
2872 if(but->flag & UI_BUT_ALIGN_TOP)
2874 if(but->flag & UI_BUT_ALIGN_LEFT)
2877 switch(but->flag & UI_BUT_ALIGN) {
2878 case UI_BUT_ALIGN_TOP:
2879 return UI_CNR_BOTTOM_LEFT | UI_CNR_BOTTOM_RIGHT;
2880 case UI_BUT_ALIGN_DOWN:
2881 return UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT;
2882 case UI_BUT_ALIGN_LEFT:
2883 return UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT;
2884 case UI_BUT_ALIGN_RIGHT:
2885 return UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT;
2886 case UI_BUT_ALIGN_DOWN | UI_BUT_ALIGN_RIGHT:
2887 return UI_CNR_TOP_LEFT;
2888 case UI_BUT_ALIGN_DOWN | UI_BUT_ALIGN_LEFT:
2889 return UI_CNR_TOP_RIGHT;
2890 case UI_BUT_ALIGN_TOP | UI_BUT_ALIGN_RIGHT:
2891 return UI_CNR_BOTTOM_LEFT;
2892 case UI_BUT_ALIGN_TOP | UI_BUT_ALIGN_LEFT:
2893 return UI_CNR_BOTTOM_RIGHT;
2902 /* conversion from old to new buttons, so still messy */
2903 void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rcti *rect)
2905 bTheme *btheme= U.themes.first;
2906 ThemeUI *tui= &btheme->tui;
2907 uiFontStyle *fstyle= &style->widget;
2908 uiWidgetType *wt= NULL;
2910 /* handle menus separately */
2911 if(but->dt==UI_EMBOSSP) {
2912 switch (but->type) {
2914 widget_draw_text_icon(&style->widgetlabel, &tui->wcol_menu_back, but, rect);
2917 ui_draw_separator(rect, &tui->wcol_menu_item);
2921 wt= widget_type(UI_WTYPE_MENU_ITEM);
2924 else if(but->dt==UI_EMBOSSN) {
2926 wt= widget_type(UI_WTYPE_ICON);
2930 switch (but->type) {
2932 if(but->block->flag & UI_BLOCK_LOOP)
2933 widget_draw_text_icon(&style->widgetlabel, &tui->wcol_menu_back, but, rect);
2935 wt= widget_type(UI_WTYPE_LABEL);
2936 fstyle= &style->widgetlabel;
2944 wt= widget_type(UI_WTYPE_EXEC);
2948 wt= widget_type(UI_WTYPE_NUMBER);
2953 wt= widget_type(UI_WTYPE_SLIDER);
2957 wt= widget_type(UI_WTYPE_RADIO);
2961 wt= widget_type(UI_WTYPE_LISTITEM);
2965 wt= widget_type(UI_WTYPE_NAME);
2969 wt= widget_type(UI_WTYPE_NAME);
2970 if(but->block->flag & UI_BLOCK_LOOP)
2971 wt->wcol_theme= &btheme->tui.wcol_menu_back;
2978 wt= widget_type(UI_WTYPE_TOGGLE);
2983 if (!(but->flag & UI_HAS_ICON)) {
2984 wt= widget_type(UI_WTYPE_OPTION);
2985 but->flag |= UI_TEXT_LEFT;
2988 wt= widget_type(UI_WTYPE_TOGGLE);
2990 /* option buttons have strings outside, on menus use different colors */
2991 if(but->block->flag & UI_BLOCK_LOOP)
2992 wt->state= widget_state_option_menu;
2999 if(!but->str[0] && but->icon)
3000 wt= widget_type(UI_WTYPE_MENU_ICON_RADIO);
3002 wt= widget_type(UI_WTYPE_MENU_RADIO);
3006 wt= widget_type(UI_WTYPE_PULLDOWN);
3010 wt= widget_type(UI_WTYPE_MENU_ITEM);
3014 wt= widget_type(UI_WTYPE_SWATCH);
3019 wt= widget_type(UI_WTYPE_BOX);
3024 wt= widget_type(UI_WTYPE_ICON);
3025 wt->custom= widget_link;
3030 widget_draw_extra_mask(C, but, widget_type(UI_WTYPE_BOX), rect);
3034 if(but->a1 == UI_GRAD_V_ALT) // vertical V slider, uses new widget draw now
3035 ui_draw_but_HSV_v(but, rect);
3036 else // other HSV pickers...
3037 ui_draw_but_HSVCUBE(but, rect);
3041 ui_draw_but_HSVCIRCLE(but, &tui->wcol_regular, rect);
3045 ui_draw_but_COLORBAND(but, &tui->wcol_regular, rect);
3049 ui_draw_but_NORMAL(but, &tui->wcol_regular, rect);
3053 ui_draw_but_IMAGE(ar, but, &tui->wcol_regular, rect);
3057 ui_draw_but_HISTOGRAM(ar, but, &tui->wcol_regular, rect);