diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-02-17 16:05:52 -0500 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-02-17 16:05:52 -0500 |
commit | 05d7947795593bb5de348412acc5741052e8e3f9 (patch) | |
tree | 2083ae787cd72c42749f4e78b04b460c2bb3c0b3 | |
parent | 3eeaec56086b5600dc9cde13550271dd374796f1 (diff) |
make stateful image canvas item actually compile
-rw-r--r-- | libs/canvas/canvas/stateful_image.h | 45 | ||||
-rw-r--r-- | libs/canvas/i18n.h | 20 | ||||
-rw-r--r-- | libs/canvas/stateful_image.cc | 62 | ||||
-rw-r--r-- | libs/canvas/wscript | 1 |
4 files changed, 100 insertions, 28 deletions
diff --git a/libs/canvas/canvas/stateful_image.h b/libs/canvas/canvas/stateful_image.h index f00129a4d5..80687c5113 100644 --- a/libs/canvas/canvas/stateful_image.h +++ b/libs/canvas/canvas/stateful_image.h @@ -1,3 +1,24 @@ +/* + Copyright (C) 2014 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef __canvas_stateful_image_h__ +#define __canvas_stateful_image_h__ + #include <string> #include <vector> #include <map> @@ -6,19 +27,29 @@ #include "canvas/item.h" -class StatefulImage : public class Item +class XMLNode; + +namespace Pango { + class FontDescription; +} + +namespace ArdourCanvas { + +class StatefulImage : public Item { private: + typedef Cairo::RefPtr<Cairo::ImageSurface> ImageHandle; + class State { + public: ImageHandle image; }; - typedef Cairo::RefPtr<Cairo::ImageSurface> ImageHandle; - typedef std::vector<State> Images; + typedef std::vector<State> States; public: - StatefulImage (const XMLNode&); + StatefulImage (Group*, const XMLNode&); ~StatefulImage (); bool set_state (States::size_type); @@ -31,7 +62,7 @@ class StatefulImage : public class Item private: States _states; - Images::size_type _state; + States::size_type _state; std::string _text; Pango::FontDescription* _font; uint32_t _text_color; @@ -46,3 +77,7 @@ class StatefulImage : public class Item static ImageHandle find_image (const std::string&); }; + +} + +#endif /* __canvas_stateful_image_h__ */ diff --git a/libs/canvas/i18n.h b/libs/canvas/i18n.h new file mode 100644 index 0000000000..43ae07cac1 --- /dev/null +++ b/libs/canvas/i18n.h @@ -0,0 +1,20 @@ +#ifndef __i18n_h__ +#define __i18n_h__ + +#include "pbd/compose.h" +#include "pbd/convert.h" +#include "gettext.h" + +#include <vector> +#include <string> + +#define _(Text) dgettext (PACKAGE,Text) +#define N_(Text) gettext_noop (Text) +#define X_(Text) Text +#define I18N(Array) PBD::internationalize (PACKAGE, Array) +/** Use this to translate strings that have different meanings in different places. + * Text should be of the form Context|Message. + */ +#define S_(Text) PBD::sgettext (PACKAGE, Text) + +#endif // __i18n_h__ diff --git a/libs/canvas/stateful_image.cc b/libs/canvas/stateful_image.cc index fb609cfb28..f2b8e71744 100644 --- a/libs/canvas/stateful_image.cc +++ b/libs/canvas/stateful_image.cc @@ -1,14 +1,28 @@ #include <string> +#include <pangomm/fontdescription.h> +#include <pangomm/layout.h> + +#include "pbd/error.h" +#include "pbd/failed_constructor.h" #include "pbd/file_utils.h" +#include "pbd/xml++.h" + +#include "canvas/stateful_image.h" +#include "canvas/utils.h" + +#include "i18n.h" + +using namespace ArdourCanvas; +using PBD::error; -std::string StatefulImage::_image_search_path; -StatefulImage::ImageCache StatefulImage::_image_cache; PBD::Searchpath StatefulImage::_image_search_path; +StatefulImage::ImageCache StatefulImage::_image_cache; -StatefulImage::StatefulImage (const XMLNode& node) - : _state (0) - , font_description (0) +StatefulImage::StatefulImage (Group* group, const XMLNode& node) + : Item (group) + , _state (0) + , _font (0) , _text_x (0) , _text_y (0) { @@ -19,7 +33,7 @@ StatefulImage::StatefulImage (const XMLNode& node) StatefulImage::~StatefulImage() { - delete font_description; + delete _font; } void @@ -41,16 +55,16 @@ StatefulImage::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) ("window" coordinates) and render it. */ context->set_source (image, self.x0, self.y0); - context.rectangle (draw->x0, draw->y0, draw->width(), draw->height()); + context->rectangle (draw->x0, draw->y0, draw->width(), draw->height()); context->fill (); - if (_text) { + if (!_text.empty()) { Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context); layout->set_text (_text); - if (_font_description) { - layout->set_font_description (*_font_description); + if (_font) { + layout->set_font_description (*_font); } // layout->set_alignment (_alignment); @@ -80,13 +94,14 @@ StatefulImage::load_states (const XMLNode& node) for (XMLNodeList::const_iterator i = nodes.begin(); i != nodes.end(); ++i) { State s; + States::size_type id; const XMLProperty* prop; if ((prop = (*i)->property ("id")) == 0) { error << _("no ID for state") << endmsg; continue; } - sscanf (prop->value().c_str(), "%ud", &s.id); + sscanf (prop->value().c_str(), "%zd", &id); if ((prop = (*i)->property ("image")) == 0) { error << _("no image for state") << endmsg; @@ -98,14 +113,14 @@ StatefulImage::load_states (const XMLNode& node) continue; } - if (_states.size() < s.id) { - _states.reserve (s.id); + if (_states.size() < id) { + _states.reserve (id); } - _states[s.id] = s; + _states[id] = s; } - + return 0; } StatefulImage::ImageHandle @@ -114,7 +129,7 @@ StatefulImage::find_image (const std::string& name) ImageCache::iterator i; if ((i = _image_cache.find (name)) != _image_cache.end()) { - return *i; + return i->second; } std::string path; @@ -125,13 +140,13 @@ StatefulImage::find_image (const std::string& name) return ImageHandle(); } - return Cairo::Image::create_from_file (path); + return Cairo::ImageSurface::create_from_png (path); } void StatefulImage::set_image_search_path (const std::string& path) { - _image_search_path = SearchPath (path); + _image_search_path = PBD::Searchpath (path); } void @@ -144,14 +159,15 @@ StatefulImage::set_text (const std::string& text) redraw (); } -void +bool StatefulImage::set_state (States::size_type n) { - begin_change (); + if (n >= _states.size()) { + return false; + } _state = n; - _need_redraw = true; - _bounding_box_dirty = true; + redraw (); - end_change (); + return true; } diff --git a/libs/canvas/wscript b/libs/canvas/wscript index 59b2526254..a0f13a660e 100644 --- a/libs/canvas/wscript +++ b/libs/canvas/wscript @@ -50,6 +50,7 @@ canvas_sources = [ 'polygon.cc', 'rectangle.cc', 'root_group.cc', + 'stateful_image.cc', 'text.cc', 'types.cc', 'utils.cc', |