1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-08-13 16:53:59 -04:00

Fixed more bugs in the color picker

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@313 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
bullzeye95 2009-12-22 00:00:48 +00:00
parent 6743cec251
commit 19abae25e1

View File

@ -30,7 +30,7 @@ interface
uses uses
Classes, SysUtils, LCLIntf,LCLType,InterfaceBase,Forms,Controls,ExtCtrls, Classes, SysUtils, LCLIntf,LCLType,InterfaceBase,Forms,Controls,ExtCtrls,
Graphics, Graphics,
Window,MufasaTypes Window,MufasaTypes, colourhistory
{$IFNDEF PICKER_CLIENT} {$IFNDEF PICKER_CLIENT}
{$IFDEF LINUX} {$IFDEF LINUX}
@ -50,7 +50,7 @@ type
procedure ImageMainMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure ImageMainMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure ImageInfoMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure ImageInfoMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
Procedure ColorPickDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer); Procedure ColorPickUp(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
public public
// Will give us CopyClientToBitmap // Will give us CopyClientToBitmap
Window: TMWindow; Window: TMWindow;
@ -95,6 +95,8 @@ procedure TMColorPicker.Pick(Out C, X, Y: Integer);
var var
w, h: integer; w, h: integer;
box : TBox; box : TBox;
SS : TShiftState;
p : TPoint;
{$IFNDEF PICKER_CLIENT} {$IFNDEF PICKER_CLIENT}
{$IFDEF LINUX} {$IFDEF LINUX}
@ -105,9 +107,11 @@ var
{$ENDIF} {$ENDIF}
begin begin
{ Disable both of the color pick buttons }
Application.MainForm.Enabled := False; Application.MainForm.Enabled := False;
ColourHistoryForm.Enabled := False;
{ We create a Form, with the client image on it. } { Create a form that will hold the client image and a form that will show cursor and color data }
ScreenForm := TForm.Create(Application.MainForm); ScreenForm := TForm.Create(Application.MainForm);
InfoForm := TForm.Create(ScreenForm); InfoForm := TForm.Create(ScreenForm);
@ -130,9 +134,12 @@ begin
{$ENDIF} {$ENDIF}
w := 0; w := 0;
h := 0; h := 0;
{ Get the dimensions of the screen }
Window.GetDimensions(w, h); Window.GetDimensions(w, h);
{ Initialize the form that will hold the client image }
ScreenForm.Caption := 'SimbaColourPicker'; ScreenForm.Caption := 'SimbaColourPicker';
{ Set the form's dimensions to match that of the screen }
ScreenForm.Width := w; ScreenForm.Width := w;
ScreenForm.Height := h; ScreenForm.Height := h;
ScreenForm.Top := 0; ScreenForm.Top := 0;
@ -141,13 +148,15 @@ begin
ScreenForm.BorderStyle:= bsNone; ScreenForm.BorderStyle:= bsNone;
ScreenForm.FormStyle := fsStayOnTop; ScreenForm.FormStyle := fsStayOnTop;
{ Initialize the form that will hold the cursor and color info }
InfoForm.Width := 173; InfoForm.Width := 173;
InfoForm.Height := 33; InfoForm.Height := 33;
InfoForm.BorderStyle := bsNone; InfoForm.BorderStyle := bsNone;
InfoForm.FormStyle := fsStayOnTop; InfoForm.FormStyle := fsStayOnTop;
InfoForm.Left := Mouse.CursorPos.X + 5; InfoForm.Left := Mouse.CursorPos.X + 5;
InfoForm.Top := Mouse.CursorPos.Y - 16; InfoForm.Top := Mouse.CursorPos.Y - 15;
{ Initialize the image that will hold the cursor and color info }
ImageInfo := TImage.Create(InfoForm); ImageInfo := TImage.Create(InfoForm);
ImageInfo.Parent := InfoForm; ImageInfo.Parent := InfoForm;
ImageInfo.Left := 0; ImageInfo.Left := 0;
@ -162,6 +171,7 @@ begin
ImageInfo.Canvas.Rectangle(142, 3, 168, 29); ImageInfo.Canvas.Rectangle(142, 3, 168, 29);
ImageInfo.Canvas.Pen.Style := psClear; ImageInfo.Canvas.Pen.Style := psClear;
{ Initialize the image that will hold the client image }
ImageMain := TImage.Create(ScreenForm); ImageMain := TImage.Create(ScreenForm);
ImageMain.Parent := ScreenForm; ImageMain.Parent := ScreenForm;
ImageMain.left := 0; ImageMain.left := 0;
@ -169,24 +179,30 @@ begin
ImageMain.width := ScreenForm.Width; ImageMain.width := ScreenForm.Width;
ImageMain.Height := ScreenForm.Height; ImageMain.Height := ScreenForm.Height;
ImageMain.Cursor:= crCross; ImageMain.Cursor:= crCross;
ImageMain.OnMouseDown:= @ColorPickDown; ImageMain.OnMouseUp:= @ColorPickUp;
ImageMain.OnMouseMove:=@ImageMainMouseMove; ImageMain.OnMouseMove:=@ImageMainMouseMove;
{ Copy the client to ImageMain }
ImageMain.Picture.Bitmap := Window.CopyClientToBitmap(0, 0, w - 1, h - 1); ImageMain.Picture.Bitmap := Window.CopyClientToBitmap(0, 0, w - 1, h - 1);
{ Set up handles and events }
ImageHandle:= ImageMain.Canvas.Handle; ImageHandle:= ImageMain.Canvas.Handle;
InfoHandle:= ImageInfo.Canvas.Handle; InfoHandle:= ImageInfo.Canvas.Handle;
TheChangedEvent := ImageMain.Canvas.OnChange; TheChangedEvent := ImageMain.Canvas.OnChange;
TheChangingEvent := ImageMain.Canvas.OnChanging; TheChangingEvent := ImageMain.Canvas.OnChanging;
{ Show the forms }
ScreenForm.Show; ScreenForm.Show;
InfoForm.Show; InfoForm.Show;
SetCursorPos(Mouse.CursorPos.X, Mouse.CursorPos.Y); { Display the data on the info form }
p := ImageMain.ScreenToClient(Mouse.CursorPos);
ImageMainMouseMove(nil, SS, p.x, p.y);
closed := False; closed := False;
while not Closed do //CBA to do this a better way... { Wait while the forms are still open }
while not Closed do
begin begin
sleep(1); sleep(1);
Application.ProcessMessages; Application.ProcessMessages;
@ -205,12 +221,15 @@ begin
{$ENDIF} {$ENDIF}
{$ENDIF} {$ENDIF}
{ Free forms and images }
ImageMain.Free; ImageMain.Free;
ImageInfo.Free; ImageInfo.Free;
InfoForm.Free; InfoForm.Free;
ScreenForm.Free; ScreenForm.Free;
{ Re-enable the color pick buttons }
Application.MainForm.Enabled := True; Application.MainForm.Enabled := True;
ColourHistoryForm.Enabled := True;
end; end;
procedure TMColorPicker.ImageMainMouseMove(Sender: TObject; Shift: TShiftState; X, procedure TMColorPicker.ImageMainMouseMove(Sender: TObject; Shift: TShiftState; X,
@ -221,30 +240,40 @@ var
R : TRect; R : TRect;
px, py : Integer; px, py : Integer;
begin begin
{ Move the info form }
InfoForm.Left := Mouse.CursorPos.X + 5; InfoForm.Left := Mouse.CursorPos.X + 5;
InfoForm.Top := Mouse.CursorPos.Y - 16; InfoForm.Top := Mouse.CursorPos.Y - 15;
TempPoint := Point(x, y); TempPoint := Point(x, y);
{ If a form cannot be fully set to 0,0 } { If a form cannot be fully set to 0,0 }
TempPoint.X := TempPoint.X - ScreenForm.Left; TempPoint.X := TempPoint.X - ScreenForm.Left;
TempPoint.Y := TempPoint.Y - ScreenForm.Top; TempPoint.Y := TempPoint.Y - ScreenForm.Top;
{ Get the pixel that the cursor is currently on }
Color := WidgetSet.DCGetPixel(ImageHandle, X, Y); Color := WidgetSet.DCGetPixel(ImageHandle, X, Y);
{ Draw the current pixel to the right color box }
ImageInfo.Canvas.Brush.Color := Color; ImageInfo.Canvas.Brush.Color := Color;
ImageInfo.Canvas.Rectangle(143, 4, 168, 29); ImageInfo.Canvas.Rectangle(143, 4, 168, 29);
{ Draw the cursor and color info }
SetBkColor(InfoHandle, 14811135); SetBkColor(InfoHandle, 14811135);
Text := 'Pos: ' + inttostr(x) + ',' + inttostr(y); Text := Format('Pos: %d, %d', [x, y]);
R := Rect(5, 6, 114, 18); R := Rect(5, 6, 114, 18);
ExtTextOut(InfoHandle, 5, 3, ETO_OPAQUE, @R, pchar(text), length(text), nil); ExtTextOut(InfoHandle, 5, 3, ETO_OPAQUE, @R, pchar(text), length(text), nil);
Text := 'Color: ' + inttostr(Color); Text := Format('Color: %d', [Color]);
R := Rect(5, 18, 114, 28); R := Rect(5, 18, 114, 28);
ExtTextOut(InfoHandle, 5, 15, ETO_OPAQUE, @R, pchar(text), length(text), nil); ExtTextOut(InfoHandle, 5, 15, ETO_OPAQUE, @R, pchar(text), length(text), nil);
{ Draw the left, slightly zoomed out, color box }
for px := -1 to 1 do for px := -1 to 1 do
for py := -1 to 1 do for py := -1 to 1 do
begin begin
ImageInfo.Canvas.Brush.Color := WidgetSet.DCGetPixel(ImageHandle, x + px, y + py); ImageInfo.Canvas.Brush.Color := WidgetSet.DCGetPixel(ImageHandle, x + px, y + py);
ImageInfo.Canvas.Rectangle((px + 1) * 8 + 115, (py + 1) * 8 + 4, (px + 1) * 8 + 124, (py + 1) * 8 + 13); ImageInfo.Canvas.Rectangle((px + 1) * 8 + 115, (py + 1) * 8 + 4, (px + 1) * 8 + 124, (py + 1) * 8 + 13);
end; end;
Oldx := TempPoint.x; Oldx := TempPoint.x;
Oldy := TempPoint.y; Oldy := TempPoint.y;
end; end;
@ -252,20 +281,27 @@ end;
procedure TMColorPicker.ImageInfoMouseMove(Sender: TObject; Shift: TShiftState; X, procedure TMColorPicker.ImageInfoMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer); Y: Integer);
begin begin
InfoForm.Top := Mouse.CursorPos.Y - 16; { Move the info form }
InfoForm.Top := Mouse.CursorPos.Y - 15;
InfoForm.Left := Mouse.CursorPos.X + 5; InfoForm.Left := Mouse.CursorPos.X + 5;
end; end;
procedure TMColorPicker.ColorPickDown(Sender: TObject; Button: TMouseButton; procedure TMColorPicker.ColorPickUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); Shift: TShiftState; X, Y: Integer);
begin; begin;
{ Set the coordinates and color that the user cliked on }
Color:= WidgetSet.DCGetPixel(ImageMain.Canvas.Handle,x,y); Color:= WidgetSet.DCGetPixel(ImageMain.Canvas.Handle,x,y);
Self.Colorx := x; Self.Colorx := x;
Self.Colory := y; Self.Colory := y;
if OnPick <> nil then if OnPick <> nil then
Onpick(Sender,Color,Colorx,Colory); Onpick(Sender,Color,Colorx,Colory);
{ Close the forms }
InfoForm.Close; InfoForm.Close;
ScreenForm.Close; ScreenForm.Close;
{ Tell Pick() that we are done }
closed := True; closed := True;
end; end;