Colorpicker variant 2; One large field for S and V, and slider for H, like
Gimp has for example. The previous picker is still as code there... ongoing experiments.
This commit is contained in:
@@ -2065,13 +2065,12 @@ static int ui_do_but_LINK(uiBlock *block, uiBut *but)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* picker sizes S size, D spacer, B button/pallette height */
|
/* picker sizes S hsize, F full size, D spacer, B button/pallette height */
|
||||||
#define SPICK 110.0
|
#define SPICK 110.0
|
||||||
|
#define FPICK 180.0
|
||||||
#define DPICK 6.0
|
#define DPICK 6.0
|
||||||
#define BPICK 24.0
|
#define BPICK 24.0
|
||||||
|
|
||||||
static short pick_mode=0;
|
|
||||||
|
|
||||||
#define UI_PALETTE_TOT 16
|
#define UI_PALETTE_TOT 16
|
||||||
static float palette[UI_PALETTE_TOT][3]= {
|
static float palette[UI_PALETTE_TOT][3]= {
|
||||||
{0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0},
|
{0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0},
|
||||||
@@ -2180,7 +2179,7 @@ static void do_palette1_cb(void *bt1, void *bt2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* color picker, cube version */
|
/* color picker, cube version */
|
||||||
static int ui_do_but_COL(uiBut *but)
|
static int ui_do_but_COL1(uiBut *but)
|
||||||
{
|
{
|
||||||
uiBlock *block;
|
uiBlock *block;
|
||||||
uiBut *bt;
|
uiBut *bt;
|
||||||
@@ -2235,12 +2234,6 @@ static int ui_do_but_COL(uiBut *but)
|
|||||||
bt= uiDefButF(block, NUM, 0, "V ", DPICK+1.5*SPICK,BPICK+DPICK+SPICK-60,SPICK/2,20, hsv+2, 0.0, 1.0, 10, 2, "");
|
bt= uiDefButF(block, NUM, 0, "V ", DPICK+1.5*SPICK,BPICK+DPICK+SPICK-60,SPICK/2,20, hsv+2, 0.0, 1.0, 10, 2, "");
|
||||||
uiButSetFunc(bt, do_palette1_cb, bt, but);
|
uiButSetFunc(bt, do_palette1_cb, bt, but);
|
||||||
|
|
||||||
//uiBlockBeginAlign(block);
|
|
||||||
//uiDefButS(block, ROW, 0, "Paste to color", DPICK+SPICK, BPICK+DPICK+20, SPICK,20, &pick_mode, 0.0, 0.0, 0, 0, "Clicks in palette pastes to active color");
|
|
||||||
//uiDefButS(block, ROW, 0, "Copy to palette",DPICK+SPICK, BPICK+DPICK, SPICK,20, &pick_mode, 0.0, 1.0, 0, 0, "Clicks in palette copies from active color");
|
|
||||||
//uiBlockEndAlign(block);
|
|
||||||
|
|
||||||
|
|
||||||
// safety
|
// safety
|
||||||
uiDefBut(block, LABEL, 0, "", -DPICK,-DPICK,2*SPICK+3*DPICK,2*SPICK+4*DPICK+BPICK, NULL, 0.0, 0.0, 0, 0, "");
|
uiDefBut(block, LABEL, 0, "", -DPICK,-DPICK,2*SPICK+3*DPICK,2*SPICK+4*DPICK+BPICK, NULL, 0.0, 0.0, 0, 0, "");
|
||||||
|
|
||||||
@@ -2253,6 +2246,79 @@ static int ui_do_but_COL(uiBut *but)
|
|||||||
return but->retval;
|
return but->retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* color picker, Gimp version */
|
||||||
|
static int ui_do_but_COL(uiBut *but)
|
||||||
|
{
|
||||||
|
uiBlock *block;
|
||||||
|
uiBut *bt;
|
||||||
|
ListBase listb={NULL, NULL};
|
||||||
|
float oldcol[3], col[3], hsv[3], h;
|
||||||
|
int a;
|
||||||
|
short event;
|
||||||
|
|
||||||
|
// signal to prevent calling up color picker
|
||||||
|
if(but->a1 == -1 || but->pointype!=FLO) {
|
||||||
|
uibut_do_func(but);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
block= uiNewBlock(&listb, "colorpicker", UI_EMBOSSP, UI_HELV, but->win);
|
||||||
|
block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT;
|
||||||
|
block->themecol= TH_BUT_NUM;
|
||||||
|
|
||||||
|
ui_get_but_vectorf(but, col);
|
||||||
|
VECCOPY(oldcol, col);
|
||||||
|
|
||||||
|
// the cube intersection
|
||||||
|
bt= uiDefButF(block, HSVCUBE, 0, "", 0,DPICK+BPICK,FPICK,FPICK, (float *)but->poin, 0.0, 0.0, 2, 0, "");
|
||||||
|
uiButSetFlag(bt, UI_NO_HILITE);
|
||||||
|
|
||||||
|
bt= uiDefButF(block, HSVCUBE, 0, "", 0,0,FPICK,BPICK, (float *)but->poin, 0.0, 0.0, 3, 0, "");
|
||||||
|
uiButSetFlag(bt, UI_NO_HILITE);
|
||||||
|
|
||||||
|
// palette
|
||||||
|
uiDefButF(block, COL, 0, "", FPICK+DPICK, 0, BPICK,BPICK, oldcol, 0.0, 0.0, -1, 0, "");
|
||||||
|
uiDefButF(block, COL, 0, "", FPICK+DPICK, BPICK+DPICK, BPICK,60-BPICK-DPICK, col, 0.0, 0.0, -1, 0, "");
|
||||||
|
|
||||||
|
h= (DPICK+BPICK+FPICK-64)/(UI_PALETTE_TOT/2.0);
|
||||||
|
for(a=0; a<UI_PALETTE_TOT/2; a++) {
|
||||||
|
bt= uiDefButF(block, COL, 0, "", FPICK+DPICK, 65.0+(float)a*h, BPICK/2, h, palette[a+UI_PALETTE_TOT/2], 0.0, 0.0, -1, 0, "");
|
||||||
|
uiButSetFunc(bt, do_palette_cb, bt, but);
|
||||||
|
bt= uiDefButF(block, COL, 0, "", FPICK+DPICK+BPICK/2, 65.0+(float)a*h, BPICK/2, h, palette[a], 0.0, 0.0, -1, 0, "");
|
||||||
|
uiButSetFunc(bt, do_palette_cb, bt, but);
|
||||||
|
}
|
||||||
|
|
||||||
|
// buttons
|
||||||
|
rgb_to_hsv(col[0], col[1], col[2], hsv, hsv+1, hsv+2);
|
||||||
|
|
||||||
|
h= (FPICK+DPICK+BPICK)/3.0;
|
||||||
|
bt= uiDefButF(block, NUM, 0, "R ", 0, BPICK+2*DPICK+FPICK+20, h,20, col, 0.0, 1.0, 10, 2, "");
|
||||||
|
uiButSetFunc(bt, do_palette1_cb, bt, but);
|
||||||
|
bt= uiDefButF(block, NUM, 0, "G ", h, BPICK+2*DPICK+FPICK+20, h,20, col+1, 0.0, 1.0, 10, 2, "");
|
||||||
|
uiButSetFunc(bt, do_palette1_cb, bt, but);
|
||||||
|
bt= uiDefButF(block, NUM, 0, "B ", 2*h, BPICK+2*DPICK+FPICK+20, h,20, col+2, 0.0, 1.0, 10, 2, "");
|
||||||
|
uiButSetFunc(bt, do_palette1_cb, bt, but);
|
||||||
|
|
||||||
|
bt= uiDefButF(block, NUM, 0, "H ", 0, BPICK+2*DPICK+FPICK, h,20, hsv, 0.0, 1.0, 10, 2, "");
|
||||||
|
uiButSetFunc(bt, do_palette1_cb, bt, but);
|
||||||
|
bt= uiDefButF(block, NUM, 0, "S ", h, BPICK+2*DPICK+FPICK, h,20, hsv+1, 0.0, 1.0, 10, 2, "");
|
||||||
|
uiButSetFunc(bt, do_palette1_cb, bt, but);
|
||||||
|
bt= uiDefButF(block, NUM, 0, "V ", 2*h, BPICK+2*DPICK+FPICK, h,20, hsv+2, 0.0, 1.0, 10, 2, "");
|
||||||
|
uiButSetFunc(bt, do_palette1_cb, bt, but);
|
||||||
|
|
||||||
|
// safety
|
||||||
|
uiDefBut(block, LABEL, 0, "", -DPICK,-DPICK, FPICK+3*DPICK+BPICK, FPICK+4*DPICK+BPICK+40, NULL, 0.0, 0.0, 0, 0, "");
|
||||||
|
|
||||||
|
/* and lets go */
|
||||||
|
block->direction= UI_TOP;
|
||||||
|
ui_positionblock(block, but);
|
||||||
|
block->win= G.curscreen->mainwin;
|
||||||
|
event= uiDoBlocks(&listb, 0);
|
||||||
|
|
||||||
|
return but->retval;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static int ui_do_but_HSVCUBE(uiBut *but)
|
static int ui_do_but_HSVCUBE(uiBut *but)
|
||||||
{
|
{
|
||||||
uiBut *bt;
|
uiBut *bt;
|
||||||
@@ -2279,10 +2345,13 @@ static int ui_do_but_HSVCUBE(uiBut *but)
|
|||||||
/* assign position to color */
|
/* assign position to color */
|
||||||
ui_get_but_vectorf(but, col);
|
ui_get_but_vectorf(but, col);
|
||||||
rgb_to_hsv(col[0], col[1], col[2], &h, &s, &v);
|
rgb_to_hsv(col[0], col[1], col[2], &h, &s, &v);
|
||||||
|
if(v==0.0) v= 0.001;
|
||||||
|
if(s==0.0) s= 0.001;
|
||||||
|
|
||||||
if(but->a1==0) hsv_to_rgb(x, s, y, col, col+1, col+2);
|
if(but->a1==0) hsv_to_rgb(x, s, y, col, col+1, col+2);
|
||||||
else if(but->a1==1) hsv_to_rgb(x, y, v, col, col+1, col+2);
|
else if(but->a1==1) hsv_to_rgb(x, y, v, col, col+1, col+2);
|
||||||
else hsv_to_rgb(h, y, x, col, col+1, col+2);
|
else if(but->a1==2) hsv_to_rgb(h, y, x, col, col+1, col+2);
|
||||||
|
else hsv_to_rgb(x, s, v, col, col+1, col+2);
|
||||||
|
|
||||||
ui_set_but_vectorf(but, col);
|
ui_set_but_vectorf(but, col);
|
||||||
|
|
||||||
|
|||||||
@@ -1518,13 +1518,20 @@ static void ui_draw_but_HSVCUBE(uiBut *but)
|
|||||||
hsv_to_rgb(0.0, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
|
hsv_to_rgb(0.0, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
|
||||||
x= h; y= s;
|
x= h; y= s;
|
||||||
}
|
}
|
||||||
else { // S and V vary
|
else if(but->a1==2) { // S and V vary
|
||||||
hsv_to_rgb(h, 0.0, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
|
hsv_to_rgb(h, 0.0, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
|
||||||
hsv_to_rgb(h, 0.333, 0.0, &col1[1][0], &col1[1][1], &col1[1][2]);
|
hsv_to_rgb(h, 0.333, 0.0, &col1[1][0], &col1[1][1], &col1[1][2]);
|
||||||
hsv_to_rgb(h, 0.666, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
|
hsv_to_rgb(h, 0.666, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
|
||||||
hsv_to_rgb(h, 1.0, 0.0, &col1[3][0], &col1[3][1], &col1[3][2]);
|
hsv_to_rgb(h, 1.0, 0.0, &col1[3][0], &col1[3][1], &col1[3][2]);
|
||||||
x= v; y= s;
|
x= v; y= s;
|
||||||
}
|
}
|
||||||
|
else { // only hue slider
|
||||||
|
hsv_to_rgb(0.0, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]);
|
||||||
|
VECCOPY(col1[1], col1[0]);
|
||||||
|
VECCOPY(col1[2], col1[0]);
|
||||||
|
VECCOPY(col1[3], col1[0]);
|
||||||
|
x= h; y= 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
for(dx=0.0; dx<1.0; dx+= 0.05) {
|
for(dx=0.0; dx<1.0; dx+= 0.05) {
|
||||||
// previous color
|
// previous color
|
||||||
@@ -1546,12 +1553,18 @@ static void ui_draw_but_HSVCUBE(uiBut *but)
|
|||||||
hsv_to_rgb(dx, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
|
hsv_to_rgb(dx, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
|
||||||
hsv_to_rgb(dx, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
|
hsv_to_rgb(dx, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
|
||||||
}
|
}
|
||||||
else { // S and V vary
|
else if(but->a1==2) { // S and V vary
|
||||||
hsv_to_rgb(h, 0.0, dx, &col1[0][0], &col1[0][1], &col1[0][2]);
|
hsv_to_rgb(h, 0.0, dx, &col1[0][0], &col1[0][1], &col1[0][2]);
|
||||||
hsv_to_rgb(h, 0.333, dx, &col1[1][0], &col1[1][1], &col1[1][2]);
|
hsv_to_rgb(h, 0.333, dx, &col1[1][0], &col1[1][1], &col1[1][2]);
|
||||||
hsv_to_rgb(h, 0.666, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
|
hsv_to_rgb(h, 0.666, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
|
||||||
hsv_to_rgb(h, 1.0, dx, &col1[3][0], &col1[3][1], &col1[3][2]);
|
hsv_to_rgb(h, 1.0, dx, &col1[3][0], &col1[3][1], &col1[3][2]);
|
||||||
}
|
}
|
||||||
|
else { // only H
|
||||||
|
hsv_to_rgb(dx, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]);
|
||||||
|
VECCOPY(col1[1], col1[0]);
|
||||||
|
VECCOPY(col1[2], col1[0]);
|
||||||
|
VECCOPY(col1[3], col1[0]);
|
||||||
|
}
|
||||||
|
|
||||||
// rect
|
// rect
|
||||||
sx1= but->x1 + dx*(but->x2-but->x1);
|
sx1= but->x1 + dx*(but->x2-but->x1);
|
||||||
|
|||||||
Reference in New Issue
Block a user