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:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/editors/interface/interface_region_menu_pie.c
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/editors/interface/interface_region_menu_pie.c')
-rw-r--r--source/blender/editors/interface/interface_region_menu_pie.c496
1 files changed, 272 insertions, 224 deletions
diff --git a/source/blender/editors/interface/interface_region_menu_pie.c b/source/blender/editors/interface/interface_region_menu_pie.c
index b2fcfc0b23b..b115600a80b 100644
--- a/source/blender/editors/interface/interface_region_menu_pie.c
+++ b/source/blender/editors/interface/interface_region_menu_pie.c
@@ -59,225 +59,249 @@
* \{ */
struct uiPieMenu {
- uiBlock *block_radial; /* radial block of the pie menu (more could be added later) */
- uiLayout *layout;
- int mx, my;
+ uiBlock *block_radial; /* radial block of the pie menu (more could be added later) */
+ uiLayout *layout;
+ int mx, my;
};
static uiBlock *ui_block_func_PIE(bContext *UNUSED(C), uiPopupBlockHandle *handle, void *arg_pie)
{
- uiBlock *block;
- uiPieMenu *pie = arg_pie;
- int minwidth, width, height;
+ uiBlock *block;
+ uiPieMenu *pie = arg_pie;
+ int minwidth, width, height;
- minwidth = UI_MENU_WIDTH_MIN;
- block = pie->block_radial;
+ minwidth = UI_MENU_WIDTH_MIN;
+ block = pie->block_radial;
- /* in some cases we create the block before the region,
- * so we set it delayed here if necessary */
- if (BLI_findindex(&handle->region->uiblocks, block) == -1) {
- UI_block_region_set(block, handle->region);
- }
+ /* in some cases we create the block before the region,
+ * so we set it delayed here if necessary */
+ if (BLI_findindex(&handle->region->uiblocks, block) == -1) {
+ UI_block_region_set(block, handle->region);
+ }
- UI_block_layout_resolve(block, &width, &height);
+ UI_block_layout_resolve(block, &width, &height);
- UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_NUMSELECT);
- UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP);
+ UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_NUMSELECT);
+ UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP);
- block->minbounds = minwidth;
- block->bounds = 1;
- block->bounds_offset[0] = 0;
- block->bounds_offset[1] = 0;
- block->bounds_type = UI_BLOCK_BOUNDS_PIE_CENTER;
+ block->minbounds = minwidth;
+ block->bounds = 1;
+ block->bounds_offset[0] = 0;
+ block->bounds_offset[1] = 0;
+ block->bounds_type = UI_BLOCK_BOUNDS_PIE_CENTER;
- block->pie_data.pie_center_spawned[0] = pie->mx;
- block->pie_data.pie_center_spawned[1] = pie->my;
+ block->pie_data.pie_center_spawned[0] = pie->mx;
+ block->pie_data.pie_center_spawned[1] = pie->my;
- return pie->block_radial;
+ return pie->block_radial;
}
static float ui_pie_menu_title_width(const char *name, int icon)
{
- const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
- return (UI_fontstyle_string_width(fstyle, name) +
- (UI_UNIT_X * (1.50f + (icon ? 0.25f : 0.0f))));
+ const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
+ return (UI_fontstyle_string_width(fstyle, name) + (UI_UNIT_X * (1.50f + (icon ? 0.25f : 0.0f))));
}
uiPieMenu *UI_pie_menu_begin(struct bContext *C, const char *title, int icon, const wmEvent *event)
{
- uiStyle *style;
- uiPieMenu *pie;
- short event_type;
-
- wmWindow *win = CTX_wm_window(C);
-
- style = UI_style_get_dpi();
- pie = MEM_callocN(sizeof(*pie), "pie menu");
-
- pie->block_radial = UI_block_begin(C, NULL, __func__, UI_EMBOSS);
- /* may be useful later to allow spawning pies
- * from old positions */
- /* pie->block_radial->flag |= UI_BLOCK_POPUP_MEMORY; */
- pie->block_radial->puphash = ui_popup_menu_hash(title);
- pie->block_radial->flag |= UI_BLOCK_RADIAL;
-
- /* if pie is spawned by a left click, release or click event,
- * it is always assumed to be click style */
- if (event->type == LEFTMOUSE || ELEM(event->val, KM_RELEASE, KM_CLICK)) {
- pie->block_radial->pie_data.flags |= UI_PIE_CLICK_STYLE;
- pie->block_radial->pie_data.event = EVENT_NONE;
- win->lock_pie_event = EVENT_NONE;
- }
- else {
- if (win->last_pie_event != EVENT_NONE) {
- /* original pie key has been released, so don't propagate the event */
- if (win->lock_pie_event == EVENT_NONE) {
- event_type = EVENT_NONE;
- pie->block_radial->pie_data.flags |= UI_PIE_CLICK_STYLE;
- }
- else {
- event_type = win->last_pie_event;
- }
- }
- else {
- event_type = event->type;
- }
-
- pie->block_radial->pie_data.event = event_type;
- win->lock_pie_event = event_type;
- }
-
- pie->layout = UI_block_layout(pie->block_radial, UI_LAYOUT_VERTICAL, UI_LAYOUT_PIEMENU, 0, 0, 200, 0, 0, style);
-
- /* Note event->x/y is where we started dragging in case of KM_CLICK_DRAG. */
- pie->mx = event->x;
- pie->my = event->y;
-
- /* create title button */
- if (title[0]) {
- uiBut *but;
- char titlestr[256];
- int w;
- if (icon) {
- BLI_snprintf(titlestr, sizeof(titlestr), " %s", title);
- w = ui_pie_menu_title_width(titlestr, icon);
- but = uiDefIconTextBut(
- pie->block_radial, UI_BTYPE_LABEL, 0, icon, titlestr, 0, 0, w, UI_UNIT_Y,
- NULL, 0.0, 0.0, 0, 0, "");
- }
- else {
- w = ui_pie_menu_title_width(title, 0);
- but = uiDefBut(
- pie->block_radial, UI_BTYPE_LABEL, 0, title, 0, 0, w, UI_UNIT_Y,
- NULL, 0.0, 0.0, 0, 0, "");
- }
- /* do not align left */
- but->drawflag &= ~UI_BUT_TEXT_LEFT;
- pie->block_radial->pie_data.title = but->str;
- pie->block_radial->pie_data.icon = icon;
- }
-
- return pie;
+ uiStyle *style;
+ uiPieMenu *pie;
+ short event_type;
+
+ wmWindow *win = CTX_wm_window(C);
+
+ style = UI_style_get_dpi();
+ pie = MEM_callocN(sizeof(*pie), "pie menu");
+
+ pie->block_radial = UI_block_begin(C, NULL, __func__, UI_EMBOSS);
+ /* may be useful later to allow spawning pies
+ * from old positions */
+ /* pie->block_radial->flag |= UI_BLOCK_POPUP_MEMORY; */
+ pie->block_radial->puphash = ui_popup_menu_hash(title);
+ pie->block_radial->flag |= UI_BLOCK_RADIAL;
+
+ /* if pie is spawned by a left click, release or click event,
+ * it is always assumed to be click style */
+ if (event->type == LEFTMOUSE || ELEM(event->val, KM_RELEASE, KM_CLICK)) {
+ pie->block_radial->pie_data.flags |= UI_PIE_CLICK_STYLE;
+ pie->block_radial->pie_data.event = EVENT_NONE;
+ win->lock_pie_event = EVENT_NONE;
+ }
+ else {
+ if (win->last_pie_event != EVENT_NONE) {
+ /* original pie key has been released, so don't propagate the event */
+ if (win->lock_pie_event == EVENT_NONE) {
+ event_type = EVENT_NONE;
+ pie->block_radial->pie_data.flags |= UI_PIE_CLICK_STYLE;
+ }
+ else {
+ event_type = win->last_pie_event;
+ }
+ }
+ else {
+ event_type = event->type;
+ }
+
+ pie->block_radial->pie_data.event = event_type;
+ win->lock_pie_event = event_type;
+ }
+
+ pie->layout = UI_block_layout(
+ pie->block_radial, UI_LAYOUT_VERTICAL, UI_LAYOUT_PIEMENU, 0, 0, 200, 0, 0, style);
+
+ /* Note event->x/y is where we started dragging in case of KM_CLICK_DRAG. */
+ pie->mx = event->x;
+ pie->my = event->y;
+
+ /* create title button */
+ if (title[0]) {
+ uiBut *but;
+ char titlestr[256];
+ int w;
+ if (icon) {
+ BLI_snprintf(titlestr, sizeof(titlestr), " %s", title);
+ w = ui_pie_menu_title_width(titlestr, icon);
+ but = uiDefIconTextBut(pie->block_radial,
+ UI_BTYPE_LABEL,
+ 0,
+ icon,
+ titlestr,
+ 0,
+ 0,
+ w,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ "");
+ }
+ else {
+ w = ui_pie_menu_title_width(title, 0);
+ but = uiDefBut(pie->block_radial,
+ UI_BTYPE_LABEL,
+ 0,
+ title,
+ 0,
+ 0,
+ w,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ "");
+ }
+ /* do not align left */
+ but->drawflag &= ~UI_BUT_TEXT_LEFT;
+ pie->block_radial->pie_data.title = but->str;
+ pie->block_radial->pie_data.icon = icon;
+ }
+
+ return pie;
}
void UI_pie_menu_end(bContext *C, uiPieMenu *pie)
{
- wmWindow *window = CTX_wm_window(C);
- uiPopupBlockHandle *menu;
+ wmWindow *window = CTX_wm_window(C);
+ uiPopupBlockHandle *menu;
- menu = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_PIE, pie);
- menu->popup = true;
- menu->towardstime = PIL_check_seconds_timer();
+ menu = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_PIE, pie);
+ menu->popup = true;
+ menu->towardstime = PIL_check_seconds_timer();
- UI_popup_handlers_add(
- C, &window->modalhandlers,
- menu, WM_HANDLER_ACCEPT_DBL_CLICK);
- WM_event_add_mousemove(C);
+ UI_popup_handlers_add(C, &window->modalhandlers, menu, WM_HANDLER_ACCEPT_DBL_CLICK);
+ WM_event_add_mousemove(C);
- MEM_freeN(pie);
+ MEM_freeN(pie);
}
uiLayout *UI_pie_menu_layout(uiPieMenu *pie)
{
- return pie->layout;
+ return pie->layout;
}
int UI_pie_menu_invoke(struct bContext *C, const char *idname, const wmEvent *event)
{
- uiPieMenu *pie;
- uiLayout *layout;
- MenuType *mt = WM_menutype_find(idname, true);
+ uiPieMenu *pie;
+ uiLayout *layout;
+ MenuType *mt = WM_menutype_find(idname, true);
- if (mt == NULL) {
- printf("%s: named menu \"%s\" not found\n", __func__, idname);
- return OPERATOR_CANCELLED;
- }
+ if (mt == NULL) {
+ printf("%s: named menu \"%s\" not found\n", __func__, idname);
+ return OPERATOR_CANCELLED;
+ }
- if (WM_menutype_poll(C, mt) == false) {
- /* cancel but allow event to pass through, just like operators do */
- return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
- }
+ if (WM_menutype_poll(C, mt) == false) {
+ /* cancel but allow event to pass through, just like operators do */
+ return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
+ }
- pie = UI_pie_menu_begin(C, IFACE_(mt->label), ICON_NONE, event);
- layout = UI_pie_menu_layout(pie);
+ pie = UI_pie_menu_begin(C, IFACE_(mt->label), ICON_NONE, event);
+ layout = UI_pie_menu_layout(pie);
- UI_menutype_draw(C, mt, layout);
+ UI_menutype_draw(C, mt, layout);
- UI_pie_menu_end(C, pie);
+ UI_pie_menu_end(C, pie);
- return OPERATOR_INTERFACE;
+ return OPERATOR_INTERFACE;
}
-int UI_pie_menu_invoke_from_operator_enum(
- struct bContext *C, const char *title, const char *opname,
- const char *propname, const wmEvent *event)
+int UI_pie_menu_invoke_from_operator_enum(struct bContext *C,
+ const char *title,
+ const char *opname,
+ const char *propname,
+ const wmEvent *event)
{
- uiPieMenu *pie;
- uiLayout *layout;
+ uiPieMenu *pie;
+ uiLayout *layout;
- pie = UI_pie_menu_begin(C, IFACE_(title), ICON_NONE, event);
- layout = UI_pie_menu_layout(pie);
+ pie = UI_pie_menu_begin(C, IFACE_(title), ICON_NONE, event);
+ layout = UI_pie_menu_layout(pie);
- layout = uiLayoutRadial(layout);
- uiItemsEnumO(layout, opname, propname);
+ layout = uiLayoutRadial(layout);
+ uiItemsEnumO(layout, opname, propname);
- UI_pie_menu_end(C, pie);
+ UI_pie_menu_end(C, pie);
- return OPERATOR_INTERFACE;
+ return OPERATOR_INTERFACE;
}
-int UI_pie_menu_invoke_from_rna_enum(
- struct bContext *C, const char *title, const char *path,
- const wmEvent *event)
+int UI_pie_menu_invoke_from_rna_enum(struct bContext *C,
+ const char *title,
+ const char *path,
+ const wmEvent *event)
{
- PointerRNA ctx_ptr;
- PointerRNA r_ptr;
- PropertyRNA *r_prop;
- uiPieMenu *pie;
- uiLayout *layout;
+ PointerRNA ctx_ptr;
+ PointerRNA r_ptr;
+ PropertyRNA *r_prop;
+ uiPieMenu *pie;
+ uiLayout *layout;
- RNA_pointer_create(NULL, &RNA_Context, C, &ctx_ptr);
+ RNA_pointer_create(NULL, &RNA_Context, C, &ctx_ptr);
- if (!RNA_path_resolve(&ctx_ptr, path, &r_ptr, &r_prop)) {
- return OPERATOR_CANCELLED;
- }
+ if (!RNA_path_resolve(&ctx_ptr, path, &r_ptr, &r_prop)) {
+ return OPERATOR_CANCELLED;
+ }
- /* invalid property, only accept enums */
- if (RNA_property_type(r_prop) != PROP_ENUM) {
- BLI_assert(0);
- return OPERATOR_CANCELLED;
- }
+ /* invalid property, only accept enums */
+ if (RNA_property_type(r_prop) != PROP_ENUM) {
+ BLI_assert(0);
+ return OPERATOR_CANCELLED;
+ }
- pie = UI_pie_menu_begin(C, IFACE_(title), ICON_NONE, event);
+ pie = UI_pie_menu_begin(C, IFACE_(title), ICON_NONE, event);
- layout = UI_pie_menu_layout(pie);
+ layout = UI_pie_menu_layout(pie);
- layout = uiLayoutRadial(layout);
- uiItemFullR(layout, &r_ptr, r_prop, RNA_NO_INDEX, 0, UI_ITEM_R_EXPAND, NULL, 0);
+ layout = uiLayoutRadial(layout);
+ uiItemFullR(layout, &r_ptr, r_prop, RNA_NO_INDEX, 0, UI_ITEM_R_EXPAND, NULL, 0);
- UI_pie_menu_end(C, pie);
+ UI_pie_menu_end(C, pie);
- return OPERATOR_INTERFACE;
+ return OPERATOR_INTERFACE;
}
/** \} */
@@ -298,15 +322,15 @@ int UI_pie_menu_invoke_from_rna_enum(
* \{ */
typedef struct PieMenuLevelData {
- char title[UI_MAX_NAME_STR]; /* parent pie title, copied for level */
- int icon; /* parent pie icon, copied for level */
- int totitem; /* total count of *remaining* items */
-
- /* needed for calling uiItemsFullEnumO_array again for new level */
- wmOperatorType *ot;
- const char *propname;
- IDProperty *properties;
- int context, flag;
+ char title[UI_MAX_NAME_STR]; /* parent pie title, copied for level */
+ int icon; /* parent pie icon, copied for level */
+ int totitem; /* total count of *remaining* items */
+
+ /* needed for calling uiItemsFullEnumO_array again for new level */
+ wmOperatorType *ot;
+ const char *propname;
+ IDProperty *properties;
+ int context, flag;
} PieMenuLevelData;
/**
@@ -314,66 +338,90 @@ typedef struct PieMenuLevelData {
*/
static void ui_pie_menu_level_invoke(bContext *C, void *argN, void *arg2)
{
- EnumPropertyItem *item_array = (EnumPropertyItem *)argN;
- PieMenuLevelData *lvl = (PieMenuLevelData *)arg2;
- wmWindow *win = CTX_wm_window(C);
-
- uiPieMenu *pie = UI_pie_menu_begin(C, IFACE_(lvl->title), lvl->icon, win->eventstate);
- uiLayout *layout = UI_pie_menu_layout(pie);
-
- layout = uiLayoutRadial(layout);
-
- PointerRNA ptr;
-
- WM_operator_properties_create_ptr(&ptr, lvl->ot);
- /* so the context is passed to itemf functions (some need it) */
- WM_operator_properties_sanitize(&ptr, false);
- PropertyRNA *prop = RNA_struct_find_property(&ptr, lvl->propname);
-
- if (prop) {
- uiItemsFullEnumO_items(
- layout, lvl->ot, ptr, prop, lvl->properties, lvl->context, lvl->flag,
- item_array, lvl->totitem);
- }
- else {
- RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), lvl->propname);
- }
-
- UI_pie_menu_end(C, pie);
+ EnumPropertyItem *item_array = (EnumPropertyItem *)argN;
+ PieMenuLevelData *lvl = (PieMenuLevelData *)arg2;
+ wmWindow *win = CTX_wm_window(C);
+
+ uiPieMenu *pie = UI_pie_menu_begin(C, IFACE_(lvl->title), lvl->icon, win->eventstate);
+ uiLayout *layout = UI_pie_menu_layout(pie);
+
+ layout = uiLayoutRadial(layout);
+
+ PointerRNA ptr;
+
+ WM_operator_properties_create_ptr(&ptr, lvl->ot);
+ /* so the context is passed to itemf functions (some need it) */
+ WM_operator_properties_sanitize(&ptr, false);
+ PropertyRNA *prop = RNA_struct_find_property(&ptr, lvl->propname);
+
+ if (prop) {
+ uiItemsFullEnumO_items(layout,
+ lvl->ot,
+ ptr,
+ prop,
+ lvl->properties,
+ lvl->context,
+ lvl->flag,
+ item_array,
+ lvl->totitem);
+ }
+ else {
+ RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), lvl->propname);
+ }
+
+ UI_pie_menu_end(C, pie);
}
/**
* Set up data for defining a new pie menu level and add button that invokes it.
*/
-void ui_pie_menu_level_create(
- uiBlock *block, wmOperatorType *ot, const char *propname, IDProperty *properties,
- const EnumPropertyItem *items, int totitem, int context, int flag)
+void ui_pie_menu_level_create(uiBlock *block,
+ wmOperatorType *ot,
+ const char *propname,
+ IDProperty *properties,
+ const EnumPropertyItem *items,
+ int totitem,
+ int context,
+ int flag)
{
- const int totitem_parent = PIE_MAX_ITEMS - 1;
- const int totitem_remain = totitem - totitem_parent;
- size_t array_size = sizeof(EnumPropertyItem) * totitem_remain;
-
- /* used as but->func_argN so freeing is handled elsewhere */
- EnumPropertyItem *remaining = MEM_mallocN(array_size + sizeof(EnumPropertyItem), "pie_level_item_array");
- memcpy(remaining, items + totitem_parent, array_size);
- /* a NULL terminating sentinal element is required */
- memset(&remaining[totitem_remain], 0, sizeof(EnumPropertyItem));
-
-
- /* yuk, static... issue is we can't reliably free this without doing dangerous changes */
- static PieMenuLevelData lvl;
- BLI_strncpy(lvl.title, block->pie_data.title, UI_MAX_NAME_STR);
- lvl.totitem = totitem_remain;
- lvl.ot = ot;
- lvl.propname = propname;
- lvl.properties = properties;
- lvl.context = context;
- lvl.flag = flag;
-
- /* add a 'more' menu entry */
- uiBut *but = uiDefIconTextBut(block, UI_BTYPE_BUT, 0, ICON_PLUS, "More", 0, 0, UI_UNIT_X * 3, UI_UNIT_Y, NULL,
- 0.0f, 0.0f, 0.0f, 0.0f, "Show more items of this menu");
- UI_but_funcN_set(but, ui_pie_menu_level_invoke, remaining, &lvl);
+ const int totitem_parent = PIE_MAX_ITEMS - 1;
+ const int totitem_remain = totitem - totitem_parent;
+ size_t array_size = sizeof(EnumPropertyItem) * totitem_remain;
+
+ /* used as but->func_argN so freeing is handled elsewhere */
+ EnumPropertyItem *remaining = MEM_mallocN(array_size + sizeof(EnumPropertyItem),
+ "pie_level_item_array");
+ memcpy(remaining, items + totitem_parent, array_size);
+ /* a NULL terminating sentinal element is required */
+ memset(&remaining[totitem_remain], 0, sizeof(EnumPropertyItem));
+
+ /* yuk, static... issue is we can't reliably free this without doing dangerous changes */
+ static PieMenuLevelData lvl;
+ BLI_strncpy(lvl.title, block->pie_data.title, UI_MAX_NAME_STR);
+ lvl.totitem = totitem_remain;
+ lvl.ot = ot;
+ lvl.propname = propname;
+ lvl.properties = properties;
+ lvl.context = context;
+ lvl.flag = flag;
+
+ /* add a 'more' menu entry */
+ uiBut *but = uiDefIconTextBut(block,
+ UI_BTYPE_BUT,
+ 0,
+ ICON_PLUS,
+ "More",
+ 0,
+ 0,
+ UI_UNIT_X * 3,
+ UI_UNIT_Y,
+ NULL,
+ 0.0f,
+ 0.0f,
+ 0.0f,
+ 0.0f,
+ "Show more items of this menu");
+ UI_but_funcN_set(but, ui_pie_menu_level_invoke, remaining, &lvl);
}
/** \} */ /* Pie Menu Levels */