storyscreen/part.hpp

Go to the documentation of this file.
00001 /* $Id: part.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2009 - 2012 by Ignacio R. Morelle <shadowm2006@gmail.com>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /**
00017  * @file
00018  * Storyscreen parts and floating images representation.
00019  */
00020 
00021 #ifndef STORYSCREEN_PART_HPP_INCLUDED
00022 #define STORYSCREEN_PART_HPP_INCLUDED
00023 
00024 #include <string>
00025 #include <utility>
00026 #include <vector>
00027 
00028 #include "sdl_utils.hpp"
00029 
00030 class config;
00031 class vconfig;
00032 class display;
00033 class game_state;
00034 
00035 namespace storyscreen {
00036 
00037 /**
00038  * Represents and contains information about image labels used
00039  * in story screen parts.
00040  */
00041 class floating_image
00042 {
00043 public:
00044     struct render_input
00045     {
00046         SDL_Rect rect;  /**< Corrected rectangle for rendering surf. */
00047         surface image;  /**< Surface, scaled if required. */
00048     };
00049 
00050     /**
00051      * WML-based constructor.
00052      * @param cfg Object corresponding to a [image] block's contents from
00053      *            a [part] node.
00054      */
00055     floating_image(const config& cfg);
00056 
00057     /**
00058      * Copy constructor.
00059      */
00060     floating_image(const floating_image& fi);
00061 
00062     floating_image& operator=(const floating_image& fi) {
00063         assign(fi);
00064         return *this;
00065     }
00066 
00067     /**
00068      * Returns the referential X coordinate of the image.
00069      * The actual (corrected) value is determined at render time - see get_render_input().
00070      */
00071     int ref_x() const {
00072         return x_;
00073     }
00074 
00075     /**
00076      * Returns the referential Y coordinate of the image.
00077      * The actual (corrected) value is determined at render time - see get_render_input().
00078      */
00079     int ref_y() const {
00080         return y_;
00081     }
00082 
00083     /**
00084      * Whether the image should be automatically scaled as much as
00085      * the storyscreen background is.
00086      */
00087     bool autoscale() const { return autoscaled_; }
00088 
00089     /**
00090      * Whether the image coordinates specify the location of its
00091      * center (true) or top-left corner (false).
00092      */
00093     bool centered() const  { return centered_; }
00094 
00095     /**
00096      * Delay before displaying, in milliseconds.
00097      */
00098     int display_delay() const { return delay_; }
00099 
00100     /**
00101      * Gets a render_input object for use by the rendering code after applying
00102      * any geometric transformations required.
00103      */
00104     render_input get_render_input(double scale, SDL_Rect& dst_rect) const;
00105 
00106 private:
00107     std::string file_;
00108     int x_, y_; // referential (non corrected) x,y
00109     int delay_;
00110     bool autoscaled_;
00111     bool centered_;
00112 
00113     /** Copy constructor and operator=() implementation details. */
00114     void assign(const floating_image& fi);
00115 };
00116 
00117 /**
00118  * Represents and contains information about a single storyscreen part.
00119  */
00120 class part
00121 {
00122 public:
00123     /**
00124      * Currently used to indicate where the text block should be placed.
00125      * Note that it will always take as much space as it is
00126      * possible horizontally.
00127      */
00128     enum BLOCK_LOCATION {
00129         BLOCK_TOP,      /**< Top of the screen. */
00130         BLOCK_MIDDLE,   /**< Center of the screen. */
00131         BLOCK_BOTTOM    /**< Bottom of the screen. This is the default. */
00132     };
00133     /**
00134      * Currently used to indicate where the page title should be placed.
00135      * It always takes as little space (horizontally) as possible,
00136      * and it is always placed at the top of the screen.
00137      */
00138     enum TEXT_ALIGNMENT {
00139         TEXT_LEFT,      /**< Top-left corner. */
00140         TEXT_CENTERED,  /**< Center on the topmost edge of the screen. */
00141         TEXT_RIGHT      /**< Top-right corner. */
00142     };
00143     /**
00144      * Used to signal user actions.
00145      */
00146     enum RESULT {
00147         NEXT,       /**< Jump to next story part. */
00148         SKIP,       /**< Skip all story parts for this set. */
00149         QUIT        /**< Quit game and go back to main menu. */
00150     };
00151 
00152     /**
00153      * Constructs a storyscreen part from a managed WML node.
00154      * @param part_cfg Node object which should correspond to a [part] block's contents.
00155      */
00156     part(const vconfig &part_cfg);
00157 
00158     /** Whether the background image should be scaled to fill the screen or not. */
00159     bool scale_background() const {
00160         return scale_background_;
00161     }
00162 
00163     /** Path to the background image. */
00164     const std::string& background() const {
00165         return background_file_;
00166     }
00167 
00168     /** Whether the story screen title should be displayed or not. */
00169     bool show_title() const {
00170         return show_title_;
00171     }
00172 
00173     /** Retrieves the story text itself. */
00174     const std::string& text() const {
00175         return text_;
00176     }
00177 
00178     /** Changes the story text. */
00179     void set_text(const std::string& text) {
00180         text_ = text;
00181     }
00182 
00183     /** Retrieves the story screen title. */
00184     const std::string& title() const {
00185         return text_title_;
00186     }
00187 
00188     /** Changes the story screen title. */
00189     void set_title(const std::string& title) {
00190         text_title_ = title;
00191     }
00192 
00193     /** Retrieves the background music. */
00194     const std::string& music() const {
00195         return music_;
00196     }
00197 
00198     /** Retrieves a one-time-only sound effect. */
00199     const std::string& sound() const {
00200         return sound_;
00201     }
00202 
00203     /** Retrieves the area of the screen on which the story text is displayed. */
00204     BLOCK_LOCATION story_text_location() const {
00205         return text_block_loc_;
00206     }
00207 
00208     /** Retrieves the alignment of the title text against the screen. */
00209     TEXT_ALIGNMENT title_text_alignment() const {
00210         return title_alignment_;
00211     }
00212 
00213     /** Retrieve any associated floating images for this story screen. */
00214     const std::vector<floating_image>& get_floating_images() const {
00215         return floating_images_;
00216     }
00217 
00218 private:
00219     /** Takes care of initializing and branching properties. */
00220     void resolve_wml(const vconfig &cfg);
00221 
00222     static BLOCK_LOCATION string_tblock_loc(const std::string& s);
00223     static TEXT_ALIGNMENT string_title_align(const std::string& s);
00224 
00225     bool scale_background_;
00226     std::string background_file_;
00227 
00228     bool show_title_;
00229     std::string text_;
00230     std::string text_title_;
00231     BLOCK_LOCATION text_block_loc_;
00232     TEXT_ALIGNMENT title_alignment_;
00233 
00234     std::string music_;
00235     std::string sound_;
00236 
00237     std::vector<floating_image> floating_images_;
00238 };
00239 
00240 } // end namespace storyscreen
00241 
00242 
00243 #endif /* ! STORYSCREEN_PART_HPP_INCLUDED */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:10 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs