diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/editors/gpencil/gpencil_undo.c | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_undo.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_undo.c | 207 |
1 files changed, 103 insertions, 104 deletions
diff --git a/source/blender/editors/gpencil/gpencil_undo.c b/source/blender/editors/gpencil/gpencil_undo.c index 7ed794a0a32..d91977bc0da 100644 --- a/source/blender/editors/gpencil/gpencil_undo.c +++ b/source/blender/editors/gpencil/gpencil_undo.c @@ -21,7 +21,6 @@ * \ingroup edgpencil */ - #include <stdlib.h> #include <string.h> @@ -48,10 +47,10 @@ #include "gpencil_intern.h" typedef struct bGPundonode { - struct bGPundonode *next, *prev; + struct bGPundonode *next, *prev; - char name[BKE_UNDO_STR_MAX]; - struct bGPdata *gpd; + char name[BKE_UNDO_STR_MAX]; + struct bGPdata *gpd; } bGPundonode; static ListBase undo_nodes = {NULL, NULL}; @@ -59,140 +58,140 @@ static bGPundonode *cur_node = NULL; int ED_gpencil_session_active(void) { - return (BLI_listbase_is_empty(&undo_nodes) == false); + return (BLI_listbase_is_empty(&undo_nodes) == false); } int ED_undo_gpencil_step(bContext *C, int step, const char *name) { - bGPdata **gpd_ptr = NULL, *new_gpd = NULL; - - gpd_ptr = ED_gpencil_data_get_pointers(C, NULL); - - if (step == 1) { /* undo */ - //printf("\t\tGP - undo step\n"); - if (cur_node->prev) { - if (!name || STREQ(cur_node->name, name)) { - cur_node = cur_node->prev; - new_gpd = cur_node->gpd; - } - } - } - else if (step == -1) { - //printf("\t\tGP - redo step\n"); - if (cur_node->next) { - if (!name || STREQ(cur_node->name, name)) { - cur_node = cur_node->next; - new_gpd = cur_node->gpd; - } - } - } - - if (new_gpd) { - if (gpd_ptr) { - if (*gpd_ptr) { - bGPdata *gpd = *gpd_ptr; - bGPDlayer *gpl, *gpld; - - BKE_gpencil_free_layers(&gpd->layers); - - /* copy layers */ - BLI_listbase_clear(&gpd->layers); - - for (gpl = new_gpd->layers.first; gpl; gpl = gpl->next) { - /* make a copy of source layer and its data */ - gpld = BKE_gpencil_layer_duplicate(gpl); - BLI_addtail(&gpd->layers, gpld); - } - } - } - /* drawing batch cache is dirty now */ - DEG_id_tag_update(&new_gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); - new_gpd->flag |= GP_DATA_CACHE_IS_DIRTY; - } - - WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL); - - return OPERATOR_FINISHED; + bGPdata **gpd_ptr = NULL, *new_gpd = NULL; + + gpd_ptr = ED_gpencil_data_get_pointers(C, NULL); + + if (step == 1) { /* undo */ + //printf("\t\tGP - undo step\n"); + if (cur_node->prev) { + if (!name || STREQ(cur_node->name, name)) { + cur_node = cur_node->prev; + new_gpd = cur_node->gpd; + } + } + } + else if (step == -1) { + //printf("\t\tGP - redo step\n"); + if (cur_node->next) { + if (!name || STREQ(cur_node->name, name)) { + cur_node = cur_node->next; + new_gpd = cur_node->gpd; + } + } + } + + if (new_gpd) { + if (gpd_ptr) { + if (*gpd_ptr) { + bGPdata *gpd = *gpd_ptr; + bGPDlayer *gpl, *gpld; + + BKE_gpencil_free_layers(&gpd->layers); + + /* copy layers */ + BLI_listbase_clear(&gpd->layers); + + for (gpl = new_gpd->layers.first; gpl; gpl = gpl->next) { + /* make a copy of source layer and its data */ + gpld = BKE_gpencil_layer_duplicate(gpl); + BLI_addtail(&gpd->layers, gpld); + } + } + } + /* drawing batch cache is dirty now */ + DEG_id_tag_update(&new_gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); + new_gpd->flag |= GP_DATA_CACHE_IS_DIRTY; + } + + WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL); + + return OPERATOR_FINISHED; } void gpencil_undo_init(bGPdata *gpd) { - gpencil_undo_push(gpd); + gpencil_undo_push(gpd); } static void gpencil_undo_free_node(bGPundonode *undo_node) { - /* HACK: animdata wasn't duplicated, so it shouldn't be freed here, - * or else the real copy will segfault when accessed - */ - undo_node->gpd->adt = NULL; + /* HACK: animdata wasn't duplicated, so it shouldn't be freed here, + * or else the real copy will segfault when accessed + */ + undo_node->gpd->adt = NULL; - BKE_gpencil_free(undo_node->gpd, false); - MEM_freeN(undo_node->gpd); + BKE_gpencil_free(undo_node->gpd, false); + MEM_freeN(undo_node->gpd); } void gpencil_undo_push(bGPdata *gpd) { - bGPundonode *undo_node; + bGPundonode *undo_node; - //printf("\t\tGP - undo push\n"); + //printf("\t\tGP - undo push\n"); - if (cur_node) { - /* remove all un-done nodes from stack */ - undo_node = cur_node->next; + if (cur_node) { + /* remove all un-done nodes from stack */ + undo_node = cur_node->next; - while (undo_node) { - bGPundonode *next_node = undo_node->next; + while (undo_node) { + bGPundonode *next_node = undo_node->next; - gpencil_undo_free_node(undo_node); - BLI_freelinkN(&undo_nodes, undo_node); + gpencil_undo_free_node(undo_node); + BLI_freelinkN(&undo_nodes, undo_node); - undo_node = next_node; - } - } + undo_node = next_node; + } + } - /* limit number of undo steps to the maximum undo steps - * - to prevent running out of memory during **really** - * long drawing sessions (triggering swapping) - */ - /* TODO: Undo-memory constraint is not respected yet, but can be added if we have any need for it */ - if (U.undosteps && !BLI_listbase_is_empty(&undo_nodes)) { - /* remove anything older than n-steps before cur_node */ - int steps = 0; + /* limit number of undo steps to the maximum undo steps + * - to prevent running out of memory during **really** + * long drawing sessions (triggering swapping) + */ + /* TODO: Undo-memory constraint is not respected yet, but can be added if we have any need for it */ + if (U.undosteps && !BLI_listbase_is_empty(&undo_nodes)) { + /* remove anything older than n-steps before cur_node */ + int steps = 0; - undo_node = (cur_node) ? cur_node : undo_nodes.last; - while (undo_node) { - bGPundonode *prev_node = undo_node->prev; + undo_node = (cur_node) ? cur_node : undo_nodes.last; + while (undo_node) { + bGPundonode *prev_node = undo_node->prev; - if (steps >= U.undosteps) { - gpencil_undo_free_node(undo_node); - BLI_freelinkN(&undo_nodes, undo_node); - } + if (steps >= U.undosteps) { + gpencil_undo_free_node(undo_node); + BLI_freelinkN(&undo_nodes, undo_node); + } - steps++; - undo_node = prev_node; - } - } + steps++; + undo_node = prev_node; + } + } - /* create new undo node */ - undo_node = MEM_callocN(sizeof(bGPundonode), "gpencil undo node"); - undo_node->gpd = BKE_gpencil_data_duplicate(NULL, gpd, true); + /* create new undo node */ + undo_node = MEM_callocN(sizeof(bGPundonode), "gpencil undo node"); + undo_node->gpd = BKE_gpencil_data_duplicate(NULL, gpd, true); - cur_node = undo_node; + cur_node = undo_node; - BLI_addtail(&undo_nodes, undo_node); + BLI_addtail(&undo_nodes, undo_node); } void gpencil_undo_finish(void) { - bGPundonode *undo_node = undo_nodes.first; + bGPundonode *undo_node = undo_nodes.first; - while (undo_node) { - gpencil_undo_free_node(undo_node); - undo_node = undo_node->next; - } + while (undo_node) { + gpencil_undo_free_node(undo_node); + undo_node = undo_node->next; + } - BLI_freelistN(&undo_nodes); + BLI_freelistN(&undo_nodes); - cur_node = NULL; + cur_node = NULL; } |