helpers added

This commit is contained in:
turanszkij
2016-06-10 22:06:06 +02:00
parent 2326451761
commit 4cbcf4854d
4 changed files with 79 additions and 5 deletions
+60
View File
@@ -73,4 +73,64 @@ namespace wiHelper
ss << std::put_time(&time_info, "%d-%m-%Y %H-%M-%S");
return ss.str();
}
string GetWorkingDirectory()
{
char result[MAX_PATH];
return std::string(result, GetModuleFileNameA(NULL, result, MAX_PATH));
}
void GetFilesInDirectory(vector<string>& out, const string& directory)
{
#ifndef WINSTORE_SUPPORT
// WINDOWS
wstring wdirectory = wstring(directory.begin(), directory.end());
HANDLE dir;
WIN32_FIND_DATA file_data;
if ((dir = FindFirstFile((wdirectory + L"/*").c_str(), &file_data)) == INVALID_HANDLE_VALUE)
return; /* No files found */
do {
const wstring file_name = file_data.cFileName;
const wstring full_file_name = wdirectory + L"/" + file_name;
const bool is_directory = (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
//if (file_name[0] == '.')
// continue;
//if (is_directory)
// continue;
out.push_back(string(full_file_name.begin(), full_file_name.end()));
} while (FindNextFile(dir, &file_data));
FindClose(dir);
#endif
// UNIX
//DIR *dir;
//class dirent *ent;
//class stat st;
//dir = opendir(directory);
//while ((ent = readdir(dir)) != NULL) {
// const string file_name = ent->d_name;
// const string full_file_name = directory + "/" + file_name;
// if (file_name[0] == '.')
// continue;
// if (stat(full_file_name.c_str(), &st) == -1)
// continue;
// const bool is_directory = (st.st_mode & S_IFDIR) != 0;
// if (is_directory)
// continue;
// out.push_back(full_file_name);
//}
//closedir(dir);
}
}
+4
View File
@@ -15,6 +15,10 @@ namespace wiHelper
void screenshot(const string& name = "");
string getCurrentDateTimeAsString();
string GetWorkingDirectory();
void GetFilesInDirectory(vector<string> &out, const string &directory);
};
#endif
+13 -3
View File
@@ -5,6 +5,7 @@
#include "wiTextureHelper.h"
#include "wiFont.h"
#include "wiMath.h"
#include "wiHelper.h"
wiWidget::wiWidget():Transform()
@@ -704,7 +705,7 @@ void wiWindow::AddWidget(wiWidget* widget)
childrenWidgets.push_back(widget);
}
void wiWindow::RemoveWidget(wiWidget* widget)
void wiWindow::RemoveWidget(wiWidget* widget, bool alsoDelete)
{
assert(gui != nullptr && "Ivalid GUI!");
@@ -712,15 +713,24 @@ void wiWindow::RemoveWidget(wiWidget* widget)
widget->detach();
childrenWidgets.remove(widget);
if (alsoDelete)
{
SAFE_DELETE(widget);
}
}
void wiWindow::RemoveWidgets()
void wiWindow::RemoveWidgets(bool alsoDelete)
{
assert(gui != nullptr && "Ivalid GUI!");
for (auto& x : childrenWidgets)
{
gui->RemoveWidget(x);
x->detach();
gui->RemoveWidget(x);
if (alsoDelete)
{
SAFE_DELETE(x);
}
}
childrenWidgets.clear();
+2 -2
View File
@@ -170,8 +170,8 @@ public:
virtual ~wiWindow();
void AddWidget(wiWidget* widget);
void RemoveWidget(wiWidget* widget);
void RemoveWidgets();
void RemoveWidget(wiWidget* widget, bool alsoDelete = false);
void RemoveWidgets(bool alsoDelete = false);
virtual void Update(wiGUI* gui) override;
virtual void Render(wiGUI* gui) override;