ardour
cursors.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 Paul Davis
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18 */
19 
20 #include <sstream>
21 #include <fstream>
22 
23 #include "pbd/error.h"
24 #include "pbd/compose.h"
25 
26 #include "gtkmm2ext/cursors.h"
27 
28 #include "i18n.h"
29 
30 using namespace Gtkmm2ext;
31 
33 
34 CursorInfo::CursorInfo (const std::string& n, int hotspot_x, int hotspot_y)
35  : name (n)
36  , x (hotspot_x)
37  , y (hotspot_y)
38 {
39 }
40 
41 int
42 CursorInfo::load_cursor_info (const std::string& path)
43 {
44  std::ifstream infofile (path.c_str());
45 
46  if (!infofile) {
47  return -1;
48  }
49 
50  std::stringstream s;
51  std::string name;
52  int x;
53  int y;
54  bool parse_ok;
55  int line_number = 1;
56 
57  do {
58  parse_ok = false;
59  infofile >> name;
60  if (!infofile) {
61  /* failing here is OK ... EOF */
62  parse_ok = true;
63  break;
64  }
65  infofile >> x;
66  if (!infofile) {
67  break;
68  }
69  infofile >> y;
70  if (!infofile) {
71  break;
72  }
73 
74  parse_ok = true;
75  line_number++;
76 
77  infos[name] = new CursorInfo (name, x, y);
78 
79  } while (true);
80 
81  if (!parse_ok) {
82  PBD::error << string_compose (_("cursor hotspots info file %1 has an error on line %2"), path, line_number) << endmsg;
83  infos.clear ();
84  return -1;
85  }
86 
87  return 0;
88 }
89 
90 void
92 {
93  infos.clear ();
94 }
95 
98 {
99  Infos::iterator i = infos.find (name);
100 
101  if (i == infos.end()) {
102  return 0;
103  }
104  return i->second;
105 }
static CursorInfo * lookup_cursor_info(const std::string &image_name)
Definition: cursors.cc:97
static void drop_cursor_info()
Definition: cursors.cc:91
LIBPBD_API Transmitter error
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:71
#define _(Text)
Definition: i18n.h:11
static Infos infos
Definition: cursors.h:45
std::string name
Definition: cursors.h:37
std::map< std::string, CursorInfo * > Infos
Definition: cursors.h:44
const char * name
static int load_cursor_info(const std::string &path)
Definition: cursors.cc:42
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208
CursorInfo(const std::string &image_name, int hotspot_x, int hotspot_y)
Definition: cursors.cc:34