Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_align.cc
- This file was moved from source/blender/editors/interface/interface_align.c.
| Context not available. | |||||
| * This will probably not work in all possible cases, | * This will probably not work in all possible cases, | ||||
| * but not sure we want to support such exotic cases anyway. | * but not sure we want to support such exotic cases anyway. | ||||
| */ | */ | ||||
| typedef struct ButAlign { | struct ButAlign { | ||||
| uiBut *but; | uiBut *but; | ||||
| /* Neighbor buttons */ | /* Neighbor buttons */ | ||||
| Context not available. | |||||
| /* Flags, used to mark whether we should 'stitch' | /* Flags, used to mark whether we should 'stitch' | ||||
| * the corners of this button with its neighbors' ones. */ | * the corners of this button with its neighbors' ones. */ | ||||
| char flags[4]; | char flags[4]; | ||||
| } ButAlign; | }; | ||||
| /* Side-related enums and flags. */ | /* Side-related enums and flags. */ | ||||
| enum { | enum { | ||||
| Context not available. | |||||
| /* We found an as close or closer neighbor. | /* We found an as close or closer neighbor. | ||||
| * If both buttons are alignable, we set them as each other neighbors. | * If both buttons are alignable, we set them as each other neighbors. | ||||
| * Else, we have an unalignable one, we need to reset the others matching | * Else, we have an unalignable one, we need to reset the others matching | ||||
| * neighbor to NULL if its 'proximity distance' | * neighbor to nullptr if its 'proximity distance' | ||||
| * is really lower with current one. | * is really lower with current one. | ||||
| * | * | ||||
| * NOTE: We cannot only execute that piece of code in case we found a | * NOTE: We cannot only execute that piece of code in case we found a | ||||
| Context not available. | |||||
| butal_other->neighbors[side_opp] = butal; | butal_other->neighbors[side_opp] = butal; | ||||
| } | } | ||||
| else if (butal_can_align && (delta < butal->dists[side])) { | else if (butal_can_align && (delta < butal->dists[side])) { | ||||
| butal->neighbors[side] = NULL; | butal->neighbors[side] = nullptr; | ||||
| } | } | ||||
| else if (butal_other_can_align && (delta < butal_other->dists[side_opp])) { | else if (butal_other_can_align && (delta < butal_other->dists[side_opp])) { | ||||
| butal_other->neighbors[side_opp] = NULL; | butal_other->neighbors[side_opp] = nullptr; | ||||
| } | } | ||||
| butal->dists[side] = butal_other->dists[side_opp] = delta; | butal->dists[side] = butal_other->dists[side_opp] = delta; | ||||
| } | } | ||||
| Context not available. | |||||
| const int stitch = STITCH(side); | const int stitch = STITCH(side); | ||||
| const int stitch_opp = STITCH(side_opp); | const int stitch_opp = STITCH(side_opp); | ||||
| if (butal->neighbors[side] == NULL) { | if (butal->neighbors[side] == nullptr) { | ||||
| butal->neighbors[side] = butal_other; | butal->neighbors[side] = butal_other; | ||||
| } | } | ||||
| if (butal_other->neighbors[side_opp] == NULL) { | if (butal_other->neighbors[side_opp] == nullptr) { | ||||
| butal_other->neighbors[side_opp] = butal; | butal_other->neighbors[side_opp] = butal; | ||||
| } | } | ||||
| Context not available. | |||||
| */ | */ | ||||
| static int ui_block_align_butal_cmp(const void *a, const void *b) | static int ui_block_align_butal_cmp(const void *a, const void *b) | ||||
| { | { | ||||
| const ButAlign *butal = a; | const ButAlign *butal = static_cast<const ButAlign *>(a); | ||||
| const ButAlign *butal_other = b; | const ButAlign *butal_other = static_cast<const ButAlign *>(b); | ||||
| /* Sort by align group. */ | /* Sort by align group. */ | ||||
| if (butal->but->alignnr != butal_other->but->alignnr) { | if (butal->but->alignnr != butal_other->but->alignnr) { | ||||
| Context not available. | |||||
| butal_array = butal_array_buf; | butal_array = butal_array_buf; | ||||
| } | } | ||||
| else { | else { | ||||
| butal_array = MEM_mallocN(sizeof(*butal_array) * num_buttons, __func__); | butal_array = static_cast<ButAlign *>( | ||||
| MEM_mallocN(sizeof(*butal_array) * num_buttons, __func__)); | |||||
| } | } | ||||
| memset(butal_array, 0, sizeof(*butal_array) * (size_t)num_buttons); | memset(butal_array, 0, sizeof(*butal_array) * (size_t)num_buttons); | ||||
| Context not available. | |||||
| static void ui_block_align_calc_but(uiBut *first, short nr) | static void ui_block_align_calc_but(uiBut *first, short nr) | ||||
| { | { | ||||
| uiBut *prev, *but = NULL, *next; | uiBut *prev, *but = nullptr, *next; | ||||
| int flag = 0, cols = 0, rows = 0; | int flag = 0, cols = 0, rows = 0; | ||||
| /* auto align */ | /* auto align */ | ||||
| Context not available. | |||||
| /* NOTE: manipulation of 'flag' in the loop below is confusing. | /* NOTE: manipulation of 'flag' in the loop below is confusing. | ||||
| * In some cases it's assigned, other times OR is used. */ | * In some cases it's assigned, other times OR is used. */ | ||||
| for (but = first, prev = NULL; but && but->alignnr == nr; prev = but, but = but->next) { | for (but = first, prev = nullptr; but && but->alignnr == nr; prev = but, but = but->next) { | ||||
| next = but->next; | next = but->next; | ||||
| if (next && next->alignnr != nr) { | if (next && next->alignnr != nr) { | ||||
| next = NULL; | next = nullptr; | ||||
| } | } | ||||
| /* clear old flag */ | /* clear old flag */ | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (next == NULL) { /* last case */ | else if (next == nullptr) { /* last case */ | ||||
| if (prev) { | if (prev) { | ||||
| if (buts_are_horiz(prev, but)) { | if (buts_are_horiz(prev, but)) { | ||||
| if (rows == 0) { | if (rows == 0) { | ||||
| Context not available. | |||||
| } | } | ||||
| bt = bt->next; | bt = bt->next; | ||||
| } | } | ||||
| if (bt == NULL || bt->alignnr != nr) { | if (bt == nullptr || bt->alignnr != nr) { | ||||
| flag = UI_BUT_ALIGN_TOP | UI_BUT_ALIGN_RIGHT; | flag = UI_BUT_ALIGN_TOP | UI_BUT_ALIGN_RIGHT; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| void ui_block_align_calc(uiBlock *block, const struct ARegion *UNUSED(region)) | void ui_block_align_calc(uiBlock *block, const struct ARegion *(region)) | ||||
| { | { | ||||
| short nr; | short nr; | ||||
| Context not available. | |||||