74 #define MVAL_MAX_PX_DIST 12.0f
87 #define RULER_PICK_DIST 12.0f
88 #define RULER_PICK_DIST_SQ (RULER_PICK_DIST * RULER_PICK_DIST)
91 #define PART_LINE 0xff
117 #ifndef USE_SNAP_DETECT_FROM_KEYMAP_HACK
176 ruler_item->
co[0], ruler_item->
co[1], ruler_item->
co[2]);
183 numstr, numstr_size, (
double)ruler_angle, prec,
B_UNIT_ROTATION, unit,
false);
187 const float ruler_len =
len_v3v3(ruler_item->
co[0], ruler_item->
co[2]);
190 BLI_snprintf(numstr, numstr_size,
"%.*f", prec, ruler_len);
214 int co_index_best = -1;
222 for (j = 0; j < 3; j++) {
229 if (dist < dist_best) {
234 const float dist_points[3] = {
250 if (dist < dist_best) {
255 const float dist_points[2] = {
260 co_index_best = (dist_points[0] < dist_points[1]) ? 0 : 2;
270 *r_co_index = co_index_best;
307 const bool do_thickness
315 const float eps_bias = 0.0002f;
324 if (do_thickness && inter->
co_index != 1) {
329 const float mval_fl[2] = {
UNPACK2(mval)};
334 co_other = ruler_item->
co[inter->
co_index == 0 ? 2 : 0];
341 .use_object_edit_cage =
true,
355 .use_object_edit_cage =
true,
365 #ifndef USE_SNAP_DETECT_FROM_KEYMAP_HACK
370 const float mval_fl[2] = {
UNPACK2(mval)};
371 float *prev_point =
NULL;
375 prev_point = ruler_item->
co[1];
378 prev_point = ruler_item->
co[2];
381 prev_point = ruler_item->
co[0];
384 if (prev_point !=
NULL) {
427 #define RULER_ID "RulerData3D"
440 bool changed =
false;
468 for (j = 0; j < 3; j++) {
478 for (j = 0; j < 3; j += 2) {
502 bool changed =
false;
518 for (j = 0; j < 3; j++) {
527 for (j = 0; j < 3; j += 2) {
555 const float cap_size = 4.0f *
U.dpi_fac;
556 const float bg_margin = 4.0f *
U.dpi_fac;
557 const float arc_size = 64.0f *
U.dpi_fac;
560 const float color_act[4] = {1.0f, 1.0f, 1.0f, 1.0f};
561 const float color_base[4] = {0.0f, 0.0f, 0.0f, 1.0f};
564 float color_back[4] = {1.0f, 1.0f, 1.0f, 0.5f};
584 if ((
int)color_text[0] + (
int)color_text[1] + (
int)color_text[2] > 127 * 3 * 0.6f) {
588 const bool is_act = (ruler_info->
item_active == ruler_item);
595 for (j = 0; j < 3; j++) {
616 float viewport_size[4];
618 immUniform2f(
"viewport_size", viewport_size[2], viewport_size[3]);
621 const float *
col = is_act ? color_act : color_base;
624 (
float *)(
float[][4]){{0.67f, 0.67f, 0.67f, 1.0f}, {
col[0],
col[1],
col[2],
col[3]}},
653 len_v2v2(co_ss[0], co_ss[1]) / 2.0f,
654 len_v2v2(co_ss[2], co_ss[1]) / 2.0f));
672 for (j = 0; j <= arc_steps; 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;
695 (
float *)(
float[][4]){{0.67f, 0.67f, 0.67f, 1.0f}, {
col[0],
col[1],
col[2],
col[3]}},
722 float rot_90_vec_a[2];
723 float rot_90_vec_b[2];
727 rot_90_vec_a[0] = -dir_ruler[1];
728 rot_90_vec_a[1] = dir_ruler[0];
732 rot_90_vec_b[0] = -dir_ruler[1];
733 rot_90_vec_b[1] = dir_ruler[0];
743 immVertex2f(shdr_pos_2d, co_ss[1][0] - cap_size, co_ss[1][1] - cap_size);
744 immVertex2f(shdr_pos_2d, co_ss[1][0] + cap_size, co_ss[1][1] + cap_size);
745 immVertex2f(shdr_pos_2d, co_ss[1][0] - cap_size, co_ss[1][1] + cap_size);
746 immVertex2f(shdr_pos_2d, co_ss[1][0] + cap_size, co_ss[1][1] - cap_size);
754 if (proj_ok[0] || proj_ok[2] || proj_ok[1]) {
773 immVertex2f(shdr_pos_2d, co_ss[1][0] - cap_size, co_ss[1][1] - cap_size);
774 immVertex2f(shdr_pos_2d, co_ss[1][0] + cap_size, co_ss[1][1] + cap_size);
775 immVertex2f(shdr_pos_2d, co_ss[1][0] - cap_size, co_ss[1][1] + cap_size);
776 immVertex2f(shdr_pos_2d, co_ss[1][0] + cap_size, co_ss[1][1] - cap_size);
787 float numstr_size[2];
795 posit[0] = co_ss[1][0] + (cap_size * 2.0f);
796 posit[1] = co_ss[1][1] - (numstr_size[1] / 2.0f);
803 posit[0] - bg_margin,
804 posit[1] - bg_margin,
805 posit[0] + bg_margin + numstr_size[0],
806 posit[1] + bg_margin + numstr_size[1]);
827 float rot_90_vec[2] = {-dir_ruler[1], dir_ruler[0]};
836 if (proj_ok[0] || proj_ok[2]) {
861 float numstr_size[2];
872 posit[0] -= numstr_size[0] / 2.0f;
873 posit[1] -= numstr_size[1] / 2.0f;
876 if (proj_ok[0] && proj_ok[2]) {
880 posit[0] - bg_margin,
881 posit[1] - bg_margin,
882 posit[0] + bg_margin + numstr_size[0],
883 posit[1] + bg_margin + numstr_size[1]);
890 if (proj_ok[0] && proj_ok[2]) {
910 const float mval_fl[2] = {
UNPACK2(mval)};
915 if (co_index == -1) {
932 bool do_draw =
false;
939 ruler_info->
region = region;
941 #ifndef USE_SNAP_DETECT_FROM_KEYMAP_HACK
946 do_cursor_update =
true;
949 if (do_cursor_update) {
1006 CLAMP(fac, 0.0f, 1.0f);
1009 ruler_item_pick->
co[1], ruler_item_pick->
co[0], ruler_item_pick->
co[2], fac);
1045 prev_point = (inter->
co_index != 1) ? ruler_item_pick->
co[1] :
NULL;
1048 prev_point = ruler_item_pick->
co[2];
1051 prev_point = ruler_item_pick->
co[0];
1098 gzt->
idname =
"VIEW3D_GT_ruler_item";
1128 "snap_elements_force",
1148 ruler_info->
wm = wm;
1149 ruler_info->
win = win;
1151 ruler_info->
region = region;
1160 gzgt->
name =
"Ruler Widgets";
1248 ot->
idname =
"VIEW3D_OT_ruler_add";
1301 ot->
name =
"Ruler Remove";
1302 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 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[])
struct bGPDlayer * BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive)
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
void BKE_report(ReportList *reports, ReportType type, const char *message)
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 len, float *r_width, float *r_height) ATTR_NONNULL()
void BLF_draw(int fontid, const char *str, size_t len) ATTR_NONNULL(2)
void BLF_disable(int fontid, int option)
void BLF_rotation(int fontid, float angle)
void BLF_size(int fontid, int size, int dpi)
void BLF_enable(int fontid, int option)
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 axis_angle_to_quat(float r[4], const float axis[3], const 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])
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], const float t)
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])
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)
Object is a sort of wrapper for general info.
#define SCE_SNAP_MODE_FACE
#define SCE_SNAP_MODE_EDGE_PERPENDICULAR
#define SCE_SNAP_MODE_EDGE_MIDPOINT
#define SCE_SNAP_MODE_VERTEX
#define SCE_SNAP_MODE_EDGE
#define USE_SNAP_DETECT_FROM_KEYMAP_HACK
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)
bool ED_transform_snap_object_project_ray(SnapObjectContext *sctx, struct Depsgraph *depsgraph, 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])
bool ED_transform_snap_object_project_view3d(struct SnapObjectContext *sctx, struct Depsgraph *depsgraph, const unsigned short snap_to, const struct SnapObjectParams *params, const float mval[2], const float prev_co[3], float *dist_px, float r_loc[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])
float ED_view3d_pixel_size_no_ui_scale(const struct RegionView3D *rv3d, const float co[3])
eV3DProjStatus ED_view3d_project_float_global(const struct ARegion *region, const float co[3], float r_co[2], const eV3DProjTest flag)
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 RGB to Bright Vector Camera CLAMP
void UI_GetThemeColor3ubv(int colorid, unsigned char col[3])
eWM_GizmoFlagTweak
Gizmo tweak flag. Bitflag 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)
short ED_gizmotypes_snap_3d_update(wmGizmo *gz, struct Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const wmWindowManager *wm, const float mval_fl[2])
void ED_gizmotypes_snap_3d_data_get(wmGizmo *gz, float r_loc[3], float r_nor[3], int r_elem_index[3], int *r_snap_elem)
bool ED_gizmotypes_snap_3d_is_enabled(wmGizmo *gz)
SnapObjectContext * ED_gizmotypes_snap_3d_context_ensure(Scene *scene, const ARegion *region, const View3D *v3d, wmGizmo *gz)
struct wmGizmoMap * gizmo_map
struct RulerInfo::@553 drag_state_prev
struct RulerItem * item_active
PropertyRNA * prop_prevpoint
struct RulerInfo::@554 snap_data
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)
struct RulerInteraction RulerInteraction
@ RULERITEM_USE_ANGLE_ACTIVE
static bGPDlayer * view3d_ruler_layer_get(bGPdata *gpd)
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_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 bool view3d_ruler_item_mousemove(struct Depsgraph *depsgraph, RulerInfo *ruler_info, RulerItem *ruler_item, const int mval[2], const bool do_thickness)
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
int WM_operator_name_call(bContext *C, const char *opstring, short context, PointerRNA *properties)
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)