Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--release/scripts/startup/bl_ui/space_info.py2
-rw-r--r--source/blender/editors/include/ED_view3d.h2
-rw-r--r--source/blender/editors/mesh/editmesh_add.c24
-rw-r--r--source/blender/editors/object/object_add.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c14
-rw-r--r--source/blender/windowmanager/WM_api.h1
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c30
7 files changed, 60 insertions, 17 deletions
diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py
index 662d5526a37..8df117e27a0 100644
--- a/release/scripts/startup/bl_ui/space_info.py
+++ b/release/scripts/startup/bl_ui/space_info.py
@@ -193,7 +193,7 @@ class INFO_MT_mesh_add(Menu):
def draw(self, context):
layout = self.layout
- layout.operator_context = 'EXEC_REGION_WIN'
+ layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("mesh.primitive_plane_add", icon='MESH_PLANE', text="Plane")
layout.operator("mesh.primitive_cube_add", icon='MESH_CUBE', text="Cube")
layout.operator("mesh.primitive_circle_add", icon='MESH_CIRCLE', text="Circle")
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index d5c9b9ef01a..b4679bd1c69 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -295,6 +295,8 @@ void ED_view3D_background_image_clear(struct View3D *v3d);
#define VIEW3D_MARGIN 1.4f
float ED_view3d_offset_distance(float mat[4][4], float ofs[3]);
+
+float ED_scene_grid_scale(struct Scene *scene, const char **grid_unit);
float ED_view3d_grid_scale(struct Scene *scene, struct View3D *v3d, const char **grid_unit);
/* view matrix properties utilities */
diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c
index eed72935b3c..4a425c83d86 100644
--- a/source/blender/editors/mesh/editmesh_add.c
+++ b/source/blender/editors/mesh/editmesh_add.c
@@ -204,7 +204,7 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op)
if (!EDBM_op_call_and_selectf(em, op, "verts.out",
"create_circle segments=%i diameter=%f cap_ends=%b cap_tris=%b matrix=%m4",
- RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius") * dia,
+ RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius"),
cap_end, cap_tri, mat))
{
return OPERATOR_CANCELLED;
@@ -225,6 +225,7 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot)
ot->idname = "MESH_OT_primitive_circle_add";
/* api callbacks */
+ ot->invoke = WM_operator_view3d_distance_invoke;
ot->exec = add_primitive_circle_exec;
ot->poll = ED_operator_scene_editable;
@@ -260,10 +261,10 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
em, op, "verts.out",
"create_cone segments=%i diameter1=%f diameter2=%f cap_ends=%b cap_tris=%b depth=%f matrix=%m4",
RNA_int_get(op->ptr, "vertices"),
- RNA_float_get(op->ptr, "radius") * dia,
- RNA_float_get(op->ptr, "radius") * dia,
+ RNA_float_get(op->ptr, "radius"),
+ RNA_float_get(op->ptr, "radius"),
cap_end, cap_tri,
- RNA_float_get(op->ptr, "depth") * dia, mat))
+ RNA_float_get(op->ptr, "depth"), mat))
{
return OPERATOR_CANCELLED;
}
@@ -283,6 +284,7 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot)
ot->idname = "MESH_OT_primitive_cylinder_add";
/* api callbacks */
+ ot->invoke = WM_operator_view3d_distance_invoke;
ot->exec = add_primitive_cylinder_exec;
ot->poll = ED_operator_scene_editable;
@@ -319,8 +321,8 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
if (!EDBM_op_call_and_selectf(
em, op, "verts.out",
"create_cone segments=%i diameter1=%f diameter2=%f cap_ends=%b cap_tris=%b depth=%f matrix=%m4",
- RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius1") * dia,
- RNA_float_get(op->ptr, "radius2") * dia, cap_end, cap_tri, RNA_float_get(op->ptr, "depth") * dia, mat))
+ RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius1"),
+ RNA_float_get(op->ptr, "radius2"), cap_end, cap_tri, RNA_float_get(op->ptr, "depth"), mat))
{
return OPERATOR_CANCELLED;
}
@@ -340,6 +342,7 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot)
ot->idname = "MESH_OT_primitive_cone_add";
/* api callbacks */
+ ot->invoke = WM_operator_view3d_distance_invoke;
ot->exec = add_primitive_cone_exec;
ot->poll = ED_operator_scene_editable;
@@ -376,7 +379,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
"create_grid x_segments=%i y_segments=%i size=%f matrix=%m4",
RNA_int_get(op->ptr, "x_subdivisions"),
RNA_int_get(op->ptr, "y_subdivisions"),
- RNA_float_get(op->ptr, "size") * dia, mat))
+ RNA_float_get(op->ptr, "size"), mat))
{
return OPERATOR_CANCELLED;
}
@@ -396,6 +399,7 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot)
ot->idname = "MESH_OT_primitive_grid_add";
/* api callbacks */
+ ot->invoke = WM_operator_view3d_distance_invoke;
ot->exec = add_primitive_grid_exec;
ot->poll = ED_operator_scene_editable;
@@ -473,7 +477,7 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
if (!EDBM_op_call_and_selectf(em, op, "verts.out",
"create_uvsphere u_segments=%i v_segments=%i diameter=%f matrix=%m4",
RNA_int_get(op->ptr, "segments"), RNA_int_get(op->ptr, "ring_count"),
- RNA_float_get(op->ptr, "size") * dia, mat))
+ RNA_float_get(op->ptr, "size"), mat))
{
return OPERATOR_CANCELLED;
}
@@ -493,6 +497,7 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot)
ot->idname = "MESH_OT_primitive_uv_sphere_add";
/* api callbacks */
+ ot->invoke = WM_operator_view3d_distance_invoke;
ot->exec = add_primitive_uvsphere_exec;
ot->poll = ED_operator_scene_editable;
@@ -525,7 +530,7 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
em, op, "verts.out",
"create_icosphere subdivisions=%i diameter=%f matrix=%m4",
RNA_int_get(op->ptr, "subdivisions"),
- RNA_float_get(op->ptr, "size") * dia, mat))
+ RNA_float_get(op->ptr, "size"), mat))
{
return OPERATOR_CANCELLED;
}
@@ -545,6 +550,7 @@ void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot)
ot->idname = "MESH_OT_primitive_ico_sphere_add";
/* api callbacks */
+ ot->invoke = WM_operator_view3d_distance_invoke;
ot->exec = add_primitive_icosphere_exec;
ot->poll = ED_operator_scene_editable;
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index ad1e2816c10..7c4a547debc 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -210,8 +210,8 @@ float ED_object_new_primitive_matrix(bContext *C, Object *obedit,
invert_m3_m3(imat, mat);
mul_m3_v3(imat, primmat[3]);
- if (v3d) {
- float dia = ED_view3d_grid_scale(scene, v3d, NULL);
+ {
+ const float dia = v3d ? ED_view3d_grid_scale(scene, v3d, NULL) : ED_scene_grid_scale(scene, NULL);
if (apply_diameter) {
primmat[0][0] *= dia;
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 6c23635da90..51261f4c341 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -451,10 +451,9 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **
}
#undef GRID_MIN_PX
-float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit)
+/** could move this elsewhere, but tied into #ED_view3d_grid_scale */
+float ED_scene_grid_scale(Scene *scene, const char **grid_unit)
{
- float grid_scale = v3d->grid;
-
/* apply units */
if (scene->unit.system) {
void *usys;
@@ -466,11 +465,16 @@ float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit)
int i = bUnit_GetBaseUnit(usys);
if (grid_unit)
*grid_unit = bUnit_GetNameDisplay(usys, i);
- grid_scale = (grid_scale * (float)bUnit_GetScaler(usys, i)) / scene->unit.scale_length;
+ return (float)bUnit_GetScaler(usys, i) / scene->unit.scale_length;
}
}
- return grid_scale;
+ return 1.0f;
+}
+
+float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit)
+{
+ return v3d->grid * ED_scene_grid_scale(scene, grid_unit);
}
static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit)
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 1037542759f..8d885bf6d6f 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -171,6 +171,7 @@ void WM_event_timer_sleep(struct wmWindowManager *wm, struct wmWindow *win, str
/* operator api, default callbacks */
/* invoke callback, uses enum property named "type" */
+int WM_operator_view3d_distance_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
int WM_menu_invoke (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
int WM_enum_search_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
/* invoke callback, confirm menu + exec */
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index c555f771a48..8a0701b1063 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -87,6 +87,7 @@
#include "ED_screen.h"
#include "ED_util.h"
#include "ED_object.h"
+#include "ED_view3d.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -689,6 +690,35 @@ void WM_operator_properties_free(PointerRNA *ptr)
/* ************ default op callbacks, exported *********** */
+int WM_operator_view3d_distance_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *UNUSED(event))
+{
+ Scene *scene = CTX_data_scene(C);
+ View3D *v3d = CTX_wm_view3d(C);
+
+ const float dia = v3d ? ED_view3d_grid_scale(scene, v3d, NULL) : ED_scene_grid_scale(scene, NULL);
+
+ /* always run, so the values are initialized,
+ * otherwise we may get differ behavior when (dia != 1.0) */
+ RNA_STRUCT_BEGIN(op->ptr, prop)
+ {
+ if (RNA_property_type(prop) == PROP_FLOAT) {
+ PropertySubType pstype = RNA_property_subtype(prop);
+ if (pstype == PROP_DISTANCE) {
+ /* we don't support arrays yet */
+ BLI_assert(RNA_property_array_check(prop) == FALSE);
+ /* initialize */
+ if (!RNA_property_is_set_ex(op->ptr, prop, FALSE)) {
+ const float value = RNA_property_float_get_default(op->ptr, prop) * dia;
+ RNA_property_float_set(op->ptr, prop, value);
+ }
+ }
+ }
+ }
+ RNA_STRUCT_END;
+
+ return op->type->exec(C, op);
+}
+
/* invoke callback, uses enum property named "type" */
int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
{