UQGL Beta(11/04/02)
GraphicMgr.h
説明を見る。
00001 #pragma once
00002 
00009 #include "Base.h"
00010 
00011 namespace UQ{
00012 
00017 class Color{
00018 public:
00019     Color() : color32bit_(0){}
00020 
00025     Color(unsigned long color32bit) : color32bit_(color32bit){}
00026 
00034     Color(unsigned char a, unsigned char r, unsigned char g, unsigned char b) : a_(a), r_(r), g_(g), b_(b){}
00035 
00043     void setARGB(unsigned char a, unsigned char r, unsigned char g, unsigned char b){a_ = a; r_ = r; g_ = g; b_ = b;}
00044 
00048     operator unsigned long() const{return color32bit_;}
00049 
00050     union{
00051         struct{
00052             unsigned char b_;   
00053             unsigned char g_;   
00054             unsigned char r_;   
00055             unsigned char a_;   
00056         };
00057         unsigned long color32bit_;  
00058     };
00059 };
00060 
00065 template<typename T>
00066 class Vector2DTemplate{
00067 public:
00068     Vector2DTemplate() : x_(0), y_(0){}
00069     
00075     Vector2DTemplate(T x, T y) : x_(x), y_(y){}
00076     
00082     void set(T x, T y){x_ = x; y_ = y;}
00083 
00084     Vector2DTemplate operator +() const{return *this;}
00085     Vector2DTemplate operator +(const Vector2DTemplate& v) const{return Vector2DTemplate(x_ + v.x_, y_ + v.y_);}
00086     Vector2DTemplate& operator +=(const Vector2DTemplate& v){x_ += v.x_; y_ += v.y_; return *this;}
00087     
00088     Vector2DTemplate operator -() const{return Vector2DTemplate(-x_, -y_);}
00089     Vector2DTemplate operator -(const Vector2DTemplate& v) const{return Vector2DTemplate(x_ - v.x_, y_ - v.y_);}
00090     Vector2DTemplate& operator -=(const Vector2DTemplate& v){x_ -= v.x_; y_ -= v.y_; return *this;}
00091 
00092     Vector2DTemplate operator *(const T t) const{return Vector2DTemplate(x_ * t, y_ * t);}
00093     Vector2DTemplate& operator *=(const T t){x_ *= t; y_ *= t; return *this;}
00094 
00095     Vector2DTemplate operator /(const T t) const{return Vector2DTemplate(x_ / t, y_ / t);}
00096     Vector2DTemplate& operator /=(const T t){x_ /= t; y_ /= t; return *this;}
00097 
00098     T x_; 
00099     T y_; 
00100 };
00101 
00102 typedef Vector2DTemplate<float> Vector2D; 
00103 
00108 class Vertex{
00109 private:
00110     typedef Vector2DTemplate<int> TextureCoordinate; 
00111 
00112 public:
00113     Vertex() : vector_(), color_(0xFFFFFFFF), textureCoordinate_(){}
00114 
00115     Vector2D vector_;                       
00116     Color color_;                           
00117     TextureCoordinate textureCoordinate_;   
00118 };
00119 
00126 class DLL_EXPORT Polygon{
00127 public:
00128     Polygon() : vertexCount_(0){}
00129 
00138     void setRectangle(int   x, int   y, int width, int height);
00139     void setRectangle(float x, float y, int width, int height);
00140 
00150     void setRectangleTexture(int x, int y, int width, int height);
00151 
00160     void setRegularPolygon(int n, Vector2D center, float radius);
00161 
00167     void setColor(Color color);
00168 
00174     void translate(Vector2D vector);
00175 
00182     void rotate(Vector2D center, float angle);
00183 
00191     void scale(Vector2D center, float scaleX, float scaleY);
00192 
00193     static const int VERTEX_COUNT_MAX_ = 128;   
00194 #pragma warning(disable:4251)
00195     Vertex vertex_[VERTEX_COUNT_MAX_];  
00196 #pragma warning(default:4251)
00197     int vertexCount_;   
00198 };
00199 
00204 class GraphicMgr{
00205 public:
00206     virtual ~GraphicMgr(){}
00207 
00213     virtual void setBackgroundColor(Color color) = 0;
00214     
00220     virtual void drawPolygon(Polygon polygon) const = 0;
00221 
00230     virtual bool loadTexture(int id, const char* fileName) = 0;
00231 
00237     virtual void unloadTexture(int id) = 0;
00238 
00244     virtual void setTexture(int id) = 0;
00245 
00250     virtual void unsetTexture(void) = 0;
00251 
00258     virtual int getTextureWidth(int id) const = 0;
00259 
00266     virtual int getTextureHeight(int id) const = 0;
00267 
00276     virtual void outputString(int x, int y, const char* str, Color color = 0xFFFFFFFF) = 0;
00277 };
00278 
00279 } // namespace UQ