The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
common_palette.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2003 - 2025
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
22struct rect;
23
24namespace editor {
25
26/**
27 * Stores the info about the groups in a nice format.
28 */
30{
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
46
47public:
48
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 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) = 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 /** Whether the hotkey system should the enable GUI button connected to swap(). */
84 virtual bool supports_swap() { return true; }
85 /**
86 * For tools which support fg and bg items, exchange the two items. Typically, fg and bg mean
87 * that they're placed by left or right mouse clicks, respectively.
88 *
89 * There's a mismatch between class structure and responsibilities here, as part of the UX isn't
90 * part of the palette. The tool decides what right-click does. Even for the scenery item tool,
91 * where right-click deletes an item, fg and bg provide a way to switch between two items.
92 */
93 virtual void swap() = 0;
94
95 virtual std::vector<std::string> action_pressed() const { return std::vector<std::string>(); }
96};
97
98// a palette containing tristtate buttons.
100{
101public:
104 {
105 }
106 virtual void select_fg_item(const std::string& item_id) = 0;
107 virtual void select_bg_item(const std::string& item_id) = 0;
108};
109
110}
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
virtual void swap()=0
For tools which support fg and bg items, exchange the two items.
virtual void set_start_item(std::size_t index)=0
virtual std::size_t start_num()=0
virtual void adjust_size(const rect &target)=0
virtual bool scroll_down()=0
Scroll the editor-palette down one step if possible.
virtual void set_group(std::size_t index)=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()
Whether the hotkey system should the enable GUI button connected to swap().
virtual void prev_group()=0
virtual void expand_palette_groups_menu(std::vector< config > &items)=0
Menu expanding for palette group list.
virtual const std::vector< item_group > & get_groups() const =0
virtual std::vector< std::string > action_pressed() const
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
Definitions for the interface to Wesnoth Markup Language (WML).
std::vector< events::sdl_handler * > sdl_handler_vector
Definition events.hpp:219
const config * cfg
Manage the empty-palette in the editor.
Definition action.cpp:31
General purpose widgets.
Stores the info about the groups in a nice format.
item_group(const config &cfg)
An abstract description of a rectangle with integer coordinates.
Definition rect.hpp:49