Table of Contents

Using native File/Message Dialog Boxes in an Orx application.

Orx being a game engine, does not itself offer any support for UI dialog boxes. Most commonly used dialogs are:

If you want to write an application in Orx that requires a dialog, you could roll your own. But this is complicated, and I'm sure you'd rather get on with the job of your application itself. However there is a neat little library out there called tinyfiledialogs which will do all this for you.

Tiny File Dialogs is a perfect companion for Orx. Both projects are cross-platform. Your application can be compiled and used on Windows, Mac or Linux.

To set up is very easy.

Downloading and Integrating into your project

Download the header file here: https://sourceforge.net/projects/tinyfiledialogs/files/tinyfiledialogs.h/download

Copy this into your orxproject/include folder.

Download the source file here: https://sourceforge.net/projects/tinyfiledialogs/files/tinyfiledialogs.c/download

Copy this into your orxproject/src folder.

Include the tinyfiledialogs.c file into your project source files so that it will be compiled along with your other source files.

In your main source files, include the header with:

#include "tinyfiledialogs.h"

For Windows users, change the linker libraries setting of your project from:

orxd;winmm

To:

orxd;winmm;comdlg32;ole32

You don't need to link to anything for linux.

Calling a Messagebox Dialog

Message boxes or Message dialogs are used to inform the user that something has happened, or that they need to acknowledge something.

They can either have a single button to acknowledge or a choice of two or more buttons.

To display a “Yes/No” style message box use the following:

orxBOOL OpenQuitDialog(){
	orxBOOL choice = tinyfd_messageBox ( 
		"Quit?", 
		"Are you sure you want to quit?",
		"yesno",
		"question",
		0
	);
 
	return choice;
}

Compile and run. Hopefully when your Orx application loads, a message dialog box will appear. You can click yes or no, and the return value is returned from the function.

Calling an Open File Dialog

An open file dialog allows you to browse the file system and select the filename (and path) of your file. It then returns this path and file as a string to your application.

You can use it like this:

const orxSTRING OpenFileDialog(){
 
	const orxSTRING openFileName;
	const int numberOfPatterns = 3;
	const orxSTRING filterPatterns[numberOfPatterns] = { "*.jpg", "*.png", "*.gif" };
	const orxBOOL allowMultipleSelects = orxFALSE;
 
	openFileName = tinyfd_openFileDialog(
		"Select an image file.",
		"",
		numberOfPatterns,
		filterPatterns,
		"Image files (*.jpg, *.png, *.gif)",
		allowMultipleSelects
	);
 
	return openFileName;
}

(Open File Dialog on Ubuntu Linux running KDE)

Calling a Save File Dialog

In the same fashion as a opwn file dialog, you can also use a save file dialog:

const orxSTRING SaveFileDialog(){
	const orxSTRING saveFileName;
	const int numberOfPatterns = 2;
	const orxSTRING filterPatterns[numberOfPatterns] = { "*.mpg", "*.flv" };
 
	saveFileName = tinyfd_saveFileDialog (
		"Save video file",
		"", 
		numberOfPatterns, 
		filterPatterns, 
		"Video file (*.mpg, *.flv)"
	);
 
	return saveFileName;
}

There are many other dialog types available.

Full instructions, options, requirements and code examples for all dialog types can be found here: https://sourceforge.net/projects/tinyfiledialogs/files/