add new (mostly) static class to permit lookup of cursor image hotspots
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 10 Sep 2014 20:47:49 +0000 (16:47 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 10 Sep 2014 20:50:10 +0000 (16:50 -0400)
libs/gtkmm2ext/cursors.cc [new file with mode: 0644]
libs/gtkmm2ext/gtkmm2ext/cursors.h [new file with mode: 0644]
libs/gtkmm2ext/wscript

diff --git a/libs/gtkmm2ext/cursors.cc b/libs/gtkmm2ext/cursors.cc
new file mode 100644 (file)
index 0000000..3377a7c
--- /dev/null
@@ -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 (file)
index 0000000..d628c13
--- /dev/null
@@ -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___ */
index c2de82d0c27f3389f60fccb8a1ccac6561dbe9f6..ef45563c18e000b841222cfee7c0ea1e0e61f9eb 100644 (file)
@@ -36,6 +36,7 @@ gtkmm2ext_sources = [
         'cell_renderer_pixbuf_toggle.cc',
         'choice.cc',
         'click_box.cc',
+        'cursors.cc',
         'debug.cc',
         'dndtreeview.cc',
         'fastmeter.cc',