GNU Octave  8.1.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-2023 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 
42 
43 class graphics_object;
44 class graphics_toolkit;
45 
47 {
48 public:
49 
50  friend class graphics_toolkit;
51 
52 public:
53 
54  base_graphics_toolkit (const std::string& nm)
55  : m_name (nm)
56  { }
57 
58  virtual ~base_graphics_toolkit (void) = default;
59 
60  std::string get_name (void) const
61  {
62  return m_name;
63  }
64 
65  virtual bool is_valid (void) const
66  {
67  return false;
68  }
69 
70  virtual void redraw_figure (const graphics_object&) const
71  {
72  gripe_if_tkit_invalid ("redraw_figure");
73  }
74 
75  virtual void show_figure (const graphics_object&) const
76  {
77  gripe_if_tkit_invalid ("show_figure");
78  }
79 
80  virtual void print_figure (const graphics_object&, const std::string&,
81  const std::string&,
82  const std::string& = "") const
83  {
84  gripe_if_tkit_invalid ("print_figure");
85  }
86 
87  virtual uint8NDArray get_pixels (const graphics_object&) const
88  {
89  gripe_if_tkit_invalid ("get_pixels");
90  return uint8NDArray ();
91  }
92 
93  virtual Matrix get_canvas_size (const graphics_handle&) const
94  {
95  gripe_if_tkit_invalid ("get_canvas_size");
96  return Matrix (1, 2, 0.0);
97  }
98 
99  virtual double get_screen_resolution (void) const
100  {
101  gripe_if_tkit_invalid ("get_screen_resolution");
102  return 72.0;
103  }
104 
105  virtual Matrix get_screen_size (void) const
106  {
107  gripe_if_tkit_invalid ("get_screen_size");
108  return Matrix (1, 2, 0.0);
109  }
110 
111  virtual Matrix get_text_extent (const graphics_object&) const
112  {
113  gripe_if_tkit_invalid ("get_text_extent");
114  return Matrix ();
115  }
116 
117  // Callback function executed when the given graphics object
118  // changes. This allows the graphics toolkit to act on property
119  // changes if needed.
120  virtual void update (const graphics_object&, int)
121  {
122  gripe_if_tkit_invalid ("base_graphics_toolkit::update");
123  }
124 
125  void update (const graphics_handle&, int);
126 
127  // Callback function executed when the given graphics object is
128  // created. This allows the graphics toolkit to do toolkit-specific
129  // initializations for a newly created object.
130  virtual bool initialize (const graphics_object&)
131  {
132  gripe_if_tkit_invalid ("base_graphics_toolkit::initialize");
133  return false;
134  }
135 
136  bool initialize (const graphics_handle&);
137 
138  // Callback function executed just prior to deleting the given
139  // graphics object. This allows the graphics toolkit to perform
140  // toolkit-specific cleanup operations before an object is deleted.
141  virtual void finalize (const graphics_object&)
142  {
143  gripe_if_tkit_invalid ("base_graphics_toolkit::finalize");
144  }
145 
146  void finalize (const graphics_handle&);
147 
148  // Close the graphics toolkit.
149  virtual void close (void)
150  {
151  gripe_if_tkit_invalid ("base_graphics_toolkit::close");
152  }
153 
154 private:
155 
156  std::string m_name;
157 
158 private:
159 
160  void gripe_if_tkit_invalid (const std::string& fname) const
161  {
162  if (! is_valid ())
163  error ("%s: invalid graphics toolkit", fname.c_str ());
164  }
165 };
166 
168 {
169 public:
170  graphics_toolkit (const std::string& name = "unknown")
171  : m_rep (new base_graphics_toolkit (name))
172  { }
173 
174  // NEW_REP must be dynamically allocated.
176  : m_rep (std::shared_ptr<base_graphics_toolkit> (new_rep))
177  {
178  if (! m_rep)
179  error ("invalid graphics_toolkit!");
180  }
181 
182  graphics_toolkit (const graphics_toolkit& b) = default;
183 
185 
186  ~graphics_toolkit (void) = default;
187 
188  operator bool (void) const
189  {
190  return m_rep->is_valid ();
191  }
192 
193  std::string get_name (void) const
194  {
195  return m_rep->get_name ();
196  }
197 
198  void redraw_figure (const graphics_object& go) const
199  {
200  m_rep->redraw_figure (go);
201  }
202 
203  void show_figure (const graphics_object& go) const
204  {
205  m_rep->show_figure (go);
206  }
207 
208  void print_figure (const graphics_object& go, const std::string& term,
209  const std::string& file,
210  const std::string& debug_file = "") const
211  {
212  m_rep->print_figure (go, term, file, debug_file);
213  }
214 
215  uint8NDArray get_pixels (const graphics_object& go) const
216  {
217  return m_rep->get_pixels (go);
218  }
219 
221  {
222  return m_rep->get_canvas_size (fh);
223  }
224 
225  double get_screen_resolution (void) const
226  {
227  return m_rep->get_screen_resolution ();
228  }
229 
230  Matrix get_screen_size (void) const
231  {
232  return m_rep->get_screen_size ();
233  }
234 
235  Matrix get_text_extent (const graphics_object& go) const
236  {
237  return m_rep->get_text_extent (go);
238  }
239 
240  // Notifies graphics toolkit that object't property has changed.
241  void update (const graphics_object& go, int id)
242  {
243  m_rep->update (go, id);
244  }
245 
246  void update (const graphics_handle& h, int id)
247  {
248  m_rep->update (h, id);
249  }
250 
251  // Notifies graphics toolkit that new object was created.
252  bool initialize (const graphics_object& go)
253  {
254  return m_rep->initialize (go);
255  }
256 
257  bool initialize (const graphics_handle& h)
258  {
259  return m_rep->initialize (h);
260  }
261 
262  // Notifies graphics toolkit that object was destroyed.
263  // This is called only for explicitly deleted object.
264  // Children are deleted implicitly and graphics toolkit isn't notified.
265  void finalize (const graphics_object& go)
266  {
267  m_rep->finalize (go);
268  }
269 
270  void finalize (const graphics_handle& h)
271  {
272  m_rep->finalize (h);
273  }
274 
275  // Close the graphics toolkit.
276  void close (void)
277  {
278  m_rep->close ();
279  }
280 
281 private:
282 
283  std::shared_ptr<base_graphics_toolkit> m_rep;
284 };
285 
287 
288 #endif
OCTAVE_END_NAMESPACE(octave)
Definition: dMatrix.h:42
virtual ~base_graphics_toolkit(void)=default
virtual void update(const graphics_object &, int)
virtual Matrix get_screen_size(void) const
virtual void show_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 &)
virtual void close(void)
virtual Matrix get_text_extent(const graphics_object &) const
virtual void redraw_figure(const graphics_object &) const
virtual Matrix get_canvas_size(const graphics_handle &) const
virtual bool is_valid(void) const
std::string get_name(void) const
base_graphics_toolkit(const std::string &nm)
void gripe_if_tkit_invalid(const std::string &fname) const
virtual uint8NDArray get_pixels(const graphics_object &) const
virtual double get_screen_resolution(void) const
Matrix get_canvas_size(const graphics_handle &fh) const
graphics_toolkit(const graphics_toolkit &b)=default
void update(const graphics_object &go, int id)
void show_figure(const graphics_object &go) const
void finalize(const graphics_handle &h)
void redraw_figure(const graphics_object &go) const
bool initialize(const graphics_object &go)
std::shared_ptr< base_graphics_toolkit > m_rep
std::string get_name(void) const
void finalize(const graphics_object &go)
~graphics_toolkit(void)=default
void update(const graphics_handle &h, int id)
graphics_toolkit(const std::string &name="unknown")
void print_figure(const graphics_object &go, const std::string &term, const std::string &file, const std::string &debug_file="") const
graphics_toolkit & operator=(const graphics_toolkit &b)=default
uint8NDArray get_pixels(const graphics_object &go) const
graphics_toolkit(base_graphics_toolkit *new_rep)
double get_screen_resolution(void) const
Matrix get_text_extent(const graphics_object &go) const
Matrix get_screen_size(void) const
bool initialize(const graphics_handle &h)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition: error.cc:979
class OCTAVE_API Matrix
Definition: mx-fwd.h:31
intNDArray< octave_uint8 > uint8NDArray
Definition: uint8NDArray.h:36