[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50675] trunk/blender/source/blender/ editors/interface/interface_widgets.c: code cleanup: add some comments and made some small speedup to text clipping in the UI
Campbell Barton
ideasman42 at gmail.com
Mon Sep 17 02:33:08 CEST 2012
Revision: 50675
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50675
Author: campbellbarton
Date: 2012-09-17 00:33:07 +0000 (Mon, 17 Sep 2012)
Log Message:
-----------
code cleanup: add some comments and made some small speedup to text clipping in the UI
Modified Paths:
--------------
trunk/blender/source/blender/editors/interface/interface_widgets.c
Modified: trunk/blender/source/blender/editors/interface/interface_widgets.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_widgets.c 2012-09-16 23:40:03 UTC (rev 50674)
+++ trunk/blender/source/blender/editors/interface/interface_widgets.c 2012-09-17 00:33:07 UTC (rev 50675)
@@ -965,14 +965,19 @@
but->ofs += bytes;
}
-/* sets but->ofs to make sure text is correctly visible */
+/**
+ * Cut off the start of the text to fit into the width of \a rect
+ *
+ * \note Sets but->ofs to make sure text is correctly visible.
+ * \note Clips right in some cases, this function could be cleaned up.
+ */
static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
{
int border = (but->flag & UI_BUT_ALIGN_RIGHT) ? 8 : 10;
int okwidth = BLI_rcti_size_x(rect) - border;
if (but->flag & UI_HAS_ICON) okwidth -= UI_DPI_ICON_SIZE;
-
+
/* need to set this first */
uiStyleFontSet(fstyle);
@@ -984,10 +989,13 @@
if (but->ofs > but->pos)
but->ofs = but->pos;
- if (BLF_width(fstyle->uifont_id, but->drawstr) <= okwidth)
+ if (BLF_width(fstyle->uifont_id, but->drawstr) <= okwidth) {
but->ofs = 0;
+ }
}
- else but->ofs = 0;
+ else {
+ but->ofs = 0;
+ }
but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
@@ -1005,8 +1013,9 @@
width = BLF_width(fstyle->uifont_id, buf + but->ofs);
/* if cursor is at 20 pixels of right side button we clip left */
- if (width > okwidth - 20)
+ if (width > okwidth - 20) {
ui_text_clip_give_next_off(but);
+ }
else {
int len, bytes;
/* shift string to the left */
@@ -1017,24 +1026,32 @@
but->drawstr[len - bytes] = 0;
}
}
- else
+ else {
ui_text_clip_give_next_off(but);
+ }
but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
if (but->strwidth < 10) break;
}
-
- if (fstyle->kerning == 1)
+
+ if (fstyle->kerning == 1) {
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
+ }
}
+/**
+ * Cut off the end of text to fit into the width of \a rect.
+ *
+ * \note deals with ': ' especially for number buttons
+ */
static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
{
int border = (but->flag & UI_BUT_ALIGN_RIGHT) ? 8 : 10;
int okwidth = BLI_rcti_size_x(rect) - border;
char *cpoin = NULL;
- char *cpend = but->drawstr + strlen(but->drawstr);
+ int drawstr_len = strlen(but->drawstr);
+ char *cpend = but->drawstr + drawstr_len;
/* need to set this first */
uiStyleFontSet(fstyle);
@@ -1045,6 +1062,13 @@
but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr);
but->ofs = 0;
+
+ /* First shorten num-buttopns eg,
+ * Translucency: 0.000
+ * becomes
+ * Trans: 0.000
+ */
+
/* find the space after ':' separator */
cpoin = strrchr(but->drawstr, ':');
@@ -1057,8 +1081,11 @@
int bytes = cp2 - prev_utf8;
/* shift the text after and including cp2 back by 1 char, +1 to include null terminator */
- memmove(cp2 - bytes, cp2, strlen(cp2) + 1);
+ memmove(cp2 - bytes, cp2, drawstr_len + 1);
cp2 -= bytes;
+
+ drawstr_len -= bytes;
+ // BLI_assert(strlen(but->drawstr) == drawstr_len);
but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
if (but->strwidth < 10) break;
@@ -1074,14 +1101,17 @@
}
+
+ /* Now just remove trailing chars */
/* once the label's gone, chop off the least significant digits */
while (but->strwidth > okwidth) {
- int len = strlen(but->drawstr);
- int bytes = BLI_str_utf8_size(BLI_str_find_prev_char_utf8(but->drawstr, but->drawstr + len));
+ int bytes = BLI_str_utf8_size(BLI_str_find_prev_char_utf8(but->drawstr, but->drawstr + drawstr_len));
if (bytes < 0)
bytes = 1;
- but->drawstr[len - bytes] = 0;
+ drawstr_len -= bytes;
+ but->drawstr[drawstr_len] = 0;
+ // BLI_assert(strlen(but->drawstr) == drawstr_len);
but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
if (but->strwidth < 10) break;
More information about the Bf-blender-cvs
mailing list