Stellarium 0.15.0
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:
149  void createScreenImage(const QString& id,
150  const QString& filename,
151  float x,
152  float y,
153  float scale=1.,
154  bool visible=true,
155  float alpha=1.,
156  float fadeDuration=1.);
157 
160  bool getShowImage(const QString& id);
164  void showImage(const QString& id, bool show);
167  int getImageWidth(const QString& id);
170  int getImageHeight(const QString& id);
171 
177  void setImageScale(const QString& id, float scaleX, float scaleY, float duration=0.);
180  float getImageScaleX(const QString& id);
183  float getImageScaleY(const QString& id);
187  void setImageAlpha(const QString& id, float alpha);
193  void setImageXY(const QString& id, float x, float y, float duration=0.);
199  void addImageXY(const QString& id, float x, float y, float duration=0.);
202  void deleteImage(const QString& id);
204  void deleteAllImages(void);
206  QStringList getAllImageIDs(void);
207 
208 private:
209  QMap<QString, ScreenImage*> allScreenImages;
210 };
211 
212 #endif // _SCREENIMAGEMGR_HPP_
QStringList getAllImageIDs(void)
Get a list of currently loaded image IDs.
void deleteAllImages(void)
Delete all images currently managed by ScreenImageMgr.
virtual bool getFlagShow(void)
Get the displayed status of the image.
void deleteImage(const QString &id)
Delete an 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.
float getImageScaleX(const QString &id)
Define the StelTextureSP type.
void addImageXY(const QString &id, float x, float y, float duration=0.)
Add x and y coordinate offsets to the specified image.
void showImage(const QString &id, bool show)
Set an image's visible status.
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
void setImageScale(const QString &id, float scaleX, float scaleY, float duration=0.)
Set the x and y scale for the specified image, relative to size given at load time.
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 double getCallOrder(StelModuleActionName actionName) const
Defines the order in which the various modules are drawn.
float getImageScaleY(const QString &id)
virtual void draw(StelCore *core)
Execute all the drawing functions for this module.
virtual void setAlpha(float a)
Set the image alpha for when it is in full "on" (after fade in).
virtual void init()
Initialize itself.
void setImageXY(const QString &id, float x, float y, float duration=0.)
Set the x and y coordinates for the specified image.
void setImageAlpha(const QString &id, float alpha)
Set an image's alpha value when visible.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:117
void createScreenImage(const QString &id, const QString &filename, float x, float y, float scale=1., bool visible=true, float alpha=1., float fadeDuration=1.)
Create an image from a file and display on the screen at x,y coordinates.
bool getShowImage(const QString &id)
Find out if an image is currently visible.
int getImageHeight(const QString &id)
ScreenImageMgr()
Construct a LabelMgr object.
virtual void update(double deltaTime)
Update time-dependent parts of the module.
int getImageWidth(const QString &id)
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.