ubit
uima.hpp
1 /* ***********************************************************************
2  *
3  * uima.hpp: images
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef _uima_hpp_
18 #define _uima_hpp_ 1
19 #include <ubit/udata.hpp>
20 namespace ubit {
21 
50 class UIma: public UData {
51 public:
52  UCLASS(UIma)
53 
54  UIma(int width, int height);
58  UIma(const char* filename = null, bool load_now = false);
66  UIma(const UStr& filename, bool load_now = false);
74  UIma(const char** xpm_data, bool load_now = false);
85  UIma(const char** xpm_data, UConst);
86 
87  virtual ~UIma();
88 
89  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
90 
91  UIma& operator=(const UIma& ima2);
96  void resize(int width, int height) { resize(width, height, false, false);}
101  void resize(int max_width, int max_height, bool preserve_ratio, bool dont_magnify);
110  bool rescale(float scale) {return rescale(scale, scale);}
112 
113  bool rescale(float xscale, float yscale);
115 
116  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
117 
118  virtual int read(const UStr& filename, int max_width = 0, int max_height =0);
125  virtual int read(const char* filename, int max_width = 0, int max_height =0);
132  virtual int loadFromData(const char** xpm_data);
138  virtual int loadNow();
143  bool isLoaded() const {return stat > 0;}
149  virtual void set(const UStr& filename);
150  virtual void set(const char* filename);
151  virtual void set(const char** xpm_data);
157  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
158 
159  int getWidth() const;
161 
162  int getHeight() const;
164 
165  int getBpp() const;
167 
168  int getTransparency() const;
170 
171  int getStatus() const {return stat;}
173 
174  virtual bool isPix() const {return false;}
176 
177  virtual void update();
179 
180  // - - - impl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
181 
182  int realize(int max_w = 0, int max_h = 0,
183  UDisp* disp = null, bool force_reload = true) const;
196  bool isRealized() const;
198 
199  std::list<UHardIma*>& getNatImas() const {return natimas;}
201 
202  static void getFullPath(UStr& fullpath, const char* filename);
208 #ifndef NO_DOC
209  friend class UBox;
210  friend class UHardIma;
211  friend class UPix;
212 
213  virtual void setImpl(const char* fname);
214  virtual void setImpl(const char** xpm_data);
215  virtual void setImpl(int width, int height);
216  virtual void cleanCache();
217  virtual void getSize(UUpdateContext&, UDimension&) const;
218  virtual void paint(UGraph&, UUpdateContext&, const URect&) const;
219 
220  UHardIma* getOrCreateIma(UDisp*, float xyscale) const; // not virtual!
221  UHardIma* findImaInCache(UDisp*, float xyscale) const; // not virtual!
222  UHardIma* addImaInCache(UDisp*, float xyscale) const; // not virtual!
223 
224 protected:
225  mutable std::list<UHardIma*> natimas;
226  char *name;
227  const char **data;
228  mutable signed char stat; // can have negative values
229  enum Mode {EMPTY, CREATE, READ_FROM_FILE, READ_FROM_DATA};
230  mutable char mode;
231  bool show_unknown_ima;
232 #endif
233 };
234 
235 inline UIma& uima(const UStr& filename) {return *new UIma(filename);}
237 
238 inline UIma& uima(const char* filename) {return *new UIma(filename);}
240 
241 inline UIma& uima(const char** xpm_data) {return *new UIma(xpm_data);}
243 
244 }
245 #endif
int getHeight() const
returns the image height (0 if the image is not loaded).
Definition: uima.cpp:101
virtual bool isPix() const
returns true if this UIma is in fact a UPix (that derives from UIma).
Definition: uima.hpp:174
2D Dimension.
Definition: ugeom.hpp:55
virtual int loadNow()
loads the image file that was specified by set() or by the constructor.
Definition: uima.cpp:209
std::list< UHardIma * > & getNatImas() const
[impl] returns internal implementation.
Definition: uima.hpp:199
UIma & operator=(const UIma &ima2)
copies the content of ima2 to this image.
Definition: uima.cpp:128
Image.
Definition: uima.hpp:50
Definition: uobject.hpp:282
Box container.
Definition: ubox.hpp:64
int getTransparency() const
0 (opaque), 1(bitmask) or >1(alpha channel).
Definition: uima.cpp:113
bool rescale(float scale)
rescales this image.
Definition: uima.hpp:110
class for drawing on widgets.
Definition: ugraph.hpp:44
2D Rectangle.
Definition: ugeom.hpp:165
[Impl] image implementation (encapsulates system resources).
Definition: uhardima.hpp:71
Display Context.
Definition: udisp.hpp:44
bool isLoaded() const
returns true if the image has been loaded.
Definition: uima.hpp:143
int getWidth() const
returns the image width (0 if the image is not loaded).
Definition: uima.cpp:105
virtual int read(const UStr &filename, int max_width=0, int max_height=0)
loads an image file.
Definition: uima.cpp:191
void resize(int width, int height)
resizes the image data to the specified size.
Definition: uima.hpp:96
Base class for Viewable Objects.
Definition: udata.hpp:31
int realize(int max_w=0, int max_h=0, UDisp *disp=null, bool force_reload=true) const
[impl] allocates physical resources and loads the image in memory.
Definition: uima.cpp:427
static void getFullPath(UStr &fullpath, const char *filename)
gets the full image pathname.
Definition: uima.cpp:418
bool isRealized() const
[impl] returns true if the image has been sucesfully loaded and initialized.
Definition: uima.cpp:97
int getStatus() const
returns the loading status of this image (see UFilestat)
Definition: uima.hpp:171
Definition: uupdatecontext.hpp:32
int getBpp() const
returns the number of bits per pixel (0 if the image is not loaded).
Definition: uima.cpp:109
Definition: uhardfont.hpp:31
virtual void update()
update parents&#39; views.
Definition: uima.cpp:91
Pixmap Image.
Definition: upix.hpp:31
UIma(int width, int height)
creates an empty image.
Definition: uima.cpp:69
Ubit String.
Definition: ustr.hpp:72
virtual int loadFromData(const char **xpm_data)
loads XPM data.
Definition: uima.cpp:216