summaryrefslogtreecommitdiffstats
path: root/client/SDL/dialogs/sdl_input_widgets.hpp
blob: 83568bab8d816466daa003c46d0add57d4e78f63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once

#include <string>
#include <vector>
#include <SDL.h>

#include "sdl_input.hpp"
#include "sdl_buttons.hpp"

class SdlInputWidgetList
{
  public:
	SdlInputWidgetList(const std::string& title, const std::vector<std::string>& labels,
	                   const std::vector<std::string>& initial, const std::vector<Uint32>& flags);
	virtual ~SdlInputWidgetList();

	int run(std::vector<std::string>& result);

  protected:
	bool update(SDL_Renderer* renderer);
	ssize_t get_index(const SDL_MouseButtonEvent& button);

  private:
	SdlInputWidgetList(const SdlInputWidgetList& other) = delete;
	SdlInputWidgetList(SdlInputWidgetList&& other) = delete;

  private:
	enum
	{
		INPUT_BUTTON_ACCEPT = 1,
		INPUT_BUTTON_CANCEL = -2
	};

  private:
	ssize_t next(ssize_t current);
	[[nodiscard]] bool valid(ssize_t current) const;
	SdlInputWidget* get(ssize_t index);

  private:
	SDL_Window* _window;
	SDL_Renderer* _renderer;
	std::vector<SdlInputWidget> _list;
	SdlButtonList _buttons;
};