Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_utils.c
| Show First 20 Lines • Show All 1,744 Lines • ▼ Show 20 Lines | static void gpencil_brush_cursor_draw(bContext *C, int x, int y, void *customdata) | ||||
| Material *ma = NULL; | Material *ma = NULL; | ||||
| MaterialGPencilStyle *gp_style = NULL; | MaterialGPencilStyle *gp_style = NULL; | ||||
| float *last_mouse_position = customdata; | float *last_mouse_position = customdata; | ||||
| /* default radius and color */ | /* default radius and color */ | ||||
| float color[3] = {1.0f, 1.0f, 1.0f}; | float color[3] = {1.0f, 1.0f, 1.0f}; | ||||
| float darkcolor[3]; | float darkcolor[3]; | ||||
| float radius = 3.0f; | float radius = 3.0f; | ||||
| bool fixed_radius = true; | |||||
| const int mval_i[2] = {x, y}; | const int mval_i[2] = {x, y}; | ||||
| /* Check if cursor is in drawing region and has valid data-block. */ | /* Check if cursor is in drawing region and has valid data-block. */ | ||||
| if (!gpencil_check_cursor_region(C, mval_i) || (gpd == NULL)) { | if (!gpencil_check_cursor_region(C, mval_i) || (gpd == NULL)) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* for paint use paint brush size and color */ | /* for paint use paint brush size and color */ | ||||
| Show All 21 Lines | if (gpd->flag & GP_DATA_STROKE_PAINTMODE) { | ||||
| } | } | ||||
| /* get current drawing color */ | /* get current drawing color */ | ||||
| ma = BKE_gpencil_object_material_from_brush_get(ob, brush); | ma = BKE_gpencil_object_material_from_brush_get(ob, brush); | ||||
| if (ma) { | if (ma) { | ||||
| gp_style = ma->gp_style; | gp_style = ma->gp_style; | ||||
| /* after some testing, display the size of the brush is not practical because | /* Follow user settings for the size of the draw cursor: | ||||
| * is too disruptive and the size of cursor does not change with zoom factor. | * - Fixed size, or | ||||
| * The decision was to use a fix size, instead of brush->thickness value. | * - Brush size (i.e. stroke thickness) | ||||
| */ | */ | ||||
| if ((gp_style) && GPENCIL_PAINT_MODE(gpd) && | if ((gp_style) && GPENCIL_PAINT_MODE(gpd) && | ||||
| ((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE) == 0) && | ((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE) == 0) && | ||||
| ((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE_TEMP) == 0) && | ((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE_TEMP) == 0) && | ||||
| (brush->gpencil_tool == GPAINT_TOOL_DRAW)) { | (brush->gpencil_tool == GPAINT_TOOL_DRAW)) { | ||||
| /* Check user setting for cursor size. */ | |||||
| fixed_radius = ((brush->gpencil_settings->flag & GP_BRUSH_SHOW_DRAW_SIZE) == 0); | |||||
| if (fixed_radius) { | |||||
| /* Show fixed radius. */ | |||||
| radius = 2.0f; | radius = 2.0f; | ||||
| copy_v3_v3(color, gp_style->stroke_rgba); | copy_v3_v3(color, gp_style->stroke_rgba); | ||||
| } | } | ||||
| else { | else { | ||||
| /* Show brush size. */ | |||||
| tGPspoint point2D; | |||||
| float p1[3]; | |||||
| float p2[3]; | |||||
| float distance; | |||||
| /* Strokes in screen space or world space? */ | |||||
| if ((gpd->flag & GP_DATA_STROKE_KEEPTHICKNESS) != 0) { | |||||
| /* In screen space the cursor radius matches the brush size. */ | |||||
| radius = (float)brush->size * 0.5f; | |||||
| } | |||||
| else { | |||||
| /* To calculate the brush size in world space, we have to establish the zoom level. | |||||
| * For this we take two 2D screen coordinates with a fixed offset, | |||||
| * convert them to 3D coordinates and measure the offset distance in 3D. | |||||
| * A small distance means a high zoom level. */ | |||||
| point2D.m_xy[0] = (float)x; | |||||
| point2D.m_xy[1] = (float)y; | |||||
| gpencil_stroke_convertcoords_tpoint(scene, region, ob, &point2D, NULL, p1); | |||||
| point2D.m_xy[0] = (float)(x + 64); | |||||
| gpencil_stroke_convertcoords_tpoint(scene, region, ob, &point2D, NULL, p2); | |||||
| /* Clip extreme zoom level (and avoid division by zero). */ | |||||
| distance = MAX2(len_v3v3(p1, p2), 0.001f); | |||||
| /* Handle layer thickness change. */ | |||||
| float brush_size = (float)brush->size; | |||||
| bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd); | |||||
| if (gpl != NULL) { | |||||
| brush_size = MAX2(1.0f, brush_size + gpl->line_change); | |||||
| } | |||||
| /* Convert the 3D offset distance to a brush radius. */ | |||||
| radius = (1 / distance) * 2.0f * gpd->pixfactor * (brush_size / 64); | |||||
| } | |||||
| copy_v3_v3(color, brush->rgb); | |||||
| } | |||||
| } | |||||
| else { | |||||
| /* Only Tint tool must show big cursor. */ | /* Only Tint tool must show big cursor. */ | ||||
| if (brush->gpencil_tool == GPAINT_TOOL_TINT) { | if (brush->gpencil_tool == GPAINT_TOOL_TINT) { | ||||
| radius = brush->size; | radius = brush->size; | ||||
| copy_v3_v3(color, brush->rgb); | copy_v3_v3(color, brush->rgb); | ||||
| } | } | ||||
| else { | else { | ||||
| radius = 5.0f; | radius = 5.0f; | ||||
| copy_v3_v3(color, brush->add_col); | copy_v3_v3(color, brush->add_col); | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | static void gpencil_brush_cursor_draw(bContext *C, int x, int y, void *customdata) | ||||
| uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | ||||
| GPU_line_smooth(true); | GPU_line_smooth(true); | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| /* Inner Ring: Color from UI panel */ | /* Inner Ring: Color from UI panel */ | ||||
| immUniformColor4f(color[0], color[1], color[2], 0.8f); | immUniformColor4f(color[0], color[1], color[2], 0.8f); | ||||
| if ((gp_style) && GPENCIL_PAINT_MODE(gpd) && | if ((gp_style) && GPENCIL_PAINT_MODE(gpd) && (fixed_radius) && | ||||
| ((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE) == 0) && | ((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE) == 0) && | ||||
| ((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE_TEMP) == 0) && | ((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE_TEMP) == 0) && | ||||
| (brush->gpencil_tool == GPAINT_TOOL_DRAW)) { | (brush->gpencil_tool == GPAINT_TOOL_DRAW)) { | ||||
| imm_draw_circle_fill_2d(pos, x, y, radius, 40); | imm_draw_circle_fill_2d(pos, x, y, radius, 40); | ||||
| } | } | ||||
| else { | else { | ||||
| imm_draw_circle_wire_2d(pos, x, y, radius, 40); | imm_draw_circle_wire_2d(pos, x, y, radius, 40); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,412 Lines • Show Last 20 Lines | |||||