The Battle for Wesnoth  1.19.0-dev
common_palette.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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 
24 namespace editor {
25 
26 /**
27  * Stores the info about the groups in a nice format.
28  */
29 struct item_group
30 {
31  item_group(const config& cfg)
32  : id(cfg["id"])
33  , name(cfg["name"].t_str())
34  , icon(cfg["icon"])
35  , core(cfg["core"].to_bool())
36  {}
37 
38  std::string id;
40  std::string icon;
41  bool core;
42 };
43 
44 
45 class common_palette : public gui::widget {
46 
47 public:
48 
49  common_palette() : gui::widget(true) {}
50 
51  virtual ~common_palette() {}
52 
53  //event handling
54 
56 
57 
58  /** Scroll the editor-palette up one step if possible. */
59  virtual bool scroll_up() = 0;
60  virtual bool can_scroll_up() = 0;
61 
62  /** Scroll the editor-palette down one step if possible. */
63  virtual bool scroll_down() = 0;
64  virtual bool can_scroll_down() = 0;
65 
66  //drawing
67  virtual void adjust_size(const SDL_Rect& target) = 0;
68 
69  //group
70  virtual void set_group(std::size_t index) = 0;
71  virtual void next_group() = 0;
72  virtual void prev_group() = 0;
73  virtual const std::vector<item_group>& get_groups() const = 0;
74 
75  /** Menu expanding for palette group list */
76  virtual void expand_palette_groups_menu(std::vector<config>& items, int i) = 0;
77 
78  //item
79  virtual std::size_t num_items() = 0;
80  virtual std::size_t start_num() = 0;
81  virtual void set_start_item(std::size_t index) = 0;
82 
83  virtual bool supports_swap() { return true; }
84  virtual void swap() = 0;
85 
86  virtual std::vector<std::string> action_pressed() const { return std::vector<std::string>(); }
87 };
88 
89 // a palette containing tristtate buttons.
91 {
92 public:
94  : common_palette()
95  {
96  }
97  virtual void select_fg_item(const std::string& item_id) = 0;
98  virtual void select_bg_item(const std::string& item_id) = 0;
99 };
100 
101 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
virtual void swap()=0
virtual void set_start_item(std::size_t index)=0
virtual std::size_t start_num()=0
virtual std::vector< std::string > action_pressed() const
virtual bool scroll_down()=0
Scroll the editor-palette down one step if possible.
virtual void set_group(std::size_t index)=0
virtual const std::vector< item_group > & get_groups() const =0
virtual void next_group()=0
virtual bool scroll_up()=0
Scroll the editor-palette up one step if possible.
virtual bool can_scroll_down()=0
virtual bool can_scroll_up()=0
virtual bool supports_swap()
virtual void prev_group()=0
virtual void expand_palette_groups_menu(std::vector< config > &items, int i)=0
Menu expanding for palette group list.
virtual void adjust_size(const SDL_Rect &target)=0
virtual std::size_t num_items()=0
virtual sdl_handler_vector handler_members()
virtual void select_bg_item(const std::string &item_id)=0
virtual void select_fg_item(const std::string &item_id)=0
widget(const bool auto_join=true)
Definition: widget.cpp:33
std::vector< events::sdl_handler * > sdl_handler_vector
Definition: events.hpp:190
std::size_t i
Definition: function.cpp:968
Manage the empty-palette in the editor.
Definition: action.cpp:31
General purpose widgets.
const std::vector< std::string > items
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:70
Stores the info about the groups in a nice format.
item_group(const config &cfg)