64 #define USE_AXIS_CONSTRAINTS
68 #define MVAL_MAX_PX_DIST 12.0f
81 #define RULER_PICK_DIST 12.0f
82 #define RULER_PICK_DIST_SQ (RULER_PICK_DIST * RULER_PICK_DIST)
85 #define PART_LINE 0xff
95 #ifdef USE_AXIS_CONSTRAINTS
123 #ifdef USE_AXIS_CONSTRAINTS
135 #ifndef USE_SNAP_DETECT_FROM_KEYMAP_HACK
194 ruler_item->
co[0], ruler_item->
co[1], ruler_item->
co[2]);
201 numstr, numstr_size, (
double)ruler_angle, prec,
B_UNIT_ROTATION, unit,
false);
205 const float ruler_len =
len_v3v3(ruler_item->
co[0], ruler_item->
co[2]);
208 BLI_snprintf(numstr, numstr_size,
"%.*f", prec, ruler_len);
232 int co_index_best = -1;
240 for (j = 0; j < 3; j++) {
247 if (dist < dist_best) {
252 const float dist_points[3] = {
268 if (dist < dist_best) {
273 const float dist_points[2] = {
278 co_index_best = (dist_points[0] < dist_points[1]) ? 0 : 2;
288 *r_co_index = co_index_best;
328 const bool do_thickness
336 const float eps_bias = 0.0002f;
345 if (do_thickness && inter->
co_index != 1) {
349 const float mval_fl[2] = {
UNPACK2(mval)};
354 co_other = ruler_item->
co[inter->
co_index == 0 ? 2 : 0];
362 .snap_target_select = SCE_SNAP_TARGET_ALL,
363 .edit_mode_type = SNAP_GEOM_CAGE,
389 #ifndef USE_SNAP_DETECT_FROM_KEYMAP_HACK
394 float *prev_point =
NULL;
398 prev_point = ruler_item->
co[1];
401 prev_point = ruler_item->
co[2];
404 prev_point = ruler_item->
co[0];
407 if (prev_point !=
NULL) {
416 #ifdef USE_AXIS_CONSTRAINTS
437 scene, view_layer, v3d, rv3d, ob, obedit, orient_index, pivot_point, mat);
444 for (
int i = 0; i <= 2; i++) {
498 #define RULER_ID "RulerData3D"
511 bool changed =
false;
539 for (j = 0; j < 3; j++) {
549 for (j = 0; j < 3; j += 2) {
573 bool changed =
false;
589 for (j = 0; j < 3; j++) {
598 for (j = 0; j < 3; j += 2) {
626 const float cap_size = 4.0f *
U.dpi_fac;
627 const float bg_margin = 4.0f *
U.dpi_fac;
628 const float arc_size = 64.0f *
U.dpi_fac;
631 const float color_act[4] = {1.0f, 1.0f, 1.0f, 1.0f};
632 const float color_base[4] = {0.0f, 0.0f, 0.0f, 1.0f};
635 float color_back[4] = {1.0f, 1.0f, 1.0f, 0.5f};
655 if ((
int)color_text[0] + (
int)color_text[1] + (
int)color_text[2] > 127 * 3 * 0.6f) {
659 const bool is_act = (ruler_info->
item_active == ruler_item);
666 for (j = 0; j < 3; j++) {
687 float viewport_size[4];
689 immUniform2f(
"viewport_size", viewport_size[2], viewport_size[3]);
692 const float *
col = is_act ? color_act : color_base;
722 len_v2v2(co_ss[0], co_ss[1]) / 2.0f,
723 len_v2v2(co_ss[2], co_ss[1]) / 2.0f));
741 for (j = 0; j <= arc_steps; j++) {
756 float viewport_size[4];
758 immUniform2f(
"viewport_size", viewport_size[2], viewport_size[3]);
761 const float *
col = is_act ? color_act : color_base;
789 float rot_90_vec_a[2];
790 float rot_90_vec_b[2];
794 rot_90_vec_a[0] = -dir_ruler[1];
795 rot_90_vec_a[1] = dir_ruler[0];
799 rot_90_vec_b[0] = -dir_ruler[1];
800 rot_90_vec_b[1] = dir_ruler[0];
810 immVertex2f(shdr_pos_2d, co_ss[1][0] - cap_size, co_ss[1][1] - cap_size);
811 immVertex2f(shdr_pos_2d, co_ss[1][0] + cap_size, co_ss[1][1] + cap_size);
812 immVertex2f(shdr_pos_2d, co_ss[1][0] - cap_size, co_ss[1][1] + cap_size);
813 immVertex2f(shdr_pos_2d, co_ss[1][0] + cap_size, co_ss[1][1] - cap_size);
821 if (proj_ok[0] || proj_ok[2] || proj_ok[1]) {
840 immVertex2f(shdr_pos_2d, co_ss[1][0] - cap_size, co_ss[1][1] - cap_size);
841 immVertex2f(shdr_pos_2d, co_ss[1][0] + cap_size, co_ss[1][1] + cap_size);
842 immVertex2f(shdr_pos_2d, co_ss[1][0] - cap_size, co_ss[1][1] + cap_size);
843 immVertex2f(shdr_pos_2d, co_ss[1][0] + cap_size, co_ss[1][1] - cap_size);
854 float numstr_size[2];
862 posit[0] = co_ss[1][0] + (cap_size * 2.0f);
863 posit[1] = co_ss[1][1] - (numstr_size[1] / 2.0f);
870 posit[0] - bg_margin,
871 posit[1] - bg_margin,
872 posit[0] + bg_margin + numstr_size[0],
873 posit[1] + bg_margin + numstr_size[1]);
894 float rot_90_vec[2] = {-dir_ruler[1], dir_ruler[0]};
903 if (proj_ok[0] || proj_ok[2]) {
928 float numstr_size[2];
939 posit[0] -= numstr_size[0] / 2.0f;
940 posit[1] -= numstr_size[1] / 2.0f;
943 if (proj_ok[0] && proj_ok[2]) {
947 posit[0] - bg_margin,
948 posit[1] - bg_margin,
949 posit[0] + bg_margin + numstr_size[0],
950 posit[1] + bg_margin + numstr_size[1]);
957 if (proj_ok[0] && proj_ok[2]) {
977 const float mval_fl[2] = {
UNPACK2(mval)};
982 if (co_index == -1) {
999 bool do_draw =
false;
1006 ruler_info->
region = region;
1008 #ifdef USE_AXIS_CONSTRAINTS
1033 do_cursor_update =
true;
1037 #ifndef USE_SNAP_DETECT_FROM_KEYMAP_HACK
1042 do_cursor_update =
true;
1045 if (do_cursor_update) {
1085 #ifdef USE_AXIS_CONSTRAINTS
1109 CLAMP(fac, 0.0f, 1.0f);
1112 ruler_item_pick->
co[1], ruler_item_pick->
co[0], ruler_item_pick->
co[2], fac);
1149 prev_point = (inter->
co_index != 1) ? ruler_item_pick->
co[1] :
NULL;
1152 prev_point = ruler_item_pick->
co[2];
1155 prev_point = ruler_item_pick->
co[0];
1202 gzt->
idname =
"VIEW3D_GT_ruler_item";
1249 ruler_info->
wm = wm;
1250 ruler_info->
win = win;
1252 ruler_info->
region = region;
1261 gzgt->
name =
"Ruler Widgets";
1358 ot->
idname =
"VIEW3D_OT_ruler_add";
1414 ot->
name =
"Ruler Remove";
1415 ot->
idname =
"VIEW3D_OT_ruler_remove";
struct ScrArea * CTX_wm_area(const bContext *C)
struct Scene * CTX_data_scene(const bContext *C)
struct wmWindowManager * CTX_wm_manager(const bContext *C)
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
struct View3D * CTX_wm_view3d(const bContext *C)
struct ARegion * CTX_wm_region(const bContext *C)
struct Main * CTX_data_main(const bContext *C)
struct RegionView3D * CTX_wm_region_view3d(const bContext *C)
struct wmWindow * CTX_wm_window(const bContext *C)
bool BKE_gpencil_free_strokes(struct bGPDframe *gpf)
struct bGPDlayer * BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive, bool add_to_header)
struct bGPDframe * BKE_gpencil_layer_frame_get(struct bGPDlayer *gpl, int cframe, eGP_GetFrame_Mode addnew)
struct bGPdata * BKE_gpencil_data_addnew(struct Main *bmain, const char name[])
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
void BKE_report(ReportList *reports, eReportType type, const char *message)
int BKE_scene_orientation_get_index(struct Scene *scene, int slot_index)
size_t BKE_unit_value_as_string(char *str, int len_max, double value, int prec, int type, const struct UnitSettings *settings, bool pad)
void BLF_color3ubv(int fontid, const unsigned char rgb[3])
void BLF_width_and_height(int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL()
void BLF_disable(int fontid, int option)
void BLF_rotation(int fontid, float angle)
void BLF_draw(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2)
void BLF_enable(int fontid, int option)
void BLF_size(int fontid, float size, int dpi)
void BLF_position(int fontid, float x, float y, float z)
#define LISTBASE_FOREACH(type, var, list)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
MINLINE float min_ff(float a, float b)
MINLINE float min_fff(float a, float b, float c)
float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2])
MINLINE int min_axis_v3(const float vec[3])
float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
void mul_m3_m3_pre(float R[3][3], const float A[3][3])
bool invert_m3(float R[3][3])
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
void mul_qt_v3(const float q[4], float r[3])
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
MINLINE float normalize_v3(float r[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void negate_v3(float r[3])
void mid_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE float len_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
float angle_v3v3v3(const float a[3], const float b[3], const float c[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float normalize_v2(float r[2])
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v2_fl(float r[2], float f)
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
struct Depsgraph Depsgraph
struct Scene * DEG_get_input_scene(const Depsgraph *graph)
struct ViewLayer * DEG_get_input_view_layer(const Depsgraph *graph)
Object is a sort of wrapper for general info.
#define OBEDIT_FROM_OBACT(ob)
#define OBACT(_view_layer)
@ SCE_SNAP_MODE_FACE_RAYCAST
bool ED_gizmo_poll_or_unlink_delayed_from_tool(const struct bContext *C, struct wmGizmoGroupType *gzgt)
void ED_region_tag_redraw_editor_overlays(struct ARegion *region)
eSnapMode ED_transform_snap_object_project_view3d(struct SnapObjectContext *sctx, struct Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const eSnapMode snap_to, const struct SnapObjectParams *params, const float init_co[3], const float mval[2], const float prev_co[3], float *dist_px, float r_loc[3], float r_no[3])
bool ED_transform_snap_object_project_ray(SnapObjectContext *sctx, struct Depsgraph *depsgraph, const View3D *v3d, const struct SnapObjectParams *params, const float ray_origin[3], const float ray_direction[3], float *ray_depth, float r_co[3], float r_no[3])
@ V3D_PROJ_TEST_CLIP_NEAR
void ED_view3d_win_to_3d_int(const struct View3D *v3d, const struct ARegion *region, const float depth_pt[3], const int mval[2], float r_out[3])
#define USE_SNAP_DETECT_FROM_KEYMAP_HACK
eV3DProjStatus ED_view3d_project_float_global(const struct ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
float ED_view3d_pixel_size_no_ui_scale(const struct RegionView3D *rv3d, const float co[3])
@ V3D_SNAPCURSOR_SNAP_EDIT_GEOM_CAGE
void GPU_matrix_pop(void)
void GPU_matrix_pop_projection(void)
#define GPU_matrix_set(x)
void GPU_matrix_push(void)
#define GPU_matrix_projection_set(x)
void GPU_matrix_identity_set(void)
void GPU_matrix_push_projection(void)
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
@ GPU_SHADER_2D_UNIFORM_COLOR
@ GPU_SHADER_3D_UNIFORM_COLOR
void GPU_blend(eGPUBlend blend)
void GPU_line_width(float width)
void GPU_line_smooth(bool enable)
void GPU_viewport_size_get_f(float coords[4])
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
void UI_GetThemeColor3ubv(int colorid, unsigned char col[3])
eWM_GizmoFlagTweak
Gizmo tweak flag. Bit-flag passed to gizmo while tweaking.
@ WM_GIZMOGROUPTYPE_SCALE
@ WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL
@ WM_OP_INVOKE_REGION_WIN
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
const Depsgraph * depsgraph
void *(* MEM_callocN)(size_t len, const char *str)
static void area(int d1, int d2, int e1, int e2, float weights[2])
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
void RNA_property_unset(PointerRNA *ptr, PropertyRNA *prop)
void ED_gizmotypes_snap_3d_flag_set(struct wmGizmo *gz, int flag)
bool ED_gizmotypes_snap_3d_is_enabled(const wmGizmo *UNUSED(gz))
SnapObjectContext * ED_gizmotypes_snap_3d_context_ensure(Scene *scene, wmGizmo *UNUSED(gz))
void ED_gizmotypes_snap_3d_data_get(const struct bContext *C, wmGizmo *gz, float r_loc[3], float r_nor[3], int r_elem_index[3], eSnapMode *r_snap_elem)
struct wmGizmoMap * gizmo_map
struct RulerInfo::@570 drag_state_prev
struct RulerItem * item_active
PropertyRNA * prop_prevpoint
struct RulerInfo::@571 snap_data
struct ToolSettings * toolsettings
eWM_GizmoFlagGroupTypeFlag flag
struct wmGizmoMapType_Params gzmap_params
struct wmGizmoMap * parent_gzmap
wmGizmoFnTestSelect test_select
wmGizmoFnCursorGet cursor_get
struct wmGizmoGroup * parent_gzgroup
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
static void WIDGETGROUP_ruler_setup(const bContext *C, wmGizmoGroup *gzgroup)
static void ruler_item_remove(bContext *C, wmGizmoGroup *gzgroup, RulerItem *ruler_item)
@ RULERITEM_USE_ANGLE_ACTIVE
struct RulerInteraction RulerInteraction
static bGPDlayer * view3d_ruler_layer_get(bGPdata *gpd)
static bool gizmo_ruler_check_for_operator(const wmGizmoGroup *gzgroup)
static int view3d_ruler_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool view3d_ruler_poll(bContext *C)
static void ruler_state_set(RulerInfo *ruler_info, int state)
static const char * view3d_gzgt_ruler_id
void VIEW3D_OT_ruler_remove(wmOperatorType *ot)
static int view3d_ruler_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
void VIEW3D_GGT_ruler(wmGizmoGroupType *gzgt)
static void gizmo_ruler_draw(const bContext *C, wmGizmo *gz)
void VIEW3D_OT_ruler_add(wmOperatorType *ot)
static void ruler_item_as_string(RulerItem *ruler_item, UnitSettings *unit, char *numstr, size_t numstr_size, int prec)
static bool view3d_ruler_item_mousemove(const bContext *C, struct Depsgraph *depsgraph, RulerInfo *ruler_info, RulerItem *ruler_item, const int mval[2], const bool do_thickness)
static bool view3d_ruler_from_gpencil(const bContext *C, wmGizmoGroup *gzgroup)
static void view3d_ruler_item_project(RulerInfo *ruler_info, float r_co[3], const int xy[2])
static RulerItem * gzgroup_ruler_item_first_get(wmGizmoGroup *gzgroup)
static int gizmo_ruler_invoke(bContext *C, wmGizmo *gz, const wmEvent *event)
static RulerItem * ruler_item_add(wmGizmoGroup *gzgroup)
static int gizmo_ruler_cursor_get(wmGizmo *gz)
static int gizmo_ruler_modal(bContext *C, wmGizmo *gz, const wmEvent *event, eWM_GizmoFlagTweak tweak_flag)
static int gizmo_ruler_test_select(bContext *UNUSED(C), wmGizmo *gz, const int mval[2])
struct RulerItem RulerItem
static void gizmo_ruler_exit(bContext *C, wmGizmo *gz, const bool cancel)
static bool view3d_ruler_to_gpencil(bContext *C, wmGizmoGroup *gzgroup)
struct RulerInfo RulerInfo
static bool view3d_ruler_pick(wmGizmoGroup *gzgroup, RulerItem *ruler_item, const float mval[2], int *r_co_index)
void VIEW3D_GT_ruler_item(wmGizmoType *gzt)
#define RULER_PICK_DIST_SQ
void WM_event_drag_start_mval_fl(const wmEvent *event, const ARegion *region, float r_mval[2])
void WM_event_drag_start_mval(const wmEvent *event, const ARegion *region, int r_mval[2])
int WM_operator_name_call(bContext *C, const char *opstring, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
PointerRNA * WM_gizmo_operator_set(wmGizmo *gz, int part_index, wmOperatorType *ot, IDProperty *properties)
wmGizmo * WM_gizmo_new_ptr(const wmGizmoType *gzt, wmGizmoGroup *gzgroup, PointerRNA *properties)
bool WM_gizmo_highlight_set(wmGizmoMap *gzmap, wmGizmo *gz)
void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable)
void WM_gizmo_set_color(wmGizmo *gz, const float color[4])
void WM_gizmo_unlink(ListBase *gizmolist, wmGizmoMap *gzmap, wmGizmo *gz, bContext *C)
wmGizmoGroup * WM_gizmomap_group_find(struct wmGizmoMap *gzmap, const char *idname)
const wmGizmoType * WM_gizmotype_find(const char *idname, bool quiet)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void wmOrtho2_region_pixelspace(const ARegion *region)