| Autor |
Beitrag |
Bremi80
      
Beiträge: 37
Win XP
Delphi 5 Pro/Std
|
Verfasst: Do 05.01.06 09:28
Hallo zusammen.
Ich habe diese Frage zwar schonmal so ähnlich gestellt, aber irgendwie hatte ich nicht mehr wirklich Zeit, daß richtig auszuprobieren. Allerdings ist dieses Problem für mich noch nicht gelöst.
Also: Ich habe meine Komponente, eine LED-Box zur Anzeige Boolscher Werte, mit der Erweiterung zur Checkbox. Wie kann ich jetzt das Bild der LED-Box in einen Zeichenpuffer (TBitmap, o.ä.) schreiben, so daß ich in der Paint-Methode nur noch das ganze kopieren brauche? Ich hab's mit CopyRect versucht, aber dann erscheint die Komponente gar nicht. Draufklicken kann ich trotzdem, zumindest im Designmodus, dann erscheint ein Rahmen.
Fragen über Fragen...
Gruß, Daniel
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: 225: 226: 227:
| unit LEDBox;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Math;
type TLEDBoxType = (btLED,btCheckbox); TLEDBox = class(TCustomControl) private FChecked : Boolean; FonColorFrom : TColor; FOnColorTo : TColor; FOffColorFrom : TColor; FOffColorTo : TColor; FType : TLEDBoxType; procedure SetChecked(newState : Boolean); procedure SetOnColorFrom(newColor : TColor); procedure SetOnColorTo(newColor : TColor); procedure SetOffColorFrom(newColor: TColor); procedure SetOffColorTo(newColor : TColor); procedure SetType(newType : TLEDBoxType);
protected procedure Paint; override; procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);override;
public constructor Create(AOwner : TComponent); override; destructor Destroy; override;
published property Checked:Boolean read FChecked write SetChecked; property OnColorFrom:TColor read FOnColorFrom write SetOnColorFrom; property OnColorTo:TColor read FOnColorTo write SetOnColorTo; property OffColorFrom:TColor read FOffColorFrom write SetOffColorFrom; property OffColorTo:TColor read FOffColorTo write SetOffColorTo; property LEDType:TLEDBoxType read FType write SetType; property Visible; property OnClick; property OnDblClick; property ShowHint; property ParentShowHint; property Enabled;
end;
procedure Register;
implementation
constructor TLEDBox.Create(AOwner : TComponent);
begin inherited; Height := 15; Width := 15; FOnColorTo := clLime; FOnColorFrom := clGreen; FOffColorTo := clRed; FOffColorFrom := clMaroon; FType := btLED; end;
destructor TLEDBox.Destroy;
begin Inherited; end;
procedure TLEDBox.SetChecked(newState : Boolean);
begin If (FChecked <> newState) then begin FChecked := newState; Invalidate; end; end;
procedure TLEDBox.SetOnColorFrom(newColor : TColor);
begin If (FOnColorFrom <> newColor) then begin FOnColorFrom := newColor; Invalidate; end; end;
procedure TLEDBox.SetOnColorTo(newColor : TColor);
begin If (FOnColorTo <> newColor) then begin FOnColorTo := newColor; Invalidate; end; end;
procedure TLEDBox.SetOffColorFrom(newColor : TColor);
begin If (FOffColorFrom <> newColor) then begin FOffColorFrom := newColor; Invalidate; end; end;
procedure TLEDBox.SetOffColorTo(newColor : TColor);
begin If (FOffColorTo <> newColor) then begin FOffColorTo := newColor; Invalidate; end; end;
procedure TLEDBox.SetType(newType : TLEDBoxType);
begin If (FType <> newType) then begin FType := newType; end; end;
procedure TLEDBox.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin If (ssLeft in Shift) then begin If (FType = btCheckbox) then begin If FChecked then SetChecked(FALSE) Else SetChecked(TRUE); Invalidate; end; end; end;
procedure TLEDBox.Paint;
var PRect : TRect; i : Integer; maxLength : Integer; paintColor : array[0..2] of Byte; deltaColor : array[0..2] of Single; ColorTo : TColor; ColorFrom : TColor; begin PRect.Top := 0; PRect.Left := 0; PRect.Bottom := Height; PRect.Right := Width;
maxLength := max(Width,Height)div 2;
with Canvas do begin If FChecked then begin ColorFrom := ColorToRGB(FOnColorFrom); ColorTo := ColorToRGB(FOnColorTo); end Else begin ColorFrom := ColorToRGB(FOffColorFrom); ColorTo := ColorToRGB(FOffColorTo); end;
Brush.Color := ColorFrom; Brush.Style := bsSolid; FillRect(PRect);
deltaColor[0] := (GetRValue(ColorFrom) - GetRValue(ColorTo)); deltaColor[1] := (GetGValue(ColorFrom) - GetGValue(ColorTo)); deltaColor[2] := (GetBValue(ColorFrom) - GetBValue(ColorTo));
for i := maxLength downto 1 do begin paintColor[0] := GetRValue(ColorTo) + Trunc(deltaColor[0]*sqr(i/maxLength)); paintColor[1] := GetGValue(ColorTo) + Trunc(deltaColor[1]*sqr(i/maxLength)); paintColor[2] := GetBValue(ColorTo) + Trunc(deltaColor[2]*sqr(i/maxLength)); Brush.Color := RGB(paintColor[0],paintColor[1],paintColor[2]); Pen.Color := RGB(paintColor[0],paintColor[1],paintColor[2]); Ellipse(Width div 2 -i, Height div 2 -i, Width div 2 +i, Height div 2 +i); end;
for i := 1 to 2 do begin Pen.Color := cl3DDkShadow; MoveTo(PRect.Left,PRect.Bottom); LineTo(PRect.Left,PRect.Top); LineTo(PRect.Right,PRect.Top); Pen.Color := clBtnHighlight; LineTo(PRect.Right,PRect.Bottom); LineTo(PRect.Left,PRect.Bottom);
InflateRect(PRect,-1,-1); end; end; end;
procedure Register;
begin RegisterComponents('Zusätzlich', [TLEDBox]); end;
end. |
|
|
Kroko
      
Beiträge: 1284
W98 W2k WXP
Turbo D
|
Verfasst: Do 05.01.06 12:09
nimm mal BitBlt statt CopyRect
_________________ Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
|
|
Bremi80 
      
Beiträge: 37
Win XP
Delphi 5 Pro/Std
|
Verfasst: Do 05.01.06 13:26
Klappt irgendwie nicht. Ich habe mir jetzt ein TBitmap als DrawBuffer erzeugt und rufe die Zeichenmethode nur auf, wenn sich etwas ändert. Die Paintmethode sieht bei mir so aus:
Delphi-Quelltext 1: 2: 3: 4: 5: 6:
| procedure TLEDBox.Paint;
begin Inherited; BitBlt(Canvas.Handle,Left,Top,Width,Height,FDrawBuffer.Canvas.Handle,0,0,SRCCOPY); end; |
Ich sehe auf meiner Form aber nur ein graues Rechteck.
|
|
Kroko
      
Beiträge: 1284
W98 W2k WXP
Turbo D
|
Verfasst: Do 05.01.06 13:45
für Left und top jeweils 0 eingeben!
_________________ Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
|
|
Bremi80 
      
Beiträge: 37
Win XP
Delphi 5 Pro/Std
|
Verfasst: Do 05.01.06 14:56
Funktioniert auch nicht. Das Ding ist immer noch grau.
|
|
Kroko
      
Beiträge: 1284
W98 W2k WXP
Turbo D
|
Verfasst: Do 05.01.06 15:18
hast Du in der Bitmap FDrawBuffer auch Width und Height gesetzt 
_________________ Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
|
|
Bremi80 
      
Beiträge: 37
Win XP
Delphi 5 Pro/Std
|
Verfasst: Do 05.01.06 16:17
Hups, hatte ich vergessen.
Hab ich jetzt gemacht, aber es kommt immer noch nix dabei raus.
|
|
JRegier
      
Beiträge: 1268
Win XP Home, Prof, 2003 Server
D6 Enterprise
|
Verfasst: Do 05.01.06 16:51
Bremi80 hat folgendes geschrieben: | Hups, hatte ich vergessen.
Hab ich jetzt gemacht, aber es kommt immer noch nix dabei raus. |
Delphi-Quelltext 1:
| LEDBox.PaintTo(Bitmap.Canvas,..); |
|
|
Bremi80 
      
Beiträge: 37
Win XP
Delphi 5 Pro/Std
|
Verfasst: Fr 06.01.06 09:48
Hurra!
Es klappt, vielen Dank für eure Hilfe.
Gruß, Daniel
|
|
|