Blender V4.3
view3d_gizmo_ruler.cc File Reference
#include "BLI_listbase.h"
#include "BLI_math_matrix.hh"
#include "BLI_math_matrix_types.hh"
#include "BLI_math_rotation.h"
#include "BLI_math_vector_types.hh"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BKE_context.hh"
#include "BKE_gpencil_legacy.h"
#include "BKE_report.hh"
#include "BKE_layer.hh"
#include "BKE_scene.hh"
#include "BKE_unit.hh"
#include "DNA_gpencil_legacy_types.h"
#include "DNA_object_types.h"
#include "DNA_view3d_types.h"
#include "ED_gizmo_library.hh"
#include "ED_gizmo_utils.hh"
#include "ED_screen.hh"
#include "ED_transform.hh"
#include "ED_transform_snap_object_context.hh"
#include "ED_view3d.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"
#include "MEM_guardedalloc.h"
#include "RNA_access.hh"
#include "WM_api.hh"
#include "WM_toolsystem.hh"
#include "WM_types.hh"
#include "DEG_depsgraph_query.hh"
#include "view3d_intern.hh"
#include "GPU_immediate.hh"
#include "GPU_immediate_util.hh"
#include "GPU_matrix.hh"
#include "GPU_state.hh"
#include "BLF_api.hh"

Go to the source code of this file.

Classes

struct  RulerInfo
 
struct  RulerItem
 
struct  RulerInteraction
 

Macros

#define USE_AXIS_CONSTRAINTS
 
#define MVAL_MAX_PX_DIST   12.0f
 
#define RULER_PICK_DIST   12.0f
 
#define RULER_PICK_DIST_SQ   (RULER_PICK_DIST * RULER_PICK_DIST)
 
#define PART_LINE   0xff
 

Enumerations

enum  { RULERITEM_USE_ANGLE = (1 << 0) , RULERITEM_USE_ANGLE_ACTIVE = (1 << 1) }
 
enum  { RULER_STATE_NORMAL = 0 , RULER_STATE_DRAG }
 
enum  { CONSTRAIN_AXIS_NONE = -1 , CONSTRAIN_AXIS_X = 0 , CONSTRAIN_AXIS_Y = 1 , CONSTRAIN_AXIS_Z = 2 }
 
enum  { CONSTRAIN_MODE_OFF = 0 , CONSTRAIN_MODE_1 = 1 , CONSTRAIN_MODE_2 = 2 }
 

Functions

Internal Ruler Utilities
static RulerItemruler_item_add (wmGizmoGroup *gzgroup)
 
static void ruler_item_remove (bContext *C, wmGizmoGroup *gzgroup, RulerItem *ruler_item)
 
static void ruler_item_as_string (RulerItem *ruler_item, UnitSettings *unit, char *numstr, size_t numstr_size, int prec)
 
static bool view3d_ruler_pick (wmGizmoGroup *gzgroup, RulerItem *ruler_item, const float2 mval, int *r_co_index)
 
static void ruler_state_set (RulerInfo *ruler_info, int state)
 
static void view3d_ruler_item_project (RulerInfo *ruler_info, float3 &r_co, const int xy[2])
 
static bool view3d_ruler_item_mousemove (const bContext *C, Depsgraph *depsgraph, RulerInfo *ruler_info, RulerItem *ruler_item, const int mval[2], const bool do_thickness, const bool do_snap)
 
static bool gizmo_ruler_check_for_operator (const wmGizmoGroup *gzgroup)
 
Ruler Item Gizmo Type
static void gizmo_ruler_draw (const bContext *C, wmGizmo *gz)
 
static int gizmo_ruler_test_select (bContext *, wmGizmo *gz, const int mval[2])
 
static int gizmo_ruler_modal (bContext *C, wmGizmo *gz, const wmEvent *event, eWM_GizmoFlagTweak tweak_flag)
 
static int gizmo_ruler_invoke (bContext *C, wmGizmo *gz, const wmEvent *event)
 
static void gizmo_ruler_exit (bContext *C, wmGizmo *gz, const bool cancel)
 
static int gizmo_ruler_cursor_get (wmGizmo *gz)
 
void VIEW3D_GT_ruler_item (wmGizmoType *gzt)
 
Ruler Gizmo Group
static void WIDGETGROUP_ruler_setup (const bContext *C, wmGizmoGroup *gzgroup)
 
void VIEW3D_GGT_ruler (wmGizmoGroupType *gzgt)
 
Add Ruler Operator
static bool view3d_ruler_poll (bContext *C)
 
static int view3d_ruler_add_invoke (bContext *C, wmOperator *op, const wmEvent *event)
 
void VIEW3D_OT_ruler_add (wmOperatorType *ot)
 
Remove Ruler Operator
static int view3d_ruler_remove_invoke (bContext *C, wmOperator *op, const wmEvent *)
 
void VIEW3D_OT_ruler_remove (wmOperatorType *ot)
 

Variables

static const char * view3d_gzgt_ruler_id = "VIEW3D_GGT_ruler"
 

Ruler/Grease Pencil Conversion

#define RULER_ID   "RulerData3D"
 
static bGPDlayerview3d_ruler_layer_get (bGPdata *gpd)
 
static RulerItemgzgroup_ruler_item_first_get (wmGizmoGroup *gzgroup)
 
static void view3d_ruler_gpencil_ensure (bContext *C)
 
static bool view3d_ruler_to_gpencil (bContext *C, wmGizmoGroup *gzgroup)
 
static bool view3d_ruler_from_gpencil (const bContext *C, wmGizmoGroup *gzgroup)
 

Macro Definition Documentation

◆ MVAL_MAX_PX_DIST

#define MVAL_MAX_PX_DIST   12.0f

Definition at line 73 of file view3d_gizmo_ruler.cc.

Referenced by view3d_ruler_item_mousemove().

◆ PART_LINE

#define PART_LINE   0xff

◆ RULER_ID

#define RULER_ID   "RulerData3D"

Definition at line 511 of file view3d_gizmo_ruler.cc.

Referenced by view3d_ruler_to_gpencil().

◆ RULER_PICK_DIST

#define RULER_PICK_DIST   12.0f

Definition at line 86 of file view3d_gizmo_ruler.cc.

◆ RULER_PICK_DIST_SQ

#define RULER_PICK_DIST_SQ   (RULER_PICK_DIST * RULER_PICK_DIST)

Definition at line 87 of file view3d_gizmo_ruler.cc.

Referenced by view3d_ruler_pick().

◆ USE_AXIS_CONSTRAINTS

#define USE_AXIS_CONSTRAINTS

Supporting transform features could be removed if the actual transform system is used. Keep the option open since each transform feature is duplicating logic.

Definition at line 69 of file view3d_gizmo_ruler.cc.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RULERITEM_USE_ANGLE 

Use protractor.

RULERITEM_USE_ANGLE_ACTIVE 

Protractor vertex is selected (deleting removes it).

Definition at line 78 of file view3d_gizmo_ruler.cc.

◆ anonymous enum

anonymous enum
Enumerator
RULER_STATE_NORMAL 
RULER_STATE_DRAG 

Definition at line 95 of file view3d_gizmo_ruler.cc.

◆ anonymous enum

anonymous enum
Enumerator
CONSTRAIN_AXIS_NONE 
CONSTRAIN_AXIS_X 
CONSTRAIN_AXIS_Y 
CONSTRAIN_AXIS_Z 

Definition at line 102 of file view3d_gizmo_ruler.cc.

◆ anonymous enum

anonymous enum

Constraining modes. Off / Scene orientation / Global (or Local if Scene orientation is Global).

Enumerator
CONSTRAIN_MODE_OFF 
CONSTRAIN_MODE_1 
CONSTRAIN_MODE_2 

Definition at line 113 of file view3d_gizmo_ruler.cc.

Function Documentation

◆ gizmo_ruler_check_for_operator()

static bool gizmo_ruler_check_for_operator ( const wmGizmoGroup * gzgroup)
static

When the gizmo-group has been created immediately before running an operator to manipulate rulers, it's possible the new gizmo-group has not yet been initialized. in 3.0 this happened because left-click drag would both select and add a new ruler, significantly increasing the likelihood of this happening. Workaround this crash by checking the gizmo's custom-data has not been cleared. The key-map has also been modified not to trigger this bug, see #95591.

Definition at line 480 of file view3d_gizmo_ruler.cc.

References wmGizmoGroup::customdata.

Referenced by view3d_ruler_add_invoke(), and view3d_ruler_remove_invoke().

◆ gizmo_ruler_cursor_get()

static int gizmo_ruler_cursor_get ( wmGizmo * gz)
static

◆ gizmo_ruler_draw()

static void gizmo_ruler_draw ( const bContext * C,
wmGizmo * gz )
static

Definition at line 645 of file view3d_gizmo_ruler.cc.

References angle(), angle_normalized_v3v3(), axis_angle_to_quat(), BLF_color3ubv(), BLF_disable(), BLF_draw(), BLF_enable(), blf_mono_font, BLF_position(), BLF_ROTATION, BLF_rotation(), BLF_size(), BLF_width_and_height(), RulerItem::co, col, copy_v3_fl(), blender::math::cross(), CTX_data_scene(), wmGizmoGroup::customdata, blender::math::distance(), ED_view3d_pixel_size_no_ui_scale(), ED_view3d_project_float_global(), fabs(), RulerItem::flag, GPU_blend(), GPU_BLEND_ALPHA, GPU_BLEND_NONE, GPU_COMP_F32, GPU_FETCH_FLOAT, GPU_line_smooth(), GPU_line_width(), GPU_matrix_identity_set(), GPU_matrix_pop(), GPU_matrix_pop_projection(), GPU_matrix_projection_set, GPU_matrix_push(), GPU_matrix_push_projection(), GPU_matrix_set, GPU_PRIM_LINE_STRIP, GPU_PRIM_LINES, GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR, GPU_SHADER_3D_UNIFORM_COLOR, GPU_vertformat_attr_add(), GPU_viewport_size_get_f(), immBegin(), immBindBuiltinProgram(), immEnd(), immRectf(), immUnbindProgram(), immUniform1f(), immUniform1i(), immUniform2f(), immUniform4f(), immUniform4fv(), immUniformColor3fv(), immUniformColor3ubv(), immUniformColor4fv(), immVertex2f(), immVertex2fv(), immVertex3fv(), immVertexFormat(), RulerInfo::item_active, len, len_v2v2(), min_fff(), mul_qt_v3(), blender::math::normalize(), normalize_v2(), wmGizmo::parent_gzgroup, RulerInfo::region, ruler_item_as_string(), RULERITEM_USE_ANGLE, RULERITEM_USE_ANGLE_ACTIVE, sub_v2_v2v2(), TH_TEXT, TH_WIRE, UI_GetThemeColor3ubv(), UI_SCALE_FAC, V3D_PROJ_RET_OK, V3D_PROJ_TEST_CLIP_NEAR, RegionView3D::viewmat, RegionView3D::winmat, and wmOrtho2_region_pixelspace().

Referenced by VIEW3D_GT_ruler_item().

◆ gizmo_ruler_exit()

◆ gizmo_ruler_invoke()

◆ gizmo_ruler_modal()

◆ gizmo_ruler_test_select()

static int gizmo_ruler_test_select ( bContext * ,
wmGizmo * gz,
const int mval[2] )
static

◆ gzgroup_ruler_item_first_get()

static RulerItem * gzgroup_ruler_item_first_get ( wmGizmoGroup * gzgroup)
static

◆ ruler_item_add()

static RulerItem * ruler_item_add ( wmGizmoGroup * gzgroup)
static

◆ ruler_item_as_string()

static void ruler_item_as_string ( RulerItem * ruler_item,
UnitSettings * unit,
char * numstr,
size_t numstr_size,
int prec )
static

◆ ruler_item_remove()

static void ruler_item_remove ( bContext * C,
wmGizmoGroup * gzgroup,
RulerItem * ruler_item )
static

◆ ruler_state_set()

static void ruler_state_set ( RulerInfo * ruler_info,
int state )
static

Ensure the 'snap_context' is only cached while dragging, needed since the user may toggle modes between tool use.

Definition at line 304 of file view3d_gizmo_ruler.cc.

References BLI_assert, RulerInfo::drag_state_prev, RulerInfo::gizmo, RulerInfo::prop_prevpoint, wmGizmo::ptr, RNA_property_float_set_array(), RULER_STATE_DRAG, RULER_STATE_NORMAL, RulerInfo::snap_data, RulerInfo::state, state, WM_GIZMO_DRAW_VALUE, and WM_gizmo_set_flag().

Referenced by gizmo_ruler_exit(), and gizmo_ruler_invoke().

◆ VIEW3D_GGT_ruler()

◆ VIEW3D_GT_ruler_item()

◆ VIEW3D_OT_ruler_add()

◆ VIEW3D_OT_ruler_remove()

◆ view3d_ruler_add_invoke()

◆ view3d_ruler_from_gpencil()

◆ view3d_ruler_gpencil_ensure()

◆ view3d_ruler_item_mousemove()

static bool view3d_ruler_item_mousemove ( const bContext * C,
Depsgraph * depsgraph,
RulerInfo * ruler_info,
RulerItem * ruler_item,
const int mval[2],
const bool do_thickness,
const bool do_snap )
static

◆ view3d_ruler_item_project()

static void view3d_ruler_item_project ( RulerInfo * ruler_info,
float3 & r_co,
const int xy[2] )
static

◆ view3d_ruler_layer_get()

static bGPDlayer * view3d_ruler_layer_get ( bGPdata * gpd)
static

◆ view3d_ruler_pick()

◆ view3d_ruler_poll()

◆ view3d_ruler_remove_invoke()

◆ view3d_ruler_to_gpencil()

◆ WIDGETGROUP_ruler_setup()

Variable Documentation

◆ view3d_gzgt_ruler_id

const char* view3d_gzgt_ruler_id = "VIEW3D_GGT_ruler"
static