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:
| procedure TGradientPanel.DrawGradient(ACanvas: TCanvas; Rect: TRect; Horicontal: Boolean; Colors: array of TColor); type RGBArray = array[0..2] of Byte; var x, y, z, stelle, mx, bis, faColorsh, mass: Integer; Faktor: double; A: RGBArray; B: array of RGBArray; merkw: integer; merks: TPenStyle; merkp: TColor; begin mx := High(Colors); if mx > 0 then begin if Horicontal then mass := Rect.Right - Rect.Left else mass := Rect.Bottom - Rect.Top; SetLength(b, mx + 1); for x := 0 to mx do begin Colors[x] := ColorToRGB(Colors[x]); b[x][0] := GetRValue(Colors[x]); b[x][1] := GetGValue(Colors[x]); b[x][2] := GetBValue(Colors[x]); end; merkw := ACanvas.Pen.Width; merks := ACanvas.Pen.Style; merkp := ACanvas.Pen.Color; ACanvas.Pen.Width := 1; ACanvas.Pen.Style := psSolid; faColorsh := Round(mass / mx); for y := 0 to mx - 1 do begin if y = mx - 1 then bis := mass - y * faColorsh - 1 else bis := faColorsh; for x := 0 to bis do begin Stelle := x + y * faColorsh; faktor := x / bis; for z := 0 to 3 do a[z] := Trunc(b[y][z] + ((b[y + 1][z] - b[y][z]) * Faktor)); ACanvas.Pen.Color := RGB(a[0], a[1], a[2]); if Horicontal then begin ACanvas.MoveTo(Rect.Left + Stelle, Rect.Top); ACanvas.LineTo(Rect.Left + Stelle, Rect.Bottom); end else begin ACanvas.MoveTo(Rect.Left, Rect.Top + Stelle); ACanvas.LineTo(Rect.Right, Rect.Top + Stelle); end; end; end; b := nil; ACanvas.Pen.Width := merkw; ACanvas.Pen.Style := merks; ACanvas.Pen.Color := merkp; end else raise EMathError.Create('Error by colors'); end;
procedure TGradientPanel.Paint; var R, SR: TRect; Offset: integer; Buffer: TBitmap; TargetCanvas: TCanvas; begin buffer:=nil; try if BufferedDraw then begin Buffer := TBitmap.Create; Buffer.Width := Width; Buffer.Height := Height; TargetCanvas := Buffer.Canvas; end else begin Buffer := nil; TargetCanvas := Canvas; end; R := ClientRect; TargetCanvas.Brush.Color := clWindow; TargetCanvas.FillRect(R);
DrawGradient(TargetCanvas, R, Honrizontal, [StartColor,StartColor, EndColor]);
DrawGradient(TargetCanvas, Rect(R.Left, R.Bottom-5, R.Right, R.Bottom), true, [FWStartColor,FWMiddleColor,FWEndColor]);
Inc(R.Left, 20); Dec(R.Right, 60); Inc(R.Top, 8); Dec(R.Bottom, 5); SetBkMode(TargetCanvas.Handle,TRANSPARENT);
TargetCanvas.Font.Assign(FTitleCaptionFont); DrawText(TargetCanvas.Handle, PChar(FTitleCaption), length(fTitleCaption), R, DT_SINGLELINE); inc(R.Top, TargetCanvas.TextHeight('Hy')); inc(R.Left, 20);
TargetCanvas.Font.Assign(FHintCaptionFont); SR := R; DrawText(TargetCanvas.Handle, PChar(FHintCaption), length(FHintCaption), SR, DT_WORDBREAK or DT_CALCRECT);
OffsetRect(SR, 0, (R.Bottom - SR.Bottom) div 2); DrawText(TargetCanvas.Handle, PChar(FHintCaption), length(FHintCaption), SR, DT_WORDBREAK);
if (fShowArt=ShowIcon)and(Assigned(fIcon)) then begin R := ClientRect; Offset := (Height - fIcon.Height) div 2; DrawIcon(TargetCanvas.Handle, R.Right-FIcon.Width-Offset, R.Top+Offset, fIcon.Handle); end else begin R := ClientRect; SR := Rect(R.Right-50, R.Top+5, R.Right-5, R.Bottom-5 ); TargetCanvas.Font.Assign(fSymbolFont); DrawText(TargetCanvas.Handle, PChar(fSymbol), length(fSymbol), SR, DT_SINGLELINE or DT_CENTER or DT_VCENTER); if FShowSymbolEdges then DrawEdge(TargetCanvas.Handle, SR, EDGE_ETCHED, BF_BOTTOM or BF_RIGHT or BF_LEFT or BF_TOP ); end; if BufferedDraw then BitBlt(Canvas.Handle, 0, 0, Width, Height, TargetCanvas.Handle, 0, 0, SRCCOPY); finally if BufferedDraw then Buffer.Free; end; end; |