[Bf-blender-cvs] [a42fd3de5d8] master: UI: Add 'interface_query.c'

Campbell Barton noreply at git.blender.org
Sat Jun 30 10:50:11 CEST 2018


Commit: a42fd3de5d82deff4b7d9b1f14a58fd95d9d20ff
Author: Campbell Barton
Date:   Sat Jun 30 10:36:40 2018 +0200
Branches: master
https://developer.blender.org/rBa42fd3de5d82deff4b7d9b1f14a58fd95d9d20ff

UI: Add 'interface_query.c'

Interface files are increasingly mixing up too much functionality,
add a file only to handle queries.

More functions can be moved/added here.

===================================================================

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/CMakeLists.txt
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_intern.h
A	source/blender/editors/interface/interface_query.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 6227ea15b71..c87334f4bac 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -379,6 +379,11 @@ typedef void (*uiMenuHandleFunc)(struct bContext *C, void *arg, int event);
  */
 typedef bool (*uiMenuStepFunc)(struct bContext *C, int direction, void *arg1);
 
+
+/* interface_query.c */
+bool UI_block_is_empty(const uiBlock *block);
+
+
 /* interface_region_menu_popup.c */
 /* Popup Menus
  *
@@ -498,8 +503,6 @@ void    UI_block_order_flip(uiBlock *block);
 void    UI_block_flag_enable(uiBlock *block, int flag);
 void    UI_block_flag_disable(uiBlock *block, int flag);
 
-bool    UI_block_is_empty(const uiBlock *block);
-
 int     UI_but_return_value_get(uiBut *but);
 
 void    UI_but_drag_set_id(uiBut *but, struct ID *id);
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 3a05e60bd35..2c984d64266 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -55,6 +55,7 @@ set(SRC
 	interface_layout.c
 	interface_ops.c
 	interface_panel.c
+	interface_query.c
 	interface_region_color_picker.c
 	interface_region_menu_pie.c
 	interface_region_menu_popup.c
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 90fb477480a..645f776db17 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -93,18 +93,6 @@
 
 static void ui_but_free(const bContext *C, uiBut *but);
 
-bool ui_block_is_menu(const uiBlock *block)
-{
-	return (((block->flag & UI_BLOCK_LOOP) != 0) &&
-	        /* non-menu popups use keep-open, so check this is off */
-	        ((block->flag & UI_BLOCK_KEEP_OPEN) == 0));
-}
-
-bool ui_block_is_pie_menu(const uiBlock *block)
-{
-	return ((block->flag & UI_BLOCK_RADIAL) != 0);
-}
-
 static bool ui_but_is_unit_radians_ex(UnitSettings *unit, const int unit_type)
 {
 	return (unit->system_rotation == USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION);
@@ -4007,16 +3995,6 @@ int UI_blocklist_min_y_get(ListBase *lb)
 	return min;
 }
 
-bool UI_block_is_empty(const uiBlock *block)
-{
-	for (const uiBut *but = block->buttons.first; but; but = but->next) {
-		if (!ELEM(but->type, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE)) {
-			return false;
-		}
-	}
-	return true;
-}
-
 void UI_block_direction_set(uiBlock *block, char direction)
 {
 	block->direction = direction;
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index d8771ebf93f..7d059137a00 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -471,36 +471,6 @@ void ui_pan_to_scroll(const wmEvent *event, int *type, int *val)
 	}
 }
 
-bool ui_but_is_editable(const uiBut *but)
-{
-	return !ELEM(but->type,
-	             UI_BTYPE_LABEL, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE,
-	             UI_BTYPE_ROUNDBOX, UI_BTYPE_LISTBOX, UI_BTYPE_PROGRESS_BAR);
-}
-
-bool ui_but_is_editable_as_text(const uiBut *but)
-{
-	return  ELEM(but->type,
-	             UI_BTYPE_TEXT, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER,
-	             UI_BTYPE_SEARCH_MENU);
-
-}
-
-bool ui_but_is_toggle(const uiBut *but)
-{
-	return ELEM(
-	        but->type,
-	        UI_BTYPE_BUT_TOGGLE,
-	        UI_BTYPE_TOGGLE,
-	        UI_BTYPE_ICON_TOGGLE,
-	        UI_BTYPE_ICON_TOGGLE_N,
-	        UI_BTYPE_TOGGLE_N,
-	        UI_BTYPE_CHECKBOX,
-	        UI_BTYPE_CHECKBOX_N,
-	        UI_BTYPE_ROW
-	);
-}
-
 static uiBut *ui_but_prev(uiBut *but)
 {
 	while (but->prev) {
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 7cec8c43d69..cc86530871d 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -453,8 +453,6 @@ extern void ui_linkline_remove(uiLinkLine *line, uiBut *but);
 
 void ui_fontscale(short *points, float aspect);
 
-extern bool ui_block_is_menu(const uiBlock *block) ATTR_WARN_UNUSED_RESULT;
-extern bool ui_block_is_pie_menu(const uiBlock *block) ATTR_WARN_UNUSED_RESULT;
 extern void ui_block_to_window_fl(const struct ARegion *ar, uiBlock *block, float *x, float *y);
 extern void ui_block_to_window(const struct ARegion *ar, uiBlock *block, int *x, int *y);
 extern void ui_block_to_window_rctf(const struct ARegion *ar, uiBlock *block, rctf *rct_dst, const rctf *rct_src);
@@ -677,9 +675,6 @@ extern void ui_but_text_password_hide(char password_str[UI_MAX_DRAW_STR], uiBut
 extern uiBut *ui_but_find_select_in_enum(uiBut *but, int direction);
 extern uiBut *ui_but_find_active_in_region(struct ARegion *ar);
 extern uiBut *ui_but_find_mouse_over(struct ARegion *ar, const struct wmEvent *event);
-bool ui_but_is_editable(const uiBut *but);
-bool ui_but_is_editable_as_text(const uiBut *but);
-bool ui_but_is_toggle(const uiBut *but);
 void ui_but_pie_dir_visual(RadialDirection dir, float vec[2]);
 void ui_but_pie_dir(RadialDirection dir, float vec[2]);
 float ui_block_calc_pie_segment(struct uiBlock *block, const float event_xy[2]);
@@ -699,8 +694,8 @@ void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y
 void ui_draw_anti_roundbox(int mode, float minx, float miny, float maxx, float maxy, float rad, bool use_alpha);
 void ui_draw_menu_back(struct uiStyle *style, uiBlock *block, rcti *rect);
 void ui_draw_pie_center(uiBlock *block);
-uiWidgetColors *ui_tooltip_get_theme(void);
-void ui_draw_tooltip_background(uiStyle *UNUSED(style), uiBlock *block, rcti *rect);
+struct uiWidgetColors *ui_tooltip_get_theme(void);
+void ui_draw_tooltip_background(struct uiStyle *UNUSED(style), uiBlock *block, rcti *rect);
 void ui_draw_search_back(struct uiStyle *style, uiBlock *block, rcti *rect);
 bool ui_link_bezier_points(const rcti *rect, float coord_array[][2], int resol);
 void ui_draw_link_bezier(const rcti *rect);
@@ -750,6 +745,14 @@ bool ui_but_anim_expression_set(uiBut *but, const char *str);
 bool ui_but_anim_expression_create(uiBut *but, const char *str);
 void ui_but_anim_autokey(struct bContext *C, uiBut *but, struct Scene *scene, float cfra);
 
+/* interface_query.c */
+bool ui_but_is_editable(const uiBut *but);
+bool ui_but_is_editable_as_text(const uiBut *but);
+bool ui_but_is_toggle(const uiBut *but);
+
+extern bool ui_block_is_menu(const uiBlock *block) ATTR_WARN_UNUSED_RESULT;
+extern bool ui_block_is_pie_menu(const uiBlock *block) ATTR_WARN_UNUSED_RESULT;
+
 /* interface_context_menu.c */
 bool ui_popup_context_menu_for_button(struct bContext *C, uiBut *but);
 void ui_popup_context_menu_for_panel(struct bContext *C, struct ARegion *ar, struct Panel *pa);
diff --git a/source/blender/editors/interface/interface_query.c b/source/blender/editors/interface/interface_query.c
new file mode 100644
index 00000000000..5d6d03ece60
--- /dev/null
+++ b/source/blender/editors/interface/interface_query.c
@@ -0,0 +1,97 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/interface/interface_query.c
+ *  \ingroup edinterface
+ *
+ * Utilities to inspect the interface, extract information.
+ */
+
+#include "BLI_utildefines.h"
+
+#include "DNA_screen_types.h"
+
+#include "UI_interface.h"
+
+#include "interface_intern.h"
+
+/* -------------------------------------------------------------------- */
+/** \name Button (uiBut)
+ * \{ */
+
+bool ui_but_is_editable(const uiBut *but)
+{
+	return !ELEM(but->type,
+	             UI_BTYPE_LABEL, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE,
+	             UI_BTYPE_ROUNDBOX, UI_BTYPE_LISTBOX, UI_BTYPE_PROGRESS_BAR);
+}
+
+bool ui_but_is_editable_as_text(const uiBut *but)
+{
+	return  ELEM(but->type,
+	             UI_BTYPE_TEXT, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER,
+	             UI_BTYPE_SEARCH_MENU);
+
+}
+
+bool ui_but_is_toggle(const uiBut *but)
+{
+	return ELEM(
+	        but->type,
+	        UI_BTYPE_BUT_TOGGLE,
+	        UI_BTYPE_TOGGLE,
+	        UI_BTYPE_ICON_TOGGLE,
+	        UI_BTYPE_ICON_TOGGLE_N,
+	        UI_BTYPE_TOGGLE_N,
+	        UI_BTYPE_CHECKBOX,
+	        UI_BTYPE_CHECKBOX_N,
+	        UI_BTYPE_ROW
+	);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Block (uiBlock)
+ * \{ */
+
+bool ui_block_is_menu(const uiBlock *block)
+{
+	return (((block->flag & UI_BLOCK_LOOP) != 0) &&
+	        /* non-menu popups use keep-open, so check this is off */
+	        ((block->flag & UI_BLOCK_KEEP_OPEN) == 0));
+}
+
+bool ui_block_is_pie_menu(const uiBlock *block)
+{
+	return ((block->flag & UI_BLOCK_RADIAL) != 0);
+}
+
+bool UI_block_is_empty(const uiBlock *block)
+{
+	for (const uiBut *but = block->buttons.first; but; but = but->next) {
+		if (!ELEM(but->type, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE)) {
+			return false;
+		}
+	}
+	return true;
+}
+
+/** \} */



More information about the Bf-blender-cvs mailing list