Skip to content

Commit

Permalink
updated docs and removed some throw restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
stohrendorf committed Jun 24, 2011
1 parent f7b7000 commit 33cd11a
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 60 deletions.
15 changes: 15 additions & 0 deletions src/ppg/ppgexcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@
#include <iostream>
#include <sstream>

/**
* @ingroup Ppg
* @{
*/

namespace ppg {

/**
* @brief Build a string representing a source file position
* @param[in] lineno Line number
* @param[in] function Function name
* @return String in the form of "{lineno}:{function}"
*/
static std::string makePos( int lineno, const char function[] ) {
std::ostringstream out;
out << std::dec << lineno << ":" << function;
Expand Down Expand Up @@ -51,3 +62,7 @@ namespace ppg {
}

} // namespace ppg

/**
* @}
*/
16 changes: 11 additions & 5 deletions src/ppg/ppgexcept.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
#include <exception>
#include <stdexcept>

/**
* @ingroup Ppg
* @{
*/

namespace ppg {
/**
* @class Exception
* @ingroup Ppg
* @brief A simple tracing exception for PeePeeGUI
*/
class Exception : public std::exception {
Expand All @@ -42,15 +46,13 @@ namespace ppg {
/**
* @brief Constructor with additional information
* @param[in] msg Initial Message
* @param[in] file File name (use @c __BASE_FILE__ or @c __FILE__ here)
* @param[in] lineno Line number (use @c __LINE__ here)
* @param[in] function Function (use @c __PRETTY_FUNCTION__ or @c __FUNCTION__ here)
*/
Exception( const std::string& msg, int lineno, const char function[] ) throw();
/**
* @brief Constructor with additional information for Re-Throws
* @param[in] previous Previous PppException
* @param[in] file File name (use @c __BASE_FILE__ or @c __FILE__ here)
* @param[in] lineno Line number (use @c __LINE__ here)
* @param[in] function Function (use @c __PRETTY_FUNCTION__ or @c __FUNCTION__ here)
* @see PPG_RETHROW
Expand All @@ -65,7 +67,7 @@ namespace ppg {
virtual ~Exception() throw();
/**
* @brief Get the exception message
* @return Message
* @return m_msg
*/
virtual const char* what() const throw();
};
Expand All @@ -74,7 +76,6 @@ namespace ppg {

/**
* @brief Catch PeePeeGUI exceptions
* @ingroup Ppg
* @details
* Catches general exceptions and throws a ppg::Exception for tracing the exception
*/
Expand Down Expand Up @@ -107,4 +108,9 @@ namespace ppg {

} // namespace ppg

/**
* @}
*/


#endif
74 changes: 64 additions & 10 deletions src/ppg/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,74 @@
#include <SDL.h>
#include <SDL_endian.h>

/**
* @ingroup Ppg
* @{
*/

namespace ppg {

/**
* @name Internal data and functions
* @{
* @details
* The g_ABC and g_currentABC arrays are compared everytime the screen needs to be redrawn.@n
* If at least one of the foreground colors, background colors or characters differ, it is redrawn,
* otherwise it is skipped. See ppg::Screen::drawThis().@n
* This reduces the graphical overhead significantly.
*/
/**
* @brief Maps DOS color values to their on-screen representation
* @see ppg::Color
*/
static Uint32 g_dosColors[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
/**
* @brief Contains the chars to be displayed
* @see g_currentChars
*/
static char* g_chars = NULL;
/**
* @brief Contains the chars currently visible to determine what needs to be drawn
* @see g_chars
*/
static char* g_currentChars = NULL;
/**
* @brief Contains the foreground colors to be displayed
*/
static Color* g_colorsF = NULL;
/**
* @brief Contains the foreground colors currently visible to determine what needs to be drawn
*/
static Color* g_currentColorsF = NULL;
/**
* @brief Contains the background colors to be displayed
*/
static Color* g_colorsB = NULL;
/**
* @brief Contains the background colors currently visible to determine what needs to be drawn
*/
static Color* g_currentColorsB = NULL;
/**
* @brief The current SDL screen surface instance
*/
static SDL_Surface* g_screenSurface = NULL;

static inline void g_drawPixel( int x, int y, Uint32 color ) throw() {
/**
* @brief Draw a pixel
* @param[in] x X position
* @param[in] y Y position
* @param[in] color %Screen color value
*/
static inline void g_drawPixel( int x, int y, Uint32 color ) {
if( ( x < 0 ) || ( y < 0 ) || ( y >= g_screenSurface->h ) || ( x >= g_screenSurface->w ) )
return;
reinterpret_cast<Uint32*>( g_screenSurface->pixels )[( ( y * g_screenSurface->pitch ) >> 2 ) + x] = color;
}
/**
* @}
*/

Screen::Screen( int w, int h, const std::string& title ) throw( Exception ) : Widget( NULL ), m_cursorX( 0 ), m_cursorY( 0 ) {
Screen::Screen( int w, int h, const std::string& title ) : Widget( NULL ), m_cursorX( 0 ), m_cursorY( 0 ) {
PPG_TEST( g_screenSurface != NULL );
if( !SDL_WasInit( SDL_INIT_VIDEO ) ) {
if( SDL_Init( SDL_INIT_VIDEO ) == -1 ) {
Expand Down Expand Up @@ -102,7 +152,7 @@ namespace ppg {
SDL_ShowCursor( 0 );
}

Screen::~Screen() throw() {
Screen::~Screen() {
delete[] g_chars;
g_chars = NULL;
delete[] g_currentChars;
Expand All @@ -119,7 +169,7 @@ namespace ppg {

#include "pfonts.inc"

void Screen::drawChar8( int x, int y, uint8_t c, uint32_t foreground, uint32_t background, bool opaque ) throw() {
void Screen::drawChar8( int x, int y, uint8_t c, uint32_t foreground, uint32_t background, bool opaque ) {
x <<= 3;
y <<= 3;
for( unsigned char py = 0; py < 8; py++ ) {
Expand All @@ -132,7 +182,7 @@ namespace ppg {
}
}

void Screen::drawChar16( int x, int y, uint8_t c, uint32_t foreground, uint32_t background, bool opaque ) throw() {
void Screen::drawChar16( int x, int y, uint8_t c, uint32_t foreground, uint32_t background, bool opaque ) {
x <<= 3;
y <<= 4;
for( unsigned char py = 0; py < 16; py++ ) {
Expand All @@ -145,14 +195,14 @@ namespace ppg {
}
}

void Screen::clear( uint8_t c, Color foreground, Color background ) throw() {
void Screen::clear( uint8_t c, Color foreground, Color background ) {
std::size_t size = area().width() * area().height();
std::fill_n( g_chars, size, c );
std::fill_n( g_colorsF, size, foreground );
std::fill_n( g_colorsB, size, background );
}

void Screen::drawThis() throw( Exception ) {
void Screen::drawThis() {
if( SDL_MUSTLOCK( g_screenSurface ) ) {
if( SDL_LockSurface( g_screenSurface ) < 0 )
return;
Expand Down Expand Up @@ -187,21 +237,21 @@ namespace ppg {
PPG_THROW( "Flip failed" );
}

void Screen::drawChar( int x, int y, char c ) throw() {
void Screen::drawChar( int x, int y, char c ) {
if( !area().contains( x, y ) ) {
LOG_ERROR( "Out of range: %d,%d", x, y );
return;
}
g_chars[x + y * area().width()] = c;
}

void Screen::setFgColorAt( int x, int y, Color c ) throw() {
void Screen::setFgColorAt( int x, int y, Color c ) {
if( !area().contains( x, y ) )
return;
g_colorsF[x + y * area().width()] = c;
}

void Screen::setBgColorAt( int x, int y, Color c ) throw() {
void Screen::setBgColorAt( int x, int y, Color c ) {
if( !area().contains( x, y ) )
return;
g_colorsB[x + y * area().width()] = c;
Expand All @@ -215,3 +265,7 @@ namespace ppg {
}

} // namespace ppg

/**
* @}
*/
18 changes: 9 additions & 9 deletions src/ppg/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ namespace ppg {
* @param[in] background Background color
* @param[in] opaque Set to @c false to draw a transparent char
*/
void drawChar8( int x, int y, uint8_t c, uint32_t foreground, uint32_t background, bool opaque = true ) throw();
void drawChar8( int x, int y, uint8_t c, uint32_t foreground, uint32_t background, bool opaque = true );
/**
* @copydoc ppg::Screen::drawChar8
* @brief Draw an 8x16 char
*/
void drawChar16( int x, int y, uint8_t c, uint32_t foreground, uint32_t background, bool opaque = true ) throw();
virtual void drawThis() throw( Exception );
void drawChar16( int x, int y, uint8_t c, uint32_t foreground, uint32_t background, bool opaque = true );
virtual void drawThis();
int m_cursorX; //!< @brief Cursor X position
int m_cursorY; //!< @brief Cursor Y position
public:
Expand All @@ -55,18 +55,18 @@ namespace ppg {
* @param[in] h Height in characters
* @param[in] title Title of the screen
*/
Screen( int w, int h, const std::string& title ) throw( Exception );
virtual ~Screen() throw();
Screen( int w, int h, const std::string& title );
virtual ~Screen();
/**
* @brief Clear the screen
* @param[in] c Character to overwrite the screen with
* @param[in] foreground Foreground color
* @param[in] background Background color
*/
void clear( uint8_t c, Color foreground, Color background ) throw();
virtual void drawChar( int x, int y, char c ) throw();
virtual void setFgColorAt( int x, int y, Color c ) throw();
virtual void setBgColorAt( int x, int y, Color c ) throw();
void clear( uint8_t c, Color foreground, Color background );
virtual void drawChar( int x, int y, char c );
virtual void setFgColorAt( int x, int y, Color c );
virtual void setBgColorAt( int x, int y, Color c );
virtual bool onMouseMove( int x, int y );
};
} // namespace ppg
Expand Down
2 changes: 2 additions & 0 deletions src/s3mmod/s3mcell.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class S3mCell : public GenCell {
/**
* @brief Load this cell from a stream
* @param[in,out] str Reference to the stream to load from
* @retval true on success
* @retval false if an error occured
*/
bool load(BinStream& str);
virtual void clear();
Expand Down
Loading

0 comments on commit 33cd11a

Please sign in to comment.