smoothen rendering of x-fades
[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 (Group*, const XMLNode&);
53     ~StatefulImage ();
54
55     bool set_state (States::size_type);
56     void set_text (const std::string&);
57
58     void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const;
59     void compute_bounding_box () const;
60
61     static void set_image_search_path (const std::string&);
62
63   private:
64     States                  _states;
65     States::size_type       _state;
66     std::string             _text;
67     Pango::FontDescription* _font;
68     uint32_t                _text_color;
69     double                  _text_x;
70     double                  _text_y;
71
72     int load_states (const XMLNode&);
73     
74     typedef std::map<std::string,Cairo::RefPtr<Cairo::ImageSurface> > ImageCache;
75     static ImageCache _image_cache;
76     static PBD::Searchpath _image_search_path;
77
78     static ImageHandle find_image (const std::string&);
79 };
80
81 }
82
83 #endif /* __canvas_stateful_image_h__ */