The Battle for Wesnoth  1.19.0-dev
show_dialog.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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 
19 #include "cursor.hpp"
20 #include "floating_label.hpp"
22 #include "widgets/button.hpp"
23 
24 namespace gui
25 {
26 
27 extern const int ButtonHPadding;
28 extern const int ButtonVPadding;
34  ESCAPE_DIALOG=-3, //special return used by WML event dialogs
36  CLOSE_DIALOG=-1
37  /* results (0..N) reserved for standard button indices */
38 };
39 
40 bool in_dialog();
41 
45 
46 private:
47  bool reset_to;
48 };
49 
51 public:
55  };
56  class style {
57  public:
58  style(const std::string& p, int br) : panel(p), blur_radius(br) {}
59  std::string panel;
61  };
62 
63  //Static members
64  static const int title_border_w, title_border_h;
65  static const style default_style;
66 
67  dialog_frame(const std::string& title="",
68  const style& dialog_style=default_style,
69  std::vector<button*>* buttons=nullptr,
70  button* help_button=nullptr);
71  ~dialog_frame();
72 
73  dimension_measurements layout(int x, int y, int w, int h);
74  dimension_measurements layout(const SDL_Rect& frame_area);
75  void set_layout(dimension_measurements &new_dim) { dim_ = new_dim; }
77 
78  int top_padding() const;
79  int bottom_padding() const;
80 
81  void draw();
82 
83  /** Called by draw_manager to validate layout. */
84  virtual void layout() override;
85 
86  /** Called by draw_manager when it believes a redraw is necessary. */
87  virtual bool expose(const rect& region) override;
88 
89  /** The current draw location of the window, on the screen. */
90  virtual rect screen_location() override;
91 
92  //called by draw
93  void draw_border();
94  void draw_background();
95 
96  //also called by layout with null param
97  rect draw_title(bool actually_draw);
98 
99  void set_dirty(bool dirty = true);
100 
101 private:
103 
104  std::string title_;
106  std::vector<button*>* buttons_;
112  bool dirty_;
113 };
114 
115 }
A top-level drawable item (TLD), such as a window.
A button is a control that can be pushed to start an action or close a dialog.
Definition: button.hpp:52
style(const std::string &p, int br)
Definition: show_dialog.hpp:58
dimension_measurements dim_
std::vector< button * > * buttons_
int top_padding() const
void set_layout(dimension_measurements &new_dim)
Definition: show_dialog.hpp:75
dialog_frame(const std::string &title="", const style &dialog_style=default_style, std::vector< button * > *buttons=nullptr, button *help_button=nullptr)
Definition: show_dialog.cpp:81
static const style default_style
Definition: show_dialog.hpp:65
void set_dirty(bool dirty=true)
dimension_measurements get_layout() const
Definition: show_dialog.hpp:76
static const int title_border_h
Definition: show_dialog.hpp:64
virtual void layout() override
Called by draw_manager to validate layout.
virtual bool expose(const rect &region) override
Called by draw_manager when it believes a redraw is necessary.
virtual rect screen_location() override
The current draw location of the window, on the screen.
std::string title_
const style & dialog_style_
static const int title_border_w
Definition: show_dialog.hpp:64
int bottom_padding() const
rect draw_title(bool actually_draw)
Wrapper class to encapsulate creation and management of an SDL_Texture.
Definition: texture.hpp:33
int w
General purpose widgets.
DIALOG_RESULT
Definition: show_dialog.hpp:29
@ DIALOG_FORWARD
Definition: show_dialog.hpp:31
@ DELETE_ITEM
Definition: show_dialog.hpp:33
@ DIALOG_BACK
Definition: show_dialog.hpp:30
@ CLOSE_DIALOG
Definition: show_dialog.hpp:36
@ CONTINUE_DIALOG
Definition: show_dialog.hpp:35
@ ESCAPE_DIALOG
Definition: show_dialog.hpp:34
@ CREATE_ITEM
Definition: show_dialog.hpp:32
const int ButtonHPadding
Definition: show_dialog.cpp:45
const int ButtonVPadding
Definition: show_dialog.cpp:46
bool in_dialog()
Definition: show_dialog.cpp:56
structure which will hide all current floating labels, and cause floating labels instantiated after i...
An abstract description of a rectangle with integer coordinates.
Definition: rect.hpp:47
mock_party p
#define h