src/object/anchor_point.cpp File Reference

#include "object/anchor_point.hpp"
#include <config.h>
#include <stdexcept>
#include <sstream>
#include "math/rectf.hpp"
#include "util/log.hpp"

Go to the source code of this file.

Functions

std::string anchor_point_to_string (AnchorPoint point)
AnchorPoint string_to_anchor_point (const std::string &str)
Vector get_anchor_pos (const Rectf &rect, AnchorPoint point)
Vector get_anchor_pos (const Rectf &destrect, float width, float height, AnchorPoint point)


Function Documentation

std::string anchor_point_to_string ( AnchorPoint  point  ) 

Definition at line 27 of file anchor_point.cpp.

References ANCHOR_BOTTOM, ANCHOR_BOTTOM_LEFT, ANCHOR_BOTTOM_RIGHT, ANCHOR_LEFT, ANCHOR_MIDDLE, ANCHOR_RIGHT, ANCHOR_TOP, ANCHOR_TOP_LEFT, and ANCHOR_TOP_RIGHT.

00028 {
00029   switch(point) {
00030     case ANCHOR_TOP_LEFT:
00031       return "topleft";
00032     case ANCHOR_TOP:
00033       return "top";
00034     case ANCHOR_TOP_RIGHT:
00035       return "topright";
00036     case ANCHOR_LEFT:
00037       return "left";
00038     case ANCHOR_MIDDLE:
00039       return "middle";
00040     case ANCHOR_RIGHT:
00041       return "right";
00042     case ANCHOR_BOTTOM_LEFT:
00043       return "bottomleft";
00044     case ANCHOR_BOTTOM:
00045       return "bottom";
00046     case ANCHOR_BOTTOM_RIGHT:
00047       return "bottomright";
00048     default:
00049       throw std::runtime_error("Invalid anchor point");
00050   }
00051 }

Vector get_anchor_pos ( const Rectf destrect,
float  width,
float  height,
AnchorPoint  point 
)

Definition at line 118 of file anchor_point.cpp.

References ANCHOR_BOTTOM, ANCHOR_H_MASK, ANCHOR_LEFT, ANCHOR_MIDDLE, ANCHOR_RIGHT, ANCHOR_TOP, ANCHOR_V_MASK, Rectf::get_bottom(), Rectf::get_left(), Rectf::get_middle(), Rectf::get_right(), Rectf::get_top(), log_warning, Vector::x, and Vector::y.

00120 {
00121   Vector result;
00122 
00123   switch(point & ANCHOR_V_MASK) {
00124     case ANCHOR_LEFT:
00125       result.x = destrect.get_left();
00126       break;
00127     case ANCHOR_MIDDLE:
00128       result.x = destrect.get_middle().x - width/2.0;
00129       break;
00130     case ANCHOR_RIGHT:
00131       result.x = destrect.get_right() - width;
00132       break;
00133     default:
00134       log_warning << "Invalid anchor point found" << std::endl;
00135       result.x = destrect.get_left();
00136       break;
00137   }
00138 
00139   switch(point & ANCHOR_H_MASK) {
00140     case ANCHOR_TOP:
00141       result.y = destrect.get_top();
00142       break;
00143     case ANCHOR_MIDDLE:
00144       result.y = destrect.get_middle().y - height/2.0;
00145       break;
00146     case ANCHOR_BOTTOM:
00147       result.y = destrect.get_bottom() - height;
00148       break;
00149     default:
00150       log_warning << "Invalid anchor point found" << std::endl;
00151       result.y = destrect.get_top();
00152       break;
00153   }
00154 
00155   return result;
00156 }

Vector get_anchor_pos ( const Rectf rect,
AnchorPoint  point 
)

Definition at line 79 of file anchor_point.cpp.

Referenced by Owl::active_update(), Rectf::distance(), TextObject::draw(), FloatingImage::draw(), SkyDive::explode(), Sector::get_nearest_player(), Dispenser::launch_badguy(), MovingSprite::set_action(), and SpriteParticle::SpriteParticle().

00080 {
00081   Vector result;
00082 
00083   switch(point & ANCHOR_V_MASK) {
00084     case ANCHOR_LEFT:
00085       result.x = rect.get_left();
00086       break;
00087     case ANCHOR_MIDDLE:
00088       result.x = rect.get_left() + (rect.get_right() - rect.get_left()) / 2.0;
00089       break;
00090     case ANCHOR_RIGHT:
00091       result.x = rect.get_right();
00092       break;
00093     default:
00094       log_warning << "Invalid anchor point found" << std::endl;
00095       result.x = rect.get_left();
00096       break;
00097   }
00098 
00099   switch(point & ANCHOR_H_MASK) {
00100     case ANCHOR_TOP:
00101       result.y = rect.get_top();
00102       break;
00103     case ANCHOR_MIDDLE:
00104       result.y = rect.get_top() + (rect.get_bottom() - rect.get_top()) / 2.0;
00105       break;
00106     case ANCHOR_BOTTOM:
00107       result.y = rect.get_bottom();
00108       break;
00109     default:
00110       log_warning << "Invalid anchor point found" << std::endl;
00111       result.y = rect.get_top();
00112       break;
00113   }
00114 
00115   return result;
00116 }

AnchorPoint string_to_anchor_point ( const std::string &  str  ) 

Definition at line 53 of file anchor_point.cpp.

References ANCHOR_BOTTOM, ANCHOR_BOTTOM_LEFT, ANCHOR_BOTTOM_RIGHT, ANCHOR_LEFT, ANCHOR_MIDDLE, ANCHOR_RIGHT, ANCHOR_TOP, ANCHOR_TOP_LEFT, and ANCHOR_TOP_RIGHT.

00054 {
00055   if(str == "topleft")
00056     return ANCHOR_TOP_LEFT;
00057   else if(str == "top")
00058     return ANCHOR_TOP;
00059   else if(str == "topright")
00060     return ANCHOR_TOP_RIGHT;
00061   else if(str == "left")
00062     return ANCHOR_LEFT;
00063   else if(str == "middle")
00064     return ANCHOR_MIDDLE;
00065   else if(str == "right")
00066     return ANCHOR_RIGHT;
00067   else if(str == "bottomleft")
00068     return ANCHOR_BOTTOM_LEFT;
00069   else if(str == "bottom")
00070     return ANCHOR_BOTTOM;
00071   else if(str == "bottomright")
00072     return ANCHOR_BOTTOM_RIGHT;
00073 
00074   std::ostringstream msg;
00075   msg << "Unknown anchor '" << str << "'";
00076   throw std::runtime_error(msg.str());
00077 }


Generated on Mon Jun 9 03:38:26 2014 for SuperTux by  doxygen 1.5.1