2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2009 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2009-04-09 18:11:18 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup edinterface
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
2022-04-02 16:17:48 -05:00
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
2009-04-09 18:11:18 +00:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_userdef_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_listbase.h"
|
|
|
|
|
#include "BLI_rect.h"
|
|
|
|
|
#include "BLI_string.h"
|
2011-09-27 19:04:27 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2009-04-09 18:11:18 +00:00
|
|
|
|
2024-02-10 18:25:14 +01:00
|
|
|
#include "BKE_global.hh"
|
2009-04-09 18:11:18 +00:00
|
|
|
|
2024-01-31 14:04:56 -05:00
|
|
|
#include "BLF_api.hh"
|
2022-01-29 17:40:02 -05:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
2009-04-09 18:11:18 +00:00
|
|
|
|
2022-11-26 00:21:17 -06:00
|
|
|
#include "interface_intern.hh"
|
2009-04-09 18:11:18 +00:00
|
|
|
|
2014-05-01 07:21:08 +10:00
|
|
|
#ifdef WIN32
|
|
|
|
|
# include "BLI_math_base.h" /* M_PI */
|
|
|
|
|
#endif
|
2009-04-09 18:11:18 +00:00
|
|
|
|
2024-12-06 14:08:10 +01:00
|
|
|
using blender::StringRef;
|
|
|
|
|
|
2022-12-08 10:49:55 +11:00
|
|
|
static void fontstyle_set_ex(const uiFontStyle *fs, const float dpi_fac);
|
|
|
|
|
|
2009-04-09 18:11:18 +00:00
|
|
|
/* style + theme + layout-engine = UI */
|
|
|
|
|
|
2015-05-31 14:20:03 +10:00
|
|
|
/**
|
2018-05-23 10:47:12 +02:00
|
|
|
* This is a complete set of layout rules, the 'state' of the Layout
|
|
|
|
|
* Engine. Multiple styles are possible, defined via C or Python. Styles
|
|
|
|
|
* get a name, and will typically get activated per region type, like
|
2023-05-24 11:21:18 +10:00
|
|
|
* `Header`, or `Listview` or `Toolbar`. Properties of Style definitions
|
2012-03-03 16:31:46 +00:00
|
|
|
* are:
|
|
|
|
|
*
|
2012-03-04 04:35:12 +00:00
|
|
|
* - default column properties, internal spacing, aligning, min/max width
|
2012-03-03 16:31:46 +00:00
|
|
|
* - button alignment rules (for groups)
|
|
|
|
|
* - label placement rules
|
|
|
|
|
* - internal labeling or external labeling default
|
|
|
|
|
* - default minimum widths for buttons/labels (in amount of characters)
|
|
|
|
|
* - font types, styles and relative sizes for Panel titles, labels, etc.
|
|
|
|
|
*/
|
2009-04-09 18:11:18 +00:00
|
|
|
|
|
|
|
|
/* ********************************************** */
|
|
|
|
|
|
2011-07-22 14:14:28 +00:00
|
|
|
static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id)
|
2009-04-09 18:11:18 +00:00
|
|
|
{
|
2025-03-05 16:35:09 +01:00
|
|
|
uiStyle *style = MEM_callocN<uiStyle>(__func__);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-04-09 18:11:18 +00:00
|
|
|
BLI_addtail(styles, style);
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(style->name, name);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
style->panelzoom = 1.0; /* unused */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
style->paneltitle.uifont_id = uifont_id;
|
2020-10-12 09:53:00 -07:00
|
|
|
style->paneltitle.points = UI_DEFAULT_TITLE_POINTS;
|
2023-10-21 00:28:28 +02:00
|
|
|
style->paneltitle.character_weight = 400;
|
2018-11-03 02:03:42 +01:00
|
|
|
style->paneltitle.shadow = 3;
|
2012-03-30 01:51:25 +00:00
|
|
|
style->paneltitle.shadx = 0;
|
|
|
|
|
style->paneltitle.shady = -1;
|
2018-11-03 02:03:42 +01:00
|
|
|
style->paneltitle.shadowalpha = 0.5f;
|
|
|
|
|
style->paneltitle.shadowcolor = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
style->grouplabel.uifont_id = uifont_id;
|
2020-10-12 09:53:00 -07:00
|
|
|
style->grouplabel.points = UI_DEFAULT_TITLE_POINTS;
|
2023-10-21 00:28:28 +02:00
|
|
|
style->grouplabel.character_weight = 400;
|
2012-03-30 01:51:25 +00:00
|
|
|
style->grouplabel.shadow = 3;
|
|
|
|
|
style->grouplabel.shadx = 0;
|
|
|
|
|
style->grouplabel.shady = -1;
|
2018-11-03 02:03:42 +01:00
|
|
|
style->grouplabel.shadowalpha = 0.5f;
|
|
|
|
|
style->grouplabel.shadowcolor = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
style->widget.uifont_id = uifont_id;
|
2020-10-12 09:53:00 -07:00
|
|
|
style->widget.points = UI_DEFAULT_TEXT_POINTS;
|
2023-10-21 00:28:28 +02:00
|
|
|
style->widget.character_weight = 400;
|
2018-11-03 02:03:42 +01:00
|
|
|
style->widget.shadow = 1;
|
|
|
|
|
style->widget.shady = -1;
|
|
|
|
|
style->widget.shadowalpha = 0.5f;
|
|
|
|
|
style->widget.shadowcolor = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-07-25 19:12:41 +02:00
|
|
|
style->tooltip.uifont_id = uifont_id;
|
|
|
|
|
style->tooltip.points = UI_DEFAULT_TOOLTIP_POINTS;
|
|
|
|
|
style->tooltip.character_weight = 400;
|
|
|
|
|
style->tooltip.shadow = 1;
|
|
|
|
|
style->tooltip.shady = -1;
|
|
|
|
|
style->tooltip.shadowalpha = 0.5f;
|
|
|
|
|
style->tooltip.shadowcolor = 0.0f;
|
|
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
style->columnspace = 8;
|
|
|
|
|
style->templatespace = 5;
|
|
|
|
|
style->boxspace = 5;
|
|
|
|
|
style->buttonspacex = 8;
|
|
|
|
|
style->buttonspacey = 2;
|
|
|
|
|
style->panelspace = 8;
|
|
|
|
|
style->panelouter = 4;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-04-09 18:11:18 +00:00
|
|
|
return style;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uiFont *uifont_to_blfont(int id)
|
|
|
|
|
{
|
2022-04-02 16:17:48 -05:00
|
|
|
uiFont *font = static_cast<uiFont *>(U.uifonts.first);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
for (; font; font = font->next) {
|
|
|
|
|
if (font->uifont_id == id) {
|
2009-04-09 18:11:18 +00:00
|
|
|
return font;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-02 16:17:48 -05:00
|
|
|
return static_cast<uiFont *>(U.uifonts.first);
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* *************** draw ************************ */
|
|
|
|
|
|
2015-01-20 14:25:39 +11:00
|
|
|
void UI_fontstyle_draw_ex(const uiFontStyle *fs,
|
2019-01-04 09:58:03 +11:00
|
|
|
const rcti *rect,
|
|
|
|
|
const char *str,
|
2022-01-12 12:49:36 +01:00
|
|
|
const size_t str_len,
|
2019-01-04 09:58:03 +11:00
|
|
|
const uchar col[4],
|
2023-06-03 08:36:28 +10:00
|
|
|
const uiFontStyleDraw_Params *fs_params,
|
2020-04-14 18:41:23 +10:00
|
|
|
int *r_xofs,
|
2020-04-14 18:46:13 +10:00
|
|
|
int *r_yofs,
|
2023-06-03 08:36:28 +10:00
|
|
|
ResultBLF *r_info)
|
2009-04-09 18:11:18 +00:00
|
|
|
{
|
2012-03-30 01:51:25 +00:00
|
|
|
int xofs = 0, yofs;
|
2015-08-29 02:09:12 +10:00
|
|
|
int font_flag = BLF_CLIPPING;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_fontstyle_set(fs);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-08-29 02:09:12 +10:00
|
|
|
/* set the flag */
|
|
|
|
|
if (fs->shadow) {
|
|
|
|
|
font_flag |= BLF_SHADOW;
|
2016-04-22 20:02:03 +10:00
|
|
|
const float shadow_color[4] = {
|
|
|
|
|
fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha};
|
UI: Improved overlay text contrast with new outline text decoration
Overlay texts were previously drawn with two sets of shadows:
- 3px blur,
- 5px blur, slightly offset
But since the shadow color was always set to black, it was still
causing legibility issues when the text itself was dark (set
via theme for example).
This PR adds a new "outline" BLF text decoration, and uses that
for the overlays. And it picks text/outline color depending
on the "background" color of the view.
Details:
- Instead of "shadow level" integer where the only valid options
are 0, 3 or 5, have a FontShadowType enum.
- Add a new FontShadowType::Outline enum entry, that does a 1px
outline by doing a 3x3 dilation in the font shader.
- BLF_draw_default_shadowed is changed to do outline, instead of
drawing the shadow twice.
- In the font shader, instead of encoding shadow type in signs of
the glyph_size, pass that as a "flags" vertex attribute. Put
font texture channel count into the same flags, so that the
vertex size stays the same.
- Well actually, vertex size becomes smaller by 4 bytes, since turns
out glyph_mode vertex attribute was not used for anything at all.
Images in the PR.
Co-authored-by: Harley Acheson <harley.acheson@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/121383
2024-05-10 21:06:44 +02:00
|
|
|
BLF_shadow(fs->uifont_id, FontShadowType(fs->shadow), shadow_color);
|
2015-08-29 02:09:12 +10:00
|
|
|
BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
|
|
|
|
|
}
|
2019-01-04 09:58:03 +11:00
|
|
|
if (fs_params->word_wrap == 1) {
|
2015-09-18 20:21:25 +10:00
|
|
|
font_flag |= BLF_WORD_WRAP;
|
|
|
|
|
}
|
2020-06-05 15:39:17 -07:00
|
|
|
if (fs->bold) {
|
|
|
|
|
font_flag |= BLF_BOLD;
|
|
|
|
|
}
|
|
|
|
|
if (fs->italic) {
|
|
|
|
|
font_flag |= BLF_ITALIC;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-08-29 02:09:12 +10:00
|
|
|
BLF_enable(fs->uifont_id, font_flag);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-04 09:58:03 +11:00
|
|
|
if (fs_params->word_wrap == 1) {
|
2022-01-06 13:54:52 +11:00
|
|
|
/* Draw from bound-box top. */
|
2015-09-19 14:50:35 +10:00
|
|
|
yofs = BLI_rcti_size_y(rect) - BLF_height_max(fs->uifont_id);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-01-06 13:54:52 +11:00
|
|
|
/* Draw from bound-box center. */
|
2022-04-13 12:45:41 +10:00
|
|
|
const int height = BLF_ascender(fs->uifont_id) + BLF_descender(fs->uifont_id);
|
2018-10-11 12:24:33 +02:00
|
|
|
yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height));
|
2015-09-19 14:50:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-04 09:58:03 +11:00
|
|
|
if (fs_params->align == UI_STYLE_TEXT_CENTER) {
|
2022-01-12 12:49:36 +01:00
|
|
|
xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len)));
|
2011-04-15 01:32:37 +00:00
|
|
|
}
|
2019-01-04 09:58:03 +11:00
|
|
|
else if (fs_params->align == UI_STYLE_TEXT_RIGHT) {
|
2022-01-12 12:49:36 +01:00
|
|
|
xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, str_len);
|
2011-04-15 01:32:37 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-07 16:33:19 +11:00
|
|
|
yofs = std::max(0, yofs);
|
|
|
|
|
xofs = std::max(0, xofs);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-15 15:12:42 +01:00
|
|
|
BLF_clipping(fs->uifont_id, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
|
2012-03-30 01:51:25 +00:00
|
|
|
BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f);
|
2017-02-10 00:00:21 +01:00
|
|
|
BLF_color4ubv(fs->uifont_id, col);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-03-28 04:02:13 +01:00
|
|
|
BLF_draw(fs->uifont_id, str, str_len, r_info);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-08-29 02:09:12 +10:00
|
|
|
BLF_disable(fs->uifont_id, font_flag);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Asset System: New Asset Browser editor
This introduces the User Interface part of the Asset Browser, based on the
design in T54642.
Additions:
* New Asset Browser (internally a sub-editor of the File Browser).
* Navigation region showing asset categories.
* Main region showing the assets of the selected asset library with previews.
The assets may be stored over multiple .blends in the directory that's
"mounted" as asset library in the Preferences. They will all be shown in this
list.
* Header with an asset library dropdown, allowing to choose the active asset
library to show. Options are the "Current File" as asset library and all
custom libraries.
* Display popover, filter popover and search box (partially dummies, see
T82680).
* Sidebar showing the metadata of the currently active file (name, preview,
description and tags), which can be edited for assets in the "Current File"
asset library. (For others it will reset on reload.)
* The sidebar includes a button to load a custom preview image from a file.
* Make asset files draggable (with preview image).
* If a library with invalid path is selected, a message is drawn in the main
region to help the user understand what's wrong.
* Operators to add and remove asset tags. Exposed in the sidebar.
* "Only Assets" option for Link/Append.
* Internal utilities for asset UI scripts.
For screenshots or demo videos, please see D9725. Or the 2.92 release notes.
Note that there are many things to be tweaked and polished in the Asset Browser
UI still. For example, the filter and display popovers are mostly dummies. See
T82680.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9725
Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-14 14:07:42 +01:00
|
|
|
if (r_xofs) {
|
|
|
|
|
*r_xofs = xofs;
|
|
|
|
|
}
|
|
|
|
|
if (r_yofs) {
|
|
|
|
|
*r_yofs = yofs;
|
|
|
|
|
}
|
2010-12-14 02:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-04 09:58:03 +11:00
|
|
|
void UI_fontstyle_draw(const uiFontStyle *fs,
|
|
|
|
|
const rcti *rect,
|
|
|
|
|
const char *str,
|
2022-01-12 12:49:36 +01:00
|
|
|
const size_t str_len,
|
2019-01-04 09:58:03 +11:00
|
|
|
const uchar col[4],
|
2023-06-03 08:36:28 +10:00
|
|
|
const uiFontStyleDraw_Params *fs_params)
|
2010-12-14 02:38:29 +00:00
|
|
|
{
|
2022-04-02 16:17:48 -05:00
|
|
|
UI_fontstyle_draw_ex(fs, rect, str, str_len, col, fs_params, nullptr, nullptr, nullptr);
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:03:26 +02:00
|
|
|
void UI_fontstyle_draw_multiline_clipped_ex(const uiFontStyle *fs,
|
|
|
|
|
const rcti *rect,
|
|
|
|
|
const char *str,
|
|
|
|
|
const uchar col[4],
|
|
|
|
|
const eFontStyle_Align align,
|
|
|
|
|
int *r_xofs,
|
|
|
|
|
int *r_yofs,
|
|
|
|
|
ResultBLF *r_info)
|
|
|
|
|
{
|
|
|
|
|
int xofs = 0, yofs;
|
|
|
|
|
int font_flag = BLF_CLIPPING;
|
|
|
|
|
|
|
|
|
|
/* Recommended for testing: Results should be the same with or without BLF clipping since the
|
|
|
|
|
* string is wrapped and shortened to fit. Disabling it can help spot issues. */
|
|
|
|
|
// font_flag &= ~BLF_CLIPPING;
|
|
|
|
|
|
|
|
|
|
UI_fontstyle_set(fs);
|
|
|
|
|
|
|
|
|
|
/* set the flag */
|
|
|
|
|
if (fs->shadow) {
|
|
|
|
|
font_flag |= BLF_SHADOW;
|
|
|
|
|
const float shadow_color[4] = {
|
|
|
|
|
fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha};
|
|
|
|
|
BLF_shadow(fs->uifont_id, FontShadowType(fs->shadow), shadow_color);
|
|
|
|
|
BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
|
|
|
|
|
}
|
|
|
|
|
if (fs->bold) {
|
|
|
|
|
font_flag |= BLF_BOLD;
|
|
|
|
|
}
|
|
|
|
|
if (fs->italic) {
|
|
|
|
|
font_flag |= BLF_ITALIC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLF_enable(fs->uifont_id, font_flag);
|
|
|
|
|
|
|
|
|
|
const int max_width = BLI_rcti_size_x(rect);
|
|
|
|
|
const int max_height = BLI_rcti_size_y(rect);
|
|
|
|
|
const int line_height = BLF_height_max(fs->uifont_id);
|
|
|
|
|
const int max_line_count = max_height / line_height;
|
|
|
|
|
|
|
|
|
|
BLF_clipping(fs->uifont_id, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
|
|
|
|
|
BLF_color4ubv(fs->uifont_id, col);
|
|
|
|
|
|
|
|
|
|
char str_buf[UI_MAX_DRAW_STR];
|
|
|
|
|
const blender::Vector<blender::StringRef> lines = UI_text_clip_multiline_middle(
|
|
|
|
|
fs, str, str_buf, sizeof(str_buf), max_width, max_line_count);
|
|
|
|
|
|
|
|
|
|
BLI_assert(lines.size() <= max_line_count);
|
|
|
|
|
|
|
|
|
|
/* Draw so that overall text is centered vertically. */
|
|
|
|
|
yofs = (max_height + lines.size() * line_height) / 2.0f - BLF_ascender(fs->uifont_id) -
|
2025-04-24 22:45:22 +00:00
|
|
|
/* Not sure subtracting the descender is always wanted,
|
|
|
|
|
* gives best results where this is currently used. */
|
2025-04-24 18:03:26 +02:00
|
|
|
BLF_descender(fs->uifont_id) / 2.0f;
|
|
|
|
|
yofs = std::max(0, yofs);
|
|
|
|
|
|
|
|
|
|
ResultBLF line_result = {0, 0};
|
|
|
|
|
/* Draw each line with the given alignment. */
|
|
|
|
|
for (StringRef line : lines) {
|
2025-04-24 22:45:22 +00:00
|
|
|
/* String wrapping might have trailing/leading white-space. */
|
2025-04-24 18:03:26 +02:00
|
|
|
line = line.trim();
|
|
|
|
|
|
|
|
|
|
if (align == UI_STYLE_TEXT_CENTER) {
|
|
|
|
|
xofs = floor(0.5f * (max_width - BLF_width(fs->uifont_id, line.data(), line.size())));
|
|
|
|
|
}
|
|
|
|
|
else if (align == UI_STYLE_TEXT_RIGHT) {
|
|
|
|
|
xofs = max_width - BLF_width(fs->uifont_id, line.data(), line.size());
|
|
|
|
|
}
|
|
|
|
|
xofs = std::max(0, xofs);
|
|
|
|
|
|
|
|
|
|
BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f);
|
|
|
|
|
BLF_draw(fs->uifont_id, line.data(), line.size(), &line_result);
|
|
|
|
|
|
|
|
|
|
yofs -= line_height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (r_info) {
|
|
|
|
|
r_info->width = rect->xmin + xofs + line_result.width;
|
|
|
|
|
r_info->lines = lines.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLF_disable(fs->uifont_id, font_flag);
|
|
|
|
|
|
|
|
|
|
if (r_xofs) {
|
|
|
|
|
*r_xofs = xofs;
|
|
|
|
|
}
|
|
|
|
|
if (r_yofs) {
|
|
|
|
|
*r_yofs = yofs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UI_fontstyle_draw_multiline_clipped(const uiFontStyle *fs,
|
|
|
|
|
const rcti *rect,
|
|
|
|
|
const char *str,
|
|
|
|
|
const uchar col[4],
|
|
|
|
|
const eFontStyle_Align align)
|
|
|
|
|
{
|
|
|
|
|
UI_fontstyle_draw_multiline_clipped_ex(fs, rect, str, col, align, nullptr, nullptr, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-04 11:05:53 +11:00
|
|
|
void UI_fontstyle_draw_rotated(const uiFontStyle *fs,
|
|
|
|
|
const rcti *rect,
|
|
|
|
|
const char *str,
|
|
|
|
|
const uchar col[4])
|
2009-10-19 03:54:30 +00:00
|
|
|
{
|
|
|
|
|
float height;
|
|
|
|
|
int xofs, yofs;
|
|
|
|
|
float angle;
|
|
|
|
|
rcti txtrect;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_fontstyle_set(fs);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-10-11 12:24:33 +02:00
|
|
|
height = BLF_ascender(fs->uifont_id) + BLF_descender(fs->uifont_id);
|
2009-10-19 03:54:30 +00:00
|
|
|
/* becomes x-offset when rotated */
|
2012-09-15 11:48:20 +00:00
|
|
|
xofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-10-19 03:54:30 +00:00
|
|
|
/* ignore UI_STYLE, always aligned to top */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-26 21:35:18 +10:00
|
|
|
/* Rotate counter-clockwise for now (assumes left-to-right language). */
|
2012-03-30 01:51:25 +00:00
|
|
|
xofs += height;
|
2013-12-02 20:33:45 +11:00
|
|
|
yofs = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX) + 5;
|
2015-01-31 17:23:30 +11:00
|
|
|
angle = M_PI_2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-10-19 03:54:30 +00:00
|
|
|
/* translate rect to vertical */
|
2012-09-15 11:48:20 +00:00
|
|
|
txtrect.xmin = rect->xmin - BLI_rcti_size_y(rect);
|
|
|
|
|
txtrect.ymin = rect->ymin - BLI_rcti_size_x(rect);
|
2012-03-24 02:51:46 +00:00
|
|
|
txtrect.xmax = rect->xmin;
|
|
|
|
|
txtrect.ymax = rect->ymin;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-10-19 03:54:30 +00:00
|
|
|
/* clip is very strict, so we give it some space */
|
|
|
|
|
/* clipping is done without rotation, so make rect big enough to contain both positions */
|
2012-03-30 01:51:25 +00:00
|
|
|
BLF_clipping(fs->uifont_id,
|
|
|
|
|
txtrect.xmin - 1,
|
|
|
|
|
txtrect.ymin - yofs - xofs - 4,
|
|
|
|
|
rect->xmax + 1,
|
|
|
|
|
rect->ymax + 4);
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_enable(fs->uifont_id, BLF_CLIPPING);
|
2012-03-30 01:51:25 +00:00
|
|
|
BLF_position(fs->uifont_id, txtrect.xmin + xofs, txtrect.ymax - yofs, 0.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_enable(fs->uifont_id, BLF_ROTATION);
|
|
|
|
|
BLF_rotation(fs->uifont_id, angle);
|
2017-02-10 00:00:21 +01:00
|
|
|
BLF_color4ubv(fs->uifont_id, col);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-10-19 03:54:30 +00:00
|
|
|
if (fs->shadow) {
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_enable(fs->uifont_id, BLF_SHADOW);
|
2016-04-22 20:02:03 +10:00
|
|
|
const float shadow_color[4] = {
|
|
|
|
|
fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha};
|
UI: Improved overlay text contrast with new outline text decoration
Overlay texts were previously drawn with two sets of shadows:
- 3px blur,
- 5px blur, slightly offset
But since the shadow color was always set to black, it was still
causing legibility issues when the text itself was dark (set
via theme for example).
This PR adds a new "outline" BLF text decoration, and uses that
for the overlays. And it picks text/outline color depending
on the "background" color of the view.
Details:
- Instead of "shadow level" integer where the only valid options
are 0, 3 or 5, have a FontShadowType enum.
- Add a new FontShadowType::Outline enum entry, that does a 1px
outline by doing a 3x3 dilation in the font shader.
- BLF_draw_default_shadowed is changed to do outline, instead of
drawing the shadow twice.
- In the font shader, instead of encoding shadow type in signs of
the glyph_size, pass that as a "flags" vertex attribute. Put
font texture channel count into the same flags, so that the
vertex size stays the same.
- Well actually, vertex size becomes smaller by 4 bytes, since turns
out glyph_mode vertex attribute was not used for anything at all.
Images in the PR.
Co-authored-by: Harley Acheson <harley.acheson@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/121383
2024-05-10 21:06:44 +02:00
|
|
|
BLF_shadow(fs->uifont_id, FontShadowType(fs->shadow), shadow_color);
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
|
2009-10-19 03:54:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-11 12:33:51 +00:00
|
|
|
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_disable(fs->uifont_id, BLF_ROTATION);
|
|
|
|
|
BLF_disable(fs->uifont_id, BLF_CLIPPING);
|
2019-03-25 10:15:20 +11:00
|
|
|
if (fs->shadow) {
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_disable(fs->uifont_id, BLF_SHADOW);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
2009-10-19 03:54:30 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-04 11:05:53 +11:00
|
|
|
void UI_fontstyle_draw_simple(
|
|
|
|
|
const uiFontStyle *fs, float x, float y, const char *str, const uchar col[4])
|
2015-01-20 14:25:39 +11:00
|
|
|
{
|
|
|
|
|
UI_fontstyle_set(fs);
|
|
|
|
|
BLF_position(fs->uifont_id, x, y, 0.0f);
|
2017-02-10 00:00:21 +01:00
|
|
|
BLF_color4ubv(fs->uifont_id, col);
|
2015-01-20 14:25:39 +11:00
|
|
|
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-20 15:48:40 +11:00
|
|
|
void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs,
|
|
|
|
|
float x,
|
|
|
|
|
float y,
|
2024-01-19 10:45:33 -05:00
|
|
|
const blender::StringRef str,
|
2016-11-22 14:40:57 +01:00
|
|
|
const float col_fg[4],
|
|
|
|
|
const float col_bg[4])
|
2015-01-20 15:48:40 +11:00
|
|
|
{
|
|
|
|
|
UI_fontstyle_set(fs);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-20 15:48:40 +11:00
|
|
|
{
|
2024-01-19 10:45:33 -05:00
|
|
|
const int width = BLF_width(fs->uifont_id, str.data(), str.size());
|
2022-04-13 12:45:41 +10:00
|
|
|
const int height = BLF_height_max(fs->uifont_id);
|
|
|
|
|
const int decent = BLF_descender(fs->uifont_id);
|
2015-01-20 15:48:40 +11:00
|
|
|
const float margin = height / 4.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-02 16:17:48 -05:00
|
|
|
rctf rect;
|
|
|
|
|
rect.xmin = x - margin;
|
|
|
|
|
rect.xmax = x + width + margin;
|
|
|
|
|
rect.ymin = (y + decent) - margin;
|
|
|
|
|
rect.ymax = (y + decent) + height + margin;
|
2017-04-06 19:15:26 -04:00
|
|
|
UI_draw_roundbox_corner_set(UI_CNR_ALL);
|
2022-04-02 16:17:48 -05:00
|
|
|
UI_draw_roundbox_4fv(&rect, true, margin, col_bg);
|
2015-01-20 15:48:40 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-20 15:48:40 +11:00
|
|
|
BLF_position(fs->uifont_id, x, y, 0.0f);
|
2017-02-10 00:00:21 +01:00
|
|
|
BLF_color4fv(fs->uifont_id, col_fg);
|
2024-01-19 10:45:33 -05:00
|
|
|
BLF_draw(fs->uifont_id, str.data(), str.size());
|
2015-01-20 15:48:40 +11:00
|
|
|
}
|
|
|
|
|
|
2009-04-10 16:30:28 +00:00
|
|
|
/* ************** helpers ************************ */
|
2021-12-09 00:55:11 +11:00
|
|
|
|
2023-07-02 19:37:22 +10:00
|
|
|
const uiStyle *UI_style_get()
|
2011-07-16 18:28:24 +00:00
|
|
|
{
|
2015-05-14 23:58:08 +02:00
|
|
|
#if 0
|
2022-04-02 16:17:48 -05:00
|
|
|
uiStyle *style = nullptr;
|
2011-07-22 14:14:28 +00:00
|
|
|
/* offset is two struct uiStyle pointers */
|
2015-05-14 23:58:08 +02:00
|
|
|
style = BLI_findstring(&U.uistyles, "Unifont Style", sizeof(style) * 2);
|
2022-04-02 16:17:48 -05:00
|
|
|
return (style != nullptr) ? style : U.uistyles.first;
|
2015-05-14 23:58:08 +02:00
|
|
|
#else
|
2022-04-02 16:17:48 -05:00
|
|
|
return static_cast<const uiStyle *>(U.uistyles.first);
|
2015-05-14 23:58:08 +02:00
|
|
|
#endif
|
2011-07-16 18:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-02 19:37:22 +10:00
|
|
|
const uiStyle *UI_style_get_dpi()
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
{
|
2020-03-15 17:32:25 +11:00
|
|
|
const uiStyle *style = UI_style_get();
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
static uiStyle _style;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
_style = *style;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-17 04:19:05 +01:00
|
|
|
_style.paneltitle.shadx = short(UI_SCALE_FAC * _style.paneltitle.shadx);
|
|
|
|
|
_style.paneltitle.shady = short(UI_SCALE_FAC * _style.paneltitle.shady);
|
|
|
|
|
_style.grouplabel.shadx = short(UI_SCALE_FAC * _style.grouplabel.shadx);
|
|
|
|
|
_style.grouplabel.shady = short(UI_SCALE_FAC * _style.grouplabel.shady);
|
2024-07-19 21:57:49 +02:00
|
|
|
_style.widget.shadx = short(UI_SCALE_FAC * _style.widget.shadx);
|
|
|
|
|
_style.widget.shady = short(UI_SCALE_FAC * _style.widget.shady);
|
2024-07-25 19:12:41 +02:00
|
|
|
_style.tooltip.shadx = short(UI_SCALE_FAC * _style.tooltip.shadx);
|
|
|
|
|
_style.tooltip.shady = short(UI_SCALE_FAC * _style.tooltip.shady);
|
2023-03-17 04:19:05 +01:00
|
|
|
|
|
|
|
|
_style.columnspace = short(UI_SCALE_FAC * _style.columnspace);
|
|
|
|
|
_style.templatespace = short(UI_SCALE_FAC * _style.templatespace);
|
|
|
|
|
_style.boxspace = short(UI_SCALE_FAC * _style.boxspace);
|
|
|
|
|
_style.buttonspacex = short(UI_SCALE_FAC * _style.buttonspacex);
|
|
|
|
|
_style.buttonspacey = short(UI_SCALE_FAC * _style.buttonspacey);
|
|
|
|
|
_style.panelspace = short(UI_SCALE_FAC * _style.panelspace);
|
|
|
|
|
_style.panelouter = short(UI_SCALE_FAC * _style.panelouter);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
return &_style;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-20 14:25:39 +11:00
|
|
|
int UI_fontstyle_string_width(const uiFontStyle *fs, const char *str)
|
2009-04-10 16:30:28 +00:00
|
|
|
{
|
2015-01-20 14:25:39 +11:00
|
|
|
UI_fontstyle_set(fs);
|
2022-09-25 18:33:28 +10:00
|
|
|
return int(BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX));
|
2009-04-10 16:30:28 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-26 00:10:18 +11:00
|
|
|
int UI_fontstyle_string_width_with_block_aspect(const uiFontStyle *fs,
|
2024-12-06 14:08:10 +01:00
|
|
|
const StringRef str,
|
2021-10-26 00:10:18 +11:00
|
|
|
const float aspect)
|
|
|
|
|
{
|
2023-02-09 11:30:25 +11:00
|
|
|
/* FIXME(@ideasman42): the final scale of the font is rounded which should be accounted for.
|
2022-12-08 10:49:55 +11:00
|
|
|
* Failing to do so causes bad alignment when zoomed out very far in the node-editor. */
|
2023-03-17 04:19:05 +01:00
|
|
|
fontstyle_set_ex(fs, UI_SCALE_FAC / aspect);
|
2024-12-06 14:08:10 +01:00
|
|
|
return int(BLF_width(fs->uifont_id, str.data(), str.size()) * aspect);
|
2021-10-26 00:10:18 +11:00
|
|
|
}
|
|
|
|
|
|
2015-01-20 15:48:40 +11:00
|
|
|
int UI_fontstyle_height_max(const uiFontStyle *fs)
|
|
|
|
|
{
|
|
|
|
|
UI_fontstyle_set(fs);
|
|
|
|
|
return BLF_height_max(fs->uifont_id);
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-09 18:11:18 +00:00
|
|
|
/* ************** init exit ************************ */
|
|
|
|
|
|
2022-12-29 12:01:32 -05:00
|
|
|
void uiStyleInit()
|
2009-04-09 18:11:18 +00:00
|
|
|
{
|
2022-04-02 16:17:48 -05:00
|
|
|
const uiStyle *style = static_cast<uiStyle *>(U.uistyles.first);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-05-06 17:56:59 +10:00
|
|
|
/* Recover from uninitialized DPI. */
|
2019-03-25 10:15:20 +11:00
|
|
|
if (U.dpi == 0) {
|
2012-03-30 01:51:25 +00:00
|
|
|
U.dpi = 72;
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
2013-06-24 15:06:14 +00:00
|
|
|
CLAMP(U.dpi, 48, 144);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-06-17 10:30:34 -07:00
|
|
|
/* Needed so that custom fonts are always first. */
|
|
|
|
|
BLF_unload_all();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-02 16:17:48 -05:00
|
|
|
uiFont *font_first = static_cast<uiFont *>(U.uifonts.first);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-04-09 18:11:18 +00:00
|
|
|
/* default builtin */
|
2022-04-02 16:17:48 -05:00
|
|
|
if (font_first == nullptr) {
|
2025-03-05 16:35:09 +01:00
|
|
|
font_first = MEM_callocN<uiFont>(__func__);
|
2020-08-18 21:46:29 -04:00
|
|
|
BLI_addtail(&U.uifonts, font_first);
|
2014-06-14 02:23:32 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-06-14 02:23:32 +10:00
|
|
|
if (U.font_path_ui[0]) {
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(font_first->filepath, U.font_path_ui);
|
2020-08-18 21:46:29 -04:00
|
|
|
font_first->uifont_id = UIFONT_CUSTOM1;
|
2014-06-14 02:23:32 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(font_first->filepath, "default");
|
2020-08-18 21:46:29 -04:00
|
|
|
font_first->uifont_id = UIFONT_DEFAULT;
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-18 21:46:29 -04:00
|
|
|
LISTBASE_FOREACH (uiFont *, font, &U.uifonts) {
|
2020-02-17 14:07:18 +01:00
|
|
|
const bool unique = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
if (font->uifont_id == UIFONT_DEFAULT) {
|
2020-02-17 14:07:18 +01:00
|
|
|
font->blf_id = BLF_load_default(unique);
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2009-04-09 18:11:18 +00:00
|
|
|
else {
|
2022-01-07 18:01:32 +11:00
|
|
|
font->blf_id = BLF_load(font->filepath);
|
2014-06-14 02:23:32 +10:00
|
|
|
if (font->blf_id == -1) {
|
2020-02-17 14:07:18 +01:00
|
|
|
font->blf_id = BLF_load_default(unique);
|
2014-06-14 02:23:32 +10:00
|
|
|
}
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-20 14:50:56 +11:00
|
|
|
BLF_default_set(font->blf_id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-01-22 06:48:29 +00:00
|
|
|
if (font->blf_id == -1) {
|
2019-03-25 10:15:20 +11:00
|
|
|
if (G.debug & G_DEBUG) {
|
2011-09-27 17:04:38 +00:00
|
|
|
printf("%s: error, no fonts available\n", __func__);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
2010-01-22 06:48:29 +00:00
|
|
|
}
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-02 16:17:48 -05:00
|
|
|
if (style == nullptr) {
|
2021-11-06 16:26:09 +11:00
|
|
|
style = ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT);
|
2011-07-16 18:28:24 +00:00
|
|
|
}
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2021-11-06 16:26:09 +11:00
|
|
|
BLF_cache_flush_set_fn(UI_widgetbase_draw_cache_flush);
|
|
|
|
|
|
2024-07-19 21:57:49 +02:00
|
|
|
BLF_default_size(style->widget.points);
|
2021-11-06 16:26:09 +11:00
|
|
|
|
2019-01-15 23:24:20 +11:00
|
|
|
/* XXX, this should be moved into a style,
|
|
|
|
|
* but for now best only load the monospaced font once. */
|
2015-12-01 16:57:52 +11:00
|
|
|
BLI_assert(blf_mono_font == -1);
|
2020-02-17 14:07:18 +01:00
|
|
|
/* Use unique font loading to avoid thread safety issues with mono font
|
|
|
|
|
* used for render metadata stamp in threads. */
|
2015-12-01 16:57:52 +11:00
|
|
|
if (U.font_path_ui_mono[0]) {
|
|
|
|
|
blf_mono_font = BLF_load_unique(U.font_path_ui_mono);
|
|
|
|
|
}
|
|
|
|
|
if (blf_mono_font == -1) {
|
2020-02-17 14:07:18 +01:00
|
|
|
const bool unique = true;
|
|
|
|
|
blf_mono_font = BLF_load_mono_default(unique);
|
2015-12-01 16:57:52 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-31 16:05:31 +10:00
|
|
|
/* Set default flags based on UI preferences (not render fonts) */
|
|
|
|
|
{
|
2020-08-26 10:11:13 +10:00
|
|
|
const int flag_disable = (BLF_MONOCHROME | BLF_HINTING_NONE | BLF_HINTING_SLIGHT |
|
2023-09-29 19:02:25 +02:00
|
|
|
BLF_HINTING_FULL | BLF_RENDER_SUBPIXELAA);
|
2018-08-14 17:53:27 +02:00
|
|
|
int flag_enable = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-14 17:53:27 +02:00
|
|
|
if (U.text_render & USER_TEXT_HINTING_NONE) {
|
|
|
|
|
flag_enable |= BLF_HINTING_NONE;
|
2018-07-31 16:05:31 +10:00
|
|
|
}
|
2018-08-14 17:53:27 +02:00
|
|
|
else if (U.text_render & USER_TEXT_HINTING_SLIGHT) {
|
|
|
|
|
flag_enable |= BLF_HINTING_SLIGHT;
|
|
|
|
|
}
|
|
|
|
|
else if (U.text_render & USER_TEXT_HINTING_FULL) {
|
|
|
|
|
flag_enable |= BLF_HINTING_FULL;
|
2018-07-31 16:05:31 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-31 16:57:05 +10:00
|
|
|
if (U.text_render & USER_TEXT_DISABLE_AA) {
|
|
|
|
|
flag_enable |= BLF_MONOCHROME;
|
|
|
|
|
}
|
2024-01-17 18:36:54 +11:00
|
|
|
else {
|
|
|
|
|
if (U.text_render & USER_TEXT_RENDER_SUBPIXELAA) {
|
|
|
|
|
flag_enable |= BLF_RENDER_SUBPIXELAA;
|
|
|
|
|
}
|
2023-09-29 19:02:25 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-18 21:46:29 -04:00
|
|
|
LISTBASE_FOREACH (uiFont *, font, &U.uifonts) {
|
2018-07-31 16:05:31 +10:00
|
|
|
if (font->blf_id != -1) {
|
|
|
|
|
BLF_disable(font->blf_id, flag_disable);
|
2018-08-14 17:53:27 +02:00
|
|
|
BLF_enable(font->blf_id, flag_enable);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-07-31 16:05:31 +10:00
|
|
|
}
|
|
|
|
|
if (blf_mono_font != -1) {
|
|
|
|
|
BLF_disable(blf_mono_font, flag_disable);
|
2018-08-14 17:53:27 +02:00
|
|
|
BLF_enable(blf_mono_font, flag_enable);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-07-31 16:05:31 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-28 16:18:17 +10:00
|
|
|
/**
|
|
|
|
|
* Second for rendering else we get threading problems,
|
|
|
|
|
*
|
|
|
|
|
* \note This isn't good that the render font depends on the preferences,
|
|
|
|
|
* keep for now though, since without this there is no way to display many unicode chars.
|
|
|
|
|
*/
|
2019-03-25 10:15:20 +11:00
|
|
|
if (blf_mono_font_render == -1) {
|
2020-02-17 14:07:18 +01:00
|
|
|
const bool unique = true;
|
|
|
|
|
blf_mono_font_render = BLF_load_mono_default(unique);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
2022-06-17 10:30:34 -07:00
|
|
|
|
|
|
|
|
/* Load the fallback fonts last. */
|
|
|
|
|
BLF_load_font_stack();
|
2009-04-09 18:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-08 10:49:55 +11:00
|
|
|
static void fontstyle_set_ex(const uiFontStyle *fs, const float dpi_fac)
|
2009-04-10 14:06:24 +00:00
|
|
|
{
|
2024-07-25 10:17:40 +10:00
|
|
|
const uiFont *font = uifont_to_blfont(fs->uifont_id);
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2022-12-08 10:49:55 +11:00
|
|
|
BLF_size(font->blf_id, fs->points * dpi_fac);
|
2024-03-22 21:28:55 +01:00
|
|
|
BLF_character_weight(font->blf_id, fs->character_weight);
|
2022-12-08 10:49:55 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UI_fontstyle_set(const uiFontStyle *fs)
|
|
|
|
|
{
|
2023-03-17 04:19:05 +01:00
|
|
|
fontstyle_set_ex(fs, UI_SCALE_FAC);
|
2009-04-10 14:06:24 +00:00
|
|
|
}
|