Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-11-06 20:39:56 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-11-06 20:54:33 +0300
commit3d39b98f94a6cd3d4445226dd04d5ba3261bf10b (patch)
tree60dd4a9d3ad22e6622272558e3b09ec0505e9a0b /source/blender/editors/interface/interface.c
parenta25df21631f205c547a476bdc442259bd9a793e0 (diff)
New uialign code, based on 2D positions of widgets.
This new code fixes a tons of issues with previous one, which basically was epic-failing in many non-basic cases (especially mixed columns and rows with column-dominant layout). It basically no more relies over order of buttons declaration in the uiBlock, instead it finds and stores spatial neighbors and uses that data to compute needed stitching. See code comments for details. New code seems to be roughly ten times slower than old one (for complex grouped layouts), that is, about a few microsecconds per alignment group - this remains reasonable. Also, ui-align code becomming rather big in itself, it was separated in own new `interface_align.c` file. Reviewers: campbellbarton, severin Reviewed By: campbellbarton, severin Differential Revision: https://developer.blender.org/D1573
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r--source/blender/editors/interface/interface.c189
1 files changed, 0 insertions, 189 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 28e1f541240..1f0d10588ca 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2926,200 +2926,11 @@ void UI_block_align_begin(uiBlock *block)
/* buttons declared after this call will get this align nr */ // XXX flag?
}
-static bool buts_are_horiz(uiBut *but1, uiBut *but2)
-{
- float dx, dy;
-
- /* simple case which can fail if buttons shift apart
- * with proportional layouts, see: [#38602] */
- if ((but1->rect.ymin == but2->rect.ymin) &&
- (but1->rect.xmin != but2->rect.xmin))
- {
- return true;
- }
-
- dx = fabsf(but1->rect.xmax - but2->rect.xmin);
- dy = fabsf(but1->rect.ymin - but2->rect.ymax);
-
- return (dx <= dy);
-}
-
void UI_block_align_end(uiBlock *block)
{
block->flag &= ~UI_BUT_ALIGN; /* all 4 flags */
}
-bool ui_but_can_align(uiBut *but)
-{
- return !ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_CHECKBOX, UI_BTYPE_CHECKBOX_N, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE);
-}
-
-static void ui_block_align_calc_but(uiBut *first, short nr)
-{
- uiBut *prev, *but = NULL, *next;
- int flag = 0, cols = 0, rows = 0;
-
- /* auto align */
-
- for (but = first; but && but->alignnr == nr; but = but->next) {
- if (but->next && but->next->alignnr == nr) {
- if (buts_are_horiz(but, but->next)) cols++;
- else rows++;
- }
- }
-
- /* rows == 0: 1 row, cols == 0: 1 column */
-
- /* note; how it uses 'flag' in loop below (either set it, or OR it) is confusing */
- for (but = first, prev = NULL; but && but->alignnr == nr; prev = but, but = but->next) {
- next = but->next;
- if (next && next->alignnr != nr)
- next = NULL;
-
- /* clear old flag */
- but->drawflag &= ~UI_BUT_ALIGN;
-
- if (flag == 0) { /* first case */
- if (next) {
- if (buts_are_horiz(but, next)) {
- if (rows == 0)
- flag = UI_BUT_ALIGN_RIGHT;
- else
- flag = UI_BUT_ALIGN_DOWN | UI_BUT_ALIGN_RIGHT;
- }
- else {
- flag = UI_BUT_ALIGN_DOWN;
- }
- }
- }
- else if (next == NULL) { /* last case */
- if (prev) {
- if (buts_are_horiz(prev, but)) {
- if (rows == 0)
- flag = UI_BUT_ALIGN_LEFT;
- else
- flag = UI_BUT_ALIGN_TOP | UI_BUT_ALIGN_LEFT;
- }
- else {
- flag = UI_BUT_ALIGN_TOP;
- }
- }
- }
- else if (buts_are_horiz(but, next)) {
- /* check if this is already second row */
- if (prev && buts_are_horiz(prev, but) == 0) {
- flag &= ~UI_BUT_ALIGN_LEFT;
- flag |= UI_BUT_ALIGN_TOP;
- /* exception case: bottom row */
- if (rows > 0) {
- uiBut *bt = but;
- while (bt && bt->alignnr == nr) {
- if (bt->next && bt->next->alignnr == nr && buts_are_horiz(bt, bt->next) == 0) {
- break;
- }
- bt = bt->next;
- }
- if (bt == NULL || bt->alignnr != nr) flag = UI_BUT_ALIGN_TOP | UI_BUT_ALIGN_RIGHT;
- }
- }
- else {
- flag |= UI_BUT_ALIGN_LEFT;
- }
- }
- else {
- if (cols == 0) {
- flag |= UI_BUT_ALIGN_TOP;
- }
- else { /* next button switches to new row */
-
- if (prev && buts_are_horiz(prev, but))
- flag |= UI_BUT_ALIGN_LEFT;
- else {
- flag &= ~UI_BUT_ALIGN_LEFT;
- flag |= UI_BUT_ALIGN_TOP;
- }
-
- if ((flag & UI_BUT_ALIGN_TOP) == 0) { /* stil top row */
- if (prev) {
- if (next && buts_are_horiz(but, next))
- flag = UI_BUT_ALIGN_DOWN | UI_BUT_ALIGN_LEFT | UI_BUT_ALIGN_RIGHT;
- else {
- /* last button in top row */
- flag = UI_BUT_ALIGN_DOWN | UI_BUT_ALIGN_LEFT;
- }
- }
- else
- flag |= UI_BUT_ALIGN_DOWN;
- }
- else
- flag |= UI_BUT_ALIGN_TOP;
- }
- }
-
- but->drawflag |= flag;
-
- /* merge coordinates */
- if (prev) {
- /* simple cases */
- if (rows == 0) {
- but->rect.xmin = (prev->rect.xmax + but->rect.xmin) / 2.0f;
- prev->rect.xmax = but->rect.xmin;
- }
- else if (cols == 0) {
- but->rect.ymax = (prev->rect.ymin + but->rect.ymax) / 2.0f;
- prev->rect.ymin = but->rect.ymax;
- }
- else {
- if (buts_are_horiz(prev, but)) {
- but->rect.xmin = (prev->rect.xmax + but->rect.xmin) / 2.0f;
- prev->rect.xmax = but->rect.xmin;
- /* copy height too */
- but->rect.ymax = prev->rect.ymax;
- }
- else if (prev->prev && buts_are_horiz(prev->prev, prev) == 0) {
- /* the previous button is a single one in its row */
- but->rect.ymax = (prev->rect.ymin + but->rect.ymax) / 2.0f;
- prev->rect.ymin = but->rect.ymax;
-
- but->rect.xmin = prev->rect.xmin;
- if (next && buts_are_horiz(but, next) == 0)
- but->rect.xmax = prev->rect.xmax;
- }
- else {
- /* the previous button is not a single one in its row */
- but->rect.ymax = prev->rect.ymin;
- }
- }
- }
- }
-}
-
-void ui_block_align_calc(uiBlock *block)
-{
- uiBut *but;
- short nr;
-
- /* align buttons with same align nr */
- for (but = block->buttons.first; but; ) {
- if (but->alignnr) {
- nr = but->alignnr;
- ui_block_align_calc_but(but, nr);
-
- /* skip with same number */
- for (; but && but->alignnr == nr; but = but->next) {
- /* pass */
- }
-
- if (!but) {
- break;
- }
- }
- else {
- but = but->next;
- }
- }
-}
-
struct ColorManagedDisplay *ui_block_cm_display_get(uiBlock *block)
{
return IMB_colormanagement_display_get_named(block->display_device);