From a05130e453b1c54d3ca80ed4a781ae5b9a787171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Mon, 26 Jun 2017 09:14:15 +0300 Subject: [PATCH] Widgets|libappfw: Configurable DocumentWidget colors --- .../include/de/widgets/documentwidget.h | 12 +++ .../libappfw/src/widgets/documentwidget.cpp | 78 +++++++------------ doomsday/sdk/libgui/include/de/text/font.h | 3 +- 3 files changed, 42 insertions(+), 51 deletions(-) diff --git a/doomsday/sdk/libappfw/include/de/widgets/documentwidget.h b/doomsday/sdk/libappfw/include/de/widgets/documentwidget.h index 8f1f7f40bb..212c60aca2 100644 --- a/doomsday/sdk/libappfw/include/de/widgets/documentwidget.h +++ b/doomsday/sdk/libappfw/include/de/widgets/documentwidget.h @@ -24,6 +24,8 @@ namespace de { +class ProgressWidget; + /** * Widget for displaying large amounts of text. * @@ -76,6 +78,16 @@ class LIBAPPFW_PUBLIC DocumentWidget : public ScrollAreaWidget */ void setMaximumLineWidth(int maxWidth); + /** + * Set one of the style colors. + * + * @param id Color identifier. + * @param colorName Name of the color. + */ + void setStyleColor(Font::RichFormat::Color id, DotPath const &colorName); + + ProgressWidget &progress(); + // Events. void viewResized(); void drawContent(); diff --git a/doomsday/sdk/libappfw/src/widgets/documentwidget.cpp b/doomsday/sdk/libappfw/src/widgets/documentwidget.cpp index 890706fa38..5f3d0c9846 100644 --- a/doomsday/sdk/libappfw/src/widgets/documentwidget.cpp +++ b/doomsday/sdk/libappfw/src/widgets/documentwidget.cpp @@ -24,17 +24,13 @@ namespace de { -//static int const ID_BACKGROUND = 1; // does not scroll -//static int const ID_TEXT = 2; // scrolls - DENG_GUI_PIMPL(DocumentWidget), public Font::RichFormat::IStyle { - //typedef DefaultVertexBuf VertexBuf; - ProgressWidget *progress = nullptr; // Style. + DotPath colorIds[Font::RichFormat::MaxColors]; ColorBank::Color normalColor; ColorBank::Color highlightColor; ColorBank::Color dimmedColor; @@ -51,18 +47,18 @@ public Font::RichFormat::IStyle // GL objects. TextDrawable glText; - //Drawable drawable; - //Matrix4f modelMatrix; - //GLState clippedTextState; - //GLUniform uMvpMatrix { "uMvpMatrix", GLUniform::Mat4 }; - //GLUniform uScrollMvpMatrix { "uMvpMatrix", GLUniform::Mat4 }; - //GLUniform uColor { "uColor", GLUniform::Vec4 }; GuiVertexBuilder bgVerts; GuiVertexBuilder textVerts; Matrix4f scrollMvpMatrix; Impl(Public *i) : Base(i) { + colorIds[Font::RichFormat::NormalColor] = "document.normal"; + colorIds[Font::RichFormat::HighlightColor] = "document.highlight"; + colorIds[Font::RichFormat::DimmedColor] = "document.dimmed"; + colorIds[Font::RichFormat::AccentColor] = "document.accent"; + colorIds[Font::RichFormat::DimAccentColor] = "document.dimaccent"; + updateStyle(); // Widget to show while lines are being wrapped. @@ -85,11 +81,11 @@ public Font::RichFormat::IStyle { Style const &st = style(); - normalColor = st.colors().color("document.normal"); - highlightColor = st.colors().color("document.highlight"); - dimmedColor = st.colors().color("document.dimmed"); - accentColor = st.colors().color("document.accent"); - dimAccentColor = st.colors().color("document.dimaccent"); + normalColor = st.colors().color(colorIds[Font::RichFormat::NormalColor]); + highlightColor = st.colors().color(colorIds[Font::RichFormat::HighlightColor]); + dimmedColor = st.colors().color(colorIds[Font::RichFormat::DimmedColor]); + accentColor = st.colors().color(colorIds[Font::RichFormat::AccentColor]); + dimAccentColor = st.colors().color(colorIds[Font::RichFormat::DimAccentColor]); glText.setFont(self().font()); self().requestGeometry(); @@ -142,24 +138,12 @@ public Font::RichFormat::IStyle glText.init(atlas(), self().font(), this); self().setIndicatorUv(atlas().imageRectf(root().solidWhitePixel()).middle()); - - /*drawable.addBuffer(ID_BACKGROUND, new VertexBuf); - drawable.addBuffer(ID_TEXT, new VertexBuf); - - shaders().build(drawable.program(), "generic.textured.color_ucolor") - << uMvpMatrix << uColor << uAtlas(); - - shaders().build(drawable.addProgram(ID_TEXT), "generic.textured.color_ucolor") - << uScrollMvpMatrix << uColor << uAtlas(); - drawable.setProgram(ID_TEXT, drawable.program(ID_TEXT)); - drawable.setState(ID_TEXT, clippedTextState);*/ } void glDeinit() { atlas().audienceForReposition() -= this; glText.deinit(); - //drawable.clear(); bgVerts.clear(); textVerts.clear(); } @@ -214,12 +198,7 @@ public Font::RichFormat::IStyle // Background and scroll indicator. bgVerts.clear(); - //VertexBuf::Builder verts; self().glMakeGeometry(bgVerts); - /*drawable.buffer(ID_BACKGROUND) - .setVertices(gl::TriangleStrip, verts, self().isScrolling()? gl::Dynamic : gl::Static);*/ - - //uMvpMatrix = root().projMatrix2D(); if (!progress->isVisible()) { @@ -239,10 +218,8 @@ public Font::RichFormat::IStyle glText.setRange(visRange); glText.update(); // alloc visible lines - //VertexBuf::Builder verts; textVerts.clear(); glText.makeVertices(textVerts, Vector2i(0, 0), ui::AlignLeft); - //drawable.buffer(ID_TEXT).setVertices(gl::TriangleStrip, verts, gl::Static); // Update content size to match the generated vertices exactly. self().setContentWidth(glText.verticesMaxWidth()); @@ -261,8 +238,6 @@ public Font::RichFormat::IStyle { updateGeometry(); - //painter.flush(); - Vector4f const color = Vector4f(1, 1, 1, self().visibleOpacity()); auto &painter = root().painter(); @@ -278,18 +253,11 @@ public Font::RichFormat::IStyle // Update the scissor for the text. auto const oldClip = painter.normalizedScissor(); painter.setNormalizedScissor(oldClip & self().normalizedContentRect()); - //GLState::push() - //clippedTextState = GLState::current(); - /*clippedTextState.setNormalizedScissor(self().normalizedContentRect());*/ - - //drawable.draw(); painter.setColor(color); painter.drawTriangleStrip(textVerts); painter.setNormalizedScissor(oldClip); painter.setModelViewProjection(root().projMatrix2D()); } - - //GLState::pop(); } }; @@ -309,10 +277,6 @@ void DocumentWidget::setText(String const &styledText) { // Show the progress indicator until the text is ready for drawing. d->textVerts.clear(); - /*if (d->drawable.hasBuffer(ID_TEXT)) - { - d->drawable.buffer(ID_TEXT).clear(); - }*/ d->progress->show(); @@ -358,11 +322,25 @@ void DocumentWidget::setMaximumLineWidth(int maxWidth) requestGeometry(); } +void DocumentWidget::setStyleColor(Font::RichFormat::Color id, DotPath const &colorName) +{ + DENG2_ASSERT(id != Font::RichFormat::AltAccentColor); // FIXME: not implemented! + + if (id >= 0 && id < Font::RichFormat::MaxColors) + { + d->colorIds[id] = colorName; + updateStyle(); + } +} + +ProgressWidget &DocumentWidget::progress() +{ + return *d->progress; +} + void DocumentWidget::viewResized() { ScrollAreaWidget::viewResized(); - - //d->uMvpMatrix = root().projMatrix2D(); requestGeometry(); } diff --git a/doomsday/sdk/libgui/include/de/text/font.h b/doomsday/sdk/libgui/include/de/text/font.h index f25946c5a3..4401d10cb4 100644 --- a/doomsday/sdk/libgui/include/de/text/font.h +++ b/doomsday/sdk/libgui/include/de/text/font.h @@ -117,7 +117,8 @@ class LIBGUI_PUBLIC Font DimmedColor = 2, AccentColor = 3, DimAccentColor = 4, - AltAccentColor = 5 + AltAccentColor = 5, + MaxColors }; /**