Rewrote some code from C to C++

This commit is contained in:
Leon Styhre 2020-12-16 23:59:00 +01:00
parent 605aa4ba8e
commit debf072a0e
52 changed files with 138 additions and 154 deletions

View file

@ -200,12 +200,12 @@ const std::string FileData::getMediaDirectory()
const std::string FileData::getMediafilePath(std::string subdirectory, std::string mediatype) const
{
const char* extList[2] = { ".png", ".jpg" };
std::vector<std::string> extList = { ".png", ".jpg" };
// Look for an image file in the media directory.
std::string tempPath = getMediaDirectory() + mSystemName + "/" +
subdirectory + "/" + getDisplayName();
for (int i = 0; i < 2; i++) {
for (int i = 0; i < extList.size(); i++) {
std::string mediaPath = tempPath + extList[i];
if (Utils::FileSystem::exists(mediaPath))
return mediaPath;
@ -214,7 +214,7 @@ const std::string FileData::getMediafilePath(std::string subdirectory, std::stri
// No media found in the media directory, so look
// for local art as well (if configured to do so).
if (Settings::getInstance()->getBool("ROMDirGameMedia")) {
for (int i = 0; i < 2; i++) {
for (int i = 0; i < extList.size(); i++) {
std::string localMediaPath = mEnvData->mStartPath + "/images/" +
getDisplayName() + "-" + mediatype + extList[i];
if (Utils::FileSystem::exists(localMediaPath))
@ -273,11 +273,11 @@ const std::string FileData::getThumbnailPath() const
const std::string FileData::getVideoPath() const
{
const char* extList[5] = { ".avi", ".mkv", ".mov", ".mp4", ".wmv" };
std::vector<std::string> extList = { ".avi", ".mkv", ".mov", ".mp4", ".wmv" };
std::string tempPath = getMediaDirectory() + mSystemName + "/videos/" + getDisplayName();
// Look for media in the media directory.
for (int i = 0; i < 5; i++) {
for (int i = 0; i < extList.size(); i++) {
std::string mediaPath = tempPath + extList[i];
if (Utils::FileSystem::exists(mediaPath))
return mediaPath;
@ -287,7 +287,7 @@ const std::string FileData::getVideoPath() const
// for local art as well (if configured to do so).
if (Settings::getInstance()->getBool("ROMDirGameMedia"))
{
for (int i = 0; i < 5; i++) {
for (int i = 0; i < extList.size(); i++) {
std::string localMediaPath = mEnvData->mStartPath + "/videos/" +
getDisplayName() + "-video" + extList[i];
if (Utils::FileSystem::exists(localMediaPath))

View file

@ -26,10 +26,6 @@ enum FileType {
PLACEHOLDER = 3
};
// Used for loading/saving gamelist.xml.
const char* fileTypeToString(FileType type);
FileType stringToFileType(const char* str);
// A tree node that holds information for a file.
class FileData
{

View file

@ -116,13 +116,13 @@ void parseGamelist(SystemData* system)
std::string relativeTo = system->getStartPath();
bool showHiddenFiles = Settings::getInstance()->getBool("ShowHiddenFiles");
const char* tagList[2] = { "game", "folder" };
std::vector<std::string> tagList = { "game", "folder" };
FileType typeList[2] = { GAME, FOLDER };
for (int i = 0; i < 2; i++) {
const char* tag = tagList[i];
std::string tag = tagList[i];
FileType type = typeList[i];
for (pugi::xml_node fileNode = root.child(tag); fileNode; fileNode =
fileNode.next_sibling(tag)) {
for (pugi::xml_node fileNode = root.child(tag.c_str()); fileNode; fileNode =
fileNode.next_sibling(tag.c_str())) {
const std::string path =
Utils::FileSystem::resolveRelativePath(fileNode.child("path").text().get(),
relativeTo, false);
@ -179,10 +179,10 @@ void parseGamelist(SystemData* system)
}
void addFileDataNode(pugi::xml_node& parent, const FileData* file,
const char* tag, SystemData* system)
const std::string& tag, SystemData* system)
{
// Create game and add to parent node.
pugi::xml_node newNode = parent.append_child(tag);
pugi::xml_node newNode = parent.append_child(tag.c_str());
// Write metadata.
file->metadata.appendToXML(newNode, true, system->getStartPath());
@ -258,7 +258,7 @@ void updateGamelist(SystemData* system)
// Iterate through all files, checking if they're already in the XML file.
for (std::vector<FileData*>::const_iterator fit = files.cbegin();
fit != files.cend(); ++fit) {
const char* tag = ((*fit)->getType() == GAME) ? "game" : "folder";
const std::string tag = ((*fit)->getType() == GAME) ? "game" : "folder";
// Do not touch if it wasn't changed and is not flagged for deletion.
if (!(*fit)->metadata.wasChanged() && !(*fit)->getDeletionFlag())
@ -266,8 +266,8 @@ void updateGamelist(SystemData* system)
// Check if the file already exists in the XML file.
// If it does, remove the entry before adding it back.
for (pugi::xml_node fileNode = root.child(tag); fileNode;
fileNode = fileNode.next_sibling(tag)) {
for (pugi::xml_node fileNode = root.child(tag.c_str()); fileNode;
fileNode = fileNode.next_sibling(tag.c_str())) {
pugi::xml_node pathNode = fileNode.child("path");
if (!pathNode) {
LOG(LogError) << "<" << tag << "> node contains no <path> child";

View file

@ -9,10 +9,11 @@
#include "PlatformId.h"
#include <string.h>
#include <vector>
namespace PlatformIds
{
const char* PlatformNames[PLATFORM_COUNT + 1] = {
std::vector<std::string> PlatformNames = {
"unknown", // Nothing set.
"3do",
@ -124,20 +125,20 @@ namespace PlatformIds
"invalid"
};
PlatformId getPlatformId(const char* str)
PlatformId getPlatformId(const std::string& str)
{
if (str == nullptr)
if (str == "")
return PLATFORM_UNKNOWN;
for (unsigned int i = 1; i < PLATFORM_COUNT; i++) {
if (strcmp(PlatformNames[i], str) == 0)
if (PlatformNames[i] == str)
return (PlatformId)i;
}
return PLATFORM_UNKNOWN;
}
const char* getPlatformName(PlatformId id)
const std::string getPlatformName(PlatformId id)
{
return PlatformNames[id];
}

View file

@ -9,6 +9,8 @@
#ifndef ES_APP_PLATFORM_ID_H
#define ES_APP_PLATFORM_ID_H
#include <string>
namespace PlatformIds
{
enum PlatformId : unsigned int {
@ -123,8 +125,8 @@ namespace PlatformIds
PLATFORM_COUNT
};
PlatformId getPlatformId(const char* str);
const char* getPlatformName(PlatformId id);
PlatformId getPlatformId(const std::string& str);
const std::string getPlatformName(PlatformId id);
}
#endif // ES_APP_PLATFORM_ID_H

View file

@ -206,7 +206,7 @@ void SystemData::indexAllGameFilters(const FileData* folder)
}
}
std::vector<std::string> readList(const std::string& str, const char* delims = " \t\r\n,")
std::vector<std::string> readList(const std::string& str, const std::string& delims = " \t\r\n,")
{
std::vector<std::string> ret;
@ -285,11 +285,11 @@ bool SystemData::loadConfig()
cmd = system.child("command").text().get();
// Platform ID list
const char* platformList = system.child("platform").text().get();
const std::string platformList = system.child("platform").text().get();
std::vector<std::string> platformStrs = readList(platformList);
std::vector<PlatformIds::PlatformId> platformIds;
for (auto it = platformStrs.cbegin(); it != platformStrs.cend(); it++) {
const char* str = it->c_str();
std::string str = it->c_str();
PlatformIds::PlatformId platformId = PlatformIds::getPlatformId(str);
if (platformId == PlatformIds::PLATFORM_IGNORE) {
@ -301,7 +301,7 @@ bool SystemData::loadConfig()
// If there appears to be an actual platform ID supplied
// but it didn't match the list, generate a warning.
if (str != nullptr && str[0] != '\0' && platformId == PlatformIds::PLATFORM_UNKNOWN)
if (str != "" && platformId == PlatformIds::PLATFORM_UNKNOWN)
LOG(LogWarning) << "Unknown platform for system \"" << name <<
"\" (platform \"" << str << "\" from list \"" << platformList << "\")";
else if (platformId != PlatformIds::PLATFORM_UNKNOWN)

View file

@ -26,11 +26,11 @@
// the rest of the volume control code in here compiles and works fine.
#if defined(__linux__)
#if defined(_RPI_) || defined(_VERO4K_)
const char * VolumeControl::mixerName = "PCM";
const std::string VolumeControl::mixerName = "PCM";
#else
const char * VolumeControl::mixerName = "Master";
const std::string VolumeControl::mixerName = "Master";
#endif
const char * VolumeControl::mixerCard = "default";
const std::string VolumeControl::mixerCard = "default";
#endif
std::weak_ptr<VolumeControl> VolumeControl::sInstance;
@ -113,19 +113,19 @@ void VolumeControl::init()
if (mixerHandle == nullptr) {
// Allow user to override the AudioCard and AudioDevice in es_settings.cfg.
#if defined(_RPI_)
mixerCard = Settings::getInstance()->getString("AudioCard").c_str();
mixerName = Settings::getInstance()->getString("AudioDevice").c_str();
mixerCard = Settings::getInstance()->getString("AudioCard");
mixerName = Settings::getInstance()->getString("AudioDevice");
#endif
snd_mixer_selem_id_alloca(&mixerSelemId);
// Sets simple-mixer index and name.
snd_mixer_selem_id_set_index(mixerSelemId, mixerIndex);
snd_mixer_selem_id_set_name(mixerSelemId, mixerName);
snd_mixer_selem_id_set_name(mixerSelemId, mixerName.c_str());
// Open mixer.
if (snd_mixer_open(&mixerHandle, 0) >= 0) {
LOG(LogDebug) << "VolumeControl::init() - Opened ALSA mixer";
// Ok, attach to defualt card.
if (snd_mixer_attach(mixerHandle, mixerCard) >= 0) {
if (snd_mixer_attach(mixerHandle, mixerCard.c_str()) >= 0) {
LOG(LogDebug) << "VolumeControl::init() - Attached to default card";
// Ok, register simple element class.
if (snd_mixer_selem_register(mixerHandle, nullptr, nullptr) >= 0) {
@ -253,7 +253,7 @@ void VolumeControl::deinit()
// #error TODO: Not implemented for MacOS yet!!!
#elif defined(__linux__)
if (mixerHandle != nullptr) {
snd_mixer_detach(mixerHandle, mixerCard);
snd_mixer_detach(mixerHandle, mixerCard.c_str());
snd_mixer_free(mixerHandle);
snd_mixer_close(mixerHandle);
mixerHandle = nullptr;

View file

@ -30,8 +30,8 @@ class VolumeControl
#if defined(__APPLE__)
// #error TODO: Not implemented for MacOS yet!!!
#elif defined(__linux__)
static const char * mixerName;
static const char * mixerCard;
static const std::string mixerName;
static const std::string mixerCard;
int mixerIndex;
snd_mixer_t* mixerHandle;
snd_mixer_elem_t* mixerElem;

View file

@ -938,7 +938,7 @@ void GuiMenu::onSizeChanged()
mVersion.setPosition(0, mSize.y() - mVersion.getSize().y());
}
void GuiMenu::addEntry(const char* name, unsigned int color,
void GuiMenu::addEntry(const std::string& name, unsigned int color,
bool add_arrow, const std::function<void()>& func)
{
std::shared_ptr<Font> font = Font::get(FONT_SIZE_MEDIUM);

View file

@ -26,7 +26,7 @@ public:
private:
void close(bool closeAllWindows);
void addEntry(const char* name, unsigned int color,
void addEntry(const std::string& name, unsigned int color,
bool add_arrow, const std::function<void()>& func);
void addVersionInfo();

View file

@ -579,7 +579,7 @@ std::queue<ScraperSearchParams> GuiScraperMenu::getSearches(
return queue;
}
void GuiScraperMenu::addEntry(const char* name, unsigned int color,
void GuiScraperMenu::addEntry(const std::string& name, unsigned int color,
bool add_arrow, const std::function<void()>& func)
{
std::shared_ptr<Font> font = Font::get(FONT_SIZE_MEDIUM);

View file

@ -37,7 +37,7 @@ private:
void pressedStart();
void start();
void addEntry(const char* name, unsigned int color,
void addEntry(const std::string&, unsigned int color,
bool add_arrow, const std::function<void()>& func);
void openAccountSettings();
void openContentSettings();

View file

@ -15,7 +15,7 @@
#include "guis/GuiMsgBox.h"
#include "Settings.h"
GuiScreensaverOptions::GuiScreensaverOptions(Window* window, const char* title)
GuiScreensaverOptions::GuiScreensaverOptions(Window* window, const std::string& title)
: GuiSettings(window, title)
{
// Screensaver timer.

View file

@ -15,7 +15,7 @@
class GuiScreensaverOptions : public GuiSettings
{
public:
GuiScreensaverOptions(Window* window, const char* title);
GuiScreensaverOptions(Window* window, const std::string& title);
private:
void openSlideshowScreensaverOptions();

View file

@ -143,7 +143,7 @@ pugi::xml_node find_child_by_attribute_list(const pugi::xml_node& node_parent,
{
for (auto _val : attribute_values) {
for (pugi::xml_node node : node_parent.children(node_name.c_str())) {
if (strcmp(node.attribute(attribute_name.c_str()).value(), _val.c_str()) == 0)
if (node.attribute(attribute_name.c_str()).value() == _val)
return node;
}
}

View file

@ -30,7 +30,7 @@ public:
virtual FileData* getLastEntry() override;
virtual FileData* getFirstGameEntry() override;
virtual const char* getName() const override { return "basic"; }
virtual std::string getName() const override { return "basic"; }
virtual std::vector<HelpPrompt> getHelpPrompts() override;
virtual void launch(FileData* game) override;

View file

@ -150,7 +150,7 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& them
initMDLabels();
std::vector<TextComponent*> labels = getMDLabels();
assert(labels.size() == 8);
const char* lblElements[8] = {
std::vector<std::string> lblElements = {
"md_lbl_rating", "md_lbl_releasedate", "md_lbl_developer", "md_lbl_publisher",
"md_lbl_genre", "md_lbl_players", "md_lbl_lastplayed", "md_lbl_playcount"
};
@ -161,7 +161,7 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& them
initMDValues();
std::vector<GuiComponent*> values = getMDValues();
assert(values.size() == 8);
const char* valElements[8] = {
std::vector<std::string> valElements = {
"md_rating", "md_releasedate", "md_developer", "md_publisher",
"md_genre", "md_players", "md_lastplayed", "md_playcount"
};

View file

@ -21,7 +21,7 @@ public:
virtual void onShow() override;
virtual void onThemeChanged(const std::shared_ptr<ThemeData>& theme) override;
virtual const char* getName() const override { return "detailed"; }
virtual std::string getName() const override { return "detailed"; }
virtual void launch(FileData* game) override;
protected:

View file

@ -282,7 +282,7 @@ void GridGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
initMDLabels();
std::vector<TextComponent*> labels = getMDLabels();
assert(labels.size() == 8);
const char* lblElements[8] = {
std::vector<std::string> lblElements = {
"md_lbl_rating", "md_lbl_releasedate", "md_lbl_developer", "md_lbl_publisher",
"md_lbl_genre", "md_lbl_players", "md_lbl_lastplayed", "md_lbl_playcount"
};
@ -293,7 +293,7 @@ void GridGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
initMDValues();
std::vector<GuiComponent*> values = getMDValues();
assert(values.size() == 8);
const char* valElements[8] = {
std::vector<std::string> valElements = {
"md_rating", "md_releasedate", "md_developer", "md_publisher",
"md_genre", "md_players", "md_lastplayed", "md_playcount"
};

View file

@ -36,7 +36,7 @@ public:
virtual bool input(InputConfig* config, Input input) override;
virtual const char* getName() const override { return "grid"; }
virtual std::string getName() const override { return "grid"; }
virtual std::vector<HelpPrompt> getHelpPrompts() override;
virtual void launch(FileData* game) override;

View file

@ -52,7 +52,7 @@ public:
virtual void remove(FileData* game, bool deleteFile) = 0;
virtual void removeMedia(FileData* game) = 0;
virtual const char* getName() const = 0;
virtual std::string getName() const = 0;
virtual void launch(FileData* game) = 0;
virtual HelpStyle getHelpStyle() override;

View file

@ -175,7 +175,7 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
initMDLabels();
std::vector<TextComponent*> labels = getMDLabels();
assert(labels.size() == 8);
const char* lblElements[8] = {
std::vector<std::string> lblElements = {
"md_lbl_rating", "md_lbl_releasedate", "md_lbl_developer", "md_lbl_publisher",
"md_lbl_genre", "md_lbl_players", "md_lbl_lastplayed", "md_lbl_playcount"
};
@ -186,7 +186,7 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
initMDValues();
std::vector<GuiComponent*> values = getMDValues();
assert(values.size() == 8);
const char* valElements[8] = {
std::vector<std::string> valElements = {
"md_rating", "md_releasedate", "md_developer", "md_publisher",
"md_genre", "md_players", "md_lastplayed", "md_playcount"
};

View file

@ -24,7 +24,7 @@ public:
virtual void onShow() override;
virtual void onThemeChanged(const std::shared_ptr<ThemeData>& theme) override;
virtual const char* getName() const override { return "video"; }
virtual std::string getName() const override { return "video"; }
virtual void launch(FileData* game) override;
protected:

View file

@ -355,7 +355,7 @@ void GuiComponent::setHiddenValue(const std::string& /*value*/)
{
}
void GuiComponent::textInput(const char* text)
void GuiComponent::textInput(const std::string& text)
{
for (auto iter = mChildren.cbegin(); iter != mChildren.cend(); iter++)
(*iter)->textInput(text);

View file

@ -41,7 +41,7 @@ public:
GuiComponent(Window* window);
virtual ~GuiComponent();
virtual void textInput(const char* text);
virtual void textInput(const std::string& text);
// Called when input is received.
// Return true if the input is consumed, false if

View file

@ -190,7 +190,7 @@ std::string HttpReq::getContent() const
return mContent.str();
}
void HttpReq::onError(const char* msg)
void HttpReq::onError(const std::string& msg)
{
mErrorMsg = msg;
}

View file

@ -67,7 +67,7 @@ public:
private:
static size_t write_content(void* buff, size_t size, size_t nmemb, void* req_ptr);
void onError(const char* msg);
void onError(const std::string& msg);
// God dammit libcurl why can't you have some way to check the status of an
// individual handle why do I have to handle ALL messages at once.

View file

@ -15,8 +15,8 @@
class ImageIO
{
public:
static std::vector<unsigned char> loadFromMemoryRGBA32(const unsigned char * data,
const size_t size, size_t & width, size_t & height);
static std::vector<unsigned char> loadFromMemoryRGBA32(const unsigned char* data,
const size_t size, size_t& width, size_t& height);
static void flipPixelsVert(unsigned char* imagePx, const size_t& width, const size_t& height);
};

View file

@ -16,6 +16,7 @@
#include "utils/StringUtil.h"
#include "Log.h"
#include <algorithm>
#include <pugixml.hpp>
#include <string.h>
@ -171,19 +172,5 @@ const bool MameNames::isDevice(const std::string& _deviceName)
const bool MameNames::find(std::vector<std::string> devices, const std::string& name)
{
size_t start = 0;
size_t end = devices.size();
while (start < end) {
const size_t index = (start + end) / 2;
const int compare = strcmp(devices[index].c_str(), name.c_str());
if (compare < 0)
start = index + 1;
else if (compare > 0)
end = index;
else
return true;
}
return false;
return (std::find(devices.begin(), devices.end(), name) != devices.end());
}

View file

@ -198,13 +198,13 @@ std::map<std::string, std::map<std::string,
#define CURRENT_THEME_FORMAT_VERSION 6
// Helper.
unsigned int getHexColor(const char* str)
unsigned int getHexColor(const std::string& str)
{
ThemeException error;
if (!str)
if (str == "")
throw error << "Empty color";
size_t len = strlen(str);
size_t len = str.size();
if (len != 6 && len != 8)
throw error << "Invalid color (bad length, \"" << str << "\" - must be 6 or 8)";
@ -221,22 +221,20 @@ unsigned int getHexColor(const char* str)
std::map<std::string, std::string> mVariables;
std::string resolvePlaceholders(const char* in)
std::string resolvePlaceholders(const std::string& in)
{
std::string inStr(in);
if (in.empty())
return in;
if (inStr.empty())
return inStr;
const size_t variableBegin = inStr.find("${");
const size_t variableEnd = inStr.find("}", variableBegin);
const size_t variableBegin = in.find("${");
const size_t variableEnd = in.find("}", variableBegin);
if ((variableBegin == std::string::npos) || (variableEnd == std::string::npos))
return inStr;
return in;
std::string prefix = inStr.substr(0, variableBegin);
std::string replace = inStr.substr(variableBegin + 2, variableEnd - (variableBegin + 2));
std::string suffix = resolvePlaceholders(inStr.substr(variableEnd + 1).c_str());
std::string prefix = in.substr(0, variableBegin);
std::string replace = in.substr(variableBegin + 2, variableEnd - (variableBegin + 2));
std::string suffix = resolvePlaceholders(in.substr(variableEnd + 1).c_str());
return prefix + mVariables[replace] + suffix;
}
@ -377,7 +375,7 @@ void ThemeData::parseViews(const pugi::xml_node& root)
if (!node.attribute("name"))
throw error << "View missing \"name\" attribute!";
const char* delim = " \t\r\n,";
const std::string delim = " \t\r\n,";
const std::string nameAttr = node.attribute("name").as_string();
size_t prevOff = nameAttr.find_first_not_of(delim, 0);
size_t off = nameAttr.find_first_of(delim, prevOff);
@ -410,7 +408,7 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view)
if (elemTypeIt == sElementMap.cend())
throw error << "Unknown element of type \"" << node.name() << "\"!";
const char* delim = " \t\r\n,";
const std::string delim = " \t\r\n,";
const std::string nameAttr = node.attribute("name").as_string();
size_t prevOff = nameAttr.find_first_not_of(delim, 0);
size_t off = nameAttr.find_first_of(delim, prevOff);
@ -502,7 +500,7 @@ void ThemeData::parseElement(const pugi::xml_node& root,
break;
}
case COLOR: {
element.properties[node.name()] = getHexColor(str.c_str());
element.properties[node.name()] = getHexColor(str);
break;
}
case FLOAT: {

View file

@ -131,7 +131,7 @@ void Window::deinit()
Renderer::deinit();
}
void Window::textInput(const char* text)
void Window::textInput(const std::string& text)
{
if (peekGui())
peekGui()->textInput(text);
@ -530,19 +530,18 @@ void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpSt
std::sort(addPrompts.begin(), addPrompts.end(),
[](const HelpPrompt& a, const HelpPrompt& b) -> bool {
static const char* map[] = {
static const std::vector<std::string> map = {
"up/down/left/right",
"up/down",
"left/right",
"a", "b", "x", "y", "l", "r",
"start", "select",
nullptr
"start", "select"
};
int i = 0;
int aVal = 0;
int bVal = 0;
while (map[i] != nullptr) {
while (i < map.size()) {
if (a.first == map[i])
aVal = i;
if (b.first == map[i])

View file

@ -65,9 +65,9 @@ public:
GuiComponent* peekGui();
inline int getGuiStackSize() { return static_cast<int>(mGuiStack.size()); }
void textInput(const char* text);
void textInput(const std::string& text);
void input(InputConfig* config, Input input);
void logInput(InputConfig * config, Input input);
void logInput(InputConfig* config, Input input);
void update(int deltaTime);
void render();

View file

@ -24,7 +24,7 @@ void AnimatedImageComponent::load(const AnimationDef* def)
assert(def->frameCount >= 1);
for (size_t i = 0; i < def->frameCount; i++) {
if (def->frames[i].path != nullptr &&
if (def->frames[i].path != "" &&
!ResourceManager::getInstance()->fileExists(def->frames[i].path)) {
LOG(LogError) << "Missing animation frame " << i <<
" (\"" << def->frames[i].path << "\")";

View file

@ -14,7 +14,7 @@
class ImageComponent;
struct AnimationFrame {
const char* path;
std::string path;
int time;
};

View file

@ -358,7 +358,7 @@ void ComponentGrid::render(const Transform4x4f& parentTrans)
}
}
void ComponentGrid::textInput(const char* text)
void ComponentGrid::textInput(const std::string& text)
{
const GridEntry* selectedEntry = getCellAt(mCursor);
if (selectedEntry != nullptr && selectedEntry->canFocus)

View file

@ -48,7 +48,7 @@ public:
unsigned int border = GridFlags::BORDER_NONE,
GridFlags::UpdateType updateType = GridFlags::UPDATE_ALWAYS);
void textInput(const char* text) override;
void textInput(const std::string& text) override;
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;

View file

@ -357,7 +357,7 @@ void ComponentList::updateElementSize(const ComponentListRow& row)
(*it)->setSize(width, (*it)->getSize().y());
}
void ComponentList::textInput(const char* text)
void ComponentList::textInput(const std::string& text)
{
if (!size())
return;

View file

@ -62,7 +62,7 @@ public:
void addRow(const ComponentListRow& row, bool setCursorHere = false);
void textInput(const char* text) override;
void textInput(const std::string& text) override;
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;

View file

@ -22,7 +22,7 @@
#define ICON_TEXT_SPACING 8 // Space between [icon] and [text] (px).
#define ENTRY_SPACING 16 // Space between [text] and next [icon] (px).
static const std::map<std::string, const char*> ICON_PATH_MAP {
static const std::map<std::string, std::string> ICON_PATH_MAP {
{ "up/down", ":/help/dpad_updown.svg" },
{ "left/right", ":/help/dpad_leftright.svg" },
{ "up/down/left/right", ":/help/dpad_all.svg" },

View file

@ -62,7 +62,7 @@ std::string TextEditComponent::getValue() const
return mText;
}
void TextEditComponent::textInput(const char* text)
void TextEditComponent::textInput(const std::string& text)
{
if (mEditing) {
mCursorRepeatDir = 0;
@ -75,7 +75,7 @@ void TextEditComponent::textInput(const char* text)
}
else {
mText.insert(mCursor, text);
mCursor += static_cast<unsigned int>(strlen(text));
mCursor += static_cast<unsigned int>(text.size());
}
}

View file

@ -21,7 +21,7 @@ class TextEditComponent : public GuiComponent
public:
TextEditComponent(Window* window);
void textInput(const char* text) override;
void textInput(const std::string& text) override;
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;

View file

@ -25,12 +25,12 @@ GuiComplexTextEditPopup::GuiComplexTextEditPopup(
const std::string& initValue,
const std::function<void(const std::string&)>& okCallback,
bool multiLine,
const char* acceptBtnText,
const char* saveConfirmationText,
const char* loadBtnText,
const char* loadBtnHelpText,
const char* clearBtnText,
const char* clearBtnHelpText,
const std::string& acceptBtnText,
const std::string& saveConfirmationText,
const std::string& loadBtnText,
const std::string& loadBtnHelpText,
const std::string& clearBtnText,
const std::string& clearBtnHelpText,
bool hideCancelButton)
: GuiComponent(window),
mHelpStyle(helpstyle),

View file

@ -30,12 +30,12 @@ public:
const std::string& initValue,
const std::function<void(const std::string&)>& okCallback,
bool multiLine,
const char* acceptBtnText = "OK",
const char* saveConfirmationText = "SAVE CHANGES?",
const char* loadBtnText = "LOAD",
const char* loadBtnHelpText = "load default",
const char* clearBtnText = "CLEAR",
const char* clearBtnHelpText = "clear",
const std::string& acceptBtnText = "OK",
const std::string& saveConfirmationText = "SAVE CHANGES?",
const std::string& loadBtnText = "LOAD",
const std::string& loadBtnHelpText = "load default",
const std::string& clearBtnText = "CLEAR",
const std::string& clearBtnHelpText = "clear",
bool hideCancelButton = false);
bool input(InputConfig* config, Input input) override;

View file

@ -66,7 +66,7 @@ GuiDetectDevice::GuiDetectDevice(
mGrid.setEntry(mMsg1, Vector2i(0, 2), false, true);
const char* msg2str = firstRun ?
const std::string msg2str = firstRun ?
"PRESS ESC TO SKIP (OR F4 TO QUIT AT ANY TIME)." : "PRESS ESC TO CANCEL.";
mMsg2 = std::make_shared<TextComponent>(mWindow, msg2str,
Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER);

View file

@ -16,10 +16,10 @@
#include "Window.h"
struct InputConfigStructure {
const char* name;
std::string name;
const bool skippable;
const char* dispName;
const char* icon;
std::string dispName;
std::string icon;
};
static const int inputCount = 22;
@ -355,7 +355,7 @@ bool GuiInputConfig::assign(Input input, int inputId)
// generate an error. (If it's the same as what it was before, allow it.)
if (mTargetConfig->getMappedTo(input).size() > 0 &&
!mTargetConfig->isMappedTo(GUI_INPUT_CONFIG_LIST[inputId].name, input) &&
strcmp(GUI_INPUT_CONFIG_LIST[inputId].name, "HotKeyEnable") != 0) {
GUI_INPUT_CONFIG_LIST[inputId].name != "HotKeyEnable") {
error(mMappings.at(inputId), "Already mapped!");
return false;
}

View file

@ -21,8 +21,8 @@ GuiTextEditPopup::GuiTextEditPopup(
const std::string& initValue,
const std::function<void(const std::string&)>& okCallback,
bool multiLine,
const char* acceptBtnText,
const char* saveConfirmationText)
const std::string& acceptBtnText,
const std::string& saveConfirmationText)
: GuiComponent(window),
mHelpStyle(helpstyle),
mBackground(window, ":/graphics/frame.png"),

View file

@ -26,8 +26,8 @@ public:
const std::string& initValue,
const std::function<void(const std::string&)>& okCallback,
bool multiLine,
const char* acceptBtnText = "OK",
const char* saveConfirmationText = "SAVE CHANGES?");
const std::string& acceptBtnText = "OK",
const std::string& saveConfirmationText = "SAVE CHANGES?");
bool input(InputConfig* config, Input input) override;
void onSizeChanged() override;

View file

@ -55,7 +55,7 @@ namespace Renderer
#if !defined(NDEBUG)
#define GL_CHECK_ERROR(Function) (Function, _GLCheckError(#Function))
static void _GLCheckError(const char* _funcName)
static void _GLCheckError(const std::string& _funcName)
{
const GLenum errorCode = glGetError();

View file

@ -569,7 +569,7 @@ TextCache* Font::buildTextCache(
if (character == '\n') {
y += getHeight(lineSpacing);
x = offset[0] + (xLen != 0 ? getNewlineStartOffset(text,
(const unsigned int)cursor /* cursor is already advanced */,
static_cast<const unsigned int>(cursor) /* cursor is already advanced */,
xLen, alignment) : 0);
continue;
}

View file

@ -15,6 +15,7 @@
#include "renderers/Renderer.h"
#include "resources/ResourceManager.h"
#include "ThemeData.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#include <vector>
@ -82,7 +83,7 @@ public:
int getSize() const;
inline const std::string& getPath() const { return mPath; }
inline static const char* getDefaultPath() { return FONT_PATH_REGULAR; }
inline static std::string getDefaultPath() { return FONT_PATH_REGULAR; }
static std::shared_ptr<Font> getFromTheme(const ThemeData::ThemeElement* elem,
unsigned int properties, const std::shared_ptr<Font>& orig);

View file

@ -81,7 +81,7 @@ void TextureResource::initFromMemory(const char* data, size_t length)
assert(mTextureData != nullptr);
mTextureData->releaseVRAM();
mTextureData->releaseRAM();
mTextureData->initImageFromMemory((const unsigned char*)data, length);
mTextureData->initImageFromMemory(reinterpret_cast<const unsigned char*>(data), length);
// Get the size from the texture data.
mSize = Vector2i(static_cast<int>(mTextureData->width()),
static_cast<int>(mTextureData->height()));

View file

@ -208,7 +208,7 @@ namespace Utils
std::string removeParenthesis(const std::string& _string)
{
static const char remove[4] = { '(', ')', '[', ']' };
static std::vector<char> remove = { '(', ')', '[', ']' };
std::string string = _string;
size_t start;
size_t end;
@ -217,9 +217,9 @@ namespace Utils
while (!done) {
done = true;
for (size_t i = 0; i < sizeof(remove); i += 2) {
for (size_t i = 0; i < remove.size(); i += 2) {
end = string.find_first_of(remove[i + 1]);
start = string.find_last_of( remove[i + 0], end);
start = string.find_last_of(remove[i + 0], end);
if ((start != std::string::npos) && (end != std::string::npos)) {
string.erase(start, end - start + 1);