GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_graphics_toolkit_h)
27 #define octave_graphics_toolkit_h 1
28 
29 #include "octave-config.h"
30 
31 #include <map>
32 #include <memory>
33 #include <string>
34 
35 #include "dMatrix.h"
36 
37 #include "Cell.h"
38 #include "error.h"
39 #include "graphics-handle.h"
40 
41 class graphics_object;
42 
43 namespace octave
44 {
45  class graphics_toolkit;
46 
48  {
49  public:
50 
51  friend class graphics_toolkit;
52 
53  public:
54 
55  base_graphics_toolkit (const std::string& nm)
56  : m_name (nm)
57  { }
58 
59  virtual ~base_graphics_toolkit (void) = default;
60 
61  std::string get_name (void) const
62  {
63  return m_name;
64  }
65 
66  virtual bool is_valid (void) const
67  {
68  return false;
69  }
70 
71  virtual void redraw_figure (const graphics_object&) const
72  {
73  gripe_if_tkit_invalid ("redraw_figure");
74  }
75 
76  virtual void show_figure (const graphics_object&) const
77  {
78  gripe_if_tkit_invalid ("show_figure");
79  }
80 
81  virtual void print_figure (const graphics_object&, const std::string&,
82  const std::string&,
83  const std::string& = "") const
84  {
85  gripe_if_tkit_invalid ("print_figure");
86  }
87 
88  virtual uint8NDArray get_pixels (const graphics_object&) const
89  {
90  gripe_if_tkit_invalid ("get_pixels");
91  return uint8NDArray ();
92  }
93 
94  virtual Matrix get_canvas_size (const graphics_handle&) const
95  {
96  gripe_if_tkit_invalid ("get_canvas_size");
97  return Matrix (1, 2, 0.0);
98  }
99 
100  virtual double get_screen_resolution (void) const
101  {
102  gripe_if_tkit_invalid ("get_screen_resolution");
103  return 72.0;
104  }
105 
106  virtual Matrix get_screen_size (void) const
107  {
108  gripe_if_tkit_invalid ("get_screen_size");
109  return Matrix (1, 2, 0.0);
110  }
111 
112  virtual Matrix get_text_extent (const graphics_object&) const
113  {
114  gripe_if_tkit_invalid ("get_text_extent");
115  return Matrix ();
116  }
117 
118  // Callback function executed when the given graphics object
119  // changes. This allows the graphics toolkit to act on property
120  // changes if needed.
121  virtual void update (const graphics_object&, int)
122  {
123  gripe_if_tkit_invalid ("base_graphics_toolkit::update");
124  }
125 
126  void update (const graphics_handle&, int);
127 
128  // Callback function executed when the given graphics object is
129  // created. This allows the graphics toolkit to do toolkit-specific
130  // initializations for a newly created object.
131  virtual bool initialize (const graphics_object&)
132  {
133  gripe_if_tkit_invalid ("base_graphics_toolkit::initialize");
134  return false;
135  }
136 
137  bool initialize (const graphics_handle&);
138 
139  // Callback function executed just prior to deleting the given
140  // graphics object. This allows the graphics toolkit to perform
141  // toolkit-specific cleanup operations before an object is deleted.
142  virtual void finalize (const graphics_object&)
143  {
144  gripe_if_tkit_invalid ("base_graphics_toolkit::finalize");
145  }
146 
147  void finalize (const graphics_handle&);
148 
149  // Close the graphics toolkit.
150  virtual void close (void)
151  {
152  gripe_if_tkit_invalid ("base_graphics_toolkit::close");
153  }
154 
155  private:
156 
157  std::string m_name;
158 
159  private:
160 
161  void gripe_if_tkit_invalid (const std::string& fname) const
162  {
163  if (! is_valid ())
164  error ("%s: invalid graphics toolkit", fname.c_str ());
165  }
166  };
167 
169  {
170  public:
171  graphics_toolkit (const std::string& name = "unknown")
173  { }
174 
175  // NEW_REP must be dynamically allocated.
177  : m_rep (std::shared_ptr<base_graphics_toolkit> (new_rep))
178  {
179  if (! m_rep)
180  error ("invalid graphics_toolkit!");
181  }
182 
183  graphics_toolkit (const graphics_toolkit& b) = default;
184 
186 
187  ~graphics_toolkit (void) = default;
188 
189  operator bool (void) const
190  {
191  return m_rep->is_valid ();
192  }
193 
194  std::string get_name (void) const
195  {
196  return m_rep->get_name ();
197  }
198 
199  void redraw_figure (const graphics_object& go) const
200  {
201  m_rep->redraw_figure (go);
202  }
203 
204  void show_figure (const graphics_object& go) const
205  {
206  m_rep->show_figure (go);
207  }
208 
209  void print_figure (const graphics_object& go, const std::string& term,
210  const std::string& file,
211  const std::string& debug_file = "") const
212  {
213  m_rep->print_figure (go, term, file, debug_file);
214  }
215 
217  {
218  return m_rep->get_pixels (go);
219  }
220 
222  {
223  return m_rep->get_canvas_size (fh);
224  }
225 
226  double get_screen_resolution (void) const
227  {
228  return m_rep->get_screen_resolution ();
229  }
230 
231  Matrix get_screen_size (void) const
232  {
233  return m_rep->get_screen_size ();
234  }
235 
237  {
238  return m_rep->get_text_extent (go);
239  }
240 
241  // Notifies graphics toolkit that object't property has changed.
242  void update (const graphics_object& go, int id)
243  {
244  m_rep->update (go, id);
245  }
246 
247  void update (const graphics_handle& h, int id)
248  {
249  m_rep->update (h, id);
250  }
251 
252  // Notifies graphics toolkit that new object was created.
253  bool initialize (const graphics_object& go)
254  {
255  return m_rep->initialize (go);
256  }
257 
258  bool initialize (const graphics_handle& h)
259  {
260  return m_rep->initialize (h);
261  }
262 
263  // Notifies graphics toolkit that object was destroyed.
264  // This is called only for explicitly deleted object.
265  // Children are deleted implicitly and graphics toolkit isn't notified.
266  void finalize (const graphics_object& go)
267  {
268  m_rep->finalize (go);
269  }
270 
271  void finalize (const graphics_handle& h)
272  {
273  m_rep->finalize (h);
274  }
275 
276  // Close the graphics toolkit.
277  void close (void)
278  {
279  m_rep->close ();
280  }
281 
282  private:
283 
284  std::shared_ptr<base_graphics_toolkit> m_rep;
285  };
286 }
287 
288 OCTAVE_DEPRECATED (6, "use 'octave::graphics_toolkit' instead")
290 
291 OCTAVE_DEPRECATED (6, "use 'octave::base_graphics_toolkit' instead")
293 
294 #endif
Definition: dMatrix.h:42
virtual Matrix get_canvas_size(const graphics_handle &) const
base_graphics_toolkit(const std::string &nm)
virtual ~base_graphics_toolkit(void)=default
std::string get_name(void) const
virtual void update(const graphics_object &, int)
virtual void show_figure(const graphics_object &) const
virtual bool is_valid(void) const
virtual uint8NDArray get_pixels(const graphics_object &) const
virtual Matrix get_text_extent(const graphics_object &) const
virtual double get_screen_resolution(void) const
virtual Matrix get_screen_size(void) const
void gripe_if_tkit_invalid(const std::string &fname) const
virtual void redraw_figure(const graphics_object &) const
virtual void print_figure(const graphics_object &, const std::string &, const std::string &, const std::string &="") const
virtual void finalize(const graphics_object &)
virtual bool initialize(const graphics_object &)
Matrix get_text_extent(const graphics_object &go) const
~graphics_toolkit(void)=default
graphics_toolkit(const std::string &name="unknown")
graphics_toolkit(const graphics_toolkit &b)=default
void redraw_figure(const graphics_object &go) const
bool initialize(const graphics_object &go)
std::string get_name(void) const
void finalize(const graphics_object &go)
Matrix get_canvas_size(const graphics_handle &fh) const
graphics_toolkit(base_graphics_toolkit *new_rep)
uint8NDArray get_pixels(const graphics_object &go) const
void update(const graphics_handle &h, int id)
void finalize(const graphics_handle &h)
bool initialize(const graphics_handle &h)
void print_figure(const graphics_object &go, const std::string &term, const std::string &file, const std::string &debug_file="") const
void update(const graphics_object &go, int id)
void show_figure(const graphics_object &go) const
std::shared_ptr< base_graphics_toolkit > m_rep
graphics_toolkit & operator=(const graphics_toolkit &b)=default
double get_screen_resolution(void) const
Matrix get_screen_size(void) const
void error(const char *fmt,...)
Definition: error.cc:968
QString name
intNDArray< octave_uint8 > uint8NDArray
Definition: uint8NDArray.h:36