Compare commits
3 Commits
tmp-dynami
...
temp-fix-h
Author | SHA1 | Date | |
---|---|---|---|
d99f317ab8 | |||
b038f63aee | |||
4f903560a8 |
@@ -118,9 +118,7 @@ typedef struct uiHandlePanelData {
|
||||
} uiHandlePanelData;
|
||||
|
||||
typedef struct PanelSort {
|
||||
Panel *panel;
|
||||
int new_offset_x;
|
||||
int new_offset_y;
|
||||
Panel *panel, *orig;
|
||||
} PanelSort;
|
||||
|
||||
static void panel_set_expansion_from_list_data(const bContext *C, Panel *panel);
|
||||
@@ -472,7 +470,8 @@ static void reorder_instanced_panel_list(bContext *C, ARegion *region, Panel *dr
|
||||
if (panel->type) {
|
||||
if (panel->type->flag & PNL_INSTANCED) {
|
||||
if (panel_type_context_poll(region, panel->type, context)) {
|
||||
sort_index->panel = panel;
|
||||
sort_index->panel = MEM_dupallocN(panel);
|
||||
sort_index->orig = panel;
|
||||
sort_index++;
|
||||
}
|
||||
}
|
||||
@@ -483,11 +482,16 @@ static void reorder_instanced_panel_list(bContext *C, ARegion *region, Panel *dr
|
||||
/* Find how many of those panels are above this panel. */
|
||||
int move_to_index = 0;
|
||||
for (; move_to_index < list_panels_len; move_to_index++) {
|
||||
if (panel_sort[move_to_index].panel == drag_panel) {
|
||||
if (panel_sort[move_to_index].orig == drag_panel) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Free panel sort array. */
|
||||
int i = 0;
|
||||
for (sort_index = panel_sort; i < list_panels_len; i++, sort_index++) {
|
||||
MEM_freeN(sort_index->panel);
|
||||
}
|
||||
MEM_freeN(panel_sort);
|
||||
|
||||
/* Set the bit to tell the interface to instanced the list. */
|
||||
@@ -1646,48 +1650,46 @@ bool UI_panel_is_dragging(const struct Panel *panel)
|
||||
* panels do not match for sorting.
|
||||
*/
|
||||
|
||||
static int find_highest_panel(const void *a, const void *b)
|
||||
static int find_highest_panel(const void *a1, const void *a2)
|
||||
{
|
||||
const Panel *panel_a = ((PanelSort *)a)->panel;
|
||||
const Panel *panel_b = ((PanelSort *)b)->panel;
|
||||
const PanelSort *ps1 = a1, *ps2 = a2;
|
||||
|
||||
/* Stick uppermost header-less panels to the top of the region -
|
||||
* prevent them from being sorted (multiple header-less panels have to be sorted though). */
|
||||
if (panel_a->type->flag & PNL_NO_HEADER && panel_b->type->flag & PNL_NO_HEADER) {
|
||||
if (ps1->panel->type->flag & PNL_NO_HEADER && ps2->panel->type->flag & PNL_NO_HEADER) {
|
||||
/* Skip and check for `ofsy` and #Panel.sortorder below. */
|
||||
}
|
||||
if (panel_a->type->flag & PNL_NO_HEADER) {
|
||||
if (ps1->panel->type->flag & PNL_NO_HEADER) {
|
||||
return -1;
|
||||
}
|
||||
if (panel_b->type->flag & PNL_NO_HEADER) {
|
||||
if (ps2->panel->type->flag & PNL_NO_HEADER) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (panel_a->ofsy + panel_a->sizey < panel_b->ofsy + panel_b->sizey) {
|
||||
if (ps1->panel->ofsy + ps1->panel->sizey < ps2->panel->ofsy + ps2->panel->sizey) {
|
||||
return 1;
|
||||
}
|
||||
if (panel_a->ofsy + panel_a->sizey > panel_b->ofsy + panel_b->sizey) {
|
||||
if (ps1->panel->ofsy + ps1->panel->sizey > ps2->panel->ofsy + ps2->panel->sizey) {
|
||||
return -1;
|
||||
}
|
||||
if (panel_a->sortorder > panel_b->sortorder) {
|
||||
if (ps1->panel->sortorder > ps2->panel->sortorder) {
|
||||
return 1;
|
||||
}
|
||||
if (panel_a->sortorder < panel_b->sortorder) {
|
||||
if (ps1->panel->sortorder < ps2->panel->sortorder) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int compare_panel(const void *a, const void *b)
|
||||
static int compare_panel(const void *a1, const void *a2)
|
||||
{
|
||||
const Panel *panel_a = ((PanelSort *)a)->panel;
|
||||
const Panel *panel_b = ((PanelSort *)b)->panel;
|
||||
const PanelSort *ps1 = a1, *ps2 = a2;
|
||||
|
||||
if (panel_a->sortorder > panel_b->sortorder) {
|
||||
if (ps1->panel->sortorder > ps2->panel->sortorder) {
|
||||
return 1;
|
||||
}
|
||||
if (panel_a->sortorder < panel_b->sortorder) {
|
||||
if (ps1->panel->sortorder < ps2->panel->sortorder) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1723,6 +1725,7 @@ static bool uiAlignPanelStep(ARegion *region, const float factor, const bool dra
|
||||
if (panel->runtime_flag & PANEL_ACTIVE) {
|
||||
/* These panels should have types since they are currently displayed to the user. */
|
||||
BLI_assert(panel->type != NULL);
|
||||
|
||||
active_panels_len++;
|
||||
}
|
||||
}
|
||||
@@ -1731,22 +1734,24 @@ static bool uiAlignPanelStep(ARegion *region, const float factor, const bool dra
|
||||
}
|
||||
|
||||
/* Sort panels. */
|
||||
PanelSort *panel_sort = MEM_mallocN(sizeof(PanelSort) * active_panels_len, __func__);
|
||||
{
|
||||
PanelSort *ps = panel_sort;
|
||||
LISTBASE_FOREACH (Panel *, panel, ®ion->panels) {
|
||||
if (panel->runtime_flag & PANEL_ACTIVE) {
|
||||
ps->panel = panel;
|
||||
ps++;
|
||||
}
|
||||
PanelSort *panel_sort = MEM_callocN(active_panels_len * sizeof(PanelSort), "panelsort");
|
||||
|
||||
PanelSort *ps = panel_sort;
|
||||
LISTBASE_FOREACH (Panel *, panel, ®ion->panels) {
|
||||
if (panel->runtime_flag & PANEL_ACTIVE) {
|
||||
ps->panel = MEM_dupallocN(panel);
|
||||
ps->orig = panel;
|
||||
ps++;
|
||||
}
|
||||
}
|
||||
|
||||
if (drag) {
|
||||
/* While dragging, sort based on location and update #Panel.sortorder. */
|
||||
qsort(panel_sort, active_panels_len, sizeof(PanelSort), find_highest_panel);
|
||||
for (int i = 0; i < active_panels_len; i++) {
|
||||
panel_sort[i].panel->sortorder = i;
|
||||
|
||||
int i;
|
||||
for (ps = panel_sort, i = 0; i < active_panels_len; i++, ps++) {
|
||||
ps->orig->sortorder = i;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1754,48 +1759,45 @@ static bool uiAlignPanelStep(ARegion *region, const float factor, const bool dra
|
||||
qsort(panel_sort, active_panels_len, sizeof(PanelSort), compare_panel);
|
||||
}
|
||||
|
||||
/* X offset. */
|
||||
const int region_offset_x = panel_region_offset_x_get(region);
|
||||
for (int i = 0; i < active_panels_len; i++) {
|
||||
PanelSort *ps = &panel_sort[i];
|
||||
const bool use_box = ps->panel->type->flag & PNL_DRAW_BOX;
|
||||
ps->panel->runtime.region_ofsx = region_offset_x;
|
||||
ps->new_offset_x = region_offset_x + ((use_box) ? UI_PANEL_BOX_STYLE_MARGIN : 0);
|
||||
/* No smart other default start location! This keeps switching f5/f6/etc compatible. */
|
||||
ps = panel_sort;
|
||||
ps->panel->runtime.region_ofsx = panel_region_offset_x_get(region);
|
||||
ps->panel->ofsx = 0;
|
||||
ps->panel->ofsy = -get_panel_size_y(ps->panel);
|
||||
ps->panel->ofsx += ps->panel->runtime.region_ofsx;
|
||||
|
||||
for (int i = 0; i < active_panels_len - 1; i++, ps++) {
|
||||
PanelSort *psnext = ps + 1;
|
||||
|
||||
const bool use_box = ps->panel->type && ps->panel->type->flag & PNL_DRAW_BOX;
|
||||
const bool use_box_next = psnext->panel->type && psnext->panel->type->flag & PNL_DRAW_BOX;
|
||||
psnext->panel->ofsx = ps->panel->ofsx;
|
||||
psnext->panel->ofsy = get_panel_real_ofsy(ps->panel) - get_panel_size_y(psnext->panel);
|
||||
|
||||
/* Extra margin for box style panels. */
|
||||
ps->panel->ofsx += (use_box) ? UI_PANEL_BOX_STYLE_MARGIN : 0.0f;
|
||||
if (use_box || use_box_next) {
|
||||
psnext->panel->ofsy -= UI_PANEL_BOX_STYLE_MARGIN;
|
||||
}
|
||||
}
|
||||
|
||||
/* Y offset. */
|
||||
for (int i = 0, y = 0; i < active_panels_len; i++) {
|
||||
PanelSort *ps = &panel_sort[i];
|
||||
y -= get_panel_real_size_y(ps->panel);
|
||||
|
||||
const bool use_box = ps->panel->type->flag & PNL_DRAW_BOX;
|
||||
if (use_box) {
|
||||
y -= UI_PANEL_BOX_STYLE_MARGIN;
|
||||
}
|
||||
ps->new_offset_y = y;
|
||||
/* The header still draws offset by the size of closed panels, so apply the offset here. */
|
||||
if (UI_panel_is_closed(ps->panel)) {
|
||||
panel_sort[i].new_offset_y -= ps->panel->sizey;
|
||||
}
|
||||
/* Extra margin for the last panel if it's a box-style panel. */
|
||||
if (panel_sort[active_panels_len - 1].panel->type &&
|
||||
panel_sort[active_panels_len - 1].panel->type->flag & PNL_DRAW_BOX) {
|
||||
panel_sort[active_panels_len - 1].panel->ofsx += UI_PANEL_BOX_STYLE_MARGIN;
|
||||
}
|
||||
|
||||
/* Interpolate based on the input factor. */
|
||||
bool changed = false;
|
||||
for (int i = 0; i < active_panels_len; i++) {
|
||||
PanelSort *ps = &panel_sort[i];
|
||||
if (ps->panel->flag & PNL_SELECT) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ps->new_offset_x != ps->panel->ofsx) {
|
||||
const float x = interpf((float)ps->new_offset_x, (float)ps->panel->ofsx, factor);
|
||||
ps->panel->ofsx = round_fl_to_int(x);
|
||||
changed = true;
|
||||
}
|
||||
if (ps->new_offset_y != ps->panel->ofsy) {
|
||||
const float y = interpf((float)ps->new_offset_y, (float)ps->panel->ofsy, factor);
|
||||
ps->panel->ofsy = round_fl_to_int(y);
|
||||
changed = true;
|
||||
ps = panel_sort;
|
||||
for (int i = 0; i < active_panels_len; i++, ps++) {
|
||||
if ((ps->panel->flag & PNL_SELECT) == 0) {
|
||||
if ((ps->orig->ofsx != ps->panel->ofsx) || (ps->orig->ofsy != ps->panel->ofsy)) {
|
||||
ps->orig->ofsx = round_fl_to_int(factor * (float)ps->panel->ofsx +
|
||||
(1.0f - factor) * (float)ps->orig->ofsx);
|
||||
ps->orig->ofsy = round_fl_to_int(factor * (float)ps->panel->ofsy +
|
||||
(1.0f - factor) * (float)ps->orig->ofsy);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1808,6 +1810,10 @@ static bool uiAlignPanelStep(ARegion *region, const float factor, const bool dra
|
||||
}
|
||||
}
|
||||
|
||||
int i;
|
||||
for (ps = panel_sort, i = 0; i < active_panels_len; i++, ps++) {
|
||||
MEM_freeN(ps->panel);
|
||||
}
|
||||
MEM_freeN(panel_sort);
|
||||
|
||||
return changed;
|
||||
|
Reference in New Issue
Block a user