Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_align.c
| Show All 18 Lines | |||||
| /** \file | /** \file | ||||
| * \ingroup edinterface | * \ingroup edinterface | ||||
| */ | */ | ||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "DNA_userdef_types.h" | #include "DNA_userdef_types.h" | ||||
| #include "BLI_listbase.h" | |||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_rect.h" | #include "BLI_rect.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "interface_intern.h" | #include "interface_intern.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| ▲ Show 20 Lines • Show All 345 Lines • ▼ Show 20 Lines | |||||
| * Compute the alignment of all 'align groups' of buttons in given block. | * Compute the alignment of all 'align groups' of buttons in given block. | ||||
| * | * | ||||
| * This is using an order-independent algorithm, | * This is using an order-independent algorithm, | ||||
| * i.e. alignment of buttons should be OK regardless of order in which | * i.e. alignment of buttons should be OK regardless of order in which | ||||
| * they are added to the block. | * they are added to the block. | ||||
| */ | */ | ||||
| void ui_block_align_calc(uiBlock *block, const ARegion *region) | void ui_block_align_calc(uiBlock *block, const ARegion *region) | ||||
| { | { | ||||
| uiBut *but; | |||||
| int num_buttons = 0; | int num_buttons = 0; | ||||
| const int sides_to_ui_but_align_flags[4] = SIDE_TO_UI_BUT_ALIGN; | const int sides_to_ui_but_align_flags[4] = SIDE_TO_UI_BUT_ALIGN; | ||||
| ButAlign *butal_array; | ButAlign *butal_array; | ||||
| ButAlign *butal, *butal_other; | ButAlign *butal, *butal_other; | ||||
| int side; | int side; | ||||
| int i, j; | int i, j; | ||||
| /* First loop: we count number of buttons belonging to an align group, | /* First loop: we count number of buttons belonging to an align group, | ||||
| * and clear their align flag. | * and clear their align flag. | ||||
| * Tabs get some special treatment here, they get aligned to region border. */ | * Tabs get some special treatment here, they get aligned to region border. */ | ||||
| for (but = block->buttons.first; but; but = but->next) { | LISTBASE_FOREACH (uiBut *, but, &block->buttons) { | ||||
| /* special case: tabs need to be aligned to a region border, drawflag tells which one */ | /* special case: tabs need to be aligned to a region border, drawflag tells which one */ | ||||
| if (but->type == UI_BTYPE_TAB) { | if (but->type == UI_BTYPE_TAB) { | ||||
| ui_block_align_but_to_region(but, region); | ui_block_align_but_to_region(but, region); | ||||
| } | } | ||||
| else { | else { | ||||
| /* Clear old align flags. */ | /* Clear old align flags. */ | ||||
| but->drawflag &= ~UI_BUT_ALIGN_ALL; | but->drawflag &= ~UI_BUT_ALIGN_ALL; | ||||
| } | } | ||||
| Show All 16 Lines | if (num_buttons <= ARRAY_SIZE(butal_array_buf)) { | ||||
| butal_array = butal_array_buf; | butal_array = butal_array_buf; | ||||
| } | } | ||||
| else { | else { | ||||
| butal_array = MEM_mallocN(sizeof(*butal_array) * num_buttons, __func__); | butal_array = 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); | ||||
| /* Second loop: we initialize our ButAlign data for each button. */ | /* Second loop: we initialize our ButAlign data for each button. */ | ||||
| for (but = block->buttons.first, butal = butal_array; but; but = but->next) { | butal = butal_array; | ||||
| LISTBASE_FOREACH (uiBut *, but, &block->buttons) { | |||||
| if (but->alignnr != 0) { | if (but->alignnr != 0) { | ||||
| butal->but = but; | butal->but = but; | ||||
| butal->borders[LEFT] = &but->rect.xmin; | butal->borders[LEFT] = &but->rect.xmin; | ||||
| butal->borders[RIGHT] = &but->rect.xmax; | butal->borders[RIGHT] = &but->rect.xmax; | ||||
| butal->borders[DOWN] = &but->rect.ymin; | butal->borders[DOWN] = &but->rect.ymin; | ||||
| butal->borders[TOP] = &but->rect.ymax; | butal->borders[TOP] = &but->rect.ymax; | ||||
| copy_v4_fl(butal->dists, FLT_MAX); | copy_v4_fl(butal->dists, FLT_MAX); | ||||
| butal++; | butal++; | ||||
| ▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | if (prev) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void ui_block_align_calc(uiBlock *block, const struct ARegion *UNUSED(region)) | void ui_block_align_calc(uiBlock *block, const struct ARegion *UNUSED(region)) | ||||
| { | { | ||||
| uiBut *but; | |||||
| short nr; | short nr; | ||||
| /* align buttons with same align nr */ | /* align buttons with same align nr */ | ||||
| for (but = block->buttons.first; but;) { | LISTBASE_FOREACH (uiBut *, but, &block->buttons) { | ||||
| if (but->alignnr) { | if (but->alignnr) { | ||||
| nr = but->alignnr; | nr = but->alignnr; | ||||
| ui_block_align_calc_but(but, nr); | ui_block_align_calc_but(but, nr); | ||||
| /* skip with same number */ | /* skip with same number */ | ||||
| for (; but && but->alignnr == nr; but = but->next) { | for (; but && but->alignnr == nr; but = but->next) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| Show All 32 Lines | |||||