| 1 | {
|
|---|
| 2 | BGRANeoButton 2011 - 2012 by Lainz
|
|---|
| 3 |
|
|---|
| 4 | This is a control that can be modified to create your own graphic button.
|
|---|
| 5 | By default it has very limited functionality, but you can extend the code to
|
|---|
| 6 | get the result you want.
|
|---|
| 7 |
|
|---|
| 8 | * TGraphicButton *
|
|---|
| 9 | TGraphicControl descendant. It handles mouse events and
|
|---|
| 10 | ModalResult. It uses TGraphicButtonState to indicate the current button stage.
|
|---|
| 11 |
|
|---|
| 12 | * TBGRANeoTextStyle *
|
|---|
| 13 | BGRABitmap font style and alpha.
|
|---|
| 14 |
|
|---|
| 15 | * TBGRANeoShadowStyle *
|
|---|
| 16 | Usefull to general shadow purposes.
|
|---|
| 17 |
|
|---|
| 18 | * TBGRANeoGradientStyle *
|
|---|
| 19 | Gradient with alpha.
|
|---|
| 20 |
|
|---|
| 21 | * TBGRANeoBorderStyle *
|
|---|
| 22 | Round rectangle options, inner and outer border.
|
|---|
| 23 | It uses TBGRANeoRoundRectangleOption.
|
|---|
| 24 |
|
|---|
| 25 | * TBGRANeoButtonStyle *
|
|---|
| 26 | A combination of TBGRANeoTextStyle, TBGRANeoShadowStyle, TBGRANeoGradientStyle
|
|---|
| 27 | and TBGRANeoBorderStyle. Is the style of each TBGRANeoButton states.
|
|---|
| 28 |
|
|---|
| 29 | * TCustomBGRANeoButton *
|
|---|
| 30 | A button that can be overriden. TSampleBGRANeoButton show how
|
|---|
| 31 | to do that. With 4 states, each of them read the style properties
|
|---|
| 32 | from TBGRANeoButtonStyle.
|
|---|
| 33 |
|
|---|
| 34 | * TBGRANeoButton *
|
|---|
| 35 | TSampleBGRANeoButton descendant. It show how to publish all the properties that
|
|---|
| 36 | are visible in the object inspector.
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | unit BGRANeoButton;
|
|---|
| 40 |
|
|---|
| 41 | {$mode objfpc}{$H+}
|
|---|
| 42 | {off $DEFINE DEBUG}
|
|---|
| 43 |
|
|---|
| 44 | interface
|
|---|
| 45 |
|
|---|
| 46 | uses
|
|---|
| 47 | Classes, LResources, Forms, Controls, Graphics, Dialogs, types,
|
|---|
| 48 | BGRABitmap, BGRABitmapTypes, BGRAPolygon, BGRAGradients;
|
|---|
| 49 |
|
|---|
| 50 | type
|
|---|
| 51 | TGraphicButtonState = (gbsNormal, gbsHover, gbsActive);
|
|---|
| 52 | TBGRANeoRoundRectangleOption = (rroRound, rroBevel, rroSquare);
|
|---|
| 53 |
|
|---|
| 54 | type
|
|---|
| 55 |
|
|---|
| 56 | { TGraphicButton }
|
|---|
| 57 |
|
|---|
| 58 | TGraphicButton = class(TGraphicControl)
|
|---|
| 59 | protected
|
|---|
| 60 | FState: TGraphicButtonState;
|
|---|
| 61 | FModalResult: TModalResult;
|
|---|
| 62 | protected
|
|---|
| 63 | procedure DoClick; virtual;
|
|---|
| 64 | procedure DoMouseDown; virtual;
|
|---|
| 65 | procedure DoMouseUp; virtual;
|
|---|
| 66 | procedure DoMouseEnter; virtual;
|
|---|
| 67 | procedure DoMouseLeave; virtual;
|
|---|
| 68 | protected
|
|---|
| 69 | procedure Click; override;
|
|---|
| 70 | procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
|
|---|
| 71 | X, Y: integer); override;
|
|---|
| 72 | procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
|
|---|
| 73 | procedure MouseEnter; override;
|
|---|
| 74 | procedure MouseLeave; override;
|
|---|
| 75 | public
|
|---|
| 76 | property ModalResult: TModalResult
|
|---|
| 77 | read FModalResult write FModalResult default mrNone;
|
|---|
| 78 | end;
|
|---|
| 79 |
|
|---|
| 80 | { TBGRANeoShadowStyle }
|
|---|
| 81 |
|
|---|
| 82 | TBGRANeoShadowStyle = class(TPersistent)
|
|---|
| 83 | protected
|
|---|
| 84 | FOwner: TControl;
|
|---|
| 85 | FColor: TColor;
|
|---|
| 86 | FAlpha: byte;
|
|---|
| 87 | FOffsetX: integer;
|
|---|
| 88 | FOffsetY: integer;
|
|---|
| 89 | FRadius: integer;
|
|---|
| 90 | protected
|
|---|
| 91 | procedure SetFAlpha(AValue: byte); virtual;
|
|---|
| 92 | procedure SetFColor(AValue: TColor); virtual;
|
|---|
| 93 | procedure SetFOffsetX(AValue: integer); virtual;
|
|---|
| 94 | procedure SetFOffsetY(AValue: integer); virtual;
|
|---|
| 95 | procedure SetFRadius(AValue: integer); virtual;
|
|---|
| 96 | public
|
|---|
| 97 | constructor Create(AOwner: TControl);
|
|---|
| 98 | destructor Destroy; override;
|
|---|
| 99 | procedure Assign(Source: TPersistent); override;
|
|---|
| 100 | published
|
|---|
| 101 | property Color: TColor read FColor write SetFColor default clWhite;
|
|---|
| 102 | property Alpha: byte read FAlpha write SetFAlpha default 255;
|
|---|
| 103 | property OffsetX: integer read FOffsetX write SetFOffsetX default 0;
|
|---|
| 104 | property OffsetY: integer read FOffsetY write SetFOffsetY default 0;
|
|---|
| 105 | property Radius: integer read FRadius write SetFRadius default 0;
|
|---|
| 106 | end;
|
|---|
| 107 |
|
|---|
| 108 | { TBGRANeoTextStyle }
|
|---|
| 109 |
|
|---|
| 110 | TBGRANeoTextStyle = class(TPersistent)
|
|---|
| 111 | protected
|
|---|
| 112 | FOwner: TControl;
|
|---|
| 113 | FFont: TFont;
|
|---|
| 114 | FAlpha: byte;
|
|---|
| 115 | FQuality: TBGRAFontQuality;
|
|---|
| 116 | protected
|
|---|
| 117 | procedure SetFAlpha(AValue: byte); virtual;
|
|---|
| 118 | procedure SetFFont(AValue: TFont); virtual;
|
|---|
| 119 | procedure SetFQuality(AValue: TBGRAFontQuality); virtual;
|
|---|
| 120 | public
|
|---|
| 121 | constructor Create(AOwner: TControl);
|
|---|
| 122 | destructor Destroy; override;
|
|---|
| 123 | procedure Assign(Source: TPersistent); override;
|
|---|
| 124 | published
|
|---|
| 125 | property Font: TFont read FFont write SetFFont;
|
|---|
| 126 | property Alpha: byte read FAlpha write SetFAlpha default 255;
|
|---|
| 127 | property Quality: TBGRAFontQuality read FQuality write SetFQuality default
|
|---|
| 128 | fqSystemClearType;
|
|---|
| 129 | end;
|
|---|
| 130 |
|
|---|
| 131 | { TBGRANeoGradientStyle }
|
|---|
| 132 |
|
|---|
| 133 | TBGRANeoGradientStyle = class(TPersistent)
|
|---|
| 134 | protected
|
|---|
| 135 | FOwner: TControl;
|
|---|
| 136 | FColor1: TColor;
|
|---|
| 137 | FColor1Alpha: byte;
|
|---|
| 138 | FColor2: TColor;
|
|---|
| 139 | FColor2Alpha: byte;
|
|---|
| 140 | FStyle: TGradientType;
|
|---|
| 141 | FSinus: boolean;
|
|---|
| 142 | protected
|
|---|
| 143 | procedure SetFColor1(AValue: TColor); virtual;
|
|---|
| 144 | procedure SetFColor1Alpha(AValue: byte); virtual;
|
|---|
| 145 | procedure SetFColor2(AValue: TColor); virtual;
|
|---|
| 146 | procedure SetFColor2Alpha(AValue: byte); virtual;
|
|---|
| 147 | procedure SetFSinus(AValue: boolean); virtual;
|
|---|
| 148 | procedure SetFStyle(AValue: TGradientType); virtual;
|
|---|
| 149 | public
|
|---|
| 150 | constructor Create(AOwner: TControl);
|
|---|
| 151 | destructor Destroy; override;
|
|---|
| 152 | procedure Assign(Source: TPersistent); override;
|
|---|
| 153 | published
|
|---|
| 154 | property Color1: TColor read FColor1 write SetFColor1 default clWhite;
|
|---|
| 155 | property Color1Alpha: byte read FColor1Alpha write SetFColor1Alpha default 255;
|
|---|
| 156 | property Color2: TColor read FColor2 write SetFColor2 default clWhite;
|
|---|
| 157 | property Color2Alpha: byte read FColor1Alpha write SetFColor2Alpha default 255;
|
|---|
| 158 | property Style: TGradientType read FStyle write SetFStyle default gtLinear;
|
|---|
| 159 | property Sinus: boolean read FSinus write SetFSinus default False;
|
|---|
| 160 | end;
|
|---|
| 161 |
|
|---|
| 162 | { TBGRANeoBorderStyle }
|
|---|
| 163 |
|
|---|
| 164 | TBGRANeoBorderStyle = class(TPersistent)
|
|---|
| 165 | protected
|
|---|
| 166 | FOwner: TControl;
|
|---|
| 167 | FInnerColor: TColor;
|
|---|
| 168 | FInnerAlpha: byte;
|
|---|
| 169 | FInnerWidth: single;
|
|---|
| 170 | FOuterColor: TColor;
|
|---|
| 171 | FOuterAlpha: byte;
|
|---|
| 172 | FOuterWidth: single;
|
|---|
| 173 | FRoundX: single;
|
|---|
| 174 | FRoundY: single;
|
|---|
| 175 | FTopLeft, FTopRight, FBottomLeft, FBottomRight: TBGRANeoRoundRectangleOption;
|
|---|
| 176 | protected
|
|---|
| 177 | procedure SetFBottomLeft(AValue: TBGRANeoRoundRectangleOption); virtual;
|
|---|
| 178 | procedure SetFBottomRight(AValue: TBGRANeoRoundRectangleOption); virtual;
|
|---|
| 179 | procedure SetFInnerAlpha(AValue: byte); virtual;
|
|---|
| 180 | procedure SetFInnerColor(AValue: TColor); virtual;
|
|---|
| 181 | procedure SetFInnerWidth(AValue: single); virtual;
|
|---|
| 182 | procedure SetFOuterAlpha(AValue: byte); virtual;
|
|---|
| 183 | procedure SetFOuterColor(AValue: TColor); virtual;
|
|---|
| 184 | procedure SetFOuterWidth(AValue: single); virtual;
|
|---|
| 185 | procedure SetFRoundX(AValue: single); virtual;
|
|---|
| 186 | procedure SetFRoundY(AValue: single); virtual;
|
|---|
| 187 | procedure SetFTopLeft(AValue: TBGRANeoRoundRectangleOption); virtual;
|
|---|
| 188 | procedure SetFTopRight(AValue: TBGRANeoRoundRectangleOption); virtual;
|
|---|
| 189 | public
|
|---|
| 190 | constructor Create(AOwner: TControl);
|
|---|
| 191 | destructor Destroy; override;
|
|---|
| 192 | procedure Assign(Source: TPersistent); override;
|
|---|
| 193 | function Options: TRoundRectangleOptions;
|
|---|
| 194 | published
|
|---|
| 195 | property InnerColor: TColor read FInnerColor write SetFInnerColor default clWhite;
|
|---|
| 196 | property InnerColorAlpha: byte read FInnerAlpha write SetFInnerAlpha default 255;
|
|---|
| 197 | property InnerWidth: single read FInnerWidth write SetFInnerWidth default 0;
|
|---|
| 198 | property OuterColor: TColor read FOuterColor write SetFOuterColor default clWhite;
|
|---|
| 199 | property OuterColorAlpha: byte read FOuterAlpha write SetFOuterAlpha default 255;
|
|---|
| 200 | property OuterWidth: single read FOuterWidth write SetFOuterWidth default 0;
|
|---|
| 201 | property RoundX: single read FRoundX write SetFRoundX default 0;
|
|---|
| 202 | property RoundY: single read FRoundY write SetFRoundY default 0;
|
|---|
| 203 | property TopLeft: TBGRANeoRoundRectangleOption
|
|---|
| 204 | read FTopLeft write SetFTopLeft default rroRound;
|
|---|
| 205 | property TopRight: TBGRANeoRoundRectangleOption
|
|---|
| 206 | read FTopRight write SetFTopRight default rroRound;
|
|---|
| 207 | property BottomLeft: TBGRANeoRoundRectangleOption
|
|---|
| 208 | read FBottomLeft write SetFBottomLeft default rroRound;
|
|---|
| 209 | property BottomRight: TBGRANeoRoundRectangleOption
|
|---|
| 210 | read FBottomRight write SetFBottomRight default rroRound;
|
|---|
| 211 | end;
|
|---|
| 212 |
|
|---|
| 213 | { TBGRANeoButtonStyle }
|
|---|
| 214 |
|
|---|
| 215 | TBGRANeoButtonStyle = class(TPersistent)
|
|---|
| 216 | protected
|
|---|
| 217 | FOwner: TControl;
|
|---|
| 218 | FText: TBGRANeoTextStyle;
|
|---|
| 219 | FShadow: TBGRANeoShadowStyle;
|
|---|
| 220 | FGradient1: TBGRANeoGradientStyle;
|
|---|
| 221 | FGradient2: TBGRANeoGradientStyle;
|
|---|
| 222 | FGradientPosition: single;
|
|---|
| 223 | FBorder: TBGRANeoBorderStyle;
|
|---|
| 224 | protected
|
|---|
| 225 | procedure SetFBorder(AValue: TBGRANeoBorderStyle); virtual;
|
|---|
| 226 | procedure SetFGradient1(AValue: TBGRANeoGradientStyle); virtual;
|
|---|
| 227 | procedure SetFGradient2(AValue: TBGRANeoGradientStyle); virtual;
|
|---|
| 228 | procedure SetFGradientPosition(AValue: single); virtual;
|
|---|
| 229 | procedure SetFShadow(AValue: TBGRANeoShadowStyle); virtual;
|
|---|
| 230 | procedure SetFText(AValue: TBGRANeoTextStyle); virtual;
|
|---|
| 231 | public
|
|---|
| 232 | constructor Create(AOwner: TControl);
|
|---|
| 233 | destructor Destroy; override;
|
|---|
| 234 | procedure Assign(Source: TPersistent); override;
|
|---|
| 235 | published
|
|---|
| 236 | property Text: TBGRANeoTextStyle read FText write SetFText;
|
|---|
| 237 | property Shadow: TBGRANeoShadowStyle read FShadow write SetFShadow;
|
|---|
| 238 | property Gradient1: TBGRANeoGradientStyle read FGradient1 write SetFGradient1;
|
|---|
| 239 | property Gradient2: TBGRANeoGradientStyle read FGradient2 write SetFGradient2;
|
|---|
| 240 | property GradientPosition: single read FGradientPosition write SetFGradientPosition;
|
|---|
| 241 | property Border: TBGRANeoBorderStyle read FBorder write SetFBorder;
|
|---|
| 242 | end;
|
|---|
| 243 |
|
|---|
| 244 | { TCustomBGRANeoButton }
|
|---|
| 245 |
|
|---|
| 246 | TCustomBGRANeoButton = class(TGraphicButton)
|
|---|
| 247 | protected
|
|---|
| 248 | FBGRA: TBGRABitmap;
|
|---|
| 249 | FStyleNormal, FStyleHover, FStyleActive, FStyleDisabled: TBGRANeoButtonStyle;
|
|---|
| 250 | {$IFDEF DEBUG}
|
|---|
| 251 | FPaintCount: integer;
|
|---|
| 252 | {$ENDIF}
|
|---|
| 253 | protected
|
|---|
| 254 | procedure SetFStyleActive(AValue: TBGRANeoButtonStyle); virtual;
|
|---|
| 255 | procedure SetFStyleDisabled(AValue: TBGRANeoButtonStyle); virtual;
|
|---|
| 256 | procedure SetFStyleHover(AValue: TBGRANeoButtonStyle); virtual;
|
|---|
| 257 | procedure SetFStyleNormal(AValue: TBGRANeoButtonStyle); virtual;
|
|---|
| 258 | protected
|
|---|
| 259 | procedure DrawButton; virtual;
|
|---|
| 260 | procedure DrawBody(AStyle: TBGRANeoButtonStyle); virtual;
|
|---|
| 261 | procedure DrawText(AStyle: TBGRANeoButtonStyle); virtual;
|
|---|
| 262 | protected
|
|---|
| 263 | procedure Paint; override;
|
|---|
| 264 | public
|
|---|
| 265 | constructor Create(AOwner: TComponent); override;
|
|---|
| 266 | destructor Destroy; override;
|
|---|
| 267 | procedure Assign(Source: TPersistent); override;
|
|---|
| 268 | published
|
|---|
| 269 | property StyleNormal: TBGRANeoButtonStyle read FStyleNormal write SetFStyleNormal;
|
|---|
| 270 | property StyleHover: TBGRANeoButtonStyle read FStyleHover write SetFStyleHover;
|
|---|
| 271 | property StyleActive: TBGRANeoButtonStyle read FStyleActive write SetFStyleActive;
|
|---|
| 272 | property StyleDisabled: TBGRANeoButtonStyle
|
|---|
| 273 | read FStyleDisabled write SetFStyleDisabled;
|
|---|
| 274 | end;
|
|---|
| 275 |
|
|---|
| 276 | { TSampleBGRANeoButton }
|
|---|
| 277 |
|
|---|
| 278 | TSampleBGRANeoButton = class(TCustomBGRANeoButton)
|
|---|
| 279 | protected
|
|---|
| 280 | procedure DrawBody(AStyle: TBGRANeoButtonStyle); override;
|
|---|
| 281 | procedure DrawText(AStyle: TBGRANeoButtonStyle); override;
|
|---|
| 282 | end;
|
|---|
| 283 |
|
|---|
| 284 | { TBGRANeoButton }
|
|---|
| 285 |
|
|---|
| 286 | TBGRANeoButton = class(TSampleBGRANeoButton)
|
|---|
| 287 | published
|
|---|
| 288 | property StyleNormal;
|
|---|
| 289 | property StyleHover;
|
|---|
| 290 | property StyleActive;
|
|---|
| 291 | property StyleDisabled;
|
|---|
| 292 | published
|
|---|
| 293 | property Action;
|
|---|
| 294 | property Align;
|
|---|
| 295 | property Anchors;
|
|---|
| 296 | property AutoSize;
|
|---|
| 297 | property BidiMode;
|
|---|
| 298 | property BorderSpacing;
|
|---|
| 299 | property Caption;
|
|---|
| 300 | property Color;
|
|---|
| 301 | property Constraints;
|
|---|
| 302 | property DragCursor;
|
|---|
| 303 | property DragKind;
|
|---|
| 304 | property DragMode;
|
|---|
| 305 | property Enabled;
|
|---|
| 306 | property Font;
|
|---|
| 307 | property ModalResult;
|
|---|
| 308 | property OnChangeBounds;
|
|---|
| 309 | property OnClick;
|
|---|
| 310 | property OnContextPopup;
|
|---|
| 311 | property OnDragDrop;
|
|---|
| 312 | property OnDragOver;
|
|---|
| 313 | property OnEndDrag;
|
|---|
| 314 | property OnMouseDown;
|
|---|
| 315 | property OnMouseEnter;
|
|---|
| 316 | property OnMouseLeave;
|
|---|
| 317 | property OnMouseMove;
|
|---|
| 318 | property OnMouseUp;
|
|---|
| 319 | property OnResize;
|
|---|
| 320 | property OnStartDrag;
|
|---|
| 321 | property ParentBidiMode;
|
|---|
| 322 | property ParentFont;
|
|---|
| 323 | property ParentShowHint;
|
|---|
| 324 | property PopupMenu;
|
|---|
| 325 | property ShowHint;
|
|---|
| 326 | property Visible;
|
|---|
| 327 | end;
|
|---|
| 328 |
|
|---|
| 329 | procedure Register;
|
|---|
| 330 |
|
|---|
| 331 | implementation
|
|---|
| 332 |
|
|---|
| 333 | uses sysutils;
|
|---|
| 334 |
|
|---|
| 335 | procedure Register;
|
|---|
| 336 | begin
|
|---|
| 337 | RegisterComponents('BGRA Controls', [TBGRANeoButton]);
|
|---|
| 338 | end;
|
|---|
| 339 |
|
|---|
| 340 | { TSampleBGRANeoButton }
|
|---|
| 341 |
|
|---|
| 342 | procedure TSampleBGRANeoButton.DrawBody(AStyle: TBGRANeoButtonStyle);
|
|---|
| 343 |
|
|---|
| 344 | procedure DrawBodyStyle(bitmap: TBGRABitmap;
|
|---|
| 345 | cl1, cl2, cl3, cl4, border, light: TBGRAPixel; rx, ry, w, Value: single;
|
|---|
| 346 | dir1, dir2, dir3: TGradientDirection; options: TRoundRectangleOptions = [];
|
|---|
| 347 | drawlight: boolean = True);
|
|---|
| 348 | var
|
|---|
| 349 | texture: TBGRABitmap;
|
|---|
| 350 | w2, b2: single;
|
|---|
| 351 | begin
|
|---|
| 352 | texture := DoubleGradientAlphaFill(Rect(0, 0, bitmap.Width, bitmap.Height),
|
|---|
| 353 | cl1, cl2, cl3, cl4, dir1, dir2, dir3, Value);
|
|---|
| 354 |
|
|---|
| 355 | b2 := 1;
|
|---|
| 356 | w2 := w * 2 - 1;
|
|---|
| 357 |
|
|---|
| 358 | FillRoundRectangleAntialiasWithTexture(bitmap, Trunc(w / 2),
|
|---|
| 359 | Trunc(w / 2), bitmap.Width - b2 - Trunc(w / 2),
|
|---|
| 360 | bitmap.Height - b2 - Trunc(w / 2), rx, ry, options, texture);
|
|---|
| 361 | texture.Free;
|
|---|
| 362 |
|
|---|
| 363 | if drawlight then
|
|---|
| 364 | BorderRoundRectangleAntialias(bitmap, w, w,
|
|---|
| 365 | bitmap.Width - b2 - w,
|
|---|
| 366 | bitmap.Height - b2 - w, rx, ry, w2, options, light, False);
|
|---|
| 367 |
|
|---|
| 368 | BorderRoundRectangleAntialias(bitmap, Trunc(w / 2), Trunc(w / 2),
|
|---|
| 369 | bitmap.Width - b2 - Trunc(w / 2),
|
|---|
| 370 | bitmap.Height - b2 - Trunc(w / 2), rx, ry, w, options, border, False);
|
|---|
| 371 | end;
|
|---|
| 372 |
|
|---|
| 373 | begin
|
|---|
| 374 | FBGRA.Fill(BGRAPixelTransparent);
|
|---|
| 375 | DrawBodyStyle(FBGRA,
|
|---|
| 376 | ColorToBGRA(AStyle.Gradient1.Color1, AStyle.Gradient1.Color1Alpha),
|
|---|
| 377 | ColorToBGRA(AStyle.Gradient1.Color2, AStyle.Gradient1.Color2Alpha),
|
|---|
| 378 | ColorToBGRA(AStyle.Gradient2.Color1, AStyle.Gradient2.Color1Alpha),
|
|---|
| 379 | ColorToBGRA(AStyle.Gradient2.Color2, AStyle.Gradient2.Color2Alpha),
|
|---|
| 380 | ColorToBGRA(AStyle.Border.OuterColor, AStyle.Border.OuterColorAlpha),
|
|---|
| 381 | ColorToBGRA(AStyle.Border.InnerColor, AStyle.Border.InnerColorAlpha),
|
|---|
| 382 | AStyle.Border.RoundX, AStyle.Border.RoundY, AStyle.Border.OuterWidth,
|
|---|
| 383 | AStyle.GradientPosition,
|
|---|
| 384 | gdVertical, gdVertical, gdVertical, AStyle.Border.Options);
|
|---|
| 385 | end;
|
|---|
| 386 |
|
|---|
| 387 | procedure TSampleBGRANeoButton.DrawText(AStyle: TBGRANeoButtonStyle);
|
|---|
| 388 | var
|
|---|
| 389 | bmpSdw: TBGRABitmap;
|
|---|
| 390 | OutTxtSize: TSize;
|
|---|
| 391 | OutX, OutY: integer;
|
|---|
| 392 | begin
|
|---|
| 393 | if (AStyle.Shadow.Alpha = 0) and (AStyle.Text.Alpha = 0) then
|
|---|
| 394 | exit;
|
|---|
| 395 |
|
|---|
| 396 | FBGRA.FontAntialias := True;
|
|---|
| 397 | FBGRA.FontHeight := AStyle.Text.Font.Height;
|
|---|
| 398 | FBGRA.FontStyle := AStyle.Text.Font.Style;
|
|---|
| 399 | FBGRA.FontName := AStyle.Text.Font.Name;
|
|---|
| 400 | FBGRA.FontQuality := AStyle.Text.Quality;
|
|---|
| 401 |
|
|---|
| 402 | OutTxtSize := FBGRA.TextSize(Caption);
|
|---|
| 403 | OutX := Round(Width / 2) - Round(OutTxtSize.cx / 2);
|
|---|
| 404 | OutY := Round(Height / 2) - Round(OutTxtSize.cy / 2);
|
|---|
| 405 |
|
|---|
| 406 | if AStyle.Shadow.Alpha > 0 then
|
|---|
| 407 | begin
|
|---|
| 408 | bmpSdw := TBGRABitmap.Create(OutTxtSize.cx + 2 * AStyle.Shadow.Radius,
|
|---|
| 409 | OutTxtSize.cy + 2 * AStyle.Shadow.Radius);
|
|---|
| 410 |
|
|---|
| 411 | bmpSdw.FontAntialias := True;
|
|---|
| 412 | bmpSdw.FontHeight := AStyle.Text.Font.Height;
|
|---|
| 413 | bmpSdw.FontStyle := AStyle.Text.Font.Style;
|
|---|
| 414 | bmpSdw.FontName := AStyle.Text.Font.Name;
|
|---|
| 415 | bmpSdw.FontQuality := AStyle.Text.Quality;
|
|---|
| 416 |
|
|---|
| 417 | bmpSdw.TextOut(AStyle.Shadow.Radius, AStyle.Shadow.Radius,
|
|---|
| 418 | Caption, ColorToBGRA(AStyle.Shadow.Color, AStyle.Shadow.Alpha));
|
|---|
| 419 |
|
|---|
| 420 | BGRAReplace(bmpSdw, bmpSdw.FilterBlurRadial(AStyle.Shadow.Radius, rbFast));
|
|---|
| 421 |
|
|---|
| 422 | FBGRA.PutImage(OutX + AStyle.Shadow.OffsetX - AStyle.Shadow.Radius,
|
|---|
| 423 | OutY + AStyle.Shadow.OffsetY - AStyle.Shadow.Radius, bmpSdw,
|
|---|
| 424 | dmDrawWithTransparency);
|
|---|
| 425 |
|
|---|
| 426 | bmpSdw.Free;
|
|---|
| 427 | end;
|
|---|
| 428 |
|
|---|
| 429 | if AStyle.Text.Alpha > 0 then
|
|---|
| 430 | FBGRA.TextOut(OutX, OutY, Caption, ColorToBGRA(AStyle.Text.Font.Color,
|
|---|
| 431 | AStyle.Text.Alpha));
|
|---|
| 432 | end;
|
|---|
| 433 |
|
|---|
| 434 | { TBGRANeoButtonStyle }
|
|---|
| 435 |
|
|---|
| 436 | procedure TBGRANeoButtonStyle.SetFBorder(AValue: TBGRANeoBorderStyle);
|
|---|
| 437 | begin
|
|---|
| 438 | if FBorder = AValue then
|
|---|
| 439 | Exit;
|
|---|
| 440 | FBorder := AValue;
|
|---|
| 441 | end;
|
|---|
| 442 |
|
|---|
| 443 | procedure TBGRANeoButtonStyle.SetFGradient1(AValue: TBGRANeoGradientStyle);
|
|---|
| 444 | begin
|
|---|
| 445 | if FGradient1 = AValue then
|
|---|
| 446 | Exit;
|
|---|
| 447 | FGradient1 := AValue;
|
|---|
| 448 | end;
|
|---|
| 449 |
|
|---|
| 450 | procedure TBGRANeoButtonStyle.SetFGradient2(AValue: TBGRANeoGradientStyle);
|
|---|
| 451 | begin
|
|---|
| 452 | if FGradient2 = AValue then
|
|---|
| 453 | Exit;
|
|---|
| 454 | FGradient2 := AValue;
|
|---|
| 455 | end;
|
|---|
| 456 |
|
|---|
| 457 | procedure TBGRANeoButtonStyle.SetFGradientPosition(AValue: single);
|
|---|
| 458 | begin
|
|---|
| 459 | if FGradientPosition = AValue then
|
|---|
| 460 | Exit;
|
|---|
| 461 | FGradientPosition := AValue;
|
|---|
| 462 | end;
|
|---|
| 463 |
|
|---|
| 464 | procedure TBGRANeoButtonStyle.SetFShadow(AValue: TBGRANeoShadowStyle);
|
|---|
| 465 | begin
|
|---|
| 466 | if FShadow = AValue then
|
|---|
| 467 | Exit;
|
|---|
| 468 | FShadow := AValue;
|
|---|
| 469 | end;
|
|---|
| 470 |
|
|---|
| 471 | procedure TBGRANeoButtonStyle.SetFText(AValue: TBGRANeoTextStyle);
|
|---|
| 472 | begin
|
|---|
| 473 | if FText = AValue then
|
|---|
| 474 | Exit;
|
|---|
| 475 | FText := AValue;
|
|---|
| 476 | end;
|
|---|
| 477 |
|
|---|
| 478 | constructor TBGRANeoButtonStyle.Create(AOwner: TControl);
|
|---|
| 479 | begin
|
|---|
| 480 | inherited Create;
|
|---|
| 481 | FOwner := AOwner;
|
|---|
| 482 | FText := TBGRANeoTextStyle.Create(FOwner);
|
|---|
| 483 | FShadow := TBGRANeoShadowStyle.Create(FOwner);
|
|---|
| 484 | FGradient1 := TBGRANeoGradientStyle.Create(FOwner);
|
|---|
| 485 | FGradient2 := TBGRANeoGradientStyle.Create(FOwner);
|
|---|
| 486 | FGradientPosition := 0.5;
|
|---|
| 487 | FBorder := TBGRANeoBorderStyle.Create(FOwner);
|
|---|
| 488 | end;
|
|---|
| 489 |
|
|---|
| 490 | destructor TBGRANeoButtonStyle.Destroy;
|
|---|
| 491 | begin
|
|---|
| 492 | FText.Free;
|
|---|
| 493 | FShadow.Free;
|
|---|
| 494 | FGradient1.Free;
|
|---|
| 495 | FGradient2.Free;
|
|---|
| 496 | FBorder.Free;
|
|---|
| 497 | inherited Destroy;
|
|---|
| 498 | end;
|
|---|
| 499 |
|
|---|
| 500 | procedure TBGRANeoButtonStyle.Assign(Source: TPersistent);
|
|---|
| 501 | begin
|
|---|
| 502 | if Source is TBGRANeoButtonStyle then
|
|---|
| 503 | begin
|
|---|
| 504 | FText.Assign(TBGRANeoButtonStyle(Source).Text);
|
|---|
| 505 | FShadow.Assign(TBGRANeoButtonStyle(Source).Shadow);
|
|---|
| 506 | FGradient1.Assign(TBGRANeoButtonStyle(Source).Gradient1);
|
|---|
| 507 | FGradient2.Assign(TBGRANeoButtonStyle(Source).Gradient2);
|
|---|
| 508 | FGradientPosition := TBGRANeoButtonStyle(Source).GradientPosition;
|
|---|
| 509 | FBorder.Assign(TBGRANeoButtonStyle(Source).Border);
|
|---|
| 510 | end
|
|---|
| 511 | else
|
|---|
| 512 | inherited Assign(Source);
|
|---|
| 513 | end;
|
|---|
| 514 |
|
|---|
| 515 | { TBGRANeoBorderStyle }
|
|---|
| 516 |
|
|---|
| 517 | procedure TBGRANeoBorderStyle.SetFBottomLeft(AValue: TBGRANeoRoundRectangleOption);
|
|---|
| 518 | begin
|
|---|
| 519 | if FBottomLeft = AValue then
|
|---|
| 520 | Exit;
|
|---|
| 521 | FBottomLeft := AValue;
|
|---|
| 522 | end;
|
|---|
| 523 |
|
|---|
| 524 | procedure TBGRANeoBorderStyle.SetFBottomRight(AValue: TBGRANeoRoundRectangleOption);
|
|---|
| 525 | begin
|
|---|
| 526 | if FBottomRight = AValue then
|
|---|
| 527 | Exit;
|
|---|
| 528 | FBottomRight := AValue;
|
|---|
| 529 | end;
|
|---|
| 530 |
|
|---|
| 531 | procedure TBGRANeoBorderStyle.SetFInnerAlpha(AValue: byte);
|
|---|
| 532 | begin
|
|---|
| 533 | if FInnerAlpha = AValue then
|
|---|
| 534 | Exit;
|
|---|
| 535 | FInnerAlpha := AValue;
|
|---|
| 536 | end;
|
|---|
| 537 |
|
|---|
| 538 | procedure TBGRANeoBorderStyle.SetFInnerColor(AValue: TColor);
|
|---|
| 539 | begin
|
|---|
| 540 | if FInnerColor = AValue then
|
|---|
| 541 | Exit;
|
|---|
| 542 | FInnerColor := AValue;
|
|---|
| 543 | end;
|
|---|
| 544 |
|
|---|
| 545 | procedure TBGRANeoBorderStyle.SetFInnerWidth(AValue: single);
|
|---|
| 546 | begin
|
|---|
| 547 | if FInnerWidth = AValue then
|
|---|
| 548 | Exit;
|
|---|
| 549 | FInnerWidth := AValue;
|
|---|
| 550 | end;
|
|---|
| 551 |
|
|---|
| 552 | procedure TBGRANeoBorderStyle.SetFOuterAlpha(AValue: byte);
|
|---|
| 553 | begin
|
|---|
| 554 | if FOuterAlpha = AValue then
|
|---|
| 555 | Exit;
|
|---|
| 556 | FOuterAlpha := AValue;
|
|---|
| 557 | end;
|
|---|
| 558 |
|
|---|
| 559 | procedure TBGRANeoBorderStyle.SetFOuterColor(AValue: TColor);
|
|---|
| 560 | begin
|
|---|
| 561 | if FOuterColor = AValue then
|
|---|
| 562 | Exit;
|
|---|
| 563 | FOuterColor := AValue;
|
|---|
| 564 | end;
|
|---|
| 565 |
|
|---|
| 566 | procedure TBGRANeoBorderStyle.SetFOuterWidth(AValue: single);
|
|---|
| 567 | begin
|
|---|
| 568 | if FOuterWidth = AValue then
|
|---|
| 569 | Exit;
|
|---|
| 570 | FOuterWidth := AValue;
|
|---|
| 571 | end;
|
|---|
| 572 |
|
|---|
| 573 | procedure TBGRANeoBorderStyle.SetFRoundX(AValue: single);
|
|---|
| 574 | begin
|
|---|
| 575 | if FRoundX = AValue then
|
|---|
| 576 | Exit;
|
|---|
| 577 | FRoundX := AValue;
|
|---|
| 578 | end;
|
|---|
| 579 |
|
|---|
| 580 | procedure TBGRANeoBorderStyle.SetFRoundY(AValue: single);
|
|---|
| 581 | begin
|
|---|
| 582 | if FRoundY = AValue then
|
|---|
| 583 | Exit;
|
|---|
| 584 | FRoundY := AValue;
|
|---|
| 585 | end;
|
|---|
| 586 |
|
|---|
| 587 | procedure TBGRANeoBorderStyle.SetFTopLeft(AValue: TBGRANeoRoundRectangleOption);
|
|---|
| 588 | begin
|
|---|
| 589 | if FTopLeft = AValue then
|
|---|
| 590 | Exit;
|
|---|
| 591 | FTopLeft := AValue;
|
|---|
| 592 | end;
|
|---|
| 593 |
|
|---|
| 594 | procedure TBGRANeoBorderStyle.SetFTopRight(AValue: TBGRANeoRoundRectangleOption);
|
|---|
| 595 | begin
|
|---|
| 596 | if FTopRight = AValue then
|
|---|
| 597 | Exit;
|
|---|
| 598 | FTopRight := AValue;
|
|---|
| 599 | end;
|
|---|
| 600 |
|
|---|
| 601 | constructor TBGRANeoBorderStyle.Create(AOwner: TControl);
|
|---|
| 602 | begin
|
|---|
| 603 | inherited Create;
|
|---|
| 604 | FOwner := AOwner;
|
|---|
| 605 | FInnerColor := clWhite;
|
|---|
| 606 | FInnerAlpha := 255;
|
|---|
| 607 | FInnerWidth := 0;
|
|---|
| 608 | FOuterColor := clWhite;
|
|---|
| 609 | FOuterAlpha := 255;
|
|---|
| 610 | FOuterWidth := 0;
|
|---|
| 611 | FRoundX := 0;
|
|---|
| 612 | FRoundY := 0;
|
|---|
| 613 | FTopLeft := rroRound;
|
|---|
| 614 | FTopRight := rroRound;
|
|---|
| 615 | FBottomLeft := rroRound;
|
|---|
| 616 | FBottomRight := rroRound;
|
|---|
| 617 | end;
|
|---|
| 618 |
|
|---|
| 619 | destructor TBGRANeoBorderStyle.Destroy;
|
|---|
| 620 | begin
|
|---|
| 621 | inherited Destroy;
|
|---|
| 622 | end;
|
|---|
| 623 |
|
|---|
| 624 | procedure TBGRANeoBorderStyle.Assign(Source: TPersistent);
|
|---|
| 625 | begin
|
|---|
| 626 | if Source is TBGRANeoBorderStyle then
|
|---|
| 627 | begin
|
|---|
| 628 | FInnerColor := TBGRANeoBorderStyle(Source).InnerColor;
|
|---|
| 629 | FInnerAlpha := TBGRANeoBorderStyle(Source).InnerColorAlpha;
|
|---|
| 630 | FInnerWidth := TBGRANeoBorderStyle(Source).InnerWidth;
|
|---|
| 631 | FOuterColor := TBGRANeoBorderStyle(Source).OuterColor;
|
|---|
| 632 | FOuterAlpha := TBGRANeoBorderStyle(Source).OuterColorAlpha;
|
|---|
| 633 | FOuterWidth := TBGRANeoBorderStyle(Source).OuterWidth;
|
|---|
| 634 | FRoundX := TBGRANeoBorderStyle(Source).RoundX;
|
|---|
| 635 | FRoundY := TBGRANeoBorderStyle(Source).RoundY;
|
|---|
| 636 | FTopLeft := TBGRANeoBorderStyle(Source).TopLeft;
|
|---|
| 637 | FTopRight := TBGRANeoBorderStyle(Source).TopRight;
|
|---|
| 638 | FBottomLeft := TBGRANeoBorderStyle(Source).BottomLeft;
|
|---|
| 639 | FBottomRight := TBGRANeoBorderStyle(Source).BottomRight;
|
|---|
| 640 | end
|
|---|
| 641 | else
|
|---|
| 642 | inherited Assign(Source);
|
|---|
| 643 | end;
|
|---|
| 644 |
|
|---|
| 645 | function TBGRANeoBorderStyle.Options: TRoundRectangleOptions;
|
|---|
| 646 | var
|
|---|
| 647 | tl, tr, br, bl: TRoundRectangleOptions;
|
|---|
| 648 | begin
|
|---|
| 649 | case TopLeft of
|
|---|
| 650 | rroBevel: tl := [rrTopLeftBevel];
|
|---|
| 651 | rroSquare: tl := [rrTopLeftSquare];
|
|---|
| 652 | rroRound: tl := [];
|
|---|
| 653 | end;
|
|---|
| 654 |
|
|---|
| 655 | case TopRight of
|
|---|
| 656 | rroBevel: tr := [rrTopRightBevel];
|
|---|
| 657 | rroSquare: tr := [rrTopRightSquare];
|
|---|
| 658 | rroRound: tr := [];
|
|---|
| 659 | end;
|
|---|
| 660 |
|
|---|
| 661 | case BottomRight of
|
|---|
| 662 | rroBevel: br := [rrBottomRightBevel];
|
|---|
| 663 | rroSquare: br := [rrBottomRightSquare];
|
|---|
| 664 | rroRound: br := [];
|
|---|
| 665 | end;
|
|---|
| 666 |
|
|---|
| 667 | case BottomLeft of
|
|---|
| 668 | rroBevel: bl := [rrBottomLeftBevel];
|
|---|
| 669 | rroSquare: bl := [rrBottomLeftSquare];
|
|---|
| 670 | rroRound: bl := [];
|
|---|
| 671 | end;
|
|---|
| 672 |
|
|---|
| 673 | Result := tl + tr + br + bl;
|
|---|
| 674 | end;
|
|---|
| 675 |
|
|---|
| 676 | { TBGRANeoGradientStyle }
|
|---|
| 677 |
|
|---|
| 678 | procedure TBGRANeoGradientStyle.SetFColor1(AValue: TColor);
|
|---|
| 679 | begin
|
|---|
| 680 | if FColor1 = AValue then
|
|---|
| 681 | Exit;
|
|---|
| 682 | FColor1 := AValue;
|
|---|
| 683 | end;
|
|---|
| 684 |
|
|---|
| 685 | procedure TBGRANeoGradientStyle.SetFColor1Alpha(AValue: byte);
|
|---|
| 686 | begin
|
|---|
| 687 | if FColor1Alpha = AValue then
|
|---|
| 688 | Exit;
|
|---|
| 689 | FColor1Alpha := AValue;
|
|---|
| 690 | end;
|
|---|
| 691 |
|
|---|
| 692 | procedure TBGRANeoGradientStyle.SetFColor2(AValue: TColor);
|
|---|
| 693 | begin
|
|---|
| 694 | if FColor2 = AValue then
|
|---|
| 695 | Exit;
|
|---|
| 696 | FColor2 := AValue;
|
|---|
| 697 | end;
|
|---|
| 698 |
|
|---|
| 699 | procedure TBGRANeoGradientStyle.SetFColor2Alpha(AValue: byte);
|
|---|
| 700 | begin
|
|---|
| 701 | if FColor1Alpha = AValue then
|
|---|
| 702 | Exit;
|
|---|
| 703 | FColor1Alpha := AValue;
|
|---|
| 704 | end;
|
|---|
| 705 |
|
|---|
| 706 | procedure TBGRANeoGradientStyle.SetFSinus(AValue: boolean);
|
|---|
| 707 | begin
|
|---|
| 708 | if FSinus = AValue then
|
|---|
| 709 | Exit;
|
|---|
| 710 | FSinus := AValue;
|
|---|
| 711 | end;
|
|---|
| 712 |
|
|---|
| 713 | procedure TBGRANeoGradientStyle.SetFStyle(AValue: TGradientType);
|
|---|
| 714 | begin
|
|---|
| 715 | if FStyle = AValue then
|
|---|
| 716 | Exit;
|
|---|
| 717 | FStyle := AValue;
|
|---|
| 718 | end;
|
|---|
| 719 |
|
|---|
| 720 | constructor TBGRANeoGradientStyle.Create(AOwner: TControl);
|
|---|
| 721 | begin
|
|---|
| 722 | inherited Create;
|
|---|
| 723 | FOwner := AOwner;
|
|---|
| 724 | FColor1 := clWhite;
|
|---|
| 725 | FColor1Alpha := 255;
|
|---|
| 726 | FColor2 := clWhite;
|
|---|
| 727 | FColor2Alpha := 255;
|
|---|
| 728 | FStyle := gtLinear;
|
|---|
| 729 | FSinus := False;
|
|---|
| 730 | end;
|
|---|
| 731 |
|
|---|
| 732 | destructor TBGRANeoGradientStyle.Destroy;
|
|---|
| 733 | begin
|
|---|
| 734 | inherited Destroy;
|
|---|
| 735 | end;
|
|---|
| 736 |
|
|---|
| 737 | procedure TBGRANeoGradientStyle.Assign(Source: TPersistent);
|
|---|
| 738 | begin
|
|---|
| 739 | if Source is TBGRANeoGradientStyle then
|
|---|
| 740 | begin
|
|---|
| 741 | FColor1 := TBGRANeoGradientStyle(Source).Color1;
|
|---|
| 742 | FColor1Alpha := TBGRANeoGradientStyle(Source).Color1Alpha;
|
|---|
| 743 | FColor2 := TBGRANeoGradientStyle(Source).Color2;
|
|---|
| 744 | FColor2Alpha := TBGRANeoGradientStyle(Source).Color2Alpha;
|
|---|
| 745 | FStyle := TBGRANeoGradientStyle(Source).Style;
|
|---|
| 746 | FSinus := TBGRANeoGradientStyle(Source).Sinus;
|
|---|
| 747 | end
|
|---|
| 748 | else
|
|---|
| 749 | inherited Assign(Source);
|
|---|
| 750 | end;
|
|---|
| 751 |
|
|---|
| 752 | { TBGRANeoTextStyle }
|
|---|
| 753 |
|
|---|
| 754 | procedure TBGRANeoTextStyle.SetFAlpha(AValue: byte);
|
|---|
| 755 | begin
|
|---|
| 756 | if FAlpha = AValue then
|
|---|
| 757 | Exit;
|
|---|
| 758 | FAlpha := AValue;
|
|---|
| 759 | end;
|
|---|
| 760 |
|
|---|
| 761 | procedure TBGRANeoTextStyle.SetFFont(AValue: TFont);
|
|---|
| 762 | begin
|
|---|
| 763 | if FFont.IsEqual(AValue) then
|
|---|
| 764 | exit;
|
|---|
| 765 | FFont.Assign(AValue);
|
|---|
| 766 | end;
|
|---|
| 767 |
|
|---|
| 768 | procedure TBGRANeoTextStyle.SetFQuality(AValue: TBGRAFontQuality);
|
|---|
| 769 | begin
|
|---|
| 770 | if FQuality = AValue then
|
|---|
| 771 | Exit;
|
|---|
| 772 | FQuality := AValue;
|
|---|
| 773 | end;
|
|---|
| 774 |
|
|---|
| 775 | constructor TBGRANeoTextStyle.Create(AOwner: TControl);
|
|---|
| 776 | begin
|
|---|
| 777 | inherited Create;
|
|---|
| 778 | FOwner := AOwner;
|
|---|
| 779 | FAlpha := 255;
|
|---|
| 780 | FFont := TFont.Create;
|
|---|
| 781 | FQuality := fqSystemClearType;
|
|---|
| 782 | end;
|
|---|
| 783 |
|
|---|
| 784 | destructor TBGRANeoTextStyle.Destroy;
|
|---|
| 785 | begin
|
|---|
| 786 | FFont.Free;
|
|---|
| 787 | inherited Destroy;
|
|---|
| 788 | end;
|
|---|
| 789 |
|
|---|
| 790 | procedure TBGRANeoTextStyle.Assign(Source: TPersistent);
|
|---|
| 791 | begin
|
|---|
| 792 | if Source is TBGRANeoTextStyle then
|
|---|
| 793 | begin
|
|---|
| 794 | FAlpha := TBGRANeoTextStyle(Source).Alpha;
|
|---|
| 795 | FFont.Assign(TBGRANeoTextStyle(Source).Font);
|
|---|
| 796 | FQuality := TBGRANeoTextStyle(Source).Quality;
|
|---|
| 797 | end
|
|---|
| 798 | else
|
|---|
| 799 | inherited Assign(Source);
|
|---|
| 800 | end;
|
|---|
| 801 |
|
|---|
| 802 | { TBGRANeoShadowStyle }
|
|---|
| 803 |
|
|---|
| 804 | procedure TBGRANeoShadowStyle.SetFAlpha(AValue: byte);
|
|---|
| 805 | begin
|
|---|
| 806 | if FAlpha = AValue then
|
|---|
| 807 | Exit;
|
|---|
| 808 | FAlpha := AValue;
|
|---|
| 809 | end;
|
|---|
| 810 |
|
|---|
| 811 | procedure TBGRANeoShadowStyle.SetFColor(AValue: TColor);
|
|---|
| 812 | begin
|
|---|
| 813 | if FColor = AValue then
|
|---|
| 814 | Exit;
|
|---|
| 815 | FColor := AValue;
|
|---|
| 816 | end;
|
|---|
| 817 |
|
|---|
| 818 | procedure TBGRANeoShadowStyle.SetFOffsetX(AValue: integer);
|
|---|
| 819 | begin
|
|---|
| 820 | if FOffsetX = AValue then
|
|---|
| 821 | Exit;
|
|---|
| 822 | FOffsetX := AValue;
|
|---|
| 823 | end;
|
|---|
| 824 |
|
|---|
| 825 | procedure TBGRANeoShadowStyle.SetFOffsetY(AValue: integer);
|
|---|
| 826 | begin
|
|---|
| 827 | if FOffsetY = AValue then
|
|---|
| 828 | Exit;
|
|---|
| 829 | FOffsetY := AValue;
|
|---|
| 830 | end;
|
|---|
| 831 |
|
|---|
| 832 | procedure TBGRANeoShadowStyle.SetFRadius(AValue: integer);
|
|---|
| 833 | begin
|
|---|
| 834 | if FRadius = AValue then
|
|---|
| 835 | Exit;
|
|---|
| 836 | FRadius := AValue;
|
|---|
| 837 | end;
|
|---|
| 838 |
|
|---|
| 839 | constructor TBGRANeoShadowStyle.Create(AOwner: TControl);
|
|---|
| 840 | begin
|
|---|
| 841 | inherited Create;
|
|---|
| 842 | FOwner := AOwner;
|
|---|
| 843 | FColor := clWhite;
|
|---|
| 844 | FAlpha := 255;
|
|---|
| 845 | FOffsetX := 0;
|
|---|
| 846 | FOffsetY := 0;
|
|---|
| 847 | FRadius := 0;
|
|---|
| 848 | end;
|
|---|
| 849 |
|
|---|
| 850 | destructor TBGRANeoShadowStyle.Destroy;
|
|---|
| 851 | begin
|
|---|
| 852 | inherited Destroy;
|
|---|
| 853 | end;
|
|---|
| 854 |
|
|---|
| 855 | procedure TBGRANeoShadowStyle.Assign(Source: TPersistent);
|
|---|
| 856 | begin
|
|---|
| 857 | if Source is TBGRANeoShadowStyle then
|
|---|
| 858 | begin
|
|---|
| 859 | FColor := TBGRANeoShadowStyle(Source).Color;
|
|---|
| 860 | FAlpha := TBGRANeoShadowStyle(Source).Alpha;
|
|---|
| 861 | FOffsetX := TBGRANeoShadowStyle(Source).OffsetX;
|
|---|
| 862 | FOffsetY := TBGRANeoShadowStyle(Source).OffsetY;
|
|---|
| 863 | FRadius := TBGRANeoShadowStyle(Source).Radius;
|
|---|
| 864 | end
|
|---|
| 865 | else
|
|---|
| 866 | inherited Assign(Source);
|
|---|
| 867 | end;
|
|---|
| 868 |
|
|---|
| 869 | { TCustomBGRANeoButton }
|
|---|
| 870 |
|
|---|
| 871 | procedure TCustomBGRANeoButton.SetFStyleActive(AValue: TBGRANeoButtonStyle);
|
|---|
| 872 | begin
|
|---|
| 873 | if FStyleActive = AValue then
|
|---|
| 874 | Exit;
|
|---|
| 875 | FStyleActive := AValue;
|
|---|
| 876 | end;
|
|---|
| 877 |
|
|---|
| 878 | procedure TCustomBGRANeoButton.SetFStyleDisabled(AValue: TBGRANeoButtonStyle);
|
|---|
| 879 | begin
|
|---|
| 880 | if FStyleDisabled = AValue then
|
|---|
| 881 | Exit;
|
|---|
| 882 | FStyleDisabled := AValue;
|
|---|
| 883 | end;
|
|---|
| 884 |
|
|---|
| 885 | procedure TCustomBGRANeoButton.SetFStyleHover(AValue: TBGRANeoButtonStyle);
|
|---|
| 886 | begin
|
|---|
| 887 | if FStyleHover = AValue then
|
|---|
| 888 | Exit;
|
|---|
| 889 | FStyleHover := AValue;
|
|---|
| 890 | end;
|
|---|
| 891 |
|
|---|
| 892 | procedure TCustomBGRANeoButton.SetFStyleNormal(AValue: TBGRANeoButtonStyle);
|
|---|
| 893 | begin
|
|---|
| 894 | if FStyleNormal = AValue then
|
|---|
| 895 | Exit;
|
|---|
| 896 | FStyleNormal := AValue;
|
|---|
| 897 | end;
|
|---|
| 898 |
|
|---|
| 899 | procedure TCustomBGRANeoButton.DrawButton;
|
|---|
| 900 | begin
|
|---|
| 901 | if Enabled then
|
|---|
| 902 | case FState of
|
|---|
| 903 | gbsNormal:
|
|---|
| 904 | begin
|
|---|
| 905 | DrawBody(StyleNormal);
|
|---|
| 906 | DrawText(StyleNormal);
|
|---|
| 907 | end;
|
|---|
| 908 | gbsHover:
|
|---|
| 909 | begin
|
|---|
| 910 | DrawBody(StyleHover);
|
|---|
| 911 | DrawText(StyleHover);
|
|---|
| 912 | end;
|
|---|
| 913 | gbsActive:
|
|---|
| 914 | begin
|
|---|
| 915 | DrawBody(StyleActive);
|
|---|
| 916 | DrawText(StyleActive);
|
|---|
| 917 | end;
|
|---|
| 918 | end
|
|---|
| 919 | else
|
|---|
| 920 | begin
|
|---|
| 921 | DrawBody(StyleDisabled);
|
|---|
| 922 | DrawText(StyleDisabled);
|
|---|
| 923 | end;
|
|---|
| 924 | end;
|
|---|
| 925 |
|
|---|
| 926 | procedure TCustomBGRANeoButton.DrawBody(AStyle: TBGRANeoButtonStyle);
|
|---|
| 927 | begin
|
|---|
| 928 | // nothing here
|
|---|
| 929 | end;
|
|---|
| 930 |
|
|---|
| 931 | procedure TCustomBGRANeoButton.DrawText(AStyle: TBGRANeoButtonStyle);
|
|---|
| 932 | begin
|
|---|
| 933 | // nothing here
|
|---|
| 934 | end;
|
|---|
| 935 |
|
|---|
| 936 | procedure TCustomBGRANeoButton.Paint;
|
|---|
| 937 | begin
|
|---|
| 938 | FBGRA.SetSize(Width, Height);
|
|---|
| 939 | DrawButton;
|
|---|
| 940 |
|
|---|
| 941 | {$IFDEF DEBUG}
|
|---|
| 942 | Inc(FPaintCount);
|
|---|
| 943 | FBGRA.TextOut(0, 0, IntToStr(FPaintCount), BGRAWhite);
|
|---|
| 944 | FBGRA.TextOut(1, 1, IntToStr(FPaintCount), BGRABlack);
|
|---|
| 945 | {$ENDIF}
|
|---|
| 946 |
|
|---|
| 947 | FBGRA.Draw(Canvas, 0, 0, False);
|
|---|
| 948 | end;
|
|---|
| 949 |
|
|---|
| 950 | constructor TCustomBGRANeoButton.Create(AOwner: TComponent);
|
|---|
| 951 | begin
|
|---|
| 952 | inherited Create(AOwner);
|
|---|
| 953 | FBGRA := TBGRABitmap.Create;
|
|---|
| 954 | FStyleNormal := TBGRANeoButtonStyle.Create(Self);
|
|---|
| 955 | FStyleHover := TBGRANeoButtonStyle.Create(Self);
|
|---|
| 956 | FStyleActive := TBGRANeoButtonStyle.Create(Self);
|
|---|
| 957 | FStyleDisabled := TBGRANeoButtonStyle.Create(Self);
|
|---|
| 958 | end;
|
|---|
| 959 |
|
|---|
| 960 | destructor TCustomBGRANeoButton.Destroy;
|
|---|
| 961 | begin
|
|---|
| 962 | FBGRA.Free;
|
|---|
| 963 | FStyleNormal.Free;
|
|---|
| 964 | FStyleHover.Free;
|
|---|
| 965 | FStyleActive.Free;
|
|---|
| 966 | FStyleDisabled.Free;
|
|---|
| 967 | inherited Destroy;
|
|---|
| 968 | end;
|
|---|
| 969 |
|
|---|
| 970 | procedure TCustomBGRANeoButton.Assign(Source: TPersistent);
|
|---|
| 971 | begin
|
|---|
| 972 | inherited Assign(Source);
|
|---|
| 973 | end;
|
|---|
| 974 |
|
|---|
| 975 | { TGraphicButton }
|
|---|
| 976 |
|
|---|
| 977 | procedure TGraphicButton.DoClick;
|
|---|
| 978 | var
|
|---|
| 979 | Form: TCustomForm;
|
|---|
| 980 | begin
|
|---|
| 981 | if ModalResult <> mrNone then
|
|---|
| 982 | begin
|
|---|
| 983 | Form := GetParentForm(Self);
|
|---|
| 984 | if Form <> nil then
|
|---|
| 985 | Form.ModalResult := ModalResult;
|
|---|
| 986 | end;
|
|---|
| 987 | end;
|
|---|
| 988 |
|
|---|
| 989 | procedure TGraphicButton.DoMouseDown;
|
|---|
| 990 | var
|
|---|
| 991 | NewState: TGraphicButtonState;
|
|---|
| 992 | begin
|
|---|
| 993 | NewState := gbsActive;
|
|---|
| 994 |
|
|---|
| 995 | if NewState <> FState then
|
|---|
| 996 | begin
|
|---|
| 997 | FState := NewState;
|
|---|
| 998 | Invalidate;
|
|---|
| 999 | end;
|
|---|
| 1000 | end;
|
|---|
| 1001 |
|
|---|
| 1002 | procedure TGraphicButton.DoMouseUp;
|
|---|
| 1003 | var
|
|---|
| 1004 | NewState: TGraphicButtonState;
|
|---|
| 1005 | p: TPoint;
|
|---|
| 1006 | begin
|
|---|
| 1007 | p := ScreenToClient(Mouse.CursorPos);
|
|---|
| 1008 |
|
|---|
| 1009 | if (p.x >= 0) and (p.x <= Width) and (p.y >= 0) and (p.y <= Height) then
|
|---|
| 1010 | NewState := gbsHover
|
|---|
| 1011 | else
|
|---|
| 1012 | NewState := gbsNormal;
|
|---|
| 1013 |
|
|---|
| 1014 | if NewState <> FState then
|
|---|
| 1015 | begin
|
|---|
| 1016 | FState := NewState;
|
|---|
| 1017 | Invalidate;
|
|---|
| 1018 | end;
|
|---|
| 1019 | end;
|
|---|
| 1020 |
|
|---|
| 1021 | procedure TGraphicButton.DoMouseEnter;
|
|---|
| 1022 | var
|
|---|
| 1023 | NewState: TGraphicButtonState;
|
|---|
| 1024 | begin
|
|---|
| 1025 | if Enabled then
|
|---|
| 1026 | NewState := gbsHover
|
|---|
| 1027 | else
|
|---|
| 1028 | begin
|
|---|
| 1029 | FState := gbsNormal;
|
|---|
| 1030 | NewState := FState;
|
|---|
| 1031 | end;
|
|---|
| 1032 |
|
|---|
| 1033 | if NewState <> FState then
|
|---|
| 1034 | begin
|
|---|
| 1035 | FState := NewState;
|
|---|
| 1036 | Invalidate;
|
|---|
| 1037 | end;
|
|---|
| 1038 | end;
|
|---|
| 1039 |
|
|---|
| 1040 | procedure TGraphicButton.DoMouseLeave;
|
|---|
| 1041 | var
|
|---|
| 1042 | NewState: TGraphicButtonState;
|
|---|
| 1043 | begin
|
|---|
| 1044 | if Enabled then
|
|---|
| 1045 | NewState := gbsNormal
|
|---|
| 1046 | else
|
|---|
| 1047 | begin
|
|---|
| 1048 | FState := gbsNormal;
|
|---|
| 1049 | NewState := FState;
|
|---|
| 1050 | end;
|
|---|
| 1051 |
|
|---|
| 1052 | if NewState <> FState then
|
|---|
| 1053 | begin
|
|---|
| 1054 | FState := NewState;
|
|---|
| 1055 | Invalidate;
|
|---|
| 1056 | end;
|
|---|
| 1057 | end;
|
|---|
| 1058 |
|
|---|
| 1059 | procedure TGraphicButton.Click;
|
|---|
| 1060 | begin
|
|---|
| 1061 | DoClick;
|
|---|
| 1062 | inherited Click;
|
|---|
| 1063 | end;
|
|---|
| 1064 |
|
|---|
| 1065 | procedure TGraphicButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
|---|
| 1066 | X, Y: integer);
|
|---|
| 1067 | begin
|
|---|
| 1068 | inherited MouseDown(Button, Shift, X, Y);
|
|---|
| 1069 | if Button = mbLeft then
|
|---|
| 1070 | DoMouseDown;
|
|---|
| 1071 | end;
|
|---|
| 1072 |
|
|---|
| 1073 | procedure TGraphicButton.MouseUp(Button: TMouseButton; Shift: TShiftState;
|
|---|
| 1074 | X, Y: integer);
|
|---|
| 1075 | begin
|
|---|
| 1076 | inherited MouseUp(Button, Shift, X, Y);
|
|---|
| 1077 | DoMouseUp;
|
|---|
| 1078 | end;
|
|---|
| 1079 |
|
|---|
| 1080 | procedure TGraphicButton.MouseEnter;
|
|---|
| 1081 | begin
|
|---|
| 1082 | inherited MouseEnter;
|
|---|
| 1083 | DoMouseEnter;
|
|---|
| 1084 | end;
|
|---|
| 1085 |
|
|---|
| 1086 | procedure TGraphicButton.MouseLeave;
|
|---|
| 1087 | begin
|
|---|
| 1088 | inherited MouseLeave;
|
|---|
| 1089 | DoMouseLeave;
|
|---|
| 1090 | end;
|
|---|
| 1091 |
|
|---|
| 1092 | end.
|
|---|
| 1093 |
|
|---|