00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00026
00028 #include <SFML/Graphics/Drawable.hpp>
00029 #include <SFML/Graphics/OpenGL.hpp>
00030
00031
00032 namespace sf
00033 {
00037 Drawable::Drawable(float Left, float Top, float ScaleX, float ScaleY, float Rotation, const Color& Col) :
00038 myLeft (Left),
00039 myTop (Top),
00040 myScaleX (ScaleX),
00041 myScaleY (ScaleY),
00042 myRotation(Rotation),
00043 myCenterX (0.f),
00044 myCenterY (0.f),
00045 myColor (Col)
00046 {
00047
00048 }
00049
00050
00054 Drawable::~Drawable()
00055 {
00056
00057 }
00058
00059
00063 void Drawable::SetLeft(float Left)
00064 {
00065 myLeft = Left;
00066 }
00067
00068
00072 void Drawable::SetTop(float Top)
00073 {
00074 myTop = Top;
00075 }
00076
00077
00081 void Drawable::SetScale(float ScaleX, float ScaleY)
00082 {
00083 if (ScaleX > 0.f) myScaleX = ScaleX;
00084 if (ScaleY > 0.f) myScaleY = ScaleY;
00085 }
00086
00087
00091 void Drawable::SetRotation(float Rotation)
00092 {
00093 myRotation = Rotation;
00094 }
00095
00096
00101 void Drawable::SetRotationCenter(float X, float Y)
00102 {
00103 myCenterX = X;
00104 myCenterY = Y;
00105 }
00106
00107
00111 void Drawable::SetColor(const Color& Col)
00112 {
00113 myColor = Col;
00114 }
00115
00116
00120 float Drawable::GetLeft() const
00121 {
00122 return myLeft;
00123 }
00124
00125
00129 float Drawable::GetTop() const
00130 {
00131 return myTop;
00132 }
00133
00134
00138 float Drawable::GetScaleX() const
00139 {
00140 return myScaleX;
00141 }
00142
00143
00147 float Drawable::GetScaleY() const
00148 {
00149 return myScaleY;
00150 }
00151
00152
00156 float Drawable::GetRotation() const
00157 {
00158 return myRotation;
00159 }
00160
00161
00165 const Color& Drawable::GetColor() const
00166 {
00167 return myColor;
00168 }
00169
00170
00174 void Drawable::Move(float OffsetX, float OffsetY)
00175 {
00176 myLeft += OffsetX;
00177 myTop += OffsetY;
00178 }
00179
00180
00184 void Drawable::Scale(float FactorX, float FactorY)
00185 {
00186 if (FactorX > 0.f) myScaleX *= FactorX;
00187 if (FactorY > 0.f) myScaleY *= FactorY;
00188 }
00189
00190
00194 void Drawable::Rotate(float Angle)
00195 {
00196 myRotation += Angle;
00197 }
00198
00199
00203 void Drawable::Draw(RenderWindow& Window)
00204 {
00205
00206 GLCheck(glMatrixMode(GL_MODELVIEW));
00207 GLCheck(glPushMatrix());
00208
00209
00210 GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
00211
00212
00213 GLCheck(glColor4ub(myColor.r, myColor.g, myColor.b, myColor.a));
00214
00215
00216 GLCheck(glTranslatef(myLeft + myCenterX, myTop + myCenterY, 0));
00217 GLCheck(glRotatef(-myRotation, 0, 0, 1));
00218 GLCheck(glTranslatef(-myCenterX, -myCenterY, 0));
00219 GLCheck(glScalef(myScaleX, myScaleY, 1));
00220
00221
00222 Render(Window);
00223
00224
00225 GLCheck(glPopMatrix());
00226 }
00227
00228 }