The Battle for Wesnoth  1.17.0-dev
show_dialog.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
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 class surface;
19 
20 #include "cursor.hpp"
21 #include "floating_label.hpp"
22 #include "tooltips.hpp"
23 #include "video.hpp"
24 #include "widgets/button.hpp"
25 
26 namespace gui
27 {
28 
29 extern const int ButtonHPadding;
30 extern const int ButtonVPadding;
36  ESCAPE_DIALOG=-3, //special return used by WML event dialogs
39  /* results (0..N) reserved for standard button indices */
40 };
41 
42 bool in_dialog();
43 
47 
48 private:
49  bool reset_to;
50 };
51 
53 public:
56  SDL_Rect interior, exterior, title, button_row;
57  };
58  class style {
59  public:
60  style(const std::string& p, int br) : panel(p), blur_radius(br) {}
61  std::string panel;
63  };
64 
65  //Static members
66  static const int title_border_w, title_border_h;
67  static const style default_style;
68 
69  dialog_frame(CVideo &video, const std::string& title="",
70  const style& dialog_style=default_style,
71  bool auto_restore=true, std::vector<button*>* buttons=nullptr,
72  button* help_button=nullptr);
73  ~dialog_frame();
74 
75  dimension_measurements layout(int x, int y, int w, int h);
76  dimension_measurements layout(const SDL_Rect& frame_area);
77  void set_layout(dimension_measurements &new_dim) { dim_ = new_dim; }
78  dimension_measurements get_layout() const { return dim_; }
79 
80  int top_padding() const;
81  int bottom_padding() const;
82 
83  void draw();
84 
85  //called by draw
86  void draw_border();
87  void draw_background();
88 
89  //also called by layout with null param
90  SDL_Rect draw_title(CVideo *video);
91 
92  void set_dirty(bool dirty = true);
93 
94  virtual void handle_event(const SDL_Event&);
95  void handle_window_event(const SDL_Event& event);
96 
97 private:
98  void clear_background();
99 
100  std::string title_;
103  std::vector<button*>* buttons_;
108  surface top_, bot_, left_, right_, top_left_, bot_left_, top_right_, bot_right_, bg_;
110  bool dirty_;
111 };
112 
113 }
static const style default_style
Definition: show_dialog.hpp:67
Definition: video.hpp:32
bool in_dialog()
Definition: show_dialog.cpp:53
static void draw_background(surface screen, const SDL_Rect &area, const std::string &image)
Definition: display.cpp:1496
General purpose widgets.
std::vector< button * > * buttons_
surface_restorer * restorer_
#define h
const style & dialog_style_
const int ButtonHPadding
Definition: show_dialog.cpp:42
std::string title_
style(const std::string &p, int br)
Definition: show_dialog.hpp:60
static const int title_border_w
Definition: show_dialog.hpp:66
A button is a control that can be pushed to start an action or close a dialog.
Definition: button.hpp:50
mock_party p
structure which will hide all current floating labels, and cause floating labels instantiated after i...
dimension_measurements dim_
int w
DIALOG_RESULT
Definition: show_dialog.hpp:31
void set_layout(dimension_measurements &new_dim)
Definition: show_dialog.hpp:77
dimension_measurements get_layout() const
Definition: show_dialog.hpp:78
const int ButtonVPadding
Definition: show_dialog.cpp:43