[Bf-blender-cvs] [56c6bd6] temp-ui-widget-refactor: New widget type for preview menu items

Julian Eisel noreply at git.blender.org
Thu Jul 16 21:56:39 CEST 2015


Commit: 56c6bd646af638a9d0e5fc52f6c0e66117c99f18
Author: Julian Eisel
Date:   Thu Jul 16 21:44:42 2015 +0200
Branches: temp-ui-widget-refactor
https://developer.blender.org/rB56c6bd646af638a9d0e5fc52f6c0e66117c99f18

New widget type for preview menu items

Also to avoid special draw calls.

Note: This adds iconid and str args to uiWidgetDrawType->text callback, which is currently only needed for preview menu items (could also be done differently), but in future this might be handy to get rid of uiBut usage on this level.

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

M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/interface/widgets/widgets.h
M	source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c
M	source/blender/editors/interface/widgets/widgets_draw/widgets_draw_intern.h
M	source/blender/editors/interface/widgets/widgets_draw/widgets_draw_text.c

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

diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index adeb7cf..6a8d627 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -88,6 +88,7 @@ typedef enum {
 	UI_WTYPE_PULLDOWN,
 	UI_WTYPE_MENU_LABEL,
 	UI_WTYPE_MENU_ITEM,
+	UI_WTYPE_MENU_ITEM_PREVIEW,
 	UI_WTYPE_MENU_ITEM_RADIAL,
 	UI_WTYPE_MENU_BACK,
 
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index fe9f2e3..e616949 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1301,7 +1301,12 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type)
 			wt.wcol_theme = &btheme->tui.wcol_menu_back;
 			wt.draw_type = draw_style->menu_back;
 			break;
-			
+
+		case UI_WTYPE_MENU_ITEM_PREVIEW:
+			wt.wcol_theme = &btheme->tui.wcol_menu_item;
+			wt.draw_type = draw_style->menu_item_preview;
+			break;
+
 		/* specials */
 		case UI_WTYPE_ICON:
 			wt.draw_type = draw_style->icon;
@@ -1663,7 +1668,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
 
 		if (disabled)
 			glEnable(GL_BLEND);
-		wt->draw_type->text(fstyle, &wt->wcol, but, rect);
+		wt->draw_type->text(fstyle, &wt->wcol, but, rect, but->drawstr, but->icon);
 
 		if (disabled)
 			glDisable(GL_BLEND);
@@ -1931,45 +1936,12 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic
 	}
 }
 
-#define PREVIEW_PAD 4
-
 void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state)
 {
-	rcti trect = *rect;
-	const float text_size = UI_UNIT_Y;
-	float font_dims[2] = {0.0f, 0.0f};
-	uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM);
-	
+	uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM_PREVIEW);
+
 	/* drawing button background */
 	wt->draw_type->state(wt, state);
 	wt->draw_type->draw(&wt->wcol, rect, 0, 0);
-	
-	/* draw icon in rect above the space reserved for the label */
-	rect->ymin += text_size;
-	glEnable(GL_BLEND);
-	widget_draw_preview(iconid, 1.0f, rect);
-	glDisable(GL_BLEND);
-	
-	BLF_width_and_height(fstyle->uifont_id, name, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]);
-
-	/* text rect */
-	trect.xmin += 0;
-	trect.xmax = trect.xmin + font_dims[0] + U.widget_unit / 2;
-	trect.ymin += U.widget_unit / 2;
-	trect.ymax = trect.ymin + font_dims[1];
-	if (trect.xmax > rect->xmax - PREVIEW_PAD)
-		trect.xmax = rect->xmax - PREVIEW_PAD;
-
-	{
-		char drawstr[UI_MAX_DRAW_STR];
-		const float okwidth = (float)BLI_rcti_size_x(&trect);
-		const size_t max_len = sizeof(drawstr);
-		const float minwidth = (float)(UI_DPI_ICON_SIZE);
-
-		BLI_strncpy(drawstr, name, sizeof(drawstr));
-		UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0');
-
-		glColor4ubv((unsigned char *)wt->wcol.text);
-		UI_fontstyle_draw(fstyle, &trect, drawstr);
-	}
+	wt->draw_type->text(fstyle, &wt->wcol, NULL, rect, name, iconid);
 }
diff --git a/source/blender/editors/interface/widgets/widgets.h b/source/blender/editors/interface/widgets/widgets.h
index 3823de4..df2e111 100644
--- a/source/blender/editors/interface/widgets/widgets.h
+++ b/source/blender/editors/interface/widgets/widgets.h
@@ -59,7 +59,7 @@ typedef struct uiWidgetDrawType {
 	/* XXX uiBut and uiFontStyle shouldn't be needed/used at this level,
 	 * the needed data should be transferred using uiWidget API instead */
 	void (*custom)(struct uiBut *, struct uiWidgetColors *, rcti *, int state, int roundboxalign);
-	void (*text)(struct uiFontStyle *, struct uiWidgetColors *, struct uiBut *, rcti *);
+	void (*text)(struct uiFontStyle *, struct uiWidgetColors *, struct uiBut *, rcti *, const char *str, const int iconid);
 } uiWidgetDrawType;
 
 #if 0 /* uiWidgetDrawType init template */
@@ -85,6 +85,7 @@ typedef struct uiWidgetDrawStyle {
 	                 *menu_back,
 	                 *menu_icon_radio,
 	                 *menu_item,
+	                 *menu_item_preview,
 	                 *menu_item_radial,
 	                 *menu_label,
 	                 *menu_node_link,
diff --git a/source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c b/source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c
index c29e397..4a4cba7 100644
--- a/source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c
+++ b/source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c
@@ -26,8 +26,11 @@
 
 #include "BIF_gl.h"
 
+#include "BLF_api.h"
+
 #include "BLI_math.h"
 #include "BLI_rect.h"
+#include "BLI_string.h"
 #include "BLI_utildefines.h"
 
 #include "DNA_screen_types.h"
@@ -634,6 +637,7 @@ static void widget_unitvec(uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNU
 	ui_draw_but_UNITVEC(but, wcol, rect);
 }
 
+
 /* states ************************************* */
 
 static void widget_state_blend(char cp[3], const char cpstate[3], const float fac)
@@ -848,6 +852,12 @@ static void widget_state_numslider(uiWidgetType *wt, int state)
 	}
 }
 
+
+/* text *************************************** */
+
+/* nothing here yet - currently we call widgets_draw_text.c functions directly */
+
+
 /* helper calls *************************************** */
 
 /**
@@ -936,6 +946,13 @@ uiWidgetDrawType drawtype_classic_menu_item = {
 	/* text */   widget_draw_text_icon,
 };
 
+uiWidgetDrawType drawtype_classic_menu_item_preview = {
+	/* state */  widget_state_menu_item,
+	/* draw */   widget_menu_itembut,
+	/* custom */ NULL,
+	/* text */   widget_draw_text_preview_item,
+};
+
 uiWidgetDrawType drawtype_classic_menu_item_radial = {
 	/* state */  widget_state_pie_menu_item,
 	/* draw */   NULL,
@@ -1068,6 +1085,7 @@ uiWidgetDrawStyle WidgetStyle_Classic = {
 	/* menu_back */         &drawtype_classic_menu_back,
 	/* menu_icon_radio */   &drawtype_classic_menu_icon_radio,
 	/* menu_item */         &drawtype_classic_menu_item,
+	/* menu_item_preview */ &drawtype_classic_menu_item_preview,
 	/* menu_item_radial */  &drawtype_classic_menu_item_radial,
 	/* menu_item_label */   &drawtype_classic_menu_label,
 	/* menu_node_link */    &drawtype_classic_menu_node_link,
diff --git a/source/blender/editors/interface/widgets/widgets_draw/widgets_draw_intern.h b/source/blender/editors/interface/widgets/widgets_draw/widgets_draw_intern.h
index 10101a6..67c8c55 100644
--- a/source/blender/editors/interface/widgets/widgets_draw/widgets_draw_intern.h
+++ b/source/blender/editors/interface/widgets/widgets_draw/widgets_draw_intern.h
@@ -29,10 +29,6 @@
  * \brief Blender widget drawing module
  */
 
-#include "UI_resources.h"
-
-
-
 /* Struct Declarations */
 
 struct uiBut;
@@ -81,7 +77,9 @@ typedef struct uiWidgetBase {
 	uiWidgetTrias tria2;
 } uiWidgetBase;
 
+
 /* widgets_draw.c - shared low-level drawing functions */
+
 void widgetbase_init(uiWidgetBase *wtb);
 
 void round_box_edges(uiWidgetBase *wt, int roundboxalign, const rcti *rect, float rad); /* XXX rename to widgetbase_roundboxedges_set */
@@ -100,9 +98,15 @@ void widget_softshadow(const rcti *rect, int roundboxalign, const float radin);
 
 void widgetbase_draw(uiWidgetBase *wtb, struct uiWidgetColors *wcol);
 
-/* TODO temp */
-void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect);
-void widget_draw_preview(BIFIconID icon, float alpha, const rcti *rect);
+
+/* widgets_draw_text.c - shared low-level text formatting/drawing functions */
+
+void widget_draw_text_icon(
+        uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but,
+        rcti *rect, const char *str, const int iconid);
+void widget_draw_text_preview_item(
+        uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *UNUSED(but),
+        rcti *rect, const char *str, const int iconid);
 
 #endif  /* __WIDGETS_DRAW_INTERN_H__ */
 
diff --git a/source/blender/editors/interface/widgets/widgets_draw/widgets_draw_text.c b/source/blender/editors/interface/widgets/widgets_draw/widgets_draw_text.c
index 247b6a4..ba6faf6 100644
--- a/source/blender/editors/interface/widgets/widgets_draw/widgets_draw_text.c
+++ b/source/blender/editors/interface/widgets/widgets_draw/widgets_draw_text.c
@@ -55,9 +55,10 @@
 /* icons are 80% of height of button (16 pixels inside 20 height) */
 #define ICON_SIZE_FROM_BUTRECT(rect) (0.8f * BLI_rcti_size_y(rect))
 
+
 #define PREVIEW_PAD 4
 
-void widget_draw_preview(BIFIconID icon, float alpha, const rcti *rect)
+static void widget_draw_preview(BIFIconID icon, float alpha, const rcti *rect)
 {
 	int w, h, size;
 
@@ -77,6 +78,44 @@ void widget_draw_preview(BIFIconID icon, float alpha, const rcti *rect)
 	}
 }
 
+void widget_draw_text_preview_item(
+        uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *UNUSED(but),
+        rcti *rect, const char *str, const int iconid)
+{
+	rcti trect = *rect;
+	const float text_size = UI_UNIT_Y;
+	float font_dims[2] = {0.0f, 0.0f};
+
+	/* draw icon in rect above the space reserved for the label */
+	rect->ymin += text_size;
+	glEnable(GL_BLEND);
+	widget_draw_preview(iconid, 1.0f, rect);
+	glDisable(GL_BLEND);
+
+	BLF_width_and_height(fstyle->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]);
+
+	/* text rect */
+	trect.xmin += 0;
+	trect.xmax = trect.xmin + font_dims[0] + U.widget_unit / 2;
+	trect.ymin += U.widget_unit / 2;
+	trect.ymax = trect.ymin + font_dims[1];
+	if (trect.xmax > rect->xmax - PREVIEW_PAD)
+		trect.xmax = rect->xmax - PREVIEW_PAD;
+
+	{
+		char drawstr[UI_MAX_DRAW_STR];
+		const float okwidth = (float)BLI_rcti_size_x(&trect);
+		const size_t max_len = sizeof(drawstr);
+		const float minwidth = (float)(UI_DPI_ICON_SIZE);
+
+		BLI_strncpy(drawstr, str, sizeof(drawstr));
+		UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0');
+
+		glColor4ubv((unsigned char *)wcol->text);
+		UI_fontstyle_draw(fstyle, &trect, drawstr);
+	}
+}
+
 
 static int ui_but_draw_menu_icon(const uiBut *but)
 {
@@ -530,10 +569,9 @@ static void widget_draw_text_ime_underline(
 }
 #endif  /* WITH_INPUT_IME */
 
-static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
+static void widget_draw

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list