5 * Copyright (C) 2010-2011 Scott Smith
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 #include <sys/types.h>
41 #include <unistd.h> //*SEB* for execlp
45 #include "SDL_image.h"
49 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) /**< Return minimum of two numbers. */
50 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) /**< Return maximum of two numbers. */
52 /** @brief Generic class to hold any common methods usable by any other class
62 /** @brief Logging function
63 * @param output : formating string to write to the log
65 void Log ( const char* output, ... );
67 /** @brief Checks a value is between 0 and size
68 * @param value : value for the range check
69 * @param size : max that the value should be less than
71 uint32_t CheckRange ( int32_t value, int32_t size );
73 /** @brief Convert color componets to a single integer
74 * @param color : SDL color struct with color components
75 * @return color in integer form
77 uint32_t rgb_to_int ( SDL_Color color );
79 /** @brief Convert string to integer form
80 * @param line : string to convert (typically one character)
81 * @return string in integer form
83 int32_t a_to_i ( const string& line );
85 /** @brief Convert integer to string form
86 * @param num : integer to convert
87 * @return integer in string form
89 string i_to_a ( const int16_t num );
91 /** @brief Convert string to all lowercase characters
92 * @param text : string to convert
93 * @return copy fo string in all lowercase characters
95 string lowercase ( string text );
97 /** @brief Load graphics from file
98 * @param filename : file location to the graphic
99 * @return pointer to the optimized graphic
101 SDL_Surface* LoadImage ( const string& filename );
103 /** @brief Blit a surface to another surface(screen)
104 * @param x : x coordinate location for the blit
105 * @param y : y coordinate location for the blit
106 * @param src : source graphic to blit to destination
107 * @param dst : destination graphic to blit to source
108 * @param clip : dimensions to clip the source graphic
110 void ApplyImage ( int16_t x, int16_t y, SDL_Surface* src, SDL_Surface* dst, SDL_Rect* clip );
112 /** @brief Detect collision by determining if two rects overlap
113 * @param boxA : first rect
114 * @param boxB : second rect
115 * @return true if collision occured, false if it has not
117 bool CheckRectCollision ( SDL_Rect* boxA, SDL_Rect* boxB );
119 /** @brief Separate string into different substring based on a delimter string
120 * @param delimiter : string value to separate text string
121 * @param text : string to separate
122 * @param array : contains all of the separate string parts
124 void SplitString ( const std::string& delimiter, const std::string& text, vector<string>& array );
126 /** @brief Removes a prefix from the beginning of the line and returns the result
127 * @param result : resulting string
128 * @param line : string to separate
129 * @param prefix : string to remove
130 * @return true if prefix was found and removed, false if it has not
132 bool UnprefixString ( string& result, const string& line, const string& prefix );
134 /** @brief Checks a string filename to be ended by a extension string
135 * @param filename : string filename to scan
136 * @param ext : string extension to find
137 * @return position of ext if found
139 int16_t CheckExtension ( const string& filename, const string& ext );
141 /** @brief Checks a string path if ended with a backslash
142 * @param path : string path to scan
144 void CheckPath ( string& path );
146 /** @brief Removes a list of characters from the string command line
147 * @param cmdline : string command line to filter
148 * @return the filtered string
150 string cmdclean ( string& cmdline );
152 /** @brief Replaces one string for another string
153 * @param orig : original string to search
154 * @param search : string to search
155 * @param replace : string to replace any instances of string search
156 * @return the modified result
158 string strreplace ( string& orig, const string& search, const string& replace );
160 /** @brief Scales the input surface to a new surface with the dimensions provided
161 * @param surface : input image to be scaled
162 * @param width : width of the new scaled image
163 * @param height : height of the new scaled image
164 * @return the new scaled image
166 SDL_Surface* ScaleSurface ( SDL_Surface *surface, uint16_t width, uint16_t height );
168 /** @brief Gets the pixel data at the provided coordinates
169 * @param surface : input image to be read
170 * @param x : x position of the pixel
171 * @param y : y position of the pixel
174 uint32_t getpixel ( SDL_Surface *surface, int16_t x, int16_t y );
176 /** @brief Writes the pixel data at the provided coordinates
177 * @param surface : input image to be modified
178 * @param x : x position of the pixel
179 * @param y : y position of the pixel
181 void putpixel ( SDL_Surface *surface, int16_t x, int16_t y, uint32_t pixel );