Back to index

unity  6.0.0
FilterMultiRangeButton.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 Canonical Ltd.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License version 3, as
00006  * published by the  Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranties of
00010  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00012  * License for more details.
00013  *
00014  * You should have received a copy of both the GNU Lesser General Public
00015  * License version 3 along with this program.  If not, see
00016  * <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Gordon Allott <gord.allott@canonical.com>
00019  *
00020  */
00021 
00022 #ifndef UNITYSHELL_FILTERMULTIRANGEBUTTON_H
00023 #define UNITYSHELL_FILTERMULTIRANGEBUTTON_H
00024 
00025 #include <memory>
00026 
00027 #include <Nux/Nux.h>
00028 #include <Nux/CairoWrapper.h>
00029 #include <Nux/ToggleButton.h>
00030 #include <Nux/View.h>
00031 #include <UnityCore/Filter.h>
00032 
00033 namespace unity
00034 {
00035 namespace dash
00036 {
00037 
00038 enum class MultiRangeSide : unsigned int
00039 {
00040   LEFT = 0,
00041   RIGHT,
00042   CENTER
00043 };
00044 
00045 enum class MultiRangeArrow : unsigned int
00046 {
00047   LEFT = 0,
00048   RIGHT,
00049   BOTH,
00050   NONE
00051 };
00052 
00053 class FilterMultiRangeButton : public nux::ToggleButton
00054 {
00055 public:
00056   FilterMultiRangeButton (std::string const& label, NUX_FILE_LINE_PROTO);
00057   FilterMultiRangeButton (NUX_FILE_LINE_PROTO);
00058   ~FilterMultiRangeButton();
00059 
00060   void SetFilter(FilterOption::Ptr const& filter);
00061   FilterOption::Ptr GetFilter();
00062 
00063   void SetVisualSide(MultiRangeSide side); //0 = left, 1 = center, 2 = right - sucky api i know :(
00064   void SetHasArrow(MultiRangeArrow arrow); //0 = left, 1 = both, 2 = right, -1 = none
00065 
00066 protected:
00067   virtual long ComputeContentSize();
00068   virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
00069 
00070 private:
00071   void InitTheme();
00072   void Init();
00073 
00074   void RedrawTheme(nux::Geometry const& geom,
00075                    cairo_t* cr,
00076                    nux::ButtonVisualState faked_state,
00077                    MultiRangeArrow faked_arrow,
00078                    MultiRangeSide faked_side);
00079 
00080   void RedrawFocusOverlay(nux::Geometry const& geom,
00081                           cairo_t* cr,
00082                           MultiRangeArrow faked_arrow,
00083                           MultiRangeSide faked_side);
00084  
00085   void OnActivated(nux::Area* area);
00086   void OnActiveChanged(bool value);
00087 
00088   FilterOption::Ptr filter_;
00089 
00090   typedef std::unique_ptr<nux::CairoWrapper> NuxCairoPtr;
00091   typedef std::pair<MultiRangeArrow, MultiRangeSide> MapKey;
00092 
00093   std::map<MapKey, NuxCairoPtr> active_;
00094   std::map<MapKey, NuxCairoPtr> focus_;
00095   std::map<MapKey, NuxCairoPtr> normal_;
00096   std::map<MapKey, NuxCairoPtr> prelight_;
00097 
00098   nux::Geometry cached_geometry_;
00099   MultiRangeArrow has_arrow_;
00100   MultiRangeSide side_;
00101 };
00102 
00103 } // namespace dash
00104 } // namespace unity
00105 
00106 #endif // UNITYSHELL_FILTERMULTIRANGEBUTTON_H