summaryrefslogtreecommitdiff
path: root/unity-shared
diff options
Diffstat (limited to 'unity-shared')
-rw-r--r--unity-shared/ApplicationScreenshot.cpp125
-rw-r--r--unity-shared/ApplicationScreenshot.h67
-rw-r--r--unity-shared/CMakeLists.txt2
-rw-r--r--unity-shared/IconTexture.cpp2
-rw-r--r--unity-shared/IdleAnimator.cpp104
-rw-r--r--unity-shared/IdleAnimator.h59
-rw-r--r--unity-shared/PreviewStyle.cpp13
-rw-r--r--unity-shared/PreviewStyle.h3
-rw-r--r--unity-shared/RatingsButton.cpp273
-rw-r--r--unity-shared/RatingsButton.h74
10 files changed, 721 insertions, 1 deletions
diff --git a/unity-shared/ApplicationScreenshot.cpp b/unity-shared/ApplicationScreenshot.cpp
new file mode 100644
index 000000000..da87210b2
--- /dev/null
+++ b/unity-shared/ApplicationScreenshot.cpp
@@ -0,0 +1,125 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright 2011 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 Cimitan <andrea.cimitan@canonical.com>
+ *
+ */
+
+#include "ApplicationScreenshot.h"
+#include "unity-shared/IntrospectableWrappers.h"
+#include <NuxCore/Logger.h>
+
+namespace unity
+{
+namespace dash
+{
+namespace previews
+{
+
+namespace
+{
+nux::logging::Logger logger("unity.dash.previews.applicationscreenshot");
+}
+
+NUX_IMPLEMENT_OBJECT_TYPE(ApplicationScreenshot);
+
+ApplicationScreenshot::ApplicationScreenshot(std::string const& image_hint)
+ : View(NUX_TRACKER_LOCATION)
+{
+ texture_screenshot_.Adopt(nux::CreateTexture2DFromFile(image_hint.c_str(), -1, true));
+ SetupViews();
+}
+
+ApplicationScreenshot::~ApplicationScreenshot()
+{
+}
+
+void ApplicationScreenshot::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
+{
+ nux::Geometry const& base = GetGeometry();
+
+ gfx_engine.PushClippingRectangle(base);
+ nux::GetPainter().PaintBackground(gfx_engine, base);
+
+ gfx_engine.PopClippingRectangle();
+}
+
+void ApplicationScreenshot::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
+{
+ nux::Geometry const& base = GetGeometry();
+ gfx_engine.PushClippingRectangle(base);
+
+ if (texture_screenshot_)
+ {
+ nux::Geometry imageDest = base;
+ nux::TexCoordXForm texxform;
+
+ float base_apsect = float(base.GetWidth()) / base.GetHeight();
+ float image_aspect = float(texture_screenshot_->GetWidth()) / texture_screenshot_->GetHeight();
+
+ if (image_aspect > base_apsect)
+ {
+ imageDest.SetHeight(float(imageDest.GetWidth())/image_aspect);
+ }
+ if (image_aspect < base_apsect)
+ {
+ imageDest.SetWidth(image_aspect*imageDest.GetHeight());
+ }
+
+ int border_width = 1;
+
+ //DrawBorder(gfx_engine, imageDest, 0, nux::Color(0.15f, 0.15f, 0.15f));
+ gfx_engine.QRP_Color(imageDest.x + (float(base.GetWidth() - imageDest.GetWidth()) / 2),
+ imageDest.y + (float(base.GetHeight() - imageDest.GetHeight()) / 2),
+ imageDest.GetWidth(),
+ imageDest.GetHeight(),
+ nux::Color(0.15f, 0.15f, 0.15f));
+
+ texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_SCALE_COORD);
+ texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER);
+ texxform.SetFilter(nux::TEXFILTER_LINEAR, nux::TEXFILTER_LINEAR);
+
+ texxform.u0 = 0;
+ texxform.v0 = 0;
+ texxform.u1 = imageDest.width;
+ texxform.v1 = imageDest.height;
+
+ gfx_engine.QRP_1Tex(imageDest.x + (float(base.GetWidth() - imageDest.GetWidth()) / 2) + border_width,
+ imageDest.y + (float(base.GetHeight() - imageDest.GetHeight()) / 2) + border_width,
+ imageDest.width - (border_width * 2),
+ imageDest.height - (border_width * 2),
+ texture_screenshot_.GetPointer()->GetDeviceTexture(),
+ texxform,
+ nux::color::White);
+ }
+
+ gfx_engine.PopClippingRectangle();
+}
+
+std::string ApplicationScreenshot::GetName() const
+{
+ return "ApplicationScreenshot";
+}
+
+void ApplicationScreenshot::SetupViews()
+{
+}
+
+}
+}
+} \ No newline at end of file
diff --git a/unity-shared/ApplicationScreenshot.h b/unity-shared/ApplicationScreenshot.h
new file mode 100644
index 000000000..e61e551e5
--- /dev/null
+++ b/unity-shared/ApplicationScreenshot.h
@@ -0,0 +1,67 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright 2011 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 Cimitan <andrea.cimitan@canonical.com>
+ *
+ */
+
+#ifndef APPLICATIONSCREENSHOT_H
+#define APPLICATIONSCREENSHOT_H
+
+#include <Nux/Nux.h>
+#include <Nux/View.h>
+#include <UnityCore/ApplicationPreview.h>
+#include "unity-shared/StaticCairoText.h"
+#include <Nux/StaticText.h>
+#include <NuxCore/ObjectPtr.h>
+
+namespace unity
+{
+namespace dash
+{
+namespace previews
+{
+
+class ApplicationScreenshot : public nux::View
+{
+public:
+ typedef nux::ObjectPtr<ApplicationScreenshot> Ptr;
+ NUX_DECLARE_OBJECT_TYPE(ApplicationScreenshot, nux::View);
+
+ ApplicationScreenshot(std::string const& image_hint);
+ virtual ~ApplicationScreenshot();
+
+ // From debug::Introspectable
+ std::string GetName() const;
+
+protected:
+ virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw);
+ virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw);
+
+ void SetupViews();
+
+private:
+ nux::ObjectPtr<nux::BaseTexture> texture_screenshot_;
+
+};
+
+}
+}
+}
+
+#endif // APPLICATIONSCREENSHOT_H \ No newline at end of file
diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt
index 49193fafa..4a0c11471 100644
--- a/unity-shared/CMakeLists.txt
+++ b/unity-shared/CMakeLists.txt
@@ -30,6 +30,7 @@ include_directories (. .. ../services ../UnityCore ${UNITY_SRC} ${CMAKE_BINARY_D
set (UNITY_SHARED_SOURCES
AbstractSeparator.cpp
Animator.cpp
+ ApplicationScreenshot.cpp
BGHash.cpp
BackgroundEffectHelper.cpp
DashStyle.cpp
@@ -46,6 +47,7 @@ set (UNITY_SHARED_SOURCES
OverlayRenderer.cpp
PanelStyle.cpp
PreviewStyle.cpp
+ RatingsButton.cpp
SearchBar.cpp
SearchBarSpinner.cpp
StaticCairoText.cpp
diff --git a/unity-shared/IconTexture.cpp b/unity-shared/IconTexture.cpp
index f97e5eb43..45c4a06a8 100644
--- a/unity-shared/IconTexture.cpp
+++ b/unity-shared/IconTexture.cpp
@@ -181,7 +181,7 @@ void IconTexture::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
GfxContext.PushClippingRectangle(geo);
- nux::GetPainter().PaintBackground(GfxContext, geo);
+ //nux::GetPainter().PaintBackground(GfxContext, geo);
if (_texture_cached)
{
diff --git a/unity-shared/IdleAnimator.cpp b/unity-shared/IdleAnimator.cpp
new file mode 100644
index 000000000..b134c11c4
--- /dev/null
+++ b/unity-shared/IdleAnimator.cpp
@@ -0,0 +1,104 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2011 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Marco Trevisan (Treviño) <mail@3v1n0.net>
+ */
+
+#include "IdleAnimator.h"
+
+namespace unity
+{
+
+IdleAnimator::IdleAnimator(unsigned int duration_)
+ : duration_(0)
+{
+ SetDuration(duration_);
+}
+
+IdleAnimator::~IdleAnimator()
+{
+ Stop();
+}
+
+
+void IdleAnimator::SetDuration(unsigned int duration)
+{
+ duration_ = duration * 1000;
+}
+
+unsigned int IdleAnimator::GetRate() const
+{
+ if (rate_ != 0)
+ return 1000 / rate_;
+
+ return rate_;
+}
+
+unsigned int IdleAnimator::GetDuration() const
+{
+ return (one_time_duration_ > 0 ? one_time_duration_ : duration_) / 1000;
+}
+
+bool IdleAnimator::IsRunning() const
+{
+ // short circuit to avoid unneeded calculations
+ struct timespec current;
+ clock_gettime(CLOCK_MONOTONIC, &current);
+
+ // hover in animation
+ if (unity::TimeUtil::TimeDelta(&current, &_times) < ANIM_DURATION_LONG)
+ return true;
+
+ return false;
+}
+
+void IdleAnimator::Start(unsigned int one_time_duration, double start_progress)
+{
+ DoStep();
+}
+
+void IdleAnimator::Start(double start_progress)
+{
+ Start(0, start_progress);
+}
+
+void IdleAnimator::Stop()
+{
+ if (timeout_)
+ {
+ timeout_.reset();
+ animation_updated.emit(progress_);
+ animation_ended.emit();
+ animation_stopped.emit(progress_);
+ one_time_duration_ = 0;
+ }
+}
+
+bool IdleAnimator::DoStep()
+{
+ // rely on the compiz event loop to come back to us in a nice throttling
+ if (IsRunning())
+ {
+ auto idle = std::make_shared<glib::Idle>(glib::Source::Priority::DEFAULT);
+ sources_.Add(idle, ANIMATION_IDLE);
+ idle->Run([&]() {
+ EnsureAnimation();
+ return false;
+ });
+ }
+}
+
+} //namespace
diff --git a/unity-shared/IdleAnimator.h b/unity-shared/IdleAnimator.h
new file mode 100644
index 000000000..fc230f6df
--- /dev/null
+++ b/unity-shared/IdleAnimator.h
@@ -0,0 +1,59 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2011 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Marco Trevisan (Treviño) <mail@3v1n0.net>
+ */
+
+#ifndef UNITY_ANIMATOR_H_
+#define UNITY_ANIMATOR_H_
+
+#include <cstdint>
+#include <UnityCore/GLibSource.h>
+
+namespace unity
+{
+class IdleAnimator : boost::noncopyable
+{
+public:
+ IdleAnimator(unsigned int duration);
+ ~IdleAnimator();
+
+ void SetDuration(unsigned int duration);
+
+ unsigned int GetRate() const;
+ unsigned int GetDuration() const;
+ double GetProgress() const;
+ bool IsRunning() const;
+
+ void Start(int source, int destination);
+
+ sigc::signal<void> animation_started;
+ sigc::signal<void> animation_ended;
+
+ sigc::signal<void, double> animation_updated;
+ sigc::signal<void, double> animation_stopped;
+
+private:
+ bool DoStep();
+ unsigned int duration_;
+
+ // Animation
+ struct timespec times;
+ glib::SourceManager sources_;
+};
+
+}
+#endif
diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp
index fc2e97b00..63b4ba1f3 100644
--- a/unity-shared/PreviewStyle.cpp
+++ b/unity-shared/PreviewStyle.cpp
@@ -82,6 +82,10 @@ std::string Style::version_size_font() const
{
return "Ubuntu 12";
}
+std::string Style::app_license_font() const
+{
+ return "Ubuntu Light 9.5";
+}
std::string Style::app_last_update_font() const
{
return "Ubuntu Light 10";
@@ -95,6 +99,15 @@ std::string Style::app_description_font() const
return "Ubuntu Light 10";
}
+std::string Style::info_hint_font() const
+{
+ return "Ubuntu Light 10";
+}
+std::string Style::user_rating_font() const
+{
+ return "Ubuntu Light 10";
+}
+
}
}
}
diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h
index 1626d9040..b0482ee8d 100644
--- a/unity-shared/PreviewStyle.h
+++ b/unity-shared/PreviewStyle.h
@@ -54,9 +54,12 @@ public:
// Application Preview
std::string app_name_font() const;
std::string version_size_font() const;
+ std::string app_license_font() const;
std::string app_last_update_font() const;
std::string app_copywrite_font() const;
std::string app_description_font() const;
+ std::string info_hint_font() const;
+ std::string user_rating_font() const;
////////////////////////////////
protected:
diff --git a/unity-shared/RatingsButton.cpp b/unity-shared/RatingsButton.cpp
new file mode 100644
index 000000000..112985394
--- /dev/null
+++ b/unity-shared/RatingsButton.cpp
@@ -0,0 +1,273 @@
+/*
+ * Copyright 2011 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: Gordon Allott <gord.allott@canonical.com>
+ *
+ */
+
+#include <math.h>
+
+#include <Nux/Nux.h>
+#include <NuxCore/Logger.h>
+
+#include "RatingsButton.h"
+#include "DashStyle.h"
+
+namespace
+{
+const int num_stars = 5;
+}
+
+namespace unity
+{
+RatingsButton::RatingsButton(int star_size, int star_gap, NUX_FILE_LINE_DECL)
+ : nux::ToggleButton(NUX_FILE_LINE_PARAM)
+ , editable_(true)
+ , focused_star_(-1)
+ , star_size_(star_size)
+ , star_gap_(star_gap)
+{
+ SetAcceptKeyNavFocusOnMouseDown(false);
+ SetAcceptKeyNavFocusOnMouseEnter(true);
+
+ mouse_up.connect(sigc::mem_fun(this, &RatingsButton::RecvMouseUp));
+ mouse_move.connect(sigc::mem_fun(this, &RatingsButton::RecvMouseMove));
+ mouse_drag.connect(sigc::mem_fun(this, &RatingsButton::RecvMouseDrag));
+
+ key_nav_focus_change.connect([&](nux::Area* area, bool has_focus, nux::KeyNavDirection direction)
+ {
+ if (has_focus && direction != nux::KEY_NAV_NONE)
+ focused_star_ = 0;
+ else if (!has_focus)
+ focused_star_ = -1;
+
+ QueueDraw();
+ });
+ key_nav_focus_activate.connect([&](nux::Area*) { SetRating(static_cast<float>(focused_star_+1)/num_stars); });
+ key_down.connect(sigc::mem_fun(this, &RatingsButton::OnKeyDown));
+}
+
+RatingsButton::~RatingsButton()
+{
+}
+
+void RatingsButton::SetEditable(bool editable)
+{
+ editable_ = editable;
+ if (!editable_)
+ focused_star_ = -1;
+ QueueDraw();
+}
+
+void RatingsButton::SetRating(float rating)
+{
+ rating_ = rating;
+ QueueDraw();
+}
+
+void RatingsButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
+{
+ int rating = static_cast<int>(rating_ * num_stars);
+ // FIXME: 9/26/2011
+ // We should probably support an API for saying whether the ratings
+ // should or shouldn't support half stars...but our only consumer at
+ // the moment is the applications lens which according to design
+ // (Bug #839759) shouldn't. So for now just force rounding.
+ // int total_half_stars = rating % 2;
+ // int total_full_stars = rating / 2;
+ int total_full_stars = rating;
+
+ nux::Geometry const& geo = GetGeometry();
+ nux::Geometry geo_star(geo);
+ geo_star.width = star_size_;
+
+ gPainter.PaintBackground(GfxContext, geo);
+ // set up our texture mode
+ nux::TexCoordXForm texxform;
+ texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER);
+ texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_SCALE_COORD);
+ texxform.SetFilter(nux::TEXFILTER_LINEAR, nux::TEXFILTER_LINEAR);
+
+ // clear what is behind us
+ unsigned int alpha = 0, src = 0, dest = 0;
+
+ GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
+ GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ nux::Color col = nux::color::Black;
+ col.alpha = 0;
+ GfxContext.QRP_Color(geo.x,
+ geo.y,
+ geo.width,
+ geo.height,
+ col);
+
+ for (int index = 0; index < num_stars; ++index)
+ {
+ dash::Style& style = dash::Style::Instance();
+ nux::BaseTexture* texture = style.GetStarSelectedIcon();
+ if (index < total_full_stars)
+ {
+ if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL)
+ texture = style.GetStarSelectedIcon();
+ else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
+ texture = style.GetStarSelectedIcon();
+ else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
+ texture = style.GetStarSelectedIcon();
+ }
+ else
+ {
+ if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_NORMAL)
+ texture = style.GetStarDeselectedIcon();
+ else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)
+ texture = style.GetStarDeselectedIcon();
+ else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
+ texture = style.GetStarDeselectedIcon();
+ }
+
+ GfxContext.QRP_1Tex(geo_star.x,
+ geo_star.y,
+ geo_star.width,
+ geo_star.height,
+ texture->GetDeviceTexture(),
+ texxform,
+ nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ if (focused_star_ == index)
+ {
+ GfxContext.QRP_1Tex(geo_star.x,
+ geo_star.y,
+ geo_star.width,
+ geo_star.height,
+ style.GetStarHighlightIcon()->GetDeviceTexture(),
+ texxform,
+ nux::Color(1.0f, 1.0f, 1.0f, 0.5f));
+ }
+
+ geo_star.x += geo_star.width + star_gap_;
+
+ }
+
+ GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
+
+}
+
+void RatingsButton::UpdateRatingToMouse(int x)
+{
+ int width = num_stars*star_size_ + (num_stars-1)*star_gap_;
+ float new_rating = (static_cast<float>(x) / width);
+
+ // FIXME: change to * 2 once we decide to support also half-stars
+ new_rating = ceil((num_stars * 1) * new_rating) / (num_stars * 1);
+ new_rating = (new_rating > 1) ? 1 : ((new_rating < 0) ? 0 : new_rating);
+
+ UpdateRating(new_rating);
+}
+
+void RatingsButton::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags)
+{
+ if (!editable_)
+ return;
+
+ UpdateRatingToMouse(x);
+}
+
+void RatingsButton::RecvMouseDrag(int x, int y, int dx, int dy,
+ unsigned long button_flags,
+ unsigned long key_flags)
+{
+ if (!editable_)
+ return;
+
+ UpdateRatingToMouse(x);
+}
+
+void RatingsButton::RecvMouseMove(int x, int y, int dx, int dy,
+ unsigned long button_flags,
+ unsigned long key_flags)
+{
+ if (!editable_)
+ return;
+
+ int width = num_stars*star_size_+ (num_stars-1)*star_gap_;
+ focused_star_ = std::max(0, std::min(static_cast<int>(ceil((static_cast<float>(x) / width) * num_stars) - 1), num_stars - 1));
+
+ if (!HasKeyFocus())
+ nux::GetWindowCompositor().SetKeyFocusArea(this);
+
+ QueueDraw();
+}
+
+
+bool RatingsButton::InspectKeyEvent(unsigned int eventType, unsigned int keysym, const char* character)
+{
+ nux::KeyNavDirection direction = nux::KEY_NAV_NONE;
+
+ switch (keysym)
+ {
+ case NUX_VK_LEFT:
+ direction = nux::KeyNavDirection::KEY_NAV_LEFT;
+ break;
+ case NUX_VK_RIGHT:
+ direction = nux::KeyNavDirection::KEY_NAV_RIGHT;
+ break;
+ default:
+ direction = nux::KeyNavDirection::KEY_NAV_NONE;
+ break;
+ }
+
+ if (direction == nux::KeyNavDirection::KEY_NAV_NONE)
+ return false;
+ else if (direction == nux::KEY_NAV_LEFT && (focused_star_ <= 0))
+ return false;
+ else if (direction == nux::KEY_NAV_RIGHT && (focused_star_ >= num_stars - 1))
+ return false;
+ else
+ return true;
+}
+
+
+void RatingsButton::OnKeyDown(unsigned long event_type, unsigned long event_keysym,
+ unsigned long event_state, const TCHAR* character,
+ unsigned short key_repeat_count)
+{
+ switch (event_keysym)
+ {
+ case NUX_VK_LEFT:
+ --focused_star_;
+ break;
+ case NUX_VK_RIGHT:
+ ++focused_star_;
+ break;
+ default:
+ return;
+ }
+
+ QueueDraw();
+}
+
+bool RatingsButton::AcceptKeyNavFocus()
+{
+ return true;
+}
+
+void RatingsButton::UpdateRating(float rating)
+{
+
+}
+
+} // namespace unity
diff --git a/unity-shared/RatingsButton.h b/unity-shared/RatingsButton.h
new file mode 100644
index 000000000..b162bc0a9
--- /dev/null
+++ b/unity-shared/RatingsButton.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2011 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: Gordon Allott <gord.allott@canonical.com>
+ * Nick Dedekind <nick.dedelomd@canonical.com>
+ *
+ */
+
+#ifndef UNITYSHELL_RATINGSBUTTONWIDGET_H
+#define UNITYSHELL_RATINGSBUTTONWIDGET_H
+
+#include <memory>
+
+#include <Nux/Nux.h>
+#include <Nux/ToggleButton.h>
+
+namespace unity
+{
+
+class RatingsButton : public nux::ToggleButton
+{
+public:
+ RatingsButton(int star_size, int star_gap, NUX_FILE_LINE_PROTO);
+ virtual ~RatingsButton();
+
+ void SetEditable(bool editable);
+ virtual void SetRating(float rating);
+
+protected:
+ virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
+
+ // Key-nav
+ virtual bool AcceptKeyNavFocus();
+ virtual bool InspectKeyEvent(unsigned int eventType, unsigned int keysym, const char* character);
+
+ virtual void UpdateRating(float rating);
+
+private:
+ void OnKeyDown(unsigned long event_type, unsigned long event_keysym,
+ unsigned long event_state, const TCHAR* character,
+ unsigned short key_repeat_count);
+
+ void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
+ void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
+ void RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
+ void UpdateRatingToMouse(int x);
+
+
+protected:
+ bool editable_;
+ float rating_;
+ int focused_star_;
+ int star_size_;
+ int star_gap_;
+};
+
+} // namespace unity
+
+#endif // UNITYSHELL_RATINGSBUTTONWIDGET_H
+