GPv3: Add API function to get active frame
Adds the Layer method `frame_at` which finds the frame that is active at a given frame number. Pull Request: https://projects.blender.org/blender/blender/pulls/110583
This commit is contained in:
committed by
Amélie Fondevilla
parent
79e7449a52
commit
6f8ff2846f
@@ -266,9 +266,15 @@ class Layer : public ::GreasePencilLayer {
|
||||
Span<int> sorted_keys() const;
|
||||
|
||||
/**
|
||||
* \returns the index of the drawing at frame \a frame or -1 if there is no drawing.
|
||||
* \returns the index of the active drawing at frame \a frame_number or -1 if there is no
|
||||
* drawing. */
|
||||
int drawing_index_at(const int frame_number) const;
|
||||
|
||||
/**
|
||||
* \returns a pointer to the active frame at \a frame_number or nullptr if there is no frame.
|
||||
*/
|
||||
int drawing_index_at(const int frame) const;
|
||||
const GreasePencilFrame *frame_at(const int frame_number) const;
|
||||
GreasePencilFrame *frame_at(const int frame_number);
|
||||
|
||||
void tag_frames_map_changed();
|
||||
|
||||
@@ -280,6 +286,7 @@ class Layer : public ::GreasePencilLayer {
|
||||
|
||||
private:
|
||||
GreasePencilFrame *add_frame_internal(int frame_number, int drawing_index);
|
||||
int frame_index_at(int frame_number) const;
|
||||
};
|
||||
|
||||
class LayerGroupRuntime {
|
||||
|
||||
@@ -675,7 +675,7 @@ Span<int> Layer::sorted_keys() const
|
||||
return this->runtime->sorted_keys_cache_.data();
|
||||
}
|
||||
|
||||
int Layer::drawing_index_at(const int frame) const
|
||||
int Layer::frame_index_at(const int frame_number) const
|
||||
{
|
||||
Span<int> sorted_keys = this->sorted_keys();
|
||||
/* No keyframes, return no drawing. */
|
||||
@@ -683,19 +683,37 @@ int Layer::drawing_index_at(const int frame) const
|
||||
return -1;
|
||||
}
|
||||
/* Before the first drawing, return no drawing. */
|
||||
if (frame < sorted_keys.first()) {
|
||||
if (frame_number < sorted_keys.first()) {
|
||||
return -1;
|
||||
}
|
||||
/* After or at the last drawing, return the last drawing. */
|
||||
if (frame >= sorted_keys.last()) {
|
||||
return this->frames().lookup(sorted_keys.last()).drawing_index;
|
||||
if (frame_number >= sorted_keys.last()) {
|
||||
return sorted_keys.last();
|
||||
}
|
||||
/* Search for the drawing. upper_bound will get the drawing just after. */
|
||||
auto it = std::upper_bound(sorted_keys.begin(), sorted_keys.end(), frame);
|
||||
auto it = std::upper_bound(sorted_keys.begin(), sorted_keys.end(), frame_number);
|
||||
if (it == sorted_keys.end() || it == sorted_keys.begin()) {
|
||||
return -1;
|
||||
}
|
||||
return this->frames().lookup(*std::prev(it)).drawing_index;
|
||||
return *std::prev(it);
|
||||
}
|
||||
|
||||
const GreasePencilFrame *Layer::frame_at(const int frame_number) const
|
||||
{
|
||||
const int frame_index = this->frame_index_at(frame_number);
|
||||
return (frame_index == -1) ? nullptr : this->frames().lookup_ptr(frame_index);
|
||||
}
|
||||
|
||||
GreasePencilFrame *Layer::frame_at(const int frame_number)
|
||||
{
|
||||
const int frame_index = this->frame_index_at(frame_number);
|
||||
return (frame_index == -1) ? nullptr : this->frames_for_write().lookup_ptr(frame_index);
|
||||
}
|
||||
|
||||
int Layer::drawing_index_at(const int frame_number) const
|
||||
{
|
||||
const GreasePencilFrame *frame = frame_at(frame_number);
|
||||
return (frame != nullptr) ? frame->drawing_index : -1;
|
||||
}
|
||||
|
||||
void Layer::tag_frames_map_changed()
|
||||
|
||||
Reference in New Issue
Block a user