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;}
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;
257 bool resize(
int new_size);
272 bool erase(
const std::string name);
274 static int calculate_memory(
int width,
int height,
int mode,
bool withPalette);
294 SPA_INVERT, SPA_NONE, SPA_AND_NOT, SPA_OR_NOT, SPA_USE_MASK};
306 virtual void plot(
int x,
int y)
const;
307 virtual void plot(
const Point &pos)
const;
343 virtual void plot_raw(
int x,
int y,
int code = SPA_USE_MASK)
const = 0;
364 virtual void plot_screen(
int x,
int y,
int code = SPA_USE_MASK)
const = 0;
371 virtual std::string
name()
const = 0;
422 int mode()
const {
int m;
info(NULL, &m);
return m;};
473 virtual void plot_raw(
const Point &pos,
int code = SPA_USE_MASK)
const;
476 virtual void plot_raw(
int x,
int y,
int code = SPA_USE_MASK)
const;
478 virtual void plot_screen(
int x,
int y,
int code = SPA_USE_MASK)
const;
480 virtual std::string
name()
const;
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;
635 WimpSprite(
int file_type, std::string leafname);
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;
648 virtual std::string
name()
const {
return _name;}
ColourPalette(int size=0)
Construct a colour palette of a specified size.
Definition: sprite.cc:1476
int * OsSpriteAreaPtr
Type for pointer to underlying RISC OS Sprite area.
Definition: sprite.h:214
A SpriteArea holds zero or more user sprites.
Definition: sprite.h:232
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.
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.
SpriteFormat
Standard sprite formats (colour <= 256)
Definition: sprite.h:152
~SpriteCapture()
Sprite capture destructor.
Definition: sprite.cc:1619
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
bool is_valid() const
Returns true if area is valid.
Definition: sprite.h:247
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
UserSprite operator*()
Get the sprite the iterator is pointing at.
Definition: sprite.h:556
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
bool operator==(const UserSprite &other) const
Check if two sprite classes refer to the same underlying sprite.
Definition: sprite.h:461
OsSpritePtr pointer() const
Return pointer to underlying RISC OS sprite.
Definition: sprite.h:512
bool exist() const
Check if this sprite exists in the Wimp sprite area.
Definition: sprite.cc:1726
Exception thrown for sprite method failures.
Definition: sprite.h:196
int pixel(int x, int y) const
Get pixel at given location.
Definition: sprite.cc:518
virtual void plot(int x, int y) const
Plot sprite to screen.
Definition: sprite.cc:55
bool erase(UserSprite &sprite)
Erase a sprite from the sprite area.
Definition: sprite.cc:1242
int free_space() const
Get the free space in the sprite area.
Definition: sprite.cc:1170
SpriteArea * _area
Sprite area containing this sprite.
Definition: sprite.h:530
UserSprite()
Construct an unassigned sprite.
Definition: sprite.cc:126
bool release()
Release screen output from sprite.
Definition: sprite.cc:1654
bool has_palette() const
Returns true if this sprite has a palette.
Definition: sprite.h:523
int * OsSpritePtr
Type for pointer to underlyin RISC OS sprite.
Definition: sprite.h:224
bool resize(int new_size)
Resize the sprite area.
Definition: sprite.cc:1181
const std::string & what() const
Return the error message for the exception.
Definition: sprite.h:208
WimpSprite(const std::string &sname)
Construct a WIMP sprite.
Definition: sprite.h:620
iterator end()
Return an iterator to the sprite after the last one in the sprite area.
Definition: sprite.cc:880
bool set_palette(ColourPalette &pal)
Set the sprites palette.
Definition: sprite.cc:388
Common base class for the UserSprite and WimpSprite classes.
Definition: sprite.h:301
UserSprite get_sprite(const std::string &name)
Get a sprite from this sprite area by name.
Definition: sprite.cc:747
Size pixel_size() const
Get size of the sprite in pixels.
Definition: sprite.h:416
iterator operator++()
Move to next sprite in the area.
Definition: sprite.h:547
void entry(int index, const Colour &col)
Set the specified index to the given colour.
Definition: sprite.h:91
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
virtual std::string name() const
Get the name of the sprite.
Definition: sprite.h:648
bool create_palette(bool col256=false)
Create a palette for a sprite.
Definition: sprite.cc:415
const Colour & operator[](int index) const
Get constant reference to colour in the palette.
Definition: sprite.h:83
SpriteArea()
Construct an uninitialised sprite area.
Definition: sprite.cc:648
bool save(const std::string &file_name) const
Save the sprite area to a file.
Definition: sprite.cc:1139
iterator operator++(int)
Move to next sprite in the area.
Definition: sprite.h:552
bool capture()
Capture screen output to sprite or sprites mask.
Definition: sprite.cc:1630
void resize(int new_size)
Resize the colour palette.
Definition: sprite.cc:1514
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.
Sprite from a user sprite area.
Definition: sprite.h:449
int mode() const
Get the mode of the sprite.
Definition: sprite.h:422
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 size() const
Return the size of the palette.
Definition: sprite.h:103
virtual void plot_raw(int x, int y, int code=SPA_USE_MASK) const =0
Plot sprite with no scaling or colour translation.
iterator begin()
Return an iterator to the first sprite in the sprite area.
Definition: sprite.cc:864
int size() const
Get the size of the sprite area.
Definition: sprite.cc:1160
Class to represent a RGB colour.
Definition: colour.h:44
bool get_palette(ColourPalette &pal) const
Get palette (non-flashing colours only) for this sprite.
Definition: sprite.cc:364
Iterator class for iterating through UserSprites in a sprite area.
Definition: sprite.h:538
bool has_mask() const
Check if the sprite has a mask.
Definition: sprite.h:428
SpriteCapture(UserSprite *sprite, bool start_capture=false, bool to_mask=false)
Class to capture screen output to a sprite.
Definition: sprite.cc:1597
sprite_plot_action
Enumeration of the plot actions for sprites.
Definition: sprite.h:293
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
bool has_palette() const
Check if WimpSprite is using a palette.
Definition: sprite.cc:1875
void set(OsSpriteAreaPtr data, bool ownsarea=false)
Assign this sprite area to a sprite area pointer.
Definition: sprite.cc:732
int sprite_count() const
Return the number of sprites in the sprite area.
Definition: sprite.cc:1003
Class to represent a two-dimensional size.
Definition: size.h:35
Base class image classes providing a consistent interface to plot the to the screen.
Definition: image.h:45
ColourPalette & operator=(const ColourPalette &other)
Assign to a copy of another palette.
Definition: sprite.cc:1543
Class for handling sprites from the Wimp sprite pool.
Definition: sprite.h:606
int width() const
Return the width of the sprite.
Definition: sprite.cc:88
bool operator==(const ColourPalette &other)
Check if two palettes contain all the same colours.
Definition: sprite.cc:1566
bool initialise(int size)
Initialise a new user sprite area.
Definition: sprite.cc:1027
Size size() const
Return the size of the sprite.
Definition: sprite.cc:70
virtual void plot_screen(const Point &pos, int code=SPA_USE_MASK) const
Plot sprite to screen.
Definition: sprite.cc:226
bool rename(UserSprite &sprite, const std::string &newname)
Rename a sprite in a sprite area.
Definition: sprite.cc:1218
SpriteColours
Sprite colour constant.
Definition: sprite.h:170
virtual bool info(Size *pixel_size, int *mode=NULL, bool *mask=NULL) const =0
Get information about the sprite.
virtual bool info(Size *pixel_size, int *mode=NULL, bool *mask=NULL) const
Get information about the sprite.
Definition: sprite.cc:326
OsSpriteAreaPtr pointer() const
Return pointer to underlying sprite are that can be used when using low-level area manipulation.
Definition: sprite.h:268
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
Class to represent a position in two dimensional space.
Definition: point.h:37
const OsSpriteAreaPtr WIMP_SPRITEAREA
Constant representing the WIMP sprite area.
Definition: sprite.h:219
SpriteArea * get_sprite_area() const
Return SpriteArea this sprite is from.
Definition: sprite.h:502
~SpriteArea()
Destructor deletes the RISC OS sprite area if it owns it.
Definition: sprite.cc:685
virtual bool info(Size *pixel_size, int *mode=NULL, bool *mask=NULL) const
Get information about the sprite.
Definition: sprite.cc:1894
bool operator!=(const ColourPalette &other)
Check if two palette have one or more colours different.
Definition: sprite.cc:1582
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.
bool rename(const std::string &name)
Renames the sprite.
Definition: sprite.cc:169
static int calculate_mask_size(int width, int height, int mode)
Calculate the size required for a sprite mask.
Definition: sprite.cc:927
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
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
SpriteException(const std::string &m)
Construct exception with the given message.
Definition: sprite.h:204
Colour entry(int index) const
Return the colour for the specified index.
Definition: sprite.h:98
bool load(const std::string &file_name)
Load a sprite area from a file.
Definition: sprite.cc:1073
int height() const
Return the height of the sprite.
Definition: sprite.cc:106
int offset() const
Return offset of this sprite in the sprite area.
Definition: sprite.h:507
Class for sprite ScaleFactors.
Definition: scalefactors.h:46
void clear()
Clear the sprite area, freeing memory used.
Definition: sprite.cc:1060
virtual std::string name() const =0
Get the name of the 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
Class to capture screen output to a sprite.
Definition: sprite.h:578
int _offset
offset of sprite within the sprite area
Definition: sprite.h:531
Class for a sprite colour translation table.
Definition: sprite.h:122
unsigned char * data() const
Return a pointer to the translation table data.
Definition: sprite.h:137
Colour & operator[](int index)
Get reference to colour in the palette.
Definition: sprite.h:76
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
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
bool is_valid() const
Check this sprite object is valid.
Definition: sprite.h:470
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
bool operator!=(const iterator &other) const
See if iterators are not equal.
Definition: sprite.h:568
bool create_mask()
Create a mask for the sprite.
Definition: sprite.cc:472
TranslationTable()
Construct an empty translation table.
Definition: sprite.h:127
bool operator!=(const UserSprite &other) const
Check if two sprite classes DO NOT refer to the same underlying sprite.
Definition: sprite.h:465
bool operator==(const iterator &other) const
See if iterators are equal.
Definition: sprite.h:562
const Colour * address() const
Get a pointer to the array of colours.
Definition: sprite.h:107
void desktop_palette()
Convert this palette to the current desktop palette.
Definition: sprite.cc:1525
WimpSprite(const char *sname)
Construct a WIMP sprite.
Definition: sprite.h:633
bool remove_mask()
Remove sprite mask.
Definition: sprite.cc:497
bool is_capturing()
Check if this capture is capturing to the sprite.
Definition: sprite.h:595
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
virtual void plot_screen(const Point &pos, int code=SPA_USE_MASK) const
Plot sprite to screen.
Definition: sprite.cc:1783
SpriteArea & operator=(const SpriteArea &other)
Deletes current area and replaces it with a copy of the given area.
Definition: sprite.cc:711
static int calculate_memory(int width, int height, int mode, bool withPalette)
Calculate the memory required to create a sprite.
Definition: sprite.cc:894
int sprite_mode(SpriteColours colours, int horzDpi=90, int vertDpi=90)
Return new format sprite mode.
Definition: sprite.h:187
A class to hold a list of Colours for the a colour palette.
Definition: sprite.h:56
bool merge(const std::string &file_name)
Merge a sprite area from a file into this sprite area.
Definition: sprite.cc:1107
virtual std::string name() const
Get the name of the sprite.
Definition: sprite.cc:310
bool mask_pixel(int x, int y) const
Check is mask pixel is set at given location.
Definition: sprite.cc:604
const int SPRITE_NAMELEN
Maximum length of a sprite name including a terminating character 0.
Definition: sprite.h:48
virtual void plot_raw(const Point &pos, int code=SPA_USE_MASK) const =0
Plot sprite with no scaling or colour translation.
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
virtual void plot_scaled(const Point &pos, const ScaleFactors *sf, const TranslationTable *tt=0, int code=SPA_USE_MASK) const =0
Plot sprite scaled.