/* Brush operators */ static int brush_add_exec(bContext *C, wmOperator *UNUSED(op)) { /*int type = RNA_enum_get(op->ptr, "type");*/ Paint *paint = paint_get_active(CTX_data_scene(C)); struct Brush *br = paint_brush(paint); if (br) br = copy_brush(br); else br = add_brush("Brush"); paint_brush_set(paint_get_active(CTX_data_scene(C)), br); return OPERATOR_FINISHED; }
static int brush_curve_preset_exec(bContext *C, wmOperator *op) { Brush *br = paint_brush(paint_get_active(CTX_data_scene(C))); brush_curve_preset(br, RNA_enum_get(op->ptr, "shape")); return OPERATOR_FINISHED; }
static int buttons_context_path_brush(ButsContextPath *path) { Scene *scene; Brush *br= NULL; PointerRNA *ptr= &path->ptr[path->len-1]; /* if we already have a (pinned) brush, we're done */ if(RNA_struct_is_a(ptr->type, &RNA_Brush)) { return 1; } /* if we have a scene, use the toolsettings brushes */ else if(buttons_context_path_scene(path)) { scene= path->ptr[path->len-1].data; if(scene) br= paint_brush(paint_get_active(scene)); if(br) { RNA_id_pointer_create((ID *)br, &path->ptr[path->len]); path->len++; return 1; } } /* no path to a brush possible */ return 0; }
/*** Cursor ***/ static void paint_draw_smooth_stroke(bContext *C, int x, int y, void *customdata) { Brush *brush = paint_brush(paint_get_active(CTX_data_scene(C))); PaintStroke *stroke = customdata; glColor4ubv(paint_get_active(CTX_data_scene(C))->paint_cursor_col); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); if(stroke && brush && (brush->flag & BRUSH_SMOOTH_STROKE)) { ARegion *ar = CTX_wm_region(C); sdrawline(x, y, (int)stroke->last_mouse_position[0] - ar->winrct.xmin, (int)stroke->last_mouse_position[1] - ar->winrct.ymin); } glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); }
static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op)) { Paint *paint = paint_get_active(CTX_data_scene(C)); struct Brush *brush = paint_brush(paint); Object *ob = CTX_data_active_object(C); if(!ob) return OPERATOR_CANCELLED; if(ob->mode & OB_MODE_SCULPT) brush_reset_sculpt(brush); /* TODO: other modes */ return OPERATOR_FINISHED; }
/* used for both 3d view and image window */ void paint_sample_color(Scene *scene, ARegion *ar, int x, int y) /* frontbuf */ { Brush *br = paint_brush(paint_get_active(scene)); unsigned int col; char *cp; CLAMP(x, 0, ar->winx); CLAMP(y, 0, ar->winy); glReadBuffer(GL_FRONT); glReadPixels(x+ar->winrct.xmin, y+ar->winrct.ymin, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col); glReadBuffer(GL_BACK); cp = (char *)&col; if(br) { br->rgb[0]= cp[0]/255.0f; br->rgb[1]= cp[1]/255.0f; br->rgb[2]= cp[2]/255.0f; } }
static int brush_scale_size_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Paint *paint= paint_get_active(scene); struct Brush *brush= paint_brush(paint); // Object *ob= CTX_data_active_object(C); float scalar= RNA_float_get(op->ptr, "scalar"); if (brush) { // pixel radius { const int old_size= brush_size(scene, brush); int size= (int)(scalar*old_size); if (old_size == size) { if (scalar > 1) { size++; } else if (scalar < 1) { size--; } } CLAMP(size, 1, 2000); // XXX magic number brush_set_size(scene, brush, size); } // unprojected radius { float unprojected_radius= scalar*brush_unprojected_radius(scene, brush); if (unprojected_radius < 0.001f) // XXX magic number unprojected_radius= 0.001f; brush_set_unprojected_radius(scene, brush, unprojected_radius); } } return OPERATOR_FINISHED; }
static int brush_curve_preset_poll(bContext *C) { Brush *br = paint_brush(paint_get_active(CTX_data_scene(C))); return br && br->curve; }
static void buttons_texture_users_from_context(ListBase *users, const bContext *C, SpaceButs *sbuts) { Scene *scene= NULL; Object *ob= NULL; Material *ma= NULL; Lamp *la= NULL; World *wrld= NULL; Brush *brush= NULL; ID *pinid = sbuts->pinid; /* get data from context */ if(pinid) { if(GS(pinid->name) == ID_SCE) scene= (Scene*)pinid; else if(GS(pinid->name) == ID_OB) ob= (Object*)pinid; else if(GS(pinid->name) == ID_LA) la= (Lamp*)pinid; else if(GS(pinid->name) == ID_WO) wrld= (World*)pinid; else if(GS(pinid->name) == ID_MA) ma= (Material*)pinid; else if(GS(pinid->name) == ID_BR) brush= (Brush*)pinid; } if(!scene) scene= CTX_data_scene(C); if(!(pinid || pinid == &scene->id)) { ob= (scene->basact)? scene->basact->object: NULL; wrld= scene->world; brush= paint_brush(paint_get_active(scene)); } if(ob && ob->type == OB_LAMP && !la) la= ob->data; if(ob && !ma) ma= give_current_material(ob, ob->actcol); /* fill users */ users->first = users->last = NULL; if(ma) buttons_texture_users_find_nodetree(users, &ma->id, ma->nodetree, "Material"); if(la) buttons_texture_users_find_nodetree(users, &la->id, la->nodetree, "Lamp"); if(wrld) buttons_texture_users_find_nodetree(users, &wrld->id, wrld->nodetree, "World"); if(ob) { ParticleSystem *psys= psys_get_current(ob); MTex *mtex; int a; /* modifiers */ modifiers_foreachTexLink(ob, buttons_texture_modifier_foreach, users); /* particle systems */ if(psys) { /* todo: these slots are not in the UI */ for(a=0; a<MAX_MTEX; a++) { mtex = psys->part->mtex[a]; if(mtex) { PointerRNA ptr; PropertyRNA *prop; RNA_pointer_create(&psys->part->id, &RNA_ParticleSettingsTextureSlot, mtex, &ptr); prop = RNA_struct_find_property(&ptr, "texture"); buttons_texture_user_property_add(users, &psys->part->id, ptr, prop, "Particles", RNA_struct_ui_icon(&RNA_ParticleSettings), psys->name); } } } /* field */ if(ob->pd && ob->pd->forcefield == PFIELD_TEXTURE) { PointerRNA ptr; PropertyRNA *prop; RNA_pointer_create(&ob->id, &RNA_FieldSettings, ob->pd, &ptr); prop = RNA_struct_find_property(&ptr, "texture"); buttons_texture_user_property_add(users, &ob->id, ptr, prop, "Fields", ICON_FORCE_TEXTURE, "Texture Field"); } } /* brush */ if(brush) { PointerRNA ptr; PropertyRNA *prop; RNA_pointer_create(&brush->id, &RNA_BrushTextureSlot, &brush->mtex, &ptr); prop= RNA_struct_find_property(&ptr, "texture"); buttons_texture_user_property_add(users, &brush->id, ptr, prop, "Brush", ICON_BRUSH_DATA, brush->id.name+2); } }