Nodes: Panel declarations for grouping sockets #108649

Merged
Lukas Tönne merged 27 commits from LukasTonne/blender:node-socket-categories into main 2023-06-14 18:02:46 +02:00
163 changed files with 2396 additions and 1006 deletions
Showing only changes of commit 3d1aae86c5 - Show all commits

View File

@ -1,5 +1,10 @@
# SPDX-License-Identifier: GPL-2.0-or-later
if(CMAKE_COMPILER_IS_GNUCC)
# NOTE: Resolved up-stream, quiet noisy compiler warnings for now.
add_cxx_flag("-Wno-uninitialized")
endif()
set(INC
include
)

View File

@ -104,7 +104,7 @@ ccl_device int bsdf_ashikhmin_velvet_sample(ccl_private const ShaderClosure *sc,
float cosHI = fabsf(dot(wi, H));
float cosNH = dot(N, H);
if (!(fabsf(cosNI) > 1e-5f && fabsf(cosNH) < 1.0f - 1e-5f && cosHI > 1e-5f)) {
if (!(cosNI > 1e-5f && fabsf(cosNH) < 1.0f - 1e-5f && cosHI > 1e-5f)) {
*pdf = 0.0f;
*eval = zero_spectrum();
return LABEL_NONE;

View File

@ -79,6 +79,7 @@ struct CCLShadowContext
#endif
IntegratorShadowState isect_s;
float throughput;
float max_t;
bool opaque_hit;
numhit_t max_hits;
numhit_t num_hits;
@ -314,7 +315,7 @@ ccl_device_forceinline void kernel_embree_filter_occluded_shadow_all_func_impl(
/* Current implementation in Cycles assumes only single-ray intersection queries. */
assert(args->N == 1);
RTCRay *ray = (RTCRay *)args->ray;
const RTCRay *ray = (RTCRay *)args->ray;
RTCHit *hit = (RTCHit *)args->hit;
#if EMBREE_MAJOR_VERSION >= 4
CCLShadowContext *ctx = (CCLShadowContext *)(args->context);
@ -367,42 +368,51 @@ ccl_device_forceinline void kernel_embree_filter_occluded_shadow_all_func_impl(
}
}
/* Test if we need to record this transparent intersection. */
const numhit_t max_record_hits = min(ctx->max_hits, numhit_t(INTEGRATOR_SHADOW_ISECT_SIZE));
if (ctx->num_recorded_hits < max_record_hits) {
/* If maximum number of hits was reached, replace the intersection with the
* highest distance. We want to find the N closest intersections. */
const numhit_t num_recorded_hits = min(ctx->num_recorded_hits, max_record_hits);
numhit_t isect_index = num_recorded_hits;
if (num_recorded_hits + 1 >= max_record_hits) {
float max_t = INTEGRATOR_STATE_ARRAY(ctx->isect_s, shadow_isect, 0, t);
numhit_t max_recorded_hit = numhit_t(0);
for (numhit_t i = numhit_t(1); i < num_recorded_hits; ++i) {
const float isect_t = INTEGRATOR_STATE_ARRAY(ctx->isect_s, shadow_isect, i, t);
if (isect_t > max_t) {
max_recorded_hit = i;
max_t = isect_t;
}
}
if (num_recorded_hits >= max_record_hits) {
isect_index = max_recorded_hit;
}
/* Limit the ray distance and stop counting hits beyond this. */
ray->tfar = max(current_isect.t, max_t);
}
integrator_state_write_shadow_isect(ctx->isect_s, &current_isect, isect_index);
}
numhit_t isect_index = ctx->num_recorded_hits;
/* Always increase the number of recorded hits, even beyond the maximum,
* so that we can detect this and trace another ray if needed. */
* so that we can detect this and trace another ray if needed.
* More details about the related logic can be found in implementation of
* "shadow_intersections_has_remaining" and "integrate_transparent_shadow"
* functions. */
++ctx->num_recorded_hits;
/* This tells Embree to continue tracing. */
*args->valid = 0;
const numhit_t max_record_hits = min(ctx->max_hits, numhit_t(INTEGRATOR_SHADOW_ISECT_SIZE));
/* If the maximum number of hits was reached, replace the furthest intersection
* with a closer one so we get the N closest intersections. */
if (isect_index >= max_record_hits) {
/* When recording only N closest hits, max_t will always only decrease.
* So let's test if we are already not meeting criteria and can skip max_t recalculation. */
if (current_isect.t >= ctx->max_t) {
return;
}
float max_t = INTEGRATOR_STATE_ARRAY(ctx->isect_s, shadow_isect, 0, t);
numhit_t max_recorded_hit = numhit_t(0);
for (numhit_t i = numhit_t(1); i < max_record_hits; ++i) {
const float isect_t = INTEGRATOR_STATE_ARRAY(ctx->isect_s, shadow_isect, i, t);
if (isect_t > max_t) {
max_recorded_hit = i;
max_t = isect_t;
}
}
isect_index = max_recorded_hit;
/* Limit the ray distance and avoid processing hits beyond this. */
ctx->max_t = max_t;
/* If it's further away than max_t, we don't record this transparent intersection. */
if (current_isect.t >= max_t) {
return;
}
}
integrator_state_write_shadow_isect(ctx->isect_s, &current_isect, isect_index);
}
ccl_device_forceinline void kernel_embree_filter_occluded_local_func_impl(

View File

@ -224,7 +224,7 @@ ccl_device void osl_closure_dielectric_bsdf_setup(KernelGlobals kg,
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
}
}
/* GGX (either single- or multiscattering) */
/* GGX (either single- or multi-scattering). */
else {
if (has_reflection && has_transmission) {
sd->flag |= bsdf_microfacet_ggx_glass_setup(bsdf);
@ -278,7 +278,7 @@ ccl_device void osl_closure_conductor_bsdf_setup(KernelGlobals kg,
if (closure->distribution == make_string("beckmann", 14712237670914973463ull)) {
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
}
/* GGX (either single- or multiscattering) */
/* GGX (either single- or multi-scattering) */
else {
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
preserve_energy = (closure->distribution == make_string("multi_ggx", 16842698693386468366ull));
@ -338,7 +338,7 @@ ccl_device void osl_closure_generalized_schlick_bsdf_setup(
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
}
}
/* GGX (either single- or multiscattering) */
/* GGX (either single- or multi-scattering) */
else {
if (has_reflection && has_transmission) {
sd->flag |= bsdf_microfacet_ggx_glass_setup(bsdf);
@ -414,7 +414,7 @@ ccl_device void osl_closure_microfacet_setup(KernelGlobals kg,
else if (closure->distribution == make_string("ashikhmin_shirley", 11318482998918370922ull)) {
sd->flag |= bsdf_ashikhmin_shirley_setup(bsdf);
}
/* GGX (either single- or multiscattering) */
/* GGX (either single- or multi-scattering) */
else {
if (closure->refract == 1) {
sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
@ -523,7 +523,7 @@ ccl_device void osl_closure_microfacet_aniso_fresnel_setup(
bsdf->ior = closure->ior;
bsdf->T = closure->T;
/* Only GGX (either single- or multiscattering) supported here */
/* Only GGX (either single- or multi-scattering) supported here */
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
const bool preserve_energy = (closure->distribution ==

View File

@ -26,7 +26,7 @@ closure color principled_diffuse(normal N, float roughness) BUILTIN;
closure color principled_sheen(normal N) BUILTIN;
closure color principled_clearcoat(normal N, float clearcoat, float clearcoat_roughness) BUILTIN;
/* Needed to pass along the color for multiscattering saturation adjustment,
/* Needed to pass along the color for multi-scattering saturation adjustment,
* otherwise could be replaced by microfacet() */
closure color microfacet_multi_ggx_glass(normal N, float ag, float eta, color C) BUILTIN;
closure color microfacet_multi_ggx_aniso(normal N, vector T, float ax, float ay, color C) BUILTIN;

View File

@ -170,14 +170,15 @@ typedef enum {
GHOST_kModifierKeyNum
} GHOST_TModifierKey;
/**
* \note these values are stored in #wmWindow::windowstate,
* don't change, only add new values.
*/
typedef enum {
GHOST_kWindowStateNormal = 0,
GHOST_kWindowStateMaximized,
GHOST_kWindowStateMinimized,
GHOST_kWindowStateFullScreen,
GHOST_kWindowStateEmbedded,
// GHOST_kWindowStateModified,
// GHOST_kWindowStateUnModified,
GHOST_kWindowStateMaximized = 1,
GHOST_kWindowStateMinimized = 2,
GHOST_kWindowStateFullScreen = 3,
} GHOST_TWindowState;
typedef enum {

View File

@ -332,9 +332,6 @@ static bool gwl_window_state_set_for_libdecor(libdecor_frame *frame,
libdecor_frame_set_fullscreen(frame, nullptr);
break;
}
case GHOST_kWindowStateEmbedded: {
return false;
}
}
return true;
}
@ -377,9 +374,6 @@ static bool gwl_window_state_set_for_xdg(xdg_toplevel *toplevel,
xdg_toplevel_set_fullscreen(toplevel, nullptr);
break;
}
case GHOST_kWindowStateEmbedded: {
return false;
}
}
return true;
}

View File

@ -350,7 +350,7 @@ def main():
if name.rpartition(".")[2].isdigit():
continue
if not ob_eval.data.attributes.active_color:
if (not hasattr(ob_eval.data, 'attributes')) or not ob_eval.data.attributes.active_color:
print("Skipping:", name, "(no vertex colors)")
continue

View File

@ -80,7 +80,7 @@ def keyconfig_update(keyconfig_data, keyconfig_version):
km_items.append(('ROTATE_NORMALS', {"type": 'N', "value": 'PRESS'}, None))
break
if keyconfig_version <= (3, 6, 3):
if keyconfig_version <= (4, 0, 3):
if not has_copy:
keyconfig_data = copy.deepcopy(keyconfig_data)
has_copy = True

View File

@ -1836,6 +1836,10 @@ def km_graph_editor(params):
("graph.delete", {"type": 'DEL', "value": 'PRESS'}, {"properties": [("confirm", False)]}),
("graph.duplicate_move", {"type": 'D', "value": 'PRESS', "shift": True}, None),
("graph.keyframe_insert", {"type": 'I', "value": 'PRESS'}, None),
("graph.keyframe_jump", {"type": 'UP_ARROW', "value": 'PRESS', "repeat": True},
{"properties": [("next", True)]}),
("graph.keyframe_jump", {"type": 'DOWN_ARROW', "value": 'PRESS', "repeat": True},
{"properties": [("next", False)]}),
("graph.click_insert", {"type": params.action_mouse, "value": 'CLICK', "ctrl": True}, None),
("graph.click_insert", {"type": params.action_mouse, "value": 'CLICK', "shift": True, "ctrl": True},
{"properties": [("extend", True)]}),

View File

@ -8,7 +8,6 @@ from bpy.app.translations import pgettext_tip as tip_
def guess_player_path(preset):
import os
import sys
if preset == 'INTERNAL':
@ -17,6 +16,7 @@ def guess_player_path(preset):
elif preset == 'DJV':
player_path = "djv"
if sys.platform == "darwin":
import os
test_path = "/Applications/DJV2.app/Contents/Resources/bin/djv"
if os.path.exists(test_path):
player_path = test_path
@ -141,7 +141,15 @@ class PlayRenderedAnim(Operator):
opts = [file, "%d-%d" % (scene.frame_start, scene.frame_end)]
cmd.extend(opts)
elif preset == 'RV':
opts = ["-fps", str(rd.fps), "-play", "[ %s ]" % file]
opts = ["-fps", str(rd.fps), "-play"]
if scene.use_preview_range:
opts += [
"%s" % file.replace("#", "", file.count('#') - 1),
"%d-%d" % (frame_start, frame_end),
]
else:
opts.append(file)
cmd.extend(opts)
elif preset == 'MPLAYER':
opts = []

View File

@ -937,7 +937,6 @@ def brush_settings_advanced(layout, context, brush, popover=False):
col = layout.column(heading="Auto-Masking", align=True)
col = layout.column(align=True)
col.prop(brush, "use_automasking_topology", text="Topology")
col.prop(brush, "use_automasking_face_sets", text="Face Sets")

View File

@ -764,20 +764,26 @@ class NODE_PT_quality(bpy.types.Panel):
tree = snode.node_tree
prefs = bpy.context.preferences
use_realtime = False
col = layout.column()
if prefs.experimental.use_full_frame_compositor:
if prefs.experimental.use_experimental_compositors:
col.prop(tree, "execution_mode")
use_realtime = tree.execution_mode == 'REALTIME'
col = layout.column()
col.active = not use_realtime
col.prop(tree, "render_quality", text="Render")
col.prop(tree, "edit_quality", text="Edit")
col.prop(tree, "chunk_size")
col = layout.column()
col.active = not use_realtime
col.prop(tree, "use_opencl")
col.prop(tree, "use_groupnode_buffer")
col.prop(tree, "use_two_pass")
col.prop(tree, "use_viewer_border")
col.separator()
col = layout.column()
col.prop(snode, "use_auto_render")

View File

@ -25,7 +25,7 @@ if "_icon_cache" in locals():
del release
# (filename -> icon_value) map
# (icon_name -> icon_value) map
_icon_cache = {}
@ -236,14 +236,14 @@ class ToolSelectPanelHelper:
icon_value = _icon_cache.get(icon_name)
if icon_value is None:
dirname = bpy.utils.system_resource('DATAFILES', path="icons")
filename = os.path.join(dirname, icon_name + ".dat")
filepath = os.path.join(dirname, icon_name + ".dat")
try:
icon_value = bpy.app.icons.new_triangles_from_file(filename)
icon_value = bpy.app.icons.new_triangles_from_file(filepath)
except Exception as ex:
if not os.path.exists(filename):
print("Missing icons:", filename, ex)
if not os.path.exists(filepath):
print("Missing icons:", filepath, ex)
else:
print("Corrupt icon:", filename, ex)
print("Corrupt icon:", filepath, ex)
# Use none as a fallback (avoids layout issues).
if icon_name != "none":
icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle("none")

View File

@ -3111,7 +3111,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
*_tools_annotate,
],
'EDIT_GPENCIL': [
*_tools_gpencil_select,
*_tools_select,
_defs_view3d_generic.cursor,
None,
*_tools_transform,

View File

@ -2423,7 +2423,7 @@ class USERPREF_PT_experimental_prototypes(ExperimentalPanel, Panel):
({"property": "use_new_curves_tools"}, ("blender/blender/issues/68981", "#68981")),
({"property": "use_new_point_cloud_type"}, ("blender/blender/issues/75717", "#75717")),
({"property": "use_sculpt_texture_paint"}, ("blender/blender/issues/96225", "#96225")),
({"property": "use_full_frame_compositor"}, ("blender/blender/issues/88150", "#88150")),
({"property": "use_experimental_compositors"}, ("blender/blender/issues/88150", "#88150")),
({"property": "enable_eevee_next"}, ("blender/blender/issues/93220", "#93220")),
({"property": "enable_workbench_next"}, ("blender/blender/issues/101619", "#101619")),
({"property": "use_grease_pencil_version3"}, ("blender/blender/projects/40", "Grease Pencil 3.0")),

View File

@ -2028,7 +2028,7 @@ class VIEW3D_MT_select_edit_gpencil(Menu):
layout.operator("grease_pencil.select_all", text="None").action = 'DESELECT'
layout.operator("grease_pencil.select_all", text="Invert").action = 'INVERT'
layout.separator()
layout.separator()
class VIEW3D_MT_select_paint_mask(Menu):

View File

@ -38,6 +38,13 @@ typedef struct AssetTypeInfo {
struct AssetMetaData *BKE_asset_metadata_create(void);
void BKE_asset_metadata_free(struct AssetMetaData **asset_data);
/**
* Create a copy of the #AssetMetaData so that it can be assigned to another asset.
*
* The caller becomes the owner of the returned pointer.
*/
struct AssetMetaData *BKE_asset_metadata_copy(const struct AssetMetaData *source);
struct AssetTagEnsureResult {
struct AssetTag *tag;
/* Set to false if a tag of this name was already present. */

View File

@ -65,7 +65,7 @@ void BKE_blendfile_read_setup_readfile(struct bContext *C,
const char *startup_app_template);
/**
* Simpler version of #BKE_blendfile_read_setup_readfile used when reading undoe steps from
* Simpler version of #BKE_blendfile_read_setup_readfile used when reading undo steps from
* memfile. */
void BKE_blendfile_read_setup_undo(struct bContext *C,
struct BlendFileData *bfd,

View File

@ -51,5 +51,8 @@ struct GeometryDeformation {
GeometryDeformation get_evaluated_curves_deformation(const Object *ob_eval, const Object &ob_orig);
GeometryDeformation get_evaluated_curves_deformation(const Depsgraph &depsgraph,
const Object &ob_orig);
GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object *ob_eval,
const Object &ob_orig,
int drawing_index);
} // namespace blender::bke::crazyspace

View File

@ -75,15 +75,13 @@ bool BKE_texture_dependsOnTime(const struct Tex *texture);
*/
bool BKE_texture_is_image_user(const struct Tex *tex);
void BKE_texture_get_value_ex(const struct Scene *scene,
struct Tex *texture,
void BKE_texture_get_value_ex(struct Tex *texture,
const float *tex_co,
struct TexResult *texres,
struct ImagePool *pool,
bool use_color_management);
void BKE_texture_get_value(const struct Scene *scene,
struct Tex *texture,
void BKE_texture_get_value(struct Tex *texture,
const float *tex_co,
struct TexResult *texres,
bool use_color_management);

View File

@ -21,6 +21,7 @@ struct MovieClipUser;
struct MovieDistortion;
struct MovieReconstructContext;
struct MovieTracking;
struct MovieTrackingCamera;
struct MovieTrackingMarker;
struct MovieTrackingObject;
struct MovieTrackingPlaneMarker;
@ -464,6 +465,16 @@ void BKE_tracking_camera_principal_point_pixel_get(struct MovieClip *clip,
void BKE_tracking_camera_principal_point_pixel_set(struct MovieClip *clip,
const float principal_point_pixel[2]);
/* Compares distortion related parameters of camera. Ideally, this implementation will be
* abstracted away in the future, but for now, one needs to be careful about it and handle any
* extra parameters of distortions models. */
bool BKE_tracking_camera_distortion_equal(const struct MovieTrackingCamera *a,
const struct MovieTrackingCamera *b);
/* Hashes distortion related parameters of camera. Ideally, this implementation will be
* abstracted away in the future, but for now, one needs to be careful about it and handle any
* extra parameters of distortions models. */
uint64_t BKE_tracking_camera_distortion_hash(const struct MovieTrackingCamera *camera);
/* --------------------------------------------------------------------
* (Un)distortion.
*/

View File

@ -1852,7 +1852,7 @@ void BKE_pose_blend_write(BlendWriter *writer, bPose *pose, bArmature *arm)
animviz_motionpath_blend_write(writer, chan->mpath);
/* Prevent crashes with autosave,
/* Prevent crashes with auto-save,
* when a bone duplicated in edit-mode has not yet been assigned to its pose-channel.
* Also needed with memundo, in some cases we can store a step before pose has been
* properly rebuilt from previous undo step. */

View File

@ -114,10 +114,10 @@ AnimData *BKE_animdata_ensure_id(ID *id)
return NULL;
}
/* Action / Tmpact Setter shared code -------------------------
/* Action / `tmpact` Setter shared code -------------------------
*
* Both the action and tmpact setter functions have essentially
* identical semantics, because tmpact is just a place to temporarily
* Both the action and `tmpact` setter functions have essentially
* identical semantics, because `tmpact` is just a place to temporarily
* store the main action during tweaking. This function contains the
* shared code between those two setter functions, setting the action
* of the passed `act_slot` to `act`.

View File

@ -65,7 +65,7 @@ static void pchan_deform_accumulate(const DualQuat *deform_dq,
BLI_assert(!co_accum);
if (deform_dq->scale_weight) {
/* FIX https://projects.blender.org/blender/blender/issues/32022 */
/* FIX #32022. */
DualQuat mdq = *deform_dq;
float dst[3];
mul_v3_m4v3(dst, mdq.scale, co_in);

View File

@ -39,6 +39,38 @@ void BKE_asset_metadata_free(AssetMetaData **asset_data)
*asset_data = nullptr;
}
AssetMetaData *BKE_asset_metadata_copy(const AssetMetaData *source)
{
AssetMetaData *copy = BKE_asset_metadata_create();
copy->local_type_info = source->local_type_info;
if (source->properties) {
copy->properties = IDP_CopyProperty(source->properties);
}
BKE_asset_metadata_catalog_id_set(copy, source->catalog_id, source->catalog_simple_name);
if (source->author) {
copy->author = BLI_strdup(source->author);
}
if (source->description) {
copy->description = BLI_strdup(source->description);
}
if (source->copyright) {
copy->copyright = BLI_strdup(source->copyright);
}
if (source->license) {
copy->license = BLI_strdup(source->license);
}
BLI_duplicatelist(&copy->tags, &source->tags);
copy->active_tag = source->active_tag;
copy->tot_tags = source->tot_tags;
return copy;
}
AssetMetaData::~AssetMetaData()
{
if (properties) {

View File

@ -208,14 +208,13 @@ static void setup_app_userdef(BlendFileData *bfd)
BKE_blender_userdef_data_set_and_free(bfd->user);
bfd->user = nullptr;
/* Security issue: any blend file could include a USER block.
/* Security issue: any blend file could include a #BLO_CODE_USER block.
*
* Currently we load prefs from BLENDER_STARTUP_FILE and later on load BLENDER_USERPREF_FILE,
* to load the preferences defined in the users home dir.
* Preferences are loaded from #BLENDER_STARTUP_FILE and later on load #BLENDER_USERPREF_FILE,
* to load the preferences defined in the users home directory.
*
* This means we will never accidentally (or maliciously)
* enable scripts auto-execution by loading a '.blend' file.
*/
* enable scripts auto-execution by loading a `.blend` file. */
U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
}
}
@ -251,7 +250,7 @@ typedef struct ReuseOldBMainData {
* NOTE: The case where the `old_bmain` would be a library in the newly read one is not handled
* here, as it does not create explicit issues. The local data from `old_bmain` is either
* discarded, or added to the `new_bmain` as local data as well. Worst case, there will be a
* doublon of a linked data as a local one, without any known relationships between them. In
* double of a linked data as a local one, without any known relationships between them. In
* practice, this latter case is not expected to commonly happen.
*/
static IDRemapper *reuse_bmain_data_remapper_ensure(ReuseOldBMainData *reuse_data)
@ -747,7 +746,7 @@ static void setup_app_data(bContext *C,
wmWindow *win = nullptr;
bScreen *curscreen = nullptr;
/* Ensure that there is a valid scene and viewlayer. */
/* Ensure that there is a valid scene and view-layer. */
if (curscene == nullptr) {
curscene = static_cast<Scene *>(bfd->main->scenes.first);
}
@ -904,7 +903,7 @@ static void setup_app_data(bContext *C,
bmain->filepath[0] = '\0';
}
else if (recover) {
/* In case of autosave or quit.blend, use original filepath instead. */
/* In case of auto-save or quit.blend, use original filepath instead. */
bmain->recovered = true;
STRNCPY(bmain->filepath, bfd->filepath);
}

View File

@ -24,6 +24,7 @@
#include "BKE_curves.hh"
#include "BKE_editmesh.h"
#include "BKE_geometry_set.hh"
#include "BKE_grease_pencil.hh"
#include "BKE_lib_id.h"
#include "BKE_mesh.hh"
#include "BKE_mesh_wrapper.h"
@ -662,4 +663,37 @@ GeometryDeformation get_evaluated_curves_deformation(const Depsgraph &depsgraph,
return get_evaluated_curves_deformation(ob_eval, ob_orig);
}
GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object *ob_eval,
const Object &ob_orig,
const int drawing_index)
{
BLI_assert(ob_orig.type == OB_GREASE_PENCIL);
const GreasePencil &grease_pencil_orig = *static_cast<const GreasePencil *>(ob_orig.data);
GreasePencilDrawingBase *drawing_base = grease_pencil_orig.drawings()[drawing_index];
GeometryDeformation deformation;
if (drawing_base->type == GP_DRAWING) {
GreasePencilDrawing *drawing = reinterpret_cast<GreasePencilDrawing *>(drawing_base);
/* Use the undeformed positions by default. */
deformation.positions = drawing->geometry.wrap().positions();
}
else if (drawing_base->type == GP_DRAWING_REFERENCE) {
/* TODO */
}
if (ob_eval == nullptr) {
return deformation;
}
const GeometrySet *geometry_eval = ob_eval->runtime.geometry_set_eval;
if (geometry_eval == nullptr) {
return deformation;
}
/* TODO: Read `GeometryComponentEditData` from `geometry_eval` and populate deformation with it.
*/
return deformation;
}
} // namespace blender::bke::crazyspace

View File

@ -1931,7 +1931,7 @@ static void sample_mesh(FluidFlowSettings *ffs,
tex_co[1] = tex_co[1] * 2.0f - 1.0f;
tex_co[2] = ffs->texture_offset;
}
BKE_texture_get_value(nullptr, ffs->noise_texture, tex_co, &texres, false);
BKE_texture_get_value(ffs->noise_texture, tex_co, &texres, false);
emission_strength *= texres.tin;
}
}

View File

@ -1061,7 +1061,7 @@ enum ForeachDrawingMode {
static void foreach_drawing_ex(GreasePencil &grease_pencil,
int frame,
ForeachDrawingMode mode,
blender::FunctionRef<void(GreasePencilDrawing &)> function)
blender::FunctionRef<void(int, GreasePencilDrawing &)> function)
{
using namespace blender::bke::greasepencil;
@ -1089,7 +1089,7 @@ static void foreach_drawing_ex(GreasePencil &grease_pencil,
GreasePencilDrawingBase *drawing_base = drawings[index];
if (drawing_base->type == GP_DRAWING) {
GreasePencilDrawing *drawing = reinterpret_cast<GreasePencilDrawing *>(drawing_base);
function(*drawing);
function(index, *drawing);
}
else if (drawing_base->type == GP_DRAWING_REFERENCE) {
/* TODO */
@ -1098,13 +1098,13 @@ static void foreach_drawing_ex(GreasePencil &grease_pencil,
}
void GreasePencil::foreach_visible_drawing(
int frame, blender::FunctionRef<void(GreasePencilDrawing &)> function)
int frame, blender::FunctionRef<void(int, GreasePencilDrawing &)> function)
{
foreach_drawing_ex(*this, frame, VISIBLE, function);
}
void GreasePencil::foreach_editable_drawing(
int frame, blender::FunctionRef<void(GreasePencilDrawing &)> function)
int frame, blender::FunctionRef<void(int, GreasePencilDrawing &)> function)
{
foreach_drawing_ex(*this, frame, EDITABLE, function);
}

View File

@ -14,7 +14,7 @@
*
* Usage:
*
* ```
* \code{.cc}
* Image *image = ...;
* ImBuf *image_buffer = ...;
*
@ -44,8 +44,7 @@
*
* // Free partial_update_user.
* BKE_image_partial_update_free(partial_update_user);
*
* ```
* \endcode
*/
#include <optional>

View File

@ -331,7 +331,6 @@ static void library_foreach_node_socket(LibraryForeachIDData *data, bNodeSocket
case SOCK_BOOLEAN:
case SOCK_INT:
case SOCK_STRING:
case SOCK_MESH_DEPRECATED:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:
@ -479,7 +478,6 @@ static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *so
case SOCK_CUSTOM:
/* Custom node sockets where default_value is defined uses custom properties for storage. */
break;
case SOCK_MESH_DEPRECATED:
case SOCK_SHADER:
case SOCK_GEOMETRY:
BLI_assert_unreachable();
@ -934,7 +932,6 @@ static void lib_link_node_socket(BlendLibReader *reader, ID *self_id, bNodeSocke
case SOCK_BOOLEAN:
case SOCK_INT:
case SOCK_STRING:
case SOCK_MESH_DEPRECATED:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:
@ -1027,7 +1024,6 @@ static void expand_node_socket(BlendExpander *expander, bNodeSocket *sock)
case SOCK_BOOLEAN:
case SOCK_INT:
case SOCK_STRING:
case SOCK_MESH_DEPRECATED:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:
@ -1716,7 +1712,6 @@ static void socket_id_user_increment(bNodeSocket *sock)
case SOCK_BOOLEAN:
case SOCK_INT:
case SOCK_STRING:
case SOCK_MESH_DEPRECATED:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:
@ -1762,7 +1757,6 @@ static bool socket_id_user_decrement(bNodeSocket *sock)
case SOCK_BOOLEAN:
case SOCK_INT:
case SOCK_STRING:
case SOCK_MESH_DEPRECATED:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:
@ -1815,7 +1809,6 @@ void nodeModifySocketType(bNodeTree *ntree,
case SOCK_SHADER:
case SOCK_BOOLEAN:
case SOCK_CUSTOM:
case SOCK_MESH_DEPRECATED:
case SOCK_OBJECT:
case SOCK_IMAGE:
case SOCK_GEOMETRY:
@ -1955,7 +1948,6 @@ const char *nodeStaticSocketType(const int type, const int subtype)
case SOCK_MATERIAL:
return "NodeSocketMaterial";
case SOCK_CUSTOM:
case SOCK_MESH_DEPRECATED:
break;
}
return nullptr;
@ -2035,7 +2027,6 @@ const char *nodeStaticSocketInterfaceType(const int type, const int subtype)
case SOCK_MATERIAL:
return "NodeSocketInterfaceMaterial";
case SOCK_CUSTOM:
case SOCK_MESH_DEPRECATED:
break;
}
return nullptr;
@ -2071,7 +2062,6 @@ const char *nodeStaticSocketLabel(const int type, const int /*subtype*/)
case SOCK_MATERIAL:
return "Material";
case SOCK_CUSTOM:
case SOCK_MESH_DEPRECATED:
break;
}
return nullptr;
@ -2593,7 +2583,6 @@ static void *socket_value_storage(bNodeSocket &socket)
case SOCK_STRING:
/* We don't want do this now! */
return nullptr;
case SOCK_MESH_DEPRECATED:
case SOCK_CUSTOM:
case SOCK_SHADER:
case SOCK_GEOMETRY:

View File

@ -705,22 +705,15 @@ bool BKE_texture_dependsOnTime(const Tex *texture)
/* ------------------------------------------------------------------------- */
void BKE_texture_get_value_ex(const Scene *scene,
Tex *texture,
void BKE_texture_get_value_ex(Tex *texture,
const float *tex_co,
TexResult *texres,
ImagePool *pool,
bool use_color_management)
{
int result_type;
bool do_color_manage = false;
if (scene && use_color_management) {
do_color_manage = BKE_scene_check_color_management_enabled(scene);
}
/* no node textures for now */
result_type = multitex_ext_safe(texture, tex_co, texres, pool, do_color_manage, false);
const int result_type = multitex_ext_safe(
texture, tex_co, texres, pool, use_color_management, false);
/* if the texture gave an RGB value, we assume it didn't give a valid
* intensity, since this is in the context of modifiers don't use perceptual color conversion.
@ -734,13 +727,12 @@ void BKE_texture_get_value_ex(const Scene *scene,
}
}
void BKE_texture_get_value(const Scene *scene,
Tex *texture,
void BKE_texture_get_value(Tex *texture,
const float *tex_co,
TexResult *texres,
bool use_color_management)
{
BKE_texture_get_value_ex(scene, texture, tex_co, texres, nullptr, use_color_management);
BKE_texture_get_value_ex(texture, tex_co, texres, nullptr, use_color_management);
}
static void texture_nodes_fetch_images_for_pool(Tex *texture, bNodeTree *ntree, ImagePool *pool)

View File

@ -6,6 +6,7 @@
* \ingroup bke
*/
#include <cstdint>
#include <limits.h>
#include <math.h>
#include <memory.h>
@ -23,9 +24,12 @@
#include "BLI_bitmap_draw_2d.h"
#include "BLI_ghash.h"
#include "BLI_hash.hh"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_math_base.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector_types.hh"
#include "BLI_string.h"
#include "BLI_string_utils.h"
#include "BLI_threads.h"
@ -2197,6 +2201,66 @@ void BKE_tracking_camera_principal_point_pixel_set(MovieClip *clip,
principal_point_pixel, frame_width, frame_height, camera->principal_point);
}
bool BKE_tracking_camera_distortion_equal(const MovieTrackingCamera *a,
const MovieTrackingCamera *b)
{
if (a->pixel_aspect != b->pixel_aspect || a->focal != b->focal ||
!equals_v2v2(a->principal_point, b->principal_point))
{
return false;
}
if (a->distortion_model != b->distortion_model) {
return false;
}
switch (a->distortion_model) {
case TRACKING_DISTORTION_MODEL_POLYNOMIAL:
return a->k1 == b->k1 && a->k2 == b->k2 && a->k3 == b->k3;
case TRACKING_DISTORTION_MODEL_DIVISION:
return a->division_k1 == b->division_k1 && a->division_k2 == b->division_k2;
case TRACKING_DISTORTION_MODEL_NUKE:
return a->nuke_k1 == b->nuke_k1 && a->nuke_k2 == b->nuke_k2;
case TRACKING_DISTORTION_MODEL_BROWN:
return a->brown_k1 == b->brown_k1 && a->brown_k2 == b->brown_k2 &&
a->brown_k3 == b->brown_k3 && a->brown_k4 == b->brown_k4 &&
a->brown_p1 == b->brown_p1 && a->brown_p2 == b->brown_p2;
}
BLI_assert_unreachable();
return false;
}
uint64_t BKE_tracking_camera_distortion_hash(const MovieTrackingCamera *camera)
{
using namespace blender;
switch (camera->distortion_model) {
case TRACKING_DISTORTION_MODEL_POLYNOMIAL:
return get_default_hash_4(camera->distortion_model,
float2(camera->pixel_aspect, camera->focal),
float2(camera->principal_point),
float3(camera->k1, camera->k2, camera->k3));
case TRACKING_DISTORTION_MODEL_DIVISION:
return get_default_hash_4(camera->distortion_model,
float2(camera->pixel_aspect, camera->focal),
float2(camera->principal_point),
float2(camera->division_k1, camera->division_k2));
case TRACKING_DISTORTION_MODEL_NUKE:
return get_default_hash_4(camera->distortion_model,
float2(camera->pixel_aspect, camera->focal),
float2(camera->principal_point),
float2(camera->nuke_k1, camera->nuke_k2));
case TRACKING_DISTORTION_MODEL_BROWN:
return get_default_hash_4(
float2(camera->pixel_aspect, camera->focal),
float2(camera->principal_point),
float4(camera->brown_k1, camera->brown_k2, camera->brown_k3, camera->brown_k4),
float2(camera->brown_p1, camera->brown_p2));
}
BLI_assert_unreachable();
return 0;
}
/* --------------------------------------------------------------------
* (Un)distortion.
*/

View File

@ -205,8 +205,8 @@ eFileAttributes BLI_file_attributes(const char *path);
* Usage of this function is strongly discouraged as it is not thread safe. It will likely cause
* issues if there is an operation on another thread that does not expect the current working
* directory to change. This has been added to support USDZ export, which has a problematic
* "feature" described in this issue https://projects.blender.org/blender/blender/issues/99807. It
* will be removed if it is possible to resolve that issue upstream in the USD library.
* "feature" described in this issue #99807. It will be removed if it is possible to resolve
* that issue upstream in the USD library.
*
* \return true on success, false otherwise.
*/

View File

@ -91,6 +91,11 @@ template<typename T> inline T floor(const T &a)
return std::floor(a);
}
template<typename T> inline T round(const T &a)
{
return std::round(a);
}
/**
* Repeats the saw-tooth pattern even on negative numbers.
* ex: `mod_periodic(-3, 4) = 1`, `mod(-3, 4)= -3`
@ -127,6 +132,20 @@ template<typename T> inline T sqrt(const T &a)
return std::sqrt(a);
}
/* Inverse value.
* If the input is zero the output is NaN. */
template<typename T> inline T rcp(const T &a)
{
return T(1) / a;
}
/* Inverse value.
* If the input is zero the output is zero. */
template<typename T> inline T safe_rcp(const T &a)
{
return a ? T(1) / a : T(0);
}
template<typename T> inline T cos(const T &a)
{
return std::cos(a);

View File

@ -111,7 +111,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result = a;
for (int i = 0; i < Size; i++) {
result[i] = std::clamp(result[i], min[i], max[i]);
result[i] = math::clamp(result[i], min[i], max[i]);
}
return result;
}
@ -121,7 +121,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result = a;
for (int i = 0; i < Size; i++) {
result[i] = std::clamp(result[i], min, max);
result[i] = math::clamp(result[i], min, max);
}
return result;
}
@ -132,7 +132,7 @@ template<typename T, int Size>
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
BLI_assert(b[i] != 0);
result[i] = std::fmod(a[i], b[i]);
result[i] = math::mod(a[i], b[i]);
}
return result;
}
@ -143,7 +143,7 @@ template<typename T, int Size>
BLI_assert(b != 0);
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::fmod(a[i], b);
result[i] = math::mod(a[i], b);
}
return result;
}
@ -157,7 +157,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = (b[i] != 0) ? std::fmod(a[i], b[i]) : 0;
result[i] = (b[i] != 0) ? math::mod(a[i], b[i]) : 0;
}
return result;
}
@ -173,7 +173,7 @@ template<typename T, int Size>
}
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::fmod(a[i], b);
result[i] = math::mod(a[i], b);
}
return result;
}
@ -187,7 +187,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::pow(x[i], y);
result[i] = math::pow(x[i], y);
}
return result;
}
@ -201,7 +201,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::pow(x[i], y[i]);
result[i] = math::pow(x[i], y[i]);
}
return result;
}
@ -276,7 +276,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::floor(a[i]);
result[i] = math::floor(a[i]);
}
return result;
}
@ -286,7 +286,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::round(a[i]);
result[i] = math::round(a[i]);
}
return result;
}
@ -296,7 +296,62 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = std::ceil(a[i]);
result[i] = math::ceil(a[i]);
}
return result;
}
/**
* Per-element square root.
* Negative elements are evaluated to NaN.
*/
template<typename T, int Size>
[[nodiscard]] inline VecBase<T, Size> sqrt(const VecBase<T, Size> &a)
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = math::sqrt(a[i]);
}
return result;
}
/**
* Per-element square root.
* Negative elements are evaluated to zero.
*/
template<typename T, int Size>
[[nodiscard]] inline VecBase<T, Size> safe_sqrt(const VecBase<T, Size> &a)
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = a[i] >= T(0) ? math ::sqrt(a[i]) : T(0);
}
return result;
}
/**
* Per-element inverse.
* Zero elements are evaluated to NaN.
*/
template<typename T, int Size> [[nodiscard]] inline VecBase<T, Size> rcp(const VecBase<T, Size> &a)
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = math::rcp(a[i]);
}
return result;
}
/**
* Per-element inverse.
* Zero elements are evaluated to zero.
*/
template<typename T, int Size>
[[nodiscard]] inline VecBase<T, Size> safe_rcp(const VecBase<T, Size> &a)
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = math::safe_rcp(a[i]);
}
return result;
}
@ -306,7 +361,7 @@ template<typename T, int Size>
{
VecBase<T, Size> result;
for (int i = 0; i < Size; i++) {
result[i] = a[i] - std::floor(a[i]);
result[i] = math::fract(a[i]);
}
return result;
}
@ -332,9 +387,9 @@ template<typename T, int Size>
*/
template<typename T, int Size> [[nodiscard]] inline T length_manhattan(const VecBase<T, Size> &a)
{
T result = std::abs(a[0]);
T result = math::abs(a[0]);
for (int i = 1; i < Size; i++) {
result += std::abs(a[i]);
result += math::abs(a[i]);
}
return result;
}
@ -346,7 +401,7 @@ template<typename T, int Size> [[nodiscard]] inline T length_squared(const VecBa
template<typename T, int Size> [[nodiscard]] inline T length(const VecBase<T, Size> &a)
{
return std::sqrt(length_squared(a));
return math::sqrt(length_squared(a));
}
/** Return true if each individual column is unit scaled. Mainly for assert usage. */
@ -356,8 +411,8 @@ template<typename T, int Size> [[nodiscard]] inline bool is_unit_scale(const Vec
* normalized and in the case we don't want NAN to be raising asserts since there
* is nothing to be done in that case. */
const T test_unit = math::length_squared(v);
return (!(std::abs(test_unit - T(1)) >= AssertUnitEpsilon<T>::value) ||
!(std::abs(test_unit) >= AssertUnitEpsilon<T>::value));
return (!(math::abs(test_unit - T(1)) >= AssertUnitEpsilon<T>::value) ||
!(math::abs(test_unit) >= AssertUnitEpsilon<T>::value));
}
template<typename T, int Size>
@ -593,7 +648,7 @@ template<typename T, int Size>
const T epsilon = T(0))
{
for (int i = 0; i < Size; i++) {
if (std::abs(a[i] - b[i]) > epsilon) {
if (math::abs(a[i] - b[i]) > epsilon) {
return false;
}
}

View File

@ -253,7 +253,7 @@ static float BLI_convexhull_aabb_fit_hull_2d(const float (*points_hull)[2], int
i_prev = i;
}
return (area_best != FLT_MAX) ? atan2f(dvec_best[0], dvec_best[1]) : 0.0f;
return (area_best != FLT_MAX) ? (float)atan2(dvec_best[0], dvec_best[1]) : 0.0f;
}
float BLI_convexhull_aabb_fit_points_2d(const float (*points)[2], int n)

View File

@ -136,4 +136,40 @@ TEST(math_vector, Sign)
EXPECT_FLOAT_EQ(result.z, 0);
}
TEST(math_vector, sqrt)
{
const float3 a(1.0f, 4.0f, 9.0f);
const float3 result = math::sqrt(a);
EXPECT_NEAR(result.x, 1.0f, 1e-6f);
EXPECT_NEAR(result.y, 2.0f, 1e-6f);
EXPECT_NEAR(result.z, 3.0f, 1e-6f);
}
TEST(math_vector, safe_sqrt)
{
const float3 a(1.0f, -4.0f, 9.0f);
const float3 result = math::safe_sqrt(a);
EXPECT_NEAR(result.x, 1.0f, 1e-6f);
EXPECT_NEAR(result.y, 0.0f, 1e-6f);
EXPECT_NEAR(result.z, 3.0f, 1e-6f);
}
TEST(math_vector, rcp)
{
const float3 a(1.0f, 2.0f, 4.0f);
const float3 result = math::rcp(a);
EXPECT_NEAR(result.x, 1.0f, 1e-6f);
EXPECT_NEAR(result.y, 0.5f, 1e-6f);
EXPECT_NEAR(result.z, 0.25f, 1e-6f);
}
TEST(math_vector, safe_rcp)
{
const float3 a(1.0f, 0.0f, 4.0f);
const float3 result = math::safe_rcp(a);
EXPECT_NEAR(result.x, 1.0f, 1e-6f);
EXPECT_NEAR(result.y, 0.0f, 1e-6f);
EXPECT_NEAR(result.z, 0.25f, 1e-6f);
}
} // namespace blender::tests

View File

@ -47,8 +47,8 @@ typedef struct WorkspaceConfigFileData {
typedef enum eBlenFileType {
BLENFILETYPE_BLEND = 1,
/* BLENFILETYPE_PUB = 2, */ /* UNUSED */
/* BLENFILETYPE_RUNTIME = 3, */ /* UNUSED */
// BLENFILETYPE_PUB = 2, /* UNUSED */
// BLENFILETYPE_RUNTIME = 3, /* UNUSED */
} eBlenFileType;
typedef struct BlendFileData {
@ -59,17 +59,24 @@ typedef struct BlendFileData {
int globalf;
char filepath[1024]; /* 1024 = FILE_MAX */
struct bScreen *curscreen; /* TODO: think this isn't needed anymore? */
/** TODO: think this isn't needed anymore? */
struct bScreen *curscreen;
struct Scene *curscene;
struct ViewLayer *cur_view_layer; /* layer to activate in workspaces when reading without UI */
/** Layer to activate in workspaces when reading without UI. */
struct ViewLayer *cur_view_layer;
eBlenFileType type;
} BlendFileData;
/** Data used by WM readfile code and BKE's setup_app_data to handle the complex preservation logic
* of WindowManager and other UI data-blocks across blendfile reading prcess. */
/**
* Data used by WM readfile code and BKE's setup_app_data to handle the complex preservation logic
* of WindowManager and other UI data-blocks across blend-file reading process.
*/
typedef struct BlendFileReadWMSetupData {
struct wmWindowManager *old_wm; /** The existing WM when filereading process is started. */
/** The existing WM when filereading process is started. */
struct wmWindowManager *old_wm;
bool is_read_homefile;
} BlendFileReadWMSetupData;
struct BlendFileReadParams {
@ -81,10 +88,10 @@ struct BlendFileReadParams {
};
typedef struct BlendFileReadReport {
/* General reports handling. */
/** General reports handling. */
struct ReportList *reports;
/* Timing information. */
/** Timing information. */
struct {
double whole;
double libraries;
@ -93,38 +100,44 @@ typedef struct BlendFileReadReport {
double lib_overrides_recursive_resync;
} duration;
/* Count information. */
/** Count information. */
struct {
/* Some numbers of IDs that ended up in a specific state, or required some specific process
* during this file read. */
/**
* Some numbers of IDs that ended up in a specific state, or required some specific process
* during this file read.
*/
int missing_libraries;
int missing_linked_id;
/* Some sub-categories of the above `missing_linked_id` counter. */
/** Some sub-categories of the above `missing_linked_id` counter. */
int missing_obdata;
int missing_obproxies;
/* Number of root override IDs that were resynced. */
/** Number of root override IDs that were resynced. */
int resynced_lib_overrides;
/* Number of proxies converted to library overrides. */
/** Number of proxies converted to library overrides. */
int proxies_to_lib_overrides_success;
/* Number of proxies that failed to convert to library overrides. */
/** Number of proxies that failed to convert to library overrides. */
int proxies_to_lib_overrides_failures;
/* Number of sequencer strips that were not read because were in non-supported channels. */
/** Number of sequencer strips that were not read because were in non-supported channels. */
int sequence_strips_skipped;
} count;
/* Number of libraries which had overrides that needed to be resynced, and a single linked list
* of those. */
/**
* Number of libraries which had overrides that needed to be resynced,
* and a single linked list of those.
*/
int resynced_lib_overrides_libraries_count;
bool do_resynced_lib_overrides_libraries_list;
struct LinkNode *resynced_lib_overrides_libraries;
} BlendFileReadReport;
/* skip reading some data-block types (may want to skip screen data too). */
/** Skip reading some data-block types (may want to skip screen data too). */
typedef enum eBLOReadSkip {
BLO_READ_SKIP_NONE = 0,
/** Skip #BLO_CODE_USER blocks. */
BLO_READ_SKIP_USERDEF = (1 << 0),
/** Only read #BLO_CODE_USER (and associated data). */
BLO_READ_SKIP_DATA = (1 << 1),
/** Do not attempt to re-use IDs from old bmain for unchanged ones in case of undo. */
BLO_READ_SKIP_UNDO_OLD_MAIN = (1 << 2),
@ -133,7 +146,7 @@ ENUM_OPERATORS(eBLOReadSkip, BLO_READ_SKIP_UNDO_OLD_MAIN)
#define BLO_READ_SKIP_ALL (BLO_READ_SKIP_USERDEF | BLO_READ_SKIP_DATA)
/**
* Open a blender file from a pathname. The function returns NULL
* Open a blender file from a `filepath`. The function returns NULL
* and sets a report in the list if it cannot open the file.
*
* \param filepath: The path of the file to open.
@ -189,10 +202,12 @@ typedef struct BLODataBlockInfo {
char name[64]; /* MAX_NAME */
struct AssetMetaData *asset_data;
bool free_asset_data;
/* Optimization: Tag data-blocks for which we know there is no preview.
/**
* Optimization: Tag data-blocks for which we know there is no preview.
* Knowing this can be used to skip the (potentially expensive) preview loading process. If this
* is set to true it means we looked for a preview and couldn't find one. False may mean that
* either no preview was found, or that it wasn't looked for in the first place. */
* either no preview was found, or that it wasn't looked for in the first place.
*/
bool no_preview_found;
} BLODataBlockInfo;
@ -336,9 +351,11 @@ typedef enum eBLOLibLinkFlags {
BLO_LIBLINK_FORCE_INDIRECT = 1 << 17,
/** Set fake user on appended IDs. */
BLO_LIBLINK_APPEND_SET_FAKEUSER = 1 << 19,
/** Append (make local) also indirect dependencies of appended IDs coming from other libraries.
/**
* Append (make local) also indirect dependencies of appended IDs coming from other libraries.
* NOTE: All IDs (including indirectly linked ones) coming from the same initial library are
* always made local. */
* always made local.
*/
BLO_LIBLINK_APPEND_RECURSIVE = 1 << 20,
/** Try to re-use previously appended matching ID on new append. */
BLO_LIBLINK_APPEND_LOCAL_ID_REUSE = 1 << 21,
@ -437,7 +454,7 @@ typedef struct TempLibraryContext {
struct LibraryLink_Params liblink_params;
struct Library *lib;
/* The ID datablock that was loaded. Is NULL if loading failed. */
/** The ID datablock that was loaded. Is NULL if loading failed. */
struct ID *temp_id;
} TempLibraryContext;
@ -485,7 +502,7 @@ void BLO_expand_main(void *fdhandle, struct Main *mainvar);
void BLO_update_defaults_startup_blend(struct Main *bmain, const char *app_template);
void BLO_update_defaults_workspace(struct WorkSpace *workspace, const char *app_template);
/* Disable unwanted experimental feature settings on startup. */
/** Disable unwanted experimental feature settings on startup. */
void BLO_sanitize_experimental_features_userpref_blend(struct UserDef *userdef);
/**
@ -498,8 +515,9 @@ void BLO_sanitize_experimental_features_userpref_blend(struct UserDef *userdef);
*/
struct BlendThumbnail *BLO_thumbnail_from_file(const char *filepath);
/* datafiles (generated theme) */
/** Default theme, see: `release/datafiles/userdef/userdef_default_theme.c`. */
extern const struct bTheme U_theme_default;
/** Default preferences, defined by: `release/datafiles/userdef/userdef_default.c`. */
extern const struct UserDef U_default;
#ifdef __cplusplus

View File

@ -126,7 +126,7 @@
* - read associated 'direct data'
* - link direct data (internal and to LibBlock)
* - read #FileGlobal
* - read #USER data, only when indicated (file is `~/.config/blender/X.XX/config/userpref.blend`)
* - read #USER data, only when indicated (file is `~/.config/blender/X.X/config/userpref.blend`)
* - free file
* - per Library (per #Main)
* - read file

View File

@ -206,7 +206,7 @@ bool BLO_memfile_write_file(MemFile *memfile, const char *filepath)
MemFileChunk *chunk;
int file, oflags;
/* NOTE: This is currently used for autosave and 'quit.blend',
/* NOTE: This is currently used for auto-save and `quit.blend`,
* where _not_ following symlinks is OK,
* however if this is ever executed explicitly by the user,
* we may want to allow writing to symlinks.

View File

@ -2184,46 +2184,6 @@ static void versioning_replace_legacy_mix_rgb_node(bNodeTree *ntree)
}
}
static void versioning_replace_legacy_glossy_node(bNodeTree *ntree)
{
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->type == SH_NODE_BSDF_GLOSSY_LEGACY) {
strcpy(node->idname, "ShaderNodeBsdfAnisotropic");
node->type = SH_NODE_BSDF_GLOSSY;
}
}
}
static void versioning_remove_microfacet_sharp_distribution(bNodeTree *ntree)
{
/* Find all glossy, glass and refraction BSDF nodes that have their distribution
* set to SHARP and set them to GGX, disconnect any link to the Roughness input
* and set its value to zero. */
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (!ELEM(node->type, SH_NODE_BSDF_GLOSSY, SH_NODE_BSDF_GLASS, SH_NODE_BSDF_REFRACTION)) {
continue;
}
if (node->custom1 != SHD_GLOSSY_SHARP_DEPRECATED) {
continue;
}
node->custom1 = SHD_GLOSSY_GGX;
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if (!STREQ(socket->identifier, "Roughness")) {
continue;
}
if (socket->link != nullptr) {
nodeRemLink(ntree, socket->link);
}
bNodeSocketValueFloat *socket_value = (bNodeSocketValueFloat *)socket->default_value;
socket_value->value = 0.0f;
break;
}
}
}
static void version_fix_image_format_copy(Main *bmain, ImageFormatData *format)
{
/* Fix bug where curves in image format were not properly copied to file output
@ -4461,26 +4421,8 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
}
}
/**
* Versioning code until next subversion bump goes here.
*
* \note Be sure to check when bumping the version:
* - "versioning_userdef.c", #blo_do_versions_userdef
* - "versioning_userdef.c", #do_versions_theme
*
* \note Keep this message at the bottom of the function.
*/
{
/* Keep this block, even when empty. */
/* Convert anisotropic BSDF node to glossy BSDF. */
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
versioning_replace_legacy_glossy_node(ntree);
versioning_remove_microfacet_sharp_distribution(ntree);
}
FOREACH_NODETREE_END;
BKE_animdata_main_cb(bmain, version_liboverride_nla_frame_start_end, nullptr);
if (!MAIN_VERSION_ATLEAST(bmain, 306, 11)) {
BKE_animdata_main_cb(bmain, version_liboverride_nla_frame_start_end, NULL);
/* Store simulation bake directory in geometry nodes modifier. */
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
@ -4519,4 +4461,18 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
}
}
}
/**
* Versioning code until next subversion bump goes here.
*
* \note Be sure to check when bumping the version:
* - #do_versions_after_linking_300 in this file.
* - "versioning_userdef.c", #blo_do_versions_userdef
* - "versioning_userdef.c", #do_versions_theme
*
* \note Keep this message at the bottom of the function.
*/
{
/* Keep this block, even when empty. */
}
}

View File

@ -31,9 +31,23 @@
// static CLG_LogRef LOG = {"blo.readfile.doversion"};
void do_versions_after_linking_400(FileData * /*fd*/, Main *bmain)
void do_versions_after_linking_400(FileData * /*fd*/, Main * /*bmain*/)
{
UNUSED_VARS(bmain);
/**
* Versioning code until next subversion bump goes here.
*
* \note Be sure to check when bumping the version:
* - #blo_do_versions_400 in this file.
* - "versioning_cycles.cc", #blo_do_versions_cycles
* - "versioning_cycles.cc", #do_versions_after_linking_cycles
* - "versioning_userdef.c", #blo_do_versions_userdef
* - "versioning_userdef.c", #do_versions_theme
*
* \note Keep this message at the bottom of the function.
*/
{
/* Keep this block, even when empty. */
}
}
static void version_mesh_legacy_to_struct_of_array_format(Mesh &mesh)
@ -103,6 +117,46 @@ static void version_geometry_nodes_add_realize_instance_nodes(bNodeTree *ntree)
}
}
static void versioning_replace_legacy_glossy_node(bNodeTree *ntree)
{
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->type == SH_NODE_BSDF_GLOSSY_LEGACY) {
strcpy(node->idname, "ShaderNodeBsdfAnisotropic");
node->type = SH_NODE_BSDF_GLOSSY;
}
}
}
static void versioning_remove_microfacet_sharp_distribution(bNodeTree *ntree)
{
/* Find all glossy, glass and refraction BSDF nodes that have their distribution
* set to SHARP and set them to GGX, disconnect any link to the Roughness input
* and set its value to zero. */
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (!ELEM(node->type, SH_NODE_BSDF_GLOSSY, SH_NODE_BSDF_GLASS, SH_NODE_BSDF_REFRACTION)) {
continue;
}
if (node->custom1 != SHD_GLOSSY_SHARP_DEPRECATED) {
continue;
}
node->custom1 = SHD_GLOSSY_GGX;
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if (!STREQ(socket->identifier, "Roughness")) {
continue;
}
if (socket->link != nullptr) {
nodeRemLink(ntree, socket->link);
}
bNodeSocketValueFloat *socket_value = (bNodeSocketValueFloat *)socket->default_value;
socket_value->value = 0.0f;
break;
}
}
}
void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
{
if (!MAIN_VERSION_ATLEAST(bmain, 400, 1)) {
@ -142,13 +196,21 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
* Versioning code until next subversion bump goes here.
*
* \note Be sure to check when bumping the version:
* - #do_versions_after_linking_400 in this file.
* - "versioning_cycles.cc", #blo_do_versions_cycles
* - "versioning_cycles.cc", #do_versions_after_linking_cycles
* - "versioning_userdef.c", #blo_do_versions_userdef
* - "versioning_userdef.c", #do_versions_theme
*
* \note Keep this message at the bottom of the function.
*/
{
/* Keep this block, even when empty. */
/* Convert anisotropic BSDF node to glossy BSDF. */
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
versioning_replace_legacy_glossy_node(ntree);
versioning_remove_microfacet_sharp_distribution(ntree);
}
FOREACH_NODETREE_END;
if (!DNA_struct_elem_find(fd->filesdna, "bNodeSocket", "int", "panel_id")) {
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
@ -161,5 +223,7 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
}
FOREACH_NODETREE_END;
}
/* Keep this block, even when empty. */
}
}

View File

@ -50,10 +50,12 @@
* - write library block
* - per LibBlock
* - write the ID of LibBlock
* - write #TEST (#RenderInfo struct. 128x128 blend file preview is optional).
* - write #GLOB (#FileGlobal struct) (some global vars).
* - write #DNA1 (#SDNA struct)
* - write #USER (#UserDef struct) if filename is `~/.config/blender/X.XX/config/startup.blend`.
* - write #BLO_CODE_GLOB (#RenderInfo struct. 128x128 blend file preview is optional).
* - write #BLO_CODE_GLOB (#FileGlobal struct) (some global vars).
* - write #BLO_CODE_DNA1 (#SDNA struct)
* - write #BLO_CODE_USER (#UserDef struct) for file paths:
- #BLENDER_STARTUP_FILE (on UNIX `~/.config/blender/X.X/config/startup.blend`).
- #BLENDER_USERPREF_FILE (on UNIX `~/.config/blender/X.X/config/userpref.blend`).
*/
#include <cerrno>
@ -971,10 +973,10 @@ static void write_libraries(WriteData *wd, Main *main)
}
}
/* To be able to restore 'quit.blend' and temp saves,
/* To be able to restore `quit.blend` and temp saves,
* the packed blend has to be in undo buffers... */
/* XXX needs rethink, just like save UI in undo files now -
* would be nice to append things only for the 'quit.blend' and temp saves. */
* would be nice to append things only for the `quit.blend` and temp saves. */
if (found_one) {
/* Not overridable. */

View File

@ -11,6 +11,8 @@
extern "C" {
#endif
struct Render;
/* Keep ascii art. */
/* clang-format off */
@ -294,6 +296,9 @@ extern "C" {
* It can be executed during editing (blenkernel/node.cc) or rendering
* (renderer/pipeline.c)
*
* \param render: [struct Render]
* Render instance for GPU context.
*
* \param render_data: [struct RenderData]
* Render data for this composite, this won't always belong to a scene.
*
@ -305,10 +310,10 @@ extern "C" {
* (true) or editing (false).
* based on this setting the system will work differently:
* - during rendering only Composite & the File output node will be calculated
* \see NodeOperation.is_output_program(int rendering) of the specific operations
* \see NodeOperation.is_output_program(bool rendering) of the specific operations
*
* - during editing all output nodes will be calculated
* \see NodeOperation.is_output_program(int rendering) of the specific operations
* \see NodeOperation.is_output_program(bool rendering) of the specific operations
*
* - another quality setting can be used bNodeTree.
* The quality is determined by the bNodeTree fields.
@ -326,10 +331,11 @@ extern "C" {
*/
/* clang-format off */
void COM_execute(RenderData *render_data,
void COM_execute(Render *render,
RenderData *render_data,
Scene *scene,
bNodeTree *node_tree,
int rendering,
bool rendering,
const char *view_name);
/**

View File

@ -14,6 +14,8 @@
#include "COM_WorkScheduler.h"
#include "COM_compositor.h"
#include "RE_compositor.hh"
static struct {
bool is_initialized = false;
ThreadMutex mutex;
@ -47,10 +49,11 @@ static void compositor_reset_node_tree_status(bNodeTree *node_tree)
node_tree->runtime->stats_draw(node_tree->runtime->sdh, IFACE_("Compositing"));
}
void COM_execute(RenderData *render_data,
void COM_execute(Render *render,
RenderData *render_data,
Scene *scene,
bNodeTree *node_tree,
int rendering,
bool rendering,
const char *view_name)
{
/* Initialize mutex, TODO: this mutex init is actually not thread safe and
@ -73,26 +76,41 @@ void COM_execute(RenderData *render_data,
compositor_init_node_previews(render_data, node_tree);
compositor_reset_node_tree_status(node_tree);
/* Initialize workscheduler. */
const bool use_opencl = (node_tree->flag & NTREE_COM_OPENCL) != 0;
blender::compositor::WorkScheduler::initialize(use_opencl, BKE_render_num_threads(render_data));
if (U.experimental.use_full_frame_compositor &&
node_tree->execution_mode == NTREE_EXECUTION_MODE_REALTIME)
{
/* Realtime GPU compositor. */
/* Execute. */
const bool twopass = (node_tree->flag & NTREE_TWO_PASS) && !rendering;
if (twopass) {
blender::compositor::ExecutionSystem fast_pass(
render_data, scene, node_tree, rendering, true, view_name);
fast_pass.execute();
if (node_tree->runtime->test_break(node_tree->runtime->tbh)) {
BLI_mutex_unlock(&g_compositor.mutex);
return;
}
/* TODO: add persistence and depsgraph updates for better performance. */
blender::render::RealtimeCompositor compositor(
*render, *scene, *render_data, *node_tree, rendering, view_name);
compositor.execute();
}
else {
/* Tiled and Full Frame compositors. */
blender::compositor::ExecutionSystem system(
render_data, scene, node_tree, rendering, false, view_name);
system.execute();
/* Initialize workscheduler. */
const bool use_opencl = (node_tree->flag & NTREE_COM_OPENCL) != 0;
blender::compositor::WorkScheduler::initialize(use_opencl,
BKE_render_num_threads(render_data));
/* Execute. */
const bool twopass = (node_tree->flag & NTREE_TWO_PASS) && !rendering;
if (twopass) {
blender::compositor::ExecutionSystem fast_pass(
render_data, scene, node_tree, rendering, true, view_name);
fast_pass.execute();
if (node_tree->runtime->test_break(node_tree->runtime->tbh)) {
BLI_mutex_unlock(&g_compositor.mutex);
return;
}
}
blender::compositor::ExecutionSystem system(
render_data, scene, node_tree, rendering, false, view_name);
system.execute();
}
BLI_mutex_unlock(&g_compositor.mutex);
}

View File

@ -9,6 +9,7 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
../../draw
../../gpu
../../imbuf
../../makesdna
@ -17,6 +18,9 @@ set(INC
../../render
../../gpu/intern
../../../../intern/guardedalloc
# dna_type_offsets.h
${CMAKE_CURRENT_BINARY_DIR}/../../makesdna/intern
)
set(INC_SYS
@ -74,6 +78,7 @@ set(SRC
cached_resources/intern/cached_mask.cc
cached_resources/intern/cached_texture.cc
cached_resources/intern/distortion_grid.cc
cached_resources/intern/morphological_distance_feather_weights.cc
cached_resources/intern/ocio_color_space_conversion_shader.cc
cached_resources/intern/smaa_precomputed_textures.cc
@ -83,6 +88,7 @@ set(SRC
cached_resources/COM_cached_mask.hh
cached_resources/COM_cached_resource.hh
cached_resources/COM_cached_texture.hh
cached_resources/COM_distortion_grid.hh
cached_resources/COM_morphological_distance_feather_weights.hh
cached_resources/COM_ocio_color_space_conversion_shader.hh
cached_resources/COM_smaa_precomputed_textures.hh
@ -133,6 +139,7 @@ set(GLSL_SRC
shaders/compositor_morphological_distance_feather.glsl
shaders/compositor_morphological_distance_threshold.glsl
shaders/compositor_morphological_step.glsl
shaders/compositor_movie_distortion.glsl
shaders/compositor_normalize.glsl
shaders/compositor_parallel_reduction.glsl
shaders/compositor_plane_deform.glsl
@ -234,6 +241,7 @@ set(SRC_SHADER_CREATE_INFOS
shaders/infos/compositor_morphological_distance_info.hh
shaders/infos/compositor_morphological_distance_threshold_info.hh
shaders/infos/compositor_morphological_step_info.hh
shaders/infos/compositor_movie_distortion_info.hh
shaders/infos/compositor_normalize_info.hh
shaders/infos/compositor_parallel_reduction_info.hh
shaders/infos/compositor_plane_deform_info.hh

View File

@ -42,8 +42,17 @@ class Context {
public:
Context(TexturePool &texture_pool);
/* Get the active compositing scene. */
virtual const Scene *get_scene() const = 0;
/* Get the node tree used for compositing. */
virtual const bNodeTree &get_node_tree() const = 0;
/* True if compositor should do write file outputs, false if only running for viewing. */
virtual bool use_file_output() const = 0;
/* True if color management should be used for texture evaluation. */
virtual bool use_texture_color_management() const = 0;
/* Get the render settings for compositing. */
virtual const RenderData &get_render_data() const = 0;
/* Get the width and height of the render passes and of the output texture returned by the
* get_input_texture and get_output_texture methods respectively. */
@ -63,7 +72,7 @@ class Context {
/* Get the texture where the given render pass is stored. This should be called by the Render
* Layer node to populate its outputs. */
virtual GPUTexture *get_input_texture(int view_layer, eScenePassType pass_type) = 0;
virtual GPUTexture *get_input_texture(int view_layer, const char *pass_name) = 0;
/* Get the name of the view currently being rendered. */
virtual StringRef get_view_name() = 0;

View File

@ -6,6 +6,7 @@
#include "COM_cached_mask.hh"
#include "COM_cached_texture.hh"
#include "COM_distortion_grid.hh"
#include "COM_morphological_distance_feather_weights.hh"
#include "COM_ocio_color_space_conversion_shader.hh"
#include "COM_smaa_precomputed_textures.hh"
@ -45,6 +46,7 @@ class StaticCacheManager {
CachedMaskContainer cached_masks;
SMAAPrecomputedTexturesContainer smaa_precomputed_textures;
OCIOColorSpaceConversionShaderContainer ocio_color_space_conversion_shaders;
DistortionGridContainer distortion_grids;
/* Reset the cache manager by deleting the cached resources that are no longer needed because
* they weren't used in the last evaluation and prepare the remaining cached resources to track

View File

@ -13,7 +13,6 @@
#include "GPU_texture.h"
#include "DNA_scene_types.h"
#include "DNA_texture_types.h"
#include "COM_cached_resource.hh"
@ -49,7 +48,7 @@ class CachedTexture : public CachedResource {
GPUTexture *value_texture_ = nullptr;
public:
CachedTexture(Tex *texture, const Scene *scene, int2 size, float2 offset, float2 scale);
CachedTexture(Tex *texture, bool use_color_management, int2 size, float2 offset, float2 scale);
~CachedTexture();
@ -74,8 +73,12 @@ class CachedTextureContainer : CachedResourceContainer {
* CachedTexture cached resource with the given parameters in the container, if one exists,
* return it, otherwise, return a newly created one and add it to the container. In both cases,
* tag the cached resource as needed to keep it cached for the next evaluation. */
CachedTexture &get(
Context &context, Tex *texture, const Scene *scene, int2 size, float2 offset, float2 scale);
CachedTexture &get(Context &context,
Tex *texture,
bool use_color_management,
int2 size,
float2 offset,
float2 scale);
};
} // namespace blender::realtime_compositor

View File

@ -0,0 +1,86 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include <cstdint>
#include <memory>
#include "BLI_map.hh"
#include "BLI_math_vector_types.hh"
#include "GPU_shader.h"
#include "GPU_texture.h"
#include "DNA_movieclip_types.h"
#include "COM_cached_resource.hh"
namespace blender::realtime_compositor {
enum class DistortionType : uint8_t {
Distort,
Undistort,
};
/* ------------------------------------------------------------------------------------------------
* Distortion Grid Key.
*/
class DistortionGridKey {
public:
MovieTrackingCamera camera;
int2 size;
DistortionType type;
int2 calibration_size;
DistortionGridKey(MovieTrackingCamera camera,
int2 size,
DistortionType type,
int2 calibration_size);
uint64_t hash() const;
};
bool operator==(const DistortionGridKey &a, const DistortionGridKey &b);
/* -------------------------------------------------------------------------------------------------
* Distortion Grid.
*
* A cached resource that computes and caches a GPU texture containing the normalized coordinates
* after applying the camera distortion of a given movie clip tracking camera. See the constructor
* for more information. */
class DistortionGrid : public CachedResource {
private:
GPUTexture *texture_ = nullptr;
public:
/* The calibration size is the size of the image where the tracking camera was calibrated, this
* is the size of the movie clip in most cases. */
DistortionGrid(MovieClip *movie_clip, int2 size, DistortionType type, int2 calibration_size);
~DistortionGrid();
void bind_as_texture(GPUShader *shader, const char *texture_name) const;
void unbind_as_texture() const;
};
/* ------------------------------------------------------------------------------------------------
* Distortion Grid Container.
*/
class DistortionGridContainer : CachedResourceContainer {
private:
Map<DistortionGridKey, std::unique_ptr<DistortionGrid>> map_;
public:
void reset() override;
/* Check if there is an available DistortionGrid cached resource with the given parameters in the
* container, if one exists, return it, otherwise, return a newly created one and add it to the
* container. In both cases, tag the cached resource as needed to keep it cached for the next
* evaluation. */
DistortionGrid &get(MovieClip *movie_clip, int2 size, DistortionType type, int frame_number);
};
} // namespace blender::realtime_compositor

View File

@ -51,7 +51,7 @@ bool operator==(const CachedTextureKey &a, const CachedTextureKey &b)
*/
CachedTexture::CachedTexture(
Tex *texture, const Scene *scene, int2 size, float2 offset, float2 scale)
Tex *texture, bool use_color_management, int2 size, float2 offset, float2 scale)
{
ImagePool *image_pool = BKE_image_pool_new();
BKE_texture_fetch_images_for_pool(texture, image_pool);
@ -67,7 +67,8 @@ CachedTexture::CachedTexture(
/* Note that it is expected that the offset is scaled by the scale. */
coordinates = (coordinates + offset) * scale;
TexResult texture_result;
BKE_texture_get_value_ex(scene, texture, coordinates, &texture_result, image_pool, true);
BKE_texture_get_value_ex(
texture, coordinates, &texture_result, image_pool, use_color_management);
color_pixels[y * size.x + x] = float4(texture_result.trgba);
value_pixels[y * size.x + x] = texture_result.talpha ? texture_result.trgba[3] :
texture_result.tin;
@ -131,8 +132,12 @@ void CachedTextureContainer::reset()
}
}
CachedTexture &CachedTextureContainer::get(
Context &context, Tex *texture, const Scene *scene, int2 size, float2 offset, float2 scale)
CachedTexture &CachedTextureContainer::get(Context &context,
Tex *texture,
bool use_color_management,
int2 size,
float2 offset,
float2 scale)
{
const CachedTextureKey key(size, offset, scale);
@ -143,8 +148,9 @@ CachedTexture &CachedTextureContainer::get(
cached_textures_for_id.clear();
}
auto &cached_texture = *cached_textures_for_id.lookup_or_add_cb(
key, [&]() { return std::make_unique<CachedTexture>(texture, scene, size, offset, scale); });
auto &cached_texture = *cached_textures_for_id.lookup_or_add_cb(key, [&]() {
return std::make_unique<CachedTexture>(texture, use_color_management, size, offset, scale);
});
cached_texture.needed = true;
return cached_texture;

View File

@ -0,0 +1,160 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include <cstdint>
#include <memory>
#include "BLI_array.hh"
#include "BLI_hash.hh"
#include "BLI_index_range.hh"
#include "BLI_math_vector_types.hh"
#include "BLI_task.hh"
#include "DNA_defaults.h"
#include "DNA_movieclip_types.h"
#include "DNA_tracking_types.h"
#include "GPU_texture.h"
#include "BKE_movieclip.h"
#include "BKE_tracking.h"
#include "COM_distortion_grid.hh"
namespace blender::realtime_compositor {
/* --------------------------------------------------------------------
* Distortion Grid Key.
*/
DistortionGridKey::DistortionGridKey(MovieTrackingCamera camera,
int2 size,
DistortionType type,
int2 calibration_size)
: camera(camera), size(size), type(type), calibration_size(calibration_size)
{
}
uint64_t DistortionGridKey::hash() const
{
return get_default_hash_4(
BKE_tracking_camera_distortion_hash(&camera), size, type, calibration_size);
}
bool operator==(const DistortionGridKey &a, const DistortionGridKey &b)
{
return BKE_tracking_camera_distortion_equal(&a.camera, &b.camera) && a.size == b.size &&
a.type == b.type && a.calibration_size == b.calibration_size;
}
/* --------------------------------------------------------------------
* Distortion Grid.
*/
DistortionGrid::DistortionGrid(MovieClip *movie_clip,
int2 size,
DistortionType type,
int2 calibration_size)
{
MovieDistortion *distortion = BKE_tracking_distortion_new(
&movie_clip->tracking, calibration_size.x, calibration_size.y);
Array<float2> distortion_grid(size.x * size.y);
threading::parallel_for(IndexRange(size.y), 1, [&](const IndexRange sub_y_range) {
for (const int64_t y : sub_y_range) {
for (const int64_t x : IndexRange(size.x)) {
/* The tracking distortion functions expect the coordinates to be in the space of the image
* where the tracking camera was calibrated. So we first remap the coordinates into that
* space, apply the distortion, then remap back to the original coordinates space. This is
* done by dividing the by the size then multiplying by the calibration size, making sure
* to add 0.5 to evaluate at the center of pixels. */
float2 coordinates = ((float2(x, y) + 0.5f) / float2(size)) * float2(calibration_size);
if (type == DistortionType::Undistort) {
BKE_tracking_distortion_undistort_v2(distortion, coordinates, coordinates);
}
else {
BKE_tracking_distortion_distort_v2(distortion, coordinates, coordinates);
}
/* Note that we should remap the coordinates back into the original size by dividing by the
* calibration size and multiplying by the size, however, we skip the latter to store the
* coordinates in normalized form, since this is what the shader expects. */
distortion_grid[y * size.x + x] = coordinates / float2(calibration_size);
}
}
});
BKE_tracking_distortion_free(distortion);
texture_ = GPU_texture_create_2d("Distortion Grid",
size.x,
size.y,
1,
GPU_RG16F,
GPU_TEXTURE_USAGE_SHADER_READ,
*distortion_grid.data());
}
DistortionGrid::~DistortionGrid()
{
GPU_texture_free(texture_);
}
void DistortionGrid::bind_as_texture(GPUShader *shader, const char *texture_name) const
{
const int texture_image_unit = GPU_shader_get_sampler_binding(shader, texture_name);
GPU_texture_bind(texture_, texture_image_unit);
}
void DistortionGrid::unbind_as_texture() const
{
GPU_texture_unbind(texture_);
}
/* --------------------------------------------------------------------
* Distortion Grid Container.
*/
void DistortionGridContainer::reset()
{
/* First, delete all resources that are no longer needed. */
map_.remove_if([](auto item) { return !item.value->needed; });
/* Second, reset the needed status of the remaining resources to false to ready them to track
* their needed status for the next evaluation. */
for (auto &value : map_.values()) {
value->needed = false;
}
}
static int2 get_movie_clip_size(MovieClip *movie_clip, int frame_number)
{
MovieClipUser user = *DNA_struct_default_get(MovieClipUser);
BKE_movieclip_user_set_frame(&user, frame_number);
int2 size;
BKE_movieclip_get_size(movie_clip, &user, &size.x, &size.y);
return size;
}
DistortionGrid &DistortionGridContainer::get(MovieClip *movie_clip,
int2 size,
DistortionType type,
int frame_number)
{
const int2 calibration_size = get_movie_clip_size(movie_clip, frame_number);
const DistortionGridKey key(movie_clip->tracking.camera, size, type, calibration_size);
auto &distortion_grid = *map_.lookup_or_add_cb(key, [&]() {
return std::make_unique<DistortionGrid>(movie_clip, size, type, calibration_size);
});
distortion_grid.needed = true;
return distortion_grid;
}
} // namespace blender::realtime_compositor

View File

@ -23,18 +23,19 @@ int2 Context::get_compositing_region_size() const
float Context::get_render_percentage() const
{
return get_scene()->r.size / 100.0f;
return get_render_data().size / 100.0f;
}
int Context::get_frame_number() const
{
return get_scene()->r.cfra;
return get_render_data().cfra;
}
float Context::get_time() const
{
const float frame_number = float(get_frame_number());
const float frame_rate = float(get_scene()->r.frs_sec) / float(get_scene()->r.frs_sec_base);
const float frame_rate = float(get_render_data().frs_sec) /
float(get_render_data().frs_sec_base);
return frame_number / frame_rate;
}

View File

@ -66,7 +66,7 @@ bool Evaluator::validate_node_tree()
void Evaluator::compile_and_evaluate()
{
derived_node_tree_ = std::make_unique<DerivedNodeTree>(*context_.get_scene()->nodetree);
derived_node_tree_ = std::make_unique<DerivedNodeTree>(context_.get_node_tree());
if (!validate_node_tree()) {
return;

View File

@ -0,0 +1,7 @@
#pragma BLENDER_REQUIRE(gpu_shader_compositor_texture_utilities.glsl)
void main()
{
ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
imageStore(output_img, texel, texture(input_tx, texture_load(distortion_grid_tx, texel).xy));
}

View File

@ -0,0 +1,13 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "gpu_shader_create_info.hh"
GPU_SHADER_CREATE_INFO(compositor_movie_distortion)
.local_group_size(16, 16)
.sampler(0, ImageType::FLOAT_2D, "input_tx")
.sampler(1, ImageType::FLOAT_2D, "distortion_grid_tx")
.image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_img")
.compute_source("compositor_movie_distortion.glsl")
.do_static_compilation(true);

View File

@ -58,9 +58,24 @@ class Context : public realtime_compositor::Context {
{
}
const Scene *get_scene() const override
const bNodeTree &get_node_tree() const override
{
return DRW_context_state_get()->scene;
return *DRW_context_state_get()->scene->nodetree;
}
bool use_file_output() const override
{
return false;
}
bool use_texture_color_management() const override
{
return BKE_scene_check_color_management_enabled(DRW_context_state_get()->scene);
}
const RenderData &get_render_data() const override
{
return DRW_context_state_get()->scene->r;
}
int2 get_render_size() const override
@ -130,15 +145,20 @@ class Context : public realtime_compositor::Context {
return DRW_viewport_texture_list_get()->color;
}
GPUTexture *get_input_texture(int /*view_layer*/, eScenePassType /*pass_type*/) override
GPUTexture *get_input_texture(int view_layer, const char *pass_name) override
{
return get_output_texture();
if (view_layer == 0 && STREQ(pass_name, RE_PASSNAME_COMBINED)) {
return get_output_texture();
}
else {
return nullptr;
}
}
StringRef get_view_name() override
{
const SceneRenderView *view = static_cast<SceneRenderView *>(
BLI_findlink(&get_scene()->r.views, DRW_context_state_get()->v3d->multiview_eye));
BLI_findlink(&get_render_data().views, DRW_context_state_get()->v3d->multiview_eye));
return view->name;
}

View File

@ -204,7 +204,8 @@ static void grease_pencil_geom_batch_ensure(GreasePencil &grease_pencil, int cfr
/* Get the visible drawings. */
Vector<const GreasePencilDrawing *> drawings;
grease_pencil.foreach_visible_drawing(
cfra, [&](GreasePencilDrawing &drawing) { drawings.append(&drawing); });
cfra,
[&](int /*drawing_index*/, GreasePencilDrawing &drawing) { drawings.append(&drawing); });
/* First, count how many vertices and triangles are needed for the whole object. Also record the
* offsets into the curves for the vertices and triangles. */

View File

@ -12,6 +12,7 @@
extern "C" {
#endif
struct AssetMetaData;
struct ID;
struct Main;
struct bContext;
@ -42,6 +43,18 @@ void ED_asset_generate_preview(const struct bContext *C, struct ID *id);
*/
bool ED_asset_clear_id(struct ID *id);
/**
* Copy the asset metadata to the given destination ID.
*
* The copy is assigned to \a destination, any pre-existing asset metadata is
* freed before that. If \a destination was not yet marked as asset, it will be
* after this call.
*
* \return true when the copy succeeded, false otherwise. The only reason for
* failure is when \a destination is of a type that cannot be an asset.
*/
bool ED_asset_copy_to_id(const struct AssetMetaData *asset_data, struct ID *destination);
void ED_assets_pre_save(struct Main *bmain);
bool ED_asset_can_mark_single_from_context(const struct bContext *C);

View File

@ -27,6 +27,9 @@
#include "ED_asset_mark_clear.h"
#include "ED_asset_type.h"
#include "WM_api.h"
#include "WM_types.h"
bool ED_asset_mark_id(ID *id)
{
if (id->asset_data) {
@ -96,3 +99,16 @@ bool ED_asset_can_mark_single_from_context(const bContext *C)
}
return ED_asset_type_is_supported(id);
}
bool ED_asset_copy_to_id(const struct AssetMetaData *asset_data, struct ID *destination)
{
if (!BKE_id_can_be_asset(destination)) {
return false;
}
if (destination->asset_data) {
BKE_asset_metadata_free(&destination->asset_data);
}
destination->asset_data = BKE_asset_metadata_copy(asset_data);
return true;
}

View File

@ -373,7 +373,9 @@ static void try_convert_single_object(Object &curves_ob,
HairKey &key = hair_keys[key_i];
copy_v3_v3(key.co, key_pos_ha);
key.time = 100.0f * key_i / float(hair_keys.size() - 1);
const float key_fac = key_i / float(hair_keys.size() - 1);
key.time = 100.0f * key_fac;
key.weight = 1.0f - key_fac;
}
}

View File

@ -48,10 +48,11 @@ static int select_all_exec(bContext *C, wmOperator *op)
Object *object = CTX_data_active_object(C);
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
grease_pencil.foreach_editable_drawing(scene->r.cfra, [action](GreasePencilDrawing &drawing) {
// TODO: Support different selection domains.
blender::ed::curves::select_all(drawing.geometry.wrap(), ATTR_DOMAIN_POINT, action);
});
grease_pencil.foreach_editable_drawing(
scene->r.cfra, [action](int /*drawing_index*/, GreasePencilDrawing &drawing) {
// TODO: Support different selection domains.
blender::ed::curves::select_all(drawing.geometry.wrap(), ATTR_DOMAIN_POINT, action);
});
/* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
* attribute for now. */

View File

@ -2408,7 +2408,10 @@ void uiTemplateImage(uiLayout *layout,
struct PointerRNA *userptr,
bool compact,
bool multiview);
void uiTemplateImageSettings(uiLayout *layout, struct PointerRNA *imfptr, bool color_management);
void uiTemplateImageSettings(uiLayout *layout,
struct PointerRNA *imfptr,
bool color_management,
bool show_z_buffer);
void uiTemplateImageStereo3d(uiLayout *layout, struct PointerRNA *stereo3d_format_ptr);
void uiTemplateImageViews(uiLayout *layout, struct PointerRNA *imaptr);
void uiTemplateImageFormatViews(uiLayout *layout,

View File

@ -35,6 +35,7 @@
#include "interface_intern.hh"
#include "RNA_access.h"
#include "RNA_path.h"
#include "RNA_prototypes.h"
#ifdef WITH_PYTHON
@ -344,7 +345,10 @@ static bUserMenuItem *ui_but_user_menu_find(bContext *C, uiBut *but, bUserMenu *
}
if (but->rnaprop) {
char *member_id_data_path = WM_context_path_resolve_full(C, &but->rnapoin);
const char *prop_id = RNA_property_identifier(but->rnaprop);
/* Ignore the actual array index [pass -1] since the index is handled separately. */
const char *prop_id = RNA_property_is_idprop(but->rnaprop) ?
RNA_path_property_py(&but->rnapoin, but->rnaprop, -1) :
RNA_property_identifier(but->rnaprop);
bUserMenuItem *umi = (bUserMenuItem *)ED_screen_user_menu_item_find_prop(
&um->items, member_id_data_path, prop_id, but->rnaindex);
MEM_freeN(member_id_data_path);
@ -419,7 +423,10 @@ static void ui_but_user_menu_add(bContext *C, uiBut *but, bUserMenu *um)
else if (but->rnaprop) {
/* NOTE: 'member_id' may be a path. */
char *member_id_data_path = WM_context_path_resolve_full(C, &but->rnapoin);
const char *prop_id = RNA_property_identifier(but->rnaprop);
/* Ignore the actual array index [pass -1] since the index is handled separately. */
const char *prop_id = RNA_property_is_idprop(but->rnaprop) ?
RNA_path_property_py(&but->rnapoin, but->rnaprop, -1) :
RNA_property_identifier(but->rnaprop);
/* NOTE: ignore 'drawstr', use property idname always. */
ED_screen_user_menu_item_add_prop(&um->items, "", member_id_data_path, prop_id, but->rnaindex);
MEM_freeN(member_id_data_path);

View File

@ -290,7 +290,8 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
uiItemR(sub, imfptr, "export_mesh_type_selection", 0, "", ICON_NONE);
if (RNA_boolean_get(imfptr, "include_animations")) {
uiItemR(col, imfptr, "export_animation_transformation_type_selection", 0, nullptr, ICON_NONE);
uiItemR(
col, imfptr, "export_animation_transformation_type_selection", 0, nullptr, ICON_NONE);
}
else {
uiItemR(col, imfptr, "export_object_transformation_type_selection", 0, nullptr, ICON_NONE);
@ -317,7 +318,8 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
uiLayoutSetActive(row, include_animations && animation_type == BC_ANIMATION_EXPORT_SAMPLES);
if (RNA_boolean_get(imfptr, "include_animations")) {
uiItemR(box, imfptr, "export_animation_transformation_type_selection", 0, nullptr, ICON_NONE);
uiItemR(
box, imfptr, "export_animation_transformation_type_selection", 0, nullptr, ICON_NONE);
}
else {
uiItemR(box, imfptr, "export_object_transformation_type_selection", 0, nullptr, ICON_NONE);

View File

@ -86,7 +86,7 @@ static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
const int resolution = RNA_int_get(op->ptr, "resolution");
const float scale = RNA_float_get(op->ptr, "scale");
GpencilIOParams params {};
GpencilIOParams params{};
params.C = C;
params.region = region;
params.v3d = v3d;

View File

@ -1086,7 +1086,7 @@ static void shader_preview_texture(ShaderPreview *sp, Tex *tex, Scene *sce, Rend
/* Fill in image buffer. */
float *rect_float = rv->combined_buffer.data;
float tex_coord[3] = {0.0f, 0.0f, 0.0f};
bool color_manage = true;
bool color_manage = BKE_scene_check_color_management_enabled(sce);
for (int y = 0; y < height; y++) {
/* Tex coords between -1.0f and 1.0f. */
@ -1097,7 +1097,7 @@ static void shader_preview_texture(ShaderPreview *sp, Tex *tex, Scene *sce, Rend
/* Evaluate texture at tex_coord. */
TexResult texres = {0};
BKE_texture_get_value_ex(sce, tex, tex_coord, &texres, img_pool, color_manage);
BKE_texture_get_value_ex(tex, tex_coord, &texres, img_pool, color_manage);
copy_v4_fl4(rect_float,
texres.trgba[0],
texres.trgba[1],

View File

@ -3180,6 +3180,12 @@ static int keyframe_jump_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static bool keyframe_jump_poll(bContext *C)
{
/* There is a keyframe jump operator specifically for the Graph Editor. */
return ED_operator_screenactive_norender(C) && CTX_wm_area(C)->spacetype != SPACE_GRAPH;
}
static void SCREEN_OT_keyframe_jump(wmOperatorType *ot)
{
ot->name = "Jump to Keyframe";
@ -3188,7 +3194,7 @@ static void SCREEN_OT_keyframe_jump(wmOperatorType *ot)
ot->exec = keyframe_jump_exec;
ot->poll = ED_operator_screenactive_norender;
ot->poll = keyframe_jump_poll;
ot->flag = OPTYPE_UNDO_GROUPED;
ot->undo_group = "Frame Change";

View File

@ -218,7 +218,7 @@ static void screenshot_draw(bContext *UNUSED(C), wmOperator *op)
/* image template */
PointerRNA ptr;
RNA_pointer_create(NULL, &RNA_ImageFormatSettings, &scd->im_format, &ptr);
uiTemplateImageSettings(layout, &ptr, false);
uiTemplateImageSettings(layout, &ptr, false, true);
/* main draw call */
uiDefAutoButsRNA(

View File

@ -391,8 +391,7 @@ static int palette_color_add_exec(bContext *C, wmOperator * /*op*/)
PAINT_MODE_TEXTURE_3D,
PAINT_MODE_TEXTURE_2D,
PAINT_MODE_VERTEX,
PAINT_MODE_SCULPT))
{
PAINT_MODE_SCULPT)) {
copy_v3_v3(color->rgb, BKE_brush_color_get(scene, brush));
color->value = 0.0;
}

View File

@ -39,6 +39,7 @@
#include "BKE_global.h"
#include "BKE_nla.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "DEG_depsgraph_build.h"
@ -2179,6 +2180,104 @@ void GRAPH_OT_frame_jump(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
static bool find_closest_frame(const FCurve *fcu,
const float frame,
const bool next,
float *closest_frame)
{
bool replace;
int bezt_index = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, frame, fcu->totvert, &replace);
BezTriple *bezt;
if (next) {
if (replace) {
bezt_index++;
}
if (bezt_index > fcu->totvert - 1) {
return false;
}
bezt = &fcu->bezt[bezt_index];
}
else {
if (bezt_index - 1 < 0) {
return false;
}
bezt = &fcu->bezt[bezt_index - 1];
}
*closest_frame = bezt->vec[1][0];
return true;
}
static int keyframe_jump_exec(bContext *C, wmOperator *op)
{
bAnimContext ac;
Scene *scene = CTX_data_scene(C);
bool next = RNA_boolean_get(op->ptr, "next");
/* Get editor data. */
if (ANIM_animdata_get_context(C, &ac) == 0) {
return OPERATOR_CANCELLED;
}
ListBase anim_data = {NULL, NULL};
int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FCURVESONLY |
ANIMFILTER_NODUPLIS);
if (U.animation_flag & USER_ANIM_ONLY_SHOW_SELECTED_CURVE_KEYS) {
filter |= ANIMFILTER_SEL;
}
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
float closest_frame = next ? FLT_MAX : -FLT_MAX;
bool found = false;
const float current_frame = BKE_scene_frame_get(scene);
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
const FCurve *fcu = ale->key_data;
if (!fcu->bezt) {
continue;
}
float closest_fcu_frame;
if (!find_closest_frame(fcu, current_frame, next, &closest_fcu_frame)) {
continue;
}
if ((next && closest_fcu_frame < closest_frame) ||
(!next && closest_fcu_frame > closest_frame)) {
closest_frame = closest_fcu_frame;
found = true;
}
}
if (!found) {
BKE_report(op->reports, RPT_INFO, "No more keyframes to jump to in this direction");
return OPERATOR_CANCELLED;
}
BKE_scene_frame_set(scene, closest_frame);
/* Set notifier that things have changed. */
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, ac.scene);
return OPERATOR_FINISHED;
}
void GRAPH_OT_keyframe_jump(wmOperatorType *ot)
{
ot->name = "Jump to Keyframe";
ot->description = "Jump to previous/next keyframe";
ot->idname = "GRAPH_OT_keyframe_jump";
ot->exec = keyframe_jump_exec;
ot->poll = graphkeys_framejump_poll;
ot->flag = OPTYPE_UNDO_GROUPED;
ot->undo_group = "Frame Change";
/* properties */
RNA_def_boolean(ot->srna, "next", true, "Next Keyframe", "");
}
/* snap 2D cursor value to the average value of selected keyframe */
static int graphkeys_snap_cursor_value_exec(bContext *C, wmOperator *UNUSED(op))
{

View File

@ -131,6 +131,7 @@ void GRAPH_OT_extrapolation_type(struct wmOperatorType *ot);
void GRAPH_OT_easing_type(struct wmOperatorType *ot);
void GRAPH_OT_frame_jump(struct wmOperatorType *ot);
void GRAPH_OT_keyframe_jump(struct wmOperatorType *ot);
void GRAPH_OT_snap_cursor_value(struct wmOperatorType *ot);
void GRAPH_OT_snap(struct wmOperatorType *ot);
void GRAPH_OT_equalize_handles(struct wmOperatorType *ot);

View File

@ -449,6 +449,7 @@ void graphedit_operatortypes(void)
WM_operatortype_append(GRAPH_OT_equalize_handles);
WM_operatortype_append(GRAPH_OT_mirror);
WM_operatortype_append(GRAPH_OT_frame_jump);
WM_operatortype_append(GRAPH_OT_keyframe_jump);
WM_operatortype_append(GRAPH_OT_snap_cursor_value);
WM_operatortype_append(GRAPH_OT_handle_type);
WM_operatortype_append(GRAPH_OT_interpolation_type);

View File

@ -962,7 +962,10 @@ void uiTemplateImage(uiLayout *layout,
UI_block_funcN_set(block, NULL, NULL, NULL);
}
void uiTemplateImageSettings(uiLayout *layout, PointerRNA *imfptr, bool color_management)
void uiTemplateImageSettings(uiLayout *layout,
PointerRNA *imfptr,
bool color_management,
bool show_z_buffer)
{
ImageFormatData *imf = imfptr->data;
ID *id = imfptr->owner_id;
@ -1014,7 +1017,7 @@ void uiTemplateImageSettings(uiLayout *layout, PointerRNA *imfptr, bool color_ma
uiItemR(col, imfptr, "exr_codec", 0, NULL, ICON_NONE);
}
if (BKE_imtype_supports_zbuf(imf->imtype)) {
if (BKE_imtype_supports_zbuf(imf->imtype) && show_z_buffer) {
uiItemR(col, imfptr, "use_zbuffer", 0, NULL, ICON_NONE);
}

View File

@ -2007,7 +2007,7 @@ static void image_save_as_draw(bContext *UNUSED(C), wmOperator *op)
/* Image format settings. */
RNA_pointer_create(NULL, &RNA_ImageFormatSettings, &isd->opts.im_format, &imf_ptr);
uiTemplateImageSettings(layout, &imf_ptr, save_as_render);
uiTemplateImageSettings(layout, &imf_ptr, save_as_render, true);
if (!save_as_render) {
PointerRNA linear_settings_ptr = RNA_pointer_get(&imf_ptr, "linear_colorspace_settings");

View File

@ -1196,7 +1196,7 @@ static const float std_node_socket_colors[][4] = {
{0.78, 0.78, 0.16, 1.0}, /* SOCK_RGBA */
{0.39, 0.78, 0.39, 1.0}, /* SOCK_SHADER */
{0.80, 0.65, 0.84, 1.0}, /* SOCK_BOOLEAN */
{0.0, 0.0, 0.0, 1.0}, /* SOCK_MESH_DEPRECATED */
{0.0, 0.0, 0.0, 0.0}, /* UNUSED */
{0.35, 0.55, 0.36, 1.0}, /* SOCK_INT */
{0.44, 0.70, 1.00, 1.0}, /* SOCK_STRING */
{0.93, 0.62, 0.36, 1.0}, /* SOCK_OBJECT */

View File

@ -3327,6 +3327,12 @@ static bool realtime_compositor_is_in_use(const bContext &context)
return false;
}
if (U.experimental.use_full_frame_compositor &&
scene->nodetree->execution_mode == NTREE_EXECUTION_MODE_REALTIME)
{
return true;
}
const Main *main = CTX_data_main(&context);
LISTBASE_FOREACH (const bScreen *, screen, &main->screens) {
LISTBASE_FOREACH (const ScrArea *, area, &screen->areabase) {

View File

@ -95,6 +95,8 @@ struct CompoJob {
/* Evaluated state/ */
Depsgraph *compositor_depsgraph;
bNodeTree *localtree;
/* Render instance. */
Render *re;
/* Jon system integration. */
const bool *stop;
bool *do_update;
@ -239,6 +241,9 @@ static void compo_initjob(void *cjv)
if (cj->recalc_flags) {
compo_tag_output_nodes(cj->localtree, cj->recalc_flags);
}
cj->re = RE_NewSceneRender(scene);
RE_gl_context_create(cj->re);
}
/* Called before redraw notifiers, it moves finished previews over. */
@ -286,17 +291,19 @@ static void compo_startjob(void *cjv,
BKE_callback_exec_id(cj->bmain, &scene->id, BKE_CB_EVT_COMPOSITE_PRE);
if ((cj->scene->r.scemode & R_MULTIVIEW) == 0) {
ntreeCompositExecTree(cj->scene, ntree, &cj->scene->r, false, true, "");
ntreeCompositExecTree(cj->re, cj->scene, ntree, &cj->scene->r, false, true, "");
}
else {
LISTBASE_FOREACH (SceneRenderView *, srv, &scene->r.views) {
if (BKE_scene_multiview_is_render_view_active(&scene->r, srv) == false) {
continue;
}
ntreeCompositExecTree(cj->scene, ntree, &cj->scene->r, false, true, srv->name);
ntreeCompositExecTree(cj->re, cj->scene, ntree, &cj->scene->r, false, true, srv->name);
}
}
RE_gl_context_destroy(cj->re);
ntree->runtime->test_break = nullptr;
ntree->runtime->stats_draw = nullptr;
ntree->runtime->progress = nullptr;

View File

@ -2222,8 +2222,6 @@ void node_insert_on_link_flags(Main &bmain, SpaceNode &snode)
static int get_main_socket_priority(const bNodeSocket *socket)
{
switch ((eNodeSocketDatatype)socket->type) {
case SOCK_MESH_DEPRECATED:
return -1;
case SOCK_CUSTOM:
return 0;
case SOCK_BOOLEAN:

View File

@ -23,21 +23,21 @@ set(INC_SYS
)
set(SRC
space_text.c
text_autocomplete.c
text_draw.c
text_format.c
text_format_lua.c
text_format_osl.c
text_format_pov.c
text_format_pov_ini.c
text_format_py.c
text_header.c
text_ops.c
space_text.cc
text_autocomplete.cc
text_draw.cc
text_format.cc
text_format_lua.cc
text_format_osl.cc
text_format_pov.cc
text_format_pov_ini.cc
text_format_py.cc
text_header.cc
text_ops.cc
text_undo.cc
text_format.h
text_intern.h
text_format.hh
text_intern.hh
)
set(LIB

View File

@ -35,17 +35,17 @@
#include "RNA_access.h"
#include "RNA_path.h"
#include "text_format.h"
#include "text_intern.h" /* own include */
#include "text_format.hh"
#include "text_intern.hh" /* own include */
/* ******************** default callbacks for text space ***************** */
static SpaceLink *text_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
static SpaceLink *text_create(const ScrArea * /*area*/, const Scene * /*scene*/)
{
ARegion *region;
SpaceText *stext;
stext = MEM_callocN(sizeof(SpaceText), "inittext");
stext = static_cast<SpaceText *>(MEM_callocN(sizeof(SpaceText), "inittext"));
stext->spacetype = SPACE_TEXT;
stext->lheight = 12;
@ -55,20 +55,20 @@ static SpaceLink *text_create(const ScrArea *UNUSED(area), const Scene *UNUSED(s
stext->showlinenrs = true;
/* header */
region = MEM_callocN(sizeof(ARegion), "header for text");
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "header for text"));
BLI_addtail(&stext->regionbase, region);
region->regiontype = RGN_TYPE_HEADER;
region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
/* footer */
region = MEM_callocN(sizeof(ARegion), "footer for text");
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "footer for text"));
BLI_addtail(&stext->regionbase, region);
region->regiontype = RGN_TYPE_FOOTER;
region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_TOP : RGN_ALIGN_BOTTOM;
/* properties region */
region = MEM_callocN(sizeof(ARegion), "properties region for text");
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "properties region for text"));
BLI_addtail(&stext->regionbase, region);
region->regiontype = RGN_TYPE_UI;
@ -76,7 +76,7 @@ static SpaceLink *text_create(const ScrArea *UNUSED(area), const Scene *UNUSED(s
region->flag = RGN_FLAG_HIDDEN;
/* main region */
region = MEM_callocN(sizeof(ARegion), "main region for text");
region = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "main region for text"));
BLI_addtail(&stext->regionbase, region);
region->regiontype = RGN_TYPE_WINDOW;
@ -89,20 +89,20 @@ static void text_free(SpaceLink *sl)
{
SpaceText *stext = (SpaceText *)sl;
stext->text = NULL;
stext->text = nullptr;
text_free_caches(stext);
}
/* spacetype; init callback */
static void text_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area)) {}
static void text_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
static SpaceLink *text_duplicate(SpaceLink *sl)
{
SpaceText *stextn = MEM_dupallocN(sl);
SpaceText *stextn = static_cast<SpaceText *>(MEM_dupallocN(sl));
/* clear or remove stuff from old */
stextn->runtime.drawcache = NULL; /* space need its own cache */
stextn->runtime.drawcache = nullptr; /* space need its own cache */
return (SpaceLink *)stextn;
}
@ -111,13 +111,13 @@ static void text_listener(const wmSpaceTypeListenerParams *params)
{
ScrArea *area = params->area;
const wmNotifier *wmn = params->notifier;
SpaceText *st = area->spacedata.first;
SpaceText *st = static_cast<SpaceText *>(area->spacedata.first);
/* context changes */
switch (wmn->category) {
case NC_TEXT:
/* check if active text was changed, no need to redraw if text isn't active
* (reference == NULL) means text was unlinked, should update anyway for this
* (reference == nullptr) means text was unlinked, should update anyway for this
* case -- no way to know was text active before unlinking or not */
if (wmn->reference && wmn->reference != st->text) {
break;
@ -220,7 +220,7 @@ static void text_keymap(wmKeyConfig *keyconf)
WM_keymap_ensure(keyconf, "Text", SPACE_TEXT, 0);
}
const char *text_context_dir[] = {"edit_text", NULL};
const char *text_context_dir[] = {"edit_text", nullptr};
static int /*eContextResult*/ text_context(const bContext *C,
const char *member,
@ -233,7 +233,7 @@ static int /*eContextResult*/ text_context(const bContext *C,
return CTX_RESULT_OK;
}
if (CTX_data_equals(member, "edit_text")) {
if (st->text != NULL) {
if (st->text != nullptr) {
CTX_data_id_pointer_set(result, &st->text->id);
}
return CTX_RESULT_OK;
@ -286,7 +286,7 @@ static void text_main_region_draw(const bContext *C, ARegion *region)
static void text_cursor(wmWindow *win, ScrArea *area, ARegion *region)
{
SpaceText *st = area->spacedata.first;
SpaceText *st = static_cast<SpaceText *>(area->spacedata.first);
int wmcursor = WM_CURSOR_TEXT_EDIT;
if (st->text && BLI_rcti_isect_pt(&st->runtime.scroll_region_handle,
@ -301,10 +301,10 @@ static void text_cursor(wmWindow *win, ScrArea *area, ARegion *region)
/* ************* dropboxes ************* */
static bool text_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
static bool text_drop_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
{
if (drag->type == WM_DRAG_PATH) {
const eFileSel_File_Types file_type = WM_drag_get_path_file_type(drag);
const eFileSel_File_Types file_type = eFileSel_File_Types(WM_drag_get_path_file_type(drag));
if (ELEM(file_type, 0, FILE_TYPE_PYSCRIPT, FILE_TYPE_TEXT)) {
return true;
}
@ -312,18 +312,18 @@ static bool text_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNU
return false;
}
static void text_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
static void text_drop_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
{
/* copy drag path to properties */
RNA_string_set(drop->ptr, "filepath", WM_drag_get_path(drag));
}
static bool text_drop_paste_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
static bool text_drop_paste_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
{
return (drag->type == WM_DRAG_ID);
}
static void text_drop_paste(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
static void text_drop_paste(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
{
char *text;
ID *id = WM_drag_get_local_ID(drag, 0);
@ -339,8 +339,8 @@ static void text_dropboxes(void)
{
ListBase *lb = WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy, NULL, NULL);
WM_dropbox_add(lb, "TEXT_OT_insert", text_drop_paste_poll, text_drop_paste, NULL, NULL);
WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy, nullptr, nullptr);
WM_dropbox_add(lb, "TEXT_OT_insert", text_drop_paste_poll, text_drop_paste, nullptr, nullptr);
}
/* ************* end drop *********** */
@ -348,7 +348,7 @@ static void text_dropboxes(void)
/****************** header region ******************/
/* add handlers, stuff you only do once or on area/region changes */
static void text_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region)
static void text_header_region_init(wmWindowManager * /*wm*/, ARegion *region)
{
ED_region_header_init(region);
}
@ -390,15 +390,13 @@ static void text_properties_region_draw(const bContext *C, ARegion *region)
}
}
static void text_id_remap(ScrArea *UNUSED(area),
SpaceLink *slink,
const struct IDRemapper *mappings)
static void text_id_remap(ScrArea * /*area*/, SpaceLink *slink, const IDRemapper *mappings)
{
SpaceText *stext = (SpaceText *)slink;
BKE_id_remapper_apply(mappings, (ID **)&stext->text, ID_REMAP_APPLY_ENSURE_REAL);
}
static void text_space_blend_read_data(BlendDataReader *UNUSED(reader), SpaceLink *sl)
static void text_space_blend_read_data(BlendDataReader * /*reader*/, SpaceLink *sl)
{
SpaceText *st = (SpaceText *)sl;
memset(&st->runtime, 0x0, sizeof(st->runtime));
@ -419,7 +417,7 @@ static void text_space_blend_write(BlendWriter *writer, SpaceLink *sl)
void ED_spacetype_text(void)
{
SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype text");
SpaceType *st = static_cast<SpaceType *>(MEM_callocN(sizeof(SpaceType), "spacetype text"));
ARegionType *art;
st->spaceid = SPACE_TEXT;
@ -440,7 +438,7 @@ void ED_spacetype_text(void)
st->blend_write = text_space_blend_write;
/* regions: main window */
art = MEM_callocN(sizeof(ARegionType), "spacetype text region");
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype text region"));
art->regionid = RGN_TYPE_WINDOW;
art->init = text_main_region_init;
art->draw = text_main_region_draw;
@ -450,7 +448,7 @@ void ED_spacetype_text(void)
BLI_addhead(&st->regiontypes, art);
/* regions: properties */
art = MEM_callocN(sizeof(ARegionType), "spacetype text region");
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype text region"));
art->regionid = RGN_TYPE_UI;
art->prefsizex = UI_COMPACT_PANEL_WIDTH;
art->keymapflag = ED_KEYMAP_UI;
@ -460,7 +458,7 @@ void ED_spacetype_text(void)
BLI_addhead(&st->regiontypes, art);
/* regions: header */
art = MEM_callocN(sizeof(ARegionType), "spacetype text region");
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype text region"));
art->regionid = RGN_TYPE_HEADER;
art->prefsizey = HEADERY;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
@ -470,7 +468,7 @@ void ED_spacetype_text(void)
BLI_addhead(&st->regiontypes, art);
/* regions: footer */
art = MEM_callocN(sizeof(ARegionType), "spacetype text region");
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype text region"));
art->regionid = RGN_TYPE_FOOTER;
art->prefsizey = HEADERY;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FOOTER;

View File

@ -30,8 +30,8 @@
#include "UI_interface.h"
#include "text_format.h"
#include "text_intern.h" /* own include */
#include "text_format.hh"
#include "text_intern.hh" /* own include */
/* -------------------------------------------------------------------- */
/** \name Public API
@ -155,7 +155,7 @@ static GHash *text_autocomplete_build(Text *text)
gh = BLI_ghash_str_new(__func__);
for (linep = text->lines.first; linep; linep = linep->next) {
for (linep = static_cast<TextLine *>(text->lines.first); linep; linep = linep->next) {
size_t i_start = 0;
size_t i_end = 0;
size_t i_pos = 0;
@ -217,7 +217,7 @@ static GHash *text_autocomplete_build(Text *text)
tft = ED_text_format_get(text);
GHASH_ITER (gh_iter, gh) {
const char *s = BLI_ghashIterator_getValue(&gh_iter);
const char *s = static_cast<char *>(BLI_ghashIterator_getValue(&gh_iter));
texttool_suggest_add(s, tft->format_identifier(s));
}
}
@ -288,7 +288,7 @@ static void confirm_suggestion(Text *text)
/** \name Auto Complete Operator
* \{ */
static int text_autocomplete_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int text_autocomplete_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
@ -588,10 +588,10 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
static void text_autocomplete_free(bContext *C, wmOperator *op)
{
GHash *gh = op->customdata;
GHash *gh = static_cast<GHash *>(op->customdata);
if (gh) {
BLI_ghash_free(gh, NULL, MEM_freeN);
op->customdata = NULL;
BLI_ghash_free(gh, nullptr, MEM_freeN);
op->customdata = nullptr;
}
/* other stuff */

View File

@ -31,8 +31,8 @@
#include "UI_resources.h"
#include "UI_view2d.h"
#include "text_format.h"
#include "text_intern.h"
#include "text_format.hh"
#include "text_intern.hh"
#include "WM_api.h"
#include "WM_types.h"
@ -41,12 +41,12 @@
/** \name Text Font Drawing
* \{ */
typedef struct TextDrawContext {
struct TextDrawContext {
int font_id;
int cwidth_px;
int lheight_px;
bool syntax_highlight;
} TextDrawContext;
};
static void text_draw_context_init(const SpaceText *st, TextDrawContext *tdc)
{
@ -58,10 +58,10 @@ static void text_draw_context_init(const SpaceText *st, TextDrawContext *tdc)
static void text_font_begin(const TextDrawContext *tdc)
{
BLF_size(tdc->font_id, (float)tdc->lheight_px);
BLF_size(tdc->font_id, float(tdc->lheight_px));
}
static void text_font_end(const TextDrawContext *UNUSED(tdc)) {}
static void text_font_end(const TextDrawContext * /*tdc*/) {}
static int text_font_draw(const TextDrawContext *tdc, int x, int y, const char *str)
{
@ -207,7 +207,7 @@ void wrap_offset(
text = st->text;
/* Move pointer to first visible line (top) */
linep = text->lines.first;
linep = static_cast<TextLine *>(text->lines.first);
i = st->top;
while (i > 0 && linep) {
int lines = text_get_visible_lines(st, region, linep->line);
@ -416,7 +416,7 @@ static int text_draw_wrapped(const SpaceText *st,
int mi, ma, mstart, mend; /* mem */
char fmt_prev = 0xff;
/* don't draw lines below this */
const int clip_min_y = -(int)(st->runtime.lheight_px - 1);
const int clip_min_y = -int(st->runtime.lheight_px - 1);
flatten_string(st, &fs, str);
str = fs.buf;
@ -509,7 +509,7 @@ static void text_draw(const SpaceText *st,
const bool use_syntax = (tdc->syntax_highlight && format);
FlattenString fs;
int columns, size, n, w = 0, padding, amount = 0;
const char *in = NULL;
const char *in = nullptr;
for (n = flatten_string(st, &fs, str), str = fs.buf; n > 0; n--) {
columns = BLI_str_utf8_char_width_safe(str);
@ -567,7 +567,7 @@ static void text_draw(const SpaceText *st,
/** \name Cache Utilities
* \{ */
typedef struct DrawCache {
struct DrawCache {
int *line_height;
int total_lines, nlines;
@ -580,11 +580,12 @@ typedef struct DrawCache {
/* for partial lines recalculation */
short update_flag;
int valid_head, valid_tail; /* amount of unchanged lines */
} DrawCache;
};
static void text_drawcache_init(SpaceText *st)
{
DrawCache *drawcache = MEM_callocN(sizeof(DrawCache), "text draw cache");
DrawCache *drawcache = static_cast<DrawCache *>(
MEM_callocN(sizeof(DrawCache), "text draw cache"));
drawcache->winx = -1;
drawcache->nlines = BLI_listbase_count(&st->text->lines);
@ -599,13 +600,13 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
int full_update = 0, nlines = 0;
Text *txt = st->text;
if (st->runtime.drawcache == NULL) {
if (st->runtime.drawcache == nullptr) {
text_drawcache_init(st);
}
text_update_character_width(st);
drawcache = st->runtime.drawcache;
drawcache = static_cast<DrawCache *>(st->runtime.drawcache);
nlines = drawcache->nlines;
/* check if full cache update is needed */
@ -634,7 +635,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
}
if (drawcache->update_flag) {
TextLine *line = st->text->lines.first;
TextLine *line = static_cast<TextLine *>(st->text->lines.first);
int lineno = 0, size, lines_count;
int *fp = drawcache->line_height, *new_tail, *old_tail;
@ -642,10 +643,10 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
size = sizeof(int) * nlines;
if (fp) {
fp = MEM_reallocN(fp, size);
fp = static_cast<int *>(MEM_reallocN(fp, size));
}
else {
fp = MEM_callocN(size, "text drawcache line_height");
fp = static_cast<int *>(MEM_callocN(size, "text drawcache line_height"));
}
drawcache->valid_tail = drawcache->valid_head = 0;
@ -716,12 +717,12 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
void text_drawcache_tag_update(SpaceText *st, const bool full)
{
/* This happens if text editor ops are called from Python. */
if (st == NULL) {
if (st == nullptr) {
return;
}
if (st->runtime.drawcache != NULL) {
DrawCache *drawcache = st->runtime.drawcache;
if (st->runtime.drawcache != nullptr) {
DrawCache *drawcache = static_cast<DrawCache *>(st->runtime.drawcache);
Text *txt = st->text;
if (drawcache->update_flag) {
@ -764,7 +765,7 @@ void text_drawcache_tag_update(SpaceText *st, const bool full)
void text_free_caches(SpaceText *st)
{
DrawCache *drawcache = st->runtime.drawcache;
DrawCache *drawcache = static_cast<DrawCache *>(st->runtime.drawcache);
if (drawcache) {
if (drawcache->line_height) {
@ -784,7 +785,7 @@ void text_free_caches(SpaceText *st)
/* cache should be updated in caller */
static int text_get_visible_lines_no(const SpaceText *st, int lineno)
{
const DrawCache *drawcache = st->runtime.drawcache;
const DrawCache *drawcache = static_cast<const DrawCache *>(st->runtime.drawcache);
return drawcache->line_height[lineno];
}
@ -853,7 +854,7 @@ int text_get_total_lines(SpaceText *st, ARegion *region)
DrawCache *drawcache;
text_update_drawcache(st, region);
drawcache = st->runtime.drawcache;
drawcache = static_cast<DrawCache *>(st->runtime.drawcache);
return drawcache->total_lines;
}
@ -910,13 +911,15 @@ static void calc_text_rcts(SpaceText *st, ARegion *region, rcti *scroll, rcti *b
CLAMP(st->runtime.scroll_region_handle.ymin, pix_bottom_margin, region->winy - pix_top_margin);
CLAMP(st->runtime.scroll_region_handle.ymax, pix_bottom_margin, region->winy - pix_top_margin);
st->runtime.scroll_px_per_line = (pix_available > 0) ? (float)ltexth / pix_available : 0;
st->runtime.scroll_px_per_line = (pix_available > 0) ? float(ltexth) / pix_available : 0;
if (st->runtime.scroll_px_per_line < 0.1f) {
st->runtime.scroll_px_per_line = 0.1f;
}
curl_off = text_get_span_wrap(st, region, st->text->lines.first, st->text->curl);
sell_off = text_get_span_wrap(st, region, st->text->lines.first, st->text->sell);
curl_off = text_get_span_wrap(
st, region, static_cast<TextLine *>(st->text->lines.first), st->text->curl);
sell_off = text_get_span_wrap(
st, region, static_cast<TextLine *>(st->text->lines.first), st->text->sell);
lhlstart = MIN2(curl_off, sell_off);
lhlend = MAX2(curl_off, sell_off);
@ -1013,16 +1016,13 @@ static void draw_textscroll(const SpaceText *st, rcti *scroll, rcti *back)
BLI_rcti_size_y(&st->runtime.scroll_region_select));
UI_GetThemeColor3fv(TH_HILITE, col);
col[3] = 0.18f;
UI_draw_roundbox_aa(
&(const rctf){
.xmin = st->runtime.scroll_region_select.xmin + 1,
.xmax = st->runtime.scroll_region_select.xmax - 1,
.ymin = st->runtime.scroll_region_select.ymin,
.ymax = st->runtime.scroll_region_select.ymax,
},
true,
rad,
col);
rctf rect;
rect.xmin = st->runtime.scroll_region_select.xmin + 1;
rect.xmax = st->runtime.scroll_region_select.xmax - 1;
rect.ymin = st->runtime.scroll_region_select.ymin;
rect.ymax = st->runtime.scroll_region_select.ymax;
UI_draw_roundbox_aa(&rect, true, rad, col);
}
/** \} */
@ -1117,7 +1117,7 @@ static void draw_documentation(const SpaceText *st, ARegion *region)
buf[i] = '\0';
if (lines >= 0) {
y -= st->runtime.lheight_px;
text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, NULL);
text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, nullptr);
}
i = 0;
br = DOC_WIDTH;
@ -1128,7 +1128,7 @@ static void draw_documentation(const SpaceText *st, ARegion *region)
buf[br] = '\0';
if (lines >= 0) {
y -= st->runtime.lheight_px;
text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, NULL);
text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, nullptr);
}
p -= i - br - 1; /* Rewind pointer to last break */
i = 0;
@ -1177,7 +1177,8 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
top = texttool_suggest_top();
wrap_offset(st, region, st->text->curl, st->text->curc, &offl, &offc);
vcurl = txt_get_span(st->text->lines.first, st->text->curl) - st->top + offl;
vcurl = txt_get_span(static_cast<TextLine *>(st->text->lines.first), st->text->curl) - st->top +
offl;
vcurc = text_get_char_pos(st, st->text->curl->line, st->text->curc) - st->left + offc;
x = TXT_BODY_LEFT(st) + (vcurc * st->runtime.cwidth_px);
@ -1196,14 +1197,14 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
}
/* not needed but stands out nicer */
UI_draw_box_shadow(
&(const rctf){
.xmin = x,
.xmax = x + boxw,
.ymin = y - boxh,
.ymax = y,
},
220);
{
rctf rect;
rect.xmin = x;
rect.xmax = x + boxw;
rect.ymin = y - boxh;
rect.ymax = y;
UI_draw_box_shadow(&rect, 220);
}
uint pos = GPU_vertformat_attr_add(
immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
@ -1222,7 +1223,7 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
}
for (i = 0; i < SUGG_LIST_SIZE && item; i++, item = item->next) {
int len = txt_utf8_forward_columns(item->name, SUGG_LIST_WIDTH, NULL) - item->name;
int len = txt_utf8_forward_columns(item->name, SUGG_LIST_WIDTH, nullptr) - item->name;
y -= lheight;
@ -1242,7 +1243,7 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
}
format_draw_color(tdc, item->type);
text_draw(st, tdc, str, 0, 0, x + margin_x, y - 1, NULL);
text_draw(st, tdc, str, 0, 0, x + margin_x, y - 1, nullptr);
if (item == last) {
break;
@ -1266,7 +1267,7 @@ static void draw_text_decoration(SpaceText *st, ARegion *region)
/* Convert to view space character coordinates to determine if cursor is hidden */
wrap_offset(st, region, text->sell, text->selc, &offl, &offc);
vsell = txt_get_span(text->lines.first, text->sell) - st->top + offl;
vsell = txt_get_span(static_cast<TextLine *>(text->lines.first), text->sell) - st->top + offl;
vselc = text_get_char_pos(st, text->sell->line, text->selc) - st->left + offc;
if (vselc < 0) {
@ -1287,7 +1288,7 @@ static void draw_text_decoration(SpaceText *st, ARegion *region)
if (text->curl != text->sell || text->curc != text->selc) {
/* Convert all to view space character coordinates */
wrap_offset(st, region, text->curl, text->curc, &offl, &offc);
vcurl = txt_get_span(text->lines.first, text->curl) - st->top + offl;
vcurl = txt_get_span(static_cast<TextLine *>(text->lines.first), text->curl) - st->top + offl;
vcurc = text_get_char_pos(st, text->curl->line, text->curc) - st->left + offc;
if (vcurc < 0) {
@ -1449,7 +1450,7 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi
linep = startl;
c = startc;
fc = BLI_str_utf8_offset_to_index(linep->line, startc);
endl = NULL;
endl = nullptr;
endc = -1;
find = -b;
stack = 0;
@ -1559,7 +1560,7 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi
viewc = text_get_char_pos(st, startl->line, startc) - st->left + offc;
if (viewc >= 0) {
viewl = txt_get_span(text->lines.first, startl) - st->top + offl;
viewl = txt_get_span(static_cast<TextLine *>(text->lines.first), startl) - st->top + offl;
text_font_draw_character(
tdc, x + viewc * st->runtime.cwidth_px, y - viewl * TXT_LINE_HEIGHT(st), ch);
@ -1573,7 +1574,7 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi
viewc = text_get_char_pos(st, endl->line, endc) - st->left + offc;
if (viewc >= 0) {
viewl = txt_get_span(text->lines.first, endl) - st->top + offl;
viewl = txt_get_span(static_cast<TextLine *>(text->lines.first), endl) - st->top + offl;
text_font_draw_character(
tdc, x + viewc * st->runtime.cwidth_px, y - viewl * TXT_LINE_HEIGHT(st), ch);
@ -1609,10 +1610,10 @@ void draw_text_main(SpaceText *st, ARegion *region)
st->runtime.lheight_px = (U.widget_unit * st->lheight) / 20;
/* don't draw lines below this */
const int clip_min_y = -(int)(st->runtime.lheight_px - 1);
const int clip_min_y = -int(st->runtime.lheight_px - 1);
st->runtime.viewlines = (st->runtime.lheight_px) ?
(int)(region->winy - clip_min_y) / TXT_LINE_HEIGHT(st) :
int(region->winy - clip_min_y) / TXT_LINE_HEIGHT(st) :
0;
text_draw_context_init(st, &tdc);
@ -1629,7 +1630,7 @@ void draw_text_main(SpaceText *st, ARegion *region)
/* update syntax formatting if needed */
tft = ED_text_format_get(text);
tmp = text->lines.first;
tmp = static_cast<TextLine *>(text->lines.first);
lineno = 0;
for (i = 0; i < st->top && tmp; i++) {
if (tdc.syntax_highlight && !tmp->format) {
@ -1658,7 +1659,7 @@ void draw_text_main(SpaceText *st, ARegion *region)
text_font_begin(&tdc);
tdc.cwidth_px = max_ii((int)BLF_fixed_width(tdc.font_id), 1);
tdc.cwidth_px = max_ii(int(BLF_fixed_width(tdc.font_id)), 1);
st->runtime.cwidth_px = tdc.cwidth_px;
/* draw line numbers background */
@ -1759,7 +1760,7 @@ void text_update_character_width(SpaceText *st)
text_font_begin(&tdc);
st->runtime.cwidth_px = BLF_fixed_width(tdc.font_id);
st->runtime.cwidth_px = MAX2(st->runtime.cwidth_px, (char)1);
st->runtime.cwidth_px = MAX2(st->runtime.cwidth_px, char(1));
text_font_end(&tdc);
}
@ -1767,7 +1768,7 @@ bool ED_text_activate_in_screen(bContext *C, Text *text)
{
ScrArea *area = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_TEXT, 0);
if (area) {
SpaceText *st = area->spacedata.first;
SpaceText *st = static_cast<SpaceText *>(area->spacedata.first);
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
st->text = text;
if (region) {
@ -1785,7 +1786,7 @@ void ED_text_scroll_to_cursor(SpaceText *st, ARegion *region, const bool center)
Text *text;
int i, x, winx = region->winx;
if (ELEM(NULL, st, st->text, st->text->curl)) {
if (ELEM(nullptr, st, st->text, st->text->curl)) {
return;
}
@ -1793,7 +1794,7 @@ void ED_text_scroll_to_cursor(SpaceText *st, ARegion *region, const bool center)
text_update_character_width(st);
i = txt_get_span(text->lines.first, text->sell);
i = txt_get_span(static_cast<TextLine *>(text->lines.first), text->sell);
if (st->wordwrap) {
int offl, offc;
wrap_offset(st, region, text->sell, text->selc, &offl, &offc);
@ -1851,7 +1852,7 @@ void text_scroll_to_cursor__area(SpaceText *st, ScrArea *area, const bool center
{
ARegion *region;
if (ELEM(NULL, st, st->text, st->text->curl)) {
if (ELEM(nullptr, st, st->text, st->text->curl)) {
return;
}
@ -1875,13 +1876,13 @@ bool ED_text_region_location_from_cursor(SpaceText *st,
const int cursor_co[2],
int r_pixel_co[2])
{
TextLine *line = NULL;
TextLine *line = nullptr;
if (!st->text) {
goto error;
}
line = BLI_findlink(&st->text->lines, cursor_co[0]);
line = static_cast<TextLine *>(BLI_findlink(&st->text->lines, cursor_co[0]));
if (!line || (cursor_co[1] < 0) || (cursor_co[1] > line->len)) {
goto error;
}

View File

@ -6,7 +6,7 @@
* \ingroup sptext
*/
#include <string.h>
#include <cstring>
#include "MEM_guardedalloc.h"
@ -18,7 +18,7 @@
#include "ED_text.h"
#include "text_format.h"
#include "text_format.hh"
/****************** flatten string **********************/
@ -31,8 +31,8 @@ static void flatten_string_append(FlattenString *fs, const char *c, int accum, i
int *naccum;
fs->len *= 2;
nbuf = MEM_callocN(sizeof(*fs->buf) * fs->len, "fs->buf");
naccum = MEM_callocN(sizeof(*fs->accum) * fs->len, "fs->accum");
nbuf = static_cast<char *>(MEM_callocN(sizeof(*fs->buf) * fs->len, "fs->buf"));
naccum = static_cast<int *>(MEM_callocN(sizeof(*fs->accum) * fs->len, "fs->accum"));
memcpy(nbuf, fs->buf, fs->pos * sizeof(*fs->buf));
memcpy(naccum, fs->accum, fs->pos * sizeof(*fs->accum));
@ -99,7 +99,7 @@ void flatten_string_free(FlattenString *fs)
int flatten_string_strlen(FlattenString *fs, const char *str)
{
const int len = (fs->pos - (int)(str - fs->buf)) - 1;
const int len = (fs->pos - int(str - fs->buf)) - 1;
BLI_assert(strlen(str) == len);
return len;
}
@ -109,14 +109,14 @@ int text_check_format_len(TextLine *line, uint len)
if (line->format) {
if (strlen(line->format) < len) {
MEM_freeN(line->format);
line->format = MEM_mallocN(len + 2, "SyntaxFormat");
line->format = static_cast<char *>(MEM_mallocN(len + 2, "SyntaxFormat"));
if (!line->format) {
return 0;
}
}
}
else {
line->format = MEM_mallocN(len + 2, "SyntaxFormat");
line->format = static_cast<char *>(MEM_mallocN(len + 2, "SyntaxFormat"));
if (!line->format) {
return 0;
}
@ -164,7 +164,7 @@ void text_format_fill_ascii(const char **str_p, char **fmt_p, const char type, c
}
/* *** Registration *** */
static ListBase tft_lb = {NULL, NULL};
static ListBase tft_lb = {nullptr, nullptr};
void ED_text_format_register(TextFormatType *tft)
{
BLI_addtail(&tft_lb, tft);
@ -179,7 +179,7 @@ TextFormatType *ED_text_format_get(Text *text)
if (text_ext) {
text_ext++; /* skip the '.' */
/* Check all text formats in the static list */
for (tft = tft_lb.first; tft; tft = tft->next) {
for (tft = static_cast<TextFormatType *>(tft_lb.first); tft; tft = tft->next) {
/* All formats should have an ext, but just in case */
const char **ext;
for (ext = tft->ext; *ext; ext++) {
@ -193,11 +193,11 @@ TextFormatType *ED_text_format_get(Text *text)
/* If we make it here we never found an extension that worked - return
* the "default" text format */
return tft_lb.first;
return static_cast<TextFormatType *>(tft_lb.first);
}
/* Return the "default" text format */
return tft_lb.first;
return static_cast<TextFormatType *>(tft_lb.first);
}
const char *ED_text_format_comment_line_prefix(Text *text)
@ -208,14 +208,14 @@ const char *ED_text_format_comment_line_prefix(Text *text)
bool ED_text_is_syntax_highlight_supported(Text *text)
{
if (text == NULL) {
if (text == nullptr) {
return false;
}
TextFormatType *tft;
const char *text_ext = BLI_path_extension(text->id.name + 2);
if (text_ext == NULL) {
if (text_ext == nullptr) {
/* Extensionless data-blocks are considered highlightable as Python. */
return true;
}
@ -226,7 +226,7 @@ bool ED_text_is_syntax_highlight_supported(Text *text)
}
/* Check all text formats in the static list */
for (tft = tft_lb.first; tft; tft = tft->next) {
for (tft = static_cast<TextFormatType *>(tft_lb.first); tft; tft = tft->next) {
/* All formats should have an ext, but just in case */
const char **ext;
for (ext = tft->ext; *ext; ext++) {

View File

@ -8,18 +8,20 @@
#pragma once
struct Text;
/* *** Flatten String *** */
typedef struct FlattenString {
struct FlattenString {
char fixedbuf[256];
int fixedaccum[256];
char *buf;
int *accum;
int pos, len;
} FlattenString;
};
/**
* Format continuation flags (stored just after the NULL terminator).
* Format continuation flags (stored just after the null terminator).
*/
enum {
FMT_CONT_NOP = 0, /* no continuation */
@ -75,7 +77,7 @@ typedef struct TextFormatType {
*/
void (*format_line)(SpaceText *st, TextLine *line, bool do_next);
const char **ext; /* NULL terminated extensions */
const char **ext; /* Null terminated extensions. */
/** The prefix of a single-line line comment (without trailing space). */
const char *comment_line;
@ -104,15 +106,34 @@ enum {
FMT_TYPE_DEFAULT = 'q',
};
TextFormatType *ED_text_format_get(Text *text);
TextFormatType *ED_text_format_get(struct Text *text);
void ED_text_format_register(TextFormatType *tft);
/* formatters */
void ED_text_format_register_py(void);
void ED_text_format_register_osl(void);
void ED_text_format_register_lua(void);
void ED_text_format_register_pov(void);
void ED_text_format_register_pov_ini(void);
void ED_text_format_register_py();
void ED_text_format_register_osl();
void ED_text_format_register_lua();
void ED_text_format_register_pov();
void ED_text_format_register_pov_ini();
#define STR_LITERAL_STARTSWITH(str, str_literal, len_var) \
(strncmp(str, str_literal, len_var = (sizeof(str_literal) - 1)) == 0)
/* Workaround `C1061` with MSVC (looks like a bug),
* this can be removed if the issue is resolved.
*
* Add #MSVC_WORKAROUND_BREAK to break up else-if's blocks to be under 128.
* `_keep_me` just ensures #MSVC_WORKAROUND_BREAK follows an #MSVC_WORKAROUND_INIT. */
#ifdef _MSC_VER
# define MSVC_WORKAROUND_INIT(i) \
char _keep_me = 0; \
i = -1; \
((void)0)
# define MSVC_WORKAROUND_BREAK(i) \
} \
((void)_keep_me); \
if (i != -1) {
#else
# define MSVC_WORKAROUND_INIT(i) ((void)0)
# define MSVC_WORKAROUND_BREAK(i)
#endif

View File

@ -6,7 +6,7 @@
* \ingroup sptext
*/
#include <string.h>
#include <cstring>
#include "BLI_blenlib.h"
@ -15,7 +15,7 @@
#include "BKE_text.h"
#include "text_format.h"
#include "text_format.hh"
/* *** Lua Keywords (for format_line) *** */
@ -173,7 +173,7 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_
int len, i;
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
if (line->prev && line->prev->format != nullptr) {
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont) == cont);
@ -183,7 +183,7 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_
}
/* Get original continuation from this line */
if (line->format != NULL) {
if (line->format != nullptr) {
fmt = line->format;
cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
@ -258,7 +258,7 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_
}
/* Single line comment */
else if (*str == '-' && *(str + 1) == '-') {
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - (int)(fmt - line->format));
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - int(fmt - line->format));
}
else if (ELEM(*str, '"', '\'')) {
/* Strings */
@ -336,10 +336,10 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_
flatten_string_free(&fs);
}
void ED_text_format_register_lua(void)
void ED_text_format_register_lua()
{
static TextFormatType tft = {NULL};
static const char *ext[] = {"lua", NULL};
static TextFormatType tft = {nullptr};
static const char *ext[] = {"lua", nullptr};
tft.format_identifier = txtfmt_lua_format_identifier;
tft.format_line = txtfmt_lua_format_line;

View File

@ -6,7 +6,7 @@
* \ingroup sptext
*/
#include <string.h>
#include <cstring>
#include "BLI_blenlib.h"
@ -15,7 +15,7 @@
#include "BKE_text.h"
#include "text_format.h"
#include "text_format.hh"
/* *** Local Functions (for format_line) *** */
@ -199,7 +199,7 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_
int len, i;
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
if (line->prev && line->prev->format != nullptr) {
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont) == cont);
@ -209,7 +209,7 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_
}
/* Get original continuation from this line */
if (line->format != NULL) {
if (line->format != nullptr) {
fmt = line->format;
cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
@ -271,7 +271,7 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_
/* Deal with comments first */
if (*str == '/' && *(str + 1) == '/') {
/* fill the remaining line */
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - (int)(fmt - line->format));
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - int(fmt - line->format));
}
/* C-Style (multi-line) comments */
else if (*str == '/' && *(str + 1) == '*') {
@ -354,10 +354,10 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_
flatten_string_free(&fs);
}
void ED_text_format_register_osl(void)
void ED_text_format_register_osl()
{
static TextFormatType tft = {NULL};
static const char *ext[] = {"osl", NULL};
static TextFormatType tft = {nullptr};
static const char *ext[] = {"osl", nullptr};
tft.format_identifier = txtfmt_osl_format_identifier;
tft.format_line = txtfmt_osl_format_line;

View File

@ -6,7 +6,7 @@
* \ingroup sptext
*/
#include <string.h>
#include <cstring>
#include "BLI_blenlib.h"
@ -15,7 +15,7 @@
#include "BKE_text.h"
#include "text_format.h"
#include "text_format.hh"
/* *** POV Keywords (for format_line) *** */
@ -88,6 +88,7 @@ static int txtfmt_pov_find_reserved_keywords(const char *string)
/* Keep aligned args for readability. */
/* clang-format off */
MSVC_WORKAROUND_INIT(i);
/* Float Functions */
if (STR_LITERAL_STARTSWITH(string, "conserve_energy", len)) { i = len;
@ -185,6 +186,7 @@ static int txtfmt_pov_find_reserved_keywords(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "sky", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "up", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "ln", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Color Identifiers */
} else if (STR_LITERAL_STARTSWITH(string, "transmit", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "filter", len)) { i = len;
@ -248,6 +250,7 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
/* Keep aligned args for readability. */
/* clang-format off */
MSVC_WORKAROUND_INIT(i);
/* Language Keywords */
if (STR_LITERAL_STARTSWITH(string, "reflection_exponent", len)) { i = len;
@ -319,6 +322,7 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "now", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "pot", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "type", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Animation Options */
} else if (STR_LITERAL_STARTSWITH(string, "global_settings", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "input_file_name", len)) { i = len;
@ -332,6 +336,7 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "clock_delta", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "clock_on", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "clock", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Spline Identifiers */
} else if (STR_LITERAL_STARTSWITH(string, "extended_x_spline", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "general_x_spline", len)) { i = len;
@ -347,6 +352,7 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "linear_sweep", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "conic_sweep", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "b_spline", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Patterns */
} else if (STR_LITERAL_STARTSWITH(string, "pigment_pattern", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "image_pattern", len)) { i = len;
@ -399,6 +405,7 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "wood", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "agate", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "aoi", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Objects */
} else if (STR_LITERAL_STARTSWITH(string, "superellipsoid", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "bicubic_patch", len)) { i = len;
@ -467,13 +474,12 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
} else { i = 0;
}
/* clang-format off */
/* clang-format on */
/* If next source char is an identifier (eg. 'i' in "definite") no match */
return (i == 0 || text_check_identifier(string[i])) ? -1 : i;
}
/**
* Checks the specified source string for a POV modifiers. This
* name must start at the beginning of the source string and must be followed
@ -488,6 +494,11 @@ static int txtfmt_pov_find_reserved_builtins(const char *string)
static int txtfmt_pov_find_specialvar(const char *string)
{
int i, len;
/* Keep aligned args for readability. */
/* clang-format off */
MSVC_WORKAROUND_INIT(i);
/* Modifiers */
if (STR_LITERAL_STARTSWITH(string, "dispersion_samples", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "projected_through", len)) { i = len;
@ -579,6 +590,7 @@ static int txtfmt_pov_find_specialvar(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "distance", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "autostop", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "caustics", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
} else if (STR_LITERAL_STARTSWITH(string, "octaves", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "aa_level", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "frequency", len)) { i = len;
@ -633,6 +645,7 @@ static int txtfmt_pov_find_specialvar(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "ratio", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "open", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "ior", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Light Types and options. */
} else if (STR_LITERAL_STARTSWITH(string, "area_light", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "looks_like", len)) { i = len;
@ -643,6 +656,7 @@ static int txtfmt_pov_find_specialvar(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "point_at", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "falloff", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "radius", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* Camera Types and options. */
} else if (STR_LITERAL_STARTSWITH(string, "omni_directional_stereo", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "lambert_cylindrical", len)) { i = len;
@ -687,6 +701,8 @@ static int txtfmt_pov_find_specialvar(const char *string)
} else { i = 0;
}
/* clang-format on */
/* If next source char is an identifier (eg. 'i' in "definite") no match */
return (i == 0 || text_check_identifier(string[i])) ? -1 : i;
}
@ -772,7 +788,7 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_
int len, i;
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
if (line->prev && line->prev->format != nullptr) {
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont) == cont);
@ -782,7 +798,7 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_
}
/* Get original continuation from this line */
if (line->format != NULL) {
if (line->format != nullptr) {
fmt = line->format;
cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
@ -851,7 +867,7 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_
}
/* Single line comment */
else if (*str == '/' && *(str + 1) == '/') {
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - (int)(fmt - line->format));
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - int(fmt - line->format));
}
else if (ELEM(*str, '"', '\'')) {
/* Strings */
@ -931,10 +947,10 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_
flatten_string_free(&fs);
}
void ED_text_format_register_pov(void)
void ED_text_format_register_pov()
{
static TextFormatType tft = {NULL};
static const char *ext[] = {"pov", "inc", "mcr", "mac", NULL};
static TextFormatType tft = {nullptr};
static const char *ext[] = {"pov", "inc", "mcr", "mac", nullptr};
tft.format_identifier = txtfmt_pov_format_identifier;
tft.format_line = txtfmt_pov_format_line;

View File

@ -6,7 +6,7 @@
* \ingroup sptext
*/
#include <string.h>
#include <cstring>
#include "BLI_blenlib.h"
@ -15,7 +15,7 @@
#include "BKE_text.h"
#include "text_format.h"
#include "text_format.hh"
/* *** POV INI Keywords (for format_line) *** */
@ -95,7 +95,7 @@ static int txtfmt_ini_find_reserved(const char *string)
/* Keep aligned args for readability. */
/* clang-format off */
MSVC_WORKAROUND_INIT(i);
/* POV-Ray Built-in INI Variables
* list is from...
* http://www.povray.org/documentation/view/3.7.0/212/
@ -158,6 +158,7 @@ static int txtfmt_ini_find_reserved(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "Bounding_Method", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "Create_Ini", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "Display_Gamma", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
} else if (STR_LITERAL_STARTSWITH(string, "Display", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "Version", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "Pause_When_Done", len)) { i = len;
@ -208,6 +209,7 @@ static int txtfmt_ini_find_reserved(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "WarningColour", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "ErrorColour", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "BackgroundColour", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
} else if (STR_LITERAL_STARTSWITH(string, "DropToEditor", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "LastRenderName", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "LastRenderPath", len)) { i = len;
@ -268,6 +270,7 @@ static int txtfmt_ini_find_reserved(const char *string)
} else if (STR_LITERAL_STARTSWITH(string, "Dither", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "Flags", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "Font", len)) { i = len;
MSVC_WORKAROUND_BREAK(i)
/* File-types. */
} else if (STR_LITERAL_STARTSWITH(string, "df3", len)) { i = len;
} else if (STR_LITERAL_STARTSWITH(string, "exr", len)) { i = len;
@ -357,7 +360,7 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool
int len, i;
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
if (line->prev && line->prev->format != nullptr) {
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont) == cont);
@ -367,7 +370,7 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool
}
/* Get original continuation from this line */
if (line->format != NULL) {
if (line->format != nullptr) {
fmt = line->format;
cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
@ -429,7 +432,7 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool
/* Multi-line comments not supported */
/* Single line comment */
if (*str == ';') {
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - (int)(fmt - line->format));
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - int(fmt - line->format));
}
else if (ELEM(*str, '"', '\'')) {
/* Strings */
@ -507,10 +510,10 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool
flatten_string_free(&fs);
}
void ED_text_format_register_pov_ini(void)
void ED_text_format_register_pov_ini()
{
static TextFormatType tft = {NULL};
static const char *ext[] = {"ini", NULL};
static TextFormatType tft = {nullptr};
static const char *ext[] = {"ini", nullptr};
tft.format_identifier = txtfmt_pov_ini_format_identifier;
tft.format_line = txtfmt_pov_ini_format_line;

View File

@ -6,7 +6,7 @@
* \ingroup sptext
*/
#include <string.h>
#include <cstring>
#include "BLI_blenlib.h"
@ -15,7 +15,7 @@
#include "BKE_text.h"
#include "text_format.h"
#include "text_format.hh"
/* *** Local Functions (for format_line) *** */
@ -239,7 +239,7 @@ static uint txtfmt_py_numeral_string_count_zeros(const char *string)
static int txtfmt_py_find_numeral_inner(const char *string)
{
if (string == NULL || *string == '\0') {
if (string == nullptr || *string == '\0') {
return -1;
}
@ -281,7 +281,7 @@ static int txtfmt_py_find_numeral_inner(const char *string)
static int txtfmt_py_literal_numeral(const char *string, char prev_fmt)
{
if (string == NULL || *string == '\0') {
if (string == nullptr || *string == '\0') {
return -1;
}
@ -339,7 +339,7 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const bool do_n
int len, i;
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
if (line->prev && line->prev->format != nullptr) {
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont) == cont);
@ -349,7 +349,7 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const bool do_n
}
/* Get original continuation from this line */
if (line->format != NULL) {
if (line->format != nullptr) {
fmt = line->format;
cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
@ -411,7 +411,7 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const bool do_n
/* Deal with comments first */
if (*str == '#') {
/* fill the remaining line */
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - (int)(fmt - line->format));
text_format_fill(&str, &fmt, FMT_TYPE_COMMENT, len - int(fmt - line->format));
}
else if (ELEM(*str, '"', '\'')) {
/* Strings */
@ -546,10 +546,10 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const bool do_n
flatten_string_free(&fs);
}
void ED_text_format_register_py(void)
void ED_text_format_register_py()
{
static TextFormatType tft = {NULL};
static const char *ext[] = {"py", NULL};
static TextFormatType tft = {nullptr};
static const char *ext[] = {"py", nullptr};
tft.format_identifier = txtfmt_py_format_identifier;
tft.format_line = txtfmt_py_format_line;

View File

@ -21,7 +21,7 @@
#include "UI_interface.h"
#include "text_intern.h"
#include "text_intern.hh"
/* ************************ header area region *********************** */
@ -40,11 +40,11 @@ static ARegion *text_has_properties_region(ScrArea *area)
region = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
/* is error! */
if (region == NULL) {
return NULL;
if (region == nullptr) {
return nullptr;
}
arnew = MEM_callocN(sizeof(ARegion), "properties region");
arnew = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "properties region"));
BLI_insertlinkafter(&area->regionbase, region, arnew);
arnew->regiontype = RGN_TYPE_UI;
@ -57,10 +57,10 @@ static ARegion *text_has_properties_region(ScrArea *area)
static bool text_properties_poll(bContext *C)
{
return (CTX_wm_space_text(C) != NULL);
return (CTX_wm_space_text(C) != nullptr);
}
static int text_text_search_exec(bContext *C, wmOperator *UNUSED(op))
static int text_text_search_exec(bContext *C, wmOperator * /*op*/)
{
ScrArea *area = CTX_wm_area(C);
ARegion *region = text_has_properties_region(area);

View File

@ -6,8 +6,8 @@
* \ingroup sptext
*/
#include <errno.h>
#include <string.h>
#include <cerrno>
#include <cstring>
#include "MEM_guardedalloc.h"
@ -45,8 +45,8 @@
# include "BPY_extern_run.h"
#endif
#include "text_format.h"
#include "text_intern.h"
#include "text_format.hh"
#include "text_intern.hh"
static void txt_screen_clamp(SpaceText *st, ARegion *region);
@ -118,7 +118,7 @@ static char *buf_tabs_to_spaces(const char *in_buf, const int tab_size, int *r_o
/* Allocate output before with extra space for expanded tabs. */
const int out_size = strlen(in_buf) + num_tabs * (tab_size - 1) + 1;
char *out_buf = MEM_mallocN(out_size * sizeof(char), __func__);
char *out_buf = static_cast<char *>(MEM_mallocN(out_size * sizeof(char), __func__));
/* Fill output buffer. */
int spaces_until_tab = 0;
@ -169,8 +169,8 @@ static void text_select_update_primary_clipboard(const Text *text)
if (!txt_has_sel(text)) {
return;
}
char *buf = txt_sel_to_buf(text, NULL);
if (buf == NULL) {
char *buf = txt_sel_to_buf(text, nullptr);
if (buf == nullptr) {
return;
}
WM_clipboard_text_set(buf, true);
@ -183,7 +183,7 @@ static void text_select_update_primary_clipboard(const Text *text)
/** \name Operator Poll
* \{ */
static bool text_new_poll(bContext *UNUSED(C))
static bool text_new_poll(bContext * /*C*/)
{
return true;
}
@ -272,7 +272,7 @@ void text_update_edited(Text *text)
{
TextLine *line;
for (line = text->lines.first; line; line = line->next) {
for (line = static_cast<TextLine *>(text->lines.first); line; line = line->next) {
text_update_line_edited(line);
}
}
@ -283,7 +283,7 @@ void text_update_edited(Text *text)
/** \name New Operator
* \{ */
static int text_new_exec(bContext *C, wmOperator *UNUSED(op))
static int text_new_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
Main *bmain = CTX_data_main(C);
@ -298,7 +298,7 @@ static int text_new_exec(bContext *C, wmOperator *UNUSED(op))
if (prop) {
RNA_id_pointer_create(&text->id, &idptr);
RNA_property_pointer_set(&ptr, prop, idptr, NULL);
RNA_property_pointer_set(&ptr, prop, idptr, nullptr);
RNA_property_update(C, &ptr, prop);
}
else if (st) {
@ -338,13 +338,14 @@ void TEXT_OT_new(wmOperatorType *ot)
static void text_open_init(bContext *C, wmOperator *op)
{
PropertyPointerRNA *pprop;
PropertyPointerRNA *pprop = static_cast<PropertyPointerRNA *>(
MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA"));
op->customdata = pprop = MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
op->customdata = pprop;
UI_context_active_but_prop_get_templateID(C, &pprop->ptr, &pprop->prop);
}
static void text_open_cancel(bContext *UNUSED(C), wmOperator *op)
static void text_open_cancel(bContext * /*C*/, wmOperator *op)
{
MEM_freeN(op->customdata);
}
@ -375,11 +376,11 @@ static int text_open_exec(bContext *C, wmOperator *op)
}
/* hook into UI */
pprop = op->customdata;
pprop = static_cast<PropertyPointerRNA *>(op->customdata);
if (pprop->prop) {
RNA_id_pointer_create(&text->id, &idptr);
RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr, NULL);
RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr, nullptr);
RNA_property_update(C, &pprop->ptr, pprop->prop);
}
else if (st) {
@ -398,7 +399,7 @@ static int text_open_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static int text_open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int text_open_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
Main *bmain = CTX_data_main(C);
Text *text = CTX_data_edit_text(C);
@ -440,7 +441,7 @@ void TEXT_OT_open(wmOperatorType *ot)
FILE_DEFAULTDISPLAY,
FILE_SORT_DEFAULT); /* TODO: relative_path. */
RNA_def_boolean(
ot->srna, "internal", 0, "Make Internal", "Make text file internal after loading");
ot->srna, "internal", false, "Make Internal", "Make text file internal after loading");
}
/** \} */
@ -462,7 +463,7 @@ static int text_reload_exec(bContext *C, wmOperator *op)
/* Don't make this part of 'poll', since 'Alt-R' will type 'R',
* if poll checks for the filename. */
if (text->filepath == NULL) {
if (text->filepath == nullptr) {
BKE_report(op->reports, RPT_ERROR, "This text has not been saved");
return OPERATOR_CANCELLED;
}
@ -516,10 +517,10 @@ void TEXT_OT_reload(wmOperatorType *ot)
static bool text_unlink_poll(bContext *C)
{
/* it should be possible to unlink texts if they're lib-linked in... */
return CTX_data_edit_text(C) != NULL;
return CTX_data_edit_text(C) != nullptr;
}
static int text_unlink_exec(bContext *C, wmOperator *UNUSED(op))
static int text_unlink_exec(bContext *C, wmOperator * /*op*/)
{
Main *bmain = CTX_data_main(C);
SpaceText *st = CTX_wm_space_text(C);
@ -528,11 +529,11 @@ static int text_unlink_exec(bContext *C, wmOperator *UNUSED(op))
/* make the previous text active, if its not there make the next text active */
if (st) {
if (text->id.prev) {
st->text = text->id.prev;
st->text = static_cast<Text *>(text->id.prev);
text_update_cursor_moved(C);
}
else if (text->id.next) {
st->text = text->id.next;
st->text = static_cast<Text *>(text->id.next);
text_update_cursor_moved(C);
}
}
@ -540,7 +541,7 @@ static int text_unlink_exec(bContext *C, wmOperator *UNUSED(op))
BKE_id_delete(bmain, text);
text_drawcache_tag_update(st, true);
WM_event_add_notifier(C, NC_TEXT | NA_REMOVED, NULL);
WM_event_add_notifier(C, NC_TEXT | NA_REMOVED, nullptr);
return OPERATOR_FINISHED;
}
@ -567,7 +568,7 @@ void TEXT_OT_unlink(wmOperatorType *ot)
/** \name Make Internal Operator
* \{ */
static int text_make_internal_exec(bContext *C, wmOperator *UNUSED(op))
static int text_make_internal_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
@ -620,7 +621,7 @@ static void txt_write_file(Main *bmain, Text *text, ReportList *reports)
}
fp = BLI_fopen(filepath, "w");
if (fp == NULL) {
if (fp == nullptr) {
BKE_reportf(reports,
RPT_ERROR,
"Unable to save '%s': %s",
@ -629,7 +630,7 @@ static void txt_write_file(Main *bmain, Text *text, ReportList *reports)
return;
}
for (tmp = text->lines.first; tmp; tmp = tmp->next) {
for (tmp = static_cast<TextLine *>(text->lines.first); tmp; tmp = tmp->next) {
fputs(tmp->line, fp);
if (tmp->next) {
fputc('\n', fp);
@ -674,8 +675,8 @@ static int text_save_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Text *text = CTX_data_edit_text(C);
/* Internal and texts without a filepath will go to "Save As". */
if (text->filepath == NULL || (text->flags & TXT_ISMEM)) {
WM_operator_name_call(C, "TEXT_OT_save_as", WM_OP_INVOKE_DEFAULT, NULL, event);
if (text->filepath == nullptr || (text->flags & TXT_ISMEM)) {
WM_operator_name_call(C, "TEXT_OT_save_as", WM_OP_INVOKE_DEFAULT, nullptr, event);
return OPERATOR_CANCELLED;
}
return text_save_exec(C, op);
@ -726,7 +727,7 @@ static int text_save_as_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static int text_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int text_save_as_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
Main *bmain = CTX_data_main(C);
Text *text = CTX_data_edit_text(C);
@ -784,7 +785,7 @@ static int text_run_script(bContext *C, ReportList *reports)
{
#ifdef WITH_PYTHON
Text *text = CTX_data_edit_text(C);
const bool is_live = (reports == NULL);
const bool is_live = (reports == nullptr);
/* only for comparison */
void *curl_prev = text->curl;
@ -793,7 +794,7 @@ static int text_run_script(bContext *C, ReportList *reports)
if (BPY_run_text(C, text, reports, !is_live)) {
if (is_live) {
/* for nice live updates */
WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, nullptr);
}
return OPERATOR_FINISHED;
}
@ -852,7 +853,7 @@ void TEXT_OT_run_script(wmOperatorType *ot)
/** \name Refresh Pyconstraints Operator
* \{ */
static int text_refresh_pyconstraints_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
static int text_refresh_pyconstraints_exec(bContext * /*C*/, wmOperator * /*op*/)
{
#ifdef WITH_PYTHON
# if 0
@ -955,7 +956,7 @@ static int text_paste_exec(bContext *C, wmOperator *op)
/* run the script while editing, evil but useful */
if (st->live_edit) {
text_run_script(C, NULL);
text_run_script(C, nullptr);
}
return OPERATOR_FINISHED;
@ -979,7 +980,7 @@ void TEXT_OT_paste(wmOperatorType *ot)
PropertyRNA *prop;
prop = RNA_def_boolean(ot->srna,
"selection",
0,
false,
"Selection",
"Paste text selected elsewhere rather than copied (X11/Wayland only)");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
@ -991,7 +992,7 @@ void TEXT_OT_paste(wmOperatorType *ot)
/** \name Duplicate Operator
* \{ */
static int text_duplicate_line_exec(bContext *C, wmOperator *UNUSED(op))
static int text_duplicate_line_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
@ -1003,7 +1004,7 @@ static int text_duplicate_line_exec(bContext *C, wmOperator *UNUSED(op))
/* run the script while editing, evil but useful */
if (CTX_wm_space_text(C)->live_edit) {
text_run_script(C, NULL);
text_run_script(C, nullptr);
}
return OPERATOR_FINISHED;
@ -1038,15 +1039,15 @@ static void txt_copy_clipboard(Text *text)
return;
}
buf = txt_sel_to_buf(text, NULL);
buf = txt_sel_to_buf(text, nullptr);
if (buf) {
WM_clipboard_text_set(buf, 0);
WM_clipboard_text_set(buf, false);
MEM_freeN(buf);
}
}
static int text_copy_exec(bContext *C, wmOperator *UNUSED(op))
static int text_copy_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
@ -1073,7 +1074,7 @@ void TEXT_OT_copy(wmOperatorType *ot)
/** \name Cut Operator
* \{ */
static int text_cut_exec(bContext *C, wmOperator *UNUSED(op))
static int text_cut_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
@ -1090,7 +1091,7 @@ static int text_cut_exec(bContext *C, wmOperator *UNUSED(op))
/* run the script while editing, evil but useful */
if (st->live_edit) {
text_run_script(C, NULL);
text_run_script(C, nullptr);
}
return OPERATOR_FINISHED;
@ -1117,16 +1118,16 @@ void TEXT_OT_cut(wmOperatorType *ot)
/** \name Indent or Autocomplete Operator
* \{ */
static int text_indent_or_autocomplete_exec(bContext *C, wmOperator *UNUSED(op))
static int text_indent_or_autocomplete_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
TextLine *line = text->curl;
bool text_before_cursor = text->curc != 0 && !ELEM(line->line[text->curc - 1], ' ', '\t');
if (text_before_cursor && (txt_has_sel(text) == false)) {
WM_operator_name_call(C, "TEXT_OT_autocomplete", WM_OP_INVOKE_DEFAULT, NULL, NULL);
WM_operator_name_call(C, "TEXT_OT_autocomplete", WM_OP_INVOKE_DEFAULT, nullptr, nullptr);
}
else {
WM_operator_name_call(C, "TEXT_OT_indent", WM_OP_EXEC_DEFAULT, NULL, NULL);
WM_operator_name_call(C, "TEXT_OT_indent", WM_OP_EXEC_DEFAULT, nullptr, nullptr);
}
return OPERATOR_FINISHED;
}
@ -1152,7 +1153,7 @@ void TEXT_OT_indent_or_autocomplete(wmOperatorType *ot)
/** \name Indent Operator
* \{ */
static int text_indent_exec(bContext *C, wmOperator *UNUSED(op))
static int text_indent_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
@ -1198,7 +1199,7 @@ void TEXT_OT_indent(wmOperatorType *ot)
/** \name Unindent Operator
* \{ */
static int text_unindent_exec(bContext *C, wmOperator *UNUSED(op))
static int text_unindent_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
@ -1239,7 +1240,7 @@ void TEXT_OT_unindent(wmOperatorType *ot)
/** \name Line Break Operator
* \{ */
static int text_line_break_exec(bContext *C, wmOperator *UNUSED(op))
static int text_line_break_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
@ -1336,10 +1337,10 @@ static int text_comment_exec(bContext *C, wmOperator *op)
void TEXT_OT_comment_toggle(wmOperatorType *ot)
{
static const EnumPropertyItem comment_items[] = {
{0, "TOGGLE", 0, "Toggle Comments", NULL},
{1, "COMMENT", 0, "Comment", NULL},
{-1, "UNCOMMENT", 0, "Un-Comment", NULL},
{0, NULL, 0, NULL, NULL},
{0, "TOGGLE", 0, "Toggle Comments", nullptr},
{1, "COMMENT", 0, "Comment", nullptr},
{-1, "UNCOMMENT", 0, "Un-Comment", nullptr},
{0, nullptr, 0, nullptr, nullptr},
};
/* identifiers */
@ -1356,7 +1357,7 @@ void TEXT_OT_comment_toggle(wmOperatorType *ot)
/* properties */
PropertyRNA *prop;
prop = RNA_def_enum(ot->srna, "type", comment_items, 0, "Type", "Add or remove comments");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
RNA_def_property_flag(prop, PropertyFlag(PROP_HIDDEN | PROP_SKIP_SAVE));
}
/** \} */
@ -1367,9 +1368,9 @@ void TEXT_OT_comment_toggle(wmOperatorType *ot)
enum { TO_SPACES, TO_TABS };
static const EnumPropertyItem whitespace_type_items[] = {
{TO_SPACES, "SPACES", 0, "To Spaces", NULL},
{TO_TABS, "TABS", 0, "To Tabs", NULL},
{0, NULL, 0, NULL, NULL},
{TO_SPACES, "SPACES", 0, "To Spaces", nullptr},
{TO_TABS, "TABS", 0, "To Tabs", nullptr},
{0, nullptr, 0, nullptr, nullptr},
};
static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
@ -1383,7 +1384,7 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
/* first convert to all space, this make it a lot easier to convert to tabs
* because there is no mixtures of ' ' && '\t' */
for (tmp = text->lines.first; tmp; tmp = tmp->next) {
for (tmp = static_cast<TextLine *>(text->lines.first); tmp; tmp = tmp->next) {
char *new_line;
BLI_assert(tmp->line);
@ -1400,16 +1401,16 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
/* Put new_line in the tmp->line spot still need to try and set the curc correctly. */
tmp->line = new_line;
tmp->len = strlen(new_line);
tmp->format = NULL;
tmp->format = nullptr;
if (tmp->len > max_len) {
max_len = tmp->len;
}
}
if (type == TO_TABS) {
char *tmp_line = MEM_mallocN(sizeof(*tmp_line) * (max_len + 1), __func__);
char *tmp_line = static_cast<char *>(MEM_mallocN(sizeof(*tmp_line) * (max_len + 1), __func__));
for (tmp = text->lines.first; tmp; tmp = tmp->next) {
for (tmp = static_cast<TextLine *>(text->lines.first); tmp; tmp = tmp->next) {
const char *text_check_line = tmp->line;
const int text_check_line_len = tmp->len;
char *tmp_line_cur = tmp_line;
@ -1476,7 +1477,7 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
* still need to try and set the curc correctly. */
tmp->line = BLI_strdup(tmp_line);
tmp->len = strlen(tmp_line);
tmp->format = NULL;
tmp->format = nullptr;
}
}
@ -1520,7 +1521,7 @@ void TEXT_OT_convert_whitespace(wmOperatorType *ot)
/** \name Select All Operator
* \{ */
static int text_select_all_exec(bContext *C, wmOperator *UNUSED(op))
static int text_select_all_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
@ -1552,7 +1553,7 @@ void TEXT_OT_select_all(wmOperatorType *ot)
/** \name Select Line Operator
* \{ */
static int text_select_line_exec(bContext *C, wmOperator *UNUSED(op))
static int text_select_line_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
@ -1584,7 +1585,7 @@ void TEXT_OT_select_line(wmOperatorType *ot)
/** \name Select Word Operator
* \{ */
static int text_select_word_exec(bContext *C, wmOperator *UNUSED(op))
static int text_select_word_exec(bContext *C, wmOperator * /*op*/)
{
Text *text = CTX_data_edit_text(C);
@ -1631,7 +1632,7 @@ static int move_lines_exec(bContext *C, wmOperator *op)
/* run the script while editing, evil but useful */
if (CTX_wm_space_text(C)->live_edit) {
text_run_script(C, NULL);
text_run_script(C, nullptr);
}
return OPERATOR_FINISHED;
@ -1642,7 +1643,7 @@ void TEXT_OT_move_lines(wmOperatorType *ot)
static const EnumPropertyItem direction_items[] = {
{TXT_MOVE_LINE_UP, "UP", 0, "Up", ""},
{TXT_MOVE_LINE_DOWN, "DOWN", 0, "Down", ""},
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
/* identifiers */
@ -1680,7 +1681,7 @@ static const EnumPropertyItem move_type_items[] = {
{NEXT_LINE, "NEXT_LINE", 0, "Next Line", ""},
{PREV_PAGE, "PREVIOUS_PAGE", 0, "Previous Page", ""},
{NEXT_PAGE, "NEXT_PAGE", 0, "Next Page", ""},
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
/* get cursor position in line by relative wrapped line and column positions */
@ -2170,7 +2171,7 @@ static int text_move_cursor(bContext *C, int type, bool select)
/* ensure we have the right region, it's optional */
if (region && region->regiontype != RGN_TYPE_WINDOW) {
region = NULL;
region = nullptr;
}
switch (type) {
@ -2263,7 +2264,7 @@ static int text_move_cursor(bContext *C, int type, bool select)
cursor_skip(st, region, st->text, -st->runtime.viewlines, select);
}
else {
cursor_skip(NULL, NULL, text, -10, select);
cursor_skip(nullptr, nullptr, text, -10, select);
}
break;
@ -2272,7 +2273,7 @@ static int text_move_cursor(bContext *C, int type, bool select)
cursor_skip(st, region, st->text, st->runtime.viewlines, select);
}
else {
cursor_skip(NULL, NULL, text, 10, select);
cursor_skip(nullptr, nullptr, text, 10, select);
}
break;
}
@ -2291,7 +2292,7 @@ static int text_move_exec(bContext *C, wmOperator *op)
{
int type = RNA_enum_get(op->ptr, "type");
return text_move_cursor(C, type, 0);
return text_move_cursor(C, type, false);
}
void TEXT_OT_move(wmOperatorType *ot)
@ -2319,7 +2320,7 @@ static int text_move_select_exec(bContext *C, wmOperator *op)
{
int type = RNA_enum_get(op->ptr, "type");
return text_move_cursor(C, type, 1);
return text_move_cursor(C, type, true);
}
void TEXT_OT_move_select(wmOperatorType *ot)
@ -2352,16 +2353,18 @@ static int text_jump_exec(bContext *C, wmOperator *op)
{
Text *text = CTX_data_edit_text(C);
int line = RNA_int_get(op->ptr, "line");
short nlines = txt_get_span(text->lines.first, text->lines.last) + 1;
short nlines = txt_get_span(static_cast<TextLine *>(text->lines.first),
static_cast<TextLine *>(text->lines.last)) +
1;
if (line < 1) {
txt_move_toline(text, 1, 0);
txt_move_toline(text, 1, false);
}
else if (line > nlines) {
txt_move_toline(text, nlines - 1, 0);
txt_move_toline(text, nlines - 1, false);
}
else {
txt_move_toline(text, line - 1, 0);
txt_move_toline(text, line - 1, false);
}
text_update_cursor_moved(C);
@ -2370,7 +2373,7 @@ static int text_jump_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static int text_jump_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int text_jump_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
return WM_operator_props_dialog_popup(C, op, 200);
}
@ -2405,7 +2408,7 @@ static const EnumPropertyItem delete_type_items[] = {
{DEL_PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
{DEL_NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
{DEL_PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
static int text_delete_exec(bContext *C, wmOperator *op)
@ -2492,7 +2495,7 @@ static int text_delete_exec(bContext *C, wmOperator *op)
/* run the script while editing, evil but useful */
if (st->live_edit) {
text_run_script(C, NULL);
text_run_script(C, nullptr);
}
return OPERATOR_FINISHED;
@ -2520,7 +2523,7 @@ void TEXT_OT_delete(wmOperatorType *ot)
DEL_NEXT_CHAR,
"Type",
"Which part of the text to delete");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
RNA_def_property_flag(prop, PropertyFlag(PROP_HIDDEN | PROP_SKIP_SAVE));
}
/** \} */
@ -2529,7 +2532,7 @@ void TEXT_OT_delete(wmOperatorType *ot)
/** \name Toggle Overwrite Operator
* \{ */
static int text_toggle_overwrite_exec(bContext *C, wmOperator *UNUSED(op))
static int text_toggle_overwrite_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
@ -2588,7 +2591,7 @@ enum eScrollZone {
SCROLLHANDLE_MAX_OUTSIDE,
};
typedef struct TextScroll {
struct TextScroll {
int mval_prev[2];
int mval_delta[2];
@ -2605,7 +2608,7 @@ typedef struct TextScroll {
} state;
int ofs_delta[2];
int ofs_delta_px[2];
} TextScroll;
};
static void text_scroll_state_init(TextScroll *tsc, SpaceText *st, ARegion *region)
{
@ -2624,7 +2627,7 @@ static bool text_scroll_poll(bContext *C)
{
/* it should be possible to still scroll linked texts to read them,
* even if they can't be edited... */
return CTX_data_edit_text(C) != NULL;
return CTX_data_edit_text(C) != nullptr;
}
static int text_scroll_exec(bContext *C, wmOperator *op)
@ -2648,7 +2651,7 @@ static int text_scroll_exec(bContext *C, wmOperator *op)
static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
{
SpaceText *st = CTX_wm_space_text(C);
TextScroll *tsc = op->customdata;
TextScroll *tsc = static_cast<TextScroll *>(op->customdata);
const int mval[2] = {event->xy[0], event->xy[1]};
text_update_character_width(st);
@ -2737,7 +2740,7 @@ static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
static void scroll_exit(bContext *C, wmOperator *op)
{
SpaceText *st = CTX_wm_space_text(C);
TextScroll *tsc = op->customdata;
TextScroll *tsc = static_cast<TextScroll *>(op->customdata);
st->flags &= ~ST_SCROLL_SELECT;
@ -2754,7 +2757,7 @@ static void scroll_exit(bContext *C, wmOperator *op)
static int text_scroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
TextScroll *tsc = op->customdata;
TextScroll *tsc = static_cast<TextScroll *>(op->customdata);
SpaceText *st = CTX_wm_space_text(C);
ARegion *region = CTX_wm_region(C);
@ -2800,7 +2803,7 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return text_scroll_exec(C, op);
}
tsc = MEM_callocN(sizeof(TextScroll), "TextScroll");
tsc = static_cast<TextScroll *>(MEM_callocN(sizeof(TextScroll), "TextScroll"));
tsc->is_first = true;
tsc->zone = SCROLLHANDLE_BAR;
@ -2868,14 +2871,14 @@ static bool text_region_scroll_poll(bContext *C)
ARegion *region = CTX_wm_region(C);
if (!st || !text) {
return 0;
return false;
}
if (!region || region->regiontype != RGN_TYPE_WINDOW) {
return 0;
return false;
}
return 1;
return true;
}
static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *event)
@ -2915,7 +2918,7 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *ev
return OPERATOR_PASS_THROUGH;
}
tsc = MEM_callocN(sizeof(TextScroll), "TextScroll");
tsc = static_cast<TextScroll *>(MEM_callocN(sizeof(TextScroll), "TextScroll"));
tsc->is_first = true;
tsc->is_scrollbar = true;
tsc->zone = zone;
@ -2969,11 +2972,11 @@ void TEXT_OT_scroll_bar(wmOperatorType *ot)
/** \name Set Selection Operator
* \{ */
typedef struct SetSelection {
struct SetSelection {
int selc, sell;
short mval_prev[2];
wmTimer *timer; /* needed for scrolling when mouse at region bounds */
} SetSelection;
};
static int flatten_width(SpaceText *st, const char *str)
{
@ -3016,11 +3019,11 @@ static int flatten_column_to_offset(SpaceText *st, const char *str, int index)
static TextLine *get_line_pos_wrapped(SpaceText *st, ARegion *region, int *y)
{
TextLine *linep = st->text->lines.first;
TextLine *linep = static_cast<TextLine *>(st->text->lines.first);
int i, lines;
if (*y < -st->top) {
return NULL; /* We are beyond the first line... */
return nullptr; /* We are beyond the first line... */
}
for (i = -st->top; i <= *y && linep; linep = linep->next, i += lines) {
@ -3142,11 +3145,11 @@ static void text_cursor_set_to_pos_wrapped(
}
}
else if (y < 0) { /* Before start of text. */
linep = st->text->lines.first;
linep = static_cast<TextLine *>(st->text->lines.first);
charp = 0;
}
else { /* Beyond end of text */
linep = st->text->lines.last;
linep = static_cast<TextLine *>(st->text->lines.last);
charp = linep->len;
}
@ -3191,7 +3194,7 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *region, int x, int y,
charp = &text->curc;
}
y -= txt_get_span(text->lines.first, *linep) - st->top;
y -= txt_get_span(static_cast<TextLine *>(text->lines.first), *linep) - st->top;
if (y > 0) {
while (y-- != 0) {
@ -3223,7 +3226,7 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *region, int x, int y,
static void text_cursor_timer_ensure(bContext *C, SetSelection *ssel)
{
if (ssel->timer == NULL) {
if (ssel->timer == nullptr) {
wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win = CTX_wm_window(C);
@ -3239,20 +3242,20 @@ static void text_cursor_timer_remove(bContext *C, SetSelection *ssel)
WM_event_remove_timer(wm, win, ssel->timer);
}
ssel->timer = NULL;
ssel->timer = nullptr;
}
static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *event)
{
SpaceText *st = CTX_wm_space_text(C);
ARegion *region = CTX_wm_region(C);
SetSelection *ssel = op->customdata;
SetSelection *ssel = static_cast<SetSelection *>(op->customdata);
if (event->mval[1] < 0 || event->mval[1] > region->winy) {
text_cursor_timer_ensure(C, ssel);
if (event->type == TIMER) {
text_cursor_set_to_pos(st, region, event->mval[0], event->mval[1], 1);
text_cursor_set_to_pos(st, region, event->mval[0], event->mval[1], true);
ED_text_scroll_to_cursor(st, region, false);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
}
@ -3262,7 +3265,7 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
if (event->type == TIMER) {
text_cursor_set_to_pos(
st, region, CLAMPIS(event->mval[0], 0, region->winx), event->mval[1], 1);
st, region, CLAMPIS(event->mval[0], 0, region->winx), event->mval[1], true);
ED_text_scroll_to_cursor(st, region, false);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
}
@ -3271,7 +3274,7 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
text_cursor_timer_remove(C, ssel);
if (event->type != TIMER) {
text_cursor_set_to_pos(st, region, event->mval[0], event->mval[1], 1);
text_cursor_set_to_pos(st, region, event->mval[0], event->mval[1], true);
ED_text_scroll_to_cursor(st, region, false);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
@ -3284,7 +3287,7 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
static void text_cursor_set_exit(bContext *C, wmOperator *op)
{
SpaceText *st = CTX_wm_space_text(C);
SetSelection *ssel = op->customdata;
SetSelection *ssel = static_cast<SetSelection *>(op->customdata);
text_update_cursor_moved(C);
text_select_update_primary_clipboard(st->text);
@ -3305,12 +3308,12 @@ static int text_selection_set_invoke(bContext *C, wmOperator *op, const wmEvent
}
op->customdata = MEM_callocN(sizeof(SetSelection), "SetCursor");
ssel = op->customdata;
ssel = static_cast<SetSelection *>(op->customdata);
ssel->mval_prev[0] = event->mval[0];
ssel->mval_prev[1] = event->mval[1];
ssel->sell = txt_get_span(st->text->lines.first, st->text->sell);
ssel->sell = txt_get_span(static_cast<TextLine *>(st->text->lines.first), st->text->sell);
ssel->selc = st->text->selc;
WM_event_add_modal_handler(C, op);
@ -3369,7 +3372,7 @@ static int text_cursor_set_exec(bContext *C, wmOperator *op)
int x = RNA_int_get(op->ptr, "x");
int y = RNA_int_get(op->ptr, "y");
text_cursor_set_to_pos(st, region, x, y, 0);
text_cursor_set_to_pos(st, region, x, y, false);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
@ -3414,7 +3417,7 @@ void TEXT_OT_cursor_set(wmOperatorType *ot)
/** \name Line Number Operator
* \{ */
static int text_line_number_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
static int text_line_number_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *event)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
@ -3448,9 +3451,9 @@ static int text_line_number_invoke(bContext *C, wmOperator *UNUSED(op), const wm
}
jump_to *= 10;
jump_to += (int)(event_ascii - '0');
jump_to += int(event_ascii - '0');
txt_move_toline(text, jump_to - 1, 0);
txt_move_toline(text, jump_to - 1, false);
last_jump = time;
text_update_cursor_moved(C);
@ -3489,7 +3492,7 @@ static int text_insert_exec(bContext *C, wmOperator *op)
text_drawcache_tag_update(st, false);
str = RNA_string_get_alloc(op->ptr, "text", NULL, 0, &str_len);
str = RNA_string_get_alloc(op->ptr, "text", nullptr, 0, &str_len);
ED_text_undo_push_init(C);
@ -3561,7 +3564,7 @@ static int text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* run the script while editing, evil but useful */
if (ret == OPERATOR_FINISHED && st->live_edit) {
text_run_script(C, NULL);
text_run_script(C, nullptr);
}
return ret;
@ -3586,7 +3589,7 @@ void TEXT_OT_insert(wmOperatorType *ot)
/* properties */
prop = RNA_def_string(
ot->srna, "text", NULL, 0, "Text", "Text to insert at the cursor position");
ot->srna, "text", nullptr, 0, "Text", "Text to insert at the cursor position");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
@ -3597,8 +3600,10 @@ void TEXT_OT_insert(wmOperatorType *ot)
* \{ */
/* mode */
#define TEXT_FIND 0
#define TEXT_REPLACE 1
enum {
TEXT_FIND = 0,
TEXT_REPLACE = 1,
};
static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
{
@ -3620,7 +3625,7 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
/* Replace current */
if (mode != TEXT_FIND && txt_has_sel(text)) {
tmp = txt_sel_to_buf(text, NULL);
tmp = txt_sel_to_buf(text, nullptr);
if (flags & ST_MATCH_CASE) {
found = STREQ(st->findstr, tmp);
@ -3635,7 +3640,7 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
txt_insert_buf(text, st->replacestr, strlen(st->replacestr));
if (text->curl && text->curl->format) {
MEM_freeN(text->curl->format);
text->curl->format = NULL;
text->curl->format = nullptr;
}
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
@ -3643,7 +3648,7 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
}
}
MEM_freeN(tmp);
tmp = NULL;
tmp = nullptr;
}
/* Find next */
@ -3653,12 +3658,12 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
}
else if (flags & ST_FIND_ALL) {
if (text->id.next) {
text = st->text = text->id.next;
text = st->text = static_cast<Text *>(text->id.next);
}
else {
text = st->text = bmain->texts.first;
text = st->text = static_cast<Text *>(bmain->texts.first);
}
txt_move_toline(text, 0, 0);
txt_move_toline(text, 0, false);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
}
@ -3719,7 +3724,7 @@ static int text_replace_all(bContext *C)
txt_insert_buf(text, st->replacestr, strlen(st->replacestr));
if (text->curl && text->curl->format) {
MEM_freeN(text->curl->format);
text->curl->format = NULL;
text->curl->format = nullptr;
}
found = txt_find_string(text, st->findstr, 0, flags & ST_MATCH_CASE);
} while (found);
@ -3762,7 +3767,7 @@ void TEXT_OT_replace(wmOperatorType *ot)
/* properties */
PropertyRNA *prop;
prop = RNA_def_boolean(ot->srna, "all", false, "Replace All", "Replace all occurrences");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
RNA_def_property_flag(prop, PropertyFlag(PROP_HIDDEN | PROP_SKIP_SAVE));
}
/** \} */
@ -3777,7 +3782,7 @@ static int text_find_set_selected_exec(bContext *C, wmOperator *op)
Text *text = CTX_data_edit_text(C);
char *tmp;
tmp = txt_sel_to_buf(text, NULL);
tmp = txt_sel_to_buf(text, nullptr);
STRNCPY(st->findstr, tmp);
MEM_freeN(tmp);
@ -3806,13 +3811,13 @@ void TEXT_OT_find_set_selected(wmOperatorType *ot)
/** \name Replace Set Selected
* \{ */
static int text_replace_set_selected_exec(bContext *C, wmOperator *UNUSED(op))
static int text_replace_set_selected_exec(bContext *C, wmOperator * /*op*/)
{
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
char *tmp;
tmp = txt_sel_to_buf(text, NULL);
tmp = txt_sel_to_buf(text, nullptr);
STRNCPY(st->replacestr, tmp);
MEM_freeN(tmp);
@ -3851,7 +3856,7 @@ static int text_jump_to_file_at_point_internal_exec(bContext *C, wmOperator *op)
const int column = RNA_int_get(op->ptr, "column");
Main *bmain = CTX_data_main(C);
Text *text = NULL;
Text *text = nullptr;
LISTBASE_FOREACH (Text *, text_iter, &bmain->texts) {
if (text_iter->filepath && BLI_path_cmp(text_iter->filepath, filepath) == 0) {
@ -3860,11 +3865,11 @@ static int text_jump_to_file_at_point_internal_exec(bContext *C, wmOperator *op)
}
}
if (text == NULL) {
if (text == nullptr) {
text = BKE_text_load(bmain, filepath, BKE_main_blendfile_path(bmain));
}
if (text == NULL) {
if (text == nullptr) {
BKE_reportf(op->reports, RPT_WARNING, "File '%s' cannot be opened", filepath);
return OPERATOR_CANCELLED;
}
@ -3897,12 +3902,12 @@ void TEXT_OT_jump_to_file_at_point_internal(wmOperatorType *ot)
/* flags */
ot->flag = 0;
prop = RNA_def_string(ot->srna, "filepath", NULL, FILE_MAX, "Filepath", "");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
prop = RNA_def_string(ot->srna, "filepath", nullptr, FILE_MAX, "Filepath", "");
RNA_def_property_flag(prop, PropertyFlag(PROP_HIDDEN | PROP_SKIP_SAVE));
prop = RNA_def_int(ot->srna, "line", 0, 0, INT_MAX, "Line", "Line to jump to", 1, 10000);
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
RNA_def_property_flag(prop, PropertyFlag(PROP_HIDDEN | PROP_SKIP_SAVE));
prop = RNA_def_int(ot->srna, "column", 0, 0, INT_MAX, "Column", "Column to jump to", 1, 10000);
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
RNA_def_property_flag(prop, PropertyFlag(PROP_HIDDEN | PROP_SKIP_SAVE));
}
/** \} */
@ -3917,7 +3922,7 @@ static const EnumPropertyItem resolution_items[] = {
{RESOLVE_RELOAD, "RELOAD", 0, "Reload", ""},
{RESOLVE_SAVE, "SAVE", 0, "Save", ""},
{RESOLVE_MAKE_INTERNAL, "MAKE_INTERNAL", 0, "Make Internal", ""},
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
static bool text_resolve_conflict_poll(bContext *C)
@ -3928,7 +3933,7 @@ static bool text_resolve_conflict_poll(bContext *C)
return false;
}
return ((text->filepath != NULL) && !(text->flags & TXT_ISMEM));
return ((text->filepath != nullptr) && !(text->flags & TXT_ISMEM));
}
static int text_resolve_conflict_exec(bContext *C, wmOperator *op)
@ -3951,7 +3956,7 @@ static int text_resolve_conflict_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
static int text_resolve_conflict_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
static int text_resolve_conflict_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
Text *text = CTX_data_edit_text(C);
uiPopupMenu *pup;
@ -4065,7 +4070,7 @@ void TEXT_OT_to_3d_object(wmOperatorType *ot)
/* properties */
RNA_def_boolean(
ot->srna, "split_lines", 0, "Split Lines", "Create one object per line in the text");
ot->srna, "split_lines", false, "Split Lines", "Create one object per line in the text");
}
/** \} */

View File

@ -6,8 +6,8 @@
* \ingroup sptext
*/
#include <errno.h>
#include <string.h>
#include <cerrno>
#include <cstring>
#include "MEM_guardedalloc.h"
@ -40,8 +40,8 @@
#include "RNA_access.h"
#include "RNA_define.h"
#include "text_format.h"
#include "text_intern.h"
#include "text_format.hh"
#include "text_intern.hh"
/* -------------------------------------------------------------------- */
/** \name Implements ED Undo System
@ -52,12 +52,12 @@
/**
* Only stores the state of a text buffer.
*/
typedef struct TextState {
struct TextState {
BArrayState *buf_array_state;
int cursor_line, cursor_line_select;
int cursor_column, cursor_column_select;
} TextState;
};
static void text_state_encode(TextState *state, Text *text, BArrayStore *buffer_store)
{
@ -106,7 +106,7 @@ static void text_state_decode(TextState *state, Text *text)
/** \name Implements ED Undo System
* \{ */
typedef struct TextUndoStep {
struct TextUndoStep {
UndoStep step;
UndoRefID_Text text_ref;
/**
@ -114,7 +114,7 @@ typedef struct TextUndoStep {
* the second is the state after the operation is done.
*/
TextState states[2];
} TextUndoStep;
};
static struct {
BArrayStore *buffer_store;

View File

@ -53,6 +53,7 @@
#include "BKE_crazyspace.hh"
#include "BKE_curve.h"
#include "BKE_editmesh.h"
#include "BKE_grease_pencil.hh"
#include "BKE_layer.h"
#include "BKE_mball.h"
#include "BKE_mesh.hh"
@ -4028,6 +4029,32 @@ static bool do_pose_box_select(bContext *C,
return changed_multi;
}
static bool do_grease_pencil_box_select(ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
{
using namespace blender;
Scene *scene = vc->scene;
const Object *ob_eval = DEG_get_evaluated_object(vc->depsgraph,
const_cast<Object *>(vc->obedit));
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(vc->obedit->data);
bool changed = false;
grease_pencil.foreach_editable_drawing(
scene->r.cfra, [&](int drawing_index, GreasePencilDrawing &drawing) {
bke::crazyspace::GeometryDeformation deformation =
bke::crazyspace::get_evaluated_grease_pencil_drawing_deformation(
ob_eval, *vc->obedit, drawing_index);
changed |= ed::curves::select_box(
*vc, drawing.geometry.wrap(), deformation.positions, ATTR_DOMAIN_POINT, *rect, sel_op);
});
if (changed) {
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
WM_event_add_notifier(vc->C, NC_GEOM | ND_DATA, &grease_pencil);
}
return changed;
}
static int view3d_box_select_exec(bContext *C, wmOperator *op)
{
using namespace blender;
@ -4113,6 +4140,10 @@ static int view3d_box_select_exec(bContext *C, wmOperator *op)
}
break;
}
case OB_GREASE_PENCIL: {
changed = do_grease_pencil_box_select(&vc, &rect, sel_op);
break;
}
default:
BLI_assert_msg(0, "box select on incorrect object type");
break;

View File

@ -119,7 +119,9 @@ static float transdata_get_time_shuffle_offset_side(ListBase *trans_datas, const
}
total_offset += offset;
} while (!IS_EQF(offset, 0.0f));
} while (!IS_EQT(offset, 0.0f, 1e-4));
/* Needs a eps greater than FLT_EPS because strip->start/end could be non-integral, and after
* those calculations, `offset` could fall outside of FLT_EPS. */
return total_offset;
}

View File

@ -1385,7 +1385,7 @@ eSnapMode snapObjectsTransform(
SnapObjectParams snap_object_params{};
snap_object_params.snap_target_select = t->tsnap.target_operation;
snap_object_params.edit_mode_type = (t->flag & T_EDIT) != 0 ? SNAP_GEOM_EDIT : SNAP_GEOM_FINAL;
snap_object_params.use_occlusion_test = t->settings->snap_mode != SCE_SNAP_MODE_FACE;
snap_object_params.use_occlusion_test = true;
snap_object_params.use_backface_culling = (t->tsnap.flag & SCE_SNAP_BACKFACE_CULLING) != 0;
float *target = (t->tsnap.status & SNAP_SOURCE_FOUND) ? t->tsnap.snap_source : t->center_global;

View File

@ -969,7 +969,8 @@ struct RaycastObjUserData {
/* read/write args */
float *ray_depth;
bool use_occlusion_test;
uint use_occlusion_test : 1;
uint use_occlusion_test_edit : 1;
};
/**
@ -986,21 +987,17 @@ static eSnapMode raycast_obj_fn(SnapObjectContext *sctx,
{
RaycastObjUserData *dt = static_cast<RaycastObjUserData *>(data);
const uint ob_index = dt->ob_index++;
bool use_occlusion_test = dt->use_occlusion_test;
/* read/write args */
float *ray_depth = dt->ray_depth;
bool retval = false;
bool is_edit = false;
if (use_occlusion_test) {
if (ELEM(ob_eval->dt, OB_BOUNDBOX, OB_WIRE)) {
/* Do not hit objects that are in wire or bounding box
* display mode. */
return SCE_SNAP_MODE_NONE;
}
}
if (ob_data == nullptr) {
if (dt->use_occlusion_test_edit && ELEM(ob_eval->dt, OB_BOUNDBOX, OB_WIRE)) {
/* Do not hit objects that are in wire or bounding box display mode. */
return SCE_SNAP_MODE_NONE;
}
if (ob_eval->type == OB_MESH) {
BMEditMesh *em = BKE_editmesh_from_object(ob_eval);
if (UNLIKELY(!em)) { /* See #mesh_for_snap doc-string. */
@ -1028,6 +1025,10 @@ static eSnapMode raycast_obj_fn(SnapObjectContext *sctx,
return SCE_SNAP_MODE_NONE;
}
}
else if (dt->use_occlusion_test && ELEM(ob_eval->dt, OB_BOUNDBOX, OB_WIRE)) {
/* Do not hit objects that are in wire or bounding box display mode. */
return SCE_SNAP_MODE_NONE;
}
else if (GS(ob_data->name) != ID_ME) {
return SCE_SNAP_MODE_NONE;
}
@ -1080,26 +1081,20 @@ static bool raycastObjects(SnapObjectContext *sctx,
const SnapObjectParams *params,
const float ray_start[3],
const float ray_dir[3],
const bool use_occlusion_test,
const bool use_occlusion_test_edit,
/* read/write args */
/* Parameters below cannot be const, because they are assigned to a
* non-const variable (readability-non-const-parameter). */
float *ray_depth /* NOLINT */)
{
const View3D *v3d = sctx->runtime.v3d;
if (params->use_occlusion_test && v3d && XRAY_FLAG_ENABLED(v3d)) {
/* General testing of occlusion geometry is disabled if the snap is not intended for the edit
* cage. */
if (params->edit_mode_type == SNAP_GEOM_EDIT) {
return false;
}
}
RaycastObjUserData data = {};
data.ray_start = ray_start;
data.ray_dir = ray_dir;
data.ob_index = 0;
data.ray_depth = ray_depth;
data.use_occlusion_test = params->use_occlusion_test;
data.use_occlusion_test = use_occlusion_test;
data.use_occlusion_test_edit = use_occlusion_test_edit;
return iter_snap_objects(sctx, params, raycast_obj_fn, &data) != SCE_SNAP_MODE_NONE;
}
@ -3117,7 +3112,14 @@ bool ED_transform_snap_object_project_ray_ex(SnapObjectContext *sctx,
sctx->ret.dist_sq = FLT_MAX;
sctx->ret.is_edit = false;
if (raycastObjects(sctx, params, ray_start, ray_normal, ray_depth)) {
if (raycastObjects(sctx,
params,
ray_start,
ray_normal,
params->use_occlusion_test,
params->use_occlusion_test,
ray_depth))
{
copy_v3_v3(r_loc, sctx->ret.loc);
if (r_no) {
copy_v3_v3(r_no, sctx->ret.no);
@ -3167,7 +3169,14 @@ bool ED_transform_snap_object_project_ray_all(SnapObjectContext *sctx,
float ray_depth_prev = ray_depth;
#endif
if (raycastObjects(sctx, params, ray_start, ray_normal, &ray_depth)) {
if (raycastObjects(sctx,
params,
ray_start,
ray_normal,
params->use_occlusion_test,
params->use_occlusion_test,
&ray_depth))
{
if (sort) {
BLI_listbase_sort(r_hit_list, hit_depth_cmp);
}
@ -3275,17 +3284,21 @@ static eSnapMode transform_snap_context_project_view3d_mixed_impl(SnapObjectCont
const RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
if (snap_to_flag & (SCE_SNAP_MODE_FACE | SCE_SNAP_MODE_FACE_NEAREST)) {
if (params->use_occlusion_test && XRAY_ENABLED(v3d)) {
/* Remove Snap to Face with Occlusion Test as they are not visible in wireframe mode. */
snap_to_flag &= ~(SCE_SNAP_MODE_FACE | SCE_SNAP_MODE_FACE_NEAREST);
}
else if (prev_co == nullptr || init_co == nullptr) {
/* No location to work with #SCE_SNAP_MODE_FACE_NEAREST. */
snap_to_flag &= ~SCE_SNAP_MODE_FACE_NEAREST;
bool use_occlusion_test = params->use_occlusion_test;
if (use_occlusion_test && XRAY_ENABLED(v3d) && (snap_to_flag & SCE_SNAP_MODE_FACE)) {
if (snap_to_flag != SCE_SNAP_MODE_FACE) {
/* In theory everything is visible in X-Ray except faces. */
snap_to_flag &= ~SCE_SNAP_MODE_FACE;
use_occlusion_test = false;
}
}
if ((snap_to_flag & SCE_SNAP_MODE_FACE_NEAREST) && ELEM(nullptr, prev_co, init_co)) {
/* No location to work with #SCE_SNAP_MODE_FACE_NEAREST. */
snap_to_flag &= ~SCE_SNAP_MODE_FACE_NEAREST;
}
/* NOTE: if both face ray-cast and face nearest are enabled, first find result of nearest, then
* override with ray-cast. */
if ((snap_to_flag & SCE_SNAP_MODE_FACE_NEAREST) && !has_hit) {
@ -3310,8 +3323,6 @@ static eSnapMode transform_snap_context_project_view3d_mixed_impl(SnapObjectCont
}
}
bool use_occlusion_test = params->use_occlusion_test && !XRAY_ENABLED(v3d);
if ((snap_to_flag & SCE_SNAP_MODE_FACE) || use_occlusion_test) {
float ray_start[3], ray_normal[3];
if (!ED_view3d_win_to_ray_clipped_ex(
@ -3322,7 +3333,13 @@ static eSnapMode transform_snap_context_project_view3d_mixed_impl(SnapObjectCont
float dummy_ray_depth = BVH_RAYCAST_DIST_MAX;
has_hit = raycastObjects(sctx, params, ray_start, ray_normal, &dummy_ray_depth);
has_hit = raycastObjects(sctx,
params,
ray_start,
ray_normal,
use_occlusion_test,
use_occlusion_test && (snap_to_flag & SCE_SNAP_MODE_FACE) == 0,
&dummy_ray_depth);
if (has_hit) {
if (r_face_nor) {

Some files were not shown because too many files have changed in this diff Show More