diff options
| author | Denton Woods <devil.imagelib@gmail.com> | 2009-02-14 00:33:41 +0000 |
|---|---|---|
| committer | Denton Woods <devil.imagelib@gmail.com> | 2009-02-14 00:33:41 +0000 |
| commit | 6febd3cc242f73e0578b554019123b5ec5d9f96b (patch) | |
| tree | 8c822cc2fcef96f69708075e48bd23b2568aac0e /DevIL/examples | |
| parent | 89ff3c5876d75b813d38ac1f08a049fca9342cee (diff) | |
| download | devil-6febd3cc242f73e0578b554019123b5ec5d9f96b.tar.gz | |
* WindowsTest.cpp: Added slideshows capabilities with Page Up and Page Down.
Diffstat (limited to 'DevIL/examples')
| -rw-r--r-- | DevIL/examples/windows_example/BatchConv.cpp | 168 | ||||
| -rw-r--r-- | DevIL/examples/windows_example/WindowsTest.cpp | 165 | ||||
| -rw-r--r-- | DevIL/examples/windows_example/windows_example-vc8.vcproj | 4 |
3 files changed, 225 insertions, 112 deletions
diff --git a/DevIL/examples/windows_example/BatchConv.cpp b/DevIL/examples/windows_example/BatchConv.cpp index a6343b7c..d2b72e19 100644 --- a/DevIL/examples/windows_example/BatchConv.cpp +++ b/DevIL/examples/windows_example/BatchConv.cpp @@ -10,14 +10,14 @@ using namespace std; TCHAR *ImageExtArray[] = { - "jpe", "jpg", "jpeg", - "bmp", - "ico", - "pbm", "pgm", "pnm", "ppm", - "png", - "bw", "rgb", "rgba", "sgi", - "tga", "tif", "tiff", - "pcx", + L"jpe", L"jpg", L"jpeg", + L"bmp", + L"ico", + L"pbm", L"pgm", L"pnm", L"ppm", + L"png", + L"bw", L"rgb", L"rgba", L"sgi", + L"tga", L"tif", L"tiff", + L"pcx", NULL }; @@ -28,87 +28,87 @@ char *GetExtension(const char *FileName); bool CheckExtension(char *Arg, char *Ext); -char *Ext; +TCHAR *Ext; string NewExt; int i, j; -void BatchConv(TCHAR *Directory, TCHAR *ExtList, TCHAR *ConvExt, bool Recurse) -{ - ILuint Id, OrigId; - ilGenImages(1, &Id); - OrigId = ilGetInteger(IL_CUR_IMAGE); - ilBindImage(Id); - if (ExtList == NULL) - ParseDirs(string(Directory), ImageExtArray, ConvExt, Recurse); - else { - /*char **List = ConvertExtList(ExtList); - ParseDirs(string(Directory), ConvertExtList(ExtList), ConvExt, Recurse); - DestroyExtList(List);*/ - } - ilDeleteImages(1, &Id); - ilBindImage(OrigId); - return; -} - - -void ParseDirs(const string &_Dir, TCHAR **ExtList, TCHAR *ConvExt, bool Recurse) -{ - HANDLE Search; - WIN32_FIND_DATA FindData; - - _chdir(_Dir.c_str()); - Search = FindFirstFile("*.*", &FindData); - - do { - if (!strcmp(FindData.cFileName, ".") || !strcmp(FindData.cFileName, "..")) - continue; - if (IsDir(&FindData) && Recurse) { - _chdir(FindData.cFileName); - string NewDir = _Dir + string("\\"); - NewDir += FindData.cFileName; - ParseDirs(NewDir, ExtList, ConvExt, Recurse); - _chdir(".."); - } - Ext = GetExtension(FindData.cFileName); - if (Ext == NULL) - continue; - if (!_stricmp(Ext, ConvExt)) // Already has that extension. - continue; - for (j = 0; ExtList[j] != NULL; j++) { - if (CheckExtension(FindData.cFileName, ExtList[j])) { - string NewName; - for (i = 0; i < Ext - FindData.cFileName; i++) { - NewName += FindData.cFileName[i]; - } - NewName += ConvExt; - if (!ilLoadImage(FindData.cFileName)) - break; - ilSaveImage((TCHAR*)NewName.c_str()); - break; - } - } - } while (FindNextFile(Search, &FindData)); - - FindClose(Search); - return; -} - - -// Is the file actually a directory? -bool IsDir(WIN32_FIND_DATA *_Data) -{ - if (_Data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - return true; - return false; -} +//void BatchConv(TCHAR *Directory, TCHAR *ExtList, TCHAR *ConvExt, bool Recurse) +//{ +// ILuint Id, OrigId; +// ilGenImages(1, &Id); +// OrigId = ilGetInteger(IL_CUR_IMAGE); +// ilBindImage(Id); +// if (ExtList == NULL) +// ParseDirs(string(Directory), ImageExtArray, ConvExt, Recurse); +// else { +// /*char **List = ConvertExtList(ExtList); +// ParseDirs(string(Directory), ConvertExtList(ExtList), ConvExt, Recurse); +// DestroyExtList(List);*/ +// } +// ilDeleteImages(1, &Id); +// ilBindImage(OrigId); +// return; +//} +// +// +//void ParseDirs(const string &_Dir, TCHAR **ExtList, TCHAR *ConvExt, bool Recurse) +//{ +// HANDLE Search; +// WIN32_FIND_DATA FindData; +// +// _chdir(_Dir.c_str()); +// Search = FindFirstFile("*.*", &FindData); +// +// do { +// if (!strcmp(FindData.cFileName, ".") || !strcmp(FindData.cFileName, "..")) +// continue; +// if (IsDir(&FindData) && Recurse) { +// _chdir(FindData.cFileName); +// string NewDir = _Dir + string("\\"); +// NewDir += FindData.cFileName; +// ParseDirs(NewDir, ExtList, ConvExt, Recurse); +// _chdir(".."); +// } +// Ext = GetExtension(FindData.cFileName); +// if (Ext == NULL) +// continue; +// if (!_stricmp(Ext, ConvExt)) // Already has that extension. +// continue; +// for (j = 0; ExtList[j] != NULL; j++) { +// if (CheckExtension(FindData.cFileName, ExtList[j])) { +// string NewName; +// for (i = 0; i < Ext - FindData.cFileName; i++) { +// NewName += FindData.cFileName[i]; +// } +// NewName += ConvExt; +// if (!ilLoadImage(FindData.cFileName)) +// break; +// ilSaveImage((TCHAR*)NewName.c_str()); +// break; +// } +// } +// } while (FindNextFile(Search, &FindData)); +// +// FindClose(Search); +// return; +//} +// +// +//// Is the file actually a directory? +//bool IsDir(WIN32_FIND_DATA *_Data) +//{ +// if (_Data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) +// return true; +// return false; +//} TCHAR *GetExtension(const TCHAR *FileName) { bool PeriodFound = false; TCHAR *Ext = (TCHAR*)FileName; - long i, Len = (long)strlen(FileName); + long i, Len = (long)wcslen(FileName); if (FileName == NULL || !Len) // if not a good filename/extension, exit early return NULL; @@ -134,16 +134,16 @@ TCHAR *GetExtension(const TCHAR *FileName) bool CheckExtension(TCHAR *Arg, TCHAR *Ext) { bool PeriodFound = false; - char *Argu = Arg; // pointer to arg so we don't destroy arg + TCHAR *Argu = Arg; // pointer to arg so we don't destroy arg unsigned int i; - if (Arg == NULL || Ext == NULL || !strlen(Arg) || !strlen(Ext)) // if not a good filename/extension, exit early + if (Arg == NULL || Ext == NULL || !wcslen(Arg) || !wcslen(Ext)) // if not a good filename/extension, exit early return false; - Argu += strlen(Arg); // start at the end + Argu += wcslen(Arg); // start at the end - for (i = (int)strlen(Arg); i >= 0; i--) { + for (i = (int)wcslen(Arg); i >= 0; i--) { if (*Argu == '.') { // try to find a period PeriodFound = true; break; @@ -154,7 +154,7 @@ bool CheckExtension(TCHAR *Arg, TCHAR *Ext) if (!PeriodFound) // if no period, no extension return false; - if (!_stricmp(Argu+1, Ext)) // extension and ext match? + if (!_wcsicmp(Argu+1, Ext)) // extension and ext match? return true; return false; // if all else fails, return IL_FALSE diff --git a/DevIL/examples/windows_example/WindowsTest.cpp b/DevIL/examples/windows_example/WindowsTest.cpp index 246a5671..c477658b 100644 --- a/DevIL/examples/windows_example/WindowsTest.cpp +++ b/DevIL/examples/windows_example/WindowsTest.cpp @@ -51,9 +51,9 @@ HBRUSH BackBrush; #define BORDER_W 16 //8 #define MENU_H 58 //54 -#define MIN_W 250 // Accomodate the menu bar. -#define MAX_W 400 -#define MAX_H 400 +#define MIN_W 450 // Accomodate the menu bar. +//#define MAX_W 400 +//#define MAX_H 400 #define TITLE L"DevIL Windows Test" ILuint NumUndosAllowed = 4, UndoSize = 0; ILuint Undos[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -69,9 +69,17 @@ ILuint FilterType; ILuint FilterParamInt; ILfloat FilterParamFloat; TCHAR FilterEditString[255]; - +TCHAR OpenFileName[2048]; +TCHAR SaveFileName[2048]; TCHAR NewTitle[512]; +TCHAR *ExtList[] = { + L"pix", L"cut", L"dcx", L"gif", L"mdl", L"lif", L"jpe", L"jpg", L"jpeg", L"lif", L"bmp", + L"ico", L"pbm", L"pgm", L"ppm", L"png", L"bw", L"rgb", L"rgba", L"sgi", L"tga", L"tif", + L"tiff", L"xpm", L"psp", L"psd", L"iwi", L"exr", L"blp", L"tpl", L"wdp", L"pcx", NULL +}; + + LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); INT_PTR APIENTRY AboutDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); INT_PTR APIENTRY PropertiesDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); @@ -83,8 +91,10 @@ void GenFilterString(TCHAR *Out, TCHAR **Strings); void ResizeWin(void); void CreateGDI(void); bool IsOpenable(TCHAR *FileName); -bool GetPrevImage(TCHAR *OpenFileName, TCHAR *ConvExt); -bool GetNextImage(TCHAR *OpenFileName, TCHAR *ConvExt); +bool GetPrevImage(void); +bool GetNextImage(void); +TCHAR *GetExtension(const TCHAR *FileName); +bool CheckExtension(TCHAR *Arg, TCHAR *Ext); //extern "C" //// Colour picker export @@ -101,6 +111,7 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, HACCEL hAccelTable; hInstance = hInst; + memset(OpenFileName, 0, 2048 * sizeof(TCHAR)); BackBrush = CreateSolidBrush(RGB(128,128,128)); @@ -248,9 +259,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) static PAINTSTRUCT ps; static HDROP hDrop; - static TCHAR OpenFileName[2048]; static TCHAR OpenFilter[2048]; - static TCHAR SaveFileName[2048]; static TCHAR SaveFilter[2048]; static TCHAR *OFilter[] = { L"All Files (*.*)", L"*.*", @@ -297,7 +306,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) L"ZSoft Pcx Files (*.pcx)", L"*.pcx", L"\0\0" }; - static OPENFILENAME Ofn = { sizeof(OPENFILENAME), hWnd, @@ -406,7 +414,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } if (wParam == VK_PRIOR) { - GetPrevImage(OpenFileName); + if (!GetPrevImage()) + break; DestroyGDI(); ilDeleteImages(UndoSize, Undos); @@ -418,8 +427,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ilBindImage(Undos[0]); //last_elapsed = SDL_GetTicks(); - if (!ilLoadImage(OpenFileName)) + if (!ilLoadImage(OpenFileName)) { + wsprintf(CurFileName, L"%s", OpenFileName); + wsprintf(NewTitle, L"%s - Could not open %s", TITLE, OpenFileName); + SetWindowText(hWnd, NewTitle); return (0L); + } CurImage = 0; //cur_elapsed = SDL_GetTicks(); elapsed = cur_elapsed - last_elapsed; @@ -432,11 +445,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) wsprintf(CurFileName, L"%s", OpenFileName); wsprintf(NewTitle, L"%s - %s: %u ms", TITLE, OpenFileName, (unsigned int)elapsed); SetWindowText(hWnd, NewTitle); - } if (wParam == VK_NEXT) { - GetNextImage(OpenFileName); + if (!GetNextImage()) + break; DestroyGDI(); ilDeleteImages(UndoSize, Undos); @@ -448,8 +461,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ilBindImage(Undos[0]); //last_elapsed = SDL_GetTicks(); - if (!ilLoadImage(OpenFileName)) + if (!ilLoadImage(OpenFileName)) { + wsprintf(CurFileName, L"%s", OpenFileName); + wsprintf(NewTitle, L"%s - Could not open %s", TITLE, OpenFileName); + SetWindowText(hWnd, NewTitle); return (0L); + } CurImage = 0; //cur_elapsed = SDL_GetTicks(); elapsed = cur_elapsed - last_elapsed; @@ -462,10 +479,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) wsprintf(CurFileName, L"%s", OpenFileName); wsprintf(NewTitle, L"%s - %s: %u ms", TITLE, OpenFileName, (unsigned int)elapsed); SetWindowText(hWnd, NewTitle); - } - InvalidateRect(hWnd, NULL, FALSE); break; @@ -1269,42 +1284,136 @@ INT_PTR APIENTRY BatchDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa } -bool GetPrevImage(TCHAR *OpenFileName, TCHAR *ConvExt) +bool GetPrevImage() { HANDLE Search; - WIN32_FIND_DATA FindData; - int Total = 0, FileNamePos; + WIN32_FIND_DATA FindData; + int i = 0, j, Total = 0, FileNamePos = -1; + TCHAR *Ext, *CurName; Search = FindFirstFile(L"*.*", &FindData); + CurName = wcsrchr(CurFileName, '\\'); + if (CurName == NULL) { + CurName = CurFileName; + } + else { + CurName++; // Skip the '\' + } do { - if (!_wcsicmp(FindData.cFileName, L".") || !strcmp(FindData.cFileName, L"..")) + if (!_wcsicmp(FindData.cFileName, L".") || !_wcsicmp(FindData.cFileName, L"..")) continue; Ext = GetExtension(FindData.cFileName); if (Ext == NULL) continue; - if (!_wcsicmp(Ext, ConvExt)) // Already has that extension. - continue; for (j = 0; ExtList[j] != NULL; j++) { - if (CheckExtension(FindData.cFileName, ExtList[j])) { - if (FindData.cFileName + if (!_wcsicmp(FindData.cFileName, CurName)) + FileNamePos = Total; + Total++; break; } } } while (FindNextFile(Search, &FindData)); FindClose(Search); - return; + Search = FindFirstFile(L"*.*", &FindData); - return TRUE; + if (Total == 0 || FileNamePos == -1) + return false; + + if (FileNamePos == 0) + FileNamePos = Total; + + do { + if (!_wcsicmp(FindData.cFileName, L".") || !_wcsicmp(FindData.cFileName, L"..")) + continue; + Ext = GetExtension(FindData.cFileName); + if (Ext == NULL) + continue; + for (j = 0; ExtList[j] != NULL; j++) { + if (CheckExtension(FindData.cFileName, ExtList[j])) { + if (FileNamePos == i+1) { + wcscpy(OpenFileName, FindData.cFileName); + i++; + break; + } + i++; + break; + } + } + } while (FindNextFile(Search, &FindData)); + + + FindClose(Search); + return true; } -bool GetNextImage(TCHAR *OpenFileName, TCHAR *ConvExt) +bool GetNextImage() { + HANDLE Search; + WIN32_FIND_DATA FindData; + int i = 0, j, Total = 0, FileNamePos = -1; + TCHAR *Ext, *CurName; + Search = FindFirstFile(L"*.*", &FindData); + CurName = wcsrchr(CurFileName, '\\'); + if (CurName == NULL) { + CurName = CurFileName; + } + else { + CurName++; // Skip the '\' + } + + do { + if (!_wcsicmp(FindData.cFileName, L".") || !_wcsicmp(FindData.cFileName, L"..")) + continue; + Ext = GetExtension(FindData.cFileName); + if (Ext == NULL) + continue; + for (j = 0; ExtList[j] != NULL; j++) { + if (CheckExtension(FindData.cFileName, ExtList[j])) { + if (!_wcsicmp(FindData.cFileName, CurName)) + FileNamePos = Total; + Total++; + break; + } + } + } while (FindNextFile(Search, &FindData)); + + FindClose(Search); + Search = FindFirstFile(L"*.*", &FindData); + + if (Total == 0 || FileNamePos == -1) + return false; - return TRUE; + if (FileNamePos == Total-1) + FileNamePos = -1; + + do { + if (!_wcsicmp(FindData.cFileName, L".") || !_wcsicmp(FindData.cFileName, L"..")) + continue; + Ext = GetExtension(FindData.cFileName); + if (Ext == NULL) + continue; + for (j = 0; ExtList[j] != NULL; j++) { + if (CheckExtension(FindData.cFileName, ExtList[j])) { + if (FileNamePos == i-1) { + wcscpy(OpenFileName, FindData.cFileName); + i++; + break; + } + i++; + break; + } + } + } while (FindNextFile(Search, &FindData)); + + + FindClose(Search); + return true; } + + diff --git a/DevIL/examples/windows_example/windows_example-vc8.vcproj b/DevIL/examples/windows_example/windows_example-vc8.vcproj index cd35ac87..bbc2d069 100644 --- a/DevIL/examples/windows_example/windows_example-vc8.vcproj +++ b/DevIL/examples/windows_example/windows_example-vc8.vcproj @@ -305,6 +305,10 @@ Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
+ RelativePath=".\BatchConv.cpp"
+ >
+ </File>
+ <File
RelativePath="WindowsTest.cpp"
>
<FileConfiguration
|
