PointDensity *BKE_add_pointdensity(void) { PointDensity *pd; pd = MEM_callocN(sizeof(PointDensity), "pointdensity"); pd->flag = 0; pd->radius = 0.3f; pd->falloff_type = TEX_PD_FALLOFF_STD; pd->falloff_softness = 2.0; pd->source = TEX_PD_PSYS; pd->point_tree = NULL; pd->point_data = NULL; pd->noise_size = 0.5f; pd->noise_depth = 1; pd->noise_fac = 1.0f; pd->noise_influence = TEX_PD_NOISE_STATIC; pd->coba = add_colorband(true); pd->speed_scale = 1.0f; pd->totpoints = 0; pd->object = NULL; pd->psys = 0; pd->psys_cache_space = TEX_PD_WORLDSPACE; pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1); pd->falloff_curve->preset = CURVE_PRESET_LINE; pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE; curvemap_reset(pd->falloff_curve->cm, &pd->falloff_curve->clipr, pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE); curvemapping_changed(pd->falloff_curve, FALSE); return pd; }
static PyObject *Freestyle_evaluateCurveMappingF(PyObject *self, PyObject *args) { BPy_StructRNA *py_srna; CurveMapping *cumap; int cur; float value; if (!(PyArg_ParseTuple(args, "O!if", &pyrna_struct_Type, &py_srna, &cur, &value))) return NULL; if (!RNA_struct_is_a(py_srna->ptr.type, &RNA_CurveMapping)) { PyErr_SetString(PyExc_TypeError, "1st argument is not a CurveMapping object"); return NULL; } if (cur < 0 || cur > 3) { PyErr_SetString(PyExc_ValueError, "2nd argument is out of range"); return NULL; } cumap = (CurveMapping *)py_srna->ptr.data; curvemapping_initialize(cumap); /* disable extrapolation if enabled */ if ((cumap->cm[cur].flag & CUMA_EXTEND_EXTRAPOLATE)) { cumap->cm[cur].flag &= ~(CUMA_EXTEND_EXTRAPOLATE); curvemapping_changed(cumap, 0); } return PyFloat_FromDouble(curvemapping_evaluateF(cumap, cur, value)); }
static void rna_CurveMapping_clip_set(PointerRNA *ptr, int value) { CurveMapping *cumap = (CurveMapping *)ptr->data; if (value) cumap->flag |= CUMA_DO_CLIP; else cumap->flag &= ~CUMA_DO_CLIP; curvemapping_changed(cumap, false); }
void curvemapping_changed_all(CurveMapping *cumap) { int a, cur = cumap->cur; for (a = 0; a < CM_TOT; a++) { if (cumap->cm[a].curve) { cumap->cur = a; curvemapping_changed(cumap, FALSE); } } cumap->cur = cur; }
/** * Library Operations * \param preset CurveMappingPreset */ void BKE_brush_curve_preset(Brush *b, int preset) { CurveMap *cm = NULL; if (!b->curve) b->curve = curvemapping_add(1, 0, 0, 1, 1); cm = b->curve->cm; cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE; b->curve->preset = preset; curvemap_reset(cm, &b->curve->clipr, b->curve->preset, CURVEMAP_SLOPE_NEGATIVE); curvemapping_changed(b->curve, false); }
void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect) { CurveMapping *cumap; CurveMap *cuma; CurveMapPoint *cmp; float fx, fy, fac[2], zoomx, zoomy, offsx, offsy; GLint scissor[4]; rcti scissor_new; int a; if (but->editcumap) { cumap = but->editcumap; } else { cumap = (CurveMapping *)but->poin; } cuma = &cumap->cm[cumap->cur]; /* need scissor test, curve can draw outside of boundary */ glGetIntegerv(GL_VIEWPORT, scissor); scissor_new.xmin = ar->winrct.xmin + rect->xmin; scissor_new.ymin = ar->winrct.ymin + rect->ymin; scissor_new.xmax = ar->winrct.xmin + rect->xmax; scissor_new.ymax = ar->winrct.ymin + rect->ymax; BLI_rcti_isect(&scissor_new, &ar->winrct, &scissor_new); glScissor(scissor_new.xmin, scissor_new.ymin, BLI_rcti_size_x(&scissor_new), BLI_rcti_size_y(&scissor_new)); /* calculate offset and zoom */ zoomx = (BLI_rcti_size_x(rect) - 2.0f * but->aspect) / BLI_rctf_size_x(&cumap->curr); zoomy = (BLI_rcti_size_y(rect) - 2.0f * but->aspect) / BLI_rctf_size_y(&cumap->curr); offsx = cumap->curr.xmin - but->aspect / zoomx; offsy = cumap->curr.ymin - but->aspect / zoomy; /* backdrop */ if (but->a1 == UI_GRAD_H) { /* magic trigger for curve backgrounds */ rcti grid; float col[3] = {0.0f, 0.0f, 0.0f}; /* dummy arg */ grid.xmin = rect->xmin + zoomx * (-offsx); grid.xmax = rect->xmax + zoomx * (-offsx); grid.ymin = rect->ymin + zoomy * (-offsy); grid.ymax = rect->ymax + zoomy * (-offsy); ui_draw_gradient(&grid, col, UI_GRAD_H, 1.0f); /* grid, hsv uses different grid */ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ub(0, 0, 0, 48); ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.1666666f); glDisable(GL_BLEND); } else { if (cumap->flag & CUMA_DO_CLIP) { gl_shaded_color((unsigned char *)wcol->inner, -20); glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); glColor3ubv((unsigned char *)wcol->inner); glRectf(rect->xmin + zoomx * (cumap->clipr.xmin - offsx), rect->ymin + zoomy * (cumap->clipr.ymin - offsy), rect->xmin + zoomx * (cumap->clipr.xmax - offsx), rect->ymin + zoomy * (cumap->clipr.ymax - offsy)); } else { glColor3ubv((unsigned char *)wcol->inner); glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); } /* grid, every 0.25 step */ gl_shaded_color((unsigned char *)wcol->inner, -16); ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.25f); /* grid, every 1.0 step */ gl_shaded_color((unsigned char *)wcol->inner, -24); ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 1.0f); /* axes */ gl_shaded_color((unsigned char *)wcol->inner, -50); glBegin(GL_LINES); glVertex2f(rect->xmin, rect->ymin + zoomy * (-offsy)); glVertex2f(rect->xmax, rect->ymin + zoomy * (-offsy)); glVertex2f(rect->xmin + zoomx * (-offsx), rect->ymin); glVertex2f(rect->xmin + zoomx * (-offsx), rect->ymax); glEnd(); } /* cfra option */ /* XXX 2.48 */ #if 0 if (cumap->flag & CUMA_DRAW_CFRA) { glColor3ub(0x60, 0xc0, 0x40); glBegin(GL_LINES); glVertex2f(rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymin); glVertex2f(rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymax); glEnd(); } #endif /* sample option */ if (cumap->flag & CUMA_DRAW_SAMPLE) { if (but->a1 == UI_GRAD_H) { float tsample[3]; float hsv[3]; linearrgb_to_srgb_v3_v3(tsample, cumap->sample); rgb_to_hsv_v(tsample, hsv); glColor3ub(240, 240, 240); glBegin(GL_LINES); glVertex2f(rect->xmin + zoomx * (hsv[0] - offsx), rect->ymin); glVertex2f(rect->xmin + zoomx * (hsv[0] - offsx), rect->ymax); glEnd(); } else if (cumap->cur == 3) { float lum = rgb_to_bw(cumap->sample); glColor3ub(240, 240, 240); glBegin(GL_LINES); glVertex2f(rect->xmin + zoomx * (lum - offsx), rect->ymin); glVertex2f(rect->xmin + zoomx * (lum - offsx), rect->ymax); glEnd(); } else { if (cumap->cur == 0) glColor3ub(240, 100, 100); else if (cumap->cur == 1) glColor3ub(100, 240, 100); else glColor3ub(100, 100, 240); glBegin(GL_LINES); glVertex2f(rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymin); glVertex2f(rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymax); glEnd(); } } /* the curve */ glColor3ubv((unsigned char *)wcol->item); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBegin(GL_LINE_STRIP); if (cuma->table == NULL) curvemapping_changed(cumap, FALSE); cmp = cuma->table; /* first point */ if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) { glVertex2f(rect->xmin, rect->ymin + zoomy * (cmp[0].y - offsy)); } else { fx = rect->xmin + zoomx * (cmp[0].x - offsx + cuma->ext_in[0]); fy = rect->ymin + zoomy * (cmp[0].y - offsy + cuma->ext_in[1]); glVertex2f(fx, fy); } for (a = 0; a <= CM_TABLE; a++) { fx = rect->xmin + zoomx * (cmp[a].x - offsx); fy = rect->ymin + zoomy * (cmp[a].y - offsy); glVertex2f(fx, fy); } /* last point */ if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) { glVertex2f(rect->xmax, rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy)); } else { fx = rect->xmin + zoomx * (cmp[CM_TABLE].x - offsx - cuma->ext_out[0]); fy = rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy - cuma->ext_out[1]); glVertex2f(fx, fy); } glEnd(); glDisable(GL_LINE_SMOOTH); glDisable(GL_BLEND); /* the points, use aspect to make them visible on edges */ cmp = cuma->curve; glPointSize(3.0f); bglBegin(GL_POINTS); for (a = 0; a < cuma->totpoint; a++) { if (cmp[a].flag & CUMA_SELECT) UI_ThemeColor(TH_TEXT_HI); else UI_ThemeColor(TH_TEXT); fac[0] = rect->xmin + zoomx * (cmp[a].x - offsx); fac[1] = rect->ymin + zoomy * (cmp[a].y - offsy); bglVertex2fv(fac); } bglEnd(); glPointSize(1.0f); /* restore scissortest */ glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); /* outline */ glColor3ubv((unsigned char *)wcol->outline); fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax); }
void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect) { CurveMapping *cumap; CurveMap *cuma; CurveMapPoint *cmp; float fx, fy, fac[2], zoomx, zoomy, offsx, offsy; GLint scissor[4]; rcti scissor_new; int a; cumap= (CurveMapping *)(but->editcumap? but->editcumap: but->poin); cuma= cumap->cm+cumap->cur; /* need scissor test, curve can draw outside of boundary */ glGetIntegerv(GL_VIEWPORT, scissor); scissor_new.xmin= ar->winrct.xmin + rect->xmin; scissor_new.ymin= ar->winrct.ymin + rect->ymin; scissor_new.xmax= ar->winrct.xmin + rect->xmax; scissor_new.ymax= ar->winrct.ymin + rect->ymax; BLI_isect_rcti(&scissor_new, &ar->winrct, &scissor_new); glScissor(scissor_new.xmin, scissor_new.ymin, scissor_new.xmax-scissor_new.xmin, scissor_new.ymax-scissor_new.ymin); /* calculate offset and zoom */ zoomx= (rect->xmax-rect->xmin-2.0f*but->aspect)/(cumap->curr.xmax - cumap->curr.xmin); zoomy= (rect->ymax-rect->ymin-2.0f*but->aspect)/(cumap->curr.ymax - cumap->curr.ymin); offsx= cumap->curr.xmin-but->aspect/zoomx; offsy= cumap->curr.ymin-but->aspect/zoomy; /* backdrop */ if(cumap->flag & CUMA_DO_CLIP) { glColor3ubvShade((unsigned char *)wcol->inner, -20); glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); glColor3ubv((unsigned char*)wcol->inner); glRectf(rect->xmin + zoomx*(cumap->clipr.xmin-offsx), rect->ymin + zoomy*(cumap->clipr.ymin-offsy), rect->xmin + zoomx*(cumap->clipr.xmax-offsx), rect->ymin + zoomy*(cumap->clipr.ymax-offsy)); } else { glColor3ubv((unsigned char*)wcol->inner); glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); } /* grid, every .25 step */ glColor3ubvShade((unsigned char *)wcol->inner, -16); ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.25f); /* grid, every 1.0 step */ glColor3ubvShade((unsigned char *)wcol->inner, -24); ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 1.0f); /* axes */ glColor3ubvShade((unsigned char *)wcol->inner, -50); glBegin(GL_LINES); glVertex2f(rect->xmin, rect->ymin + zoomy*(-offsy)); glVertex2f(rect->xmax, rect->ymin + zoomy*(-offsy)); glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymin); glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymax); glEnd(); /* magic trigger for curve backgrounds */ if (but->a1 != -1) { if (but->a1 == UI_GRAD_H) { rcti grid; float col[3]= {0.0f, 0.0f, 0.0f}; /* dummy arg */ grid.xmin = rect->xmin + zoomx*(-offsx); grid.xmax = rect->xmax + zoomx*(-offsx); grid.ymin = rect->ymin + zoomy*(-offsy); grid.ymax = rect->ymax + zoomy*(-offsy); glEnable(GL_BLEND); ui_draw_gradient(&grid, col, UI_GRAD_H, 0.5f); glDisable(GL_BLEND); } } /* cfra option */ /* XXX 2.48 if(cumap->flag & CUMA_DRAW_CFRA) { glColor3ub(0x60, 0xc0, 0x40); glBegin(GL_LINES); glVertex2f(rect->xmin + zoomx*(cumap->sample[0]-offsx), rect->ymin); glVertex2f(rect->xmin + zoomx*(cumap->sample[0]-offsx), rect->ymax); glEnd(); }*/ /* sample option */ /* XXX 2.48 * if(cumap->flag & CUMA_DRAW_SAMPLE) { if(cumap->cur==3) { float lum= cumap->sample[0]*0.35f + cumap->sample[1]*0.45f + cumap->sample[2]*0.2f; glColor3ub(240, 240, 240); glBegin(GL_LINES); glVertex2f(rect->xmin + zoomx*(lum-offsx), rect->ymin); glVertex2f(rect->xmin + zoomx*(lum-offsx), rect->ymax); glEnd(); } else { if(cumap->cur==0) glColor3ub(240, 100, 100); else if(cumap->cur==1) glColor3ub(100, 240, 100); else glColor3ub(100, 100, 240); glBegin(GL_LINES); glVertex2f(rect->xmin + zoomx*(cumap->sample[cumap->cur]-offsx), rect->ymin); glVertex2f(rect->xmin + zoomx*(cumap->sample[cumap->cur]-offsx), rect->ymax); glEnd(); } }*/ /* the curve */ glColor3ubv((unsigned char*)wcol->item); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBegin(GL_LINE_STRIP); if(cuma->table==NULL) curvemapping_changed(cumap, 0); /* 0 = no remove doubles */ cmp= cuma->table; /* first point */ if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0) glVertex2f(rect->xmin, rect->ymin + zoomy*(cmp[0].y-offsy)); else { fx= rect->xmin + zoomx*(cmp[0].x-offsx + cuma->ext_in[0]); fy= rect->ymin + zoomy*(cmp[0].y-offsy + cuma->ext_in[1]); glVertex2f(fx, fy); } for(a=0; a<=CM_TABLE; a++) { fx= rect->xmin + zoomx*(cmp[a].x-offsx); fy= rect->ymin + zoomy*(cmp[a].y-offsy); glVertex2f(fx, fy); } /* last point */ if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0) glVertex2f(rect->xmax, rect->ymin + zoomy*(cmp[CM_TABLE].y-offsy)); else { fx= rect->xmin + zoomx*(cmp[CM_TABLE].x-offsx - cuma->ext_out[0]); fy= rect->ymin + zoomy*(cmp[CM_TABLE].y-offsy - cuma->ext_out[1]); glVertex2f(fx, fy); } glEnd(); glDisable(GL_LINE_SMOOTH); glDisable(GL_BLEND); /* the points, use aspect to make them visible on edges */ cmp= cuma->curve; glPointSize(3.0f); bglBegin(GL_POINTS); for(a=0; a<cuma->totpoint; a++) { if(cmp[a].flag & SELECT) UI_ThemeColor(TH_TEXT_HI); else UI_ThemeColor(TH_TEXT); fac[0]= rect->xmin + zoomx*(cmp[a].x-offsx); fac[1]= rect->ymin + zoomy*(cmp[a].y-offsy); bglVertex2fv(fac); } bglEnd(); glPointSize(1.0f); /* restore scissortest */ glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); /* outline */ glColor3ubv((unsigned char*)wcol->outline); fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax); }