mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-24 03:39:07 +02:00
FileInfo struct, not properly used yet. ui code cleaning
This commit is contained in:
1 parent
5b7c95d474
commit
113f10abfe
5 files changed
+47
-33
No files matched your search
+8
-8
@@ -61,8 +61,7 @@ bool ReadFileToString(bool text_file, const char *filename, std::string &str)
|
||||
|
||||
#ifndef METRO
|
||||
|
||||
size_t getFilesInDir(const char *directory, std::vector<std::string> *files)
|
||||
{
|
||||
size_t getFilesInDir(const char *directory, std::vector<FileInfo> *files) {
|
||||
size_t foundEntries = 0;
|
||||
#ifdef _WIN32
|
||||
// Find the first file in the directory.
|
||||
@@ -72,10 +71,9 @@ size_t getFilesInDir(const char *directory, std::vector<std::string> *files)
|
||||
#else
|
||||
HANDLE hFind = FindFirstFile((std::string(directory) + "\\*").c_str(), &ffd);
|
||||
#endif
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (hFind == INVALID_HANDLE_VALUE) {
|
||||
FindClose(hFind);
|
||||
return foundEntries;
|
||||
return 0;
|
||||
}
|
||||
// windows loop
|
||||
do
|
||||
@@ -98,8 +96,10 @@ size_t getFilesInDir(const char *directory, std::vector<std::string> *files)
|
||||
((virtualName[0] == '.') && (virtualName[1] == '.') &&
|
||||
(virtualName[2] == '\0')))
|
||||
continue;
|
||||
|
||||
files->push_back(std::string(directory) + virtualName);
|
||||
FileInfo info;
|
||||
info.name = std::string(directory) + virtualName;
|
||||
info.isDirectory = false; // TODO
|
||||
files->push_back(info);
|
||||
#ifdef _WIN32
|
||||
} while (FindNextFile(hFind, &ffd) != 0);
|
||||
FindClose(hFind);
|
||||
@@ -136,4 +136,4 @@ std::string getDir(const std::string &path)
|
||||
if (cutpath[i] == '\\') cutpath[i] = '/';
|
||||
}
|
||||
return cutpath;
|
||||
}
|
||||
}
|
||||
+8
-1
@@ -8,7 +8,14 @@ bool writeStringToFile(bool text_file, const std::string &str, const char *filen
|
||||
bool readFileToString(bool text_file, const char *filename, std::string &str);
|
||||
|
||||
// Beginnings of a directory utility system. TODO: Improve.
|
||||
size_t getFilesInDir(const char *directory, std::vector<std::string> *files);
|
||||
|
||||
struct FileInfo
|
||||
{
|
||||
std::string name;
|
||||
bool isDirectory;
|
||||
};
|
||||
|
||||
size_t getFilesInDir(const char *directory, std::vector<FileInfo> *files);
|
||||
void deleteFile(const char *file);
|
||||
|
||||
std::string getDir(const std::string &path);
|
||||
+1
-1
@@ -63,5 +63,5 @@ private:
|
||||
std::list<Screen *> dialog_;
|
||||
};
|
||||
|
||||
// Yeah, an old school non enforced singleton. Good enough.
|
||||
// Yeah, an old school non enforced singleton. Good enough (not?)
|
||||
extern ScreenManager screenManager;
|
||||
@@ -248,7 +248,7 @@ void StringVectorListAdapter::drawItem(int item, int x, int y, int w, int h, boo
|
||||
ui_draw2d.DrawTextShadow(theme.uiFont, (*items_)[item].c_str(), x + UI_SPACE , y, 0xFFFFFFFF, ALIGN_LEFT | ALIGN_VCENTER);
|
||||
}
|
||||
|
||||
int UIList(int id, int x, int y, int w, int h, UIListAdapter *adapter, UIListState *state) {
|
||||
int UIList::Do(int id, int x, int y, int w, int h, UIListAdapter *adapter) {
|
||||
const int item_h = 64;
|
||||
|
||||
int clicked = 0;
|
||||
@@ -262,12 +262,12 @@ int UIList(int id, int x, int y, int w, int h, UIListAdapter *adapter, UIListSta
|
||||
}
|
||||
|
||||
// If button is hot and active, but mouse button is not
|
||||
// down, the user must have clicked the button.
|
||||
// down, the user must have clicked a list item (unless after the last item).
|
||||
if (uistate.mousedown[i] == 0 &&
|
||||
uistate.hotitem[i] == id &&
|
||||
uistate.activeitem[i] == id &&
|
||||
state->selected != -1) {
|
||||
clicked = 1;
|
||||
uistate.hotitem[i] == id &&
|
||||
uistate.activeitem[i] == id &&
|
||||
selected != -1) {
|
||||
clicked = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,13 +275,15 @@ int UIList(int id, int x, int y, int w, int h, UIListAdapter *adapter, UIListSta
|
||||
int itemHeight = adapter->itemHeight(0);
|
||||
int numItems = adapter->getCount();
|
||||
for (int i = 0; i < numItems; i++) {
|
||||
int item_y = y + i * itemHeight - state->scrollY;
|
||||
if (uistate.mousedown && adapter->itemEnabled(i) && item_y >= y - itemHeight && item_y <= y + h &&
|
||||
UIRegionHit(i, x, item_y, w, h, 0)) {
|
||||
// ultra fast touch response
|
||||
state->selected = i;
|
||||
int item_y = y + i * itemHeight - scrollY;
|
||||
if (uistate.mousedown &&
|
||||
adapter->itemEnabled(i) &&
|
||||
item_y >= y - itemHeight &&
|
||||
item_y <= y + h &&
|
||||
UIRegionHit(i, x, item_y, w, h, 0)) {
|
||||
selected = i;
|
||||
}
|
||||
adapter->drawItem(i, x, item_y, w, itemHeight, i == state->selected);
|
||||
adapter->drawItem(i, x, item_y, w, itemHeight, i == selected);
|
||||
}
|
||||
uistate.lastwidget = id;
|
||||
|
||||
|
||||
@@ -162,18 +162,12 @@ public:
|
||||
|
||||
class StringVectorListAdapter : public UIListAdapter {
|
||||
public:
|
||||
StringVectorListAdapter(std::vector<std::string> *items) : items_(items) {}
|
||||
StringVectorListAdapter(const std::vector<std::string> *items) : items_(items) {}
|
||||
virtual size_t getCount() const { return items_->size(); }
|
||||
virtual void drawItem(int item, int x, int y, int w, int h, bool active) const;
|
||||
|
||||
private:
|
||||
std::vector<std::string> *items_;
|
||||
};
|
||||
|
||||
struct UIListState {
|
||||
UIListState() : scrollY(0.0f), selected(-1) {}
|
||||
float scrollY;
|
||||
int selected;
|
||||
const std::vector<std::string> *items_;
|
||||
};
|
||||
|
||||
|
||||
@@ -205,9 +199,20 @@ void UIText(int x, int y, const char *text, uint32_t color, float scale = 1.0f,
|
||||
// Slide choice, like the Angry Birds level selector. Not yet working.
|
||||
void UISlideChoice(int id, int y, const SlideItem *items, int numItems, UISlideState *state);
|
||||
|
||||
// List view.
|
||||
// return -1 = no selection
|
||||
int UIList(int id, int x, int y, int w, int h, UIListAdapter *adapter, UIListState *state);
|
||||
|
||||
class UIList {
|
||||
public:
|
||||
UIList() : scrollY(0.0f), startDragY(0.0f), dragFinger(-1), selected(-1) {}
|
||||
float scrollY;
|
||||
float startDragY;
|
||||
int dragFinger;
|
||||
int selected;
|
||||
// List view.
|
||||
// return -1 = no selection
|
||||
int Do(int id, int x, int y, int w, int h, UIListAdapter *adapter);
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(UIList);
|
||||
};
|
||||
|
||||
// Call at end of frame.
|
||||
// Do this afterwards (or similar):
|
||||
|
||||
Reference in new issue
Block a user