Core Function FontDialog

From Sputnik Wiki
Jump to: navigation, search
FontDialog( <font> )

Contents

Description

Allows the user to select a font and allows you to get the Name, size, bold etc values.

Parameters

Font

Optional; A font to use as the default font see examples.

Return Value

Success: Returns array with details.

Failure: Returns null (the user pressing cancel also returns null).

Remarks

Example

Select a font print its details and optionally place it on a control

my $Value = FontDialog();
if($Value)
{
	my List ( $Name, $Size, $Bold, $Italic, $Strikeout, $Underline ) = $Value;
	// Display font information
	print(	"Name '$Name' \n" .
		"Size '$Size' \n" .
		"Bold '" . ($Bold ? "TRUE" : "FALSE") . "' \n" .
		"Italic '" . ($Italic ? "TRUE" : "FALSE") . "' \n" .
		"Strikeout '" . ($Strikeout ? "TRUE" : "FALSE") . "' \n" .
		"Underline '" . ($Underline ? "TRUE" : "FALSE") . "' \n"
		);
	// Create a new GUI font using this information
	my $Flags = 0;
	if($Bold) $Flags |= @fontBold;
	if($Italic) $Flags |= @fontItalic;
	if($Strikeout) $Flags |= @fontStrikeout;
	if($Underline) $Flags |= @FontUnderline;
	$NewFont = GUICreate("Font", $Name, $Size, $Flags);
	// Example of setting this font to a GUI control
	//GUISetProp($mObj, "Font", $NewFont);
}

Same as before but this time set the DEFAULT font of the font dialog to be same as a controls font

// Set your control here and the font in the dialog will use its font as default
my $Value = FontDialog(GUIGetProp($mObj, "Font"));
if($Value)
{
	my List ( $Name, $Size, $Bold, $Italic, $Strikeout, $Underline ) = $Value;
	// Display font information
	print(	"Name '$Name' \n" .
		"Size '$Size' \n" .
		"Bold '" . ($Bold ? "TRUE" : "FALSE") . "' \n" .
		"Italic '" . ($Italic ? "TRUE" : "FALSE") . "' \n" .
		"Strikeout '" . ($Strikeout ? "TRUE" : "FALSE") . "' \n" .
		"Underline '" . ($Underline ? "TRUE" : "FALSE") . "' \n"
		);
	// Create a new GUI font using this information
	my $Flags = 0;
	if($Bold) $Flags |= @fontBold;
	if($Italic) $Flags |= @fontItalic;
	if($Strikeout) $Flags |= @fontStrikeout;
	if($Underline) $Flags |= @FontUnderline;
	$NewFont = GUICreate("Font", $Name, $Size, $Flags);
	// Example of setting this font to a GUI control
	//GUISetProp($mObj, "Font", $NewFont);
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox