Compare commits
6 Commits
4839adf6c1
...
baca22a004
| Author | SHA1 | Date | |
|---|---|---|---|
| baca22a004 | |||
| d40a00c74a | |||
| 2c664b24a9 | |||
| d28aa8a401 | |||
| c3367cdf3e | |||
| 2e83baea8e |
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
@echo off
|
||||||
|
|
||||||
|
cl /c tinyfiledialogs.c /Fo:tinyfiledialogs.obj
|
||||||
|
lib /OUT:tinyfiledialogs.lib tinyfiledialogs.obj
|
||||||
|
move tinyfiledialogs.lib \windows\
|
||||||
|
del tinyfiledialogs.obj
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
case $(uname) in
|
||||||
|
"Darwin")
|
||||||
|
case $(uname -m) in
|
||||||
|
"arm64") lib_path="macos-arm64" ;;
|
||||||
|
*) lib_path="macos" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Static
|
||||||
|
clang -c -o tinyfiledialogs.o tinyfiledialogs.c -fPIC
|
||||||
|
ar r tinyfiledialogs.a tinyfiledialogs.o
|
||||||
|
mv tinyfiledialogs.a $lib_path/tinyfiledialogs.a
|
||||||
|
rm tinyfiledialogs.o
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
gcc -c tinyfiledialogs.c -o linux/tinyfiledialogs.o
|
||||||
|
ar rcs linux/tinyfiledialogs.a linux/tinyfiledialogs.o
|
||||||
|
rm linux/tinyfiledialogs.o
|
||||||
|
;;
|
||||||
|
esac
|
||||||
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
+8171
File diff suppressed because it is too large
Load Diff
+314
@@ -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
|
||||||
|
*/
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
package tinyfiledialogs
|
||||||
|
|
||||||
|
import "base:builtin"
|
||||||
|
import "core:c"
|
||||||
|
|
||||||
|
when ODIN_OS == .Darwin {
|
||||||
|
foreign import lib "./macos-arm64/tinyfiledialogs.a"
|
||||||
|
} else when ODIN_OS == .Linux {
|
||||||
|
// TODO: this is completely untested.
|
||||||
|
foreign import lib "./linux/tinyfiledialogs.a"
|
||||||
|
} else when ODIN_OS == .Windows {
|
||||||
|
foreign import lib {"./windows/tinyfiledialogs.lib", "system:User32.lib", "system:Shell32.lib", "system:Comdlg32.lib", "system:Ole32.lib"}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@(default_calling_convention = "c")
|
||||||
|
@(link_prefix = "tinyfd_")
|
||||||
|
foreign lib {
|
||||||
|
// contains tinyfd current version number
|
||||||
|
version: [8]c.char
|
||||||
|
// info about requirements
|
||||||
|
needs: []c.char
|
||||||
|
// 0 (default) or 1 : on unix, prints the command line calls
|
||||||
|
verbose: c.int
|
||||||
|
// 1 (default) or 0 : on unix, hide errors and warnings from called dialogs
|
||||||
|
silent: c.int
|
||||||
|
// Curses dialogs are difficult to use and counter-intuitive.
|
||||||
|
// On windows they are only ascii and still uses the unix backslash !
|
||||||
|
// 0 (default) or 1
|
||||||
|
allowCursesDialogs: c.int
|
||||||
|
// 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
|
||||||
|
// 0 (default) or 1
|
||||||
|
forceConsole: c.int
|
||||||
|
// 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
|
||||||
|
assumeGraphicDisplay: c.int
|
||||||
|
// 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
|
||||||
|
response: [1024]c.char
|
||||||
|
|
||||||
|
beep :: proc() ---
|
||||||
|
notifyPopup :: proc(aTitle: cstring, aMessage: cstring, aIconType: cstring) -> c.int ---
|
||||||
|
messageBox :: proc(aTitle: cstring, aMessage: cstring, aDialogType: cstring, aIconType: cstring, aDefaultButton: c.int) -> c.int ---
|
||||||
|
inputBox :: proc(aTitle: cstring, aMessage: cstring, aDefaultInput: cstring) -> cstring ---
|
||||||
|
saveFileDialog :: proc(aTitle: cstring, aDefaultPathAndOrFile: cstring, aNumOfFilterPatterns: c.int, aFilterPatterns: [^]cstring, aSingleFilterDescription: cstring) -> cstring ---
|
||||||
|
openFileDialog :: proc(aTitle: cstring, aDefaultPathAndOrFile: cstring, aNumOfFilterPatterns: c.int, aFilterPatterns: [^]cstring, aSingleFilterDescription: cstring, aAllowMultipleSelects: c.int) -> cstring ---
|
||||||
|
selectFolderDialog :: proc(aTitle: cstring, aDefaultPath: cstring) -> cstring ---
|
||||||
|
colorChooser :: proc(aTitle: cstring, aDefaultHexRGB: cstring, aDefaultRGB: [^]c.uchar, aoResultRGB: [^]c.uchar) -> cstring ---
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package tinyfiledialogs
|
||||||
|
|
||||||
|
import "base:builtin"
|
||||||
|
import "core:c"
|
||||||
|
import win32 "core:sys/windows"
|
||||||
|
|
||||||
|
foreign import lib {"./windows/tinyfiledialogs.lib", "system:User32.lib", "system:Shell32.lib", "system:Comdlg32.lib", "system:Ole32.lib"}
|
||||||
|
|
||||||
|
@(default_calling_convention = "c")
|
||||||
|
@(link_prefix = "tinyfd_")
|
||||||
|
foreign lib {
|
||||||
|
winUtf8: c.int
|
||||||
|
|
||||||
|
utf8toMbcs :: proc(aUtf8string: cstring) -> cstring ---
|
||||||
|
utf16toMbcs :: proc(aUtf16string: [^]win32.wchar_t) -> cstring ---
|
||||||
|
mbcsTo16 :: proc(aMbcsString: cstring) -> [^]win32.wchar_t ---
|
||||||
|
mbcsTo8 :: proc(aMbcsString: cstring) -> cstring ---
|
||||||
|
utf8to16 :: proc(aUtf8string: cstring) -> [^]win32.wchar_t ---
|
||||||
|
utf16to8 :: proc(aUtf16string: [^]win32.wchar_t) -> cstring ---
|
||||||
|
// Windows only utf-16 versions
|
||||||
|
notifyPopupW :: proc(aTitle: [^]win32.wchar_t, aMessage: [^]win32.wchar_t, aIconType: [^]win32.wchar_t) -> c.int ---
|
||||||
|
messageBoxW :: proc(aTitle: [^]win32.wchar_t, aMessage: [^]win32.wchar_t, aDialogType: [^]win32.wchar_t, aIconType: [^]win32.wchar_t, aDefaultButton: c.int) -> c.int ---
|
||||||
|
inputBoxW :: proc(aTitle: [^]win32.wchar_t, aMessage: [^]win32.wchar_t, aDefaultInput: [^]win32.wchar_t) -> [^]win32.wchar_t ---
|
||||||
|
saveFileDialogW :: proc(aTitle: [^]win32.wchar_t, aDefaultPathAndOrFile: [^]win32.wchar_t, aNumOfFilterPatterns: c.int, aFilterPatterns: [^]win32.wstring, aSingleFilterDescription: [^]win32.wchar_t) -> [^]win32.wchar_t ---
|
||||||
|
openFileDialogW :: proc(aTitle: [^]win32.wchar_t, aDefaultPathAndOrFile: [^]win32.wchar_t, aNumOfFilterPatterns: c.int, aFilterPatterns: [^]win32.wstring, aSingleFilterDescription: [^]win32.wchar_t, aAllowMultipleSelects: c.int) -> [^]win32.wchar_t ---
|
||||||
|
selectFolderDialogW :: proc(aTitle: [^]win32.wchar_t, aDefaultPath: [^]win32.wchar_t) -> [^]win32.wchar_t ---
|
||||||
|
colorChooserW :: proc(aTitle: [^]win32.wchar_t, aDefaultHexRGB: [^]win32.wchar_t, aDefaultRGB: [^]c.uchar, aoResultRGB: [^]c.uchar) -> win32.wchar_t ---
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -68,3 +68,18 @@ run_machine :: proc(s: ^System, cycles: int) {
|
|||||||
cycle(s)
|
cycle(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new_machine :: proc() -> System {
|
||||||
|
s: System
|
||||||
|
s.pc = 0x200
|
||||||
|
s.current_key = -1
|
||||||
|
// load fonts into the memory
|
||||||
|
for v, i in FONT_SET {
|
||||||
|
s.memory[i] = v
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
reset_machine :: proc(s: ^System) {
|
||||||
|
s^ = new_machine()
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,13 +23,6 @@ main :: proc() {
|
|||||||
// Init the emu 8 "cpu"
|
// Init the emu 8 "cpu"
|
||||||
system := emu.init()
|
system := emu.init()
|
||||||
|
|
||||||
// @TODO: move this into a gui component
|
|
||||||
// load rom, hardcoded for now, will eventually be cli or gui
|
|
||||||
err := emu.load_rom(&system, "./test_roms/7-beep.ch8")
|
|
||||||
if err != nil {
|
|
||||||
panic("failed to load rom!")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initilize sim, gui etc
|
// Initilize sim, gui etc
|
||||||
sim.run_simulator(&system)
|
sim.run_simulator(&system)
|
||||||
|
|
||||||
|
|||||||
@@ -7,27 +7,23 @@ PADDING :: 10
|
|||||||
|
|
||||||
gui_control_bar :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
gui_control_bar :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
||||||
rl.DrawRectangleLinesEx(rect, 1, rl.DARKGRAY)
|
rl.DrawRectangleLinesEx(rect, 1, rl.DARKGRAY)
|
||||||
// Small text area
|
|
||||||
|
|
||||||
// Control bar buttons
|
// Cursor moves for every btn call places them left to right with padding
|
||||||
btn_w : f32 = 80
|
cursor : f32 = rect.x + PANEL_PADDING
|
||||||
btn_h : f32 = rect.height - (PADDING * 2)
|
|
||||||
gap : f32 = 6
|
|
||||||
cursor : f32 = rect.x + PADDING
|
|
||||||
|
|
||||||
if btn(&cursor, rect, btn_h, btn_w, gap, "RUN") {
|
if btn(&cursor, rect, BUTTON_HEIGHT, BUTTON_WIDTH, PANEL_PADDING, "RUN") {
|
||||||
log.info("RUN clicked")
|
if sim.rom_loaded {
|
||||||
sim.paused = false
|
sim.paused = false
|
||||||
sim.running = true
|
sim.running = true
|
||||||
|
} else {
|
||||||
|
log.info("no rom selected, can't run")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if btn(&cursor, rect, btn_h, btn_w, gap, "PAUSE") {
|
if btn(&cursor, rect, BUTTON_HEIGHT, BUTTON_WIDTH, PANEL_PADDING, "PAUSE") {
|
||||||
log.info("PAUSE clicked")
|
|
||||||
sim.paused = true
|
sim.paused = true
|
||||||
sim.running = false
|
sim.running = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if btn(&cursor, rect, btn_h, btn_w, gap, "STEP") { log.info("STEP clicked") }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
btn :: proc(cursor: ^f32, rect: rl.Rectangle, h, w, gap: f32, label: cstring) -> bool {
|
btn :: proc(cursor: ^f32, rect: rl.Rectangle, h, w, gap: f32, label: cstring) -> bool {
|
||||||
|
|||||||
+53
-34
@@ -8,24 +8,23 @@ WINDOW_WIDTH :: 1920
|
|||||||
WINDOW_HEIGHT :: 1080
|
WINDOW_HEIGHT :: 1080
|
||||||
|
|
||||||
// @TODO: If this grows lets move it into its own file
|
// @TODO: If this grows lets move it into its own file
|
||||||
|
// ─── Layout constants ───────────────────────────────────────────────────
|
||||||
SIDEBAR_PERCENT :: 0.20
|
SIDEBAR_PERCENT :: 0.20
|
||||||
DISPLAY_PERCENT :: 0.30
|
DISPLAY_PERCENT :: 0.30
|
||||||
CONTROL_BAR_H :: f32(50)
|
CONTROL_BAR_H :: f32(50)
|
||||||
STATUS_BAR_H :: f32(30)
|
STATUS_BAR_H :: f32(30)
|
||||||
|
|
||||||
// ─── Layout constants ───────────────────────────────────────────────────
|
|
||||||
PANEL_PADDING :: 10
|
PANEL_PADDING :: 10
|
||||||
PANEL_HEADER :: 24
|
PANEL_HEADER :: 24
|
||||||
BUTTON_HEIGHT :: 30
|
BUTTON_HEIGHT :: 30
|
||||||
BUTTON_WIDTH :: 120
|
BUTTON_WIDTH :: 120
|
||||||
DROP_FONT_SIZE :: 20
|
BIG_FONT_SIZE :: 20
|
||||||
KEYPAD_FONT_SIZE :: 18
|
KEYPAD_FONT_SIZE :: 18
|
||||||
|
|
||||||
|
|
||||||
Layout :: struct {
|
Layout :: struct {
|
||||||
control_bar : rl.Rectangle,
|
control_bar : rl.Rectangle,
|
||||||
left_panel : rl.Rectangle,
|
left_panel : rl.Rectangle,
|
||||||
display : rl.Rectangle,
|
display : rl.Rectangle,
|
||||||
|
bottom_panel : rl.Rectangle,
|
||||||
right_panel : rl.Rectangle,
|
right_panel : rl.Rectangle,
|
||||||
status_bar : rl.Rectangle,
|
status_bar : rl.Rectangle,
|
||||||
}
|
}
|
||||||
@@ -36,7 +35,7 @@ run_gui :: proc(sim: ^Simulator) {
|
|||||||
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "raylib")
|
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "raylib")
|
||||||
rl.InitAudioDevice()
|
rl.InitAudioDevice()
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
beep := rl.LoadSound("./beep.wav")
|
beep := rl.LoadSound("./assets/sounds/beep.wav")
|
||||||
|
|
||||||
// Load fonts
|
// Load fonts
|
||||||
font := rl.LoadFontEx("./assets/fonts/Inter_18pt-Regular.ttf", 18, nil, 0)
|
font := rl.LoadFontEx("./assets/fonts/Inter_18pt-Regular.ttf", 18, nil, 0)
|
||||||
@@ -63,8 +62,8 @@ run_gui :: proc(sim: ^Simulator) {
|
|||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
rl.ClearBackground(rl.BLACK)
|
rl.ClearBackground(rl.BLACK)
|
||||||
|
|
||||||
// Cycle the machine to update memory etc
|
|
||||||
if (!sim.paused) {
|
if (!sim.paused) {
|
||||||
|
// Cycle the machine to update memory etc
|
||||||
emu.run_machine(sim.machine, 12)
|
emu.run_machine(sim.machine, 12)
|
||||||
|
|
||||||
// Handle delay timer
|
// Handle delay timer
|
||||||
@@ -78,16 +77,11 @@ run_gui :: proc(sim: ^Simulator) {
|
|||||||
} else {
|
} else {
|
||||||
rl.StopSound(beep)
|
rl.StopSound(beep)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gui_control_bar(layout.control_bar, sim)
|
gui_control_bar(layout.control_bar, sim)
|
||||||
gui_left_panel(layout.left_panel, sim)
|
gui_left_panel(layout.left_panel, sim)
|
||||||
// gui_right_panel(layout.right_panel, s.machine)
|
gui_screen(layout.display, sim)
|
||||||
|
|
||||||
// Screen is just drawing the display buffer just needs that as arg
|
|
||||||
// Not the whole sim struct
|
|
||||||
gui_screen(layout.display, sim.machine)
|
|
||||||
gui_status_bar(layout.status_bar, sim)
|
gui_status_bar(layout.status_bar, sim)
|
||||||
|
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
@@ -101,39 +95,64 @@ run_gui :: proc(sim: ^Simulator) {
|
|||||||
|
|
||||||
// @TODO: If this grows lets move it into its own file
|
// @TODO: If this grows lets move it into its own file
|
||||||
calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout {
|
calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout {
|
||||||
sidebar_width := screen_width * SIDEBAR_PERCENT
|
top_h := CONTROL_BAR_H
|
||||||
content_height := screen_height - CONTROL_BAR_H - STATUS_BAR_H
|
bottom_h := STATUS_BAR_H
|
||||||
display_height := screen_height * DISPLAY_PERCENT - CONTROL_BAR_H - STATUS_BAR_H
|
content_h := screen_height - top_h - bottom_h
|
||||||
|
content_y := top_h
|
||||||
|
|
||||||
|
sidebar_w := screen_width * SIDEBAR_PERCENT
|
||||||
|
|
||||||
|
screen_h_ratio := 0.40
|
||||||
|
bottom_panel_h := content_h * f32(1.0 - screen_h_ratio)
|
||||||
|
screen_h := content_h * f32(screen_h_ratio)
|
||||||
|
memory_h := content_h - screen_h
|
||||||
|
|
||||||
|
center_x := sidebar_w
|
||||||
|
center_w := screen_width - sidebar_w * 2
|
||||||
|
|
||||||
return Layout {
|
return Layout {
|
||||||
control_bar = rl.Rectangle {
|
control_bar = rl.Rectangle{
|
||||||
x = 0,
|
x = 0,
|
||||||
y = 0,
|
y = 0,
|
||||||
width = screen_width,
|
width = screen_width,
|
||||||
height = CONTROL_BAR_H,
|
height = top_h,
|
||||||
},
|
},
|
||||||
left_panel = rl.Rectangle {
|
|
||||||
|
left_panel = rl.Rectangle{
|
||||||
x = 0,
|
x = 0,
|
||||||
y = CONTROL_BAR_H,
|
y = top_h,
|
||||||
width = sidebar_width,
|
width = sidebar_w,
|
||||||
height = content_height,
|
height = content_h,
|
||||||
},
|
},
|
||||||
display = rl.Rectangle {
|
|
||||||
x = sidebar_width,
|
// CHIP-8 screen (top center)
|
||||||
y = CONTROL_BAR_H,
|
display = rl.Rectangle{
|
||||||
width = screen_width - (sidebar_width * 2),
|
x = center_x,
|
||||||
height = display_height,
|
y = top_h,
|
||||||
|
width = center_w,
|
||||||
|
height = screen_h,
|
||||||
},
|
},
|
||||||
right_panel = rl.Rectangle {
|
|
||||||
x = screen_width - sidebar_width,
|
// MEMORY / DEBUG panel (bottom center)
|
||||||
y = CONTROL_BAR_H,
|
bottom_panel = rl.Rectangle{
|
||||||
width = sidebar_width,
|
x = center_x,
|
||||||
height = content_height,
|
y = top_h + screen_h,
|
||||||
|
width = center_w,
|
||||||
|
height = memory_h,
|
||||||
},
|
},
|
||||||
status_bar = rl.Rectangle {
|
|
||||||
|
right_panel = rl.Rectangle{
|
||||||
|
x = screen_width - sidebar_w,
|
||||||
|
y = top_h,
|
||||||
|
width = sidebar_w,
|
||||||
|
height = content_h,
|
||||||
|
},
|
||||||
|
|
||||||
|
status_bar = rl.Rectangle{
|
||||||
x = 0,
|
x = 0,
|
||||||
y = screen_height - STATUS_BAR_H,
|
y = screen_height - bottom_h,
|
||||||
width = screen_width, height = STATUS_BAR_H,
|
width = screen_width,
|
||||||
|
height = bottom_h,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import "core:log"
|
|||||||
import "core:strings"
|
import "core:strings"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
|
import emu "../machine"
|
||||||
|
import tfd "../../external/tinyfiledialogs"
|
||||||
|
|
||||||
gui_left_panel :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
gui_left_panel :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
||||||
// ── Top panel and components ──
|
// ── Top panel and components ──
|
||||||
top_panel := rl.Rectangle {
|
top_panel := rl.Rectangle {
|
||||||
@@ -16,13 +19,12 @@ gui_left_panel :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
|||||||
|
|
||||||
// Dropzone/file loader
|
// Dropzone/file loader
|
||||||
file_loader_rect := rl.Rectangle {
|
file_loader_rect := rl.Rectangle {
|
||||||
top_panel.x + PANEL_PADDING,
|
top_panel.x,
|
||||||
top_panel.y + PANEL_HEADER,
|
top_panel.y,
|
||||||
top_panel.width - PANEL_PADDING * 2,
|
top_panel.width,
|
||||||
(top_panel.height / 3) - PANEL_HEADER - PANEL_PADDING * 2,
|
(top_panel.height / 3) - PANEL_HEADER - PANEL_PADDING * 2,
|
||||||
}
|
}
|
||||||
rl.GuiPanel(file_loader_rect, "Rom / File")
|
gui_file_loader(file_loader_rect, sim)
|
||||||
gui_file_loader(file_loader_rect)
|
|
||||||
|
|
||||||
// ── Bottom panel and components ──
|
// ── Bottom panel and components ──
|
||||||
bottom_panel := rl.Rectangle {
|
bottom_panel := rl.Rectangle {
|
||||||
@@ -35,7 +37,9 @@ gui_left_panel :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
|||||||
gui_key_pad(bottom_panel, sim.machine.keypad, sim.font)
|
gui_key_pad(bottom_panel, sim.machine.keypad, sim.font)
|
||||||
}
|
}
|
||||||
|
|
||||||
gui_file_loader :: proc(rect: rl.Rectangle) {
|
gui_file_loader :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
||||||
|
rl.GuiPanel(rect, "Rom / File")
|
||||||
|
|
||||||
// drop-zone occupies the panel's content area, minus space for the button
|
// drop-zone occupies the panel's content area, minus space for the button
|
||||||
drop_zone := rl.Rectangle {
|
drop_zone := rl.Rectangle {
|
||||||
rect.x + PANEL_PADDING,
|
rect.x + PANEL_PADDING,
|
||||||
@@ -47,10 +51,10 @@ gui_file_loader :: proc(rect: rl.Rectangle) {
|
|||||||
|
|
||||||
// centered drop-zone text
|
// centered drop-zone text
|
||||||
text: cstring = "Drop a CHIP-8 ROM here"
|
text: cstring = "Drop a CHIP-8 ROM here"
|
||||||
text_width := rl.MeasureText(text, DROP_FONT_SIZE)
|
text_width := rl.MeasureText(text, BIG_FONT_SIZE)
|
||||||
text_x := drop_zone.x + (drop_zone.width - f32(text_width)) / 2
|
text_x := drop_zone.x + (drop_zone.width - f32(text_width)) / 2
|
||||||
text_y := drop_zone.y + (drop_zone.height - f32(DROP_FONT_SIZE)) / 2
|
text_y := drop_zone.y + (drop_zone.height - f32(BIG_FONT_SIZE)) / 2
|
||||||
rl.DrawText(text, i32(text_x), i32(text_y), DROP_FONT_SIZE, rl.GRAY)
|
rl.DrawTextEx(sim.font, text, {text_x, text_y}, BIG_FONT_SIZE, 1, rl.WHITE)
|
||||||
|
|
||||||
// open rom button below drop-zone
|
// open rom button below drop-zone
|
||||||
btn_rect := rl.Rectangle {
|
btn_rect := rl.Rectangle {
|
||||||
@@ -61,7 +65,23 @@ gui_file_loader :: proc(rect: rl.Rectangle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rl.GuiButton(btn_rect, "Open ROM") {
|
if rl.GuiButton(btn_rect, "Open ROM") {
|
||||||
// @TODO: get tinyfiledialog working here
|
ret := tfd.openFileDialog("Open File Dialog", nil, 0, nil, nil, 0,)
|
||||||
|
rom_path := string(ret)
|
||||||
|
if rom_path == "" do return
|
||||||
|
|
||||||
|
// reset machine state
|
||||||
|
emu.reset_machine(sim.machine)
|
||||||
|
|
||||||
|
// load new rom
|
||||||
|
err := emu.load_rom(sim.machine, rom_path)
|
||||||
|
if err != nil {
|
||||||
|
// @TODO: update status bar here
|
||||||
|
panic("failed to load rom!")
|
||||||
|
}
|
||||||
|
|
||||||
|
sim.rom_loaded = true
|
||||||
|
sim.running = true
|
||||||
|
sim.paused = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle file drop
|
// Handle file drop
|
||||||
@@ -96,6 +116,7 @@ gui_key_pad :: proc(rect: rl.Rectangle, display: [16]bool, font: rl.Font) {
|
|||||||
label: string,
|
label: string,
|
||||||
index: int,
|
index: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
keys := [16]Key {
|
keys := [16]Key {
|
||||||
{"1", 1}, {"2", 2}, {"3", 3}, {"C", 12},
|
{"1", 1}, {"2", 2}, {"3", 3}, {"C", 12},
|
||||||
{"4", 4}, {"5", 5}, {"6", 6}, {"D", 13},
|
{"4", 4}, {"5", 5}, {"6", 6}, {"D", 13},
|
||||||
@@ -122,7 +143,9 @@ gui_key_pad :: proc(rect: rl.Rectangle, display: [16]bool, font: rl.Font) {
|
|||||||
if display[val.index] { rl.DrawRectangleRec(irect, rl.BLACK) }
|
if display[val.index] { rl.DrawRectangleRec(irect, rl.BLACK) }
|
||||||
|
|
||||||
rl.DrawRectangleLinesEx(irect, 1, rl.GRAY)
|
rl.DrawRectangleLinesEx(irect, 1, rl.GRAY)
|
||||||
rl.DrawTextEx( font, str,
|
rl.DrawTextEx(
|
||||||
|
font,
|
||||||
|
str,
|
||||||
rl.Vector2{irect.x + btn_width / 2, irect.y + btn_height / 2},
|
rl.Vector2{irect.x + btn_width / 2, irect.y + btn_height / 2},
|
||||||
KEYPAD_FONT_SIZE,
|
KEYPAD_FONT_SIZE,
|
||||||
1,
|
1,
|
||||||
|
|||||||
+36
-22
@@ -1,38 +1,52 @@
|
|||||||
package simulator
|
package simulator
|
||||||
|
|
||||||
import m "../machine"
|
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
gui_screen :: proc(rect: rl.Rectangle, s: ^m.System) {
|
gui_screen :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
||||||
// Make sure screen is staying in its aspect ratio
|
s := sim.machine
|
||||||
chip8_aspect := f32(64.0 / 32.0)
|
|
||||||
available_aspect := rect.width / rect.height
|
|
||||||
screen_rect := rect
|
|
||||||
|
|
||||||
if available_aspect > chip8_aspect {
|
// 2 : 1
|
||||||
// Area is too wide
|
// 2 so, for every 1 unit of height I have 2 units of width
|
||||||
screen_rect.width = rect.height * chip8_aspect
|
// twice as wide as it is tall, or half as tall as it is wide
|
||||||
screen_rect.x = rect.x + (rect.width - screen_rect.width) / 2
|
aspect_ratio : f32 = 64.0 / 32.0
|
||||||
|
|
||||||
|
// create viewport for the ratio
|
||||||
|
view := rect
|
||||||
|
avail_space := rect.width / rect.height
|
||||||
|
|
||||||
|
if avail_space > aspect_ratio {
|
||||||
|
view.width = rect.height * aspect_ratio
|
||||||
|
view.x = rect.x + (rect.width - view.width) * 0.5
|
||||||
} else {
|
} else {
|
||||||
// Area is too tall
|
view.height = rect.width / aspect_ratio
|
||||||
screen_rect.height = rect.width / chip8_aspect
|
view.y = rect.y + (rect.height - view.height) * 0.5
|
||||||
screen_rect.y = rect.y + (rect.height - screen_rect.height) / 2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_size := min(int(screen_rect.width / 64), int(screen_rect.height / 32))
|
// get scale
|
||||||
pixel_size = max(pixel_size, 1)
|
pixel := min(int(view.width / 64), int(view.height / 32))
|
||||||
|
pixel = max(pixel, 1)
|
||||||
|
|
||||||
actual_width := pixel_size * 64
|
draw_w := pixel * 64
|
||||||
actual_height := pixel_size * 32
|
draw_h := pixel * 32
|
||||||
|
|
||||||
display_x := i32(screen_rect.x) + i32(int(screen_rect.width) - actual_width) / 2
|
// center frame
|
||||||
display_y := i32(screen_rect.y) + i32(int(screen_rect.height) - actual_height) / 2
|
x := i32(view.x + (view.width - f32(draw_w)) * 0.5)
|
||||||
|
y := i32(view.y + (view.height - f32(draw_h)) * 0.5)
|
||||||
|
|
||||||
// Debug borders
|
|
||||||
rl.DrawRectangleLinesEx(rect, 1, rl.DARKGRAY)
|
rl.DrawRectangleLinesEx(rect, 1, rl.DARKGRAY)
|
||||||
rl.DrawRectangleLinesEx(screen_rect, 2, rl.WHITE)
|
rl.DrawRectangleLinesEx(view, 2, rl.WHITE)
|
||||||
|
|
||||||
render_display(&s.display, display_x, display_y, i32(pixel_size))
|
if !sim.rom_loaded {
|
||||||
|
// centered drop-zone text
|
||||||
|
text: cstring = "PLEASE SELECT AND LOAD A CHIP 8 ROM"
|
||||||
|
text_width := rl.MeasureText(text, BIG_FONT_SIZE)
|
||||||
|
text_x := view.x + (view.width - f32(text_width)) * 0.6
|
||||||
|
text_y := view.y + (view.height - f32(BIG_FONT_SIZE)) * 0.5
|
||||||
|
|
||||||
|
rl.DrawTextEx(sim.font, text, {text_x,text_y}, BIG_FONT_SIZE, 1, rl.WHITE)
|
||||||
|
} else {
|
||||||
|
render_display(&s.display, x, y, i32(pixel))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
@(private = "file")
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import rl "vendor:raylib"
|
|||||||
|
|
||||||
Simulator :: struct {
|
Simulator :: struct {
|
||||||
machine: ^emu.System,
|
machine: ^emu.System,
|
||||||
|
rom_loaded: bool,
|
||||||
running: bool,
|
running: bool,
|
||||||
paused: bool,
|
paused: bool,
|
||||||
cycles_per_second: int,
|
cycles_per_second: int,
|
||||||
@@ -15,8 +16,9 @@ Simulator :: struct {
|
|||||||
run_simulator :: proc(s: ^emu.System) {
|
run_simulator :: proc(s: ^emu.System) {
|
||||||
sim := Simulator {
|
sim := Simulator {
|
||||||
machine = s,
|
machine = s,
|
||||||
running = true,
|
rom_loaded = false,
|
||||||
paused = false,
|
running = false,
|
||||||
|
paused = true,
|
||||||
cycles_per_second = 12
|
cycles_per_second = 12
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package simulator
|
|||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
|
// @TODO: render status bar text
|
||||||
gui_status_bar :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
gui_status_bar :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
||||||
|
// Left to right text draws
|
||||||
rl.DrawRectangleLinesEx(rect, 1, rl.DARKGRAY)
|
rl.DrawRectangleLinesEx(rect, 1, rl.DARKGRAY)
|
||||||
|
|
||||||
cursor: f32 = rect.x + PADDING
|
cursor: f32 = rect.x + PADDING
|
||||||
@@ -16,7 +18,21 @@ gui_status_bar :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
status_divider(&cursor, cy)
|
status_divider(&cursor, cy)
|
||||||
status_text(&cursor, cy, fmt.ctprintf("FPS: %d", rl.GetFPS()), sim.font)
|
status_text(&cursor, cy, fmt.ctprintf("Rom Loaded: %v", sim.rom_loaded), sim.font)
|
||||||
|
|
||||||
|
// FPS set far right
|
||||||
|
fps_text := fmt.ctprintf("FPS: %d", rl.GetFPS())
|
||||||
|
fps_width := rl.MeasureTextEx(sim.font, fps_text, f32(sim.font.baseSize), 1).x
|
||||||
|
fps_x := rect.x + rect.width - PADDING - fps_width
|
||||||
|
|
||||||
|
rl.DrawTextEx(
|
||||||
|
sim.font,
|
||||||
|
fps_text,
|
||||||
|
{fps_x, cy - f32(sim.font.baseSize) * 0.5},
|
||||||
|
f32(sim.font.baseSize),
|
||||||
|
1,
|
||||||
|
rl.RAYWHITE,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusIconShape :: enum { CIRCLE, SQUARE }
|
StatusIconShape :: enum { CIRCLE, SQUARE }
|
||||||
|
|||||||
Reference in New Issue
Block a user