| 1 |
unit mbTrackBarPicker; |
| 2 |
|
| 3 |
{$MODE DELPHI} |
| 4 |
|
| 5 |
interface |
| 6 |
|
| 7 |
uses |
| 8 |
LCLIntf, LCLType, LMessages, SysUtils, Classes, Controls, Graphics, Forms, |
| 9 |
Themes, ExtCtrls, |
| 10 |
PalUtils, mbColorConv, mbBasicPicker; |
| 11 |
|
| 12 |
const |
| 13 |
TBA_Resize = 0; |
| 14 |
TBA_Paint = 1; |
| 15 |
TBA_MouseMove = 2; |
| 16 |
TBA_MouseDown = 3; |
| 17 |
TBA_MouseUp = 4; |
| 18 |
TBA_WheelUp = 5; |
| 19 |
TBA_WheelDown = 6; |
| 20 |
TBA_VKUp = 7; |
| 21 |
TBA_VKCtrlUp = 8; |
| 22 |
TBA_VKDown = 9; |
| 23 |
TBA_VKCtrlDown = 10; |
| 24 |
TBA_VKLeft = 11; |
| 25 |
TBA_VKCtrlLeft = 12; |
| 26 |
TBA_VKRight = 13; |
| 27 |
TBA_VKCtrlRight = 14; |
| 28 |
TBA_RedoBMP = 15; |
| 29 |
|
| 30 |
type |
| 31 |
TTrackBarLayout = (lyHorizontal, lyVertical); |
| 32 |
TSliderPlacement = (spBefore, spAfter, spBoth); |
| 33 |
TSelIndicator = (siArrows, siRect); |
| 34 |
|
| 35 |
{ TmbTrackBarPicker } |
| 36 |
|
| 37 |
TmbTrackBarPicker = class(TmbBasicPicker) |
| 38 |
private |
| 39 |
Aw, Ah: integer; |
| 40 |
mx, my: integer; |
| 41 |
FBevelInner: TBevelCut; |
| 42 |
FBevelOuter: TBevelCut; |
| 43 |
FBevelWidth: TBevelWidth; |
| 44 |
FBorderStyle: TBorderStyle; |
| 45 |
FHintFormat: string; |
| 46 |
FIncrement: integer; |
| 47 |
FNewArrowStyle: boolean; |
| 48 |
FPlacement: TSliderPlacement; |
| 49 |
FSelIndicator: TSelIndicator; |
| 50 |
FWebSafe: boolean; |
| 51 |
procedure CalcPickRect; |
| 52 |
procedure DrawMarker(p: integer); |
| 53 |
procedure SetBevelInner(Value: TBevelCut); |
| 54 |
procedure SetBevelOuter(Value: TBevelCut); |
| 55 |
procedure SetBevelWidth(Value: TBevelWidth); |
| 56 |
procedure SetLayout(Value: TTrackBarLayout); |
| 57 |
procedure SetNewArrowStyle(s: boolean); |
| 58 |
procedure SetPlacement(Value: TSliderPlacement); |
| 59 |
procedure SetSelIndicator(Value: TSelIndicator); |
| 60 |
procedure SetWebSafe(s: boolean); |
| 61 |
function XToArrowPos(p: integer): integer; |
| 62 |
function YToArrowPos(p: integer): integer; |
| 63 |
protected |
| 64 |
FArrowPos: integer; |
| 65 |
// FBack: TBitmap; |
| 66 |
FLayout: TTrackBarLayout; |
| 67 |
FLimit: integer; |
| 68 |
FPickRect: TRect; |
| 69 |
procedure CreateGradient; override; |
| 70 |
procedure CreateWnd; override; |
| 71 |
function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; |
| 72 |
MousePos: TPoint): Boolean; override; |
| 73 |
procedure DrawFrames; dynamic; |
| 74 |
procedure Execute(tbaAction: integer); dynamic; |
| 75 |
function GetArrowPos: integer; dynamic; |
| 76 |
function GetHintPos(X, Y: Integer): TPoint; override; |
| 77 |
function GetHintStr(X, Y: Integer): String; override; |
| 78 |
function GetSelectedValue: integer; virtual; abstract; |
| 79 |
procedure KeyDown(var Key: Word; Shift: TShiftState); override; |
| 80 |
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; |
| 81 |
procedure MouseLeave; override; |
| 82 |
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; |
| 83 |
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; |
| 84 |
procedure Paint; override; |
| 85 |
procedure Resize; override; |
| 86 |
procedure SetBorderStyle(Value: TBorderStyle); override; |
| 87 |
procedure CMGotFocus(var Message: TLMessage); message CM_ENTER; |
| 88 |
procedure CMLostFocus(var Message: TLMessage); message CM_EXIT; |
| 89 |
property HintFormat: string read FHintFormat write FHintFormat; |
| 90 |
|
| 91 |
public |
| 92 |
constructor Create(AOwner: TComponent); override; |
| 93 |
destructor Destroy; override; |
| 94 |
|
| 95 |
published |
| 96 |
property BevelInner: TPanelBevel read FBevelInner write SetBevelInner default bvNone; |
| 97 |
property BevelOuter: TPanelBevel read FBevelOuter write SetBevelOuter default bvNone; |
| 98 |
property BevelWidth: TBevelWidth read FBevelWidth write SetBevelWidth default 1; |
| 99 |
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsNone; |
| 100 |
property Increment: integer read FIncrement write FIncrement default 1; |
| 101 |
property Layout: TTrackBarLayout read FLayout write SetLayout default lyHorizontal; |
| 102 |
property ArrowPlacement: TSliderPlacement read FPlacement write SetPlacement default spAfter; |
| 103 |
property NewArrowStyle: boolean read FNewArrowStyle write SetNewArrowStyle default false; |
| 104 |
property SelectionIndicator: TSelIndicator read FSelIndicator write SetSelIndicator default siArrows; |
| 105 |
property WebSafe: boolean read FWebSafe write SetWebSafe default false; |
| 106 |
property TabStop default true; |
| 107 |
property ShowHint; |
| 108 |
property Color; |
| 109 |
property ParentColor; |
| 110 |
property ParentShowHint default true; |
| 111 |
property Anchors; |
| 112 |
property Align; |
| 113 |
property BorderSpacing; |
| 114 |
property Visible; |
| 115 |
property Enabled; |
| 116 |
property PopupMenu; |
| 117 |
property TabOrder; |
| 118 |
property DragCursor; |
| 119 |
property DragMode; |
| 120 |
property DragKind; |
| 121 |
property Constraints; |
| 122 |
property OnChange; |
| 123 |
property OnContextPopup; |
| 124 |
property OnGetHintStr; |
| 125 |
property OnMouseDown; |
| 126 |
property OnMouseMove; |
| 127 |
property OnMouseUp; |
| 128 |
property OnMouseWheel; |
| 129 |
property OnMouseWheelUp; |
| 130 |
property OnMouseWheelDown; |
| 131 |
property OnKeyDown; |
| 132 |
property OnKeyPress; |
| 133 |
property OnKeyUp; |
| 134 |
property OnDragDrop; |
| 135 |
property OnDragOver; |
| 136 |
property OnEndDrag; |
| 137 |
property OnEnter; |
| 138 |
property OnExit; |
| 139 |
property OnResize; |
| 140 |
property OnStartDrag; |
| 141 |
end; |
| 142 |
|
| 143 |
{ TmbHSLVTrackbarPicker } |
| 144 |
|
| 145 |
TmbHSLVTrackbarPicker = class(TmbTrackbarPicker) |
| 146 |
private |
| 147 |
FBrightnessMode: TBrightnessMode; |
| 148 |
function GetHue: Integer; |
| 149 |
function GetLum: Integer; |
| 150 |
function GetSat: Integer; |
| 151 |
function GetVal: Integer; |
| 152 |
procedure SetHue(h: integer); |
| 153 |
procedure SetLum(L: Integer); |
| 154 |
procedure SetSat(s: integer); |
| 155 |
procedure SetVal(v: integer); |
| 156 |
protected |
| 157 |
FHue, FSat, FLum, FVal: Double; |
| 158 |
FMaxHue, FMaxSat, FMaxLum, FMaxVal: Integer; |
| 159 |
procedure ColorToHSLV(c: TColor; var H, S, L, V: Double); |
| 160 |
function GetSelectedColor: TColor; override; |
| 161 |
function HSLVtoColor(H, S, L, V: Double): TColor; |
| 162 |
procedure SetBrightnessMode(AMode: TBrightnessMode); virtual; |
| 163 |
procedure SetMaxHue(h: Integer); virtual; |
| 164 |
procedure SetMaxLum(L: Integer); virtual; |
| 165 |
procedure SetMaxSat(s: Integer); virtual; |
| 166 |
procedure SetMaxVal(v: Integer); virtual; |
| 167 |
procedure SetRelHue(H: Double); virtual; |
| 168 |
procedure SetRelLum(L: Double); virtual; |
| 169 |
procedure SetRelSat(S: Double); virtual; |
| 170 |
procedure SetRelVal(V: Double); virtual; |
| 171 |
public |
| 172 |
constructor Create(AOwner: TComponent); override; |
| 173 |
property RelHue: Double read FHue write SetRelHue; |
| 174 |
property RelSaturation: Double read FSat write SetRelSat; |
| 175 |
property RelLuminance: Double read FLum write SetRelLum; |
| 176 |
property RelValue: Double read FVal write SetRelVal; |
| 177 |
published |
| 178 |
property BrightnessMode: TBrightnessMode |
| 179 |
read FBrightnessMode write SetBrightnessMode default bmLuminance; |
| 180 |
property Hue: integer read GetHue write SetHue; |
| 181 |
property Luminance: Integer read GetLum write SetLum; |
| 182 |
property Saturation: integer read GetSat write SetSat; |
| 183 |
property Value: integer read GetVal write SetVal; |
| 184 |
property MaxHue: Integer read FMaxHue write SetMaxHue default 360; |
| 185 |
property MaxSaturation: Integer read FMaxSat write SetMaxSat default 255; |
| 186 |
property MaxLuminance: Integer read FMaxLum write SetMaxLum default 255; |
| 187 |
property MaxValue: Integer read FMaxVal write SetMaxVal default 255; |
| 188 |
end; |
| 189 |
|
| 190 |
implementation |
| 191 |
|
| 192 |
uses |
| 193 |
IntfGraphics, fpimage, Math, |
| 194 |
mbUtils, HTMLColors; |
| 195 |
|
| 196 |
const |
| 197 |
{ 3D border styles } |
| 198 |
BDR_RAISEDOUTER = 1; |
| 199 |
BDR_SUNKENOUTER = 2; |
| 200 |
BDR_RAISEDINNER = 4; |
| 201 |
BDR_SUNKENINNER = 8; |
| 202 |
|
| 203 |
BDR_OUTER = 3; |
| 204 |
BDR_INNER = 12; |
| 205 |
|
| 206 |
{ Border flags } |
| 207 |
BF_LEFT = 1; |
| 208 |
BF_TOP = 2; |
| 209 |
BF_RIGHT = 4; |
| 210 |
BF_BOTTOM = 8; |
| 211 |
BF_RECT = (BF_LEFT or BF_TOP or BF_RIGHT or BF_BOTTOM); |
| 212 |
|
| 213 |
|
| 214 |
{TmbTrackBarPicker} |
| 215 |
|
| 216 |
constructor TmbTrackBarPicker.Create(AOwner: TComponent); |
| 217 |
begin |
| 218 |
inherited; |
| 219 |
//ControlStyle := ControlStyle - [csAcceptsControls]; // + [csOpaque]; // !!!!!!!! |
| 220 |
//DoubleBuffered := true; |
| 221 |
|
| 222 |
Width := 267; |
| 223 |
Height := 22; |
| 224 |
TabStop := true; |
| 225 |
ParentShowHint := true; |
| 226 |
|
| 227 |
FGradientWidth := 256; |
| 228 |
FGradientHeight := 1; |
| 229 |
|
| 230 |
// FBack := TBitmap.Create; |
| 231 |
|
| 232 |
FBufferBmp := TBitmap.Create; |
| 233 |
//FBufferBmp.PixelFormat := pf32bit; |
| 234 |
|
| 235 |
mx := 0; |
| 236 |
my := 0; |
| 237 |
FIncrement := 1; |
| 238 |
FArrowPos := GetArrowPos; |
| 239 |
FHintFormat := ''; |
| 240 |
FLayout := lyHorizontal; |
| 241 |
FNewArrowStyle := false; |
| 242 |
Aw := 6; |
| 243 |
Ah := 10; |
| 244 |
FPlacement := spAfter; |
| 245 |
FPickRect := Rect(Aw, 0, Width - Aw, Height - Ah); |
| 246 |
// FDoChange := false; |
| 247 |
FSelIndicator := siArrows; |
| 248 |
FLimit := 7; |
| 249 |
FWebSafe := false; |
| 250 |
FBevelInner := bvNone; |
| 251 |
FBevelOuter := bvNone; |
| 252 |
FBevelWidth := 1; |
| 253 |
FBorderStyle := bsNone; |
| 254 |
end; |
| 255 |
|
| 256 |
destructor TmbTrackbarPicker.Destroy; |
| 257 |
begin |
| 258 |
// FBack.Free; |
| 259 |
inherited; |
| 260 |
end; |
| 261 |
|
| 262 |
procedure TmbTrackBarPicker.CalcPickRect; |
| 263 |
var |
| 264 |
f: integer; |
| 265 |
begin |
| 266 |
case FSelIndicator of |
| 267 |
siArrows: |
| 268 |
if not FNewArrowStyle then |
| 269 |
begin |
| 270 |
f := 0; |
| 271 |
Aw := 6; |
| 272 |
Ah := 10; |
| 273 |
FLimit := 7; |
| 274 |
end |
| 275 |
else |
| 276 |
begin |
| 277 |
Aw := 8; |
| 278 |
Ah := 9; |
| 279 |
f := 2; |
| 280 |
FLimit := 7; |
| 281 |
end; |
| 282 |
|
| 283 |
siRect: |
| 284 |
begin |
| 285 |
f := 0; |
| 286 |
Aw := 4; |
| 287 |
Ah := 5; |
| 288 |
FLimit := 3; |
| 289 |
end |
| 290 |
|
| 291 |
else |
| 292 |
f := 0; |
| 293 |
end; |
| 294 |
|
| 295 |
case FLayout of |
| 296 |
lyHorizontal: |
| 297 |
case FSelIndicator of |
| 298 |
siArrows: |
| 299 |
case FPlacement of |
| 300 |
spAfter : FPickRect := Rect(Aw, 0, Width - Aw, Height - Ah - f); |
| 301 |
spBefore : FPickRect := Rect(Aw, Ah + f, Width - Aw, Height); |
| 302 |
spBoth : FPickRect := Rect(Aw, Ah + f, Width - Aw, Height - Ah - f); |
| 303 |
end; |
| 304 |
siRect: |
| 305 |
FPickRect := Rect(Aw, Ah, width - 2*Aw + 1, height - Ah); |
| 306 |
end; |
| 307 |
lyVertical: |
| 308 |
case FSelIndicator of |
| 309 |
siArrows: |
| 310 |
case FPlacement of |
| 311 |
spAfter : FPickRect := Rect(0, Aw, Width - Ah - f, Height - Aw); |
| 312 |
spBefore : FPickRect := Rect(Ah + f, Aw, Width, Height - Aw); |
| 313 |
spBoth : FPickRect := Rect(Ah + f, Aw, Width - Ah - f, Height - Aw); |
| 314 |
end; |
| 315 |
siRect: |
| 316 |
FPickRect := Rect(Ah, Aw, width - 5, height - 2*Aw + 1); |
| 317 |
end; |
| 318 |
end; |
| 319 |
end; |
| 320 |
|
| 321 |
procedure TmbTrackBarPicker.CMGotFocus( |
| 322 |
var Message: {$IFDEF FPC}TLMessage{$ELSE}TCMGotFocus{$ENDIF}); |
| 323 |
begin |
| 324 |
inherited; |
| 325 |
Invalidate; |
| 326 |
end; |
| 327 |
|
| 328 |
procedure TmbTrackBarPicker.CMLostFocus( |
| 329 |
var Message: {$IFDEF FPC}TLMessage{$ELSE}TCMLostFocus{$ENDIF}); |
| 330 |
begin |
| 331 |
inherited; |
| 332 |
Invalidate; |
| 333 |
end; |
| 334 |
|
| 335 |
{ AWidth and AHeight are seen for horizontal arrangement of the bar } |
| 336 |
procedure TmbTrackbarPicker.CreateGradient; |
| 337 |
var |
| 338 |
i,j: integer; |
| 339 |
col: TColor; |
| 340 |
fpcol: TFPColor; |
| 341 |
intfimg: TLazIntfImage; |
| 342 |
imgHandle, imgMaskHandle: HBitmap; |
| 343 |
begin |
| 344 |
if FBufferBmp = nil then |
| 345 |
exit; |
| 346 |
|
| 347 |
intfimg := TLazIntfImage.Create(0, 0); |
| 348 |
try |
| 349 |
if Layout = lyHorizontal then |
| 350 |
begin |
| 351 |
FBufferBmp.Width := FGradientWidth; |
| 352 |
FBufferBmp.Height := FGradientHeight; |
| 353 |
intfImg.LoadFromBitmap(FBufferBmp.Handle, FBufferBmp.MaskHandle); |
| 354 |
|
| 355 |
for i := 0 to FBufferBmp.Width-1 do |
| 356 |
begin |
| 357 |
col := GetGradientColor(i); |
| 358 |
if WebSafe then col := GetWebSafe(col); |
| 359 |
fpcol := TColorToFPColor(col); |
| 360 |
for j := 0 to FBufferBmp.Height-1 do |
| 361 |
intfImg.Colors[i, j] := fpcol; |
| 362 |
end; |
| 363 |
end |
| 364 |
else |
| 365 |
begin |
| 366 |
FBufferBmp.Width := FGradientHeight; |
| 367 |
FBufferBmp.Height := FGradientWidth; |
| 368 |
intfImg.LoadFromBitmap(FBufferBmp.Handle, FBufferBmp.MaskHandle); |
| 369 |
for j := 0 to FBufferBmp.Height-1 do |
| 370 |
begin |
| 371 |
col := GetGradientColor(FBufferBmp.Height - 1 - j); |
| 372 |
if WebSafe then col := GetWebSafe(col); |
| 373 |
fpcol := TColorToFPColor(col); |
| 374 |
for i := 0 to FBufferBmp.Width-1 do |
| 375 |
intfImg.Colors[i, j] := fpcol; |
| 376 |
end; |
| 377 |
end; |
| 378 |
|
| 379 |
intfimg.CreateBitmaps(imgHandle, imgMaskHandle, false); |
| 380 |
FBufferBmp.Handle := imgHandle; |
| 381 |
FBufferBmp.MaskHandle := imgMaskHandle; |
| 382 |
finally |
| 383 |
intfImg.Free; |
| 384 |
end; |
| 385 |
end; |
| 386 |
|
| 387 |
procedure TmbTrackbarPicker.CreateWnd; |
| 388 |
begin |
| 389 |
inherited; |
| 390 |
CreateGradient; |
| 391 |
end; |
| 392 |
|
| 393 |
function TmbTrackbarPicker.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; |
| 394 |
MousePos: TPoint): Boolean; |
| 395 |
begin |
| 396 |
Result := inherited DoMouseWheel(Shift, WheelDelta, MousePos); |
| 397 |
if not Result then |
| 398 |
begin |
| 399 |
Result := True; |
| 400 |
if WheelDelta > 0 then |
| 401 |
Execute(TBA_WheelUp) |
| 402 |
else |
| 403 |
Execute(TBA_WheelDown); |
| 404 |
DoChange; |
| 405 |
end; |
| 406 |
end; |
| 407 |
|
| 408 |
procedure TmbTrackBarPicker.DrawFrames; |
| 409 |
var |
| 410 |
flags: cardinal; |
| 411 |
R: TRect; |
| 412 |
i: integer; |
| 413 |
begin |
| 414 |
flags := 0; |
| 415 |
if (FBorderStyle = bsNone) |
| 416 |
{ always false, since TBevelWidth type is always > 0 } |
| 417 |
{or (FBevelWidth = 0)} then |
| 418 |
Exit; |
| 419 |
case FBevelInner of |
| 420 |
bvNone: flags := 0; |
| 421 |
bvRaised: flags := BDR_RAISEDINNER; |
| 422 |
bvLowered: flags := BDR_SUNKENINNER; |
| 423 |
bvSpace: flags := BDR_INNER; |
| 424 |
end; |
| 425 |
case FBevelOuter of |
| 426 |
bvRaised: flags := flags or BDR_RAISEDOUTER; |
| 427 |
bvLowered: flags := flags or BDR_SUNKENOUTER; |
| 428 |
bvSpace: flags := flags or BDR_OUTER; |
| 429 |
end; |
| 430 |
R := FPickRect; |
| 431 |
InflateRect(R, -FBevelWidth + 1, -FBevelWidth + 1); |
| 432 |
for i := 0 to FBevelWidth do |
| 433 |
begin |
| 434 |
DrawEdge(Canvas.Handle, R, flags, BF_RECT); |
| 435 |
InflateRect(R, 1, 1); |
| 436 |
end; |
| 437 |
end; |
| 438 |
|
| 439 |
procedure TmbTrackBarPicker.DrawMarker(p: integer); |
| 440 |
var |
| 441 |
x, y: integer; |
| 442 |
R: TRect; |
| 443 |
begin |
| 444 |
case FSelIndicator of |
| 445 |
siRect: |
| 446 |
begin |
| 447 |
case FLayout of |
| 448 |
lyHorizontal: |
| 449 |
begin |
| 450 |
p := p + Aw; |
| 451 |
R := Rect(p - 2, 2, p + 3, Height - 2); |
| 452 |
end; |
| 453 |
lyVertical: |
| 454 |
begin |
| 455 |
p := p + Aw; |
| 456 |
R := Rect(2, p - 2, Width - 2, p + 3); |
| 457 |
end; |
| 458 |
end; |
| 459 |
Canvas.Pen.Mode := pmNot; |
| 460 |
Canvas.Brush.Style := bsClear; |
| 461 |
Canvas.Rectangle(R); |
| 462 |
Canvas.Brush.Style := bsSolid; |
| 463 |
Canvas.Pen.Mode := pmCopy; |
| 464 |
end; |
| 465 |
|
| 466 |
siArrows: |
| 467 |
begin |
| 468 |
if not FNewArrowStyle then |
| 469 |
begin |
| 470 |
if Focused or (csDesigning in ComponentState) then |
| 471 |
begin |
| 472 |
Canvas.Brush.Color := clBlack; |
| 473 |
Canvas.Pen.Color := clBlack; |
| 474 |
end |
| 475 |
else |
| 476 |
begin |
| 477 |
Canvas.Brush.Color := clGray; |
| 478 |
Canvas.Pen.Color := clGray; |
| 479 |
end; |
| 480 |
end |
| 481 |
else |
| 482 |
begin |
| 483 |
Canvas.Brush.Color := clWindow; |
| 484 |
Canvas.Pen.Color := clBtnShadow; |
| 485 |
end; |
| 486 |
|
| 487 |
if FLayout = lyHorizontal then |
| 488 |
begin |
| 489 |
x := p + Aw; |
| 490 |
if x < Aw then x := Aw; |
| 491 |
if x > Width - Aw then x := Width - Aw; |
| 492 |
case FPlacement of |
| 493 |
spAfter: |
| 494 |
begin |
| 495 |
y := Height - Aw - 1; |
| 496 |
if not FNewArrowStyle then |
| 497 |
Canvas.Polygon([Point(x, y), Point(x - 4, y + 6), Point(x + 4, y + 6)]) |
| 498 |
else |
| 499 |
Canvas.Polygon([Point(x, y), Point(x - 4, y + 4), Point(x - 4, y + 6), |
| 500 |
Point(x - 3, y + 7), Point(x + 3, y + 7), Point(x + 4, y + 6), |
| 501 |
Point(x + 4, y + 4)]); |
| 502 |
end; |
| 503 |
spBefore: |
| 504 |
begin |
| 505 |
y := Aw; |
| 506 |
if not FNewArrowStyle then |
| 507 |
Canvas.Polygon([Point(x, y), Point(x - 4, y - 6), Point(x +4, y - 6) |
| 508 |
]) |
| 509 |
else |
| 510 |
Canvas.Polygon([Point(x, y), Point(x + 4, y - 4), Point(x + 4, y - 6), |
| 511 |
Point(x + 3, y - 7), Point(x - 3, y - 7), Point(x - 4, y - 6), |
| 512 |
Point(x - 4, y - 4) ]); |
| 513 |
end; |
| 514 |
spBoth: |
| 515 |
begin |
| 516 |
y := Height - Aw - 1; |
| 517 |
if not FNewArrowStyle then |
| 518 |
Canvas.Polygon([Point(x, y), Point(x - 4, y + 6), Point(x + 4, y + 6) ]) |
| 519 |
else |
| 520 |
Canvas.Polygon([Point(x, y), Point(x - 4, y + 4), Point(x - 4, y + 6), |
| 521 |
Point(x - 3, y + 7), Point(x + 3, y + 7), Point(x + 4, y + 6), |
| 522 |
Point(x + 4, y + 4) ]); |
| 523 |
y := Aw; |
| 524 |
if not FNewArrowStyle then |
| 525 |
Canvas.Polygon([Point(x, y), Point(x - 4, y - 6), Point(x +4, y - 6) ]) |
| 526 |
else |
| 527 |
Canvas.Polygon([Point(x, y), Point(x + 4, y - 4), Point(x + 4, y - 6), |
| 528 |
Point(x + 3, y - 7), Point(x - 3, y - 7), Point(x - 4, y - 6), |
| 529 |
Point(x - 4, y - 4) ]); |
| 530 |
end; |
| 531 |
end; // case FPlacement |
| 532 |
end // if FLayout |
| 533 |
else |
| 534 |
begin |
| 535 |
if not FNewArrowStyle then |
| 536 |
y := p + Aw |
| 537 |
else |
| 538 |
y := p + Aw - 1; |
| 539 |
if y < Aw then y := Aw; |
| 540 |
if y > Height - Aw - 1 then y := Height - Aw - 1; |
| 541 |
case FPlacement of |
| 542 |
spAfter: |
| 543 |
begin |
| 544 |
x := width - Aw - 1; |
| 545 |
if not FNewArrowStyle then |
| 546 |
Canvas.Polygon([Point(x, y), Point(x + 6, y - 4), Point(x + 6, y + 4)]) |
| 547 |
else |
| 548 |
Canvas.Polygon([Point(x, y), Point(x + 4, y - 4), Point(x + 6, y - 4), |
| 549 |
Point(x + 7, y - 3), Point(x + 7, y + 3), Point(x + 6, y + 4), |
| 550 |
Point(x + 4, y + 4)]); |
| 551 |
end; |
| 552 |
spBefore: |
| 553 |
begin |
| 554 |
x := Aw; |
| 555 |
if not FNewArrowStyle then |
| 556 |
Canvas.Polygon([Point(x, y), Point(x - 6, y - 4), Point(x - 6, y + 4)]) |
| 557 |
else |
| 558 |
Canvas.Polygon([Point(x, y), Point(x - 4, y - 4), Point(x - 6, y - 4), |
| 559 |
Point(x - 7, y + 1 - 4), Point(x - 7, y + 3), Point(x - 6, y + 4), |
| 560 |
Point(x - 4, y + 4)]); |
| 561 |
end; |
| 562 |
spBoth: |
| 563 |
begin |
| 564 |
x := width - Aw - 1; |
| 565 |
if not FNewArrowStyle then |
| 566 |
Canvas.Polygon([Point(x, y), Point(x + 6, y - 4), Point(x + 6, y + 4)]) |
| 567 |
else |
| 568 |
Canvas.Polygon([Point(x, y), Point(x + 4, y - 4), Point(x + 6, y - 4), |
| 569 |
Point(x + 7, y - 3), Point(x + 7, y + 3), Point(x + 6, y + 4), |
| 570 |
Point(x + 4, y + 4)]); |
| 571 |
x := Aw; |
| 572 |
if not FNewArrowStyle then |
| 573 |
Canvas.Polygon([Point(x, y), Point(x - 6, y - 4), Point(x - 6, y + 4)]) |
| 574 |
else |
| 575 |
Canvas.Polygon([Point(x, y), Point(x - 4, y - 4), Point(x - 6, y - 4), |
| 576 |
Point(x - 7, y + 1 - 4), Point(x - 7, y + 3), Point(x - 6, y + 4), |
| 577 |
Point(x - 4, y + 4)]); |
| 578 |
end; |
| 579 |
end; // case FPlacement |
| 580 |
end; // else (if FLayout) |
| 581 |
end; // siArrow |
| 582 |
end; // case FSelIndicator |
| 583 |
end; |
| 584 |
|
| 585 |
procedure TmbTrackBarPicker.Execute(tbaAction: integer); |
| 586 |
begin |
| 587 |
case tbaAction of |
| 588 |
TBA_Paint : Canvas.StretchDraw(FPickRect, FBufferBmp); |
| 589 |
TBA_RedoBMP : CreateGradient; |
| 590 |
// Rest handled in descendants |
| 591 |
end; |
| 592 |
end; |
| 593 |
|
| 594 |
function TmbTrackBarPicker.GetArrowPos: integer; |
| 595 |
begin |
| 596 |
Result := 0; |
| 597 |
//handled in descendants |
| 598 |
end; |
| 599 |
|
| 600 |
function TmbTrackBarPicker.GetHintPos(X, Y: Integer): TPoint; |
| 601 |
begin |
| 602 |
case FLayout of |
| 603 |
lyHorizontal: |
| 604 |
Result := Point(X - 8, Height + 2); |
| 605 |
lyVertical: |
| 606 |
Result := Point(Width + 2, Y - 8); |
| 607 |
end; |
| 608 |
end; |
| 609 |
|
| 610 |
function TmbTrackBarPicker.GetHintStr(X, Y: Integer): string; |
| 611 |
begin |
| 612 |
Result := inherited GetHintStr(X, Y); |
| 613 |
if Result = '' then |
| 614 |
Result := ReplaceFlags(FHintFormat, ['%value', '%h', '%s', '%l', '%v', '%c', |
| 615 |
'%m', '%y', '%k', '%r', '%g', '%b'], GetSelectedValue); |
| 616 |
end; |
| 617 |
|
| 618 |
procedure TmbTrackBarPicker.KeyDown(var Key: Word; Shift: TShiftState); |
| 619 |
var |
| 620 |
eraseKey: Boolean; |
| 621 |
begin |
| 622 |
eraseKey := true; |
| 623 |
case Key of |
| 624 |
VK_UP: |
| 625 |
if FLayout = lyHorizontal then |
| 626 |
eraseKey := false |
| 627 |
else |
| 628 |
begin |
| 629 |
if not (ssCtrl in Shift) then |
| 630 |
Execute(TBA_VKUp) |
| 631 |
else |
| 632 |
Execute(TBA_VKCtrlUp); |
| 633 |
DoChange; |
| 634 |
end; |
| 635 |
VK_LEFT: |
| 636 |
if FLayout = lyVertical then |
| 637 |
eraseKey := false |
| 638 |
else |
| 639 |
begin |
| 640 |
if not (ssCtrl in Shift) then |
| 641 |
Execute(TBA_VKLeft) |
| 642 |
else |
| 643 |
Execute(TBA_VKCtrlLeft); |
| 644 |
DoChange; |
| 645 |
end; |
| 646 |
VK_RIGHT: |
| 647 |
if FLayout = lyVertical then |
| 648 |
eraseKey := false |
| 649 |
else |
| 650 |
begin |
| 651 |
if not (ssCtrl in Shift) then |
| 652 |
Execute(TBA_VKRight) |
| 653 |
else |
| 654 |
Execute(TBA_VKCtrlRight); |
| 655 |
DoChange; |
| 656 |
end; |
| 657 |
VK_DOWN: |
| 658 |
if FLayout = lyHorizontal then |
| 659 |
eraseKey := false |
| 660 |
else |
| 661 |
begin |
| 662 |
if not (ssCtrl in Shift) then |
| 663 |
Execute(TBA_VKDown) |
| 664 |
else |
| 665 |
Execute(TBA_VKCtrlDown); |
| 666 |
DoChange; |
| 667 |
end |
| 668 |
else |
| 669 |
eraseKey := false; |
| 670 |
end; // case |
| 671 |
|
| 672 |
if eraseKey then |
| 673 |
Key := 0; |
| 674 |
|
| 675 |
inherited; |
| 676 |
end; |
| 677 |
|
| 678 |
procedure TmbTrackBarPicker.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); |
| 679 |
begin |
| 680 |
if Button = mbLeft then |
| 681 |
begin |
| 682 |
SetFocus; |
| 683 |
mx := X; |
| 684 |
my := Y; |
| 685 |
FArrowPos := IfThen(FLayout = lyHorizontal, XToArrowPos(X), YToArrowPos(Y)); |
| 686 |
Execute(TBA_MouseDown); |
| 687 |
end; |
| 688 |
inherited; |
| 689 |
end; |
| 690 |
|
| 691 |
procedure TmbTrackBarPicker.MouseLeave; |
| 692 |
begin |
| 693 |
inherited; |
| 694 |
FHintShown := false; |
| 695 |
end; |
| 696 |
|
| 697 |
procedure TmbTrackBarPicker.MouseMove(Shift: TShiftState; X, Y: Integer); |
| 698 |
begin |
| 699 |
if ssLeft in shift then |
| 700 |
begin |
| 701 |
mx := X; |
| 702 |
my := Y; |
| 703 |
FArrowPos := IfThen(FLayout = lyHorizontal, XToArrowPos(X), YToArrowPos(Y)); |
| 704 |
Execute(TBA_MouseMove); |
| 705 |
end; |
| 706 |
inherited; |
| 707 |
end; |
| 708 |
|
| 709 |
procedure TmbTrackBarPicker.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); |
| 710 |
begin |
| 711 |
if Button = mbLeft then |
| 712 |
begin |
| 713 |
mx := X; |
| 714 |
my := Y; |
| 715 |
FArrowPos := IfThen(FLayout = lyHorizontal, XToArrowPos(X), YToArrowPos(Y)); |
| 716 |
Execute(TBA_MouseUp); |
| 717 |
end; |
| 718 |
|
| 719 |
inherited; |
| 720 |
end; |
| 721 |
|
| 722 |
procedure TmbTrackBarPicker.Paint; |
| 723 |
begin |
| 724 |
CalcPickRect; |
| 725 |
PaintParentBack(Canvas); |
| 726 |
FArrowPos := GetArrowPos; |
| 727 |
Execute(TBA_Paint); |
| 728 |
if FBorderStyle <> bsNone then |
| 729 |
DrawFrames; |
| 730 |
DrawMarker(FArrowPos); |
| 731 |
{ |
| 732 |
if FDoChange then |
| 733 |
begin |
| 734 |
if Assigned(OnChange) then OnChange(Self); |
| 735 |
FDoChange := false; |
| 736 |
end; |
| 737 |
} |
| 738 |
end; |
| 739 |
|
| 740 |
procedure TmbTrackBarPicker.Resize; |
| 741 |
begin |
| 742 |
inherited; |
| 743 |
Execute(TBA_Resize); |
| 744 |
end; |
| 745 |
|
| 746 |
procedure TmbTrackBarPicker.SetBevelInner(Value: TBevelCut); |
| 747 |
begin |
| 748 |
if FBevelInner <> Value then |
| 749 |
begin |
| 750 |
FBevelInner := Value; |
| 751 |
Invalidate; |
| 752 |
end; |
| 753 |
end; |
| 754 |
|
| 755 |
procedure TmbTrackBarPicker.SetBevelOuter(Value: TBevelCut); |
| 756 |
begin |
| 757 |
if FBevelOuter <> Value then |
| 758 |
begin |
| 759 |
FBevelOuter := Value; |
| 760 |
Invalidate; |
| 761 |
end; |
| 762 |
end; |
| 763 |
|
| 764 |
procedure TmbTrackBarPicker.SetBorderStyle(Value: TBorderStyle); |
| 765 |
begin |
| 766 |
if FBorderStyle <> Value then |
| 767 |
begin |
| 768 |
FBorderStyle := Value; |
| 769 |
Invalidate; |
| 770 |
end; |
| 771 |
end; |
| 772 |
|
| 773 |
procedure TmbTrackBarPicker.SetBevelWidth(Value: TBevelWidth); |
| 774 |
begin |
| 775 |
if FBevelWidth <> Value then |
| 776 |
begin |
| 777 |
FBevelWidth := Value; |
| 778 |
Invalidate; |
| 779 |
end; |
| 780 |
end; |
| 781 |
|
| 782 |
{ IMPORTANT: If pickers are created at designtime the layout must be set before |
| 783 |
defining the picker width and height because changing the layout will flip the |
| 784 |
bounding rectangle !!! } |
| 785 |
procedure TmbTrackBarPicker.SetLayout(Value: TTrackBarLayout); |
| 786 |
begin |
| 787 |
if FLayout <> Value then |
| 788 |
begin |
| 789 |
FLayout := Value; |
| 790 |
if not (csLoading in ComponentState) then |
| 791 |
SetBounds(Left, Top, Height, Width); // flip rectangle |
| 792 |
Execute(TBA_RedoBMP); |
| 793 |
Invalidate; |
| 794 |
end; |
| 795 |
end; |
| 796 |
|
| 797 |
procedure TmbTrackBarPicker.SetNewArrowStyle(s: boolean); |
| 798 |
begin |
| 799 |
if FNewArrowStyle <> s then |
| 800 |
begin |
| 801 |
FNewArrowStyle := s; |
| 802 |
Invalidate; |
| 803 |
end; |
| 804 |
end; |
| 805 |
|
| 806 |
procedure TmbTrackBarPicker.SetPlacement(Value: TSliderPlacement); |
| 807 |
begin |
| 808 |
if FPlacement <> Value then |
| 809 |
begin |
| 810 |
FPlacement := Value; |
| 811 |
Invalidate; |
| 812 |
end; |
| 813 |
end; |
| 814 |
|
| 815 |
procedure TmbTrackBarPicker.SetSelIndicator(Value: TSelIndicator); |
| 816 |
begin |
| 817 |
if FSelIndicator <> Value then |
| 818 |
begin |
| 819 |
FSelIndicator := Value; |
| 820 |
Invalidate; |
| 821 |
end; |
| 822 |
end; |
| 823 |
|
| 824 |
procedure TmbTrackBarPicker.SetWebSafe(s: boolean); |
| 825 |
begin |
| 826 |
if FWebSafe <> s then |
| 827 |
begin |
| 828 |
FWebSafe := s; |
| 829 |
Execute(TBA_RedoBMP); |
| 830 |
Invalidate; |
| 831 |
end; |
| 832 |
end; |
| 833 |
|
| 834 |
function TmbTrackBarPicker.XToArrowPos(p: integer): integer; |
| 835 |
var |
| 836 |
pos: integer; |
| 837 |
begin |
| 838 |
pos := p - Aw; |
| 839 |
if pos < 0 then pos := 0; |
| 840 |
if pos > Width - Aw - 1 then pos := Width - Aw - 1; |
| 841 |
Result := pos; |
| 842 |
end; |
| 843 |
|
| 844 |
function TmbTrackBarPicker.YToArrowPos(p: integer): integer; |
| 845 |
var |
| 846 |
pos: integer; |
| 847 |
begin |
| 848 |
pos := p - Aw; |
| 849 |
if pos < 0 then pos := 0; |
| 850 |
if pos > Height - Aw - 1 then pos := Height - Aw - 1; |
| 851 |
Result := pos; |
| 852 |
end; |
| 853 |
|
| 854 |
|
| 855 |
{ TmbHSLVTrackbarPicker } |
| 856 |
|
| 857 |
constructor TmbHSLVTrackbarPicker.Create(AOwner: TComponent); |
| 858 |
begin |
| 859 |
inherited Create(AOwner); |
| 860 |
FBrightnessMode := bmLuminance; |
| 861 |
FMaxHue := 360; |
| 862 |
FMaxSat := 255; |
| 863 |
FMaxVal := 255; |
| 864 |
FMaxLum := 255; |
| 865 |
end; |
| 866 |
|
| 867 |
procedure TmbHSLVTrackbarPicker.ColorToHSLV(c: TColor; var H, S, L, V: Double); |
| 868 |
begin |
| 869 |
case FBrightnessMode of |
| 870 |
bmLuminance : ColorToHSL(c, H, S, L); |
| 871 |
bmValue : ColorToHSV(c, H, S, V); |
| 872 |
end; |
| 873 |
end; |
| 874 |
|
| 875 |
function TmbHSLVTrackbarPicker.GetHue: Integer; |
| 876 |
begin |
| 877 |
Result := round(FHue * FMaxHue); |
| 878 |
end; |
| 879 |
|
| 880 |
function TmbHSLVTrackbarPicker.GetLum: Integer; |
| 881 |
begin |
| 882 |
Result := round(FLum * FMaxLum); |
| 883 |
end; |
| 884 |
|
| 885 |
function TmbHSLVTrackbarPicker.GetSat: Integer; |
| 886 |
begin |
| 887 |
Result := round(FSat * FMaxSat); |
| 888 |
end; |
| 889 |
|
| 890 |
function TmbHSLVTrackbarPicker.GetSelectedColor: TColor; |
| 891 |
begin |
| 892 |
Result := HSLVtoColor(FHue, FSat, FLum, FVal); |
| 893 |
end; |
| 894 |
|
| 895 |
function TmbHSLVTrackbarPicker.GetVal: Integer; |
| 896 |
begin |
| 897 |
Result := round(FVal * FMaxVal); |
| 898 |
end; |
| 899 |
|
| 900 |
function TmbHSLVTrackbarPicker.HSLVtoColor(H, S, L, V: Double): TColor; |
| 901 |
begin |
| 902 |
case FBrightnessMode of |
| 903 |
bmLuminance : Result := HSLToColor(H, S, L); |
| 904 |
bmValue : Result := HSVtoColor(H, S, V); |
| 905 |
end; |
| 906 |
if WebSafe then |
| 907 |
Result := GetWebSafe(Result); |
| 908 |
end; |
| 909 |
|
| 910 |
procedure TmbHSLVTrackbarPicker.SetBrightnessMode(AMode: TBrightnessMode); |
| 911 |
var |
| 912 |
c: TColor; |
| 913 |
//S, L, V: Double; |
| 914 |
begin |
| 915 |
c := HSLVtoColor(FHue, FSat, FLum, FVal); |
| 916 |
FBrightnessMode := AMode; |
| 917 |
(* |
| 918 |
ColorToHSLV(c, FHue, S, L, V); |
| 919 |
SetRelSat(S); |
| 920 |
case AMode of |
| 921 |
bmLuminance: SetRelLum(L); |
| 922 |
bmValue : SetRelVal(V); |
| 923 |
end; |
| 924 |
*) |
| 925 |
ColorToHSLV(c, FHue, FSat, FLum, FVal); |
| 926 |
CreateGradient; |
| 927 |
Invalidate; |
| 928 |
DoChange; |
| 929 |
end; |
| 930 |
|
| 931 |
procedure TmbHSLVTrackbarPicker.SetHue(H: Integer); |
| 932 |
begin |
| 933 |
SetRelHue(H / FMaxHue); |
| 934 |
end; |
| 935 |
|
| 936 |
procedure TmbHSLVTrackbarPicker.SetLum(L: Integer); |
| 937 |
begin |
| 938 |
SetRelLum(L / FMaxLum); |
| 939 |
end; |
| 940 |
|
| 941 |
procedure TmbHSLVTrackbarPicker.SetMaxHue(h: Integer); |
| 942 |
begin |
| 943 |
if h = FMaxHue then |
| 944 |
exit; |
| 945 |
FMaxHue := h; |
| 946 |
FGradientWidth := FMaxHue; // we don't want to access H=360, i.e. don't use FMaxHue+1 |
| 947 |
//CreateGradient; |
| 948 |
Invalidate; |
| 949 |
end; |
| 950 |
|
| 951 |
procedure TmbHSLVTrackbarPicker.SetMaxLum(L: Integer); |
| 952 |
begin |
| 953 |
if L = FMaxLum then |
| 954 |
exit; |
| 955 |
FMaxLum := L; |
| 956 |
if FBrightnessMode = bmLuminance then begin |
| 957 |
//CreateGradient; |
| 958 |
Invalidate; |
| 959 |
end; |
| 960 |
end; |
| 961 |
|
| 962 |
procedure TmbHSLVTrackbarPicker.SetMaxSat(S: Integer); |
| 963 |
begin |
| 964 |
if S = FMaxSat then |
| 965 |
exit; |
| 966 |
FMaxSat := S; |
| 967 |
//CreateGradient; |
| 968 |
Invalidate; |
| 969 |
end; |
| 970 |
|
| 971 |
procedure TmbHSLVTrackbarPicker.SetMaxVal(V: Integer); |
| 972 |
begin |
| 973 |
if V = FMaxVal then |
| 974 |
exit; |
| 975 |
FMaxVal := V; |
| 976 |
if FBrightnessMode = bmValue then begin |
| 977 |
//CreateGradient; |
| 978 |
Invalidate; |
| 979 |
end; |
| 980 |
end; |
| 981 |
|
| 982 |
procedure TmbHSLVTrackbarPicker.SetRelHue(H: Double); |
| 983 |
begin |
| 984 |
Clamp(H, 0, 1 - 1/FMaxHue); // don't go up to 360 because this will flip back to the start |
| 985 |
if (FHue <> H) then |
| 986 |
begin |
| 987 |
FHue := H; |
| 988 |
CreateGradient; |
| 989 |
Invalidate; |
| 990 |
DoChange; |
| 991 |
end; |
| 992 |
end; |
| 993 |
|
| 994 |
procedure TmbHSLVTrackbarPicker.SetRelLum(L: Double); |
| 995 |
begin |
| 996 |
Clamp(L, 0, 1.0); |
| 997 |
if (FLum <> L) then |
| 998 |
begin |
| 999 |
FLum := L; |
| 1000 |
if BrightnessMode = bmLuminance then begin |
| 1001 |
CreateGradient; |
| 1002 |
Invalidate; |
| 1003 |
end; |
| 1004 |
DoChange; |
| 1005 |
end; |
| 1006 |
end; |
| 1007 |
|
| 1008 |
procedure TmbHSLVTrackbarPicker.SetRelSat(S: Double); |
| 1009 |
begin |
| 1010 |
Clamp(S, 0, 1.0); |
| 1011 |
if FSat <> S then |
| 1012 |
begin |
| 1013 |
FSat := S; |
| 1014 |
CreateGradient; |
| 1015 |
Invalidate; |
| 1016 |
DoChange; |
| 1017 |
end; |
| 1018 |
end; |
| 1019 |
|
| 1020 |
procedure TmbHSLVTrackbarPicker.SetRelVal(V: Double); |
| 1021 |
begin |
| 1022 |
Clamp(V, 0, 1.0); |
| 1023 |
if FVal <> V then |
| 1024 |
begin |
| 1025 |
FVal := V; |
| 1026 |
if BrightnessMode = bmValue then |
| 1027 |
begin |
| 1028 |
CreateGradient; |
| 1029 |
Invalidate; |
| 1030 |
end; |
| 1031 |
DoChange; |
| 1032 |
end; |
| 1033 |
end; |
| 1034 |
|
| 1035 |
procedure TmbHSLVTrackbarPicker.SetSat(S: Integer); |
| 1036 |
begin |
| 1037 |
SetRelSat(S / FMaxSat); |
| 1038 |
end; |
| 1039 |
|
| 1040 |
procedure TmbHSLVTrackbarPicker.SetVal(V: Integer); |
| 1041 |
begin |
| 1042 |
SetRelVal(V / FMaxVal); |
| 1043 |
end; |
| 1044 |
|
| 1045 |
end. |