FTGL 2.1.3~rc5
FTBBox.h
Go to the documentation of this file.
00001 /*
00002  * FTGL - OpenGL font library
00003  *
00004  * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
00005  * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
00006  * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining
00009  * a copy of this software and associated documentation files (the
00010  * "Software"), to deal in the Software without restriction, including
00011  * without limitation the rights to use, copy, modify, merge, publish,
00012  * distribute, sublicense, and/or sell copies of the Software, and to
00013  * permit persons to whom the Software is furnished to do so, subject to
00014  * the following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be
00017  * included in all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00020  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00021  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00022  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00023  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00024  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00025  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00026  */
00027 
00028 #ifndef __ftgl__
00029 #   warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
00030 #   include <FTGL/ftgl.h>
00031 #endif
00032 
00033 #ifndef __FTBBox__
00034 #define __FTBBox__
00035 
00036 #ifdef __cplusplus
00037 
00038 
00042 class FTGL_EXPORT FTBBox
00043 {
00044     public:
00048         FTBBox()
00049         :   lower(0.0f, 0.0f, 0.0f),
00050             upper(0.0f, 0.0f, 0.0f)
00051         {}
00052 
00056         FTBBox(float lx, float ly, float lz, float ux, float uy, float uz)
00057         :   lower(lx, ly, lz),
00058             upper(ux, uy, uz)
00059         {}
00060 
00064         FTBBox(FTPoint l, FTPoint u)
00065         :   lower(l),
00066             upper(u)
00067         {}
00068 
00075         FTBBox(FT_GlyphSlot glyph)
00076         :   lower(0.0f, 0.0f, 0.0f),
00077             upper(0.0f, 0.0f, 0.0f)
00078         {
00079             FT_BBox bbox;
00080             FT_Outline_Get_CBox(&(glyph->outline), &bbox);
00081 
00082             lower.X(static_cast<float>(bbox.xMin) / 64.0f);
00083             lower.Y(static_cast<float>(bbox.yMin) / 64.0f);
00084             lower.Z(0.0f);
00085             upper.X(static_cast<float>(bbox.xMax) / 64.0f);
00086             upper.Y(static_cast<float>(bbox.yMax) / 64.0f);
00087             upper.Z(0.0f);
00088         }
00089 
00093         ~FTBBox()
00094         {}
00095 
00100         void Invalidate()
00101         {
00102             lower = FTPoint(1.0f, 1.0f, 1.0f);
00103             upper = FTPoint(-1.0f, -1.0f, -1.0f);
00104         }
00105 
00112         bool IsValid()
00113         {
00114             return lower.X() <= upper.X()
00115                 && lower.Y() <= upper.Y()
00116                 && lower.Z() <= upper.Z();
00117         }
00118 
00124         FTBBox& operator += (const FTPoint vector)
00125         {
00126             lower += vector;
00127             upper += vector;
00128 
00129             return *this;
00130         }
00131 
00138         FTBBox& operator |= (const FTBBox& bbox)
00139         {
00140             if(bbox.lower.X() < lower.X()) lower.X(bbox.lower.X());
00141             if(bbox.lower.Y() < lower.Y()) lower.Y(bbox.lower.Y());
00142             if(bbox.lower.Z() < lower.Z()) lower.Z(bbox.lower.Z());
00143             if(bbox.upper.X() > upper.X()) upper.X(bbox.upper.X());
00144             if(bbox.upper.Y() > upper.Y()) upper.Y(bbox.upper.Y());
00145             if(bbox.upper.Z() > upper.Z()) upper.Z(bbox.upper.Z());
00146 
00147             return *this;
00148         }
00149 
00150         void SetDepth(float depth)
00151         {
00152             if(depth > 0)
00153                 upper.Z(lower.Z() + depth);
00154             else
00155                 lower.Z(upper.Z() + depth);
00156         }
00157 
00158 
00159         inline FTPoint const Upper() const
00160         {
00161             return upper;
00162         }
00163 
00164 
00165         inline FTPoint const Lower() const
00166         {
00167             return lower;
00168         }
00169 
00170     private:
00174         FTPoint lower, upper;
00175 };
00176 
00177 #endif //__cplusplus
00178 
00179 #endif  //  __FTBBox__
00180