| 1 |
// Copyright © 2002 Rob Kaper <[email protected]> |
| 2 |
// 2010-2015 Sylvain Rochet <[email protected]> |
| 3 |
// |
| 4 |
// This program is free software; you can redistribute it and/or |
| 5 |
// modify it under the terms of the GNU General Public License |
| 6 |
// version 2 as published by the Free Software Foundation. |
| 7 |
// |
| 8 |
// This program is distributed in the hope that it will be useful, |
| 9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
// General Public License for more details. |
| 12 |
// |
| 13 |
// You should have received a copy of the GNU General Public License |
| 14 |
// along with this program; see the file COPYING. If not, see |
| 15 |
// <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
#include "config.h" |
| 18 |
|
| 19 |
#include <stdio.h> |
| 20 |
#include <stdarg.h> |
| 21 |
|
| 22 |
#include "display.h" |
| 23 |
#include "estate.h" |
| 24 |
#include "io.h" |
| 25 |
#include "player.h" |
| 26 |
|
| 27 |
DisplayButton::DisplayButton(const std::string command, const std::string caption, const bool enabled) |
| 28 |
{ |
| 29 |
m_command = command; |
| 30 |
m_caption = caption; |
| 31 |
m_enabled = enabled; |
| 32 |
} |
| 33 |
|
| 34 |
DisplayButton::DisplayButton(const DisplayButton *button) { |
| 35 |
m_command = button->m_command; |
| 36 |
m_caption = button->m_caption; |
| 37 |
m_enabled = button->m_enabled; |
| 38 |
} |
| 39 |
|
| 40 |
const std::string DisplayButton::command() |
| 41 |
{ |
| 42 |
return m_command; |
| 43 |
} |
| 44 |
|
| 45 |
const std::string DisplayButton::caption() |
| 46 |
{ |
| 47 |
return m_caption; |
| 48 |
} |
| 49 |
|
| 50 |
bool DisplayButton::enabled() |
| 51 |
{ |
| 52 |
return m_enabled; |
| 53 |
} |
| 54 |
|
| 55 |
Display::Display() |
| 56 |
{ |
| 57 |
m_estate = NULL; |
| 58 |
m_text = ""; |
| 59 |
m_clearText = m_clearButtons = m_clearEstate = false; |
| 60 |
} |
| 61 |
|
| 62 |
Display::Display(const Display *display) { |
| 63 |
m_estate = display->m_estate; |
| 64 |
m_text = display->m_text; |
| 65 |
m_clearText = display->m_clearText; |
| 66 |
m_clearButtons = display->m_clearButtons; |
| 67 |
m_clearEstate = display->m_clearEstate; |
| 68 |
|
| 69 |
std::vector<DisplayButton *> buttons = display->m_buttons; |
| 70 |
for (std::vector<DisplayButton *>::iterator it = buttons.begin() ; it != buttons.end(); ++it) { |
| 71 |
DisplayButton *button = new DisplayButton(*it); |
| 72 |
m_buttons.push_back(button); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
Display::~Display() |
| 77 |
{ |
| 78 |
while (!m_buttons.empty()) { delete *m_buttons.begin(); m_buttons.erase(m_buttons.begin()); } |
| 79 |
} |
| 80 |
|
| 81 |
void Display::setEstate(Estate *estate) |
| 82 |
{ |
| 83 |
m_estate = estate; |
| 84 |
} |
| 85 |
|
| 86 |
Estate *Display::estate() |
| 87 |
{ |
| 88 |
return m_estate; |
| 89 |
} |
| 90 |
|
| 91 |
void Display::setText(const std::string text) |
| 92 |
{ |
| 93 |
m_text = text; |
| 94 |
} |
| 95 |
|
| 96 |
void Display::setText(const char *fmt, ...) |
| 97 |
{ |
| 98 |
va_list arg; |
| 99 |
char buf[2048]; |
| 100 |
|
| 101 |
va_start(arg, fmt); |
| 102 |
vsnprintf(buf, sizeof(buf), fmt, arg); |
| 103 |
va_end(arg); |
| 104 |
buf[sizeof(buf)-1] = 0; |
| 105 |
|
| 106 |
m_text = std::string(buf); |
| 107 |
} |
| 108 |
|
| 109 |
const std::string Display::text() |
| 110 |
{ |
| 111 |
return escapeXML(m_text); |
| 112 |
} |
| 113 |
|
| 114 |
void Display::addButton(const std::string command, const std::string caption, const bool enabled) |
| 115 |
{ |
| 116 |
DisplayButton *button = new DisplayButton(command, caption, enabled); |
| 117 |
m_buttons.push_back(button); |
| 118 |
} |
| 119 |
|
| 120 |
void Display::resetButtons() |
| 121 |
{ |
| 122 |
m_clearButtons = true; |
| 123 |
} |
| 124 |
|
| 125 |
void Display::resetText() |
| 126 |
{ |
| 127 |
m_clearText = true; |
| 128 |
} |
| 129 |
|
| 130 |
void Display::resetEstate() |
| 131 |
{ |
| 132 |
m_clearEstate = true; |
| 133 |
} |
| 134 |
|
| 135 |
bool Display::clearButtons() |
| 136 |
{ |
| 137 |
return m_clearButtons; |
| 138 |
} |
| 139 |
|
| 140 |
bool Display::clearText() |
| 141 |
{ |
| 142 |
return m_clearText; |
| 143 |
} |
| 144 |
|
| 145 |
bool Display::clearEstate() |
| 146 |
{ |
| 147 |
return m_clearEstate; |
| 148 |
} |
| 149 |
|
| 150 |
std::vector<DisplayButton *> Display::buttons() |
| 151 |
{ |
| 152 |
return m_buttons; |
| 153 |
} |