Compare commits
3 Commits
temp-inter
...
temp-fix-h
Author | SHA1 | Date | |
---|---|---|---|
d99f317ab8 | |||
b038f63aee | |||
4f903560a8 |
@@ -118,9 +118,7 @@ typedef struct uiHandlePanelData {
|
|||||||
} uiHandlePanelData;
|
} uiHandlePanelData;
|
||||||
|
|
||||||
typedef struct PanelSort {
|
typedef struct PanelSort {
|
||||||
Panel *panel;
|
Panel *panel, *orig;
|
||||||
int new_offset_x;
|
|
||||||
int new_offset_y;
|
|
||||||
} PanelSort;
|
} PanelSort;
|
||||||
|
|
||||||
static void panel_set_expansion_from_list_data(const bContext *C, Panel *panel);
|
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) {
|
||||||
if (panel->type->flag & PNL_INSTANCED) {
|
if (panel->type->flag & PNL_INSTANCED) {
|
||||||
if (panel_type_context_poll(region, panel->type, context)) {
|
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++;
|
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. */
|
/* Find how many of those panels are above this panel. */
|
||||||
int move_to_index = 0;
|
int move_to_index = 0;
|
||||||
for (; move_to_index < list_panels_len; move_to_index++) {
|
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;
|
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);
|
MEM_freeN(panel_sort);
|
||||||
|
|
||||||
/* Set the bit to tell the interface to instanced the list. */
|
/* 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.
|
* 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 PanelSort *ps1 = a1, *ps2 = a2;
|
||||||
const Panel *panel_b = ((PanelSort *)b)->panel;
|
|
||||||
|
|
||||||
/* Stick uppermost header-less panels to the top of the region -
|
/* 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). */
|
* 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. */
|
/* 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;
|
return -1;
|
||||||
}
|
}
|
||||||
if (panel_b->type->flag & PNL_NO_HEADER) {
|
if (ps2->panel->type->flag & PNL_NO_HEADER) {
|
||||||
return 1;
|
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;
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
if (panel_a->sortorder > panel_b->sortorder) {
|
if (ps1->panel->sortorder > ps2->panel->sortorder) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (panel_a->sortorder < panel_b->sortorder) {
|
if (ps1->panel->sortorder < ps2->panel->sortorder) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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 PanelSort *ps1 = a1, *ps2 = a2;
|
||||||
const Panel *panel_b = ((PanelSort *)b)->panel;
|
|
||||||
|
|
||||||
if (panel_a->sortorder > panel_b->sortorder) {
|
if (ps1->panel->sortorder > ps2->panel->sortorder) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (panel_a->sortorder < panel_b->sortorder) {
|
if (ps1->panel->sortorder < ps2->panel->sortorder) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1723,6 +1725,7 @@ static bool uiAlignPanelStep(ARegion *region, const float factor, const bool dra
|
|||||||
if (panel->runtime_flag & PANEL_ACTIVE) {
|
if (panel->runtime_flag & PANEL_ACTIVE) {
|
||||||
/* These panels should have types since they are currently displayed to the user. */
|
/* These panels should have types since they are currently displayed to the user. */
|
||||||
BLI_assert(panel->type != NULL);
|
BLI_assert(panel->type != NULL);
|
||||||
|
|
||||||
active_panels_len++;
|
active_panels_len++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1731,22 +1734,24 @@ static bool uiAlignPanelStep(ARegion *region, const float factor, const bool dra
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Sort panels. */
|
/* Sort panels. */
|
||||||
PanelSort *panel_sort = MEM_mallocN(sizeof(PanelSort) * active_panels_len, __func__);
|
PanelSort *panel_sort = MEM_callocN(active_panels_len * sizeof(PanelSort), "panelsort");
|
||||||
{
|
|
||||||
PanelSort *ps = panel_sort;
|
PanelSort *ps = panel_sort;
|
||||||
LISTBASE_FOREACH (Panel *, panel, ®ion->panels) {
|
LISTBASE_FOREACH (Panel *, panel, ®ion->panels) {
|
||||||
if (panel->runtime_flag & PANEL_ACTIVE) {
|
if (panel->runtime_flag & PANEL_ACTIVE) {
|
||||||
ps->panel = panel;
|
ps->panel = MEM_dupallocN(panel);
|
||||||
|
ps->orig = panel;
|
||||||
ps++;
|
ps++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (drag) {
|
if (drag) {
|
||||||
/* While dragging, sort based on location and update #Panel.sortorder. */
|
/* While dragging, sort based on location and update #Panel.sortorder. */
|
||||||
qsort(panel_sort, active_panels_len, sizeof(PanelSort), find_highest_panel);
|
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 {
|
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);
|
qsort(panel_sort, active_panels_len, sizeof(PanelSort), compare_panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* X offset. */
|
/* No smart other default start location! This keeps switching f5/f6/etc compatible. */
|
||||||
const int region_offset_x = panel_region_offset_x_get(region);
|
ps = panel_sort;
|
||||||
for (int i = 0; i < active_panels_len; i++) {
|
ps->panel->runtime.region_ofsx = panel_region_offset_x_get(region);
|
||||||
PanelSort *ps = &panel_sort[i];
|
ps->panel->ofsx = 0;
|
||||||
const bool use_box = ps->panel->type->flag & PNL_DRAW_BOX;
|
ps->panel->ofsy = -get_panel_size_y(ps->panel);
|
||||||
ps->panel->runtime.region_ofsx = region_offset_x;
|
ps->panel->ofsx += ps->panel->runtime.region_ofsx;
|
||||||
ps->new_offset_x = region_offset_x + ((use_box) ? UI_PANEL_BOX_STYLE_MARGIN : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Y offset. */
|
for (int i = 0; i < active_panels_len - 1; i++, ps++) {
|
||||||
for (int i = 0, y = 0; i < active_panels_len; i++) {
|
PanelSort *psnext = ps + 1;
|
||||||
PanelSort *ps = &panel_sort[i];
|
|
||||||
y -= get_panel_real_size_y(ps->panel);
|
|
||||||
|
|
||||||
const bool use_box = ps->panel->type->flag & PNL_DRAW_BOX;
|
const bool use_box = ps->panel->type && ps->panel->type->flag & PNL_DRAW_BOX;
|
||||||
if (use_box) {
|
const bool use_box_next = psnext->panel->type && psnext->panel->type->flag & PNL_DRAW_BOX;
|
||||||
y -= UI_PANEL_BOX_STYLE_MARGIN;
|
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;
|
||||||
}
|
}
|
||||||
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. */
|
/* Interpolate based on the input factor. */
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
for (int i = 0; i < active_panels_len; i++) {
|
ps = panel_sort;
|
||||||
PanelSort *ps = &panel_sort[i];
|
for (int i = 0; i < active_panels_len; i++, ps++) {
|
||||||
if (ps->panel->flag & PNL_SELECT) {
|
if ((ps->panel->flag & PNL_SELECT) == 0) {
|
||||||
continue;
|
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);
|
||||||
if (ps->new_offset_x != ps->panel->ofsx) {
|
ps->orig->ofsy = round_fl_to_int(factor * (float)ps->panel->ofsy +
|
||||||
const float x = interpf((float)ps->new_offset_x, (float)ps->panel->ofsx, factor);
|
(1.0f - factor) * (float)ps->orig->ofsy);
|
||||||
ps->panel->ofsx = round_fl_to_int(x);
|
|
||||||
changed = true;
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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);
|
MEM_freeN(panel_sort);
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
|
Reference in New Issue
Block a user