00001 /* 00002 $Id: mapview.h,v 1.29 2003/02/23 23:14:34 ksterker Exp $ 00003 00004 Copyright (C) 1999/2000/2001 Alexandre Courbot 00005 Part of the Adonthell Project http://adonthell.linuxgames.com 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License. 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY. 00011 00012 See the COPYING file for more details. 00013 */ 00014 00015 00016 /** 00017 * @file mapview.h 00018 * @author Alexandre Courbot <alexandrecourbot@linuxgames.com> 00019 * 00020 * @brief Declares the mapview class. 00021 * 00022 * 00023 */ 00024 00025 00026 00027 #ifndef MAPVIEW_H_ 00028 #define MAPVIEW_H_ 00029 00030 #include "landmap.h" 00031 #include "python_class.h" 00032 00033 00034 /** 00035 * Allows you to display a landmap on a specified area of a surface. 00036 * 00037 * This class just acts as a "camera" which takes snapshots of a landmap. 00038 * It's size can be specified, a schedule can be set to 00039 * update it's movment. Nothing prevents you from having several mapviews 00040 * on the same map that displays each a different (or similar) part of the 00041 * landmap. 00042 * 00043 */ 00044 class mapview : public drawable 00045 { 00046 00047 public: 00048 00049 /** 00050 * Default constructor. 00051 * 00052 */ 00053 mapview (); 00054 00055 /** 00056 * Destructor. 00057 * 00058 */ 00059 ~mapview (); 00060 00061 /** 00062 * Attach/Detach a map 00063 * 00064 */ 00065 00066 //@{ 00067 00068 00069 /** 00070 * Sets which map this mapview will display. 00071 * 00072 * @param m pointer to the map that will be displayed by the mapview. 00073 */ 00074 void attach_map (landmap * m); 00075 00076 /** 00077 * Stops displaying a map. 00078 * 00079 */ 00080 void detach_map (); 00081 00082 //@} 00083 00084 00085 /** 00086 * Position settings 00087 * 00088 */ 00089 00090 //@{ 00091 00092 /** 00093 * Sets the position of the top-left corner of the mapview on the map. 00094 * 00095 * You'll probably don't want to use this method. To center the mapview 00096 * on a precise position, see center_on () instead. 00097 * 00098 * @param sm submap. 00099 * @param x X position. 00100 * @param y Y position. 00101 * @param ox X offset. 00102 * @param oy Y offset. 00103 * 00104 * @sa center_on () 00105 * 00106 */ 00107 s_int8 set_pos (u_int16 sm, u_int16 x, u_int16 y, s_int16 ox = 0, s_int16 oy = 0); 00108 00109 /** 00110 * Sets the position of the center of the mapview on the map. 00111 * 00112 * @param sm submap. 00113 * @param x X position. 00114 * @param y Y position. 00115 * @param ox X offset. 00116 * @param oy Y offset. 00117 * 00118 */ 00119 s_int8 center_on (u_int16 sm, u_int16 x, u_int16 y, s_int16 ox = 0, s_int16 oy = 0); 00120 00121 //@} 00122 00123 00124 /** 00125 * Position information 00126 * 00127 */ 00128 00129 //@{ 00130 00131 /** 00132 * Returns the submap this mapview is displaying. 00133 * 00134 * 00135 * @return current submap this mapview is displaying. 00136 */ 00137 u_int16 currentsubmap () 00138 { 00139 return currentsubmap_; 00140 } 00141 00142 /** 00143 * Returns the X position of the mapview. 00144 * 00145 * 00146 * @return X position of the mapview. 00147 */ 00148 u_int16 posx () const 00149 { 00150 return posx_; 00151 } 00152 00153 /** 00154 * Returns the Y position of the mapview. 00155 * 00156 * 00157 * @return Y position of the mapview. 00158 */ 00159 u_int16 posy () const 00160 { 00161 return posy_; 00162 } 00163 00164 /** 00165 * Returns the X offset of the mapview. 00166 * 00167 * 00168 * @return X offset of the mapview. 00169 */ 00170 u_int16 offx () const 00171 { 00172 return offx_; 00173 } 00174 00175 /** 00176 * Returns the Y offset of the mapview. 00177 * 00178 * 00179 * @return Y offset of the mapview. 00180 */ 00181 u_int16 offy () const 00182 { 00183 return offy_; 00184 } 00185 00186 //@} 00187 00188 /** 00189 * Basic movment 00190 * 00191 */ 00192 00193 //@{ 00194 00195 /** 00196 * Returns whether it is possible to scroll to right. A scrolling is impossible 00197 * if the mapview is at the map limits. 00198 * 00199 * 00200 * @return true if a right scrolling is possible, false otherwise. 00201 */ 00202 bool can_scroll_right () 00203 { 00204 s_int32 tpx = posx () * MAPSQUARE_SIZE + offx () + length (); 00205 return (tpx < m_map->submap[currentsubmap_]->area_length () * MAPSQUARE_SIZE); 00206 } 00207 00208 /** 00209 * Returns whether it is possible to scroll to left. A scrolling is impossible 00210 * if the mapview is at the map limits. 00211 * 00212 * 00213 * @return true if a left scrolling is possible, false otherwise. 00214 */ 00215 bool can_scroll_left () 00216 { 00217 return (posx_ || offx_); 00218 } 00219 00220 /** 00221 * Returns whether it is possible to scroll to up. A scrolling is impossible 00222 * if the mapview is at the map limits. 00223 * 00224 * 00225 * @return true if a up scrolling is possible, false otherwise. 00226 */ 00227 bool can_scroll_up () 00228 { 00229 return (posy_ || offy_); 00230 } 00231 00232 /** 00233 * Returns whether it is possible to scroll to down. A scrolling is impossible 00234 * if the mapview is at the map limits. 00235 * 00236 * 00237 * @return true if a down scrolling is possible, false otherwise. 00238 */ 00239 bool can_scroll_down () 00240 { 00241 s_int32 tpy = posy () * MAPSQUARE_SIZE + offy () + height (); 00242 return (tpy < m_map->submap[currentsubmap_]->area_height () * MAPSQUARE_SIZE); 00243 } 00244 00245 /** 00246 * Scrolls 1 pixel to right, if possible. 00247 * 00248 */ 00249 void scroll_right (); 00250 00251 /** 00252 * Scrolls 1 pixel to left, if possible. 00253 * 00254 */ 00255 void scroll_left (); 00256 00257 /** 00258 * Scrolls 1 pixel to down, if possible. 00259 * 00260 */ 00261 void scroll_down (); 00262 00263 /** 00264 * Scrolls 1 pixel to up, if possible. 00265 * 00266 */ 00267 void scroll_up (); 00268 00269 //@} 00270 00271 00272 /** 00273 * State saving/loading 00274 * 00275 */ 00276 00277 //@{ 00278 00279 /** 00280 * Restore the mapview's state from an opened file. 00281 * 00282 * @param file the opened file from which to load the state. 00283 * 00284 * @return 0 in case of success, error code otherwise. 00285 */ 00286 s_int8 get_state (igzstream& file); 00287 00288 /** 00289 * Saves the mapview's state into an opened file. 00290 * 00291 * @param file the opened file where to the state. 00292 * 00293 * @return 0 in case of success, error code otherwise. 00294 */ 00295 s_int8 put_state (ogzstream& file); 00296 00297 //@} 00298 00299 /** 00300 * Resize the mapview. The parameters are given in pixels. 00301 * 00302 * @param l new length. 00303 * @param h new height. 00304 */ 00305 void resize (u_int16 l, u_int16 h); 00306 00307 /** 00308 * Assign a schedule to the mapview. 00309 * 00310 * The schedule's filename will be \e "scripts/schedules/mapviews/<file>.py". 00311 * 00312 * @param file name of the schedule to use. 00313 * @param args Python tuple containing extra arguments passed to the class constructor. 00314 * 00315 * @warning the args tuple argument MUST ONLY contain strings or integers, as it will 00316 * be saved with the mapcharacter state by python::put_tuple (). 00317 * 00318 */ 00319 void set_schedule (string file, PyObject * args = NULL); 00320 00321 /** 00322 * Returns the name of the mapview's current schedule. 00323 * 00324 * 00325 * @return name of the mapview's current schedule. 00326 */ 00327 string schedule_file () 00328 { 00329 return schedule_file_; 00330 } 00331 00332 /** 00333 * Updates the mapview's state and launchs his schedule. 00334 * 00335 */ 00336 bool update (); 00337 00338 void draw (s_int16 x, s_int16 y, const drawing_area * da_opt = NULL, 00339 surface *target = NULL) const; 00340 00341 private: 00342 /** 00343 * Forbid value passing. 00344 */ 00345 mapview (const mapview& src); 00346 00347 #ifndef SWIG 00348 void draw_tile (s_int16 x, s_int16 y, const drawing_area * da_opt, surface * target, 00349 list<mapsquare_tile>::iterator it) const; 00350 00351 void draw_mapchar (s_int16 x, s_int16 y, const drawing_area * da_opt, 00352 surface * target, list<mapsquare_char>::iterator itc) const; 00353 void draw_bubble (s_int16 x, s_int16 y, const drawing_area * da_opt, 00354 surface * target, list<mapcharacter *>::iterator itc) const; 00355 #endif 00356 00357 landmap *m_map; 00358 00359 u_int16 d_length, d_height; // size of the view in map squares 00360 00361 u_int16 currentsubmap_; 00362 u_int16 posx_, posy_; 00363 u_int16 offx_, offy_; 00364 00365 00366 mutable drawing_area da; 00367 00368 py_object schedule; 00369 00370 PyObject * schedule_args; 00371 00372 string schedule_file_; 00373 }; 00374 00375 #endif