00001 
00002 
00003 
00004 
00005 
00007 
00008 
00010 
00011 #ifndef __CDESKTOP_H__
00012 #define __CDESKTOP_H__
00013 
00014 #include <assert.h>
00015 
00016 #include "MFrameBuffer.h" 
00017 
00029 class CDesktop  
00030 {
00031  public:        
00032   typedef unsigned int TColor; 
00034  public:
00039   static TColor GetNearestColor( unsigned int aR, unsigned int aG, unsigned int aB );
00040 
00043   static void   PutPixel( MFrameBuffer& aFrameBuffer, unsigned int aX, unsigned int aY, TColor aColor );
00044 
00047   static TColor GetPixel( MFrameBuffer& aFrameBuffer, unsigned int aX, unsigned int aY );
00048 
00051   static void   HLine( MFrameBuffer& aFrameBuffer, unsigned int aXFrom, unsigned int aY, unsigned int aXTo, TColor aColor );
00052 
00055   static void   VLine( MFrameBuffer& aFrameBuffer, unsigned int aX, unsigned int aYFrom, unsigned int aYTo, TColor aColor );
00056 
00061   static void   Line( MFrameBuffer& aFrameBuffer, unsigned int aXFrom, unsigned int aYFrom, unsigned int aXTo,unsigned int aYTo, TColor aColor );
00062 
00065   static void   Rect( MFrameBuffer& aFrameBuffer, unsigned int aXFrom, unsigned int aYFrom, unsigned int aXTo, unsigned int aYTo, TColor aColor);
00066 
00077   static void   RectFill( MFrameBuffer& aFrameBuffer, unsigned int aXFrom, unsigned int aYFrom, unsigned int aXTo, unsigned int aYTo, TColor aColor, unsigned int aRounding );
00078 
00080 
00081   static const TColor ColorBlack;
00082   static const TColor ColorWhite;
00083   static const TColor ColorLightGray;
00084   static const TColor ColorDarkGray;
00085   static const TColor ColorYellow;
00086   static const TColor ColorVeryLightBlue;
00087   static const TColor ColorLightBlue;
00088   static const TColor ColorCyan;
00089   static const TColor ColorRed;
00090   static const TColor ColorGreen;
00091   static const TColor ColorBrown;
00092   static const TColor ColorLightGreen;
00093   static const TColor ColorBlue;
00094   static const TColor ColorPink;
00095   static const TColor ColorDarkPink;
00096   static const TColor ColorOrange;
00098 
00099  private:
00100   CDesktop();
00101   CDesktop( const CDesktop& );
00102   CDesktop& operator=( CDesktop& );
00103 
00104  private:
00105   static char* GetPixelAddress( MFrameBuffer& aFrameBuffer, unsigned int aX,unsigned int aY );
00106 };
00107 
00108 
00109 inline char* CDesktop::GetPixelAddress( MFrameBuffer& aFrameBuffer, unsigned int aX,unsigned int aY )
00110 {
00111 
00112 
00113 
00114  return aFrameBuffer.GetScreenBuffer() + aFrameBuffer.GetPixelAddressOffset( aX, aY );
00115 }
00116 
00117 inline void CDesktop::PutPixel( MFrameBuffer& aFrameBuffer, unsigned int aX,unsigned int aY, CDesktop::TColor aColor )
00118 {
00119   
00120 
00121 
00122 
00123   if (aX < aFrameBuffer.GetWidth() && aY < aFrameBuffer.GetHeight() )
00124   {
00125     *reinterpret_cast< unsigned short *>( GetPixelAddress( aFrameBuffer, aX, aY ) ) =
00126       static_cast< unsigned short >( aColor ); 
00127   }
00128 }
00129 
00130 
00131 inline CDesktop::TColor CDesktop::GetPixel( MFrameBuffer& aFrameBuffer, unsigned int aX,unsigned int aY )
00132 {
00133 
00134 
00135 
00136 
00137  return 
00138   *reinterpret_cast< unsigned short *>( GetPixelAddress( aFrameBuffer, aX, aY ) );
00139 }
00140 
00141 
00142 inline CDesktop::TColor CDesktop::GetNearestColor( unsigned int aR, unsigned int aG, unsigned int aB )
00143 {
00144  
00145  
00146  return ( ( aR & 0xF8 ) << 8 ) | 
00147             ( ( aG & 0xFC ) << 3 ) |
00148                 ( ( aB & 0xF8 ) >> 3 );
00149 }
00150 
00151 #endif // __CDESKTOP_H__