Back to index

unity  6.0.0
Tooltip.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2010-2012 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: Jay Taoko <jay.taoko@canonical.com>
00018  *              Mirco Müller <mirco.mueller@canonical.com
00019  *              Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
00020  */
00021 
00022 #ifndef TOOLTIP_H
00023 #define TOOLTIP_H
00024 
00025 #include <Nux/Nux.h>
00026 #include <Nux/BaseWindow.h>
00027 #include <Nux/HLayout.h>
00028 #include <Nux/VLayout.h>
00029 
00030 #include "CairoBaseWindow.h"
00031 #include "unity-shared/StaticCairoText.h"
00032 #include "unity-shared/Introspectable.h"
00033 
00034 namespace unity
00035 {
00036 class Tooltip : public CairoBaseWindow, public debug::Introspectable
00037 {
00038   NUX_DECLARE_OBJECT_TYPE(Tooltip, CairoBaseWindow);
00039 public:
00040   Tooltip();
00041 
00042   void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw);
00043   void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw);
00044 
00045   void SetText(std::string const& text);
00046 
00047   void ShowTooltipWithTipAt(int anchor_tip_x, int anchor_tip_y);
00048 
00049   // Introspection
00050   std::string GetName() const;
00051   void AddProperties(GVariantBuilder* builder);
00052 
00053   virtual nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type);
00054 
00055 private:
00056   void RecvCairoTextChanged(nux::StaticCairoText* cairo_text);
00057 
00058   void PreLayoutManagement();
00059 
00060   long PostLayoutManagement(long layoutResult);
00061 
00062   void PositionChildLayout(float offsetX,
00063                            float offsetY);
00064 
00065   void LayoutWindowElements();
00066 
00067   void NotifyConfigurationChange(int width,
00068                                  int height);
00069 
00070   int                   _anchorX;
00071   int                   _anchorY;
00072   std::string           _labelText;
00073 
00074   nux::ObjectPtr<nux::StaticCairoText> _tooltip_text;
00075 
00076   nux::HLayout* _hlayout;
00077   nux::VLayout* _vlayout;
00078   nux::SpaceLayout* _left_space;  
00079   nux::SpaceLayout* _right_space; 
00080   nux::SpaceLayout* _top_space;  
00081   nux::SpaceLayout* _bottom_space; 
00082 
00083   bool _cairo_text_has_changed;
00084   void UpdateTexture();
00085 };
00086 }
00087 
00088 #endif // TOOLTIP_H
00089