8b5037a6 |
1 | /** |
2 | * @section LICENSE |
3 | * |
4 | * PickleLauncher |
5 | * Copyright (C) 2010-2011 Scott Smith |
6 | * |
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. |
11 | * |
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. |
16 | * |
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/>. |
19 | * |
20 | * @section LOCATION |
21 | */ |
22 | |
23 | #ifndef CBASE_H |
24 | #define CBASE_H |
25 | |
26 | #include <cctype> |
27 | #include <string> |
28 | #include <vector> |
29 | #include <algorithm> |
30 | #include <fstream> |
31 | #include <sstream> |
32 | #include <iostream> |
33 | #include <iomanip> |
34 | #include <dirent.h> |
35 | #include <stdlib.h> |
36 | #include <errno.h> |
37 | #include <sys/stat.h> |
38 | #include <sys/types.h> |
39 | #include <fcntl.h> |
40 | #include <sys/mman.h> |
41 | #include <unistd.h> //*SEB* for execlp |
42 | |
43 | #include "SDL.h" |
44 | #include "SDL_ttf.h" |
45 | #include "SDL_image.h" |
46 | |
47 | using namespace std; |
48 | |
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. */ |
51 | |
52 | /** @brief Generic class to hold any common methods usable by any other class |
53 | */ |
54 | class CBase |
55 | { |
56 | public: |
57 | /** Constructor. */ |
58 | CBase(); |
59 | /** Destructor. */ |
60 | virtual ~CBase(); |
61 | |
62 | /** @brief Logging function |
63 | * @param output : formating string to write to the log |
64 | */ |
65 | void Log ( const char* output, ... ); |
66 | |
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 |
70 | */ |
71 | uint32_t CheckRange ( int32_t value, int32_t size ); |
72 | |
73 | /** @brief Convert color componets to a single integer |
74 | * @param color : SDL color struct with color components |
75 | * @return color in integer form |
76 | */ |
77 | uint32_t rgb_to_int ( SDL_Color color ); |
78 | |
79 | /** @brief Convert string to integer form |
80 | * @param line : string to convert (typically one character) |
81 | * @return string in integer form |
82 | */ |
83 | int32_t a_to_i ( const string& line ); |
84 | |
85 | /** @brief Convert integer to string form |
86 | * @param num : integer to convert |
87 | * @return integer in string form |
88 | */ |
89 | string i_to_a ( const int16_t num ); |
90 | |
91 | /** @brief Convert string to all lowercase characters |
92 | * @param text : string to convert |
93 | * @return copy fo string in all lowercase characters |
94 | */ |
95 | string lowercase ( string text ); |
96 | |
97 | /** @brief Load graphics from file |
98 | * @param filename : file location to the graphic |
99 | * @return pointer to the optimized graphic |
100 | */ |
101 | SDL_Surface* LoadImage ( const string& filename ); |
102 | |
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 |
109 | */ |
110 | void ApplyImage ( int16_t x, int16_t y, SDL_Surface* src, SDL_Surface* dst, SDL_Rect* clip ); |
111 | |
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 |
116 | */ |
117 | bool CheckRectCollision ( SDL_Rect* boxA, SDL_Rect* boxB ); |
118 | |
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 |
123 | */ |
124 | void SplitString ( const std::string& delimiter, const std::string& text, vector<string>& array ); |
125 | |
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 |
131 | */ |
132 | bool UnprefixString ( string& result, const string& line, const string& prefix ); |
133 | |
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 |
138 | */ |
139 | int16_t CheckExtension ( const string& filename, const string& ext ); |
140 | |
141 | /** @brief Checks a string path if ended with a backslash |
142 | * @param path : string path to scan |
143 | */ |
144 | void CheckPath ( string& path ); |
145 | |
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 |
149 | */ |
150 | string cmdclean ( string& cmdline ); |
151 | |
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 |
157 | */ |
158 | string strreplace ( string& orig, const string& search, const string& replace ); |
159 | |
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 |
165 | */ |
166 | SDL_Surface* ScaleSurface ( SDL_Surface *surface, uint16_t width, uint16_t height ); |
167 | |
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 |
172 | * @return pixel data |
173 | */ |
174 | uint32_t getpixel ( SDL_Surface *surface, int16_t x, int16_t y ); |
175 | |
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 |
180 | */ |
181 | void putpixel ( SDL_Surface *surface, int16_t x, int16_t y, uint32_t pixel ); |
182 | }; |
183 | |
184 | #endif // CBASE_H |