mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-28 20:12:16 -05:00
Rewrote the color picker. It's as fast as or faster than SCAR's now
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@309 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
64ba5b72ec
commit
4c23f14232
@ -1,5 +1,5 @@
|
|||||||
function rs_GetUpText: String;
|
function rs_GetUpText: String;
|
||||||
begin
|
begin
|
||||||
Result := CurrThread.Client.MOCR.GetUpTextAt(7,7);
|
Result := CurrThread.Client.MOCR.GetUpTextAt(7, 7, false);
|
||||||
{writeln('inside: ' + result);}
|
{writeln('inside: ' + result);}
|
||||||
end;
|
end;
|
||||||
|
@ -48,31 +48,27 @@ type
|
|||||||
|
|
||||||
procedure Pick(Out C, X, Y: Integer);
|
procedure Pick(Out C, X, Y: Integer);
|
||||||
|
|
||||||
procedure ImageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer );
|
procedure ImageMainMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
||||||
procedure TimorTimer(Sender: TObject);
|
procedure ImageInfoMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
||||||
Procedure ColorPickDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
|
Procedure ColorPickDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
|
||||||
public
|
public
|
||||||
// Will give us CopyClientToBitmap
|
// Will give us CopyClientToBitmap
|
||||||
Window: TMWindow;
|
Window: TMWindow;
|
||||||
|
|
||||||
{ Form components }
|
{ Form components }
|
||||||
Form : TForm;
|
ScreenForm, InfoForm : TForm;
|
||||||
Image: TImage;
|
ImageMain, ImageInfo: TImage;
|
||||||
Timor : TTimer;
|
|
||||||
Bitmap : Graphics.TBitmap;
|
|
||||||
Note : Graphics.TBitmap;
|
|
||||||
Brush : TBrush;
|
|
||||||
Text : string;
|
Text : string;
|
||||||
FPickEvent : TPickEvent;
|
FPickEvent : TPickEvent;
|
||||||
|
|
||||||
{ Some temp vars }
|
{ Some temp vars }
|
||||||
oldx, oldy, Color, colorx, colory: Integer;
|
oldx, oldy, Color, colorx, colory: Integer;
|
||||||
targetleft,targettop : integer;
|
// targetleft,targettop : integer;
|
||||||
|
|
||||||
TheChangedEvent,TheChangingEvent : TNotifyEvent;
|
TheChangedEvent,TheChangingEvent : TNotifyEvent;
|
||||||
|
|
||||||
{ Handles }
|
{ Handles }
|
||||||
NoteHandle, BitmapHandle, ImageHandle : HDC;
|
InfoHandle, ImageHandle : HDC;
|
||||||
public
|
public
|
||||||
property OnPick: TPickEvent read FPickEvent write FPickEvent;
|
property OnPick: TPickEvent read FPickEvent write FPickEvent;
|
||||||
end;
|
end;
|
||||||
@ -92,10 +88,12 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
closed: Boolean;
|
||||||
|
|
||||||
procedure TMColorPicker.Pick(Out C, X, Y: Integer);
|
procedure TMColorPicker.Pick(Out C, X, Y: Integer);
|
||||||
var
|
var
|
||||||
w, h: integer;
|
w, h: integer;
|
||||||
bmp: TBitmap;
|
|
||||||
box : TBox;
|
box : TBox;
|
||||||
|
|
||||||
{$IFNDEF PICKER_CLIENT}
|
{$IFNDEF PICKER_CLIENT}
|
||||||
@ -108,8 +106,10 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
{ We create a Form, with the client image on it. }
|
{ We create a Form, with the client image on it. }
|
||||||
Form := TForm.Create(Application.MainForm);
|
ScreenForm := TForm.Create(Application.MainForm);
|
||||||
if Window.GetDimensionBox( box) then
|
InfoForm := TForm.Create(ScreenForm);
|
||||||
|
|
||||||
|
{ if Window.GetDimensionBox(box) then
|
||||||
begin;
|
begin;
|
||||||
targetleft := box.x1;
|
targetleft := box.x1;
|
||||||
targettop := box.y1;
|
targettop := box.y1;
|
||||||
@ -117,7 +117,7 @@ begin
|
|||||||
begin;
|
begin;
|
||||||
targetleft := 0;
|
targetleft := 0;
|
||||||
targettop := 0;
|
targettop := 0;
|
||||||
end;
|
end; }
|
||||||
{$IFNDEF PICKER_CLIENT}
|
{$IFNDEF PICKER_CLIENT}
|
||||||
{$IFDEF LINUX}
|
{$IFDEF LINUX}
|
||||||
OldWindow := Window.CurWindow;
|
OldWindow := Window.CurWindow;
|
||||||
@ -130,53 +130,63 @@ begin
|
|||||||
h := 0;
|
h := 0;
|
||||||
Window.GetDimensions(w, h);
|
Window.GetDimensions(w, h);
|
||||||
|
|
||||||
Form.Caption := 'SimbaColourPicker';
|
ScreenForm.Caption := 'SimbaColourPicker';
|
||||||
Form.Width := w;
|
ScreenForm.Width := w;
|
||||||
Form.Height := h;
|
ScreenForm.Height := h;
|
||||||
Form.Top := 0;
|
ScreenForm.Top := 0;
|
||||||
Form.left := 0;
|
ScreenForm.left := 0;
|
||||||
Form.WindowState := wsmaximized;
|
ScreenForm.WindowState := wsmaximized;
|
||||||
Form.BorderStyle:= bsNone;
|
ScreenForm.BorderStyle:= bsNone;
|
||||||
|
ScreenForm.FormStyle := fsStayOnTop;
|
||||||
|
|
||||||
Image := TImage.Create(Form);
|
InfoForm.Width := 173;
|
||||||
Image.Parent := Form;
|
InfoForm.Height := 33;
|
||||||
Image.left := 0;
|
InfoForm.BorderStyle := bsNone;
|
||||||
image.Width := 0;
|
InfoForm.FormStyle := fsStayOnTop;
|
||||||
Image.width := Form.Width;
|
InfoForm.Left := Mouse.CursorPos.X + 5;
|
||||||
Image.Height := Form.Height;
|
InfoForm.Top := Mouse.CursorPos.Y - 16;
|
||||||
Image.Cursor:= crCross;
|
|
||||||
Image.OnMouseDown:= @ColorPickDown;
|
|
||||||
Image.OnMouseMove:=@ImageMouseMove;
|
|
||||||
Image.Canvas.Brush.Color := 14811135;
|
|
||||||
Bitmap := Graphics.TBitmap.create;
|
|
||||||
Bitmap.width := Form.Width;
|
|
||||||
Bitmap.Height := Form.Height;
|
|
||||||
Note := Graphics.TBitmap.create;
|
|
||||||
Note.Canvas.Brush.Color := 14811135;
|
|
||||||
Note.Width := 148;
|
|
||||||
Note.Height := 33;
|
|
||||||
Note.Canvas.Rectangle(0, 0, 147, 33);
|
|
||||||
Note.Canvas.Rectangle(89, 3, 115, 29);
|
|
||||||
Note.Canvas.Pen.Style:= psClear;
|
|
||||||
|
|
||||||
bmp := Window.CopyClientToBitmap(0, 0, w - 1, h - 1);
|
ImageInfo := TImage.Create(InfoForm);
|
||||||
BitBlt(Image.Canvas.Handle, 0,0,w ,h , bmp.Canvas.Handle,0,0,SRCCOPY);
|
ImageInfo.Parent := InfoForm;
|
||||||
BitBlt(Bitmap.Canvas.Handle, 0,0,w ,h , bmp.Canvas.Handle,0,0,SRCCOPY);
|
ImageInfo.Left := 0;
|
||||||
bmp.Free;
|
ImageInfo.Top := 0;
|
||||||
|
ImageInfo.Width := 173;
|
||||||
|
ImageInfo.Height := 33;
|
||||||
|
ImageInfo.Cursor := crCross;
|
||||||
|
ImageInfo.OnMouseMove := @ImageInfoMouseMove;
|
||||||
|
ImageInfo.Canvas.Brush.Color := 14811135;
|
||||||
|
ImageInfo.Canvas.Rectangle(0, 0, 173, 33);
|
||||||
|
ImageInfo.Canvas.Rectangle(114, 3, 140, 29);
|
||||||
|
ImageInfo.Canvas.Rectangle(142, 3, 168, 29);
|
||||||
|
ImageInfo.Canvas.Pen.Style := psClear;
|
||||||
|
|
||||||
ImageHandle:= Image.Canvas.Handle;
|
ImageMain := TImage.Create(ScreenForm);
|
||||||
BitmapHandle:= Bitmap.Canvas.Handle;
|
ImageMain.Parent := ScreenForm;
|
||||||
NoteHandle:= Note.Canvas.Handle;
|
ImageMain.left := 0;
|
||||||
TheChangedEvent := Image.Canvas.OnChange;
|
ImageMain.top := 0;
|
||||||
TheChangingEvent := Image.Canvas.OnChanging;
|
ImageMain.width := ScreenForm.Width;
|
||||||
|
ImageMain.Height := ScreenForm.Height;
|
||||||
|
ImageMain.Cursor:= crCross;
|
||||||
|
ImageMain.OnMouseDown:= @ColorPickDown;
|
||||||
|
ImageMain.OnMouseMove:=@ImageMainMouseMove;
|
||||||
|
|
||||||
Brush := Image.Canvas.Brush;
|
ImageMain.Picture.Bitmap := Window.CopyClientToBitmap(0, 0, w - 1, h - 1);
|
||||||
Timor := TTimer.Create(Form);
|
|
||||||
|
|
||||||
Timor.OnTimer:= @TimorTimer;
|
ImageHandle:= ImageMain.Canvas.Handle;
|
||||||
Timor.Interval:= 50;
|
InfoHandle:= ImageInfo.Canvas.Handle;
|
||||||
Timor.Enabled:= False;
|
TheChangedEvent := ImageMain.Canvas.OnChange;
|
||||||
Form.ShowModal;
|
TheChangingEvent := ImageMain.Canvas.OnChanging;
|
||||||
|
|
||||||
|
ScreenForm.Show;
|
||||||
|
InfoForm.Show;
|
||||||
|
|
||||||
|
closed := False;
|
||||||
|
|
||||||
|
while not Closed do //CBA to do this a better way...
|
||||||
|
begin
|
||||||
|
sleep(1);
|
||||||
|
Application.ProcessMessages;
|
||||||
|
end;
|
||||||
|
|
||||||
// add x to history here.
|
// add x to history here.
|
||||||
c := Color;
|
c := Color;
|
||||||
@ -191,91 +201,66 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
Note.Free;
|
ImageMain.Free;
|
||||||
Bitmap.Free;
|
ImageInfo.Free;
|
||||||
Timor.Free;
|
InfoForm.Free;
|
||||||
Image.Free;
|
ScreenForm.Free;
|
||||||
Form.Free;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMColorPicker.ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
|
procedure TMColorPicker.ImageMainMouseMove(Sender: TObject; Shift: TShiftState; X,
|
||||||
Y: Integer);
|
Y: Integer);
|
||||||
{$ifdef mswindows}
|
|
||||||
var
|
var
|
||||||
TempPoint : TPoint;
|
TempPoint : TPoint;
|
||||||
|
Data : TRetData;
|
||||||
|
R : TRect;
|
||||||
|
px, py : Integer;
|
||||||
begin
|
begin
|
||||||
|
InfoForm.Left := Mouse.CursorPos.X + 5;
|
||||||
|
InfoForm.Top := Mouse.CursorPos.Y - 16;
|
||||||
|
|
||||||
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 - Form.Left;
|
TempPoint.X := TempPoint.X - ScreenForm.Left;
|
||||||
TempPoint.Y := TempPoint.Y - Form.Top;
|
TempPoint.Y := TempPoint.Y - ScreenForm.Top;
|
||||||
|
Color := WidgetSet.DCGetPixel(ImageHandle, X, Y);
|
||||||
BitBlt(ImageHandle, oldx + 5, oldy + 5,147,33,BitmapHandle,oldx + 5,oldy + 5,SRCCOPY);
|
ImageInfo.Canvas.Brush.Color := Color;
|
||||||
Color := WidgetSet.DCGetPixel(ImageHandle, TempPoint.X, TempPoint.Y);
|
ImageInfo.Canvas.Rectangle(143, 4, 168, 29);
|
||||||
Rectangle(NoteHandle,1,1,85,32);
|
SetBkColor(InfoHandle, 14811135);
|
||||||
// Text:='Pos: ' + inttostr(TempPoint.x - Client.Rect.Left) + ',' + inttostr(TempPoint.y - Client.Rect.Bottom);
|
Text := 'Pos: ' + inttostr(x) + ',' + inttostr(y);
|
||||||
Text:='Pos: ' + inttostr(TempPoint.x - targetleft) + ',' + inttostr(TempPoint.y - targettop);
|
R := Rect(5, 6, 114, 18);
|
||||||
ExtTextOut(NoteHandle, 5, 3,0,nil,pchar(text),length(text),nil);
|
ExtTextOut(InfoHandle, 5, 3, ETO_OPAQUE, @R, pchar(text), length(text), nil);
|
||||||
Text := 'Color: ' + inttostr(Color);
|
Text := 'Color: ' + inttostr(Color);
|
||||||
ExtTextOut(NoteHandle, 5, 15,0,nil,pchar(text),length(text),nil);
|
R := Rect(5, 18, 114, 28);
|
||||||
BitBlt( ImageHandle, TempPoint.x + 5, TempPoint.y + 5,147,33,NoteHandle,0,0,SRCCOPY);
|
ExtTextOut(InfoHandle, 5, 15, ETO_OPAQUE, @R, pchar(text), length(text), nil);
|
||||||
Brush.Color := Color;
|
for px := -1 to 1 do
|
||||||
Image.Canvas.Rectangle(TempPoint.x + 123, TempPoint.y + 8, tempPoint.x + 149, temppoint.y + 34);
|
for py := -1 to 1 do
|
||||||
// Rectangle(ImageHandle,TempPoint.x + 123, TempPoint.y + 8, tempPoint.x + 149, temppoint.y + 34);
|
begin
|
||||||
TheChangingEvent(Sender);
|
ImageInfo.Canvas.Brush.Color := WidgetSet.DCGetPixel(ImageHandle, x + px, y + py);
|
||||||
StretchBlt(ImageHandle,TempPoint.x + 95, TempPoint.y + 9, 24,24, BitmapHandle, TempPoint.x - 1, TempPoint.y-1,3,3, SRCCOPY);
|
ImageInfo.Canvas.Rectangle((px + 1) * 8 + 115, (py + 1) * 8 + 4, (px + 1) * 8 + 124, (py + 1) * 8 + 13);
|
||||||
TheChangedEvent(Sender);
|
end;
|
||||||
Oldx := TempPoint.x;
|
Oldx := TempPoint.x;
|
||||||
Oldy := TempPoint.y;
|
Oldy := TempPoint.y;
|
||||||
end;
|
end;
|
||||||
{$else}
|
|
||||||
|
procedure TMColorPicker.ImageInfoMouseMove(Sender: TObject; Shift: TShiftState; X,
|
||||||
|
Y: Integer);
|
||||||
begin
|
begin
|
||||||
Timor.Enabled:= True;
|
InfoForm.Top := Mouse.CursorPos.Y - 16;
|
||||||
end;
|
InfoForm.Left := Mouse.CursorPos.X + 5;
|
||||||
{$endif}
|
|
||||||
|
|
||||||
procedure TMColorPicker.TimorTimer(Sender: TObject);
|
|
||||||
var
|
|
||||||
TempPoint : TPoint;
|
|
||||||
begin
|
|
||||||
// GetCursorPos(TempPoint);
|
|
||||||
TempPoint := Mouse.CursorPos;
|
|
||||||
|
|
||||||
{ If a form cannot be fully set to 0,0 }
|
|
||||||
TempPoint.X := TempPoint.X - Form.Left;
|
|
||||||
TempPoint.Y := TempPoint.Y - Form.Top;
|
|
||||||
|
|
||||||
BitBlt(ImageHandle, oldx + 5, oldy + 5,147,33,BitmapHandle,oldx + 5,oldy + 5,SRCCOPY);
|
|
||||||
Color := WidgetSet.DCGetPixel(ImageHandle, TempPoint.X, TempPoint.Y);
|
|
||||||
Rectangle(NoteHandle,1,1,85,32);
|
|
||||||
// Text:='Pos: ' + inttostr(TempPoint.x - Client.Rect.Left) + ',' + inttostr(TempPoint.y - Client.Rect.Bottom);
|
|
||||||
Text:={'Pos: ' + }inttostr(TempPoint.x - targetleft) + ',' + inttostr(TempPoint.y - targettop);
|
|
||||||
ExtTextOut(NoteHandle, 5, 3,0,nil,pchar(text),length(text),nil);
|
|
||||||
Text := {'Color: ' + }inttostr(Color);
|
|
||||||
ExtTextOut(NoteHandle, 5, 15,0,nil,pchar(text),length(text),nil);
|
|
||||||
BitBlt( ImageHandle, TempPoint.x + 5, TempPoint.y + 5,147,33,NoteHandle,0,0,SRCCOPY);
|
|
||||||
Brush.Color := Color;
|
|
||||||
Image.Canvas.Rectangle(TempPoint.x + 123, TempPoint.y + 8, tempPoint.x + 149, temppoint.y + 34);
|
|
||||||
// Rectangle(ImageHandle,TempPoint.x + 123, TempPoint.y + 8, tempPoint.x + 149, temppoint.y + 34);
|
|
||||||
TheChangingEvent(Sender);
|
|
||||||
StretchBlt(ImageHandle,TempPoint.x + 95, TempPoint.y + 9, 24,24, BitmapHandle, TempPoint.x - 1, TempPoint.y-1,3,3, SRCCOPY);
|
|
||||||
TheChangedEvent(Sender);
|
|
||||||
Oldx := TempPoint.x;
|
|
||||||
Oldy := TempPoint.y;
|
|
||||||
Timor.Enabled:= False;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMColorPicker.ColorPickDown(Sender: TObject; Button: TMouseButton;
|
procedure TMColorPicker.ColorPickDown(Sender: TObject; Button: TMouseButton;
|
||||||
Shift: TShiftState; X, Y: Integer);
|
Shift: TShiftState; X, Y: Integer);
|
||||||
begin;
|
begin;
|
||||||
Color:= WidgetSet.DCGetPixel(Image.Canvas.Handle,x,y);
|
Color:= WidgetSet.DCGetPixel(ImageMain.Canvas.Handle,x,y);
|
||||||
Self.Colorx := x - targetleft;
|
Self.Colorx := x;
|
||||||
Self.Colory := y - targettop;
|
Self.Colory := y;
|
||||||
Timor.enabled := false;
|
|
||||||
if OnPick <> nil then
|
if OnPick <> nil then
|
||||||
Onpick(Sender,Color,Colorx,Colory);
|
Onpick(Sender,Color,Colorx,Colory);
|
||||||
Form.Close;
|
InfoForm.Close;
|
||||||
|
ScreenForm.Close;
|
||||||
|
closed := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user