Histogram and line sample can now be resized vertically

This commit is contained in:
2010-04-04 02:37:22 +00:00
parent f7977ab8cc
commit 5de041c51f
6 changed files with 46 additions and 22 deletions

View File

@@ -694,15 +694,16 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *
int i;
int rgb;
float w, h;
float scaler_x1, scaler_x2;
float alpha;
GLint scissor[4];
if (hist==NULL) { printf("hist is null \n"); return; }
rect.xmin = (float)recti->xmin;
rect.xmax = (float)recti->xmax;
rect.ymin = (float)recti->ymin;
rect.ymax = (float)recti->ymax;
rect.xmin = (float)recti->xmin+1;
rect.xmax = (float)recti->xmax-1;
rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
rect.ymax = (float)recti->ymax-1;
w = rect.xmax - rect.xmin;
h = rect.ymax - rect.ymin;
@@ -763,14 +764,28 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *
glDisable(GL_LINE_SMOOTH);
}
/* restore scissortest */
glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
/* height scaling widget */
scaler_x1 = rect.xmin + w/2 - SCOPE_RESIZE_PAD;
scaler_x2 = rect.xmin + w/2 + SCOPE_RESIZE_PAD;
glColor4f(0.f, 0.f, 0.f, 0.25f);
fdrawline(scaler_x1, rect.ymin-4, scaler_x2, rect.ymin-4);
fdrawline(scaler_x1, rect.ymin-7, scaler_x2, rect.ymin-7);
glColor4f(1.f, 1.f, 1.f, 0.25f);
fdrawline(scaler_x1, rect.ymin-5, scaler_x2, rect.ymin-5);
fdrawline(scaler_x1, rect.ymin-8, scaler_x2, rect.ymin-8);
glColor4f(0.f, 0.f, 0.f, 0.5f);
uiSetRoundBox(15);
gl_round_box(GL_LINE_LOOP, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
gl_round_box(GL_LINE_LOOP, rect.xmin-1, rect.ymin, rect.xmax+1, rect.ymax+1, 3.0f);
glDisable(GL_BLEND);
}

View File

@@ -3460,6 +3460,12 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
return WM_UI_HANDLER_CONTINUE;
}
static int in_histogram_resize_zone(uiBut *but, int x, int y)
{
// bottom corner return (x > but->x2 - SCOPE_RESIZE_PAD) && (y < but->y1 + SCOPE_RESIZE_PAD);
return (y < but->y1 + SCOPE_RESIZE_PAD);
}
static int ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx, int my)
{
Histogram *hist = (Histogram *)but->poin;
@@ -3473,10 +3479,17 @@ static int ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx
dx = mx - data->draglastx;
dy = my - data->draglasty;
yfac = MIN2(powf(hist->ymax, 2.f), 1.f) * 0.5;
hist->ymax += dy * yfac;
CLAMP(hist->ymax, 1.f, 100.f);
if (in_histogram_resize_zone(but, data->dragstartx, data->dragstarty)) {
/* resize histogram widget itself */
hist->height = (but->y2 - but->y1) + (data->dragstarty - my);
} else {
/* scale histogram values */
yfac = MIN2(powf(hist->ymax, 2.f), 1.f) * 0.5;
hist->ymax += dy * yfac;
CLAMP(hist->ymax, 1.f, 100.f);
}
data->draglastx= mx;
data->draglasty= my;
@@ -4432,7 +4445,7 @@ static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState s
but->flag |= UI_SELECT;
button_timers_tooltip_remove(C, but);
}
/* text editing */
if(state == BUTTON_STATE_TEXT_EDITING && data->state != BUTTON_STATE_TEXT_SELECTING)
ui_textedit_begin(C, but, data);

View File

@@ -127,6 +127,9 @@ typedef enum {
#define EXTEND_LEFT 1
#define EXTEND_RIGHT 2
/* for scope resize zone */
#define SCOPE_RESIZE_PAD 9
typedef struct {
short xim, yim;
unsigned int *rect;

View File

@@ -1589,7 +1589,9 @@ void uiTemplateHistogram(uiLayout *layout, PointerRNA *ptr, char *propname, int
hist = (Histogram *)cptr.data;
bt= uiDefBut(block, HISTOGRAM, 0, "", rect.xmin, rect.ymin, rect.xmax-rect.xmin, 100.0f, hist, 0, 0, 0, 0, "");
hist->height= (hist->height==0)?100:hist->height;
bt= uiDefBut(block, HISTOGRAM, 0, "", rect.xmin, rect.ymin, rect.xmax-rect.xmin, hist->height, hist, 0, 0, 0, 0, "");
uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
MEM_freeN(cb);