File: customdrawn_extra1.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (224 lines) | stat: -rw-r--r-- 7,305 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
unit customdrawn_extra1;

{$mode objfpc}{$H+}

interface

uses
  // RTL
  Classes, SysUtils, Types,
  // LCL -> Use only TForm, TWinControl, TCanvas and TLazIntfImage
  Graphics, Controls, LCLType,
  //
  customdrawndrawers, customdrawn_common;

type

  { TCDDrawerExtra1 }

  TCDDrawerExtra1 = class(TCDDrawerCommon)
  public
    function GetMeasures(AMeasureID: Integer): Integer; override;
    // ===================================
    // Common Controls Tab
    // ===================================
    procedure DrawTrackBar(ADest: TCanvas; ASize: TSize;
      AState: TCDControlState; AStateEx: TCDPositionedCStateEx); override;
  end;
{  TCDButtonDrawerGrad = class(TCDButtonDrawer)
  public
    procedure DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); override;
    procedure DrawToCanvas(ADest: TCanvas; CDButton: TCDButton); override;
  end;

  TCDTrackBarDrawerGraph = class(TCDTrackBarDrawer)
  public
    procedure DrawToIntfImage(ADest: TFPImageCanvas; FPImg: TLazIntfImage;
      CDTrackBar: TCDTrackBar); override;
    procedure GetGeometry(var ALeftBorder, ARightBorder: Integer); override;
  end;}

implementation

{procedure TCDButtonDrawerGrad.DrawToIntfImage(ADest: TFPImageCanvas;
  CDButton: TCDButton);
begin

end;

procedure TCDButtonDrawerGrad.DrawToCanvas(ADest: TCanvas; CDButton: TCDButton);
var
  TmpB: TBitmap;
  Str: string;
begin
  // Button shape -> This crashes in Gtk2
  TmpB := TBitmap.Create;
  TmpB.Width := CDButton.Width;
  TmpB.Height := CDButton.Height;
  TmpB.Canvas.Brush.Color := CDButton.Color;
  TmpB.Canvas.Brush.Style := bsSolid;
  TmpB.Canvas.RoundRect(0, 0, TmpB.Width, TmpB.Height, 8, 8);
  //  CDButton.SetShape(TmpB);

  with TmpB.Canvas do
  begin
    Brush.Style := bsSolid;
    Brush.Color := CDButton.Parent.Color;
    Pen.Color := Brush.Color;
    Rectangle(0, 0, Width, Height);
    FillRect(0, 0, Width, Height);
    Brush.Color := GetAColor(CDButton.Color, 90);
  end;

  // Button image
  if CDButton.IsDown then
    DrawCDButtonDown(TmpB.Canvas, CDButton.GetRGBBackgroundColor)
  else if CDButton.Focused then
    //GradientFill(GetUColor(CDButton.Color, 50), GetAColor(CDButton.Color, 60), TmpB.Canvas);
    GradientFill(clWhite, GetAColor(CDButton.Color, 96), TmpB.Canvas)
  else
    //GradientFill(GetUColor(CDButton.Color, 10), GetAColor(CDButton.Color, 20), TmpB.Canvas);
    GradientFill(clWhite, CDButton.Color, TmpB.Canvas);

  ADest.Draw(0, 0, TmpB);

  TmpB.Free;

  // Button text
  ADest.Font.Assign(CDButton.Font);
  ADest.Brush.Style := bsClear;
  ADest.Pen.Style := psSolid;
  Str := CDButton.Caption;
  ADest.TextOut((CDButton.Width - ADest.TextWidth(Str)) div 2,
    (CDButton.Height - ADest.TextHeight(Str)) div 2, Str);
end;

{ TCDTrackBarDrawer }

procedure TCDTrackBarDrawerGraph.DrawToIntfImage(ADest: TFPImageCanvas;
  FPImg: TLazIntfImage; CDTrackBar: TCDTrackBar);

procedure TCDTrackBarDrawerGraph.GetGeometry(var ALeftBorder,
  ARightBorder: Integer);
begin
  ALeftBorder := 9;
  ARightBorder := 9;
end;

  RegisterTrackBarDrawer(TCDTrackBarDrawerGraph.Create, dsExtra1);}

{ TCDDrawerExtra1 }

function TCDDrawerExtra1.GetMeasures(AMeasureID: Integer): Integer;
begin
  case AMeasureId of
  TCDTRACKBAR_LEFT_SPACING:  Result := 9;
  TCDTRACKBAR_RIGHT_SPACING: Result := 9;
  else
    Result:=inherited GetMeasures(AMeasureID);
  end;
end;

procedure TCDDrawerExtra1.DrawTrackBar(ADest: TCanvas;
  ASize: TSize; AState: TCDControlState; AStateEx: TCDPositionedCStateEx);
var
  lDrawingBottom, StepsCount, i: Integer;
  pStart, pEnd: integer; // for drawing the decorative bars
  dRect: TRect;
  pStepWidth, pHalfStepWidth: Integer;
  CDBarEdge: Integer;
begin
  CDBarEdge := GetMeasures(TCDTRACKBAR_LEFT_SPACING)
    + GetMeasures(TCDTRACKBAR_RIGHT_SPACING);

  // Preparations
  StepsCount := AStateEx.PosCount;
  pStepWidth := (ASize.cx - CDBarEdge) div StepsCount;
  pHalfStepWidth := (ASize.cx - CDBarEdge) div (StepsCount * 2);

  // The bottom part of the drawing
  lDrawingBottom := ASize.cy - 10;

  // Background

  ADest.Brush.Color := AStateEx.ParentRGBColor;
  ADest.Brush.Style := bsSolid;
  ADest.Pen.Style := psSolid;
  ADest.Pen.Color := AStateEx.ParentRGBColor;
  ADest.Rectangle(0, 0, ASize.cx, ASize.cy);

  // Draws the double-sided arrow in the center of the slider

  ADest.Brush.Color := ColorToRGB($006BB6E6);
  ADest.Pen.Style := psSolid;
  ADest.Pen.Color := ColorToRGB($006BB6E6);
  ADest.Line(0, lDrawingBottom, ASize.cx, lDrawingBottom);
  ADest.Line(3, lDrawingBottom - 1, 6, lDrawingBottom - 1);
  ADest.Line(5, lDrawingBottom - 2, 6, lDrawingBottom - 2);
  ADest.Line(3, lDrawingBottom + 1, 6, lDrawingBottom + 1);
  ADest.Line(5, lDrawingBottom + 2, 6, lDrawingBottom + 2);
  ADest.Line(ASize.cx - 1 - 3, lDrawingBottom - 1, ASize.cx - 1 - 6, lDrawingBottom - 1);
  ADest.Line(ASize.cx - 1 - 5, lDrawingBottom - 2, ASize.cx - 1 - 6, lDrawingBottom - 2);
  ADest.Line(ASize.cx - 1 - 3, lDrawingBottom + 1, ASize.cx - 1 - 6, lDrawingBottom + 1);
  ADest.Line(ASize.cx - 1 - 5, lDrawingBottom + 2, ASize.cx - 1 - 6, lDrawingBottom + 2);
  ADest.Pen.Color := ColorToRGB(clGray);
  ADest.Brush.Color := ColorToRGB($00F0F0F0);

  // Draws the decorative bars and also the slider button

  pStart := 10 - 1;
  for i := 0 to StepsCount - 1 do
  begin
    // Draw the decorative bars
    dRect := Bounds(
      pStart + pHalfStepWidth,
      lDrawingBottom - 5 - i,
      Round(pStepWidth)-3,
      4 + i);

    ADest.Brush.Style := bsSolid;
    ADest.Pen.Style := psSolid;
    ADest.Pen.Color := clBlack;
    if i <= AStateEx.Position then
      ADest.Brush.Color := clDkGray
    else
      ADest.Brush.Color := clWhite;

    ADest.Rectangle(dRect);

    // Draw the slider

    if i = AStateEx.Position then
    begin
      ADest.Brush.FPColor := TColorToFPColor(ColorToRGB($006BB6E6));
      ADest.Brush.Style := bsSolid;
      ADest.Rectangle(pStart, lDrawingBottom + 1, pStart + 10, lDrawingBottom + 6);
      ADest.Pen.Color := ColorToRGB($005BA6C6);
      ADest.RecTangle(pStart, lDrawingBottom + 2, pStart + 10, lDrawingBottom + 7);
      ADest.Pen.Color := ColorToRGB($006BB6E6);
      ADest.RecTangle(pStart, lDrawingBottom, pStart + 10, lDrawingBottom + 2);
    end;
    pStart := pStart + pStepWidth;
  end;

  ADest.Pen.Color := ColorToRGB($007BC6F6);
  ADest.Line(7, lDrawingBottom - 1, ASize.cx - 8, lDrawingBottom - 1);
  ADest.Line(7, lDrawingBottom + 1, ASize.cx - 8, lDrawingBottom + 1);
  ADest.Pixels[2, lDrawingBottom - 1] := ADest.Pen.Color;
  ADest.Pixels[4, lDrawingBottom - 2] := ADest.Pen.Color;
  ADest.Pixels[2, lDrawingBottom + 1] := ADest.Pen.Color;
  ADest.Pixels[4, lDrawingBottom + 2] := ADest.Pen.Color;
  ADest.Pixels[6, lDrawingBottom - 3] := ADest.Pen.Color;
  ADest.Pixels[6, lDrawingBottom + 3] := ADest.Pen.Color;
  ADest.Pixels[ASize.cx - 1 - 2, lDrawingBottom - 1] := ADest.Pen.Color;
  ADest.Pixels[ASize.cx - 1 - 4, lDrawingBottom - 2] := ADest.Pen.Color;
  ADest.Pixels[ASize.cx - 1 - 2, lDrawingBottom + 1] := ADest.Pen.Color;
  ADest.Pixels[ASize.cx - 1 - 4, lDrawingBottom + 2] := ADest.Pen.Color;
  ADest.Pixels[ASize.cx - 1 - 6, lDrawingBottom - 3] := ADest.Pen.Color;
  ADest.Pixels[ASize.cx - 1 - 6, lDrawingBottom + 3] := ADest.Pen.Color;
end;

initialization
  RegisterDrawer(TCDDrawerExtra1.Create, dsExtra1);
end.