#include <arspaint.h>
Inheritance diagram for Ars::HPaint:


Public Types | |
| enum | EPaintMode { PAINT_IGNORE = 0, PAINT_REPLACE, PAINT_NORMAL, PAINT_OR, PAINT_AND, PAINT_XOR } |
Public Member Functions | |
| HPaint (void) | |
| HPaint (SDL_Surface *&surface) | |
| const EPaintMode | SetMode (const EPaintMode aNewMode) |
| FontEngine * | SetFont (FontEngine *aFontEngine) |
| FontEngine * | GetFont (void) |
| const int | GetFontSize (void) const |
| XPoint | GetTextSize (const string &str) |
| void | GetMetrics (const string &str, XPoint *pBoundedDimensions, XPoint *pOriginOffset, std::vector< XRect > *pCharacterRects=0) const |
| void | SetTextAlign (const int vAlign, const int hAlign=-1) |
| virtual const unsigned long | GetStates (void) const |
| unsigned int | GetMaxFontHeight (void) |
| virtual void | TextOutStr (const XRect &BoundingRect, const std::string &str, const RGBColor &FontColor) |
| void | SetMaskChar (const char MaskChar) |
| void | _TextOut (XRect &drawRect, XPoint &OriginPoint, const std::string &str, const RGBColor &FontColor) |
| void | SetGDI (SDL_Surface *&surface) |
| Assign a surface to draw onto. | |
| SDL_Surface *& | GetGDI (void) const |
| Get the graphical device interafce pointer. | |
| void | DrawHLine (const int xStart, const int xEnd, const int y, const RGBColor &LineColor) |
| void | DrawVLine (const int yStart, const int yEnd, const int x, const RGBColor &LineColor) |
| void | DrawRect (const XRect &Rect, const bool bFilled, const RGBColor &BorderColor, const RGBColor &FillColor) |
| void | DrawLine (const XPoint &StartPoint, const XPoint &EndPoint, const RGBColor &LineColor) |
| void | DrawPoint (const XPoint &Point, const RGBColor &PointColor) |
| void | DrawPoint (SDL_Surface *s, const XPoint &Point, const RGBColor &PointColor) |
| RGBColor | ReadPoint (const XPoint &Point) |
| RGBColor | ReadPoint (SDL_Surface *s, const XPoint &Point) |
| void | ReplaceColor (const RGBColor &NewColor, const RGBColor &OldColor) |
| void | TransparentColor (const RGBColor &TransparentColor) |
Static Public Attributes | |
| SDL_Surface * | NoSurface = 0 |
Protected Member Functions | |
| void | LockSurface (void) |
| Locks the SDL surface. | |
| void | UnlockSurface (void) |
| Unlocks the SDL surface. | |
| RGBColor | MixColor (const RGBColor &ColorBase, const RGBColor &ColorAdd) |
Protected Attributes | |
| SDL_Surface *& | m_pSurface |
| A pointer to the SDL Surface to draw on. | |
| EPaintMode | m_PaintMode |
| The painting mode to use. | |
| FontEngine * | m_pFontEngine |
| A pointer to the Font Engine. | |
| XPoint | m_CachedBoundedDimensions |
| The cached value of the rendered string's dimensions. | |
| XPoint | m_OriginOffset |
| The cached value of the string's offset from the origin. | |
| std::vector< XRect > | m_CachedCharacterRects |
| The cached value of the CRects for the various characters. | |
| bool | m_bCachedMetricsValid |
| A boolean indicating if the cached values are valid. | |
| char | m_MaskChar |
| Character to use as the mask, used for passwords and such. | |
| int | m_MaxFontHeight |
| Maximum height of any character with ASCII value 0-255 for the current font. | |
| XPoint | textSize |
Private Attributes | |
| unsigned long | states |
| Text alignment when HPaint used alone.... | |
Friends | |
| class | View |
|
|
A mode for painting the surface can be specified currently this does not work for the DrawHLine, DrawVLine, or DrawRect methods
Definition at line 10 of file arspaint.h. Referenced by Ars::XGroupBox::Draw(), and SetMode().
00010 {
00011 PAINT_IGNORE = 0,
00012 PAINT_REPLACE,
00013 PAINT_NORMAL,
00014 PAINT_OR,
00015 PAINT_AND,
00016 PAINT_XOR
00017 };
|
|
|
Definition at line 7 of file arspaint.cpp. References m_pFontEngine.
00008 : m_pSurface( NoSurface ), m_PaintMode( PAINT_NORMAL ) 00009 , m_pFontEngine( 0 ) 00010 , m_bCachedMetricsValid(false), m_MaskChar(' '), m_MaxFontHeight(-1) 00011 { 00012 m_pFontEngine = ArsApplication::GetInstance()->GetDefaultFontEngine(); 00013 } |
|
|
Definition at line 15 of file arspaint.cpp. References m_pFontEngine.
00016 : m_pSurface( surface ), m_PaintMode( PAINT_NORMAL ) 00017 , m_pFontEngine( 0 ) 00018 , m_bCachedMetricsValid(false), m_MaskChar(' '), m_MaxFontHeight(-1) 00019 { 00020 m_pFontEngine = ArsApplication::GetInstance()->GetDefaultFontEngine(); 00021 } |
|
||||||||||||||||||||
|
Definition at line 23 of file arspaint.cpp. References Ars::RGBColor::blue, Ars::XRect::Bottom(), DrawPoint(), GetMetrics(), GetStates(), Ars::RGBColor::green, HALIGN_MASK, Ars::XRect::HitTest(), m_bCachedMetricsValid, m_MaskChar, m_pFontEngine, Ars::RGBColor::red, Ars::FontEngine::RenderGlyph(), Ars::XRect::Right(), S_ALIGN_BOTTOM, S_ALIGN_LEFT, S_ALIGN_RIGHT, S_ALIGN_TOP, textSize, VALIGN_MASK, Ars::XRect::Width(), Ars::XPoint::x, and Ars::XPoint::y. Referenced by TextOutStr().
00024 {
00025 m_bCachedMetricsValid = false;
00026 XPoint OriginOffset , linebox;
00027 std::vector<XRect> CharacterRects;
00028
00029 GetMetrics( str , &linebox , &OriginOffset , &CharacterRects );
00030
00031 textSize.x = max( textSize.x , linebox.x );
00032 switch( (GetStates() & VALIGN_MASK) )
00033 {
00034 case S_ALIGN_TOP : OriginPoint = XPoint( OriginPoint.x , drawRect.y ); break;
00035 case S_ALIGN_BOTTOM : OriginPoint = XPoint( OriginPoint.x , drawRect.Bottom() ); break;
00036 }
00037
00038 switch( (GetStates() & HALIGN_MASK) )
00039 {
00040 case S_ALIGN_LEFT : OriginPoint = XPoint( drawRect.x , OriginPoint.y ); break;
00041 case S_ALIGN_RIGHT : OriginPoint = XPoint( drawRect.Right() , OriginPoint.y ); break;
00042 default : OriginPoint = XPoint( drawRect.x + drawRect.Width() / 2 , OriginPoint.y ); break;
00043 }
00044
00045 for( unsigned int i = 0 ; i < str.size() ; ++i )
00046 {
00047 FT_BitmapGlyphRec *pGlyph;
00048 if( m_MaskChar == ' ' )
00049 pGlyph = m_pFontEngine->RenderGlyph( str[i] );
00050 else
00051 pGlyph = m_pFontEngine->RenderGlyph( m_MaskChar );
00052
00053 for (int y = 0; y < pGlyph->bitmap.rows; ++y )
00054 {
00055 for (int x = 0; x < pGlyph->bitmap.width; ++x )
00056 {
00057 unsigned char *PixelOffset = pGlyph->bitmap.buffer + y * pGlyph->bitmap.width + x;
00058 if( *PixelOffset != 0x00 )
00059 {
00060 RGBColor PixelColor(FontColor.red, FontColor.green, FontColor.blue, *PixelOffset);
00061
00062 XPoint PixelPoint( XPoint( x + pGlyph->left, y ) + OriginPoint + OriginOffset + CharacterRects[i].TopLeft() );
00063
00064 if( drawRect.HitTest( PixelPoint ) == XRect::RELPOS_INSIDE)
00065 DrawPoint(PixelPoint, PixelColor);
00066 }
00067 }
00068 }
00069 }
00070 }
|
|
||||||||||||||||||||
|
Draw a horizontal line
Definition at line 263 of file arspaint.cpp. References m_pSurface, Ars::RGBColor::SDLColor(), and tron. Referenced by Ars::XBox::Draw(), Ars::XBox::DrawRaised(), DrawRect(), and Ars::XBox::DrawSunken().
00264 {
00265 if (!m_pSurface)
00266 {
00267 tron<< "HPaint::HPaint : Invalid pointer to surface.\n";
00268 return ;
00269 }
00270
00271 #ifdef WIN32
00272 #ifndef MSVC6 // There are problems with VC6 and these std lib template classes
00273 /*
00274 if (xStart < std::numeric_limits<short int>::min() ||xStart > std::numeric_limits<short int>::max()
00275 || xEnd < std::numeric_limits<short int>::min() ||xEnd > std::numeric_limits<short int>::max()
00276 || y < std::numeric_limits<short int>::min() ||y > std::numeric_limits<short int>::max())
00277 {
00278 throw(ExceptionRange("HPaint::DrawHLine : Out of range - converting int to short int!"));
00279 }
00280 */
00281 #endif // MSVC6
00282 #endif // WIN32
00283
00284 SDL_Rect Rect;
00285 Rect.x = static_cast<short int>( min(xStart, xEnd) );
00286 Rect.y = static_cast<short int>(y);
00287 Rect.w = static_cast<short int>( max(xEnd - xStart + 1, xStart - xEnd + 1) );
00288 Rect.h = 1;
00289 SDL_FillRect(m_pSurface, &Rect, LineColor.SDLColor(m_pSurface->format));
00290 }
|
|
||||||||||||||||
|
Draw a line between two points
Definition at line 351 of file arspaint.cpp. References DrawPoint(), DrawVLine(), m_pSurface, tron, Ars::XPoint::x, and Ars::XPoint::y. Referenced by Ars::XCheckBox::Draw().
00352 {
00353 if (!m_pSurface)
00354 {
00355 tron<< "HPaint::HPaint : Invalid pointer to surface.\n";
00356 return ;
00357 }
00358 if (Point1.x == Point2.x)
00359 {
00360 DrawVLine(Point1.y, Point2.y, Point1.x, LineColor);
00361 }
00362 else
00363 {
00364 const double iSlope = double(Point2.y - Point1.y) / (Point2.x - Point1.x);
00365 if( iSlope <= 1.0 && iSlope >= -1.0 )
00366 {
00367 XPoint StartPoint = (Point1.x < Point2.x) ? Point1 : Point2;
00368 XPoint EndPoint = (Point1.x < Point2.x) ? Point2 : Point1;
00369 for (int x = StartPoint.x; x <= EndPoint.x; ++x)
00370 {
00371 DrawPoint(XPoint(x, static_cast<int>(StartPoint.y + (x - StartPoint.x) * iSlope)), LineColor);
00372 }
00373 }
00374 else
00375 {
00376 XPoint StartPoint = (Point1.y < Point2.y) ? Point1 : Point2;
00377 XPoint EndPoint = (Point1.y < Point2.y) ? Point2 : Point1;
00378 for (int y = StartPoint.y; y <= EndPoint.y; ++y)
00379 {
00380 DrawPoint(XPoint(static_cast<int>(StartPoint.x + (y - StartPoint.y) / iSlope), y), LineColor);
00381 }
00382 }
00383 }
00384 }
|
|
||||||||||||||||
|
Definition at line 397 of file arspaint.cpp. References LockSurface(), MixColor(), ReadPoint(), Ars::RGBColor::SDLColor(), tron, UnlockSurface(), Ars::XPoint::x, and Ars::XPoint::y.
00398 {
00399 if (!s)
00400 {
00401 tron<< "HPaint::HPaint : Invalid pointer to surface.\n";
00402 return ;
00403 }
00404 XPoint RealPoint = Point;
00405 if (XRect(0, 0, s->w, s->h).HitTest(RealPoint) == XRect::RELPOS_INSIDE)
00406 {
00407 LockSurface();
00408 Uint8* PixelOffset = static_cast<Uint8*>(s->pixels) +
00409 s->format->BytesPerPixel * RealPoint.x + s->pitch * RealPoint.y;
00410 switch (s->format->BytesPerPixel)
00411 {
00412 case 1: // 8 bpp
00413 *reinterpret_cast<Uint8*>(PixelOffset) = static_cast<Uint8>(MixColor(ReadPoint(Point), PointColor).SDLColor(s->format));
00414 break;
00415 case 2: // 16 bpp
00416 *reinterpret_cast<Uint16*>(PixelOffset) = static_cast<Uint16>(MixColor(ReadPoint(Point), PointColor).SDLColor(s->format));
00417 break;
00418 case 3: // 24 bpp
00419 {
00420 Uint32 PixelColor = MixColor(ReadPoint(Point), PointColor).SDLColor(s->format);
00421 Uint8* pPixelSource = reinterpret_cast<Uint8*>(&PixelColor);
00422 Uint8* pPixelDest = reinterpret_cast<Uint8*>(PixelOffset);
00423 *pPixelDest = *pPixelSource;
00424 *(++pPixelDest) = *(++pPixelSource);
00425 *(++pPixelDest) = *(++pPixelSource);
00426 break;
00427 }
00428 case 4: // 32 bpp
00429 *reinterpret_cast<Uint32*>(PixelOffset) = static_cast<Uint32>(MixColor(ReadPoint(Point), PointColor).SDLColor(s->format));
00430 break;
00431 default:
00432 tron << "HPaint::DrawPoint : Unrecognized BytesPerPixel.\n";
00433 break;
00434 }
00435 UnlockSurface();
00436 }
00437 }
|
|
||||||||||||
|
Draw a pixel
Definition at line 386 of file arspaint.cpp. References m_pSurface, and tron. Referenced by _TextOut(), Ars::XBox::DrawFocus(), DrawLine(), Ars::XBox::DrawRaised(), Ars::XBox::DrawSunken(), and ReplaceColor().
00387 {
00388 if (!m_pSurface)
00389 {
00390 tron<< "HPaint::HPaint : Invalid pointer to surface.\n";
00391 return ;
00392 }
00393 DrawPoint( m_pSurface , Point , PointColor );
00394 }
|
|
||||||||||||||||||||
|
Draw a rectangle
Definition at line 322 of file arspaint.cpp. References Ars::XRect::Bottom(), DrawHLine(), DrawVLine(), Ars::XRect::Grow(), m_pSurface, Ars::XRect::Right(), Ars::RGBColor::SDLColor(), and tron. Referenced by Ars::XScrollBar::Draw(), Ars::XProgress::Draw(), Ars::XListBox::Draw(), Ars::XGroupBox::Draw(), Ars::XEditBox::Draw(), Ars::XCheckBox::Draw(), Ars::XBox::Draw(), and Ars::Window::DrawBG().
00323 {
00324 if (!m_pSurface)
00325 {
00326 tron<< "HPaint::HPaint : Invalid pointer to surface.\n";
00327 return ;
00328 }
00329 XRect RealRect( Rect );
00330
00331 if (bFilled)
00332 {
00333 RealRect.w += 1;
00334 RealRect.h += 1;
00335 SDL_FillRect(m_pSurface, &RealRect, FillColor.SDLColor(m_pSurface->format));
00336 }
00337
00338 if (!bFilled || (BorderColor != FillColor))
00339 {
00340 RealRect = Rect;
00341
00342 DrawHLine(RealRect.x, RealRect.Right(), RealRect.y, BorderColor);
00343 DrawHLine(RealRect.x, RealRect.Right(), RealRect.Bottom(), BorderColor);
00344 DrawVLine(RealRect.y, RealRect.Bottom(), RealRect.x, BorderColor);
00345 DrawVLine(RealRect.y, RealRect.Bottom(), RealRect.Right(), BorderColor);
00346 RealRect.Grow(-1); //In case we have to fill the rect, then it's ready to go.
00347 }
00348 }
|
|
||||||||||||||||||||
|
Draw a vertical line
Definition at line 293 of file arspaint.cpp. References m_pSurface, Ars::RGBColor::SDLColor(), and tron. Referenced by Ars::XEditBox::Draw(), Ars::XBox::Draw(), DrawLine(), Ars::XBox::DrawRaised(), DrawRect(), and Ars::XBox::DrawSunken().
00294 {
00295 if (!m_pSurface)
00296 {
00297 tron<< "HPaint::HPaint : Invalid pointer to surface.\n";
00298 return ;
00299 }
00300 #ifdef WIN32
00301 #ifndef MSVC6 // There are problems with VC6 and these std lib template classes
00302 /*
00303 if (yStart < std::numeric_limits<short int>::min() ||yStart > std::numeric_limits<short int>::max()
00304 || yEnd < std::numeric_limits<short int>::min() ||yEnd > std::numeric_limits<short int>::max()
00305 || x < std::numeric_limits<short int>::min() ||x > std::numeric_limits<short int>::max())
00306 {
00307 throw(ExceptionRange("HPaint::DrawVLine : Out of range - converting int to short int!"));
00308 }
00309 */
00310 #endif // MSVC6
00311 #endif // WIN32
00312
00313 SDL_Rect Rect;
00314 Rect.x = static_cast<short int>(x);
00315 Rect.y = static_cast<short int>( min(yStart, yEnd) );
00316 Rect.w = 1;
00317 Rect.h = static_cast<short int>( max(yEnd - yStart + 1, yStart - yEnd + 1) );
00318 SDL_FillRect(m_pSurface, &Rect, LineColor.SDLColor(m_pSurface->format));
00319 }
|
|
|
Definition at line 62 of file arspaint.h. References m_pFontEngine. Referenced by Ars::XListBox::AddItem(), Ars::XTextBox::Init(), Ars::XScrollBar::Init(), Ars::XListBox::Init(), and Ars::XDropDown::Init().
00062 { return m_pFontEngine; }
|
|
|
Definition at line 64 of file arspaint.h. References Ars::FontEngine::GetFontSize(), and m_pFontEngine. Referenced by Ars::XListBox::AddItem(), Ars::XTextBox::Draw(), Ars::XGroupBox::Draw(), Ars::XEditBox::Draw(), Ars::XCheckBox::Draw(), Ars::XButtonImage::Draw(), Ars::XListBox::Init(), Ars::XListBox::RemoveItem(), Ars::XTextBox::SetWndText(), and Ars::XToolTip::SetWndText().
00064 { return m_pFontEngine->GetFontSize(); }
|
|
|
Get the graphical device interafce pointer.
Definition at line 111 of file arspaint.h. References m_pSurface. Referenced by Ars::XImage::Draw(), Ars::XButtonImage::Draw(), Ars::XBox::Draw(), Ars::Window::DrawBG(), Ars::Window::SetParent(), Ars::XMPEG::SetupWindow(), Ars::Window::wmPaint(), and Ars::Window::~Window().
00111 { return m_pSurface; }
|
|
|
Get the maximum height of the font, ASCII characters 0-255
Definition at line 150 of file arspaint.cpp. References Ars::FontEngine::GetMetrics(), m_MaxFontHeight, and m_pFontEngine. Referenced by TextOutStr().
00151 {
00152 if (m_MaxFontHeight < 0)
00153 {
00154 int maxHeight=0;
00155 FT_Glyph_Metrics* pMetrics;
00156 for(int i=0; i < 256; i++)
00157 {
00158 pMetrics = m_pFontEngine->GetMetrics((char)i);
00159 if ((pMetrics->height >> 6) > maxHeight)
00160 {
00161 maxHeight = (pMetrics->height >> 6);
00162 }
00163 //maxHeight = std::max(maxHeight, pMetrics->height);
00164 }
00165 m_MaxFontHeight = maxHeight + 2;
00166 }
00167 return m_MaxFontHeight;
00168 }
|
|
||||||||||||||||||||
|
Get some metrics for the rendered string
Definition at line 170 of file arspaint.cpp. References Ars::FontEngine::GetMetrics(), GetStates(), HALIGN_MASK, m_bCachedMetricsValid, m_CachedBoundedDimensions, m_CachedCharacterRects, m_MaskChar, m_OriginOffset, m_pFontEngine, S_ALIGN_BOTTOM, S_ALIGN_LEFT, S_ALIGN_RIGHT, S_ALIGN_TOP, VALIGN_MASK, Ars::XPoint::x, and Ars::XPoint::y. Referenced by _TextOut(), Ars::XGroupBox::Draw(), Ars::XEditBox::Draw(), Ars::XEditBox::evMouseButtonDown(), Ars::XEditBox::evMouseMove(), and GetTextSize().
00171 {
00172 if (! m_bCachedMetricsValid )
00173 {
00174 m_CachedCharacterRects.clear();
00175
00176 int iMinY = 0;
00177 int iMaxY = 0;
00178 int iLength = 0;
00179 for (unsigned int i = 0; i < str.size(); ++i)
00180 {
00181 FT_Glyph_Metrics* pMetrics;
00182 if (m_MaskChar == ' ')
00183 {
00184 pMetrics = m_pFontEngine->GetMetrics(str[i]);
00185 }
00186 else
00187 {
00188 pMetrics = m_pFontEngine->GetMetrics(m_MaskChar);
00189 }
00190
00191
00192 if ((pMetrics->horiBearingY - pMetrics->height) < iMinY)
00193 {
00194 iMinY = pMetrics->horiBearingY - pMetrics->height;
00195 }
00196 if (pMetrics->horiBearingY > iMaxY)
00197 {
00198 iMaxY = pMetrics->horiBearingY;
00199 }
00200 iLength += (pMetrics->horiAdvance);
00201 // The top and bottom values of the rect are not actually in rect coordinates at this point, since iMaxY and iMinY are not yet know
00202 m_CachedCharacterRects.push_back( XRect((iLength - pMetrics->horiAdvance) >> 6, pMetrics->horiBearingY >> 6, (iLength >> 6) - ((iLength - pMetrics->horiAdvance) >> 6) , (pMetrics->height >> 6) - (pMetrics->horiBearingY >> 6 )));
00203 }
00204
00205 iMinY = iMinY >> 6;
00206 iMaxY = iMaxY >> 6;
00207 iLength = iLength >> 6;
00208
00209 // now fix the top and bottom values of the rects
00210 for(std::vector<XRect>::iterator iter = m_CachedCharacterRects.begin(); iter != m_CachedCharacterRects.end(); ++iter)
00211 iter->y = iMaxY - iter->y;
00212
00213 // Tack an empty rect on the end
00214 m_CachedCharacterRects.push_back(XRect(iLength, iMaxY, iLength, iMinY));
00215
00216 m_CachedBoundedDimensions = XPoint(iLength, iMaxY - iMinY);
00217
00218 switch ( (GetStates() & HALIGN_MASK) )
00219 {
00220 default:
00221 m_OriginOffset.x = -iLength / 2;
00222 break;
00223 case S_ALIGN_RIGHT:
00224 m_OriginOffset.x = -iLength;
00225 break;
00226 case S_ALIGN_LEFT:
00227 m_OriginOffset.x = 0;
00228 break;
00229 }
00230
00231 switch( (GetStates() & VALIGN_MASK) )
00232 {
00233 case S_ALIGN_TOP:
00234 m_OriginOffset.y = 0;
00235 break;
00236 case S_ALIGN_BOTTOM:
00237 m_OriginOffset.y = iMinY - iMaxY;
00238 break;
00239 default:
00240 m_OriginOffset.y = (iMinY - iMaxY) / 2;
00241 break;
00242 }
00243
00244 m_bCachedMetricsValid = true;
00245 }
00246
00247 if (pBoundedDimensions)
00248 {
00249 *pBoundedDimensions = m_CachedBoundedDimensions;
00250 }
00251
00252 if (pOriginOffset)
00253 {
00254 *pOriginOffset = m_OriginOffset;
00255 }
00256
00257 if (pCharacterRects)
00258 {
00259 *pCharacterRects = m_CachedCharacterRects;
00260 }
00261 }
|
|
|
Reimplemented in Ars::Painter. Definition at line 89 of file arspaint.h. References states. Referenced by _TextOut(), GetMetrics(), and TextOutStr().
00089 { return states; }
|
|
|
Get the rectangle requested to draw the string. including multiple lines
Definition at line 116 of file arspaint.cpp. References Ars::FontEngine::GetFontSize(), GetMetrics(), m_bCachedMetricsValid, m_pFontEngine, Ars::XPoint::x, and Ars::XPoint::y. Referenced by Ars::XButtonImage::Draw(), Ars::XEditBox::evKeyDown(), and Ars::XToolTip::SetWndText().
00117 {
00118 string str;
00119 for( int i = 0 ; aStr[i] ; i++ )
00120 if( aStr[i] == '\t' )
00121 str += " ";
00122 else
00123 str += aStr[i];
00124 XPoint ans( 0 , 0 );
00125
00126 int nrlines = 1;
00127 string s = str;
00128 string::size_type n0 = 0 , n1 = s.find( '\n' , n0 );
00129 while( n1 != string::npos )
00130 {
00131 XPoint lineBox( 0 , 0 );
00132
00133 m_bCachedMetricsValid = false;
00134 GetMetrics( s.substr( n0 , n1 - n0 ) , &lineBox , 0 , 0 );
00135 ans.x = max( ans.x , lineBox.x );
00136 n0 = n1 + 1;
00137 n1 = s.find( '\n' , n0 );
00138 nrlines += 1;
00139 }
00140 XPoint lineBox( 0 , 0 );
00141 m_bCachedMetricsValid = false;
00142 GetMetrics( s.substr( n0 ) , &lineBox , 0 , 0 );
00143 ans.x = max( ans.x , lineBox.x );
00144
00145 ans.y = (m_pFontEngine->GetFontSize() + 2) * nrlines;
00146
00147 return ans;
00148 }
|
|
|
Locks the SDL surface.
Definition at line 491 of file arspaint.cpp. References m_pSurface, and tron. Referenced by DrawPoint().
00492 {
00493 if (!m_pSurface)
00494 {
00495 tron<< "HPaint::HPaint : Invalid pointer to surface.\n";
00496 return ;
00497 }
00498 if (SDL_MUSTLOCK(m_pSurface))
00499 {
00500 if (SDL_LockSurface(m_pSurface) < 0)
00501 {
00502 SDL_Delay(10);
00503 if (SDL_LockSurface(m_pSurface) < 0)
00504 {
00505 tron << "Unable to lock surface.\n";
00506 }
00507 }
00508 }
00509 }
|
|
||||||||||||
|
Mixes thje two colors based on the painting mode
Definition at line 524 of file arspaint.cpp. References m_PaintMode, PAINT_AND, PAINT_IGNORE, PAINT_NORMAL, PAINT_OR, PAINT_REPLACE, and PAINT_XOR. Referenced by DrawPoint().
00525 {
00526 RGBColor MixedColor( 0x00, 0x00, 0x00, 0x00 );
00527 switch (m_PaintMode)
00528 {
00529 case PAINT_IGNORE:
00530 MixedColor = ColorBase;
00531 break;
00532 case PAINT_REPLACE:
00533 MixedColor = ColorAdd;
00534 break;
00535 case PAINT_NORMAL:
00536 MixedColor = ColorBase + ColorAdd;
00537 break;
00538 case PAINT_AND:
00539 MixedColor = ColorBase &ColorAdd;
00540 break;
00541 case PAINT_OR:
00542 MixedColor = ColorBase | ColorAdd;
00543 break;
00544 case PAINT_XOR:
00545 MixedColor = ColorBase ^ ColorAdd;
00546 break;
00547 }
00548
00549 return MixedColor;
00550 }
|
|
||||||||||||
|
Definition at line 449 of file arspaint.cpp. References tron, Ars::XPoint::x, and Ars::XPoint::y.
00450 {
00451 if (!s)
00452 {
00453 tron<< "HPaint::HPaint : Invalid pointer to surface.\n";
00454 return RGBColor( 0 , 0 ,0 );
00455 }
00456 XPoint RealPoint = Point;
00457 Uint32 PixelColor = 0;
00458 if (XRect(0, 0, s->w, s->h).HitTest(RealPoint) == XRect::RELPOS_INSIDE)
00459 {
00460 Uint8* PixelOffset = static_cast<Uint8*>(s->pixels) +
00461 s->format->BytesPerPixel * RealPoint.x + s->pitch * RealPoint.y;
00462 switch (s->format->BytesPerPixel)
00463 {
00464 case 1: // 8 bpp
00465 PixelColor = *reinterpret_cast<Uint8*>(PixelOffset);
00466 break;
00467 case 2: // 16 bpp
00468 PixelColor = *reinterpret_cast<Uint16*>(PixelOffset);
00469 break;
00470 case 3: // 24 bpp
00471 {
00472 Uint8* pPixelDest = reinterpret_cast<Uint8*>(&PixelColor);
00473 Uint8* pPixelSource = reinterpret_cast<Uint8*>(PixelOffset);
00474 *pPixelDest = *pPixelSource;
00475 *(++pPixelDest) = *(++pPixelSource);
00476 *(++pPixelDest) = *(++pPixelSource);
00477 break;
00478 }
00479 case 4: // 32 bpp
00480 PixelColor = *reinterpret_cast<Uint32*>(PixelOffset);
00481 break;
00482 default:
00483 tron << "HPaint::DrawPoint : Unrecognized BytesPerPixel.\n";
00484 break;
00485 }
00486 }
00487 return RGBColor(&PixelColor, s->format);
00488 }
|
|
|
Get the color of the pixel at the given point
Definition at line 440 of file arspaint.cpp. References m_pSurface, and tron. Referenced by DrawPoint(), and ReplaceColor().
00441 {
00442 if (!m_pSurface)
00443 tron<< "HPaint::HPaint : Invalid pointer to surface.\n";
00444 else
00445 return ReadPoint( m_pSurface , Point );
00446 return RGBColor( 0 , 0 ,0 );
00447 }
|
|
||||||||||||
|
Replace all pixels of a certain color with a new color
Definition at line 553 of file arspaint.cpp. References DrawPoint(), m_pSurface, and ReadPoint().
00554 {
00555 for (int y = 0; y < m_pSurface->h; ++y)
00556 {
00557 for (int x = 0; x < m_pSurface->w; ++x)
00558 {
00559 XPoint point(x, y);
00560 if(ReadPoint(point) == OldColor)
00561 {
00562 DrawPoint(point, NewColor);
00563 }
00564 }
00565 }
00566 }
|
|
|
Definition at line 55 of file arspaint.h. References m_bCachedMetricsValid, and m_pFontEngine. Referenced by Ars::XListBox::Draw(), Ars::XTextBox::Init(), Ars::XScrollBar::Init(), Ars::XListBox::Init(), and Ars::XDropDown::Init().
00056 {
00057 FontEngine *ans = m_pFontEngine;
00058 m_pFontEngine = aFontEngine;
00059 m_bCachedMetricsValid = false;
00060 return ans;
00061 }
|
|
|
Assign a surface to draw onto.
Definition at line 108 of file arspaint.h. References m_pSurface. Referenced by Ars::Window::SetParent().
00108 { m_pSurface = surface; }
|
|
|
Set the mask character
Definition at line 103 of file arspaint.h. References m_MaskChar. Referenced by Ars::XEditBox::Draw().
00103 { m_MaskChar = MaskChar; }
|
|
|
Definition at line 48 of file arspaint.h. References EPaintMode, and m_PaintMode. Referenced by Ars::XGroupBox::Draw().
00049 {
00050 EPaintMode ans = m_PaintMode;
00051 m_PaintMode = aNewMode;
00052 return ans;
00053 }
|
|
||||||||||||
|
Reimplemented in Ars::Painter. Definition at line 76 of file arspaint.h. References HALIGN_MASK, states, and VALIGN_MASK.
00077 {
00078 if( vAlign != -1 )
00079 {
00080 states &= ~VALIGN_MASK;
00081 states |= vAlign;
00082 }
00083 if( hAlign != -1 )
00084 {
00085 states &= ~HALIGN_MASK;
00086 states |= vAlign;
00087 }
00088 }
|
|
||||||||||||||||
|
Render the string onto the given surface
Definition at line 72 of file arspaint.cpp. References _TextOut(), GetMaxFontHeight(), GetStates(), Ars::XRect::Height(), m_bCachedMetricsValid, textSize, Ars::XRect::TopLeft(), VALIGN_MASK, Ars::XPoint::x, and Ars::XPoint::y. Referenced by Ars::XTextBox::Draw(), Ars::XListBox::Draw(), Ars::XLabel::Draw(), Ars::XGroupBox::Draw(), and Ars::XEditBox::Draw().
00073 {
00074 string str;
00075 for( int i = 0 ; aStr[i] ; i++ )
00076 if( aStr[i] == '\t' )
00077 str += " ";
00078 else
00079 str += aStr[i];
00080
00081 m_bCachedMetricsValid = false;
00082 textSize = XPoint( 0 , 0 );
00083
00084 XPoint OriginPoint = BoundingRect.TopLeft();
00085 XRect drawRect = BoundingRect;
00086
00087 int nrlines = 1;
00088 string s = str;
00089 string::size_type n0 = 0 , n1 = s.find( '\n' , n0 );
00090 while( n1 != string::npos )
00091 {
00092 n0 = n1 + 1;
00093 n1 = s.find( '\n' , n0 );
00094 nrlines += 1;
00095 }
00096 if( (GetStates() & VALIGN_MASK) == 0 )
00097 OriginPoint = XPoint( OriginPoint.x , OriginPoint.y + 2 + max( 0 , (int)(drawRect.Height() - ((GetMaxFontHeight() + 2) * (nrlines -1))) / 2 ) );
00098
00099 textSize.y = (GetMaxFontHeight() + 2) * nrlines;
00100 n0 = 0 , n1 = s.find( '\n' , n0 );
00101 while( n1 != string::npos )
00102 {
00103 _TextOut( drawRect , OriginPoint , s.substr( n0 , n1 - n0 ) , FontColor );
00104
00105 n0 = n1 + 1;
00106 n1 = s.find( '\n' , n0 );
00107 if( (GetStates() & VALIGN_MASK) == 0 )
00108 OriginPoint = XPoint( OriginPoint.x , OriginPoint.y + (GetMaxFontHeight() + 2) );
00109 else
00110 drawRect.y = drawRect.y + (GetMaxFontHeight() + 2);
00111 }
00112
00113 _TextOut( drawRect , OriginPoint , s.substr( n0 ) , FontColor );
00114 }
|
|
|
Sets the transparent pixel
Definition at line 569 of file arspaint.cpp. References m_pSurface, and Ars::RGBColor::SDLColor().
00570 {
00571 SDL_SetColorKey(m_pSurface, SDL_SRCCOLORKEY, TransparentColor.SDLColor(m_pSurface->format));
00572 }
|
|
|
Unlocks the SDL surface.
Definition at line 512 of file arspaint.cpp. References m_pSurface, and tron. Referenced by DrawPoint().
00513 {
00514 if (!m_pSurface)
00515 {
00516 tron<< "HPaint::HPaint : Invalid pointer to surface.\n";
00517 return ;
00518 }
00519 if (SDL_MUSTLOCK(m_pSurface))
00520 SDL_UnlockSurface(m_pSurface);
00521 }
|
|
|
Reimplemented in Ars::Window. Definition at line 20 of file arspaint.h. |
|
|
A boolean indicating if the cached values are valid.
Definition at line 31 of file arspaint.h. Referenced by _TextOut(), GetMetrics(), GetTextSize(), SetFont(), and TextOutStr(). |
|
|
The cached value of the rendered string's dimensions.
Definition at line 28 of file arspaint.h. Referenced by GetMetrics(). |
|
|
The cached value of the CRects for the various characters.
Definition at line 30 of file arspaint.h. Referenced by GetMetrics(). |
|
|
Character to use as the mask, used for passwords and such.
Definition at line 32 of file arspaint.h. Referenced by _TextOut(), GetMetrics(), and SetMaskChar(). |
|
|
Maximum height of any character with ASCII value 0-255 for the current font.
Definition at line 33 of file arspaint.h. Referenced by GetMaxFontHeight(). |
|
|
The cached value of the string's offset from the origin.
Definition at line 29 of file arspaint.h. Referenced by GetMetrics(). |
|
|
The painting mode to use.
Definition at line 24 of file arspaint.h. Referenced by MixColor(), and SetMode(). |
|
|
A pointer to the Font Engine.
Definition at line 26 of file arspaint.h. Referenced by _TextOut(), GetFont(), GetFontSize(), GetMaxFontHeight(), GetMetrics(), GetTextSize(), HPaint(), Ars::Painter::Init(), and SetFont(). |
|
|
A pointer to the SDL Surface to draw on.
Definition at line 22 of file arspaint.h. Referenced by DrawHLine(), DrawLine(), DrawPoint(), DrawRect(), DrawVLine(), GetGDI(), LockSurface(), ReadPoint(), ReplaceColor(), SetGDI(), TransparentColor(), UnlockSurface(), Ars::View::View(), Ars::View::wmResize(), and Ars::View::~View(). |
|
|
Definition at line 5 of file arspaint.cpp. |
|
|
Text alignment when HPaint used alone....
Definition at line 38 of file arspaint.h. Referenced by GetStates(), and SetTextAlign(). |
|
|
Definition at line 34 of file arspaint.h. Referenced by _TextOut(), and TextOutStr(). |
1.3.3