{ ------------------------------------------------------------- }
{ Purpose : NextLayout 6                                        }
{ By      : Bojan Nikolic                                       }
{ For     : BergSoft                                            }
{ ------------------------------------------------------------- }
{ Copyright (C) BergSoft.net 2013. All Rights Reserved.         }
{ ------------------------------------------------------------- }
unit NxLayoutStylePaint6;

interface

uses
  { Standard }
  Classes, Types, Windows, Graphics, Controls, Messages, StdCtrls,
  { Next Standard 6 }
  NxConsts6, NxIntf6, NxClasses6, NxTypes6, NxStylePaint6;

type
  INxLayoutStylePaint = interface(INxStylePaint)
    ['{FF6F6F5F-FAE8-4331-B013-88E076A906C5}']
    procedure DrawHorzSeparator(ARect: TRect);
    procedure DrawToggleButton(ARect: TRect; Expanded: Boolean);
    procedure DrawTopLevel(ARect: TRect);
    function GetButtonTextColor: TColor;
    function GetToggleButtonSize(const LineHeight: Integer): TSize;
  end;

  TNxLayoutStylePaint = class(TNxNativeStylePaint, INxLayoutStylePaint)
  public
    procedure DrawHorzSeparator(Rect: TRect); virtual; abstract;
    procedure DrawToggleButton(ARect: TRect; Expanded: Boolean); virtual; abstract;
    procedure DrawTopLevel(ARect: TRect); virtual; abstract;
    function GetButtonTextColor: TColor;
    function GetToggleButtonSize(const LineHeight: Integer): TSize; virtual; abstract;
  end;

  { TNxNativeLayoutStylePaint }

  TNxNativeLayoutStylePaint = class(TNxLayoutStylePaint)
  public
    procedure DrawHorzSeparator(ARect: TRect); override;
    procedure DrawTopLevel(ARect: TRect); override;
    procedure DrawToggleButton(ARect: TRect; Expanded: Boolean); override;
    function GetToggleButtonSize(const LineHeight: Integer): TSize; override;
  end;

  { TNxModernLayoutStylePaint }

  TNxModernLayoutStylePaint = class(TNxLayoutStylePaint)
  public
    { INxControlStyle }
    procedure PaintCheckBox(ARect: TRect; CheckBoxState: TCheckBoxState;
      AState: TNxButtonState); override;
    procedure PaintDropDownButton(ARect: TRect; AState: TNxButtonState); override;
    procedure DrawHorzSeparator(Rect: TRect); override;
    procedure PaintPushButton(ButtonRect: TRect; State: TNxButtonState); override;
    procedure PaintToolButton(ARect: TRect; AState: TNxButtonState); override;
    { INxFormPaintStyle }
    procedure DrawToggleButton(ARect: TRect; Expanded: Boolean); override;
    procedure DrawTopLevel(ARect: TRect); override;
    function GetToggleButtonSize(const LineHeight: Integer): TSize; override;
  end;

  TNxDarkLayoutStylePaint = class(TNxLayoutStylePaint)
  public
    procedure DrawHorzSeparator(Rect: TRect); override;
    procedure DrawToggleButton(ARect: TRect; Expanded: Boolean); override;
    procedure DrawTopLevel(ARect: TRect); override;
    procedure PaintToolButton(ARect: TRect; AState: TNxButtonState); override;
  end;

implementation

uses
  { Next Standard 6 }
  NxGraphics6, NxStyles6, NxTheme6;

{ TNxLayoutStylePaint }

function TNxLayoutStylePaint.GetButtonTextColor: TColor;
begin
  Result := clBtnText;
end;

{ TNxNativeLayoutStylePaint }

procedure TNxNativeLayoutStylePaint.DrawHorzSeparator(ARect: TRect);
var
  Y: Integer;
begin
  Y := ARect.Top + (ARect.Bottom - ARect.Top) div 2;
  with Canvas do
  begin
    Pen.Color := clBtnHighlight;
    Polyline([
      Point(ARect.Left, Y),
      Point(ARect.Right, Y)
    ]);
    Pen.Color := clBtnShadow;
    Polyline([
      Point(ARect.Left, Y + 1),
      Point(ARect.Right, Y + 1)
    ]);
  end;
end;

procedure TNxNativeLayoutStylePaint.DrawToggleButton(ARect: TRect; Expanded: Boolean);
begin
  TNxTreeStyledView6.PaintToggle(Canvas, Control.Handle, ARect, Expanded, [], StyleOptions);
end;

procedure TNxNativeLayoutStylePaint.DrawTopLevel(ARect: TRect);
begin
  TNxHeaderStyle6.Paint(Canvas, Control.Handle, ARect, [bsHover], StyleOptions);
end;

function TNxNativeLayoutStylePaint.GetToggleButtonSize(const LineHeight: Integer): TSize;
begin
  Result := Size(12, 12);
end;

{ TNxModernLayoutStylePaint }

procedure TNxModernLayoutStylePaint.PaintCheckBox(ARect: TRect;
  CheckBoxState: TCheckBoxState; AState: TNxButtonState);
var
  State: Integer;
  Theme: HTHEME;
begin
  { Create Theme Handle }
  Theme := OpenThemeData(Control.Handle, teButton);

  State := 0;

  case CheckBoxState of
    cbUnchecked:
      begin
        State := tiRadioNormal;
        if bsHover in AState then State := tiRadioHover;
        if bsPressed in AState then State := tiRadioDown;
        if bsDisabled in AState then State := tiRadioDisabled;
      end;
    cbChecked:
      begin
        State := tiRadioChecked;
        if bsHover in AState then State := tiRadioCheckedHover;
        if bsPressed in AState then State := tiRadioCheckedDown;
        if bsDisabled in AState then State := tiRadioCheckedDisabled;
      end;
    cbGrayed:
      begin
        State := tiRadioGrayed;
        if bsHover in AState then State := tiRadioGrayedHover;
        if bsPressed in AState then State := tiRadioGrayedDown;
        if bsDisabled in AState then State := tiRadioGrayedDisabled;
      end;
  end;

  { Draw CheckBox }
  DrawThemeBackground(Theme, Canvas.Handle, tcCheckBox, State, ARect, nil);

  { Destroy Theme }
  CloseThemeData(Theme);
end;

procedure TNxModernLayoutStylePaint.PaintDropDownButton(ARect: TRect;
  AState: TNxButtonState);
begin

end;

procedure TNxModernLayoutStylePaint.PaintPushButton(ButtonRect: TRect; State: TNxButtonState);
begin
  inherited;
end;

procedure TNxModernLayoutStylePaint.DrawHorzSeparator(Rect: TRect);
var
  Y: Integer;
begin
  Y := Rect.Top + (Rect.Bottom - Rect.Top) div 2;
  with Canvas do
  begin
    Pen.Color := ColorOf(seDivider);
    Polyline([
      Point(Rect.Left, Y),
      Point(Rect.Right, Y)
    ]);
  end;
end;

procedure TNxModernLayoutStylePaint.DrawToggleButton(ARect: TRect;
  Expanded: Boolean);
var
  X, Y: Integer;
begin
  with Canvas do
  begin
    X := ARect.Left;
    Y := ARect.Top + (ARect.Bottom - ARect.Top) div 2;

    if Expanded then
    begin

      Y := Y - 3;

      Brush.Color := $00444444;
      Pen.Color := Brush.Color;

      Polygon([
        Point(X, Y + 5),
        Point(X + 5, Y + 5),
        Point(X + 5, Y + 0),
        Point(X, Y + 5)
      ]);
    end else
    begin
      Y := Y - 5;

      Brush.Color := clWhite;
      Pen.Color := $00888683;

      Polygon([
        Point(X, Y),
        Point(X + 4, Y + 4),
        Point(X, Y + 8),
        Point(X, Y)
      ]);
    end;
  end;
end;

procedure TNxModernLayoutStylePaint.PaintToolButton(ARect: TRect;
  AState: TNxButtonState);
begin
  with Canvas do
  begin
    if AState <> [] then
    begin
      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;

procedure TNxModernLayoutStylePaint.DrawTopLevel(ARect: TRect);
begin
  with Canvas do
  begin
    Brush.Color := ColorOf(seBtnFace);
    FillRect(ARect);
  end;
end;

function TNxModernLayoutStylePaint.GetToggleButtonSize(const LineHeight: Integer): TSize;
var
  h, w: Integer;
begin
  h := Round(LineHeight * 0.2);
  w := Round(h) * 2 - 1;
  Result := Size(w, h);
end;

{ TNxDarkLayoutStylePaint }

procedure TNxDarkLayoutStylePaint.DrawHorzSeparator(Rect: TRect);
var
  Location: TPoint;
  SeparatorRect: TRect;
begin

  Location := PosInRect(0, 2, Rect, taLeftJustify, taVerticalCenter);
  SeparatorRect := Types.Rect(Location.X, Location.Y, Rect.Right, Location.Y + 2);

  with Canvas, SeparatorRect do
  begin
    Pen.Color := $00303030;
    Polyline([
      Point(Left, Top),
      Point(Right, Top)
    ]);

    Pen.Color := $00484848;
    Polyline([
      Point(Left, Top + 1),
      Point(Right, Top + 1)
    ]);
  end;

end;

procedure TNxDarkLayoutStylePaint.DrawToggleButton(ARect: TRect;
  Expanded: Boolean);
begin
  with Canvas, ARect do
  begin
    Brush.Color := clWhite;
    Pen.Color := clWhite;
    if Expanded then
      Polygon([
        Point(Left, Top),
        Point(Right - 1, Top),
        Point(Left + (Right - Left) div 2, Bottom - 1),
        Point(Left, Top)
      ])
    else
      Polygon([
        Point(Left, Top),
        Point(Right - 1, Top + (Bottom - Top) div 2),
        Point(Left, Bottom - 1),
        Point(Left, Top)
      ])
  end;
end;

procedure TNxDarkLayoutStylePaint.PaintToolButton(ARect: TRect;
  AState: TNxButtonState);
begin

  with Canvas do
  begin
    Brush.Color := $00595959;
    FillRect(ARect);
//    Frame3D(Canvas, ButtonRect, $00757575, $00232323, 1);
  end;

end;

procedure TNxDarkLayoutStylePaint.DrawTopLevel(ARect: TRect);
begin
//      Font.Color := clWhite;

//        Brush.Color := $003d3d3d;
//        FillRect(ClientRect);
//
//        Pen.Color := $00303030;
//        Polyline([
//          Point(ClientRect.Left, ClientRect.Top),
//          Point(ClientRect.Right, ClientRect.Top)
//        ]);
//        Polyline([
//          Point(ClientRect.Left, ClientRect.Bottom - 1),
//          Point(ClientRect.Right, ClientRect.Bottom - 1)
//        ]);
//
//        Pen.Color := $00484848;
//        Polyline([
//          Point(ClientRect.Left, ClientRect.Top + 1),
//          Point(ClientRect.Right, ClientRect.Top + 1)
//        ]);

end;

end.
