📄 graphicentity.h.svn-base
字号:
#ifndef COMMON_GRAPHIC_ENTITY_H
#define COMMON_GRAPHIC_ENTITY_H
#include <vector>
#include <string>
#include "hgeCurvedani.h"
#include "caPoint2d.h"
#include "caRect.h"
#include "common/utils.h"
#include "common/entity.h"
using std::vector;
using std::string;
using cAni::iAnimation;
using cAni::Point2f;
using cAni::Rectf;
class hgeFont;
struct GfxObj
{
public:
enum Type
{
T_Anim,
T_Line,
T_Text,
T_Triple,
T_Quad,
NumTypes,
};
Type type;
bool screenPos;
Point2f a, b;
float direction;
int frame;
const iAnimation *anim;
string str;
hgeFont *font;
int align;
DWORD color;
hgeTriple triple;
hgeQuad quad;
};
class iGraphicEntity : public Entity::iEntity
{
public:
iGraphicEntity(Entity &e, cAni::iAnimResManager &arm) : Entity::iEntity(e), animResManager(arm)
{
}
virtual void render(float gameTime, float deltaTime)
{
gameTime, deltaTime;
}
cAni::iAnimResManager &animResManager;
};
class iViewerEntity : public Entity::iEntity
{
public:
iViewerEntity(Entity &e) : Entity::iEntity(e)
{
}
virtual Point2f getViewerPos() const
{
return Point2f();
}
virtual float getViewerOrientation() const
{
return 0;
}
};
class RenderQueue : public Singleton<RenderQueue>
{
public:
enum
{
LayerDebugInfo = 0,
MaxLayers = 16,
};
RenderQueue() : viewer(0)
{
}
void render(const Point2f &pos, float direction, int frame, const iAnimation *anim, size_t layer = LayerDebugInfo, bool screenPos = false)
{
assert(layer < MaxLayers);
if (!anim)
return;
GfxObj obj;
obj.type = GfxObj::T_Anim;
obj.screenPos = screenPos;
obj.a = pos;
obj.direction = direction;
obj.frame = frame;
obj.anim = anim;
gfxobjs[layer].push_back(obj);
}
void render(const hgeQuad &quad, size_t layer = LayerDebugInfo, bool screenPos = false)
{
assert(layer < MaxLayers);
GfxObj obj;
obj.type = GfxObj::T_Quad;
obj.screenPos = screenPos;
obj.quad = quad;
gfxobjs[layer].push_back(obj);
}
void render(const Point2f &a, const Point2f &b, DWORD color, size_t layer = LayerDebugInfo, bool screenPos = false)
{
assert(layer < MaxLayers);
GfxObj obj;
obj.type = GfxObj::T_Line;
obj.screenPos = screenPos;
obj.a = a;
obj.b = b;
obj.color = color;
gfxobjs[layer].push_back(obj);
}
void render(const Point2f &p, hgeFont *font, const char *s, int align, DWORD color, size_t layer = LayerDebugInfo, bool screenPos = false)
{
assert(layer < MaxLayers);
if (!font || !s)
return;
GfxObj obj;
obj.type = GfxObj::T_Text;
obj.screenPos = screenPos;
obj.a = p;
obj.font = font;
obj.str = s;
obj.color = color;
obj.align = align;
gfxobjs[layer].push_back(obj);
}
void render(const Point2f &p, const hgeTriple &t, size_t layer = LayerDebugInfo, bool screenPos = false)
{
assert(layer < MaxLayers);
GfxObj obj;
obj.type = GfxObj::T_Triple;
obj.a = p;
obj.screenPos = screenPos;
obj.triple = t;
gfxobjs[layer].push_back(obj);
}
void flush();
void setViewer(Entity *entity)
{
if (entity)
viewer = (iViewerEntity *)entity->getEntityInterface(Entity::EII_ViewerEntity);
else
viewer = 0;
}
Rectf getWindowViewer();
void screenToGame(Point2f &pos)
{
pos += getViewerPos();
}
Point2f getViewerPos();
void setViewerPos(const Point2f &vp)
{
viewerPos = vp;
}
const Point2f &getWindowSize() const
{
return windowSize;
}
void setWindowSize(const Point2f &ws)
{
windowSize = ws;
}
protected:
vector<GfxObj> gfxobjs[MaxLayers];
iViewerEntity *viewer;
Point2f viewerPos;
Point2f windowSize;
};
#endif//COMMON_GRAPHIC_ENTITY_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -