2018-03-10 23:01:28 -08:00
/ *
2018-06-24 11:21:34 -07:00
Copyright ( c ) 2018 , Lars Brubaker , John Lewin
2018-03-10 23:01:28 -08:00
All rights reserved .
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions are met :
1. Redistributions of source code must retain the above copyright notice , this
list of conditions and the following disclaimer .
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
and / or other materials provided with the distribution .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies ,
either expressed or implied , of the FreeBSD Project .
* /
2018-03-13 17:18:21 -07:00
using System ;
using System.Collections.Generic ;
2018-03-10 23:01:28 -08:00
using System.IO ;
2018-03-13 17:18:21 -07:00
using System.Linq ;
2018-03-10 23:01:28 -08:00
using MatterHackers.Agg ;
using MatterHackers.Agg.Platform ;
using MatterHackers.Agg.UI ;
2021-05-21 15:23:25 -07:00
using MatterHackers.ImageProcessing ;
2018-03-10 23:01:28 -08:00
using MatterHackers.Localizations ;
using MatterHackers.MatterControl.CustomWidgets ;
2023-03-18 20:07:56 -07:00
using MatterHackers.MatterControl.SettingsManagement ;
2018-03-10 23:01:28 -08:00
using MatterHackers.VectorMath ;
2018-03-13 17:18:21 -07:00
using Newtonsoft.Json ;
2018-03-10 23:01:28 -08:00
namespace MatterHackers.MatterControl
{
2022-01-06 16:55:55 -08:00
public class AboutPage : DialogPage
2018-03-10 23:01:28 -08:00
{
public AboutPage ( )
: base ( "Close" . Localize ( ) )
{
this . WindowTitle = "About" . Localize ( ) + " " + ApplicationController . Instance . ProductName ;
2018-03-11 12:23:16 -07:00
this . MinimumSize = new Vector2 ( 480 * GuiWidget . DeviceScale , 520 * GuiWidget . DeviceScale ) ;
2018-03-10 23:01:28 -08:00
this . WindowSize = new Vector2 ( 500 * GuiWidget . DeviceScale , 550 * GuiWidget . DeviceScale ) ;
2018-11-03 10:12:27 -07:00
contentRow . BackgroundColor = Color . Transparent ;
2018-03-10 23:01:28 -08:00
2018-03-11 12:23:16 -07:00
headerRow . Visible = false ;
2018-03-10 23:01:28 -08:00
2018-03-11 12:23:16 -07:00
var altHeadingRow = new GuiWidget ( )
{
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Absolute ,
Height = 100 ,
} ;
2018-11-03 10:12:27 -07:00
contentRow . AddChild ( altHeadingRow ) ;
2018-03-11 12:23:16 -07:00
var productInfo = new FlowLayoutWidget ( FlowDirection . TopToBottom )
{
HAnchor = HAnchor . Center | HAnchor . Fit ,
VAnchor = VAnchor . Center | VAnchor . Fit
} ;
var productTitle = new FlowLayoutWidget ( )
{
HAnchor = HAnchor . Center | HAnchor . Fit
} ;
2023-03-18 20:07:56 -07:00
productTitle . AddChild ( new TextWidget ( ApplicationController . Instance . ProductName , textColor : theme . TextColor , pointSize : 20 ) { Margin = new BorderDouble ( right : 3 ) } ) ;
2018-11-03 09:13:07 -07:00
productTitle . AddChild ( new TextWidget ( "TM" . Localize ( ) , textColor : theme . TextColor , pointSize : 7 ) { VAnchor = VAnchor . Top } ) ;
2018-03-11 12:23:16 -07:00
altHeadingRow . AddChild ( productInfo ) ;
productInfo . AddChild ( productTitle ) ;
var spinnerPanel = new GuiWidget ( )
{
HAnchor = HAnchor . Absolute | HAnchor . Left ,
VAnchor = VAnchor . Absolute ,
Height = 100 ,
Width = 100 ,
} ;
altHeadingRow . AddChild ( spinnerPanel ) ;
2018-10-15 18:25:53 -07:00
var accentColor = theme . PrimaryAccentColor ;
2018-03-11 17:49:57 -07:00
2020-08-05 10:07:40 -07:00
var spinner = new LogoSpinner ( spinnerPanel , 4 , 0.2 , 0 , rotateX : 0 ) ;
2018-03-11 12:23:16 -07:00
productInfo . AddChild (
2018-11-03 09:13:07 -07:00
new TextWidget ( "Version" . Localize ( ) + " " + VersionInfo . Instance . BuildVersion , textColor : theme . TextColor , pointSize : theme . DefaultFontSize )
2018-03-10 23:01:28 -08:00
{
HAnchor = HAnchor . Center
} ) ;
2018-03-11 12:23:16 -07:00
productInfo . AddChild (
2018-11-03 09:13:07 -07:00
new TextWidget ( "Developed By" . Localize ( ) + ": " + "MatterHackers" , textColor : theme . TextColor , pointSize : theme . DefaultFontSize )
2018-03-10 23:01:28 -08:00
{
HAnchor = HAnchor . Center
} ) ;
2018-11-03 10:12:27 -07:00
contentRow . AddChild (
2018-03-13 17:18:21 -07:00
new WrappedTextWidget (
2023-03-18 20:07:56 -07:00
"{0} is made possible by the team at MatterHackers and other open source software" . Localize ( ) . FormatWith ( ApplicationController . Instance . ProductName ) + ":" ,
2018-03-13 17:18:21 -07:00
pointSize : theme . DefaultFontSize ,
2018-11-03 09:13:07 -07:00
textColor : theme . TextColor )
2018-03-13 17:18:21 -07:00
{
Margin = new BorderDouble ( 0 , 15 )
} ) ;
var licensePanel = new FlowLayoutWidget ( FlowDirection . TopToBottom )
2018-03-11 12:23:16 -07:00
{
2018-03-13 17:18:21 -07:00
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Fit ,
Margin = new BorderDouble ( bottom : 15 )
2018-03-11 12:23:16 -07:00
} ;
2020-11-25 07:39:36 -08:00
var data = JsonConvert . DeserializeObject < List < LibraryLicense > > ( StaticData . Instance . ReadAllText ( Path . Combine ( "License" , "license.json" ) ) ) ;
2018-03-11 12:23:16 -07:00
2021-05-21 15:23:25 -07:00
var linkIcon = StaticData . Instance . LoadIcon ( "fa-link_16.png" , 16 , 16 ) . SetToColor ( theme . TextColor ) ;
2018-03-11 12:23:16 -07:00
2018-10-13 17:58:54 -07:00
SectionWidget section = null ;
2018-03-13 17:18:21 -07:00
foreach ( var item in data . OrderBy ( i = > i . Name ) )
2018-03-11 12:23:16 -07:00
{
2022-07-16 07:46:44 -07:00
var linkButton = new ThemedIconButton ( linkIcon , theme ) ;
2018-03-13 17:18:21 -07:00
linkButton . Click + = ( s , e ) = > UiThread . RunOnIdle ( ( ) = >
{
2020-09-22 17:52:57 -07:00
ApplicationController . LaunchBrowser ( item . Url ) ;
2018-03-13 17:18:21 -07:00
} ) ;
2018-03-11 12:23:16 -07:00
2018-10-13 17:58:54 -07:00
section = new SectionWidget ( item . Title ? ? item . Name , new LazyLicenseText ( item . Name , theme ) , theme , linkButton , expanded : false )
2018-03-13 17:18:21 -07:00
{
HAnchor = HAnchor . Stretch
} ;
licensePanel . AddChild ( section ) ;
}
2018-03-10 23:01:28 -08:00
2018-10-13 17:58:54 -07:00
// Apply a bottom border to the last time for balance
if ( section ! = null )
{
section . Border = section . Border . Clone ( bottom : 1 ) ;
}
2018-03-13 17:18:21 -07:00
var scrollable = new ScrollableWidget ( autoScroll : true )
{
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Stretch ,
Margin = new BorderDouble ( bottom : 10 ) ,
} ;
2018-10-13 17:58:54 -07:00
2018-03-13 17:18:21 -07:00
scrollable . ScrollArea . HAnchor = HAnchor . Stretch ;
scrollable . AddChild ( licensePanel ) ;
2018-11-03 10:12:27 -07:00
contentRow . AddChild ( scrollable ) ;
2018-03-10 23:01:28 -08:00
2018-11-03 10:12:27 -07:00
contentRow . AddChild (
2019-05-30 09:51:17 -07:00
new TextWidget ( "Copyright © 2019 MatterHackers, Inc." , textColor : theme . TextColor , pointSize : theme . DefaultFontSize )
2018-07-11 12:26:45 -07:00
{
HAnchor = HAnchor . Center ,
} ) ;
2018-07-11 09:26:54 -07:00
var siteLink = new LinkLabel ( "www.matterhackers.com" , theme )
{
HAnchor = HAnchor . Center ,
2018-11-03 09:13:07 -07:00
TextColor = theme . TextColor
2018-07-11 09:26:54 -07:00
} ;
2018-03-10 23:01:28 -08:00
siteLink . Click + = ( s , e ) = > UiThread . RunOnIdle ( ( ) = >
{
2020-09-22 17:52:57 -07:00
ApplicationController . LaunchBrowser ( "http://www.matterhackers.com" ) ;
2018-03-10 23:01:28 -08:00
} ) ;
2018-11-03 10:12:27 -07:00
contentRow . AddChild ( siteLink ) ;
2018-03-10 23:01:28 -08:00
}
2018-03-13 17:18:21 -07:00
private class LazyLicenseText : GuiWidget
{
private string sourceName ;
private ThemeConfig theme ;
public LazyLicenseText ( string sourceName , ThemeConfig theme )
{
this . sourceName = sourceName ;
this . theme = theme ;
this . HAnchor = HAnchor . Stretch ;
this . VAnchor = VAnchor . Fit ;
this . MinimumSize = new Vector2 ( 0 , 10 ) ;
}
public override void OnLoad ( EventArgs args )
{
string filePath = Path . Combine ( "License" , $"{sourceName}.txt" ) ;
2020-11-25 07:39:36 -08:00
if ( StaticData . Instance . FileExists ( filePath ) )
2018-03-13 17:18:21 -07:00
{
2020-11-25 07:39:36 -08:00
string content = StaticData . Instance . ReadAllText ( filePath ) ;
2018-03-13 17:18:21 -07:00
2020-08-14 07:37:40 -07:00
this . AddChild ( new WrappedTextWidget ( content , theme . DefaultFontSize , textColor : theme . TextColor ) ) ;
2018-03-13 17:18:21 -07:00
}
base . OnLoad ( args ) ;
}
}
private class LibraryLicense
{
public string Url { get ; set ; }
public string Name { get ; set ; }
public string Title { get ; set ; }
}
2018-03-10 23:01:28 -08:00
}
}