diff options
Diffstat (limited to 'dash')
| -rw-r--r-- | dash/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | dash/PlacesSimpleTile.cpp | 226 | ||||
| -rw-r--r-- | dash/PlacesSimpleTile.h | 71 | ||||
| -rw-r--r-- | dash/PlacesTile.cpp | 295 | ||||
| -rw-r--r-- | dash/PlacesTile.h | 75 | 
5 files changed, 0 insertions, 669 deletions
| diff --git a/dash/CMakeLists.txt b/dash/CMakeLists.txt index e8820c321..77f0b8554 100644 --- a/dash/CMakeLists.txt +++ b/dash/CMakeLists.txt @@ -48,8 +48,6 @@ set (DASH_SOURCES  LensView.cpp  LensViewPrivate.cpp  PlacesGroup.cpp - PlacesSimpleTile.cpp - PlacesTile.cpp  PlacesVScrollBar.cpp  PreviewApplications.cpp  PreviewBase.cpp diff --git a/dash/PlacesSimpleTile.cpp b/dash/PlacesSimpleTile.cpp deleted file mode 100644 index 5149bc49d..000000000 --- a/dash/PlacesSimpleTile.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* - * 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> - * Neil Jagdish Patel <neil.patel@canonical.com> - * - */ - -#include "PlacesSimpleTile.h" - -#include <NuxImage/GdkGraphics.h> -#include <gtk/gtk.h> -#include <gdk/gdk.h> - -#include <UnityCore/Variant.h> - -#include "unity-shared/DashStyle.h" -#include "unity-shared/ubus-server.h" -#include "unity-shared/UBusMessages.h" - - -namespace unity -{ -NUX_IMPLEMENT_OBJECT_TYPE(PlacesSimpleTile); - -PlacesSimpleTile::PlacesSimpleTile(std::string const& icon_name, - std::string const& label, - int icon_size, - bool defer_icon_loading, - const void* id) - : PlacesTile(NUX_TRACKER_LOCATION, id), - _label(label), - _icon(icon_name), - _idealiconsize(icon_size) -{ - dash::Style& style = dash::Style::Instance(); - nux::VLayout* layout = new nux::VLayout("", NUX_TRACKER_LOCATION); - - _icontex = new IconTexture(_icon, icon_size, defer_icon_loading); - _icontex->SetMinMaxSize(style.GetTileWidth(), icon_size); - AddChild(_icontex); - - _cairotext = new nux::StaticCairoText(""); - _cairotext->SetMaximumWidth(style.GetTileWidth()); - _cairotext->SetTextEllipsize(nux::StaticCairoText::NUX_ELLIPSIZE_START); - _cairotext->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_CENTRE); - _cairotext->SetText(_label); - - layout->AddLayout(new nux::SpaceLayout(0, 0, 12, 12)); - layout->AddView(_icontex, 0, nux::eCenter, nux::eFull); - layout->AddLayout(new nux::SpaceLayout(0, 0, 12, 12)); - layout->AddView(_cairotext, 0, nux::eCenter, nux::eFull); - - SetMinMaxSize(style.GetTileWidth(), style.GetTileHeight()); - - SetLayout(layout); - - SetDndEnabled(true, false); -} - -bool -PlacesSimpleTile::DndSourceDragBegin() -{ - Reference(); - ubus_server_send_message(ubus_server_get_default(), - UBUS_PLACE_VIEW_CLOSE_REQUEST, - NULL); - return true; -} - -nux::NBitmapData* -PlacesSimpleTile::DndSourceGetDragImage() -{ - nux::NBitmapData* result = 0; - GdkPixbuf* pbuf; - GtkIconTheme* theme; - GtkIconInfo* info; - GError* error = NULL; - GIcon* icon; - - std::string icon_name = _icon; - int size = 64; - - if (icon_name.empty()) - icon_name = "application-default-icon"; - - theme = gtk_icon_theme_get_default(); - icon = g_icon_new_for_string(icon_name.c_str(), NULL); - - if (G_IS_ICON(icon)) - { - info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0); - g_object_unref(icon); - } - else - { - info = gtk_icon_theme_lookup_icon(theme, - icon_name.c_str(), - size, - (GtkIconLookupFlags) 0); - } - - if (!info) - { - info = gtk_icon_theme_lookup_icon(theme, - "application-default-icon", - size, - (GtkIconLookupFlags) 0); - } - - if (gtk_icon_info_get_filename(info) == NULL) - { - gtk_icon_info_free(info); - info = gtk_icon_theme_lookup_icon(theme, - "application-default-icon", - size, - (GtkIconLookupFlags) 0); - } - - pbuf = gtk_icon_info_load_icon(info, &error); - gtk_icon_info_free(info); - - if (GDK_IS_PIXBUF(pbuf)) - { - nux::GdkGraphics graphics(pbuf); - result = graphics.GetBitmap(); - } - - return result; -} - -std::list<const char*> PlacesSimpleTile::DndSourceGetDragTypes() -{ - std::list<const char*> result; - result.push_back("text/uri-list"); - return result; -} - -const char* PlacesSimpleTile::DndSourceGetDataForType(const char* type, int* size, int* format) -{ - *format = 8; - - if (!_uri.empty()) - { - *size = _uri.size(); - return _uri.c_str(); - } - else - { - *size = 0; - return 0; - } -} - -void PlacesSimpleTile::DndSourceDragFinished(nux::DndAction result) -{ - UnReference(); -} - -nux::Geometry PlacesSimpleTile::GetHighlightGeometry() -{ - nux::Geometry base = GetGeometry(); - int width = 0, height = 0; - - _icontex->GetTextureSize(&width, &height); - - _highlight_geometry.width = MAX(width, _idealiconsize); - _highlight_geometry.height = MAX(height, _idealiconsize); - _highlight_geometry.x = (base.width - _highlight_geometry.width) / 2; - _highlight_geometry.y = 12; - - return _highlight_geometry; -} - -std::string PlacesSimpleTile::GetLabel() const -{ - return _label; -} - -std::string PlacesSimpleTile::GetIcon() const -{ - return _icon; -} - -std::string PlacesSimpleTile::GetURI() const -{ - return _uri; -} - -void PlacesSimpleTile::SetURI(std::string const& uri) -{ - _uri = uri; -} - -std::string PlacesSimpleTile::GetName() const -{ - return "PlacesTile"; -} - -void PlacesSimpleTile::AddProperties(GVariantBuilder* builder) -{ - unity::variant::BuilderWrapper(builder).add(GetGeometry()); -} - -void PlacesSimpleTile::LoadIcon() -{ - _icontex->LoadIcon(); - - QueueDraw(); -} - -} // namespace unity diff --git a/dash/PlacesSimpleTile.h b/dash/PlacesSimpleTile.h deleted file mode 100644 index 699cd60dd..000000000 --- a/dash/PlacesSimpleTile.h +++ /dev/null @@ -1,71 +0,0 @@ -// -*- 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: Gordon Allott <gord.allott@canonical.com> - */ - -#ifndef PLACES_SIMPLE_TILE_H -#define PLACES_SIMPLE_TILE_H - -#include <sigc++/sigc++.h> - -#include "unity-shared/IconTexture.h" -#include "unity-shared/Introspectable.h" -#include "PlacesTile.h" -#include "unity-shared/StaticCairoText.h" - -namespace unity -{ - -class PlacesSimpleTile : public unity::debug::Introspectable, public PlacesTile -{ - NUX_DECLARE_OBJECT_TYPE(PlacesSimpleTile, PlacesTile); -public: - - PlacesSimpleTile(std::string const& icon, std::string const& label, int icon_size = 64, bool defer_icon_loading = false, const void* id = NULL); - - std::string GetLabel() const; - std::string GetIcon() const; - std::string GetURI() const; - void SetURI(std::string const& uri); - - void LoadIcon(); - -protected: - nux::Geometry GetHighlightGeometry(); - - std::string GetName() const; - void AddProperties(GVariantBuilder* builder); - - virtual bool DndSourceDragBegin(); - virtual nux::NBitmapData* DndSourceGetDragImage(); - virtual std::list<const char*> DndSourceGetDragTypes(); - virtual const char* DndSourceGetDataForType(const char* type, int* size, int* format); - virtual void DndSourceDragFinished(nux::DndAction result); - -private: - nux::Geometry _highlight_geometry; - std::string _label; - std::string _icon; - std::string _uri; - int _idealiconsize; - IconTexture* _icontex; - nux::StaticCairoText* _cairotext; -}; - -} - -#endif /* PLACES_SIMPLE_TILE_H */ diff --git a/dash/PlacesTile.cpp b/dash/PlacesTile.cpp deleted file mode 100644 index 9d588464b..000000000 --- a/dash/PlacesTile.cpp +++ /dev/null @@ -1,295 +0,0 @@ -/* - * 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 "config.h" - -#include <Nux/Nux.h> - -#include "unity-shared/CairoTexture.h" -#include "unity-shared/TextureCache.h" -#include "PlacesTile.h" - -namespace unity -{ - -namespace -{ - const int PADDING = 8; - const int BLUR_SIZE = 6; -} - -NUX_IMPLEMENT_OBJECT_TYPE(PlacesTile); - -PlacesTile::PlacesTile(NUX_FILE_LINE_DECL, const void* id) : - View(NUX_FILE_LINE_PARAM), - _id(id), - _hilight_layer(NULL), - _last_width(0), - _last_height(0) -{ - SetAcceptKeyNavFocusOnMouseDown(false); - - mouse_down.connect(sigc::mem_fun(this, &PlacesTile::RecvMouseDown)); - mouse_up.connect(sigc::mem_fun(this, &PlacesTile::RecvMouseUp)); - mouse_click.connect(sigc::mem_fun(this, &PlacesTile::RecvMouseClick)); - mouse_enter.connect(sigc::mem_fun(this, &PlacesTile::RecvMouseEnter)); - mouse_leave.connect(sigc::mem_fun(this, &PlacesTile::RecvMouseLeave)); - key_nav_focus_change.connect(sigc::mem_fun(this, &PlacesTile::OnFocusChanged)); - key_nav_focus_activate.connect(sigc::mem_fun(this, &PlacesTile::OnFocusActivated)); -} - -PlacesTile::~PlacesTile() -{ - if (_hilight_layer) - { - delete _hilight_layer; - _hilight_layer = NULL; - } -} - -const void* -PlacesTile::GetId() -{ - return _id; -} - -void -PlacesTile::OnFocusChanged(nux::Area* label, bool has_focus, nux::KeyNavDirection direction) -{ - QueueDraw(); -} - -nux::Geometry -PlacesTile::GetHighlightGeometry() -{ - return GetGeometry(); -} - -nux::BaseTexture* -PlacesTile::DrawHighlight(std::string const& texid, int width, int height) -{ - nux::Geometry base = GetGeometry(); - nux::Geometry highlight_geo = GetHighlightGeometry(); - - int padding = PADDING + (BLUR_SIZE * 3); - nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, - highlight_geo.width + padding, - highlight_geo.height + padding); - cairo_t* cr = cairo_graphics.GetInternalContext(); - - cairo_scale(cr, 1.0f, 1.0f); - - cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.0); - cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); - cairo_paint(cr); - - int bg_width = highlight_geo.width + PADDING + 1; - int bg_height = highlight_geo.height + PADDING + 1; - int bg_x = BLUR_SIZE - 1; - int bg_y = BLUR_SIZE - 1; - - // draw the glow - cairo_set_operator(cr, CAIRO_OPERATOR_OVER); - cairo_set_line_width(cr, 1.0f); - cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 0.75f); - cairo_graphics.DrawRoundedRectangle(cr, - 1.0f, - bg_x, - bg_y, - 5.0, - bg_width, - bg_height, - true); - cairo_fill(cr); - cairo_graphics.BlurSurface(BLUR_SIZE - 2); - - cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); - cairo_graphics.DrawRoundedRectangle(cr, - 1.0, - bg_x, - bg_y, - 5.0, - bg_width, - bg_height, - true); - cairo_clip(cr); - cairo_set_operator(cr, CAIRO_OPERATOR_OVER); - - cairo_graphics.DrawRoundedRectangle(cr, - 1.0, - bg_x, - bg_y, - 5.0, - bg_width, - bg_height, - true); - cairo_set_source_rgba(cr, 240 / 255.0f, 240 / 255.0f, 240 / 255.0f, 1.0f); - cairo_fill_preserve(cr); - - cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0); - cairo_stroke(cr); - - return texture_from_cairo_graphics(cairo_graphics); -} - -void -PlacesTile::UpdateBackground() -{ - nux::Geometry base = GetGeometry(); - nux::Geometry highlight_geo = GetHighlightGeometry(); - - if ((base.width == _last_width) && (base.height == _last_height)) - return; - - _last_width = base.width; - _last_height = base.height; - - // try and get a texture from the texture cache - TextureCache& cache = TextureCache::GetDefault(); - - _hilight_background = cache.FindTexture("PlacesTile.HilightTexture", - highlight_geo.width, highlight_geo.height, - sigc::mem_fun(this, &PlacesTile::DrawHighlight)); - - nux::ROPConfig rop; - rop.Blend = true; - rop.SrcBlend = GL_ONE; - rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; - - nux::TexCoordXForm texxform; - texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); - texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); - - if (_hilight_layer) - delete _hilight_layer; - - _hilight_layer = new nux::TextureLayer(_hilight_background->GetDeviceTexture(), - texxform, - nux::color::White, - true, - rop); -} - -nux::Area* -PlacesTile::FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type) -{ - bool mouse_inside = TestMousePointerInclusion(mouse_position, event_type); - - if (mouse_inside == false) - return NULL; - - return this; -} - -void -PlacesTile::Draw(nux::GraphicsEngine& gfxContext, - bool forceDraw) -{ - nux::Geometry base = GetGeometry(); - - nux::GetPainter().PaintBackground(gfxContext, base); - - gfxContext.PushClippingRectangle(base); - - if (HasKeyFocus() || IsMouseInside()) - { - UpdateBackground(); - nux::Geometry hl_geo = GetHighlightGeometry(); - nux::Geometry total_highlight_geo = nux::Geometry(base.x + hl_geo.x - (PADDING) / 2 - BLUR_SIZE, - base.y + hl_geo.y - (PADDING) / 2 - BLUR_SIZE, - hl_geo.width + PADDING + BLUR_SIZE * 2, - hl_geo.height + PADDING + BLUR_SIZE * 2); - - _hilight_layer->SetGeometry(total_highlight_geo); - nux::GetPainter().RenderSinglePaintLayer(gfxContext, total_highlight_geo, _hilight_layer); - } - - gfxContext.PopClippingRectangle(); -} - -void -PlacesTile::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) -{ - nux::Geometry base = GetGeometry(); - - GfxContext.PushClippingRectangle(base); - - if (HasKeyFocus() || IsMouseInside()) - { - UpdateBackground(); - - nux::Geometry hl_geo = GetHighlightGeometry(); - nux::Geometry total_highlight_geo = nux::Geometry(base.x + hl_geo.x - (PADDING) / 2 - BLUR_SIZE, - base.y + hl_geo.y - (PADDING) / 2 - BLUR_SIZE, - hl_geo.width + PADDING + BLUR_SIZE * 2, - hl_geo.height + PADDING + BLUR_SIZE * 2); - - nux::GetPainter().PushLayer(GfxContext, total_highlight_geo, _hilight_layer); - } - - if (GetCompositionLayout()) - GetCompositionLayout()->ProcessDraw(GfxContext, force_draw); - - if (IsMouseInside() || HasKeyFocus()) - nux::GetPainter().PopBackground(); - - GfxContext.PopClippingRectangle(); -} - -void -PlacesTile::RecvMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags) -{ - if (nux::GetEventButton(button_flags) == 1) - sigClick.emit(this); - QueueDraw(); -} - -void -PlacesTile::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags) -{ - QueueDraw(); -} - -void -PlacesTile::RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags) -{ - QueueDraw(); -} - -void -PlacesTile::RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags) -{ - QueueDraw(); -} - -void -PlacesTile::RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags) -{ - QueueDraw(); -} - -void -PlacesTile::OnFocusActivated(nux::Area* label) -{ - sigClick.emit(this); -} - -} // namespace unity diff --git a/dash/PlacesTile.h b/dash/PlacesTile.h deleted file mode 100644 index 115399eef..000000000 --- a/dash/PlacesTile.h +++ /dev/null @@ -1,75 +0,0 @@ -// -*- 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: Gordon Allott <gord.allott@canonical.com> - */ - -#ifndef PLACES_TILE_H -#define PLACES_TILE_H - -#include <sigc++/sigc++.h> - -#include <Nux/Nux.h> -#include <Nux/VLayout.h> -#include <NuxImage/CairoGraphics.h> - -namespace unity -{ - -class PlacesTile : public nux::View -{ - NUX_DECLARE_OBJECT_TYPE(PlacesTile, nux::View); -public: - PlacesTile(NUX_FILE_LINE_PROTO, const void* id = NULL); - ~PlacesTile(); - - const void* GetId(); - - sigc::signal<void, PlacesTile*> sigClick; - -protected: - virtual nux::Geometry GetHighlightGeometry(); - nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type); - -private: - void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); - void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); - - void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags); - void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags); - void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags); - void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags); - void RecvMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags); - - void UpdateBackground(); - nux::BaseTexture* DrawHighlight(std::string const& texid, int width, int height); - -private: - const void* _id; - nux::ObjectPtr<nux::BaseTexture> _hilight_background; - nux::TextureLayer* _hilight_layer; - - void OnFocusChanged(nux::Area* label, bool has_focus, nux::KeyNavDirection direction); - void OnFocusActivated(nux::Area* label); - int _last_width; - int _last_height; - - sigc::connection con_obj; -}; - -} - -#endif // PLACE_TILE_H | 
