Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_ruler.c
| Context not available. | |||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_gpencil_types.h" | #include "DNA_gpencil_types.h" | ||||
| #include "DNA_brush_types.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| Context not available. | |||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_main.h" | |||||
| #include "BKE_unit.h" | #include "BKE_unit.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_material.h" | |||||
| #include "BIF_gl.h" | #include "BIF_gl.h" | ||||
| Context not available. | |||||
| static bool view3d_ruler_to_gpencil(bContext *C, RulerInfo *ruler_info) | static bool view3d_ruler_to_gpencil(bContext *C, RulerInfo *ruler_info) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Main *bmain = CTX_data_main(C); | |||||
| Object *ob = CTX_data_active_object(C); | |||||
| bGPDlayer *gpl; | bGPDlayer *gpl; | ||||
| bGPDframe *gpf; | bGPDframe *gpf; | ||||
| bGPDstroke *gps; | bGPDstroke *gps; | ||||
| bGPDpalette *palette; | |||||
| bGPDpalettecolor *palcolor; | |||||
| RulerItem *ruler_item; | RulerItem *ruler_item; | ||||
| const char *ruler_name = RULER_ID; | const char *ruler_name = RULER_ID; | ||||
| bool changed = false; | bool changed = false; | ||||
| /* FIXME: This needs to be reviewed. Should it keep being done like this? */ | |||||
| if (scene->gpd == NULL) { | if (scene->gpd == NULL) { | ||||
| scene->gpd = BKE_gpencil_data_addnew("GPencil"); | scene->gpd = BKE_gpencil_data_addnew(bmain, "Ruler GPencil"); | ||||
| } | } | ||||
| gpl = BLI_findstring(&scene->gpd->layers, ruler_name, offsetof(bGPDlayer, info)); | gpl = BLI_findstring(&scene->gpd->layers, ruler_name, offsetof(bGPDlayer, info)); | ||||
| Context not available. | |||||
| gpl->flag |= GP_LAYER_HIDE; | gpl->flag |= GP_LAYER_HIDE; | ||||
| } | } | ||||
| /* try to get active palette or create a new one */ | /* try to get active color or create a new one */ | ||||
| palette = BKE_gpencil_palette_getactive(scene->gpd); | Material *mat = BKE_gpencil_color_ensure(bmain, ob); | ||||
| if (palette == NULL) { | |||||
| palette = BKE_gpencil_palette_addnew(scene->gpd, DATA_("GP_Palette"), true); | |||||
| } | |||||
| /* try to get color with the ruler name or create a new one */ | |||||
| palcolor = BKE_gpencil_palettecolor_getbyname(palette, (char *)ruler_name); | |||||
| if (palcolor == NULL) { | |||||
| palcolor = BKE_gpencil_palettecolor_addnew(palette, (char *)ruler_name, true); | |||||
| } | |||||
| gpf = BKE_gpencil_layer_getframe(gpl, CFRA, true); | gpf = BKE_gpencil_layer_getframe(gpl, CFRA, true); | ||||
| BKE_gpencil_free_strokes(gpf); | BKE_gpencil_free_strokes(gpf); | ||||
| Context not available. | |||||
| gps->flag = GP_STROKE_3DSPACE; | gps->flag = GP_STROKE_3DSPACE; | ||||
| gps->thickness = 3; | gps->thickness = 3; | ||||
| /* assign color to stroke */ | /* assign color to stroke */ | ||||
| BLI_strncpy(gps->colorname, palcolor->info, sizeof(gps->colorname)); | gps->mat_nr = BKE_object_material_slot_find_index(ob, mat) - 1; | ||||
| gps->palcolor = palcolor; | |||||
| BLI_addtail(&gpf->strokes, gps); | BLI_addtail(&gpf->strokes, gps); | ||||
| changed = true; | changed = true; | ||||
| } | } | ||||
| Context not available. | |||||