mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
less global var usage in Screens.c
This commit is contained in:
parent
05e98ad064
commit
eac64212ff
@ -404,9 +404,6 @@
|
||||
<ClCompile Include="Vectors.c">
|
||||
<Filter>Source Files\Math</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Texture.c">
|
||||
<Filter>Source Files\Graphics</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GraphicsCommon.c">
|
||||
<Filter>Source Files\Graphics</Filter>
|
||||
</ClCompile>
|
||||
@ -596,5 +593,8 @@
|
||||
<ClCompile Include="Searcher.c">
|
||||
<Filter>Source Files\Math</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Texture.c">
|
||||
<Filter>Source Files\Graphics</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -27,6 +27,8 @@ DateTime Platform_CurrentLocalTime(void);
|
||||
bool Platform_DirectoryExists(STRING_PURE String* path);
|
||||
ReturnCode Platform_DirectoryCreate(STRING_PURE String* path);
|
||||
bool Platform_FileExists(STRING_PURE String* path);
|
||||
typedef void Platform_EnumFilesCallback(STRING_PURE String* path, void* obj);
|
||||
ReturnCode Platform_EnumFiles(STRING_PURE String* path, void* obj, Platform_EnumFilesCallback callback);
|
||||
|
||||
ReturnCode Platform_FileCreate(void** file, STRING_PURE String* path);
|
||||
ReturnCode Platform_FileOpen(void** file, STRING_PURE String* path, bool readOnly);
|
||||
|
@ -511,8 +511,7 @@ typedef struct FilesScreen_ {
|
||||
} FilesScreen;
|
||||
FilesScreen FilesScreen_Instance;
|
||||
|
||||
String FilesScreen_Get(UInt32 index) {
|
||||
FilesScreen* screen = &FilesScreen_Instance;
|
||||
String FilesScreen_Get(FilesScreen* screen, UInt32 index) {
|
||||
if (index < screen->Entries.Count) {
|
||||
return StringsBuffer_UNSAFE_Get(&screen->Entries, index);
|
||||
} else {
|
||||
@ -520,52 +519,51 @@ String FilesScreen_Get(UInt32 index) {
|
||||
}
|
||||
}
|
||||
|
||||
void FilesScreen_MakeText(ButtonWidget* widget, Int32 x, Int32 y, String* text) {
|
||||
FilesScreen* screen = &FilesScreen_Instance;
|
||||
void FilesScreen_MakeText(FilesScreen* screen, Int32 idx, Int32 x, Int32 y, String* text) {
|
||||
ButtonWidget* widget = &screen->Buttons[idx];
|
||||
ButtonWidget_Create(widget, text, 300, &screen->Font, screen->TextButtonClick);
|
||||
Widget_SetLocation(&widget->Base, ANCHOR_CENTRE, ANCHOR_CENTRE, x, y);
|
||||
}
|
||||
|
||||
void FilesScreen_Make(ButtonWidget* widget, Int32 x, Int32 y, String* text, Gui_MouseHandler onClick) {
|
||||
FilesScreen* screen = &FilesScreen_Instance;
|
||||
void FilesScreen_Make(FilesScreen* screen, Int32 idx, Int32 x, Int32 y, String* text, Gui_MouseHandler onClick) {
|
||||
ButtonWidget* widget = &screen->Buttons[idx];
|
||||
ButtonWidget_Create(widget, text, 40, &screen->Font, onClick);
|
||||
Widget_SetLocation(&widget->Base, ANCHOR_CENTRE, ANCHOR_CENTRE, x, y);
|
||||
}
|
||||
|
||||
void FilesScreen_UpdateArrows(void) {
|
||||
FilesScreen* screen = &FilesScreen_Instance;
|
||||
void FilesScreen_UpdateArrows(FilesScreen* screen) {
|
||||
Int32 start = FILES_SCREEN_ITEMS, end = screen->Entries.Count - FILES_SCREEN_ITEMS;
|
||||
screen->Buttons[5].Base.Disabled = screen->CurrentIndex < start;
|
||||
screen->Buttons[6].Base.Disabled = screen->CurrentIndex >= end;
|
||||
}
|
||||
|
||||
void FilesScreen_SetCurrentIndex(Int32 index) {
|
||||
FilesScreen* screen = &FilesScreen_Instance;
|
||||
void FilesScreen_SetCurrentIndex(FilesScreen* screen, Int32 index) {
|
||||
if (index >= screen->Entries.Count) index -= FILES_SCREEN_ITEMS;
|
||||
if (index < 0) index = 0;
|
||||
|
||||
UInt32 i;
|
||||
for (i = 0; i < FILES_SCREEN_ITEMS; i++) {
|
||||
String str = FilesScreen_Get(index + i);
|
||||
String str = FilesScreen_Get(screen, index + i);
|
||||
ButtonWidget_SetText(&screen->Buttons[i], &str);
|
||||
}
|
||||
|
||||
screen->CurrentIndex = index;
|
||||
FilesScreen_UpdateArrows();
|
||||
FilesScreen_UpdateArrows(screen);
|
||||
}
|
||||
|
||||
void FilesScreen_PageClick(bool forward) {
|
||||
FilesScreen* screen = &FilesScreen_Instance;
|
||||
void FilesScreen_PageClick(FilesScreen* screen, bool forward) {
|
||||
Int32 delta = forward ? FILES_SCREEN_ITEMS : -FILES_SCREEN_ITEMS;
|
||||
FilesScreen_SetCurrentIndex(screen->CurrentIndex + delta);
|
||||
FilesScreen_SetCurrentIndex(screen, screen->CurrentIndex + delta);
|
||||
}
|
||||
|
||||
bool FilesScreen_MoveBackwards(GuiElement* elem, Int32 x, Int32 y, MouseButton btn) {
|
||||
LeftOnly(FilesScreen_PageClick(false));
|
||||
FilesScreen* screen = (FilesScreen*)elem;
|
||||
LeftOnly(FilesScreen_PageClick(screen, false));
|
||||
}
|
||||
|
||||
bool FilesScreen_MoveForwards(GuiElement* elem, Int32 x, Int32 y, MouseButton btn) {
|
||||
LeftOnly(FilesScreen_PageClick(true));
|
||||
FilesScreen* screen = (FilesScreen*)elem;
|
||||
LeftOnly(FilesScreen_PageClick(screen, true));
|
||||
}
|
||||
|
||||
void FilesScreen_ContextLost(void* obj) {
|
||||
@ -580,14 +578,14 @@ void FilesScreen_ContextRecreated(void* obj) {
|
||||
|
||||
UInt32 i;
|
||||
for (i = 0; i < FILES_SCREEN_ITEMS; i++) {
|
||||
String str = FilesScreen_Get(i);
|
||||
FilesScreen_MakeText(&screen->Buttons[i], 0, 50 * (Int32)i - 100, &str);
|
||||
String str = FilesScreen_Get(screen, i);
|
||||
FilesScreen_MakeText(screen, i, 0, 50 * (Int32)i - 100, &str);
|
||||
}
|
||||
|
||||
String lArrow = String_FromConst("<");
|
||||
FilesScreen_Make(&screen->Buttons[5], -220, 0, &lArrow, FilesScreen_MoveBackwards);
|
||||
FilesScreen_Make(screen, 5, -220, 0, &lArrow, FilesScreen_MoveBackwards);
|
||||
String rArrow = String_FromConst(">");
|
||||
FilesScreen_Make(&screen->Buttons[6], 220, 0, &rArrow, FilesScreen_MoveForwards);
|
||||
FilesScreen_Make(screen, 6, 220, 0, &rArrow, FilesScreen_MoveForwards);
|
||||
Screen_MakeDefaultBack(&screen->Buttons[7], false, &screen->Font, Screen_SwitchPause);
|
||||
|
||||
screen->Widgets[0] = &screen->Title.Base;
|
||||
@ -595,7 +593,7 @@ void FilesScreen_ContextRecreated(void* obj) {
|
||||
screen->Widgets[i + 1] = &screen->Buttons[i].Base;
|
||||
}
|
||||
ClickableScreen_Init(&screen->Clickable, &screen->Base.Base, screen->Widgets, Array_NumElements(screen->Widgets));
|
||||
FilesScreen_UpdateArrows();
|
||||
FilesScreen_UpdateArrows(screen);
|
||||
}
|
||||
|
||||
void FilesScreen_Init(GuiElement* elem) {
|
||||
@ -627,9 +625,9 @@ bool FilesScreen_HandlesKeyDown(GuiElement* elem, Key key) {
|
||||
if (key == Key_Escape) {
|
||||
Gui_SetNewScreen(NULL);
|
||||
} else if (key == Key_Left) {
|
||||
FilesScreen_PageClick(false);
|
||||
FilesScreen_PageClick(screen, false);
|
||||
} else if (key == Key_Right) {
|
||||
FilesScreen_PageClick(true);
|
||||
FilesScreen_PageClick(screen, true);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -125,6 +125,30 @@ ReturnCode Platform_DirectoryCreate(STRING_PURE String* path) {
|
||||
return success ? 0 : GetLastError();
|
||||
}
|
||||
|
||||
ReturnCode Platform_EnumFiles(STRING_PURE String* path, void* obj, Platform_EnumFilesCallback callback) {
|
||||
/* Need to do directory\* to search for files in directory */
|
||||
UInt8 searchPatternBuffer[FILENAME_SIZE + 10];
|
||||
String searchPattern = String_InitAndClearArray(searchPatternBuffer);
|
||||
String_AppendString(&searchPattern, path);
|
||||
String_AppendConst(&searchPattern, "\\*");
|
||||
|
||||
WIN32_FIND_DATAA data;
|
||||
HANDLE find = FindFirstFileA(searchPattern.buffer, &data);
|
||||
if (find == INVALID_HANDLE_VALUE) return GetLastError();
|
||||
|
||||
do {
|
||||
String filePath = String_FromRawArray(data.cFileName);
|
||||
if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||
callback(&filePath, obj);
|
||||
}
|
||||
} while (FindNextFileA(find, &data));
|
||||
|
||||
/* get return code from FindNextFile before closing find handle */
|
||||
ReturnCode code = GetLastError();
|
||||
FindClose(find);
|
||||
return code == ERROR_NO_MORE_FILES ? 0 : code;
|
||||
}
|
||||
|
||||
|
||||
ReturnCode Platform_FileOpen(void** file, STRING_PURE String* path, bool readOnly) {
|
||||
UINT32 access = GENERIC_READ;
|
||||
|
Loading…
x
Reference in New Issue
Block a user