summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2014-09-10 16:47:49 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2014-09-10 16:50:10 -0400
commitc4f7aae7d5c227650675c17c37ebbd36eab670fb (patch)
tree47c9c4e608540495891c8b2efaee4a690af27e9a /libs/gtkmm2ext
parentbeb0b3a6a710fe0ec06d4426f307da1195ba9c9c (diff)
add new (mostly) static class to permit lookup of cursor image hotspots
Diffstat (limited to 'libs/gtkmm2ext')
-rw-r--r--libs/gtkmm2ext/cursors.cc66
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/cursors.h29
-rw-r--r--libs/gtkmm2ext/wscript1
3 files changed, 96 insertions, 0 deletions
diff --git a/libs/gtkmm2ext/cursors.cc b/libs/gtkmm2ext/cursors.cc
new file mode 100644
index 0000000000..3377a7cda9
--- /dev/null
+++ b/libs/gtkmm2ext/cursors.cc
@@ -0,0 +1,66 @@
+#include <sstream>
+#include <fstream>
+
+#include "gtkmm2ext/cursors.h"
+
+using namespace Gtkmm2ext;
+
+CursorInfo::Infos CursorInfo::infos;
+
+CursorInfo::CursorInfo (const std::string& n, int hotspot_x, int hotspot_y)
+ : name (n)
+ , x (hotspot_x)
+ , y (hotspot_y)
+{
+}
+
+int
+CursorInfo::load_cursor_info (const std::string& path)
+{
+ std::ifstream infofile (path.c_str());
+
+ if (!infofile) {
+ return -1;
+ }
+
+ std::stringstream s;
+ std::string name;
+ int x;
+ int y;
+
+ do {
+ s << infofile;
+ if (!infofile) {
+ break;
+ }
+ s >> name;
+ s >> x;
+ s >> y;
+ if (!s) {
+ break;
+ }
+
+ CursorInfo* ci = new CursorInfo (name, x, y);
+ infos[name] = ci;
+
+ } while (true);
+
+ return 0;
+}
+
+void
+CursorInfo::drop_cursor_info ()
+{
+ infos.clear ();
+}
+
+CursorInfo*
+CursorInfo::lookup_cursor_info (const std::string& name)
+{
+ Infos::iterator i = infos.find (name);
+
+ if (i == infos.end()) {
+ return 0;
+ }
+ return i->second;
+}
diff --git a/libs/gtkmm2ext/gtkmm2ext/cursors.h b/libs/gtkmm2ext/gtkmm2ext/cursors.h
new file mode 100644
index 0000000000..d628c13cd8
--- /dev/null
+++ b/libs/gtkmm2ext/gtkmm2ext/cursors.h
@@ -0,0 +1,29 @@
+#ifndef __gtkmm2ext_cursor_info_h___
+#define __gtkmm2ext_cursor_info_h___
+
+#include <string>
+#include <map>
+
+namespace Gtkmm2ext {
+
+class CursorInfo
+{
+ public:
+ static CursorInfo* lookup_cursor_info (const std::string& image_name);
+ static int load_cursor_info (const std::string& path);
+ static void drop_cursor_info ();
+
+ private:
+ CursorInfo (const std::string& image_name, int hotspot_x, int hotspot_y);
+
+ typedef std::map<std::string,CursorInfo*> Infos;
+ static Infos infos;
+
+ std::string name;
+ int x;
+ int y;
+};
+
+} /* namespace */
+
+#endif /* __gtkmm2ext_cursor_info_h___ */
diff --git a/libs/gtkmm2ext/wscript b/libs/gtkmm2ext/wscript
index c2de82d0c2..ef45563c18 100644
--- a/libs/gtkmm2ext/wscript
+++ b/libs/gtkmm2ext/wscript
@@ -36,6 +36,7 @@ gtkmm2ext_sources = [
'cell_renderer_pixbuf_toggle.cc',
'choice.cc',
'click_box.cc',
+ 'cursors.cc',
'debug.cc',
'dndtreeview.cc',
'fastmeter.cc',