32 #include "scalefactors.h"
91 void entry(
int index,
const Colour &col) {_palette[index] = col;};
103 int size()
const {
return _size;};
137 unsigned char *
data()
const {
return _table;};
140 int initialise(
int mode);
143 unsigned char *_table;
153 SF_Colour2dpi90x45 = 0,
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
189 return (colours << 27) | (horzDpi << 1) | (vertDpi << 14) | 1;
197 std::string _message;
208 const std::string &
what()
const {
return _message;}
250 bool load(
const std::string &file_name);
251 bool merge(
const std::string &file_name);
252 bool save(
const std::string &file_name)
const;
256 bool resize(
int new_size);
271 bool erase(
const std::string name);
273 static int calculate_memory(
int width,
int height,
int mode,
bool withPalette);
293 SPA_INVERT, SPA_NONE, SPA_AND_NOT, SPA_OR_NOT, SPA_USE_MASK};
305 virtual void plot(
int x,
int y)
const;
306 virtual void plot(
const Point &pos)
const;
315 virtual void plot_raw(
const Point &pos,
int code = SPA_USE_MASK)
const = 0;
334 virtual void plot_screen(
const Point &pos,
int code = SPA_USE_MASK)
const = 0;
342 virtual void plot_raw(
int x,
int y,
int code = SPA_USE_MASK)
const = 0;
363 virtual void plot_screen(
int x,
int y,
int code = SPA_USE_MASK)
const = 0;
370 virtual std::string
name()
const = 0;
375 virtual int area_id()
const = 0;
421 int mode()
const {
int m;
info(NULL, &m);
return m;};
470 bool rename(
const std::string &name);
472 virtual void plot_raw(
const Point &pos,
int code = SPA_USE_MASK)
const;
475 virtual void plot_raw(
int x,
int y,
int code = SPA_USE_MASK)
const;
477 virtual void plot_screen(
int x,
int y,
int code = SPA_USE_MASK)
const;
479 virtual std::string
name()
const;
490 int pixel(
int x,
int y)
const;
491 void pixel(
int x,
int y,
int gcol);
492 void pixel(
int x,
int y,
int gcol,
int tint);
493 int pixel(
int x,
int y,
int *tint)
const;
634 WimpSprite(
int file_type, std::string leafname);
640 virtual void plot_raw(
const Point &pos,
int code = SPA_USE_MASK)
const ;
641 virtual void plot_scaled(
const Point &pos,
const ScaleFactors *sf,
const TranslationTable *tt = NULL,
int code = SPA_USE_MASK)
const;
642 virtual void plot_screen(
const Point &pos,
int code = SPA_USE_MASK)
const;
643 virtual void plot_raw(
int x,
int y,
int code = SPA_USE_MASK)
const ;
644 virtual void plot_scaled(
int x,
int y,
const ScaleFactors *sf,
const TranslationTable *tt = NULL,
int code = SPA_USE_MASK)
const;
645 virtual void plot_screen(
int x,
int y,
int code = SPA_USE_MASK)
const;
647 virtual std::string
name()
const {
return _name;}
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
int size() const
Return the size of the palette.
Definition: sprite.h:103
int * OsSpriteAreaPtr
Type for pointer to underlying RISC OS Sprite area.
Definition: sprite.h:214
bool is_valid() const
Returns true if area is valid.
Definition: sprite.h:247
int * OsSpritePtr
Type for pointer to underlyin RISC OS sprite.
Definition: sprite.h:224
Class to represent a two-dimensional size.
Definition: size.h:34
bool operator!=(const iterator &other) const
See if iterators are not equal.
Definition: sprite.h:567
bool erase(UserSprite &sprite)
Erase a sprite from the sprite area.
Definition: sprite.cc:1224
bool operator==(const iterator &other) const
See if iterators are equal.
Definition: sprite.h:561
SpriteArea * get_sprite_area() const
Return SpriteArea this sprite is from.
Definition: sprite.h:501
bool merge(const std::string &file_name)
Merge a sprite area from a file into this sprite area.
Definition: sprite.cc:1089
UserSprite()
Construct an unassigned sprite.
Definition: sprite.cc:126
virtual void plot_scaled(const Point &pos, const ScaleFactors *sf, const TranslationTable *tt=0, int code=SPA_USE_MASK) const =0
Plot sprite scaled.
virtual std::string name() const =0
Get the name of the sprite.
virtual bool info(Size *pixel_size, int *mode=NULL, bool *mask=NULL) const =0
Get information about the sprite.
int size() const
Get the size of the sprite area.
Definition: sprite.cc:1142
~SpriteCapture()
Sprite capture destructor.
Definition: sprite.cc:1601
int height() const
Return the height of the sprite.
Definition: sprite.cc:106
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
bool resize(int new_size)
Resize the sprite area.
Definition: sprite.cc:1163
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
bool operator==(const UserSprite &other) const
Check if two sprite classes refer to the same underlying sprite.
Definition: sprite.h:460
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...
int mode() const
Get the mode of the sprite.
Definition: sprite.h:421
bool mask_pixel(int x, int y) const
Check is mask pixel is set at given location.
Definition: sprite.cc:604
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
WimpSprite(const std::string &sname)
Construct a WIMP sprite.
Definition: sprite.h:619
SpriteArea()
Construct an uninitialised sprite area.
Definition: sprite.cc:648
const Colour & operator[](int index) const
Get constant reference to colour in the palette.
Definition: sprite.h:83
iterator end()
Return an iterator to the sprite after the last one in the sprite area.
Definition: sprite.cc:880
virtual void plot_raw(const Point &pos, int code=SPA_USE_MASK) const =0
Plot sprite with no scaling or colour translation.
SpriteArea * _area
Sprite area containing this sprite.
Definition: sprite.h:529
bool exist() const
Check if this sprite exists in the Wimp sprite area.
Definition: sprite.cc:1708
bool is_valid() const
Check this sprite object is valid.
Definition: sprite.h:469
iterator operator++(int)
Move to next sprite in the area.
Definition: sprite.h:551
Size size() const
Return the size of the sprite.
Definition: sprite.cc:70
UserSprite get_sprite(const std::string &name)
Get a sprite from this sprite area by name.
Definition: sprite.cc:747
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:1719
iterator begin()
Return an iterator to the first sprite in the sprite area.
Definition: sprite.cc:864
void resize(int new_size)
Resize the colour palette.
Definition: sprite.cc:1496
Sprite from a user sprite area.
Definition: sprite.h:447
bool save(const std::string &file_name) const
Save the sprite area to a file.
Definition: sprite.cc:1121
Class to capture screen output to a sprite.
Definition: sprite.h:576
ColourPalette & operator=(const ColourPalette &other)
Assign to a copy of another palette.
Definition: sprite.cc:1525
Exception thrown for sprite method failures.
Definition: sprite.h:195
bool has_palette() const
Returns true if this sprite has a palette.
Definition: sprite.h:522
bool set_palette(ColourPalette &pal)
Set the sprites palette.
Definition: sprite.cc:388
A class to hold a list of Colours for the a colour palette.
Definition: sprite.h:55
virtual bool info(Size *pixel_size, int *mode=NULL, bool *mask=NULL) const
Get information about the sprite.
Definition: sprite.cc:326
const Colour * address() const
Get a pointer to the array of colours.
Definition: sprite.h:107
int sprite_count() const
Return the number of sprites in the sprite area.
Definition: sprite.cc:1003
iterator operator++()
Move to next sprite in the area.
Definition: sprite.h:546
int pixel(int x, int y) const
Get pixel at given location.
Definition: sprite.cc:518
Base class image classes providing a consistent interface to plot the to the screen.
Definition: image.h:44
OsSpritePtr pointer() const
Return pointer to underlying RISC OS sprite.
Definition: sprite.h:511
bool initialise(int size)
Initialise a new user sprite area.
Definition: sprite.cc:1026
Class for handling sprites from the Wimp sprite pool.
Definition: sprite.h:604
void entry(int index, const Colour &col)
Set the specified index to the given colour.
Definition: sprite.h:91
Common base class for the UserSprite and WimpSprite classes.
Definition: sprite.h:299
bool create_palette(bool col256=false)
Create a palette for a sprite.
Definition: sprite.cc:415
bool release()
Release screen output from sprite.
Definition: sprite.cc:1636
SpriteFormat
Standard sprite formats (colour <= 256)
Definition: sprite.h:152
void set(OsSpriteAreaPtr data, bool ownsarea=false)
Assign this sprite area to a sprite area pointer.
Definition: sprite.cc:732
int offset() const
Return offset of this sprite in the sprite area.
Definition: sprite.h:506
Class to represent a position in two dimensional space.
Definition: point.h:36
sprite_plot_action
Enumeration of the plot actions for sprites.
Definition: sprite.h:292
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.
bool operator!=(const ColourPalette &other)
Check if two palette have one or more colours different.
Definition: sprite.cc:1564
bool operator!=(const UserSprite &other) const
Check if two sprite classes DO NOT refer to the same underlying sprite.
Definition: sprite.h:464
static int calculate_mask_size(int width, int height, int mode)
Calculate the size required for a sprite mask.
Definition: sprite.cc:927
virtual void plot_screen(const Point &pos, int code=SPA_USE_MASK) const
Plot sprite to screen.
Definition: sprite.cc:1765
const std::string & what() const
Return the error message for the exception.
Definition: sprite.h:208
bool create(int mode, const ColourPalette *pal=0)
Create a colour translation table for the given screen mode and optional palette. ...
Definition: sprite.cc:1263
bool has_mask() const
Check if the sprite has a mask.
Definition: sprite.h:427
bool get_palette(ColourPalette &pal) const
Get palette (non-flashing colours only) for this sprite.
Definition: sprite.cc:364
Colour & operator[](int index)
Get reference to colour in the palette.
Definition: sprite.h:76
virtual std::string name() const
Get the name of the sprite.
Definition: sprite.h:647
TranslationTable()
Construct an empty translation table.
Definition: sprite.h:127
unsigned char * data() const
Return a pointer to the translation table data.
Definition: sprite.h:137
virtual void plot(int x, int y) const
Plot sprite to screen.
Definition: sprite.cc:55
int _offset
offset of sprite within the sprite area
Definition: sprite.h:530
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:1842
const OsSpriteAreaPtr WIMP_SPRITEAREA
Constant representing the WIMP sprite area.
Definition: sprite.h:219
SpriteCapture(UserSprite *sprite, bool start_capture=false, bool to_mask=false)
Class to capture screen output to a sprite.
Definition: sprite.cc:1579
bool operator==(const ColourPalette &other)
Check if two palettes contain all the same colours.
Definition: sprite.cc:1548
Colour entry(int index) const
Return the colour for the specified index.
Definition: sprite.h:98
SpriteColours
Sprite colour constant.
Definition: sprite.h:170
Class for sprite ScaleFactors.
Definition: scalefactors.h:45
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
bool remove_palette()
Remove palette from a sprite.
Definition: sprite.cc:455
const int SPRITE_NAMELEN
Maximum length of a sprite name including a terminating character 0.
Definition: sprite.h:48
Class for a sprite colour translation table.
Definition: sprite.h:121
virtual void plot_screen(const Point &pos, int code=SPA_USE_MASK) const
Plot sprite to screen.
Definition: sprite.cc:226
~SpriteArea()
Destructor deletes the RISC OS sprite area if it owns it.
Definition: sprite.cc:685
OsSpriteAreaPtr pointer() const
Return pointer to underlying sprite are that can be used when using low-level area manipulation...
Definition: sprite.h:267
bool rename(const std::string &name)
Renames the sprite.
Definition: sprite.cc:169
Iterator class for iterating through UserSprites in a sprite area.
Definition: sprite.h:536
Size pixel_size() const
Get size of the sprite in pixels.
Definition: sprite.h:415
SpriteArea & operator=(const SpriteArea &other)
Deletes current area and replaces it with a copy of the given area.
Definition: sprite.cc:711
bool rename(UserSprite &sprite, const std::string &newname)
Rename a sprite in a sprite area.
Definition: sprite.cc:1200
Class to represent a RGB colour.
Definition: colour.h:43
int width() const
Return the width of the sprite.
Definition: sprite.cc:88
bool load(const std::string &file_name)
Load a sprite area from a file.
Definition: sprite.cc:1055
bool is_capturing()
Check if this capture is capturing to the sprite.
Definition: sprite.h:594
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:517
UserSprite create_sprite(const std::string &name, int width, int height, int mode, bool palette=false)
Create a new sprite.
Definition: sprite.cc:792
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:1742
bool capture()
Capture screen output to sprite or sprites mask.
Definition: sprite.cc:1612
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:658
bool remove_mask()
Remove sprite mask.
Definition: sprite.cc:497
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
SpriteException(const std::string &m)
Construct exception with the given message.
Definition: sprite.h:204
A SpriteArea holds zero or more user sprites.
Definition: sprite.h:231
int sprite_mode(SpriteColours colours, int horzDpi=90, int vertDpi=90)
Return new format sprite mode.
Definition: sprite.h:187
virtual std::string name() const
Get the name of the sprite.
Definition: sprite.cc:310
bool create_mask()
Create a mask for the sprite.
Definition: sprite.cc:472
int free_space() const
Get the free space in the sprite area.
Definition: sprite.cc:1152
UserSprite operator*()
Get the sprite the iterator is pointing at.
Definition: sprite.h:555
WimpSprite(const char *sname)
Construct a WIMP sprite.
Definition: sprite.h:632
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.
ColourPalette(int size=0)
Construct a colour palette of a specified size.
Definition: sprite.cc:1458
virtual bool info(Size *pixel_size, int *mode=NULL, bool *mask=NULL) const
Get information about the sprite.
Definition: sprite.cc:1876
bool has_palette() const
Check if WimpSprite is using a palette.
Definition: sprite.cc:1857
static int calculate_memory(int width, int height, int mode, bool withPalette)
Calculate the memory required to create a sprite.
Definition: sprite.cc:894
void desktop_palette()
Convert this palette to the current desktop palette.
Definition: sprite.cc:1507