00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Teddy/TeddyConfig.h"
00026 #include "Teddy/Graphics/Device.h"
00027 #include "Teddy/Graphics/Font.h"
00028 #include "Teddy/Graphics/PsRenderer.h"
00029 #include "Teddy/Graphics/Texture.h"
00030 #include "Teddy/Graphics/View.h"
00031 #include "Teddy/Maths/Matrix.h"
00032 #include "Teddy/PhysicalComponents/WindowManager.h"
00033 #include "Teddy/PhysicalComponents/Style.h"
00034 #include "Teddy/SysSupport/Messages.h"
00035 #include "Teddy/SysSupport/StdSDL.h"
00036 #include "Teddy/SysSupport/StdIO.h"
00037 #ifndef SWIG
00038 #include <cstdlib>
00039 #endif
00040 using namespace Teddy::Maths;
00041 using namespace Teddy::PhysicalComponents;
00042 using namespace Teddy::SysSupport;
00043
00044
00045 namespace Teddy {
00046 namespace Graphics {
00047
00048
00049
00050
00052 void View::vertex( const Vector &v, const Vector2 &t ) const {
00053 texture( t );
00054 vertex ( v );
00055 }
00056
00057
00059 void View::vertex( const Vector2 &v, const Vector2 &t ) const {
00060 msg( M_GL, "vertex( %f, %f %f, %f )", v[0],v[1],t[0],t[1] );
00061 texture( t );
00062 vertex( v );
00063 }
00064
00065
00067 void View::drawFillRect( const float x1, const float y1, const float x2, const float y2 ){
00068 msg( M_GL, "View::drawFillRect( %f, %f, %f, %f )", x1,y1,x2,y2 );
00069 setPolygonMode( GL_FILL );
00070 beginQuads();
00071 vertex( x1, y1 );
00072 vertex( x2, y1 );
00073 vertex( x2, y2 );
00074 vertex( x1, y2 );
00075 end();
00076 }
00077
00078
00079 void View::blit( const Vector2 &pos, Texture *t ){
00080 Vector2 size = Vector2( t->getSize() );
00081 Vector2 max = pos + (Vector2)( t->getSize() ) - Vector2( 1, 1 );
00082
00083
00084
00085 color ( C_WHITE );
00086 setTexture ( t );
00087 setPolygonMode( GL_FILL );
00088 setBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
00089 enable ( TEXTURE_2D );
00090 enable ( BLEND );
00091
00092 beginQuads();
00093 vertex( pos , Vector2(0,0) );
00094 vertex( Vector2( max[0], pos[1] ) , Vector2(1,0) );
00095 vertex( max , Vector2(1,1) );
00096 vertex( Vector2( pos[0], max[1] ) , Vector2(0,1) );
00097 end();
00098 }
00099
00100
00102 void View::drawRect( const float x1, const float y1, const float x2, const float y2 ){
00103 setPolygonMode( GL_LINE );
00104 beginQuads();
00105 vertex( x1 , y1+1.0f );
00106 vertex( x2-1.0f, y1+1.0f );
00107 vertex( x2-1.0f, y2 );
00108 vertex( x1 , y2 );
00109 end();
00110 }
00111
00112
00114 void View::drawBiColRect( const float x1, const float y1, const float x2, const float y2, const Color &top_left, const Color &bottom_right ){
00115 color( top_left );
00116 beginLineStrip();
00117 vertex( x1, y2 );
00118 vertex( x1, y1+1.0f );
00119 vertex( x2, y1+1.0f );
00120 end();
00121 color( bottom_right );
00122 beginLineStrip();
00123 vertex( x2-1.0f, y1+1.0f );
00124 vertex( x2-1.0f, y2 );
00125 vertex( x1, y2 );
00126 end();
00127 }
00128
00129
00131 void View::drawString( const Vector2 &pos, const char *str, Font *font ){
00132 font->drawString( pos, str, this );
00133 }
00134
00135
00136 };
00137 };
00138