[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58628] branches/soc-2013-ui_replay/source /blender: Toolbar popup panels work.
Vincent Akkermans
vincent at ack-err.net
Fri Jul 26 18:14:24 CEST 2013
Revision: 58628
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58628
Author: ack-err
Date: 2013-07-26 16:14:24 +0000 (Fri, 26 Jul 2013)
Log Message:
-----------
Toolbar popup panels work. There are still some bugs with laying out and drawing text.
Modified Paths:
--------------
branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h
branches/soc-2013-ui_replay/source/blender/editors/interface/interface.c
branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c
branches/soc-2013-ui_replay/source/blender/editors/interface/interface_panel.c
branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_operators.c
Modified: branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h 2013-07-26 16:13:09 UTC (rev 58627)
+++ branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h 2013-07-26 16:14:24 UTC (rev 58628)
@@ -387,6 +387,7 @@
uiBlock *uiGetBlock(const char *name, struct ARegion *ar);
void uiBlockSetEmboss(uiBlock *block, char dt);
+void uiBlockSetPanel(uiBlock *block, struct Panel *pa);
void uiFreeBlock(const struct bContext *C, uiBlock *block);
void uiFreeBlocks(const struct bContext *C, struct ListBase *lb);
Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface.c 2013-07-26 16:13:09 UTC (rev 58627)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface.c 2013-07-26 16:14:24 UTC (rev 58628)
@@ -2254,6 +2254,11 @@
block->dt = dt;
}
+void uiBlockSetPanel(uiBlock *block, Panel *pa)
+{
+ block->panel = pa;
+}
+
void ui_check_but(uiBut *but)
{
/* if something changed in the button */
Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c 2013-07-26 16:13:09 UTC (rev 58627)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c 2013-07-26 16:14:24 UTC (rev 58628)
@@ -736,8 +736,10 @@
/* text alignment for toolbar buttons */
if ((layout->root->type == UI_LAYOUT_TOOLBAR) && (!icon || flag & UI_ITEM_O_SHORTCUT)) {
but->flag |= UI_TEXT_LEFT;
- but->flag |= UI_ICON_LEFT;
}
+
+ if (layout->root->type == UI_LAYOUT_TOOLBAR && !(flag & UI_ITEM_O_SHORTCUT))
+ but->flag &= ~UI_ICON_LEFT;
if (flag & UI_ITEM_R_NO_BG)
uiBlockSetEmboss(block, UI_EMBOSS);
Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface_panel.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface_panel.c 2013-07-26 16:13:09 UTC (rev 58627)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_panel.c 2013-07-26 16:14:24 UTC (rev 58628)
@@ -61,6 +61,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "RNA_access.h"
+
#include "interface_intern.h"
/*********************** defines and structs ************************/
@@ -1092,7 +1094,7 @@
/* this function is supposed to call general window drawing too */
/* also it supposes a block has panel, and isn't a menu */
-static void ui_handle_panel_header(const bContext *C, uiBlock *block, int mx, int my, int event, int ctrl)
+static void ui_handle_panel_header(bContext *C, uiBlock *block, int mx, int my, int event, int ctrl)
{
ScrArea *sa = CTX_wm_area(C);
ARegion *ar = CTX_wm_region(C);
@@ -1100,7 +1102,9 @@
int align = panel_aligned(sa, ar), button = 0;
int x_popup = block->rect.xmax - ((2 * PNL_ICON) + 5) / block->aspect;
int x_drag = block->rect.xmax - (PNL_ICON + 5) / block->aspect;
-
+ PointerRNA props_ptr, panel_ptr;
+ PropertyRNA *prop = NULL;
+
/* mouse coordinates in panel space! */
/* XXX weak code, currently it assumes layout style for location of widgets */
@@ -1179,7 +1183,15 @@
ED_region_tag_redraw(ar);
break;
case 3:
- printf("Boo!\n");
+ WM_operator_properties_create(&props_ptr, "WM_OT_panel_popup");
+
+ // Can't seem to pass an RNA pointer..
+// RNA_pointer_create(NULL, &RNA_Panel, &block->panel, &panel_ptr);
+// RNA_pointer_set(&props_ptr, "panel", panel_ptr);
+
+ RNA_string_set(&props_ptr, "panel_name", block->panel->type->idname);
+ WM_operator_name_call(C, "WM_OT_panel_popup", WM_OP_INVOKE_DEFAULT, &props_ptr);
+ break;
case 4:
default:
panel_activate_state(C, block->panel, PANEL_STATE_DRAG);
Modified: branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_operators.c 2013-07-26 16:13:09 UTC (rev 58627)
+++ branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_operators.c 2013-07-26 16:14:24 UTC (rev 58628)
@@ -91,6 +91,7 @@
#include "ED_object.h"
#include "ED_view3d.h"
+#include "RNA_types.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -4146,6 +4147,116 @@
}
/* ******************************************************* */
+
+static uiBlock *wm_panel_popup_create_block(bContext *C, ARegion *ar, void *arg_op)
+{
+ ARegion *tar = CTX_wm_region(C);
+// wmWindow *win = CTX_wm_window(C);
+// wmEvent event;
+ uiBlock *block;
+ wmOperator *op = arg_op;
+ char panel_name[64];
+ Panel *pa;
+ PanelType *pt = NULL;
+ uiStyle *style = UI_GetStyleDraw();
+ int xco, yco;
+ int w = UI_PANEL_WIDTH / 2;
+ int em = UI_UNIT_Y;
+
+ // Can't seem to pass RNA pointers in op properties, PropertyRNA/PointerPropertyPRNA stuff
+ // pa = RNA_pointer_get(op->ptr, "panel").data;
+ // printf("%s, %s\n", __func__, "");
+
+ RNA_string_get(op->ptr, "panel_name", panel_name);
+
+ /* Get the first panel with the same name. If multiple panels
+ with the same name exist this won't work. Tried to pass an
+ RNA Pointer, but that doesn't seem to be possible. */
+ for (pa = tar->panels.first; pa; pa = pa->next) {
+ if (pa->type && pa->type->idname) {
+ if(strcmp(pa->type->idname, panel_name) == 0) {
+ pt = pa->type;
+ break;
+ }
+ }
+ }
+
+ block = uiBeginBlock(C, ar, "popup", UI_EMBOSS);
+
+ uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU);
+
+ if (pt) {
+
+ pa = MEM_callocN(sizeof(Panel), "new panel");
+ pa->type = pt;
+ BLI_strncpy(pa->panelname, pt->idname, UI_MAX_NAME_STR);
+ BLI_strncpy(pa->tabname, pt->idname, UI_MAX_NAME_STR);
+
+ pa->ofsx = 0;
+ pa->ofsy = 0;
+ pa->sizex = 0;
+ pa->sizey = 0;
+
+ uiBlockSetPanel(block, pa);
+
+ pa->layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_TOOLBAR,
+ style->panelspace, 0, w - 2 * style->panelspace, em, style);
+ pt->draw(C, pa);
+ pa->labelofs = 0;
+ uiBlockLayoutResolve(block, &xco, &yco);
+
+ yco -= 2 * style->panelspace;
+ uiEndPanel(block, w, 0);
+ }
+
+ uiPopupBoundsBlock(block, 6, 0, -UI_UNIT_Y); /* move it downwards, mouse over button */
+ uiEndBlock(C, block);
+
+ return block;
+}
+
+
+static int wm_panel_popup_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
+{
+ return OPERATOR_FINISHED;
+}
+
+static int wm_panel_popup_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ uiPupBlock(C, wm_panel_popup_create_block, op);
+ return OPERATOR_CANCELLED;
+}
+
+static int wm_panel_popup_poll(bContext *UNUSED(C))
+{
+ return 1;
+}
+
+static void WM_OT_panel_popup(wmOperatorType *ot)
+{
+ PropertyRNA *prop;
+
+ ot->name = "Panel Popup";
+ ot->idname = "WM_OT_panel_popup";
+ ot->description = "Pop-up a panel so that the panel's content is available without unfolding it";
+
+ ot->invoke = wm_panel_popup_invoke;
+ ot->exec = wm_panel_popup_exec;
+ ot->poll = wm_panel_popup_poll;
+
+ ot->flag |= OPTYPE_INTERNAL;
+
+ // Can't seem to define a pointer property for operators.
+ // The set/get/etc. functions aren't present when calling RNA_pointer_set
+// prop = RNA_def_pointer(ot->srna, "panel", "Panel", "", "");
+// RNA_def_property_flag(prop, PROP_HIDDEN | PROP_REQUIRED | PROP_NEVER_NULL);
+
+ prop = RNA_def_string(ot->srna, "panel_name", "", 64, "panel_name", "The name of the panel being opened in a popup");
+ RNA_def_property_flag(prop, PROP_HIDDEN | PROP_REQUIRED);
+}
+
+
+/* ******************************************************* */
/* called on initialize WM_exit() */
void wm_operatortype_free(void)
{
@@ -4184,6 +4295,7 @@
WM_operatortype_append(WM_OT_call_menu);
WM_operatortype_append(WM_OT_radial_control);
WM_operatortype_append(WM_OT_ndof_sensitivity_change);
+ WM_operatortype_append(WM_OT_panel_popup);
#if defined(WIN32)
WM_operatortype_append(WM_OT_console_toggle);
#endif
More information about the Bf-blender-cvs
mailing list