aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@seriouslyembedded.com>2015-10-30 15:37:55 +0100
committerJoel Bodenmann <joel@seriouslyembedded.com>2015-10-30 15:37:55 +0100
commitee2b82271d7f85dc94c19aed46d42ac8187c79e6 (patch)
tree8e12867ab632257087d528f4f20708b5aafde80d
parent1c7948b9267ae684ef602cbca9d5675d0b0a6281 (diff)
downloaduGFX-ee2b82271d7f85dc94c19aed46d42ac8187c79e6.tar.gz
uGFX-ee2b82271d7f85dc94c19aed46d42ac8187c79e6.tar.bz2
uGFX-ee2b82271d7f85dc94c19aed46d42ac8187c79e6.zip
Adding word-wrap support for gdispDrawStringBox() and gdispFillStringBox()
Thanks to Koryagin Dmitry for this contribution
-rw-r--r--gfxconf.example.h1
-rw-r--r--src/gdisp/gdisp.c51
-rw-r--r--src/gdisp/gdisp_options.h8
-rw-r--r--src/gdisp/mcufont/mf_config.h11
4 files changed, 66 insertions, 5 deletions
diff --git a/gfxconf.example.h b/gfxconf.example.h
index 9f901fce..387a4b2b 100644
--- a/gfxconf.example.h
+++ b/gfxconf.example.h
@@ -73,6 +73,7 @@
//#define GDISP_NEED_MULTITHREAD FALSE
//#define GDISP_NEED_STREAMING FALSE
//#define GDISP_NEED_TEXT FALSE
+// #define GDISP_NEED_TEXT_WORDWRAP FALSE
// #define GDISP_NEED_ANTIALIAS FALSE
// #define GDISP_NEED_UTF8 FALSE
// #define GDISP_NEED_TEXT_KERNING FALSE
diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c
index ffede502..f2fd2738 100644
--- a/src/gdisp/gdisp.c
+++ b/src/gdisp/gdisp.c
@@ -20,6 +20,17 @@
#define GDISP_STARTUP_LOGO_TIMEOUT 0
#endif
+// For internal use only.
+#if GDISP_NEED_TEXT_WORDWRAP
+ typedef struct wrapParameters {
+ GDisplay* g;
+ coord_t x;
+ coord_t y;
+ font_t font;
+ justify_t justify;
+ } wrapParameters_t;
+#endif
+
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
@@ -3156,6 +3167,19 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
#undef GD
}
+ /* Callback to render string boxes with word wrap. */
+ #if GDISP_NEED_TEXT_WORDWRAP
+ static bool mf_line_callback(mf_str line, uint16_t count, void *state) {
+ wrapParameters_t* wrapParameters = (wrapParameters_t*)state;
+
+ mf_render_aligned(wrapParameters->font, wrapParameters->x, wrapParameters->y, wrapParameters->justify, line, count, fillcharglyph, wrapParameters->g);
+
+ wrapParameters->y += wrapParameters->font->baseline_y;
+
+ return TRUE;
+ }
+ #endif
+
void gdispGDrawChar(GDisplay *g, coord_t x, coord_t y, uint16_t c, font_t font, color_t color) {
MUTEX_ENTER(g);
g->t.font = font;
@@ -3247,7 +3271,19 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
}
y += (cy+1 - font->height)/2;
- mf_render_aligned(font, x, y, justify, str, 0, drawcharglyph, g);
+ /* Render */
+ #if GDISP_NEED_TEXT_WORDWRAP
+ wrapParameters_t wrapParameters;
+ wrapParameters.x = x;
+ wrapParameters.y = y;
+ wrapParameters.font = font;
+ wrapParameters.justify = justify;
+ wrapParameters.g = g;
+
+ mf_wordwrap(font, cx, str, mf_line_callback, &wrapParameters);
+ #else
+ mf_render_aligned(font, x, y, justify, str, 0, fillcharglyph, g);
+ #endif
autoflush(g);
MUTEX_EXIT(g);
@@ -3285,7 +3321,18 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
y += (cy+1 - font->height)/2;
/* Render */
- mf_render_aligned(font, x, y, justify, str, 0, fillcharglyph, g);
+ #if GDISP_NEED_TEXT_WORDWRAP
+ wrapParameters_t wrapParameters;
+ wrapParameters.x = x;
+ wrapParameters.y = y;
+ wrapParameters.font = font;
+ wrapParameters.justify = justify;
+ wrapParameters.g = g;
+
+ mf_wordwrap(font, cx, str, mf_line_callback, &wrapParameters);
+ #else
+ mf_render_aligned(font, x, y, justify, str, 0, fillcharglyph, g);
+ #endif
}
autoflush(g);
diff --git a/src/gdisp/gdisp_options.h b/src/gdisp/gdisp_options.h
index 51d759d8..c3eec451 100644
--- a/src/gdisp/gdisp_options.h
+++ b/src/gdisp/gdisp_options.h
@@ -387,6 +387,14 @@
* @{
*/
/**
+ * @brief Enable advanced word-wrapping.
+ * @details Only has an effect with @p gdispGDrawStringBox() and @p gdispGFillStringBox()
+ * @details Defaults to FALSE
+ */
+ #ifndef GDISP_NEED_TEXT_WORDWRAP
+ #define GDISP_NEED_TEXT_WORDWRAP FALSE
+ #endif
+ /**
* @brief Enable UTF-8 support for text rendering.
* @details Defaults to FALSE
*/
diff --git a/src/gdisp/mcufont/mf_config.h b/src/gdisp/mcufont/mf_config.h
index ac2262d4..5c6f4ea9 100644
--- a/src/gdisp/mcufont/mf_config.h
+++ b/src/gdisp/mcufont/mf_config.h
@@ -25,16 +25,21 @@
/* Mapping from uGFX settings to mcufont settings */
#if GDISP_NEED_UTF8
-#define MF_ENCODING MF_ENCODING_UTF8
+ #define MF_ENCODING MF_ENCODING_UTF8
+#else
+ #define MF_ENCODING MF_ENCODING_ASCII
+#endif
+
+#if GDISP_NEED_TEXT_WORDWRAP
+ #define MF_USE_ADVANCED_WORDWRAP 1
#else
-#define MF_ENCODING MF_ENCODING_ASCII
+ #define MF_USE_ADVANCED_WORDWRAP 0
#endif
#define MF_USE_KERNING GDISP_NEED_TEXT_KERNING
#define MF_FONT_FILE_NAME "src/gdisp/fonts/fonts.h"
/* These are not used for now */
-#define MF_USE_ADVANCED_WORDWRAP 0
#define MF_USE_JUSTIFY 0
/*******************************************************