OpenVideo Documentation

   Main Page       Modules       Class Hierarchy       Alphabetical List       Compound List       File List       Compound Members       Related Pages   

utility.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // PocketHAL
00004 // Copyright 2004 by Thierry Tremblay
00005 //
00007 
00008 #include "utility.h"
00009 
00010 
00011 namespace PHAL
00012 {
00013 
00015 //
00016 // Static data
00017 //
00019 
00020 static const uint8_t VGAFONT[] =
00021 {
00022     #include "VGAFont.h"
00023 };
00024 
00025 static const int CHAR_WIDTH  = 8;       // 8 pixels wide
00026 static const int CHAR_HEIGHT = 16;      // 16 pixels high
00027 static const int CHAR_SIZE   = 16;      // 16 bytes / character
00028 
00029 
00030 
00032 //
00033 // Utility functions
00034 //
00036 
00037 void Clear( Surface* surface, uint16_t color )
00038 {
00039     // We operate on two pixels at a time. The count
00040     // thus represents the number of pixel pairs.
00041     unsigned  count    = surface->GetHeight() * surface->GetPitch() >> 2;
00042     uint32_t* pixels   = (uint32_t*)surface->GetPixels();
00043     uint32_t  color32  = (color << 16) | (color);
00044 
00045     while (count--)
00046         *pixels++ = color32;
00047 }
00048 
00049 
00050 
00051 bool DrawChar( Surface* surface, int x, int y, char character, uint16_t color )
00052 {
00053     // Check surface dimensions
00054     if (x < 0 || y < 0 || x + CHAR_WIDTH > (int)surface->GetWidth() || y + CHAR_HEIGHT > (int)surface->GetHeight())
00055         return false;
00056 
00057     // Draw the char
00058     const uint8_t* glyph = &VGAFONT[character * CHAR_SIZE];
00059 
00060     for (int row = 0; row != CHAR_HEIGHT; ++row, ++glyph)
00061     {
00062         uint16_t* pixels = surface->GetPixels( x, y + row );
00063 
00064         if (*glyph & 0x80) *pixels = color; ++pixels;
00065         if (*glyph & 0x40) *pixels = color; ++pixels;
00066         if (*glyph & 0x20) *pixels = color; ++pixels;
00067         if (*glyph & 0x10) *pixels = color; ++pixels;
00068         if (*glyph & 0x08) *pixels = color; ++pixels;
00069         if (*glyph & 0x04) *pixels = color; ++pixels;
00070         if (*glyph & 0x02) *pixels = color; ++pixels;
00071         if (*glyph & 0x01) *pixels = color; ++pixels;
00072     }
00073 
00074     return true;
00075 }
00076 
00077 
00078 
00079 void DrawText( Surface* surface, int x, int y, const char* text, uint16_t color )
00080 {
00081     // Draw each character...
00082     for ( ; *text; ++text, x += CHAR_WIDTH)
00083     {
00084         if (!DrawChar( surface, x, y, *text, color ))
00085             return;
00086     }
00087 }
00088 
00089 
00090 
00091 
00092 } // end of namespace PHAL
 This page was generated at Wed May 31 13:04:16 2006 for OpenVideo by Doxygen.
 If you have any comments, please send a message to schmalstieg@icg.tu-graz.ac.at.
www.studierstube.org