Ver Fonte

demo: started checkbox

mattias há 1 ano atrás
pai
commit
07b29c6cc8

+ 2 - 0
demo/CheckBox/.gitignore

@@ -0,0 +1,2 @@
+CustomCheckBox
+CustomCheckBox.app

BIN
demo/CheckBox/Check.png


BIN
demo/CheckBox/CustomCheckBox.ico


+ 93 - 0
demo/CheckBox/CustomCheckBox.lpi

@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+  <ProjectOptions>
+    <Version Value="12"/>
+    <General>
+      <Flags>
+        <MainUnitHasCreateFormStatements Value="False"/>
+        <MainUnitHasTitleStatement Value="False"/>
+        <MainUnitHasScaledStatement Value="False"/>
+      </Flags>
+      <SessionStorage Value="InProjectDir"/>
+      <Title Value="CustomCheckBox"/>
+      <ResourceType Value="res"/>
+      <UseXPManifest Value="True"/>
+      <Icon Value="0"/>
+    </General>
+    <BuildModes>
+      <Item Name="Default" Default="True"/>
+    </BuildModes>
+    <PublishOptions>
+      <Version Value="2"/>
+      <UseFileFilters Value="True"/>
+    </PublishOptions>
+    <RunParams>
+      <FormatVersion Value="2"/>
+    </RunParams>
+    <RequiredPackages>
+      <Item>
+        <PackageName Value="FresnelDsgn"/>
+      </Item>
+      <Item>
+        <PackageName Value="FresnelBase"/>
+      </Item>
+      <Item>
+        <PackageName Value="Fresnel"/>
+      </Item>
+    </RequiredPackages>
+    <Units>
+      <Unit>
+        <Filename Value="CustomCheckBox.lpr"/>
+        <IsPartOfProject Value="True"/>
+      </Unit>
+      <Unit>
+        <Filename Value="MainUnit.pas"/>
+        <IsPartOfProject Value="True"/>
+        <ComponentName Value="FresnelSliderForm"/>
+        <ResourceBaseClass Value="Other"/>
+        <ResourceBaseClassname Value="TFresnelForm"/>
+      </Unit>
+      <Unit>
+        <Filename Value="DemoSlider.pas"/>
+        <IsPartOfProject Value="True"/>
+      </Unit>
+      <Unit>
+        <Filename Value="DemoCheckBox.pas"/>
+        <IsPartOfProject Value="True"/>
+      </Unit>
+    </Units>
+  </ProjectOptions>
+  <CompilerOptions>
+    <Version Value="11"/>
+    <Target>
+      <Filename Value="CustomCheckBox"/>
+    </Target>
+    <SearchPaths>
+      <IncludeFiles Value="$(ProjOutDir)"/>
+      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
+    </SearchPaths>
+    <Linking>
+      <Debugging>
+        <DebugInfoType Value="dsDwarf2"/>
+      </Debugging>
+      <Options>
+        <Win32>
+          <GraphicApplication Value="True"/>
+        </Win32>
+      </Options>
+    </Linking>
+  </CompilerOptions>
+  <Debugging>
+    <Exceptions>
+      <Item>
+        <Name Value="EAbort"/>
+      </Item>
+      <Item>
+        <Name Value="ECodetoolError"/>
+      </Item>
+      <Item>
+        <Name Value="EFOpenError"/>
+      </Item>
+    </Exceptions>
+  </Debugging>
+</CONFIG>

+ 23 - 0
demo/CheckBox/CustomCheckBox.lpr

@@ -0,0 +1,23 @@
+program CustomCheckBox;
+
+{$mode objfpc}{$H+}
+
+uses
+  {$IFDEF UNIX}
+  cthreads,
+  {$ENDIF}
+  {$IFDEF HASAMIGA}
+  athreads,
+  {$ENDIF}
+  Fresnel, // this includes the Fresnel widgetset
+  Fresnel.Forms, MainUnit, DemoCheckBox
+  { you can add units after this };
+
+{$R *.res}
+
+begin
+  Application.Initialize;
+  Application.CreateForm(TFresnelCheckBoxForm, FresnelCheckBoxForm);
+  Application.Run;
+end.
+

BIN
demo/CheckBox/CustomCheckBox.res


+ 146 - 0
demo/CheckBox/DemoCheckBox.pas

@@ -0,0 +1,146 @@
+unit DemoCheckBox;
+
+{$mode ObjFPC}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, FPReadPNG, Fresnel.DOM, Fresnel.Controls, Fresnel.Classes,
+  FCL.Events, Fresnel.Events;
+
+type
+
+  { TDemoCheckBoxButton }
+
+  TDemoCheckBoxButton = class(TImage)
+  private
+    FChecked: boolean;
+    procedure OnClickEvent(Event: TAbstractEvent);
+  protected
+    procedure SetChecked(const AValue: boolean); virtual;
+  public
+    const
+      cStyle = ''
+        +'.CheckBoxButton {'+LineEnding
+        +'  cursor: pointer;'+LineEnding
+        +'  border-radius: 3px;'+LineEnding
+        +'  padding: 1px;'+LineEnding
+        +'  width: 11px;'+LineEnding
+        +'  height: 11px;'+LineEnding
+        +'}'+LineEnding;
+      cCheckedStyle = 'background: blue; border: 2px solid blue;';
+      cUncheckedStyle = 'background: white; border: 2px solid #999;';
+  public
+    CheckedStyle: string;
+    UncheckedStyle: string;
+    constructor Create(AOwner: TComponent); override;
+    property Checked: boolean read FChecked write SetChecked;
+  end;
+
+  { TDemoCheckBox }
+
+  TDemoCheckBox = class(TDiv)
+  private
+    function GetCaption: TFresnelCaption;
+    function GetChecked: boolean;
+    procedure SetCaption(const AValue: TFresnelCaption);
+    procedure SetChecked(const AValue: boolean);
+  public
+    // default styles
+    const
+      cStyle = ''
+        +'.CheckBoxButton {'+LineEnding
+        +'  margin: 0 2px 0 0;'+LineEnding
+        +'}'+LineEnding
+        +'.CheckBoxLabel {'+LineEnding
+        +'  cursor: pointer;'+LineEnding
+        +'  font-size: 11px;'+LineEnding
+        +'  padding: 4px 3px;'+LineEnding
+        +'  margin-bottom: 0;'+LineEnding
+        +'}'+LineEnding;
+  public
+    Box: TDemoCheckBoxButton;
+    CaptionLabel: TLabel;
+    constructor Create(AOwner: TComponent); override;
+    property Caption: TFresnelCaption read GetCaption write SetCaption;
+    property Checked: boolean read GetChecked write SetChecked;
+  end;
+
+implementation
+
+{ TDemoCheckBoxButton }
+
+procedure TDemoCheckBoxButton.OnClickEvent(Event: TAbstractEvent);
+begin
+  if Event is TFresnelMouseClickEvent then ;
+  Checked:=not Checked;
+end;
+
+procedure TDemoCheckBoxButton.SetChecked(const AValue: boolean);
+begin
+  if FChecked=AValue then Exit;
+  FChecked:=AValue;
+  if Checked then
+  begin
+    Style:=CheckedStyle;
+  end else begin
+    Style:=UncheckedStyle;
+  end;
+end;
+
+constructor TDemoCheckBoxButton.Create(AOwner: TComponent);
+begin
+  inherited Create(AOwner);
+
+  CheckedStyle:=cCheckedStyle;
+  UncheckedStyle:=cUncheckedStyle;
+
+  Style:=UncheckedStyle;
+  Image.LoadFromFile('Check.png');
+
+  AddEventListener(evtClick,@OnClickEvent);
+end;
+
+{ TDemoCheckBox }
+
+function TDemoCheckBox.GetCaption: TFresnelCaption;
+begin
+  Result:=CaptionLabel.Caption;
+end;
+
+function TDemoCheckBox.GetChecked: boolean;
+begin
+  Result:=Box.Checked;
+end;
+
+procedure TDemoCheckBox.SetCaption(const AValue: TFresnelCaption);
+begin
+  CaptionLabel.Caption:=AValue;
+end;
+
+procedure TDemoCheckBox.SetChecked(const AValue: boolean);
+begin
+  Box.Checked:=AValue;
+end;
+
+constructor TDemoCheckBox.Create(AOwner: TComponent);
+begin
+  inherited Create(AOwner);
+
+  Box:=TDemoCheckBoxButton.Create(Self);
+  with Box do begin
+    Name:='Box';
+    CSSClasses.Add('CheckBoxButton');
+    Parent:=Self;
+  end;
+
+  CaptionLabel:=TLabel.Create(Self);
+  with CaptionLabel do begin
+    Name:='CaptionLabel';
+    CSSClasses.Add('CheckBoxCaption');
+    Parent:=Self;
+  end;
+end;
+
+end.
+

+ 8 - 0
demo/CheckBox/MainUnit.lfm

@@ -0,0 +1,8 @@
+object FresnelCheckBoxForm: TFresnelCheckBoxForm
+  Caption = 'Fresnel CheckBox'
+  FormLeft = 301
+  FormTop = 206
+  FormWidth = 320
+  FormHeight = 240
+  OnCreate = FresnelCheckBoxFormCreate
+end

+ 45 - 0
demo/CheckBox/MainUnit.pas

@@ -0,0 +1,45 @@
+unit MainUnit;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, Fresnel.Forms, Fresnel.DOM, Fresnel.Controls, DemoCheckBox;
+
+type
+
+  { TFresnelCheckBoxForm }
+
+  TFresnelCheckBoxForm = class(TFresnelForm)
+    procedure FresnelCheckBoxFormCreate(Sender: TObject);
+  private
+  public
+  end;
+
+var
+  FresnelCheckBoxForm: TFresnelCheckBoxForm;
+
+implementation
+
+{$R *.lfm}
+
+{ TFresnelCheckBoxForm }
+
+procedure TFresnelCheckBoxForm.FresnelCheckBoxFormCreate(Sender: TObject);
+var
+  CheckBox: TDemoCheckBox;
+begin
+  Stylesheet.Text:=TDemoCheckBoxButton.cStyle+TDemoCheckBox.cStyle;
+
+  CheckBox:=TDemoCheckBox.Create(Self);
+  with CheckBox do begin
+    Name:='CheckBox';
+    Style:='width: 150px';
+    Caption:='CheckBox Text';
+    Parent:=Self;
+  end;
+end;
+
+end.
+