Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ViewDraw.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id: View.cpp,v 1.8 2002/02/16 16:38:11 tksuoran Exp $
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     //int x2 = x1 + t->getWidth () -1 ;
00083     //int y2 = y1 + t->getHeight() -1 ;
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 };  //  namespace Graphics
00137 };  //  namespace Teddy
00138