mirror of
https://github.com/moparisthebest/Simba
synced 2024-08-13 16:53:59 -04:00
Yo dawg I herd you like fixes
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@149 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
4e931dc421
commit
3bacb9f537
@ -1,229 +1,235 @@
|
|||||||
{
|
{
|
||||||
This file is part of the Mufasa Macro Library (MML)
|
This file is part of the Mufasa Macro Library (MML)
|
||||||
Copyright (c) 2009 by Raymond van Venetië and Merlijn Wajer
|
Copyright (c) 2009 by Raymond van Venetië and Merlijn Wajer
|
||||||
|
|
||||||
MML is free software: you can redistribute it and/or modify
|
MML is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
MML is distributed in the hope that it will be useful,
|
MML is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with MML. If not, see <http://www.gnu.org/licenses/>.
|
along with MML. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
See the file COPYING, included in this distribution,
|
See the file COPYING, included in this distribution,
|
||||||
for details about the copyright.
|
for details about the copyright.
|
||||||
|
|
||||||
Colourpicker for the Mufasa Macro Library
|
Colourpicker for the Mufasa Macro Library
|
||||||
}
|
}
|
||||||
|
|
||||||
unit colourpicker;
|
unit colourpicker;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, LCLIntf,LCLType,InterfaceBase,Forms,Controls,ExtCtrls,
|
Classes, SysUtils, LCLIntf,LCLType,InterfaceBase,Forms,Controls,ExtCtrls,
|
||||||
Graphics,
|
Graphics,
|
||||||
Window
|
Window,MufasaTypes
|
||||||
|
|
||||||
{$IFNDEF PICKER_CLIENT}
|
{$IFNDEF PICKER_CLIENT}
|
||||||
{$IFDEF LINUX}
|
{$IFDEF LINUX}
|
||||||
,x
|
,x
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
;
|
;
|
||||||
|
|
||||||
type
|
type
|
||||||
TPickEvent = procedure (Sender: TObject; Color, X, Y: Integer);
|
TPickEvent = procedure (Sender: TObject; Color, X, Y: Integer);
|
||||||
|
|
||||||
TMColorPicker = class(TObject)
|
TMColorPicker = class(TObject)
|
||||||
constructor Create(aWindow: TMWindow);
|
constructor Create(aWindow: TMWindow);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
procedure Pick(Out C, X, Y: Integer);
|
procedure Pick(Out C, X, Y: Integer);
|
||||||
|
|
||||||
procedure ImageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer );
|
procedure ImageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer );
|
||||||
procedure TimorTimer(Sender: TObject);
|
procedure TimorTimer(Sender: TObject);
|
||||||
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;
|
||||||
ColourHistory: TList; // for colour history
|
ColourHistory: TList; // for colour history
|
||||||
|
|
||||||
Form : TForm;
|
Form : TForm;
|
||||||
Image: TImage;
|
Image: TImage;
|
||||||
Timor : TTimer;
|
Timor : TTimer;
|
||||||
Bitmap : Graphics.TBitmap;
|
Bitmap : Graphics.TBitmap;
|
||||||
Note : Graphics.TBitmap;
|
Note : Graphics.TBitmap;
|
||||||
Brush : TBrush;
|
Brush : TBrush;
|
||||||
Text : string;
|
Text : string;
|
||||||
FPickEvent : TPickEvent;
|
FPickEvent : TPickEvent;
|
||||||
|
|
||||||
oldx, oldy, Color, colorx, colory: Integer;
|
oldx, oldy, Color, colorx, colory: Integer;
|
||||||
|
|
||||||
TheChangedEvent,TheChangingEvent : TNotifyEvent;
|
TheChangedEvent,TheChangingEvent : TNotifyEvent;
|
||||||
NoteHandle, BitmapHandle, ImageHandle : HDC;
|
NoteHandle, BitmapHandle, ImageHandle : HDC;
|
||||||
public
|
public
|
||||||
property OnPick: TPickEvent read FPickEvent write FPickEvent;
|
property OnPick: TPickEvent read FPickEvent write FPickEvent;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
constructor TMColorPicker.Create(aWindow: TMWindow);
|
constructor TMColorPicker.Create(aWindow: TMWindow);
|
||||||
begin
|
begin
|
||||||
Self.Window := aWindow;
|
Self.Window := aWindow;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TMColorPicker.Destroy;
|
destructor TMColorPicker.Destroy;
|
||||||
begin
|
begin
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
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;
|
bmp: TBitmap;
|
||||||
|
|
||||||
{$IFNDEF PICKER_CLIENT}
|
{$IFNDEF PICKER_CLIENT}
|
||||||
{$IFDEF LINUX}
|
{$IFDEF LINUX}
|
||||||
OldWindow: TWindow;
|
OldWindow: TWindow;
|
||||||
{$ENDIF}
|
{$ELSE}
|
||||||
{$ENDIF}
|
OldWindow: HWND;
|
||||||
|
{$ENDIF}
|
||||||
begin
|
{$ENDIF}
|
||||||
Form := TForm.Create(Application.MainForm);
|
|
||||||
{$IFNDEF PICKER_CLIENT}
|
begin
|
||||||
{$IFDEF LINUX}
|
Form := TForm.Create(Application.MainForm);
|
||||||
OldWindow := Window.CurWindow;
|
{$IFNDEF PICKER_CLIENT}
|
||||||
Window.SetTarget(Window.DesktopWindow);
|
{$IFDEF LINUX}
|
||||||
{$ENDIF}
|
OldWindow := Window.CurWindow;
|
||||||
{$ENDIF}
|
{$ELSE}
|
||||||
w := 0;
|
OldWindow := Window.TargetHandle;
|
||||||
h := 0;
|
{$ENDIF}
|
||||||
Window.GetDimensions(w, h);
|
Window.SetDesktop;
|
||||||
|
{$ENDIF}
|
||||||
Form.Width := w;
|
w := 0;
|
||||||
Form.Height := h;
|
h := 0;
|
||||||
Form.Top := 0;
|
Window.GetDimensions(w, h);
|
||||||
Form.left := 0;
|
|
||||||
Form.WindowState := wsmaximized;
|
Form.Width := w;
|
||||||
Form.BorderStyle:= bsNone;
|
Form.Height := h;
|
||||||
|
Form.Top := 0;
|
||||||
Image := TImage.Create(Form);
|
Form.left := 0;
|
||||||
Image.Parent := Form;
|
Form.WindowState := wsmaximized;
|
||||||
Image.left := 0;
|
Form.BorderStyle:= bsNone;
|
||||||
image.Width := 0;
|
|
||||||
Image.width := Form.Width - 1;
|
Image := TImage.Create(Form);
|
||||||
Image.Height := Form.Height - 1;
|
Image.Parent := Form;
|
||||||
Image.Cursor:= crCross;
|
Image.left := 0;
|
||||||
Image.OnMouseDown:= @ColorPickDown;
|
image.Width := 0;
|
||||||
Image.OnMouseMove:=@ImageMouseMove;
|
Image.width := Form.Width - 1;
|
||||||
Image.Canvas.Brush.Color := 14811135;
|
Image.Height := Form.Height - 1;
|
||||||
Bitmap := Graphics.TBitmap.create;
|
Image.Cursor:= crCross;
|
||||||
Bitmap.width := Form.Width;
|
Image.OnMouseDown:= @ColorPickDown;
|
||||||
Bitmap.Height := Form.Height;
|
Image.OnMouseMove:=@ImageMouseMove;
|
||||||
Note := Graphics.TBitmap.create;
|
Image.Canvas.Brush.Color := 14811135;
|
||||||
Note.Canvas.Brush.Color := 14811135;
|
Bitmap := Graphics.TBitmap.create;
|
||||||
Note.Width := 148;
|
Bitmap.width := Form.Width;
|
||||||
Note.Height := 33;
|
Bitmap.Height := Form.Height;
|
||||||
Note.Canvas.Rectangle(0, 0, 147, 33);
|
Note := Graphics.TBitmap.create;
|
||||||
Note.Canvas.Rectangle(89, 3, 115, 29);
|
Note.Canvas.Brush.Color := 14811135;
|
||||||
Note.Canvas.Pen.Style:= psClear;
|
Note.Width := 148;
|
||||||
|
Note.Height := 33;
|
||||||
bmp := Window.CopyClientToBitmap(0, 0, w - 1, h - 1);
|
Note.Canvas.Rectangle(0, 0, 147, 33);
|
||||||
BitBlt(Image.Canvas.Handle, 0,0,w ,h , bmp.Canvas.Handle,0,0,SRCCOPY);
|
Note.Canvas.Rectangle(89, 3, 115, 29);
|
||||||
BitBlt(Bitmap.Canvas.Handle, 0,0,w ,h , bmp.Canvas.Handle,0,0,SRCCOPY);
|
Note.Canvas.Pen.Style:= psClear;
|
||||||
bmp.Free;
|
|
||||||
|
bmp := Window.CopyClientToBitmap(0, 0, w - 1, h - 1);
|
||||||
ImageHandle:= Image.Canvas.Handle;
|
BitBlt(Image.Canvas.Handle, 0,0,w ,h , bmp.Canvas.Handle,0,0,SRCCOPY);
|
||||||
BitmapHandle:= Bitmap.Canvas.Handle;
|
BitBlt(Bitmap.Canvas.Handle, 0,0,w ,h , bmp.Canvas.Handle,0,0,SRCCOPY);
|
||||||
NoteHandle:= Note.Canvas.Handle;
|
bmp.Free;
|
||||||
TheChangedEvent := Image.Canvas.OnChange;
|
|
||||||
TheChangingEvent := Image.Canvas.OnChanging;
|
ImageHandle:= Image.Canvas.Handle;
|
||||||
|
BitmapHandle:= Bitmap.Canvas.Handle;
|
||||||
Brush := Image.Canvas.Brush;
|
NoteHandle:= Note.Canvas.Handle;
|
||||||
Timor := TTimer.Create(Form);
|
TheChangedEvent := Image.Canvas.OnChange;
|
||||||
|
TheChangingEvent := Image.Canvas.OnChanging;
|
||||||
Timor.OnTimer:= @TimorTimer;
|
|
||||||
Timor.Interval:= 50;
|
Brush := Image.Canvas.Brush;
|
||||||
Timor.Enabled:= False;
|
Timor := TTimer.Create(Form);
|
||||||
|
|
||||||
Form.ShowModal;
|
Timor.OnTimer:= @TimorTimer;
|
||||||
|
Timor.Interval:= 50;
|
||||||
// add x to history here.
|
Timor.Enabled:= False;
|
||||||
c := Color;
|
|
||||||
x := Colorx;
|
Form.ShowModal;
|
||||||
y := Colory;
|
|
||||||
|
// add x to history here.
|
||||||
{$IFNDEF PICKER_CLIENT}
|
c := Color;
|
||||||
{$IFDEF LINUX}
|
x := Colorx;
|
||||||
Window.SetTarget(OldWindow);
|
y := Colory;
|
||||||
{$ENDIF}
|
|
||||||
{$ENDIF}
|
{$IFNDEF PICKER_CLIENT}
|
||||||
|
{$IFDEF LINUX}
|
||||||
Note.Free;
|
Window.SetTarget(OldWindow);
|
||||||
Bitmap.Free;
|
{$ELSE}
|
||||||
Timor.Free;
|
Window.SetTarget(OldWindow, w_Window);
|
||||||
Image.Free;
|
{$ENDIF}
|
||||||
Form.Free;
|
{$ENDIF}
|
||||||
end;
|
|
||||||
|
Note.Free;
|
||||||
procedure TMColorPicker.ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
|
Bitmap.Free;
|
||||||
Y: Integer);
|
Timor.Free;
|
||||||
begin
|
Image.Free;
|
||||||
Timor.Enabled:= True;
|
Form.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMColorPicker.TimorTimer(Sender: TObject);
|
procedure TMColorPicker.ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
|
||||||
var
|
Y: Integer);
|
||||||
TempPoint : TPoint;
|
begin
|
||||||
begin
|
Timor.Enabled:= True;
|
||||||
// GetCursorPos(TempPoint);
|
end;
|
||||||
TempPoint := Mouse.CursorPos;
|
|
||||||
|
procedure TMColorPicker.TimorTimer(Sender: TObject);
|
||||||
{ If a form cannot be fully set to 0,0 }
|
var
|
||||||
TempPoint.X := TempPoint.X - Form.Left;
|
TempPoint : TPoint;
|
||||||
TempPoint.Y := TempPoint.Y - Form.Top;
|
begin
|
||||||
|
// GetCursorPos(TempPoint);
|
||||||
BitBlt(ImageHandle, oldx + 5, oldy + 5,147,33,BitmapHandle,oldx + 5,oldy + 5,SRCCOPY);
|
TempPoint := Mouse.CursorPos;
|
||||||
Color := WidgetSet.DCGetPixel(ImageHandle, TempPoint.X, TempPoint.Y);
|
|
||||||
Rectangle(NoteHandle,1,1,85,32);
|
{ If a form cannot be fully set to 0,0 }
|
||||||
// Text:='Pos: ' + inttostr(TempPoint.x - Client.Rect.Left) + ',' + inttostr(TempPoint.y - Client.Rect.Bottom);
|
TempPoint.X := TempPoint.X - Form.Left;
|
||||||
Text:='Pos: ' + inttostr(TempPoint.x) + ',' + inttostr(TempPoint.y);
|
TempPoint.Y := TempPoint.Y - Form.Top;
|
||||||
ExtTextOut(NoteHandle, 5, 3,0,nil,pchar(text),length(text),nil);
|
|
||||||
Text := 'Color: ' + inttostr(Color);
|
BitBlt(ImageHandle, oldx + 5, oldy + 5,147,33,BitmapHandle,oldx + 5,oldy + 5,SRCCOPY);
|
||||||
ExtTextOut(NoteHandle, 5, 15,0,nil,pchar(text),length(text),nil);
|
Color := WidgetSet.DCGetPixel(ImageHandle, TempPoint.X, TempPoint.Y);
|
||||||
BitBlt( ImageHandle, TempPoint.x + 5, TempPoint.y + 5,147,33,NoteHandle,0,0,SRCCOPY);
|
Rectangle(NoteHandle,1,1,85,32);
|
||||||
Brush.Color := Color;
|
// Text:='Pos: ' + inttostr(TempPoint.x - Client.Rect.Left) + ',' + inttostr(TempPoint.y - Client.Rect.Bottom);
|
||||||
Image.Canvas.Rectangle(TempPoint.x + 123, TempPoint.y + 8, tempPoint.x + 149, temppoint.y + 34);
|
Text:='Pos: ' + inttostr(TempPoint.x) + ',' + inttostr(TempPoint.y);
|
||||||
// Rectangle(ImageHandle,TempPoint.x + 123, TempPoint.y + 8, tempPoint.x + 149, temppoint.y + 34);
|
ExtTextOut(NoteHandle, 5, 3,0,nil,pchar(text),length(text),nil);
|
||||||
TheChangingEvent(Sender);
|
Text := 'Color: ' + inttostr(Color);
|
||||||
StretchBlt(ImageHandle,TempPoint.x + 95, TempPoint.y + 9, 24,24, BitmapHandle, TempPoint.x - 1, TempPoint.y-1,3,3, SRCCOPY);
|
ExtTextOut(NoteHandle, 5, 15,0,nil,pchar(text),length(text),nil);
|
||||||
TheChangedEvent(Sender);
|
BitBlt( ImageHandle, TempPoint.x + 5, TempPoint.y + 5,147,33,NoteHandle,0,0,SRCCOPY);
|
||||||
Oldx := TempPoint.x;
|
Brush.Color := Color;
|
||||||
Oldy := TempPoint.y;
|
Image.Canvas.Rectangle(TempPoint.x + 123, TempPoint.y + 8, tempPoint.x + 149, temppoint.y + 34);
|
||||||
Timor.Enabled:= False;
|
// Rectangle(ImageHandle,TempPoint.x + 123, TempPoint.y + 8, tempPoint.x + 149, temppoint.y + 34);
|
||||||
end;
|
TheChangingEvent(Sender);
|
||||||
|
StretchBlt(ImageHandle,TempPoint.x + 95, TempPoint.y + 9, 24,24, BitmapHandle, TempPoint.x - 1, TempPoint.y-1,3,3, SRCCOPY);
|
||||||
procedure TMColorPicker.ColorPickDown(Sender: TObject; Button: TMouseButton;
|
TheChangedEvent(Sender);
|
||||||
Shift: TShiftState; X, Y: Integer);
|
Oldx := TempPoint.x;
|
||||||
begin;
|
Oldy := TempPoint.y;
|
||||||
Color:= WidgetSet.DCGetPixel(Image.Canvas.Handle,x,y);
|
Timor.Enabled:= False;
|
||||||
Self.Colorx := x;
|
end;
|
||||||
Self.Colory := y;
|
|
||||||
Timor.enabled := false;
|
procedure TMColorPicker.ColorPickDown(Sender: TObject; Button: TMouseButton;
|
||||||
if OnPick <> nil then
|
Shift: TShiftState; X, Y: Integer);
|
||||||
Onpick(Sender,Color,x,y);
|
begin;
|
||||||
Form.Close;
|
Color:= WidgetSet.DCGetPixel(Image.Canvas.Handle,x,y);
|
||||||
end;
|
Self.Colorx := x;
|
||||||
|
Self.Colory := y;
|
||||||
end.
|
Timor.enabled := false;
|
||||||
|
if OnPick <> nil then
|
||||||
|
Onpick(Sender,Color,x,y);
|
||||||
|
Form.Close;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user