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