add tinyfiledialogs
This commit is contained in:
parent
6cb5c745b7
commit
a7e778640f
314
lab16 with raylib/include/tinyfiledialogs.h
Normal file
314
lab16 with raylib/include/tinyfiledialogs.h
Normal file
@ -0,0 +1,314 @@
|
|||||||
|
/* SPDX-License-Identifier: Zlib
|
||||||
|
Copyright (c) 2014 - 2024 Guillaume Vareille http://ysengrin.com
|
||||||
|
____________________________________________________________________
|
||||||
|
| |
|
||||||
|
| 100% compatible C C++ -> You can rename tinfiledialogs.c as .cpp |
|
||||||
|
|____________________________________________________________________|
|
||||||
|
|
||||||
|
********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE *********
|
||||||
|
_________
|
||||||
|
/ \ tinyfiledialogs.h v3.18.2 [Jun 8, 2024]
|
||||||
|
|tiny file| Unique header file created [November 9, 2014]
|
||||||
|
| dialogs |
|
||||||
|
\____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
____________________________________________
|
||||||
|
| |
|
||||||
|
| email: tinyfiledialogs at ysengrin.com |
|
||||||
|
|____________________________________________|
|
||||||
|
________________________________________________________________________________
|
||||||
|
| ____________________________________________________________________________ |
|
||||||
|
| | | |
|
||||||
|
| | - in tinyfiledialogs, char is UTF-8 by default (since v3.6) | |
|
||||||
|
| | | |
|
||||||
|
| | on windows: | |
|
||||||
|
| | - for UTF-16, use the wchar_t functions at the bottom of the header file | |
|
||||||
|
| | | |
|
||||||
|
| | - _wfopen() requires wchar_t | |
|
||||||
|
| | - fopen() uses char but expects ASCII or MBCS (not UTF-8) | |
|
||||||
|
| | - if you want char to be MBCS: set tinyfd_winUtf8 to 0 | |
|
||||||
|
| | | |
|
||||||
|
| | - alternatively, tinyfiledialogs provides | |
|
||||||
|
| | functions to convert between UTF-8, UTF-16 and MBCS | |
|
||||||
|
| |____________________________________________________________________________| |
|
||||||
|
|________________________________________________________________________________|
|
||||||
|
|
||||||
|
If you like tinyfiledialogs, please upvote my stackoverflow answer
|
||||||
|
https://stackoverflow.com/a/47651444
|
||||||
|
|
||||||
|
- License -
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
__________________________________________
|
||||||
|
| ______________________________________ |
|
||||||
|
| | | |
|
||||||
|
| | DO NOT USE USER INPUT IN THE DIALOGS | |
|
||||||
|
| |______________________________________| |
|
||||||
|
|__________________________________________|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TINYFILEDIALOGS_H
|
||||||
|
#define TINYFILEDIALOGS_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************************************/
|
||||||
|
/**************************************** UTF-8 on Windows ********************************************/
|
||||||
|
/******************************************************************************************************/
|
||||||
|
#ifdef _WIN32
|
||||||
|
/* On windows, if you want to use UTF-8 ( instead of the UTF-16/wchar_t functions at the end of this file )
|
||||||
|
Make sure your code is really prepared for UTF-8 (on windows, functions like fopen() expect MBCS and not UTF-8) */
|
||||||
|
extern int tinyfd_winUtf8; /* on windows char strings can be 1:UTF-8(default) or 0:MBCS */
|
||||||
|
/* for MBCS change this to 0, in tinyfiledialogs.c or in your code */
|
||||||
|
|
||||||
|
/* Here are some functions to help you convert between UTF-16 UTF-8 MBSC */
|
||||||
|
char * tinyfd_utf8toMbcs(char const * aUtf8string);
|
||||||
|
char * tinyfd_utf16toMbcs(wchar_t const * aUtf16string);
|
||||||
|
wchar_t * tinyfd_mbcsTo16(char const * aMbcsString);
|
||||||
|
char * tinyfd_mbcsTo8(char const * aMbcsString);
|
||||||
|
wchar_t * tinyfd_utf8to16(char const * aUtf8string);
|
||||||
|
char * tinyfd_utf16to8(wchar_t const * aUtf16string);
|
||||||
|
#endif
|
||||||
|
/******************************************************************************************************/
|
||||||
|
/******************************************************************************************************/
|
||||||
|
/******************************************************************************************************/
|
||||||
|
|
||||||
|
/************* 3 funtions for C# (you don't need this in C or C++) : */
|
||||||
|
char const * tinyfd_getGlobalChar(char const * aCharVariableName); /* returns NULL on error */
|
||||||
|
int tinyfd_getGlobalInt(char const * aIntVariableName); /* returns -1 on error */
|
||||||
|
int tinyfd_setGlobalInt(char const * aIntVariableName, int aValue); /* returns -1 on error */
|
||||||
|
/* aCharVariableName: "tinyfd_version" "tinyfd_needs" "tinyfd_response"
|
||||||
|
aIntVariableName : "tinyfd_verbose" "tinyfd_silent" "tinyfd_allowCursesDialogs"
|
||||||
|
"tinyfd_forceConsole" "tinyfd_assumeGraphicDisplay" "tinyfd_winUtf8"
|
||||||
|
**************/
|
||||||
|
|
||||||
|
extern char tinyfd_version[8]; /* contains tinyfd current version number */
|
||||||
|
extern char tinyfd_needs[]; /* info about requirements */
|
||||||
|
extern int tinyfd_verbose; /* 0 (default) or 1 : on unix, prints the command line calls */
|
||||||
|
extern int tinyfd_silent; /* 1 (default) or 0 : on unix, hide errors and warnings from called dialogs */
|
||||||
|
|
||||||
|
/** Curses dialogs are difficult to use and counter-intuitive.
|
||||||
|
On windows they are only ascii and still uses the unix backslash ! **/
|
||||||
|
extern int tinyfd_allowCursesDialogs; /* 0 (default) or 1 */
|
||||||
|
|
||||||
|
extern int tinyfd_forceConsole; /* 0 (default) or 1 */
|
||||||
|
/* for unix & windows: 0 (graphic mode) or 1 (console mode).
|
||||||
|
0: try to use a graphic solution, if it fails then it uses console mode.
|
||||||
|
1: forces all dialogs into console mode even when an X server is present.
|
||||||
|
if enabled, it can use the package Dialog or dialog.exe.
|
||||||
|
on windows it only make sense for console applications */
|
||||||
|
|
||||||
|
extern int tinyfd_assumeGraphicDisplay; /* 0 (default) or 1 */
|
||||||
|
/* some systems don't set the environment variable DISPLAY even when a graphic display is present.
|
||||||
|
set this to 1 to tell tinyfiledialogs to assume the existence of a graphic display */
|
||||||
|
|
||||||
|
extern char tinyfd_response[1024];
|
||||||
|
/* if you pass "tinyfd_query" as aTitle,
|
||||||
|
the functions will not display the dialogs
|
||||||
|
but will return 0 for console mode, 1 for graphic mode.
|
||||||
|
tinyfd_response is then filled with the retain solution.
|
||||||
|
possible values for tinyfd_response are (all lowercase)
|
||||||
|
for graphic mode:
|
||||||
|
windows_wchar windows applescript kdialog zenity zenity3 yad matedialog
|
||||||
|
shellementary qarma python2-tkinter python3-tkinter python-dbus
|
||||||
|
perl-dbus gxmessage gmessage xmessage xdialog gdialog dunst
|
||||||
|
for console mode:
|
||||||
|
dialog whiptail basicinput no_solution */
|
||||||
|
|
||||||
|
void tinyfd_beep(void);
|
||||||
|
|
||||||
|
int tinyfd_notifyPopup(
|
||||||
|
char const * aTitle, /* NULL or "" */
|
||||||
|
char const * aMessage, /* NULL or "" may contain \n \t */
|
||||||
|
char const * aIconType); /* "info" "warning" "error" */
|
||||||
|
/* return has only meaning for tinyfd_query */
|
||||||
|
|
||||||
|
int tinyfd_messageBox(
|
||||||
|
char const * aTitle , /* NULL or "" */
|
||||||
|
char const * aMessage , /* NULL or "" may contain \n \t */
|
||||||
|
char const * aDialogType , /* "ok" "okcancel" "yesno" "yesnocancel" */
|
||||||
|
char const * aIconType , /* "info" "warning" "error" "question" */
|
||||||
|
int aDefaultButton ) ;
|
||||||
|
/* 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel */
|
||||||
|
|
||||||
|
char * tinyfd_inputBox(
|
||||||
|
char const * aTitle , /* NULL or "" */
|
||||||
|
char const * aMessage , /* NULL or "" (\n and \t have no effect) */
|
||||||
|
char const * aDefaultInput ) ; /* NULL = passwordBox, "" = inputbox */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
char * tinyfd_saveFileDialog(
|
||||||
|
char const * aTitle , /* NULL or "" */
|
||||||
|
char const * aDefaultPathAndOrFile , /* NULL or "" , ends with / to set only a directory */
|
||||||
|
int aNumOfFilterPatterns , /* 0 (1 in the following example) */
|
||||||
|
char const * const * aFilterPatterns , /* NULL or char const * lFilterPatterns[1]={"*.txt"} */
|
||||||
|
char const * aSingleFilterDescription ) ; /* NULL or "text files" */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
char * tinyfd_openFileDialog(
|
||||||
|
char const * aTitle, /* NULL or "" */
|
||||||
|
char const * aDefaultPathAndOrFile, /* NULL or "" , ends with / to set only a directory */
|
||||||
|
int aNumOfFilterPatterns , /* 0 (2 in the following example) */
|
||||||
|
char const * const * aFilterPatterns, /* NULL or char const * lFilterPatterns[2]={"*.png","*.jpg"}; */
|
||||||
|
char const * aSingleFilterDescription, /* NULL or "image files" */
|
||||||
|
int aAllowMultipleSelects ) ; /* 0 or 1 */
|
||||||
|
/* in case of multiple files, the separator is | */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
char * tinyfd_selectFolderDialog(
|
||||||
|
char const * aTitle, /* NULL or "" */
|
||||||
|
char const * aDefaultPath); /* NULL or "" */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
char * tinyfd_colorChooser(
|
||||||
|
char const * aTitle, /* NULL or "" */
|
||||||
|
char const * aDefaultHexRGB, /* NULL or "" or "#FF0000" */
|
||||||
|
unsigned char const aDefaultRGB[3] , /* unsigned char lDefaultRGB[3] = { 0 , 128 , 255 }; */
|
||||||
|
unsigned char aoResultRGB[3] ) ; /* unsigned char lResultRGB[3]; */
|
||||||
|
/* aDefaultRGB is used only if aDefaultHexRGB is absent */
|
||||||
|
/* aDefaultRGB and aoResultRGB can be the same array */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
/* returns the hexcolor as a string "#FF0000" */
|
||||||
|
/* aoResultRGB also contains the result */
|
||||||
|
|
||||||
|
|
||||||
|
/************ WINDOWS ONLY SECTION ************************/
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
int tinyfd_notifyPopupW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aMessage, /* NULL or L"" may contain \n \t */
|
||||||
|
wchar_t const * aIconType); /* L"info" L"warning" L"error" */
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
int tinyfd_messageBoxW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aMessage, /* NULL or L"" may contain \n \t */
|
||||||
|
wchar_t const * aDialogType, /* L"ok" L"okcancel" L"yesno" */
|
||||||
|
wchar_t const * aIconType, /* L"info" L"warning" L"error" L"question" */
|
||||||
|
int aDefaultButton ); /* 0 for cancel/no , 1 for ok/yes */
|
||||||
|
/* returns 0 for cancel/no , 1 for ok/yes */
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
wchar_t * tinyfd_inputBoxW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aMessage, /* NULL or L"" (\n nor \t not respected) */
|
||||||
|
wchar_t const * aDefaultInput); /* NULL passwordBox, L"" inputbox */
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
wchar_t * tinyfd_saveFileDialogW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aDefaultPathAndOrFile, /* NULL or L"" , ends with / to set only a directory */
|
||||||
|
int aNumOfFilterPatterns, /* 0 (1 in the following example) */
|
||||||
|
wchar_t const * const * aFilterPatterns, /* NULL or wchar_t const * lFilterPatterns[1]={L"*.txt"} */
|
||||||
|
wchar_t const * aSingleFilterDescription); /* NULL or L"text files" */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
wchar_t * tinyfd_openFileDialogW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aDefaultPathAndOrFile, /* NULL or L"" , ends with / to set only a directory */
|
||||||
|
int aNumOfFilterPatterns , /* 0 (2 in the following example) */
|
||||||
|
wchar_t const * const * aFilterPatterns, /* NULL or wchar_t const * lFilterPatterns[2]={L"*.png","*.jpg"} */
|
||||||
|
wchar_t const * aSingleFilterDescription, /* NULL or L"image files" */
|
||||||
|
int aAllowMultipleSelects ) ; /* 0 or 1 */
|
||||||
|
/* in case of multiple files, the separator is | */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
wchar_t * tinyfd_selectFolderDialogW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aDefaultPath); /* NULL or L"" */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
wchar_t * tinyfd_colorChooserW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aDefaultHexRGB, /* NULL or L"#FF0000" */
|
||||||
|
unsigned char const aDefaultRGB[3], /* unsigned char lDefaultRGB[3] = { 0 , 128 , 255 }; */
|
||||||
|
unsigned char aoResultRGB[3]); /* unsigned char lResultRGB[3]; */
|
||||||
|
/* returns the hexcolor as a string L"#FF0000" */
|
||||||
|
/* aoResultRGB also contains the result */
|
||||||
|
/* aDefaultRGB is used only if aDefaultHexRGB is NULL */
|
||||||
|
/* aDefaultRGB and aoResultRGB can be the same array */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
#endif /*_WIN32 */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /*extern "C"*/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* TINYFILEDIALOGS_H */
|
||||||
|
|
||||||
|
/*
|
||||||
|
________________________________________________________________________________
|
||||||
|
| ____________________________________________________________________________ |
|
||||||
|
| | | |
|
||||||
|
| | on windows: | |
|
||||||
|
| | - for UTF-16, use the wchar_t functions at the bottom of the header file | |
|
||||||
|
| | - _wfopen() requires wchar_t | |
|
||||||
|
| | | |
|
||||||
|
| | - in tinyfiledialogs, char is UTF-8 by default (since v3.6) | |
|
||||||
|
| | - but fopen() expects MBCS (not UTF-8) | |
|
||||||
|
| | - if you want char to be MBCS: set tinyfd_winUtf8 to 0 | |
|
||||||
|
| | | |
|
||||||
|
| | - alternatively, tinyfiledialogs provides | |
|
||||||
|
| | functions to convert between UTF-8, UTF-16 and MBCS | |
|
||||||
|
| |____________________________________________________________________________| |
|
||||||
|
|________________________________________________________________________________|
|
||||||
|
|
||||||
|
- This is not for ios nor android (it works in termux though).
|
||||||
|
- The files can be renamed with extension ".cpp" as the code is 100% compatible C C++
|
||||||
|
(just comment out << extern "C" >> in the header file)
|
||||||
|
- Windows is fully supported from XP to 10 (maybe even older versions)
|
||||||
|
- C# & LUA via dll, see files in the folder EXTRAS
|
||||||
|
- OSX supported from 10.4 to latest (maybe even older versions)
|
||||||
|
- Do not use " and ' as the dialogs will be displayed with a warning
|
||||||
|
instead of the title, message, etc...
|
||||||
|
- There's one file filter only, it may contain several patterns.
|
||||||
|
- If no filter description is provided,
|
||||||
|
the list of patterns will become the description.
|
||||||
|
- On windows link against Comdlg32.lib and Ole32.lib
|
||||||
|
(on windows the no linking claim is a lie)
|
||||||
|
- On unix: it tries command line calls, so no such need (NO LINKING).
|
||||||
|
- On unix you need one of the following:
|
||||||
|
applescript, kdialog, zenity, matedialog, shellementary, qarma, yad,
|
||||||
|
python (2 or 3)/tkinter/python-dbus (optional), Xdialog
|
||||||
|
or curses dialogs (opens terminal if running without console).
|
||||||
|
- One of those is already included on most (if not all) desktops.
|
||||||
|
- In the absence of those it will use gdialog, gxmessage or whiptail
|
||||||
|
with a textinputbox. If nothing is found, it switches to basic console input,
|
||||||
|
it opens a console if needed (requires xterm + bash).
|
||||||
|
- for curses dialogs you must set tinyfd_allowCursesDialogs=1
|
||||||
|
- You can query the type of dialog that will be used (pass "tinyfd_query" as aTitle)
|
||||||
|
- String memory is preallocated statically for all the returned values.
|
||||||
|
- File and path names are tested before return, they should be valid.
|
||||||
|
- tinyfd_forceConsole=1; at run time, forces dialogs into console mode.
|
||||||
|
- On windows, console mode only make sense for console applications.
|
||||||
|
- On windows, console mode is not implemented for wchar_T UTF-16.
|
||||||
|
- Mutiple selects are not possible in console mode.
|
||||||
|
- The package dialog must be installed to run in curses dialogs in console mode.
|
||||||
|
It is already installed on most unix systems.
|
||||||
|
- On osx, the package dialog can be installed via
|
||||||
|
http://macappstore.org/dialog or http://macports.org
|
||||||
|
- On windows, for curses dialogs console mode,
|
||||||
|
dialog.exe should be copied somewhere on your executable path.
|
||||||
|
It can be found at the bottom of the following page:
|
||||||
|
http://andrear.altervista.org/home/cdialog.php
|
||||||
|
*/
|
@ -140,11 +140,13 @@
|
|||||||
<ClInclude Include="..\include\raylib.h" />
|
<ClInclude Include="..\include\raylib.h" />
|
||||||
<ClInclude Include="..\include\raymath.h" />
|
<ClInclude Include="..\include\raymath.h" />
|
||||||
<ClInclude Include="..\include\resource_dir.h" />
|
<ClInclude Include="..\include\resource_dir.h" />
|
||||||
|
<ClInclude Include="..\include\tinyfiledialogs.h" />
|
||||||
<ClInclude Include="..\include\windows_functions.h" />
|
<ClInclude Include="..\include\windows_functions.h" />
|
||||||
<ClInclude Include="resource.h" />
|
<ClInclude Include="resource.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\src\main.c" />
|
<ClCompile Include="..\src\main.c" />
|
||||||
|
<ClCompile Include="..\src\tinyfiledialogs.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="lab16 with raylib.rc" />
|
<ResourceCompile Include="lab16 with raylib.rc" />
|
||||||
|
@ -39,11 +39,17 @@
|
|||||||
<ClInclude Include="..\include\nuklear.h">
|
<ClInclude Include="..\include\nuklear.h">
|
||||||
<Filter>Файлы заголовков</Filter>
|
<Filter>Файлы заголовков</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\include\tinyfiledialogs.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\src\main.c">
|
<ClCompile Include="..\src\main.c">
|
||||||
<Filter>Исходные файлы</Filter>
|
<Filter>Исходные файлы</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\tinyfiledialogs.c">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="lab16 with raylib.rc">
|
<ResourceCompile Include="lab16 with raylib.rc">
|
||||||
|
BIN
lab16 with raylib/resources/consola.ttf
Normal file
BIN
lab16 with raylib/resources/consola.ttf
Normal file
Binary file not shown.
BIN
lab16 with raylib/resources/consolab.ttf
Normal file
BIN
lab16 with raylib/resources/consolab.ttf
Normal file
Binary file not shown.
672
lab16 with raylib/src/main with enemy.c
Normal file
672
lab16 with raylib/src/main with enemy.c
Normal file
@ -0,0 +1,672 @@
|
|||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <iso646.h>
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "raymath.h"
|
||||||
|
#include "resource_dir.h"
|
||||||
|
#include "windows_functions.h"
|
||||||
|
|
||||||
|
#define RAYGUI_IMPLEMENTATION
|
||||||
|
//#define RAYGUI_PANEL_BORDER_WIDTH 2
|
||||||
|
#define RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT 32
|
||||||
|
#define RAYGUI_MESSAGEBOX_BUTTON_HEIGHT 36
|
||||||
|
#include "raygui.h"
|
||||||
|
|
||||||
|
#define RAYLIB_NUKLEAR_IMPLEMENTATION
|
||||||
|
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
||||||
|
#pragma warning(disable: 4116)
|
||||||
|
#include "raylib-nuklear.h"
|
||||||
|
|
||||||
|
#define M 10
|
||||||
|
#define N 15
|
||||||
|
#define HEIGHT 50
|
||||||
|
#define WIDTH 50
|
||||||
|
#define VOFFSET 50
|
||||||
|
|
||||||
|
#define FWIDTH (float)WIDTH
|
||||||
|
#define FHEIGHT (float)HEIGHT
|
||||||
|
|
||||||
|
#define PUREBLUE (Color) { 0, 0, 255, 255 }
|
||||||
|
#define BLACKGRAY (Color) {30, 30, 30, 255}
|
||||||
|
#define VSGRAY (Color) {78, 201, 176, 255}
|
||||||
|
|
||||||
|
// Коды ячеек:
|
||||||
|
// 0 - свободна
|
||||||
|
// 1 -
|
||||||
|
// 2 - препятствие
|
||||||
|
// 3 - золото
|
||||||
|
int map[M][N] = {
|
||||||
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0},
|
||||||
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0},
|
||||||
|
{0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 3, 3, 0, 0, 0},
|
||||||
|
{0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 3, 3, 0, 0, 0},
|
||||||
|
|
||||||
|
{0, 0, 0, 0, 0, 0, 3, 3, 3, 0, 0, 0, 0, 0, 0},
|
||||||
|
{0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 2, 0, 0, 2, 0},
|
||||||
|
{0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0},
|
||||||
|
{0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 0},
|
||||||
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
int player_x = 1;
|
||||||
|
int player_y = 1;
|
||||||
|
bool player_turn = true;
|
||||||
|
|
||||||
|
int enemy_x = 14;
|
||||||
|
int enemy_y = 1;
|
||||||
|
int target_gold_x = 0;
|
||||||
|
int target_gold_y = 0;
|
||||||
|
int min_dist_to_gold = INT_MAX;
|
||||||
|
int enemy_gold = 0;
|
||||||
|
|
||||||
|
typedef enum { empty = 0, wall = 2, gold = 3 } obj_enum;
|
||||||
|
// TODO: do something with "empty" object
|
||||||
|
#define INVENTORY_SIZE 4
|
||||||
|
int inventory[INVENTORY_SIZE] = { 0, 0, 15, 0 };
|
||||||
|
obj_enum selected_element = gold;
|
||||||
|
|
||||||
|
typedef enum { left, right, up, down } enum_ways;
|
||||||
|
void movePlayer(enum_ways move) {
|
||||||
|
switch (move) {
|
||||||
|
case left:
|
||||||
|
if ((player_x > 0) and map[player_y][player_x - 1] != wall) player_x -= 1;
|
||||||
|
break;
|
||||||
|
case right:
|
||||||
|
if ((player_x < N - 1) and map[player_y][player_x + 1] != wall) player_x += 1;
|
||||||
|
break;
|
||||||
|
case up:
|
||||||
|
if ((player_y > 0) and map[player_y - 1][player_x] != wall) player_y -= 1;
|
||||||
|
break;
|
||||||
|
case down:
|
||||||
|
if ((player_y < M - 1) and map[player_y + 1][player_x] != wall) player_y += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (map[player_y][player_x] == gold) {
|
||||||
|
map[player_y][player_x] = empty;
|
||||||
|
inventory[gold]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveEnemy() {
|
||||||
|
int dx = target_gold_x - enemy_x;
|
||||||
|
int dy = target_gold_y - enemy_y;
|
||||||
|
enum_ways move = -1;
|
||||||
|
if (dx) {
|
||||||
|
if (dx > 0) {
|
||||||
|
move = right;
|
||||||
|
}
|
||||||
|
else if (dx < 0) {
|
||||||
|
move = left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (dy > 0) {
|
||||||
|
move = down;
|
||||||
|
}
|
||||||
|
else if (dy < 0) {
|
||||||
|
move = up;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (move) {
|
||||||
|
case left:
|
||||||
|
if ((enemy_x > 0) and map[enemy_y][enemy_x - 1] != wall) enemy_x -= 1;
|
||||||
|
break;
|
||||||
|
case right:
|
||||||
|
if ((enemy_x < N - 1) and map[enemy_y][enemy_x + 1] != wall) enemy_x += 1;
|
||||||
|
break;
|
||||||
|
case up:
|
||||||
|
if ((enemy_y > 0) and map[enemy_y - 1][enemy_x] != wall) enemy_y -= 1;
|
||||||
|
break;
|
||||||
|
case down:
|
||||||
|
if ((enemy_y < M - 1) and map[enemy_y + 1][enemy_x] != wall) enemy_y += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (map[enemy_y][enemy_x] == gold) {
|
||||||
|
map[enemy_y][enemy_x] = empty;
|
||||||
|
enemy_gold++;
|
||||||
|
min_dist_to_gold = INT_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void putElement(enum_ways way, obj_enum element) {
|
||||||
|
if (element != empty && inventory[element] == 0) return;
|
||||||
|
|
||||||
|
switch (way) {
|
||||||
|
case left:
|
||||||
|
if ((player_x > 0) and map[player_y][player_x - 1] == 0) {
|
||||||
|
map[player_y][player_x - 1] = element;
|
||||||
|
inventory[element]--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case right:
|
||||||
|
if ((player_x < N - 1) and map[player_y][player_x + 1] == 0) {
|
||||||
|
map[player_y][player_x + 1] = element;
|
||||||
|
inventory[element]--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case up:
|
||||||
|
if ((player_y > 0) and map[player_y - 1][player_x] == 0) {
|
||||||
|
map[player_y - 1][player_x] = element;
|
||||||
|
inventory[element]--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case down:
|
||||||
|
if ((player_y < M - 1) and map[player_y + 1][player_x] == 0) {
|
||||||
|
map[player_y + 1][player_x] = element;
|
||||||
|
inventory[element]--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deathbeam(enum_ways way) {
|
||||||
|
for (int i = player_x + 1; i < N; i++) {
|
||||||
|
if (map[player_y][i] != empty) inventory[map[player_y][i]] += 1;
|
||||||
|
map[player_y][i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void stomp(int r) {
|
||||||
|
for (int i = 0; i < M; i++) {
|
||||||
|
for (int j = 0; j < N; j++) {
|
||||||
|
if ((player_y - r <= i) && (i <= player_y + r) && (player_x - r <= j) && (j <= player_x + r) && map[i][j] == wall) {
|
||||||
|
inventory[wall] += 1;
|
||||||
|
map[i][j] = empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void midasHand(int m, int n) {
|
||||||
|
if (map[m][n] == wall) {
|
||||||
|
map[m][n] = gold;
|
||||||
|
if (m > 0) midasHand(m - 1, n);
|
||||||
|
if (n > 0) midasHand(m, n - 1);
|
||||||
|
if (m < M - 1) midasHand(m + 1, n);
|
||||||
|
if (n < N - 1) midasHand(m, n + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void doMidashand() {
|
||||||
|
if ((player_y < M - 1) and map[player_y + 1][player_x] == wall) midasHand(player_y + 1, player_x);
|
||||||
|
if ((player_x < N - 1) and map[player_y][player_x + 1] == wall) midasHand(player_y, player_x + 1);
|
||||||
|
if ((player_y > 0) and map[player_y - 1][player_x] == wall) midasHand(player_y - 1, player_x);
|
||||||
|
if ((player_x > 0) and map[player_y][player_x - 1] == wall) midasHand(player_y, player_x - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool netToggle = false;
|
||||||
|
void drawNet() {
|
||||||
|
for (int i = 0; i <= N * WIDTH; i += WIDTH) {
|
||||||
|
DrawLine(i, 0, i, M * HEIGHT, BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i <= M * HEIGHT; i += HEIGHT) {
|
||||||
|
DrawLine(0, i, N * WIDTH, i, BLACK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawMap() {
|
||||||
|
// Коды ячеек:
|
||||||
|
// 0 - свободна
|
||||||
|
// 1 -
|
||||||
|
// 2 - препятствие
|
||||||
|
// 3 - золото
|
||||||
|
Color colors[4] = { LIGHTGRAY, PUREBLUE, BLACK, YELLOW };
|
||||||
|
|
||||||
|
for (int i = 0; i < M; i++) {
|
||||||
|
for (int j = 0; j < N; j++) {
|
||||||
|
int x1 = j * WIDTH;
|
||||||
|
int y1 = i * HEIGHT;
|
||||||
|
int dist = abs(j - enemy_x) + abs(i - enemy_y);
|
||||||
|
if (map[i][j] == gold and dist < min_dist_to_gold) {
|
||||||
|
min_dist_to_gold = dist;
|
||||||
|
target_gold_x = j;
|
||||||
|
target_gold_y = i;
|
||||||
|
}
|
||||||
|
DrawRectangle(x1, y1, WIDTH, HEIGHT, colors[map[i][j]]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (map[target_gold_y][target_gold_x] != gold) {
|
||||||
|
min_dist_to_gold = INT_MAX;
|
||||||
|
}
|
||||||
|
DrawRectangle(target_gold_x * WIDTH, target_gold_y * HEIGHT, WIDTH, HEIGHT, ORANGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawPlayer() {
|
||||||
|
int x1 = player_x * WIDTH;
|
||||||
|
int y1 = player_y * HEIGHT;;
|
||||||
|
DrawRectangle(x1, y1, WIDTH, HEIGHT, PUREBLUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawEnemy(Font font) {
|
||||||
|
int x1 = enemy_x * WIDTH;
|
||||||
|
int y1 = enemy_y * HEIGHT;;
|
||||||
|
DrawRectangle(x1, y1, WIDTH, HEIGHT, RED);
|
||||||
|
DrawTextEx(font, TextFormat("%d", enemy_gold), (Vector2) { (float)x1, (float)y1 }, 24, 0, BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawBottomBar(Font font, float fontSize) {
|
||||||
|
DrawRectangle(0, HEIGHT * M, WIDTH * N, VOFFSET, BLACKGRAY);
|
||||||
|
|
||||||
|
static char gold_string[50];
|
||||||
|
static char wall_string[50];
|
||||||
|
|
||||||
|
static char help_string[] = "wasd - move player G - change item F5 - save\narrows - place item M - Midas hand F9 - load";
|
||||||
|
|
||||||
|
sprintf(gold_string, " gold = %d", inventory[gold]);
|
||||||
|
sprintf(wall_string, " wall = %d", inventory[wall]);
|
||||||
|
|
||||||
|
if (selected_element == gold) gold_string[0] = '>';
|
||||||
|
else if (selected_element == wall) wall_string[0] = '>';
|
||||||
|
|
||||||
|
Vector2 goldpos = { WIDTH / 4, HEIGHT * M };
|
||||||
|
Vector2 wallpos = { WIDTH / 4, HEIGHT * M + fontSize };
|
||||||
|
Vector2 helppos = { WIDTH * N - 550 , HEIGHT * M };
|
||||||
|
|
||||||
|
DrawTextEx(font, gold_string, goldpos, fontSize, 0, VSGRAY);
|
||||||
|
DrawTextEx(font, wall_string, wallpos, fontSize, 0, VSGRAY);
|
||||||
|
DrawTextEx(font, help_string, helppos, fontSize, 0, VSGRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void save() {
|
||||||
|
FILE* fout = fopen("savefile.txt", "w");
|
||||||
|
if (fout == NULL) {
|
||||||
|
printf("save error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(fout, "%d %d\n", M, N);
|
||||||
|
for (int i = 0; i < M; i++) {
|
||||||
|
for (int j = 0; j < N; j++) {
|
||||||
|
fprintf(fout, "%d ", map[i][j]);
|
||||||
|
}
|
||||||
|
fprintf(fout, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < INVENTORY_SIZE; i++) {
|
||||||
|
fprintf(fout, "%d ", inventory[i]);
|
||||||
|
}
|
||||||
|
fprintf(fout, "\n");
|
||||||
|
|
||||||
|
fprintf(fout, "%d %d %d\n", player_x, player_y, selected_element);
|
||||||
|
|
||||||
|
fclose(fout);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef enum { OK = 0, saveError, loadError1, loadError2 } ErrorCodes;
|
||||||
|
ErrorCodes errorCode = OK;
|
||||||
|
void load() {
|
||||||
|
FILE* fin = fopen("savefile.txt", "r");
|
||||||
|
if (fin == NULL) {
|
||||||
|
printf("1) load error\n");
|
||||||
|
/*MessageBoxA(
|
||||||
|
GetActiveWindow(),
|
||||||
|
"Файл не найден\nПопробуйте сначала сохранить игру",
|
||||||
|
"Ошибка загрузки",
|
||||||
|
MB_ICONERROR
|
||||||
|
);*/
|
||||||
|
errorCode = loadError1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int m, n;
|
||||||
|
fscanf_s(fin, "%d%d", &m, &n);
|
||||||
|
if (m != M || n != N) {
|
||||||
|
printf("2) load error\n");
|
||||||
|
/*MessageBoxW(
|
||||||
|
NULL,
|
||||||
|
L"Неправильный размер карты!\nПроверьте целостность сохранения",
|
||||||
|
L"Ошибка загрузки",
|
||||||
|
MB_ICONERROR
|
||||||
|
);*/
|
||||||
|
errorCode = loadError2;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < m; i++) {
|
||||||
|
for (int j = 0; j < n; j++) {
|
||||||
|
fscanf_s(fin, "%d", &map[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < INVENTORY_SIZE; i++) {
|
||||||
|
fscanf_s(fin, "%d", &inventory[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
fscanf_s(fin, "%d%d%d", &player_x, &player_y, &selected_element);
|
||||||
|
|
||||||
|
fclose(fin);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool editMap = 0;
|
||||||
|
void handleKeys() {
|
||||||
|
|
||||||
|
/*if (IsKeyPressedRepeat(KEY_W)) movePlayer(up);
|
||||||
|
if (IsKeyPressedRepeat(KEY_S)) movePlayer(down);
|
||||||
|
if (IsKeyPressedRepeat(KEY_D)) movePlayer(right);
|
||||||
|
if (IsKeyPressedRepeat(KEY_A)) movePlayer(left);*/
|
||||||
|
|
||||||
|
int key;
|
||||||
|
while (key = GetKeyPressed()) {
|
||||||
|
if (not editMap) {
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case KEY_W:
|
||||||
|
movePlayer(up);
|
||||||
|
break;
|
||||||
|
case KEY_S:
|
||||||
|
movePlayer(down);
|
||||||
|
break;
|
||||||
|
case KEY_D:
|
||||||
|
movePlayer(right);
|
||||||
|
break;
|
||||||
|
case KEY_A:
|
||||||
|
movePlayer(left);
|
||||||
|
break;
|
||||||
|
case KEY_ONE:
|
||||||
|
stomp(1);
|
||||||
|
break;
|
||||||
|
case KEY_TWO:
|
||||||
|
stomp(2);
|
||||||
|
break;
|
||||||
|
case KEY_Z:
|
||||||
|
deathbeam(right);
|
||||||
|
break;
|
||||||
|
case KEY_M:
|
||||||
|
doMidashand();
|
||||||
|
break;
|
||||||
|
case KEY_LEFT:
|
||||||
|
putElement(left, selected_element);
|
||||||
|
break;
|
||||||
|
case KEY_RIGHT:
|
||||||
|
putElement(right, selected_element);
|
||||||
|
break;
|
||||||
|
case KEY_UP:
|
||||||
|
putElement(up, selected_element);
|
||||||
|
break;
|
||||||
|
case KEY_DOWN:
|
||||||
|
putElement(down, selected_element);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case KEY_F5:
|
||||||
|
save();
|
||||||
|
break;
|
||||||
|
case KEY_F9:
|
||||||
|
load();
|
||||||
|
break;
|
||||||
|
case KEY_SPACE:
|
||||||
|
netToggle = !netToggle;
|
||||||
|
break;
|
||||||
|
case KEY_ENTER:
|
||||||
|
editMap = !editMap;
|
||||||
|
break;
|
||||||
|
case KEY_G:
|
||||||
|
if (selected_element == gold) selected_element = wall;
|
||||||
|
else selected_element = gold;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
player_turn = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawRayguiErrorBoxes() {
|
||||||
|
const Rectangle errorBoxRect = { N * WIDTH / 2 - 200, M * HEIGHT / 2 - 75, 400, 150 };
|
||||||
|
int btn = -1;
|
||||||
|
|
||||||
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case OK:
|
||||||
|
break;
|
||||||
|
case saveError:
|
||||||
|
btn = GuiMessageBox(errorBoxRect,
|
||||||
|
u8"Ошибка сохранения",
|
||||||
|
u8"Невозможно создать файл",
|
||||||
|
u8"Ок;Выйти");
|
||||||
|
break;
|
||||||
|
case loadError1:
|
||||||
|
btn = GuiMessageBox(errorBoxRect,
|
||||||
|
u8"Ошибка загрузки",
|
||||||
|
u8"Файл не найден\nПопробуйте сначала сохранить игру",
|
||||||
|
u8"Игнорировать;Выйти из игры");
|
||||||
|
break;
|
||||||
|
case loadError2:
|
||||||
|
btn = GuiMessageBox(errorBoxRect,
|
||||||
|
u8"Ошибка загрузки",
|
||||||
|
u8"Неправильный размер карты!\nПроверьте целостность сохранения",
|
||||||
|
u8"Игнорировать;Выйти из игры");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (btn)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
errorCode = OK;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
errorCode = OK;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int nk_error_box(struct nk_context* ctx, const char* title, const char* error, const char* description)
|
||||||
|
{
|
||||||
|
int result = -1;
|
||||||
|
if (nk_begin(ctx, title,
|
||||||
|
nk_rect(N * WIDTH / 2 - 200, M * HEIGHT / 2 - 72, 400, 144),
|
||||||
|
NK_WINDOW_TITLE | NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR))
|
||||||
|
{
|
||||||
|
nk_layout_row_dynamic(ctx, 24, 1);
|
||||||
|
nk_label(ctx, error, NK_TEXT_CENTERED);
|
||||||
|
nk_layout_row_dynamic(ctx, 24, 1);
|
||||||
|
nk_label(ctx, description, NK_TEXT_CENTERED);
|
||||||
|
nk_layout_row_dynamic(ctx, 36, 2);
|
||||||
|
if (nk_button_label(ctx, u8"Игнорировать")) {
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
if (nk_button_label(ctx, u8"Выйти из игры")) {
|
||||||
|
result = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void callNKErrorBoxes(struct nk_context* ctx) {
|
||||||
|
int btn = -1;
|
||||||
|
|
||||||
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case OK:
|
||||||
|
break;
|
||||||
|
case saveError:
|
||||||
|
btn = nk_error_box(ctx,
|
||||||
|
u8"Ошибка сохранения",
|
||||||
|
u8"Невозможно создать файл",
|
||||||
|
u8"Проверьте целостность сохранения");
|
||||||
|
break;
|
||||||
|
case loadError1:
|
||||||
|
btn = nk_error_box(ctx,
|
||||||
|
u8"Ошибка загрузки",
|
||||||
|
u8"Файл не найден",
|
||||||
|
u8"Проверьте целостность сохранения");
|
||||||
|
break;
|
||||||
|
case loadError2:
|
||||||
|
btn = nk_error_box(ctx,
|
||||||
|
u8"Ошибка загрузки",
|
||||||
|
u8"Неправильный размер карты!",
|
||||||
|
u8"Проверьте целостность сохранения");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (btn)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
errorCode = OK;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
errorCode = OK;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CPSIZE 213
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
SetConfigFlags(FLAG_WINDOW_HIGHDPI);
|
||||||
|
//SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||||
|
|
||||||
|
InitWindow(N * WIDTH, M * HEIGHT + VOFFSET, "lab16 with raylib");
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
SearchAndSetResourceDir("resources");
|
||||||
|
|
||||||
|
int codepoints[CPSIZE] = { 0 };
|
||||||
|
for (int i = 0; i < 127 - 32; i++) codepoints[i] = 32 + i; // Basic ASCII characters
|
||||||
|
for (int i = 0; i < 118; i++) codepoints[95 + i] = 1024 + i; // Cyrillic characters
|
||||||
|
|
||||||
|
//Font InconsolataRegular = LoadFontEx("Inconsolata-Regular.ttf", 24, NULL, 0);
|
||||||
|
//Font InconsolataSemiBold = LoadFontEx("Inconsolata-SemiBold.ttf", 48, codepoints, 512);
|
||||||
|
Font InconsolataBold = LoadFontEx("Inconsolata-LGC-Bold.ttf", 36, codepoints, CPSIZE);
|
||||||
|
SetTextureFilter(InconsolataBold.texture, TEXTURE_FILTER_BILINEAR);
|
||||||
|
//Font Arial = LoadFontEx("arial.ttf", 36, codepoints, CPSIZE);
|
||||||
|
//SetTextureFilter(Arial.texture, TEXTURE_FILTER_BILINEAR);
|
||||||
|
|
||||||
|
GuiSetFont(InconsolataBold);
|
||||||
|
GuiSetStyle(DEFAULT, TEXT_SIZE, 24);
|
||||||
|
GuiSetStyle(DEFAULT, TEXT_SPACING, 0);
|
||||||
|
GuiSetStyle(DEFAULT, TEXT_LINE_SPACING, 24);
|
||||||
|
GuiSetStyle(STATUSBAR, BORDER_WIDTH, 2);
|
||||||
|
|
||||||
|
// Create the Nuklear Context
|
||||||
|
struct nk_context* ctx = InitNuklearEx(InconsolataBold, 24);
|
||||||
|
|
||||||
|
Vector2 mousePos = { 0 };
|
||||||
|
int mouseCellX = 0;
|
||||||
|
int mouseCellY = 0;
|
||||||
|
|
||||||
|
// game loop
|
||||||
|
while (!WindowShouldClose()) // run the loop untill the user presses ESCAPE or presses the Close button on the window
|
||||||
|
{
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
// Update game logic
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
if (errorCode == OK)
|
||||||
|
{
|
||||||
|
if (player_turn) {
|
||||||
|
handleKeys();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
player_turn = true;
|
||||||
|
moveEnemy();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (editMap) {
|
||||||
|
mousePos = GetMousePosition();
|
||||||
|
mouseCellX = (int)(Clamp(mousePos.x, 0, FWIDTH * N - 1) / WIDTH);
|
||||||
|
mouseCellY = (int)(Clamp(mousePos.y, 0, FHEIGHT * M - 1) / HEIGHT);
|
||||||
|
|
||||||
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) and not(mouseCellX == player_x and mouseCellY == player_y)) {
|
||||||
|
map[mouseCellY][mouseCellX] = selected_element;
|
||||||
|
}
|
||||||
|
else if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) {
|
||||||
|
map[mouseCellY][mouseCellX] = empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
// Update Nuklear context
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
UpdateNuklear(ctx);
|
||||||
|
|
||||||
|
callNKErrorBoxes(ctx);
|
||||||
|
|
||||||
|
nk_end(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
// Draw
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
// Setup the back buffer for drawing (clear color and depth buffers)
|
||||||
|
ClearBackground(WHITE);
|
||||||
|
|
||||||
|
drawMap();
|
||||||
|
drawPlayer();
|
||||||
|
drawEnemy(InconsolataBold);
|
||||||
|
drawBottomBar(InconsolataBold, 24);
|
||||||
|
|
||||||
|
const Rectangle RoundRect = { 100, 250, 185, 36 };
|
||||||
|
//DrawRectangleRoundedLinesEx(RoundRect, 0.3f, 20, 1, BLACK);
|
||||||
|
|
||||||
|
if (editMap) {
|
||||||
|
Rectangle rec = {
|
||||||
|
mouseCellX * FWIDTH,
|
||||||
|
mouseCellY * FHEIGHT,
|
||||||
|
FWIDTH, FHEIGHT
|
||||||
|
};
|
||||||
|
|
||||||
|
Color color = { 0, 0, 0, 255 };
|
||||||
|
if (mouseCellX == player_x and mouseCellY == player_y) {
|
||||||
|
color.r = 255;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
color.g = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawRectangleLinesEx(rec, 2, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (netToggle) {
|
||||||
|
drawNet();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorCode > OK) {
|
||||||
|
// Render the Nuklear GUI
|
||||||
|
DrawNuklear(ctx);
|
||||||
|
|
||||||
|
//drawRayguiErrorBoxes();
|
||||||
|
}
|
||||||
|
|
||||||
|
//DrawTextEx(InconsolataBold, u8"Файл не найден\nПопробуйте сначала сохранить игру", (Vector2) { 100, 100 }, 24, 0, BLACK);
|
||||||
|
|
||||||
|
// show mouse position
|
||||||
|
//DrawText(TextFormat("%.1f %.1f", mousePos.x, mousePos.y), 5, M * HEIGHT - 30, 30, ORANGE);
|
||||||
|
|
||||||
|
// show FPS and frametime
|
||||||
|
//DrawText(TextFormat("%2d FPS", GetFPS()), 0, 0, 34, ORANGE);
|
||||||
|
//DrawText(TextFormat("%4f ms", GetFrameTime()), 0, 34, 34, BEIGE);
|
||||||
|
|
||||||
|
// end the frame and get ready for the next one (display frame, poll input, etc...)
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
//UnloadFont(InconsolataRegular);
|
||||||
|
UnloadFont(InconsolataBold);
|
||||||
|
//UnloadFont(Arial);
|
||||||
|
//UnloadFont(InconsolataBold);
|
||||||
|
|
||||||
|
// De-initialize the Nuklear GUI
|
||||||
|
UnloadNuklear(ctx);
|
||||||
|
|
||||||
|
// destroy the window and cleanup the OpenGL context
|
||||||
|
CloseWindow();
|
||||||
|
return 0;
|
||||||
|
}
|
@ -6,6 +6,7 @@
|
|||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
#include "resource_dir.h"
|
#include "resource_dir.h"
|
||||||
#include "windows_functions.h"
|
#include "windows_functions.h"
|
||||||
|
#include "tinyfiledialogs.h"
|
||||||
|
|
||||||
#define RAYGUI_IMPLEMENTATION
|
#define RAYGUI_IMPLEMENTATION
|
||||||
//#define RAYGUI_PANEL_BORDER_WIDTH 2
|
//#define RAYGUI_PANEL_BORDER_WIDTH 2
|
||||||
@ -15,6 +16,7 @@
|
|||||||
|
|
||||||
#define RAYLIB_NUKLEAR_IMPLEMENTATION
|
#define RAYLIB_NUKLEAR_IMPLEMENTATION
|
||||||
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
||||||
|
//#define RAYLIB_NUKLEAR_DEFAULT_ARC_SEGMENTS 1
|
||||||
#pragma warning(disable: 4116)
|
#pragma warning(disable: 4116)
|
||||||
#include "raylib-nuklear.h"
|
#include "raylib-nuklear.h"
|
||||||
|
|
||||||
@ -29,7 +31,7 @@
|
|||||||
|
|
||||||
#define PUREBLUE (Color) { 0, 0, 255, 255 }
|
#define PUREBLUE (Color) { 0, 0, 255, 255 }
|
||||||
#define BLACKGRAY (Color) {30, 30, 30, 255}
|
#define BLACKGRAY (Color) {30, 30, 30, 255}
|
||||||
#define VSGRAY (Color) {78, 201, 176, 255}
|
#define VSGREEN (Color) {78, 201, 176, 255}
|
||||||
|
|
||||||
// Коды ячеек:
|
// Коды ячеек:
|
||||||
// 0 - свободна
|
// 0 - свободна
|
||||||
@ -199,9 +201,9 @@ void drawBottomBar(Font font, float fontSize) {
|
|||||||
Vector2 wallpos = { WIDTH / 4, HEIGHT * M + fontSize };
|
Vector2 wallpos = { WIDTH / 4, HEIGHT * M + fontSize };
|
||||||
Vector2 helppos = { WIDTH * N - 550 , HEIGHT * M };
|
Vector2 helppos = { WIDTH * N - 550 , HEIGHT * M };
|
||||||
|
|
||||||
DrawTextEx(font, gold_string, goldpos, fontSize, 0, VSGRAY);
|
DrawTextEx(font, gold_string, goldpos, fontSize, 0, VSGREEN);
|
||||||
DrawTextEx(font, wall_string, wallpos, fontSize, 0, VSGRAY);
|
DrawTextEx(font, wall_string, wallpos, fontSize, 0, VSGREEN);
|
||||||
DrawTextEx(font, help_string, helppos, fontSize, 0, VSGRAY);
|
DrawTextEx(font, help_string, helppos, fontSize, 0, VSGREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void save() {
|
void save() {
|
||||||
@ -241,6 +243,11 @@ void load() {
|
|||||||
"Ошибка загрузки",
|
"Ошибка загрузки",
|
||||||
MB_ICONERROR
|
MB_ICONERROR
|
||||||
);*/
|
);*/
|
||||||
|
tinyfd_messageBox(
|
||||||
|
u8"Ошибка сохранения",
|
||||||
|
u8"Невозможно создать файл\nПроверьте целостность сохранения",
|
||||||
|
u8"ok",
|
||||||
|
"error", 1);
|
||||||
errorCode = loadError1;
|
errorCode = loadError1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -430,12 +437,12 @@ void callNKErrorBoxes(struct nk_context* ctx) {
|
|||||||
btn = nk_error_box(ctx,
|
btn = nk_error_box(ctx,
|
||||||
u8"Ошибка загрузки",
|
u8"Ошибка загрузки",
|
||||||
u8"Файл не найден",
|
u8"Файл не найден",
|
||||||
u8"Проверьте целостность сохранения");
|
u8"Попробуйте сначала сохранить игру");
|
||||||
break;
|
break;
|
||||||
case loadError2:
|
case loadError2:
|
||||||
btn = nk_error_box(ctx,
|
btn = nk_error_box(ctx,
|
||||||
u8"Ошибка загрузки",
|
u8"Ошибка загрузки",
|
||||||
u8"Неправильный размер карты!",
|
u8"Неправильный размер карты",
|
||||||
u8"Проверьте целостность сохранения");
|
u8"Проверьте целостность сохранения");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -457,12 +464,12 @@ void callNKErrorBoxes(struct nk_context* ctx) {
|
|||||||
#define CPSIZE 213
|
#define CPSIZE 213
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
SetConfigFlags(FLAG_WINDOW_HIGHDPI);
|
//SetConfigFlags(FLAG_WINDOW_HIGHDPI);
|
||||||
//SetConfigFlags(FLAG_MSAA_4X_HINT);
|
//SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||||
|
|
||||||
InitWindow(N * WIDTH, M * HEIGHT + VOFFSET, "lab16 with raylib");
|
InitWindow(N * WIDTH, M * HEIGHT + VOFFSET, "lab16 with raylib");
|
||||||
|
|
||||||
SetTargetFPS(20);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
SearchAndSetResourceDir("resources");
|
SearchAndSetResourceDir("resources");
|
||||||
|
|
||||||
@ -474,6 +481,8 @@ int main()
|
|||||||
//Font InconsolataSemiBold = LoadFontEx("Inconsolata-SemiBold.ttf", 48, codepoints, 512);
|
//Font InconsolataSemiBold = LoadFontEx("Inconsolata-SemiBold.ttf", 48, codepoints, 512);
|
||||||
Font InconsolataBold = LoadFontEx("Inconsolata-LGC-Bold.ttf", 36, codepoints, CPSIZE);
|
Font InconsolataBold = LoadFontEx("Inconsolata-LGC-Bold.ttf", 36, codepoints, CPSIZE);
|
||||||
SetTextureFilter(InconsolataBold.texture, TEXTURE_FILTER_BILINEAR);
|
SetTextureFilter(InconsolataBold.texture, TEXTURE_FILTER_BILINEAR);
|
||||||
|
Font Consolas = LoadFontEx("consola.ttf", 24, codepoints, CPSIZE);
|
||||||
|
SetTextureFilter(Consolas.texture, TEXTURE_FILTER_BILINEAR);
|
||||||
//Font Arial = LoadFontEx("arial.ttf", 36, codepoints, CPSIZE);
|
//Font Arial = LoadFontEx("arial.ttf", 36, codepoints, CPSIZE);
|
||||||
//SetTextureFilter(Arial.texture, TEXTURE_FILTER_BILINEAR);
|
//SetTextureFilter(Arial.texture, TEXTURE_FILTER_BILINEAR);
|
||||||
|
|
||||||
@ -518,11 +527,11 @@ int main()
|
|||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
// Update Nuklear context
|
// Update Nuklear context
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
UpdateNuklear(ctx);
|
/*UpdateNuklear(ctx);
|
||||||
|
|
||||||
callNKErrorBoxes(ctx);
|
callNKErrorBoxes(ctx);
|
||||||
|
|
||||||
nk_end(ctx);
|
nk_end(ctx);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
@ -534,10 +543,7 @@ int main()
|
|||||||
|
|
||||||
drawMap();
|
drawMap();
|
||||||
drawPlayer();
|
drawPlayer();
|
||||||
drawBottomBar(InconsolataBold, 24);
|
drawBottomBar(Consolas, 24);
|
||||||
|
|
||||||
const Rectangle RoundRect = { 100, 250, 185, 36 };
|
|
||||||
DrawRectangleRoundedLinesEx(RoundRect, 0.3f, 20, 1, BLACK);
|
|
||||||
|
|
||||||
if (editMap) {
|
if (editMap) {
|
||||||
Rectangle rec = {
|
Rectangle rec = {
|
||||||
@ -563,12 +569,12 @@ int main()
|
|||||||
|
|
||||||
if (errorCode > OK) {
|
if (errorCode > OK) {
|
||||||
// Render the Nuklear GUI
|
// Render the Nuklear GUI
|
||||||
DrawNuklear(ctx);
|
//DrawNuklear(ctx);
|
||||||
|
|
||||||
//drawRayguiErrorBoxes();
|
//drawRayguiErrorBoxes();
|
||||||
}
|
}
|
||||||
|
|
||||||
//DrawTextEx(InconsolataBold, u8"Файл не найден\nПопробуйте сначала сохранить игру", (Vector2) { 100, 100 }, 24, 0, BLACK);
|
DrawTextEx(Consolas, u8"Файл не найден\nПопробуйте сначала сохранить игру", (Vector2) { 100, 100 }, 24, 0, BLACK);
|
||||||
|
|
||||||
// show mouse position
|
// show mouse position
|
||||||
//DrawText(TextFormat("%.1f %.1f", mousePos.x, mousePos.y), 5, M * HEIGHT - 30, 30, ORANGE);
|
//DrawText(TextFormat("%.1f %.1f", mousePos.x, mousePos.y), 5, M * HEIGHT - 30, 30, ORANGE);
|
||||||
|
8171
lab16 with raylib/src/tinyfiledialogs.c
Normal file
8171
lab16 with raylib/src/tinyfiledialogs.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -322,7 +322,7 @@ void drawBottomBar(HDC hdc) {
|
|||||||
RECT helprect = { WIDTH * N - 550 , HEIGHT * M, WIDTH * N - WIDTH / 4, HEIGHT * M + VOFFSET };
|
RECT helprect = { WIDTH * N - 550 , HEIGHT * M, WIDTH * N - WIDTH / 4, HEIGHT * M + VOFFSET };
|
||||||
|
|
||||||
HFONT hFont = CreateFontW(24, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
|
HFONT hFont = CreateFontW(24, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
|
||||||
CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, TEXT("Consolas"));
|
CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, TEXT("consolas"));
|
||||||
SelectObject(hdc, hFont);
|
SelectObject(hdc, hFont);
|
||||||
|
|
||||||
SetTextColor(hdc, RGB(78, 201, 176));
|
SetTextColor(hdc, RGB(78, 201, 176));
|
||||||
|
@ -76,6 +76,7 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>..\..\hash functions</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
Binary file not shown.
232
tinyfiledialogs/README.txt
Normal file
232
tinyfiledialogs/README.txt
Normal file
@ -0,0 +1,232 @@
|
|||||||
|
SPDX-License-Identifier: Zlib
|
||||||
|
Copyright (c) 2014 - 2024 Guillaume Vareille http://ysengrin.com
|
||||||
|
|
||||||
|
********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE *********
|
||||||
|
|
||||||
|
http://tinyfiledialogs.sourceforge.net
|
||||||
|
git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
***************************************************************************
|
||||||
|
____________________________________________________________________
|
||||||
|
| |
|
||||||
|
| 100% compatible C C++ -> You can rename tinfiledialogs.c as .cpp |
|
||||||
|
|____________________________________________________________________|
|
||||||
|
|
||||||
|
tiny file dialogs ( cross-platform C C++ ) v3.18.2 [Jun 16, 2024]
|
||||||
|
_________
|
||||||
|
/ \ Tray-popup InputBox PasswordBox MessageBox Notification Beep
|
||||||
|
|tiny file| ColorPicker OpenFileDialog SaveFileDialog SelectFolderDialog
|
||||||
|
| dialogs | ASCII UTF-8 (and also MBCS & UTF-16 for windows)
|
||||||
|
\____ ___/ Native dialog library for WINDOWS MAC OSX GTK+ QT CONSOLE
|
||||||
|
\| SSH support via automatic switch to console mode or X forwarding
|
||||||
|
|
||||||
|
C89/C18 & C++98/C++20 compliant: tested with C & C++ compilers
|
||||||
|
VisualStudio MinGW GCC Clang TinyCC OpenWatcom-v2 BorlandC SunCC ZapCC
|
||||||
|
on Windows Mac Linux Bsd Solaris Minix Raspbian Flatpak
|
||||||
|
using Gnome Kde Mate Enlightenment Cinnamon Budgie Unity Lxde Lxqt Xfce
|
||||||
|
WindowMaker IceWm Cde Jds OpenBox Awesome Jwm Xdm Cwm
|
||||||
|
|
||||||
|
Bindings for LUA, C#, dll, Fortran, Pascal, R.
|
||||||
|
Included in LWJGL(java), Rust, Haskell, Allegrobasic.
|
||||||
|
____________________________________________________________________________
|
||||||
|
| ________________________________________________________________________ |
|
||||||
|
| | ____________________________________________________________________ | |
|
||||||
|
| | | If you like tinyfiledialogs, please upvote my stackoverflow answer | | |
|
||||||
|
| | | https://stackoverflow.com/a/47651444 | | |
|
||||||
|
| | |____________________________________________________________________| | |
|
||||||
|
| |________________________________________________________________________| |
|
||||||
|
|____________________________________________________________________________|
|
||||||
|
___________________________________________________________
|
||||||
|
| |
|
||||||
|
| v3.10: NEW FORTRAN module fully implemented with examples |
|
||||||
|
| v3.13: NEW PASCAL unit fully implemented with examples |
|
||||||
|
| v3.14: NEW R inteface fully implemented with examples |
|
||||||
|
|___________________________________________________________|
|
||||||
|
_____________________________________________________________________
|
||||||
|
| |
|
||||||
|
| my email address is at the top of the header file tinyfiledialogs.h |
|
||||||
|
|_____________________________________________________________________|
|
||||||
|
________________________________________________________________________________
|
||||||
|
| ____________________________________________________________________________ |
|
||||||
|
| | | |
|
||||||
|
| | - in tinyfiledialogs, char is UTF-8 by default (since v3.6) | |
|
||||||
|
| | | |
|
||||||
|
| | on windows: | |
|
||||||
|
| | - for UTF-16, use the wchar_t functions at the bottom of the header file | |
|
||||||
|
| | - _wfopen() requires wchar_t | |
|
||||||
|
| | | |
|
||||||
|
| | - but fopen() expects MBCS (not UTF-8) | |
|
||||||
|
| | - if you want char to be MBCS: set tinyfd_winUtf8 = 0 | |
|
||||||
|
| | | |
|
||||||
|
| | - alternatively, tinyfiledialogs provides | |
|
||||||
|
| | functions to convert between UTF-8, UTF-16 and MBCS | |
|
||||||
|
| |____________________________________________________________________________| |
|
||||||
|
|________________________________________________________________________________|
|
||||||
|
|
||||||
|
___________________________________________________________________________________
|
||||||
|
| _______________________________________________________________________________ |
|
||||||
|
| | | |
|
||||||
|
| | wchar_t UTF-16 (windows only) prototypes are at the bottom of the header file | |
|
||||||
|
| |_______________________________________________________________________________| |
|
||||||
|
|___________________________________________________________________________________|
|
||||||
|
|
||||||
|
__________________________________________
|
||||||
|
| ______________________________________ |
|
||||||
|
| | | |
|
||||||
|
| | DO NOT USE USER INPUT IN THE DIALOGS | |
|
||||||
|
| |______________________________________| |
|
||||||
|
|__________________________________________|
|
||||||
|
|
||||||
|
|
||||||
|
See compilation instructions at the end of this file
|
||||||
|
|
||||||
|
void tinyfd_beep();
|
||||||
|
|
||||||
|
int tinyfd_notifyPopup(
|
||||||
|
char const * aTitle , // NULL or ""
|
||||||
|
char const * aMessage , // NULL or "" may contain \n \t
|
||||||
|
char const * aIconType ); // "info" "warning" "error"
|
||||||
|
|
||||||
|
int tinyfd_messageBox(
|
||||||
|
char const * aTitle , // NULL or ""
|
||||||
|
char const * aMessage , // NULL or "" may contain \n \t
|
||||||
|
char const * aDialogType , // "ok" "okcancel" "yesno" "yesnocancel"
|
||||||
|
char const * aIconType , // "info" "warning" "error" "question"
|
||||||
|
int aDefaultButton );
|
||||||
|
// 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel
|
||||||
|
|
||||||
|
char const * tinyfd_inputBox(
|
||||||
|
char const * aTitle , // NULL or ""
|
||||||
|
char const * aMessage , // NULL or "" (\n and \t have no effect)
|
||||||
|
char const * aDefaultInput ); // NULL for a passwordBox, "" for an inputbox
|
||||||
|
// returns NULL on cancel
|
||||||
|
|
||||||
|
char const * tinyfd_saveFileDialog(
|
||||||
|
char const * aTitle , // NULL or ""
|
||||||
|
char const * aDefaultPathAndOrFile , // NULL or "" , ends with / to set only a directory
|
||||||
|
int aNumOfFilterPatterns , // 0 (1 in the following example)
|
||||||
|
char const * const * aFilterPatterns , // NULL or char const * lFilterPatterns[1]={"*.txt"};
|
||||||
|
char const * aSingleFilterDescription ); // NULL or "text files"
|
||||||
|
// returns NULL on cancel
|
||||||
|
|
||||||
|
char const * tinyfd_openFileDialog(
|
||||||
|
char const * aTitle , // NULL or ""
|
||||||
|
char const * aDefaultPathAndOrFile , // NULL or "" , ends with / to set only a directory
|
||||||
|
int aNumOfFilterPatterns , // 0 (2 in the following example)
|
||||||
|
char const * const * aFilterPatterns , // NULL or char const * lFilterPatterns[2]={"*.png","*.jpg"};
|
||||||
|
char const * aSingleFilterDescription , // NULL or "image files"
|
||||||
|
int aAllowMultipleSelects ); // 0
|
||||||
|
// in case of multiple files, the separator is |
|
||||||
|
// returns NULL on cancel
|
||||||
|
|
||||||
|
char const * tinyfd_selectFolderDialog(
|
||||||
|
char const * aTitle , // NULL or ""
|
||||||
|
char const * aDefaultPath ); // NULL or ""
|
||||||
|
// returns NULL on cancel
|
||||||
|
|
||||||
|
char const * tinyfd_colorChooser(
|
||||||
|
char const * aTitle , // NULL or ""
|
||||||
|
char const * aDefaultHexRGB , // NULL or "#FF0000‚Ç¥
|
||||||
|
unsigned char const aDefaultRGB[3] , // unsigned char lDefaultRGB[3] = { 0 , 128 , 255 };
|
||||||
|
unsigned char aoResultRGB[3] ); // unsigned char lResultRGB[3];
|
||||||
|
// returns the hexcolor as a string "#FF0000"
|
||||||
|
// aoResultRGB also contains the result
|
||||||
|
// aDefaultRGB is used only if aDefaultHexRGB is NULL
|
||||||
|
// aDefaultRGB and aoResultRGB can be the same array
|
||||||
|
// returns NULL on cancel
|
||||||
|
___________________________________________________________________________________
|
||||||
|
| _______________________________________________________________________________ |
|
||||||
|
| | | |
|
||||||
|
| | wchar_t UTF-16 (windows only) prototypes are at the bottom of the header file | |
|
||||||
|
| |_______________________________________________________________________________| |
|
||||||
|
|___________________________________________________________________________________|
|
||||||
|
|
||||||
|
- This is not for ios nor android (it works in termux and iSH though).
|
||||||
|
- The files can be renamed with extension ".cpp" as the code is 100% compatible C C++
|
||||||
|
- Windows is fully supported from XP to 11 (maybe even older versions)
|
||||||
|
- C# & LUA via dll, see files in the folder EXTRAS
|
||||||
|
- OSX supported from 10.4 to latest (maybe even older versions)
|
||||||
|
- Do not use " and ' as the dialogs will be display with a warning
|
||||||
|
instead of the title, message, etc...
|
||||||
|
- There's one file filter only, it may contain several patterns.
|
||||||
|
- If no filter description is provided,
|
||||||
|
the list of patterns will become the description.
|
||||||
|
- On windows link against Comdlg32.lib and Ole32.lib
|
||||||
|
(on windows the no linking claim is a lie)
|
||||||
|
- On unix / macos: it only tries command line calls, so no linking is need.
|
||||||
|
- On unix /macos you need one of the following:
|
||||||
|
applescript, kdialog, zenity, matedialog, shellementary, qarma, yad,
|
||||||
|
python (2 or 3)with tkinter/python-dbus, Xdialog
|
||||||
|
or curses dialogs (opens terminal if running without console).
|
||||||
|
- One of those is already included on most (if not all) desktops.
|
||||||
|
- In the absence of those it will use gdialog, gxmessage or whiptail
|
||||||
|
with a textinputbox.
|
||||||
|
- If nothing is found, it switches to basic console input,
|
||||||
|
it opens a console if needed (requires xterm + bash).
|
||||||
|
- for curses dialogs you must set tinyfd_allowCursesDialogs=1
|
||||||
|
- You can query the type of dialog that will be used (pass "tinyfd_query" as aTitle)
|
||||||
|
- String memory is preallocated statically for all the returned values.
|
||||||
|
- File and path names are tested before return, they should be valid.
|
||||||
|
- tinyfd_forceConsole=1; at run time, forces dialogs into console mode.
|
||||||
|
- On windows, console mode only make sense for console applications.
|
||||||
|
- On windows, console mode is not implemented for wchar_T UTF-16.
|
||||||
|
- Mutiple selects are not possible in console mode.
|
||||||
|
- The package dialog must be installed to run in curses dialogs in console mode.
|
||||||
|
It is already installed on most unix systems.
|
||||||
|
- On osx, the package dialog can be installed via
|
||||||
|
http://macappstore.org/dialog or http://macports.org
|
||||||
|
- On windows, for curses dialogs console mode,
|
||||||
|
dialog.exe should be copied somewhere on your executable path.
|
||||||
|
It can be found at the bottom of the following page:
|
||||||
|
http://andrear.altervista.org/home/cdialog.php
|
||||||
|
_________________________________________________________________
|
||||||
|
| The project provides an Hello World example: |
|
||||||
|
| if a console is missing, it will use graphic dialogs |
|
||||||
|
| if a graphical display is absent, it will use console dialogs |
|
||||||
|
|_________________________________________________________________|
|
||||||
|
|
||||||
|
|
||||||
|
UNIX (including MacOS) :
|
||||||
|
$ clang -o hello hello.c tinyfiledialogs.c
|
||||||
|
( or gcc tcc owcc icx suncc )
|
||||||
|
( or g++ clang++ icpx sunCC )
|
||||||
|
( some possible options :
|
||||||
|
-ansi -std=c89 -std=c++98 -pedantic -Wstrict-prototypes
|
||||||
|
-g3 -Wall -Wextra -Wdouble-promotion -Wconversion -Wno-sign-conversion
|
||||||
|
-Wno-unused-parameter -Wno-unused-function -fsanitize=undefined -fsanitize=thread
|
||||||
|
-Wno-deprecated -Wno-incompatible-compiler )
|
||||||
|
( if using musl instead of glibc: clang -fuse-ld=lld --rtlib=compiler-rt )
|
||||||
|
|
||||||
|
_____________________________________________________________________________
|
||||||
|
| Windows : |
|
||||||
|
| You'll probably need to install The Windows SDK (Software Development Kit) |
|
||||||
|
| http://developer.microsoft.com/en-us/windows/downloads/windows-sdk |
|
||||||
|
| The end user doesn't need to install anything |
|
||||||
|
|_____________________________________________________________________________|
|
||||||
|
|
||||||
|
MinGW needs gcc >= v4.9 otherwise some headers are incomplete
|
||||||
|
> gcc -o hello.exe hello.c tinyfiledialogs.c -LC:/mingw/lib -lcomdlg32 -lole32
|
||||||
|
|
||||||
|
TinyCC needs >= v0.9.27 (+ tweaks - contact me) otherwise some headers are missing
|
||||||
|
> tcc -o hello.exe hello.c tinyfiledialogs.c ^
|
||||||
|
-isystem C:\tcc\winapi-full-for-0.9.27\include\winapi ^
|
||||||
|
-lcomdlg32 -lole32 -luser32 -lshell32
|
||||||
|
|
||||||
|
Borland C :
|
||||||
|
> bcc32c -o hello.exe hello.c tinyfiledialogs.c
|
||||||
|
|
||||||
|
Open Watcom C v2
|
||||||
|
> owcc -o hello.exe hello.c tinyfiledialogs.c
|
||||||
|
|
||||||
|
Windows Intel C :
|
||||||
|
> icx-cc -o hello.exe hello.c tinyfiledialogs.c -lcomdlg32 -lole32 -luser32 -lshell32
|
||||||
|
> icx-cl -o hello.exe hello.c tinyfiledialogs.c comdlg32.lib ole32.lib user32.lib shell32.lib
|
||||||
|
> icx -o hello.exe hello.c tinyfiledialogs.c comdlg32.lib ole32.lib user32.lib shell32.lib
|
||||||
|
> icpx -o hello.exe hello.c tinyfiledialogs.c -lcomdlg32 -lole32 -luser32 -lshell32 -Wno-deprecated
|
||||||
|
|
||||||
|
VisualStudio command line :
|
||||||
|
> cl hello.c tinyfiledialogs.c comdlg32.lib ole32.lib user32.lib shell32.lib /W4
|
||||||
|
|
||||||
|
VisualStudio
|
||||||
|
In the properties of your project, in the linker input field,
|
||||||
|
you may need to add: comdlg32.lib ole32.lib user32.lib shell32.lib
|
||||||
|
or maybe simply add: %(AdditionalDependencies)
|
@ -0,0 +1,287 @@
|
|||||||
|
/* SPDX-License-Identifier: ZLIB
|
||||||
|
Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
|
||||||
|
_________
|
||||||
|
/ \ LUA_plugin.tinyfiledialogs.cpp v3.8.3 [Nov 1, 2020]
|
||||||
|
|tiny file| LUA bindings created [2016] Copyright (c) 2016 Steven Johnson
|
||||||
|
| dialogs |
|
||||||
|
\____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
____________________________________________
|
||||||
|
| |
|
||||||
|
| email: tinyfiledialogs at ysengrin.com |
|
||||||
|
|____________________________________________|
|
||||||
|
|
||||||
|
If you like tinyfiledialogs, please upvote my stackoverflow answer
|
||||||
|
https://stackoverflow.com/a/47651444
|
||||||
|
|
||||||
|
- License -
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
-----------
|
||||||
|
|
||||||
|
this file was contributed by Steven Johnson from the Corona SDK project
|
||||||
|
and is offered here under the same zlib license as tinyfiledialogs
|
||||||
|
|
||||||
|
-#include "CoronaLua.h" will typically be something like
|
||||||
|
extern "C" {
|
||||||
|
#include "lua.h"
|
||||||
|
#include "lualib.h"
|
||||||
|
#include "lauxlib.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
in a normal(i.e.non - Corona) program.
|
||||||
|
- For that matter, CORONA_EXPORT just hides the library exporting code.
|
||||||
|
- The "_plugin_" stuff is part of a signature used by Corona to dynamically load the entry point function, but might be out
|
||||||
|
of place in a non - Corona program.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "CoronaLua.h"
|
||||||
|
#include "tinyfiledialogs.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define STATIC_FILTER_COUNT 8
|
||||||
|
|
||||||
|
static int GetBool (lua_State * L, const char * key)
|
||||||
|
{
|
||||||
|
lua_getfield(L, 1, key);// ..., bool
|
||||||
|
|
||||||
|
int bval = lua_toboolean(L, -1);
|
||||||
|
|
||||||
|
lua_pop(L, 1); // ...
|
||||||
|
|
||||||
|
return bval;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char * GetStrOrBlank (lua_State * L, const char * key, const char * blank = "")
|
||||||
|
{
|
||||||
|
lua_getfield(L, 1, key);// ..., str?
|
||||||
|
|
||||||
|
const char * str = blank; // might be NULL, thus not using luaL_optstring
|
||||||
|
|
||||||
|
if (!lua_isnil(L, -1)) str = luaL_checkstring(L, -1);
|
||||||
|
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int GetFilters (lua_State * L, const char *** filters)
|
||||||
|
{
|
||||||
|
int nfilters = 0;
|
||||||
|
|
||||||
|
lua_getfield(L, 1, "filter_patterns"); // ..., patts
|
||||||
|
|
||||||
|
if (lua_istable(L, -1))
|
||||||
|
{
|
||||||
|
int n = lua_objlen(L, -1);
|
||||||
|
|
||||||
|
if (n > STATIC_FILTER_COUNT) *filters = (const char **)lua_newuserdata(L, sizeof(const char *) * n);// ..., patts, filters
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; ++i, lua_pop(L, 1))
|
||||||
|
{
|
||||||
|
lua_rawgeti(L, -1, i); // ..., patts[, filters], patt
|
||||||
|
|
||||||
|
(*filters)[nfilters++] = luaL_checkstring(L, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (!lua_isnil(L, -1)) (*filters)[nfilters++] = luaL_checkstring(L, -1);
|
||||||
|
|
||||||
|
return nfilters;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int StringResponse (lua_State * L, const char * res)
|
||||||
|
{
|
||||||
|
if (!res) lua_pushboolean(L, 0);// ..., false
|
||||||
|
|
||||||
|
else lua_pushstring(L, res);// ..., res
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static luaL_Reg tfd_funcs[] = {
|
||||||
|
{
|
||||||
|
"notifyPopup", [](lua_State * L)
|
||||||
|
{
|
||||||
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
|
|
||||||
|
const char * title = GetStrOrBlank(L, "title");
|
||||||
|
const char * message = GetStrOrBlank(L, "message");
|
||||||
|
const char * icon_types[] = { "info", "warning", "error" };
|
||||||
|
|
||||||
|
lua_getfield(L, 1, "icon_type"); // opts, icon_type
|
||||||
|
|
||||||
|
const char * itype = icon_types[luaL_checkoption(L, -1, "info", icon_types)];
|
||||||
|
|
||||||
|
lua_pushboolean(L, tinyfd_notifyPopup(title, message, itype)); // opts, icon_type
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"messageBox", [](lua_State * L)
|
||||||
|
{
|
||||||
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
|
|
||||||
|
const char * title = GetStrOrBlank(L, "title");
|
||||||
|
const char * message = GetStrOrBlank(L, "message");
|
||||||
|
const char * dialog_types[] = { "ok", "okcancel", "yesno", "yesnocancel" };
|
||||||
|
const char * icon_types[] = { "info", "warning", "error", "question" };
|
||||||
|
|
||||||
|
lua_getfield(L, 1, "dialog_type"); // opts, dialog_type
|
||||||
|
lua_getfield(L, 1, "icon_type");// opts, dialog_type, icon_type
|
||||||
|
|
||||||
|
const char * dtype = dialog_types[luaL_checkoption(L, -2, "ok", dialog_types)];
|
||||||
|
const char * itype = icon_types[luaL_checkoption(L, -1, "info", icon_types)];
|
||||||
|
|
||||||
|
lua_pushboolean(L, tinyfd_messageBox(title, message, dtype, itype, GetBool(L, "default_okyes"))); // opts, dialog_type, icon_type, ok / yes
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"inputBox", [](lua_State * L)
|
||||||
|
{
|
||||||
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
|
|
||||||
|
const char * title = GetStrOrBlank(L, "title");
|
||||||
|
const char * message = GetStrOrBlank(L, "message");
|
||||||
|
|
||||||
|
//
|
||||||
|
lua_getfield(L, 1, "default_input");// opts, def_input
|
||||||
|
|
||||||
|
const char * def_input;
|
||||||
|
|
||||||
|
if (lua_type(L, -1) == LUA_TBOOLEAN && !lua_toboolean(L, -1)) def_input = NULL;
|
||||||
|
|
||||||
|
else def_input = luaL_optstring(L, -1, "");
|
||||||
|
|
||||||
|
return StringResponse(L, tinyfd_inputBox(title, message, def_input)); // opts, def_input, input
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"saveFileDialog", [](lua_State * L)
|
||||||
|
{
|
||||||
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
|
|
||||||
|
const char * title = GetStrOrBlank(L, "title");
|
||||||
|
const char * def_path_and_file = GetStrOrBlank(L, "default_path_and_file");
|
||||||
|
const char * filter_description = GetStrOrBlank(L, "filter_description", NULL);
|
||||||
|
const char * filter_array[STATIC_FILTER_COUNT] = { 0 }, ** filters = filter_array;
|
||||||
|
int nfilters = GetFilters(L, &filters); // opts, patts[, filters]
|
||||||
|
|
||||||
|
return StringResponse(L, tinyfd_saveFileDialog(title, def_path_and_file, nfilters, filters, filter_description)); // opts, patts[, filters], file
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"openFileDialog", [](lua_State * L)
|
||||||
|
{
|
||||||
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
|
|
||||||
|
//
|
||||||
|
const char * title = GetStrOrBlank(L, "title");
|
||||||
|
const char * def_path_and_file = GetStrOrBlank(L, "default_path_and_file");
|
||||||
|
const char * filter_description = GetStrOrBlank(L, "filter_description", NULL);
|
||||||
|
const char * filter_array[STATIC_FILTER_COUNT] = { 0 }, ** filters = filter_array;
|
||||||
|
int allow_multiple_selects = GetBool(L, "allow_multiple_selects");
|
||||||
|
int nfilters = GetFilters(L, &filters); // opts, patts[, filters]
|
||||||
|
|
||||||
|
//
|
||||||
|
const char * files = tinyfd_openFileDialog(title, def_path_and_file, nfilters, nfilters ? filters : NULL, filter_description, allow_multiple_selects);
|
||||||
|
|
||||||
|
if (!allow_multiple_selects || !files) return StringResponse(L, files); // opts, patts[, filters], files?
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua_newtable(L);// opts, patts[, filters], files
|
||||||
|
|
||||||
|
char * from = (char *)files, * sep = from; // assign sep in order to pass first iteration
|
||||||
|
|
||||||
|
for (int fi = 1; sep; ++fi)
|
||||||
|
{
|
||||||
|
sep = strchr(from, '|');
|
||||||
|
|
||||||
|
if (sep)
|
||||||
|
{
|
||||||
|
lua_pushlstring(L, from, sep - from); // opts, patts[, filters], files, file
|
||||||
|
|
||||||
|
from = sep + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
else lua_pushstring(L, from);// opts, patts[, filters], files, file
|
||||||
|
|
||||||
|
lua_rawseti(L, -2, fi); // opts, patts[, filters], files = { ..., file }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"selectFolderDialog", [](lua_State * L)
|
||||||
|
{
|
||||||
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
|
|
||||||
|
const char * title = GetStrOrBlank(L, "title");
|
||||||
|
const char * def_path = GetStrOrBlank(L, "default_path");
|
||||||
|
|
||||||
|
return StringResponse(L, tinyfd_selectFolderDialog(title, def_path)); // opts, folder
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"colorChooser", [](lua_State * L)
|
||||||
|
{
|
||||||
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
|
lua_settop(L, 1); // opts
|
||||||
|
lua_getfield(L, 1, "out_rgb"); // opts, out
|
||||||
|
|
||||||
|
const char * title = GetStrOrBlank(L, "title");
|
||||||
|
|
||||||
|
//
|
||||||
|
unsigned char rgb[3];
|
||||||
|
|
||||||
|
lua_getfield(L, 1, "rgb"); // opts, out, rgb
|
||||||
|
|
||||||
|
const char * def_hex_rgb = NULL;
|
||||||
|
|
||||||
|
if (lua_istable(L, 3))
|
||||||
|
{
|
||||||
|
lua_getfield(L, 3, "r");// opts, out, rgb, r
|
||||||
|
lua_getfield(L, 3, "g");// opts, out, rgb, r, g
|
||||||
|
lua_getfield(L, 3, "b");// opts, out, rgb, r, g, b
|
||||||
|
|
||||||
|
for (int i = 1; i <= 3; ++i) rgb[i - 1] = (unsigned char)(luaL_checknumber(L, 3 + i) * 255.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
else def_hex_rgb = luaL_optstring(L, 3, "#000000");
|
||||||
|
|
||||||
|
const char * color = tinyfd_colorChooser(title, def_hex_rgb, rgb, rgb);
|
||||||
|
|
||||||
|
if (color && lua_istable(L, 2))
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 3; ++i) lua_pushnumber(L, (double)rgb[i] / 255.0); // opts, out, rgb[, r, g, b], rout, gout, bout
|
||||||
|
|
||||||
|
lua_setfield(L, 2, "b");// opts, out, rgb[, r, g, b], rout, gout
|
||||||
|
lua_setfield(L, 2, "g");// opts, out, rgb[, r, g, b], rout
|
||||||
|
lua_setfield(L, 2, "r");// opts, out, rgb[, r, g, b]
|
||||||
|
}
|
||||||
|
|
||||||
|
return StringResponse(L, color);// opts, out, rgb[, r, g, b], color
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
CORONA_EXPORT int luaopen_plugin_tinyfiledialogs(lua_State* L)
|
||||||
|
{
|
||||||
|
lua_newtable(L);// t
|
||||||
|
luaL_register(L, NULL, tfd_funcs);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
{ SPDX-License-Identifier: ZLIB
|
||||||
|
Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
|
||||||
|
|
||||||
|
found on this page:
|
||||||
|
https://github.com/pascalabcnet/pascalabcnet/discussions/2782
|
||||||
|
}
|
||||||
|
|
||||||
|
unit tinyfd;
|
||||||
|
|
||||||
|
uses System;
|
||||||
|
|
||||||
|
procedure tinyfd_beep(); external 'tinyfiledialogs64.dll';
|
||||||
|
|
||||||
|
function tinyfd_notifyPopup(aTitle: string;
|
||||||
|
aMessage: string;
|
||||||
|
aIconType: string): integer;
|
||||||
|
external 'tinyfiledialogs64.dll';
|
||||||
|
|
||||||
|
function tinyfd_messageBox(aTitle: string;
|
||||||
|
aMessage: string;
|
||||||
|
aDialogTyle: string;
|
||||||
|
aIconType: string;
|
||||||
|
aDefaultButton: integer): integer;
|
||||||
|
external 'tinyfiledialogs64.dll';
|
||||||
|
|
||||||
|
function tinyfd_inputBox(aTitle: string;
|
||||||
|
aMessage: string;
|
||||||
|
aDefaultInput: string): IntPtr;
|
||||||
|
external 'tinyfiledialogs64.dll';
|
||||||
|
|
||||||
|
function tinyfd_saveFileDialog(aTitle: string;
|
||||||
|
aDefaultPathAndFile: string;
|
||||||
|
aNumOfFilterPatterns: integer;
|
||||||
|
aFilterPatterns: array of string;
|
||||||
|
aSingleFilterDescription: string): IntPtr;
|
||||||
|
external 'tinyfiledialogs64.dll';
|
||||||
|
|
||||||
|
function tinyfd_openFileDialog(aTitle: string;
|
||||||
|
aDefaultPathAndFile: string;
|
||||||
|
aNumOfFilterPatterns: integer;
|
||||||
|
aFilterPatterns: array of string;
|
||||||
|
aSingleFilterDescription: string;
|
||||||
|
aAllowMultipleSelects: integer): IntPtr;
|
||||||
|
external 'tinyfiledialogs64.dll';
|
||||||
|
|
||||||
|
function tinyfd_selectFolderDialog(aTitle: string;
|
||||||
|
aDefaultPathAndFile: string): IntPtr;
|
||||||
|
external 'tinyfiledialogs64.dll';
|
||||||
|
|
||||||
|
function tinyfd_colorChooser(aTitle: string;
|
||||||
|
aDefaultHexRGB: string;
|
||||||
|
aDefaultRGB: array of byte;
|
||||||
|
aoResultRGB: array of byte): IntPtr;
|
||||||
|
external 'tinyfiledialogs64.dll';
|
||||||
|
|
||||||
|
end.
|
@ -0,0 +1,185 @@
|
|||||||
|
! SPDX-License-Identifier: ZLIB
|
||||||
|
! Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
|
||||||
|
! _________
|
||||||
|
! / \ tinyfiledialogs v3.18.1 [May 26, 2024]
|
||||||
|
! |tiny file|
|
||||||
|
! | dialogs |
|
||||||
|
! \____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
! \| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
|
||||||
|
! - License -
|
||||||
|
! This software is provided 'as-is', without any express or implied
|
||||||
|
! warranty. In no event will the authors be held liable for any damages
|
||||||
|
! arising from the use of this software.
|
||||||
|
! Permission is granted to anyone to use this software for any purpose,
|
||||||
|
! including commercial applications, and to alter it and redistribute it
|
||||||
|
! freely, subject to the following restrictions:
|
||||||
|
! 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
! claim that you wrote the original software. If you use this software
|
||||||
|
! in a product, an acknowledgment in the product documentation would be
|
||||||
|
! appreciated but is not required.
|
||||||
|
! 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
! misrepresented as being the original software.
|
||||||
|
! 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
! ___________________________________________________________
|
||||||
|
! | |
|
||||||
|
! | If you like this new FORTRAN module please upvote |
|
||||||
|
! | my stackoverflow answer on the FORTRAN post |
|
||||||
|
! | https://stackoverflow.com/a/59657117 |
|
||||||
|
! |___________________________________________________________|
|
||||||
|
|
||||||
|
! See compilation instructions at the end of this file
|
||||||
|
|
||||||
|
program main
|
||||||
|
use tinyfd
|
||||||
|
use iso_c_binding, only: c_ptr, c_null_char, c_f_pointer, c_loc, c_null_ptr, c_associated, c_int, c_char
|
||||||
|
implicit none
|
||||||
|
type(c_ptr) :: cpointer
|
||||||
|
character(512), pointer :: fpointer
|
||||||
|
character(128), target :: aDefaultInput
|
||||||
|
character(512) :: string, aMessage, aDefaultPath, aDefaultPathAndFile
|
||||||
|
character(128) :: aTitle, aDialogType, aIconType
|
||||||
|
character(128) :: aSingleFilterDescription
|
||||||
|
integer :: i, aInteger, aButtonPressed, aDefaultButton, aNumOfFilterPatterns, aAllowMultipleSelects
|
||||||
|
character(8) :: aDefaultHexRGB
|
||||||
|
character(3) :: aDefaultRGB, aoResultRGB
|
||||||
|
type (c_ptr), dimension(:), allocatable :: aFilterPatterns
|
||||||
|
character(len=16,kind=c_char), allocatable, target :: lExtensions(:)
|
||||||
|
|
||||||
|
! calling subroutine tinyfd_beep (it doesn't return anything: it's a subroutine')
|
||||||
|
write(*,'(A)') "Enter tinyfd_beep()"
|
||||||
|
call tinyfd_beep()
|
||||||
|
|
||||||
|
! calling function tinyfd_notifyPopup (it returns one value: it's a function')
|
||||||
|
write(*,'(A)') "Enter tinyfd_notifyPopup()"
|
||||||
|
aTitle = "a Title" // char(0)
|
||||||
|
aMessage = "a Message" // char(0)
|
||||||
|
aIconType = "info" // char(0)
|
||||||
|
aInteger = tinyfd_notifyPopup(aTitle, aMessage, aIconType )
|
||||||
|
|
||||||
|
! calling function tinyfd_messageBox
|
||||||
|
write(*,'(A)') "Enter tinyfd_messageBox()"
|
||||||
|
aTitle = "a Title" // char(0)
|
||||||
|
aMessage = "a Message" // char(0)
|
||||||
|
aIconType = "info" // char(0)
|
||||||
|
aDialogType = "ok" // char(0)
|
||||||
|
aDefaultButton = 1
|
||||||
|
aButtonPressed = tinyfd_messageBox(aTitle, aMessage, aDialogType, aIconType, aDefaultButton )
|
||||||
|
write (*,*) aButtonPressed
|
||||||
|
|
||||||
|
! calling function tinyfd_inputbox
|
||||||
|
write(*,'(A)') "Enter tinyfd_inputbox()"
|
||||||
|
aTitle = "a Title" // char(0)
|
||||||
|
aMessage = "a Message" // char(0)
|
||||||
|
aDefaultInput = "an Input" // char(0)
|
||||||
|
cpointer = tinyfd_inputBox(aTitle, aMessage, c_loc(aDefaultInput) )
|
||||||
|
! or for a password box: cpointer = tinyfd_inputbox(atitle, amessage, c_null_ptr )
|
||||||
|
if ( c_associated(cpointer) ) then
|
||||||
|
call c_f_pointer(cpointer, fpointer) ! Convert C Pointer to Fortran pointer
|
||||||
|
string = fpointer(1:index(fpointer,c_null_char)-1) ! Remove NULL character at the end
|
||||||
|
write (*,'(A)') string
|
||||||
|
endif
|
||||||
|
|
||||||
|
! calling function tinyfd_saveFileDialog
|
||||||
|
write(*,'(A)') "Enter tinyfd_saveFileDialog()"
|
||||||
|
aTitle = "a Title" // char(0)
|
||||||
|
aDefaultPathAndFile = "" // char(0)
|
||||||
|
aSingleFilterDescription = "" // char(0) ! or "Text Files" // char(0)
|
||||||
|
aNumOfFilterPatterns = 2
|
||||||
|
allocate (lExtensions( aNumOfFilterPatterns ))
|
||||||
|
allocate (aFilterPatterns( aNumOfFilterPatterns ))
|
||||||
|
lExtensions(1) = "*.txt" // char(0)
|
||||||
|
lExtensions(2) = "*.doc" // char(0)
|
||||||
|
do i = 1, aNumOfFilterPatterns, 1
|
||||||
|
aFilterPatterns(i) = c_loc(lExtensions(i))
|
||||||
|
write (*,'(A)') lExtensions(i)
|
||||||
|
!write (*,*) aFilterPatterns(i)
|
||||||
|
end do
|
||||||
|
cpointer = tinyfd_saveFileDialog(aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, aSingleFilterDescription)
|
||||||
|
! or cpointer = tinyfd_saveFileDialog(aTitle, aDefaultPathAndFile, 0, c_null_ptr, aSingleFilterDescription)
|
||||||
|
deallocate (aFilterPatterns)
|
||||||
|
deallocate (lExtensions)
|
||||||
|
if ( c_associated(cpointer) ) then
|
||||||
|
call c_f_pointer(cpointer, fpointer) ! Convert C Pointer to Fortran pointer
|
||||||
|
string = fpointer(1:index(fpointer,c_null_char)-1) ! Remove NULL character at the end
|
||||||
|
write (*,'(A)') string
|
||||||
|
endif
|
||||||
|
|
||||||
|
! calling function tinyfd_openFileDialog
|
||||||
|
write(*,'(A)') "Enter tinyfd_openFileDialog()"
|
||||||
|
aTitle = "a Title" // char(0)
|
||||||
|
aDefaultPathAndFile = "" // char(0)
|
||||||
|
aAllowMultipleSelects = 1
|
||||||
|
aSingleFilterDescription = "" // char(0) ! or "Text Files" // char(0)
|
||||||
|
aNumOfFilterPatterns = 2
|
||||||
|
allocate (lExtensions( aNumOfFilterPatterns ))
|
||||||
|
allocate (aFilterPatterns( aNumOfFilterPatterns ))
|
||||||
|
lExtensions(1) = "*.txt" // char(0)
|
||||||
|
lExtensions(2) = "*.doc" // char(0)
|
||||||
|
do i = 1, aNumOfFilterPatterns, 1
|
||||||
|
aFilterPatterns(i) = c_loc(lExtensions(i))
|
||||||
|
write (*,'(A)') lExtensions(i)
|
||||||
|
!write (*,*) aFilterPatterns(i)
|
||||||
|
end do
|
||||||
|
cpointer = tinyfd_openFileDialog(aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, &
|
||||||
|
aSingleFilterDescription, aAllowMultipleSelects)
|
||||||
|
! or cpointer = tinyfd_openFileDialog(aTitle, aDefaultPathAndFile, 0, c_null_ptr, aSingleFilterDescription, aAllowMultipleSelects)
|
||||||
|
deallocate (aFilterPatterns)
|
||||||
|
deallocate (lExtensions)
|
||||||
|
if ( c_associated(cpointer) ) then
|
||||||
|
call c_f_pointer(cpointer, fpointer) ! Convert C Pointer to Fortran pointer
|
||||||
|
string = fpointer(1:index(fpointer,c_null_char)-1) ! Remove NULL character at the end
|
||||||
|
write (*,'(A)') string
|
||||||
|
endif
|
||||||
|
|
||||||
|
! calling function tinyfd_selectFolderDialog
|
||||||
|
write(*,'(A)') "Enter tinyfd_selectFolderDialog()"
|
||||||
|
aTitle = "a Title" // char(0)
|
||||||
|
aDefaultPath = "" // char(0)
|
||||||
|
cpointer = tinyfd_selectFolderDialog(aTitle, aDefaultPath )
|
||||||
|
if ( c_associated(cpointer) ) then
|
||||||
|
call c_f_pointer(cpointer, fpointer) ! Convert C Pointer to Fortran pointer
|
||||||
|
string = fpointer(1:index(fpointer,c_null_char)-1) ! Remove NULL character at the end
|
||||||
|
write (*,'(A)') string
|
||||||
|
endif
|
||||||
|
|
||||||
|
! calling function tinyfd_colorChooser
|
||||||
|
write(*,'(A)') "Enter tinyfd_colorChooser()"
|
||||||
|
aTitle = "a Title" // char(0)
|
||||||
|
aDefaultHexRGB = "" // char(0) ! or "#FF0000" // char(0)
|
||||||
|
aDefaultRGB = char(0) // char(0) // char(255)
|
||||||
|
print *, "aDefaultRGB", IACHAR(aDefaultRGB(1:1)), IACHAR(aDefaultRGB(2:2)), IACHAR(aDefaultRGB(3:3))
|
||||||
|
cpointer = tinyfd_colorChooser(aTitle, aDefaultHexRGB, aDefaultRGB, aoResultRGB )
|
||||||
|
print *, "aoResultRGB", IACHAR(aoResultRGB(1:1)), IACHAR(aoResultRGB(2:2)), IACHAR(aoResultRGB(3:3))
|
||||||
|
if ( c_associated(cpointer) ) then
|
||||||
|
call c_f_pointer(cpointer, fpointer) ! Convert C Pointer to Fortran pointer
|
||||||
|
string = fpointer(1:index(fpointer,c_null_char)-1) ! Remove NULL character at the end
|
||||||
|
write (*,'(A)') string(1:10)
|
||||||
|
write (*,*) string
|
||||||
|
endif
|
||||||
|
|
||||||
|
end program main
|
||||||
|
|
||||||
|
! gcc -c ../../tinyfiledialogs.c
|
||||||
|
! gfortran -c tinyfd_module.f90 tinyfd_main.f90
|
||||||
|
! gfortran -o tinyfd_exe tinyfd_module.o tinyfiledialogs.o tinyfd_main.o
|
||||||
|
|
||||||
|
! or in one line : gfortran -o tinyfd_exe tinyfd_module.f90 ../../tinyfiledialogs.c tinyfd_main.f90
|
||||||
|
|
||||||
|
! This works on VisualStudio with Intel Fortran (make sure the C project has very similar settings as your fortran project):
|
||||||
|
________________________________________________________________________
|
||||||
|
! 1) | Install The Windows SDK |
|
||||||
|
! | http://developer.microsoft.com/en-us/windows/downloads/windows-sdk |
|
||||||
|
! | The end user doesn't need to install anythings |
|
||||||
|
! |________________________________________________________________________|
|
||||||
|
! 2) Create a new empty C/C++ project, verify the configuration is for X64.
|
||||||
|
! 3) Add existing files: tinyfiledialogs.c and tinyfiledialogs.h
|
||||||
|
! 4) Build this project. It will fail because there is no main(),
|
||||||
|
! but it will create tinyfiledialogs.obj
|
||||||
|
! 5) Create a new empty Fortran project, verify the configuration is for X64.
|
||||||
|
! 6) Add existing file: tinyfiledialogs.obj - the one that was created on 4)
|
||||||
|
! 7) Add existing files: tinyfd_module.f90 and tinyfd_main.f90
|
||||||
|
! 8) In the properties of this fortran project, in the linker input field,
|
||||||
|
! add: comdlg32.lib ole32.lib user32.lib shell32.lib
|
||||||
|
! or maybe add: %(AdditionalDependencies)
|
||||||
|
! 9) Build and Run. Voila !
|
@ -0,0 +1,101 @@
|
|||||||
|
! SPDX-License-Identifier: ZLIB
|
||||||
|
! Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
|
||||||
|
! _________
|
||||||
|
! / \ tinyfiledialogs v3.18.1 [Mar 26, 2024]
|
||||||
|
! |tiny file|
|
||||||
|
! | dialogs |
|
||||||
|
! \____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
! \| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
|
||||||
|
! - License -
|
||||||
|
! This software is provided 'as-is', without any express or implied
|
||||||
|
! warranty. In no event will the authors be held liable for any damages
|
||||||
|
! arising from the use of this software.
|
||||||
|
! Permission is granted to anyone to use this software for any purpose,
|
||||||
|
! including commercial applications, and to alter it and redistribute it
|
||||||
|
! freely, subject to the following restrictions:
|
||||||
|
! 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
! claim that you wrote the original software. If you use this software
|
||||||
|
! in a product, an acknowledgment in the product documentation would be
|
||||||
|
! appreciated but is not required.
|
||||||
|
! 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
! misrepresented as being the original software.
|
||||||
|
! 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
! ___________________________________________________________
|
||||||
|
! | |
|
||||||
|
! | If you like this new FORTRAN module please upvote |
|
||||||
|
! | my stackoverflow answer on the FORTRAN post |
|
||||||
|
! | https://stackoverflow.com/a/59657117 |
|
||||||
|
! |___________________________________________________________|
|
||||||
|
|
||||||
|
! See compilation instructions at the end of tinyfd_main.f90
|
||||||
|
|
||||||
|
module tinyfd
|
||||||
|
interface ! C interface
|
||||||
|
|
||||||
|
! it doesn't return anything -> it's a subroutine
|
||||||
|
subroutine tinyfd_beep() bind(C, name='tinyfd_beep')
|
||||||
|
implicit none
|
||||||
|
end subroutine tinyfd_beep
|
||||||
|
|
||||||
|
! it returns one value -> it's a function
|
||||||
|
integer function tinyfd_notifyPopup(aTitle, aMessage, aIconType) bind(c, NAME='tinyfd_notifyPopup')
|
||||||
|
use iso_c_binding, only: c_char
|
||||||
|
implicit none
|
||||||
|
character (kind=c_char, len=1) :: aTitle, aMessage, aIconType
|
||||||
|
end function tinyfd_notifyPopup
|
||||||
|
|
||||||
|
! it returns one value -> it's a function
|
||||||
|
integer function tinyfd_messageBox(aTitle, aMessage, aDialogType, aIconType, aDefaultButton) bind(c,NAME='tinyfd_messageBox')
|
||||||
|
use iso_c_binding, only: c_char, c_int
|
||||||
|
implicit none
|
||||||
|
character (kind=c_char, len=1) :: aTitle, aMessage, aDialogType, aIconType
|
||||||
|
integer(c_int), value :: aDefaultButton
|
||||||
|
end function tinyfd_messageBox
|
||||||
|
|
||||||
|
! it returns one value -> it's a function
|
||||||
|
type(c_ptr) function tinyfd_inputBox(aTitle, aMessage, aDefaultInput) bind(c,NAME='tinyfd_inputBox')
|
||||||
|
use iso_c_binding, only: c_ptr, c_char
|
||||||
|
implicit none
|
||||||
|
character (kind=c_char, len=1) :: aTitle, aMessage
|
||||||
|
! aDefaultInput is a bit different because we need to be able
|
||||||
|
! to pass c_null_ptr to obtain a password box instead of an input box
|
||||||
|
type(c_ptr), value :: aDefaultInput
|
||||||
|
end function tinyfd_inputBox
|
||||||
|
|
||||||
|
! it returns one value -> it's a function
|
||||||
|
type(c_ptr) function tinyfd_saveFileDialog(aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, &
|
||||||
|
aSingleFilterDescription) bind(c,NAME='tinyfd_saveFileDialog')
|
||||||
|
use iso_c_binding, only: c_ptr, c_char, c_int
|
||||||
|
implicit none
|
||||||
|
integer(c_int), value :: aNumOfFilterPatterns
|
||||||
|
character (kind=c_char, len=1) :: aTitle, aDefaultPathAndFile, aSingleFilterDescription
|
||||||
|
type (c_ptr), dimension(*) :: aFilterPatterns
|
||||||
|
end function tinyfd_saveFileDialog
|
||||||
|
|
||||||
|
! it returns one value -> it's a function
|
||||||
|
type(c_ptr) function tinyfd_openFileDialog(aTitle, aDefaultPathAndFile, aNumOfFilterPatterns, aFilterPatterns, &
|
||||||
|
aSingleFilterDescription, aAllowMultipleSelects) bind(c,NAME='tinyfd_openFileDialog')
|
||||||
|
use iso_c_binding, only: c_ptr, c_char, c_int
|
||||||
|
implicit none
|
||||||
|
integer(c_int), value :: aNumOfFilterPatterns, aAllowMultipleSelects
|
||||||
|
character (kind=c_char, len=1) :: aTitle, aDefaultPathAndFile, aSingleFilterDescription
|
||||||
|
type (c_ptr), dimension(*) :: aFilterPatterns
|
||||||
|
end function tinyfd_openFileDialog
|
||||||
|
|
||||||
|
! it returns one value -> it's a function
|
||||||
|
type(c_ptr) function tinyfd_selectFolderDialog(aTitle, aDefaultPath) bind(c,NAME='tinyfd_selectFolderDialog')
|
||||||
|
use iso_c_binding, only: c_ptr, c_char
|
||||||
|
implicit none
|
||||||
|
character (kind=c_char, len=1) :: aTitle, aDefaultPath
|
||||||
|
end function tinyfd_selectFolderDialog
|
||||||
|
|
||||||
|
! it returns one value -> it's a function
|
||||||
|
type(c_ptr) function tinyfd_colorChooser(aTitle, aDefaultHexRGB, aDefaultRGB, aoResultRGB) bind(c,NAME='tinyfd_colorChooser')
|
||||||
|
use iso_c_binding, only: c_ptr, c_char, c_int
|
||||||
|
implicit none
|
||||||
|
character (kind=c_char, len=1) :: aTitle, aDefaultHexRGB, aDefaultRGB, aoResultRGB
|
||||||
|
end function tinyfd_colorChooser
|
||||||
|
|
||||||
|
end interface ! C interface
|
||||||
|
end module tinyfd
|
@ -0,0 +1,91 @@
|
|||||||
|
{ SPDX-License-Identifier: ZLIB
|
||||||
|
Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
|
||||||
|
_________
|
||||||
|
/ \ tinyfiledialogs v3.13 [May 2, 2023] zlib licence
|
||||||
|
|tiny file|
|
||||||
|
| dialogs |
|
||||||
|
\____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
|
||||||
|
- License -
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
___________________________________________________________
|
||||||
|
| |
|
||||||
|
| If you like this new PASCAL module please upvote |
|
||||||
|
| my stackoverflow answer on the PASCAL post |
|
||||||
|
| https://stackoverflow.com/a/59657117 |
|
||||||
|
|___________________________________________________________|
|
||||||
|
|
||||||
|
See compilation instructions at the end of this file
|
||||||
|
}
|
||||||
|
|
||||||
|
program Hello ;
|
||||||
|
|
||||||
|
uses tinyfd ;
|
||||||
|
|
||||||
|
var
|
||||||
|
lReturnedChar : Pchar;
|
||||||
|
lReturnedValue : Integer ;
|
||||||
|
lCReturnedString: String ;
|
||||||
|
lArrayOfChar: array[0..2] of byte = (0,0,255);
|
||||||
|
|
||||||
|
begin
|
||||||
|
writeln ('Hello tinyfd');
|
||||||
|
tinyfd_beep();
|
||||||
|
|
||||||
|
lReturnedChar := tinyfd_inputBox('tinyfd_query', '', '');
|
||||||
|
writeln (tinyfd_response);
|
||||||
|
if lReturnedChar <> nil then
|
||||||
|
lReturnedValue := tinyfd_messageBox('Graphic Mode',tinyfd_response, 'okcancel', 'info', 1)
|
||||||
|
else
|
||||||
|
lReturnedValue := tinyfd_messageBox('Console Mode',tinyfd_response, 'okcancel', 'info', 1);
|
||||||
|
|
||||||
|
if lReturnedValue = 0 then exit;
|
||||||
|
|
||||||
|
lReturnedValue := tinyfd_messageBox('A tinyfd title','graphic dialogs [Yes] / console mode [No]', 'yesno', 'question', 1);
|
||||||
|
if lReturnedValue = 0 then tinyfd_forceConsole := 1 ;
|
||||||
|
|
||||||
|
tinyfd_notifyPopup('A tinyfd title', 'This is a notification', 'warning');
|
||||||
|
|
||||||
|
lReturnedChar := tinyfd_inputBox('A tinyfd title','This is an input box', '');
|
||||||
|
if lReturnedChar = nil then exit; { detect cancel was pressed - no input is allowed }
|
||||||
|
lCReturnedString := StrPas(lReturnedChar);
|
||||||
|
writeln (lCReturnedString);
|
||||||
|
|
||||||
|
lCReturnedString := tinyfd_inputBox('A tinyfd title','This is a password box', nil);
|
||||||
|
writeln (lCReturnedString);
|
||||||
|
if Length(lCReturnedString) = 0 then exit; { detect no input }
|
||||||
|
|
||||||
|
lCReturnedString := tinyfd_saveFileDialog('Choose a filename to save to','lala.txt', 0, nil,nil);
|
||||||
|
writeln (lCReturnedString);
|
||||||
|
if Length(lCReturnedString) = 0 then exit;
|
||||||
|
|
||||||
|
lCReturnedString := tinyfd_openFileDialog('Choose a filename to read from','../lala.txt', 0, nil, nil, 0);
|
||||||
|
writeln (lCReturnedString);
|
||||||
|
if Length(lCReturnedString) = 0 then exit;
|
||||||
|
|
||||||
|
lCReturnedString := tinyfd_selectFolderDialog('Select a folder','../..');
|
||||||
|
writeln (lCReturnedString);
|
||||||
|
if Length(lCReturnedString) = 0 then exit;
|
||||||
|
|
||||||
|
lCReturnedString := tinyfd_colorChooser('A tinyfd title','', lArrayOfChar, lArrayOfChar);
|
||||||
|
writeln (lCReturnedString);
|
||||||
|
end.
|
||||||
|
|
||||||
|
{
|
||||||
|
gcc -c ../../tinyfiledialogs.c
|
||||||
|
fpc tinyfd.pp
|
||||||
|
fpc hello.pas
|
||||||
|
}
|
138
tinyfiledialogs/dll_cs_lua_R_fortran_pascal/freepascal/tinyfd.pp
Normal file
138
tinyfiledialogs/dll_cs_lua_R_fortran_pascal/freepascal/tinyfd.pp
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
{ SPDX-License-Identifier: ZLIB
|
||||||
|
Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
|
||||||
|
_________
|
||||||
|
/ \ tinyfiledialogs v3.13 [May 2, 2023] zlib licence
|
||||||
|
|tiny file|
|
||||||
|
| dialogs |
|
||||||
|
\____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
|
||||||
|
- License -
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
___________________________________________________________
|
||||||
|
| |
|
||||||
|
| If you like this new PASCAL module please upvote |
|
||||||
|
| my stackoverflow answer on the PASCAL post |
|
||||||
|
| https://stackoverflow.com/a/59657117 |
|
||||||
|
|___________________________________________________________|
|
||||||
|
}
|
||||||
|
|
||||||
|
unit tinyfd;
|
||||||
|
interface
|
||||||
|
|
||||||
|
{$linklib c}
|
||||||
|
|
||||||
|
{ Adapted from
|
||||||
|
Automatically converted by H2Pas 1.0.0 from ../../tinyfiledialogs.h
|
||||||
|
The following command line parameters were used:
|
||||||
|
../../tinyfiledialogs.h
|
||||||
|
-o
|
||||||
|
tinyfd.pp
|
||||||
|
}
|
||||||
|
|
||||||
|
Type
|
||||||
|
Pchar = ^char;
|
||||||
|
|
||||||
|
{$ifdef _WIN32}
|
||||||
|
Pwchar_t = ^wchar_t;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
|
||||||
|
{$IFDEF FPC}
|
||||||
|
{$PACKRECORDS C}
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
{$ifdef _WIN32}
|
||||||
|
var
|
||||||
|
tinyfd_winUtf8 : longint;cvar;external;
|
||||||
|
|
||||||
|
function tinyfd_utf8toMbcs(aUtf8string:Pchar):Pchar;cdecl;
|
||||||
|
function tinyfd_utf16toMbcs(aUtf16string:Pwchar_t):Pchar;cdecl;
|
||||||
|
function tinyfd_mbcsTo16(aMbcsString:Pchar):Pwchar_t;cdecl;
|
||||||
|
function tinyfd_mbcsTo8(aMbcsString:Pchar):Pchar;cdecl;
|
||||||
|
function tinyfd_utf8to16(aUtf8string:Pchar):Pwchar_t;cdecl;
|
||||||
|
function tinyfd_utf16to8(aUtf16string:Pwchar_t):Pchar;cdecl;
|
||||||
|
{$endif}
|
||||||
|
|
||||||
|
function tinyfd_getGlobalChar(aCharVariableName:Pchar):Pchar;cdecl;
|
||||||
|
function tinyfd_getGlobalInt(aIntVariableName:Pchar):longint;cdecl;
|
||||||
|
function tinyfd_setGlobalInt(aIntVariableName:Pchar; aValue:longint):longint;cdecl;
|
||||||
|
|
||||||
|
var
|
||||||
|
tinyfd_version : array[0..7] of char;cvar;external;
|
||||||
|
tinyfd_needs : Pchar;cvar;external;
|
||||||
|
tinyfd_verbose : longint;cvar;external;
|
||||||
|
tinyfd_silent : longint;cvar;external;
|
||||||
|
tinyfd_allowCursesDialogs : longint;cvar;external;
|
||||||
|
tinyfd_forceConsole : longint;cvar;external;
|
||||||
|
tinyfd_assumeGraphicDisplay : longint;cvar;external;
|
||||||
|
tinyfd_response : array[0..1023] of char;cvar;external;
|
||||||
|
|
||||||
|
procedure tinyfd_beep;cdecl;
|
||||||
|
function tinyfd_notifyPopup(aTitle:Pchar; aMessage:Pchar; aIconType:Pchar):longint;cdecl;
|
||||||
|
function tinyfd_messageBox(aTitle:Pchar; aMessage:Pchar; aDialogType:Pchar; aIconType:Pchar; aDefaultButton:longint):longint;cdecl;
|
||||||
|
function tinyfd_inputBox(aTitle:Pchar; aMessage:Pchar; aDefaultInput:Pchar):Pchar;cdecl;
|
||||||
|
function tinyfd_saveFileDialog(aTitle:Pchar; aDefaultPathAndFile:Pchar; aNumOfFilterPatterns:longint; aFilterPatterns:PPchar; aSingleFilterDescription:Pchar):Pchar;cdecl;
|
||||||
|
function tinyfd_openFileDialog(aTitle:Pchar; aDefaultPathAndFile:Pchar; aNumOfFilterPatterns:longint; aFilterPatterns:PPchar; aSingleFilterDescription:Pchar;aAllowMultipleSelects:longint):Pchar;cdecl;
|
||||||
|
function tinyfd_selectFolderDialog(aTitle:Pchar; aDefaultPath:Pchar):Pchar;cdecl;
|
||||||
|
function tinyfd_colorChooser(aTitle:Pchar; aDefaultHexRGB:Pchar; aDefaultRGB:array of byte; aoResultRGB:array of byte):Pchar;cdecl;
|
||||||
|
|
||||||
|
{$ifdef _WIN32}
|
||||||
|
function tinyfd_notifyPopupW(aTitle:Pwchar_t; aMessage:Pwchar_t; aIconType:Pwchar_t):longint;cdecl;
|
||||||
|
function tinyfd_messageBoxW(aTitle:Pwchar_t; aMessage:Pwchar_t; aDialogType:Pwchar_t; aIconType:Pwchar_t; aDefaultButton:longint):longint;cdecl;
|
||||||
|
function tinyfd_inputBoxW(aTitle:Pwchar_t; aMessage:Pwchar_t; aDefaultInput:Pwchar_t):Pwchar_t;cdecl;
|
||||||
|
function tinyfd_saveFileDialogW(aTitle:Pwchar_t; aDefaultPathAndFile:Pwchar_t; aNumOfFilterPatterns:longint; aFilterPatterns:PPwchar_t; aSingleFilterDescription:Pwchar_t):Pwchar_t;cdecl;
|
||||||
|
function tinyfd_openFileDialogW(aTitle:Pwchar_t; aDefaultPathAndFile:Pwchar_t; aNumOfFilterPatterns:longint; aFilterPatterns:PPwchar_t; aSingleFilterDescription:Pwchar_t;aAllowMultipleSelects:longint):Pwchar_t;cdecl;
|
||||||
|
function tinyfd_selectFolderDialogW(aTitle:Pwchar_t; aDefaultPath:Pwchar_t):Pwchar_t;cdecl;
|
||||||
|
function tinyfd_colorChooserW(aTitle:Pwchar_t; aDefaultHexRGB:Pwchar_t; aDefaultRGB:array of byte; aoResultRGB:array of byte):Pwchar_t;cdecl;
|
||||||
|
{$endif}
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{$Link 'tinyfiledialogs.o'}
|
||||||
|
|
||||||
|
{$ifdef _WIN32}
|
||||||
|
function tinyfd_utf8toMbcs(aUtf8string:Pchar):Pchar;cdecl;external;
|
||||||
|
function tinyfd_utf16toMbcs(aUtf16string:Pwchar_t):Pchar;cdecl;external;
|
||||||
|
function tinyfd_mbcsTo16(aMbcsString:Pchar):Pwchar_t;cdecl;external;
|
||||||
|
function tinyfd_mbcsTo8(aMbcsString:Pchar):Pchar;cdecl;external;
|
||||||
|
function tinyfd_utf8to16(aUtf8string:Pchar):Pwchar_t;cdecl;external;
|
||||||
|
function tinyfd_utf16to8(aUtf16string:Pwchar_t):Pchar;cdecl;external;
|
||||||
|
{$endif}
|
||||||
|
|
||||||
|
function tinyfd_getGlobalChar(aCharVariableName:Pchar):Pchar;cdecl;external;
|
||||||
|
function tinyfd_getGlobalInt(aIntVariableName:Pchar):longint;cdecl;external;
|
||||||
|
function tinyfd_setGlobalInt(aIntVariableName:Pchar; aValue:longint):longint;cdecl;external;
|
||||||
|
|
||||||
|
procedure tinyfd_beep;cdecl;external;
|
||||||
|
function tinyfd_notifyPopup(aTitle:Pchar; aMessage:Pchar; aIconType:Pchar):longint;cdecl;external;
|
||||||
|
function tinyfd_messageBox(aTitle:Pchar; aMessage:Pchar; aDialogType:Pchar; aIconType:Pchar; aDefaultButton:longint):longint;cdecl;external;
|
||||||
|
function tinyfd_inputBox(aTitle:Pchar; aMessage:Pchar; aDefaultInput:Pchar):Pchar;cdecl;external;
|
||||||
|
function tinyfd_saveFileDialog(aTitle:Pchar; aDefaultPathAndFile:Pchar; aNumOfFilterPatterns:longint; aFilterPatterns:PPchar; aSingleFilterDescription:Pchar):Pchar;cdecl;external;
|
||||||
|
function tinyfd_openFileDialog(aTitle:Pchar; aDefaultPathAndFile:Pchar; aNumOfFilterPatterns:longint; aFilterPatterns:PPchar; aSingleFilterDescription:Pchar;aAllowMultipleSelects:longint):Pchar;cdecl;external;
|
||||||
|
function tinyfd_selectFolderDialog(aTitle:Pchar; aDefaultPath:Pchar):Pchar;cdecl;external;
|
||||||
|
function tinyfd_colorChooser(aTitle:Pchar; aDefaultHexRGB:Pchar; aDefaultRGB:array of byte; aoResultRGB:array of byte):Pchar;cdecl;external;
|
||||||
|
|
||||||
|
{$ifdef _WIN32}
|
||||||
|
function tinyfd_notifyPopupW(aTitle:Pwchar_t; aMessage:Pwchar_t; aIconType:Pwchar_t):longint;cdecl;external;
|
||||||
|
function tinyfd_messageBoxW(aTitle:Pwchar_t; aMessage:Pwchar_t; aDialogType:Pwchar_t; aIconType:Pwchar_t; aDefaultButton:longint):longint;cdecl;external;
|
||||||
|
function tinyfd_inputBoxW(aTitle:Pwchar_t; aMessage:Pwchar_t; aDefaultInput:Pwchar_t):Pwchar_t;cdecl;external;
|
||||||
|
function tinyfd_saveFileDialogW(aTitle:Pwchar_t; aDefaultPathAndFile:Pwchar_t; aNumOfFilterPatterns:longint; aFilterPatterns:PPwchar_t; aSingleFilterDescription:Pwchar_t):Pwchar_t;cdecl;external;
|
||||||
|
function tinyfd_openFileDialogW(aTitle:Pwchar_t; aDefaultPathAndFile:Pwchar_t; aNumOfFilterPatterns:longint; aFilterPatterns:PPwchar_t; aSingleFilterDescription:Pwchar_t;aAllowMultipleSelects:longint):Pwchar_t;cdecl;external;
|
||||||
|
function tinyfd_selectFolderDialogW(aTitle:Pwchar_t; aDefaultPath:Pwchar_t):Pwchar_t;cdecl;external;
|
||||||
|
function tinyfd_colorChooserW(aTitle:Pwchar_t; aDefaultHexRGB:Pwchar_t; aDefaultRGB:array of byte; aoResultRGB:array of byte):Pwchar_t;cdecl;external;
|
||||||
|
{$endif}
|
||||||
|
|
||||||
|
end.
|
157
tinyfiledialogs/dll_cs_lua_R_fortran_pascal/tinyfiledialogs.r
Normal file
157
tinyfiledialogs/dll_cs_lua_R_fortran_pascal/tinyfiledialogs.r
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
# SPDX-License-Identifier: ZLIB
|
||||||
|
# Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
|
||||||
|
# _________
|
||||||
|
# / \ tinyfiledialogs v3.14.0 [Sep 12, 2023]
|
||||||
|
# |tiny file|
|
||||||
|
# | dialogs |
|
||||||
|
# \____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
# \| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
|
||||||
|
# - License -
|
||||||
|
# This software is provided 'as-is', without any express or implied
|
||||||
|
# warranty. In no event will the authors be held liable for any damages
|
||||||
|
# arising from the use of this software.
|
||||||
|
# Permission is granted to anyone to use this software for any purpose,
|
||||||
|
# including commercial applications, and to alter it and redistribute it
|
||||||
|
# freely, subject to the following restrictions:
|
||||||
|
# 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
# claim that you wrote the original software. If you use this software
|
||||||
|
# in a product, an acknowledgment in the product documentation would be
|
||||||
|
# appreciated but is not required.
|
||||||
|
# 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
# misrepresented as being the original software.
|
||||||
|
# 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
# ___________________________________________________________
|
||||||
|
# | |
|
||||||
|
# | If you like this new R interface please upvote |
|
||||||
|
# | my stackoverflow answer on the R post |
|
||||||
|
# | https://stackoverflow.com/a/77091332 |
|
||||||
|
# |___________________________________________________________|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Load the appropriate tinyfd library
|
||||||
|
|
||||||
|
# Macintosh
|
||||||
|
dyn.load("tinyfiledialogsAppleSilicon.dylib")
|
||||||
|
#dyn.load("tinyfiledialogsIntel.dylib")
|
||||||
|
|
||||||
|
# Linux on Intel
|
||||||
|
#dyn.load("tinyfiledialogsLinux86.so")
|
||||||
|
#dyn.load("tinyfiledialogsLinux64.so")
|
||||||
|
|
||||||
|
# Windows on Intel
|
||||||
|
#dyn.load("tinyfiledialogs32.dll")
|
||||||
|
#dyn.load("tinyfiledialogs64.dll")
|
||||||
|
|
||||||
|
|
||||||
|
# R interface to tinyfd C functions
|
||||||
|
|
||||||
|
tinyfd_beep <- function() {
|
||||||
|
result <- .C("tinyfd_beep")
|
||||||
|
return(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tinyfd_notifyPopup <- function(aTitle, aMessage, aIconType)
|
||||||
|
{
|
||||||
|
result <- .C("tinyfd_notifyPopup",
|
||||||
|
charToRaw(aTitle),
|
||||||
|
charToRaw(aMessage),
|
||||||
|
charToRaw(aIconType))
|
||||||
|
|
||||||
|
return(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tinyfd_messageBox <- function(aTitle , aMessage , aDialogType , aIconType , aDefaultButton)
|
||||||
|
{
|
||||||
|
result <- .C("tfd_messageBox",
|
||||||
|
charToRaw(aTitle),
|
||||||
|
charToRaw(aMessage),
|
||||||
|
charToRaw(aDialogType),
|
||||||
|
charToRaw(aIconType),
|
||||||
|
lDefaultButton = as.integer(aDefaultButton) )
|
||||||
|
|
||||||
|
return(result$lDefaultButton)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tinyfd_inputBox <- function(aTitle , aMessage , aDefaultInput) # "NULL" for a password box
|
||||||
|
{
|
||||||
|
result <- .C("tfd_inputBox",
|
||||||
|
charToRaw(aTitle),
|
||||||
|
charToRaw(aMessage),
|
||||||
|
lTextOutput = aDefaultInput )
|
||||||
|
|
||||||
|
if ( result$lTextOutput == "NULL" ) return()
|
||||||
|
else return(result$lTextOutput)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tinyfd_saveFileDialog <- function(aTitle, aDefaultPathAndFile, aNumOfFilterPatterns,
|
||||||
|
aFilterPatterns, aSingleFilterDescription )
|
||||||
|
{
|
||||||
|
result <- .C("tfd_saveFileDialog",
|
||||||
|
charToRaw(aTitle),
|
||||||
|
lSaveFile = aDefaultPathAndFile ,
|
||||||
|
as.integer(aNumOfFilterPatterns) ,
|
||||||
|
aFilterPatterns ,
|
||||||
|
charToRaw(aSingleFilterDescription) )
|
||||||
|
|
||||||
|
if ( result$lSaveFile == "NULL" ) return()
|
||||||
|
else return(result$lSaveFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tinyfd_openFileDialog <- function(aTitle, aDefaultPathAndFile , aNumOfFilterPatterns,
|
||||||
|
aFilterPatterns, aSingleFilterDescription , aAllowMultipleSelects )
|
||||||
|
{
|
||||||
|
result <- .C("tfd_openFileDialog",
|
||||||
|
charToRaw(aTitle),
|
||||||
|
lOpenFile = aDefaultPathAndFile ,
|
||||||
|
as.integer(aNumOfFilterPatterns) ,
|
||||||
|
aFilterPatterns ,
|
||||||
|
charToRaw(aSingleFilterDescription) ,
|
||||||
|
as.integer(aAllowMultipleSelects) )
|
||||||
|
|
||||||
|
if ( result$lOpenFile == "NULL" ) return()
|
||||||
|
else return(result$lOpenFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tinyfd_selectFolderDialog <- function(aTitle, aDefaultPath)
|
||||||
|
{
|
||||||
|
result <- .C("tfd_selectFolderDialog",
|
||||||
|
charToRaw(aTitle),
|
||||||
|
lSelectedFolder = aDefaultPath )
|
||||||
|
|
||||||
|
if ( result$lSelectedFolder == "NULL" ) return()
|
||||||
|
else return(result$lSelectedFolder)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tinyfd_colorChooser <- function(aTitle, aDefaultHexRGB) # "#FF0000"
|
||||||
|
{
|
||||||
|
result <- .C("tfd_colorChooser",
|
||||||
|
charToRaw(aTitle),
|
||||||
|
lOutputHexRGB = aDefaultHexRGB )
|
||||||
|
|
||||||
|
if ( result$lOutputHexRGB == "NULL" ) return()
|
||||||
|
else return(result$lOutputHexRGB)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# example R calls to tinyfd functions
|
||||||
|
|
||||||
|
tinyfd_beep()
|
||||||
|
tinyfd_notifyPopup( "a title" , "a message", "warning" )
|
||||||
|
tinyfd_messageBox( "a title" , "a message" , "yesno" , "info" , 1 )
|
||||||
|
tinyfd_inputBox( "a title" , "a message" , "NULL" ) # "NULL" for a password box
|
||||||
|
tinyfd_saveFileDialog( "a title" , "/Users/bardos/Documents/test.txt" , 0 , "" , "")
|
||||||
|
tinyfd_saveFileDialog( "a title" , "/Users/bardos/Documents/test.txt" , 1 , c ("*.txt","*.jpg") , "some files")
|
||||||
|
lFilename <- tinyfd_openFileDialog( "a title" , "/Users/bardos/Documents/" , 1 , c ("*.txt","*.jpg") , "some files" , 0 )
|
||||||
|
lFilename
|
||||||
|
tinyfd_selectFolderDialog( "a title" , "/Users/bardos/Devs" )
|
||||||
|
tinyfd_colorChooser( "a title" , "#FF0000" )
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,153 @@
|
|||||||
|
<EFBFBD>©À/* SPDX-License-Identifier: ZLIB
|
||||||
|
Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
|
||||||
|
_________
|
||||||
|
/ \ tinyfiledialogsTest.cs v3.15.1 [Nov 19, 2023] zlib licence
|
||||||
|
|tiny file| C# bindings created [2015]
|
||||||
|
| dialogs |
|
||||||
|
\____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
____________________________________________
|
||||||
|
| |
|
||||||
|
| email: tinyfiledialogs at ysengrin.com |
|
||||||
|
|____________________________________________|
|
||||||
|
|
||||||
|
If you like tinyfiledialogs, please upvote my stackoverflow answer
|
||||||
|
https://stackoverflow.com/a/47651444
|
||||||
|
|
||||||
|
- License -
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
class tinyfd
|
||||||
|
{
|
||||||
|
public const string mDllLocation = "C:\\Users\\frogs\\yomspace2015\\yomlibs\\tinyfd\\dll_cs_lua_fortran_pascal\\tinyfiledialogs32.dll";
|
||||||
|
|
||||||
|
// cross platform UTF8
|
||||||
|
[DllImport(mDllLocation, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern void tinyfd_beep();
|
||||||
|
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern int tinyfd_notifyPopup(string aTitle, string aMessage, string aIconType);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern int tinyfd_messageBox(string aTitle, string aMessage, string aDialogType, string aIconType, int aDefaultButton);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern IntPtr tinyfd_inputBox(string aTitle, string aMessage, string aDefaultInput);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern IntPtr tinyfd_saveFileDialog(string aTitle, string aDefaultPathAndFile, int aNumOfFilterPatterns, string[] aFilterPatterns, string aSingleFilterDescription);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern IntPtr tinyfd_openFileDialog(string aTitle, string aDefaultPathAndFile, int aNumOfFilterPatterns, string[] aFilterPatterns, string aSingleFilterDescription, int aAllowMultipleSelects);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern IntPtr tinyfd_selectFolderDialog(string aTitle, string aDefaultPathAndFile);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern IntPtr tinyfd_colorChooser(string aTitle, string aDefaultHexRGB, byte[] aDefaultRGB, byte[] aoResultRGB);
|
||||||
|
|
||||||
|
// windows only utf16
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern int tinyfd_notifyPopupW(string aTitle, string aMessage, string aIconType);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern int tinyfd_messageBoxW(string aTitle, string aMessage, string aDialogType, string aIconType, int aDefaultButton);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern IntPtr tinyfd_inputBoxW(string aTitle, string aMessage, string aDefaultInput);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern IntPtr tinyfd_saveFileDialogW(string aTitle, string aDefaultPathAndFile, int aNumOfFilterPatterns, string[] aFilterPatterns, string aSingleFilterDescription);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern IntPtr tinyfd_openFileDialogW(string aTitle, string aDefaultPathAndFile, int aNumOfFilterPatterns, string[] aFilterPatterns, string aSingleFilterDescription, int aAllowMultipleSelects);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern IntPtr tinyfd_selectFolderDialogW(string aTitle, string aDefaultPathAndFile);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern IntPtr tinyfd_colorChooserW(string aTitle, string aDefaultHexRGB, byte[] aDefaultRGB, byte[] aoResultRGB);
|
||||||
|
|
||||||
|
// cross platform
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern IntPtr tinyfd_getGlobalChar(string aCharVariableName);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern int tinyfd_getGlobalInt(string aIntVariableName);
|
||||||
|
[DllImport(mDllLocation, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern int tinyfd_setGlobalInt(string aIntVariableName, int aValue);
|
||||||
|
|
||||||
|
// ******** a complicated way to access tinyfd's global variables
|
||||||
|
// [DllImport("kernel32.dll", SetLastError = true)] internal static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
|
||||||
|
// [DllImport("kernel32.dll", SetLastError = true)] internal static extern IntPtr LoadLibrary(string lpszLib);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ConsoleApplication1
|
||||||
|
{
|
||||||
|
class tinyfiledialogsTest
|
||||||
|
{
|
||||||
|
private static string stringFromAnsi(IntPtr ptr) // for UTF-8/char
|
||||||
|
{
|
||||||
|
return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string stringFromUni(IntPtr ptr) // for UTF-16/wchar_t
|
||||||
|
{
|
||||||
|
return System.Runtime.InteropServices.Marshal.PtrToStringUni(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
[STAThread]
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
// ******** a simple way to access tinyfd's global variables
|
||||||
|
IntPtr lTheVersionText = tinyfd.tinyfd_getGlobalChar("tinyfd_version");
|
||||||
|
string lTheVersionString = stringFromAnsi(lTheVersionText);
|
||||||
|
tinyfd.tinyfd_messageBox("tinyfd_version", lTheVersionString, "ok", "info", 1);
|
||||||
|
|
||||||
|
// cross platform utf-8
|
||||||
|
IntPtr lTheInputText = tinyfd.tinyfd_inputBox("input box", "gimme a string", "A text to input");
|
||||||
|
string lTheInputString = stringFromAnsi(lTheInputText);
|
||||||
|
int lala = tinyfd.tinyfd_messageBox("a message box char", lTheInputString, "ok", "warning", 1);
|
||||||
|
|
||||||
|
lTheInputText = tinyfd.tinyfd_selectFolderDialog("select a folder", "");
|
||||||
|
lTheInputString = stringFromAnsi(lTheInputText);
|
||||||
|
lala = tinyfd.tinyfd_messageBox("the chosen folder", lTheInputString, "ok", "warning", 1);
|
||||||
|
|
||||||
|
// windows only utf-16
|
||||||
|
IntPtr lAnotherInputTextW = tinyfd.tinyfd_inputBoxW("input box", "gimme another string", "Another text to input");
|
||||||
|
string lAnotherInputString = stringFromUni(lAnotherInputTextW);
|
||||||
|
int lili = tinyfd.tinyfd_messageBoxW("a message box wchar_t", lAnotherInputString, "ok", "info", 1);
|
||||||
|
|
||||||
|
lAnotherInputTextW = tinyfd.tinyfd_selectFolderDialogW("select a folderW", "");
|
||||||
|
lAnotherInputString = stringFromUni(lAnotherInputTextW);
|
||||||
|
lili = tinyfd.tinyfd_messageBoxW("a message box wchar_t", lAnotherInputString, "ok", "info", 1);
|
||||||
|
|
||||||
|
tinyfd.tinyfd_notifyPopupW("just a dummy warning", lTheVersionString, "warning");
|
||||||
|
|
||||||
|
// cross platform
|
||||||
|
tinyfd.tinyfd_beep();
|
||||||
|
|
||||||
|
// ******** a complicated way to access tinyfd's global variables (uncomment the last 2 lines in the class tinyfd above)
|
||||||
|
// IntPtr tinyfd_DLL = tinyfd.LoadLibrary(tinyfd.mDllLocation);
|
||||||
|
// if (tinyfd_DLL != IntPtr.Zero)
|
||||||
|
// {
|
||||||
|
// IntPtr lVersionAddr = tinyfd.GetProcAddress(tinyfd_DLL, "tinyfd_version");
|
||||||
|
// string lVersion = stringFromAnsi(lVersionAddr);
|
||||||
|
// IntPtr lForceConsoleAddr = tinyfd.GetProcAddress(tinyfd_DLL, "tinyfd_forceConsole");
|
||||||
|
// if (lForceConsoleAddr != IntPtr.Zero)
|
||||||
|
// {
|
||||||
|
// int lForceConsoleValue = Marshal.ReadInt32(lForceConsoleAddr);
|
||||||
|
// tinyfd.tinyfd_notifyPopup(lVersion, lForceConsoleValue.ToString(), "info");
|
||||||
|
// Marshal.WriteInt32(lForceConsoleAddr, 0);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
:: cd C:\Users\frogs\yomspace2015\yomlibs\tinyfd\dll_cs_lua_fortran_pascal
|
||||||
|
|
||||||
|
\MinGW32-49\bin\gcc -ansi -std=gnu89 -pedantic -Wstrict-prototypes -Wall -c ../tinyfiledialogs.c
|
||||||
|
\MinGW32-49\bin\dlltool --export-all-symbols -l tinyfiledialogs32.lib tinyfiledialogs.o --dllname tinyfiledialogs32.dll
|
||||||
|
\MinGW32-49\bin\gcc -shared -static-libgcc tinyfiledialogs.o -o tinyfiledialogs32.dll -LC:/MinGW/lib -lcomdlg32 -lole32
|
||||||
|
\MinGW32-49\bin\gcc -ansi -std=gnu89 -pedantic -Wstrict-prototypes -Wall -o hello32.exe ../hello.c tinyfiledialogs32.lib
|
||||||
|
\MinGW32-49\bin\gcc -ansi -std=gnu89 -pedantic -Wstrict-prototypes -Wall -o helloW32.exe ../hello_wchar_t.c tinyfiledialogs32.lib
|
||||||
|
|
||||||
|
\MinGW32-49\bin\gcc -pedantic -Wstrict-prototypes -Wall -c ../tinyfiledialogs.c
|
||||||
|
\MinGW32-49\bin\dlltool --export-all-symbols -l tinyfiledialogs32.lib tinyfiledialogs.o --dllname tinyfiledialogs32.dll
|
||||||
|
\MinGW32-49\bin\gcc -shared -static-libgcc tinyfiledialogs.o -o tinyfiledialogs32.dll -LC:/MinGW/lib -lcomdlg32 -lole32
|
||||||
|
\MinGW32-49\bin\gcc -pedantic -Wstrict-prototypes -Wall -o hello32.exe ../hello.c tinyfiledialogs32.lib
|
||||||
|
\MinGW32-49\bin\gcc -pedantic -Wstrict-prototypes -Wall -o helloW32.exe ../hello_wchar_t.c tinyfiledialogs32.lib
|
||||||
|
|
||||||
|
|
||||||
|
\MinGW32-63\bin\gcc -ansi -std=gnu89 -pedantic -Wstrict-prototypes -Wall -c ../tinyfiledialogs.c
|
||||||
|
\MinGW32-63\bin\dlltool --export-all-symbols -l tinyfiledialogs32.lib tinyfiledialogs.o --dllname tinyfiledialogs32.dll
|
||||||
|
\MinGW32-63\bin\gcc -shared -static-libgcc tinyfiledialogs.o -o tinyfiledialogs32.dll -LC:/MinGW63/lib -lcomdlg32 -lole32
|
||||||
|
\MinGW32-63\bin\gcc -ansi -std=gnu89 -pedantic -Wstrict-prototypes -Wall -o hello32.exe ../hello.c tinyfiledialogs32.lib
|
||||||
|
\MinGW32-63\bin\gcc -ansi -std=gnu89 -pedantic -Wstrict-prototypes -Wall -o helloW32.exe ../hello_wchar_t.c tinyfiledialogs32.lib
|
||||||
|
|
||||||
|
\MinGW32-63\bin\gcc -pedantic -Wstrict-prototypes -Wall -c ../tinyfiledialogs.c
|
||||||
|
\MinGW32-63\bin\dlltool --export-all-symbols -l tinyfiledialogs32.lib tinyfiledialogs.o --dllname tinyfiledialogs32.dll
|
||||||
|
\MinGW32-63\bin\gcc -shared -static-libgcc tinyfiledialogs.o -o tinyfiledialogs32.dll -LC:/MinGW63/lib -lcomdlg32 -lole32
|
||||||
|
\MinGW32-63\bin\gcc -pedantic -Wstrict-prototypes -Wall -o hello32.exe ../hello.c tinyfiledialogs32.lib
|
||||||
|
\MinGW32-63\bin\gcc -pedantic -Wstrict-prototypes -Wall -o helloW32.exe ../hello_wchar_t.c tinyfiledialogs32.lib
|
||||||
|
|
||||||
|
@REM -std=gnu89 -Ofast -std=c++11
|
@ -0,0 +1,29 @@
|
|||||||
|
:: cd C:\Users\frogs\yomspace2015\yomlibs\tinyfd\dll_cs_lua_fortran_pascal
|
||||||
|
|
||||||
|
:: x86
|
||||||
|
\mingw-w64-720\mingw32\bin\gcc -ansi -std=c89 -pedantic -Wstrict-prototypes -m32 -Wall -c ../tinyfiledialogs.c
|
||||||
|
\mingw-w64-720\mingw32\bin\dlltool --export-all-symbols -l tinyfiledialogs32.lib tinyfiledialogs.o --dllname tinyfiledialogs32.dll
|
||||||
|
\mingw-w64-720\mingw32\bin\gcc -m32 -shared -static-libgcc tinyfiledialogs.o -o tinyfiledialogs32.dll -L\mingw-w64-720\mingw32\lib -lcomdlg32 -lole32
|
||||||
|
\mingw-w64-720\mingw32\bin\gcc -ansi -std=c89 -pedantic -Wstrict-prototypes -m32 -Wall -o hello32.exe ../hello.c tinyfiledialogs32.lib
|
||||||
|
\mingw-w64-720\mingw32\bin\gcc -ansi -std=c89 -pedantic -Wstrict-prototypes -m32 -Wall -o helloW32.exe ../hello_wchar_t.c tinyfiledialogs32.lib
|
||||||
|
|
||||||
|
\mingw-w64-720\mingw32\bin\gcc -pedantic -Wstrict-prototypes -m32 -Wall -c ../tinyfiledialogs.c
|
||||||
|
\mingw-w64-720\mingw32\bin\dlltool --export-all-symbols -l tinyfiledialogs32.lib tinyfiledialogs.o --dllname tinyfiledialogs32.dll
|
||||||
|
\mingw-w64-720\mingw32\bin\gcc -m32 -shared -static-libgcc tinyfiledialogs.o -o tinyfiledialogs32.dll -L\mingw-w64-720\mingw32\lib -lcomdlg32 -lole32
|
||||||
|
\mingw-w64-720\mingw32\bin\gcc -pedantic -Wstrict-prototypes -m32 -Wall -o hello32.exe ../hello.c tinyfiledialogs32.lib
|
||||||
|
\mingw-w64-720\mingw32\bin\gcc -pedantic -Wstrict-prototypes -m32 -Wall -o helloW32.exe ../hello_wchar_t.c tinyfiledialogs32.lib
|
||||||
|
|
||||||
|
:: x64
|
||||||
|
\mingw-w64-720\mingw64\bin\gcc -ansi -std=c89 -pedantic -Wstrict-prototypes -m64 -Wall -c ../tinyfiledialogs.c
|
||||||
|
\mingw-w64-720\mingw64\bin\dlltool --export-all-symbols -l tinyfiledialogs64.lib tinyfiledialogs.o --dllname tinyfiledialogs64.dll
|
||||||
|
\mingw-w64-720\mingw64\bin\gcc -m64 -shared -static-libgcc tinyfiledialogs.o -o tinyfiledialogs64.dll -L\mingw-w64-720\mingw64\lib -lcomdlg32 -lole32
|
||||||
|
\mingw-w64-720\mingw64\bin\gcc -ansi -std=c89 -pedantic -Wstrict-prototypes -m64 -Wall -o hello64.exe ../hello.c tinyfiledialogs64.lib
|
||||||
|
\mingw-w64-720\mingw64\bin\gcc -ansi -std=c89 -pedantic -Wstrict-prototypes -m64 -Wall -o helloW64.exe ../hello_wchar_t.c tinyfiledialogs64.lib
|
||||||
|
|
||||||
|
\mingw-w64-720\mingw64\bin\gcc -pedantic -Wstrict-prototypes -m64 -Wall -c ../tinyfiledialogs.c
|
||||||
|
\mingw-w64-720\mingw64\bin\dlltool --export-all-symbols -l tinyfiledialogs64.lib tinyfiledialogs.o --dllname tinyfiledialogs64.dll
|
||||||
|
\mingw-w64-720\mingw64\bin\gcc -m64 -shared -static-libgcc tinyfiledialogs.o -o tinyfiledialogs64.dll -L\mingw-w64-720\mingw64\lib -lcomdlg32 -lole32
|
||||||
|
\mingw-w64-720\mingw64\bin\gcc -pedantic -Wstrict-prototypes -m64 -Wall -o hello64.exe ../hello.c tinyfiledialogs64.lib
|
||||||
|
\mingw-w64-720\mingw64\bin\gcc -pedantic -Wstrict-prototypes -m64 -Wall -o helloW64.exe ../hello_wchar_t.c tinyfiledialogs64.lib
|
||||||
|
|
||||||
|
@REM \mingw-w64\mingw64\bin\gcc -std=c89 -o hello.exe tinyfiledialogs.c hello.c -LC:\mingw-w64\mingw64\lib -lcomdlg32 -lole32
|
@ -0,0 +1,29 @@
|
|||||||
|
:: cd C:\Users\frogs\yomspace2015\yomlibs\tinyfd\dll_cs_lua_R_fortran_pascal
|
||||||
|
|
||||||
|
:: x86
|
||||||
|
\mingw-w64-13.2.0\mingw32\bin\gcc -ansi -std=c89 -pedantic -Wstrict-prototypes -m32 -Wall -c ..\tinyfiledialogs.c
|
||||||
|
\mingw-w64-13.2.0\mingw32\bin\dlltool --export-all-symbols -l tinyfiledialogs32.lib tinyfiledialogs.o --dllname tinyfiledialogs32.dll
|
||||||
|
\mingw-w64-13.2.0\mingw32\bin\gcc -m32 -shared -static-libgcc tinyfiledialogs.o -o tinyfiledialogs32.dll -L\mingw-w64-13.2.0\mingw32\lib -lcomdlg32 -lole32
|
||||||
|
\mingw-w64-13.2.0\mingw32\bin\gcc -ansi -std=c89 -pedantic -Wstrict-prototypes -m32 -Wall -o hello32.exe ..\hello.c tinyfiledialogs32.lib
|
||||||
|
\mingw-w64-13.2.0\mingw32\bin\gcc -ansi -std=c89 -pedantic -Wstrict-prototypes -m32 -Wall -o helloW32.exe ..\hello_wchar_t.c tinyfiledialogs32.lib
|
||||||
|
|
||||||
|
\mingw-w64-13.2.0\mingw32\bin\gcc -pedantic -Wstrict-prototypes -m32 -Wall -c ..\tinyfiledialogs.c
|
||||||
|
\mingw-w64-13.2.0\mingw32\bin\dlltool --export-all-symbols -l tinyfiledialogs32.lib tinyfiledialogs.o --dllname tinyfiledialogs32.dll
|
||||||
|
\mingw-w64-13.2.0\mingw32\bin\gcc -m32 -shared -static-libgcc tinyfiledialogs.o -o tinyfiledialogs32.dll -L\mingw-w64-13.2.0\mingw32\lib -lcomdlg32 -lole32
|
||||||
|
\mingw-w64-13.2.0\mingw32\bin\gcc -pedantic -Wstrict-prototypes -m32 -Wall -o hello32.exe ..\hello.c tinyfiledialogs32.lib
|
||||||
|
\mingw-w64-13.2.0\mingw32\bin\gcc -pedantic -Wstrict-prototypes -m32 -Wall -o helloW32.exe ..\hello_wchar_t.c tinyfiledialogs32.lib
|
||||||
|
|
||||||
|
:: x64
|
||||||
|
\mingw-w64-13.2.0\mingw64\bin\gcc -ansi -std=c89 -pedantic -Wstrict-prototypes -m64 -Wall -c ..\tinyfiledialogs.c
|
||||||
|
\mingw-w64-13.2.0\mingw64\bin\dlltool --export-all-symbols -l tinyfiledialogs64.lib tinyfiledialogs.o --dllname tinyfiledialogs64.dll
|
||||||
|
\mingw-w64-13.2.0\mingw64\bin\gcc -m64 -shared -static-libgcc tinyfiledialogs.o -o tinyfiledialogs64.dll -L\mingw-w64-13.2.0\mingw64\lib -lcomdlg32 -lole32
|
||||||
|
\mingw-w64-13.2.0\mingw64\bin\gcc -ansi -std=c89 -pedantic -Wstrict-prototypes -m64 -Wall -o hello64.exe ..\hello.c tinyfiledialogs64.lib
|
||||||
|
\mingw-w64-13.2.0\mingw64\bin\gcc -ansi -std=c89 -pedantic -Wstrict-prototypes -m64 -Wall -o helloW64.exe ..\hello_wchar_t.c tinyfiledialogs64.lib
|
||||||
|
|
||||||
|
\mingw-w64-13.2.0\mingw64\bin\gcc -pedantic -Wstrict-prototypes -m64 -Wall -c ..\tinyfiledialogs.c
|
||||||
|
\mingw-w64-13.2.0\mingw64\bin\dlltool --export-all-symbols -l tinyfiledialogs64.lib tinyfiledialogs.o --dllname tinyfiledialogs64.dll
|
||||||
|
\mingw-w64-13.2.0\mingw64\bin\gcc -m64 -shared -static-libgcc tinyfiledialogs.o -o tinyfiledialogs64.dll -L\mingw-w64-13.2.0\mingw64\lib -lcomdlg32 -lole32
|
||||||
|
\mingw-w64-13.2.0\mingw64\bin\gcc -pedantic -Wstrict-prototypes -m64 -Wall -o hello64.exe ..\hello.c tinyfiledialogs64.lib
|
||||||
|
\mingw-w64-13.2.0\mingw64\bin\gcc -pedantic -Wstrict-prototypes -m64 -Wall -o helloW64.exe ..\hello_wchar_t.c tinyfiledialogs64.lib
|
||||||
|
|
||||||
|
@REM \mingw-w64\mingw64\bin\gcc -std=c89 -o hello.exe tinyfiledialogs.c hello.c -LC:\mingw-w64\mingw64\lib -lcomdlg32 -lole32
|
@ -0,0 +1,18 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
# clang -c ../tinyfiledialogs.c
|
||||||
|
# clang -dynamiclib tinyfiledialogs.o -o tinyfiledialogsIntel.dylib
|
||||||
|
# clang -o hello.app ../hello.c ./tinyfiledialogsIntel.dylib
|
||||||
|
|
||||||
|
clang -c ../tinyfiledialogs.c
|
||||||
|
|
||||||
|
if [ `uname -s` = "Darwin" ]; then
|
||||||
|
echo Darwin
|
||||||
|
if [ `uname -m` = "x86_64" ]; then
|
||||||
|
echo x86_64
|
||||||
|
clang -dynamiclib tinyfiledialogs.o -o tinyfiledialogsIntel.dylib
|
||||||
|
elif [ `uname -m` = "arm64" ]; then
|
||||||
|
echo arm64
|
||||||
|
clang -dynamiclib tinyfiledialogs.o -o tinyfiledialogsAppleSilicon.dylib
|
||||||
|
fi
|
||||||
|
fi
|
@ -0,0 +1,19 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
if [ `uname -s` = "Linux" ]; then
|
||||||
|
echo Linux
|
||||||
|
gcc -m32 -fPIC -shared -o tinyfiledialogsLinux86.so ../tinyfiledialogs.c
|
||||||
|
gcc -m32 -o hello ../hello.c ./tinyfiledialogsLinux86.so
|
||||||
|
|
||||||
|
gcc -m64 -fPIC -shared -o tinyfiledialogsLinux64.so ../tinyfiledialogs.c
|
||||||
|
gcc -m64 -o hello ../hello.c ./tinyfiledialogsLinux64.so
|
||||||
|
elif [ `uname -s` = "OpenBSD" ]; then
|
||||||
|
echo OpenBSD
|
||||||
|
clang -m32 -fPIC -shared -o tinyfiledialogsOpenBSDx86.so ../tinyfiledialogs.c
|
||||||
|
clang -m32 -o hello ../hello.c ./tinyfiledialogsOpenBSDx86.so
|
||||||
|
|
||||||
|
clang -m64 -fPIC -shared -o tinyfiledialogsOpenBSDx64.so ../tinyfiledialogs.c
|
||||||
|
clang -m64 -o hello ../hello.c ./tinyfiledialogsOpenBSDx64.so
|
||||||
|
else
|
||||||
|
echo Other Unix
|
||||||
|
fi
|
307
tinyfiledialogs/hello.c
Normal file
307
tinyfiledialogs/hello.c
Normal file
@ -0,0 +1,307 @@
|
|||||||
|
/* SPDX-License-Identifier: Zlib
|
||||||
|
Copyright (c) 2014 - 2024 Guillaume Vareille http://ysengrin.com
|
||||||
|
________________________________________________________________
|
||||||
|
| |
|
||||||
|
| 100% compatible C C++ -> You can rename this .c file as .cpp |
|
||||||
|
|________________________________________________________________|
|
||||||
|
|
||||||
|
********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE *********
|
||||||
|
_________
|
||||||
|
/ \ hello.c v3.18.2 [Jun 10, 2024]
|
||||||
|
|tiny file| Hello World file created [November 9, 2014]
|
||||||
|
| dialogs |
|
||||||
|
\____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
____________________________________________
|
||||||
|
| |
|
||||||
|
| email: tinyfiledialogs at ysengrin.com |
|
||||||
|
|____________________________________________|
|
||||||
|
_________________________________________________________________________________
|
||||||
|
| |
|
||||||
|
| the windows only wchar_t UTF-16 prototypes are at the bottom of the header file |
|
||||||
|
|_________________________________________________________________________________|
|
||||||
|
_________________________________________________________
|
||||||
|
| |
|
||||||
|
| on windows: - since v3.6 char is UTF-8 by default |
|
||||||
|
| - if you want MBCS set tinyfd_winUtf8 to 0 |
|
||||||
|
| - functions like fopen expect MBCS |
|
||||||
|
|_________________________________________________________|
|
||||||
|
___________________________________________________________
|
||||||
|
| |
|
||||||
|
| v3.10: NEW FORTRAN module fully implemented with examples |
|
||||||
|
| https://stackoverflow.com/a/59657117 |
|
||||||
|
|___________________________________________________________|
|
||||||
|
|
||||||
|
If you like tinyfiledialogs, please upvote my stackoverflow answer
|
||||||
|
https://stackoverflow.com/a/47651444
|
||||||
|
|
||||||
|
- License -
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
- Here is the Hello World:
|
||||||
|
if a console is missing, it will use graphic dialogs
|
||||||
|
if a graphical display is absent, it will use console dialogs
|
||||||
|
(on windows the input box may take some time to open the first time)
|
||||||
|
|
||||||
|
See compilation instructions at the end of this file
|
||||||
|
|
||||||
|
__________________________________________
|
||||||
|
| ______________________________________ |
|
||||||
|
| | | |
|
||||||
|
| | DO NOT USE USER INPUT IN THE DIALOGS | |
|
||||||
|
| |______________________________________| |
|
||||||
|
|__________________________________________|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "tinyfiledialogs.h"
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(disable:4996) /* silences warnings about strcpy strcat fopen*/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main( int argc , char * argv[] )
|
||||||
|
{
|
||||||
|
int lIntValue;
|
||||||
|
char * lPassword;
|
||||||
|
char * lTheSaveFileName;
|
||||||
|
char * lTheOpenFileName;
|
||||||
|
char * lTheSelectFolderName;
|
||||||
|
char * lTheHexColor;
|
||||||
|
char * lWillBeGraphicMode;
|
||||||
|
unsigned char lRgbColor[3];
|
||||||
|
FILE * lIn;
|
||||||
|
char lBuffer[1024];
|
||||||
|
char const * lFilterPatterns[2] = { "*.txt", "*.text" };
|
||||||
|
|
||||||
|
(void)argv; /*to silence stupid visual studio warning*/
|
||||||
|
|
||||||
|
tinyfd_verbose = argc - 1; /* default is 0 */
|
||||||
|
tinyfd_silent = 1; /* default is 1 */
|
||||||
|
|
||||||
|
tinyfd_forceConsole = 0; /* default is 0 */
|
||||||
|
tinyfd_assumeGraphicDisplay = 0; /* default is 0 */
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
tinyfd_winUtf8 = 1; /* default is 1 */
|
||||||
|
/* On windows, you decide if char holds 1:UTF-8(default) or 0:MBCS */
|
||||||
|
/* Windows is not ready to handle UTF-8 as many char functions like fopen() expect MBCS filenames.*/
|
||||||
|
/* This hello.c file has been prepared, on windows, to convert the filenames from UTF-8 to UTF-16
|
||||||
|
and pass them passed to _wfopen() instead of fopen() */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
tinyfd_beep();
|
||||||
|
|
||||||
|
lWillBeGraphicMode = tinyfd_inputBox("tinyfd_query", NULL, NULL);
|
||||||
|
|
||||||
|
strcpy(lBuffer, "tinyfiledialogs\nv");
|
||||||
|
strcat(lBuffer, tinyfd_version);
|
||||||
|
if (lWillBeGraphicMode)
|
||||||
|
{
|
||||||
|
strcat(lBuffer, "\ngraphic mode: ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcat(lBuffer, "\nconsole mode: ");
|
||||||
|
}
|
||||||
|
strcat(lBuffer, tinyfd_response);
|
||||||
|
tinyfd_messageBox("hello", lBuffer, "ok", "info", 0);
|
||||||
|
|
||||||
|
tinyfd_notifyPopup("the title", "the message\n\tfrom outer-space", "info");
|
||||||
|
|
||||||
|
if ( lWillBeGraphicMode && ! tinyfd_forceConsole )
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
lIntValue = tinyfd_messageBox("Hello World", "\
|
||||||
|
graphic dialogs [Yes]\n\
|
||||||
|
console mode [No]\n\
|
||||||
|
quit [Cancel]",
|
||||||
|
"yesnocancel", "question", 1);
|
||||||
|
if (!lIntValue) return 1;
|
||||||
|
tinyfd_forceConsole = (lIntValue == 2);
|
||||||
|
#else
|
||||||
|
lIntValue = tinyfd_messageBox(
|
||||||
|
"Hello World", "graphic dialogs [Yes] / console mode [No]",
|
||||||
|
"yesno", "question", 1);
|
||||||
|
tinyfd_forceConsole = ! lIntValue;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
lPassword = tinyfd_inputBox(
|
||||||
|
"a password box", "your password will be revealed later", NULL);
|
||||||
|
|
||||||
|
if (!lPassword) return 1;
|
||||||
|
|
||||||
|
tinyfd_messageBox("your password as read", lPassword, "ok", "info", 1);
|
||||||
|
|
||||||
|
lTheSaveFileName = tinyfd_saveFileDialog(
|
||||||
|
"let us save this password",
|
||||||
|
"./passwordFile.txt",
|
||||||
|
2,
|
||||||
|
lFilterPatterns,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (! lTheSaveFileName)
|
||||||
|
{
|
||||||
|
tinyfd_messageBox(
|
||||||
|
"Error",
|
||||||
|
"Save file name is NULL",
|
||||||
|
"ok",
|
||||||
|
"error",
|
||||||
|
1);
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (tinyfd_winUtf8)
|
||||||
|
lIn = _wfopen(tinyfd_utf8to16(lTheSaveFileName), L"w"); /* the UTF-8 filename is converted to UTF-16 to open the file*/
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
lIn = fopen(lTheSaveFileName, "w");
|
||||||
|
|
||||||
|
if (!lIn)
|
||||||
|
{
|
||||||
|
tinyfd_messageBox(
|
||||||
|
"Error",
|
||||||
|
"Can not open this file in write mode",
|
||||||
|
"ok",
|
||||||
|
"error",
|
||||||
|
1);
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
fputs(lPassword, lIn);
|
||||||
|
fclose(lIn);
|
||||||
|
|
||||||
|
lTheOpenFileName = tinyfd_openFileDialog(
|
||||||
|
"let us read the password back",
|
||||||
|
"../",
|
||||||
|
2,
|
||||||
|
lFilterPatterns,
|
||||||
|
"text files",
|
||||||
|
1);
|
||||||
|
|
||||||
|
if (! lTheOpenFileName)
|
||||||
|
{
|
||||||
|
tinyfd_messageBox(
|
||||||
|
"Error",
|
||||||
|
"Open file name is NULL",
|
||||||
|
"ok",
|
||||||
|
"error",
|
||||||
|
0);
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (tinyfd_winUtf8)
|
||||||
|
lIn = _wfopen(tinyfd_utf8to16(lTheOpenFileName), L"r"); /* the UTF-8 filename is converted to UTF-16 */
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
lIn = fopen(lTheOpenFileName, "r");
|
||||||
|
|
||||||
|
if (!lIn)
|
||||||
|
{
|
||||||
|
tinyfd_messageBox(
|
||||||
|
"Error",
|
||||||
|
"Can not open this file in read mode",
|
||||||
|
"ok",
|
||||||
|
"error",
|
||||||
|
1);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
lBuffer[0] = '\0';
|
||||||
|
fgets(lBuffer, sizeof(lBuffer), lIn);
|
||||||
|
fclose(lIn);
|
||||||
|
|
||||||
|
tinyfd_messageBox("your password as it was saved", lBuffer, "ok", "info", 1);
|
||||||
|
|
||||||
|
lTheSelectFolderName = tinyfd_selectFolderDialog(
|
||||||
|
"let us just select a directory", "../../");
|
||||||
|
|
||||||
|
if (!lTheSelectFolderName)
|
||||||
|
{
|
||||||
|
tinyfd_messageBox(
|
||||||
|
"Error",
|
||||||
|
"Select folder name is NULL",
|
||||||
|
"ok",
|
||||||
|
"error",
|
||||||
|
1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tinyfd_messageBox("The selected folder is", lTheSelectFolderName, "ok", "info", 1);
|
||||||
|
|
||||||
|
lTheHexColor = tinyfd_colorChooser(
|
||||||
|
"choose a nice color",
|
||||||
|
"#FF0077",
|
||||||
|
lRgbColor,
|
||||||
|
lRgbColor);
|
||||||
|
|
||||||
|
if (!lTheHexColor)
|
||||||
|
{
|
||||||
|
tinyfd_messageBox(
|
||||||
|
"Error",
|
||||||
|
"hexcolor is NULL",
|
||||||
|
"ok",
|
||||||
|
"error",
|
||||||
|
1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tinyfd_messageBox("The selected hexcolor is", lTheHexColor, "ok", "info", 1);
|
||||||
|
|
||||||
|
tinyfd_messageBox("your read password was", lPassword, "ok", "info", 1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(default:4996)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
OSX :
|
||||||
|
$ clang -o hello.app hello.c tinyfiledialogs.c
|
||||||
|
( or gcc )
|
||||||
|
|
||||||
|
UNIX :
|
||||||
|
$ gcc -o hello hello.c tinyfiledialogs.c
|
||||||
|
( or clang tcc owcc cc CC )
|
||||||
|
|
||||||
|
Windows :
|
||||||
|
MinGW needs gcc >= v4.9 otherwise some headers are incomplete
|
||||||
|
> gcc -o hello.exe hello.c tinyfiledialogs.c -LC:/mingw/lib -lcomdlg32 -lole32
|
||||||
|
|
||||||
|
TinyCC needs >= v0.9.27 (+ tweaks - contact me) otherwise some headers are missing
|
||||||
|
> tcc -o hello.exe hello.c tinyfiledialogs.c ^
|
||||||
|
-isystem C:\tcc\winapi-full-for-0.9.27\include\winapi ^
|
||||||
|
-lcomdlg32 -lole32 -luser32 -lshell32
|
||||||
|
|
||||||
|
Borland C: > bcc32c -o hello.exe hello.c tinyfiledialogs.c
|
||||||
|
OpenWatcom v2: create a character-mode executable project.
|
||||||
|
|
||||||
|
VisualStudio :
|
||||||
|
Create a console application project,
|
||||||
|
it links against comdlg32.lib & ole32.lib.
|
||||||
|
|
||||||
|
VisualStudio command line :
|
||||||
|
> cl hello.c tinyfiledialogs.c comdlg32.lib ole32.lib user32.lib shell32.lib /W4
|
||||||
|
*/
|
241
tinyfiledialogs/hello_wchar_t.c
Normal file
241
tinyfiledialogs/hello_wchar_t.c
Normal file
@ -0,0 +1,241 @@
|
|||||||
|
/* SPDX-License-Identifier: Zlib
|
||||||
|
Copyright (c) 2014 - 2024 Guillaume Vareille http://ysengrin.com
|
||||||
|
________________________________________________________________
|
||||||
|
| |
|
||||||
|
| 100% compatible C C++ -> You can rename this .c file as .cpp |
|
||||||
|
|________________________________________________________________|
|
||||||
|
|
||||||
|
********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE *********
|
||||||
|
_________
|
||||||
|
/ \ hello_wchar_t.c v3.18.2 [Jun 10, 2024]
|
||||||
|
|tiny file| Hello WCHAR_T windows only file created [November 9, 2014]
|
||||||
|
| dialogs |
|
||||||
|
\____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
____________________________________________
|
||||||
|
| |
|
||||||
|
| email: tinyfiledialogs at ysengrin.com |
|
||||||
|
|____________________________________________|
|
||||||
|
________________________________________________________________
|
||||||
|
| |
|
||||||
|
| this file is for windows only it uses wchar_t UTF-16 functions |
|
||||||
|
|________________________________________________________________|
|
||||||
|
|
||||||
|
If you like tinyfiledialogs, please upvote my stackoverflow answer
|
||||||
|
https://stackoverflow.com/a/47651444
|
||||||
|
|
||||||
|
- License -
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
See compilation instructions at the end of this file
|
||||||
|
|
||||||
|
__________________________________________
|
||||||
|
| ______________________________________ |
|
||||||
|
| | | |
|
||||||
|
| | DO NOT USE USER INPUT IN THE DIALOGS | |
|
||||||
|
| |______________________________________| |
|
||||||
|
|__________________________________________|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tinyfiledialogs.h"
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(disable:4996) /* silences warning about wcscpy*/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(void) /* WINDOWS ONLY */
|
||||||
|
{
|
||||||
|
wchar_t * lPassword;
|
||||||
|
wchar_t * lTheSaveFileName;
|
||||||
|
wchar_t * lTheOpenFileName;
|
||||||
|
wchar_t * lTheSelectFolderName;
|
||||||
|
wchar_t * lTheHexColor;
|
||||||
|
wchar_t * lWillBeGraphicMode;
|
||||||
|
unsigned char lRgbColor[3];
|
||||||
|
FILE * lIn;
|
||||||
|
wchar_t lWcharBuff[1024];
|
||||||
|
wchar_t lBuffer[1024];
|
||||||
|
wchar_t const * lFilterPatterns[2] = { L"*.txt", L"*.text" };
|
||||||
|
|
||||||
|
tinyfd_beep();
|
||||||
|
|
||||||
|
lWillBeGraphicMode = tinyfd_inputBoxW(L"tinyfd_query", NULL, NULL);
|
||||||
|
|
||||||
|
wcscpy(lBuffer, L"v");
|
||||||
|
mbstowcs(lWcharBuff, tinyfd_version, strlen(tinyfd_version) + 1);
|
||||||
|
wcscat(lBuffer, lWcharBuff);
|
||||||
|
if (lWillBeGraphicMode)
|
||||||
|
{
|
||||||
|
wcscat(lBuffer, L"\ngraphic mode: ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wcscat(lBuffer, L"\nconsole mode: ");
|
||||||
|
}
|
||||||
|
mbstowcs(lWcharBuff, tinyfd_response, strlen(tinyfd_response)+1);
|
||||||
|
wcscat(lBuffer, lWcharBuff);
|
||||||
|
wcscat(lBuffer, L"\n");
|
||||||
|
mbstowcs(lWcharBuff, tinyfd_needs + 78, strlen(tinyfd_needs + 78) + 1);
|
||||||
|
wcscat(lBuffer, lWcharBuff);
|
||||||
|
|
||||||
|
tinyfd_messageBoxW(L"hello", lBuffer, L"ok", L"info", 0);
|
||||||
|
|
||||||
|
tinyfd_notifyPopupW(L"the title", L"the message\n\tfrom outer-space", L"info");
|
||||||
|
|
||||||
|
lPassword = tinyfd_inputBoxW(
|
||||||
|
L"a password box", L"your password will be revealed later", NULL);
|
||||||
|
|
||||||
|
if (!lPassword) return 1;
|
||||||
|
|
||||||
|
lTheSaveFileName = tinyfd_saveFileDialogW(
|
||||||
|
L"let us save this password",
|
||||||
|
L"passwordFile.txt",
|
||||||
|
2,
|
||||||
|
lFilterPatterns,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (! lTheSaveFileName)
|
||||||
|
{
|
||||||
|
tinyfd_messageBoxW(
|
||||||
|
L"Error",
|
||||||
|
L"Save file name is NULL",
|
||||||
|
L"ok",
|
||||||
|
L"error",
|
||||||
|
1);
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
lIn = _wfopen(lTheSaveFileName, L"wt, ccs=UNICODE");
|
||||||
|
if (!lIn)
|
||||||
|
{
|
||||||
|
tinyfd_messageBoxW(
|
||||||
|
L"Error",
|
||||||
|
L"Can not open this file in write mode",
|
||||||
|
L"ok",
|
||||||
|
L"error",
|
||||||
|
1);
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
fputws(lPassword, lIn);
|
||||||
|
fclose(lIn);
|
||||||
|
|
||||||
|
lTheOpenFileName = tinyfd_openFileDialogW(
|
||||||
|
L"let us read the password back",
|
||||||
|
L"",
|
||||||
|
2,
|
||||||
|
lFilterPatterns,
|
||||||
|
NULL,
|
||||||
|
0);
|
||||||
|
|
||||||
|
if (! lTheOpenFileName)
|
||||||
|
{
|
||||||
|
tinyfd_messageBoxW(
|
||||||
|
L"Error",
|
||||||
|
L"Open file name is NULL",
|
||||||
|
L"ok",
|
||||||
|
L"error",
|
||||||
|
1);
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
lIn = _wfopen(lTheOpenFileName, L"rt, ccs=UNICODE");
|
||||||
|
|
||||||
|
if (!lIn)
|
||||||
|
{
|
||||||
|
tinyfd_messageBoxW(
|
||||||
|
L"Error",
|
||||||
|
L"Can not open this file in read mode",
|
||||||
|
L"ok",
|
||||||
|
L"error",
|
||||||
|
1);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
lBuffer[0] = '\0';
|
||||||
|
fgetws(lBuffer, sizeof(lBuffer), lIn);
|
||||||
|
fclose(lIn);
|
||||||
|
|
||||||
|
tinyfd_messageBoxW(L"your password is",
|
||||||
|
lBuffer, L"ok", L"info", 1);
|
||||||
|
|
||||||
|
lTheSelectFolderName = tinyfd_selectFolderDialogW(
|
||||||
|
L"let us just select a directory", L"C:\\");
|
||||||
|
|
||||||
|
if (!lTheSelectFolderName)
|
||||||
|
{
|
||||||
|
tinyfd_messageBoxW(
|
||||||
|
L"Error",
|
||||||
|
L"Select folder name is NULL",
|
||||||
|
L"ok",
|
||||||
|
L"error",
|
||||||
|
1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tinyfd_messageBoxW(L"The selected folder is",
|
||||||
|
lTheSelectFolderName, L"ok", L"info", 1);
|
||||||
|
|
||||||
|
lTheHexColor = tinyfd_colorChooserW(
|
||||||
|
L"choose a nice color",
|
||||||
|
L"#FF0077",
|
||||||
|
lRgbColor,
|
||||||
|
lRgbColor);
|
||||||
|
|
||||||
|
if (!lTheHexColor)
|
||||||
|
{
|
||||||
|
tinyfd_messageBoxW(
|
||||||
|
L"Error",
|
||||||
|
L"hexcolor is NULL",
|
||||||
|
L"ok",
|
||||||
|
L"error",
|
||||||
|
1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tinyfd_messageBoxW(L"The selected hexcolor is",
|
||||||
|
lTheHexColor, L"ok", L"info", 1);
|
||||||
|
|
||||||
|
tinyfd_messageBoxW(L"your password was", lPassword, L"ok", L"info", 1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(default:4996)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
MinGW needs gcc >= v4.9 otherwise some headers are incomplete
|
||||||
|
> gcc -o hello.exe hello.c tinyfiledialogs.c -LC:/mingw/lib -lcomdlg32 -lole32
|
||||||
|
|
||||||
|
TinyCC needs >= v0.9.27 (+ tweaks - contact me) otherwise some headers are missing
|
||||||
|
> tcc -o hello.exe hello.c tinyfiledialogs.c ^
|
||||||
|
-isystem C:\tcc\winapi-full-for-0.9.27\include\winapi ^
|
||||||
|
-lcomdlg32 -lole32 -luser32 -lshell32
|
||||||
|
|
||||||
|
Borland C: > bcc32c -o hello.exe hello.c tinyfiledialogs.c
|
||||||
|
OpenWatcom v2: create a character-mode executable project.
|
||||||
|
|
||||||
|
VisualStudio :
|
||||||
|
Create a console application project,
|
||||||
|
it links against comdlg32.lib & ole32.lib.
|
||||||
|
|
||||||
|
VisualStudio command line :
|
||||||
|
> cl hello.c tinyfiledialogs.c comdlg32.lib ole32.lib user32.lib shell32.lib /W4
|
||||||
|
*/
|
259
tinyfiledialogs/more_dialogs/tinyfd_moredialogs.c
Normal file
259
tinyfiledialogs/more_dialogs/tinyfd_moredialogs.c
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
/* SPDX-License-Identifier: ZLIB
|
||||||
|
Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
|
||||||
|
_________
|
||||||
|
/ \ tinyfiledialogs v3.9.0 [Nov 3, 2022] zlib licence
|
||||||
|
|tiny file|
|
||||||
|
| dialogs |
|
||||||
|
\____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
|
||||||
|
If you like tinyfiledialogs, please upvote my stackoverflow answer
|
||||||
|
https://stackoverflow.com/a/47651444
|
||||||
|
|
||||||
|
- License -
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __sun
|
||||||
|
#ifndef _POSIX_C_SOURCE
|
||||||
|
#define _POSIX_C_SOURCE 2 /* to accept POSIX 2 in old ANSI C standards */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "../tinyfiledialogs.h"
|
||||||
|
|
||||||
|
#define MAX_PATH_OR_CMD 1024 /* _MAX_PATH or MAX_PATH */
|
||||||
|
int tfd_quoteDetected(char const * aString);
|
||||||
|
void tfd_replaceSubStr( char const * aSource ,char const * aOldSubStr ,
|
||||||
|
char const * aNewSubStr ,char * aoDestination );
|
||||||
|
#ifndef _WIN32
|
||||||
|
int tfd_isDarwin(void);
|
||||||
|
int tfd_kdialogPresent(void);
|
||||||
|
int tfd_matedialogPresent(void);
|
||||||
|
int tfd_qarmaPresent(void);
|
||||||
|
int tfd_shellementaryPresent(void);
|
||||||
|
int tfd_xpropPresent(void);
|
||||||
|
int tfd_zenityPresent(void);
|
||||||
|
int tfd_zenity3Present(void);
|
||||||
|
#endif /*_WIN32 */
|
||||||
|
|
||||||
|
|
||||||
|
/* not cross platform - unix zenity only */
|
||||||
|
/* contributed by Attila Dusnoki */
|
||||||
|
#ifndef _WIN32
|
||||||
|
char * tinyfd_arrayDialog(
|
||||||
|
char const * aTitle , /* "" */
|
||||||
|
int aNumOfColumns , /* 2 */
|
||||||
|
char const * const * aColumns , /* {"Column 1","Column 2"} */
|
||||||
|
int aNumOfRows , /* 2 */
|
||||||
|
char const * const * aCells )
|
||||||
|
/* {"Row1 Col1","Row1 Col2","Row2 Col1","Row2 Col2"} */
|
||||||
|
{
|
||||||
|
static char lBuff [MAX_PATH_OR_CMD] ;
|
||||||
|
char lDialogString [MAX_PATH_OR_CMD] ;
|
||||||
|
FILE * lIn ;
|
||||||
|
int i ;
|
||||||
|
|
||||||
|
if (tfd_quoteDetected(aTitle)) return tinyfd_arrayDialog("INVALID TITLE WITH QUOTES", aNumOfColumns, aColumns, aNumOfRows, aCells);
|
||||||
|
for (i = 0; i < aNumOfColumns; i++)
|
||||||
|
{
|
||||||
|
if (tfd_quoteDetected(aColumns[i])) return tinyfd_arrayDialog("INVALID COLUMNS WITH QUOTES", 0, NULL, 0, NULL);
|
||||||
|
}
|
||||||
|
for (i = 0; i < aNumOfRows; i++)
|
||||||
|
{
|
||||||
|
if (tfd_quoteDetected(aCells[i])) return tinyfd_arrayDialog("INVALID ROWS WITH QUOTES", 0, NULL, 0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
lBuff[0]='\0';
|
||||||
|
|
||||||
|
if ( tfd_zenityPresent() || tfd_matedialogPresent() || tfd_shellementaryPresent() || tfd_qarmaPresent() )
|
||||||
|
{
|
||||||
|
if ( tfd_zenityPresent() )
|
||||||
|
{
|
||||||
|
if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"zenity");return (char *)1;}
|
||||||
|
strcpy( lDialogString , "zenity" ) ;
|
||||||
|
if ( (tfd_zenity3Present() >= 4) && !getenv("SSH_TTY") && tfd_xpropPresent() )
|
||||||
|
{
|
||||||
|
strcat( lDialogString, " --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( tfd_matedialogPresent() )
|
||||||
|
{
|
||||||
|
if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"matedialog");return (char *)1;}
|
||||||
|
strcpy( lDialogString , "matedialog" ) ;
|
||||||
|
}
|
||||||
|
else if ( tfd_shellementaryPresent() )
|
||||||
|
{
|
||||||
|
if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"shellementary");return (char *)1;}
|
||||||
|
strcpy( lDialogString , "shellementary" ) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"qarma");return (char *)1;}
|
||||||
|
strcpy( lDialogString , "qarma" ) ;
|
||||||
|
if ( !getenv("SSH_TTY") && tfd_xpropPresent() )
|
||||||
|
{
|
||||||
|
strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
strcat( lDialogString , " --list --print-column=ALL" ) ;
|
||||||
|
|
||||||
|
if ( aTitle && strlen(aTitle) )
|
||||||
|
{
|
||||||
|
strcat(lDialogString, " --title=\"") ;
|
||||||
|
strcat(lDialogString, aTitle) ;
|
||||||
|
strcat(lDialogString, "\"") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( aColumns && (aNumOfColumns > 0) )
|
||||||
|
{
|
||||||
|
for ( i = 0 ; i < aNumOfColumns ; i ++ )
|
||||||
|
{
|
||||||
|
strcat( lDialogString , " --column=\"" ) ;
|
||||||
|
strcat( lDialogString , aColumns [i] ) ;
|
||||||
|
strcat( lDialogString , "\"" ) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( aCells && (aNumOfRows > 0) )
|
||||||
|
{
|
||||||
|
strcat( lDialogString , " " ) ;
|
||||||
|
for ( i = 0 ; i < aNumOfRows*aNumOfColumns ; i ++ )
|
||||||
|
{
|
||||||
|
strcat( lDialogString , "\"" ) ;
|
||||||
|
strcat( lDialogString , aCells [i] ) ;
|
||||||
|
strcat( lDialogString , "\" " ) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"");return (char *)0;}
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tinyfd_verbose) printf( "lDialogString: %s\n" , lDialogString ) ;
|
||||||
|
if ( ! ( lIn = popen( lDialogString , "r" ) ) )
|
||||||
|
{
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
while ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL )
|
||||||
|
{}
|
||||||
|
pclose( lIn ) ;
|
||||||
|
if ( lBuff[strlen( lBuff ) -1] == '\n' )
|
||||||
|
{
|
||||||
|
lBuff[strlen( lBuff ) -1] = '\0' ;
|
||||||
|
}
|
||||||
|
/* printf( "lBuff: %s\n" , lBuff ) ; */
|
||||||
|
if ( ! strlen( lBuff ) )
|
||||||
|
{
|
||||||
|
return NULL ;
|
||||||
|
}
|
||||||
|
return lBuff ;
|
||||||
|
}
|
||||||
|
#endif /*_WIN32 */
|
||||||
|
|
||||||
|
|
||||||
|
/* not cross platform - UNIX and OSX only */
|
||||||
|
/* contributed by srikanth http://sourceforge.net/u/cr1vct/profile */
|
||||||
|
#ifndef _WIN32
|
||||||
|
char *tinyfd_checklistDialog(
|
||||||
|
char const *aTitle,
|
||||||
|
int aNumOfOptions,
|
||||||
|
char const *const *aOptions)
|
||||||
|
{
|
||||||
|
static char lBuff[MAX_PATH_OR_CMD];
|
||||||
|
static char dest[MAX_PATH_OR_CMD];
|
||||||
|
|
||||||
|
char lDialogString[MAX_PATH_OR_CMD];
|
||||||
|
FILE *lIn;
|
||||||
|
int i ;
|
||||||
|
char *target = lDialogString;
|
||||||
|
|
||||||
|
if (tfd_quoteDetected(aTitle)) return tinyfd_checklistDialog("INVALID TITLE WITH QUOTES", aNumOfOptions, aOptions);
|
||||||
|
for (i = 0; i < aNumOfOptions; i++)
|
||||||
|
{
|
||||||
|
if (tfd_quoteDetected(aOptions[i])) return tinyfd_checklistDialog("INVALID COLUMNS WITH QUOTES", 0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
lBuff[0] = '\0';
|
||||||
|
if (tfd_isDarwin())
|
||||||
|
{
|
||||||
|
target += sprintf(target, "osascript -e \'set Choices to {");
|
||||||
|
for (i = 0; i < aNumOfOptions; i++)
|
||||||
|
{
|
||||||
|
if (i != aNumOfOptions - 1)
|
||||||
|
target += sprintf(target, "\"%s\", ", aOptions[i]);
|
||||||
|
else
|
||||||
|
target += sprintf(target, "\"%s\"", aOptions[i]);
|
||||||
|
}
|
||||||
|
target += sprintf(target, "}\' -e \'set Choice to choose from list Choices with prompt \"%s\" with multiple selections allowed\' -e \'Choice\'", aTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (tfd_kdialogPresent())
|
||||||
|
{
|
||||||
|
target += sprintf(target, "kdialog --checklist \'%s\' ", aTitle);
|
||||||
|
for (i = 0; i < aNumOfOptions; i++)
|
||||||
|
{
|
||||||
|
target += sprintf(target, "\'%s\' \'%s\' OFF ", aOptions[i], aOptions[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tfd_zenityPresent())
|
||||||
|
{
|
||||||
|
target += sprintf(target, "zenity --list --column= --column= --checklist --title=\'%s\' ", aTitle);
|
||||||
|
for (i = 0; i < aNumOfOptions; i++)
|
||||||
|
{
|
||||||
|
target += sprintf(target, "\'\' \'%s\' ", aOptions[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tinyfd_verbose)
|
||||||
|
printf("lDialogString: %s\n", lDialogString);
|
||||||
|
if (!(lIn = popen(lDialogString, "r")))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
while (fgets(lBuff, sizeof(lBuff), lIn) != NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
pclose(lIn);
|
||||||
|
if (lBuff[strlen(lBuff) - 1] == '\n')
|
||||||
|
{
|
||||||
|
lBuff[strlen(lBuff) - 1] = '\0';
|
||||||
|
}
|
||||||
|
/* printf( "lBuff: %s\n" , lBuff ) ; */
|
||||||
|
if (!strlen(lBuff))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (tfd_kdialogPresent())
|
||||||
|
{
|
||||||
|
tfd_replaceSubStr(lBuff, "\" \"", "|", dest);
|
||||||
|
dest[strlen(dest) - 2] = '\0';
|
||||||
|
return dest + 1;
|
||||||
|
}
|
||||||
|
if (tfd_isDarwin())
|
||||||
|
{
|
||||||
|
tfd_replaceSubStr(lBuff, "\", \"", "|", dest);
|
||||||
|
dest[strlen(dest) - 2] = '\0';
|
||||||
|
dest[strlen(dest) - 3] = '\0';
|
||||||
|
return dest + 2;
|
||||||
|
}
|
||||||
|
return lBuff;
|
||||||
|
}
|
||||||
|
#endif /*_WIN32 */
|
48
tinyfiledialogs/more_dialogs/tinyfd_moredialogs.h
Normal file
48
tinyfiledialogs/more_dialogs/tinyfd_moredialogs.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/* SPDX-License-Identifier: ZLIB
|
||||||
|
Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
|
||||||
|
_________
|
||||||
|
/ \ tinyfiledialogs v3.9.0 [Nov 3, 2022]
|
||||||
|
|tiny file|
|
||||||
|
| dialogs |
|
||||||
|
\____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
|
||||||
|
If you like tinyfiledialogs, please upvote my stackoverflow answer
|
||||||
|
https://stackoverflow.com/a/47651444
|
||||||
|
|
||||||
|
- License -
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* not cross platform - unix zenity only */
|
||||||
|
/* contributed by Attila Dusnoki */
|
||||||
|
#ifndef _WIN32
|
||||||
|
char * tinyfd_arrayDialog(
|
||||||
|
char const * aTitle , /* NULL or "" */
|
||||||
|
int aNumOfColumns , /* 2 */
|
||||||
|
char const * const * aColumns, /* {"Column 1","Column 2"} */
|
||||||
|
int aNumOfRows, /* 2 */
|
||||||
|
char const * const * aCells);
|
||||||
|
/* {"Row1 Col1","Row1 Col2","Row2 Col1","Row2 Col2"} */
|
||||||
|
#endif /*_WIN32 */
|
||||||
|
|
||||||
|
/* not cross platform - UNIX and OSX only */
|
||||||
|
/* contributed by srikanth http://sourceforge.net/u/cr1vct/profile */
|
||||||
|
#ifndef _WIN32
|
||||||
|
char * tinyfd_checklistDialog(
|
||||||
|
char const * aTitle ,
|
||||||
|
int aNumOfOptions ,
|
||||||
|
char const * const * aOptions);
|
||||||
|
#endif /*_WIN32 */
|
8171
tinyfiledialogs/tinyfiledialogs.c
Normal file
8171
tinyfiledialogs/tinyfiledialogs.c
Normal file
File diff suppressed because it is too large
Load Diff
314
tinyfiledialogs/tinyfiledialogs.h
Normal file
314
tinyfiledialogs/tinyfiledialogs.h
Normal file
@ -0,0 +1,314 @@
|
|||||||
|
/* SPDX-License-Identifier: Zlib
|
||||||
|
Copyright (c) 2014 - 2024 Guillaume Vareille http://ysengrin.com
|
||||||
|
____________________________________________________________________
|
||||||
|
| |
|
||||||
|
| 100% compatible C C++ -> You can rename tinfiledialogs.c as .cpp |
|
||||||
|
|____________________________________________________________________|
|
||||||
|
|
||||||
|
********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE *********
|
||||||
|
_________
|
||||||
|
/ \ tinyfiledialogs.h v3.18.2 [Jun 8, 2024]
|
||||||
|
|tiny file| Unique header file created [November 9, 2014]
|
||||||
|
| dialogs |
|
||||||
|
\____ ___/ http://tinyfiledialogs.sourceforge.net
|
||||||
|
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
|
||||||
|
____________________________________________
|
||||||
|
| |
|
||||||
|
| email: tinyfiledialogs at ysengrin.com |
|
||||||
|
|____________________________________________|
|
||||||
|
________________________________________________________________________________
|
||||||
|
| ____________________________________________________________________________ |
|
||||||
|
| | | |
|
||||||
|
| | - in tinyfiledialogs, char is UTF-8 by default (since v3.6) | |
|
||||||
|
| | | |
|
||||||
|
| | on windows: | |
|
||||||
|
| | - for UTF-16, use the wchar_t functions at the bottom of the header file | |
|
||||||
|
| | | |
|
||||||
|
| | - _wfopen() requires wchar_t | |
|
||||||
|
| | - fopen() uses char but expects ASCII or MBCS (not UTF-8) | |
|
||||||
|
| | - if you want char to be MBCS: set tinyfd_winUtf8 to 0 | |
|
||||||
|
| | | |
|
||||||
|
| | - alternatively, tinyfiledialogs provides | |
|
||||||
|
| | functions to convert between UTF-8, UTF-16 and MBCS | |
|
||||||
|
| |____________________________________________________________________________| |
|
||||||
|
|________________________________________________________________________________|
|
||||||
|
|
||||||
|
If you like tinyfiledialogs, please upvote my stackoverflow answer
|
||||||
|
https://stackoverflow.com/a/47651444
|
||||||
|
|
||||||
|
- License -
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
__________________________________________
|
||||||
|
| ______________________________________ |
|
||||||
|
| | | |
|
||||||
|
| | DO NOT USE USER INPUT IN THE DIALOGS | |
|
||||||
|
| |______________________________________| |
|
||||||
|
|__________________________________________|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TINYFILEDIALOGS_H
|
||||||
|
#define TINYFILEDIALOGS_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************************************/
|
||||||
|
/**************************************** UTF-8 on Windows ********************************************/
|
||||||
|
/******************************************************************************************************/
|
||||||
|
#ifdef _WIN32
|
||||||
|
/* On windows, if you want to use UTF-8 ( instead of the UTF-16/wchar_t functions at the end of this file )
|
||||||
|
Make sure your code is really prepared for UTF-8 (on windows, functions like fopen() expect MBCS and not UTF-8) */
|
||||||
|
extern int tinyfd_winUtf8; /* on windows char strings can be 1:UTF-8(default) or 0:MBCS */
|
||||||
|
/* for MBCS change this to 0, in tinyfiledialogs.c or in your code */
|
||||||
|
|
||||||
|
/* Here are some functions to help you convert between UTF-16 UTF-8 MBSC */
|
||||||
|
char * tinyfd_utf8toMbcs(char const * aUtf8string);
|
||||||
|
char * tinyfd_utf16toMbcs(wchar_t const * aUtf16string);
|
||||||
|
wchar_t * tinyfd_mbcsTo16(char const * aMbcsString);
|
||||||
|
char * tinyfd_mbcsTo8(char const * aMbcsString);
|
||||||
|
wchar_t * tinyfd_utf8to16(char const * aUtf8string);
|
||||||
|
char * tinyfd_utf16to8(wchar_t const * aUtf16string);
|
||||||
|
#endif
|
||||||
|
/******************************************************************************************************/
|
||||||
|
/******************************************************************************************************/
|
||||||
|
/******************************************************************************************************/
|
||||||
|
|
||||||
|
/************* 3 funtions for C# (you don't need this in C or C++) : */
|
||||||
|
char const * tinyfd_getGlobalChar(char const * aCharVariableName); /* returns NULL on error */
|
||||||
|
int tinyfd_getGlobalInt(char const * aIntVariableName); /* returns -1 on error */
|
||||||
|
int tinyfd_setGlobalInt(char const * aIntVariableName, int aValue); /* returns -1 on error */
|
||||||
|
/* aCharVariableName: "tinyfd_version" "tinyfd_needs" "tinyfd_response"
|
||||||
|
aIntVariableName : "tinyfd_verbose" "tinyfd_silent" "tinyfd_allowCursesDialogs"
|
||||||
|
"tinyfd_forceConsole" "tinyfd_assumeGraphicDisplay" "tinyfd_winUtf8"
|
||||||
|
**************/
|
||||||
|
|
||||||
|
extern char tinyfd_version[8]; /* contains tinyfd current version number */
|
||||||
|
extern char tinyfd_needs[]; /* info about requirements */
|
||||||
|
extern int tinyfd_verbose; /* 0 (default) or 1 : on unix, prints the command line calls */
|
||||||
|
extern int tinyfd_silent; /* 1 (default) or 0 : on unix, hide errors and warnings from called dialogs */
|
||||||
|
|
||||||
|
/** Curses dialogs are difficult to use and counter-intuitive.
|
||||||
|
On windows they are only ascii and still uses the unix backslash ! **/
|
||||||
|
extern int tinyfd_allowCursesDialogs; /* 0 (default) or 1 */
|
||||||
|
|
||||||
|
extern int tinyfd_forceConsole; /* 0 (default) or 1 */
|
||||||
|
/* for unix & windows: 0 (graphic mode) or 1 (console mode).
|
||||||
|
0: try to use a graphic solution, if it fails then it uses console mode.
|
||||||
|
1: forces all dialogs into console mode even when an X server is present.
|
||||||
|
if enabled, it can use the package Dialog or dialog.exe.
|
||||||
|
on windows it only make sense for console applications */
|
||||||
|
|
||||||
|
extern int tinyfd_assumeGraphicDisplay; /* 0 (default) or 1 */
|
||||||
|
/* some systems don't set the environment variable DISPLAY even when a graphic display is present.
|
||||||
|
set this to 1 to tell tinyfiledialogs to assume the existence of a graphic display */
|
||||||
|
|
||||||
|
extern char tinyfd_response[1024];
|
||||||
|
/* if you pass "tinyfd_query" as aTitle,
|
||||||
|
the functions will not display the dialogs
|
||||||
|
but will return 0 for console mode, 1 for graphic mode.
|
||||||
|
tinyfd_response is then filled with the retain solution.
|
||||||
|
possible values for tinyfd_response are (all lowercase)
|
||||||
|
for graphic mode:
|
||||||
|
windows_wchar windows applescript kdialog zenity zenity3 yad matedialog
|
||||||
|
shellementary qarma python2-tkinter python3-tkinter python-dbus
|
||||||
|
perl-dbus gxmessage gmessage xmessage xdialog gdialog dunst
|
||||||
|
for console mode:
|
||||||
|
dialog whiptail basicinput no_solution */
|
||||||
|
|
||||||
|
void tinyfd_beep(void);
|
||||||
|
|
||||||
|
int tinyfd_notifyPopup(
|
||||||
|
char const * aTitle, /* NULL or "" */
|
||||||
|
char const * aMessage, /* NULL or "" may contain \n \t */
|
||||||
|
char const * aIconType); /* "info" "warning" "error" */
|
||||||
|
/* return has only meaning for tinyfd_query */
|
||||||
|
|
||||||
|
int tinyfd_messageBox(
|
||||||
|
char const * aTitle , /* NULL or "" */
|
||||||
|
char const * aMessage , /* NULL or "" may contain \n \t */
|
||||||
|
char const * aDialogType , /* "ok" "okcancel" "yesno" "yesnocancel" */
|
||||||
|
char const * aIconType , /* "info" "warning" "error" "question" */
|
||||||
|
int aDefaultButton ) ;
|
||||||
|
/* 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel */
|
||||||
|
|
||||||
|
char * tinyfd_inputBox(
|
||||||
|
char const * aTitle , /* NULL or "" */
|
||||||
|
char const * aMessage , /* NULL or "" (\n and \t have no effect) */
|
||||||
|
char const * aDefaultInput ) ; /* NULL = passwordBox, "" = inputbox */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
char * tinyfd_saveFileDialog(
|
||||||
|
char const * aTitle , /* NULL or "" */
|
||||||
|
char const * aDefaultPathAndOrFile , /* NULL or "" , ends with / to set only a directory */
|
||||||
|
int aNumOfFilterPatterns , /* 0 (1 in the following example) */
|
||||||
|
char const * const * aFilterPatterns , /* NULL or char const * lFilterPatterns[1]={"*.txt"} */
|
||||||
|
char const * aSingleFilterDescription ) ; /* NULL or "text files" */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
char * tinyfd_openFileDialog(
|
||||||
|
char const * aTitle, /* NULL or "" */
|
||||||
|
char const * aDefaultPathAndOrFile, /* NULL or "" , ends with / to set only a directory */
|
||||||
|
int aNumOfFilterPatterns , /* 0 (2 in the following example) */
|
||||||
|
char const * const * aFilterPatterns, /* NULL or char const * lFilterPatterns[2]={"*.png","*.jpg"}; */
|
||||||
|
char const * aSingleFilterDescription, /* NULL or "image files" */
|
||||||
|
int aAllowMultipleSelects ) ; /* 0 or 1 */
|
||||||
|
/* in case of multiple files, the separator is | */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
char * tinyfd_selectFolderDialog(
|
||||||
|
char const * aTitle, /* NULL or "" */
|
||||||
|
char const * aDefaultPath); /* NULL or "" */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
char * tinyfd_colorChooser(
|
||||||
|
char const * aTitle, /* NULL or "" */
|
||||||
|
char const * aDefaultHexRGB, /* NULL or "" or "#FF0000" */
|
||||||
|
unsigned char const aDefaultRGB[3] , /* unsigned char lDefaultRGB[3] = { 0 , 128 , 255 }; */
|
||||||
|
unsigned char aoResultRGB[3] ) ; /* unsigned char lResultRGB[3]; */
|
||||||
|
/* aDefaultRGB is used only if aDefaultHexRGB is absent */
|
||||||
|
/* aDefaultRGB and aoResultRGB can be the same array */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
/* returns the hexcolor as a string "#FF0000" */
|
||||||
|
/* aoResultRGB also contains the result */
|
||||||
|
|
||||||
|
|
||||||
|
/************ WINDOWS ONLY SECTION ************************/
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
int tinyfd_notifyPopupW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aMessage, /* NULL or L"" may contain \n \t */
|
||||||
|
wchar_t const * aIconType); /* L"info" L"warning" L"error" */
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
int tinyfd_messageBoxW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aMessage, /* NULL or L"" may contain \n \t */
|
||||||
|
wchar_t const * aDialogType, /* L"ok" L"okcancel" L"yesno" */
|
||||||
|
wchar_t const * aIconType, /* L"info" L"warning" L"error" L"question" */
|
||||||
|
int aDefaultButton ); /* 0 for cancel/no , 1 for ok/yes */
|
||||||
|
/* returns 0 for cancel/no , 1 for ok/yes */
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
wchar_t * tinyfd_inputBoxW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aMessage, /* NULL or L"" (\n nor \t not respected) */
|
||||||
|
wchar_t const * aDefaultInput); /* NULL passwordBox, L"" inputbox */
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
wchar_t * tinyfd_saveFileDialogW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aDefaultPathAndOrFile, /* NULL or L"" , ends with / to set only a directory */
|
||||||
|
int aNumOfFilterPatterns, /* 0 (1 in the following example) */
|
||||||
|
wchar_t const * const * aFilterPatterns, /* NULL or wchar_t const * lFilterPatterns[1]={L"*.txt"} */
|
||||||
|
wchar_t const * aSingleFilterDescription); /* NULL or L"text files" */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
wchar_t * tinyfd_openFileDialogW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aDefaultPathAndOrFile, /* NULL or L"" , ends with / to set only a directory */
|
||||||
|
int aNumOfFilterPatterns , /* 0 (2 in the following example) */
|
||||||
|
wchar_t const * const * aFilterPatterns, /* NULL or wchar_t const * lFilterPatterns[2]={L"*.png","*.jpg"} */
|
||||||
|
wchar_t const * aSingleFilterDescription, /* NULL or L"image files" */
|
||||||
|
int aAllowMultipleSelects ) ; /* 0 or 1 */
|
||||||
|
/* in case of multiple files, the separator is | */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
wchar_t * tinyfd_selectFolderDialogW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aDefaultPath); /* NULL or L"" */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
/* windows only - utf-16 version */
|
||||||
|
wchar_t * tinyfd_colorChooserW(
|
||||||
|
wchar_t const * aTitle, /* NULL or L"" */
|
||||||
|
wchar_t const * aDefaultHexRGB, /* NULL or L"#FF0000" */
|
||||||
|
unsigned char const aDefaultRGB[3], /* unsigned char lDefaultRGB[3] = { 0 , 128 , 255 }; */
|
||||||
|
unsigned char aoResultRGB[3]); /* unsigned char lResultRGB[3]; */
|
||||||
|
/* returns the hexcolor as a string L"#FF0000" */
|
||||||
|
/* aoResultRGB also contains the result */
|
||||||
|
/* aDefaultRGB is used only if aDefaultHexRGB is NULL */
|
||||||
|
/* aDefaultRGB and aoResultRGB can be the same array */
|
||||||
|
/* returns NULL on cancel */
|
||||||
|
|
||||||
|
#endif /*_WIN32 */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /*extern "C"*/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* TINYFILEDIALOGS_H */
|
||||||
|
|
||||||
|
/*
|
||||||
|
________________________________________________________________________________
|
||||||
|
| ____________________________________________________________________________ |
|
||||||
|
| | | |
|
||||||
|
| | on windows: | |
|
||||||
|
| | - for UTF-16, use the wchar_t functions at the bottom of the header file | |
|
||||||
|
| | - _wfopen() requires wchar_t | |
|
||||||
|
| | | |
|
||||||
|
| | - in tinyfiledialogs, char is UTF-8 by default (since v3.6) | |
|
||||||
|
| | - but fopen() expects MBCS (not UTF-8) | |
|
||||||
|
| | - if you want char to be MBCS: set tinyfd_winUtf8 to 0 | |
|
||||||
|
| | | |
|
||||||
|
| | - alternatively, tinyfiledialogs provides | |
|
||||||
|
| | functions to convert between UTF-8, UTF-16 and MBCS | |
|
||||||
|
| |____________________________________________________________________________| |
|
||||||
|
|________________________________________________________________________________|
|
||||||
|
|
||||||
|
- This is not for ios nor android (it works in termux though).
|
||||||
|
- The files can be renamed with extension ".cpp" as the code is 100% compatible C C++
|
||||||
|
(just comment out << extern "C" >> in the header file)
|
||||||
|
- Windows is fully supported from XP to 10 (maybe even older versions)
|
||||||
|
- C# & LUA via dll, see files in the folder EXTRAS
|
||||||
|
- OSX supported from 10.4 to latest (maybe even older versions)
|
||||||
|
- Do not use " and ' as the dialogs will be displayed with a warning
|
||||||
|
instead of the title, message, etc...
|
||||||
|
- There's one file filter only, it may contain several patterns.
|
||||||
|
- If no filter description is provided,
|
||||||
|
the list of patterns will become the description.
|
||||||
|
- On windows link against Comdlg32.lib and Ole32.lib
|
||||||
|
(on windows the no linking claim is a lie)
|
||||||
|
- On unix: it tries command line calls, so no such need (NO LINKING).
|
||||||
|
- On unix you need one of the following:
|
||||||
|
applescript, kdialog, zenity, matedialog, shellementary, qarma, yad,
|
||||||
|
python (2 or 3)/tkinter/python-dbus (optional), Xdialog
|
||||||
|
or curses dialogs (opens terminal if running without console).
|
||||||
|
- One of those is already included on most (if not all) desktops.
|
||||||
|
- In the absence of those it will use gdialog, gxmessage or whiptail
|
||||||
|
with a textinputbox. If nothing is found, it switches to basic console input,
|
||||||
|
it opens a console if needed (requires xterm + bash).
|
||||||
|
- for curses dialogs you must set tinyfd_allowCursesDialogs=1
|
||||||
|
- You can query the type of dialog that will be used (pass "tinyfd_query" as aTitle)
|
||||||
|
- String memory is preallocated statically for all the returned values.
|
||||||
|
- File and path names are tested before return, they should be valid.
|
||||||
|
- tinyfd_forceConsole=1; at run time, forces dialogs into console mode.
|
||||||
|
- On windows, console mode only make sense for console applications.
|
||||||
|
- On windows, console mode is not implemented for wchar_T UTF-16.
|
||||||
|
- Mutiple selects are not possible in console mode.
|
||||||
|
- The package dialog must be installed to run in curses dialogs in console mode.
|
||||||
|
It is already installed on most unix systems.
|
||||||
|
- On osx, the package dialog can be installed via
|
||||||
|
http://macappstore.org/dialog or http://macports.org
|
||||||
|
- On windows, for curses dialogs console mode,
|
||||||
|
dialog.exe should be copied somewhere on your executable path.
|
||||||
|
It can be found at the bottom of the following page:
|
||||||
|
http://andrear.altervista.org/home/cdialog.php
|
||||||
|
*/
|
Loading…
Reference in New Issue
Block a user