summaryrefslogtreecommitdiff
path: root/hud
diff options
authorAndrea Azzarone <azzaronea@gmail.com>2012-05-30 16:33:07 +0200
committerAndrea Azzarone <azzaronea@gmail.com>2012-05-30 16:33:07 +0200
commitd6b363260aaa5291d9b710eccb6283337a89cd40 (patch)
tree2a97caa7d410af84a992ddc6db853e4239e0d49b /hud
parent6d54ac633a4b0951f27543bfc2006acff709f967 (diff)
Update the design of the hud button text. Use a full opacity for the highlighted text.
(bzr r2370.1.4)
Diffstat (limited to 'hud')
-rw-r--r--hud/CMakeLists.txt1
-rw-r--r--hud/HudButton.cpp55
-rw-r--r--hud/HudButton.h11
-rw-r--r--hud/HudPrivate.cpp78
-rw-r--r--hud/HudPrivate.h42
5 files changed, 149 insertions, 38 deletions
diff --git a/hud/CMakeLists.txt b/hud/CMakeLists.txt
index 0911793b9..0f4957107 100644
--- a/hud/CMakeLists.txt
+++ b/hud/CMakeLists.txt
@@ -32,6 +32,7 @@ set (HUD_SOURCES
HudController.cpp
HudIcon.cpp
HudIconTextureSource.cpp
+ HudPrivate.cpp
HudView.cpp
)
diff --git a/hud/HudButton.cpp b/hud/HudButton.cpp
index a8dc21fc5..f5e0d6d48 100644
--- a/hud/HudButton.cpp
+++ b/hud/HudButton.cpp
@@ -26,6 +26,7 @@
#include <gtk/gtk.h>
#include <Nux/Nux.h>
+#include <Nux/HLayout.h>
#include <NuxCore/Logger.h>
#include <NuxImage/CairoGraphics.h>
#include <NuxGraphics/NuxGraphics.h>
@@ -33,8 +34,10 @@
#include <UnityCore/Variant.h>
#include "unity-shared/DashStyle.h"
+#include "unity-shared/StaticCairoText.h"
#include "HudButton.h"
+#include "HudPrivate.h"
namespace
{
@@ -46,42 +49,15 @@ namespace unity
namespace hud
{
-HudButton::HudButton(nux::TextureArea *image, NUX_FILE_LINE_DECL)
- : nux::Button(image, NUX_FILE_LINE_PARAM)
- , is_rounded(false)
- , is_focused_(false)
-{
- Init();
-}
-
-HudButton::HudButton(std::string const& label_, NUX_FILE_LINE_DECL)
- : nux::Button(NUX_FILE_LINE_PARAM)
- , label(label_)
- , is_rounded(false)
- , is_focused_(false)
-{
- Init();
-}
-
-HudButton::HudButton(std::string const& label_, nux::TextureArea *image, NUX_FILE_LINE_DECL)
- : nux::Button(image, NUX_FILE_LINE_PARAM)
- , label(label_)
- , is_rounded(false)
- , is_focused_(false)
-{
- Init();
-}
-
HudButton::HudButton(NUX_FILE_LINE_DECL)
: nux::Button(NUX_FILE_LINE_PARAM)
, is_rounded(false)
, is_focused_(false)
{
- Init();
-}
+ hlayout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
+ hlayout_->SetLeftAndRightPadding(46, -1);
+ SetLayout(hlayout_);
-void HudButton::Init()
-{
InitTheme();
key_nav_focus_change.connect([&](nux::Area*, bool, nux::KeyNavDirection)
@@ -119,7 +95,7 @@ void HudButton::InitTheme()
void HudButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state)
{
- dash::Style::Instance().SquareButton(cr, faked_state, label,
+ dash::Style::Instance().SquareButton(cr, faked_state, "",
is_rounded, 17,
dash::Alignment::LEFT, true);
}
@@ -195,12 +171,25 @@ void HudButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
void HudButton::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
{
+ if (IsFullRedraw() && hlayout_)
+ hlayout_->ProcessDraw(GfxContext, force_draw);
}
void HudButton::SetQuery(Query::Ptr query)
{
query_ = query;
label = query->formatted_text;
+
+ auto items(impl::RefactorText(label));
+
+ hlayout_->Clear();
+ for (auto item : items)
+ {
+ nux::StaticCairoText* text = new nux::StaticCairoText(item.first.c_str());
+ text->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, item.second ? 1.0f : 0.5f));
+ text->SetFont("Ubuntu 13"); // 17 px = 13
+ hlayout_->AddView(text, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
+ }
}
Query::Ptr HudButton::GetQuery()
@@ -220,5 +209,5 @@ void HudButton::AddProperties(GVariantBuilder* builder)
.add("label", label());
}
-}
-}
+} // namespace hud
+} // namespace unity
diff --git a/hud/HudButton.h b/hud/HudButton.h
index d8b559cf5..555f5ab38 100644
--- a/hud/HudButton.h
+++ b/hud/HudButton.h
@@ -29,6 +29,8 @@
#include <UnityCore/Hud.h>
#include "unity-shared/Introspectable.h"
+namespace nux { class HLayout; }
+
namespace unity
{
namespace hud
@@ -42,10 +44,7 @@ public:
typedef nux::ObjectPtr<HudButton> Ptr;
HudButton(NUX_FILE_LINE_PROTO);
- HudButton(nux::TextureArea *image, NUX_FILE_LINE_PROTO);
- HudButton(std::string const& label, NUX_FILE_LINE_PROTO);
- HudButton(std::string const& label, nux::TextureArea* image, NUX_FILE_LINE_PROTO);
-
+
void SetQuery(Query::Ptr query);
std::shared_ptr<Query> GetQuery();
@@ -62,7 +61,6 @@ protected:
std::string GetName() const;
void AddProperties(GVariantBuilder* builder);
- void Init();
void InitTheme();
void RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state);
@@ -70,9 +68,12 @@ private:
Query::Ptr query_;
nux::Geometry cached_geometry_;
bool is_focused_;
+
NuxCairoPtr prelight_;
NuxCairoPtr active_;
NuxCairoPtr normal_;
+
+ nux::HLayout* hlayout_;
};
} // namespace hud
diff --git a/hud/HudPrivate.cpp b/hud/HudPrivate.cpp
new file mode 100644
index 000000000..8d491acc5
--- /dev/null
+++ b/hud/HudPrivate.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2012 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License version 3, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the applicable version of the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of both the GNU Lesser General Public
+ * License version 3 along with this program. If not, see
+ * <http://www.gnu.org/licenses/>
+ *
+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
+ * Tim Penhey <tim.penhey@canonical.com>
+ *
+ */
+
+#include "HudPrivate.h"
+
+namespace unity
+{
+namespace hud
+{
+namespace impl
+{
+
+std::vector<std::pair<std::string, bool>> RefactorText(std::string const& text)
+{
+ std::vector<std::pair<std::string, bool>> ret;
+
+ static const std::string bold_start("<b>");
+ static const std::string bold_end("</b>");
+
+ std::string::size_type last = 0;
+ std::string::size_type len = text.length();
+ std::string::size_type pos = text.find(bold_start);
+
+ while (pos != std::string::npos)
+ {
+ if (pos != last)
+ {
+ ret.push_back(std::pair<std::string, bool>(text.substr(last, pos - last), false));
+ }
+
+ // Look for the end
+ pos += 3; // // to skip the "<b>"
+ std::string::size_type end_pos = text.find(bold_end, pos);
+ // We hope we find it, if we don't, just output everything...
+ if (end_pos != std::string::npos)
+ {
+ ret.push_back(std::pair<std::string, bool>(text.substr(pos, end_pos - pos), true));
+ last = end_pos + 4; // the length of "</b>"
+ pos = text.find(bold_start, last);
+ }
+ else
+ {
+ ret.push_back(std::pair<std::string, bool>(text.substr(pos), true));
+ pos = std::string::npos;
+ last = len;
+ }
+ }
+
+ if (last < len)
+ {
+ ret.push_back(std::pair<std::string, bool>(text.substr(last), false));
+ }
+
+ return ret;
+}
+
+} // namespace unity
+} // namespace hud
+} // namespace impl
diff --git a/hud/HudPrivate.h b/hud/HudPrivate.h
new file mode 100644
index 000000000..419b3ca49
--- /dev/null
+++ b/hud/HudPrivate.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2012 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License version 3, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the applicable version of the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of both the GNU Lesser General Public
+ * License version 3 along with this program. If not, see
+ * <http://www.gnu.org/licenses/>
+ *
+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
+ *
+ */
+
+#ifndef UNITYSHELL_HUD_PRIVATE_H
+#define UNITYSHELL_HUD_PRIVATE_H
+
+#include <string>
+#include <utility>
+#include <vector>
+
+namespace unity
+{
+namespace hud
+{
+namespace impl
+{
+
+std::vector<std::pair<std::string, bool>> RefactorText(std::string const& text);
+
+} // namespace impl
+} // namespace hud
+} // namespace unity
+
+#endif // UNITYSHELL_HUD_PRIVATE_H