GPv3: Select box grease pencil frames #110939

Merged
Amélie Fondevilla merged 4 commits from Chao-Li/blender:110522 into main 2023-08-16 11:44:23 +02:00
3 changed files with 40 additions and 2 deletions

View File

@ -8,6 +8,7 @@
#include "BLI_map.hh"
#include "BLI_math_vector_types.hh"
#include "BLI_utildefines.h"
#include "BKE_context.h"
#include "BKE_grease_pencil.hh"
@ -107,6 +108,19 @@ void select_frames_region(KeyframeEditData *ked,
}
}
void select_frames_range(bke::greasepencil::Layer &layer,
const float min,
Chao-Li marked this conversation as resolved Outdated

I'd name this select_frames_range, since we're not selecting in a rectangle/box here.

I'd name this `select_frames_range`, since we're not selecting in a rectangle/box here.
const float max,
const short select_mode)
{
/* Only select those frames which are in bounds. */
for (auto [frame_number, frame] : layer.frames_for_write().items()) {
if (IN_RANGE(float(frame_number), min, max)) {
select_frame(frame, select_mode);
}
}
}
static void append_frame_to_key_edit_data(KeyframeEditData *ked,
const int frame_number,
const GreasePencilFrame &frame)

View File

@ -66,6 +66,11 @@ void select_frames_region(KeyframeEditData *ked,
const short tool,
const short select_mode);
void select_frames_range(bke::greasepencil::Layer &layer,
const float min,
const float max,
const short select_mode);
/**
* Returns true if any frame of the \a layer is selected.
*/

View File

@ -433,6 +433,21 @@ static void box_select_elem(
break;
}
#endif
case ANIMTYPE_GREASE_PENCIL_DATABLOCK: {
Chao-Li marked this conversation as resolved Outdated

Here, we need to add a case for ANIMTYPE_GREASE_PENCIL_DATABLOCK, in which we loop over all the layers of the grease pencil object, and call select_frame_box on the layer.
Note: if ale->type == ANIMTYPE_GREASE_PENCIL_DATABLOCK, then ale->data can be casted to a GreasePencil structure.

Here, we need to add a case for `ANIMTYPE_GREASE_PENCIL_DATABLOCK`, in which we loop over all the layers of the grease pencil object, and call `select_frame_box` on the layer. Note: if `ale->type == ANIMTYPE_GREASE_PENCIL_DATABLOCK`, then `ale->data` can be casted to a `GreasePencil` structure.
GreasePencil *grease_pencil = static_cast<GreasePencil *>(ale->data);
for (blender::bke::greasepencil::Layer *layer : grease_pencil->layers_for_write()) {
blender::ed::greasepencil::select_frames_range(
layer->wrap(), xmin, xmax, sel_data->selectmode);
}
ale->update |= ANIM_UPDATE_DEPS;
break;
}
case ANIMTYPE_GREASE_PENCIL_LAYER: {
blender::ed::greasepencil::select_frames_range(
static_cast<GreasePencilLayer *>(ale->data)->wrap(), xmin, xmax, sel_data->selectmode);
ale->update |= ANIM_UPDATE_DEPS;
break;
}
case ANIMTYPE_GPLAYER: {
ED_gpencil_layer_frames_select_box(
static_cast<bGPDlayer *>(ale->data), xmin, xmax, sel_data->selectmode);
@ -1051,7 +1066,9 @@ static void markers_selectkeys_between(bAnimContext *ac)
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
switch (ale->type) {
case ANIMTYPE_GREASE_PENCIL_LAYER:
/* GPv3: To be implemented. */
blender::ed::greasepencil::select_frames_range(
static_cast<GreasePencilLayer *>(ale->data)->wrap(), min, max, SELECT_ADD);
ale->update |= ANIM_UPDATE_DEPS;
break;
case ANIMTYPE_GPLAYER:
ED_gpencil_layer_frames_select_box(
@ -1501,7 +1518,9 @@ static void actkeys_select_leftright(bAnimContext *ac, short leftright, short se
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
switch (ale->type) {
case ANIMTYPE_GREASE_PENCIL_LAYER:
/* GPv3: To be implemented. */
blender::ed::greasepencil::select_frames_range(
static_cast<GreasePencilLayer *>(ale->data)->wrap(), ked.f1, ked.f2, select_mode);
ale->update |= ANIM_UPDATE_DEPS;
break;
case ANIMTYPE_GPLAYER:
ED_gpencil_layer_frames_select_box(