Back to index

unity  6.0.0
ResultRendererTile.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright 2011 Canonical Ltd.
00004  *
00005  * This program is free software: you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser 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, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License version 3 along with this program.  If not, see
00017  * <http://www.gnu.org/licenses/>
00018  *
00019  * Authored by: Gordon Allott <gord.allott@canonical.com>
00020  *
00021  */
00022 
00023 
00024 
00025 #ifndef RESULTRENDERERTILE_H
00026 #define RESULTRENDERERTILE_H
00027 
00028 #include <Nux/Nux.h>
00029 #include <NuxCore/Object.h>
00030 #include <NuxCore/ObjectPtr.h>
00031 #include <NuxCore/Property.h>
00032 #include <Nux/TextureArea.h>
00033 #include <NuxGraphics/CairoGraphics.h>
00034 #include "unity-shared/IconLoader.h"
00035 
00036 #include "ResultRenderer.h"
00037 
00038 namespace unity
00039 {
00040 namespace dash
00041 {
00042   struct TextureContainer
00043   {
00044     typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr;
00045     BaseTexturePtr text;
00046     BaseTexturePtr icon;
00047     BaseTexturePtr blurred_icon;
00048     BaseTexturePtr prelight;
00049     int slot_handle;
00050 
00051     TextureContainer()
00052       : slot_handle(0)
00053     {
00054     }
00055 
00056     ~TextureContainer()
00057     {
00058       if (slot_handle > 0)
00059         IconLoader::GetDefault().DisconnectHandle(slot_handle);
00060     }
00061   };
00062 
00063 
00064 class ResultRendererTile : public ResultRenderer
00065 {
00066 public:
00067   NUX_DECLARE_OBJECT_TYPE(ResultRendererTile, ResultRenderer);
00068 
00069   ResultRendererTile(NUX_FILE_LINE_PROTO);
00070   ~ResultRendererTile();
00071 
00072   virtual void Render(nux::GraphicsEngine& GfxContext,
00073                       Result& row,
00074                       ResultRendererState state,
00075                       nux::Geometry& geometry,
00076                       int x_offset, int y_offset);
00077   // this is just to start preloading images and text that the renderer might
00078   // need - can be ignored
00079   virtual void Preload(Result& row);
00080   // unload any previous grabbed images
00081   virtual void Unload(Result& row);
00082 
00083   int highlight_padding;
00084   int spacing;
00085   int padding;
00086 
00087 protected:
00088   virtual void LoadText(Result& row);
00089   void LoadIcon(Result& row);
00090   nux::ObjectPtr<nux::BaseTexture> prelight_cache_;
00091   nux::ObjectPtr<nux::BaseTexture> normal_cache_;
00092 private:
00093   //icon loading callbacks
00094   void IconLoaded(std::string const& texid, unsigned size,
00095                   glib::Object<GdkPixbuf> const& pixbuf,
00096                   std::string icon_name, Result& row);
00097   nux::BaseTexture* CreateTextureCallback(std::string const& texid,
00098                                           int width, int height,
00099                                           glib::Object<GdkPixbuf> const& pixbuf);
00100   nux::BaseTexture* CreateBlurredTextureCallback(std::string const& texid,
00101                                                  int width, int height,
00102                                                  glib::Object<GdkPixbuf> const& pixbuf);
00103   nux::BaseTexture* DrawHighlight(std::string const& texid,
00104                                   int width, int height);
00105 };
00106 
00107 }
00108 }
00109 #endif // RESULTRENDERERTILE_H