Added CGraphic::Get and CPlayerColorGraphic::Get functions (both exposed to Lua)
This commit is contained in:
parent
9968d614e1
commit
6adaccfd9f
3 changed files with 42 additions and 0 deletions
|
@ -112,6 +112,7 @@ public:
|
|||
|
||||
static CGraphic *New(const std::string &file, int w = 0, int h = 0);
|
||||
static CGraphic *ForceNew(const std::string &file, int w = 0, int h = 0);
|
||||
static CGraphic *Get(const std::string &file);
|
||||
|
||||
static void Free(CGraphic *g);
|
||||
|
||||
|
@ -171,6 +172,7 @@ public:
|
|||
|
||||
static CPlayerColorGraphic *New(const std::string &file, int w = 0, int h = 0);
|
||||
static CPlayerColorGraphic *ForceNew(const std::string &file, int w = 0, int h = 0);
|
||||
static CPlayerColorGraphic *Get(const std::string &file);
|
||||
|
||||
CPlayerColorGraphic *Clone(bool grayscale = false) const;
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ class CGraphic
|
|||
{
|
||||
public:
|
||||
static CGraphic *New(const std::string file, int w = 0, int h = 0);
|
||||
static CGraphic *Get(const std::string file);
|
||||
static void Free(CGraphic *);
|
||||
void Load();
|
||||
void Resize(int w, int h);
|
||||
|
@ -32,6 +33,7 @@ class CPlayerColorGraphic : public CGraphic
|
|||
{
|
||||
public:
|
||||
static CPlayerColorGraphic *New(const std::string file, int w = 0, int h = 0);
|
||||
static CPlayerColorGraphic *Get(const std::string file);
|
||||
};
|
||||
|
||||
class CColor {
|
||||
|
|
|
@ -559,6 +559,44 @@ CPlayerColorGraphic *CPlayerColorGraphic::Clone(bool grayscale) const
|
|||
return g;
|
||||
}
|
||||
|
||||
/**
|
||||
** Get a graphic object.
|
||||
**
|
||||
** @param filename Filename
|
||||
**
|
||||
** @return Graphic object
|
||||
*/
|
||||
CGraphic *CGraphic::Get(const std::string &filename)
|
||||
{
|
||||
if (filename.empty()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const std::string file = LibraryFileName(filename.c_str());
|
||||
CGraphic *&g = GraphicHash[file];
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
/**
|
||||
** Get a player color graphic object.
|
||||
**
|
||||
** @param filename Filename
|
||||
**
|
||||
** @return Graphic object
|
||||
*/
|
||||
CPlayerColorGraphic *CPlayerColorGraphic::Get(const std::string &filename)
|
||||
{
|
||||
if (filename.empty()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const std::string file = LibraryFileName(filename.c_str());
|
||||
CPlayerColorGraphic *g = dynamic_cast<CPlayerColorGraphic *>(GraphicHash[file]);
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
/**
|
||||
** Make a new player color graphic object. Don't reuse a graphic from the
|
||||
** hash table.
|
||||
|
|
Loading…
Reference in a new issue