{ ------------------------------------------------------------- }
{ Purpose : NextGrid 6                                          }
{ By      : Bojan Nikolic                                       }
{ For     : BergSoft                                            }
{ ------------------------------------------------------------- }
{ Copyright (C) BergSoft.net 2012. All Rights Reserved.         }
{ ------------------------------------------------------------- }
{$I NxSuite6.inc}
unit NxStylePaint6;

interface

uses
  { Standard }
  Classes, Types, Windows, Graphics, Controls, StdCtrls,
  {$IFDEF UI_TYPES}UITypes,{$ENDIF}
  { Next Standard 6 }
  NxTypes6, NxIntf6, NxControls6, NxConsts6, NxGraphics6, NxStyles6;

type
  { INxStylePaint }

  INxStylePaint = interface(INxControlStyle)
    ['{04D84A7B-B331-4970-BA34-CD53CBAE94F6}']
    { Property Accessors }
    function GetCanvas: TCanvas;
    function GetColor: TColor;
    function GetControl: TWinControl;
    function GetFont: TFont;
    function GetHighlightColor: TColor;
    function GetStyleOptions: TNxStyleOptions;
    procedure SetCanvas(const Value: TCanvas);
    procedure SetColor(const Value: TColor);
    procedure SetControl(const Value: TWinControl);
    procedure SetFont(const Value: TFont);
    { Properties }
    property Canvas: TCanvas read GetCanvas write SetCanvas;
    property Color: TColor read GetColor write SetColor;
    property Control: TWinControl read GetControl write SetControl;
    property Font: TFont read GetFont write SetFont;
    property HighlightColor: TColor read GetHighlightColor;
    property StyleOptions: TNxStyleOptions read GetStyleOptions;
  end;

  { TNxStylePaint }

  TNxStylePaint = class(TInterfacedObject, INxStylePaint)
  private
    { Property Fields }
    FAppearanceOptions: TNxAppearanceOptions;
    FCanvas: TCanvas;
    FColor: TColor;
    FControl: TWinControl;
    FFont: TFont;
    function GetStyledControl: INxStyledControl;
  protected
    function GetHighlightColor: TColor; virtual;
  public
    { Property Accessors }
    function GetAppearanceOptions: TNxAppearanceOptions;
    function GetCanvas: TCanvas;
    function GetColor: TColor;
    function GetControl: TWinControl;
    function GetFont: TFont;
    function GetStyleOptions: TNxStyleOptions;
    procedure SetAppearanceOptions(const Value: TNxAppearanceOptions);
    procedure SetCanvas(const Value: TCanvas);
    procedure SetColor(const Value: TColor);
    procedure SetControl(const Value: TWinControl);
    procedure SetFont(const Value: TFont);
  public
    constructor Create(AOwner: TComponent); virtual;
    function CanStyle(Option: TNxStyleOption): Boolean;
    function IsStyled: Boolean;
    procedure DrawFrame(ARect: TRect); virtual; abstract;
    { INxControlStyle }
    procedure PaintCheckBox(ARect: TRect; CheckBoxState: TCheckBoxState; AState: TNxButtonState); virtual; abstract;
    procedure PaintDropDownButton(ARect: TRect; AState: TNxButtonState); virtual; abstract;
    procedure PaintProgressBar(BarRect: TRect); virtual; abstract;
    procedure PaintProgressChunk(ChunkRect: TRect); virtual; abstract;
    procedure PaintPushButton(ButtonRect: TRect; AState: TNxButtonState); virtual; abstract;
    procedure PaintToolButton(ARect: TRect; AState: TNxButtonState); virtual; abstract;
    procedure PaintTrack(TrackRect: TRect); virtual; abstract;
    procedure PaintTrackThumb(ThumbRect: TRect; State: TNxButtonState); virtual; abstract;
    { Properties }
    property Canvas: TCanvas read GetCanvas write SetCanvas;
    property Color: TColor read GetColor write SetColor;
    property Control: TWinControl read GetControl write SetControl;
    property Font: TFont read GetFont write SetFont;
    property StyledControl: INxStyledControl read GetStyledControl;
    property StyleOptions: TNxStyleOptions read GetStyleOptions;
  end;

  { TNxNativeStylePaint }

  TNxNativeStylePaint = class(TNxStylePaint)
  public
    procedure DrawFrame(ARect: TRect); override;
    { Paint }
    procedure PaintCheckBox(ARect: TRect; CheckBoxState: TCheckBoxState;
      AState: TNxButtonState); override;
    procedure PaintDropDownButton(ARect: TRect; AState: TNxButtonState); override;
    procedure PaintProgressBar(BarRect: TRect); override;
    procedure PaintProgressChunk(ProgressRect: TRect); override;
    procedure PaintPushButton(ButtonRect: TRect; AState: TNxButtonState); override;
    procedure PaintToolButton(ARect: TRect; AState: TNxButtonState); override;
    procedure PaintTrack(TrackRect: TRect); override;
    procedure PaintTrackThumb(ThumbRect: TRect; State: TNxButtonState); override;
  end;

  TNxOffice2013StylePaint = class(TNxStylePaint)
  public
    procedure PaintToolButton(ARect: TRect; AState: TNxButtonState); override;
  end;

  procedure PaintSquareToggle(Canvas: TCanvas; ToggleRect: TRect; Expanded: Boolean);
  procedure PaintTriangleToggle(Canvas: TCanvas; ToggleRect: TRect;
    Expanded: Boolean; State: TNxButtonState);


implementation

uses SysUtils, Math;

procedure PaintSquareToggle(Canvas: TCanvas; ToggleRect: TRect; Expanded: Boolean);
var
  C: Integer;
begin
  with Canvas do
  begin
    Pen.Color := clGray;
    Brush.Color := clWhite;
    Rectangle(ToggleRect);
    C := Floor(RectWidth(ToggleRect) / 2);
    Polyline([
      Point(ToggleRect.Left + 2, ToggleRect.Top + C),
      Point(ToggleRect.Right - 2, ToggleRect.Top + C)
    ]);
    if not Expanded then
      Polyline([
        Point(ToggleRect.Left + C, ToggleRect.Top + 2),
        Point(ToggleRect.Left + C, ToggleRect.Bottom - 2)
      ]);
  end;
end;

procedure PaintTriangleToggle(Canvas: TCanvas; ToggleRect: TRect;
  Expanded: Boolean; State: TNxButtonState);
var
  X, Y: Integer;
begin
  X := ToggleRect.Left;
  Y := ToggleRect.Top;
  with Canvas do
  begin
    if Expanded then
    begin
      if bsHover in State then
      begin
        Pen.Color := $00f7c41c;
        Brush.Color := $00fbdf82;
      end else
      begin
        Brush.Color := $00444444;
        Pen.Color := Brush.Color;
      end;
      Polygon([
        Point(X, Y + 5),
        Point(X + 5, Y + 5),
        Point(X + 5, Y + 0),
        Point(X, Y + 5)
      ]);
    end else
    begin
      if bsHover in State then Pen.Color := clHighlight else Pen.Color := $00888683;
      Brush.Style := bsClear;
      Polygon([
        Point(X, Y),
        Point(X + 4, Y + 4),
        Point(X, Y + 8),
        Point(X, Y)
      ]);
      Brush.Style := bsSolid;
    end;
  end;
end;

{ TNxStylePaint }

function TNxStylePaint.CanStyle(Option: TNxStyleOption): Boolean;
begin
  Result := Assigned(StyledControl) and StyledControl.CanStyle(Option);
end;

function TNxStylePaint.IsStyled: Boolean;
begin
  Result := CanStyle(soVCLStyles) or CanStyle(soNativeStyles);
end;

constructor TNxStylePaint.Create(AOwner: TComponent);
begin
  FControl := AOwner as TWinControl;
end;

function TNxStylePaint.GetAppearanceOptions: TNxAppearanceOptions;
begin
  Result := FAppearanceOptions;
end;

function TNxStylePaint.GetCanvas: TCanvas;
begin
  Result := FCanvas;
end;

function TNxStylePaint.GetColor: TColor;
begin
  Result := FColor;
end;

function TNxStylePaint.GetControl: TWinControl;
begin
  Result := FControl;
end;

function TNxStylePaint.GetFont: TFont;
begin
  Result := FFont;
end;

function TNxStylePaint.GetHighlightColor: TColor;
begin
  Result := clHighlight;
end;

function TNxStylePaint.GetStyledControl: INxStyledControl;
begin
  if not Supports(Control, INxStyledControl, Result) then Result := nil;
end;

function TNxStylePaint.GetStyleOptions: TNxStyleOptions;
begin
  Result := StyledControl.StyleOptions;
end;

procedure TNxStylePaint.SetAppearanceOptions(const Value: TNxAppearanceOptions);
begin
  FAppearanceOptions := Value;
end;

procedure TNxStylePaint.SetCanvas(const Value: TCanvas);
begin
  FCanvas := Value;
end;

procedure TNxStylePaint.SetColor(const Value: TColor);
begin
  FColor := Value;
end;

procedure TNxStylePaint.SetControl(const Value: TWinControl);
begin
  FControl := Value;
end;

procedure TNxStylePaint.SetFont(const Value: TFont);
begin
  FFont := Value;
end;

{ TNxOffice2013StylePaint }

procedure TNxOffice2013StylePaint.PaintToolButton(ARect: TRect;
  AState: TNxButtonState);
begin
  with Canvas do
  begin

    if AState <> [] then
    begin
      { Default }
      Brush.Color := ColorOf(seBtnFace);

      if bsPressed in AState then
      begin
        if bsHover in AState
          then Brush.Color := ColorOf(seBtnFacePressed)
          else Exit;
      end
      else if bsChecked in AState then
        if bsHover in AState
          then Brush.Color := ColorOf(seBtnFace)
          else Brush.Color := ColorOf(seBtnFaceChecked);

    end;

    FillRect(ARect);
  end;
end;

{ TNxNativeStylePaint }

procedure TNxNativeStylePaint.DrawFrame(ARect: TRect);
begin

end;

procedure TNxNativeStylePaint.PaintCheckBox(ARect: TRect; CheckBoxState: TCheckBoxState; AState: TNxButtonState);
begin
  TNxCheckBoxStyledView6.Paint(Canvas, Control.Handle, ARect, AState, CheckBoxState, StyleOptions);
end;

procedure TNxNativeStylePaint.PaintDropDownButton(ARect: TRect; AState: TNxButtonState);
begin
  TNxDropButtonStyledView6.Paint(Canvas, Control.Handle, ARect, AState, StyleOptions);
end;

procedure TNxNativeStylePaint.PaintProgressBar(BarRect: TRect);
begin
  TNxProgressStyledView6.Paint(Canvas, Control.Handle, BarRect, StyleOptions);
end;

procedure TNxNativeStylePaint.PaintProgressChunk(ProgressRect: TRect);
begin
  TNxProgressStyledView6.PaintChunk(Canvas, Control.Handle, ProgressRect, StyleOptions);
end;

procedure TNxNativeStylePaint.PaintPushButton(ButtonRect: TRect;
  AState: TNxButtonState);
begin
  TNxButtonStyle6.Paint(Canvas, Control.Handle, ButtonRect, AState, StyleOptions);
end;

procedure TNxNativeStylePaint.PaintToolButton(ARect: TRect;
  AState: TNxButtonState);
begin
  TNxToolbarStyle6.Paint(Canvas, Control.Handle, ARect, AState, StyleOptions, False);
end;

procedure TNxNativeStylePaint.PaintTrack(TrackRect: TRect);
begin
  TNxTrackBarStyle6.PaintTrack(Canvas, Control.Handle, TrackRect, StyleOptions);
end;

procedure TNxNativeStylePaint.PaintTrackThumb(ThumbRect: TRect; State: TNxButtonState);
begin
  TNxTrackBarStyle6.PaintThumb(Canvas, Control.Handle, ThumbRect, State, StyleOptions);
end;

end.

