git repos / blockattack-game

blame: source/code/CppSdlImageHolder.hpp

normal view · raw

c53e6443 sago007 2012-04-17 11:04 1
/*
c53e6443 sago007 2012-04-17 11:04 2
===========================================================================
c53e6443 sago007 2012-04-17 11:04 3
blockattack - Block Attack - Rise of the Blocks
c53e6443 sago007 2012-04-17 11:04 4
Copyright (C) 2005-2012 Poul Sander
c53e6443 sago007 2012-04-17 11:04 5
c53e6443 sago007 2012-04-17 11:04 6
This program is free software: you can redistribute it and/or modify
c53e6443 sago007 2012-04-17 11:04 7
it under the terms of the GNU General Public License as published by
c53e6443 sago007 2012-04-17 11:04 8
the Free Software Foundation, either version 2 of the License, or
c53e6443 sago007 2012-04-17 11:04 9
(at your option) any later version.
c53e6443 sago007 2012-04-17 11:04 10
c53e6443 sago007 2012-04-17 11:04 11
This program is distributed in the hope that it will be useful,
c53e6443 sago007 2012-04-17 11:04 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
c53e6443 sago007 2012-04-17 11:04 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c53e6443 sago007 2012-04-17 11:04 14
GNU General Public License for more details.
c53e6443 sago007 2012-04-17 11:04 15
c53e6443 sago007 2012-04-17 11:04 16
You should have received a copy of the GNU General Public License
c53e6443 sago007 2012-04-17 11:04 17
along with this program.  If not, see http://www.gnu.org/licenses/
c53e6443 sago007 2012-04-17 11:04 18
c53e6443 sago007 2012-04-17 11:04 19
Source information and contacts persons can be found at
c53e6443 sago007 2012-04-17 11:04 20
http://blockattack.sf.net
c53e6443 sago007 2012-04-17 11:04 21
===========================================================================
c53e6443 sago007 2012-04-17 11:04 22
*/
3db6ed5d sago007 2010-12-07 17:19 23
3db6ed5d sago007 2010-12-07 17:19 24
#ifndef _CPPSDLIMAGEHOLDER_HPP
3db6ed5d sago007 2010-12-07 17:19 25
#define	_CPPSDLIMAGEHOLDER_HPP
3db6ed5d sago007 2010-12-07 17:19 26
3db6ed5d sago007 2010-12-07 17:19 27
#include "SDL.h"
3db6ed5d sago007 2010-12-07 17:19 28
#include <string>
3db6ed5d sago007 2010-12-07 17:19 29
#include "CppSdlException.hpp"
3db6ed5d sago007 2010-12-07 17:19 30
c53e6443 sago007 2012-04-17 11:04 31
namespace CppSdl
c53e6443 sago007 2012-04-17 11:04 32
{
3db6ed5d sago007 2010-12-07 17:19 33
c53e6443 sago007 2012-04-17 11:04 34
class CppSdlImageHolder
c53e6443 sago007 2012-04-17 11:04 35
{
3db6ed5d sago007 2010-12-07 17:19 36
public:
c53e6443 sago007 2012-04-17 11:04 37
	/**
c53e6443 sago007 2012-04-17 11:04 38
	 * Creates a nulled ImageHolder (without data)
c53e6443 sago007 2012-04-17 11:04 39
	 */
c53e6443 sago007 2012-04-17 11:04 40
	CppSdlImageHolder();
c53e6443 sago007 2012-04-17 11:04 41
	/**
c53e6443 sago007 2012-04-17 11:04 42
	 * Creates an image from a file
c53e6443 sago007 2012-04-17 11:04 43
	 * @param filename to be loaded
c53e6443 sago007 2012-04-17 11:04 44
	 */
c53e6443 sago007 2012-04-17 11:04 45
	CppSdlImageHolder(std::string filename);
c53e6443 sago007 2012-04-17 11:04 46
	/**
c53e6443 sago007 2012-04-17 11:04 47
	 * Creates a copy. The new copy shares raw data with the original but is otherwise independent.
c53e6443 sago007 2012-04-17 11:04 48
	 * @param orig
c53e6443 sago007 2012-04-17 11:04 49
	 */
f3a1637d sago007 2015-11-14 21:32 50
	CppSdlImageHolder(const CppSdlImageHolder& orig) = delete;
c53e6443 sago007 2012-04-17 11:04 51
	CppSdlImageHolder(char *rawdata, int datasize);
f3a1637d sago007 2015-11-14 21:32 52
	~CppSdlImageHolder();
c53e6443 sago007 2012-04-17 11:04 53
	/**
c53e6443 sago007 2012-04-17 11:04 54
	 * This gives access direct access to the internal data.
c53e6443 sago007 2012-04-17 11:04 55
	 * Careful, the data might be shared between multiple ImageHolders,
c53e6443 sago007 2012-04-17 11:04 56
	 * chaing one will change them all.
c53e6443 sago007 2012-04-17 11:04 57
	 * @return A pointer
c53e6443 sago007 2012-04-17 11:04 58
	 */
c53e6443 sago007 2012-04-17 11:04 59
	SDL_Surface *GetRawDataInsecure();
f3a1637d sago007 2015-11-14 21:32 60
	CppSdlImageHolder & operator=(const CppSdlImageHolder &rhs) = delete;
c53e6443 sago007 2012-04-17 11:04 61
	/**
c53e6443 sago007 2012-04-17 11:04 62
	 * The width of the image
c53e6443 sago007 2012-04-17 11:04 63
	 * 0 if the image is nulled
c53e6443 sago007 2012-04-17 11:04 64
	 * @return The width of the image in pizels
c53e6443 sago007 2012-04-17 11:04 65
	 */
c53e6443 sago007 2012-04-17 11:04 66
	Uint32 GetWidth();
c53e6443 sago007 2012-04-17 11:04 67
	/**
c53e6443 sago007 2012-04-17 11:04 68
	 * The height of the image
c53e6443 sago007 2012-04-17 11:04 69
	 * 0 if the image is nulled
c53e6443 sago007 2012-04-17 11:04 70
	 * @return  The height of the image
c53e6443 sago007 2012-04-17 11:04 71
	 */
c53e6443 sago007 2012-04-17 11:04 72
	Uint32 GetHeight();
c53e6443 sago007 2012-04-17 11:04 73
	/**
c53e6443 sago007 2012-04-17 11:04 74
	 * Draws an image to surface at a given position.
c53e6443 sago007 2012-04-17 11:04 75
	 * If the image is nulled nothing is drawn
c53e6443 sago007 2012-04-17 11:04 76
	 * @param target Destination surface
c53e6443 sago007 2012-04-17 11:04 77
	 * @param x horizontal placement on destination surface
c53e6443 sago007 2012-04-17 11:04 78
	 * @param y vertical placement on destination surface
c53e6443 sago007 2012-04-17 11:04 79
	 */
c53e6443 sago007 2012-04-17 11:04 80
	void PaintTo(SDL_Surface *target, int x, int y);
c53e6443 sago007 2012-04-17 11:04 81
	void OptimizeForBlit(bool allowAlpha = true);
c53e6443 sago007 2012-04-17 11:04 82
	/**
c53e6443 sago007 2012-04-17 11:04 83
	 * Tests if there are data in the object
c53e6443 sago007 2012-04-17 11:04 84
	 * @return true if where are data in the object
c53e6443 sago007 2012-04-17 11:04 85
	 */
c53e6443 sago007 2012-04-17 11:04 86
	bool IsNull();
c53e6443 sago007 2012-04-17 11:04 87
	/**
c53e6443 sago007 2012-04-17 11:04 88
	 * Removes the data in the object.
c53e6443 sago007 2012-04-17 11:04 89
	 * Once all ImageHolders pointing to the same data has been freed the internal data will be freed too
c53e6443 sago007 2012-04-17 11:04 90
	 */
c53e6443 sago007 2012-04-17 11:04 91
	void MakeNull();
3db6ed5d sago007 2010-12-07 17:19 92
private:
c53e6443 sago007 2012-04-17 11:04 93
	void Initialized(); //throws an exception if *data is null
c53e6443 sago007 2012-04-17 11:04 94
	SDL_Rect area;
c53e6443 sago007 2012-04-17 11:04 95
	SDL_Surface *data;
3db6ed5d sago007 2010-12-07 17:19 96
};
3db6ed5d sago007 2010-12-07 17:19 97
3db6ed5d sago007 2010-12-07 17:19 98
}
3db6ed5d sago007 2010-12-07 17:19 99
#endif	/* _CPPSDLIMAGEHOLDER_HPP */
3db6ed5d sago007 2010-12-07 17:19 100
1970-01-01 00:00 101