gui/dialogs/wml_message.hpp

Go to the documentation of this file.
00001 /* $Id: wml_message.hpp 53727 2012-03-31 18:31:38Z mordante $ */
00002 /*
00003    Copyright (C) 2008 - 2012 by Mark de Wever <koraq@xs4all.nl>
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 #ifndef GUI_DIALOGS_WML_MESSAGE_HPP_INCLUDED
00017 #define GUI_DIALOGS_WML_MESSAGE_HPP_INCLUDED
00018 
00019 #include "gui/dialogs/dialog.hpp"
00020 
00021 namespace gui2 {
00022 
00023 /**
00024  * Base class for the wml generated messages.
00025  *
00026  * We have a separate sub class for left and right images.
00027  */
00028 class twml_message_
00029     : public tdialog
00030 {
00031 public:
00032     twml_message_(const std::string& title, const std::string& message,
00033             const std::string& portrait, const bool mirror)
00034         : title_(title)
00035         , image_("")
00036         , message_(message)
00037         , portrait_(portrait)
00038         , mirror_(mirror)
00039         , has_input_(false)
00040         , input_caption_("")
00041         , input_text_(NULL)
00042         , input_maximum_length_(0)
00043         , option_list_()
00044         , chosen_option_(NULL)
00045     {
00046     }
00047 
00048     /**
00049      * Sets the input text variables.
00050      *
00051      * @param caption             The caption for the label.
00052      * @param text                The initial text, after showing the final
00053      *                            text.
00054      * @param maximum_length      The maximum length of the text.
00055      */
00056     void set_input(const std::string& caption,
00057             std::string* text, const unsigned maximum_length);
00058 
00059     void set_option_list(
00060             const std::vector<std::string>& option_list, int* chosen_option);
00061 
00062 private:
00063 
00064     /** The title for the dialog. */
00065     std::string title_;
00066 
00067     /**
00068      * The image which is shown in the dialog.
00069      *
00070      * This image can be an icon or portrait or any other image.
00071      */
00072     std::string image_;
00073 
00074     /** The message to show to the user. */
00075     std::string message_;
00076     /** Filename of the portrait. */
00077     std::string portrait_;
00078 
00079     /** Mirror the portrait? */
00080     bool mirror_;
00081 
00082     /** Do we need to show an input box? */
00083     bool has_input_;
00084 
00085     /** The caption to show for the input text. */
00086     std::string input_caption_;
00087 
00088     /** The text input. */
00089     std::string* input_text_;
00090 
00091     /** The maximum length of the input text. */
00092     unsigned input_maximum_length_;
00093 
00094     /** The list of options the user can choose. */
00095     std::vector<std::string> option_list_;
00096 
00097     /** The chosen option. */
00098     int *chosen_option_;
00099 
00100     /** Inherited from tdialog. */
00101     void pre_show(CVideo& video, twindow& window);
00102 
00103     /** Inherited from tdialog. */
00104     void post_show(twindow& window);
00105 };
00106 
00107 /** Shows a dialog with the portrait on the left side. */
00108 class twml_message_left : public twml_message_
00109 {
00110 public:
00111     twml_message_left(const std::string& title, const std::string& message,
00112             const std::string& portrait, const bool mirror)
00113         : twml_message_(title, message, portrait, mirror)
00114     {
00115     }
00116 
00117 private:
00118 
00119     /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
00120     virtual const std::string& window_id() const;
00121 };
00122 
00123 /** Shows a dialog with the portrait on the right side. */
00124 class twml_message_right : public twml_message_
00125 {
00126 public:
00127     twml_message_right(const std::string& title, const std::string& message,
00128             const std::string& portrait, const bool mirror)
00129         : twml_message_(title, message, portrait, mirror)
00130     {
00131     }
00132 
00133 private:
00134 
00135     /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
00136     virtual const std::string& window_id() const;
00137 };
00138 
00139 
00140 /**
00141  *  Helper function to show a portrait.
00142  *
00143  *  @param left_side              If true the portrait is shown on the left,
00144  *                                on the right side otherwise.
00145  *  @param video                  The display variable.
00146  *  @param title                  The title of the dialog.
00147  *  @param message                The message to show.
00148  *  @param portrait               Filename of the portrait.
00149  *  @param mirror                 Does the portrait need to be mirrored?
00150  *
00151  *  @param has_input              Do we need to show the input box.
00152  *  @param input_caption          The caption for the optional input text
00153  *                                box. If this value != "" there is an input
00154  *                                and the input text parameter is mandatory.
00155  *  @param input_text             Pointer to the initial text value will be
00156  *                                set to the result.
00157  *  @param maximum_length         The maximum length of the text.
00158  *
00159  *  @param option_list            A list of options to select in the dialog.
00160  *  @param chosen_option          Pointer to the initially chosen option.
00161  *                                Will be set to the chosen_option when the
00162  *                                dialog closes.
00163  */
00164 int show_wml_message(const bool left_side
00165         , CVideo& video
00166         , const std::string& title
00167         , const std::string& message
00168         , const std::string& portrait
00169         , const bool mirror
00170         , const bool has_input
00171         , const std::string& input_caption
00172         , std::string* input_text
00173         , const unsigned maximum_length
00174         , const std::vector<std::string>& option_list
00175         , int* chosen_option);
00176 
00177 
00178 } // namespace gui2
00179 
00180 #endif
00181 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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