gui/auxiliary/window_builder/helper.cpp

Go to the documentation of this file.
00001 /* $Id: helper.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
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 #define GETTEXT_DOMAIN "wesnoth-lib"
00017 
00018 #include "gui/auxiliary/window_builder/helper.hpp"
00019 
00020 #include "config.hpp"
00021 #include "foreach.hpp"
00022 #include "gui/auxiliary/log.hpp"
00023 #include "gui/widgets/grid.hpp"
00024 #include "gui/widgets/window.hpp"
00025 
00026 namespace gui2 {
00027 
00028 namespace implementation {
00029 
00030 unsigned get_v_align(const std::string& v_align)
00031 {
00032     if(v_align == "top") {
00033         return tgrid::VERTICAL_ALIGN_TOP;
00034     } else if(v_align == "bottom") {
00035         return tgrid::VERTICAL_ALIGN_BOTTOM;
00036     } else {
00037         if(!v_align.empty() && v_align != "center") {
00038             ERR_GUI_E << "Invalid vertical alignment '"
00039                     << v_align << "' falling back to 'center'.\n";
00040         }
00041         return tgrid::VERTICAL_ALIGN_CENTER;
00042     }
00043 }
00044 
00045 unsigned get_h_align(const std::string& h_align)
00046 {
00047     if(h_align == "left") {
00048         return tgrid::HORIZONTAL_ALIGN_LEFT;
00049     } else if(h_align == "right") {
00050         return tgrid::HORIZONTAL_ALIGN_RIGHT;
00051     } else {
00052         if(!h_align.empty() && h_align != "center") {
00053             ERR_GUI_E << "Invalid horizontal alignment '"
00054                     << h_align << "' falling back to 'center'.\n";
00055         }
00056         return tgrid::HORIZONTAL_ALIGN_CENTER;
00057     }
00058 }
00059 
00060 unsigned get_border(const std::vector<std::string>& border)
00061 {
00062     unsigned result = 0;
00063     foreach (const std::string& s, border) {
00064         if (s == "all") {
00065             return tgrid::BORDER_ALL;
00066         } else if (s == "top") {
00067             result |= tgrid::BORDER_TOP;
00068         } else if (s == "bottom") {
00069             result |= tgrid::BORDER_BOTTOM;
00070         } else if (s == "left") {
00071             result |= tgrid::BORDER_LEFT;
00072         } else if (s == "right") {
00073             result |= tgrid::BORDER_RIGHT;
00074         }
00075     }
00076     return result;
00077 }
00078 
00079 unsigned read_flags(const config& cfg)
00080 {
00081     unsigned flags = 0;
00082 
00083     const unsigned v_flags = get_v_align(cfg["vertical_alignment"]);
00084     const unsigned h_flags = get_h_align(cfg["horizontal_alignment"]);
00085     flags |= get_border( utils::split(cfg["border"]));
00086 
00087     if (cfg["vertical_grow"].to_bool()) {
00088         flags |= tgrid::VERTICAL_GROW_SEND_TO_CLIENT;
00089 
00090         if(! (cfg["vertical_alignment"]).empty()) {
00091             ERR_GUI_P << "vertical_grow and vertical_alignment "
00092                 "can't be combined, alignment is ignored.\n";
00093         }
00094     } else {
00095         flags |= v_flags;
00096     }
00097 
00098     if (cfg["horizontal_grow"].to_bool()) {
00099         flags |= tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT;
00100 
00101         if(! (cfg["horizontal_alignment"]).empty()) {
00102             ERR_GUI_P << "horizontal_grow and horizontal_alignment "
00103                 "can't be combined, alignment is ignored.\n";
00104         }
00105     } else {
00106         flags |= h_flags;
00107     }
00108 
00109     return flags;
00110 }
00111 
00112 tscrollbar_container::tscrollbar_mode
00113         get_scrollbar_mode(const std::string& scrollbar_mode)
00114 {
00115     if(scrollbar_mode == "always") {
00116         return tscrollbar_container::always_visible;
00117     } else if(scrollbar_mode == "never") {
00118         return tscrollbar_container::always_invisible;
00119     } else if(scrollbar_mode == "auto") {
00120         return tscrollbar_container::auto_visible;
00121     } else {
00122         if(!scrollbar_mode.empty() && scrollbar_mode != "initial_auto") {
00123             ERR_GUI_E << "Invalid scrollbar mode '"
00124                     << scrollbar_mode << "' falling back to 'initial_auto'.\n";
00125         }
00126         return tscrollbar_container::auto_visible_first_run;
00127     }
00128 }
00129 
00130 int get_retval(const std::string& retval_id
00131         , const int retval
00132         , const std::string& id)
00133 {
00134     if(!retval_id.empty()) {
00135         int result = twindow::get_retval_by_id(retval_id);
00136         if(result) {
00137             return result;
00138         } else {
00139             ERR_GUI_E << "Window builder: retval_id '"
00140                     << retval_id << "' is unknown.\n";
00141         }
00142     }
00143 
00144     if(retval) {
00145         return retval;
00146     } else {
00147         return twindow::get_retval_by_id(id);
00148     }
00149 }
00150 
00151 } // namespace implementation
00152 
00153 } // namespace gui2
00154 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:43 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs