The Gnome Chemistry Utils  0.12.11
glview.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  * Gnome Chemistry Utils
5  * gcu/glview.h
6  *
7  * Copyright (C) 2006-2009 Jean Bréfort <jean.brefort@normalesup.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #ifndef GCU_GL_VIEW_H
26 #define GCU_GL_VIEW_H
27 
28 #include "macros.h"
29 #include "matrix.h"
30 #include "printable.h"
31 #include <goffice/goffice.h>
32 #include <gtk/gtkwidget.h>
33 #include <map>
34 #include <string>
35 #include <stdexcept>
36 
37 extern double DefaultPsi, DefaultTheta, DefaultPhi;
38 
40 namespace gcu {
41 
42 class GLDocument;
43 
49 class GLView: public Printable
50 {
51 public:
53 
58  GLView (GLDocument* pDoc) throw (std::runtime_error);
60 
63  virtual ~GLView ();
64 
68  GtkWidget *GetWidget () {return m_pWidget;}
72  void Init ();
76  void Reshape (int width, int height);
80  void Draw ();
87  bool OnPressed (GdkEventButton *event);
96  bool OnMotion (GdkEventMotion *event);
101  void Update ();
109  void SetRotation (double psi, double theta, double phi);
120  void SaveAsImage (std::string const &filename, char const *type, std::map<std::string, std::string>& options, unsigned width, unsigned height) const;
129  GdkPixbuf *BuildPixbuf (unsigned width, unsigned height) const;
137  void DoPrint (GtkPrintOperation *print, GtkPrintContext *context, int page) const;
141  GtkWindow *GetGtkWindow () {return GTK_WINDOW (gtk_widget_get_toplevel (m_pWidget));}
149  void RenderToCairo (cairo_t *cr, unsigned width, unsigned height) const;
150 
151 private:
158  void Rotate (gdouble x, gdouble y);
159 
160 protected:
164  GtkWidget *m_pWidget;
165 
166 private:
167  bool m_bInit;
168  Matrix m_Euler;
169  int m_WindowHeight, m_WindowWidth;
170  double m_Height, m_Width, m_Near, m_Far;
171  double m_Lastx, m_Lasty;
172  static int nbViews;
173 
174 // Properties
184 GCU_PROP (double, Angle)
194 GCU_PROP (double, Psi)
204 GCU_PROP (double, Phi)
214 GCU_PROP (double, Theta)
224 GCU_PROP (float, Red)
234 GCU_PROP (float, Green)
244 GCU_PROP (float, Blue)
261 GCU_PROP (float, Alpha)
272 GCU_PROT_PROP (double, Radius);
273 };
274 
275 } // namespace gcu
276 
277 #endif // GCU_GL_VIEW_H