Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UWelcomePageFrame;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ExtCtrls, jpeg, Buttons, ExtDlgs, Math, HMGdiPanel,
- Vcl.OleCtrls, SHDocVw
- , frmVideosUnit
- ;
- type
- THMTileColorSet = Array[0..5] of TColor;
- const
- BLUE_COLORSET: THMTileColorSet = ($966438, $3A9638, $933896, $3A9638, $967B38, $96383A);
- BLACK_COLORSET: THMTileColorSet = ($4B9417, $932117, $5F1793, $178993, $17935F, $4A9317);
- SILVER_COLORSET: THMTileColorSet = ($386496, $38963A, $963893, $966938, $387B96, $3A3896);
- {$DEFINE MEDIA_AS_FILES}
- type
- TRecentFilesOpenDocument = procedure(Sender: TObject; const AFileName: String) of object;
- THMExecFrameCommandEvent = function(ACommand: String): Boolean of object;
- THMNewsItem = record
- Title: String;
- Description: String;
- Link: String;
- PubDate: String;
- end;
- THMNewsItemArray = Array of THMNewsItem;
- TWelcomePageFrame = class(TForm)
- objStartTimer: TTimer;
- imgBackground: TImage;
- imgDefault: TImage;
- GDIPaintPanel: THMGDIPaintPanel;
- CheckBox1: TCheckBox;
- procedure FormDestroy(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure objStartTimerTimer(Sender: TObject);
- procedure GDIPaintPanelMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- procedure GDIPaintPanelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- procedure GDIPaintPanelMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- procedure GDIPaintPanelMouseLeave(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormResize(Sender: TObject);
- procedure GDIPaintPanelBackgroundDraw(Sender: TObject; ADC: HDC; const AWidth, AHeight: Integer);
- procedure btnStartClick(Sender: TObject);
- procedure btnNewsClick(Sender: TObject);
- procedure BtnWallpaperClick(Sender: TObject);
- strict private
- procedure BackFromVideos(sender: TObject);
- procedure DoVideosClick(Sender: TObject);
- private
- FOnFrameCommand: THMExecFrameCommandEvent;
- FNews: THMNewsItemArray;
- FSelectedItem: THMTileItem;
- FPressedItem: THMTileItem;
- FIsRecentPage: Boolean;
- FWelcomeItem: THMTileItem;
- FFacebookItem: THMTileItem;
- FForumItem: THMTileItem;
- FBackItem: THMTileItem;
- FBackgroundColor: TColor;
- FUpdatesItem: THMTileItem;
- FRecentFileNames: TStringList;
- FOnOpenRecentFile: TRecentFilesOpenDocument;
- FNewProjectItem: THMTileItem;
- FOpenProjectItem: THMTileItem;
- FExamplesItem: THMTileItem;
- FTutorialsItem: THMTileItem;
- FNewsUpdateItem: THMTileItem;
- FNewsFeedItem: THMTileItem;
- FColorSet: THMTileColorSet;
- FBkImage: TBitmap;
- fVideosFrame: TFrmVideos;
- FWallpaper: String;
- procedure SetBackgroundColor(const Value: TColor);
- procedure DoBack2Click(Sender: TObject);
- procedure DoNewsClick(Sender: TObject);
- procedure DoOpenRecentClick(Sender: TObject);
- procedure DoWelcomeClick(Sender: TObject);
- procedure DoNewProjectClick(Sender: TObject);
- procedure DoOpenSamplesClick(Sender: TObject);
- procedure DoForumClick(Sender: TObject);
- procedure DoFacebookClick(Sender: TObject);
- procedure DoSupportClick(Sender: TObject);
- procedure DoUpdateClick(Sender: TObject);
- procedure DoOpenNewsClick(Sender: TObject);
- procedure DoOpenNewsItemClick(Sender: TObject);
- procedure SetColorSet(const Value: THMTileColorSet);
- procedure SetSelectedItem(const Value: THMTileItem);
- procedure SetWallpaper(const Value: String);
- procedure InternalCreateWhatsNewItem(const aScale, aIndex: Integer;
- caption, desc: string);
- protected
- function _x(const AXIndex: Integer): Integer;
- function _w(const AWCount: Integer): Integer;
- function _y(const AYIndex: Integer): Integer;
- function _h(const AHCount: Integer): Integer;
- function _x2(const AXIndex: Integer): Integer;
- function _w2(const AWCount: Integer): Integer;
- function _y2(const AYIndex: Integer): Integer;
- function _h2(const AHCount: Integer): Integer;
- {$IFDEF MEDIA_AS_FILES}
- function _media(const AFileName: String): String;
- {$ELSE}
- function _media(const AFileName: String): TStream;
- {$ENDIF}
- function _recentFiles: String;
- procedure EvalImageSize;
- function ExecFrameCommand(const ACommand: String): boolean;
- function CreateSingleRecentItem(const AFileName: String): THMTileItem;
- function CreateSingleRecentItem2(const AFileName: String; const AIndex, AScale, AHeightMultiplier: Integer): THMTileItem;
- function CreateBackTile: THMTileItem;
- procedure CreateMainItems(const AScale: Integer);
- procedure CreateMainRecentItems(const AScale: Integer);
- procedure CreateRecentItems;
- procedure CreateNewsItems(const AScale: Integer);
- procedure ShowMainItems;
- procedure DoOpenRecentFile(const AFileName: String);
- procedure AnimateMainIcons;
- procedure AnimateNewsIcons;
- property SelectedItem: THMTileItem read FSelectedItem write SetSelectedItem;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- function DoCommandClick(ACommand: String): boolean;
- procedure DisplayUpdatePage;
- procedure DisplayMainPage;
- procedure ClearIcons;
- procedure RefreshDisplay;
- property ColorSet: THMTileColorSet read FColorSet write SetColorSet;
- property OnFrameCommand: THMExecFrameCommandEvent read FOnFrameCommand write FOnFrameCommand;
- property OnOpenRecentFile: TRecentFilesOpenDocument read FOnOpenRecentFile write FOnOpenRecentFile;
- property BackgroundColor: TColor read FBackgroundColor write SetBackgroundColor;
- property Wallpaper: String read FWallpaper write SetWallpaper;
- end;
- function HMEllipsifyText(AsPath: Boolean; const Text: String; const Canvas: TCanvas; MaxWidth: Integer): String;
- var
- WelcomePageFrame: TWelcomePageFrame;
- implementation
- uses
- ShellAPI;
- {$R *.dfm}
- var
- AppFileDate: TDateTimeInfoRec;
- const
- TILE_HEIGHT = 120;
- TILE_WIDTH = 120;
- TILE_HGAP = 8;
- TILE_VGAP = 8;
- V_OFFSET = 8; // 40;
- H_OFFSET = 40;
- TILE_HEIGHT2 = 56;
- // TILE_WIDTH2 = 78;
- TILE_WIDTH2 = 88;
- TILE_HGAP2 = 8;
- TILE_VGAP2 = 8;
- V_OFFSET2 = 8; // 40;
- H_OFFSET2 = 40;
- RECENT_TILESPAN = 4;
- RECENT_TILESPERROW = 2;
- EXAMPLE_TILESPAN = 3;
- EXAMPLE_TILESPERROW = 2;
- INFLATE_X = 4;
- INFLATE_Y = 4;
- ExamplesFilesDir = 'Examples\';
- var
- gStrNewsPage: AnsiString;
- resourcestring
- SUHMUpdateVersionUptodate = 'Your copy of the program is up-to-date!'#13#10'Thank you for checking!';
- SUHMHtmlWelcomePage4NoConnect = 'Cannot retrieve news feed from the website.';
- SUHMTileGetStartedHeading = 'Get Started!';
- SUHMTileGetStartedText = 'A brief introduction to FCS Express';
- SUHMTileNewsHeading = 'Updates';
- SUHMTileNewsText = 'Check for updates and news';
- SUHMTileRecentHeading = 'Recent Projects';
- SUHMTileNewProjectHeading = 'New Layout';
- SUHMTileNewProjectText = 'Create a new layout';
- SUHMTileOpenLayoutHeading = 'Open Layout';
- SUHMTileOpenLayoutText = 'Open an existing layout';
- SUHMTileForumHeading = 'Forum';
- SUHMTileFacebookHeading = '';
- SUHMTileLinkedInHeading = 'LinkedIn';
- SUHMTileFeedbackHeading = 'Feedback';
- SUHMTileExamplesHeading = 'Examples';
- SUHMTileExamplesText = 'Example layouts (for Research Use Only)';
- SUHMTileHelpfileHeading = 'Help';
- SUHMTileTutorialsHeading = 'Tutorials';
- SUHMTileTutorialsText = 'Check out the tutorials on our website';
- SUHMTileVideosHeading = 'Videos';
- SUHMTileVideosText = '';
- SUHMTileUpdateHeading = 'Update';
- SUHMTileNewsfeedHeading = 'Help+Manual News';
- SUHMTileBackToWelcomeHeading = 'Back';
- SUHMTileBackToWelcomeText = '';
- SUHMUpdateNotAvailable = 'Update information could not be retrieved. Please check your internet connection!';
- function HMEllipsifyText(AsPath: Boolean; const Text: String; const Canvas: TCanvas; MaxWidth: Integer): String;
- var
- TempPChar: PChar;
- TempRect: TRect;
- Params: UINT;
- begin
- GetMem(TempPChar, (Length(Text) + 1) * SizeOf(TempPChar));
- try
- TempPChar := StrPCopy(TempPChar, Text);
- TempRect := Rect(0, 0, MaxWidth, High(Integer));
- if AsPath then Params := DT_PATH_ELLIPSIS
- else Params := DT_END_ELLIPSIS;
- Params := Params + DT_MODIFYSTRING + DT_CALCRECT;
- DrawTextEx(Canvas.Handle, TempPChar, -1, TempRect, Params, nil);
- Result := StrPas(TempPChar);
- finally
- FreeMem(TempPChar);
- end;
- end;
- function _min(const AValue1, AValue2: Extended): Extended;
- begin
- if AValue1 < AValue2 then Result := AValue1 else Result := AValue2;
- end;
- function _dpi(const AValue: Integer): Integer;
- begin
- Result := MulDiv(AValue, Screen.PixelsPerInch, 96);
- end;
- function _makeHeader(ATile: THMTileItem; const DoPrepare: Boolean; const aHeaderMarginLeft: Integer;
- const aHeaderMarginTop: Integer; const aForcePrepare: boolean;
- const aSetLeftMargins: boolean; const aSetBottomMargins: boolean):
- THMTileItem;
- begin
- ATile.HeaderVerticalAlign := taVerticalCenter;
- ATile.HeaderMargins.Left := _dpi(aHeaderMarginLeft);
- ATile.HeaderMargins.Top := _dpi(aHeaderMarginTop);
- if aSetLeftMargins then
- ATile.TextMargins.Left := _dpi(90);
- if aSetBottomMargins and (ATile.Description <> '') then
- ATile.HeaderMargins.Bottom := _dpi(40);
- if DoPrepare then
- ATile.PrepareItem(aForcePrepare);
- Result := ATile;
- end;
- function _makeFullHeader(ATile: THMTileItem; const DoPrepare: Boolean = True):
- THMTileItem;
- begin
- result := _makeHeader(ATile, DoPrepare, 90, 6, False, True, True);
- end;
- function _makeHalfHeader(ATile: THMTileItem; const DoPrepare: Boolean = True;
- aHeaderOnBottom: Boolean = False): THMTileItem;
- var
- headerTop: Integer;
- begin
- if aHeaderOnBottom then
- headerTop := 75
- else
- headerTop := 2;
- result := _makeHeader(ATile, DoPrepare, 7, headerTop, True, False, False);
- end;
- { TWelcomePageFrame }
- procedure TWelcomePageFrame.AnimateMainIcons;
- begin
- GDIPaintPanel.ClearItems;
- CreateMainItems(100);
- objStartTimer.Enabled := True;
- end;
- procedure TWelcomePageFrame.AnimateNewsIcons;
- begin
- GDIPaintPanel.ClearItems;
- CreateNewsItems(0);
- objStartTimer.Enabled := True;
- end;
- function TWelcomePageFrame.DoCommandClick(ACommand: String): boolean;
- begin
- if ACommand = '!Update' then
- ShellExecute(Application.MainForm.Handle, 'open', 'http://www.helpandmanual.com/downloads.html', nil, nil, SW_SHOWNORMAL)
- else if ACommand = '!Facebook' then
- ShellExecute(Application.MainForm.Handle, 'open', 'https://www.facebook.com/pages/FCS-Express-by-De-Novo-Software/174628995902591', nil, nil, SW_SHOWNORMAL)
- else
- showmessage('Command clicked: ' + ACommand);
- result := true;
- end;
- procedure TWelcomePageFrame.btnNewsClick(Sender: TObject);
- begin
- AnimateNewsIcons;
- end;
- procedure TWelcomePageFrame.btnStartClick(Sender: TObject);
- begin
- AnimateMainIcons;
- end;
- procedure TWelcomePageFrame.BtnWallpaperClick(Sender: TObject);
- begin
- with TOpenDialog.create(nil) do
- try
- if Execute then SetWallpaper(filename);
- finally
- free;
- end;
- end;
- procedure TWelcomePageFrame.ClearIcons;
- begin
- FRecentFileNames.Clear;
- GDIPaintPanel.ClearItems;
- GDIPaintPanel.Redraw;
- end;
- constructor TWelcomePageFrame.Create(AOwner: TComponent);
- begin
- inherited;
- FBkImage := nil;
- FRecentFileNames := TStringList.Create;
- FSelectedItem := nil;
- FPressedItem := nil;
- FIsRecentPage := False;
- FOnFrameCommand := nil;
- FOnOpenRecentFile := nil;
- imgBackground.Picture.assign(imgDefault.Picture);
- FOnFrameCommand := DoCommandClick;
- CreateMainItems(0);
- end;
- function TWelcomePageFrame.CreateBackTile: THMTileItem;
- begin
- Result := THMTileItem.CreateEx(GDIPaintPanel, _x(2), _y(2), clYellow, clBlack, 'Show the home screen', '', '');
- Result.BorderWidth := 0;
- Result.PrepareItem;
- end;
- procedure TWelcomePageFrame.CreateMainItems(const AScale: Integer);
- const LONG_LINE = 'I am the very model of a modern major text error. ';
- begin
- Canvas.Font.Size := 10;
- FBackItem := nil;
- // first line
- FWelcomeItem := _makeFullHeader(THMTileItem.CreateEx(GDIPaintPanel, _x(2), _y(0), _w(2), _h(1), AScale, AScale, FColorSet[0], clBlack, SUHMTileGetStartedHeading, SUHMTileGetStartedText, _media('welcome.png'), clWhite, taLeftJustify, 1, DoWelcomeClick));
- FNewProjectItem := _makeFullHeader(THMTileItem.CreateEx(GDIPaintPanel, _x(0), _y(0), _w(2), _h(1), AScale, AScale, FColorSet[1], clBlack, SUHMTileNewProjectHeading, SUHMTileNewProjectText, _media('newproject.png'), clBlack, taLeftJustify, 1, DoNewProjectClick));
- FTutorialsItem := _makeHalfHeader(THMTileItem.CreateEx(GDIPaintPanel, _x(4), _y(0), _w(2), _h(1), AScale, AScale, FColorSet[5], clRed, SUHMTileVideosHeading, SUHMTileVideosText, nil{ _media('support.png')}, clWhite, taLeftJustify, 1, DoVideosClick), True, False);
- CreateMainRecentItems(AScale);
- // second line
- // FExamplesItem := _makeHalfHeader(THMTileItem.CreateEx(GDIPaintPanel, _x(0), _y(1), _w(2), _h(2), AScale, AScale, FColorSet[2], clBlack, 'What''s New', '', nil, clRed, taLeftJustify, 1, DoOpenSamplesClick));
- // FExamplesItem.HeaderVerticalAlign := taAlignTop;
- FOpenProjectItem := _makeFullHeader(THMTileItem.CreateEx(GDIPaintPanel, _x(6), _y(0), _w(2), _h(1), AScale, AScale, FColorSet[1], clBlack, SUHMTileOpenLayoutHeading, SUHMTileOpenLayoutText, _media('newproject.png'), clBlack, taLeftJustify, 1, DoNewProjectClick));
- FTutorialsItem := _makeHalfHeader(THMTileItem.CreateEx(GDIPaintPanel, _x(2), _y(1), _w(2), _h(1), AScale, AScale, FColorSet[0], clBlack, SUHMTileHelpfileHeading, '', nil{ _media('support.png')}, clWhite, taLeftJustify, 1, DoSupportClick), True, False);
- FTutorialsItem := _makeHalfHeader(THMTileItem.CreateEx(GDIPaintPanel, _x(4), _y(1), _w(2), _h(1), AScale, AScale, FColorSet[5], clBlack, SUHMTileTutorialsHeading, SUHMTileTutorialsText, nil{ _media('support.png')}, clWhite, taLeftJustify, 1, DoSupportClick), True, False);
- FForumItem := _makeHalfHeader(THMTileItem.CreateEx(GDIPaintPanel, _x(2), _y(2), _w(1), _h(1), AScale, AScale, FColorSet[3], clBlack, SUHMTileFeedbackHeading, '', nil, clWhite, taRightJustify, 1), True, True);
- FForumItem := _makeHalfHeader(THMTileItem.CreateEx(GDIPaintPanel, _x(3), _y(2), _w(1), _h(1), AScale, AScale, FColorSet[5], clBlack, SUHMTileForumHeading, '', _media('forum.png'), clWhite, taRightJustify, 1, DoForumClick), True, True);
- FFacebookItem := THMTileItem.CreateEx(GDIPaintPanel, _x(4), _y(2), _w(1), _h(1), AScale, AScale, FColorSet[4], clBlack, SUHMTileFacebookHeading, '', _media('facebook.png'), clWhite, taLeftJustify, 1, DoFacebookClick);
- FFacebookItem := THMTileItem.CreateEx(GDIPaintPanel, _x(5), _y(2), _w(1), _h(1), AScale, AScale, FColorSet[2], clBlack, SUHMTileLinkedInHeading, '', nil, clWhite, taRightJustify, 1);
- InternalCreateWhatsNewItem(AScale, 1, 'Test', LONG_LINE + LONG_LINE + LONG_LINE + LONG_LINE + LONG_LINE + LONG_LINE);
- end;
- procedure TWelcomePageFrame.CreateMainRecentItems(const AScale: Integer);
- var
- tmpFiles: TStringList;
- intIndex, intTotal, intHeightMultiplier: Integer;
- begin
- SelectedItem := nil;
- FPressedItem := nil;
- FIsRecentPage := True;
- intHeightMultiplier := 1;
- tmpFiles := TStringList.Create;
- try
- FRecentFileNames.Clear;
- for intIndex := 1 to 4 do
- tmpFiles.add(ExtractFilepath(application.ExeName)+ Format('MyFiles\File%d.txt', [intIndex]));
- Canvas.Font.Size := 8;
- intTotal := Min(4, tmpFiles.Count);
- for intIndex := 0 to intTotal-1 do
- CreateSingleRecentItem2(tmpFiles[intIndex], intIndex, AScale, intHeightMultiplier);
- finally
- FreeAndNil(tmpFiles);
- end;
- end;
- procedure TWelcomePageFrame.CreateNewsItems(const AScale: Integer);
- function GetNews: THMNewsItemArray;
- var
- intIdx: integer;
- begin
- for intIdx := 0 to 5 do
- begin
- SetLength(Result, intIdx+1);
- Result[intIdx].Title := Format('Title of news item %d', [intIdx+1]);
- Result[intIdx].Description := Format('Description of news item %d', [intIdx+1]);
- Result[intIdx].Link := 'http://www.helpandmanual.com/';
- Result[intIdx].PubDate := DateTimeToStr(now);
- end;
- end;
- var
- intIndex: Integer;
- tmpItem: THMTileItem;
- tmpText: String;
- begin
- Screen.Cursor := crHourglass;
- try
- // first line
- FNewsUpdateItem := THMTileItem.CreateEx(GDIPaintPanel, _x2(0), _y2(0), _w2(3), _h2(5), AScale, AScale, FColorSet[0], clBlack, SUHMTileUpdateHeading, SUHMUpdateVersionUptodate, _media('update.png'), clWhite, taLeftJustify, 3, DoUpdateClick);
- FNewsUpdateItem.TextMargins.Left := 0;
- FNewsUpdateItem.HeaderTextAlign := taCenter;
- FNewsUpdateItem.PrepareItem;
- try
- if Length(FNews) = 0 then
- FNews := GetNews;
- Canvas.Font.Size := 8;
- for intIndex := Low(FNews) to High(FNews) do
- begin
- if pos('+', FNews[intIndex].PubDate) > 0 then tmpText := copy(FNews[intIndex].PubDate, 1, pos('+', FNews[intIndex].PubDate)-11)
- else tmpText := FNews[intIndex].PubDate;
- tmpText := '[' + tmpText + '] ' + FNews[intIndex].Description;
- // tmpText := '[' + FormatDateTime(FormatSettings.ShortDateFormat, FNews[intIndex].PubDate) + '] ' + FNews[intIndex].Description;
- //ItemDate := copy(ItemDate, 1, pos('+', ItemDate)-10);
- tmpText := HMEllipsifyText(False, tmpText, Canvas, _w2(5)-2*_dpi(36));
- tmpItem := THMTileItem.CreateEx(GDIPaintPanel, _x2(3), _y2(intIndex), _w2(5), _h2(1), AScale, AScale, FColorSet[2], clBlack, FNews[intIndex].Title, tmpText, _media('newsitem.png'), clBlack, taLeftJustify, 3, DoOpenNewsItemClick);
- tmpItem.TitleFontSize := 13;
- tmpItem.HeaderMargins.Left := _dpi(36);
- tmpItem.TextMargins.Left := _dpi(36);
- tmpItem.DescriptionFontSize := 8;
- tmpItem.TextGap := 7;
- tmpItem.Tag := intIndex;
- tmpItem.PrepareItem;
- end;
- except
- FNewsFeedItem := THMTileItem.CreateEx(GDIPaintPanel, _x2(3), _y2(0), _w2(5), _h2(6), AScale, AScale, clYellow, clBlack, SUHMTileNewsfeedHeading, SUHMHtmlWelcomePage4NoConnect, _media('news.png'), clBlack, taLeftJustify, 3, DoOpenNewsClick);
- FNewsFeedItem.PrepareItem;
- end;
- FBackItem := THMTileItem.CreateEx(GDIPaintPanel, _x2(0), _y2(5), _w2(3), _h2(1), AScale, AScale, clGray, clBlack, SUHMTileBackToWelcomeHeading, SUHMTileBackToWelcomeText, _media('back.png'), clWhite, taRightJustify, 3, DoBack2Click);
- finally
- Screen.Cursor := crDefault;
- end;
- //
- // // second line
- // FNewProjectItem := THMTileItem.CreateEx(GDIPaintPanel, _x(0), _y(1), _w(2), _h(1), AScale, AScale, clYellow, clBlack, 'New project', 'Get help for Help & Manual', _media('buitl2.png'), clBlack, taLeftJustify);
- // FHelpItem := THMTileItem.CreateEx(GDIPaintPanel, _x(2), _y(1), _w(1), _h(1), AScale, AScale, clYellow, clBlack, 'Help', 'Get help for Help & Manual', _media('buitl2.png'), clBlack, taLeftJustify);
- // FForumItem := THMTileItem.CreateEx(GDIPaintPanel, _x(3), _y(1), _w(1), _h(1), AScale, AScale, clYellow, clBlack, 'Forum', 'Get help for Help & Manual', _media('buitl2.png'), clBlack, taLeftJustify);
- //
- // FExamplesItem := THMTileItem.CreateEx(GDIPaintPanel, _x(0), _y(2), _w(2), _h(1), AScale, AScale, clYellow, clBlack, 'Examples', 'Get help for Help & Manual', _media('buitl2.png'), clBlack, taLeftJustify);
- // FTutorialsItem := THMTileItem.CreateEx(GDIPaintPanel, _x(2), _y(2), _w(1), _h(1), AScale, AScale, clYellow, clBlack, 'Support', 'Get help for Help & Manual', _media('buitl2.png'), clBlack, taLeftJustify);
- // FFacebookItem := THMTileItem.CreateEx(GDIPaintPanel, _x(3), _y(2), _w(1), _h(1), AScale, AScale, clYellow, clBlack, 'Facebook', 'Irgendso a Schaß mit facebook', _media('buitl3.png'), clBlack, taLeftJustify);
- end;
- procedure TWelcomePageFrame.CreateRecentItems;
- var
- tmpFiles: TStringList;
- intIndex: Integer;
- begin
- SelectedItem := nil;
- FPressedItem := nil;
- FIsRecentPage := True;
- tmpFiles := TStringList.Create;
- try
- FRecentFileNames.Clear;
- // UserSettings.GetMRUDocuments(tmpFiles);
- Canvas.Font.Size := 8;
- for intIndex := 0 to tmpFiles.Count-1 do
- if intIndex < 5*RECENT_TILESPERROW then
- CreateSingleRecentItem(tmpFiles[intIndex]);
- finally
- FreeAndNil(tmpFiles);
- end;
- FBackItem := THMTileItem.CreateEx(GDIPaintPanel, _x2(0), _y2(5), _w2(RECENT_TILESPAN), _h2(1), 100, 100, clBtnFace, clBlack, SUHMTileBackToWelcomeHeading, SUHMTileBackToWelcomeText, _media('back2.png'), clWhite, taRightJustify, 2);
- FBackItem.OnClick := DoBack2Click;
- end;
- function TWelcomePageFrame.CreateSingleRecentItem(const AFileName: String): THMTileItem;
- var
- intIdx: Integer;
- tmpX: Integer;
- tmpY: Integer;
- tmpW: Integer;
- begin
- intIdx := GDIPaintPanel.GetItemCountByGroupIndex([2]);
- tmpX := _x2((intIdx MOD RECENT_TILESPERROW) * RECENT_TILESPAN);
- tmpY := _y2(intIdx DIV RECENT_TILESPERROW);
- tmpW := _w2(RECENT_TILESPAN);
- Result := THMTileItem.CreateEx(GDIPaintPanel, tmpX, tmpY, tmpW, _h2(1), 100, 100, clSilver, clBlack, ExtractFileName(AFileName), HMEllipsifyText(True, AFileName, Canvas, tmpW-20), _media('recentitem.png'), clBlack, taLeftJustify, 2);
- Result.TextGap := 7;
- Result.DescriptionFontSize := Canvas.Font.Size;
- Result.TitleFontSize := 14;
- Result.PrepareItem;
- FRecentFileNames.AddObject(AFileName, Result);
- Result.OnClick := DoOpenRecentClick;
- end;
- function TWelcomePageFrame.CreateSingleRecentItem2(const AFileName: String; const AIndex, AScale, AHeightMultiplier: Integer): THMTileItem;
- var
- tmpX: Integer;
- tmpY: Integer;
- tmpW: Integer;
- tmpFileName: String;
- tmpFilePath: String;
- tmpIsFavorite: Boolean;
- tmpImageName: String;
- begin
- tmpX := _x(6); //
- tmpY := _y2((AIndex * AHeightMultiplier) + 2);
- tmpW := _w(2);
- Canvas.Font.Size := 14;
- tmpFileName := HMEllipsifyText(False, ExtractFileName(AFileName), Canvas, tmpW - _dpi(20));
- Canvas.Font.Size := 10;
- tmpFilePath := HMEllipsifyText(True, ExtractFilePath(AFileName), Canvas, tmpW - _dpi(20));
- tmpIsFavorite := AIndex < 2;
- if tmpIsFavorite AND (AHeightMultiplier = 1) then
- tmpImageName := 'recentitem_fav.png'
- else
- tmpImageName := 'recentitem.png';
- Result := THMTileItem.CreateEx(GDIPaintPanel, tmpX, tmpY, tmpW, _h2(AHeightMultiplier), AScale, AScale, FColorSet[3], clBlack, tmpFileName, tmpFilePath, _media(tmpImageName), clBlack, taLeftJustify, 1);
- //Result := THMTileItem.CreateEx(GDIPaintPanel, tmpX, tmpY, tmpW, _h2(1), AScale, AScale, FColorSet[3], clBlack, ExtractFileName(AFileName), HMEllipsifyText(True, ExtractFilePath(AFileName), Canvas, tmpW-20), '' {_media('recentitem2.png')}, clWhite, taLeftJustify, 1);
- Result.TextGap := 7;
- Result.DescriptionFontSize := Canvas.Font.Size;
- Result.TitleFontSize := 14;
- Result.PrepareItem;
- FRecentFileNames.AddObject(AFileName, Result);
- Result.OnClick := DoOpenRecentClick;
- end;
- destructor TWelcomePageFrame.Destroy;
- begin
- FreeAndNil(FRecentFileNames);
- GDIPaintPanel.ClearItems;
- FreeAndNil(FBkImage);
- inherited;
- end;
- procedure TWelcomePageFrame.BackFromVideos(sender: TObject);
- begin
- FreeAndNil(fVideosFrame);
- CreateMainItems(100);
- GDIPaintPanel.Redraw;
- end;
- procedure TWelcomePageFrame.FormDestroy(Sender: TObject);
- begin
- if assigned(fVideosFrame) then
- FreeAndNil(fVideosFrame);
- end;
- procedure TWelcomePageFrame.DisplayMainPage;
- begin
- AnimateMainIcons;
- end;
- procedure TWelcomePageFrame.DisplayUpdatePage;
- begin
- AnimateNewsIcons;
- end;
- procedure TWelcomePageFrame.DoBack2Click(Sender: TObject);
- begin
- CreateMainItems(100);
- GDIPaintPanel.MoveItemsInOut([1], [2, 3, 4], DIRECTION_RIGHT, 25);
- GDIPaintPanel.ClearItemsByGroupIndex([2, 3, 4]);
- // FRecentFileNames.Clear;
- GDIPaintPanel.Redraw;
- end;
- procedure TWelcomePageFrame.DoFacebookClick(Sender: TObject);
- begin
- ExecFrameCommand('!Facebook');
- end;
- procedure TWelcomePageFrame.DoForumClick(Sender: TObject);
- begin
- ShellExecute(Application.MainForm.Handle, 'open', 'http://www.denovosoftware.com/v4forums/', nil, nil, SW_SHOWNORMAL)
- end;
- procedure TWelcomePageFrame.DoNewProjectClick(Sender: TObject);
- begin
- ExecFrameCommand('!NewProject');
- end;
- procedure TWelcomePageFrame.DoNewsClick(Sender: TObject);
- begin
- FRecentFileNames.Clear;
- CreateNewsItems(100);
- GDIPaintPanel.MoveItemsInOut([3], [1], DIRECTION_LEFT, 25);
- GDIPaintPanel.ClearItemsByGroupIndex([1]);
- GDIPaintPanel.Redraw;
- end;
- procedure TWelcomePageFrame.DoOpenNewsClick(Sender: TObject);
- begin
- ExecFrameCommand('!OpenSamples');
- end;
- procedure TWelcomePageFrame.DoOpenNewsItemClick(Sender: TObject);
- var
- tmpIdx: Integer;
- begin
- if Assigned(Sender) AND (Sender is THMTileItem) then
- begin
- tmpIdx := THMTileItem(Sender).Tag;
- if (tmpIdx >= Low(FNews)) AND (tmpIdx <= High(FNews)) then
- ShellExecute(Application.MainForm.Handle, 'open', PChar(FNews[tmpIdx].Link), nil, nil, SW_SHOWNORMAL);
- end;
- end;
- procedure TWelcomePageFrame.DoOpenRecentClick(Sender: TObject);
- var
- intIndex: Integer;
- begin
- for intIndex := 0 to FRecentFileNames.Count-1 do
- if FRecentFileNames.Objects[intIndex] = Sender then
- DoOpenRecentFile(FRecentFileNames[intIndex]);
- end;
- procedure TWelcomePageFrame.DoOpenRecentFile(const AFileName: String);
- begin
- if Assigned(FOnOpenRecentFile) and (AFileName <> '') then
- FOnOpenRecentFile(Self, AFileName);
- end;
- procedure TWelcomePageFrame.DoOpenSamplesClick(Sender: TObject);
- begin
- end;
- procedure TWelcomePageFrame.DoSupportClick(Sender: TObject);
- begin
- ShellExecute(Application.MainForm.Handle, 'open', 'http://www.denovosoftware.com/site/manual/index.html?tutorials.htm', nil, nil, SW_SHOWNORMAL)
- end;
- procedure TWelcomePageFrame.DoUpdateClick(Sender: TObject);
- begin
- ExecFrameCommand('!Update');
- end;
- procedure TWelcomePageFrame.DoVideosClick(Sender: TObject);
- begin
- GDIPaintPanel.ClearItemsByGroupIndex([1]);
- GDIPaintPanel.Redraw;
- fVideosFrame := TFrmVideos.Create(self);
- fVideosFrame.OnBackButton := BackFromVideos;
- fVideosFrame.parent := self;
- fVideosFrame.align := alClient;
- fVideosFrame.SetupFrame;
- fVideosFrame.Show;
- end;
- procedure TWelcomePageFrame.DoWelcomeClick(Sender: TObject);
- begin
- if FileExists(ExamplesFilesDir+'Get Me Started Example\Get_Me_Started.hmxz') then
- DoOpenRecentFile(ExamplesFilesDir+'Get Me Started Example\Get_Me_Started.hmxz')
- else
- ExecFrameCommand('!Welcome');
- end;
- procedure TWelcomePageFrame.EvalImageSize;
- var
- tmpScale: Extended;
- tmpRect: TRect;
- tmpImageWidth: Integer;
- tmpImageHeight: Integer;
- begin
- // position the panel with the tiles
- GDIPaintPanel.Left := 0;
- GDIPaintPanel.Width := ClientWidth - _dpi(32);
- GDIPaintPanel.Height := _dpi(390 { 454 });
- GDIPaintPanel.Top := (ClientHeight - GDIPaintPanel.Height) DIV 2;
- FreeAndNil(FBkImage);
- if (ClientHeight > 100) AND (imgBackground.Picture.Width > 0) then
- begin
- // reposition the image to be stretched
- tmpImageWidth := imgBackground.Picture.Width;
- tmpImageHeight := imgBackground.Picture.Height;
- tmpScale := _min(tmpImageWidth / ClientWidth, tmpImageHeight / ClientHeight);
- imgBackground.Width := Round(tmpImageWidth / tmpScale);
- imgBackground.Height := Round(tmpImageHeight / tmpScale);
- if imgBackground.Width > ClientWidth then
- begin
- imgBackground.Left := (ClientWidth - imgBackground.Width) DIV 2;
- imgBackground.Top := 0;
- end else begin
- imgBackground.Left := 0;
- imgBackground.Top := (ClientHeight - imgBackground.Height) DIV 2;
- end;
- tmpRect := Rect(0, 0, imgBackground.Width, imgBackground.Height);
- OffsetRect(tmpRect, imgBackground.Left, imgBackground.Top-GDIPaintPanel.Top);
- FBkImage := HMCreateBitmap(GDIPaintPanel.Width, GDIPaintPanel.Height);
- FBkImage.Canvas.Brush.Color := FBackgroundColor;
- FBkImage.Canvas.FillRect(Rect(-1, -1, FBkImage.Width+2, FBkImage.Height+2));
- FBkImage.Canvas.StretchDraw(tmpRect, imgBackground.Picture.Graphic);
- GDIPaintPanel.OnBackgroundDraw := GDIPaintPanelBackgroundDraw;
- end else
- GDIPaintPanel.OnBackgroundDraw := nil;
- end;
- function TWelcomePageFrame.ExecFrameCommand(const ACommand: String): boolean;
- begin
- if Assigned(FOnFrameCommand) then
- Result := FOnFrameCommand(ACommand)
- else
- Result := False;
- end;
- procedure TWelcomePageFrame.FormCreate(Sender: TObject);
- begin
- {
- Font.Size := 10; // this helps us to calculate ellipsified texts
- GDIPaintPanel := THMGDIPaintPanel.create(self);
- with GDIPaintPanel do
- begin
- Parent := self;
- BackgroundColor := clGray;
- ControlState := [];
- ControlStyle := [csCaptureMouse,csClickEvents,csSetCaption,csDoubleClicks,csGestures];
- DockOrientation := doNoOrient;
- OnMouseDown := GDIPaintPanelMouseDown;
- OnMouseLeave := GDIPaintPanelMouseLeave;
- OnMouseMove := GDIPaintPanelMouseMove;
- OnMouseUp := GDIPaintPanelMouseUp;
- end;
- }
- fVideosFrame := nil;
- end;
- procedure TWelcomePageFrame.FormResize(Sender: TObject);
- begin
- EvalImageSize;
- end;
- procedure TWelcomePageFrame.FormShow(Sender: TObject);
- begin
- GDIPaintPanel.Font.Assign(self.font);
- EvalImageSize;
- end;
- procedure TWelcomePageFrame.GDIPaintPanelBackgroundDraw(Sender: TObject; ADC: HDC; const AWidth, AHeight: Integer);
- begin
- if Assigned(FBkImage) then
- BitBlt(ADC, 0, 0, AWIdth, AHeight, FBkImage.Canvas.Handle, 0, 0, SRCCOPY)
- end;
- procedure TWelcomePageFrame.GDIPaintPanelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- var
- tmpHitTest: THMTileHitTest;
- begin
- tmpHitTest := GDIPaintPanel.HitTest;
- if Assigned(tmpHitTest.HitTile) then
- begin
- tmpHitTest.HitTile.DoHoverIn;
- FPressedItem := tmpHitTest.HitTile;
- end;
- end;
- procedure TWelcomePageFrame.GDIPaintPanelMouseLeave(Sender: TObject);
- begin
- if Assigned(FSelectedItem) then
- begin
- HMAnimateInflate(FSelectedItem, 0, 0, FSelectedItem.X, FSelectedItem.Y, INFLATE_X, 90);
- SelectedItem := nil;
- end;
- end;
- procedure TWelcomePageFrame.InternalCreateWhatsNewItem(const aScale, aIndex: Integer; caption, desc: string);
- var
- tmpX: Integer;
- tmpY: Integer;
- tmpW: Integer;
- result: THMTileItem;
- begin
- tmpX := _x(0); //
- tmpY := _y2(AIndex + 3);
- tmpW := _w(2);
- Canvas.Font.Size := 12;
- caption := HMEllipsifyText(False, caption, Canvas, tmpW - _dpi(20));
- Canvas.Font.Size := 8;
- desc := HMEllipsifyText(True, desc, Canvas, tmpW - _dpi(20));
- Result := THMTileItem.CreateEx(GDIPaintPanel, tmpX, tmpY, tmpW, _h2(1), AScale, AScale, FColorSet[2], clBlack, caption, desc, _media('whatsnew_item.png'), clGreen, taLeftJustify, 1);
- Result.HeaderVerticalAlign := taAlignTop;
- Result.TextGap := 7;
- Result.DescriptionFontSize := Canvas.Font.Size;
- Result.TitleFontSize := 14;
- Result.PrepareItem;
- end;
- procedure TWelcomePageFrame.GDIPaintPanelMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- var
- tmpHitTest: THMTileHitTest;
- begin
- tmpHitTest := GDIPaintPanel.HitTest;
- if tmpHitTest.HitTile <> FSelectedItem then
- begin
- if Assigned(FSelectedItem) then
- HMAnimateInflate(FSelectedItem, 0, 0, FSelectedItem.X, FSelectedItem.Y, INFLATE_X, 90);
- if Assigned(tmpHitTest.HitTile) then HMAnimateInflate(tmpHitTest.HitTile, INFLATE_X, INFLATE_Y, tmpHitTest.HitTile.X, tmpHitTest.HitTile.Y, INFLATE_X, 90);
- SelectedItem := tmpHitTest.HitTile;
- end;
- end;
- procedure TWelcomePageFrame.GDIPaintPanelMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- var
- tmpHitTest: THMTileHitTest;
- begin
- tmpHitTest := GDIPaintPanel.HitTest;
- if Assigned(FPressedItem) then
- begin
- FPressedItem.DoHoverOut;
- if tmpHitTest.HitTile = FPressedItem then
- FPressedItem.DoClick;
- end;
- FPressedItem := nil;
- end;
- procedure TWelcomePageFrame.objStartTimerTimer(Sender: TObject);
- begin
- objStartTimer.Enabled := False;
- GDIPaintPanel.BlendItemsIn([1, 2, 3, 4]);
- end;
- procedure TWelcomePageFrame.RefreshDisplay;
- begin
- EvalImageSize;
- Invalidate;
- GDIPaintPanel.Redraw;
- end;
- procedure TWelcomePageFrame.SetBackgroundColor(const Value: TColor);
- begin
- FBackgroundColor := Value;
- Color := Value;
- GDIPaintPanel.BackgroundColor := FBackgroundColor;
- EvalImageSize;
- GDIPaintPanel.Redraw;
- end;
- procedure TWelcomePageFrame.SetColorSet(const Value: THMTileColorSet);
- begin
- FColorSet := Value;
- if (GDIPaintPanel.ItemCount > 0) AND (GDIPaintPanel.Items[0].GroupIndex = 1) then
- begin
- GDIPaintPanel.ClearItems;
- CreateMainItems(100);
- GDIPaintPanel.Redraw;
- end;
- end;
- procedure TWelcomePageFrame.SetSelectedItem(const Value: THMTileItem);
- begin
- FSelectedItem := Value;
- if Assigned(FSelectedItem) then
- GDIPaintPanel.Cursor := crHandPoint
- else
- GDIPaintPanel.Cursor := crDefault;
- end;
- procedure TWelcomePageFrame.SetWallpaper(const Value: String);
- begin
- FWallpaper := Value;
- if FileExists(FWallpaper) then
- begin
- imgBackground.Picture.LoadFromFile(FWallpaper);
- GDIPaintPanel.AlphaEnabled := True;
- end
- else begin
- imgBackground.Picture.Assign(imgDefault.Picture);
- GDIPaintPanel.AlphaEnabled := False;
- end;
- EvalImageSize;
- Invalidate;
- GDIPaintPanel.Redraw;
- end;
- procedure TWelcomePageFrame.ShowMainItems;
- begin
- GDIPaintPanel.MoveItemsOut([2], DIRECTION_LEFT);
- GDIPaintPanel.ClearItems;
- FRecentFileNames.Clear;
- CreateMainItems(100);
- GDIPaintPanel.MoveItemsIn([1], DIRECTION_LEFT);
- end;
- function TWelcomePageFrame._h(const AHCount: Integer): Integer;
- begin
- Result := _dpi(AHCount * TILE_HEIGHT + (AHCount-1) * TILE_VGAP); // 298;
- end;
- function TWelcomePageFrame._h2(const AHCount: Integer): Integer;
- begin
- Result := _dpi(AHCount * TILE_HEIGHT2 + (AHCount-1) * TILE_VGAP2); // 298;
- end;
- {$IFDEF MEDIA_AS_FILES}
- function TWelcomePageFrame._media(const AFileName: String): String;
- begin
- Result := ExtractFilePath(Application.ExeName) + 'Media\' + AFileName;
- end;
- {$ELSE}
- function TWelcomePageFrame._media(const AFileName: String): TStream;
- begin
- if DM.Tiles.ContainsFile(AFileName) then
- Result := DM.Tiles.Files[AFileName]
- else
- Result := nil;
- end;
- {$ENDIF}
- function TWelcomePageFrame._recentFiles: String;
- var
- tmpFiles: TStringList;
- intIndex: Integer;
- begin
- Canvas.Font.Size := 10;
- tmpFiles := TStringList.Create;
- try
- // UserSettings.GetMRUDocuments(tmpFiles);
- while tmpFiles.Count > 8 do
- tmpFiles.Delete(8);
- for intIndex := 0 to tmpFiles.Count-1 do
- tmpFiles[intIndex] := HMEllipsifyText(True, tmpFiles[intIndex], Self.Canvas, 200);
- Result := tmpFiles.Text;
- finally
- FreeAndNil(tmpFiles);
- end;
- end;
- function TWelcomePageFrame._w(const AWCount: Integer): Integer;
- begin
- Result := _dpi(AWCount * TILE_WIDTH + (AWCount-1) * TILE_HGAP);
- end;
- function TWelcomePageFrame._w2(const AWCount: Integer): Integer;
- begin
- Result := _dpi(AWCount * TILE_WIDTH2 + (AWCount-1) * TILE_HGAP2);
- end;
- function TWelcomePageFrame._x(const AXIndex: Integer): Integer;
- begin
- Result := _dpi(H_OFFSET + AXIndex * TILE_WIDTH + (AXIndex-1) * TILE_HGAP); // 298;
- end;
- function TWelcomePageFrame._x2(const AXIndex: Integer): Integer;
- begin
- Result := _dpi(H_OFFSET2 + AXIndex * TILE_WIDTH2 + (AXIndex-1) * TILE_HGAP2); // 298;
- end;
- function TWelcomePageFrame._y(const AYIndex: Integer): Integer;
- begin
- Result := _dpi(V_OFFSET + AYIndex * TILE_HEIGHT + (AYIndex-1) * TILE_HGAP);
- end;
- function TWelcomePageFrame._y2(const AYIndex: Integer): Integer;
- begin
- Result := _dpi(V_OFFSET2 + AYIndex * TILE_HEIGHT2 + (AYIndex-1) * TILE_HGAP2);
- end;
- initialization
- FileGetDateTimeInfo(Application.ExeName, AppFileDate);
- gDefaultTilesAlpha := 88;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement