1 /* 2 Copyright (C) 2003 - 2018 by David White <dave@whitevine.net> 3 Part of the Battle for Wesnoth Project https://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 #pragma once 16 17 #include "editor/editor_display.hpp" 18 #include "editor/palette/common_palette.hpp" 19 #include "editor/palette/tristate_button.hpp" 20 21 #include <boost/ptr_container/ptr_vector.hpp> 22 23 class location_palette_item; 24 class location_palette_button; 25 26 namespace editor { 27 28 class editor_toolkit; 29 30 class location_palette : public common_palette { 31 32 public: 33 34 location_palette(editor_display &gui, const config& /*cfg*/, 35 editor_toolkit &toolkit); 36 37 38 virtual sdl_handler_vector handler_members() override; 39 set_start_item(size_t index)40 void set_start_item(size_t index) override { items_start_ = index; } 41 start_num(void)42 size_t start_num(void) override { return items_start_; } 43 44 /** Menu expanding for palette group list */ expand_palette_groups_menu(std::vector<config> & items,int i)45 void expand_palette_groups_menu(std::vector<config>& items, int i) override 46 { 47 items.erase(items.begin() + i); 48 } 49 set_group(size_t)50 virtual void set_group(size_t /*index*/) override {} next_group()51 virtual void next_group() override {} prev_group()52 virtual void prev_group() override {} get_groups() const53 virtual const std::vector<item_group>& get_groups() const override { static const std::vector<item_group> empty; return empty; } 54 draw()55 virtual void draw() override { 56 widget::draw(); 57 } 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 SDL_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 swap()72 void swap() override {} can_swap()73 bool can_swap() { return false; } 74 get_help_string()75 virtual std::string get_help_string() { return ""; } 76 77 /** Return the currently selected item. */ selected_item() const78 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); 83 ~location_palette(); 84 void hide(bool hidden) override; 85 86 private: 87 88 /** Scroll the editor-palette to the top. */ 89 void scroll_top(); 90 91 /** Scroll the editor-palette to the bottom. */ 92 void scroll_bottom(); 93 94 virtual bool is_selected_item(const std::string& id); 95 96 /** Return the number of items in the palette. */ 97 int num_items() override; 98 /** Return the maximum number of items shown at the same time. */ 99 int num_visible_items(); 100 protected: 101 102 int item_size_; 103 // the height of a row, the size of an item including borders. 104 int item_space_; 105 106 private: 107 unsigned int palette_y_; 108 unsigned int palette_x_; 109 110 protected: 111 //the current scrolling position 112 int items_start_; 113 114 private: 115 std::string selected_item_; 116 std::vector<std::string> items_; 117 editor_toolkit& toolkit_; 118 boost::ptr_vector<location_palette_item> buttons_; 119 std::unique_ptr<location_palette_button> button_add_; 120 std::unique_ptr<location_palette_button> button_delete_; 121 std::unique_ptr<location_palette_button> button_goto_; 122 int help_handle_; 123 editor_display& disp_; 124 }; 125 126 127 } //end namespace editor 128