Stellarium 0.15.2
ScreenImageMgr.hpp
1 /*
2  * Stellarium
3  * This file Copyright (C) 2008 Matthew Gates
4  * Parts copyright (C) 2016 Georg Zotti (added size transitions)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
19  */
20 
21 #ifndef _SCREENIMAGEMGR_HPP_
22 #define _SCREENIMAGEMGR_HPP_
23 
24 
25 #include "StelModule.hpp"
26 #include "StelTextureTypes.hpp"
27 #include "VecMath.hpp"
28 
29 #include <QMap>
30 #include <QString>
31 #include <QStringList>
32 #include <QSize>
33 
34 class StelCore;
35 class QGraphicsPixmapItem;
36 class QTimeLine;
37 class QGraphicsItemAnimation;
38 
39 // base class for different image types
40 class ScreenImage : public QObject
41 {
42  Q_OBJECT
43 
44 public:
56  ScreenImage(const QString& filename, float x, float y, bool show=false, float scale=1., float alpha=1., float fadeDuration=1.);
57  virtual ~ScreenImage();
58 
61  virtual bool draw(const StelCore* core);
63  virtual void update(double deltaTime);
65  virtual void setFadeDuration(float duration);
68  virtual void setFlagShow(bool b);
70  virtual bool getFlagShow(void);
71 
75  virtual void setAlpha(float a);
76 
81  virtual void setXY(float x, float y, float duration=0.);
82 
87  virtual void addXY(float x, float y, float duration=0.);
88  virtual int imageHeight(void);
89  virtual int imageWidth(void);
90 
95  virtual void setScale(float scaleX, float scaleY, float duration=0.);
96  virtual float imageScaleX(void);
97  virtual float imageScaleY(void);
98 
99 protected:
100  QGraphicsPixmapItem* tex;
101  QTimeLine* moveTimer; // for position changes
102  QTimeLine* fadeTimer; // for transparency
103  QTimeLine* scaleTimer; // for grow/shrink
104  QGraphicsItemAnimation* anim;
105  QGraphicsItemAnimation* scaleAnim;
106 
107 private slots:
108  void setOpacity(qreal alpha);
109 
110 private:
111  float maxAlpha;
112 
113 };
114 
122 {
123  Q_OBJECT
124 
125 public:
127  ScreenImageMgr();
128  virtual ~ScreenImageMgr();
129 
131  // Methods defined in the StelModule class
132  virtual void init();
133  virtual void draw(StelCore* core);
135  virtual void update(double deltaTime);
137  virtual double getCallOrder(StelModuleActionName actionName) const;
138 
139 public slots:
151  void createScreenImage(const QString& id,
152  const QString& filename,
153  float x,
154  float y,
155  float scale=1.,
156  bool visible=true,
157  float alpha=1.,
158  float fadeDuration=1.);
159 
163  bool getShowImage(const QString& id);
167  void showImage(const QString& id, bool show);
170  int getImageWidth(const QString& id);
173  int getImageHeight(const QString& id);
174 
180  void setImageScale(const QString& id, float scaleX, float scaleY, float duration=0.);
183  float getImageScaleX(const QString& id);
186  float getImageScaleY(const QString& id);
190  void setImageAlpha(const QString& id, float alpha);
196  void setImageXY(const QString& id, float x, float y, float duration=0.);
202  void addImageXY(const QString& id, float x, float y, float duration=0.);
205  void deleteImage(const QString& id);
207  void deleteAllImages(void);
209  QStringList getAllImageIDs(void);
210 
211 private:
212  QMap<QString, ScreenImage*> allScreenImages;
213 };
214 
215 #endif // _SCREENIMAGEMGR_HPP_
virtual bool getFlagShow(void)
Get the displayed status of the image.
virtual void setScale(float scaleX, float scaleY, float duration=0.)
Set the image scale relative to the size originally loaded.
Module for managing images for scripting.
virtual bool draw(const StelCore *core)
Draw the image.
Define the StelTextureSP type.
virtual void setFadeDuration(float duration)
Set the duration used for the fade in / fade out of the image.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
virtual void setXY(float x, float y, float duration=0.)
Set the x, y position of the image.
virtual void setFlagShow(bool b)
Show or hide the image (it will fade in/out)
virtual void addXY(float x, float y, float duration=0.)
Set the x, y position of the image relative to the current position.
virtual void setAlpha(float a)
Set the image alpha for when it is in full "on" (after fade in).
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
ScreenImage(const QString &filename, float x, float y, bool show=false, float scale=1., float alpha=1., float fadeDuration=1.)
Load an image.
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
virtual void update(double deltaTime)
Empty dummy. The various animations are updated by other means.