make stateful image canvas item actually compile
This commit is contained in:
parent
3eeaec5608
commit
05d7947795
|
@ -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__ */
|
||||
|
|
20
libs/canvas/i18n.h
Normal file
20
libs/canvas/i18n.h
Normal file
|
@ -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__
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ canvas_sources = [
|
|||
'polygon.cc',
|
||||
'rectangle.cc',
|
||||
'root_group.cc',
|
||||
'stateful_image.cc',
|
||||
'text.cc',
|
||||
'types.cc',
|
||||
'utils.cc',
|
||||
|
|
Loading…
Reference in New Issue
Block a user