The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
common_palette.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2017 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project http://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 "config.hpp"
18 #include "tstring.hpp"
19 #include "widgets/widget.hpp"
20 
21 struct SDL_Rect;
22 class CVideo;
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 
41  bool core;
42 };
43 
44 
45 class common_palette : public gui::widget {
46 
47 public:
48 
49  common_palette(CVideo& video) : gui::widget(video, 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  virtual void draw() = 0;
69 
70  //group
71  virtual void set_group(size_t index) = 0;
72  virtual void next_group() = 0;
73  virtual void prev_group() = 0;
74  virtual const std::vector<item_group>& get_groups() const = 0;
75 
76  /** Menu expanding for palette group list */
77  virtual void expand_palette_groups_menu(std::vector<config>& items, int i) = 0;
78 
79  //item
80  virtual int num_items() = 0;
81  virtual size_t start_num() = 0;
82  virtual void set_start_item(size_t index) = 0;
83 
84  virtual bool supports_swap() { return true; }
85  virtual void swap() = 0;
86 
87  virtual std::vector<std::string> action_pressed() const { return std::vector<std::string>(); }
88 };
89 
90 // a palette containing tristtate buttons.
92 {
93 public:
95  : common_palette(video)
96  {
97  }
98  virtual void select_fg_item(const std::string& item_id) = 0;
99  virtual void select_bg_item(const std::string& item_id) = 0;
100 };
101 
102 }
virtual bool supports_swap()
std::vector< char_t > string
size_t index(const utf8::string &str, const size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:71
virtual void draw()=0
std::vector< events::sdl_handler * > sdl_handler_vector
Definition: events.hpp:176
Stores the info about the groups in a nice format.
virtual void prev_group()=0
virtual void select_bg_item(const std::string &item_id)=0
virtual bool can_scroll_down()=0
Definition: video.hpp:31
virtual void expand_palette_groups_menu(std::vector< config > &items, int i)=0
Menu expanding for palette group list.
CVideo & video() const
Definition: widget.hpp:84
General purpose widgets.
virtual void next_group()=0
const std::vector< std::string > items
Definitions for the interface to Wesnoth Markup Language (WML).
virtual void swap()=0
virtual void select_fg_item(const std::string &item_id)=0
common_palette(CVideo &video)
virtual const std::vector< item_group > & get_groups() const =0
item_group(const config &cfg)
virtual bool scroll_up()=0
Scroll the editor-palette up one step if possible.
virtual bool can_scroll_up()=0
virtual int num_items()=0
Manage the empty-palette in the editor.
Definition: action.cpp:29
virtual sdl_handler_vector handler_members()
virtual void adjust_size(const SDL_Rect &target)=0
size_t i
Definition: function.cpp:933
virtual bool scroll_down()=0
Scroll the editor-palette down one step if possible.
virtual void set_start_item(size_t index)=0
virtual std::vector< std::string > action_pressed() const
virtual void set_group(size_t index)=0
widget(widget const &o)
Definition: widget.cpp:33
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
virtual size_t start_num()=0
tristate_palette(CVideo &video)