The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
location_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
20
24namespace editor {
25
26class editor_toolkit;
27
28/**
29 * List of starting locations and location ids. Shows a single-column list, with buttons to add
30 * new items to the list and to jump to that location on the map.
31 */
33
34public:
35
37
38
39 virtual sdl_handler_vector handler_members() override;
40
41 void set_start_item(std::size_t index) override { items_start_ = index; }
42
43 std::size_t start_num(void) override { return items_start_; }
44
45 /** Menu expanding for palette group list */
46 void expand_palette_groups_menu(std::vector<config>& /*items*/) override
47 {
48 }
49
50 virtual void set_group(std::size_t /*index*/) override {}
51 virtual void next_group() override {}
52 virtual void prev_group() override {}
53 virtual const std::vector<item_group>& get_groups() const override { static const std::vector<item_group> empty; return empty; }
54
55 /** Called by draw_manager to validate layout before drawing. */
56 virtual void layout() override;
57 /** Called by widget::draw() */
58 virtual void draw_contents() override;
59
60 /**
61 * Update the size of this widget.
62 *
63 * Use if the size_specs have changed.
64 */
65 void adjust_size(const rect& target) override;
66
67 virtual bool scroll_up() override;
68 virtual bool can_scroll_up() override;
69 virtual bool scroll_down() override;
70 virtual bool can_scroll_down() override;
71
72 virtual void swap() override {}
73 virtual bool supports_swap() override { return false; }
74
75 std::string get_help_string() const { return ""; }
76
77 /** Return the currently selected item. */
78 const std::string& selected_item() const { return selected_item_; }
79
80 virtual void select_item(const std::string& item_id);
81 virtual std::vector<std::string> action_pressed() const override;
82 void add_item(const std::string& id);
84 void hide(bool hidden) override;
85
86private:
87 /** Scroll the editor-palette to the top. */
88 void scroll_top();
89
90 virtual bool is_selected_item(const std::string& id);
91
92 /** Return the number of items in the palette. */
93 std::size_t num_items() override;
94 /**
95 * Return the number of GUI elements that can show items. Some of these may be hidden, if there
96 * are more of them than items to show, or if the palette has been scrolled to the bottom.
97 */
98 std::size_t num_visible_items();
99protected:
100
102 // the height of a row, the size of an item including borders.
104
105protected:
106 // the current scrolling position
107 std::size_t items_start_;
108
109private:
110 std::string selected_item_;
111 std::vector<std::string> items_;
113 std::vector<location_palette_item> buttons_;
114 std::unique_ptr<location_palette_button> button_add_;
115 std::unique_ptr<location_palette_button> button_delete_;
116 std::unique_ptr<location_palette_button> button_goto_;
118};
119
120
121} //end namespace editor
List of starting locations and location ids.
virtual bool can_scroll_down() override
std::unique_ptr< location_palette_button > button_goto_
std::vector< std::string > items_
virtual bool scroll_up() override
Scroll the editor-palette up one step if possible.
void scroll_top()
Scroll the editor-palette to the top.
virtual void layout() override
Called by draw_manager to validate layout before drawing.
void hide(bool hidden) override
void set_start_item(std::size_t index) override
std::vector< location_palette_item > buttons_
std::size_t num_items() override
Return the number of items in the palette.
virtual bool can_scroll_up() override
virtual void next_group() override
void adjust_size(const rect &target) override
Update the size of this widget.
virtual const std::vector< item_group > & get_groups() const override
std::size_t start_num(void) override
virtual void draw_contents() override
Called by widget::draw()
virtual void prev_group() override
void add_item(const std::string &id)
void expand_palette_groups_menu(std::vector< config > &) override
Menu expanding for palette group list.
virtual bool is_selected_item(const std::string &id)
std::string get_help_string() const
virtual bool supports_swap() override
Whether the hotkey system should the enable GUI button connected to swap().
std::unique_ptr< location_palette_button > button_add_
virtual sdl_handler_vector handler_members() override
virtual void swap() override
For tools which support fg and bg items, exchange the two items.
virtual std::vector< std::string > action_pressed() const override
std::size_t num_visible_items()
Return the number of GUI elements that can show items.
virtual void set_group(std::size_t) override
virtual void select_item(const std::string &item_id)
virtual bool scroll_down() override
Scroll the editor-palette down one step if possible.
std::unique_ptr< location_palette_button > button_delete_
const std::string & selected_item() const
Return the currently selected item.
A class grating read only view to a vector of config objects, viewed as one config with all children ...
bool hidden() const
Definition widget.cpp:161
std::vector< events::sdl_handler * > sdl_handler_vector
Definition events.hpp:219
Manage the empty-palette in the editor.
Definition action.cpp:31
General purpose widgets.
An abstract description of a rectangle with integer coordinates.
Definition rect.hpp:49