further tweaks to canvas tooltip mechanism
[ardour.git] / libs / canvas / canvas / stateful_image.h
1 /*
2     Copyright (C) 2014 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #ifndef __canvas_stateful_image_h__
20 #define __canvas_stateful_image_h__
21
22 #include <string>
23 #include <vector>
24 #include <map>
25
26 #include <cairomm/cairomm.h>
27
28 #include "canvas/item.h"
29
30 class XMLNode;
31
32 namespace Pango {
33         class FontDescription;
34 }
35
36 namespace ArdourCanvas {
37
38 class StatefulImage : public Item
39 {
40   private:
41     typedef Cairo::RefPtr<Cairo::ImageSurface> ImageHandle;
42
43     class State {
44       public:
45         ImageHandle image;
46     };
47     
48     typedef std::vector<State> States;
49
50   public:
51
52     StatefulImage (Canvas*, const XMLNode&);
53     StatefulImage (Item*, const XMLNode&);
54     ~StatefulImage ();
55
56     bool set_state (States::size_type);
57     void set_text (const std::string&);
58
59     void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const;
60     void compute_bounding_box () const;
61
62     static void set_image_search_path (const std::string&);
63
64   private:
65     States                  _states;
66     States::size_type       _state;
67     std::string             _text;
68     Pango::FontDescription* _font;
69     uint32_t                _text_color;
70     double                  _text_x;
71     double                  _text_y;
72
73     int load_states (const XMLNode&);
74     
75     typedef std::map<std::string,Cairo::RefPtr<Cairo::ImageSurface> > ImageCache;
76     static ImageCache _image_cache;
77     static PBD::Searchpath _image_search_path;
78
79     static ImageHandle find_image (const std::string&);
80 };
81
82 }
83
84 #endif /* __canvas_stateful_image_h__ */