2019-11-11 00:11:59 -05:00
//============================================================================
//----------------------------------------------------------------------------
// About.c
//----------------------------------------------------------------------------
//============================================================================
2020-01-02 01:32:00 -05:00
# include "PLArrayView.h"
2019-12-25 22:20:10 -05:00
# include "PLKeyEncoding.h"
2019-12-29 23:14:37 -05:00
# include "PLControlDefinitions.h"
2020-06-06 02:25:10 -04:00
# include "FontFamily.h"
# include "PLButtonWidget.h"
# include "PLLabelWidget.h"
2019-11-11 00:11:59 -05:00
# include "PLNumberFormatting.h"
# include "PLResources.h"
# include "PLSound.h"
# include "PLPasStr.h"
2020-06-06 02:25:10 -04:00
# include "PLStandardColors.h"
2020-01-02 01:32:00 -05:00
# include "PLSysCalls.h"
2020-01-23 01:19:12 -05:00
# include "PLTimeTaggedVOSEvent.h"
2020-01-02 01:32:00 -05:00
# include "PLWidgets.h"
2019-11-11 00:11:59 -05:00
# include "About.h"
2019-12-30 20:53:11 -05:00
# include "DialogManager.h"
2019-11-11 00:11:59 -05:00
# include "DialogUtils.h"
# include "Environ.h"
# include "Externs.h"
2020-06-06 02:25:10 -04:00
# include "GpApplicationName.h"
# include "GpBuildVersion.h"
2019-12-29 21:31:49 -05:00
# include "HostSystemServices.h"
2020-06-06 02:25:10 -04:00
# include "RenderedFont.h"
2020-09-12 14:01:51 -04:00
# include "GpRenderedFontMetrics.h"
2020-06-06 02:25:10 -04:00
# include "ResolveCachingColor.h"
2020-01-23 01:19:12 -05:00
# include "ResourceManager.h"
2019-12-29 04:13:35 -05:00
# include "ScanlineMask.h"
2020-06-06 02:25:10 -04:00
# include "WindowDef.h"
# include "WindowManager.h"
2019-11-11 00:11:59 -05:00
2019-12-30 20:53:11 -05:00
static void HiLiteOkayButton ( DrawSurface * surface ) ;
static void UnHiLiteOkayButton ( DrawSurface * surface ) ;
2019-12-31 02:42:20 -05:00
static void UpdateMainPict ( Dialog * ) ;
2020-09-12 22:29:57 -04:00
static int16_t AboutFilter ( void * context , Dialog * , const TimeTaggedVOSEvent * evt ) ;
static int16_t AboutFrameworkFilter ( void * context , Dialog * , const TimeTaggedVOSEvent * evt ) ;
2019-11-11 00:11:59 -05:00
2020-01-02 01:32:00 -05:00
static Point okayButtLowerV , okayButtUpperV ;
2019-11-11 00:11:59 -05:00
static Rect okayButtonBounds , mainPICTBounds ;
static Boolean okayButtIsHiLit , clickedDownInOkay ;
//============================================================== Functions
//-------------------------------------------------------------- DoAbout
// Brings up the About dialog box.
void DoAbout ( void )
{
# define kAboutDialogID 150 // res ID of About dialog
# define kTextItemVers 2 // item number of version text
# define kPictItemMain 4 // item number of main PICT
2019-12-31 02:42:20 -05:00
Dialog * aboutDialog ;
2019-11-11 00:11:59 -05:00
Str255 longVersion ;
StringPtr messagePtr ;
VersRecHndl version ;
2019-12-29 23:14:37 -05:00
ControlHandle itemHandle ;
2020-01-23 01:19:12 -05:00
short hit ;
2019-11-11 00:11:59 -05:00
2020-02-02 01:38:38 -05:00
aboutDialog = PortabilityLayer : : DialogManager : : GetInstance ( ) - > LoadDialog ( kAboutDialogID , PL_GetPutInFrontWindowPtr ( ) , nullptr ) ;
2019-11-11 00:11:59 -05:00
// if (aboutDialog == nil)
// RedAlert(kErrDialogDidntLoad);
2020-01-23 01:19:12 -05:00
version = PortabilityLayer : : ResourceManager : : GetInstance ( ) - > GetAppResource ( ' vers ' , 1 ) . StaticCast < VersionRecord > ( ) ;
2019-11-11 00:11:59 -05:00
if ( version ! = nil )
{
messagePtr = ( * * version ) . shortVersion + 1 + ( * * version ) . shortVersion [ 0 ] ;
2020-03-14 06:38:46 -04:00
memcpy ( & longVersion , messagePtr , ( ( UInt8 ) * messagePtr ) + 1 ) ;
2019-11-11 00:11:59 -05:00
SetDialogString ( aboutDialog , kTextItemVers , longVersion ) ;
}
2020-01-02 01:32:00 -05:00
okayButtonBounds = aboutDialog - > GetItems ( ) [ kOkayButton - 1 ] . GetWidget ( ) - > GetRect ( ) ;
okayButtUpperV = Point : : Create ( okayButtonBounds . left + 45 , okayButtonBounds . top + 1 ) ;
okayButtLowerV = Point : : Create ( okayButtUpperV . h - 28 , okayButtUpperV . v + 60 ) ;
2019-11-11 00:11:59 -05:00
okayButtIsHiLit = false ; // Initially, button is not hilit
clickedDownInOkay = false ; // Initially, didn't click in okay button
2020-01-02 01:32:00 -05:00
mainPICTBounds = aboutDialog - > GetItems ( ) [ kPictItemMain - 1 ] . GetWidget ( ) - > GetRect ( ) ;
UpdateMainPict ( aboutDialog ) ;
2019-11-11 00:11:59 -05:00
do // Loop until user wants to exit
{
2020-09-12 22:29:57 -04:00
hit = aboutDialog - > ExecuteModal ( nullptr , AboutFilter ) ;
2019-11-11 00:11:59 -05:00
}
2020-01-02 01:32:00 -05:00
while ( hit ! = kOkayButton ) ;
2020-01-01 20:49:18 -05:00
aboutDialog - > Destroy ( ) ;
2019-11-11 00:11:59 -05:00
}
2020-06-06 02:25:10 -04:00
void DoAboutFramework ( void )
{
# define kAboutFrameworkDialogTemplateID 2000
const Rect windowRect = Rect : : Create ( 0 , 0 , 272 , 450 ) ;
PortabilityLayer : : WindowDef wdef = PortabilityLayer : : WindowDef : : Create ( windowRect , PortabilityLayer : : WindowStyleFlags : : kAlert , true , 0 , 0 , PSTR ( " " ) ) ;
PortabilityLayer : : ResolveCachingColor blackColor = StdColors : : Black ( ) ;
PortabilityLayer : : RenderedFont * font = GetApplicationFont ( 12 , PortabilityLayer : : FontFamilyFlag_Bold , true ) ;
PortabilityLayer : : RenderedFont * fontLight = GetApplicationFont ( 8 , PortabilityLayer : : FontFamilyFlag_None , true ) ;
int16_t verticalPoint = 16 + font - > GetMetrics ( ) . m_ascent ;
int16_t horizontalOffset = 16 ;
const int16_t spacing = 12 ;
PortabilityLayer : : DialogManager * dialogManager = PortabilityLayer : : DialogManager : : GetInstance ( ) ;
Dialog * dialog = dialogManager - > LoadDialogFromTemplate ( kAboutFrameworkDialogTemplateID , windowRect , true , false , 0 , 0 , PL_GetPutInFrontWindowPtr ( ) , PSTR ( " " ) , nullptr ) ;
2020-09-12 23:07:44 -04:00
# if !GP_DEBUG_CONFIG
2020-06-06 02:25:10 -04:00
# define ABOUT_DIALOG_CONFIGURATION_TAG "Release"
# else
# define ABOUT_DIALOG_CONFIGURATION_TAG "Debug"
# endif
Window * window = dialog - > GetWindow ( ) ;
DrawSurface * surface = window - > GetDrawSurface ( ) ;
surface - > DrawString ( Point : : Create ( horizontalOffset , verticalPoint + spacing * 0 ) , PSTR ( GP_APPLICATION_NAME " " GP_APPLICATION_VERSION_STRING " \xa9 " GP_APPLICATION_COPYRIGHT_STRING ) , blackColor , font ) ;
surface - > DrawString ( Point : : Create ( horizontalOffset , verticalPoint + spacing * 2 ) , PSTR ( GP_APPLICATION_NAME " is an unoffical third-party port of Glider PRO \xaa . " ) , blackColor , font ) ;
surface - > DrawString ( Point : : Create ( horizontalOffset , verticalPoint + spacing * 4 ) , PSTR ( " This software is not maintained by, supported by, endorsed by, or " ) , blackColor , font ) ;
surface - > DrawString ( Point : : Create ( horizontalOffset , verticalPoint + spacing * 5 ) , PSTR ( " otherwise associated with the authors and publishers of Glider PRO \xaa . " ) , blackColor , font ) ;
surface - > DrawString ( Point : : Create ( horizontalOffset , verticalPoint + spacing * 7 ) , PSTR ( " Please do not contact any of them regarding issues that you have " ) , blackColor , font ) ;
surface - > DrawString ( Point : : Create ( horizontalOffset , verticalPoint + spacing * 8 ) , PSTR ( " with " GP_APPLICATION_NAME " . " ) , blackColor , font ) ;
surface - > DrawString ( Point : : Create ( horizontalOffset , verticalPoint + spacing * 10 ) , PSTR ( " If you would like to contribute to this project, visit: " ) , blackColor , font ) ;
surface - > DrawString ( Point : : Create ( horizontalOffset , verticalPoint + spacing * 11 ) , PSTR ( GP_APPLICATION_WEBSITE_STRING ) , blackColor , font ) ;
surface - > DrawString ( Point : : Create ( horizontalOffset , verticalPoint + spacing * 13 ) , PSTR ( " To report a problem or request support, submit an issue via " ) , blackColor , font ) ;
surface - > DrawString ( Point : : Create ( horizontalOffset , verticalPoint + spacing * 14 ) , PSTR ( " the website above. " ) , blackColor , font ) ;
surface - > DrawString ( Point : : Create ( horizontalOffset , verticalPoint + spacing * 16 ) , PSTR ( " For more information, please see the accompanying documentation. " ) , blackColor , font ) ;
2020-06-07 22:17:02 -04:00
surface - > DrawString ( Point : : Create ( horizontalOffset , windowRect . bottom - 16 ) , PSTR ( " Build: " __DATE__ " " __TIME__ " " ABOUT_DIALOG_CONFIGURATION_TAG ) , blackColor , fontLight ) ;
2020-06-06 02:25:10 -04:00
DrawDefaultButton ( dialog ) ;
int16_t hit = 0 ;
do
{
2020-09-12 22:29:57 -04:00
hit = dialog - > ExecuteModal ( nullptr , AboutFrameworkFilter ) ;
2020-06-06 02:25:10 -04:00
} while ( hit ! = kOkayButton ) ;
dialog - > Destroy ( ) ;
}
2019-11-11 00:11:59 -05:00
//============================================================== Static Functions
//-------------------------------------------------------------- HiLiteOkayButton
// Draws my pseudo-button to appear as though it is clicked on.
2019-12-30 20:53:11 -05:00
static void HiLiteOkayButton ( DrawSurface * surface )
2019-11-11 00:11:59 -05:00
{
# define kOkayButtPICTHiLit 151 // res ID of unhilit button PICT
2020-01-18 21:15:07 -05:00
THandle < BitmapImage > thePict ;
2019-11-11 00:11:59 -05:00
if ( ! okayButtIsHiLit )
{
2020-01-23 01:19:12 -05:00
thePict = PortabilityLayer : : ResourceManager : : GetInstance ( ) - > GetAppResource ( ' PICT ' , kOkayButtPICTHiLit ) . StaticCast < BitmapImage > ( ) ;
2019-11-11 00:11:59 -05:00
if ( thePict ! = nil )
{
2019-12-30 20:53:11 -05:00
surface - > DrawPicture ( thePict , okayButtonBounds ) ;
2019-12-29 23:14:37 -05:00
thePict . Dispose ( ) ;
2019-11-11 00:11:59 -05:00
okayButtIsHiLit = true ;
}
}
}
//-------------------------------------------------------------- UnHiLiteOkayButton
// Draws my pseudo-button normal (not clicked on).
2019-12-30 20:53:11 -05:00
static void UnHiLiteOkayButton ( DrawSurface * surface )
2019-11-11 00:11:59 -05:00
{
# define kOkayButtPICTNotHiLit 150 // res ID of hilit button PICT
2020-01-18 21:15:07 -05:00
THandle < BitmapImage > thePict ;
2019-11-11 00:11:59 -05:00
if ( okayButtIsHiLit )
{
2020-01-23 01:19:12 -05:00
thePict = PortabilityLayer : : ResourceManager : : GetInstance ( ) - > GetAppResource ( ' PICT ' , kOkayButtPICTNotHiLit ) . StaticCast < BitmapImage > ( ) ;
2019-11-11 00:11:59 -05:00
if ( thePict ! = nil )
{
2019-12-30 20:53:11 -05:00
surface - > DrawPicture ( thePict , okayButtonBounds ) ;
2019-12-29 23:14:37 -05:00
thePict . Dispose ( ) ;
2019-11-11 00:11:59 -05:00
okayButtIsHiLit = false ;
}
}
}
//-------------------------------------------------------------- UpdateMainPict
// Redraws the main graphic in the dialog (in response to an update event).
2019-12-31 02:42:20 -05:00
static void UpdateMainPict ( Dialog * theDial )
2019-11-11 00:11:59 -05:00
{
Str255 theStr , theStr2 ;
2019-12-29 21:31:49 -05:00
uint64_t freeMemory ;
freeMemory = PortabilityLayer : : HostSystemServices : : GetInstance ( ) - > GetFreeMemoryCosmetic ( ) ;
2019-11-11 00:11:59 -05:00
PasStringCopy ( PSTR ( " Memory: " ) , theStr ) ; // display free memory
2019-12-29 21:31:49 -05:00
long totalSize = static_cast < long > ( freeMemory / 1024 ) ;
2019-11-11 00:11:59 -05:00
NumToString ( totalSize , theStr2 ) ;
PasStringConcat ( theStr , theStr2 ) ;
PasStringConcat ( theStr , PSTR ( " K " ) ) ;
DrawDialogUserText2 ( theDial , 7 , theStr ) ;
PasStringCopy ( PSTR ( " Screen: " ) , theStr ) ; // display screen size/depth
2020-04-04 02:20:03 -04:00
NumToString ( ( long ) ( thisMac . fullScreen . right - thisMac . fullScreen . left ) , theStr2 ) ;
2019-11-11 00:11:59 -05:00
PasStringConcat ( theStr , theStr2 ) ;
PasStringConcat ( theStr , PSTR ( " x " ) ) ;
2020-04-04 02:20:03 -04:00
NumToString ( ( long ) ( thisMac . fullScreen . bottom - thisMac . fullScreen . top ) , theStr2 ) ;
2019-11-11 00:11:59 -05:00
PasStringConcat ( theStr , theStr2 ) ;
PasStringConcat ( theStr , PSTR ( " x " ) ) ;
NumToString ( ( long ) thisMac . isDepth , theStr2 ) ;
PasStringConcat ( theStr , theStr2 ) ;
DrawDialogUserText2 ( theDial , 8 , theStr ) ;
}
2020-01-02 01:32:00 -05:00
static bool PointIsInDiagonalOkayButton ( const Point & pt )
{
const Point upperVPt = pt - okayButtUpperV ;
const Point lowerVPt = pt - okayButtLowerV ;
const bool edge1 = ( upperVPt . h + upperVPt . v ) > = 0 ;
const bool edge2 = ( - upperVPt . h + upperVPt . v ) > = 0 ;
const bool edge3 = ( lowerVPt . h - lowerVPt . v ) > = 0 ;
const bool edge4 = ( - lowerVPt . h - lowerVPt . v ) > = 0 ;
return edge1 & & edge2 & & edge3 & & edge4 ;
}
2019-11-11 00:11:59 -05:00
//-------------------------------------------------------------- AboutFilter
// Dialog filter for the About dialog.
2020-09-12 22:29:57 -04:00
static int16_t AboutFilter ( void * context , Dialog * dialog , const TimeTaggedVOSEvent * evt )
2019-11-11 00:11:59 -05:00
{
2020-01-02 01:32:00 -05:00
bool handledIt = false ;
int16_t hit = - 1 ;
2019-12-30 20:53:11 -05:00
2020-02-16 20:55:47 -05:00
if ( ! evt )
return - 1 ;
2020-01-02 01:32:00 -05:00
Window * window = dialog - > GetWindow ( ) ;
DrawSurface * surface = window - > GetDrawSurface ( ) ;
2020-02-16 20:55:47 -05:00
if ( evt - > IsKeyDownEvent ( ) )
2019-11-11 00:11:59 -05:00
{
2020-02-16 20:55:47 -05:00
switch ( PackVOSKeyCode ( evt - > m_vosEvent . m_event . m_keyboardInputEvent ) )
2019-11-11 00:11:59 -05:00
{
2020-01-02 01:32:00 -05:00
case PL_KEY_SPECIAL ( kEnter ) :
case PL_KEY_NUMPAD_SPECIAL ( kEnter ) :
2019-12-30 20:53:11 -05:00
HiLiteOkayButton ( surface ) ;
2020-01-02 01:32:00 -05:00
PLSysCalls : : Sleep ( 8 ) ;
2019-12-30 20:53:11 -05:00
UnHiLiteOkayButton ( surface ) ;
2020-01-02 01:32:00 -05:00
hit = kOkayButton ;
2019-11-11 00:11:59 -05:00
handledIt = true ;
break ;
2020-01-02 01:32:00 -05:00
default :
2019-11-11 00:11:59 -05:00
handledIt = false ;
2020-01-02 01:32:00 -05:00
break ;
2019-11-11 00:11:59 -05:00
}
2020-01-02 01:32:00 -05:00
}
2020-02-16 20:55:47 -05:00
else if ( evt - > m_vosEvent . m_eventType = = GpVOSEventTypes : : kMouseInput )
2020-01-02 01:32:00 -05:00
{
2020-02-16 20:55:47 -05:00
const GpMouseInputEvent & mouseEvt = evt - > m_vosEvent . m_event . m_mouseInputEvent ;
2020-01-02 01:32:00 -05:00
const Point mousePt = window - > MouseToLocal ( mouseEvt ) ;
if ( mouseEvt . m_eventType = = GpMouseEventTypes : : kDown )
2019-11-11 00:11:59 -05:00
{
2020-01-02 01:32:00 -05:00
if ( PointIsInDiagonalOkayButton ( mousePt ) )
{
HiLiteOkayButton ( surface ) ;
clickedDownInOkay = true ;
handledIt = false ;
}
else
handledIt = false ;
2019-11-11 00:11:59 -05:00
}
2020-01-02 01:32:00 -05:00
else if ( mouseEvt . m_eventType = = GpMouseEventTypes : : kUp )
2019-11-11 00:11:59 -05:00
{
2020-01-02 01:32:00 -05:00
if ( PointIsInDiagonalOkayButton ( mousePt ) & & clickedDownInOkay )
{
UnHiLiteOkayButton ( surface ) ;
hit = kOkayButton ;
handledIt = true ;
}
else
{
clickedDownInOkay = false ;
handledIt = false ;
}
2019-11-11 00:11:59 -05:00
}
2020-01-02 01:32:00 -05:00
else if ( mouseEvt . m_eventType = = GpMouseEventTypes : : kMove )
2019-11-11 00:11:59 -05:00
{
2020-01-02 01:32:00 -05:00
if ( clickedDownInOkay )
{
if ( PointIsInDiagonalOkayButton ( mousePt ) )
HiLiteOkayButton ( surface ) ;
else
UnHiLiteOkayButton ( surface ) ;
}
2019-11-11 00:11:59 -05:00
}
}
2020-01-02 01:32:00 -05:00
if ( ! handledIt )
return - 1 ;
return hit ;
2019-11-11 00:11:59 -05:00
}
2020-06-06 02:25:10 -04:00
//-------------------------------------------------------------- AboutFrameworkFilter
// Dialog filter for the About Framework dialog.
2020-09-12 22:29:57 -04:00
static int16_t AboutFrameworkFilter ( void * context , Dialog * dialog , const TimeTaggedVOSEvent * evt )
2020-06-06 02:25:10 -04:00
{
bool handledIt = false ;
int16_t hit = - 1 ;
if ( ! evt )
return - 1 ;
Window * window = dialog - > GetWindow ( ) ;
DrawSurface * surface = window - > GetDrawSurface ( ) ;
if ( evt - > IsKeyDownEvent ( ) )
{
switch ( PackVOSKeyCode ( evt - > m_vosEvent . m_event . m_keyboardInputEvent ) )
{
case PL_KEY_SPECIAL ( kEnter ) :
case PL_KEY_NUMPAD_SPECIAL ( kEnter ) :
dialog - > GetItems ( ) [ kOkayButton - 1 ] . GetWidget ( ) - > SetHighlightStyle ( kControlButtonPart , true ) ;
PLSysCalls : : Sleep ( 8 ) ;
dialog - > GetItems ( ) [ kOkayButton - 1 ] . GetWidget ( ) - > SetHighlightStyle ( kControlButtonPart , false ) ;
hit = kOkayButton ;
handledIt = true ;
break ;
default :
handledIt = false ;
break ;
}
}
if ( ! handledIt )
return - 1 ;
return hit ;
}