forked from bartvdbraak/blender
Fix #27213: editing color ramp "Pos:" number value did not update the ramp
properly, when moving the current point before another.
This commit is contained in:
parent
8f01ad9bf8
commit
4aaf59324e
@ -69,9 +69,9 @@ void init_colorband(struct ColorBand *coba, int rangetype);
|
||||
struct ColorBand *add_colorband(int rangetype);
|
||||
int do_colorband(const struct ColorBand *coba, float in, float out[4]);
|
||||
void colorband_table_RGBA(struct ColorBand *coba, float **array, int *size);
|
||||
int vergcband(const void *a1, const void *a2);
|
||||
struct CBData *colorband_element_add(struct ColorBand *coba, float position);
|
||||
int colorband_element_remove(struct ColorBand *coba, int index);
|
||||
void colorband_update_sort(struct ColorBand *coba);
|
||||
|
||||
void default_tex(struct Tex *tex);
|
||||
struct Tex *add_texture(const char *name);
|
||||
|
@ -478,6 +478,26 @@ int vergcband(const void *a1, const void *a2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void colorband_update_sort(ColorBand *coba)
|
||||
{
|
||||
int a;
|
||||
|
||||
if(coba->tot<2)
|
||||
return;
|
||||
|
||||
for(a=0; a<coba->tot; a++)
|
||||
coba->data[a].cur= a;
|
||||
|
||||
qsort(coba->data, coba->tot, sizeof(CBData), vergcband);
|
||||
|
||||
for(a=0; a<coba->tot; a++) {
|
||||
if(coba->data[a].cur==coba->cur) {
|
||||
coba->cur= a;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CBData *colorband_element_add(struct ColorBand *coba, float position)
|
||||
{
|
||||
int a;
|
||||
@ -503,17 +523,7 @@ CBData *colorband_element_add(struct ColorBand *coba, float position)
|
||||
coba->tot++;
|
||||
coba->cur = coba->tot-1;
|
||||
|
||||
for(a = 0; a < coba->tot; a++)
|
||||
coba->data[a].cur = a;
|
||||
|
||||
qsort(coba->data, coba->tot, sizeof(CBData), vergcband);
|
||||
|
||||
for(a = 0; a < coba->tot; a++) {
|
||||
if(coba->data[a].cur == coba->cur) {
|
||||
coba->cur = a;
|
||||
break;
|
||||
}
|
||||
}
|
||||
colorband_update_sort(coba);
|
||||
|
||||
return coba->data + coba->cur;
|
||||
}
|
||||
|
@ -3607,31 +3607,6 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle
|
||||
}
|
||||
|
||||
|
||||
static int verg_colorband(const void *a1, const void *a2)
|
||||
{
|
||||
const CBData *x1=a1, *x2=a2;
|
||||
|
||||
if( x1->pos > x2->pos ) return 1;
|
||||
else if( x1->pos < x2->pos) return -1;
|
||||
return WM_UI_HANDLER_CONTINUE;
|
||||
}
|
||||
|
||||
static void ui_colorband_update(ColorBand *coba)
|
||||
{
|
||||
int a;
|
||||
|
||||
if(coba->tot<2) return;
|
||||
|
||||
for(a=0; a<coba->tot; a++) coba->data[a].cur= a;
|
||||
qsort(coba->data, coba->tot, sizeof(CBData), verg_colorband);
|
||||
for(a=0; a<coba->tot; a++) {
|
||||
if(coba->data[a].cur==coba->cur) {
|
||||
coba->cur= a;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int ui_numedit_but_COLORBAND(uiBut *but, uiHandleButtonData *data, int mx)
|
||||
{
|
||||
float dx;
|
||||
@ -3644,7 +3619,7 @@ static int ui_numedit_but_COLORBAND(uiBut *but, uiHandleButtonData *data, int mx
|
||||
data->dragcbd->pos += dx;
|
||||
CLAMP(data->dragcbd->pos, 0.0f, 1.0f);
|
||||
|
||||
ui_colorband_update(data->coba);
|
||||
colorband_update_sort(data->coba);
|
||||
data->dragcbd= data->coba->data + data->coba->cur; /* because qsort */
|
||||
|
||||
data->draglastx= mx;
|
||||
|
@ -1305,6 +1305,16 @@ static void colorband_flip_cb(bContext *C, void *cb_v, void *coba_v)
|
||||
rna_update_cb(C, cb_v, NULL);
|
||||
}
|
||||
|
||||
static void colorband_update_cb(bContext *UNUSED(C), void *bt_v, void *coba_v)
|
||||
{
|
||||
uiBut *bt= bt_v;
|
||||
ColorBand *coba= coba_v;
|
||||
|
||||
/* sneaky update here, we need to sort the colorband points to be in order,
|
||||
however the RNA pointer then is wrong, so we update it */
|
||||
colorband_update_sort(coba);
|
||||
bt->rnapoin.data = coba->data + coba->cur;
|
||||
}
|
||||
|
||||
/* offset aligns from bottom, standard width 300, height 115 */
|
||||
static void colorband_buttons_large(uiLayout *layout, uiBlock *block, ColorBand *coba, int xoffs, int yoffs, RNAUpdateCb *cb)
|
||||
@ -1348,7 +1358,11 @@ static void colorband_buttons_large(uiLayout *layout, uiBlock *block, ColorBand
|
||||
PointerRNA ptr;
|
||||
RNA_pointer_create(cb->ptr.id.data, &RNA_ColorRampElement, cbd, &ptr);
|
||||
row= uiLayoutRow(layout, 0);
|
||||
|
||||
uiItemR(row, &ptr, "position", 0, "Pos", ICON_NONE);
|
||||
bt= block->buttons.last;
|
||||
uiButSetFunc(bt, colorband_update_cb, bt, coba);
|
||||
|
||||
uiItemR(row, &ptr, "color", 0, "", ICON_NONE);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user