The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
helper.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 #include "config.hpp"
20 #include "gui/core/log.hpp"
21 #include "gui/widgets/grid.hpp"
22 #include "gui/widgets/window.hpp"
23 
24 namespace gui2
25 {
26 
27 namespace implementation
28 {
29 
30 unsigned get_v_align(const std::string& v_align)
31 {
32  if(v_align == "top") {
34  } else if(v_align == "bottom") {
36  } else {
37  if(!v_align.empty() && v_align != "center") {
38  ERR_GUI_E << "Invalid vertical alignment '" << v_align
39  << "' falling back to 'center'.\n";
40  }
42  }
43 }
44 
45 unsigned get_h_align(const std::string& h_align)
46 {
47  if(h_align == "left") {
49  } else if(h_align == "right") {
51  } else {
52  if(!h_align.empty() && h_align != "center") {
53  ERR_GUI_E << "Invalid horizontal alignment '" << h_align
54  << "' falling back to 'center'.\n";
55  }
57  }
58 }
59 
60 unsigned get_border(const std::vector<std::string>& borders)
61 {
62  unsigned result = 0;
63  for(const auto & border : borders)
64  {
65  if(border == "all") {
66  return tgrid::BORDER_ALL;
67  } else if(border == "top") {
68  result |= tgrid::BORDER_TOP;
69  } else if(border == "bottom") {
70  result |= tgrid::BORDER_BOTTOM;
71  } else if(border == "left") {
72  result |= tgrid::BORDER_LEFT;
73  } else if(border == "right") {
74  result |= tgrid::BORDER_RIGHT;
75  }
76  }
77  return result;
78 }
79 
80 unsigned read_flags(const config& cfg)
81 {
82  unsigned flags = 0;
83 
84  const unsigned v_flags = get_v_align(cfg["vertical_alignment"]);
85  const unsigned h_flags = get_h_align(cfg["horizontal_alignment"]);
86  flags |= get_border(utils::split(cfg["border"]));
87 
88  if(cfg["vertical_grow"].to_bool()) {
90 
91  if(!(cfg["vertical_alignment"]).empty()) {
92  ERR_GUI_P << "vertical_grow and vertical_alignment "
93  "can't be combined, alignment is ignored.\n";
94  }
95  } else {
96  flags |= v_flags;
97  }
98 
99  if(cfg["horizontal_grow"].to_bool()) {
101 
102  if(!(cfg["horizontal_alignment"]).empty()) {
103  ERR_GUI_P << "horizontal_grow and horizontal_alignment "
104  "can't be combined, alignment is ignored.\n";
105  }
106  } else {
107  flags |= h_flags;
108  }
109 
110  return flags;
111 }
112 
114 get_scrollbar_mode(const std::string& scrollbar_mode)
115 {
116  if(scrollbar_mode == "always") {
118  } else if(scrollbar_mode == "never") {
120  } else if(scrollbar_mode == "auto") {
122  } else {
123  if(!scrollbar_mode.empty() && scrollbar_mode != "initial_auto") {
124  ERR_GUI_E << "Invalid scrollbar mode '" << scrollbar_mode
125  << "' falling back to 'initial_auto'.\n";
126  }
128  }
129 }
130 
131 int get_retval(const std::string& retval_id,
132  const int retval,
133  const std::string& id)
134 {
135  if(!retval_id.empty()) {
136  int result = twindow::get_retval_by_id(retval_id);
137  if(result) {
138  return result;
139  } else {
140  ERR_GUI_E << "Window builder: retval_id '" << retval_id
141  << "' is unknown.\n";
142  }
143  }
144 
145  if(retval) {
146  return retval;
147  } else {
148  return twindow::get_retval_by_id(id);
149  }
150 }
151 
152 } // namespace implementation
153 
154 } // namespace gui2
Define the common log macros for the gui toolkit.
Like auto_visible, but when not needed upon the initial layout phase, the bars are not shown and no s...
#define ERR_GUI_E
Definition: log.hpp:38
static const unsigned BORDER_BOTTOM
Definition: grid.hpp:56
static const unsigned BORDER_ALL
Definition: grid.hpp:59
unsigned read_flags(const config &cfg)
Returns the placement/resize flags.
Definition: helper.cpp:80
static const unsigned HORIZONTAL_ALIGN_RIGHT
Definition: grid.hpp:52
This file contains the window object, this object is a top level container which has the event manage...
unsigned get_border(const std::vector< std::string > &borders)
Returns the border flags.
Definition: helper.cpp:60
static const unsigned VERTICAL_GROW_SEND_TO_CLIENT
Definition: grid.hpp:41
static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT
Definition: grid.hpp:48
int get_retval(const std::string &retval_id, const int retval, const std::string &id)
Returns the return value for a widget.
Definition: helper.cpp:131
static tretval get_retval_by_id(const std::string &id)
Gets the retval for the default buttons.
Definition: window.cpp:493
static const unsigned BORDER_RIGHT
Definition: grid.hpp:58
tscrollbar_container::tscrollbar_mode get_scrollbar_mode(const std::string &scrollbar_mode)
Returns the scrollbar mode flags.
Definition: helper.cpp:114
Definitions for the interface to Wesnoth Markup Language (WML).
static const unsigned BORDER_TOP
Definition: grid.hpp:55
The scrollbar is never shown even not when needed.
#define ERR_GUI_P
Definition: log.hpp:72
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
static const unsigned HORIZONTAL_ALIGN_LEFT
Definition: grid.hpp:50
GLuint64EXT * result
Definition: glew.h:10727
tscrollbar_mode
The way to handle the showing or hiding of the scrollbar.
static const unsigned VERTICAL_ALIGN_TOP
Definition: grid.hpp:42
cl_event GLbitfield flags
Definition: glew.h:3070
The scrollbar is always shown, whether needed or not.
static const unsigned VERTICAL_ALIGN_CENTER
Definition: grid.hpp:43
unsigned get_v_align(const std::string &v_align)
Returns the vertical alignment.
Definition: helper.cpp:30
GLint GLint GLsizei GLsizei GLsizei GLint border
Definition: glew.h:1222
static const unsigned HORIZONTAL_ALIGN_CENTER
Definition: grid.hpp:51
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
The scrollbar is shown when the number of items is larger as the visible items.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
unsigned get_h_align(const std::string &h_align)
Returns the horizontal alignment.
Definition: helper.cpp:45
static const unsigned VERTICAL_ALIGN_BOTTOM
Definition: grid.hpp:44
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Contains the implementation details for lexical_cast and shouldn't be used directly.
static const unsigned BORDER_LEFT
Definition: grid.hpp:57