Back to index

extremetuxracer  0.5beta
alignment.cpp
Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2005 Volker Stroebel <volker@planetpenguin.de>
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  */
00018  
00019 #include "alignment.h"
00020  
00021 namespace pp{
00022 
00023 Alignment::Alignment(float horizontal, float vertical)
00024  : m_horizontal(horizontal),
00025    m_vertical(vertical)
00026 {      
00027        checkHorizontal();
00028        checkVertical();
00029 }
00030 
00031 void
00032 Alignment::checkHorizontal()
00033 {
00034        if(m_horizontal>1.0f){
00035               m_horizontal = 1.0f;
00036        }else if(m_horizontal<0.0f){
00037               m_horizontal = 0.0f;
00038        }             
00039 }
00040        
00041 void
00042 Alignment::checkVertical()
00043 {
00044        if(m_vertical>1.0f){
00045               m_vertical = 1.0f;
00046        }else if(m_vertical<0.0f){
00047               m_vertical = 0.0f;
00048        }
00049 }
00050 
00051 void
00052 Alignment::setHorizontal(float horizontal)
00053 {
00054        m_horizontal = horizontal;
00055        checkHorizontal();
00056 }
00057 
00058 void
00059 Alignment::setVertical(float vertical)
00060 {
00061        m_vertical = vertical;
00062        checkVertical();     
00063 }
00064 
00065 void
00066 Alignment::set(float horizontal, float vertical)
00067 {
00068        setHorizontal(horizontal);
00069        setVertical(vertical);      
00070 }      
00071 
00072 pp::Vec2d
00073 Alignment::alignPosition( const pp::Vec2d &position,
00074                                             const pp::Vec2d &size) const
00075 {
00076        return pp::Vec2d(
00077               position.x - (m_horizontal*size.x),
00078               position.y - (m_vertical*size.y)   
00079        );     
00080 }
00081 
00082        
00083 } //namespace pp