Back to index

unity  6.0.0
IconTexture.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2010 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Gord Allott <gord.allott@canonical.com>
00018  */
00019 
00020 #ifndef ICON_TEXTURE_H
00021 #define ICON_TEXTURE_H
00022 
00023 #include <Nux/Nux.h>
00024 // FIXME: Nux/View.h needs Nux.h included first.
00025 #include <Nux/View.h>
00026 // FIXME: Nux/TextureArea.h needs View included first.
00027 #include <Nux/TextureArea.h>
00028 #include <NuxGraphics/CairoGraphics.h>
00029 #include <NuxGraphics/GraphicsEngine.h>
00030 #include <UnityCore/GLibWrapper.h>
00031 
00032 #include "unity-shared/Introspectable.h"
00033 
00034 namespace unity
00035 {
00036 
00037 class IconTexture : public nux::TextureArea, public unity::debug::Introspectable
00038 {
00039 public:
00040   IconTexture(nux::BaseTexture* texture, guint width, guint height);
00041   IconTexture(std::string const& icon_name, unsigned int size, bool defer_icon_loading = false);
00042   virtual ~IconTexture();
00043 
00044   void SetByIconName(std::string const& icon_name, unsigned int size);
00045   void SetByFilePath(std::string const& file_path, unsigned int size);
00046   void GetTextureSize(int* width, int* height);
00047 
00048   void LoadIcon();
00049 
00050   void SetOpacity(float opacity);
00051   void SetTexture(nux::BaseTexture* texture);
00052 
00053   void SetAcceptKeyNavFocus(bool accept);
00054 
00055   nux::BaseTexture* texture();
00056 
00057   sigc::signal<void, nux::BaseTexture*> texture_updated;
00058 
00059 protected:
00060   // Key navigation
00061   virtual bool AcceptKeyNavFocus();
00062   bool _accept_key_nav_focus;
00063 
00064   std::string GetName() const;
00065   void AddProperties(GVariantBuilder* builder);
00066   virtual bool DoCanFocus();
00067   glib::Object<GdkPixbuf> _pixbuf_cached;
00068 
00069 protected:
00070   void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
00071 
00072 private:
00073   nux::BaseTexture* CreateTextureCallback(std::string const& texid, int width, int height);
00074   void Refresh(glib::Object<GdkPixbuf> const& pixbuf);
00075   void IconLoaded(std::string const& icon_name, unsigned size, glib::Object<GdkPixbuf> const& pixbuf);
00076 
00077   std::string _icon_name;
00078   unsigned int _size;
00079 
00080   nux::ObjectPtr<nux::BaseTexture> _texture_cached;
00081   nux::Size _texture_size;
00082 
00083   bool _loading;
00084   float _opacity;
00085   int _handle;
00086 };
00087 
00088 }
00089 
00090 #endif // ICON_TEXTURE_H