tbx  0.7.6
sprite.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010-2021 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef tbx_sprite_h
26 #define tbx_sprite_h
27 
28 #include "colour.h"
29 #include "image.h"
30 #include "point.h"
31 #include "size.h"
32 #include "scalefactors.h"
33 
34 #include <string>
35 #include <map>
36 
37 namespace tbx
38 {
39  class SpriteArea;
40  class Sprite;
41  class UserSprite;
42  class WimpSprite;
43 
48  const int SPRITE_NAMELEN = 13;
49 
56  {
57  public:
58  ColourPalette(int size = 0);
59  ColourPalette(const ColourPalette &other);
60  ~ColourPalette();
61 
62  void resize(int new_size);
63 
64  void desktop_palette();
65 
66  ColourPalette &operator=(const ColourPalette &other);
67  bool operator==(const ColourPalette &other);
68  bool operator!=(const ColourPalette &other);
69 
76  Colour &operator[](int index) {return _palette[index];}
83  const Colour &operator[](int index) const {return _palette[index];}
84 
91  void entry(int index, const Colour &col) {_palette[index] = col;};
98  Colour entry(int index) const {return _palette[index];};
99 
103  int size() const {return _size;};
107  const Colour *address() const {return &_palette[0];};
108 
109  private:
110  int _size;
111  Colour *_palette;
112  };
113 
114 
122  {
123  public:
127  TranslationTable() {_table = 0;_size = 0;};
128 
129  bool create(int mode, const ColourPalette *pal = 0);
130  bool create(const UserSprite *s);
131  bool create(UserSprite *source, UserSprite *target);
132  bool create(const WimpSprite *s);
133 
137  unsigned char *data() const {return _table;};
138 
139  private:
140  int initialise(int mode);
141 
142  private:
143  unsigned char *_table;
144  int _size;
145  };
146 
147 
148 
153  SF_Colour2dpi90x45 = 0,
154  SF_Colour4dpi45 = 1,
155  SF_Colour2dpi45 = 4,
156  SF_Colour4dpi90x45 = 8,
157  SF_Colour16dpi45 = 9,
158  SF_Colour16dpi90x45 = 12,
159  SF_Colour256dpi45 = 13,
160  SF_Colour256dpi90x45 = 15,
161  SF_Colour2dpi90 = 18,
162  SF_Colour4dpi90 = 19,
163  SF_Colour16dpi90 = 20,
164  SF_Colour256dpi90 = 21
165  };
166 
171  SC_Colour2 = 1,
172  SC_Colour4 = 2,
173  SC_Colour16 = 3,
174  SC_Colour256 = 4,
175  SC_Colour32K = 5,
176  SC_Colour16M = 6
177  };
178 
187  inline int sprite_mode(SpriteColours colours, int horzDpi = 90, int vertDpi = 90)
188  {
189  return (colours << 27) | (horzDpi << 1) | (vertDpi << 14) | 1;
190  }
191 
196  {
197  std::string _message;
198  public:
204  SpriteException(const std::string &m) {_message = m;}
208  const std::string &what() const {return _message;}
209  };
210 
214  typedef int *OsSpriteAreaPtr;
215 
220 
224  typedef int *OsSpritePtr;
225 
232  {
233  public:
234  SpriteArea();
235  ~SpriteArea();
236  SpriteArea(OsSpriteAreaPtr data, bool ownsarea = false);
237  SpriteArea(int size);
238 
239  SpriteArea(const SpriteArea &other);
240  SpriteArea &operator=(const SpriteArea &other);
241 
242  void set(OsSpriteAreaPtr data, bool ownsarea = false);
243 
247  bool is_valid() const {return (_area != 0);}
248 
249  void clear();
250  bool initialise(int size);
251  bool load(const std::string &file_name);
252  bool merge(const std::string &file_name);
253  bool save(const std::string &file_name) const;
254 
255  int size() const;
256  int free_space() const;
257  bool resize(int new_size);
258 
259  int sprite_count() const;
260  UserSprite get_sprite(const std::string &name);
261  UserSprite create_sprite(const std::string &name, int width, int height, int mode, bool palette = false);
262  UserSprite create_sprite_pixels(const std::string &name, int width, int height, int mode, bool palette = false);
263 
268  OsSpriteAreaPtr pointer() const {return _area;};
269 
270  bool rename(UserSprite &sprite, const std::string &newname);
271  bool erase(UserSprite &sprite);
272  bool erase(const std::string name);
273 
274  static int calculate_memory(int width, int height, int mode, bool withPalette);
275  static int calculate_mask_size(int width, int height, int mode);
276  static int get_bits_per_pixel(int mode);
277 
278  class iterator;
279 
280  iterator begin();
281  iterator end();
282 
283  UserSprite get_sprite(OsSpritePtr sprite_ptr);
284 
285  private:
286  OsSpriteAreaPtr _area;
287  bool _owns_area;
288  };
289 
293  enum sprite_plot_action {SPA_OVERWRITE, SPA_OR, SPA_AND, SPA_XOR,
294  SPA_INVERT, SPA_NONE, SPA_AND_NOT, SPA_OR_NOT, SPA_USE_MASK};
295 
300  class Sprite : public Image
301  {
302  public:
303  virtual ~Sprite() {};
304 
305  // Image overrides
306  virtual void plot(int x, int y) const;
307  virtual void plot(const Point &pos) const;
308 
316  virtual void plot_raw(const Point &pos, int code = SPA_USE_MASK) const = 0;
327  virtual void plot_scaled(const Point &pos, const ScaleFactors *sf, const TranslationTable *tt = 0, int code = SPA_USE_MASK) const = 0;
335  virtual void plot_screen(const Point &pos, int code = SPA_USE_MASK) const = 0;
343  virtual void plot_raw(int x, int y, int code = SPA_USE_MASK) const = 0;
355  virtual void plot_scaled(int x, int y, const ScaleFactors *sf, const TranslationTable *tt = 0, int code = SPA_USE_MASK) const = 0;
364  virtual void plot_screen(int x, int y, int code = SPA_USE_MASK) const = 0;
365 
371  virtual std::string name() const = 0;
376  virtual int area_id() const = 0;
377 
389  virtual bool info(Size *pixel_size, int *mode = NULL, bool *mask = NULL) const = 0;
390 
391  // Functions using a virtual call to the derived class
397  Size size() const;
403  int width() const;
409  int height() const;
410 
416  Size pixel_size() const {Size ps; info(&ps); return ps;};
422  int mode() const {int m; info(NULL, &m); return m;};
428  bool has_mask() const {bool m; info(NULL, NULL, &m); return m;};
429 
436  virtual void get_wimp_scale(ScaleFactors &factor) const = 0;
437  };
438 
448  class UserSprite : public Sprite
449  {
450  protected:
451  UserSprite(SpriteArea *area, int offset);
452 
453  public:
454  UserSprite();
455  UserSprite(SpriteArea *area, const std::string &name);
456  virtual ~UserSprite();
457 
461  bool operator==(const UserSprite &other) const {return _offset == other._offset && _area == other._area;}
465  bool operator!=(const UserSprite &other) const {return _offset != other._offset || _area != other._area;}
466 
470  bool is_valid() const {return _area != 0 && _offset != 0;}
471  bool rename(const std::string &name);
472 
473  virtual void plot_raw(const Point &pos, int code = SPA_USE_MASK) const;
474  virtual void plot_scaled(const Point &pos, const ScaleFactors *sf, const TranslationTable *tt = 0, int code = SPA_USE_MASK) const;
475  virtual void plot_screen(const Point &pos, int code = SPA_USE_MASK) const;
476  virtual void plot_raw(int x, int y, int code = SPA_USE_MASK) const;
477  virtual void plot_scaled(int x, int y, const ScaleFactors *sf, const TranslationTable *tt = 0, int code = SPA_USE_MASK) const;
478  virtual void plot_screen(int x, int y, int code = SPA_USE_MASK) const;
479 
480  virtual std::string name() const;
481  virtual bool info(Size *pixel_size, int *mode = NULL, bool *mask = NULL) const;
482 
483  bool get_palette(ColourPalette &pal) const;
484  bool set_palette(ColourPalette &pal);
485  bool create_palette(bool col256 = false);
486  bool create_palette(ColourPalette &pal);
487  bool remove_palette();
488  bool create_mask();
489  bool remove_mask();
490 
491  int pixel(int x, int y) const;
492  void pixel(int x, int y, int gcol);
493  void pixel(int x, int y, int gcol, int tint);
494  int pixel(int x, int y, int *tint) const;
495 
496  bool mask_pixel(int x, int y) const;
497  void mask_pixel(int x, int y, bool on);
498 
502  SpriteArea *get_sprite_area() const {return _area;};
503 
507  int offset() const {return _offset;}
508 
512  OsSpritePtr pointer() const {return (OsSpritePtr)((char *)(_area->pointer()) + _offset);};
513 
518  virtual int area_id() const {return (int)(_area->pointer());}
519 
523  bool has_palette() const {return (*(pointer() + 8) > 0x2C);};
524 
525  virtual void get_wimp_scale(ScaleFactors &factor) const;
526 
527  friend class SpriteArea;
528 
529  protected:
531  int _offset;
532  };
533 
538  {
539  UserSprite _sprite;
540  friend class SpriteArea;
541 
542  public:
547  iterator operator++() {next_sprite(); return *this;}
552  iterator operator++(int) {iterator tmp(*this); next_sprite(); return tmp;}
556  UserSprite operator*() {return _sprite;}
562  bool operator==(const iterator &other) const {return _sprite == other._sprite;}
568  bool operator!=(const iterator &other) const {return _sprite != other._sprite;}
569 
570  private:
571  void next_sprite();
572  };
573 
578  {
579  char *_save_area;
580  int _save_regs[4];
581  UserSprite *_sprite;
582  bool _capturing;
583 
584  public:
585  SpriteCapture(UserSprite *sprite, bool start_capture = false, bool to_mask = false);
586  ~SpriteCapture();
587 
588  bool capture();
589  bool release();
595  bool is_capturing() {return _capturing;}
596  };
597 
605  class WimpSprite : public Sprite
606  {
607  public:
620  WimpSprite(const std::string &sname) : _name(sname) {};
633  WimpSprite(const char *sname) : _name(sname) {};
634  WimpSprite(int file_type);
635  WimpSprite(int file_type, std::string leafname);
636 
637  virtual ~WimpSprite() {};
638 
639  bool exist() const;
640 
641  virtual void plot_raw(const Point &pos, int code = SPA_USE_MASK) const ;
642  virtual void plot_scaled(const Point &pos, const ScaleFactors *sf, const TranslationTable *tt = NULL, int code = SPA_USE_MASK) const;
643  virtual void plot_screen(const Point &pos, int code = SPA_USE_MASK) const;
644  virtual void plot_raw(int x, int y, int code = SPA_USE_MASK) const ;
645  virtual void plot_scaled(int x, int y, const ScaleFactors *sf, const TranslationTable *tt = NULL, int code = SPA_USE_MASK) const;
646  virtual void plot_screen(int x, int y, int code = SPA_USE_MASK) const;
647 
648  virtual std::string name() const {return _name;}
649  virtual bool info(Size *pixel_size, int *mode = NULL, bool *mask = NULL) const;
650 
651  virtual void get_wimp_scale(ScaleFactors &factor) const;
652 
659  virtual int area_id() const {return 1;}
660 
661  bool has_palette() const;
662 
663 
664  private:
665  std::string _name;
666  };
667 };
668 
669 #endif
tbx::ColourPalette::ColourPalette
ColourPalette(int size=0)
Construct a colour palette of a specified size.
Definition: sprite.cc:1476
tbx::OsSpriteAreaPtr
int * OsSpriteAreaPtr
Type for pointer to underlying RISC OS Sprite area.
Definition: sprite.h:214
tbx::SpriteArea
A SpriteArea holds zero or more user sprites.
Definition: sprite.h:232
tbx::Sprite::plot_screen
virtual void plot_screen(int x, int y, int code=SPA_USE_MASK) const =0
Plot sprite to screen calculating the correct colour translation and scaling.
tbx::Sprite::plot_screen
virtual void plot_screen(const Point &pos, int code=SPA_USE_MASK) const =0
Plot sprite to screen calculating the correct colour translation and scaling.
tbx::SpriteFormat
SpriteFormat
Standard sprite formats (colour <= 256)
Definition: sprite.h:152
tbx::SpriteCapture::~SpriteCapture
~SpriteCapture()
Sprite capture destructor.
Definition: sprite.cc:1619
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::SpriteArea::is_valid
bool is_valid() const
Returns true if area is valid.
Definition: sprite.h:247
tbx::UserSprite::area_id
virtual int area_id() const
Return sprite area id used for calls that take an area pointer or a special value for WIMP/System are...
Definition: sprite.h:518
tbx::SpriteArea::iterator::operator*
UserSprite operator*()
Get the sprite the iterator is pointing at.
Definition: sprite.h:556
tbx::WimpSprite::plot_raw
virtual void plot_raw(const Point &pos, int code=SPA_USE_MASK) const
Plot this sprite at the given position with no scaling or colour conversions.
Definition: sprite.cc:1737
tbx::UserSprite::operator==
bool operator==(const UserSprite &other) const
Check if two sprite classes refer to the same underlying sprite.
Definition: sprite.h:461
tbx::UserSprite::pointer
OsSpritePtr pointer() const
Return pointer to underlying RISC OS sprite.
Definition: sprite.h:512
tbx::WimpSprite::exist
bool exist() const
Check if this sprite exists in the Wimp sprite area.
Definition: sprite.cc:1726
tbx::SpriteException
Exception thrown for sprite method failures.
Definition: sprite.h:196
tbx::UserSprite::pixel
int pixel(int x, int y) const
Get pixel at given location.
Definition: sprite.cc:518
tbx::Sprite::plot
virtual void plot(int x, int y) const
Plot sprite to screen.
Definition: sprite.cc:55
tbx::SpriteArea::erase
bool erase(UserSprite &sprite)
Erase a sprite from the sprite area.
Definition: sprite.cc:1242
tbx::SpriteArea::free_space
int free_space() const
Get the free space in the sprite area.
Definition: sprite.cc:1170
tbx::UserSprite::_area
SpriteArea * _area
Sprite area containing this sprite.
Definition: sprite.h:530
tbx::UserSprite::UserSprite
UserSprite()
Construct an unassigned sprite.
Definition: sprite.cc:126
tbx::SpriteCapture::release
bool release()
Release screen output from sprite.
Definition: sprite.cc:1654
tbx::UserSprite::has_palette
bool has_palette() const
Returns true if this sprite has a palette.
Definition: sprite.h:523
tbx::OsSpritePtr
int * OsSpritePtr
Type for pointer to underlyin RISC OS sprite.
Definition: sprite.h:224
tbx::SpriteArea::resize
bool resize(int new_size)
Resize the sprite area.
Definition: sprite.cc:1181
tbx::SpriteException::what
const std::string & what() const
Return the error message for the exception.
Definition: sprite.h:208
tbx::WimpSprite::WimpSprite
WimpSprite(const std::string &sname)
Construct a WIMP sprite.
Definition: sprite.h:620
tbx::SpriteArea::end
iterator end()
Return an iterator to the sprite after the last one in the sprite area.
Definition: sprite.cc:880
tbx::UserSprite::set_palette
bool set_palette(ColourPalette &pal)
Set the sprites palette.
Definition: sprite.cc:388
tbx::Sprite
Common base class for the UserSprite and WimpSprite classes.
Definition: sprite.h:301
tbx::SpriteArea::get_sprite
UserSprite get_sprite(const std::string &name)
Get a sprite from this sprite area by name.
Definition: sprite.cc:747
tbx::Sprite::pixel_size
Size pixel_size() const
Get size of the sprite in pixels.
Definition: sprite.h:416
tbx::SpriteArea::iterator::operator++
iterator operator++()
Move to next sprite in the area.
Definition: sprite.h:547
tbx::ColourPalette::entry
void entry(int index, const Colour &col)
Set the specified index to the given colour.
Definition: sprite.h:91
tbx::WimpSprite::plot_scaled
virtual void plot_scaled(const Point &pos, const ScaleFactors *sf, const TranslationTable *tt=NULL, int code=SPA_USE_MASK) const
Plot this sprite scaled using the given colour translation.
Definition: sprite.cc:1760
tbx::WimpSprite::name
virtual std::string name() const
Get the name of the sprite.
Definition: sprite.h:648
tbx::UserSprite::create_palette
bool create_palette(bool col256=false)
Create a palette for a sprite.
Definition: sprite.cc:415
tbx::ColourPalette::operator[]
const Colour & operator[](int index) const
Get constant reference to colour in the palette.
Definition: sprite.h:83
tbx::SpriteArea::SpriteArea
SpriteArea()
Construct an uninitialised sprite area.
Definition: sprite.cc:648
tbx::SpriteArea::save
bool save(const std::string &file_name) const
Save the sprite area to a file.
Definition: sprite.cc:1139
tbx::SpriteArea::iterator::operator++
iterator operator++(int)
Move to next sprite in the area.
Definition: sprite.h:552
tbx::SpriteCapture::capture
bool capture()
Capture screen output to sprite or sprites mask.
Definition: sprite.cc:1630
tbx::ColourPalette::resize
void resize(int new_size)
Resize the colour palette.
Definition: sprite.cc:1514
tbx::Sprite::get_wimp_scale
virtual void get_wimp_scale(ScaleFactors &factor) const =0
Get the scale factors required to plot this sprite in the WIMP as its logical size.
tbx::UserSprite
Sprite from a user sprite area.
Definition: sprite.h:449
tbx::Sprite::mode
int mode() const
Get the mode of the sprite.
Definition: sprite.h:422
tbx::Sprite::area_id
virtual int area_id() const =0
Return sprite area id used for calls that take an area pointer or a special value for WIMP/System are...
tbx::ColourPalette::size
int size() const
Return the size of the palette.
Definition: sprite.h:103
tbx::Sprite::plot_raw
virtual void plot_raw(int x, int y, int code=SPA_USE_MASK) const =0
Plot sprite with no scaling or colour translation.
tbx::SpriteArea::begin
iterator begin()
Return an iterator to the first sprite in the sprite area.
Definition: sprite.cc:864
tbx::SpriteArea::size
int size() const
Get the size of the sprite area.
Definition: sprite.cc:1160
tbx::Colour
Class to represent a RGB colour.
Definition: colour.h:44
tbx::UserSprite::get_palette
bool get_palette(ColourPalette &pal) const
Get palette (non-flashing colours only) for this sprite.
Definition: sprite.cc:364
tbx::SpriteArea::iterator
Iterator class for iterating through UserSprites in a sprite area.
Definition: sprite.h:538
tbx::Sprite::has_mask
bool has_mask() const
Check if the sprite has a mask.
Definition: sprite.h:428
tbx::SpriteCapture::SpriteCapture
SpriteCapture(UserSprite *sprite, bool start_capture=false, bool to_mask=false)
Class to capture screen output to a sprite.
Definition: sprite.cc:1597
tbx::sprite_plot_action
sprite_plot_action
Enumeration of the plot actions for sprites.
Definition: sprite.h:293
tbx::UserSprite::plot_raw
virtual void plot_raw(const Point &pos, int code=SPA_USE_MASK) const
Plot this sprite at the given position with no scaling or colour conversions.
Definition: sprite.cc:180
tbx::WimpSprite::has_palette
bool has_palette() const
Check if WimpSprite is using a palette.
Definition: sprite.cc:1875
tbx::SpriteArea::set
void set(OsSpriteAreaPtr data, bool ownsarea=false)
Assign this sprite area to a sprite area pointer.
Definition: sprite.cc:732
tbx::SpriteArea::sprite_count
int sprite_count() const
Return the number of sprites in the sprite area.
Definition: sprite.cc:1003
tbx::Size
Class to represent a two-dimensional size.
Definition: size.h:35
tbx::Image
Base class image classes providing a consistent interface to plot the to the screen.
Definition: image.h:45
tbx::ColourPalette::operator=
ColourPalette & operator=(const ColourPalette &other)
Assign to a copy of another palette.
Definition: sprite.cc:1543
tbx::WimpSprite
Class for handling sprites from the Wimp sprite pool.
Definition: sprite.h:606
tbx::Sprite::width
int width() const
Return the width of the sprite.
Definition: sprite.cc:88
tbx::ColourPalette::operator==
bool operator==(const ColourPalette &other)
Check if two palettes contain all the same colours.
Definition: sprite.cc:1566
tbx::SpriteArea::initialise
bool initialise(int size)
Initialise a new user sprite area.
Definition: sprite.cc:1027
tbx::Sprite::size
Size size() const
Return the size of the sprite.
Definition: sprite.cc:70
tbx::UserSprite::plot_screen
virtual void plot_screen(const Point &pos, int code=SPA_USE_MASK) const
Plot sprite to screen.
Definition: sprite.cc:226
tbx::SpriteArea::rename
bool rename(UserSprite &sprite, const std::string &newname)
Rename a sprite in a sprite area.
Definition: sprite.cc:1218
tbx::SpriteColours
SpriteColours
Sprite colour constant.
Definition: sprite.h:170
tbx::Sprite::info
virtual bool info(Size *pixel_size, int *mode=NULL, bool *mask=NULL) const =0
Get information about the sprite.
tbx::UserSprite::info
virtual bool info(Size *pixel_size, int *mode=NULL, bool *mask=NULL) const
Get information about the sprite.
Definition: sprite.cc:326
tbx::SpriteArea::pointer
OsSpriteAreaPtr pointer() const
Return pointer to underlying sprite are that can be used when using low-level area manipulation.
Definition: sprite.h:268
tbx::WimpSprite::area_id
virtual int area_id() const
Return sprite area id used for calls that take an area pointer or a special value for WIMP/System are...
Definition: sprite.h:659
tbx::Point
Class to represent a position in two dimensional space.
Definition: point.h:37
tbx::WIMP_SPRITEAREA
const OsSpriteAreaPtr WIMP_SPRITEAREA
Constant representing the WIMP sprite area.
Definition: sprite.h:219
tbx::UserSprite::get_sprite_area
SpriteArea * get_sprite_area() const
Return SpriteArea this sprite is from.
Definition: sprite.h:502
tbx::SpriteArea::~SpriteArea
~SpriteArea()
Destructor deletes the RISC OS sprite area if it owns it.
Definition: sprite.cc:685
tbx::WimpSprite::info
virtual bool info(Size *pixel_size, int *mode=NULL, bool *mask=NULL) const
Get information about the sprite.
Definition: sprite.cc:1894
tbx::ColourPalette::operator!=
bool operator!=(const ColourPalette &other)
Check if two palette have one or more colours different.
Definition: sprite.cc:1582
tbx::Sprite::plot_scaled
virtual void plot_scaled(int x, int y, const ScaleFactors *sf, const TranslationTable *tt=0, int code=SPA_USE_MASK) const =0
Plot sprite scaled.
tbx::UserSprite::rename
bool rename(const std::string &name)
Renames the sprite.
Definition: sprite.cc:169
tbx::SpriteArea::calculate_mask_size
static int calculate_mask_size(int width, int height, int mode)
Calculate the size required for a sprite mask.
Definition: sprite.cc:927
tbx::UserSprite::~UserSprite
virtual ~UserSprite()
Destructor - not this does not delete the sprite from the sprite area as this class is just a referen...
Definition: sprite.cc:160
tbx::TranslationTable::create
bool create(int mode, const ColourPalette *pal=0)
Create a colour translation table for the given screen mode and optional palette.
Definition: sprite.cc:1281
tbx::SpriteException::SpriteException
SpriteException(const std::string &m)
Construct exception with the given message.
Definition: sprite.h:204
tbx::ColourPalette::entry
Colour entry(int index) const
Return the colour for the specified index.
Definition: sprite.h:98
tbx::SpriteArea::load
bool load(const std::string &file_name)
Load a sprite area from a file.
Definition: sprite.cc:1073
tbx::Sprite::height
int height() const
Return the height of the sprite.
Definition: sprite.cc:106
tbx::UserSprite::offset
int offset() const
Return offset of this sprite in the sprite area.
Definition: sprite.h:507
tbx::ScaleFactors
Class for sprite ScaleFactors.
Definition: scalefactors.h:46
tbx::SpriteArea::clear
void clear()
Clear the sprite area, freeing memory used.
Definition: sprite.cc:1060
tbx::Sprite::name
virtual std::string name() const =0
Get the name of the sprite.
tbx::SpriteArea::create_sprite
UserSprite create_sprite(const std::string &name, int width, int height, int mode, bool palette=false)
Create a new sprite.
Definition: sprite.cc:792
tbx::SpriteCapture
Class to capture screen output to a sprite.
Definition: sprite.h:578
tbx::UserSprite::_offset
int _offset
offset of sprite within the sprite area
Definition: sprite.h:531
tbx::TranslationTable
Class for a sprite colour translation table.
Definition: sprite.h:122
tbx::TranslationTable::data
unsigned char * data() const
Return a pointer to the translation table data.
Definition: sprite.h:137
tbx::ColourPalette::operator[]
Colour & operator[](int index)
Get reference to colour in the palette.
Definition: sprite.h:76
tbx::UserSprite::get_wimp_scale
virtual void get_wimp_scale(ScaleFactors &factor) const
Get the scale factors required to plot this sprite in the WIMP as its logical size.
Definition: sprite.cc:633
tbx::SpriteArea::get_bits_per_pixel
static int get_bits_per_pixel(int mode)
Calculate the number of bits required for one pixel for the given mode.
Definition: sprite.cc:952
tbx::UserSprite::is_valid
bool is_valid() const
Check this sprite object is valid.
Definition: sprite.h:470
tbx::SpriteArea::create_sprite_pixels
UserSprite create_sprite_pixels(const std::string &name, int width, int height, int mode, bool palette=false)
Create a new sprite, size measured in pixels.
Definition: sprite.cc:810
tbx::UserSprite::remove_palette
bool remove_palette()
Remove palette from a sprite.
Definition: sprite.cc:455
tbx::SpriteArea::iterator::operator!=
bool operator!=(const iterator &other) const
See if iterators are not equal.
Definition: sprite.h:568
tbx::UserSprite::create_mask
bool create_mask()
Create a mask for the sprite.
Definition: sprite.cc:472
tbx::TranslationTable::TranslationTable
TranslationTable()
Construct an empty translation table.
Definition: sprite.h:127
tbx::UserSprite::operator!=
bool operator!=(const UserSprite &other) const
Check if two sprite classes DO NOT refer to the same underlying sprite.
Definition: sprite.h:465
tbx::SpriteArea::iterator::operator==
bool operator==(const iterator &other) const
See if iterators are equal.
Definition: sprite.h:562
tbx::ColourPalette::address
const Colour * address() const
Get a pointer to the array of colours.
Definition: sprite.h:107
tbx::ColourPalette::desktop_palette
void desktop_palette()
Convert this palette to the current desktop palette.
Definition: sprite.cc:1525
tbx::WimpSprite::WimpSprite
WimpSprite(const char *sname)
Construct a WIMP sprite.
Definition: sprite.h:633
tbx::UserSprite::remove_mask
bool remove_mask()
Remove sprite mask.
Definition: sprite.cc:497
tbx::SpriteCapture::is_capturing
bool is_capturing()
Check if this capture is capturing to the sprite.
Definition: sprite.h:595
tbx::UserSprite::plot_scaled
virtual void plot_scaled(const Point &pos, const ScaleFactors *sf, const TranslationTable *tt=0, int code=SPA_USE_MASK) const
Plot this sprite scaled using the given colour translation.
Definition: sprite.cc:203
tbx::WimpSprite::plot_screen
virtual void plot_screen(const Point &pos, int code=SPA_USE_MASK) const
Plot sprite to screen.
Definition: sprite.cc:1783
tbx::SpriteArea::operator=
SpriteArea & operator=(const SpriteArea &other)
Deletes current area and replaces it with a copy of the given area.
Definition: sprite.cc:711
tbx::SpriteArea::calculate_memory
static int calculate_memory(int width, int height, int mode, bool withPalette)
Calculate the memory required to create a sprite.
Definition: sprite.cc:894
tbx::sprite_mode
int sprite_mode(SpriteColours colours, int horzDpi=90, int vertDpi=90)
Return new format sprite mode.
Definition: sprite.h:187
tbx::ColourPalette
A class to hold a list of Colours for the a colour palette.
Definition: sprite.h:56
tbx::SpriteArea::merge
bool merge(const std::string &file_name)
Merge a sprite area from a file into this sprite area.
Definition: sprite.cc:1107
tbx::UserSprite::name
virtual std::string name() const
Get the name of the sprite.
Definition: sprite.cc:310
tbx::UserSprite::mask_pixel
bool mask_pixel(int x, int y) const
Check is mask pixel is set at given location.
Definition: sprite.cc:604
tbx::SPRITE_NAMELEN
const int SPRITE_NAMELEN
Maximum length of a sprite name including a terminating character 0.
Definition: sprite.h:48
tbx::Sprite::plot_raw
virtual void plot_raw(const Point &pos, int code=SPA_USE_MASK) const =0
Plot sprite with no scaling or colour translation.
tbx::WimpSprite::get_wimp_scale
virtual void get_wimp_scale(ScaleFactors &factor) const
Get the scale factors required to plot this sprite in the WIMP as its logical size.
Definition: sprite.cc:1860
tbx::Sprite::plot_scaled
virtual void plot_scaled(const Point &pos, const ScaleFactors *sf, const TranslationTable *tt=0, int code=SPA_USE_MASK) const =0
Plot sprite scaled.