[Bf-blender-cvs] [420cc7c2b50] asset-engine: Merge branch 'id_override_static' into asset-engine

Bastien Montagne noreply at git.blender.org
Mon Nov 6 17:01:35 CET 2017


Commit: 420cc7c2b5069f545c31adf312b07d7e9389bc91
Author: Bastien Montagne
Date:   Mon Nov 6 17:01:25 2017 +0100
Branches: asset-engine
https://developer.blender.org/rB420cc7c2b5069f545c31adf312b07d7e9389bc91

Merge branch 'id_override_static' into asset-engine

 Conflicts:
	source/blender/editors/interface/interface_regions.c

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



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

diff --cc source/blender/editors/interface/interface_region_tooltip.c
index 00000000000,ace1afb79aa..5ecd9de5335
mode 000000,100644..100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@@ -1,0 -1,756 +1,761 @@@
+ /*
+  * ***** 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.
+  *
+  * The Original Code is Copyright (C) 2008 Blender Foundation.
+  * All rights reserved.
+  *
+  * Contributor(s): Blender Foundation
+  *
+  * ***** END GPL LICENSE BLOCK *****
+  */
+ 
+ /** \file blender/editors/interface/interface_region_tooltip.c
+  *  \ingroup edinterface
+  *
+  * ToolTip Region and Construction
+  */
+ 
+ #include <stdarg.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <assert.h>
+ 
+ #include "MEM_guardedalloc.h"
+ 
+ #include "DNA_userdef_types.h"
+ 
+ #include "BLI_math.h"
+ #include "BLI_string.h"
+ #include "BLI_string_utf8.h"
+ #include "BLI_rect.h"
+ #include "BLI_utildefines.h"
+ 
+ #include "BKE_context.h"
+ #include "BKE_screen.h"
+ 
+ #include "WM_api.h"
+ #include "WM_types.h"
+ 
+ #include "RNA_access.h"
+ 
+ #include "BIF_gl.h"
+ 
+ #include "UI_interface.h"
+ 
+ #include "BLF_api.h"
+ #include "BLT_translation.h"
+ 
+ #include "ED_screen.h"
+ 
+ #include "interface_intern.h"
+ #include "interface_regions_intern.h"
+ 
+ #define UI_TIP_PAD_FAC      1.3f
+ #define UI_TIP_PADDING      (int)(UI_TIP_PAD_FAC * UI_UNIT_Y)
+ #define UI_TIP_MAXWIDTH     600
+ 
+ 
+ typedef struct uiTooltipFormat {
+ 	enum {
+ 		UI_TIP_STYLE_NORMAL = 0,
+ 		UI_TIP_STYLE_HEADER,
+ 		UI_TIP_STYLE_MONO,
+ 	} style : 3;
+ 	enum {
+ 		UI_TIP_LC_MAIN = 0,     /* primary text */
+ 		UI_TIP_LC_VALUE,        /* the value of buttons (also shortcuts) */
+ 		UI_TIP_LC_ACTIVE,       /* titles of active enum values */
+ 		UI_TIP_LC_NORMAL,       /* regular text */
+ 		UI_TIP_LC_PYTHON,       /* Python snippet */
+ 		UI_TIP_LC_ALERT,        /* description of why operator can't run */
+ 	} color_id : 4;
+ 	int is_pad : 1;
+ } uiTooltipFormat;
+ 
+ typedef struct uiTooltipField {
+ 	char *text;
+ 	char *text_suffix;
+ 	struct {
+ 		uint x_pos;     /* x cursor position at the end of the last line */
+ 		uint lines;     /* number of lines, 1 or more with word-wrap */
+ 	} geom;
+ 	uiTooltipFormat format;
+ 
+ } uiTooltipField;
+ 
+ #define MAX_TOOLTIP_LINES 8
+ typedef struct uiTooltipData {
+ 	rcti bbox;
+ 	uiTooltipField *fields;
+ 	uint            fields_len;
+ 	uiFontStyle fstyle;
+ 	int wrap_width;
+ 	int toth, lineh;
+ } uiTooltipData;
+ 
+ #define UI_TIP_LC_MAX 6
+ 
+ BLI_STATIC_ASSERT(UI_TIP_LC_MAX == UI_TIP_LC_ALERT + 1, "invalid lc-max");
+ BLI_STATIC_ASSERT(sizeof(uiTooltipFormat) <= sizeof(int), "oversize");
+ 
+ static uiTooltipField *text_field_add_only(
+         uiTooltipData *data)
+ {
+ 	data->fields_len += 1;
+ 	data->fields = MEM_recallocN(data->fields, sizeof(*data->fields) * data->fields_len);
+ 	return &data->fields[data->fields_len - 1];
+ }
+ 
+ static uiTooltipField *text_field_add(
+         uiTooltipData *data,
+         const uiTooltipFormat *format)
+ {
+ 	uiTooltipField *field = text_field_add_only(data);
+ 	field->format = *format;
+ 	return field;
+ }
+ 
+ /* -------------------------------------------------------------------- */
+ /** \name ToolTip Callbacks (Draw & Free)
+  * \{ */
+ 
+ static void rgb_tint(
+         float col[3],
+         float h, float h_strength,
+         float v, float v_strength)
+ {
+ 	float col_hsv_from[3];
+ 	float col_hsv_to[3];
+ 
+ 	rgb_to_hsv_v(col, col_hsv_from);
+ 
+ 	col_hsv_to[0] = h;
+ 	col_hsv_to[1] = h_strength;
+ 	col_hsv_to[2] = (col_hsv_from[2] * (1.0f - v_strength)) + (v * v_strength);
+ 
+ 	hsv_to_rgb_v(col_hsv_to, col);
+ }
+ 
+ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
+ {
+ 	const float pad_px = UI_TIP_PADDING;
+ 	uiTooltipData *data = ar->regiondata;
+ 	uiWidgetColors *theme = ui_tooltip_get_theme();
+ 	rcti bbox = data->bbox;
+ 	float tip_colors[UI_TIP_LC_MAX][3];
+ 
+ 	float *main_color    = tip_colors[UI_TIP_LC_MAIN]; /* the color from the theme */
+ 	float *value_color   = tip_colors[UI_TIP_LC_VALUE];
+ 	float *active_color  = tip_colors[UI_TIP_LC_ACTIVE];
+ 	float *normal_color  = tip_colors[UI_TIP_LC_NORMAL];
+ 	float *python_color  = tip_colors[UI_TIP_LC_PYTHON];
+ 	float *alert_color   = tip_colors[UI_TIP_LC_ALERT];
+ 
+ 	float background_color[3];
+ 	float tone_bg;
+ 	int i, multisample_enabled;
+ 
+ 	/* disable AA, makes widgets too blurry */
+ 	multisample_enabled = glIsEnabled(GL_MULTISAMPLE);
+ 	if (multisample_enabled)
+ 		glDisable(GL_MULTISAMPLE);
+ 
+ 	wmOrtho2_region_pixelspace(ar);
+ 
+ 	/* draw background */
+ 	ui_draw_tooltip_background(UI_style_get(), NULL, &bbox);
+ 
+ 	/* set background_color */
+ 	rgb_uchar_to_float(background_color, (const unsigned char *)theme->inner);
+ 
+ 	/* calculate normal_color */
+ 	rgb_uchar_to_float(main_color, (const unsigned char *)theme->text);
+ 	copy_v3_v3(active_color, main_color);
+ 	copy_v3_v3(normal_color, main_color);
+ 	copy_v3_v3(python_color, main_color);
+ 	copy_v3_v3(alert_color, main_color);
+ 	copy_v3_v3(value_color, main_color);
+ 
+ 	/* find the brightness difference between background and text colors */
+ 
+ 	tone_bg = rgb_to_grayscale(background_color);
+ 	/* tone_fg = rgb_to_grayscale(main_color); */
+ 
+ 	/* mix the colors */
+ 	rgb_tint(value_color,  0.0f, 0.0f, tone_bg, 0.2f);  /* light gray */
+ 	rgb_tint(active_color, 0.6f, 0.2f, tone_bg, 0.2f);  /* light blue */
+ 	rgb_tint(normal_color, 0.0f, 0.0f, tone_bg, 0.4f);  /* gray       */
+ 	rgb_tint(python_color, 0.0f, 0.0f, tone_bg, 0.5f);  /* dark gray  */
+ 	rgb_tint(alert_color,  0.0f, 0.8f, tone_bg, 0.1f);  /* red        */
+ 
+ 	/* draw text */
+ 	BLF_wordwrap(data->fstyle.uifont_id, data->wrap_width);
+ 	BLF_wordwrap(blf_mono_font, data->wrap_width);
+ 
+ 	bbox.xmin += 0.5f * pad_px;  /* add padding to the text */
+ 	bbox.ymax -= 0.25f * pad_px;
+ 
+ 	for (i = 0; i < data->fields_len; i++) {
+ 		const uiTooltipField *field = &data->fields[i];
+ 		const uiTooltipField *field_next = (i + 1) != data->fields_len ? &data->fields[i + 1] : NULL;
+ 
+ 		bbox.ymin = bbox.ymax - (data->lineh * field->geom.lines);
+ 		if (field->format.style == UI_TIP_STYLE_HEADER) {
+ 			/* draw header and active data (is done here to be able to change color) */
+ 			uiFontStyle fstyle_header = data->fstyle;
+ 
+ 			/* override text-style */
+ 			fstyle_header.shadow = 1;
+ 			fstyle_header.shadowcolor = rgb_to_grayscale(tip_colors[UI_TIP_LC_MAIN]);
+ 			fstyle_header.shadx = fstyle_header.shady = 0;
+ 			fstyle_header.shadowalpha = 1.0f;
+ 			fstyle_header.word_wrap = true;
+ 
+ 			UI_fontstyle_set(&fstyle_header);
+ 			glColor3fv(tip_colors[UI_TIP_LC_MAIN]);
+ 			UI_fontstyle_draw(&fstyle_header, &bbox, field->text);
+ 
+ 			fstyle_header.shadow = 0;
+ 
+ 			/* offset to the end of the last line */
+ 			if (field->text_suffix) {
+ 				float xofs = field->geom.x_pos;
+ 				float yofs = data->lineh * (field->geom.lines - 1);
+ 				bbox.xmin += xofs;
+ 				bbox.ymax -= yofs;
+ 
+ 				glColor3fv(tip_colors[UI_TIP_LC_ACTIVE]);
+ 				UI_fontstyle_draw(&fstyle_header, &bbox, field->text_suffix);
+ 
+ 				/* undo offset */
+ 				bbox.xmin -= xofs;
+ 				bbox.ymax += yofs;
+ 			}
+ 		}
+ 		else if (field->format.style == UI_TIP_STYLE_MONO) {
+ 			uiFontStyle fstyle_mono = data->fstyle;
+ 			fstyle_mono.uifont_id = blf_mono_font;
+ 			fstyle_mono.word_wrap = true;
+ 
+ 			UI_fontstyle_set(&fstyle_mono);
+ 			/* XXX, needed because we dont have mono in 'U.uifonts' */
+ 			BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi);
+ 			glColor3fv(tip_colors[field->format.color_id]);
+ 			UI_fontstyle_draw(&fstyle_mono, &bbox, field->text);
+ 		}
+ 		else {
+ 			uiFontStyle fstyle_normal = data->fstyle;
+ 			BLI_assert(field->format.style == UI_TIP_STYLE_NORMAL);
+ 			fstyle_normal.word_wrap = true;
+ 
+ 			/* draw remaining data */
+ 			UI_fontstyle_set(&fstyle_normal);
+ 			glColor3fv(tip_colors[field->format.color_id]);
+ 			UI_fontstyle_draw(&fstyle_normal, &bbox, field->text);
+ 		}
+ 
+ 		bbox.ymax -= data->lineh * field->geom.lines;
+ 
+ 		if (field_next && field_next->format.is_pad) {
+ 			bbox.ymax -= data->lineh * (UI_TIP_PAD_FAC - 1);
+ 		}
+ 	}
+ 
+ 	BLF_disable(data->fstyle.uifont_id, BLF_WORD_WRAP);
+ 	BLF_disable(blf_mono_font, BLF_WORD_WRAP);
+ 
+ 	if (multisample_enabled)
+ 		glEnable(GL_MULTISAMPLE);
+ }
+ 
+ static void ui_tooltip_region_free_cb(ARegion *ar)
+ {
+ 	uiTooltipData *data;
+ 
+ 	data = ar->regiondata;
+ 
+ 	for (int  i = 0; i < data->fields_len; i++) {
+ 		const uiTooltipField *field = &data->fields[i];
+ 		MEM_freeN(field->text);
+ 		if (field->text_suffix) {
+ 			MEM_freeN(field->text_suffix);
+ 		}
+ 	}
+ 	MEM_freeN(data->fields);
+ 	MEM_freeN(data);
+ 	ar->regiondata = NULL;
+ }
+ 
+ /** \} */
+ 
+ /* -------------------------------------------------------------------- */
+ /** \name ToolTip Creation
+  * \{ */
+ 
+ static uiTooltipData *ui_tooltip_data_from_button(bContext *C, uiBut *but)
+ {
+ 	uiStringInfo but_tip = {BUT_GET_TIP, NULL};
+ 	uiStringInfo enum_label = {BUT_GET_RNAENUM_LABEL, NULL};
+ 	uiStringInfo enum_tip = {BUT_GET_RNAENUM_TIP, NULL};
+ 	uiStringInfo op_keymap = {BUT_GET_OP_KEYMAP, NULL};
+ 	uiStringInfo prop_keymap = {BUT_GET_PROP_KEYMAP, NULL};
+ 	uiStringInfo rna_struct = {BUT_GET_RNASTRUCT_IDENTIFIER, NULL};
+ 	uiStringInfo rna_prop = {BUT_GET_RNAPROP_IDENTIFIER, NULL};
+ 
+ 	ch

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list