mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-19 07:59:11 +00:00
158 lines
4.9 KiB
C++
158 lines
4.9 KiB
C++
/* $Id$ */
|
|
/*
|
|
Copyright (C) 2003 by David White <davidnwhite@optusnet.com.au>
|
|
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License.
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY.
|
|
|
|
See the COPYING file for more details.
|
|
*/
|
|
|
|
#ifndef SHOW_DIALOG_HPP_INCLUDED
|
|
#define SHOW_DIALOG_HPP_INCLUDED
|
|
|
|
#include "config.hpp"
|
|
#include "cursor.hpp"
|
|
#include "display.hpp"
|
|
#include "font.hpp"
|
|
#include "halo.hpp"
|
|
#include "network.hpp"
|
|
#include "tooltips.hpp"
|
|
#include "unit.hpp"
|
|
#include "video.hpp"
|
|
|
|
#include "widgets/button.hpp"
|
|
|
|
#include "SDL.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace gui
|
|
{
|
|
|
|
extern const int ButtonHPadding;
|
|
extern const int ButtonVPadding;
|
|
|
|
bool in_dialog();
|
|
|
|
struct dialog_manager : private cursor::setter, private font::floating_label_context, private halo::halo_hider {
|
|
dialog_manager();
|
|
~dialog_manager();
|
|
|
|
private:
|
|
bool reset_to;
|
|
};
|
|
|
|
void draw_dialog_frame(int x, int y, int w, int h, display& disp, const std::string* dialog_style=NULL, surface_restorer* restorer=NULL);
|
|
|
|
void draw_dialog_background(int x, int y, int w, int h, display& disp, const std::string& dialog_style);
|
|
|
|
void draw_rectangle(int x, int y, int w, int h, Uint32 colour, surface tg);
|
|
|
|
void draw_solid_tinted_rectangle(int x, int y, int w, int h,
|
|
int r, int g, int b,
|
|
double alpha, surface target);
|
|
|
|
//given the location of a dialog, will draw its title.
|
|
//Returns the area the title takes up
|
|
SDL_Rect draw_dialog_title(int x, int y, display* disp, const std::string& text);
|
|
|
|
//function to draw a dialog on the screen. x,y,w,h give the dimensions of the client area
|
|
//of the dialog. 'title' is the title of the dialog. The title will be displayed at the
|
|
//top of the dialog above the client area. 'dialog_style' if present gives the style of
|
|
//the dialog to use.
|
|
//'buttons' contains pointers to standard dialog buttons such as 'ok' and 'cancel' that
|
|
//will appear on the dialog. If present, they will be located at the bottom of the dialog,
|
|
//below the client area.
|
|
//if 'restorer' is present, it will be set to a restorer that will reset the screen area
|
|
//to its original state after the dialog is drawn.
|
|
void draw_dialog(int x, int y, int w, int h, display& disp, const std::string& title,
|
|
const std::string* dialog_style=NULL, std::vector<button*>* buttons=NULL,
|
|
surface_restorer* restorer=NULL, button* help_button=NULL);
|
|
|
|
class dialog_action
|
|
{
|
|
public:
|
|
virtual ~dialog_action() {}
|
|
|
|
virtual int do_action() = 0;
|
|
|
|
enum { CONTINUE_DIALOG=-2 };
|
|
};
|
|
|
|
class dialog_button_action
|
|
{
|
|
public:
|
|
virtual ~dialog_button_action() {}
|
|
|
|
enum RESULT { DELETE_ITEM, NO_EFFECT, CLOSE_DIALOG };
|
|
|
|
virtual RESULT button_pressed(int menu_selection) = 0;
|
|
};
|
|
|
|
struct dialog_button
|
|
{
|
|
dialog_button(dialog_button_action* handler, const std::string& label) : handler(handler), label(label)
|
|
{}
|
|
|
|
dialog_button_action* handler;
|
|
std::string label;
|
|
};
|
|
|
|
enum { ESCAPE_DIALOG=-3 };
|
|
|
|
enum DIALOG_TYPE { MESSAGE, OK_ONLY, YES_NO, OK_CANCEL, CANCEL_ONLY, CLOSE_ONLY, NULL_DIALOG };
|
|
|
|
struct check_item {
|
|
check_item(const std::string& label, bool checked) : label(label), checked(checked) {}
|
|
std::string label;
|
|
bool checked;
|
|
};
|
|
|
|
//an interface for a 'preview pane'. A preview pane is shown beside a dialog created
|
|
//by 'show_dialog' and shows information about the selection.
|
|
class preview_pane : public widget {
|
|
public:
|
|
preview_pane(display& disp) : widget(disp) {}
|
|
virtual ~preview_pane() { tooltips::clear_tooltips(location()); }
|
|
|
|
virtual bool show_above() const { return false; }
|
|
virtual bool left_side() const = 0;
|
|
virtual void set_selection(int index) = 0;
|
|
};
|
|
|
|
//function to chop up one long string of text into lines
|
|
size_t text_to_lines(std::string& text, size_t max_length);
|
|
|
|
//if a menu is given, then returns -1 if the dialog was cancelled, and the
|
|
//index of the selection otherwise. If no menu is given, returns the index
|
|
//of the button that was pressed
|
|
int show_dialog(display& screen, surface image,
|
|
const std::string& caption, const std::string& message,
|
|
DIALOG_TYPE type=MESSAGE,
|
|
const std::vector<std::string>* menu_items=NULL,
|
|
const std::vector<preview_pane*>* preview_panes=NULL,
|
|
const std::string& text_widget_label="",
|
|
std::string* text_widget_text=NULL,
|
|
const int text_widget_max_chars = 256,
|
|
dialog_action* action=NULL,
|
|
std::vector<check_item>* options=NULL, int xloc=-1, int yloc=-1,
|
|
const std::string* dialog_style=NULL,
|
|
std::vector<dialog_button>* buttons=NULL,
|
|
const std::string& help_topic=""
|
|
);
|
|
|
|
void show_error_message(display &screen, std::string const &message);
|
|
|
|
network::connection network_data_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num=0);
|
|
|
|
void check_quit(display& screen);
|
|
|
|
}
|
|
|
|
#endif
|