More button code cleaning and tweaks

* now the rounded and round shaded themes use the same drawing backend
* fixed a problem with menu and number button triangles not accounting for buttons zoom
This commit is contained in:
Matt Ebb
2008-12-28 23:14:37 +00:00
parent 750bb40de3
commit e8bf295ec9

View File

@@ -483,7 +483,7 @@ void uiRoundBox(float minx, float miny, float maxx, float maxy, float rad)
glDisable( GL_LINE_SMOOTH ); glDisable( GL_LINE_SMOOTH );
} }
void uiTriangleFakeAA(float x1, float y1, float x2, float y2, float x3, float y3) void uiTriangleFakeAA(float x1, float y1, float x2, float y2, float x3, float y3, float asp)
{ {
float color[4]; float color[4];
float jitter; float jitter;
@@ -491,11 +491,11 @@ void uiTriangleFakeAA(float x1, float y1, float x2, float y2, float x3, float y3
/* get the colour and divide up the alpha */ /* get the colour and divide up the alpha */
glGetFloatv(GL_CURRENT_COLOR, color); glGetFloatv(GL_CURRENT_COLOR, color);
color[3]= 1/(float)passes; color[3]= 1.0/(float)passes;
glColor4fv(color); glColor4fv(color);
/* set the 'jitter amount' */ /* set the 'jitter amount' */
jitter = 1/(float)passes; jitter = 0.65/(float)passes * asp;
glEnable( GL_BLEND ); glEnable( GL_BLEND );
@@ -504,7 +504,7 @@ void uiTriangleFakeAA(float x1, float y1, float x2, float y2, float x3, float y3
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
/* 'point' first, then two base vertices */ /* 'point' first, then two base vertices */
glVertex2f(x1+(i*jitter), y1+(i*jitter)); glVertex2f(x1, y1+(i*jitter));
glVertex2f(x2, y2+(i*jitter)); glVertex2f(x2, y2+(i*jitter));
glVertex2f(x3, y3+(i*jitter)); glVertex2f(x3, y3+(i*jitter));
glEnd(); glEnd();
@@ -980,6 +980,48 @@ static void ui_checkmark(float x1, float y1, float x2, float y2)
glDisable( GL_LINE_SMOOTH ); glDisable( GL_LINE_SMOOTH );
} }
static void ui_draw_toggle_checkbox(int flag, int type, int colorid, float x1, float y1, float x2, float y2)
{
if (!(flag & UI_HAS_ICON)) {
/* check to see that there's room for the check mark
* draw a check mark, or if it's a TOG3, draw a + or - */
if (x2 - x1 > 20) {
ui_checkmark_box(colorid, x1, y1, x2, y2);
/* TOG3 is handled with ui_tog3_invert()
* remember to update checkmark drawing there too*/
if((flag & UI_SELECT) && (type != TOG3)) {
UI_ThemeColorShade(colorid, -140);
ui_checkmark(x1, y1, x2, y2);
}
/* draw a dot: alternate, for layers etc. */
} else if(flag & UI_SELECT) {
uiSetRoundBox(15);
UI_ThemeColorShade(colorid, -60);
glPushMatrix();
glTranslatef((x1+(x2-x1)/2), (y1+(y2-y1)/2), 0.0);
/* circle */
glutil_draw_filled_arc(0.0, M_PI*2.0, 2, 16);
glEnable( GL_LINE_SMOOTH );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
/* smooth outline */
glutil_draw_lined_arc(0.0, M_PI*2.0, 2, 16);
glDisable( GL_BLEND );
glDisable( GL_LINE_SMOOTH );
glPopMatrix();
}
}
}
/* small side double arrow for iconrow */ /* small side double arrow for iconrow */
static void ui_iconrow_arrows(float x1, float y1, float x2, float y2) static void ui_iconrow_arrows(float x1, float y1, float x2, float y2)
{ {
@@ -1004,31 +1046,31 @@ static void ui_iconrow_arrows(float x1, float y1, float x2, float y2)
} }
/* side double arrow for menu */ /* side double arrow for menu */
static void ui_menu_arrows(float x1, float y1, float x2, float y2) static void ui_menu_arrows(float x1, float y1, float x2, float y2, float asp)
{ {
/* 'point' first, then two base vertices */ /* 'point' first, then two base vertices */
uiTriangleFakeAA(x2-9, (y2-(y2-y1)/2)+6, uiTriangleFakeAA(x2-9, (y2-(y2-y1)/2)+6,
x2-6, (y2-(y2-y1)/2)+2, x2-6, (y2-(y2-y1)/2)+2,
x2-11, (y2-(y2-y1)/2)+2); x2-12, (y2-(y2-y1)/2)+2, asp);
uiTriangleFakeAA(x2-8, (y2-(y2-y1)/2)-6, uiTriangleFakeAA(x2-9, (y2-(y2-y1)/2)-6,
x2-6, (y2-(y2-y1)/2)-2, x2-6, (y2-(y2-y1)/2)-2,
x2-11, (y2-(y2-y1)/2)-2); x2-12, (y2-(y2-y1)/2)-2, asp);
} }
/* left/right arrows for number fields */ /* left/right arrows for number fields */
static void ui_num_arrows(float x1, float y1, float x2, float y2) static void ui_num_arrows(float x1, float y1, float x2, float y2, float asp)
{ {
if( x2-x1 > 25) { // 25 is a bit arbitrary, but small buttons cant have arrows if( x2-x1 > 25) { // 25 is a bit arbitrary, but small buttons cant have arrows
/* 'point' first, then two base vertices */ /* 'point' first, then two base vertices */
uiTriangleFakeAA(x1+4, y2-(y2-y1)/2, uiTriangleFakeAA(x1+4, y2-(y2-y1)/2,
x1+9, y2-(y2-y1)/2+3, x1+9, y2-(y2-y1)/2+3,
x1+9, y2-(y2-y1)/2-3); x1+9, y2-(y2-y1)/2-3, asp);
uiTriangleFakeAA(x2-4, y2-(y2-y1)/2, uiTriangleFakeAA(x2-4, y2-(y2-y1)/2,
x2-9, y2-(y2-y1)/2+3, x2-9, y2-(y2-y1)/2+3,
x2-9, y2-(y2-y1)/2-3); x2-9, y2-(y2-y1)/2-3, asp);
} }
} }
@@ -1148,7 +1190,7 @@ static void ui_roundshaded_button(int type, int colorid, float asp, float x1, fl
} else { } else {
UI_ThemeColorShade(colorid, -80); UI_ThemeColorShade(colorid, -80);
} }
ui_menu_arrows(x1, y1, x2, y2); ui_menu_arrows(x1, y1, x2, y2, asp);
/* end menu double arrow */ /* end menu double arrow */
break; break;
} }
@@ -1214,43 +1256,7 @@ static void ui_roundshaded_flat(int type, int colorid, float asp, float x1, floa
case TOG: case TOG:
case TOGN: case TOGN:
case TOG3: case TOG3:
if (!(flag & UI_HAS_ICON)) { ui_draw_toggle_checkbox(flag, type, colorid, x1, y1, x2, y2);
/* check to see that there's room for the check mark
* draw a check mark, or if it's a TOG3, draw a + or - */
if (x2 - x1 > 20) {
ui_checkmark_box(colorid, x1, y1, x2, y2);
/* TOG3 is handled with ui_tog3_invert()
* remember to update checkmark drawing there too*/
if((flag & UI_SELECT) && (type != TOG3)) {
UI_ThemeColorShade(colorid, -140);
ui_checkmark(x1, y1, x2, y2);
}
/* draw a dot: alternate, for layers etc. */
} else if(flag & UI_SELECT) {
uiSetRoundBox(15);
UI_ThemeColorShade(colorid, -60);
glPushMatrix();
glTranslatef((x1+(x2-x1)/2), (y1+(y2-y1)/2), 0.0);
/* circle */
glutil_draw_filled_arc(0.0, M_PI*2.0, 2, 16);
glEnable( GL_LINE_SMOOTH );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
/* smooth outline */
glutil_draw_lined_arc(0.0, M_PI*2.0, 2, 16);
glDisable( GL_BLEND );
glDisable( GL_LINE_SMOOTH );
glPopMatrix();
}
}
break; break;
case NUM: case NUM:
/* side arrows */ /* side arrows */
@@ -1262,7 +1268,7 @@ static void ui_roundshaded_flat(int type, int colorid, float asp, float x1, floa
else UI_ThemeColorShade(colorid, -20); else UI_ThemeColorShade(colorid, -20);
} }
ui_num_arrows(x1, y1, x2, y2); ui_num_arrows(x1, y1, x2, y2, asp);
/* end side arrows */ /* end side arrows */
break; break;
} }
@@ -1465,7 +1471,7 @@ static void ui_default_button(int type, int colorid, float asp, float x1, float
/* MENU DOUBLE-ARROW */ /* MENU DOUBLE-ARROW */
M_DARK; M_DARK;
ui_menu_arrows(x1, y1, x2, y2); ui_menu_arrows(x1, y1, x2, y2, asp);
/* MENU DOUBLE-ARROW */ /* MENU DOUBLE-ARROW */
break; break;
} }
@@ -1628,7 +1634,7 @@ static void ui_default_flat(int type, int colorid, float asp, float x1, float y1
else M_LGREY; else M_LGREY;
} }
ui_num_arrows(x1, y1, x2, y2); ui_num_arrows(x1, y1, x2, y2, asp);
/* END SIDE ARROWS */ /* END SIDE ARROWS */
} }
} }
@@ -1805,7 +1811,7 @@ static void ui_draw_oldskool(int type, int colorid, float asp, float x1, float y
case NUMABS: case NUMABS:
if(flag & UI_SELECT) UI_ThemeColorShade(colorid, -60); if(flag & UI_SELECT) UI_ThemeColorShade(colorid, -60);
else UI_ThemeColorShade(colorid, -30); else UI_ThemeColorShade(colorid, -30);
ui_num_arrows(x1, y1, x2, y2); ui_num_arrows(x1, y1, x2, y2, asp);
break; break;
case ICONROW: case ICONROW:
@@ -1824,69 +1830,24 @@ static void ui_draw_oldskool(int type, int colorid, float asp, float x1, float y
glRectf(x2-17, y1+asp, x2-asp, y2-asp); glRectf(x2-17, y1+asp, x2-asp, y2-asp);
UI_ThemeColorShade(colorid, -50); UI_ThemeColorShade(colorid, -50);
ui_menu_arrows(x1, y1, x2, y2); ui_menu_arrows(x1, y1, x2, y2, asp);
break; break;
} }
} }
/* *************** BASIC ROUNDED THEME ***************** */
static void round_button(float x1, float y1, float x2, float y2, float asp,
int colorid, int round, int menudeco, int curshade)
{
float rad;
rad= (y2-y1)/2.0;
if(rad>7.0) rad= 7.0;
uiSetRoundBox(round);
gl_round_box(GL_POLYGON, x1, y1, x2, y2, rad);
if(menudeco) {
uiSetRoundBox(round & ~9);
UI_ThemeColorShade(colorid, curshade-20);
gl_round_box(GL_POLYGON, x2-menudeco, y1, x2, y2, rad);
}
/* outline */
UI_ThemeColorBlendShade(TH_BUT_OUTLINE, TH_BACK, 0.1, -30);
uiSetRoundBox(round);
uiRoundRectFakeAA(x1, y1, x2, y2, rad, asp);
/* end outline */
}
/* button in midst of alignment row */
static void round_button_mid(float x1, float y1, float x2, float y2, float asp,
int colorid, int align, int menudeco, int curshade)
{
glRectf(x1, y1, x2, y2);
if(menudeco) {
UI_ThemeColorShade(colorid, curshade-20);
glRectf(x2-menudeco, y1, x2, y2);
}
UI_ThemeColorBlendShade(colorid, TH_BACK, 0.5, -70);
// we draw full outline, its not AA, and it works better button mouse-over hilite
// left right
fdrawline(x1, y1, x1, y2);
fdrawline(x2, y1, x2, y2);
// top down
fdrawline(x1, y2, x2, y2);
fdrawline(x1, y1, x2, y1);
}
static void ui_draw_round(int type, int colorid, float asp, float x1, float y1, float x2, float y2, int flag) static void ui_draw_round(int type, int colorid, float asp, float x1, float y1, float x2, float y2, int flag)
{ {
int align= (flag & UI_BUT_ALIGN); float rad, maxrad=7.0;
int curshade= 0, menudeco= 0; int align= (flag & UI_BUT_ALIGN), curshade;
if(type==ICONROW || type==ICONTEXTROW) menudeco= 9; /* rounded corners */
else if((type==MENU || type==BLOCK) && x2-x1>24) menudeco= 16; rad= (y2-y1)/2.0;
if (rad>(x2-x1)/2) rad = (x2-x1)/2;
if (maxrad) {
if (rad > maxrad) rad = maxrad;
}
/* end rounded corners */
/* paper */ /* paper */
if(flag & UI_SELECT) { if(flag & UI_SELECT) {
@@ -1900,49 +1861,59 @@ static void ui_draw_round(int type, int colorid, float asp, float x1, float y1,
UI_ThemeColorShade(colorid, curshade); UI_ThemeColorShade(colorid, curshade);
/* alignment */
if(align) { if(align) {
switch(align) { switch(align) {
case UI_BUT_ALIGN_TOP: case UI_BUT_ALIGN_TOP:
round_button(x1, y1, x2, y2, asp, colorid, 12, menudeco, curshade); uiSetRoundBox(12);
break; break;
case UI_BUT_ALIGN_DOWN: case UI_BUT_ALIGN_DOWN:
round_button(x1, y1, x2, y2, asp, colorid, 3, menudeco, curshade); uiSetRoundBox(3);
break; break;
case UI_BUT_ALIGN_LEFT: case UI_BUT_ALIGN_LEFT:
round_button(x1, y1, x2, y2, asp, colorid, 6, menudeco, curshade); uiSetRoundBox(6);
break; break;
case UI_BUT_ALIGN_RIGHT: case UI_BUT_ALIGN_RIGHT:
round_button(x1, y1, x2, y2, asp, colorid, 9, menudeco, curshade); uiSetRoundBox(9);
break; break;
case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT: case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT:
round_button(x1, y1, x2, y2, asp, colorid, 1, menudeco, curshade); uiSetRoundBox(1);
break; break;
case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT: case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT:
round_button(x1, y1, x2, y2, asp, colorid, 2, menudeco, curshade); uiSetRoundBox(2);
break; break;
case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT: case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT:
round_button(x1, y1, x2, y2, asp, colorid, 8, menudeco, curshade); uiSetRoundBox(8);
break; break;
case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT: case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT:
round_button(x1, y1, x2, y2, asp, colorid, 4, menudeco, curshade); uiSetRoundBox(4);
break; break;
default: default:
round_button_mid(x1, y1, x2, y2, asp, colorid, align, menudeco, curshade); uiSetRoundBox(0);
break; break;
} }
} }
else { else {
round_button(x1, y1, x2, y2, asp, colorid, 15, menudeco, curshade); uiSetRoundBox(15);
} }
/* end alignment */
/* draw the base button */
round_button_flat(colorid, asp, x1, y1, x2, y2, flag, rad);
/* special type decorations */ /* special type decorations */
switch(type) { switch(type) {
case TOG:
case TOGN:
case TOG3:
ui_draw_toggle_checkbox(flag, type, colorid, x1, y1, x2, y2);
break;
case NUM: case NUM:
case NUMABS: case NUMABS:
UI_ThemeColorShade(colorid, curshade-60); UI_ThemeColorShade(colorid, curshade-60);
ui_num_arrows(x1, y1, x2, y2); ui_num_arrows(x1, y1, x2, y2, asp);
break; break;
case ICONROW: case ICONROW:
@@ -1954,7 +1925,7 @@ static void ui_draw_round(int type, int colorid, float asp, float x1, float y1,
case MENU: case MENU:
case BLOCK: case BLOCK:
UI_ThemeColorShade(colorid, curshade-60); UI_ThemeColorShade(colorid, curshade-60);
ui_menu_arrows(x1, y1, x2, y2); ui_menu_arrows(x1, y1, x2, y2, asp);
break; break;
} }
} }
@@ -2053,7 +2024,7 @@ static void ui_draw_minimal(int type, int colorid, float asp, float x1, float y1
case NUMABS: case NUMABS:
if(flag & UI_SELECT) UI_ThemeColorShade(colorid, -60); if(flag & UI_SELECT) UI_ThemeColorShade(colorid, -60);
else UI_ThemeColorShade(colorid, -30); else UI_ThemeColorShade(colorid, -30);
ui_num_arrows(x1, y1, x2, y2); ui_num_arrows(x1, y1, x2, y2, asp);
break; break;
case ICONROW: case ICONROW:
@@ -2073,7 +2044,7 @@ static void ui_draw_minimal(int type, int colorid, float asp, float x1, float y1
glRectf(x2-17, y1+asp, x2-asp, y2-asp); glRectf(x2-17, y1+asp, x2-asp, y2-asp);
UI_ThemeColorShade(colorid, -50); UI_ThemeColorShade(colorid, -50);
ui_menu_arrows(x1, y1, x2, y2); ui_menu_arrows(x1, y1, x2, y2, asp);
break; break;
} }
@@ -3163,7 +3134,7 @@ static void ui_draw_table(int type, int colorid, float asp, float x1, float y1,
case NUMABS: case NUMABS:
if(flag & UI_SELECT) UI_ThemeColorShade(colorid, -120); if(flag & UI_SELECT) UI_ThemeColorShade(colorid, -120);
else UI_ThemeColorShade(colorid, -90); else UI_ThemeColorShade(colorid, -90);
ui_num_arrows(x1, y1, x2, y2); ui_num_arrows(x1, y1, x2, y2, asp);
break; break;
case TOG: case TOG:
@@ -3192,7 +3163,7 @@ static void ui_draw_table(int type, int colorid, float asp, float x1, float y1,
glRectf(x2-17, y1+asp, x2-asp, y2-asp); glRectf(x2-17, y1+asp, x2-asp, y2-asp);
UI_ThemeColorShade(colorid, -50); UI_ThemeColorShade(colorid, -50);
ui_menu_arrows(x1, y1, x2, y2); ui_menu_arrows(x1, y1, x2, y2, asp);
break; break;
} }
} }