Adding XML scripting to ArdourCanvas

[git-p4: depot-paths = "//Abdaw/dev_main/tracks/": change = 452743]
This commit is contained in:
Valeriy Kamyshniy 2014-04-14 12:37:20 -05:00
parent 8cbcffc3ad
commit a1709c74c6
24 changed files with 534 additions and 122 deletions

View file

@ -16,14 +16,23 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
//#include "gtkmm/messagedialog.h"
#include <cairomm/cairomm.h>
#include <gdkmm/general.h>
#include "canvas/pixbuf.h"
#include "pbd/error.h"
#include "pbd/compose.h"
#include "pbd/search_path.h"
#include "pbd/file_utils.h"
#include "ardour/filesystem_paths.h"
using namespace std;
using namespace ArdourCanvas;
using namespace PBD;
//#define dbg_msg(a) Gtk::MessageDialog (a, "ArdourCanvas::Pixbuf").run();
Pixbuf::Pixbuf (Group* g)
: Item (g)
@ -31,10 +40,48 @@ Pixbuf::Pixbuf (Group* g)
}
void
Pixbuf::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context) const
Pixbuf::Pixbuf (Group* g, const XMLNode& definition, const XMLNodeMap& styles, std::map<std::string, Item*>& named_items)
: Item (g, definition, styles, named_items)
{
Gdk::Cairo::set_source_pixbuf (context, _pixbuf, 0, 0);
std::string imagename = xml_property(definition, "file", styles, "");
if (!imagename.empty())
{
Searchpath spath(ARDOUR::ardour_data_search_path());
std::string dirname = Glib::path_get_dirname (imagename);
std::string filename = Glib::path_get_basename (imagename);
if (!dirname.empty()) {
spath.add_subdirectory_to_paths(dirname);
}
std::string data_file_path;
if (find_file_in_search_path (spath, filename, data_file_path)) {
try {
_pixbuf = Gdk::Pixbuf::create_from_file (data_file_path);
} catch (const Gdk::PixbufError &e) {
cerr << "Caught PixbufError: " << e.what() << endl;
} catch (...) {
cerr << string_compose ("Caught exception while loading icon named %1", imagename) << endmsg;
}
}
}
}
void
Pixbuf::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
{
Rect self = item_to_window (Rect (position(), position().translate (Duple (_pixbuf->get_width(), _pixbuf->get_height()))));
boost::optional<Rect> r = self.intersection (area);
if (!r) {
return;
}
Rect draw = r.get ();
context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
Gdk::Cairo::set_source_pixbuf (context, _pixbuf, draw.x0, draw.y0);
context->paint ();
}