The Battle for Wesnoth  1.17.0-dev
common_palette.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "config.hpp"
19 #include "tstring.hpp"
20 #include "widgets/widget.hpp"
21 
22 struct SDL_Rect;
23 class CVideo;
24 
25 namespace editor {
26 
27 /**
28  * Stores the info about the groups in a nice format.
29  */
30 struct item_group
31 {
32  item_group(const config& cfg)
33  : id(cfg["id"])
34  , name(cfg["name"].t_str())
35  , icon(cfg["icon"])
36  , core(cfg["core"].to_bool())
37  {}
38 
39  std::string id;
41  std::string icon;
42  bool core;
43 };
44 
45 
46 class common_palette : public gui::widget {
47 
48 public:
49 
50  common_palette(CVideo& video) : gui::widget(video, true) {}
51 
52  virtual ~common_palette() {}
53 
54  //event handling
55 
57 
58 
59  /** Scroll the editor-palette up one step if possible. */
60  virtual bool scroll_up() = 0;
61  virtual bool can_scroll_up() = 0;
62 
63  /** Scroll the editor-palette down one step if possible. */
64  virtual bool scroll_down() = 0;
65  virtual bool can_scroll_down() = 0;
66 
67  //drawing
68  virtual void adjust_size(const SDL_Rect& target) = 0;
69  virtual void draw() = 0;
70 
71  //group
72  virtual void set_group(std::size_t index) = 0;
73  virtual void next_group() = 0;
74  virtual void prev_group() = 0;
75  virtual const std::vector<item_group>& get_groups() const = 0;
76 
77  /** Menu expanding for palette group list */
78  virtual void expand_palette_groups_menu(std::vector<config>& items, int i) = 0;
79 
80  //item
81  virtual int num_items() = 0;
82  virtual std::size_t start_num() = 0;
83  virtual void set_start_item(std::size_t index) = 0;
84 
85  virtual bool supports_swap() { return true; }
86  virtual void swap() = 0;
87 
88  virtual std::vector<std::string> action_pressed() const { return std::vector<std::string>(); }
89 };
90 
91 // a palette containing tristtate buttons.
93 {
94 public:
96  : common_palette(video)
97  {
98  }
99  virtual void select_fg_item(const std::string& item_id) = 0;
100  virtual void select_bg_item(const std::string& item_id) = 0;
101 };
102 
103 }
virtual bool supports_swap()
std::vector< events::sdl_handler * > sdl_handler_vector
Definition: events.hpp:190
Stores the info about the groups in a nice format.
Definition: video.hpp:32
General purpose widgets.
const std::vector< std::string > items
Definitions for the interface to Wesnoth Markup Language (WML).
common_palette(CVideo &video)
item_group(const config &cfg)
Manage the empty-palette in the editor.
Definition: action.cpp:30
void swap(config &lhs, config &rhs)
Implement non-member swap function for std::swap (calls config::swap).
Definition: config.cpp:1456
virtual sdl_handler_vector handler_members()
std::size_t i
Definition: function.cpp:967
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:72
virtual std::vector< std::string > action_pressed() const
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
tristate_palette(CVideo &video)