GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
graphics-toolkit.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2007-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_graphics_toolkit_h)
24 #define octave_graphics_toolkit_h 1
25 
26 #include "octave-config.h"
27 
28 #include <map>
29 #include <string>
30 
31 #include "dMatrix.h"
32 
33 #include "Cell.h"
34 #include "error.h"
35 #include "graphics-handle.h"
36 
37 class graphics_toolkit;
38 class graphics_object;
39 
41 {
42 public:
43  friend class graphics_toolkit;
44 
45 public:
47  : name (nm), count (0) { }
48 
49  virtual ~base_graphics_toolkit (void) = default;
50 
51  std::string get_name (void) const { return name; }
52 
53  virtual bool is_valid (void) const { return false; }
54 
55  virtual void redraw_figure (const graphics_object&) const
56  { gripe_if_tkit_invalid ("redraw_figure"); }
57 
58  virtual void print_figure (const graphics_object&, const std::string&,
59  const std::string&,
60  const std::string& = "") const
61  { gripe_if_tkit_invalid ("print_figure"); }
62 
63  virtual uint8NDArray get_pixels (const graphics_object&) const
64  {
65  gripe_if_tkit_invalid ("get_pixels");
66  return uint8NDArray ();
67  }
68 
69  virtual Matrix get_canvas_size (const graphics_handle&) const
70  {
71  gripe_if_tkit_invalid ("get_canvas_size");
72  return Matrix (1, 2, 0.0);
73  }
74 
75  virtual double get_screen_resolution (void) const
76  {
77  gripe_if_tkit_invalid ("get_screen_resolution");
78  return 72.0;
79  }
80 
81  virtual Matrix get_screen_size (void) const
82  {
83  gripe_if_tkit_invalid ("get_screen_size");
84  return Matrix (1, 2, 0.0);
85  }
86 
87  // Callback function executed when the given graphics object
88  // changes. This allows the graphics toolkit to act on property
89  // changes if needed.
90  virtual void update (const graphics_object&, int)
91  { gripe_if_tkit_invalid ("base_graphics_toolkit::update"); }
92 
93  void update (const graphics_handle&, int);
94 
95  // Callback function executed when the given graphics object is
96  // created. This allows the graphics toolkit to do toolkit-specific
97  // initializations for a newly created object.
98  virtual bool initialize (const graphics_object&)
99  {
100  gripe_if_tkit_invalid ("base_graphics_toolkit::initialize");
101  return false;
102  }
103 
104  bool initialize (const graphics_handle&);
105 
106  // Callback function executed just prior to deleting the given
107  // graphics object. This allows the graphics toolkit to perform
108  // toolkit-specific cleanup operations before an object is deleted.
109  virtual void finalize (const graphics_object&)
110  { gripe_if_tkit_invalid ("base_graphics_toolkit::finalize"); }
111 
112  void finalize (const graphics_handle&);
113 
114  // Close the graphics toolkit.
115  virtual void close (void)
116  { gripe_if_tkit_invalid ("base_graphics_toolkit::close"); }
117 
118 private:
121 
122 private:
124  {
125  if (! is_valid ())
126  error ("%s: invalid graphics toolkit", fname.c_str ());
127  }
128 };
129 
131 {
132 public:
134  : rep (new base_graphics_toolkit ("unknown"))
135  {
136  rep->count++;
137  }
138 
140  : rep (b)
141  {
142  rep->count++;
143  }
144 
146  : rep (b.rep)
147  {
148  rep->count++;
149  }
150 
152  {
153  if (--rep->count == 0)
154  delete rep;
155  }
156 
158  {
159  if (rep != b.rep)
160  {
161  if (--rep->count == 0)
162  delete rep;
163 
164  rep = b.rep;
165  rep->count++;
166  }
167 
168  return *this;
169  }
170 
171  operator bool (void) const { return rep->is_valid (); }
172 
173  std::string get_name (void) const { return rep->get_name (); }
174 
175  void redraw_figure (const graphics_object& go) const
176  { rep->redraw_figure (go); }
177 
178  void print_figure (const graphics_object& go, const std::string& term,
179  const std::string& file,
180  const std::string& debug_file = "") const
181  { rep->print_figure (go, term, file, debug_file); }
182 
184  { return rep->get_pixels (go); }
185 
187  { return rep->get_canvas_size (fh); }
188 
189  double get_screen_resolution (void) const
190  { return rep->get_screen_resolution (); }
191 
192  Matrix get_screen_size (void) const
193  { return rep->get_screen_size (); }
194 
195  // Notifies graphics toolkit that object't property has changed.
196  void update (const graphics_object& go, int id)
197  { rep->update (go, id); }
198 
199  void update (const graphics_handle& h, int id)
200  { rep->update (h, id); }
201 
202  // Notifies graphics toolkit that new object was created.
203  bool initialize (const graphics_object& go)
204  { return rep->initialize (go); }
205 
207  { return rep->initialize (h); }
208 
209  // Notifies graphics toolkit that object was destroyed.
210  // This is called only for explicitly deleted object.
211  // Children are deleted implicitly and graphics toolkit isn't notified.
212  void finalize (const graphics_object& go)
213  { rep->finalize (go); }
214 
215  void finalize (const graphics_handle& h)
216  { rep->finalize (h); }
217 
218  // Close the graphics toolkit.
219  void close (void) { rep->close (); }
220 
221 private:
222 
224 };
225 
226 #endif
virtual Matrix get_canvas_size(const graphics_handle &) const
virtual Matrix get_screen_size(void) const
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:124
virtual ~base_graphics_toolkit(void)=default
fname
Definition: load-save.cc:767
virtual void update(const graphics_object &, int)
void finalize(const graphics_object &go)
intNDArray< octave_uint8 > uint8NDArray
Definition: uint8NDArray.h:33
void error(const char *fmt,...)
Definition: error.cc:578
graphics_toolkit(base_graphics_toolkit *b)
virtual void close(void)
virtual void print_figure(const graphics_object &, const std::string &, const std::string &, const std::string &="") const
virtual bool is_valid(void) const
graphics_toolkit(const graphics_toolkit &b)
bool initialize(const graphics_handle &h)
double h
Definition: graphics.cc:11808
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
void redraw_figure(const graphics_object &go) const
Matrix get_canvas_size(const graphics_handle &fh) const
std::string get_name(void) const
base_graphics_toolkit * rep
void print_figure(const graphics_object &go, const std::string &term, const std::string &file, const std::string &debug_file="") const
Definition: dMatrix.h:36
graphics_toolkit & operator=(const graphics_toolkit &b)
bool initialize(const graphics_object &go)
void gripe_if_tkit_invalid(const std::string &fname) const
virtual double get_screen_resolution(void) const
void update(const graphics_handle &h, int id)
virtual uint8NDArray get_pixels(const graphics_object &) const
void finalize(const graphics_handle &h)
base_graphics_toolkit(const std::string &nm)
virtual void finalize(const graphics_object &)
void update(const graphics_object &go, int id)
virtual void redraw_figure(const graphics_object &) const
std::string get_name(void) const
virtual bool initialize(const graphics_object &)
double get_screen_resolution(void) const
b
Definition: cellfun.cc:400
Matrix get_screen_size(void) const
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
uint8NDArray get_pixels(const graphics_object &go) const
octave::refcount< int > count