Commit Graph

4975 Commits

Author SHA1 Message Date
6fbad2ce7e Merge branch 'blender-v3.6-release' 2023-05-19 12:53:53 +10:00
bb543620ae Fix invalid UTF8 strings being copied into the Python console
Add a ensure_utf8 argument to WM_clipboard_text_get so callers don't
have to handle validation themselves.

Copying non-utf8 text into the Python console and buttons was possible,
causing invalid cursor position and a UnicodeDecodeError accessing
ConsoleLine.body from Python.
2023-05-19 12:49:27 +10:00
406cfd214a Refactor ImBuf buffer access
The goal is to make it more explicit and centralized operation to
assign and steal buffer data, with proper ownership tracking.

The buffers and ownership flags are wrapped into their dedicated
structures now.

There should be no functional changes currently, it is a preparation
for allowing implicit sharing of the ImBuf buffers. Additionally, in
the future it is possible to more buffer-specific information (such
as color space) next to the buffer data itself. It is also possible
to clean up the allocation flags (IB_rect, ...) to give them more
clear naming and not have stored in the ImBuf->flags as they are only
needed for allocation.

The most dangerous part of this change is the change of byte buffer
data from `int*` to `uint8_t*`. In a lot of cases the byte buffer was
cast to `uchar*`, so those casts are now gone. But some code is
operating on `int*` so now there are casts in there. In practice this
should be fine, since we only support 64bit platforms, so allocations
are aligned. The real things to watch out for here is the fact that
allocation and offsetting from the byte buffer now need an explicit 4
channel multiplier.

Once everything is C++ it will be possible to simplify public
functions even further.

Pull Request: blender/blender#107609
2023-05-18 10:19:01 +02:00
a9193a9ad2 Refactor ID liblinking on readfile to take ID pointer.
The usage of the lib pointer was cryptic to say the least, it was
essentialy used to allow or not local IDs results in the mapping
old_id_pointer -> new_id_pointer lookup result.

Now:
- Explicitely pass a boolean to allow or not local ID as result in
  lower-level code.
- Pass the 'self ID' pointer instead of its library to the whole
  liblinking code (that was already the case in a few places).

Note that naming of the 'self id' pointer is currently very inconsistent
throughout the readfile liblink code, this will have to be cleaned up in
a separate step later. For now, `self_id` has been chosen for new code
as it matches the terminology in lib_query code.

The later change can also allow finer handling of lookup on undo, based
on how it was re-read (or not), should the need for this arise.
2023-05-17 16:38:56 +02:00
ac6af0be7b Cleanup: Add enum type for drag data type definitions
Adds type safety and enables compiler features like warnings on missing
enumerator in switches.
2023-05-17 16:10:51 +02:00
e27cb91442 BLI_path: add native path canonicalize function
This function handles cleaning valid system paths that are functional
when passed to `open(..)` but may be relative to the current working
directory or have redundant slashers that can be normalized.
2023-05-17 13:42:51 +10:00
139f4981d4 Cleanup: return early, reduce indentation 2023-05-17 13:13:10 +10:00
802af4e04b BLI_file: split BLI_rename into two functions
Include the term "overwrite" so users of this function are aware
this function will delete the destination file (unlike LIBC rename).

- Add BLI_rename_overwrite (previously called BLI_rename).
- BLI_rename is now a wrapper for rename.

Use BLI_rename when renaming in the file selector.
2023-05-16 13:15:48 +10:00
f7388e3be5 Cleanup: Move BKE_node.h to C++
See: blender/blender#103343

Changes:
1. Added `BKE_node.hh` file. New file includes old one.
2. Functions moved to new file. Redundant `(void)`, `struct` are removed.
3. All cpp includes replaced from `.h` on `.hh`.
4. Everything in `BKE_node.hh` is on `blender::bke` namespace.
5. All implementation functions moved in namespace.
6. Function names (`BKE_node_*`) changed to `blender::bke::node_*`.
7. `eNodeSizePreset` now is a class, with renamed items.

Pull Request: blender/blender#107790
2023-05-15 15:14:22 +02:00
98dd91f418 WM: make all blend file paths absolute & normalized on read/write
Ensure the file path G.main->filepath is always absolute and normalized.

- It was possible to call WM_OT_open_mainfile with only a filename,
  if this resolved from the CWD, Blender's internal filepath
  would not be absolute as expected.

- It was possible to open files on UNIX with an additional forward slash
  causing the blend file path it's self to contain a '//' prefix,
  this is error prone as running BLI_path_abs(..) multiple times would
  add the blend file prefix each time.

- Remove requirement for "filepath" to be an absolute path when saving.
  Instead, expand the path - making it absolute, as this constraint
  wasn't applied open opening files, prefer making save/open behave
  consistently.

- Assert when BLI_path_abs/BLI_path_rel receive a basepath that has
  a "//" (relative) prefix itself.
2023-05-15 19:58:40 +10:00
d17f9f4872 UI: Capitalize "Python" in UI messages, improve a few others
- "... (matches pythons ...)": capitalize and use possessive ('s).
- "Layer Proxy Protection": replace proxy by override, following 2.80.
- "Enable Plane Trim": expand description.
- "Make curve path children to rotate along the path": remove "to".
- "Option for curve-deform: make deformed child to stretch along
  entire path": remove "to".
- "... apply the curve radius with path following it and deforming":
  rephrase unclear description.
- "Custom light falloff curve" : unrelated to lights, used in Grease
  Pencil modifiers.
- "Grease Pencil layer assigned to the generated strokes": rephrase
  because a GP stroke is assigned to a layer, not the other way
  around.
- "Attribute domain where the attribute domain is stored in the
  simulation state": remove second "domain" (typo).

Pull Request: blender/blender#107916
2023-05-14 15:23:43 +02:00
5a2f159ba4 Cleanup: Minor fixes to comments and CLOG reports. 2023-05-13 19:24:41 +02:00
302137b14b Fix #107759: Crash when running modal operator in load_post handler
Regression in [0] which caused the window to be NULL when the load_post
handler was called. While this can be worked around using
context.temp_override, keep the previous behavior as this
change wasn't intentional.

[0]: 46be42f6b1
2023-05-13 17:34:19 +10:00
fb584456e8 Revert "Fix #107759: Crash when running modal operator in load_post handler"
This reverts commit 95a114f3ca.

This broke bl_rigging_symmetrize, it seems likely the window was not
NULL on load in this case, setting it to NULL caused the the active
object not to be recognized.

This needs further investigation, reverting for now.
2023-05-12 23:23:49 +10:00
95a114f3ca Fix #107759: Crash when running modal operator in load_post handler
Regression in [0] which caused the window to be NULL when the load_post
handler was called. While this can be worked around using
context.temp_override, keep the previous behavior as this
change wasn't intentional.

[0]: 46be42f6b1
2023-05-12 17:23:56 +10:00
b2ebb01255 Fix crash when adding a modal operator from Python with no active window
Reported as part of #107759.
2023-05-12 16:19:24 +10:00
3958ae7241 Cleanup: use STRNCPY, SNPRINTF macros 2023-05-09 14:08:19 +10:00
cd49cb08e3 BLI_string: call BLI_string_debug_size from functions with a buffer size 2023-05-08 19:12:48 +10:00
df54b627b3 Cleanup: use of the term 'len' & 'maxlen'
Only use the term len & maxlen when they represent the length & maximum
length of a string. Instead of the available bytes to use.

Also include the data they're referencing as a suffix, otherwise it's
not always clear what the length is in reference to.
2023-05-07 16:46:37 +10:00
95fa4d73d6 Cleanup: Avoid nested conditional blocks in WM-jobs code
Conditional blocks introduce scopes that need to be kept track of,
linear code is easier to follow. So use early exiting (`continue`s in
this case) to reduce cognitive load, a number of devs consider this good
practice.
2023-05-05 12:15:38 +02:00
6796cce11d Refactor: add a function to access images extensions from it's format
Previously accessing the extension needed to ensure an extension
on an empty path.

This conflicted with DEBUG_STRSIZE as it was assumed the input was
FILE_MAX, where as it was a small buffer with RNA, see: !107602.

Resolve by separating the function that ensures the extension
with the function that finds valid extensions for a format.

Also pass the size of the filepath to functions that ensure the
extension.
2023-05-05 14:01:57 +10:00
e5e17c5a81 Cleanup: rename "name" to "filepath"
Missed in recent cleanup.
2023-05-03 17:13:42 +10:00
f9fbbd8f80 Cleanup: expand on code-comments
Rename layout_old to layout_ref as the layout is a reference
(the old layout has been freed).
Also use boolean for save_copy argument.
2023-05-03 16:31:37 +10:00
6b9a500a3a Cleanup: disambiguate terms "name", "file" & "str" / "string"
- Rename name/filename/path to filepath when it's used for full paths.
- Rename name/path to dirpath when it refers to a directory.
- Rename file to filepath or path (when it may be a file or dir).
- Rename ImBuf::name & anim::name to filepath.
2023-05-03 15:26:14 +10:00
1ab72e8459 Cleanup: use BLI_path_* prefix for path splitting functions
Also order string size after each string instead of grouping strings and
their sizes afterwards.
2023-05-02 21:08:13 +10:00
ae76fa2da3 Fix #107525: Crash loading pre 2.5x files with multiple windows open 2023-05-02 13:36:16 +10:00
6859bb6e67 Cleanup: format (with BraceWrapping::AfterControlStatement "MultiLine") 2023-05-02 09:37:49 +10:00
03ad5c17e6 Fix crash accessing the image clipboard in background mode 2023-04-30 15:08:26 +10:00
6701d24084 BLI_path: add string size arguments to sequence encode/decode functions 2023-04-28 21:33:38 +10:00
5d0595fded Suport relative path option per-asset library
This option is true by default, but it can be changed for
any asset library (that may be using Link as import method).

This also fix "Reset to Default Value" for the Import Method
since this was originally not using the defaults.

Pull Request: blender/blender#107345
2023-04-25 20:56:57 +02:00
b94a0ec8db WindowManager: Context Creation
Currently window manager always tried to create an OpenGL context.
This is incorrect and will fail when using Vulkan. Somehow this
doesn't fail for Metal.

This PR creates a context based on the current selected backend.

Pull Request: blender/blender#107301
2023-04-24 15:33:35 +02:00
68f8253c71 VFONT: Text Selection Operator
An operator to allow interactive text selection for 3D Text Objects.
This is from the code of Yash Dabhade (yashdabhade) for GSoC 2022
with corrections and simplifications. Also includes double-click for
word selection.

Pull Request: blender/blender#106915
2023-04-21 19:08:44 +02:00
35a8341d7b UI: Make it possible to add shortcuts to UI operators.
Function `WM_keymap_guess_opname()` skipped `UI_OT` operator types. In
some cases this is detremental to workflow, see #105371.

To exclude operators from getting keyboard shortcut it was suggested by
Campbell to use flag `OPTYPE_INTERNAL` or make new one.

Pull Request: blender/blender#105383
2023-04-21 17:09:41 +02:00
13d30b0481 Cleanup: fix various warnings on Windows
Ensure windows.h is included before some other headers to avoid
redefining macros.

Pull Request: blender/blender#107189
2023-04-20 20:46:13 +02:00
f04a7a07e3 macOS: Add open files to system recent files
Completes the TODO in GHOST_SystemPathsCocoa::addToSystemRecentFiles
Also renames the filename parameter to the more appropriate filepath.

The recently opened/saved file will now also show up in:
- Blender Dock icon > Right click.
- Three finger swipe down in Open Blender i.e., App Expose

Based on a earlier contribution by @jenkm.

Pull Request: blender/blender#107174
2023-04-20 23:53:08 +05:30
770b193253 Cleanup: use function style casts & nullptr, spelling in comments 2023-04-20 18:28:50 +10:00
9e6757f20f Cleanup: expand on why the extension isn't replaced for blend-file save 2023-04-19 12:58:54 +10:00
b132118f89 Cleanup: balance doxygen grouping, minor grouping adjustment 2023-04-19 09:02:21 +10:00
7b4d71683f Fix #107060: Curves sculpt mode does not select default tool
Regression in [0] when curve tool names changed to use brush names
with the utility function generate_from_enum_ex().

[0]: 786734e6c8
2023-04-18 20:16:31 +10:00
c615ccde68 Fix splash preference overriding Read Home File's use_splash property
- Split out WM_init_splash_on_startup(..) which performs startup checks.
- WM_init_splash(..) now shows the splash (ignoring preferences).
- Avoid calling BLI_exists on an empty string (in some cases).
2023-04-18 12:59:13 +10:00
153cb7e1df Cleanup: remove inline checks for GPU front-buffer reading
Add WM_window_pixels_read & WM_window_pixels_read_sample that
use front-buffer pixel reading when supported.

Note that direct access to reading from the front-buffer is still needed
for writing thumbnails - where redrawing can cause problems
(see code-comments).
2023-04-17 12:28:56 +10:00
de7e3454fb UI: Capabilities Flag for Clipboard Image copy/paste
This adds an WM_capabilities_flag to indicate that a platform
implements support for copying and pasting images using a shared
clipboard.

Pull Request: blender/blender#106990
2023-04-16 21:04:55 +02:00
e1571cb105 Cleanup: correct terms, spelling in comments 2023-04-16 20:41:22 +10:00
5f40118899 Cleanup: rename GPU_offscreen_read_{pixels=>color} noted as a TODO 2023-04-16 20:38:19 +10:00
6cc2c16d06 Fix #106264: Color picker broken with Wayland & AMD GPU
- Use off-screen drawing when reading from the front-buffer isn't
  supported.

- Add a capabilities flag for reading the front-buffer which is always
  disabled on WAYLAND.

- Add GPU_offscreen_read_pixels_region, used for reading a sub-region of
  an off-screen buffer - use for color-picking a single pixel.
2023-04-16 20:16:54 +10:00
db47f82626 GPU: Add Texture Usage Parameter to GPUOffscreen.
Currently the Textures used for offscreen rendering don't have
the `GPU_TEXTURE_USAGE_HOST_READ` flag. But some cases it is
needed. This PR adds a parameter when creating an offscreen
buffer.

Other solution could be to add this flag to all textures, but
we chose not to do this as that reduces the amount of fine-tuning
options for Metal/Vulkan backends. GPU can store textures
differently based on its actual usage.

This option isn't available in the python API as we don't expect
add-on developers to fine-tune texture usages to this extent.

For convenience `GPU_TEXTURE_USAGE_ATTACHMENT` is by default
always added.

Pull Request: blender/blender#106899
2023-04-14 22:02:51 +02:00
10f20bf5d5 Refactor: Rename more grease pencil files to legacy
This renames more files and folders to indicate that it is grease pencil legacy code.

Pull Request: blender/blender#106862
2023-04-14 13:35:08 +02:00
c9258e6e19 Cleanup: BKE: lib_query: Add a new type of callback flags for not-owned embedded ID pointers.
This is the case e.g. of the `parent` collection pointer of collections
children of a scene's master collection, or some nodetree pointers in
the UI data (node editor).

Right now handling of this new flag is exactly the same as in owning
embedded case, the distiction between both usages will happen in future
commits.

This commit is expected to have no behavioral change at all.
2023-04-14 13:29:19 +02:00
71c4b7f1d0 Fix compilation warning
GHOST_getClipboardImage expects signed integers to be passed by pointer.

Pull Request: blender/blender#106933
2023-04-14 09:58:30 +02:00
39bcf6bdc9 UI: Allow Clipboard Copy/Paste Images
Adds operators to copy and paste to and from the OS clipboard, but only
implemented for Windows.

Pull Request: blender/blender#105833
2023-04-14 03:48:17 +02:00