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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 *****
31 #include "MEM_guardedalloc.h"
34 #include "DNA_screen_types.h"
35 #include "DNA_userdef_types.h"
36 #include "DNA_windowmanager_types.h"
39 #include "BLI_listbase.h"
42 #include "BKE_context.h"
43 #include "BKE_curve.h"
44 #include "BKE_global.h"
45 #include "BKE_utildefines.h"
47 #include "RNA_access.h"
50 #include "BIF_glutil.h"
54 #include "UI_interface.h"
55 #include "UI_interface_icons.h"
56 #include "UI_resources.h"
57 #include "UI_view2d.h"
62 #include "interface_intern.h"
64 /* ************** widget base functions ************** */
66 - in: roundbox codes for corner types and radius
67 - return: array of [size][2][x,y] points, the edges of the roundbox, + UV coords
69 - draw black box with alpha 0 on exact button boundbox
71 - draw the inner part for a round filled box, with color blend codes or texture coords
72 - draw outline in outline color
73 - draw outer part, bottom half, extruded 1 pixel to bottom, for emboss shadow
74 - draw extra decorations
75 - draw background color box with alpha 1 on exact button boundbox
79 /* fill this struct with polygon info to draw AA'ed */
80 /* it has outline, back, and two optional tria meshes */
82 typedef struct uiWidgetTrias {
90 typedef struct uiWidgetBase {
92 int totvert, halfwayvert;
95 float inner_uv[64][2];
97 short inner, outline, emboss; /* set on/off */
105 /* uiWidgetType: for time being only for visual appearance,
106 later, a handling callback can be added too
108 typedef struct uiWidgetType {
110 /* pointer to theme color definition */
111 uiWidgetColors *wcol_theme;
112 uiWidgetStateColors *wcol_state;
114 /* converted colors for state */
117 void (*state)(struct uiWidgetType *, int state);
118 void (*draw)(uiWidgetColors *, rcti *, int state, int roundboxalign);
119 void (*custom)(uiBut *, uiWidgetColors *, rcti *, int state, int roundboxalign);
120 void (*text)(uiFontStyle *, uiWidgetColors *, uiBut *, rcti *);
125 /* *********************** draw data ************************** */
127 static float cornervec[9][2]= {{0.0, 0.0}, {0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169},
128 {0.707, 0.293}, {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}, {1.0, 1.0}};
130 static float jit[8][2]= {{0.468813 , -0.481430}, {-0.155755 , -0.352820},
131 {0.219306 , -0.238501}, {-0.393286 , -0.110949}, {-0.024699 , 0.013908},
132 {0.343805 , 0.147431}, {-0.272855 , 0.269918}, {0.095909 , 0.388710}};
134 static float num_tria_vert[3][2]= {
135 {-0.352077, 0.532607}, {-0.352077, -0.549313}, {0.330000, -0.008353}};
137 static int num_tria_face[1][3]= {
140 static float scroll_circle_vert[16][2]= {
141 {0.382684, 0.923879}, {0.000001, 1.000000}, {-0.382683, 0.923880}, {-0.707107, 0.707107},
142 {-0.923879, 0.382684}, {-1.000000, 0.000000}, {-0.923880, -0.382684}, {-0.707107, -0.707107},
143 {-0.382683, -0.923880}, {0.000000, -1.000000}, {0.382684, -0.923880}, {0.707107, -0.707107},
144 {0.923880, -0.382684}, {1.000000, -0.000000}, {0.923880, 0.382683}, {0.707107, 0.707107}};
146 static int scroll_circle_face[14][3]= {
147 {0, 1, 2}, {2, 0, 3}, {3, 0, 15}, {3, 15, 4}, {4, 15, 14}, {4, 14, 5}, {5, 14, 13}, {5, 13, 6},
148 {6, 13, 12}, {6, 12, 7}, {7, 12, 11}, {7, 11, 8}, {8, 11, 10}, {8, 10, 9}};
150 static float menu_tria_vert[6][2]= {
151 {-0.41, 0.16}, {0.41, 0.16}, {0, 0.82},
152 {0, -0.82}, {-0.41, -0.16}, {0.41, -0.16}};
154 static int menu_tria_face[2][3]= {{2, 0, 1}, {3, 5, 4}};
156 static float check_tria_vert[6][2]= {
157 {-0.578579, 0.253369}, {-0.392773, 0.412794}, {-0.004241, -0.328551},
158 {-0.003001, 0.034320}, {1.055313, 0.864744}, {0.866408, 1.026895}};
160 static int check_tria_face[4][3]= {
161 {3, 2, 4}, {3, 4, 5}, {1, 0, 3}, {0, 2, 3}};
163 /* ************************************************* */
165 void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3)
171 glGetFloatv(GL_CURRENT_COLOR, color);
175 /* for each AA step */
177 glTranslatef(1.0*jit[j][0], 1.0*jit[j][1], 0.0f);
185 glTranslatef(-1.0*jit[j][0], -1.0*jit[j][1], 0.0f);
192 static void widget_init(uiWidgetBase *wtb)
194 wtb->totvert= wtb->halfwayvert= 0;
204 /* helper call, makes shadow rect, with 'sun' above menu, so only shadow to left/right/bottom */
206 static int round_box_shadow_edges(float (*vert)[2], rcti *rect, float rad, int roundboxalign, float step)
209 float minx, miny, maxx, maxy;
214 if(2.0f*rad > rect->ymax-rect->ymin)
215 rad= 0.5f*(rect->ymax-rect->ymin);
217 minx= rect->xmin-step;
218 miny= rect->ymin-step;
219 maxx= rect->xmax+step;
220 maxy= rect->ymax+step;
224 vec[a][0]= rad*cornervec[a][0];
225 vec[a][1]= rad*cornervec[a][1];
228 /* start with left-top, anti clockwise */
229 if(roundboxalign & 1) {
230 for(a=0; a<9; a++, tot++) {
231 vert[tot][0]= minx+rad-vec[a][0];
232 vert[tot][1]= maxy-vec[a][1];
236 for(a=0; a<9; a++, tot++) {
242 if(roundboxalign & 8) {
243 for(a=0; a<9; a++, tot++) {
244 vert[tot][0]= minx+vec[a][1];
245 vert[tot][1]= miny+rad-vec[a][0];
249 for(a=0; a<9; a++, tot++) {
255 if(roundboxalign & 4) {
256 for(a=0; a<9; a++, tot++) {
257 vert[tot][0]= maxx-rad+vec[a][0];
258 vert[tot][1]= miny+vec[a][1];
262 for(a=0; a<9; a++, tot++) {
268 if(roundboxalign & 2) {
269 for(a=0; a<9; a++, tot++) {
270 vert[tot][0]= maxx-vec[a][1];
271 vert[tot][1]= maxy-rad+vec[a][0];
275 for(a=0; a<9; a++, tot++) {
283 /* this call has 1 extra arg to allow mask outline */
284 static void round_box__edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, float rad, float radi)
286 float vec[9][2], veci[9][2];
287 float minx= rect->xmin, miny= rect->ymin, maxx= rect->xmax, maxy= rect->ymax;
288 float minxi= minx + 1.0f; /* boundbox inner */
289 float maxxi= maxx - 1.0f;
290 float minyi= miny + 1.0f;
291 float maxyi= maxy - 1.0f;
292 float facxi= 1.0f/(maxxi-minxi); /* for uv */
293 float facyi= 1.0f/(maxyi-minyi);
294 int a, tot= 0, minsize;
296 minsize= MIN2(rect->xmax-rect->xmin, rect->ymax-rect->ymin);
298 if(2.0f*rad > minsize)
301 if(2.0f*(radi+1.0f) > minsize)
302 radi= 0.5f*minsize - 1.0f;
306 veci[a][0]= radi*cornervec[a][0];
307 veci[a][1]= radi*cornervec[a][1];
308 vec[a][0]= rad*cornervec[a][0];
309 vec[a][1]= rad*cornervec[a][1];
312 /* corner left-bottom */
313 if(roundboxalign & 8) {
315 for(a=0; a<9; a++, tot++) {
316 wt->inner_v[tot][0]= minxi+veci[a][1];
317 wt->inner_v[tot][1]= minyi+radi-veci[a][0];
319 wt->outer_v[tot][0]= minx+vec[a][1];
320 wt->outer_v[tot][1]= miny+rad-vec[a][0];
322 wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
323 wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
327 wt->inner_v[tot][0]= minxi;
328 wt->inner_v[tot][1]= minyi;
330 wt->outer_v[tot][0]= minx;
331 wt->outer_v[tot][1]= miny;
333 wt->inner_uv[tot][0]= 0.0f;
334 wt->inner_uv[tot][1]= 0.0f;
339 /* corner right-bottom */
340 if(roundboxalign & 4) {
342 for(a=0; a<9; a++, tot++) {
343 wt->inner_v[tot][0]= maxxi-radi+veci[a][0];
344 wt->inner_v[tot][1]= minyi+veci[a][1];
346 wt->outer_v[tot][0]= maxx-rad+vec[a][0];
347 wt->outer_v[tot][1]= miny+vec[a][1];
349 wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
350 wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
354 wt->inner_v[tot][0]= maxxi;
355 wt->inner_v[tot][1]= minyi;
357 wt->outer_v[tot][0]= maxx;
358 wt->outer_v[tot][1]= miny;
360 wt->inner_uv[tot][0]= 1.0f;
361 wt->inner_uv[tot][1]= 0.0f;
366 wt->halfwayvert= tot;
368 /* corner right-top */
369 if(roundboxalign & 2) {
371 for(a=0; a<9; a++, tot++) {
372 wt->inner_v[tot][0]= maxxi-veci[a][1];
373 wt->inner_v[tot][1]= maxyi-radi+veci[a][0];
375 wt->outer_v[tot][0]= maxx-vec[a][1];
376 wt->outer_v[tot][1]= maxy-rad+vec[a][0];
378 wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
379 wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
383 wt->inner_v[tot][0]= maxxi;
384 wt->inner_v[tot][1]= maxyi;
386 wt->outer_v[tot][0]= maxx;
387 wt->outer_v[tot][1]= maxy;
389 wt->inner_uv[tot][0]= 1.0f;
390 wt->inner_uv[tot][1]= 1.0f;
395 /* corner left-top */
396 if(roundboxalign & 1) {
398 for(a=0; a<9; a++, tot++) {
399 wt->inner_v[tot][0]= minxi+radi-veci[a][0];
400 wt->inner_v[tot][1]= maxyi-veci[a][1];
402 wt->outer_v[tot][0]= minx+rad-vec[a][0];
403 wt->outer_v[tot][1]= maxy-vec[a][1];
405 wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
406 wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
412 wt->inner_v[tot][0]= minxi;
413 wt->inner_v[tot][1]= maxyi;
415 wt->outer_v[tot][0]= minx;
416 wt->outer_v[tot][1]= maxy;
418 wt->inner_uv[tot][0]= 0.0f;
419 wt->inner_uv[tot][1]= 1.0f;
427 static void round_box_edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, float rad)
429 round_box__edges(wt, roundboxalign, rect, rad, rad-1.0f);
433 /* based on button rect, return scaled array of triangles */
434 static void widget_num_tria(uiWidgetTrias *tria, rcti *rect, float triasize, char where)
436 float centx, centy, sizex, sizey, minsize;
439 minsize= MIN2(rect->xmax-rect->xmin, rect->ymax-rect->ymin);
441 /* center position and size */
442 centx= (float)rect->xmin + 0.5f*minsize;
443 centy= (float)rect->ymin + 0.5f*minsize;
444 sizex= sizey= -0.5f*triasize*minsize;
447 centx= (float)rect->xmax - 0.5f*minsize;
450 else if(where=='t') {
451 centy= (float)rect->ymax - 0.5f*minsize;
455 else if(where=='b') {
461 tria->vec[a][0]= sizex*num_tria_vert[a][i1] + centx;
462 tria->vec[a][1]= sizey*num_tria_vert[a][i2] + centy;
466 tria->index= num_tria_face;
469 static void widget_scroll_circle(uiWidgetTrias *tria, rcti *rect, float triasize, char where)
471 float centx, centy, sizex, sizey, minsize;
474 minsize= MIN2(rect->xmax-rect->xmin, rect->ymax-rect->ymin);
476 /* center position and size */
477 centx= (float)rect->xmin + 0.5f*minsize;
478 centy= (float)rect->ymin + 0.5f*minsize;
479 sizex= sizey= -0.5f*triasize*minsize;
482 centx= (float)rect->xmax - 0.5f*minsize;
485 else if(where=='t') {
486 centy= (float)rect->ymax - 0.5f*minsize;
490 else if(where=='b') {
495 for(a=0; a<16; a++) {
496 tria->vec[a][0]= sizex*scroll_circle_vert[a][i1] + centx;
497 tria->vec[a][1]= sizey*scroll_circle_vert[a][i2] + centy;
501 tria->index= scroll_circle_face;
504 static void widget_trias_draw(uiWidgetTrias *tria)
508 glBegin(GL_TRIANGLES);
509 for(a=0; a<tria->tot; a++) {
510 glVertex2fv(tria->vec[ tria->index[a][0] ]);
511 glVertex2fv(tria->vec[ tria->index[a][1] ]);
512 glVertex2fv(tria->vec[ tria->index[a][2] ]);
518 static void widget_menu_trias(uiWidgetTrias *tria, rcti *rect)
520 float centx, centy, size, asp;
523 /* center position and size */
524 centx= rect->xmax - 0.5f*(rect->ymax-rect->ymin);
525 centy= rect->ymin + 0.5f*(rect->ymax-rect->ymin);
526 size= 0.4f*(rect->ymax-rect->ymin);
529 asp= ((float)rect->xmax-rect->xmin)/((float)rect->ymax-rect->ymin);
530 if(asp > 1.2f && asp < 2.6f)
531 centx= rect->xmax - 0.3f*(rect->ymax-rect->ymin);
534 tria->vec[a][0]= size*menu_tria_vert[a][0] + centx;
535 tria->vec[a][1]= size*menu_tria_vert[a][1] + centy;
539 tria->index= menu_tria_face;
542 static void widget_check_trias(uiWidgetTrias *tria, rcti *rect)
544 float centx, centy, size;
547 /* center position and size */
548 centx= rect->xmin + 0.5f*(rect->ymax-rect->ymin);
549 centy= rect->ymin + 0.5f*(rect->ymax-rect->ymin);
550 size= 0.5f*(rect->ymax-rect->ymin);
553 tria->vec[a][0]= size*check_tria_vert[a][0] + centx;
554 tria->vec[a][1]= size*check_tria_vert[a][1] + centy;
558 tria->index= check_tria_face;
562 /* prepares shade colors */
563 static void shadecolors4(char *coltop, char *coldown, char *color, short shadetop, short shadedown)
566 coltop[0]= CLAMPIS(color[0]+shadetop, 0, 255);
567 coltop[1]= CLAMPIS(color[1]+shadetop, 0, 255);
568 coltop[2]= CLAMPIS(color[2]+shadetop, 0, 255);
571 coldown[0]= CLAMPIS(color[0]+shadedown, 0, 255);
572 coldown[1]= CLAMPIS(color[1]+shadedown, 0, 255);
573 coldown[2]= CLAMPIS(color[2]+shadedown, 0, 255);
574 coldown[3]= color[3];
577 static void round_box_shade_col4(char *col1, char *col2, float fac)
580 unsigned char col[4];
582 faci= floor(255.1f*fac);
585 col[0]= (faci*col1[0] + facm*col2[0])>>8;
586 col[1]= (faci*col1[1] + facm*col2[1])>>8;
587 col[2]= (faci*col1[2] + facm*col2[2])>>8;
588 col[3]= (faci*col1[3] + facm*col2[3])>>8;
593 static void widgetbase_outline(uiWidgetBase *wtb)
598 glBegin(GL_QUAD_STRIP);
599 for(a=0; a<wtb->totvert; a++) {
600 glVertex2fv(wtb->outer_v[a]);
601 glVertex2fv(wtb->inner_v[a]);
603 glVertex2fv(wtb->outer_v[0]);
604 glVertex2fv(wtb->inner_v[0]);
608 static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
614 /* backdrop non AA */
616 if(wcol->shaded==0) {
618 /* filled center, solid */
619 glColor4ubv((unsigned char*)wcol->inner);
621 for(a=0; a<wtb->totvert; a++)
622 glVertex2fv(wtb->inner_v[a]);
627 char col1[4], col2[4];
629 shadecolors4(col1, col2, wcol->inner, wcol->shadetop, wcol->shadedown);
631 glShadeModel(GL_SMOOTH);
633 for(a=0; a<wtb->totvert; a++) {
634 round_box_shade_col4(col1, col2, wtb->inner_uv[a][wtb->shadedir]);
635 glVertex2fv(wtb->inner_v[a]);
638 glShadeModel(GL_FLAT);
642 /* for each AA step */
645 glTranslatef(1.0*jit[j][0], 1.0*jit[j][1], 0.0f);
648 glColor4ub(wcol->outline[0], wcol->outline[1], wcol->outline[2], 32);
649 glBegin(GL_QUAD_STRIP);
650 for(a=0; a<wtb->totvert; a++) {
651 glVertex2fv(wtb->outer_v[a]);
652 glVertex2fv(wtb->inner_v[a]);
654 glVertex2fv(wtb->outer_v[0]);
655 glVertex2fv(wtb->inner_v[0]);
658 /* emboss bottom shadow */
660 glColor4f(1.0f, 1.0f, 1.0f, 0.02f);
661 glBegin(GL_QUAD_STRIP);
662 for(a=0; a<wtb->halfwayvert; a++) {
663 glVertex2fv(wtb->outer_v[a]);
664 glVertex2f(wtb->outer_v[a][0], wtb->outer_v[a][1]-1.0f);
669 glTranslatef(-1.0*jit[j][0], -1.0*jit[j][1], 0.0f);
674 if(wtb->tria1.tot || wtb->tria2.tot) {
675 /* for each AA step */
677 glTranslatef(1.0*jit[j][0], 1.0*jit[j][1], 0.0f);
680 glColor4ub(wcol->item[0], wcol->item[1], wcol->item[2], 32);
681 widget_trias_draw(&wtb->tria1);
684 glColor4ub(wcol->item[0], wcol->item[1], wcol->item[2], 32);
685 widget_trias_draw(&wtb->tria2);
688 glTranslatef(-1.0*jit[j][0], -1.0*jit[j][1], 0.0f);
696 /* *********************** text/icon ************************************** */
698 #define PREVIEW_PAD 4
700 static void widget_draw_preview(BIFIconID icon, float aspect, float alpha, rcti *rect)
702 int w, h, x, y, size;
704 /* only display previews for actual preview images .. ? */
705 if (icon < BIFICONID_LAST)
708 w = rect->xmax - rect->xmin;
709 h = rect->ymax - rect->ymin;
711 size -= PREVIEW_PAD*2; /* padding */
713 x = rect->xmin + w/2 - size/2;
714 y = rect->ymin + h/2 - size/2;
716 UI_icon_draw_preview_aspect_size(x, y, icon, aspect, size);
720 /* icons have been standardized... and this call draws in untransformed coordinates */
721 #define ICON_HEIGHT 16.0f
723 static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, rcti *rect)
726 float aspect, height;
728 if (but->flag & UI_ICON_PREVIEW) {
729 widget_draw_preview(icon, but->block->aspect, alpha, rect);
733 /* this icon doesn't need draw... */
734 if(icon==ICON_BLANK1 && (but->flag & UI_ICON_SUBMENU)==0) return;
736 /* we need aspect from block, for menus... these buttons are scaled in uiPositionBlock() */
737 aspect= but->block->aspect;
738 if(aspect != but->aspect) {
739 /* prevent scaling up icon in pupmenu */
746 height= ICON_HEIGHT/aspect;
751 /* calculate blend color */
752 if ELEM4(but->type, TOG, ROW, TOGN, LISTROW) {
753 if(but->flag & UI_SELECT);
754 else if(but->flag & UI_ACTIVE);
760 if(icon && icon!=ICON_BLANK1) {
761 if(but->flag & UI_ICON_LEFT) {
762 if (but->type==BUT_TOGDUAL) {
763 if (but->drawstr[0]) {
766 xs= (rect->xmin+rect->xmax- height)/2;
769 else if (but->block->flag & UI_BLOCK_LOOP) {
770 if(but->type==SEARCH_MENU)
775 else if ((but->type==ICONROW) || (but->type==ICONTEXTROW)) {
781 ys= (rect->ymin+rect->ymax- height)/2;
784 xs= (rect->xmin+rect->xmax- height)/2;
785 ys= (rect->ymin+rect->ymax- height)/2;
788 UI_icon_draw_aspect(xs, ys, icon, aspect, alpha);
791 if(but->flag & UI_ICON_SUBMENU) {
793 ys= (rect->ymin+rect->ymax- height)/2;
795 UI_icon_draw_aspect(xs, ys, ICON_RIGHTARROW_THIN, aspect, alpha);
801 /* sets but->ofs to make sure text is correctly visible */
802 static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
804 int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10;
805 int okwidth= rect->xmax-rect->xmin - border;
807 /* need to set this first */
808 uiStyleFontSet(fstyle);
810 but->strwidth= BLF_width(but->drawstr);
813 while(but->strwidth > okwidth ) {
816 but->strwidth= BLF_width(but->drawstr+but->ofs);
818 /* textbut exception */
819 if(but->editstr && but->pos != -1) {
822 if(pos-1 < but->ofs) {
829 but->drawstr[ strlen(but->drawstr)-pos ]= 0;
833 if(but->strwidth < 10) break;
837 static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
839 int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10;
840 int okwidth= rect->xmax-rect->xmin - border;
842 char *cpend = but->drawstr + strlen(but->drawstr);
844 /* need to set this first */
845 uiStyleFontSet(fstyle);
847 but->strwidth= BLF_width(but->drawstr);
850 /* find the space after ':' separator */
851 cpoin= strrchr(but->drawstr, ':');
853 if (cpoin && (cpoin < cpend-2)) {
856 /* chop off the leading text, starting from the right */
857 while (but->strwidth > okwidth && cp2 > but->drawstr) {
858 /* shift the text after and including cp2 back by 1 char, +1 to include null terminator */
859 memmove(cp2-1, cp2, strlen(cp2)+1);
862 but->strwidth= BLF_width(but->drawstr+but->ofs);
863 if(but->strwidth < 10) break;
867 /* after the leading text is gone, chop off the : and following space, with ofs */
868 while ((but->strwidth > okwidth) && (but->ofs < 2))
871 but->strwidth= BLF_width(but->drawstr+but->ofs);
872 if(but->strwidth < 10) break;
877 /* once the label's gone, chop off the least significant digits */
878 while(but->strwidth > okwidth ) {
879 int pos= strlen(but->drawstr);
881 but->drawstr[ pos-1 ] = 0;
884 but->strwidth= BLF_width(but->drawstr+but->ofs);
885 if(but->strwidth < 10) break;
891 static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
896 uiStyleFontSet(fstyle);
898 if(but->editstr || (but->flag & UI_TEXT_LEFT))
899 fstyle->align= UI_STYLE_TEXT_LEFT;
901 fstyle->align= UI_STYLE_TEXT_CENTER;
903 /* text button selection and cursor */
904 if(but->editstr && but->pos != -1) {
905 short t=0, pos=0, ch;
906 short selsta_tmp, selend_tmp, selsta_draw, selwidth_draw;
908 if ((but->selend - but->selsta) > 0) {
909 /* text button selection */
910 selsta_tmp = but->selsta;
911 selend_tmp = but->selend;
913 if(but->drawstr[0]!=0) {
914 ch= but->drawstr[selsta_tmp];
915 but->drawstr[selsta_tmp]= 0;
917 selsta_draw = BLF_width(but->drawstr+but->ofs);
919 but->drawstr[selsta_tmp]= ch;
921 ch= but->drawstr[selend_tmp];
922 but->drawstr[selend_tmp]= 0;
924 selwidth_draw = BLF_width(but->drawstr+but->ofs);
926 but->drawstr[selend_tmp]= ch;
928 glColor3ubv((unsigned char*)wcol->item);
929 glRects(rect->xmin+selsta_draw, rect->ymin+2, rect->xmin+selwidth_draw, rect->ymax-2);
934 if(pos >= but->ofs) {
935 if(but->drawstr[0]!=0) {
936 ch= but->drawstr[pos];
937 but->drawstr[pos]= 0;
939 t= BLF_width(but->drawstr+but->ofs);
941 but->drawstr[pos]= ch;
945 glRects(rect->xmin+t, rect->ymin+2, rect->xmin+t+2, rect->ymax-2);
949 // ui_rasterpos_safe(x, y, but->aspect);
950 // if(but->type==IDPOIN) transopts= 0; // no translation, of course!
951 // else transopts= ui_translate_buttons();
953 /* cut string in 2 parts - only for menu entries */
954 if((but->block->flag & UI_BLOCK_LOOP)) {
955 if(ELEM5(but->type, SLI, NUM, TEX, NUMSLI, NUMABS)==0) {
956 cpoin= strchr(but->drawstr, '|');
961 glColor3ubv((unsigned char*)wcol->text);
962 uiStyleFontDraw(fstyle, rect, but->drawstr+but->ofs);
964 /* part text right aligned */
966 fstyle->align= UI_STYLE_TEXT_RIGHT;
968 uiStyleFontDraw(fstyle, rect, cpoin+1);
973 /* draws text and icons for buttons */
974 static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
977 if(but==NULL) return;
979 /* clip but->drawstr to fit in available space */
980 if (ELEM4(but->type, NUM, NUMABS, NUMSLI, SLI)) {
981 ui_text_label_rightclip(fstyle, but, rect);
983 else if (but->type == TEX) {
984 ui_text_leftclip(fstyle, but, rect);
988 /* check for button text label */
989 if (but->type == ICONTEXTROW) {
990 widget_draw_icon(but, (BIFIconID) (but->icon+but->iconadd), 1.0f, rect);
994 if(but->type==BUT_TOGDUAL) {
996 if(but->pointype==SHO)
997 dualset= BTST( *(((short *)but->poin)+1), but->bitnr);
998 else if(but->pointype==INT)
999 dualset= BTST( *(((int *)but->poin)+1), but->bitnr);
1001 widget_draw_icon(but, ICON_DOT, dualset?1.0f:0.25f, rect);
1004 /* If there's an icon too (made with uiDefIconTextBut) then draw the icon
1005 and offset the text label to accomodate it */
1007 if (but->flag & UI_HAS_ICON) {
1008 widget_draw_icon(but, but->icon+but->iconadd, 1.0f, rect);
1010 rect->xmin += UI_icon_get_width(but->icon+but->iconadd);
1012 if(but->editstr || (but->flag & UI_TEXT_LEFT))
1015 else if((but->flag & UI_TEXT_LEFT))
1018 /* always draw text for textbutton cursor */
1019 widget_draw_text(fstyle, wcol, but, rect);
1026 /* *********************** widget types ************************************* */
1029 /* uiWidgetStateColors
1031 char inner_anim_sel[4];
1033 char inner_key_sel[4];
1034 char inner_driven[4];
1035 char inner_driven_sel[4];
1040 static struct uiWidgetStateColors wcol_state= {
1041 {115, 190, 76, 255},
1043 {240, 235, 100, 255},
1044 {215, 211, 75, 255},
1059 float shadetop, shadedown;
1062 static struct uiWidgetColors wcol_num= {
1064 {180, 180, 180, 255},
1065 {153, 153, 153, 255},
1069 {255, 255, 255, 255},
1075 static struct uiWidgetColors wcol_numslider= {
1077 {180, 180, 180, 255},
1078 {153, 153, 153, 255},
1079 {128, 128, 128, 255},
1082 {255, 255, 255, 255},
1088 static struct uiWidgetColors wcol_text= {
1090 {153, 153, 153, 255},
1091 {153, 153, 153, 255},
1095 {255, 255, 255, 255},
1101 static struct uiWidgetColors wcol_option= {
1105 {255, 255, 255, 255},
1108 {255, 255, 255, 255},
1114 /* button that shows popup */
1115 static struct uiWidgetColors wcol_menu= {
1119 {255, 255, 255, 255},
1121 {255, 255, 255, 255},
1122 {204, 204, 204, 255},
1128 /* button that starts pulldown */
1129 static struct uiWidgetColors wcol_pulldown= {
1132 {86, 128, 194, 255},
1133 {255, 255, 255, 255},
1142 /* button inside menu */
1143 static struct uiWidgetColors wcol_menu_item= {
1146 {86, 128, 194, 255},
1147 {255, 255, 255, 255},
1149 {255, 255, 255, 255},
1156 /* backdrop menu + title text color */
1157 static struct uiWidgetColors wcol_menu_back= {
1161 {100, 100, 100, 255},
1163 {160, 160, 160, 255},
1164 {255, 255, 255, 255},
1171 static struct uiWidgetColors wcol_radio= {
1174 {86, 128, 194, 255},
1175 {255, 255, 255, 255},
1177 {255, 255, 255, 255},
1184 static struct uiWidgetColors wcol_regular= {
1186 {153, 153, 153, 255},
1187 {100, 100, 100, 255},
1191 {255, 255, 255, 255},
1197 static struct uiWidgetColors wcol_tool= {
1199 {153, 153, 153, 255},
1200 {100, 100, 100, 255},
1204 {255, 255, 255, 255},
1210 static struct uiWidgetColors wcol_box= {
1212 {128, 128, 128, 255},
1213 {100, 100, 100, 255},
1217 {255, 255, 255, 255},
1223 static struct uiWidgetColors wcol_toggle= {
1225 {153, 153, 153, 255},
1226 {100, 100, 100, 255},
1230 {255, 255, 255, 255},
1236 static struct uiWidgetColors wcol_scroll= {
1239 {100, 100, 100, 180},
1240 {128, 128, 128, 255},
1243 {255, 255, 255, 255},
1249 static struct uiWidgetColors wcol_list_item= {
1252 {86, 128, 194, 255},
1262 /* free wcol struct to play with */
1263 static struct uiWidgetColors wcol_tmp= {
1265 {128, 128, 128, 255},
1266 {100, 100, 100, 255},
1270 {255, 255, 255, 255},
1277 /* called for theme init (new theme) and versions */
1278 void ui_widget_color_init(ThemeUI *tui)
1280 tui->wcol_regular= wcol_regular;
1281 tui->wcol_tool= wcol_tool;
1282 tui->wcol_text= wcol_text;
1283 tui->wcol_radio= wcol_radio;
1284 tui->wcol_option= wcol_option;
1285 tui->wcol_toggle= wcol_toggle;
1286 tui->wcol_num= wcol_num;
1287 tui->wcol_numslider= wcol_numslider;
1288 tui->wcol_menu= wcol_menu;
1289 tui->wcol_pulldown= wcol_pulldown;
1290 tui->wcol_menu_back= wcol_menu_back;
1291 tui->wcol_menu_item= wcol_menu_item;
1292 tui->wcol_box= wcol_box;
1293 tui->wcol_scroll= wcol_scroll;
1294 tui->wcol_list_item= wcol_list_item;
1296 tui->wcol_state= wcol_state;
1299 /* ************ button callbacks, state ***************** */
1301 static void widget_state_blend(char *cp, char *cpstate, float fac)
1304 cp[0]= (int)((1.0f-fac)*cp[0] + fac*cpstate[0]);
1305 cp[1]= (int)((1.0f-fac)*cp[1] + fac*cpstate[1]);
1306 cp[2]= (int)((1.0f-fac)*cp[2] + fac*cpstate[2]);
1310 /* copy colors from theme, and set changes in it based on state */
1311 static void widget_state(uiWidgetType *wt, int state)
1313 uiWidgetStateColors *wcol_state= wt->wcol_state;
1315 wt->wcol= *(wt->wcol_theme);
1317 if(state & UI_SELECT) {
1318 QUATCOPY(wt->wcol.inner, wt->wcol.inner_sel)
1320 if(state & UI_BUT_ANIMATED_KEY)
1321 widget_state_blend(wt->wcol.inner, wcol_state->inner_key_sel, wcol_state->blend);
1322 else if(state & UI_BUT_ANIMATED)
1323 widget_state_blend(wt->wcol.inner, wcol_state->inner_anim_sel, wcol_state->blend);
1324 else if(state & UI_BUT_DRIVEN)
1325 widget_state_blend(wt->wcol.inner, wcol_state->inner_driven_sel, wcol_state->blend);
1327 VECCOPY(wt->wcol.text, wt->wcol.text_sel);
1329 /* only flip shade if it's not "pushed in" already */
1330 if(wt->wcol.shaded && wt->wcol.shadetop>wt->wcol.shadedown) {
1331 SWAP(short, wt->wcol.shadetop, wt->wcol.shadedown);
1335 if(state & UI_BUT_ANIMATED_KEY)
1336 widget_state_blend(wt->wcol.inner, wcol_state->inner_key, wcol_state->blend);
1337 else if(state & UI_BUT_ANIMATED)
1338 widget_state_blend(wt->wcol.inner, wcol_state->inner_anim, wcol_state->blend);
1339 else if(state & UI_BUT_DRIVEN)
1340 widget_state_blend(wt->wcol.inner, wcol_state->inner_driven, wcol_state->blend);
1342 if(state & UI_ACTIVE) { /* mouse over? */
1343 wt->wcol.inner[0]= wt->wcol.inner[0]>=240? 255 : wt->wcol.inner[0]+15;
1344 wt->wcol.inner[1]= wt->wcol.inner[1]>=240? 255 : wt->wcol.inner[1]+15;
1345 wt->wcol.inner[2]= wt->wcol.inner[2]>=240? 255 : wt->wcol.inner[2]+15;
1350 /* sliders use special hack which sets 'item' as inner when drawing filling */
1351 static void widget_state_numslider(uiWidgetType *wt, int state)
1353 uiWidgetStateColors *wcol_state= wt->wcol_state;
1354 float blend= wcol_state->blend - 0.2f; // XXX special tweak to make sure that bar will still be visible
1356 /* call this for option button */
1357 widget_state(wt, state);
1359 /* now, set the inner-part so that it reflects state settings too */
1360 // TODO: maybe we should have separate settings for the blending colors used for this case?
1361 if(state & UI_SELECT) {
1362 if(state & UI_BUT_ANIMATED_KEY)
1363 widget_state_blend(wt->wcol.item, wcol_state->inner_key_sel, blend);
1364 else if(state & UI_BUT_ANIMATED)
1365 widget_state_blend(wt->wcol.item, wcol_state->inner_anim_sel, blend);
1366 else if(state & UI_BUT_DRIVEN)
1367 widget_state_blend(wt->wcol.item, wcol_state->inner_driven_sel, blend);
1370 if(state & UI_BUT_ANIMATED_KEY)
1371 widget_state_blend(wt->wcol.item, wcol_state->inner_key, blend);
1372 else if(state & UI_BUT_ANIMATED)
1373 widget_state_blend(wt->wcol.item, wcol_state->inner_anim, blend);
1374 else if(state & UI_BUT_DRIVEN)
1375 widget_state_blend(wt->wcol.item, wcol_state->inner_driven, blend);
1379 /* labels use theme colors for text */
1380 static void widget_state_label(uiWidgetType *wt, int state)
1382 /* call this for option button */
1383 widget_state(wt, state);
1385 if(state & UI_SELECT)
1386 UI_GetThemeColor4ubv(TH_TEXT_HI, wt->wcol.text);
1388 UI_GetThemeColor4ubv(TH_TEXT, wt->wcol.text);
1392 static void widget_state_nothing(uiWidgetType *wt, int state)
1394 wt->wcol= *(wt->wcol_theme);
1397 /* special case, button that calls pulldown */
1398 static void widget_state_pulldown(uiWidgetType *wt, int state)
1400 wt->wcol= *(wt->wcol_theme);
1402 QUATCOPY(wt->wcol.inner, wt->wcol.inner_sel);
1403 VECCOPY(wt->wcol.outline, wt->wcol.inner);
1405 if(state & UI_ACTIVE)
1406 VECCOPY(wt->wcol.text, wt->wcol.text_sel);
1409 /* special case, menu items */
1410 static void widget_state_menu_item(uiWidgetType *wt, int state)
1412 wt->wcol= *(wt->wcol_theme);
1414 if(state & (UI_BUT_DISABLED|UI_BUT_INACTIVE)) {
1415 wt->wcol.text[0]= 0.5f*(wt->wcol.text[0]+wt->wcol.text_sel[0]);
1416 wt->wcol.text[1]= 0.5f*(wt->wcol.text[1]+wt->wcol.text_sel[1]);
1417 wt->wcol.text[2]= 0.5f*(wt->wcol.text[2]+wt->wcol.text_sel[2]);
1419 else if(state & UI_ACTIVE) {
1420 QUATCOPY(wt->wcol.inner, wt->wcol.inner_sel);
1421 VECCOPY(wt->wcol.text, wt->wcol.text_sel);
1428 /* ************ menu backdrop ************************* */
1430 /* outside of rect, rad to left/bottom/right */
1431 static void widget_softshadow(rcti *rect, int roundboxalign, float radin, float radout)
1435 float alpha, alphastep;
1438 /* prevent tooltips to not show round shadow */
1439 if( 2.0f*radout > 0.2f*(rect1.ymax-rect1.ymin) )
1440 rect1.ymax -= 0.2f*(rect1.ymax-rect1.ymin);
1442 rect1.ymax -= 2.0f*radout;
1445 tot= round_box_shadow_edges(wtb.inner_v, &rect1, radin, roundboxalign & 12, 0.0f);
1447 /* inverse linear shadow alpha */
1451 for(step= 1; step<=radout; step++, alpha*=alphastep) {
1452 round_box_shadow_edges(wtb.outer_v, &rect1, radin, 15, (float)step);
1454 glColor4f(0.0f, 0.0f, 0.0f, alpha);
1456 glBegin(GL_QUAD_STRIP);
1457 for(a=0; a<tot; a++) {
1458 glVertex2fv(wtb.outer_v[a]);
1459 glVertex2fv(wtb.inner_v[a]);
1466 static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int direction)
1469 int roundboxalign= 15;
1473 /* menu is 2nd level or deeper */
1474 if (flag & UI_BLOCK_POPUP) {
1475 //rect->ymin -= 4.0;
1476 //rect->ymax += 4.0;
1478 else if (direction == UI_DOWN) {
1482 else if (direction == UI_TOP) {
1488 widget_softshadow(rect, roundboxalign, 5.0f, 8.0f);
1490 round_box_edges(&wtb, roundboxalign, rect, 5.0f);
1492 widgetbase_draw(&wtb, wcol);
1494 glDisable(GL_BLEND);
1498 static void ui_hsv_cursor(float x, float y)
1502 glTranslatef(x, y, 0.0f);
1504 glColor3f(1.0f, 1.0f, 1.0f);
1505 glutil_draw_filled_arc(0.0f, M_PI*2.0, 3.0f, 8);
1508 glEnable(GL_LINE_SMOOTH );
1509 glColor3f(0.0f, 0.0f, 0.0f);
1510 glutil_draw_lined_arc(0.0f, M_PI*2.0, 3.0f, 12);
1511 glDisable(GL_BLEND);
1512 glDisable(GL_LINE_SMOOTH );
1518 void ui_hsvcircle_vals_from_pos(float *valrad, float *valdist, rcti *rect, float mx, float my)
1520 /* duplication of code... well, simple is better now */
1521 float centx= (float)(rect->xmin + rect->xmax)/2;
1522 float centy= (float)(rect->ymin + rect->ymax)/2;
1525 if( rect->xmax-rect->xmin > rect->ymax-rect->ymin )
1526 radius= (float)(rect->ymax - rect->ymin)/2;
1528 radius= (float)(rect->xmax - rect->xmin)/2;
1532 dist= sqrt( mx*mx + my*my);
1534 *valdist= dist/radius;
1538 *valrad= atan2(mx, my)/(2.0f*M_PI) + 0.5f;
1541 void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect)
1543 /* gouraud triangle fan */
1544 float radstep, ang= 0.0f;
1545 float centx, centy, radius;
1546 float rgb[3], hsv[3], hsvo[3], col[3], colcent[3];
1549 radstep= 2.0f*M_PI/(float)tot;
1550 centx= (float)(rect->xmin + rect->xmax)/2;
1551 centy= (float)(rect->ymin + rect->ymax)/2;
1553 if( rect->xmax-rect->xmin > rect->ymax-rect->ymin )
1554 radius= (float)(rect->ymax - rect->ymin)/2;
1556 radius= (float)(rect->xmax - rect->xmin)/2;
1559 ui_get_but_vectorf(but, rgb);
1560 rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
1561 copy_v3_v3(hsvo, hsv);
1563 hsv_to_rgb(0.f, 0.f, hsv[2], colcent, colcent+1, colcent+2);
1565 glShadeModel(GL_SMOOTH);
1567 glBegin(GL_TRIANGLE_FAN);
1568 glColor3fv(colcent);
1569 glVertex2f( centx, centy);
1571 for(a=0; a<=tot; a++, ang+=radstep) {
1575 ui_hsvcircle_vals_from_pos(hsv, hsv+1, rect, centx + co*radius, centy + si*radius);
1576 hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2);
1578 glVertex2f( centx + co*radius, centy + si*radius);
1582 glShadeModel(GL_FLAT);
1584 /* fully rounded outline */
1586 glTranslatef(centx, centy, 0.0f);
1588 glEnable(GL_LINE_SMOOTH );
1589 glColor3ubv((unsigned char*)wcol->outline);
1590 glutil_draw_lined_arc(0.0f, M_PI*2.0, radius, tot);
1591 glDisable(GL_BLEND);
1592 glDisable(GL_LINE_SMOOTH );
1596 ang= 2.0f*M_PI*hsvo[0] + 0.5f*M_PI;
1597 radius= hsvo[1]*radius;
1598 ui_hsv_cursor(centx + cos(-ang)*radius, centy + sin(-ang)*radius);
1602 /* ************ custom buttons, old stuff ************** */
1604 /* draws in resolution of 20x4 colors */
1605 static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
1608 float rgb[3], h,s,v;
1609 float dx, dy, sx1, sx2, sy, x=0.0f, y=0.0f;
1610 float col0[4][3]; // left half, rect bottom to top
1611 float col1[4][3]; // right half, rect bottom to top
1613 ui_get_but_vectorf(but, rgb);
1614 rgb_to_hsv(rgb[0], rgb[1], rgb[2], &h, &s, &v);
1616 /* draw series of gouraud rects */
1617 glShadeModel(GL_SMOOTH);
1620 if(but->a1==0) { // S and V vary
1621 hsv_to_rgb(h, 0.0, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1622 hsv_to_rgb(h, 0.333, 0.0, &col1[1][0], &col1[1][1], &col1[1][2]);
1623 hsv_to_rgb(h, 0.666, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
1624 hsv_to_rgb(h, 1.0, 0.0, &col1[3][0], &col1[3][1], &col1[3][2]);
1627 else if(but->a1==1) { // H and V vary
1628 hsv_to_rgb(0.0, s, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1629 hsv_to_rgb(0.0, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
1630 hsv_to_rgb(0.0, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
1631 hsv_to_rgb(0.0, s, 1.0, &col1[3][0], &col1[3][1], &col1[3][2]);
1634 else if(but->a1==2) { // H and S vary
1635 hsv_to_rgb(0.0, 0.0, v, &col1[0][0], &col1[0][1], &col1[0][2]);
1636 hsv_to_rgb(0.0, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
1637 hsv_to_rgb(0.0, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
1638 hsv_to_rgb(0.0, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
1641 else if(but->a1==3) { // only H
1642 hsv_to_rgb(0.0, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1643 VECCOPY(col1[1], col1[0]);
1644 VECCOPY(col1[2], col1[0]);
1645 VECCOPY(col1[3], col1[0]);
1648 else if(but->a1==4) { // only S
1649 hsv_to_rgb(1.0, 0.0, 1.0, &col1[1][0], &col1[1][1], &col1[1][2]);
1650 VECCOPY(col1[0], col1[1]);
1651 VECCOPY(col1[2], col1[1]);
1652 VECCOPY(col1[3], col1[1]);
1655 else if(but->a1==5) { // only V
1656 hsv_to_rgb(1.0, 1.0, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
1657 VECCOPY(col1[0], col1[2]);
1658 VECCOPY(col1[1], col1[2]);
1659 VECCOPY(col1[3], col1[2]);
1666 for(dx=0.0; dx<1.0; dx+= 0.05) {
1668 VECCOPY(col0[0], col1[0]);
1669 VECCOPY(col0[1], col1[1]);
1670 VECCOPY(col0[2], col1[2]);
1671 VECCOPY(col0[3], col1[3]);
1674 if(but->a1==0) { // S and V vary
1675 hsv_to_rgb(h, 0.0, dx, &col1[0][0], &col1[0][1], &col1[0][2]);
1676 hsv_to_rgb(h, 0.333, dx, &col1[1][0], &col1[1][1], &col1[1][2]);
1677 hsv_to_rgb(h, 0.666, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
1678 hsv_to_rgb(h, 1.0, dx, &col1[3][0], &col1[3][1], &col1[3][2]);
1680 else if(but->a1==1) { // H and V vary
1681 hsv_to_rgb(dx, s, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1682 hsv_to_rgb(dx, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
1683 hsv_to_rgb(dx, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
1684 hsv_to_rgb(dx, s, 1.0, &col1[3][0], &col1[3][1], &col1[3][2]);
1686 else if(but->a1==2) { // H and S vary
1687 hsv_to_rgb(dx, 0.0, v, &col1[0][0], &col1[0][1], &col1[0][2]);
1688 hsv_to_rgb(dx, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
1689 hsv_to_rgb(dx, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
1690 hsv_to_rgb(dx, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
1692 else if(but->a1==3) { // only H
1693 hsv_to_rgb(dx, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]);
1694 VECCOPY(col1[1], col1[0]);
1695 VECCOPY(col1[2], col1[0]);
1696 VECCOPY(col1[3], col1[0]);
1698 else if(but->a1==4) { // only S
1699 hsv_to_rgb(h, dx, 1.0, &col1[1][0], &col1[1][1], &col1[1][2]);
1700 VECCOPY(col1[0], col1[1]);
1701 VECCOPY(col1[2], col1[1]);
1702 VECCOPY(col1[3], col1[1]);
1704 else if(but->a1==5) { // only V
1705 hsv_to_rgb(h, 1.0, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
1706 VECCOPY(col1[0], col1[2]);
1707 VECCOPY(col1[1], col1[2]);
1708 VECCOPY(col1[3], col1[2]);
1712 sx1= rect->xmin + dx*(rect->xmax-rect->xmin);
1713 sx2= rect->xmin + (dx+0.05)*(rect->xmax-rect->xmin);
1715 dy= (rect->ymax-rect->ymin)/3.0;
1718 for(a=0; a<3; a++, sy+=dy) {
1719 glColor3fv(col0[a]);
1720 glVertex2f(sx1, sy);
1722 glColor3fv(col1[a]);
1723 glVertex2f(sx2, sy);
1725 glColor3fv(col1[a+1]);
1726 glVertex2f(sx2, sy+dy);
1728 glColor3fv(col0[a+1]);
1729 glVertex2f(sx1, sy+dy);
1734 glShadeModel(GL_FLAT);
1737 x= rect->xmin + x*(rect->xmax-rect->xmin);
1738 y= rect->ymin + y*(rect->ymax-rect->ymin);
1739 CLAMP(x, rect->xmin+3.0, rect->xmax-3.0);
1740 CLAMP(y, rect->ymin+3.0, rect->ymax-3.0);
1742 ui_hsv_cursor(x, y);
1745 glColor3ub(0, 0, 0);
1746 fdrawbox((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
1749 /* vertical 'value' slider, using new widget code */
1750 static void ui_draw_but_HSV_v(uiBut *but, rcti *rect)
1753 float rad= 0.5f*(rect->xmax - rect->xmin);
1755 float rgb[3], hsv[3], v;
1756 int color_profile = but->block->color_profile;
1759 if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
1760 color_profile = BLI_PR_NONE;
1764 ui_get_but_vectorf(but, rgb);
1765 rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
1769 v = linearrgb_to_srgb(v);
1774 round_box_edges(&wtb, 15, rect, rad);
1776 /* setup temp colors */
1777 wcol_tmp.outline[0]= wcol_tmp.outline[1]= wcol_tmp.outline[2]= 0;
1778 wcol_tmp.inner[0]= wcol_tmp.inner[1]= wcol_tmp.inner[2]= 128;
1779 wcol_tmp.shadetop= 127;
1780 wcol_tmp.shadedown= -128;
1783 widgetbase_draw(&wtb, &wcol_tmp);
1786 x= rect->xmin + 0.5f * (rect->xmax-rect->xmin);
1787 y= rect->ymin + v * (rect->ymax-rect->ymin);
1788 CLAMP(y, rect->ymin+3.0, rect->ymax-3.0);
1790 ui_hsv_cursor(x, y);
1794 /* ************ button callbacks, draw ***************** */
1796 static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
1799 float rad= 0.5f*(rect->ymax - rect->ymin);
1800 float textofs = rad*0.75;
1805 round_box_edges(&wtb, roundboxalign, rect, rad);
1808 if(!(state & UI_TEXTINPUT)) {
1809 widget_num_tria(&wtb.tria1, rect, 0.6f, 'l');
1810 widget_num_tria(&wtb.tria2, rect, 0.6f, 'r');
1813 widgetbase_draw(&wtb, wcol);
1816 rect->xmin += textofs;
1817 rect->xmax -= textofs;
1821 static int ui_link_bezier_points(rcti *rect, float coord_array[][2], int resol)
1823 float dist, vec[4][2];
1825 vec[0][0]= rect->xmin;
1826 vec[0][1]= rect->ymin;
1827 vec[3][0]= rect->xmax;
1828 vec[3][1]= rect->ymax;
1830 dist= 0.5f*ABS(vec[0][0] - vec[3][0]);
1832 vec[1][0]= vec[0][0]+dist;
1833 vec[1][1]= vec[0][1];
1835 vec[2][0]= vec[3][0]-dist;
1836 vec[2][1]= vec[3][1];
1838 forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0], coord_array[0], resol, sizeof(float)*2);
1839 forward_diff_bezier(vec[0][1], vec[1][1], vec[2][1], vec[3][1], coord_array[0]+1, resol, sizeof(float)*2);
1844 #define LINK_RESOL 24
1845 void ui_draw_link_bezier(rcti *rect)
1847 float coord_array[LINK_RESOL+1][2];
1849 if(ui_link_bezier_points(rect, coord_array, LINK_RESOL)) {
1853 /* we can reuse the dist variable here to increment the GL curve eval amount*/
1854 dist = 1.0f/(float)LINK_RESOL;
1857 glEnable(GL_LINE_SMOOTH);
1859 glBegin(GL_LINE_STRIP);
1860 for(i=0; i<=LINK_RESOL; i++) {
1861 glVertex2fv(coord_array[i]);
1865 glDisable(GL_BLEND);
1866 glDisable(GL_LINE_SMOOTH);
1871 /* function in use for buttons and for view2d sliders */
1872 void uiWidgetScrollDraw(uiWidgetColors *wcol, rcti *rect, rcti *slider, int state)
1880 /* determine horizontal/vertical */
1881 horizontal= (rect->xmax - rect->xmin > rect->ymax - rect->ymin);
1884 rad= 0.5f*(rect->ymax - rect->ymin);
1886 rad= 0.5f*(rect->xmax - rect->xmin);
1888 wtb.shadedir= (horizontal)? 1: 0;
1890 /* draw back part, colors swapped and shading inverted */
1892 SWAP(short, wcol->shadetop, wcol->shadedown);
1894 round_box_edges(&wtb, 15, rect, rad);
1895 widgetbase_draw(&wtb, wcol);
1898 if(slider->xmax-slider->xmin<2 || slider->ymax-slider->ymin<2);
1901 SWAP(short, wcol->shadetop, wcol->shadedown);
1903 QUATCOPY(wcol->inner, wcol->item);
1905 if(wcol->shadetop>wcol->shadedown)
1906 wcol->shadetop+= 20; /* XXX violates themes... */
1907 else wcol->shadedown+= 20;
1909 if(state & UI_SCROLL_PRESSED) {
1910 wcol->inner[0]= wcol->inner[0]>=250? 255 : wcol->inner[0]+5;
1911 wcol->inner[1]= wcol->inner[1]>=250? 255 : wcol->inner[1]+5;
1912 wcol->inner[2]= wcol->inner[2]>=250? 255 : wcol->inner[2]+5;
1916 wtb.emboss= 0; /* only emboss once */
1918 round_box_edges(&wtb, 15, slider, rad);
1920 if(state & UI_SCROLL_ARROWS) {
1921 if(wcol->item[0] > 48) wcol->item[0]-= 48;
1922 if(wcol->item[1] > 48) wcol->item[1]-= 48;
1923 if(wcol->item[2] > 48) wcol->item[2]-= 48;
1927 widget_scroll_circle(&wtb.tria1, slider, 0.6f, 'l');
1928 widget_scroll_circle(&wtb.tria2, slider, 0.6f, 'r');
1931 widget_scroll_circle(&wtb.tria1, slider, 0.6f, 'b');
1932 widget_scroll_circle(&wtb.tria2, slider, 0.6f, 't');
1935 widgetbase_draw(&wtb, wcol);
1939 static void widget_scroll(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
1943 float fac, size, min;
1946 /* calculate slider part */
1947 value= ui_get_but_val(but);
1949 size= (but->softmax + but->a1 - but->softmin);
1950 size= MAX2(size, 2);
1955 /* determine horizontal/vertical */
1956 horizontal= (rect->xmax - rect->xmin > rect->ymax - rect->ymin);
1959 fac= (rect->xmax - rect->xmin)/(size);
1960 rect1.xmin= rect1.xmin + ceil(fac*(value - but->softmin));
1961 rect1.xmax= rect1.xmin + ceil(fac*(but->a1 - but->softmin));
1963 /* ensure minimium size */
1964 min= rect->ymax - rect->ymin;
1966 if(rect1.xmax - rect1.xmin < min) {
1967 rect1.xmax= rect1.xmin + min;
1969 if(rect1.xmax > rect->xmax) {
1970 rect1.xmax= rect->xmax;
1971 rect1.xmin= MAX2(rect1.xmax - min, rect->xmin);
1976 fac= (rect->ymax - rect->ymin)/(size);
1977 rect1.ymax= rect1.ymax - ceil(fac*(value - but->softmin));
1978 rect1.ymin= rect1.ymax - ceil(fac*(but->a1 - but->softmin));
1980 /* ensure minimium size */
1981 min= rect->xmax - rect->xmin;
1983 if(rect1.ymax - rect1.ymin < min) {
1984 rect1.ymax= rect1.ymin + min;
1986 if(rect1.ymax > rect->ymax) {
1987 rect1.ymax= rect->ymax;
1988 rect1.ymin= MAX2(rect1.ymax - min, rect->ymin);
1993 if(state & UI_SELECT)
1994 state= UI_SCROLL_PRESSED;
1997 uiWidgetScrollDraw(wcol, rect, &rect1, state);
2000 static void widget_link(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2003 if(but->flag & UI_SELECT) {
2006 UI_ThemeColor(TH_TEXT_HI);
2008 rectlink.xmin= (rect->xmin+rect->xmax)/2;
2009 rectlink.ymin= (rect->ymin+rect->ymax)/2;
2010 rectlink.xmax= but->linkto[0];
2011 rectlink.ymax= but->linkto[1];
2013 ui_draw_link_bezier(&rectlink);
2018 static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2020 uiWidgetBase wtb, wtb1;
2029 /* backdrop first */
2032 offs= 0.5f*(rect->ymax - rect->ymin);
2033 round_box_edges(&wtb, roundboxalign, rect, offs);
2036 widgetbase_draw(&wtb, wcol);
2039 VECCOPY(outline, wcol->outline);
2040 VECCOPY(wcol->outline, wcol->item);
2041 VECCOPY(wcol->inner, wcol->item);
2042 SWAP(short, wcol->shadetop, wcol->shadedown);
2046 value= ui_get_but_val(but);
2047 fac= (value-but->softmin)*(rect1.xmax - rect1.xmin - offs)/(but->softmax - but->softmin);
2049 /* left part of slider, always rounded */
2050 rect1.xmax= rect1.xmin + ceil(offs+1.0f);
2051 round_box_edges(&wtb1, roundboxalign & ~6, &rect1, offs);
2053 widgetbase_draw(&wtb1, wcol);
2055 /* right part of slider, interpolate roundness */
2056 rect1.xmax= rect1.xmin + fac + offs;
2057 rect1.xmin+= floor(offs-1.0f);
2058 if(rect1.xmax + offs > rect->xmax)
2059 offs*= (rect1.xmax + offs - rect->xmax)/offs;
2062 round_box_edges(&wtb1, roundboxalign & ~9, &rect1, offs);
2064 widgetbase_draw(&wtb1, wcol);
2065 VECCOPY(wcol->outline, outline);
2066 SWAP(short, wcol->shadetop, wcol->shadedown);
2071 widgetbase_draw(&wtb, wcol);
2074 rect->xmin += offs*0.75f;
2075 rect->xmax -= offs*0.75f;
2078 static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2082 int color_profile = but->block->color_profile;
2085 if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
2086 color_profile = BLI_PR_NONE;
2092 round_box_edges(&wtb, roundboxalign, rect, 5.0f);
2094 ui_get_but_vectorf(but, col);
2097 linearrgb_to_srgb_v3_v3(col, col);
2099 wcol->inner[0]= FTOCHAR(col[0]);
2100 wcol->inner[1]= FTOCHAR(col[1]);
2101 wcol->inner[2]= FTOCHAR(col[2]);
2103 widgetbase_draw(&wtb, wcol);
2108 static void widget_textbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2115 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2117 widgetbase_draw(&wtb, wcol);
2122 static void widget_menubut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2129 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2132 widget_menu_trias(&wtb.tria1, rect);
2134 widgetbase_draw(&wtb, wcol);
2137 rect->xmax -= (rect->ymax-rect->ymin);
2140 static void widget_menuiconbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2147 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2150 widgetbase_draw(&wtb, wcol);
2153 static void widget_pulldownbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2155 if(state & UI_ACTIVE) {
2157 float rad= 0.5f*(rect->ymax - rect->ymin); // 4.0f
2162 round_box_edges(&wtb, 15, rect, rad);
2164 widgetbase_draw(&wtb, wcol);
2168 static void widget_menu_itembut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2174 /* not rounded, no outline */
2176 round_box_edges(&wtb, 0, rect, 0.0f);
2178 widgetbase_draw(&wtb, wcol);
2181 static void widget_list_itembut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2187 /* rounded, but no outline */
2189 round_box_edges(&wtb, 15, rect, 4.0f);
2191 widgetbase_draw(&wtb, wcol);
2194 static void widget_optionbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2197 rcti recttemp= *rect;
2203 recttemp.xmax= recttemp.xmin + (recttemp.ymax-recttemp.ymin);
2206 delta= 1 + (recttemp.ymax-recttemp.ymin)/8;
2207 recttemp.xmin+= delta;
2208 recttemp.ymin+= delta;
2209 recttemp.xmax-= delta;
2210 recttemp.ymax-= delta;
2213 round_box_edges(&wtb, 15, &recttemp, 4.0f);
2216 if(state & UI_SELECT) {
2217 widget_check_trias(&wtb.tria1, &recttemp);
2220 widgetbase_draw(&wtb, wcol);
2223 rect->xmin += (rect->ymax-rect->ymin)*0.7 + delta;
2227 static void widget_radiobut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2234 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2236 widgetbase_draw(&wtb, wcol);
2240 static void widget_but(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2247 round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2249 widgetbase_draw(&wtb, wcol);
2253 static void widget_roundbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2256 float rad= 5.0f; //0.5f*(rect->ymax - rect->ymin);
2261 round_box_edges(&wtb, roundboxalign, rect, rad);
2263 widgetbase_draw(&wtb, wcol);
2266 static void widget_draw_extra_mask(const bContext *C, uiBut *but, uiWidgetType *wt, rcti *rect)
2272 wt->wcol= *(wt->wcol_theme);
2276 if(but->block->drawextra) {
2277 /* note: drawextra can change rect +1 or -1, to match round errors of existing previews */
2278 but->block->drawextra(C, but->poin, but->block->drawextra_arg1, but->block->drawextra_arg2, rect);
2280 /* make mask to draw over image */
2281 UI_GetThemeColor3ubv(TH_BACK, col);
2282 glColor3ubv((unsigned char*)col);
2284 round_box__edges(&wtb, 15, rect, 0.0f, 4.0);
2285 widgetbase_outline(&wtb);
2289 round_box_edges(&wtb, 15, rect, 5.0f);
2292 widgetbase_draw(&wtb, &wt->wcol);
2297 static void widget_disabled(rcti *rect)
2303 /* can't use theme TH_BACK or TH_PANEL... undefined */
2304 glGetFloatv(GL_COLOR_CLEAR_VALUE, col);
2305 glColor4f(col[0], col[1], col[2], 0.5f);
2306 /* need -1 and +1 to make it work right for aligned buttons,
2307 * but problem may be somewhere else? */
2308 glRectf(rect->xmin-1, rect->ymin, rect->xmax, rect->ymax+1);
2310 glDisable(GL_BLEND);
2313 static uiWidgetType *widget_type(uiWidgetTypeEnum type)
2315 bTheme *btheme= U.themes.first;
2316 static uiWidgetType wt;
2319 wt.wcol_theme= &btheme->tui.wcol_regular;
2320 wt.wcol_state= &btheme->tui.wcol_state;
2321 wt.state= widget_state;
2322 wt.draw= widget_but;
2324 wt.text= widget_draw_text_icon;
2327 case UI_WTYPE_REGULAR:
2330 case UI_WTYPE_LABEL:
2332 wt.state= widget_state_label;
2335 case UI_WTYPE_TOGGLE:
2336 wt.wcol_theme= &btheme->tui.wcol_toggle;
2339 case UI_WTYPE_OPTION:
2340 wt.wcol_theme= &btheme->tui.wcol_option;
2341 wt.draw= widget_optionbut;
2344 case UI_WTYPE_RADIO:
2345 wt.wcol_theme= &btheme->tui.wcol_radio;
2346 wt.draw= widget_radiobut;
2349 case UI_WTYPE_NUMBER:
2350 wt.wcol_theme= &btheme->tui.wcol_num;
2351 wt.draw= widget_numbut;
2354 case UI_WTYPE_SLIDER:
2355 wt.wcol_theme= &btheme->tui.wcol_numslider;
2356 wt.custom= widget_numslider;
2357 wt.state= widget_state_numslider;
2361 wt.wcol_theme= &btheme->tui.wcol_tool;
2362 wt.draw= widget_roundbut;
2368 wt.wcol_theme= &btheme->tui.wcol_text;
2369 wt.draw= widget_textbut;
2372 case UI_WTYPE_NAME_LINK:
2375 case UI_WTYPE_POINTER_LINK:
2378 case UI_WTYPE_FILENAME:
2383 case UI_WTYPE_MENU_RADIO:
2384 wt.wcol_theme= &btheme->tui.wcol_menu;
2385 wt.draw= widget_menubut;
2388 case UI_WTYPE_MENU_ICON_RADIO:
2389 wt.wcol_theme= &btheme->tui.wcol_menu;
2390 wt.draw= widget_menuiconbut;
2393 case UI_WTYPE_MENU_POINTER_LINK:
2394 wt.wcol_theme= &btheme->tui.wcol_menu;
2395 wt.draw= widget_menubut;
2398 case UI_WTYPE_PULLDOWN:
2399 wt.wcol_theme= &btheme->tui.wcol_pulldown;
2400 wt.draw= widget_pulldownbut;
2401 wt.state= widget_state_pulldown;
2405 case UI_WTYPE_MENU_ITEM:
2406 wt.wcol_theme= &btheme->tui.wcol_menu_item;
2407 wt.draw= widget_menu_itembut;
2408 wt.state= widget_state_menu_item;
2411 case UI_WTYPE_MENU_BACK:
2412 wt.wcol_theme= &btheme->tui.wcol_menu_back;
2413 wt.draw= widget_menu_back;
2421 case UI_WTYPE_SWATCH:
2422 wt.custom= widget_swatch;
2426 wt.wcol_theme= &btheme->tui.wcol_box;
2429 case UI_WTYPE_RGB_PICKER:
2432 case UI_WTYPE_NORMAL:
2435 case UI_WTYPE_SCROLL:
2436 wt.wcol_theme= &btheme->tui.wcol_scroll;
2437 wt.state= widget_state_nothing;
2438 wt.custom= widget_scroll;
2441 case UI_WTYPE_LISTITEM:
2442 wt.wcol_theme= &btheme->tui.wcol_list_item;
2443 wt.draw= widget_list_itembut;
2451 static int widget_roundbox_set(uiBut *but, rcti *rect)
2454 if(but->flag & UI_BUT_ALIGN) {
2456 if(but->flag & UI_BUT_ALIGN_TOP)
2458 if(but->flag & UI_BUT_ALIGN_LEFT)
2461 switch(but->flag & UI_BUT_ALIGN) {
2462 case UI_BUT_ALIGN_TOP:
2465 case UI_BUT_ALIGN_DOWN:
2468 case UI_BUT_ALIGN_LEFT:
2471 case UI_BUT_ALIGN_RIGHT:
2475 case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT:
2478 case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT:
2481 case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT:
2484 case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT:
2496 /* conversion from old to new buttons, so still messy */
2497 void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rcti *rect)
2499 bTheme *btheme= U.themes.first;
2500 ThemeUI *tui= &btheme->tui;
2501 uiFontStyle *fstyle= &style->widget;
2502 uiWidgetType *wt= NULL;
2504 /* handle menus separately */
2505 if(but->dt==UI_EMBOSSP) {
2506 switch (but->type) {
2508 widget_draw_text_icon(&style->widgetlabel, &tui->wcol_menu_back, but, rect);
2514 wt= widget_type(UI_WTYPE_MENU_ITEM);
2517 else if(but->dt==UI_EMBOSSN) {
2519 wt= widget_type(UI_WTYPE_ICON);
2523 switch (but->type) {
2525 if(but->block->flag & UI_BLOCK_LOOP)
2526 widget_draw_text_icon(&style->widgetlabel, &tui->wcol_menu_back, but, rect);
2528 wt= widget_type(UI_WTYPE_LABEL);
2529 fstyle= &style->widgetlabel;
2537 wt= widget_type(UI_WTYPE_EXEC);
2541 wt= widget_type(UI_WTYPE_NUMBER);
2546 wt= widget_type(UI_WTYPE_SLIDER);
2550 wt= widget_type(UI_WTYPE_RADIO);
2554 wt= widget_type(UI_WTYPE_LISTITEM);
2558 wt= widget_type(UI_WTYPE_NAME);
2562 wt= widget_type(UI_WTYPE_NAME);
2563 if(but->block->flag & UI_BLOCK_LOOP)
2564 wt->wcol_theme= &btheme->tui.wcol_menu_back;
2571 wt= widget_type(UI_WTYPE_TOGGLE);
2576 if (!(but->flag & UI_HAS_ICON)) {
2577 wt= widget_type(UI_WTYPE_OPTION);
2578 but->flag |= UI_TEXT_LEFT;
2581 wt= widget_type(UI_WTYPE_TOGGLE);
2587 if(!but->str[0] && but->icon)
2588 wt= widget_type(UI_WTYPE_MENU_ICON_RADIO);
2590 wt= widget_type(UI_WTYPE_MENU_RADIO);
2594 wt= widget_type(UI_WTYPE_PULLDOWN);
2598 wt= widget_type(UI_WTYPE_MENU_ITEM);
2602 wt= widget_type(UI_WTYPE_SWATCH);
2607 wt= widget_type(UI_WTYPE_BOX);
2612 wt= widget_type(UI_WTYPE_ICON);
2613 wt->custom= widget_link;
2618 widget_draw_extra_mask(C, but, widget_type(UI_WTYPE_BOX), rect);
2622 if(but->a1==9) // vertical V slider, uses new widget draw now
2623 ui_draw_but_HSV_v(but, rect);
2624 else // other HSV pickers...
2625 ui_draw_but_HSVCUBE(but, rect);
2629 ui_draw_but_HSVCIRCLE(but, &tui->wcol_regular, rect);
2633 ui_draw_but_COLORBAND(but, &tui->wcol_regular, rect);
2637 ui_draw_but_NORMAL(but, &tui->wcol_regular, rect);
2641 ui_draw_but_IMAGE(ar, but, &tui->wcol_regular, rect);
2645 ui_draw_but_CURVE(ar, but, &tui->wcol_regular, rect);
2649 wt= widget_type(UI_WTYPE_SCROLL);
2653 wt= widget_type(UI_WTYPE_REGULAR);
2658 rcti disablerect= *rect; /* rect gets clipped smaller for text */
2659 int roundboxalign, state;
2661 roundboxalign= widget_roundbox_set(but, rect);
2664 if(but->editstr) state |= UI_TEXTINPUT;
2666 wt->state(wt, state);
2668 wt->custom(but, &wt->wcol, rect, state, roundboxalign);
2670 wt->draw(&wt->wcol, rect, state, roundboxalign);
2671 wt->text(fstyle, &wt->wcol, but, rect);
2673 if(state & (UI_BUT_DISABLED|UI_BUT_INACTIVE))
2674 if(but->dt!=UI_EMBOSSP)
2675 widget_disabled(&disablerect);
2679 void ui_draw_menu_back(uiStyle *style, uiBlock *block, rcti *rect)
2681 uiWidgetType *wt= widget_type(UI_WTYPE_MENU_BACK);
2685 wt->draw(&wt->wcol, rect, block->flag, block->direction);
2687 wt->draw(&wt->wcol, rect, 0, 0);
2691 void ui_draw_search_back(uiStyle *style, uiBlock *block, rcti *rect)
2693 uiWidgetType *wt= widget_type(UI_WTYPE_BOX);
2696 widget_softshadow(rect, 15, 5.0f, 8.0f);
2697 glDisable(GL_BLEND);
2701 wt->draw(&wt->wcol, rect, block->flag, 15);
2703 wt->draw(&wt->wcol, rect, 0, 15);
2708 /* helper call to draw a menu item without button */
2709 /* state: UI_ACTIVE or 0 */
2710 void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, char *name, int iconid, int state)
2712 uiWidgetType *wt= widget_type(UI_WTYPE_MENU_ITEM);
2716 wt->state(wt, state);
2717 wt->draw(&wt->wcol, rect, 0, 0);
2719 uiStyleFontSet(fstyle);
2720 fstyle->align= UI_STYLE_TEXT_LEFT;
2722 /* text location offset */
2724 if(iconid) rect->xmin+= ICON_HEIGHT;
2726 /* cut string in 2 parts? */
2727 cpoin= strchr(name, '|');
2730 rect->xmax -= BLF_width(cpoin+1) + 10;
2733 glColor3ubv((unsigned char*)wt->wcol.text);
2734 uiStyleFontDraw(fstyle, rect, name);
2736 /* part text right aligned */
2738 fstyle->align= UI_STYLE_TEXT_RIGHT;
2739 rect->xmax= _rect.xmax - 5;
2740 uiStyleFontDraw(fstyle, rect, cpoin+1);
2744 /* restore rect, was messed with */
2748 int xs= rect->xmin+4;
2749 int ys= 1 + (rect->ymin+rect->ymax- ICON_HEIGHT)/2;
2751 UI_icon_draw_aspect(xs, ys, iconid, 1.2f, 0.5f); /* XXX scale weak get from fstyle? */
2752 glDisable(GL_BLEND);
2756 void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, char *name, int iconid, int state)
2760 uiWidgetType *wt= widget_type(UI_WTYPE_MENU_ITEM);
2762 wt->state(wt, state);
2763 wt->draw(&wt->wcol, rect, 0, 0);
2765 widget_draw_preview(iconid, 1.f, 1.f, rect);
2767 if (state == UI_ACTIVE)
2768 glColor3ubv((unsigned char*)wt->wcol.text);
2770 glColor3ubv((unsigned char*)wt->wcol.text_sel);
2773 trect.xmax = trect.xmin + BLF_width(name) + 10;
2775 trect.ymax = trect.ymin + BLF_height(name);
2776 uiStyleFontDraw(fstyle, &trect, name);