summaryrefslogtreecommitdiff
path: root/examples/gui/customwindow
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@gmail.com>2015-04-09 08:12:22 +0100
committerGraeme Geldenhuys <graemeg@gmail.com>2015-04-09 08:12:22 +0100
commitdb31f06d5e7adf28fad60e36fd9e5d2cf0519e84 (patch)
treebc7782a4a174ce57836947cec194281651b642e7 /examples/gui/customwindow
parentc8acc2c1666015daeb3038c838e5018c0ecd8903 (diff)
parentf37cd9b2a08a41b8d877f64f9d5d5402105ee74a (diff)
downloadfpGUI-db31f06d5e7adf28fad60e36fd9e5d2cf0519e84.tar.xz
Merge branch 'release-1.4'
Diffstat (limited to 'examples/gui/customwindow')
-rw-r--r--examples/gui/customwindow/close.bmpbin0 -> 338 bytes
-rw-r--r--examples/gui/customwindow/custom_window.lpi65
-rw-r--r--examples/gui/customwindow/custom_window.lpr352
-rw-r--r--examples/gui/customwindow/extrafpc.cfg10
-rw-r--r--examples/gui/customwindow/images.inc57
-rw-r--r--examples/gui/customwindow/resize.bmpbin0 -> 474 bytes
-rw-r--r--examples/gui/customwindow/units/.gitignore1
7 files changed, 485 insertions, 0 deletions
diff --git a/examples/gui/customwindow/close.bmp b/examples/gui/customwindow/close.bmp
new file mode 100644
index 00000000..af6745a5
--- /dev/null
+++ b/examples/gui/customwindow/close.bmp
Binary files differ
diff --git a/examples/gui/customwindow/custom_window.lpi b/examples/gui/customwindow/custom_window.lpi
new file mode 100644
index 00000000..2059fa29
--- /dev/null
+++ b/examples/gui/customwindow/custom_window.lpi
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+ <ProjectOptions>
+ <Version Value="9"/>
+ <General>
+ <SessionStorage Value="InProjectDir"/>
+ <MainUnit Value="0"/>
+ <Title Value="custom_window"/>
+ <UseAppBundle Value="False"/>
+ <ResourceType Value="res"/>
+ </General>
+ <i18n>
+ <EnableI18N LFM="False"/>
+ </i18n>
+ <VersionInfo>
+ <StringTable ProductVersion=""/>
+ </VersionInfo>
+ <BuildModes Count="1">
+ <Item1 Name="Default" Default="True"/>
+ </BuildModes>
+ <PublishOptions>
+ <Version Value="2"/>
+ </PublishOptions>
+ <RunParams>
+ <local>
+ <FormatVersion Value="1"/>
+ </local>
+ </RunParams>
+ <RequiredPackages Count="1">
+ <Item1>
+ <PackageName Value="fpgui_toolkit"/>
+ </Item1>
+ </RequiredPackages>
+ <Units Count="2">
+ <Unit0>
+ <Filename Value="custom_window.lpr"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="custom_window"/>
+ </Unit0>
+ <Unit1>
+ <Filename Value="images.inc"/>
+ <IsPartOfProject Value="True"/>
+ </Unit1>
+ </Units>
+ </ProjectOptions>
+ <CompilerOptions>
+ <Version Value="11"/>
+ <SearchPaths>
+ <IncludeFiles Value="$(ProjOutDir)"/>
+ </SearchPaths>
+ </CompilerOptions>
+ <Debugging>
+ <Exceptions Count="3">
+ <Item1>
+ <Name Value="EAbort"/>
+ </Item1>
+ <Item2>
+ <Name Value="ECodetoolError"/>
+ </Item2>
+ <Item3>
+ <Name Value="EFOpenError"/>
+ </Item3>
+ </Exceptions>
+ </Debugging>
+</CONFIG>
diff --git a/examples/gui/customwindow/custom_window.lpr b/examples/gui/customwindow/custom_window.lpr
new file mode 100644
index 00000000..eab06e5d
--- /dev/null
+++ b/examples/gui/customwindow/custom_window.lpr
@@ -0,0 +1,352 @@
+{ This was a very quick and dirty demo to show how custom windows with your
+ own style of borders (eg: like Chrome or elementryOS) can be implement.
+ There is obviously lots of scope for improving this code and creating
+ custom widgets to make better use of code reuse and abstraction. }
+program custom_window;
+
+{$mode objfpc}{$H+}
+
+uses
+ {$IFDEF UNIX}{$IFDEF UseCThreads}
+ cthreads,
+ {$ENDIF}{$ENDIF}
+ Classes, SysUtils,
+ fpg_base, fpg_main, fpg_form, fpg_button,
+ fpg_stylemanager, fpg_cmdlineparams, fpg_grid,
+ fpg_StringGridBuilder, fpg_editbtn, fpg_checkbox,
+ fpg_panel, fpg_dialogs;
+
+type
+
+ TMainForm = class(TfpgForm)
+ procedure ResizeClicked(Sender: TObject);
+ private
+ {@VFD_HEAD_BEGIN: MainForm}
+ btnQuit: TfpgButton;
+ Grid1: TfpgStringGrid;
+ FilenameEdit1: TfpgFileNameEdit;
+ btnGo: TfpgButton;
+ CheckBox1: TfpgCheckBox;
+ bvlTitle: TfpgBevel;
+ btnClose: TfpgImagePanel;
+ btnResize: TfpgImagePanel;
+ bvlTasks: TfpgBevel;
+ {@VFD_HEAD_END: MainForm}
+ FLastPos: TPoint;
+ FMouseTracked: Boolean;
+ procedure TitleMouseDown(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint);
+ procedure TitleMouseUp(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint);
+ procedure TitleMouseMoved(Sender: TObject; AShift: TShiftState; const AMousePos: TPoint);
+ procedure btnCloseClicked(Sender: TObject);
+ procedure PaintTasksPanel(Sender: TObject);
+ procedure PaintTitle(Sender: TObject);
+ procedure FormPaint(Sender: TObject);
+ procedure btnQuitClicked(Sender: TObject);
+ procedure btnGoClicked(Sender: TObject);
+ public
+ constructor Create(AOwner: TComponent); override;
+ procedure AfterCreate; override;
+ end;
+
+{@VFD_NEWFORM_DECL}
+
+const
+ cBackground = TfpgColor($FFf5f5f5);
+ cGradientTop = TfpgColor($FFe5e5e5);
+ cGradientBottom = TfpgColor($FFbcbcbc);
+ cBorder = TfpgColor($FF7c7c7c);
+ cGrayPanel = TfpgColor($FFdedede);
+
+ { tip: probably best to use specific fonts for specific OSes }
+ cHeader1 = 'Arial-11:bold:antialias=true';
+ cHeader2 = 'Arial-10:antialias=true';
+
+{$I images.inc}
+
+{@VFD_NEWFORM_IMPL}
+
+procedure TMainForm.ResizeClicked(Sender: TObject);
+begin
+ ShowMessage('I''ll leave this one up to you to implement and experiment with. ;-)', 'Hint');
+end;
+
+procedure TMainForm.TitleMouseDown(Sender: TObject; AButton: TMouseButton;
+ AShift: TShiftState; const AMousePos: TPoint);
+begin
+ FMouseTracked := True;
+ FLastPos := bvlTitle.WindowToScreen(self, AMousePos);
+ bvlTitle.CaptureMouse;
+end;
+
+procedure TMainForm.TitleMouseUp(Sender: TObject; AButton: TMouseButton;
+ AShift: TShiftState; const AMousePos: TPoint);
+begin
+ FMouseTracked := False;
+ bvlTitle.ReleaseMouse;
+end;
+
+procedure TMainForm.TitleMouseMoved(Sender: TObject; AShift: TShiftState;
+ const AMousePos: TPoint);
+var
+ dx, dy: integer;
+ pt: TPoint;
+begin
+ pt := WindowToScreen(self, AMousePos);
+ if not FMouseTracked then
+ begin
+ FLastPos := pt;
+ Exit;
+ end;
+
+ dx := pt.X - FLastPos.X;
+ dy := pt.Y - FLastPos.Y;
+ Left := Left + dx;
+ Top := Top + dy;
+ FLastPos := pt;
+ UpdateWindowPosition;
+end;
+
+procedure TMainForm.btnCloseClicked(Sender: TObject);
+begin
+ btnQuit.Click;
+end;
+
+procedure TMainForm.PaintTasksPanel(Sender: TObject);
+begin
+ with bvlTasks do
+ begin
+ Canvas.Clear(cGrayPanel);
+
+ Canvas.Color := cBorder;
+ Canvas.DrawRectangle(0, 0, Width, Height);
+
+ Canvas.TextColor := cBorder;
+ // Output some sample text
+ Canvas.Font := fpgGetFont(cHeader1);
+ Canvas.DrawText(8, 10, 'Personal');
+ Canvas.Font := fpgGetFont(cHeader2);
+ Canvas.DrawText(20, 30, 'Home');
+ Canvas.DrawText(20, 50, 'Documents');
+ Canvas.DrawText(20, 70, 'Music');
+ Canvas.DrawText(20, 90, 'Pictures');
+ Canvas.Font := fpgGetFont(cHeader1);
+ Canvas.DrawText(8, 110, 'Network');
+ Canvas.Font := fpgGetFont(cHeader2);
+ Canvas.DrawText(20, 130, 'Entire network');
+ end;
+end;
+
+procedure TMainForm.PaintTitle(Sender: TObject);
+var
+ r: TfpgRect;
+begin
+ r.SetRect(0, 1, Width, 46);
+ with bvlTitle do
+ begin
+ Canvas.GradientFill(r, cGradientTop, cGradientBottom, gdVertical);
+
+ Canvas.Color := TfpgColor($FFc9c9c9);
+ Canvas.DrawLine(0, Height-2, Width, Height-2);
+
+ Canvas.Color := cBorder;
+ Canvas.DrawRectangle(0, 0, Width, Height);
+
+ Canvas.TextColor := cBorder;
+ Canvas.Font := fpgGetFont(cHeader1);
+ Canvas.DrawText(30, 8, Width-60, 20, WindowTitle, [txtHCenter, txtTop]);
+ end;
+end;
+
+procedure TMainForm.FormPaint(Sender: TObject);
+begin
+ Canvas.Color := cBorder;
+ Canvas.DrawRectangle(0, 0, Width, Height);
+end;
+
+procedure TMainForm.btnQuitClicked(Sender: TObject);
+begin
+ Close;
+end;
+
+procedure TMainForm.btnGoClicked(Sender: TObject);
+var
+ sgb: TStringGridBuilder;
+begin
+ try
+ sgb := TStringGridBuilder.CreateCustom(Grid1, FilenameEdit1.FileName, CheckBox1.Checked);
+ sgb.Run;
+ finally
+ sgb.Free;
+ end;
+end;
+
+constructor TMainForm.Create(AOwner: TComponent);
+begin
+ inherited Create(AOwner);
+ Include(FWindowAttributes, waBorderLess); // borderless and steals focus like a normal form
+ FMouseTracked := False;
+
+ fpgSetNamedColor(clWindowBackground, cBackground);
+
+ fpgImages.AddBMP( // 8x9 pixels.
+ 'my.close',
+ @img_close,
+ sizeof(img_close));
+
+ fpgImages.AddBMP( // 10x11 pixels.
+ 'my.resize',
+ @img_resize,
+ sizeof(img_resize));
+end;
+
+procedure TMainForm.AfterCreate;
+begin
+ {%region 'Auto-generated GUI code' -fold}
+ {@VFD_BODY_BEGIN: MainForm}
+ Name := 'MainForm';
+ SetPosition(464, 271, 866, 473);
+ WindowTitle := 'fpGUI Custom Window Demo';
+ Hint := '';
+ OnPaint := @FormPaint;
+
+ btnQuit := TfpgButton.Create(self);
+ with btnQuit do
+ begin
+ Name := 'btnQuit';
+ SetPosition(772, 436, 80, 23);
+ Text := 'Quit';
+ FontDesc := '#Label1';
+ Hint := '';
+ ImageName := '';
+ TabOrder := 1;
+ OnClick := @btnQuitClicked;
+ end;
+
+ Grid1 := TfpgStringGrid.Create(self);
+ with Grid1 do
+ begin
+ Name := 'Grid1';
+ SetPosition(182, 120, 666, 276);
+ BackgroundColor := TfpgColor($80000002);
+ FontDesc := '#Grid';
+ HeaderFontDesc := '#GridHeader';
+ Hint := '';
+ RowCount := 0;
+ RowSelect := False;
+ TabOrder := 2;
+ end;
+
+ FilenameEdit1 := TfpgFileNameEdit.Create(self);
+ with FilenameEdit1 do
+ begin
+ Name := 'FilenameEdit1';
+ SetPosition(182, 92, 510, 24);
+ ExtraHint := '';
+ FileName := '';
+ Filter := 'CSV Files (*.csv)|*.csv';
+ InitialDir := '';
+ TabOrder := 3;
+ end;
+
+ btnGo := TfpgButton.Create(self);
+ with btnGo do
+ begin
+ Name := 'btnGo';
+ SetPosition(768, 92, 80, 23);
+ Text := 'GO';
+ FontDesc := '#Label1';
+ Hint := '';
+ ImageName := '';
+ TabOrder := 4;
+ OnClick := @btnGoClicked;
+ end;
+
+ CheckBox1 := TfpgCheckBox.Create(self);
+ with CheckBox1 do
+ begin
+ Name := 'CheckBox1';
+ SetPosition(184, 68, 120, 19);
+ FontDesc := '#Label1';
+ Hint := '';
+ TabOrder := 5;
+ Text := 'Has Header';
+ end;
+
+ bvlTitle := TfpgBevel.Create(self);
+ with bvlTitle do
+ begin
+ Name := 'bvlTitle';
+ SetPosition(0, 0, 866, 48);
+ Anchors := [anLeft,anRight,anTop];
+ Hint := '';
+ Shape := bsSpacer;
+ OnPaint := @PaintTitle;
+ OnMouseMove := @TitleMouseMoved;
+ OnMouseDown := @TitleMouseDown;
+ OnMouseUp := @TitleMouseUp;
+ end;
+
+ btnClose := TfpgImagePanel.Create(bvlTitle);
+ with btnClose do
+ begin
+ Name := 'btnClose';
+ SetPosition(9, 8, 8, 9);
+ OwnsImage := False;
+ OnClick := @btnCloseClicked;
+ end;
+
+ btnResize := TfpgImagePanel.Create(bvlTitle);
+ with btnResize do
+ begin
+ Name := 'btnResize';
+ SetPosition(849, 8, 10, 11);
+ OwnsImage := False;
+ OnClick := @ResizeClicked;
+ end;
+
+ bvlTasks := TfpgBevel.Create(self);
+ with bvlTasks do
+ begin
+ Name := 'bvlTasks';
+ SetPosition(0, 47, 170, 426);
+ Anchors := [anLeft,anTop,anBottom];
+ Hint := '';
+ Shape := bsSpacer;
+ OnPaint := @PaintTasksPanel;
+ end;
+
+ {@VFD_BODY_END: MainForm}
+ {%endregion}
+
+ btnClose.Image := fpgImages.GetImage('my.close');
+ btnResize.Image := fpgImages.GetImage('my.resize');
+end;
+
+
+procedure MainProc;
+var
+ frm: TMainForm;
+begin
+ fpgApplication.Initialize;
+
+ { Set our new style as the default (before we create any forms), unless
+ a the end-user specified a different style via the command line. }
+ if not gCommandLineParams.IsParam('style') then
+ begin
+ if fpgStyleManager.SetStyle('Plastic Light Gray') then
+ fpgStyle := fpgStyleManager.Style;
+ end;
+
+ frm := TMainForm.Create(nil);
+ try
+ frm.Show;
+ fpgApplication.Run;
+ finally
+ frm.Free;
+ end;
+end;
+
+begin
+ MainProc;
+end.
+
diff --git a/examples/gui/customwindow/extrafpc.cfg b/examples/gui/customwindow/extrafpc.cfg
new file mode 100644
index 00000000..89eafa99
--- /dev/null
+++ b/examples/gui/customwindow/extrafpc.cfg
@@ -0,0 +1,10 @@
+-FUunits
+-Fu../../../lib/$fpctarget
+-Fu../common/
+-Xs
+-XX
+-CX
+#ifdef mswindows
+-WG
+#endif
+
diff --git a/examples/gui/customwindow/images.inc b/examples/gui/customwindow/images.inc
new file mode 100644
index 00000000..79663a24
--- /dev/null
+++ b/examples/gui/customwindow/images.inc
@@ -0,0 +1,57 @@
+
+const
+ img_close: array[0..337] of byte = (
+ 66, 77, 82, 1, 0, 0, 0, 0, 0, 0,122, 0, 0, 0,108, 0, 0,
+ 0, 8, 0, 0, 0, 9, 0, 0, 0, 1, 0, 24, 0, 0, 0, 0, 0,
+ 216, 0, 0, 0,196, 14, 0, 0,196, 14, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 66, 71, 82,115, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0,226,226,226,238,238,238,225,225,225,223,223,223,223,223,
+ 223,226,226,226,238,238,238,226,226,226,228,228,228,184,184,184,231,
+ 231,231,226,226,226,226,226,226,230,230,230,184,184,184,228,228,228,
+ 172,172,172,160,160,160,173,173,173,231,231,231,231,231,231,173,173,
+ 173,160,160,160,172,172,172,216,216,216,159,159,159,153,153,153,170,
+ 170,170,168,168,168,153,153,153,157,157,157,215,215,215,225,225,225,
+ 219,219,219,165,165,165,149,149,149,149,149,149,162,162,162,218,218,
+ 218,225,225,225,227,227,227,229,229,229,158,158,158,141,141,141,142,
+ 142,142,163,163,163,232,232,232,227,227,227,227,227,227,152,152,152,
+ 136,136,136,146,146,146,144,144,144,136,136,136,154,154,154,228,228,
+ 228,149,149,149,128,128,128,140,140,140,217,217,217,215,215,215,138,
+ 138,138,128,128,128,150,150,150,213,213,213,147,147,147,214,214,214,
+ 226,226,226,226,226,226,214,214,214,146,146,146,213,213,213);
+
+
+const
+ img_resize: array[0..473] of byte = (
+ 66, 77,218, 1, 0, 0, 0, 0, 0, 0,122, 0, 0, 0,108, 0, 0,
+ 0, 10, 0, 0, 0, 11, 0, 0, 0, 1, 0, 24, 0, 0, 0, 0, 0,
+ 96, 1, 0, 0,196, 14, 0, 0,196, 14, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 66, 71, 82,115, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0,242,242,242,242,242,242,242,242,242,242,242,242,233,233,
+ 233,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223, 0,
+ 0,167,167,167,167,167,167,167,167,167,162,162,162,189,189,189,223,
+ 223,223,223,223,223,223,223,223,223,223,223,223,223,223, 0, 0,157,
+ 157,157,157,157,157,157,157,157,193,193,193,226,226,226,224,224,224,
+ 224,224,224,224,224,224,224,224,224,224,224,224, 0, 0,146,146,146,
+ 141,141,141,144,144,144,164,164,164,229,229,229,224,224,224,224,224,
+ 224,224,224,224,224,224,224,224,224,224, 0, 0,131,131,131,175,175,
+ 175,146,146,146,133,133,133,153,153,153,224,224,224,224,224,224,224,
+ 224,224,224,224,224,224,224,224, 0, 0,174,174,174,225,225,225,215,
+ 215,215,146,146,146,208,208,208,228,228,228,239,239,239,227,227,227,
+ 225,225,225,235,235,235, 0, 0,225,225,225,225,225,225,225,225,225,
+ 225,225,225,225,225,225,225,225,225,183,183,183,232,232,232,235,235,
+ 235,201,201,201, 0, 0,226,226,226,226,226,226,226,226,226,226,226,
+ 226,226,226,226,167,167,167,153,153,153,167,167,167,193,193,193,154,
+ 154,154, 0, 0,226,226,226,226,226,226,226,226,226,226,226,226,226,
+ 226,226,215,215,215,152,152,152,144,144,144,144,144,144,144,144,144,
+ 0, 0,226,226,226,226,226,226,226,226,226,226,226,226,226,226,226,
+ 235,235,235,184,184,184,134,134,134,134,134,134,134,134,134, 0, 0,
+ 227,227,227,227,227,227,227,227,227,227,227,227,227,227,227,168,168,
+ 168,115,115,115,115,115,115,115,115,115,115,115,115, 0, 0);
+
+
diff --git a/examples/gui/customwindow/resize.bmp b/examples/gui/customwindow/resize.bmp
new file mode 100644
index 00000000..8bb264cf
--- /dev/null
+++ b/examples/gui/customwindow/resize.bmp
Binary files differ
diff --git a/examples/gui/customwindow/units/.gitignore b/examples/gui/customwindow/units/.gitignore
new file mode 100644
index 00000000..72e8ffc0
--- /dev/null
+++ b/examples/gui/customwindow/units/.gitignore
@@ -0,0 +1 @@
+*