[Bf-blender-cvs] [a8bb0af673b] modifier-panels-ui: Add a RECREATE panel type
Hans Goudey
noreply at git.blender.org
Sat Mar 28 05:38:12 CET 2020
Commit: a8bb0af673b3fc27ec36acddbe7d801745c6bbab
Author: Hans Goudey
Date: Fri Mar 27 23:07:06 2020 -0500
Branches: modifier-panels-ui
https://developer.blender.org/rBa8bb0af673b3fc27ec36acddbe7d801745c6bbab
Add a RECREATE panel type
Panels built from types with this flag don't have a 1 to 1 correspondence
with their types-- there can be many panels built from a single type. That
can be used to tie each panel to a modifier instead.
===================================================================
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/interface.c
M source/blender/editors/interface/interface_panel.c
M source/blender/editors/interface/interface_region_popup.c
M source/blender/editors/screen/area.c
M source/blender/makesdna/DNA_screen_types.h
===================================================================
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 1fa6e5b12c1..58d72c92822 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -669,7 +669,7 @@ void UI_block_emboss_set(uiBlock *block, char dt);
void UI_block_free(const struct bContext *C, uiBlock *block);
void UI_blocklist_free(const struct bContext *C, struct ListBase *lb);
-void UI_blocklist_free_inactive(const struct bContext *C, struct ListBase *lb);
+void UI_blocklist_free_inactive(const struct bContext *C, struct ARegion *region);
void UI_screen_free_active_but(const struct bContext *C, struct bScreen *screen);
void UI_block_region_set(uiBlock *block, struct ARegion *region);
@@ -1663,6 +1663,14 @@ void UI_panel_end(const struct ScrArea *sa,
int width,
int height,
bool open);
+struct Panel *UI_panel_add(struct ScrArea *sa,
+ struct ARegion *region,
+ struct ListBase *panels,
+ struct PanelType *panel_type,
+ int modifier_index);
+void UI_panel_delete(struct ListBase *panels, struct Panel *panel);
+
+void UI_panels_free_recreate(struct ListBase *panels);
void UI_panels_scale(struct ARegion *region, float new_width);
void UI_panel_label_offset(struct uiBlock *block, int *r_x, int *r_y);
int UI_panel_size_y(const struct Panel *pa);
@@ -1955,7 +1963,7 @@ void uiTemplatePathBuilder(uiLayout *layout,
const char *propname,
struct PointerRNA *root_ptr,
const char *text);
-uiLayout *uiTemplateModifier(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr);
+void uiTemplateModifiers(uiLayout *layout, struct bContext *C);
uiLayout *uiTemplateGpencilModifier(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr);
void uiTemplateGpencilColorPreview(uiLayout *layout,
struct bContext *C,
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 41b7683dff7..1a0bacde56f 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -3301,16 +3301,32 @@ void UI_blocklist_free(const bContext *C, ListBase *lb)
}
}
-void UI_blocklist_free_inactive(const bContext *C, ListBase *lb)
+void UI_blocklist_free_inactive(const bContext *C, ARegion *region)
{
+ printf("UI_BLOCKLIST_FREE_INACTIVE\n");
uiBlock *block, *nextblock;
- for (block = lb->first; block; block = nextblock) {
+ for (block = region->uiblocks.first; block; block = nextblock) {
nextblock = block->next;
+ Panel *panel = block->panel;
+ if (panel != NULL && panel->type->flag & PANELTYPE_RECREATE) {
+ printf(" Recreate panel found: %s\n", panel->panelname);
+ }
if (!block->handle) {
+ if (panel != NULL && panel->type->flag & PANELTYPE_RECREATE) {
+ printf(" No block handle\n");
+ }
if (!block->active) {
- BLI_remlink(lb, block);
+ if (panel != NULL && panel->type->flag & PANELTYPE_RECREATE) {
+ printf(" Block not active\n");
+ }
+ /* Remove recreate panels as well. */
+ if (panel != NULL && panel->type->flag & PANELTYPE_RECREATE) {
+ UI_panel_delete(®ion->panels, panel);
+ }
+
+ BLI_remlink(®ion->uiblocks, block);
UI_block_free(C, block);
}
else {
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index d57b4d444bd..e14adc6322d 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -451,6 +451,90 @@ static void ui_offset_panel_block(uiBlock *block)
block->rect.xmin = block->rect.ymin = 0.0;
}
+/**
+ * Called in situations where panels need to be added dynamically rather than only having one panel
+ * corresponding to each PanelType.
+ */
+Panel *UI_panel_add(
+ ScrArea *sa, ARegion *region, ListBase *panels, PanelType *panel_type, int modifier_index)
+{
+ Panel *panel = MEM_callocN(sizeof(Panel), "new panel");
+ panel->type = panel_type;
+ BLI_strncpy(panel->panelname, panel_type->idname, sizeof(panel->panelname));
+
+ if (panel_type->flag & PNL_DEFAULT_CLOSED) {
+ int align = panel_aligned(sa, region);
+ if (align == BUT_VERTICAL) {
+ panel->flag |= PNL_CLOSEDY;
+ }
+ else {
+ panel->flag |= PNL_CLOSEDX;
+ }
+ }
+
+ panel->ofsx = 0;
+ panel->ofsy = 0;
+ panel->sizex = 0;
+ panel->sizey = 0;
+ panel->blocksizex = 0;
+ panel->blocksizey = 0;
+ panel->runtime_flag |= PNL_NEW_ADDED;
+
+ panel->modifier_index = modifier_index;
+
+ /* Add the panel's children too. */
+ for (LinkData *link = panel_type->children.first; link; link = link->next) {
+ PanelType *child = link->data;
+ UI_panel_add(sa, region, &panel->children, child, modifier_index);
+ }
+
+ BLI_addtail(panels, panel);
+
+ return panel;
+}
+
+void UI_panel_delete(ListBase *panels, Panel *panel)
+{
+ printf("UI_PANEL_DELETE\n");
+ /* Recursively delete children. */
+ Panel *child = panel->children.first;
+ while (child != NULL) {
+
+ Panel *child_next = child->next;
+ UI_panel_delete(&panel->children, child);
+ child = child_next;
+ }
+ BLI_freelistN(&panel->children);
+
+ BLI_remlink(panels, panel);
+ if (panel->activedata) {
+ MEM_freeN(panel->activedata);
+ }
+ MEM_freeN(panel);
+}
+
+void UI_panels_free_recreate(ListBase *panels)
+{
+ /* Delete panels with the recreate flag. */
+ printf("UI_PANELS_FREE_RECREATE\n");
+ Panel *panel = panels->first;
+ Panel *panel_next = NULL;
+ while (panel != NULL) {
+ bool remove = false;
+ if (panel->type != NULL) { /* Some panels don't have a type.. */
+ if (panel->type->flag & PANELTYPE_RECREATE) {
+ remove = true;
+ }
+ }
+
+ panel_next = panel->next;
+ if (remove) {
+ UI_panel_delete(panels, panel);
+ }
+ panel = panel_next;
+ }
+}
+
/**************************** drawing *******************************/
/* triangle 'icon' for panel header */
diff --git a/source/blender/editors/interface/interface_region_popup.c b/source/blender/editors/interface/interface_region_popup.c
index ba9a5026ce3..099e321bbfc 100644
--- a/source/blender/editors/interface/interface_region_popup.c
+++ b/source/blender/editors/interface/interface_region_popup.c
@@ -752,7 +752,7 @@ uiBlock *ui_popup_block_refresh(bContext *C,
if (block_old) {
block->oldblock = block_old;
UI_block_update_from_old(C, block);
- UI_blocklist_free_inactive(C, ®ion->uiblocks);
+ UI_blocklist_free_inactive(C, region);
}
/* checks which buttons are visible, sets flags to prevent draw (do after region init) */
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 56ea59c1d6e..eff5beea0fc 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -27,6 +27,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_userdef_types.h"
+#include "DNA_modifier_types.h"
#include "BLI_blenlib.h"
#include "BLI_linklist_stack.h"
@@ -560,7 +561,7 @@ void ED_region_do_draw(bContext *C, ARegion *region)
memset(®ion->drawrct, 0, sizeof(region->drawrct));
- UI_blocklist_free_inactive(C, ®ion->uiblocks);
+ UI_blocklist_free_inactive(C, region);
if (sa) {
const bScreen *screen = WM_window_get_active_screen(win);
@@ -2574,8 +2575,14 @@ void ED_region_panels_layout_ex(const bContext *C,
/* set view2d view matrix - UI_block_begin() stores it */
UI_view2d_view_ortho(v2d);
+ bool has_always_recreate_panel = false;
for (LinkNode *pt_link = panel_types_stack; pt_link; pt_link = pt_link->next) {
PanelType *pt = pt_link->link;
+
+ if (pt->flag & PANELTYPE_RECREATE) {
+ has_always_recreate_panel = true;
+ continue;
+ }
Panel *panel = UI_panel_find_by_type(®ion->panels, pt);
if (use_category_tabs && pt->category[0] && !STREQ(category, pt->category)) {
@@ -2583,10 +2590,23 @@ void ED_region_panels_layout_ex(const bContext *C,
continue;
}
}
-
ed_panel_draw(C, sa, region, ®ion->panels, pt, panel, w, em, vertical);
}
+ printf("ED_REGION_PANELS_LAYOUT_EX\n");
+ if (has_always_recreate_panel) {
+ printf(" Drawing Recreate Panels:");
+ for (Panel *panel = region->panels.first; panel; panel = panel->next) {
+ if (panel->type != NULL) { /* Some panels don't have a type.. */
+ if (panel->type->flag & PANELTYPE_RECREATE) {
+ printf(" %s,", panel->type->idname);
+ ed_panel_draw(C, sa, region, ®ion->panels, panel->type, panel, w, em, vertical);
+ }
+ }
+ }
+ printf("\n");
+ }
+
/* align panels and return size */
UI_panels_end(C, region, &x, &y);
diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h
index 9a59b69604d..94ea1c99d80 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -163,6 +163,10 @@ typedef struct Panel {
int sortorder;
/** Runtime for panel manipulation. */
void *activedata;
+ /* For recreate type panels to store which instance of their panel type creator's object they
+ * correspond to. */
+ int modifier_index;
+ char _pad1[4];
/** Sub panels. */
ListBase children;
@@ -546,6 +550,8 @@ enum {
#define PNL_DEFAULT_CLOSED 1
#define PNL_NO_HEADER 2
#define PNL_LAYOUT_VERT_BAR 4
+/** Delete panel after drawing, don't search for panel by type. */
+#define PANELTYPE_RECREATE 8
/* Fallback panel category (only for old scripts which need updating) */
#define PNL_CATEGORY_FALLBACK "Misc"
More information about the Bf-blender-cvs
mailing list